Skip to main content

Context

Struct Context 

Source
pub struct Context<M: Message, L = M> {
    pub id: ActorId,
    pub episode: Uuid,
    /* private fields */
}
Expand description

The ways out of an actor: what a Behavior may do besides answer.

A behavior owns one of these, and the actor keeps the mailbox, so messages reach the behavior one step at a time.

L is what this actor logs. It defaults to the message type, which is what most actors log.

Fields§

§id: ActorId

This actor’s name, as the other actors know it.

§episode: Uuid

The episode this actor is in, stamped on everything it logs.

Implementations§

Source§

impl<M: Message, L> Context<M, L>

Source

pub fn log(&self, payload: L)

Log payload as an event stamped now. The event reaches the log when this actor holds a logger and the log is listening; otherwise it is dropped, and the actor carries on either way.

Source

pub fn send(&self, message: M, to: HashSet<ActorId>) -> Result<()>

Send the statement message to every actor in to. An actor that has already stopped is skipped. An actor may send to itself: the message waits in its own mailbox for the current step to finish.

§Errors

Fails before anything is sent when to names an actor outside those this one may send to.

Source

pub async fn request( &self, message: M, to: HashSet<ActorId>, ) -> Result<HashMap<ActorId, Vec<M>>>

Ask every actor in to the same thing and collect their replies. A recipient that has stopped, before or after receiving the request, is left out of the result.

§Errors

Fails before anything is sent when to names an actor outside those this one may send to, or names this actor itself, which is busy with this very step.

Source

pub fn stop(&self, who: &ActorId) -> Result<()>

Stop another actor at once, wherever it is in its step.

§Errors

Fails when who is outside the actors this one may shut down.

Source

pub fn shutdown(&self)

Shut this actor down. The step that calls this is abandoned at its next await, so a behavior with last words says them first. The actor then stops, leaving whatever is in its mailbox there.

Auto Trait Implementations§

§

impl<M, L> Freeze for Context<M, L>

§

impl<M, L> RefUnwindSafe for Context<M, L>

§

impl<M, L> Send for Context<M, L>

§

impl<M, L> Sync for Context<M, L>

§

impl<M, L> Unpin for Context<M, L>

§

impl<M, L> UnsafeUnpin for Context<M, L>

§

impl<M, L> UnwindSafe for Context<M, L>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.