Struct anymap2::raw::RawMap

source ·
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>

source

pub fn new() -> RawMap<A>

Create an empty collection.

source

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

Creates an empty collection with the given initial capacity.

source

pub fn capacity(&self) -> usize

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

source

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.

source

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

pub fn len(&self) -> usize

Returns the number of items in the collection.

source

pub fn is_empty(&self) -> bool

Returns true if there are no items in the collection.

source

pub fn clear(&mut self)

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

source§

impl<A: ?Sized + UncheckedAnyExt> RawMap<A>

source

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

An iterator visiting all entries in arbitrary order.

Iterator element type is &Any.

source

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

An iterator visiting all entries in arbitrary order.

Iterator element type is &mut Any.

source

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.

source

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

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

source

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

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.

source

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

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.

source

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

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.

source

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.

source

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

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§

source§

impl<A: ?Sized + UncheckedAnyExt> AsMut<RawMap<A>> for Map<A>

source§

fn as_mut(&mut self) -> &mut RawMap<A>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

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

source§

fn as_ref(&self) -> &RawMap<A>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<A: ?Sized + UncheckedAnyExt> Clone for RawMap<A>
where Box<A>: Clone,

source§

fn clone(&self) -> RawMap<A>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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

source§

fn default() -> RawMap<A>

Returns the “default value” for a type. Read more
source§

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

source§

fn from(map: Map<A>) -> Self

Converts to this type from the input type.
source§

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

§

type Output = A

The returned type after indexing.
source§

fn index(&self, index: Q) -> &A

Performs the indexing (container[index]) operation. Read more
source§

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

source§

fn index_mut(&mut self, index: Q) -> &mut A

Performs the mutable indexing (container[index]) operation. Read more
source§

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

§

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.
source§

fn into_iter(self) -> IntoIter<A>

Creates an iterator from a value. Read more

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>
where A: Send + ?Sized,

§

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

§

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

§

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

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Any for T
where T: Any,

source§

impl<T> CloneAny for T
where T: Any + Clone,

source§

impl<T> CloneAnySend for T
where T: Any + Send + Clone,

source§

impl<T> CloneAnySendSync for T
where T: Any + Send + Sync + Clone,

source§

impl<T> CloneAnySync for T
where T: Any + Sync + Clone,