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 authored and tomleavy committed Jan 18, 2024
1 parent 35c19c5 commit b9ca33a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions mls-rs/src/group/proposal_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl GroupState {
.apply_proposals(&sender, &proposals, commit_time)
.await?;

#[cfg(all(feature = "by_ref_proposal", feature = "state_update"))]
#[cfg(feature = "by_ref_proposal")]
let rejected_proposals =
rejected_proposals(all_proposals, &applier_output.applied_proposals);

Expand All @@ -268,7 +268,7 @@ impl GroupState {
applied_proposals: proposals,
external_init_index: applier_output.external_init_index,
indexes_of_added_kpkgs: applier_output.indexes_of_added_kpkgs,
#[cfg(all(feature = "by_ref_proposal", feature = "state_update"))]
#[cfg(feature = "by_ref_proposal")]
rejected_proposals,
})
}
Expand Down
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 b9ca33a

Please sign in to comment.