pub struct ContextCell<T> { /* private fields */ }Expand description
A thread-local cell storing a raw pointer to the current wide event.
This type provides safe methods for setting, getting, and saving/restoring the pointer, which is used by the generated guard to manage nested scopes.
§Safety Invariants
The raw pointer stored in this cell is sound because:
- The guard owns the event. The
WideEvent<K>is a field of the guard, which is on the stack (or in thescope()future’s state). The guard outlives any code that callscurrent()within the same scope. - Set on creation, cleared on drop. The guard’s
newsets the pointer; itsDroprestores the previous pointer (or null) before the innerScopedGuard::Dropruns. - Nested scopes save/restore the previous pointer via
replaceand theprev_ptrfield on the guard. - No cross-thread access.
thread_local!means each thread has its own cell. For async,tokio::task_local!moves with the task across threads.
The &'static lifetime returned by accessors is a “valid for the duration
of the guard” lifetime — the standard pattern used by thread_local
accessors (e.g., tracing’s Span::current()).
Implementations§
Trait Implementations§
Source§impl<T> Default for ContextCell<T>
impl<T> Default for ContextCell<T>
impl<T> Send for ContextCell<T>
impl<T> Sync for ContextCell<T>
Auto Trait Implementations§
impl<T> !Freeze for ContextCell<T>
impl<T> !RefUnwindSafe for ContextCell<T>
impl<T> Unpin for ContextCell<T>
impl<T> UnsafeUnpin for ContextCell<T>
impl<T> UnwindSafe for ContextCell<T>where
T: RefUnwindSafe,
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