pub struct TypeMap { /* private fields */ }Expand description
A map of type identifiers to type-erased values.
Implementations§
Source§impl TypeMap
impl TypeMap
Sourcepub fn insert_value<T: Any + Send + Sync>(
&mut self,
value: T,
) -> Result<Option<T>, BroomdogErr>
pub fn insert_value<T: Any + Send + Sync>( &mut self, value: T, ) -> Result<Option<T>, BroomdogErr>
Insert a value into the type map.
Sourcepub fn get_value<T: Any + Send + Sync>(&self) -> Result<Option<&T>, BroomdogErr>
pub fn get_value<T: Any + Send + Sync>(&self) -> Result<Option<&T>, BroomdogErr>
Returns a reference to the value of the given parameterized type.
Sourcepub fn get_value_mut<T: Any + Send + Sync>(
&mut self,
) -> Result<Option<&mut T>, BroomdogErr>
pub fn get_value_mut<T: Any + Send + Sync>( &mut self, ) -> Result<Option<&mut T>, BroomdogErr>
Returns a mutable reference to the value of the given parameterized type.
Sourcepub fn loan(&mut self, key: TypeKey) -> Result<Option<Loan>, BroomdogErr>
pub fn loan(&mut self, key: TypeKey) -> Result<Option<Loan>, BroomdogErr>
Indefinitely loans the typed value for sharing across threads.
Returns an error if the typed value is already exclusively loaned.
TypeMap::unify should be called before any call to
TypeMap::get_value or TypeMap::get_value_mut, or those will
result in an error.
Additionally, if TypeMap::loan_mut is called before the returned
Loan is dropped, that call will err.
Sourcepub fn loan_mut(&mut self, key: TypeKey) -> Result<Option<LoanMut>, BroomdogErr>
pub fn loan_mut(&mut self, key: TypeKey) -> Result<Option<LoanMut>, BroomdogErr>
Indefinitely loans the typed value for exclusive mutation.
TypeMap::unify should be called before any call to
TypeMap::get_value or TypeMap::get_value_mut, or those will
result in an error.
Additionally, if TypeMap::loan or TypeMap::loan_mut are called
again before the returned LoanMut is dropped, those calls will err.
Sourcepub fn is_unified(&self) -> bool
pub fn is_unified(&self) -> bool
Return whether all values are unified.
Sourcepub fn unify(&mut self) -> Result<(), BroomdogErr>
pub fn unify(&mut self) -> Result<(), BroomdogErr>
Attempts to unify the map, converting all loaned values back into owned values.
This must be called before using TypeMap::get_value or
TypeMap::get_value_mut.
If the map fails to unify, the map will remain in a consistent state.