TypeIdMapExt

Trait TypeIdMapExt 

Source
pub trait TypeIdMapExt<V> {
    // Required methods
    fn insert_type<T>(&mut self, v: V) -> Option<V>
       where T: 'static + ?Sized;
    fn get_type<T>(&self) -> Option<&V>
       where T: 'static + ?Sized;
    fn get_type_mut<T>(&mut self) -> Option<&mut V>
       where T: 'static + ?Sized;
    fn remove_type<T>(&mut self) -> Option<V>
       where T: 'static + ?Sized;
    fn entry_type<T>(&mut self) -> Entry<'_, TypeId, V, NoOpHash>
       where T: 'static + ?Sized;
}
Expand description

Extension trait to make use of TypeIdMap more ergonomic.

Each function on this trait is a trivial wrapper for a function on HashMap, replacing a TypeId key with a generic parameter T.

§Examples

use bevy_utils::TypeIdMapExt;

struct MyType;

// Using the built-in `HashMap` functions requires manually looking up `TypeId`s.
let mut map = TypeIdMap::default();
map.insert(TypeId::of::<MyType>(), 7);
assert_eq!(map.get(&TypeId::of::<MyType>()), Some(&7));

// Using `TypeIdMapExt` functions does the lookup for you.
map.insert_type::<MyType>(7);
assert_eq!(map.get_type::<MyType>(), Some(&7));

Required Methods§

Source

fn insert_type<T>(&mut self, v: V) -> Option<V>
where T: 'static + ?Sized,

Inserts a value for the type T.

If the map did not previously contain this key then None is returned, otherwise the value for this key is updated and the old value returned.

Source

fn get_type<T>(&self) -> Option<&V>
where T: 'static + ?Sized,

Returns a reference to the value for type T, if one exists.

Source

fn get_type_mut<T>(&mut self) -> Option<&mut V>
where T: 'static + ?Sized,

Returns a mutable reference to the value for type T, if one exists.

Source

fn remove_type<T>(&mut self) -> Option<V>
where T: 'static + ?Sized,

Removes type T from the map, returning the value for this key if it was previously present.

Source

fn entry_type<T>(&mut self) -> Entry<'_, TypeId, V, NoOpHash>
where T: 'static + ?Sized,

Gets the type T’s entry in the map for in-place manipulation.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§