Reader

Trait Reader 

Source
pub trait Reader {
    // Required method
    fn read(&mut self, bytes: &mut [u8]) -> Result<(), DecodeError>;

    // Provided methods
    fn peek_read(&mut self, _: usize) -> Option<&[u8]> { ... }
    fn consume(&mut self, _: usize) { ... }
}
Expand description

A reader for owned data. See the module documentation for more information.

Required Methods§

Source

fn read(&mut self, bytes: &mut [u8]) -> Result<(), DecodeError>

Fill the given bytes argument with values. Exactly the length of the given slice must be filled, or else an error must be returned. Fill the given bytes argument with values. Exactly the length of the given slice must be filled, or else an error must be returned.

§Errors

Returns DecodeError::UnexpectedEnd if the reader does not have enough bytes.

Provided Methods§

Source

fn peek_read(&mut self, _: usize) -> Option<&[u8]>

If this reader wraps a buffer of any kind, this function lets callers access contents of the buffer without passing data through a buffer first.

Source

fn consume(&mut self, _: usize)

If an implementation of peek_read is provided, an implementation of this function must be provided so that subsequent reads or peek-reads do not return the same bytes

Implementations on Foreign Types§

Source§

impl<R> Reader for BufReader<R>
where R: Read,

Available on crate feature std only.
Source§

fn read(&mut self, bytes: &mut [u8]) -> Result<(), DecodeError>

Source§

fn peek_read(&mut self, n: usize) -> Option<&[u8]>

Source§

fn consume(&mut self, n: usize)

Source§

impl<T> Reader for &mut T
where T: Reader,

Source§

fn read(&mut self, bytes: &mut [u8]) -> Result<(), DecodeError>

Source§

fn peek_read(&mut self, n: usize) -> Option<&[u8]>

Source§

fn consume(&mut self, n: usize)

Implementors§

Source§

impl<'storage> Reader for SliceReader<'storage>

Source§

impl<R> Reader for IoReader<R>
where R: Read,

Available on crate feature std only.