Skip to content

Commit

Permalink
Fix ProposalInfo specialization
Browse files Browse the repository at this point in the history
- The specialization macro needs to be invoked after the impl block, so
  that macros generated for this block are available at the
  specialization point.
- Macro qualification is not supported in the crate where the macro is
  defined.
  • Loading branch information
stefunctional committed Jan 18, 2024
1 parent 35c19c5 commit 9446b47
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions mls-rs/src/group/proposal_filter/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,8 @@ pub struct ProposalInfo<T> {
pub source: ProposalSource,
}

safer_ffi_gen::specialize!(ProposalInfoFfi = crate::group::proposal_filter::ProposalInfo<Proposal>);

#[cfg_attr(all(feature = "ffi", not(test)), ::safer_ffi_gen::safer_ffi_gen)]
impl ProposalInfo<Proposal> {
impl<T> ProposalInfo<T> {
/// Create a new ProposalInfo.
///
/// The resulting value will be either transmitted with a commit or
Expand All @@ -472,8 +470,8 @@ impl ProposalInfo<Proposal> {
///
/// This function is useful when implementing custom
/// [`MlsRules`](crate::MlsRules).
#[safer_ffi_gen::safer_ffi_gen_ignore]
pub fn new(proposal: Proposal, sender: Sender, can_transmit: bool) -> ProposalInfo<Proposal> {
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::safer_ffi_gen_ignore)]
pub fn new(proposal: T, sender: Sender, can_transmit: bool) -> Self {
let source = if can_transmit {
ProposalSource::ByValue
} else {
Expand All @@ -487,20 +485,17 @@ impl ProposalInfo<Proposal> {
}
}

// TODO: Proposal has a lot of cases that we don't have FFI support for yet.

#[cfg(feature = "ffi")]
#[cfg(all(feature = "ffi", not(test)))]
pub fn sender(&self) -> &Sender {
&self.sender
}

#[cfg(feature = "ffi")]
#[cfg(all(feature = "ffi", not(test)))]
pub fn source(&self) -> &ProposalSource {
&self.source
}
}

impl<T> ProposalInfo<T> {
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::safer_ffi_gen_ignore)]
pub fn map<U, F>(self, f: F) -> ProposalInfo<U>
where
F: FnOnce(T) -> U,
Expand All @@ -512,6 +507,7 @@ impl<T> ProposalInfo<T> {
}
}

#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::safer_ffi_gen_ignore)]
pub fn as_ref(&self) -> ProposalInfo<&T> {
ProposalInfo {
proposal: &self.proposal,
Expand Down Expand Up @@ -540,6 +536,9 @@ impl<T> ProposalInfo<T> {
}
}

#[cfg(all(feature = "ffi", not(test)))]
safer_ffi_gen::specialize!(ProposalInfoFfi = ProposalInfo<Proposal>);

pub trait Proposable: Sized {
const TYPE: ProposalType;

Expand Down

0 comments on commit 9446b47

Please sign in to comment.