pub struct RawMap<A: ?Sized + UncheckedAnyExt = dyn Any> { /* private fields */ }
Expand description
The raw, underlying form of a Map
.
At its essence, this is a wrapper around HashMap<TypeId, Box<Any>>
, with
the portions that would be memory-unsafe removed or marked unsafe. Normal
people are expected to use the safe Map
interface instead, but there is
the occasional use for this such as iteration over the contents of an Map
.
However, because you will then be dealing with Any
trait objects, it
doesn’t tend to be so very useful. Still, if you need it, it’s here.
Implementations§
Source§impl<A: ?Sized + UncheckedAnyExt> RawMap<A>
impl<A: ?Sized + UncheckedAnyExt> RawMap<A>
Sourcepub fn with_capacity(capacity: usize) -> RawMap<A>
pub fn with_capacity(capacity: usize) -> RawMap<A>
Creates an empty collection with the given initial capacity.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the collection can hold without reallocating.
Sourcepub 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
.
Sourcepub 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.
Source§impl<A: ?Sized + UncheckedAnyExt> RawMap<A>
impl<A: ?Sized + UncheckedAnyExt> RawMap<A>
Sourcepub fn iter(&self) -> Iter<'_, A> ⓘ
pub fn iter(&self) -> Iter<'_, A> ⓘ
An iterator visiting all entries in arbitrary order.
Iterator element type is &Any
.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, A> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, A> ⓘ
An iterator visiting all entries in arbitrary order.
Iterator element type is &mut Any
.
Sourcepub fn drain(&mut self) -> Drain<'_, A> ⓘ
pub fn drain(&mut self) -> Drain<'_, A> ⓘ
Clears the map, returning all items as an iterator.
Iterator element type is Box<Any>
.
Keeps the allocated memory for reuse.
Sourcepub fn entry(&mut self, key: TypeId) -> Entry<'_, A>
pub fn entry(&mut self, key: TypeId) -> Entry<'_, A>
Gets the entry for the given type in the collection for in-place manipulation.
Sourcepub fn get<Q>(&self, k: &Q) -> Option<&A>
pub fn get<Q>(&self, k: &Q) -> Option<&A>
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but Hash
and
Eq
on the borrowed form must match those for the key type.
Sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
pub fn contains_key<Q>(&self, k: &Q) -> bool
Returns true if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type, but Hash
and
Eq
on the borrowed form must match those for the key type.
Sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut A>
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut A>
Returns a mutable reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but Hash
and
Eq
on the borrowed form must match those for the key type.
Sourcepub unsafe fn insert(&mut self, key: TypeId, value: Box<A>) -> Option<Box<A>>
pub unsafe fn insert(&mut self, key: TypeId, value: Box<A>) -> Option<Box<A>>
Inserts a key-value pair from the map. If the key already had a value present in the map, that value is returned. Otherwise, None is returned.
§Safety
It is the caller’s responsibility to ensure that the key corresponds with the type ID of the value. If they do not, memory safety may be violated.