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.
Trait Implementations§
Auto Trait Implementations§
impl<A> Freeze for RawMap<A>where
A: ?Sized,
impl<A> RefUnwindSafe for RawMap<A>where
A: RefUnwindSafe + ?Sized,
impl<A> Send for RawMap<A>
impl<A> Sync for RawMap<A>
impl<A> Unpin for RawMap<A>where
A: ?Sized,
impl<A> UnwindSafe for RawMap<A>where
A: UnwindSafe + ?Sized,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)