Skip to main content

BytesRead

Trait BytesRead 

Source
pub trait BytesRead {
Show 54 methods // Required methods fn as_slice(&self) -> &[u8] ; fn remaining(&self) -> &[u8] ; fn try_read(&mut self, len: usize) -> Result<&[u8], ReadError>; fn peek(&self, len: usize) -> Option<&[u8]>; // Provided methods fn len(&self) -> usize { ... } fn read(&mut self, len: usize) -> &[u8] { ... } fn try_read_u8(&mut self) -> Result<u8, ReadError> { ... } fn read_u8(&mut self) -> u8 { ... } fn try_read_u16(&mut self) -> Result<u16, ReadError> { ... } fn read_u16(&mut self) -> u16 { ... } fn try_read_u32(&mut self) -> Result<u32, ReadError> { ... } fn read_u32(&mut self) -> u32 { ... } fn try_read_u64(&mut self) -> Result<u64, ReadError> { ... } fn read_u64(&mut self) -> u64 { ... } fn try_read_u128(&mut self) -> Result<u128, ReadError> { ... } fn read_u128(&mut self) -> u128 { ... } fn try_read_i8(&mut self) -> Result<i8, ReadError> { ... } fn read_i8(&mut self) -> i8 { ... } fn try_read_i16(&mut self) -> Result<i16, ReadError> { ... } fn read_i16(&mut self) -> i16 { ... } fn try_read_i32(&mut self) -> Result<i32, ReadError> { ... } fn read_i32(&mut self) -> i32 { ... } fn try_read_i64(&mut self) -> Result<i64, ReadError> { ... } fn read_i64(&mut self) -> i64 { ... } fn try_read_i128(&mut self) -> Result<i128, ReadError> { ... } fn read_i128(&mut self) -> i128 { ... } fn try_read_f32(&mut self) -> Result<f32, ReadError> { ... } fn read_f32(&mut self) -> f32 { ... } fn try_read_f64(&mut self) -> Result<f64, ReadError> { ... } fn read_f64(&mut self) -> f64 { ... } fn try_read_le_u8(&mut self) -> Result<u8, ReadError> { ... } fn read_le_u8(&mut self) -> u8 { ... } fn try_read_le_u16(&mut self) -> Result<u16, ReadError> { ... } fn read_le_u16(&mut self) -> u16 { ... } fn try_read_le_u32(&mut self) -> Result<u32, ReadError> { ... } fn read_le_u32(&mut self) -> u32 { ... } fn try_read_le_u64(&mut self) -> Result<u64, ReadError> { ... } fn read_le_u64(&mut self) -> u64 { ... } fn try_read_le_u128(&mut self) -> Result<u128, ReadError> { ... } fn read_le_u128(&mut self) -> u128 { ... } fn try_read_le_i8(&mut self) -> Result<i8, ReadError> { ... } fn read_le_i8(&mut self) -> i8 { ... } fn try_read_le_i16(&mut self) -> Result<i16, ReadError> { ... } fn read_le_i16(&mut self) -> i16 { ... } fn try_read_le_i32(&mut self) -> Result<i32, ReadError> { ... } fn read_le_i32(&mut self) -> i32 { ... } fn try_read_le_i64(&mut self) -> Result<i64, ReadError> { ... } fn read_le_i64(&mut self) -> i64 { ... } fn try_read_le_i128(&mut self) -> Result<i128, ReadError> { ... } fn read_le_i128(&mut self) -> i128 { ... } fn try_read_le_f32(&mut self) -> Result<f32, ReadError> { ... } fn read_le_f32(&mut self) -> f32 { ... } fn try_read_le_f64(&mut self) -> Result<f64, ReadError> { ... } fn read_le_f64(&mut self) -> f64 { ... }
}
Expand description

Read bytes or numbers.

Required Methods§

Source

fn as_slice(&self) -> &[u8]

Returns the entire slice.

Source

fn remaining(&self) -> &[u8]

Returns all remaining bytes.

Source

fn try_read(&mut self, len: usize) -> Result<&[u8], ReadError>

Try to read a given length of bytes.

§Failes

If len exceeds self.remaining().len().

Source

fn peek(&self, len: usize) -> Option<&[u8]>

Tries to read a given length without updating the internal position. Returns None if there are not enought bytes remaining.

Provided Methods§

Source

fn len(&self) -> usize

Returns the length of the entire slice.

Source

fn read(&mut self, len: usize) -> &[u8]

Reads a given length of bytes.

§Panics

If len exceeds self.remaining().len().

Source

fn try_read_u8(&mut self) -> Result<u8, ReadError>

Try to read 1 bytes in big-endian converting them into an u8.

Source

fn read_u8(&mut self) -> u8

Reads 1 bytes in big-endian converting them into an u8.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_u16(&mut self) -> Result<u16, ReadError>

Try to read 2 bytes in big-endian converting them into an u16.

Source

fn read_u16(&mut self) -> u16

Reads 2 bytes in big-endian converting them into an u16.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_u32(&mut self) -> Result<u32, ReadError>

Try to read 4 bytes in big-endian converting them into an u32.

Source

fn read_u32(&mut self) -> u32

Reads 4 bytes in big-endian converting them into an u32.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_u64(&mut self) -> Result<u64, ReadError>

Try to read 8 bytes in big-endian converting them into an u64.

Source

fn read_u64(&mut self) -> u64

Reads 8 bytes in big-endian converting them into an u64.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_u128(&mut self) -> Result<u128, ReadError>

Try to read 16 bytes in big-endian converting them into an u128.

Source

fn read_u128(&mut self) -> u128

Reads 16 bytes in big-endian converting them into an u128.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_i8(&mut self) -> Result<i8, ReadError>

Try to read 1 bytes in big-endian converting them into an i8.

Source

fn read_i8(&mut self) -> i8

Reads 1 bytes in big-endian converting them into an i8.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_i16(&mut self) -> Result<i16, ReadError>

Try to read 2 bytes in big-endian converting them into an i16.

Source

fn read_i16(&mut self) -> i16

Reads 2 bytes in big-endian converting them into an i16.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_i32(&mut self) -> Result<i32, ReadError>

Try to read 4 bytes in big-endian converting them into an i32.

Source

fn read_i32(&mut self) -> i32

Reads 4 bytes in big-endian converting them into an i32.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_i64(&mut self) -> Result<i64, ReadError>

Try to read 8 bytes in big-endian converting them into an i64.

Source

fn read_i64(&mut self) -> i64

Reads 8 bytes in big-endian converting them into an i64.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_i128(&mut self) -> Result<i128, ReadError>

Try to read 16 bytes in big-endian converting them into an i128.

Source

fn read_i128(&mut self) -> i128

Reads 16 bytes in big-endian converting them into an i128.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_f32(&mut self) -> Result<f32, ReadError>

Try to read 4 bytes in big-endian converting them into an f32.

Source

fn read_f32(&mut self) -> f32

Reads 4 bytes in big-endian converting them into an f32.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_f64(&mut self) -> Result<f64, ReadError>

Try to read 8 bytes in big-endian converting them into an f64.

Source

fn read_f64(&mut self) -> f64

Reads 8 bytes in big-endian converting them into an f64.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_le_u8(&mut self) -> Result<u8, ReadError>

Try to read 1 bytes in little-endian converting them into an u8.

Source

fn read_le_u8(&mut self) -> u8

Reads 1 bytes in little-endian converting them into an u8.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_le_u16(&mut self) -> Result<u16, ReadError>

Try to read 2 bytes in little-endian converting them into an u16.

Source

fn read_le_u16(&mut self) -> u16

Reads 2 bytes in little-endian converting them into an u16.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_le_u32(&mut self) -> Result<u32, ReadError>

Try to read 4 bytes in little-endian converting them into an u32.

Source

fn read_le_u32(&mut self) -> u32

Reads 4 bytes in little-endian converting them into an u32.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_le_u64(&mut self) -> Result<u64, ReadError>

Try to read 8 bytes in little-endian converting them into an u64.

Source

fn read_le_u64(&mut self) -> u64

Reads 8 bytes in little-endian converting them into an u64.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_le_u128(&mut self) -> Result<u128, ReadError>

Try to read 16 bytes in little-endian converting them into an u128.

Source

fn read_le_u128(&mut self) -> u128

Reads 16 bytes in little-endian converting them into an u128.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_le_i8(&mut self) -> Result<i8, ReadError>

Try to read 1 bytes in little-endian converting them into an i8.

Source

fn read_le_i8(&mut self) -> i8

Reads 1 bytes in little-endian converting them into an i8.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_le_i16(&mut self) -> Result<i16, ReadError>

Try to read 2 bytes in little-endian converting them into an i16.

Source

fn read_le_i16(&mut self) -> i16

Reads 2 bytes in little-endian converting them into an i16.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_le_i32(&mut self) -> Result<i32, ReadError>

Try to read 4 bytes in little-endian converting them into an i32.

Source

fn read_le_i32(&mut self) -> i32

Reads 4 bytes in little-endian converting them into an i32.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_le_i64(&mut self) -> Result<i64, ReadError>

Try to read 8 bytes in little-endian converting them into an i64.

Source

fn read_le_i64(&mut self) -> i64

Reads 8 bytes in little-endian converting them into an i64.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_le_i128(&mut self) -> Result<i128, ReadError>

Try to read 16 bytes in little-endian converting them into an i128.

Source

fn read_le_i128(&mut self) -> i128

Reads 16 bytes in little-endian converting them into an i128.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_le_f32(&mut self) -> Result<f32, ReadError>

Try to read 4 bytes in little-endian converting them into an f32.

Source

fn read_le_f32(&mut self) -> f32

Reads 4 bytes in little-endian converting them into an f32.

§Panics

If there aren’t enough bytes left.

Source

fn try_read_le_f64(&mut self) -> Result<f64, ReadError>

Try to read 8 bytes in little-endian converting them into an f64.

Source

fn read_le_f64(&mut self) -> f64

Reads 8 bytes in little-endian converting them into an f64.

§Panics

If there aren’t enough bytes left.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<R: BytesRead> BytesRead for &mut R

Source§

fn as_slice(&self) -> &[u8]

Source§

fn remaining(&self) -> &[u8]

Source§

fn try_read(&mut self, len: usize) -> Result<&[u8], ReadError>

Source§

fn peek(&self, len: usize) -> Option<&[u8]>

Implementors§

Source§

impl BytesRead for Bytes<'_>

Source§

impl BytesRead for BytesMut<'_>

Source§

impl BytesRead for BytesOwned

Source§

impl<T> BytesRead for Cursor<T>
where T: AsRef<[u8]>,

Source§

impl<T> BytesRead for Offset<T>
where T: BytesRead,

Source§

impl<const N: usize> BytesRead for BytesArray<N>