pub struct ActorRef<Actor, Message, State, Response, Error> { /* private fields */ }Expand description
ActorRef is a structure that represents a reference to an actor in an actor system.
It contains the necessary components to interact with the actor and manage its state.
§Type Parameters
Actor: The type of the actor this reference points to.Message: The type of messages that can be sent to the actor.State: The type of the state that the actor maintains.Response: The type of the response that the actor produces.Error: The type of the error that the actor can return.
§Fields
tx: A sender in the message-passing channel. It is used to send messages to the actor.state: An atomic reference counter (Arc) wrapping a mutex-protected state of the actor.name: A string representing the name of the actor.actor: An atomic reference counter (Arc) to the actor.running: An atomic boolean indicating whether the actor is currently running.
Trait Implementations§
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>> ActorRefTrait for ActorRef<Actor, Message, State, Response, Error>
Implementation of the ActorRefTrait 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>> ActorRefTrait for ActorRef<Actor, Message, State, Response, Error>
Implementation of the ActorRefTrait for ActorRef.
This implementation provides the functionality for creating a new actor reference (new method),
and for getting the state of the actor (state 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.
Source§async fn new(
name: impl AsRef<str>,
actor: Self::Actor,
state: Self::State,
buffer: usize,
) -> Result<Arc<Self>, Self::Error>
async fn new( name: impl AsRef<str>, actor: Self::Actor, state: Self::State, buffer: usize, ) -> Result<Arc<Self>, Self::Error>
Creates a new actor reference and starts its execution.
This method creates a new actor reference with the given name, actor, state, and buffer size. It initializes the actor’s state and starts its execution in a new task.
§Parameters
name: The name of the actor.actor: The actor that this reference will point to.state: The initial state of the actor.buffer: The size of the message buffer for the actor.
§Returns
A future that resolves to a result containing either the new actor reference or an error.
§Errors
This function will return an error if the actor fails to start.
§Panics
This function might panic if the actor’s task panics.
Source§async fn state(&self) -> Result<Arc<Mutex<Self::State>>, Error>
async fn state(&self) -> Result<Arc<Mutex<Self::State>>, Error>
Retrieves the state of the actor.
This method clones the state of the actor and returns it. The state is wrapped in an Arc<Mutex<T>> to ensure
safe concurrent access. The method logs the current state for tracing purposes.
§Returns
A future that resolves to a Result containing either the state of the actor wrapped in an Arc<Mutex<T>> or an std::io::Error.
type Actor = Actor
type State = State
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.
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.
Source§async fn ask(&self, msg: Message) -> Result<Response, Error>
async fn ask(&self, msg: Message) -> Result<Response, 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§async fn send(&self, msg: Message) -> Result<(), Error>
async fn send(&self, msg: Message) -> 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§async fn stop(&self) -> Result<(), Error>
async fn stop(&self) -> Result<(), 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).