Struct zerovec::map::ZeroMap [−][src]
Expand description
A zero-copy map datastructure, built on sorted binary-searchable ZeroVec
and VarZeroVec
.
This type, like ZeroVec
and VarZeroVec
, is able to zero-copy
deserialize from appropriately formatted byte buffers. It is internally copy-on-write, so it can be mutated
afterwards as necessary.
Implementations
impl<'a, K, V> ZeroMap<'a, K, V> where
K: ZeroMapKV<'a>,
V: ZeroMapKV<'a>,
[src]
impl<'a, K, V> ZeroMap<'a, K, V> where
K: ZeroMapKV<'a>,
V: ZeroMapKV<'a>,
[src]pub fn with_capacity(capacity: usize) -> Self
[src]
pub fn with_capacity(capacity: usize) -> Self
[src]Construct a new ZeroMap
with a given capacity
pub fn reserve(&mut self, additional: usize)
[src]
pub fn reserve(&mut self, additional: usize)
[src]Reserve capacity for additional
more elements to be inserted into
the ZeroMap
to avoid frequent reallocations.
See Vec::reserve()
for more information.
pub fn get(&self, key: &K::NeedleType) -> Option<&V::GetType>
[src]
pub fn get(&self, key: &K::NeedleType) -> Option<&V::GetType>
[src]Get the value associated with key
, if it exists.
use zerovec::ZeroMap; let mut map = ZeroMap::new(); map.insert(1, "one".to_owned()); map.insert(2, "two".to_owned()); assert_eq!(map.get(&1), Some("one")); assert_eq!(map.get(&3), None);
pub fn contains_key(&self, key: &K::NeedleType) -> bool
[src]
pub fn contains_key(&self, key: &K::NeedleType) -> bool
[src]Returns whether key
is contained in this map
use zerovec::ZeroMap; let mut map = ZeroMap::new(); map.insert(1, "one".to_owned()); map.insert(2, "two".to_owned()); assert_eq!(map.contains_key(&1), true); assert_eq!(map.contains_key(&3), false);
pub fn insert(&mut self, key: K, value: V) -> Option<V>
[src]
pub fn insert(&mut self, key: K, value: V) -> Option<V>
[src]Insert value
with key
, returning the existing value if it exists.
use zerovec::ZeroMap; let mut map = ZeroMap::new(); map.insert(1, "one".to_owned()); map.insert(2, "two".to_owned()); assert_eq!(map.get(&1), Some("one")); assert_eq!(map.get(&3), None);
pub fn remove(&mut self, key: &K::NeedleType) -> Option<V>
[src]
pub fn remove(&mut self, key: &K::NeedleType) -> Option<V>
[src]Remove the value at key
, returning it if it exists.
use zerovec::ZeroMap; let mut map = ZeroMap::new(); map.insert(1, "one".to_owned()); map.insert(2, "two".to_owned()); assert_eq!(map.remove(&1), Some("one".to_owned())); assert_eq!(map.get(&1), None);
#[must_use]pub fn try_append(&mut self, key: K, value: V) -> Option<(K, V)>
[src]
#[must_use]pub fn try_append(&mut self, key: K, value: V) -> Option<(K, V)>
[src]Appends value
with key
to the end of the underlying vector, returning
key
and value
if it failed. Useful for extending with an existing
sorted list.
use zerovec::ZeroMap; let mut map = ZeroMap::new(); assert!(map.try_append(1, "uno".to_owned()).is_none()); assert!(map.try_append(3, "tres".to_owned()).is_none()); let unsuccessful = map.try_append(3, "tres-updated".to_owned()); assert!(unsuccessful.is_some(), "append duplicate of last key"); let unsuccessful = map.try_append(2, "dos".to_owned()); assert!(unsuccessful.is_some(), "append out of order"); assert_eq!(map.get(&1), Some("uno")); // contains the original value for the key: 3 assert_eq!(map.get(&3), Some("tres")); // not appended since it wasn't in order assert_eq!(map.get(&2), None);
pub fn iter<'b>(
&'b self
) -> impl Iterator<Item = (&'b <K as ZeroMapKV<'a>>::GetType, &'b <V as ZeroMapKV<'a>>::GetType)>
[src]
pub fn iter<'b>(
&'b self
) -> impl Iterator<Item = (&'b <K as ZeroMapKV<'a>>::GetType, &'b <V as ZeroMapKV<'a>>::GetType)>
[src]Produce an ordered iterator over key-value pairs
pub fn iter_keys<'b>(
&'b self
) -> impl Iterator<Item = &'b <K as ZeroMapKV<'a>>::GetType>
[src]
pub fn iter_keys<'b>(
&'b self
) -> impl Iterator<Item = &'b <K as ZeroMapKV<'a>>::GetType>
[src]Produce an ordered iterator over keys
pub fn iter_values<'b>(
&'b self
) -> impl Iterator<Item = &'b <V as ZeroMapKV<'a>>::GetType>
[src]
pub fn iter_values<'b>(
&'b self
) -> impl Iterator<Item = &'b <V as ZeroMapKV<'a>>::GetType>
[src]Produce an iterator over values, ordered by keys
impl<'a, K, V> ZeroMap<'a, K, V> where
K: ZeroMapKV<'a>,
V: ZeroMapKV<'a, Container = ZeroVec<'a, V>>,
V: AsULE + Copy,
[src]
impl<'a, K, V> ZeroMap<'a, K, V> where
K: ZeroMapKV<'a>,
V: ZeroMapKV<'a, Container = ZeroVec<'a, V>>,
V: AsULE + Copy,
[src]pub fn get_copied(&self, key: &K::NeedleType) -> Option<V>
[src]
pub fn get_copied(&self, key: &K::NeedleType) -> Option<V>
[src]For cases when V
is fixed-size, obtain a direct copy of V
instead of V::ULE
pub fn iter_copied_values<'b>(
&'b self
) -> impl Iterator<Item = (&'b <K as ZeroMapKV<'a>>::GetType, V)>
[src]
pub fn iter_copied_values<'b>(
&'b self
) -> impl Iterator<Item = (&'b <K as ZeroMapKV<'a>>::GetType, V)>
[src]Similar to Self::iter()
except it returns a direct copy of the values instead of references
to V::ULE
, in cases when V
is fixed-size
impl<'a, K, V> ZeroMap<'a, K, V> where
K: ZeroMapKV<'a, Container = ZeroVec<'a, K>>,
V: ZeroMapKV<'a, Container = ZeroVec<'a, V>>,
K: AsULE + Copy,
V: AsULE + Copy,
[src]
impl<'a, K, V> ZeroMap<'a, K, V> where
K: ZeroMapKV<'a, Container = ZeroVec<'a, K>>,
V: ZeroMapKV<'a, Container = ZeroVec<'a, V>>,
K: AsULE + Copy,
V: AsULE + Copy,
[src]pub fn iter_copied<'b>(&'b self) -> impl Iterator<Item = (K, V)> + 'b
[src]
pub fn iter_copied<'b>(&'b self) -> impl Iterator<Item = (K, V)> + 'b
[src]Similar to Self::iter()
except it returns a direct copy of the keys values instead of references
to K::ULE
and V::ULE
, in cases when K
and V
are fixed-size
Trait Implementations
impl<'de, K, V> Deserialize<'de> for ZeroMap<'de, K, V> where
K: Deserialize<'de> + Ord,
V: Deserialize<'de>,
K::Container: Deserialize<'de>,
V::Container: Deserialize<'de>,
K: ZeroMapKV<'de>,
V: ZeroMapKV<'de>,
[src]
impl<'de, K, V> Deserialize<'de> for ZeroMap<'de, K, V> where
K: Deserialize<'de> + Ord,
V: Deserialize<'de>,
K::Container: Deserialize<'de>,
V::Container: Deserialize<'de>,
K: ZeroMapKV<'de>,
V: ZeroMapKV<'de>,
[src]This impl can be made available by enabling the optional serde
feature of the zerovec
crate
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]Deserialize this value from the given Serde deserializer. Read more
impl<'a, K, V> Serialize for ZeroMap<'a, K, V> where
K: ZeroMapKV<'a>,
V: ZeroMapKV<'a>,
K::Container: Serialize,
V::Container: Serialize,
K::SerializeType: Serialize,
V::SerializeType: Serialize,
[src]
impl<'a, K, V> Serialize for ZeroMap<'a, K, V> where
K: ZeroMapKV<'a>,
V: ZeroMapKV<'a>,
K::Container: Serialize,
V::Container: Serialize,
K::SerializeType: Serialize,
V::SerializeType: Serialize,
[src]This impl can be made available by enabling the optional serde
feature of the zerovec
crate
impl<'a, K: 'static + ZeroMapKV<'static> + Yokeable<'a>, V: 'static + ZeroMapKV<'static> + Yokeable<'a>> Yokeable<'a> for ZeroMap<'static, K, V> where
K::Output: ZeroMapKV<'a>,
V::Output: ZeroMapKV<'a>,
[src]
impl<'a, K: 'static + ZeroMapKV<'static> + Yokeable<'a>, V: 'static + ZeroMapKV<'static> + Yokeable<'a>> Yokeable<'a> for ZeroMap<'static, K, V> where
K::Output: ZeroMapKV<'a>,
V::Output: ZeroMapKV<'a>,
[src]This impl can be made available by enabling the optional yoke
feature of the zerovec
crate
type Output = ZeroMap<'a, K::Output, V::Output>
type Output = ZeroMap<'a, K::Output, V::Output>
This type MUST be Self
with the 'static
replaced with 'a
, i.e. Self<'a>
fn transform(&'a self) -> &'a ZeroMap<'a, K::Output, V::Output>
[src]
fn transform(&'a self) -> &'a ZeroMap<'a, K::Output, V::Output>
[src]This method must cast self
between &'a Self<'static>
and &'a Self<'a>
. Read more
Auto Trait Implementations
impl<'a, K, V> RefUnwindSafe for ZeroMap<'a, K, V> where
<K as ZeroMapKV<'a>>::Container: RefUnwindSafe,
<V as ZeroMapKV<'a>>::Container: RefUnwindSafe,
<K as ZeroMapKV<'a>>::Container: RefUnwindSafe,
<V as ZeroMapKV<'a>>::Container: RefUnwindSafe,
impl<'a, K, V> Send for ZeroMap<'a, K, V> where
<K as ZeroMapKV<'a>>::Container: Send,
<V as ZeroMapKV<'a>>::Container: Send,
<K as ZeroMapKV<'a>>::Container: Send,
<V as ZeroMapKV<'a>>::Container: Send,
impl<'a, K, V> Sync for ZeroMap<'a, K, V> where
<K as ZeroMapKV<'a>>::Container: Sync,
<V as ZeroMapKV<'a>>::Container: Sync,
<K as ZeroMapKV<'a>>::Container: Sync,
<V as ZeroMapKV<'a>>::Container: Sync,
impl<'a, K, V> Unpin for ZeroMap<'a, K, V> where
<K as ZeroMapKV<'a>>::Container: Unpin,
<V as ZeroMapKV<'a>>::Container: Unpin,
<K as ZeroMapKV<'a>>::Container: Unpin,
<V as ZeroMapKV<'a>>::Container: Unpin,
impl<'a, K, V> UnwindSafe for ZeroMap<'a, K, V> where
<K as ZeroMapKV<'a>>::Container: UnwindSafe,
<V as ZeroMapKV<'a>>::Container: UnwindSafe,
<K as ZeroMapKV<'a>>::Container: UnwindSafe,
<V as ZeroMapKV<'a>>::Container: UnwindSafe,