pub struct Reader { /* private fields */ }
Expand description
Panic-free forward-only cursor. See the module level docs.
Implementations§
Source§impl Reader
impl Reader
Sourcepub fn new<T: Into<Bytes>>(bytes: T) -> Self
pub fn new<T: Into<Bytes>>(bytes: T) -> Self
Creates a new Reader from anything that implements Into<Bytes>
.
This does not allocate by itself, but the Into<Bytes>
implementation might.
Sourcepub fn peek(&self, val: u8) -> bool
pub fn peek(&self, val: u8) -> bool
Returns true
if there is another byte to read and it is equal to val
.
Sourcepub fn read_to_end(self) -> Bytes
pub fn read_to_end(self) -> Bytes
Returns the rest of the unread data, consuming the iterator.
Special behavior: If there are no bytes left, the inner value will be dropped, instead returning a Bytes pointing to a static, empty slice.
Sourcepub fn subreader(&mut self, len: usize) -> Result<Self, EndOfInput>
pub fn subreader(&mut self, len: usize) -> Result<Self, EndOfInput>
Returns a Reader
that can read the next len
bytes,
advancing the original cursor by the same amount.
Sourcepub fn read_byte(&mut self) -> Result<u8, EndOfInput>
pub fn read_byte(&mut self) -> Result<u8, EndOfInput>
Reads a single byte. Identical to read_u8
.
Sourcepub fn read_bytes(&mut self, len: usize) -> Result<Bytes, EndOfInput>
pub fn read_bytes(&mut self, len: usize) -> Result<Bytes, EndOfInput>
Returns the next len
bytes as a Bytes
, advancing the cursor.
Sourcepub fn read_slice(&mut self, len: usize) -> Result<&[u8], EndOfInput>
pub fn read_slice(&mut self, len: usize) -> Result<&[u8], EndOfInput>
Returns the next len
bytes as a slice, advancing the cursor.
The returned slice will always be of length len
.
Sourcepub fn read_array<const N: usize>(&mut self) -> Result<[u8; N], EndOfInput>
pub fn read_array<const N: usize>(&mut self) -> Result<[u8; N], EndOfInput>
Returns an array of size N
, advancing the cursor.
Sourcepub fn read<T: Decode>(&mut self) -> Result<T, EndOfInput>
pub fn read<T: Decode>(&mut self) -> Result<T, EndOfInput>
Attempts to read a value based on its Decode
implementation.