Skip to content

Commit

Permalink
Hide get_type_id() from the public API
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Feb 19, 2025
1 parent eecbdc9 commit 45f80c9
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions manul/src/protocol/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,20 @@ pub enum EchoRoundParticipation<Id> {
},
}

mod sealed {
/// A dyn safe trait to get the type's ID.
pub trait DynTypeId: 'static {
/// Returns the type ID of the implementing type.
fn get_type_id(&self) -> core::any::TypeId {
core::any::TypeId::of::<Self>()
}
}

impl<T: 'static> DynTypeId for T {}
}

use sealed::DynTypeId;

/**
A type representing a single round of a protocol.
Expand All @@ -366,7 +380,7 @@ The way a round will be used by an external caller:
- process received messages from other nodes (by calling [`receive_message`](`Self::receive_message`));
- attempt to finalize (by calling [`finalize`](`Self::finalize`)) to produce the next round, or return a result.
*/
pub trait Round<Id: PartyId>: 'static + Debug + Send + Sync {
pub trait Round<Id: PartyId>: 'static + Debug + Send + Sync + DynTypeId {
/// The protocol this round is a part of.
type Protocol: Protocol<Id>;

Expand Down Expand Up @@ -449,11 +463,4 @@ pub trait Round<Id: PartyId>: 'static + Debug + Send + Sync {
payloads: BTreeMap<Id, Payload>,
artifacts: BTreeMap<Id, Artifact>,
) -> Result<FinalizeOutcome<Id, Self::Protocol>, LocalError>;

/// Returns the type ID of the implementing type.
///
/// **Warning:** replacing the blanket implementation may lead to bugs.
fn get_type_id(&self) -> core::any::TypeId {
core::any::TypeId::of::<Self>()
}
}

0 comments on commit 45f80c9

Please sign in to comment.