minicbor::decode

Struct Probe

Source
pub struct Probe<'a, 'b> { /* private fields */ }
Expand description

A decoding probe to to look ahead what comes next.

A Probe derefs to Decoder and thus can be used like one without affecting the decoder from which it was created.

Methods from Deref<Target = Decoder<'b>>§

Source

pub fn decode<T: Decode<'b, ()>>(&mut self) -> Result<T, Error>

Decode any type that implements Decode.

Source

pub fn decode_with<C, T: Decode<'b, C>>( &mut self, ctx: &mut C, ) -> Result<T, Error>

Decode any type that implements Decode.

Source

pub fn position(&self) -> usize

Get the current decode position.

Source

pub fn set_position(&mut self, pos: usize)

Set the current decode position.

Source

pub fn input(&self) -> &'b [u8]

Get a reference to the input bytes.

Source

pub fn probe<'a>(&'a mut self) -> Probe<'a, 'b>

Get a decoding probe to look ahead what is coming next.

This will not affect the decoding state of self and after the returned Probe has been dropped, decoding can continue from its current position as if probe was never called.

Source

pub fn bool(&mut self) -> Result<bool, Error>

Decode a bool value.

Source

pub fn u8(&mut self) -> Result<u8, Error>

Decode a u8 value.

Source

pub fn u16(&mut self) -> Result<u16, Error>

Decode a u16 value.

Source

pub fn u32(&mut self) -> Result<u32, Error>

Decode a u32 value.

Source

pub fn u64(&mut self) -> Result<u64, Error>

Decode a u64 value.

Source

pub fn i8(&mut self) -> Result<i8, Error>

Decode an i8 value.

Source

pub fn i16(&mut self) -> Result<i16, Error>

Decode an i16 value.

Source

pub fn i32(&mut self) -> Result<i32, Error>

Decode an i32 value.

Source

pub fn i64(&mut self) -> Result<i64, Error>

Decode an i64 value.

Source

pub fn int(&mut self) -> Result<Int, Error>

Decode a CBOR integer.

See Int for details regarding the value range of CBOR integers.

Source

pub fn f32(&mut self) -> Result<f32, Error>

Decode an f32 value.

Source

pub fn f64(&mut self) -> Result<f64, Error>

Decode an f64 value.

Source

pub fn char(&mut self) -> Result<char, Error>

Decode a char value.

Source

pub fn bytes(&mut self) -> Result<&'b [u8], Error>

Decode a byte slice.

This only decodes byte slices of definite lengths. See Decoder::bytes_iter for indefinite byte slice support.

Source

pub fn bytes_iter(&mut self) -> Result<BytesIter<'_, 'b>, Error>

Iterate over byte slices.

This supports indefinite byte slices by returing a byte slice on each iterator step. If a single definite slice is decoded the iterator will only yield one item.

Source

pub fn str(&mut self) -> Result<&'b str, Error>

Decode a string slice.

This only decodes string slices of definite lengths. See Decoder::str_iter for indefinite string slice support.

Source

pub fn str_iter(&mut self) -> Result<StrIter<'_, 'b>, Error>

Iterate over string slices.

This supports indefinite string slices by returing a string slice on each iterator step. If a single definite slice is decoded the iterator will only yield one item.

Source

pub fn array(&mut self) -> Result<Option<u64>, Error>

Begin decoding an array.

CBOR arrays are heterogenous collections and may be of indefinite length. If the length is known it is returned as a Some, for indefinite arrays a None is returned.

Source

pub fn array_iter<T>(&mut self) -> Result<ArrayIter<'_, 'b, T>, Error>
where T: Decode<'b, ()>,

Iterate over all array elements.

This supports indefinite and definite length arrays and uses the Decode trait to decode each element. Consequently only homogenous arrays are supported by this method.

Source

pub fn array_iter_with<'a, C, T>( &'a mut self, ctx: &'a mut C, ) -> Result<ArrayIterWithCtx<'a, 'b, C, T>, Error>
where T: Decode<'b, C>,

Iterate over all array elements.

This supports indefinite and definite length arrays and uses the Decode trait to decode each element. Consequently only homogenous arrays are supported by this method.

Source

pub fn map(&mut self) -> Result<Option<u64>, Error>

Begin decoding a map.

CBOR maps are heterogenous collections (both in keys and in values) and may be of indefinite length. If the length is known it is returned as a Some, for indefinite maps a None is returned.

Source

pub fn map_iter<K, V>(&mut self) -> Result<MapIter<'_, 'b, K, V>, Error>
where K: Decode<'b, ()>, V: Decode<'b, ()>,

Iterate over all map entries.

This supports indefinite and definite length maps and uses the Decode trait to decode each key and value. Consequently only homogenous maps are supported by this method.

Source

pub fn map_iter_with<'a, C, K, V>( &'a mut self, ctx: &'a mut C, ) -> Result<MapIterWithCtx<'a, 'b, C, K, V>, Error>
where K: Decode<'b, C>, V: Decode<'b, C>,

Iterate over all map entries.

This supports indefinite and definite length maps and uses the Decode trait to decode each key and value. Consequently only homogenous maps are supported by this method.

Source

pub fn tag(&mut self) -> Result<Tag, Error>

Decode a CBOR tag.

Source

pub fn null(&mut self) -> Result<(), Error>

Decode a CBOR null value.

Source

pub fn undefined(&mut self) -> Result<(), Error>

Decode a CBOR undefined value.

Source

pub fn simple(&mut self) -> Result<u8, Error>

Decode a CBOR simple value.

Source

pub fn datatype(&self) -> Result<Type, Error>

Inspect the CBOR type at the current position.

Source

pub fn skip(&mut self) -> Result<(), Error>

Skip over the current CBOR value.

Without feature alloc, skipping over maps or arrays that contain an indefinite-length map or array will return an error.

Trait Implementations§

Source§

impl<'a, 'b> Debug for Probe<'a, 'b>

Source§

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

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

impl<'b> Deref for Probe<'_, 'b>

Source§

type Target = Decoder<'b>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'b> DerefMut for Probe<'_, 'b>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<'a, 'b> Freeze for Probe<'a, 'b>

§

impl<'a, 'b> RefUnwindSafe for Probe<'a, 'b>

§

impl<'a, 'b> Send for Probe<'a, 'b>

§

impl<'a, 'b> Sync for Probe<'a, 'b>

§

impl<'a, 'b> Unpin for Probe<'a, 'b>

§

impl<'a, 'b> !UnwindSafe for Probe<'a, 'b>

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 12 bytes