pub struct Reader<'a> { /* private fields */ }
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
, read_all_mut
, 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
sourceimpl<'a> Reader<'a>
impl<'a> Reader<'a>
sourcepub fn new(input: Input<'a>) -> Reader<'a>
pub fn new(input: Input<'a>) -> Reader<'a>
Construct a new Reader for the given input. Use read_all
,
read_all_mut
, or read_all_optional
instead of Reader::new
whenever possible.
sourcepub fn at_end(&self) -> bool
pub fn at_end(&self) -> bool
Returns true
if the reader is at the end of the input, and false
otherwise.
sourcepub fn get_input_between_marks(
&self,
mark1: Mark,
mark2: Mark
) -> Result<Input<'a>, EndOfInput>
pub fn get_input_between_marks(
&self,
mark1: Mark,
mark2: Mark
) -> Result<Input<'a>, EndOfInput>
Returns an Input
for already-parsed input that has had its boundaries
marked using mark
.
sourcepub fn mark(&self) -> Mark
pub fn mark(&self) -> Mark
Return the current position of the Reader
for future use in a call
to get_input_between_marks
.
sourcepub fn peek(&self, b: u8) -> bool
pub fn peek(&self, b: u8) -> bool
Returns true
if there is at least one more byte in the input and that
byte is equal to b
, and false otherwise.
sourcepub fn read_byte(&mut self) -> Result<u8, EndOfInput>
pub fn read_byte(&mut self) -> Result<u8, EndOfInput>
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.
sourcepub fn skip(&mut self, num_bytes: usize) -> Result<(), EndOfInput>
pub fn skip(&mut self, num_bytes: usize) -> Result<(), EndOfInput>
Skips num_bytes
of the input.
Returns Ok(())
if there are at least num_bytes
of input remaining,
and Err(EndOfInput)
otherwise.
sourcepub fn skip_and_get_input(
&mut self,
num_bytes: usize
) -> Result<Input<'a>, EndOfInput>
pub fn skip_and_get_input(
&mut self,
num_bytes: usize
) -> Result<Input<'a>, EndOfInput>
Skips num_bytes
of the input, returning the skipped input as an Input
.
Returns Ok(i)
where i
is an Input
if there are at least
num_bytes
of input remaining, and Err(EndOfInput)
otherwise.
sourcepub fn skip_to_end(&mut self) -> Input<'a>
pub fn skip_to_end(&mut self) -> Input<'a>
Skips the reader to the end of the input, returning the skipped input
as an Input
.
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for Reader<'a>
impl<'a> Send for Reader<'a>
impl<'a> Sync for Reader<'a>
impl<'a> Unpin for Reader<'a>
impl<'a> UnwindSafe for Reader<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more