pub struct Context<'ty, 'r> { /* private fields */ }Expand description
Re-export the main Context type.
Runtime context storing values by type.
The context can store owned values as well as borrowed references (immutable
or mutable). Values are keyed by TypeId using a specialized hasher for
fast lookups.
Implementations§
Source§impl<'ty, 'r> Context<'ty, 'r>
impl<'ty, 'r> Context<'ty, 'r>
Sourcepub fn insert_unchecked(&mut self, key: TypeId, data: Data<'ty, 'r>)
pub fn insert_unchecked(&mut self, key: TypeId, data: Data<'ty, 'r>)
Insert a value into the context without checking the type.
This is a low-level escape hatch for advanced use-cases.
Sourcepub fn insert_ref<T: ShareableTid<'ty>>(&mut self, value: &'r T)
pub fn insert_ref<T: ShareableTid<'ty>>(&mut self, value: &'r T)
Insert a borrowed value into the context.
Sourcepub fn insert_mut<T: ShareableTid<'ty>>(&mut self, value: &'r mut T)
pub fn insert_mut<T: ShareableTid<'ty>>(&mut self, value: &'r mut T)
Insert a mutable reference into the context.
Sourcepub fn insert<T: ShareableTid<'ty>>(&mut self, value: T)
pub fn insert<T: ShareableTid<'ty>>(&mut self, value: T)
Insert an owned value into the context.
Sourcepub fn get<'b, T: ShareableTid<'ty>>(&'b self) -> Option<&'b T>
pub fn get<'b, T: ShareableTid<'ty>>(&'b self) -> Option<&'b T>
Get a shared reference to a stored value by type.
Sourcepub fn get_mut<'b, T: ShareableTid<'ty>>(&'b mut self) -> Option<&'b mut T>
pub fn get_mut<'b, T: ShareableTid<'ty>>(&'b mut self) -> Option<&'b mut T>
Get a mutable reference to a stored value by type.
Sourcepub fn get_data<'b>(&'b self, id: &TypeId) -> Option<&'b Data<'ty, 'r>>
pub fn get_data<'b>(&'b self, id: &TypeId) -> Option<&'b Data<'ty, 'r>>
Get a stored Data by TypeId.
Sourcepub fn get_data_mut<'b>(
&'b mut self,
id: &TypeId,
) -> Option<&'b mut Data<'ty, 'r>>
pub fn get_data_mut<'b>( &'b mut self, id: &TypeId, ) -> Option<&'b mut Data<'ty, 'r>>
Get a mutable Data by TypeId.
Sourcepub fn get_disjoint_mut<'b, const N: usize>(
&'b mut self,
keys: [&TypeId; N],
) -> [Option<&'b mut Data<'ty, 'r>>; N]
pub fn get_disjoint_mut<'b, const N: usize>( &'b mut self, keys: [&TypeId; N], ) -> [Option<&'b mut Data<'ty, 'r>>; N]
Get multiple mutable Data entries by distinct TypeIds.
Sourcepub fn take<T: ShareableTid<'ty>>(&mut self) -> Option<T>
pub fn take<T: ShareableTid<'ty>>(&mut self) -> Option<T>
Remove an owned value from the context and return it.
Sourcepub fn remove<T: ShareableTid<'ty>>(&mut self) -> Option<Data<'ty, 'r>>
pub fn remove<T: ShareableTid<'ty>>(&mut self) -> Option<Data<'ty, 'r>>
Remove any stored value for the given type and return the raw Data.
Sourcepub fn contains<T: ShareableTid<'ty>>(&self) -> bool
pub fn contains<T: ShareableTid<'ty>>(&self) -> bool
Check if a value of a specific type is present.
Trait Implementations§
Auto Trait Implementations§
impl<'ty, 'r> Freeze for Context<'ty, 'r>
impl<'ty, 'r> !RefUnwindSafe for Context<'ty, 'r>
impl<'ty, 'r> Send for Context<'ty, 'r>
impl<'ty, 'r> Sync for Context<'ty, 'r>
impl<'ty, 'r> Unpin for Context<'ty, 'r>
impl<'ty, 'r> !UnwindSafe for Context<'ty, 'r>
Blanket Implementations§
Source§impl<T> AnyExt for T
impl<T> AnyExt for T
Source§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind referenceSource§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable referenceSource§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointerSource§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointer