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 ZeroMapBorrowed;
// Example byte buffer representing the map { 1: "one" }
let BINCODE_BYTES: & = &;
// Deserializing to ZeroMap requires no heap allocations.
let zero_map: =
deserialize
.expect;
assert_eq!;
This can be obtained from a ZeroMap via ZeroMap::as_borrowed
Implementations
impl<'a, K, V> ZeroMapBorrowed<'a, K, V>
fn len(self: Self) -> usizeThe number of elements in the
ZeroMapBorrowedfn is_empty(self: Self) -> boolWhether the
ZeroMapBorrowedis empty
impl<'a, K, V> ZeroMapBorrowed<'a, K, V>
fn iter_copied(self: Self) -> impl Iterator<Item = (K, V)> + 'aSimilar to [
Self::iter()] except it returns a direct copy of the keys values instead of references toK::ULEandV::ULE, in cases whenKandVare fixed-size
impl<'a, K, V> ZeroMapBorrowed<'a, K, V>
fn get_copied(self: Self, key: &K) -> Option<V>For cases when
Vis fixed-size, obtain a direct copy ofVinstead ofV::ULEfn get_copied_by<impl FnMut(&K) -> Ordering: FnMut(&K) -> Ordering>(self: Self, predicate: impl FnMut(&K) -> Ordering) -> Option<V>For cases when
Vis fixed-size, obtain a direct copy ofVinstead ofV::ULEfn 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 toV::ULE, in cases whenVis 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
ZeroMapBorrowedoverZeroMap.use ZeroMap; let mut map = new; map.insert; map.insert; let borrowed = map.as_borrowed; assert_eq!; assert_eq!;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
predicateto 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
ZeroMapBorrowedoverZeroMap.use ZeroMap; let mut map = new; map.insert; map.insert; let borrowed = map.as_borrowed; assert_eq!; assert_eq!;fn contains_key(self: Self, key: &K) -> boolReturns whether
keyis contained in this mapuse ZeroMap; let mut map = new; map.insert; map.insert; let borrowed = map.as_borrowed; assert!; assert!;
impl<'a, K, V> ZeroMapBorrowed<'a, K, V>
fn new() -> SelfCreates a new, empty
ZeroMapBorrowed<K, V>.Note: Since
ZeroMapBorrowedis not mutable, the return value will be a stub unless converted into aZeroMap.Examples
use ZeroMapBorrowed; let zm: = new; assert!;
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 >::Outputfn transform_owned(self: Self) -> <Self as >::Outputunsafe fn make(from: <Self as >::Output) -> Selffn 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) -> TReturns the argument unchanged.
impl<T> ToOwned for ZeroMapBorrowed<'a, K, V>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for ZeroMapBorrowed<'a, K, V>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses 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>