pub struct LocalContext { /* private fields */ }Expand description
Tracks the current execution context.
The context tracks the current app, all or some context_local! and TracingDispatcherContext.
Implementations§
Source§impl LocalContext
impl LocalContext
Sourcepub fn current_app() -> Option<AppId>
pub fn current_app() -> Option<AppId>
Get the ID of the app that owns the current context.
Sourcepub fn register_cleanup(cleanup: impl FnOnce(AppId) + Send + 'static)
pub fn register_cleanup(cleanup: impl FnOnce(AppId) + Send + 'static)
Register to run when the app deinits and all clones of the app context are dropped.
Sourcepub fn capture() -> Self
pub fn capture() -> Self
Capture a snapshot of the current context that can be restored in another thread to recreate the current context.
Context locals modified after this capture are not included in the capture.
This is equivalent to ``CaptureFilter::All`.
Sourcepub fn capture_filtered(filter: CaptureFilter) -> Self
pub fn capture_filtered(filter: CaptureFilter) -> Self
Capture a snapshot of the current context that only includes filter.
Sourcepub fn value_set(&self) -> ContextValueSet
pub fn value_set(&self) -> ContextValueSet
Collects a set of all the values in the context.
Sourcepub fn with_context<R>(&mut self, f: impl FnOnce() -> R) -> R
pub fn with_context<R>(&mut self, f: impl FnOnce() -> R) -> R
Calls f in the captured context.
Note that this fully replaces the parent context for the duration of the f call, see with_context_blend
for a blending alternative.
Sourcepub fn with_context_blend<R>(&mut self, over: bool, f: impl FnOnce() -> R) -> R
pub fn with_context_blend<R>(&mut self, over: bool, f: impl FnOnce() -> R) -> R
Calls f while all contextual values of self are set on the parent context.
Unlike with_context this does not remove values that are only set in the parent context, the
downside is that this call is more expensive.
If over is true all the values of self are set over the parent values, if false only
the values not already set in the parent are set.
Trait Implementations§
Source§impl Clone for LocalContext
impl Clone for LocalContext
Source§fn clone(&self) -> LocalContext
fn clone(&self) -> LocalContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LocalContext
impl Debug for LocalContext
Auto Trait Implementations§
impl Freeze for LocalContext
impl !RefUnwindSafe for LocalContext
impl Send for LocalContext
impl Sync for LocalContext
impl Unpin for LocalContext
impl !UnwindSafe for LocalContext
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
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>
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>
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