Struct untrusted::Reader[][src]

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

A read-only, forward-only* cursor into the data in an Input.

Using Reader to parse input helps to ensure that no byte of the input will be accidentally processed more than once. Using Reader in conjunction with read_all and read_all_optional helps ensure that no byte of the input is accidentally left unprocessed. The methods of Reader never panic, so Reader also assists the writing of panic-free code.

* Reader is not strictly forward-only because of the method get_input_between_marks, which is provided mainly to support calculating digests over parsed data.

Implementations

impl<'a> Reader<'a>[src]

pub fn new(input: Input<'a>) -> Self[src]

Construct a new Reader for the given input. Use read_all or read_all_optional instead of Reader::new whenever possible.

pub fn at_end(&self) -> bool[src]

Returns true if the reader is at the end of the input, and false otherwise.

pub fn get_input_between_marks(
    &self,
    mark1: Mark,
    mark2: Mark
) -> Result<Input<'a>, EndOfInput>
[src]

Returns an Input for already-parsed input that has had its boundaries marked using mark.

pub fn mark(&self) -> Mark[src]

Return the current position of the Reader for future use in a call to get_input_between_marks.

pub fn peek(&self, b: u8) -> bool[src]

Returns true if there is at least one more byte in the input and that byte is equal to b, and false otherwise.

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

Reads the next input byte.

Returns Ok(b) where b is the next input byte, or Err(EndOfInput) if the Reader is at the end of the input.

pub fn read_bytes(&mut self, num_bytes: usize) -> Result<Input<'a>, EndOfInput>[src]

Skips num_bytes of the input, returning the skipped input as an Input.

Returns Ok(i) if there are at least num_bytes of input remaining, and Err(EndOfInput) otherwise.

pub fn read_bytes_to_end(&mut self) -> Input<'a>[src]

Skips the reader to the end of the input, returning the skipped input as an Input.

pub fn read_partial<F, R, E>(&mut self, read: F) -> Result<(Input<'a>, R), E> where
    F: FnOnce(&mut Reader<'a>) -> Result<R, E>, 
[src]

Calls read() with the given input as a Reader. On success, returns a pair (bytes_read, r) where bytes_read is what read() consumed and r is read()’s return value.

pub fn skip(&mut self, num_bytes: usize) -> Result<(), EndOfInput>[src]

Skips num_bytes of the input.

Returns Ok(i) if there are at least num_bytes of input remaining, and Err(EndOfInput) otherwise.

pub fn skip_to_end(&mut self)[src]

Skips the reader to the end of the input.

Trait Implementations

impl<'a> Debug for Reader<'a>[src]

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<'a> Send for Reader<'a>

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

impl<'a> Unpin for Reader<'a>

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.