pub struct RwContext(/* private fields */);Expand description
Thread-safe context for storing request-scoped data.
RwContext wraps a Context in Arc<RwLock<_>> for safe concurrent access.
It can be cloned cheaply and shared across async tasks.
§Example
ⓘ
use evento::context::RwContext;
let ctx = RwContext::new();
// Insert data (acquires write lock)
ctx.insert(42u32);
// Get data (acquires read lock, clones the value)
let value: Option<u32> = ctx.get();
// Extract panics if not found (useful for required dependencies)
let value: u32 = ctx.extract();§Panics
Methods will panic if the internal RwLock is poisoned.
Implementations§
Source§impl RwContext
impl RwContext
Sourcepub fn insert<T: Send + Sync + 'static>(&self, val: T) -> Option<T>
pub fn insert<T: Send + Sync + 'static>(&self, val: T) -> Option<T>
Insert an item into the map.
If an item of this type was already stored, it will be replaced and returned.
Sourcepub fn extract<T: Clone + 'static>(&self) -> T
pub fn extract<T: Clone + 'static>(&self) -> T
Get a clone of an item of a given type, panics if not found.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RwContext
impl RefUnwindSafe for RwContext
impl Send for RwContext
impl Sync for RwContext
impl Unpin for RwContext
impl UnwindSafe for RwContext
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