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>
impl<'a, K, V> Map<'a, K, V>
sourcepub fn get<Q>(&self, key: &Q) -> Result<Option<&V>, Error>
pub fn get<Q>(&self, key: &Q) -> Result<Option<&V>, Error>
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);
sourcepub fn len(&self) -> usize
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);
sourcepub fn is_empty(&self) -> bool
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());
sourcepub fn contains_key<Q>(&self, key: &Q) -> Result<bool, Error>
pub fn contains_key<Q>(&self, key: &Q) -> Result<bool, Error>
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>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<'a, K, V> Send for Map<'a, K, V>
impl<'a, K, V> Sync for Map<'a, K, V>
impl<'a, K, V> Unpin for Map<'a, K, V>
impl<'a, K, V> UnwindSafe for Map<'a, K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more