Struct anymap2::raw::RawMap [−][src]
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>ⓘ
[src]
An iterator visiting all entries in arbitrary order.
Iterator element type is &Any
.
pub fn iter_mut(&mut self) -> IterMut<'_, A>ⓘ
[src]
An iterator visiting all entries in arbitrary order.
Iterator element type is &mut Any
.
pub fn drain(&mut self) -> Drain<'_, 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]
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.
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool where
TypeId: Borrow<Q>,
Q: Hash + Eq,
[src]
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.
pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut A> where
TypeId: Borrow<Q>,
Q: Hash + Eq,
[src]
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.
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]
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: ?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]
Box<A>: Clone,
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]
TypeId: Borrow<Q>,
Q: Eq + Hash,
impl<A: ?Sized + UncheckedAnyExt, Q> IndexMut<Q> for RawMap<A> where
TypeId: Borrow<Q>,
Q: Eq + Hash,
[src]
TypeId: Borrow<Q>,
Q: Eq + Hash,
impl<A: ?Sized + UncheckedAnyExt> IntoIterator for RawMap<A>
[src]
Auto Trait Implementations
impl<A: ?Sized> RefUnwindSafe for RawMap<A> where
A: RefUnwindSafe,
A: RefUnwindSafe,
impl<A: ?Sized> Send for RawMap<A> where
A: Send,
A: Send,
impl<A: ?Sized> Sync for RawMap<A> where
A: Sync,
A: Sync,
impl<A: ?Sized> Unpin for RawMap<A>
impl<A: ?Sized> UnwindSafe for RawMap<A> where
A: UnwindSafe,
A: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: Any,
[src]
T: Any,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> CloneAny for T where
T: Any + Clone,
[src]
T: Any + Clone,
impl<T> CloneAnySend for T where
T: Any + Send + Clone,
[src]
T: Any + Send + Clone,
impl<T> CloneAnySendSync for T where
T: Any + Send + Sync + Clone,
[src]
T: Any + Send + Sync + Clone,
impl<T> CloneAnySync for T where
T: Any + Sync + Clone,
[src]
T: Any + Sync + Clone,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,