pub trait Actor<E>: Send + 'static {
// Required method
fn run(&mut self) -> impl Future<Output = Result<(), E>> + Send;
}Expand description
Async actor trait. Loop forever receiving and executing actions.
§Example
ⓘ
impl Actor<io::Error> for MyActor {
async fn run(&mut self) -> io::Result<()> {
loop {
tokio::select! {
Ok(action) = self.rx.recv_async() => action(self).await,
else => break Ok(()),
}
}
Err(io::Error::new(io::ErrorKind::Other, "Actor stopped"))
}
}Required Methods§
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.