pub struct FzStringMap<K, V, BH = DefaultBuildHasher> { /* private fields */ }Expand description
A map optimized for fast read access with string keys.
A frozen collection differs from the traditional Rust collections, such as
HashMap and HashSet types in three
key ways. First, creating a frozen collection performs an analysis over the input data to
determine the best implementation strategy. Depending on the situation, this analysis is
performed at build time or runtime, and it can take a relatively long time when a collection is
very large. Second, once created, the keys in frozen collections are immutable. And third,
querying a frozen collection is typically considerably faster, which is the whole point.
This type requires that the keys
implement the Eq and Hash traits. This can frequently be achieved by
using #[derive(PartialEq, Eq, Hash)]. If you implement these yourself,
it is important that the following property holds:
k1 == k2 -> hash(k1) == hash(k2)In other words, if two keys are equal, their hashes must be equal. Violating this property is a logic error.
It is also a logic error for a key to be modified in such a way that the key’s
hash, as determined by the Hash trait, or its equality, as determined by
the Eq trait, changes while it is in the collection. This is normally only
possible through core::cell::Cell, core::cell::RefCell, global state, I/O,
or unsafe code.
The behavior resulting from either logic error can include panics, incorrect results, memory leaks, and non-termination.
Implementations§
Source§impl<'a, V> FzStringMap<&'a str, V, DefaultBuildHasher>
impl<'a, V> FzStringMap<&'a str, V, DefaultBuildHasher>
Sourcepub fn new_for_str(entries: Vec<(&'a str, V)>) -> Self
pub fn new_for_str(entries: Vec<(&'a str, V)>) -> Self
Creates a frozen map. If the input contains duplicate keys, the latter one in the input is used and all former ones are discarded.
Source§impl<'a, V, BH> FzStringMap<&'a str, V, BH>
impl<'a, V, BH> FzStringMap<&'a str, V, BH>
Sourcepub fn with_hasher_for_str(entries: Vec<(&'a str, V)>, bh: BH) -> Self
pub fn with_hasher_for_str(entries: Vec<(&'a str, V)>, bh: BH) -> Self
Creates a frozen map which uses the given hash builder to hash keys. If the input contains duplicate keys, the latter one in the input is used and all former ones are discarded.
Source§impl<V> FzStringMap<Box<str>, V, DefaultBuildHasher>
impl<V> FzStringMap<Box<str>, V, DefaultBuildHasher>
Source§impl<V, BH> FzStringMap<Box<str>, V, BH>
impl<V, BH> FzStringMap<Box<str>, V, BH>
Sourcepub fn with_hasher(entries: Vec<(impl AsRef<str>, V)>, bh: BH) -> Self
pub fn with_hasher(entries: Vec<(impl AsRef<str>, V)>, bh: BH) -> Self
Creates a frozen map which uses the given hash builder to hash keys. If the input contains duplicate keys, the latter one in the input is used and all former ones are discarded.
Source§impl<K, V, BH> FzStringMap<K, V, BH>
impl<K, V, BH> FzStringMap<K, V, BH>
Sourcepub fn get(&self, key: impl AsRef<str>) -> Option<&V>
pub fn get(&self, key: impl AsRef<str>) -> Option<&V>
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type.
Sourcepub fn get_mut(&mut self, key: impl AsRef<str>) -> Option<&mut V>
pub fn get_mut(&mut self, key: impl AsRef<str>) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type.
Sourcepub fn get_key_value(&self, key: impl AsRef<str>) -> Option<(&K, &V)>
pub fn get_key_value(&self, key: impl AsRef<str>) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
This is potentially useful:
-
for key types where non-identical keys can be considered equal;
-
for getting the &K stored key value from a borrowed &Q lookup key; or
-
for getting a reference to a key with the same lifetime as the collection.
-
The supplied 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.
Sourcepub fn contains_key(&self, key: impl AsRef<str>) -> bool
pub fn contains_key(&self, key: impl AsRef<str>) -> bool
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.
Sourcepub fn get_disjoint_mut<const N: usize>(
&mut self,
keys: [impl AsRef<str>; N],
) -> [Option<&mut V>; N]
pub fn get_disjoint_mut<const N: usize>( &mut self, keys: [impl AsRef<str>; N], ) -> [Option<&mut V>; N]
Gets multiple mutable values from the map.
§Panics
Panics if the same key is specified multiple times.
Sourcepub unsafe fn get_disjoint_unchecked_mut<const N: usize>(
&mut self,
keys: [impl AsRef<str>; N],
) -> [Option<&mut V>; N]
pub unsafe fn get_disjoint_unchecked_mut<const N: usize>( &mut self, keys: [impl AsRef<str>; N], ) -> [Option<&mut V>; N]
Gets multiple mutable values from the map.
§Safety
Calling this method with overlapping keys is undefined behavior even if the resulting references are not used.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
An iterator producing mutable references to all entries in arbitrary order.
Sourcepub fn into_keys(self) -> IntoKeys<K, V> ⓘ
pub fn into_keys(self) -> IntoKeys<K, V> ⓘ
A consuming iterator visiting all keys in arbitrary order.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
An iterator visiting all values mutably in arbitrary order.
Sourcepub fn into_values(self) -> IntoValues<K, V> ⓘ
pub fn into_values(self) -> IntoValues<K, V> ⓘ
A consuming iterator visiting all values in arbitrary order.
Trait Implementations§
Source§impl<K: Clone, V: Clone, BH: Clone> Clone for FzStringMap<K, V, BH>
impl<K: Clone, V: Clone, BH: Clone> Clone for FzStringMap<K, V, BH>
Source§fn clone(&self) -> FzStringMap<K, V, BH>
fn clone(&self) -> FzStringMap<K, V, BH>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<K, V, BH> Debug for FzStringMap<K, V, BH>
impl<K, V, BH> Debug for FzStringMap<K, V, BH>
Source§impl<'de, V, BH> Deserialize<'de> for FzStringMap<Box<str>, V, BH>
Available on crate feature serde only.
impl<'de, V, BH> Deserialize<'de> for FzStringMap<Box<str>, V, BH>
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<T, BH> From<FzStringMap<T, (), BH>> for FzStringSet<T, BH>
impl<T, BH> From<FzStringMap<T, (), BH>> for FzStringSet<T, BH>
Source§fn from(map: FzStringMap<T, (), BH>) -> Self
fn from(map: FzStringMap<T, (), BH>) -> Self
Source§impl<'a, V, BH> FromIterator<(&'a str, V)> for FzStringMap<&'a str, V, BH>
impl<'a, V, BH> FromIterator<(&'a str, V)> for FzStringMap<&'a str, V, BH>
Source§impl<KI, V, BH> FromIterator<(KI, V)> for FzStringMap<Box<str>, V, BH>
impl<KI, V, BH> FromIterator<(KI, V)> for FzStringMap<Box<str>, V, BH>
Source§impl<K, V, Q, BH> Index<&Q> for FzStringMap<K, V, BH>
impl<K, V, Q, BH> Index<&Q> for FzStringMap<K, V, BH>
Source§impl<'a, K, V, BH> IntoIterator for &'a FzStringMap<K, V, BH>
impl<'a, K, V, BH> IntoIterator for &'a FzStringMap<K, V, BH>
Source§impl<'a, K, V, BH> IntoIterator for &'a mut FzStringMap<K, V, BH>
impl<'a, K, V, BH> IntoIterator for &'a mut FzStringMap<K, V, BH>
Source§impl<K, V, BH> IntoIterator for FzStringMap<K, V, BH>
impl<K, V, BH> IntoIterator for FzStringMap<K, V, BH>
Source§impl<K, V, BH> Len for FzStringMap<K, V, BH>
impl<K, V, BH> Len for FzStringMap<K, V, BH>
Source§impl<K, V, Q, BH> MapExtras<K, V, Q> for FzStringMap<K, V, BH>
impl<K, V, Q, BH> MapExtras<K, V, Q> for FzStringMap<K, V, BH>
Source§impl<K, V, BH> MapIteration<K, V> for FzStringMap<K, V, BH>where
BH: BuildHasher,
impl<K, V, BH> MapIteration<K, V> for FzStringMap<K, V, BH>where
BH: BuildHasher,
Source§type Iterator<'a> = Iter<'a, K, V>
where
K: 'a,
V: 'a,
BH: 'a
type Iterator<'a> = Iter<'a, K, V> where K: 'a, V: 'a, BH: 'a
Self::iter.Source§type KeyIterator<'a> = Keys<'a, K, V>
where
K: 'a,
V: 'a,
BH: 'a
type KeyIterator<'a> = Keys<'a, K, V> where K: 'a, V: 'a, BH: 'a
Self::keys.Source§type ValueIterator<'a> = Values<'a, K, V>
where
K: 'a,
V: 'a,
BH: 'a
type ValueIterator<'a> = Values<'a, K, V> where K: 'a, V: 'a, BH: 'a
Self::values.Source§type MutIterator<'a> = IterMut<'a, K, V>
where
K: 'a,
V: 'a,
BH: 'a
type MutIterator<'a> = IterMut<'a, K, V> where K: 'a, V: 'a, BH: 'a
Self::iter_mut.Source§type ValueMutIterator<'a> = ValuesMut<'a, K, V>
where
K: 'a,
V: 'a,
BH: 'a
type ValueMutIterator<'a> = ValuesMut<'a, K, V> where K: 'a, V: 'a, BH: 'a
Self::values_mut.Source§type IntoKeyIterator = IntoKeys<K, V>
type IntoKeyIterator = IntoKeys<K, V>
Self::into_keys.Source§type IntoValueIterator = IntoValues<K, V>
type IntoValueIterator = IntoValues<K, V>
Self::into_values.Source§fn iter_mut(&mut self) -> Self::MutIterator<'_>
fn iter_mut(&mut self) -> Self::MutIterator<'_>
Source§fn keys(&self) -> Self::KeyIterator<'_>
fn keys(&self) -> Self::KeyIterator<'_>
Source§fn into_keys(self) -> Self::IntoKeyIterator
fn into_keys(self) -> Self::IntoKeyIterator
Source§fn values(&self) -> Self::ValueIterator<'_>
fn values(&self) -> Self::ValueIterator<'_>
Source§fn values_mut(&mut self) -> Self::ValueMutIterator<'_>
fn values_mut(&mut self) -> Self::ValueMutIterator<'_>
Source§fn into_values(self) -> Self::IntoValueIterator
fn into_values(self) -> Self::IntoValueIterator
Source§impl<K, V, Q, BH> MapQuery<Q, V> for FzStringMap<K, V, BH>
impl<K, V, Q, BH> MapQuery<Q, V> for FzStringMap<K, V, BH>
Source§impl<K, V, MT, BH> PartialEq<MT> for FzStringMap<K, V, BH>
impl<K, V, MT, BH> PartialEq<MT> for FzStringMap<K, V, BH>
Source§impl<K, V, BH> Serialize for FzStringMap<K, V, BH>
Available on crate feature serde only.
impl<K, V, BH> Serialize for FzStringMap<K, V, BH>
serde only.impl<K, V, BH> Eq for FzStringMap<K, V, BH>
impl<K, V, Q, BH> Map<K, V, Q> for FzStringMap<K, V, BH>
Auto Trait Implementations§
impl<K, V, BH> Freeze for FzStringMap<K, V, BH>
impl<K, V, BH> RefUnwindSafe for FzStringMap<K, V, BH>
impl<K, V, BH> Send for FzStringMap<K, V, BH>
impl<K, V, BH> Sync for FzStringMap<K, V, BH>
impl<K, V, BH> Unpin for FzStringMap<K, V, BH>where
BH: Unpin,
impl<K, V, BH> UnsafeUnpin for FzStringMap<K, V, BH>
impl<K, V, BH> UnwindSafe for FzStringMap<K, V, BH>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.