Skip to main content

Reader

Struct Reader 

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

A cursor over SML bytes. Never allocates and never panics.

Debug shows the position and length, never the bytes: they may hold credentials.

Implementations§

Source§

impl<'a> Reader<'a>

Source

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

A reader at the start of buf.

Source

pub const fn position(&self) -> usize

Bytes consumed so far.

Source

pub const fn is_empty(&self) -> bool

Whether every byte has been consumed.

Source

pub const fn buffer(&self) -> &'a [u8] ⓘ

The underlying buffer.

Source

pub fn peek(&self) -> Option<u8>

The next byte, without consuming it.

Source

pub fn slice(&self, from: usize, to: usize) -> Result<&'a [u8]>

The bytes between two positions of this reader.

Source

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

Consume the end-of-message byte.

Source

pub fn absent(&mut self) -> bool

Consume an absent-field marker if one is next. Returns whether it was.

Source

pub fn read_tl(&mut self) -> Result<Tl>

Read one type-length field.

Source

pub fn list(&mut self, n: usize) -> Result<()>

Read a list header and require exactly n elements.

Source

pub fn list_any(&mut self) -> Result<usize>

Read a list header of any length and return the element count.

Source

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

Read an octet string. An absent marker reads as an empty string.

Source

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

Read an optional octet string.

Source

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

Read a boolean.

Source

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

Read an unsigned integer of 1 to 8 bytes.

Source

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

Read an optional unsigned integer.

Source

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

Read a signed integer of 1 to 8 bytes.

Source

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

Read an optional signed integer.

Source

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

Skip one value of any type, following lists up to MAX_DEPTH.

Trait Implementations§

Source§

impl<'a> Clone for Reader<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Reader<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Forget for Reader<'a>

§

impl<'a> Freeze for Reader<'a>
where &'a [u8]: Freeze,

§

impl<'a> Move for Reader<'a>

§

impl<'a> RefUnwindSafe for Reader<'a>

§

impl<'a> Send for Reader<'a>
where &'a [u8]: Send,

§

impl<'a> Sync for Reader<'a>

§

impl<'a> Unpin for Reader<'a>
where &'a [u8]: Unpin,

§

impl<'a> UnsafeUnpin for Reader<'a>
where &'a [u8]: UnsafeUnpin,

§

impl<'a> UnwindSafe for Reader<'a>
where &'a [u8]: UnwindSafe,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.