TypeMap

Struct TypeMap 

Source
pub struct TypeMap { /* private fields */ }
Expand description

A map of type identifiers to type-erased values.

Implementations§

Source§

impl TypeMap

Source

pub fn insert_value<T: Any + Send + Sync>( &mut self, value: T, ) -> Result<Option<T>, BroomdogErr>

Insert a value into the type map.

Source

pub fn get_value<T: Any + Send + Sync>(&self) -> Result<Option<&T>, BroomdogErr>

Returns a reference to the value of the given parameterized type.

Source

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.

Source

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.

Source

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.

Source

pub fn is_unified(&self) -> bool

Return whether all values are unified.

Source

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.

Trait Implementations§

Source§

impl Debug for TypeMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TypeMap

Source§

fn default() -> TypeMap

Returns the “default value” for a type. Read more
Source§

impl Deref for TypeMap

Source§

type Target = HashMap<TypeKey, InnerLoan, BuildHasherDefault<FxHasher>>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for TypeMap

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.