pub trait Actor: Send + 'static {
type Command: Send + 'static;
// Required method
fn handle(&mut self, cmd: Self::Command) -> impl Future<Output = ()> + Send;
// Provided methods
fn on_idle(&mut self) -> impl Future<Output = ()> + Send { ... }
fn on_shutdown(&mut self) -> impl Future<Output = ()> + Send { ... }
}Available on crate feature
concurrency only.Expand description
An actor owns mutable state and processes commands sequentially.
Implementations pick a Command type (typically an enum with
embedded oneshot::Sender<Reply> fields for request-response).
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn on_idle(&mut self) -> impl Future<Output = ()> + Send
fn on_idle(&mut self) -> impl Future<Output = ()> + Send
Called every idle_interval when no commands are pending.
Default: no-op. Useful for periodic state maintenance
(cleanup, metrics emit, etc.) without a separate timer task.
Sourcefn on_shutdown(&mut self) -> impl Future<Output = ()> + Send
fn on_shutdown(&mut self) -> impl Future<Output = ()> + Send
Called once after shutdown is signalled (or all senders dropped) and the in-flight command finishes.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".