Struct zng_app_context::LocalContext
source · 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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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