Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder<'a> { /* private fields */ }
Expand description

A zero-copy, bounds-checked cursor over a byte slice.

Decoders are immutable views. Reading advances the internal cursor. Container reads return new Decoder instances restricted to the container’s body.

§Errors

All read operations return Error::UnexpectedEnd if the buffer is exhausted.

Implementations§

Source§

impl<'a> Decoder<'a>

Source

pub fn new(buf: &'a [u8]) -> Self

Creates a decoder over the slice.

Source

pub fn remaining(&self) -> usize

Returns the remaining bytes in the view.

Source

pub fn peek_tag(&self) -> Result<Tag>

Peeks the next Tag without advancing.

Source

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

Skips the next item and its nested children.

Source

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

Decodes a bool.

Source

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

Decodes u8.

Source

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

Decodes s8.

Source

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

Decodes u16 (LE).

Source

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

Decodes s16 (LE).

Source

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

Decodes u32 (LE).

Source

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

Decodes s32 (LE).

Source

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

Decodes u64 (LE).

Source

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

Decodes s64 (LE).

Source

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

Decodes f32 (LE).

Source

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

Decodes f64 (LE).

Source

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

Decodes char (u32 LE).

Source

pub fn unit(&mut self) -> Result<()>

Decodes Unit ().

Source

pub fn option_none(&mut self) -> Result<()>

Decodes Option::None.

Source

pub fn str(&mut self) -> Result<&'a str>

Decodes a string slice (UTF-8).

Source

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

Decodes a byte slice.

Source

pub fn list(&mut self) -> Result<ListIter<'a>>

Decodes a List into an iterator.

Source

pub fn map(&mut self) -> Result<MapIter<'a>>

Decodes a Map into an iterator.

Source

pub fn option(&mut self) -> Result<Option<Decoder<'a>>>

Decodes an Option.

Returns Some(Decoder) for the payload if present, or None.

Source

pub fn result(&mut self) -> Result<Result<Decoder<'a>, Decoder<'a>>>

Decodes a Result.

Returns Ok(Decoder) or Err(Decoder) for the respective payloads.

Source

pub fn variant(&mut self) -> Result<(&'a str, Decoder<'a>)>

Decodes a Variant.

Returns (Name, PayloadDecoder).

Trait Implementations§

Source§

impl<'a> Clone for Decoder<'a>

Source§

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

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Decoder<'a>

§

impl<'a> RefUnwindSafe for Decoder<'a>

§

impl<'a> Send for Decoder<'a>

§

impl<'a> Sync for Decoder<'a>

§

impl<'a> Unpin for Decoder<'a>

§

impl<'a> UnsafeUnpin for Decoder<'a>

§

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