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,
impl<A> Map<A>where
A: Downcast + ?Sized,
pub fn new() -> Map<A>
pub fn new() -> Map<A>
Create an empty collection.
pub fn with_capacity(capacity: usize) -> Map<A>
pub fn with_capacity(capacity: usize) -> Map<A>
Creates an empty collection with the given initial capacity.
pub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the collection can hold without reallocating.
pub fn reserve(&mut self, additional: usize)
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)
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 clear(&mut self)
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>,
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>,
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>,
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>,
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) -> boolwhere
T: IntoBox<A>,
pub fn contains<T>(&self) -> boolwhere
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>,
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>>
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>>
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>>
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>
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> Extend<Box<A>> for Map<A>where
A: Downcast + ?Sized,
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>>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = Box<A>>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)