pub struct CancelScope { /* private fields */ }Expand description
A cancellation scope owned by a subsystem.
new is the canonical replacement for the legacy
cancel.unwrap_or_default() fallback — the Option<CancelToken> parent picks
the branch:
- composed (
Some(parent)): the scope’s token is a child of the parent, so a parent/master cancel reaches this subtree. - standalone (
None): the scope’s token is itself a fresh root (CancelToken::root); nothing above can cancel it.
Either way, the inner children handed out by token
derive from one node, and cancel cancels exactly that
subtree. Drop is passive: dropping a scope does not cancel its subtree;
teardown is an explicit cancel() (so a composed scope never cancels a token
it was handed from above).
Implementations§
Source§impl CancelScope
impl CancelScope
Sourcepub fn new(parent: Option<CancelToken>) -> Self
pub fn new(parent: Option<CancelToken>) -> Self
Build a scope from an optional parent token (the composed/standalone
seam). This is a domain constructor, not a generic From conversion: the
branch on parent decides ownership of the subtree root.
pub fn is_cancelled(&self) -> bool
Sourcepub fn token(&self) -> CancelToken
pub fn token(&self) -> CancelToken
The scope’s token. Clone it for the subsystem’s own subtree (.child()
for per-task/per-fetch tokens).