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>>,
_self_ref: Arc<ActorRef<Self::Actor, Self::Message, Self::State, Self::Response, Self::Error>>,
) -> impl Future<Output = Result<(), Self::Error>> { ... }
fn pre_stop(
&self,
_state: Arc<Mutex<Self::State>>,
_self_ref: Arc<ActorRef<Self::Actor, Self::Message, Self::State, Self::Response, Self::Error>>,
) -> impl Future<Output = Result<(), Self::Error>> { ... }
}Expand description
Handler is a trait that defines the behavior of an actor in the Actorlib framework.
This trait is implemented by any type that can act as an actor in the Actorlib framework. It provides methods for handling messages and managing the actor’s lifecycle.
§Type parameters
Actor: The type of the actor. This type must beSync,Sendand'static.Message: The type of the messages that the actor can process. This type must beSync,Sendand'static.State: The type of the state of the actor. This type must beSync,Sendand'static.Response: The type of the response that the actor produces after processing a message. This type must beSync,Sendand'static.Error: The type of the error that the actor can produce. This type must beSync,Sendand'static.
§Methods
receive: This method is called when the actor receives a message. It takes a context, which contains the message and the state of the actor, and returns aFuturethat resolves to aResultcontaining either the response produced by the actor after processing the message, or an error.pre_start: This method is called before the actor starts. It takes the state of the actor and a reference to the actor itself, and returns aFuturethat resolves to aResult. If theResultisOk, the actor starts; if it isErr, the actor does not start. By default, this method returnsOk(()).pre_stop: This method is called before the actor stops. It takes the state of the actor and a reference to the actor itself, and returns aFuturethat resolves to aResult. If theResultisOk, the actor stops; if it isErr, the actor does not stop. By default, this method returnsOk(()).
Required Associated Types§
type Actor: SSSD
type Message: SSSD
type State: SSSD
type Response: SSSD
type Error: SSSD + Error + From<Error>
Required Methods§
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>>, _self_ref: Arc<ActorRef<Self::Actor, Self::Message, Self::State, Self::Response, Self::Error>>, ) -> impl Future<Output = Result<(), Self::Error>>
fn pre_stop( &self, _state: Arc<Mutex<Self::State>>, _self_ref: Arc<ActorRef<Self::Actor, Self::Message, Self::State, Self::Response, Self::Error>>, ) -> impl Future<Output = Result<(), Self::Error>>
Object Safety§
This trait is not object safe.