anymap2::raw

Struct 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,

Source§

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>

Source§

type IntoIter = IntoIter<A>

Which kind of iterator are we turning this into?
Source§

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§

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

🔬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,

Source§

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>,

Source§

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>,

Source§

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,