pub trait Handler {
type Actor: SSSD;
type Message: SSSD;
type State: SSSD;
type Response: SSSD;
type Error: SSSD + Error + From<Error>;
// Required method
fn receive(
&self,
ctx: Arc<Context<Self::Actor, Self::Message, Self::State, Self::Response, Self::Error>>,
) -> impl Future<Output = Result<Self::Response, Self::Error>> + Send;
// Provided methods
fn pre_start(
&self,
_state: Arc<Mutex<Self::State>>,
) -> impl Future<Output = Result<(), Self::Error>> { ... }
fn pre_stop(
&self,
_state: Arc<Mutex<Self::State>>,
) -> impl Future<Output = Result<(), Self::Error>> { ... }
}Expand description
The Handler trait defines the behavior of an actor in an actor system.
It provides methods for handling incoming messages and lifecycle events.
§Type Parameters
Actor: The type of the actor this handler is associated with. It must implement theSSSDtrait.Message: The type of messages that this handler can process. It must implement theSSSDtrait.State: The type of the state that the actor maintains. It must implement theSSSDtrait.Response: The type of the response that the actor produces. It must implement theSSSDtrait.Error: The type of the error that the actor can return. It must implement theSSSDtrait andstd::error::Error, and be convertible fromstd::io::Error.
Required Associated Types§
type Actor: SSSD
type Message: SSSD
type State: SSSD
type Response: SSSD
type Error: SSSD + Error + From<Error>
Required Methods§
Sourcefn receive(
&self,
ctx: Arc<Context<Self::Actor, Self::Message, Self::State, Self::Response, Self::Error>>,
) -> impl Future<Output = Result<Self::Response, Self::Error>> + Send
fn receive( &self, ctx: Arc<Context<Self::Actor, Self::Message, Self::State, Self::Response, Self::Error>>, ) -> impl Future<Output = Result<Self::Response, Self::Error>> + Send
Handles the incoming message for the actor.
This method is called when the actor receives a message. It processes the message in the context of the actor and returns a future that resolves to a result containing either the response produced by the actor or an error.
§Parameters
ctx: The context in which the actor operates. It contains the message to be processed, the state of the actor, and a reference to the actor itself.
§Returns
A future that resolves to a result containing either the response produced by the actor or an error.
Provided Methods§
Sourcefn pre_start(
&self,
_state: Arc<Mutex<Self::State>>,
) -> impl Future<Output = Result<(), Self::Error>>
fn pre_start( &self, _state: Arc<Mutex<Self::State>>, ) -> impl Future<Output = Result<(), Self::Error>>
Handles the pre-start lifecycle event for the actor.
This method is called before the actor starts processing messages. It can be used to perform setup operations that the actor needs before it can start processing messages.
§Parameters
_state: The state of the actor. This parameter is currently unused.
§Returns
A future that resolves to a result. If the setup operations were successful, the result is Ok(()).
If there was an error during the setup operations, the result is Err(Self::Error).
Sourcefn pre_stop(
&self,
_state: Arc<Mutex<Self::State>>,
) -> impl Future<Output = Result<(), Self::Error>>
fn pre_stop( &self, _state: Arc<Mutex<Self::State>>, ) -> impl Future<Output = Result<(), Self::Error>>
Handles the pre-stop lifecycle event for the actor.
This method is called before the actor stops processing messages. It can be used to perform cleanup operations that the actor needs before it can safely stop.
§Parameters
_state: The state of the actor. This parameter is currently unused.
§Returns
A future that resolves to a result. If the cleanup operations were successful, the result is Ok(()).
If there was an error during the cleanup operations, the result is Err(Self::Error).
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.