pub struct Context<S: Service<Context = Self>> { /* private fields */ }Expand description
A service context.
Any service that is spawned onto a Runtime needs to have this type as context.
Implementations§
Source§impl<S: Service<Context = Self>> Context<S>
impl<S: Service<Context = Self>> Context<S>
Sourcepub fn this(&self) -> Addr<S>
pub fn this(&self) -> Addr<S>
Get the address of this service.
Beware that if you use this to send a message to yourself (with Addr::send), you will
encounter a deadlock because to handle a message you need send a message, which just makes
the message handler never finish.
Sourcepub fn spawn<F: Future + 'static>(&self, fut: F) -> JoinHandle<F::Output>
pub fn spawn<F: Future + 'static>(&self, fut: F) -> JoinHandle<F::Output>
Spawn a future onto the current arbiter.
Sourcepub async fn try_singleton<T: Service<Context = Context<T>> + Any>(
&self,
) -> Result<Addr<T>, SingletonError>
pub async fn try_singleton<T: Service<Context = Context<T>> + Any>( &self, ) -> Result<Addr<T>, SingletonError>
Try to retrieve the address of a singleton service T.
If there are more than one or no instances of T running,
this method will return a SingletonError.
Auto Trait Implementations§
impl<S> Freeze for Context<S>
impl<S> RefUnwindSafe for Context<S>where
S: RefUnwindSafe,
impl<S> Send for Context<S>where
S: Send,
impl<S> Sync for Context<S>where
S: Sync,
impl<S> Unpin for Context<S>where
S: Unpin,
impl<S> UnwindSafe for Context<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more