Struct zerovec::map::ZeroMap[][src]

pub struct ZeroMap<'a, K, V> where
    K: ZeroMapKV<'a>,
    V: ZeroMapKV<'a>, 
{ /* fields omitted */ }
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]

pub fn new() -> Self[src]

Construct a new ZeroMap

pub fn with_capacity(capacity: usize) -> Self[src]

Construct a new ZeroMap with a given capacity

pub fn len(&self) -> usize[src]

The number of elements in the ZeroMap

pub fn is_empty(&self) -> bool[src]

Whether the ZeroMap is empty

pub fn clear(&mut self)[src]

Remove all elements from the ZeroMap

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]

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]

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]

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]

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]

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]

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]

Produce an ordered iterator over keys

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]

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]

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]

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<'a, K, V> Default for ZeroMap<'a, K, V> where
    K: ZeroMapKV<'a>,
    V: ZeroMapKV<'a>, 
[src]

fn default() -> Self[src]

Returns the “default value” for a type. Read more

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]

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]

This impl can be made available by enabling the optional serde feature of the zerovec crate

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
    S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

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>

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]

This method must cast self between &'a Self<'static> and &'a Self<'a>. Read more

unsafe fn make(from: ZeroMap<'a, K::Output, V::Output>) -> Self[src]

This method can be used to cast away Self<'a>’s lifetime. Read more

fn with_mut<F>(&'a mut self, f: F) where
    F: 'static + for<'b> FnOnce(&'b mut Self::Output), 
[src]

This method must cast self between &'a mut Self<'static> and &'a mut Self<'a>, and pass it to f. 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

impl<'a, K, V> Send for ZeroMap<'a, K, V> where
    <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

impl<'a, K, V> Unpin for ZeroMap<'a, K, V> where
    <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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

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]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.