pub struct ContextGuard<T, S, C>{ /* private fields */ }Expand description
Context guard that manages thread-local or scoped context
This is a specialized guard for managing context that needs to be set and cleared in a scoped manner.
Implementations§
Source§impl<T, S, C> ContextGuard<T, S, C>
impl<T, S, C> ContextGuard<T, S, C>
Sourcepub fn new(context: T, setter: S, clearer: C) -> Self
pub fn new(context: T, setter: S, clearer: C) -> Self
Create a new context guard
§Arguments
context: The context value to managesetter: Function to set the contextclearer: Function to clear the context
§Example
use foundation_utils::raii::ContextGuard;
let _guard = ContextGuard::new(
"my_context",
|ctx| println!("set: {}", ctx),
|| println!("cleared"),
);
// Context is automatically cleared when guard dropsTrait Implementations§
Auto Trait Implementations§
impl<T, S, C> Freeze for ContextGuard<T, S, C>
impl<T, S, C> RefUnwindSafe for ContextGuard<T, S, C>
impl<T, S, C> Send for ContextGuard<T, S, C>
impl<T, S, C> Sync for ContextGuard<T, S, C>
impl<T, S, C> Unpin for ContextGuard<T, S, C>
impl<T, S, C> UnsafeUnpin for ContextGuard<T, S, C>
impl<T, S, C> UnwindSafe for ContextGuard<T, S, C>
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