pub trait Workload: MaybeSendSync + 'static {
type Dispatcher: MessageDispatcher<Workload = Self>;
Show 16 methods
// Provided methods
fn on_start<'life0, 'life1, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_ready<'life0, 'life1, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_stop<'life0, 'life1, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_error<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 ErrorEvent,
) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_signaling_connecting<'life0, 'life1, 'async_trait, C>(
&'life0 self,
_ctx: Option<&'life1 C>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_signaling_connected<'life0, 'life1, 'async_trait, C>(
&'life0 self,
_ctx: Option<&'life1 C>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_signaling_disconnected<'life0, 'life1, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_websocket_connecting<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 PeerEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_websocket_connected<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 PeerEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_websocket_disconnected<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 PeerEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_webrtc_connecting<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 PeerEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_webrtc_connected<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 PeerEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_webrtc_disconnected<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 PeerEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_credential_renewed<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 CredentialEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_credential_expiring<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 CredentialEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
fn on_mailbox_backpressure<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 BackpressureEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
C: 'async_trait + Context,
Self: Sync + 'async_trait { ... }
}Expand description
Workload — Executable Actor workload
Represents a complete Actor instance, composed of:
- an associated
MessageDispatcher(Workload::Dispatcher) that knows how to decode and route incoming RPC envelopes; - sixteen observation hooks grouped by category (see below), each with a
meaningful default that emits a
tracingrecord so unmodified workloads produce useful operational logs out of the box.
§Design
- Bidirectional association:
Workload::DispatcherandMessageDispatcher::Workloadrefer to each other so that generated dispatchers can access the user-implemented workload type. - Meaningful defaults: every hook has a
tracing-emitting default (info/debug/warn/errorlevels tuned per hook). Users override only the hooks whose behaviour they want to extend. - Auto-implementation: the code generator emits
impl<T: Handler> Workload for Wrapper<T> { type Dispatcher = Router<T>; }which inherits every default implementation. Generated wrappers thus get 16 hooks “for free”.
§Hook categories
Hooks are organised into six categories. Override only the hooks you need.
§Lifecycle (4) — fallible
Workload::on_start— node started, before accepting requestsWorkload::on_ready— node registered and ready to accept requestsWorkload::on_stop— shutdown signal receivedWorkload::on_error— framework caught a runtime error
Lifecycle hooks return ActorResult; errors propagate and abort startup
(for on_start) or are logged by the framework (for the others).
§Signaling (3) — infallible
Workload::on_signaling_connectingWorkload::on_signaling_connectedWorkload::on_signaling_disconnected
§Transport — WebSocket (3) — infallible
Workload::on_websocket_connectingWorkload::on_websocket_connectedWorkload::on_websocket_disconnected
§Transport — WebRTC P2P (3) — infallible
Workload::on_webrtc_connectingWorkload::on_webrtc_connected— includesrelayedinfo viaPeerEvent::relayedWorkload::on_webrtc_disconnected
§Credential (2) — infallible
§Mailbox (1) — infallible
§Code Generation Example
// User-implemented Handler
pub struct MyEchoService { /* ... */ }
impl EchoServiceHandler for MyEchoService {
async fn echo<C: Context>(
&self,
req: EchoRequest,
ctx: &C,
) -> ActorResult<EchoResponse> {
Ok(EchoResponse { reply: format!("Echo: {}", req.message) })
}
}
// Code-generated Workload wrapper — inherits all 16 defaults.
pub struct EchoServiceWorkload<T: EchoServiceHandler>(pub T);
impl<T: EchoServiceHandler> Workload for EchoServiceWorkload<T> {
type Dispatcher = EchoServiceRouter<T>;
}Required Associated Types§
Sourcetype Dispatcher: MessageDispatcher<Workload = Self>
type Dispatcher: MessageDispatcher<Workload = Self>
Associated dispatcher type.
Provided Methods§
Sourcefn on_start<'life0, 'life1, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
fn on_start<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, ) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
Called when the node has started.
Use this to initialise business resources, start timers, etc. Returning
Err aborts node startup.
Sourcefn on_ready<'life0, 'life1, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
fn on_ready<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, ) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
Called when signaling is connected and registration is complete: the node is now discoverable and may serve requests.
Sourcefn on_stop<'life0, 'life1, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
fn on_stop<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, ) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
Called when the node receives a shutdown signal.
Use this to release business resources and persist state.
Sourcefn on_error<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 ErrorEvent,
) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
fn on_error<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 ErrorEvent, ) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
Called when the framework catches a runtime error.
See ErrorEvent and ErrorCategory for the structure of the
argument. Use this for alerting, logging, or graceful degradation.
Sourcefn on_signaling_connecting<'life0, 'life1, 'async_trait, C>(
&'life0 self,
_ctx: Option<&'life1 C>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
fn on_signaling_connecting<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: Option<&'life1 C>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
Called when signaling connection attempt begins.
ctx is None during the initial connection (before the node has
obtained its identity) and Some for every subsequent reconnect.
Sourcefn on_signaling_connected<'life0, 'life1, 'async_trait, C>(
&'life0 self,
_ctx: Option<&'life1 C>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
fn on_signaling_connected<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: Option<&'life1 C>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
Called when signaling connection is established. Actor is online.
ctx is None during the initial connection and Some for every
subsequent reconnect.
Sourcefn on_signaling_disconnected<'life0, 'life1, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
fn on_signaling_disconnected<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
Called when signaling connection is lost. Actor is offline.
Sourcefn on_websocket_connecting<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 PeerEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
fn on_websocket_connecting<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
Called when a WebSocket connection attempt to a peer begins.
Sourcefn on_websocket_connected<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 PeerEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
fn on_websocket_connected<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
Called when a WebSocket connection to a peer is established.
Sourcefn on_websocket_disconnected<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 PeerEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
fn on_websocket_disconnected<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
Called when a WebSocket connection to a peer is lost.
Sourcefn on_webrtc_connecting<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 PeerEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
fn on_webrtc_connecting<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
Called when a WebRTC P2P connection attempt to a peer begins.
Sourcefn on_webrtc_connected<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 PeerEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
fn on_webrtc_connected<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
Called when a WebRTC P2P connection to a peer is established.
event.relayed carries whether the selected ICE candidate pair
traverses a TURN relay (Some(true)) or is a direct P2P connection
(Some(false)).
Sourcefn on_webrtc_disconnected<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 PeerEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
fn on_webrtc_disconnected<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
Called when a WebRTC P2P connection to a peer is lost.
Sourcefn on_credential_renewed<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 CredentialEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
fn on_credential_renewed<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 CredentialEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
Called when the current credential is renewed (initial registration or subsequent refresh).
Sourcefn on_credential_expiring<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 CredentialEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
fn on_credential_expiring<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 CredentialEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
Called when the active credential is approaching its expiry.
The warning lead time is controlled by
HyperConfig::credential_expiry_warning on the hyper layer.
Sourcefn on_mailbox_backpressure<'life0, 'life1, 'life2, 'async_trait, C>(
&'life0 self,
_ctx: &'life1 C,
event: &'life2 BackpressureEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
fn on_mailbox_backpressure<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 BackpressureEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
Called once per incident when the persistent mailbox queue length crosses the configured backpressure threshold.
Fires once per cross (rising edge); the framework resets the triggered flag once the queue falls below the threshold again.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".