Trait ActorTrait

Source
pub trait ActorTrait {
    type Message: SSSD;
    type Response: SSSD;
    type Error: SSSD + Error + From<Error>;

    // Required methods
    fn ask(
        &self,
        msg: Self::Message,
    ) -> impl Future<Output = Result<Self::Response, Self::Error>>;
    fn send(
        &self,
        msg: Self::Message,
    ) -> impl Future<Output = Result<(), Error>>;
    fn stop(&self) -> impl Future<Output = Result<(), Self::Error>>;
}
Expand description

The ActorTrait trait defines the behavior of an actor in an actor system. It provides methods for sending messages to the actor, asking the actor for a response, and stopping the actor.

§Type Parameters

  • Message: The type of messages that this actor can process. It must implement the SSSD trait.
  • Response: The type of the response that the actor produces. It must implement the SSSD trait.
  • Error: The type of the error that the actor can return. It must implement the SSSD trait and std::error::Error, and be convertible from std::io::Error.

Required Associated Types§

Required Methods§

Source

fn ask( &self, msg: Self::Message, ) -> impl Future<Output = Result<Self::Response, Self::Error>>

Sends a message to the actor and waits for a response.

This method sends a message to the actor and returns a future that resolves to a result containing either the response produced by the actor or an error.

§Parameters
  • msg: The message to be sent to the actor.
§Returns

A future that resolves to a result containing either the response produced by the actor or an error.

Source

fn send(&self, msg: Self::Message) -> impl Future<Output = Result<(), Error>>

Sends a message to the actor without waiting for a response.

This method sends a message to the actor and returns a future that resolves to a result indicating whether the message was successfully sent.

§Parameters
  • msg: The message to be sent to the actor.
§Returns

A future that resolves to a result indicating whether the message was successfully sent. If the message was successfully sent, the result is Ok(()). If there was an error while sending the message, the result is Err(std::io::Error).

Source

fn stop(&self) -> impl Future<Output = Result<(), Self::Error>>

Stops the actor.

This method stops the actor and returns a future that resolves to a result indicating whether the actor was successfully stopped.

§Returns

A future that resolves to a result indicating whether the actor was successfully stopped. If the actor was successfully stopped, the result is Ok(()). If there was an error while stopping the actor, 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.

Implementors§

Source§

impl<Actor: SSSDED, Message: SSSDED, State: SSSDED, Response: SSSDED, Error: SSSDED + Error + From<Error> + 'static> ActorTrait for ActorClient<Actor, Message, State, Response, Error>

Source§

type Message = Message

Source§

type Response = Response

Source§

type Error = Error

Source§

impl<Actor: Handler<Actor = Actor, State = State, Message = Message, Error = Error, Response = Response> + SSSD, Message: SSSD, State: SSSD, Response: SSSD, Error: SSSD + Error + From<Error>> ActorTrait for ActorRef<Actor, Message, State, Response, Error>

Implementation of the ActorTrait for ActorRef.

This implementation provides the functionality for sending messages to the actor (ask and send methods), and for stopping the actor (stop method).

§Type Parameters

  • Actor: The type of the actor this reference points to. It must implement the Handler and SSSD traits.
  • Message: The type of messages that this actor can process. It must implement the SSSD trait.
  • State: The type of the state that the actor maintains. It must implement the SSSD trait.
  • Response: The type of the response that the actor produces. It must implement the SSSD trait.
  • Error: The type of the error that the actor can return. It must implement the SSSD trait and std::error::Error, and be convertible from std::io::Error.
Source§

type Message = Message

Source§

type Response = Response

Source§

type Error = Error