ReadExt

Trait ReadExt 

Source
pub trait ReadExt: EndianExt {
Show 15 methods // Required methods fn read_exact<const N: usize>(&mut self) -> Result<[u8; N], DataError>; fn read_length(&mut self, buffer: &mut [u8]) -> Result<usize, DataError>; fn read_slice(&mut self, length: usize) -> Result<Cow<'_, [u8]>, DataError>; fn remaining_slice(&mut self) -> Result<Cow<'_, [u8]>, DataError>; // Provided methods fn read_string(&mut self, length: usize) -> Result<Cow<'_, str>, DataError> { ... } fn read_u8(&mut self) -> Result<u8, DataError> { ... } fn read_i8(&mut self) -> Result<i8, DataError> { ... } fn read_u16(&mut self) -> Result<u16, DataError> { ... } fn read_i16(&mut self) -> Result<i16, DataError> { ... } fn read_u32(&mut self) -> Result<u32, DataError> { ... } fn read_i32(&mut self) -> Result<i32, DataError> { ... } fn read_u64(&mut self) -> Result<u64, DataError> { ... } fn read_i64(&mut self) -> Result<i64, DataError> { ... } fn read_f32(&mut self) -> Result<f32, DataError> { ... } fn read_f64(&mut self) -> Result<f64, DataError> { ... }
}
Expand description

Trait for types that support reading operations.

Required Methods§

Source

fn read_exact<const N: usize>(&mut self) -> Result<[u8; N], DataError>

Reads exactly N bytes from the current stream.

§Errors

Returns EndOfFile if trying to read out of bounds.

Source

fn read_length(&mut self, buffer: &mut [u8]) -> Result<usize, DataError>

Attempts to fill the buffer with data.

§Errors

Returns EndOfFile if trying to read out of bounds.

Source

fn read_slice(&mut self, length: usize) -> Result<Cow<'_, [u8]>, DataError>

Reads a slice of the given length from the current position.

§Errors

Returns EndOfFile if trying to read out of bounds.

Source

fn remaining_slice(&mut self) -> Result<Cow<'_, [u8]>, DataError>

Returns the remaining data from the current position.

§Errors

Returns an error if the remaining data cannot be read.

Provided Methods§

Source

fn read_string(&mut self, length: usize) -> Result<Cow<'_, str>, DataError>

Reads a UTF-8 encoded string of the given length from the current position.

§Errors

Returns EndOfFile if trying to read out of bounds. Returns InvalidStr if the bytes are not valid UTF-8.

Source

fn read_u8(&mut self) -> Result<u8, DataError>

Reads an unsigned 8-bit integer.

§Errors

Returns EndOfFile if trying to read out of bounds.

Source

fn read_i8(&mut self) -> Result<i8, DataError>

Reads a signed 8-bit integer.

§Errors

Returns EndOfFile if trying to read out of bounds.

Source

fn read_u16(&mut self) -> Result<u16, DataError>

Reads an unsigned 16-bit integer.

§Errors

Returns EndOfFile if trying to read out of bounds.

Source

fn read_i16(&mut self) -> Result<i16, DataError>

Reads a signed 16-bit integer.

§Errors

Returns EndOfFile if trying to read out of bounds.

Source

fn read_u32(&mut self) -> Result<u32, DataError>

Reads an unsigned 32-bit integer.

§Errors

Returns EndOfFile if trying to read out of bounds.

Source

fn read_i32(&mut self) -> Result<i32, DataError>

Reads a signed 32-bit integer.

§Errors

Returns EndOfFile if trying to read out of bounds.

Source

fn read_u64(&mut self) -> Result<u64, DataError>

Reads an unsigned 64-bit integer.

§Errors

Returns EndOfFile if trying to read out of bounds.

Source

fn read_i64(&mut self) -> Result<i64, DataError>

Reads a signed 64-bit integer.

§Errors

Returns EndOfFile if trying to read out of bounds.

Source

fn read_f32(&mut self) -> Result<f32, DataError>

Reads a 32-bit floating point number.

§Errors

Returns EndOfFile if trying to read out of bounds.

Source

fn read_f64(&mut self) -> Result<f64, DataError>

Reads a 64-bit floating point number.

§Errors

Returns EndOfFile if trying to read out of bounds.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§