Struct anymap::raw::RawMap
[−]
[src]
pub struct RawMap<A: ?Sized + UncheckedAnyExt = Any> { /* fields omitted */ }
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.
Methods
impl<A: ?Sized + UncheckedAnyExt> RawMap<A>
[src]
fn new() -> RawMap<A>
Create an empty collection.
fn with_capacity(capacity: usize) -> RawMap<A>
Creates an empty collection with the given initial capacity.
fn capacity(&self) -> usize
Returns the number of elements the collection can hold without reallocating.
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
.
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.
fn len(&self) -> usize
Returns the number of items in the collection.
fn is_empty(&self) -> bool
Returns true if there are no items in the collection.
fn clear(&mut self)
Removes all items from the collection. Keeps the allocated memory for reuse.
impl<A: ?Sized + UncheckedAnyExt> RawMap<A>
[src]
fn iter(&self) -> Iter<A>
An iterator visiting all entries in arbitrary order.
Iterator element type is &Any
.
fn iter_mut(&mut self) -> IterMut<A>
An iterator visiting all entries in arbitrary order.
Iterator element type is &mut Any
.
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.
fn entry(&mut self, key: TypeId) -> Entry<A>
Gets the entry for the given type in the collection for in-place manipulation.
fn get<Q: ?Sized>(&self, k: &Q) -> Option<&A> where
TypeId: Borrow<Q>,
Q: Hash + Eq,
TypeId: Borrow<Q>,
Q: Hash + Eq,
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.
fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool where
TypeId: Borrow<Q>,
Q: Hash + Eq,
TypeId: Borrow<Q>,
Q: Hash + Eq,
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.
fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut A> where
TypeId: Borrow<Q>,
Q: Hash + Eq,
TypeId: Borrow<Q>,
Q: Hash + Eq,
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.
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.
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.
fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<Box<A>> where
TypeId: Borrow<Q>,
Q: Hash + Eq,
TypeId: Borrow<Q>,
Q: Hash + Eq,
Removes a key from the map, returning the value at the key if the key was previously in the map.
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.
Trait Implementations
impl<A: Debug + ?Sized + UncheckedAnyExt> Debug for RawMap<A>
[src]
impl<A: ?Sized + UncheckedAnyExt> Clone for RawMap<A> where
Box<A>: Clone,
[src]
Box<A>: Clone,
fn clone(&self) -> RawMap<A>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<A: ?Sized + UncheckedAnyExt> Default for RawMap<A>
[src]
impl<A: ?Sized + UncheckedAnyExt, Q> Index<Q> for RawMap<A> where
TypeId: Borrow<Q>,
Q: Eq + Hash,
[src]
TypeId: Borrow<Q>,
Q: Eq + Hash,
type Output = A
The returned type after indexing
fn index(&self, index: Q) -> &A
The method for the indexing (container[index]
) operation
impl<A: ?Sized + UncheckedAnyExt, Q> IndexMut<Q> for RawMap<A> where
TypeId: Borrow<Q>,
Q: Eq + Hash,
[src]
TypeId: Borrow<Q>,
Q: Eq + Hash,
fn index_mut(&mut self, index: Q) -> &mut A
The method for the mutable indexing (container[index]
) operation