pub trait Reader {
Show 42 methods fn remaining(&self) -> usize; fn chunk(&self) -> &[u8]Notable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]impl Reader for &[u8]impl Writer for &mut [u8]impl<T> Writable for &[T]where
    T: Writable + ByteSize,
; fn advance(&mut self, num_bytes: usize) -> Result<(), ReadError>; fn read<T>(&mut self) -> Result<T, ReadError>
   where
        T: Readable,
        Self: Sized
, { ... } fn read_with_size<T>(&mut self, num_bytes: usize) -> Result<T, ReadError>
   where
        T: ReadableWithSize,
        Self: Sized
, { ... } fn read_list<T>(&mut self, length: usize) -> Result<T, ReadError>
   where
        T: ReadableWithLength,
        Self: Sized
, { ... } fn read_bytes(&mut self, num_bytes: usize) -> Result<Vec<u8>, ReadError> { ... } fn has_remaining(&self) -> boolNotable traits for boolimpl Readable for boolimpl Writable for bool { ... } fn copy_to_slice(&mut self, slice: &mut [u8]) -> Result<(), ReadError> { ... } fn read_bool(&mut self) -> Result<bool, ReadError> { ... } fn read_u8(&mut self) -> Result<u8, ReadError> { ... } fn read_i8(&mut self) -> Result<i8, ReadError> { ... } fn read_u16_ne(&mut self) -> Result<u16, ReadError> { ... } fn read_i16_ne(&mut self) -> Result<i16, ReadError> { ... } fn read_u32_ne(&mut self) -> Result<u32, ReadError> { ... } fn read_i32_ne(&mut self) -> Result<i32, ReadError> { ... } fn read_u64_ne(&mut self) -> Result<u64, ReadError> { ... } fn read_i64_ne(&mut self) -> Result<i64, ReadError> { ... } fn read_u128_ne(&mut self) -> Result<u128, ReadError> { ... } fn read_i128_ne(&mut self) -> Result<i128, ReadError> { ... } fn read_f32_ne(&mut self) -> Result<f32, ReadError> { ... } fn read_f64_ne(&mut self) -> Result<f64, ReadError> { ... } fn read_u16_be(&mut self) -> Result<u16, ReadError> { ... } fn read_i16_be(&mut self) -> Result<i16, ReadError> { ... } fn read_u32_be(&mut self) -> Result<u32, ReadError> { ... } fn read_i32_be(&mut self) -> Result<i32, ReadError> { ... } fn read_u64_be(&mut self) -> Result<u64, ReadError> { ... } fn read_i64_be(&mut self) -> Result<i64, ReadError> { ... } fn read_u128_be(&mut self) -> Result<u128, ReadError> { ... } fn read_i128_be(&mut self) -> Result<i128, ReadError> { ... } fn read_f32_be(&mut self) -> Result<f32, ReadError> { ... } fn read_f64_be(&mut self) -> Result<f64, ReadError> { ... } fn read_u16_le(&mut self) -> Result<u16, ReadError> { ... } fn read_i16_le(&mut self) -> Result<i16, ReadError> { ... } fn read_u32_le(&mut self) -> Result<u32, ReadError> { ... } fn read_i32_le(&mut self) -> Result<i32, ReadError> { ... } fn read_u64_le(&mut self) -> Result<u64, ReadError> { ... } fn read_i64_le(&mut self) -> Result<i64, ReadError> { ... } fn read_u128_le(&mut self) -> Result<u128, ReadError> { ... } fn read_i128_le(&mut self) -> Result<i128, ReadError> { ... } fn read_f32_le(&mut self) -> Result<f32, ReadError> { ... } fn read_f64_le(&mut self) -> Result<f64, ReadError> { ... }
}
Expand description

Provides utilities to read data from buffers of bytes.

This trait is based on the implementation of the Buf trait in bytes. Its purpose in cornflakes is simply to provide utilities more specifically catered towards cornflakes’ ‘ecosystem’. Specifically, it works well with [ReadBytes], [ReadList], and [ReadSized], and it provides methods for reading data with the native endianness.

If the above functionality provided by cornflakes is not useful to you, you may wish to use bytes instead.

Required Methods

Returns the number of bytes remaining from the current position until the end of the Reader.

Returns a chunk of data starting at the current position and less than or equal to the number of remaining() bytes.

This method allows for a Reader to be stored non-contiguously; that is, the chunk() of data returned is not necessarily all of the bytes remaining() in the Reader.

This method may return a slice of zero bytes.

Advances the internal cursor of this Reader by num_bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if num_bytes is greater than remaining().

Implementation notes

This method should not panic. Return an appropriate ReadError instead.

Provided Methods

Reads a Readable type.

Reads a ReadableWithSize type with the given number of bytes.

Reads a [WritableWithLength] list of values with the given length.

Returns a Vec<u8> with a length of num_bytes bytes read from self.

Errors

This method returns a ReadError::NotEnoughRemaining error if num_bytes is greater than remaining().

Returns whether the number of bytes [remaining()] in this Reader is greater than zero.

Copies bytes from self to fill slice.

Errors

This method returns a ReadError::NotEnoughRemaining error if slice.len() is greater than remaining().

Reads a boolean value from one byte.

Advances the internal cursor by 1 byte.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is 0 bytes.

Reads an 8-bit unsigned integer.

Advances the internal cursor by 1 byte.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is 0 bytes.

Reads an 8-bit signed integer.

Advances the internal cursor by 1 byte.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is 0 bytes.

Reads a 16-bit unsigned integer with the native endianness.

Advances the internal cursor by 2 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 2 bytes.

Reads a 16-bit signed integer with the native endianness.

Advances the internal cursor by 2 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 2 bytes.

Reads a 32-bit unsigned integer with the native endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 4 bytes.

Reads a 32-bit signed integer with the native endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 4 bytes.

Reads a 64-bit unsigned integer with the native endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 8 bytes.

Reads a 64-bit signed integer with the native endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 8 bytes.

Reads a 128-bit unsigned integer with the native endianness.

Advances the internal cursor by 16 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 16 bytes.

Reads a 128-bit signed integer with the native endianness.

Advances the internal cursor by 16 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 16 bytes.

Reads a 32-bit floating point number with the native endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 4 bytes.

Reads a 64-bit floating point number with the native endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 8 bytes.

Reads a 16-bit unsigned integer with big endianness.

Advances the internal cursor by 2 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 2 bytes.

Reads a 16-bit signed integer with big endianness.

Advances the internal cursor by 2 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 2 bytes.

Reads a 32-bit unsigned integer with big endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 4 bytes.

Reads a 32-bit signed integer with big endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 4 bytes.

Reads a 64-bit unsigned integer with big endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 8 bytes.

Reads a 64-bit signed integer with big endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 8 bytes.

Reads a 128-bit unsigned integer with big endianness.

Advances the internal cursor by 16 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 16 bytes.

Reads a 128-bit signed integer with big endianness.

Advances the internal cursor by 16 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 16 bytes.

Reads a 32-bit floating point number with big endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 4 bytes.

Reads a 64-bit floating point number with big endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 8 bytes.

Reads a 16-bit unsigned integer with little endianness.

Advances the internal cursor by 2 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 2 bytes.

Reads a 16-bit signed integer with little endianness.

Advances the internal cursor by 2 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 2 bytes.

Reads a 32-bit unsigned integer with little endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 4 bytes.

Reads a 32-bit signed integer with little endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 4 bytes.

Reads a 64-bit unsigned integer with little endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 8 bytes.

Reads a 64-bit signed integer with little endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 8 bytes.

Reads a 128-bit unsigned integer with little endianness.

Advances the internal cursor by 16 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 16 bytes.

Reads a 128-bit signed integer with little endianness.

Advances the internal cursor by 16 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 16 bytes.

Reads a 32-bit floating point number with little endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 4 bytes.

Reads a 64-bit floating point number with little endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a ReadError::NotEnoughRemaining error if remaining() is less than 8 bytes.

Implementations on Foreign Types

Implementors