Skip to main content

ActorContext

Struct ActorContext 

Source
pub struct ActorContext<A: Actor + Handler<A>> { /* private fields */ }
Expand description

Execution context passed to actors during message handling and lifecycle hooks.

Provides access to the actor’s path, child management, event emission, and error reporting. The context is created by the actor system and passed as &mut ActorContext<A> to all handler and lifecycle methods.

Implementations§

Source§

impl<A> ActorContext<A>
where A: Actor + Handler<A>,

Source

pub async fn reference(&self) -> Result<ActorRef<A>, Error>

Returns an ActorRef to this actor, or an error if it has already been removed from the system.

Source

pub const fn path(&self) -> &ActorPath

Returns the hierarchical path that uniquely identifies this actor in the system.

Source

pub const fn system(&self) -> &SystemRef

Returns a reference to the actor system this actor belongs to.

Source

pub async fn get_parent<P: Actor + Handler<P>>( &self, ) -> Result<ActorRef<P>, Error>

Returns a typed handle to the parent actor, or an error if this is a root actor or the parent has stopped.

Source

pub async fn stop(&self, sender: Option<Sender<()>>)

Sends a stop signal to this actor. Pass Some(sender) to receive a confirmation when shutdown completes.

Source

pub async fn publish_event(&self, event: A::Event) -> Result<(), Error>

Broadcasts event to all current subscribers of this actor’s event channel.

Returns an error if the broadcast channel is closed (i.e., the actor is stopping).

Source

pub async fn emit_error(&mut self, error: Error) -> Result<(), Error>

Reports an error to this actor’s parent so the parent can invoke on_child_error.

Returns an error if the parent channel is no longer reachable.

Source

pub async fn emit_fail(&mut self, error: Error) -> Result<(), Error>

Emits a fatal fault, halts message processing, and escalates to the parent via on_child_fault.

Returns an error if the escalation channel is no longer reachable.

Source

pub async fn create_child<C, I>( &mut self, name: &str, actor_init: I, ) -> Result<ActorRef<C>, Error>
where C: Actor + Handler<C>, I: IntoActor<C>,

Spawns a child actor and registers it under this actor’s path.

name becomes the last segment of the child’s path. Returns an ActorRef to the new child on success, or an error if the actor system is shutting down or a child with the same name already exists.

Source

pub async fn get_child<C>(&self, name: &str) -> Result<ActorRef<C>, Error>
where C: Actor + Handler<C>,

Looks up a running child actor by its id and returns a typed handle.

Returns an error if no child with id exists or if the child’s message type does not match the requested actor type C.

Auto Trait Implementations§

§

impl<A> Freeze for ActorContext<A>

§

impl<A> !RefUnwindSafe for ActorContext<A>

§

impl<A> Send for ActorContext<A>

§

impl<A> Sync for ActorContext<A>

§

impl<A> Unpin for ActorContext<A>

§

impl<A> UnsafeUnpin for ActorContext<A>

§

impl<A> !UnwindSafe for ActorContext<A>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more