pub struct CancelToken { /* private fields */ }Expand description
A cancellation token that can be shared across tasks. When cancelled, it will cancel all linked child tasks/tokens. Thread-safe and can be cloned.
Implementations§
Source§impl CancelToken
impl CancelToken
Sourcepub fn new() -> CancelToken
pub fn new() -> CancelToken
Create a new cancellation token that is not cancelled and has no children.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if this token has been cancelled. Thread-safe.
Sourcepub fn link<T>(&self, child: T)where
T: Cancellable + 'static,
pub fn link<T>(&self, child: T)where
T: Cancellable + 'static,
Attach a child task/token to be cancelled when this token is cancelled. If already cancelled, child is cancelled immediately.
Sourcepub fn into_linked<T>(&self) -> T
pub fn into_linked<T>(&self) -> T
Create a new cancellable task/token of type T, link it to this token, and return it. See Self::link for more details.
Sourcepub fn linked<T>(&self, child: T) -> Twhere
T: Cancellable + Clone + 'static,
pub fn linked<T>(&self, child: T) -> Twhere
T: Cancellable + Clone + 'static,
Link an existing cancellable task/token of type T to this token and return it. See Self::link for more details.
Trait Implementations§
Source§impl Cancellable for CancelToken
impl Cancellable for CancelToken
Source§impl Clone for CancelToken
impl Clone for CancelToken
Source§fn clone(&self) -> CancelToken
fn clone(&self) -> CancelToken
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for CancelToken
impl Default for CancelToken
Source§fn default() -> CancelToken
fn default() -> CancelToken
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CancelToken
impl RefUnwindSafe for CancelToken
impl Send for CancelToken
impl Sync for CancelToken
impl Unpin for CancelToken
impl UnwindSafe for CancelToken
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more