Struct ZeroMapBorrowed

struct ZeroMapBorrowed<'a, K, V> { ... }
where
    K: ZeroMapKV<'a> + ?Sized,
    V: ZeroMapKV<'a> + ?Sized

A borrowed-only version of ZeroMap

This is useful for fully-zero-copy deserialization from non-human-readable serialization formats. It also has the advantage that it can return references that live for the lifetime of the backing buffer as opposed to that of the ZeroMapBorrowed instance.

Examples

use zerovec::maps::ZeroMapBorrowed;

// Example byte buffer representing the map { 1: "one" }
let BINCODE_BYTES: &[u8; 25] = &[
    4, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 1, 0, 111,
    110, 101,
];

// Deserializing to ZeroMap requires no heap allocations.
let zero_map: ZeroMapBorrowed<u32, str> =
    bincode::deserialize(BINCODE_BYTES)
        .expect("Should deserialize successfully");
assert_eq!(zero_map.get(&1), Some("one"));

This can be obtained from a ZeroMap via ZeroMap::as_borrowed

Implementations

impl<'a, K, V> ZeroMapBorrowed<'a, K, V>

fn len(self: Self) -> usize

The number of elements in the ZeroMapBorrowed

fn is_empty(self: Self) -> bool

Whether the ZeroMapBorrowed is empty

impl<'a, K, V> ZeroMapBorrowed<'a, K, V>

fn iter_copied(self: Self) -> impl Iterator<Item = (K, V)> + 'a

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

impl<'a, K, V> ZeroMapBorrowed<'a, K, V>

fn get_copied(self: Self, key: &K) -> Option<V>

For cases when V is fixed-size, obtain a direct copy of V instead of V::ULE

fn get_copied_by<impl FnMut(&K) -> Ordering: FnMut(&K) -> Ordering>(self: Self, predicate: impl FnMut(&K) -> Ordering) -> Option<V>

For cases when V is fixed-size, obtain a direct copy of V instead of V::ULE

fn iter_copied_values(self: Self) -> impl Iterator<Item = (&'a <K as ZeroMapKV<'a>>::GetType, V)>

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> ZeroMapBorrowed<'a, K, V>

fn iter(self: Self) -> impl Iterator<Item = (&'a <K as ZeroMapKV<'a>>::GetType, &'a <V as ZeroMapKV<'a>>::GetType)>

Produce an ordered iterator over key-value pairs

fn iter_keys(self: Self) -> impl Iterator<Item = &'a <K as ZeroMapKV<'a>>::GetType>

Produce an ordered iterator over keys

fn iter_values(self: Self) -> impl Iterator<Item = &'a <V as ZeroMapKV<'a>>::GetType>

Produce an iterator over values, ordered by keys

impl<'a, K, V> ZeroMapBorrowed<'a, K, V>

fn get(self: Self, key: &K) -> Option<&'a <V as >::GetType>

Get the value associated with key, if it exists.

This is able to return values that live longer than the map itself since they borrow directly from the backing buffer. This is the primary advantage of using ZeroMapBorrowed over ZeroMap.

use zerovec::ZeroMap;

let mut map = ZeroMap::new();
map.insert(&1, "one");
map.insert(&2, "two");
let borrowed = map.as_borrowed();
assert_eq!(borrowed.get(&1), Some("one"));
assert_eq!(borrowed.get(&3), None);
fn get_by<impl FnMut(&K) -> Ordering: FnMut(&K) -> Ordering>(self: Self, predicate: impl FnMut(&K) -> Ordering) -> Option<&'a <V as >::GetType>

Binary search the map with predicate to find a key, returning the value.

This is able to return values that live longer than the map itself since they borrow directly from the backing buffer. This is the primary advantage of using ZeroMapBorrowed over ZeroMap.

use zerovec::ZeroMap;

let mut map = ZeroMap::new();
map.insert(&1, "one");
map.insert(&2, "two");
let borrowed = map.as_borrowed();
assert_eq!(borrowed.get_by(|probe| probe.cmp(&1)), Some("one"));
assert_eq!(borrowed.get_by(|probe| probe.cmp(&3)), None);
fn contains_key(self: Self, key: &K) -> bool

Returns whether key is contained in this map

use zerovec::ZeroMap;

let mut map = ZeroMap::new();
map.insert(&1, "one");
map.insert(&2, "two");
let borrowed = map.as_borrowed();
assert!(borrowed.contains_key(&1));
assert!(!borrowed.contains_key(&3));

impl<'a, K, V> ZeroMapBorrowed<'a, K, V>

fn new() -> Self

Creates a new, empty ZeroMapBorrowed<K, V>.

Note: Since ZeroMapBorrowed is not mutable, the return value will be a stub unless converted into a ZeroMap.

Examples

use zerovec::maps::ZeroMapBorrowed;

let zm: ZeroMapBorrowed<u16, str> = ZeroMapBorrowed::new();
assert!(zm.is_empty());

impl<'a, 'b, K, V> PartialEq for ZeroMapBorrowed<'a, K, V>

fn eq(self: &Self, other: &ZeroMapBorrowed<'b, K, V>) -> bool

impl<'a, K, V> Clone for ZeroMapBorrowed<'a, K, V>

fn clone(self: &Self) -> Self

impl<'a, K, V> Copy for ZeroMapBorrowed<'a, K, V>

impl<'a, K, V> Debug for ZeroMapBorrowed<'a, K, V>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result<(), Error>

impl<'a, K, V> Default for ZeroMapBorrowed<'a, K, V>

fn default() -> Self

impl<'a, K, V> Freeze for ZeroMapBorrowed<'a, K, V>

impl<'a, K, V> RefUnwindSafe for ZeroMapBorrowed<'a, K, V>

impl<'a, K, V> Send for ZeroMapBorrowed<'a, K, V>

impl<'a, K, V> Sync for ZeroMapBorrowed<'a, K, V>

impl<'a, K, V> Unpin for ZeroMapBorrowed<'a, K, V>

impl<'a, K, V> UnsafeUnpin for ZeroMapBorrowed<'a, K, V>

impl<'a, K, V> UnwindSafe for ZeroMapBorrowed<'a, K, V>

impl<'a, K, V> Yokeable for ZeroMapBorrowed<'static, K, V>

fn transform(self: &'a Self) -> &'a <Self as >::Output
fn transform_owned(self: Self) -> <Self as >::Output
unsafe fn make(from: <Self as >::Output) -> Self
fn transform_mut<F>(self: &'a mut Self, f: F)
where
    F: 'static + for<'b> FnOnce(&'b mut <Self as >::Output)

impl<T> Any for ZeroMapBorrowed<'a, K, V>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for ZeroMapBorrowed<'a, K, V>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for ZeroMapBorrowed<'a, K, V>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for ZeroMapBorrowed<'a, K, V>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> ErasedDestructor for ZeroMapBorrowed<'a, K, V>

impl<T> From for ZeroMapBorrowed<'a, K, V>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for ZeroMapBorrowed<'a, K, V>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for ZeroMapBorrowed<'a, K, V>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for ZeroMapBorrowed<'a, K, V>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for ZeroMapBorrowed<'a, K, V>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>