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 participantsEndpoint: 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§
Required Methods§
Sourcefn 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>>
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>>
Send a message to a specific role
§Arguments
ep- The session endpointto- The recipient rolemsg- The message to send (must be serializable)
Sourcefn 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 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,
Sourcefn 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 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 endpointwho- The role making the choice (usually the current role)label- The selected branch label
Sourcefn 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 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,
Sourcefn 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,
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§
Sourcefn 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>>
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>>
Broadcast a message to multiple recipients
Default implementation sends sequentially. Override for optimized broadcasting.
Sourcefn 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>>
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>>
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.