pub struct Decoder<'b> { /* private fields */ }
Expand description
A non-allocating CBOR decoder.
Implementations§
Source§impl<'b> Decoder<'b>
impl<'b> Decoder<'b>
Sourcepub fn decode<T: Decode<'b, ()>>(&mut self) -> Result<T, Error>
pub fn decode<T: Decode<'b, ()>>(&mut self) -> Result<T, Error>
Decode any type that implements Decode
.
Sourcepub fn decode_with<C, T: Decode<'b, C>>(
&mut self,
ctx: &mut C,
) -> Result<T, Error>
pub fn decode_with<C, T: Decode<'b, C>>( &mut self, ctx: &mut C, ) -> Result<T, Error>
Decode any type that implements Decode
.
Sourcepub fn set_position(&mut self, pos: usize)
pub fn set_position(&mut self, pos: usize)
Set the current decode position.
Sourcepub fn probe<'a>(&'a mut self) -> Probe<'a, 'b>
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.
Sourcepub fn int(&mut self) -> Result<Int, Error>
pub fn int(&mut self) -> Result<Int, Error>
Decode a CBOR integer.
See Int
for details regarding the value range of CBOR integers.
Sourcepub fn bytes(&mut self) -> Result<&'b [u8], Error>
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.
Sourcepub fn bytes_iter(&mut self) -> Result<BytesIter<'_, 'b>, Error>
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.
Sourcepub fn str(&mut self) -> Result<&'b str, Error>
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.
Sourcepub fn str_iter(&mut self) -> Result<StrIter<'_, 'b>, Error>
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.
Sourcepub fn array(&mut self) -> Result<Option<u64>, Error>
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.
Sourcepub fn array_iter<T>(&mut self) -> Result<ArrayIter<'_, 'b, T>, Error>
pub fn array_iter<T>(&mut self) -> Result<ArrayIter<'_, 'b, T>, Error>
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.
Sourcepub 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>,
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.
Sourcepub fn map(&mut self) -> Result<Option<u64>, Error>
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.
Sourcepub fn map_iter<K, V>(&mut self) -> Result<MapIter<'_, 'b, K, V>, Error>
pub fn map_iter<K, V>(&mut self) -> Result<MapIter<'_, 'b, K, V>, Error>
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.
Sourcepub fn map_iter_with<'a, C, K, V>(
&'a mut self,
ctx: &'a mut C,
) -> Result<MapIterWithCtx<'a, 'b, C, K, V>, Error>
pub fn map_iter_with<'a, C, K, V>( &'a mut self, ctx: &'a mut C, ) -> Result<MapIterWithCtx<'a, 'b, C, K, V>, Error>
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.
Trait Implementations§
Auto Trait Implementations§
impl<'b> Freeze for Decoder<'b>
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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