Skip to main content

CborValueRef

Struct CborValueRef 

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

Source

pub unsafe fn from_canonical_range( data: &'a [u8], start: usize, end: usize, ) -> Self

Available on crate feature 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.

Source

pub fn as_bytes(self) -> &'a [u8]

Returns the raw bytes (canonical CBOR encoding) for this value.

Source

pub const fn offset(self) -> usize

Returns the starting offset (in bytes) of this value within the message.

Source

pub const fn len(self) -> usize

Returns the byte length of this value’s canonical encoding.

Source

pub const fn is_empty(self) -> bool

Returns whether this value’s canonical encoding is empty.

Source

pub fn kind(self) -> Result<CborKind, CborError>

Returns the kind of this value.

§Errors

Returns CborError if the underlying bytes are malformed.

Source

pub fn is_null(self) -> bool

Returns true if this value is CBOR null.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn bool(self) -> Result<bool, CborError>

Decodes this value as a CBOR boolean.

§Errors

Returns CborError::ExpectedBool if the value is not a boolean or is malformed.

Source

pub fn float64(self) -> Result<f64, CborError>

Decodes this value as a CBOR float64.

§Errors

Returns CborError::ExpectedFloat if the value is not a float64 or is malformed.

Trait Implementations§

Source§

impl<'de> CborDecode<'de> for CborValueRef<'de>

Source§

fn decode<const CHECKED: bool>( decoder: &mut Decoder<'de, CHECKED>, ) -> Result<Self, CborError>

Decode Self from a streaming decoder. Read more
Source§

impl CborEncode for CborValueRef<'_>

Available on crate feature alloc only.
Source§

fn encode(&self, enc: &mut Encoder) -> Result<(), CborError>

Encode self into the provided encoder. Read more
Source§

impl<'a> Clone for CborValueRef<'a>

Source§

fn clone(&self) -> CborValueRef<'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 CborValueRef<'a>

Source§

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

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

impl<'de> Deserialize<'de> for CborValueRef<'de>

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for CborValueRef<'_>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl CborArrayElem for CborValueRef<'_>

Available on crate feature alloc only.
Source§

impl<'a> Copy for CborValueRef<'a>

Source§

impl Eq for CborValueRef<'_>

Auto Trait Implementations§

§

impl<'a> Freeze for CborValueRef<'a>

§

impl<'a> RefUnwindSafe for CborValueRef<'a>

§

impl<'a> Send for CborValueRef<'a>

§

impl<'a> Sync for CborValueRef<'a>

§

impl<'a> Unpin for CborValueRef<'a>

§

impl<'a> UnsafeUnpin for CborValueRef<'a>

§

impl<'a> UnwindSafe for CborValueRef<'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.