pub trait Actor:
Sized
+ Send
+ 'static {
type Context: ActorContext<Self>;
type Error: Into<Box<dyn Error + Send + Sync>> + Send + 'static;
// Provided methods
fn pre_start(&mut self, ctx: &mut Self::Context) -> Result<(), Self::Error> { ... }
fn post_start(
&mut self,
ctx: &mut Self::Context,
) -> impl Future<Output = Result<(), Self::Error>> + Send { ... }
fn stopping(
&mut self,
ctx: &mut Self::Context,
) -> impl Future<Output = Result<Stopping, Self::Error>> + Send { ... }
fn post_stop(
&mut self,
ctx: &mut Self::Context,
) -> impl Future<Output = Result<(), Self::Error>> + Send { ... }
fn run<S>(
self,
label: S,
) -> Result<(Address<Self>, JoinHandle<()>), Self::Error>
where S: AsRef<str> { ... }
fn create<S, F>(
label: S,
f: F,
) -> Result<(Address<Self>, JoinHandle<()>), Self::Error>
where S: AsRef<str>,
F: FnOnce(&mut Self::Context) -> Result<Self, Self::Error> { ... }
}Expand description
Describes an actor.
Required Associated Types§
Sourcetype Context: ActorContext<Self>
type Context: ActorContext<Self>
The execution context type for this actor.
Provided Methods§
Sourcefn pre_start(&mut self, ctx: &mut Self::Context) -> Result<(), Self::Error>
fn pre_start(&mut self, ctx: &mut Self::Context) -> Result<(), Self::Error>
Invoked before an actor is spawned into the tokio runtime.
The actor should be in Unstarted state.
This method is used to perform initialization tasks or spawn child actors.
In the default Context implementation, it is not spawned
into the tokio runtime and it is outside of the processing loop. Thus it will be invoked
only once synchronously. The actor will enter the Starting state
after this method returns.
Panics in this method will prevent the actor being spawned into the runtime.
run will return an error to the caller in this case.
Sourcefn post_start(
&mut self,
ctx: &mut Self::Context,
) -> impl Future<Output = Result<(), Self::Error>> + Send
fn post_start( &mut self, ctx: &mut Self::Context, ) -> impl Future<Output = Result<(), Self::Error>> + Send
Invoked after an actor is spawned into the tokio runtime.
The actor should be in Starting state.
This method is used to perform addtional initialization.
In the default Context implementation, it is spawned into
the tokio runtime and it is outside of the processing loop. Thus it will be invoked only
once asynchronously. The actor will enter the Running state
after this method returns.
Panics in this method will be notified to the supervisor if there is one.
Sourcefn stopping(
&mut self,
ctx: &mut Self::Context,
) -> impl Future<Output = Result<Stopping, Self::Error>> + Send
fn stopping( &mut self, ctx: &mut Self::Context, ) -> impl Future<Output = Result<Stopping, Self::Error>> + Send
Invoked when an actor is being stopped.
The actor should be in Stopping state.
This method is used to make decisions about whether to stop or to restart the actor.
Sourcefn post_stop(
&mut self,
ctx: &mut Self::Context,
) -> impl Future<Output = Result<(), Self::Error>> + Send
fn post_stop( &mut self, ctx: &mut Self::Context, ) -> impl Future<Output = Result<(), Self::Error>> + Send
Invoked after an actor is stopped.
The actor should be in Stopped state.
This method is used to perform cleanup tasks or spawn new actors.
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.