Handle

Struct Handle 

Source
pub struct Handle { /* private fields */ }
Expand description

A handle returned from constructing a new Context. Used to cancel the context. You can explicitly call cancel, or, you can simply drop the Handle to cancel the context.

It’s also used to spawn new contexts. This fits cleaner into Rusts ownership system. We can only create new receivers by asking for them from the underlying Sender. This also ensures that only the owner of the context handle can generate more contexts for its chidlren.

Implementations§

Source§

impl Handle

Source

pub fn cancel(self)

Cancels the Context, ensuring that done() returns immediately.

We only need to drop the handle, which will drop the sender. Doing so will close the channel, causing done() to immediately return.

Source

pub fn spawn_ctx(&mut self) -> Context

Will spawn a context identical to the context that was created along with this Handle. Used to generate more receivers for receiving a cancel signal from the parent.

Source

pub fn spawn_ref(&mut self) -> RefContext

Will spawn a RefContext identical to the RefContext that was created along with this Handle. If a Context was created with this handle, it will spawn a RefContext version of the original Context.

Auto Trait Implementations§

§

impl Freeze for Handle

§

impl !RefUnwindSafe for Handle

§

impl Send for Handle

§

impl Sync for Handle

§

impl Unpin for Handle

§

impl !UnwindSafe for Handle

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.