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 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§
Required Methods§
Sourcefn ask(
&self,
msg: Self::Message,
) -> impl Future<Output = Result<Self::Response, Self::Error>>
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.
Sourcefn send(&self, msg: Self::Message) -> impl Future<Output = Result<(), Error>>
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).
Sourcefn stop(&self) -> impl Future<Output = Result<(), Self::Error>>
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>
impl<Actor: SSSDED, Message: SSSDED, State: SSSDED, Response: SSSDED, Error: SSSDED + Error + From<Error> + 'static> ActorTrait for ActorClient<Actor, Message, State, Response, 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.
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 theHandlerandSSSDtraits.Message: The type of messages that this actor 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.