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>
impl<'a> MapRef<'a>
Sourcepub fn get(self, key: &str) -> Result<Option<CborValueRef<'a>>, CborError>
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.
Sourcepub fn require(self, key: &str) -> Result<CborValueRef<'a>, CborError>
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.
Sourcepub fn require_many_sorted<const N: usize>(
self,
keys: [&str; N],
) -> Result<[CborValueRef<'a>; N], CborError>
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.
Sourcepub fn get_many_sorted<const N: usize>(
self,
keys: [&str; N],
) -> Result<[Option<CborValueRef<'a>>; N], CborError>
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.
Sourcepub fn get_many_sorted_into(
self,
keys: &[&str],
out: &mut [Option<CborValueRef<'a>>],
) -> Result<(), CborError>
Available on crate feature alloc only.
pub fn get_many_sorted_into( self, keys: &[&str], out: &mut [Option<CborValueRef<'a>>], ) -> Result<(), CborError>
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.
Sourcepub fn iter(
self,
) -> impl Iterator<Item = Result<(&'a str, CborValueRef<'a>), CborError>> + 'a
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.
Sourcepub 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,
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.
Sourcepub 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.
pub fn extras_sorted_vec<'k>(
self,
used_keys: &'k [&'k str],
) -> Result<Vec<(&'a str, CborValueRef<'a>)>, CborError>where
'a: 'k,
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.
Sourcepub 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.
pub fn extras_vec<'k>(
self,
used_keys: &'k [&'k str],
) -> Result<Vec<(&'a str, CborValueRef<'a>)>, CborError>where
'a: 'k,
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.
Sourcepub fn get_many(
self,
keys: &[&str],
) -> Result<Vec<Option<CborValueRef<'a>>>, CborError>
Available on crate feature alloc only.
pub fn get_many( self, keys: &[&str], ) -> Result<Vec<Option<CborValueRef<'a>>>, CborError>
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.
Sourcepub fn require_many(
self,
keys: &[&str],
) -> Result<Vec<CborValueRef<'a>>, CborError>
Available on crate feature alloc only.
pub fn require_many( self, keys: &[&str], ) -> Result<Vec<CborValueRef<'a>>, CborError>
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.
Sourcepub fn get_many_into(
self,
keys: &[&str],
out: &mut [Option<CborValueRef<'a>>],
) -> Result<(), CborError>
Available on crate feature alloc only.
pub fn get_many_into( self, keys: &[&str], out: &mut [Option<CborValueRef<'a>>], ) -> Result<(), CborError>
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.