Type Alias freya_native_core::SendAnyMap

source ·
pub type SendAnyMap = Map<dyn Any + Send + Sync + 'static>;
Expand description

A map of types that can be sent between threads

Aliased Type§

struct SendAnyMap { /* private fields */ }

Implementations

§

impl<A> Map<A>
where A: Downcast + ?Sized,

pub fn new() -> Map<A>

Create an empty collection.

pub fn with_capacity(capacity: usize) -> Map<A>

Creates an empty collection with the given initial capacity.

pub fn capacity(&self) -> usize

Returns the number of elements the collection can hold without reallocating.

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements to be inserted in the collection. The collection may reserve more space to avoid frequent reallocations.

§Panics

Panics if the new allocation size overflows usize.

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the collection as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.

pub fn len(&self) -> usize

Returns the number of items in the collection.

pub fn is_empty(&self) -> bool

Returns true if there are no items in the collection.

pub fn clear(&mut self)

Removes all items from the collection. Keeps the allocated memory for reuse.

pub fn get<T>(&self) -> Option<&T>
where T: IntoBox<A>,

Returns a reference to the value stored in the collection for the type T, if it exists.

pub fn get_mut<T>(&mut self) -> Option<&mut T>
where T: IntoBox<A>,

Returns a mutable reference to the value stored in the collection for the type T, if it exists.

pub fn insert<T>(&mut self, value: T) -> Option<T>
where T: IntoBox<A>,

Sets the value stored in the collection for the type T. If the collection already had a value of type T, that value is returned. Otherwise, None is returned.

pub fn remove<T>(&mut self) -> Option<T>
where T: IntoBox<A>,

Removes the T value from the collection, returning it if there was one or None if there was not.

pub fn contains<T>(&self) -> bool
where T: IntoBox<A>,

Returns true if the collection contains a value of type T.

pub fn entry<T>(&mut self) -> Entry<'_, A, T>
where T: IntoBox<A>,

Gets the entry for the given type in the collection for in-place manipulation

pub fn as_raw( &self, ) -> &HashMap<TypeId, Box<A>, BuildHasherDefault<TypeIdHasher>>

Get access to the raw hash map that backs this.

This will seldom be useful, but it’s conceivable that you could wish to iterate over all the items in the collection, and this lets you do that.

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

Get mutable access to the raw hash map that backs this.

This will seldom be useful, but it’s conceivable that you could wish to iterate over all the items in the collection mutably, or drain or something, or possibly even batch insert, and this lets you do that.

§Safety

If you insert any values to the raw map, the key (a TypeId) must match the value’s type, or undefined behaviour will occur when you access those values.

(Removing entries is perfectly safe.)

pub fn into_raw( self, ) -> HashMap<TypeId, Box<A>, BuildHasherDefault<TypeIdHasher>>

Convert this into the raw hash map that backs this.

This will seldom be useful, but it’s conceivable that you could wish to consume all the items in the collection and do something with some or all of them, and this lets you do that, without the unsafe that .as_raw_mut().drain() would require.

pub unsafe fn from_raw( raw: HashMap<TypeId, Box<A>, BuildHasherDefault<TypeIdHasher>>, ) -> Map<A>

Construct a map from a collection of raw values.

You know what? I can’t immediately think of any legitimate use for this, especially because of the requirement of the BuildHasherDefault<TypeIdHasher> generic in the map.

Perhaps this will be most practical as unsafe { Map::from_raw(iter.collect()) }, iter being an iterator over (TypeId, Box<A>) pairs. Eh, this method provides symmetry with into_raw, so I don’t care if literally no one ever uses it. I’m not even going to write a test for it, it’s so trivial.

§Safety

For all entries in the raw map, the key (a TypeId) must match the value’s type, or undefined behaviour will occur when you access that entry.

Trait Implementations

§

impl<A> Clone for Map<A>
where A: Downcast + ?Sized, Box<A>: Clone,

§

fn clone(&self) -> Map<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
§

impl<A> Debug for Map<A>
where A: Debug + Downcast + ?Sized,

§

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

Formats the value using the given formatter. Read more
§

impl<A> Default for Map<A>
where A: Downcast + ?Sized,

§

fn default() -> Map<A>

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

impl<A> Extend<Box<A>> for Map<A>
where A: Downcast + ?Sized,

§

fn extend<T>(&mut self, iter: T)
where T: IntoIterator<Item = Box<A>>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more