Struct musli_zerocopy::swiss::Map

source ·
pub struct Map<'a, K, V> { /* private fields */ }
Expand description

A map bound to a Buf through Buf::bind for convenience.

§Examples

use musli_zerocopy::OwnedBuf;
use musli_zerocopy::swiss;

let mut buf = OwnedBuf::new();

let map = swiss::store_map(&mut buf, [(1, 2), (2, 3)])?;
let map = buf.bind(map)?;

assert_eq!(map.get(&1)?, Some(&2));
assert_eq!(map.get(&2)?, Some(&3));
assert_eq!(map.get(&3)?, None);

assert!(map.contains_key(&1)?);
assert!(!map.contains_key(&3)?);

Implementations§

source§

impl<'a, K, V> Map<'a, K, V>
where K: ZeroCopy, V: ZeroCopy,

source

pub fn get<Q>(&self, key: &Q) -> Result<Option<&V>, Error>
where Q: ?Sized + Visit, Q::Target: Eq + Hash, K: Visit, K::Target: Borrow<Q::Target>,

Get a value from the map.

§Examples
use musli_zerocopy::OwnedBuf;
use musli_zerocopy::swiss;

let mut buf = OwnedBuf::new();

let map = swiss::store_map(&mut buf, [(1, 2), (2, 3)])?;
let map = buf.bind(map)?;

assert_eq!(map.get(&1)?, Some(&2));
assert_eq!(map.get(&2)?, Some(&3));
assert_eq!(map.get(&3)?, None);
source

pub fn len(&self) -> usize

Get the length of the map.

§Examples
use musli_zerocopy::OwnedBuf;
use musli_zerocopy::swiss;

let mut buf = OwnedBuf::new();

let map = swiss::store_map(&mut buf, [(1, 2), (2, 3)])?;
let map = buf.bind(map)?;

assert_eq!(map.len(), 2);
source

pub fn is_empty(&self) -> bool

Test if the map is empty.

§Examples
use musli_zerocopy::OwnedBuf;
use musli_zerocopy::swiss;

let mut buf = OwnedBuf::new();

let map = swiss::store_map(&mut buf, [(1, 2), (2, 3)])?;
let map = buf.bind(map)?;

assert!(!map.is_empty());
source

pub fn contains_key<Q>(&self, key: &Q) -> Result<bool, Error>
where Q: ?Sized + Visit, Q::Target: Eq + Hash, K: Visit, K::Target: Borrow<Q::Target>,

Test if the map contains the given key.

§Examples
use musli_zerocopy::OwnedBuf;
use musli_zerocopy::swiss;

let mut buf = OwnedBuf::new();

let map = swiss::store_map(&mut buf, [(1, 2), (2, 3)])?;
let map = buf.bind(map)?;

assert!(map.contains_key(&1)?);
assert!(map.contains_key(&2)?);
assert!(!map.contains_key(&3)?);

Auto Trait Implementations§

§

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

§

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

§

impl<'a, K, V> Send for Map<'a, K, V>
where K: Sync, V: Sync,

§

impl<'a, K, V> Sync for Map<'a, K, V>
where K: Sync, V: Sync,

§

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

§

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

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.