Struct rkyv::collections::hash_map::ArchivedHashMap
source · pub struct ArchivedHashMap<K, V> { /* private fields */ }
Expand description
An archived HashMap
.
Implementations§
source§impl<K, V> ArchivedHashMap<K, V>
impl<K, V> ArchivedHashMap<K, V>
sourcepub fn hasher(&self) -> SeaHasher
pub fn hasher(&self) -> SeaHasher
Gets the hasher for this hashmap. The hasher for all archived hashmaps is the same for reproducibility.
sourcepub fn get_key_value_pin<Q>(
self: Pin<&mut Self>,
k: &Q,
) -> Option<(&K, Pin<&mut V>)>
pub fn get_key_value_pin<Q>( self: Pin<&mut Self>, k: &Q, ) -> Option<(&K, Pin<&mut V>)>
Finds the mutable key-value entry for a key.
sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
pub fn contains_key<Q>(&self, k: &Q) -> bool
Returns whether a key is present in the hash map.
sourcepub fn get_with<Q: Hash + ?Sized, F: Fn(&K, &Q) -> bool>(
&self,
key: &Q,
comparison_predicate: F,
) -> Option<&V>
pub fn get_with<Q: Hash + ?Sized, F: Fn(&K, &Q) -> bool>( &self, key: &Q, comparison_predicate: F, ) -> Option<&V>
Gets the value associated with the given key, and matching the given predicate F
.
This method uses the hash of the given key and the provided comparison function to find a
matching element in the hash map. This is intended to be used when you are unable to
construct a key that fulfils the criteria of get
.
Note that hashes are not always guaranteed to match between Archived and non-archived
versions of the same struct. This is also the case for Archived types that are automatically
generated by #[derive(Archive)]
. You should ensure that the hashing method matches between
your types, otherwise this method might not return any value even though a value matching
comparison_predicate
exists.
§Examples
let your_hashmap: ArchivedHashMap<(ArchivedString, ArchivedString), ArchivedString> = get_your_hashmap();
let your_value = your_hashmap.get_with(
&("my", "key"),
|hashmap_key, your_key| &(hashmap_key.0.as_str(), hashmap_key.1.as_str()) == your_key
);
sourcepub fn get_pin<Q>(self: Pin<&mut Self>, k: &Q) -> Option<Pin<&mut V>>
pub fn get_pin<Q>(self: Pin<&mut Self>, k: &Q) -> Option<Pin<&mut V>>
Gets the mutable value associated with the given key.
sourcepub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
Gets an iterator over the key-value entries in the hash map.
sourcepub fn iter_pin(self: Pin<&mut Self>) -> IterPin<'_, K, V> ⓘ
pub fn iter_pin(self: Pin<&mut Self>) -> IterPin<'_, K, V> ⓘ
Gets an iterator over the mutable key-value entries in the hash map.
sourcepub fn values_pin(self: Pin<&mut Self>) -> ValuesPin<'_, K, V> ⓘ
pub fn values_pin(self: Pin<&mut Self>) -> ValuesPin<'_, K, V> ⓘ
Gets an iterator over the mutable values in the hash map.
sourcepub unsafe fn resolve_from_len(
len: usize,
pos: usize,
resolver: HashMapResolver,
out: *mut Self,
)
pub unsafe fn resolve_from_len( len: usize, pos: usize, resolver: HashMapResolver, out: *mut Self, )
Resolves an archived hash map from a given length and parameters.
§Safety
len
must be the number of elements that were serializedpos
must be the position ofout
within the archiveresolver
must be the result of serializing a hash map
source§impl<K, V> ArchivedHashMap<K, V>
impl<K, V> ArchivedHashMap<K, V>
sourcepub unsafe fn serialize_from_iter<'a, KU, VU, S, I>(
iter: I,
serializer: &mut S,
) -> Result<HashMapResolver, S::Error>where
KU: 'a + Serialize<S, Archived = K> + Hash + Eq,
VU: 'a + Serialize<S, Archived = V>,
S: Serializer + ScratchSpace + ?Sized,
I: ExactSizeIterator<Item = (&'a KU, &'a VU)>,
pub unsafe fn serialize_from_iter<'a, KU, VU, S, I>(
iter: I,
serializer: &mut S,
) -> Result<HashMapResolver, S::Error>where
KU: 'a + Serialize<S, Archived = K> + Hash + Eq,
VU: 'a + Serialize<S, Archived = V>,
S: Serializer + ScratchSpace + ?Sized,
I: ExactSizeIterator<Item = (&'a KU, &'a VU)>,
Serializes an iterator of key-value pairs as a hash map.
§Safety
The keys returned by the iterator must be unique.
Trait Implementations§
source§impl<K: Archive + Hash + Eq, V: Archive, D: Fallible + ?Sized, S: Default + BuildHasher> Deserialize<HashMap<K, V, S>, D> for ArchivedHashMap<K::Archived, V::Archived>
impl<K: Archive + Hash + Eq, V: Archive, D: Fallible + ?Sized, S: Default + BuildHasher> Deserialize<HashMap<K, V, S>, D> for ArchivedHashMap<K::Archived, V::Archived>
source§impl<K: Archive + Hash + Eq, V: Archive, D: Fallible + ?Sized, S: Default + BuildHasher> Deserialize<HashMap<K, V, S>, D> for ArchivedHashMap<K::Archived, V::Archived>
impl<K: Archive + Hash + Eq, V: Archive, D: Fallible + ?Sized, S: Default + BuildHasher> Deserialize<HashMap<K, V, S>, D> for ArchivedHashMap<K::Archived, V::Archived>
source§impl<K: Hash + Eq + Borrow<AK>, V, AK: Hash + Eq, AV: PartialEq<V>> PartialEq<ArchivedHashMap<AK, AV>> for HashMap<K, V>
impl<K: Hash + Eq + Borrow<AK>, V, AK: Hash + Eq, AV: PartialEq<V>> PartialEq<ArchivedHashMap<AK, AV>> for HashMap<K, V>
source§fn eq(&self, other: &ArchivedHashMap<AK, AV>) -> bool
fn eq(&self, other: &ArchivedHashMap<AK, AV>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<K: Hash + Eq + Borrow<AK>, V, AK: Hash + Eq, AV: PartialEq<V>> PartialEq<ArchivedHashMap<AK, AV>> for HashMap<K, V>
impl<K: Hash + Eq + Borrow<AK>, V, AK: Hash + Eq, AV: PartialEq<V>> PartialEq<ArchivedHashMap<AK, AV>> for HashMap<K, V>
source§fn eq(&self, other: &ArchivedHashMap<AK, AV>) -> bool
fn eq(&self, other: &ArchivedHashMap<AK, AV>) -> bool
self
and other
values to be equal, and is used
by ==
.