Skip to main content

Context

Struct Context 

Source
pub struct Context<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 using a dereference to BareContext.

A time-based deadline for receiving a message can be set using Self::set_deadline() and friends.

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

Methods from Deref<Target = BareContext<M>>§

Source

pub fn subscribe<E: Event + Into<M>>(&self)

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.

Source

pub fn subscribe_and_receive_latest<E: Event + Into<M>>( &self, ) -> Result<(), SendError>

Subscribe current actor to event of type E and send the last cached event to it. 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.

This method may fail if it is not possible to send the latest event. In this case it is guaranteed that the subscription did not take place. You can safely try again.

Trait Implementations§

Source§

impl<M> Deref for Context<M>

Source§

type Target = BareContext<M>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &BareContext<M>

Dereferences the value.

Auto Trait Implementations§

§

impl<M> Freeze for Context<M>

§

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 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.