Struct ActorRef

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

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

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>

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.

Source§

type Actor = Actor

Source§

type State = State

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§

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>

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>

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

Source§

type Message = Message

Source§

type Response = Response

Source§

type Error = Error

Source§

impl<Actor: Debug, Message: Debug, State: Debug, Response: Debug, Error: Debug> Debug for ActorRef<Actor, Message, State, Response, Error>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Actor, Message, State, Response, Error> Drop for ActorRef<Actor, Message, State, Response, Error>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<Actor, Message, State, Response, Error> !Freeze for ActorRef<Actor, Message, State, Response, Error>

§

impl<Actor, Message, State, Response, Error> !RefUnwindSafe for ActorRef<Actor, Message, State, Response, Error>

§

impl<Actor, Message, State, Response, Error> Send for ActorRef<Actor, Message, State, Response, Error>
where Actor: Sync + Send, State: Send, Message: Send, Response: Send, Error: Send,

§

impl<Actor, Message, State, Response, Error> Sync for ActorRef<Actor, Message, State, Response, Error>
where Actor: Sync + Send, State: Send, Message: Send, Response: Send, Error: Send,

§

impl<Actor, Message, State, Response, Error> Unpin for ActorRef<Actor, Message, State, Response, Error>

§

impl<Actor, Message, State, Response, Error> !UnwindSafe for ActorRef<Actor, Message, State, Response, Error>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S> SSSD for S
where S: Send + Sync + Debug + 'static,