Struct TypeMap

Source
pub struct TypeMap<A = dyn UnsafeAny>
where A: UnsafeAnyExt + ?Sized,
{ /* private fields */ }
Expand description

A map keyed by types.

Can contain one value of any type for each key type, as defined by the Assoc trait.

You usually do not need to worry about the A type parameter, but it can be used to add bounds to the possible value types that can be stored in this map. Usually, you are looking for ShareMap, which is Send + Sync.

Implementations§

Source§

impl TypeMap

Source

pub fn new() -> TypeMap

Create a new, empty TypeMap.

Source§

impl<A: UnsafeAnyExt + ?Sized> TypeMap<A>

Source

pub fn custom() -> TypeMap<A>

Create a new, empty TypeMap.

Can be used with any A parameter; new is specialized to get around the required type annotations when using this function.

Source

pub fn insert<K: Key>(&mut self, val: K::Value) -> Option<K::Value>
where K::Value: Any + Implements<A>,

Insert a value into the map with a specified key type.

Source

pub fn get<K: Key>(&self) -> Option<&K::Value>
where K::Value: Any + Implements<A>,

Find a value in the map and get a reference to it.

Source

pub fn get_mut<K: Key>(&mut self) -> Option<&mut K::Value>
where K::Value: Any + Implements<A>,

Find a value in the map and get a mutable reference to it.

Source

pub fn contains<K: Key>(&self) -> bool

Check if a key has an associated value stored in the map.

Source

pub fn remove<K: Key>(&mut self) -> Option<K::Value>
where K::Value: Any + Implements<A>,

Remove a value from the map.

Returns true if a value was removed.

Source

pub fn entry<'a, K: Key>(&'a mut self) -> Entry<'a, K, A>
where K::Value: Any + Implements<A>,

Get the given key’s corresponding entry in the map for in-place manipulation.

Source

pub unsafe fn data(&self) -> &HashMap<TypeId, Box<A>>

Read the underlying HashMap

Source

pub unsafe fn data_mut(&mut self) -> &mut HashMap<TypeId, Box<A>>

Get a mutable reference to the underlying HashMap

Source

pub fn len(&self) -> usize

Get the number of values stored in the map.

Source

pub fn is_empty(&self) -> bool

Return true if the map contains no values.

Source

pub fn clear(&mut self)

Remove all entries from the map.

Trait Implementations§

Source§

impl<A> Clone for TypeMap<A>
where A: UnsafeAnyExt + ?Sized, Box<A>: Clone,

Source§

fn clone(&self) -> TypeMap<A>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A> Debug for TypeMap<A>
where A: UnsafeAnyExt + Debug + ?Sized,

Source§

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

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

impl<A> Default for TypeMap<A>
where A: UnsafeAnyExt + Default + ?Sized,

Source§

fn default() -> TypeMap<A>

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

Auto Trait Implementations§

§

impl<A> Freeze for TypeMap<A>
where A: ?Sized,

§

impl<A> RefUnwindSafe for TypeMap<A>
where A: RefUnwindSafe + ?Sized,

§

impl<A> Send for TypeMap<A>
where A: Send + ?Sized,

§

impl<A> Sync for TypeMap<A>
where A: Sync + ?Sized,

§

impl<A> Unpin for TypeMap<A>
where A: ?Sized,

§

impl<A> UnwindSafe for TypeMap<A>
where A: UnwindSafe + ?Sized,

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> CloneAny for T
where T: Any + Clone,

Source§

fn clone_any(&self) -> Box<dyn CloneAny>

Source§

fn clone_any_send(&self) -> Box<dyn CloneAny + Send>
where T: Send,

Source§

fn clone_any_sync(&self) -> Box<dyn CloneAny + Sync>
where T: Sync,

Source§

fn clone_any_send_sync(&self) -> Box<dyn CloneAny + Sync + Send>
where T: Send + Sync,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DebugAny for T
where T: Any + Debug,

Source§

impl<T> UnsafeAny for T
where T: Any,