Struct minicbor::decode::Decoder[][src]

pub struct Decoder<'b> { /* fields omitted */ }

A non-allocating CBOR decoder.

Implementations

impl<'b> Decoder<'b>[src]

pub fn new(bytes: &'b [u8]) -> Self[src]

Construct a Decoder for the given byte slice.

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

Decode any type that implements Decode.

pub fn position(&self) -> usize[src]

Get the current decode position.

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

Set the current decode position.

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

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.

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

Decode a bool value.

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

Decode a u8 value.

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

Decode a u16 value.

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

Decode a u32 value.

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

Decode a u64 value.

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

Decode an i8 value.

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

Decode an i16 value.

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

Decode an i32 value.

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

Decode an i64 value.

pub fn f16(&mut self) -> Result<f32, Error>[src]

Decode a half float (f16) and return it in an f32.

Only available when the feature half is present.

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

Decode an f32 value.

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

Decode an f64 value.

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

Decode a char value.

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

Decode a byte slice.

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

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

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.

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

Decode a string slice.

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

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

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.

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

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.

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

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.

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

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.

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

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.

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

Decode a CBOR tag.

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

Decode a CBOR simple value.

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

Inspect the CBOR type at the current position.

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

Skip over the current CBOR value.

Trait Implementations

impl<'b> Clone for Decoder<'b>[src]

impl<'b> Debug for Decoder<'b>[src]

impl<'b> From<Decoder<'b>> for Tokenizer<'b>[src]

Auto Trait Implementations

impl<'b> RefUnwindSafe for Decoder<'b>

impl<'b> Send for Decoder<'b>

impl<'b> Sync for Decoder<'b>

impl<'b> Unpin for Decoder<'b>

impl<'b> UnwindSafe for Decoder<'b>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.