Skip to main content

Reader

Struct Reader 

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

A cursor over bytes that reads what the writers above write, and refuses every other spelling: a number in more bytes than it needs, a text that is not UTF-8, and anything that runs past the end.

A refusal is a DecodeError with an empty path, which says at which byte it happened; whoever reads a value at a type puts its path in.

Implementations§

Source§

impl<'a> Reader<'a>

Source

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

A cursor at the first of bytes.

Source

pub fn position(&self) -> usize

How many bytes have been read.

Source

pub fn remaining(&self) -> usize

How many bytes are left.

Source

pub fn is_empty(&self) -> bool

Whether every byte has been read.

Source

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

The next byte.

§Errors

A DecodeError when no bytes are left.

Source

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

The next Bool: one byte, 0 or 1.

§Errors

A DecodeError when no bytes are left or the byte is another.

Source

pub fn take(&mut self, count: usize) -> Result<&'a [u8], DecodeError>

The next count bytes.

§Errors

A DecodeError when fewer than count bytes are left.

Source

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

The next number, which must fit 64 bits.

§Errors

A DecodeError when the input ends inside the number, it takes more bytes than it needs, or it does not fit 64 bits.

Source

pub fn count(&mut self) -> Result<usize, DecodeError>

The next number as an index or length: one that fits this host’s addresses.

§Errors

As Reader::uint, and when the number does not fit a usize.

Source

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

The next signed number, which must fit 64 bits.

§Errors

As Reader::uint.

Source

pub fn biguint(&mut self, max_bits: u64) -> Result<BigUint, DecodeError>

The next number, of any size up to max_bits bits. A longer one is refused as a limit, as soon as it is known to be longer and before the rest of it is read.

§Errors

A DecodeError when the input ends inside the number or it takes more bytes than it needs, and a limit when it is longer than max_bits bits.

Source

pub fn int(&mut self, limits: &Limits) -> Result<BigInt, DecodeError>

The next signed number, of any size, refused as a limit when its magnitude takes more than Limits::int_bits.

§Errors

As Reader::biguint, with Limits::int_bits as its bound.

Source

pub fn bytes(&mut self, limits: &Limits) -> Result<&'a [u8], DecodeError>

The next run of bytes, its length first, refused as a limit when it is longer than Limits::text_bytes.

§Errors

A DecodeError when the length does not read, is past the limit, or is more than the bytes left.

Source

pub fn text(&mut self, limits: &Limits) -> Result<&'a str, DecodeError>

The next text, its length first: valid UTF-8, and refused as a limit when it is longer than Limits::text_bytes.

§Errors

As Reader::bytes, and when the bytes are not UTF-8.

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<'a> Debug for Reader<'a>

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> Same for T

Source§

type Output = T

Should always be Self
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.