Skip to main content

Party

Derive Macro Party 

Source
#[derive(Party)]
{
    // Attributes available to this derive:
    #[party]
    #[session_id]
    #[transcript]
    #[hasher]
}
Expand description

Procedural macro to automatically implement the Party trait for a struct.

§Requirements

  • The struct must have either:
    • A field marked with #[session_id] or a field of type SessionId, or
    • At least one field annotated with #[party] (which must itself implement Party).

§Behavior

  • session_id(): Returns a reference to the SessionId field, or delegates to the first #[party] field.
  • protocol_name(): Uses the PROTOCOL_INFO constant if a direct SessionId field is present, otherwise formats as "<TypeName> - <InnerProtocolName>".
  • refresh(): Calls refresh_from or refresh_with on the session id, and refresh() on all #[party] fields. If a hasher field is present, it is reset.

§Usage

#[derive(Party)]
pub struct MyParty {
    #[session_id]
    session_id: SessionId,
    #[party]
    inner: InnerPartyType,
    // ...
}
// or, with type/name matching fallback:
#[derive(Party)]
pub struct MyParty { session_id: SessionId, #[party] inner: InnerPartyType, ... }