Struct tonari_actor::Context

source ·
pub struct Context<M> {
    pub system_handle: SystemHandle,
    pub myself: Recipient<M>,
    /* private fields */
}
Expand description

An execution context for a specific actor. Specifically, this is useful for managing the lifecycle of itself (through the myself field) and other actors via the SystemHandle provided. A time-based deadline for receiving a message can be set using Self::set_deadline() and friends.

Fields§

§system_handle: SystemHandle§myself: Recipient<M>

Implementations§

source§

impl<M> Context<M>

source

pub fn deadline(&self) -> &Option<Instant>

Get the deadline previously set using Self::set_deadline() or Self::set_timeout(). The deadline is cleared just before Actor::deadline_passed() is called.

source

pub fn set_deadline(&mut self, deadline: Option<Instant>)

Schedule a future one-shot call to Actor::deadline_passed(), or cancel the schedule. A deadline in the past is considered to expire right in the next iteration (possibly after receiving new messages).

source

pub fn set_timeout(&mut self, timeout: Option<Duration>)

Schedule or cancel a call to Actor::deadline_passed() after timeout from now. Convenience variant of Self::set_deadline().

source

pub fn subscribe<E: Event + Into<M>>(&self)where M: 'static,

Subscribe current actor to event of type E. This is part of the event system. You don’t need to call this method to receive direct messages sent using Addr and Recipient.

Note that subscribing twice to the same event would result in duplicate events – no de-duplication of subscriptions is performed.

Auto Trait Implementations§

§

impl<M> !RefUnwindSafe for Context<M>

§

impl<M> Send for Context<M>

§

impl<M> Sync for Context<M>

§

impl<M> Unpin for Context<M>

§

impl<M> !UnwindSafe for Context<M>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.