Struct anymap2::raw::RawMap[][src]

pub struct RawMap<A: ?Sized + UncheckedAnyExt = dyn 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.

Implementations

impl<A: ?Sized + UncheckedAnyExt> RawMap<A>[src]

pub fn new() -> RawMap<A>[src]

Create an empty collection.

pub fn with_capacity(capacity: usize) -> RawMap<A>[src]

Creates an empty collection with the given initial capacity.

pub fn capacity(&self) -> usize[src]

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

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

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)[src]

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[src]

Returns the number of items in the collection.

pub fn is_empty(&self) -> bool[src]

Returns true if there are no items in the collection.

pub fn clear(&mut self)[src]

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

impl<A: ?Sized + UncheckedAnyExt> RawMap<A>[src]

pub fn iter(&self) -> Iter<'_, A>

Notable traits for Iter<'a, A>

impl<'a, A: ?Sized + UncheckedAnyExt> Iterator for Iter<'a, A> type Item = &'a A;
[src]

An iterator visiting all entries in arbitrary order.

Iterator element type is &Any.

pub fn iter_mut(&mut self) -> IterMut<'_, A>

Notable traits for IterMut<'a, A>

impl<'a, A: ?Sized + UncheckedAnyExt> Iterator for IterMut<'a, A> type Item = &'a mut A;
[src]

An iterator visiting all entries in arbitrary order.

Iterator element type is &mut Any.

pub fn drain(&mut self) -> Drain<'_, A>

Notable traits for Drain<'a, A>

impl<'a, A: ?Sized + UncheckedAnyExt> Iterator for Drain<'a, A> type Item = Box<A>;
[src]

Clears the map, returning all items as an iterator.

Iterator element type is Box<Any>.

Keeps the allocated memory for reuse.

pub fn entry(&mut self, key: TypeId) -> Entry<'_, A>[src]

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

pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&A> where
    TypeId: Borrow<Q>,
    Q: Hash + Eq
[src]

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.

pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool where
    TypeId: Borrow<Q>,
    Q: Hash + Eq
[src]

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.

pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut A> where
    TypeId: Borrow<Q>,
    Q: Hash + Eq
[src]

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.

pub unsafe fn insert(&mut self, key: TypeId, value: Box<A>) -> Option<Box<A>>[src]

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.

pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<Box<A>> where
    TypeId: Borrow<Q>,
    Q: Hash + Eq
[src]

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: ?Sized + UncheckedAnyExt> AsMut<RawMap<A>> for Map<A>[src]

impl<A: ?Sized + UncheckedAnyExt> AsRef<RawMap<A>> for Map<A>[src]

impl<A: ?Sized + UncheckedAnyExt> Clone for RawMap<A> where
    Box<A>: Clone
[src]

impl<A: Debug + ?Sized + UncheckedAnyExt> Debug for RawMap<A>[src]

impl<A: ?Sized + UncheckedAnyExt> Default for RawMap<A>[src]

impl<A: ?Sized + UncheckedAnyExt> From<Map<A>> for RawMap<A>[src]

impl<A: ?Sized + UncheckedAnyExt, Q> Index<Q> for RawMap<A> where
    TypeId: Borrow<Q>,
    Q: Eq + Hash
[src]

type Output = A

The returned type after indexing.

impl<A: ?Sized + UncheckedAnyExt, Q> IndexMut<Q> for RawMap<A> where
    TypeId: Borrow<Q>,
    Q: Eq + Hash
[src]

impl<A: ?Sized + UncheckedAnyExt> IntoIterator for RawMap<A>[src]

type IntoIter = IntoIter<A>

Which kind of iterator are we turning this into?

type Item = Box<A>

The type of the elements being iterated over.

Auto Trait Implementations

impl<A: ?Sized> RefUnwindSafe for RawMap<A> where
    A: RefUnwindSafe

impl<A: ?Sized> Send for RawMap<A> where
    A: Send

impl<A: ?Sized> Sync for RawMap<A> where
    A: Sync

impl<A: ?Sized> Unpin for RawMap<A>

impl<A: ?Sized> UnwindSafe for RawMap<A> where
    A: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: Any
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CloneAny for T where
    T: Any + Clone
[src]

impl<T> CloneAnySend for T where
    T: Any + Send + Clone
[src]

impl<T> CloneAnySendSync for T where
    T: Any + Send + Sync + Clone
[src]

impl<T> CloneAnySync for T where
    T: Any + Sync + Clone
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.