Struct Context

Source
pub struct Context<Msg: Message> {
    pub myself: ActorRef<Msg>,
    pub system: ActorSystem,
    /* private fields */
}
Expand description

Provides context, including the actor system during actor execution.

Context is passed to an actor’s functions, such as receive.

Operations performed are in most cases done so from the actor’s perspective. For example, creating a child actor using ctx.actor_of will create the child under the current actor within the heirarchy. In a similar manner, persistence operations such as persist_event use the current actor’s persistence configuration.

Since Context is specific to an actor and its functions it is not cloneable.

Fields§

§myself: ActorRef<Msg>§system: ActorSystem

Implementations§

Source§

impl<Msg> Context<Msg>
where Msg: Message,

Source

pub fn myself(&self) -> ActorRef<Msg>

Returns the ActorRef of the current actor.

Source

pub fn name(&self) -> &str

Return the name of actor. Useful for logging

Trait Implementations§

Source§

impl<Msg: Message> ActorRefFactory for Context<Msg>

Source§

fn actor_of_props<A>( &self, props: BoxActorProd<A>, name: &str, ) -> Result<ActorRef<A::Msg>, CreateError>
where A: Actor,

Source§

fn actor_of<A>( &self, name: &str, ) -> Result<ActorRef<<A as Actor>::Msg>, CreateError>
where A: ActorFactory,

Source§

fn actor_of_args<A, Args>( &self, name: &str, args: Args, ) -> Result<ActorRef<<A as Actor>::Msg>, CreateError>
where Args: ActorArgs, A: ActorFactoryArgs<Args>,

Source§

fn stop(&self, actor: impl ActorReference)

Source§

impl<Msg> ActorSelectionFactory for Context<Msg>
where Msg: Message,

Source§

fn select(&self, path: &str) -> Result<ActorSelection, InvalidPath>

Source§

impl<Msg: Debug + Message> Debug for Context<Msg>

Source§

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

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

impl<Msg> Run for Context<Msg>
where Msg: Message,

Source§

fn run<Fut>( &self, future: Fut, ) -> Result<RemoteHandle<<Fut as Future>::Output>, SpawnError>
where Fut: Future + Send + 'static, <Fut as Future>::Output: Send,

Source§

impl<Msg> Timer for Context<Msg>
where Msg: Message,

Source§

fn schedule<T, M>( &self, initial_delay: Duration, interval: Duration, receiver: ActorRef<M>, sender: Sender, msg: T, ) -> Uuid
where T: Message + Into<M>, M: Message,

Source§

fn schedule_once<T, M>( &self, delay: Duration, receiver: ActorRef<M>, sender: Sender, msg: T, ) -> Uuid
where T: Message + Into<M>, M: Message,

Source§

fn schedule_at_time<T, M>( &self, time: DateTime<Utc>, receiver: ActorRef<M>, sender: Sender, msg: T, ) -> Uuid
where T: Message + Into<M>, M: Message,

Source§

fn cancel_schedule(&self, id: Uuid)

Auto Trait Implementations§

§

impl<Msg> Freeze for Context<Msg>

§

impl<Msg> !RefUnwindSafe for Context<Msg>

§

impl<Msg> Send for Context<Msg>

§

impl<Msg> Sync for Context<Msg>

§

impl<Msg> Unpin for Context<Msg>

§

impl<Msg> !UnwindSafe for Context<Msg>

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

Source§

fn vzip(self) -> V