Trait gabriel2::Handler

source ·
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 be Sync, Send and 'static.
  • Message: The type of the messages that the actor can process. This type must be Sync, Send and 'static.
  • State: The type of the state of the actor. This type must be Sync, Send and 'static.
  • Response: The type of the response that the actor produces after processing a message. This type must be Sync, Send and 'static.
  • Error: The type of the error that the actor can produce. This type must be Sync, Send and '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 a Future that resolves to a Result containing 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 a Future that resolves to a Result. If the Result is Ok, the actor starts; if it is Err, the actor does not start. By default, this method returns Ok(()).
  • 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 a Future that resolves to a Result. If the Result is Ok, the actor stops; if it is Err, the actor does not stop. By default, this method returns Ok(()).

Required Associated Types§

Required Methods§

source

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§

source

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>>

source

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.

Implementors§