Skip to main content

ChoreoHandler

Trait ChoreoHandler 

Source
pub trait ChoreoHandler: Send {
    type Role: RoleId;
    type Endpoint: Endpoint;

    // Required methods
    fn send<'life0, 'life1, 'life2, 'async_trait, M>(
        &'life0 mut self,
        ep: &'life1 mut Self::Endpoint,
        to: Self::Role,
        msg: &'life2 M,
    ) -> Pin<Box<dyn Future<Output = ChoreoResult<()>> + Send + 'async_trait>>
       where M: 'async_trait + Serialize + Send + Sync,
             Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn recv<'life0, 'life1, 'async_trait, M>(
        &'life0 mut self,
        ep: &'life1 mut Self::Endpoint,
        from: Self::Role,
    ) -> Pin<Box<dyn Future<Output = ChoreoResult<M>> + Send + 'async_trait>>
       where M: 'async_trait + DeserializeOwned + Send,
             Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn choose<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        ep: &'life1 mut Self::Endpoint,
        who: Self::Role,
        label: <Self::Role as RoleId>::Label,
    ) -> Pin<Box<dyn Future<Output = ChoreoResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn offer<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        ep: &'life1 mut Self::Endpoint,
        from: Self::Role,
    ) -> Pin<Box<dyn Future<Output = ChoreoResult<<Self::Role as RoleId>::Label>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn with_timeout<'life0, 'life1, 'async_trait, F, T>(
        &'life0 mut self,
        ep: &'life1 mut Self::Endpoint,
        at: Self::Role,
        dur: Duration,
        body: F,
    ) -> Pin<Box<dyn Future<Output = ChoreoResult<T>> + Send + 'async_trait>>
       where F: Future<Output = ChoreoResult<T>> + Send + 'async_trait,
             T: 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn broadcast<'life0, 'life1, 'life2, 'life3, 'async_trait, M>(
        &'life0 mut self,
        ep: &'life1 mut Self::Endpoint,
        recipients: &'life2 [Self::Role],
        msg: &'life3 M,
    ) -> Pin<Box<dyn Future<Output = ChoreoResult<()>> + Send + 'async_trait>>
       where M: 'async_trait + Serialize + Send + Sync,
             Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn parallel_send<'life0, 'life1, 'life2, 'async_trait, M>(
        &'life0 mut self,
        ep: &'life1 mut Self::Endpoint,
        sends: &'life2 [(Self::Role, M)],
    ) -> Pin<Box<dyn Future<Output = ChoreoResult<()>> + Send + 'async_trait>>
       where M: 'async_trait + Serialize + Send + Sync,
             Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

The core effect handler trait that abstracts all communication effects

This trait defines the primitive operations for choreographic protocols: sending, receiving, choosing, offering, and timeouts. Implement this trait to provide custom transport mechanisms (in-memory, network, etc.).

§Type Parameters

  • Role: The type representing protocol participants
  • Endpoint: The connection state for this protocol execution

§Async implementation notes

We deliberately use the async_trait macro here so the trait stays object-safe, which lets middleware stacks (e.g. Trace<Retry<H>>) erase handlers behind trait objects. The macro also enforces Send on all returned futures, so the bounds on methods like with_timeout apply equally to native multithreaded runtimes and single-threaded WASM builds.

Required Associated Types§

Source

type Role: RoleId

The role type for this choreography

Source

type Endpoint: Endpoint

The endpoint type maintaining connection state

Required Methods§

Source

fn send<'life0, 'life1, 'life2, 'async_trait, M>( &'life0 mut self, ep: &'life1 mut Self::Endpoint, to: Self::Role, msg: &'life2 M, ) -> Pin<Box<dyn Future<Output = ChoreoResult<()>> + Send + 'async_trait>>
where M: 'async_trait + Serialize + Send + Sync, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Send a message to a specific role

§Arguments
  • ep - The session endpoint
  • to - The recipient role
  • msg - The message to send (must be serializable)
Source

fn recv<'life0, 'life1, 'async_trait, M>( &'life0 mut self, ep: &'life1 mut Self::Endpoint, from: Self::Role, ) -> Pin<Box<dyn Future<Output = ChoreoResult<M>> + Send + 'async_trait>>
where M: 'async_trait + DeserializeOwned + Send, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Receive a strongly-typed message from a specific role

§Arguments
  • ep - The session endpoint
  • from - The sender role
§Returns

The received message of type M

Source

fn choose<'life0, 'life1, 'async_trait>( &'life0 mut self, ep: &'life1 mut Self::Endpoint, who: Self::Role, label: <Self::Role as RoleId>::Label, ) -> Pin<Box<dyn Future<Output = ChoreoResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Internal choice: broadcast a label selection

Used by the choosing role to inform others of the selected branch.

§Arguments
  • ep - The session endpoint
  • who - The role making the choice (usually the current role)
  • label - The selected branch label
Source

fn offer<'life0, 'life1, 'async_trait>( &'life0 mut self, ep: &'life1 mut Self::Endpoint, from: Self::Role, ) -> Pin<Box<dyn Future<Output = ChoreoResult<<Self::Role as RoleId>::Label>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

External choice: receive a label selection

Used by non-choosing roles to receive the branch selection from another role.

§Arguments
  • ep - The session endpoint
  • from - The role that made the choice
§Returns

The label selected by the choosing role

Source

fn with_timeout<'life0, 'life1, 'async_trait, F, T>( &'life0 mut self, ep: &'life1 mut Self::Endpoint, at: Self::Role, dur: Duration, body: F, ) -> Pin<Box<dyn Future<Output = ChoreoResult<T>> + Send + 'async_trait>>
where F: Future<Output = ChoreoResult<T>> + Send + 'async_trait, T: 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute a future with a timeout

§Arguments
  • ep - The session endpoint
  • at - The role where timeout is enforced
  • dur - Maximum duration to wait
  • body - The future to execute
§Returns

Result of the future, or timeout error if duration exceeded

Provided Methods§

Source

fn broadcast<'life0, 'life1, 'life2, 'life3, 'async_trait, M>( &'life0 mut self, ep: &'life1 mut Self::Endpoint, recipients: &'life2 [Self::Role], msg: &'life3 M, ) -> Pin<Box<dyn Future<Output = ChoreoResult<()>> + Send + 'async_trait>>
where M: 'async_trait + Serialize + Send + Sync, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Broadcast a message to multiple recipients

Default implementation sends sequentially. Override for optimized broadcasting.

Source

fn parallel_send<'life0, 'life1, 'life2, 'async_trait, M>( &'life0 mut self, ep: &'life1 mut Self::Endpoint, sends: &'life2 [(Self::Role, M)], ) -> Pin<Box<dyn Future<Output = ChoreoResult<()>> + Send + 'async_trait>>
where M: 'async_trait + Serialize + Send + Sync, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Send messages to multiple recipients in parallel

Default implementation sends sequentially. Override for true parallelism.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§