pub struct ChildToken { /* private fields */ }Expand description
Child cancellation token that inherits from a parent.
Child tokens check both their local cancellation state and their parent’s state. This allows for hierarchical cancellation where a task can be cancelled independently or inherit cancellation from its parent workflow.
§Cancellation Logic
A child token is cancelled if:
- The parent token is cancelled, OR
- The child’s local cancel() method was called
§Example
ⓘ
let source = CancellationTokenSource::new();
let child = source.child_token();
// Child inherits parent cancellation
source.cancel();
assert!(child.is_cancelled());
// Or child can be cancelled independently
let source2 = CancellationTokenSource::new();
let child2 = source2.child_token();
child2.cancel();
assert!(child2.is_cancelled());
assert!(!source2.token().is_cancelled());Implementations§
Source§impl ChildToken
impl ChildToken
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true if either parent or local token is cancelled.
Checks both the parent token and local cancellation state.
§Example
ⓘ
let source = CancellationTokenSource::new();
let child = source.child_token();
assert!(!child.is_cancelled());
// Cancel parent
source.cancel();
assert!(child.is_cancelled());Sourcepub fn cancel(&self)
pub fn cancel(&self)
Cancels this child token locally.
Local cancellation does not affect the parent token or other children.
§Example
ⓘ
let source = CancellationTokenSource::new();
let child1 = source.child_token();
let child2 = source.child_token();
child1.cancel();
assert!(child1.is_cancelled());
assert!(!child2.is_cancelled()); // Other children unaffected
assert!(!source.token().is_cancelled()); // Parent unaffectedTrait Implementations§
Source§impl Clone for ChildToken
impl Clone for ChildToken
Source§fn clone(&self) -> ChildToken
fn clone(&self) -> ChildToken
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 moreAuto Trait Implementations§
impl Freeze for ChildToken
impl RefUnwindSafe for ChildToken
impl Send for ChildToken
impl Sync for ChildToken
impl Unpin for ChildToken
impl UnsafeUnpin for ChildToken
impl UnwindSafe for ChildToken
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