pub trait LogContextExt: Sized + Sealed {
// Required method
fn in_scope<R>(self, f: impl FnOnce() -> R) -> R;
}Expand description
Extension trait for LogContext to run code within a temporary logging scope.
This trait provides ergonomic, method-style access to LogScope::in_scope.
Required Methods§
Sourcefn in_scope<R>(self, f: impl FnOnce() -> R) -> R
fn in_scope<R>(self, f: impl FnOnce() -> R) -> R
Enters this context, runs a closure, and exits the scope automatically.
This is equivalent to calling LogScope::in_scope with self.
§Examples
use context_logger::{LogContext, LogContextExt as _};
let result = LogContext::new()
.with_local_record("request_id", "req-123")
.in_scope(|| 40 + 2);
assert_eq!(result, 42);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".