Skip to main content

MapRef

Struct MapRef 

Source
pub struct MapRef<'a> { /* private fields */ }
Expand description

A borrowed view into a canonical CBOR map.

Map keys are text strings and appear in canonical order (encoded length then lexicographic byte order).

Implementations§

Source§

impl<'a> MapRef<'a>

Source

pub const fn len(self) -> usize

Returns the number of entries in the map.

Source

pub const fn is_empty(self) -> bool

Returns whether the map is empty.

Source

pub fn get(self, key: &str) -> Result<Option<CborValueRef<'a>>, CborError>

Looks up a single key in the map.

This is efficient for canonical maps: it scans entries once and can stop early.

§Errors

Returns CborError if the map is malformed.

Source

pub fn require(self, key: &str) -> Result<CborValueRef<'a>, CborError>

Looks up a required key in the map.

§Errors

Returns CborError::MissingKey if the key is not present.

Source

pub fn require_many_sorted<const N: usize>( self, keys: [&str; N], ) -> Result<[CborValueRef<'a>; N], CborError>

Looks up multiple required keys in a single pass.

§Errors

Returns CborError::MissingKey if any key is not present.

Source

pub fn get_many_sorted<const N: usize>( self, keys: [&str; N], ) -> Result<[Option<CborValueRef<'a>>; N], CborError>

Looks up multiple keys in a single pass.

Keys may be in any order; results preserve the input key order. Missing keys yield None.

§Errors

Returns CborError for invalid query inputs or malformed canonical data.

Source

pub fn get_many_sorted_into( self, keys: &[&str], out: &mut [Option<CborValueRef<'a>>], ) -> Result<(), CborError>

Available on crate feature alloc only.

The slice-based form of MapRef::get_many_sorted.

out is cleared to None for all entries before results are written.

§Errors

Returns CborError for invalid query inputs or malformed canonical data.

Source

pub fn iter( self, ) -> impl Iterator<Item = Result<(&'a str, CborValueRef<'a>), CborError>> + 'a

Iterates over (key, value) pairs in canonical order.

The iterator yields Result to remain robust if canonical invariants are violated.

Source

pub fn extras_sorted<'k>( self, used_keys: &'k [&'k str], ) -> Result<impl Iterator<Item = Result<(&'a str, CborValueRef<'a>), CborError>> + 'k, CborError>
where 'a: 'k,

Iterates over map entries excluding used_keys (keys must be sorted canonically).

§Errors

Returns CborError if used_keys are not strictly increasing or if the map is malformed.

Source

pub fn extras_sorted_vec<'k>( self, used_keys: &'k [&'k str], ) -> Result<Vec<(&'a str, CborValueRef<'a>)>, CborError>
where 'a: 'k,

Available on crate feature alloc only.

Collects extras for sorted used_keys into a Vec.

§Errors

Returns CborError if used_keys are not strictly increasing or if the map is malformed.

Source

pub fn extras_vec<'k>( self, used_keys: &'k [&'k str], ) -> Result<Vec<(&'a str, CborValueRef<'a>)>, CborError>
where 'a: 'k,

Available on crate feature alloc only.

Accepts used_keys in any order (allocates to sort them), then returns extras.

§Errors

Returns CborError if used_keys contain duplicates or if the map is malformed.

Source

pub fn get_many( self, keys: &[&str], ) -> Result<Vec<Option<CborValueRef<'a>>>, CborError>

Available on crate feature alloc only.

Looks up multiple keys in one pass (keys may be in any order).

This API is available with the alloc feature. Results preserve the input key order.

§Errors

Returns CborError for invalid query inputs or malformed canonical data.

Source

pub fn require_many( self, keys: &[&str], ) -> Result<Vec<CborValueRef<'a>>, CborError>

Available on crate feature alloc only.

Looks up multiple required keys in one pass (keys may be in any order).

This API is available with the alloc feature. Results preserve the input key order.

§Errors

Returns CborError::MissingKey if any key is not present.

Source

pub fn get_many_into( self, keys: &[&str], out: &mut [Option<CborValueRef<'a>>], ) -> Result<(), CborError>

Available on crate feature alloc only.

The slice-based form of MapRef::get_many.

out is cleared to None for all entries before results are written.

§Errors

Returns CborError for invalid query inputs or malformed canonical data.

Trait Implementations§

Source§

impl<'a> Clone for MapRef<'a>

Source§

fn clone(&self) -> MapRef<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for MapRef<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Copy for MapRef<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for MapRef<'a>

§

impl<'a> RefUnwindSafe for MapRef<'a>

§

impl<'a> Send for MapRef<'a>

§

impl<'a> Sync for MapRef<'a>

§

impl<'a> Unpin for MapRef<'a>

§

impl<'a> UnsafeUnpin for MapRef<'a>

§

impl<'a> UnwindSafe for MapRef<'a>

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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.