pub struct CborValueRef<'a> { /* private fields */ }Expand description
A borrowed view into a canonical CBOR message.
The view carries the full message bytes plus a (start, end) range for the
current value. All nested values returned from queries keep referencing the
original message bytes.
Implementations§
Source§impl<'a> CborValueRef<'a>
impl<'a> CborValueRef<'a>
Sourcepub unsafe fn from_canonical_range(
data: &'a [u8],
start: usize,
end: usize,
) -> Self
Available on crate feature unsafe only.
pub unsafe fn from_canonical_range( data: &'a [u8], start: usize, end: usize, ) -> Self
unsafe only.Construct a value reference from a canonical byte slice and range.
§Safety
The caller must ensure data is canonical CBOR and the range bounds a full CBOR item.
Sourcepub fn as_bytes(self) -> &'a [u8] ⓘ
pub fn as_bytes(self) -> &'a [u8] ⓘ
Returns the raw bytes (canonical CBOR encoding) for this value.
Sourcepub const fn offset(self) -> usize
pub const fn offset(self) -> usize
Returns the starting offset (in bytes) of this value within the message.
Sourcepub fn map(self) -> Result<MapRef<'a>, CborError>
pub fn map(self) -> Result<MapRef<'a>, CborError>
Interprets this value as a CBOR map and returns a borrowed map view.
§Errors
Returns CborError::ExpectedMap if the value is not a map.
Sourcepub fn array(self) -> Result<ArrayRef<'a>, CborError>
pub fn array(self) -> Result<ArrayRef<'a>, CborError>
Interprets this value as a CBOR array and returns a borrowed array view.
§Errors
Returns CborError::ExpectedArray if the value is not an array.
Sourcepub fn get_key(self, key: &str) -> Result<Option<Self>, CborError>
pub fn get_key(self, key: &str) -> Result<Option<Self>, CborError>
Retrieves a value by map key from this value (which must be a map).
§Errors
Returns CborError::ExpectedMap if the value is not a map.
Sourcepub fn get_index(self, index: usize) -> Result<Option<Self>, CborError>
pub fn get_index(self, index: usize) -> Result<Option<Self>, CborError>
Retrieves a value by array index from this value (which must be an array).
§Errors
Returns CborError::ExpectedArray if the value is not an array.
Sourcepub fn at(self, path: &[PathElem<'_>]) -> Result<Option<Self>, CborError>
pub fn at(self, path: &[PathElem<'_>]) -> Result<Option<Self>, CborError>
Traverses a nested path starting from this value.
Returns Ok(None) if any map key is missing or any array index is out of
bounds. Returns Err(_) on type mismatches or malformed canonical input.
§Errors
Returns CborError for type mismatches or malformed canonical input.
Sourcepub fn integer(self) -> Result<CborIntegerRef<'a>, CborError>
pub fn integer(self) -> Result<CborIntegerRef<'a>, CborError>
Decodes this value as a CBOR integer (safe or bignum).
§Errors
Returns CborError::ExpectedInteger if the value is not an integer or is malformed.
Sourcepub fn text(self) -> Result<&'a str, CborError>
pub fn text(self) -> Result<&'a str, CborError>
Decodes this value as a CBOR text string.
§Errors
Returns CborError::ExpectedText if the value is not a text string or is malformed.
Sourcepub fn bytes(self) -> Result<&'a [u8], CborError>
pub fn bytes(self) -> Result<&'a [u8], CborError>
Decodes this value as a CBOR byte string.
§Errors
Returns CborError::ExpectedBytes if the value is not a byte string or is malformed.
Trait Implementations§
Source§impl<'de> CborDecode<'de> for CborValueRef<'de>
impl<'de> CborDecode<'de> for CborValueRef<'de>
Source§impl CborEncode for CborValueRef<'_>
Available on crate feature alloc only.
impl CborEncode for CborValueRef<'_>
alloc only.Source§impl<'a> Clone for CborValueRef<'a>
impl<'a> Clone for CborValueRef<'a>
Source§fn clone(&self) -> CborValueRef<'a>
fn clone(&self) -> CborValueRef<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for CborValueRef<'a>
impl<'a> Debug for CborValueRef<'a>
Source§impl<'de> Deserialize<'de> for CborValueRef<'de>
Available on crate feature serde only.
impl<'de> Deserialize<'de> for CborValueRef<'de>
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl PartialEq for CborValueRef<'_>
impl PartialEq for CborValueRef<'_>
impl CborArrayElem for CborValueRef<'_>
alloc only.