pub trait ByteRead {
// Required methods
fn read<V>(&mut self) -> Result<V, Error>
where V: Primitive;
fn read_as<F, V>(&mut self) -> Result<V, Error>
where F: Endianness,
V: Primitive;
fn skip(&mut self, bytes: u32) -> Result<()>;
fn reader_ref(&mut self) -> &mut dyn Read;
// Provided methods
fn read_bytes(&mut self, buf: &mut [u8]) -> Result<()> { ... }
fn read_to_bytes<const SIZE: usize>(&mut self) -> Result<[u8; SIZE]> { ... }
fn read_to_vec(&mut self, bytes: usize) -> Result<Vec<u8>> { ... }
fn parse<F: FromByteStream>(&mut self) -> Result<F, F::Error> { ... }
fn parse_with<'a, F: FromByteStreamWith<'a>>(
&mut self,
context: &F::Context,
) -> Result<F, F::Error> { ... }
fn parse_using<F: FromByteStreamUsing>(
&mut self,
context: F::Context,
) -> Result<F, F::Error> { ... }
}Expand description
A trait for anything that can read aligned values from an input stream
Required Methods§
Sourcefn read<V>(&mut self) -> Result<V, Error>where
V: Primitive,
fn read<V>(&mut self) -> Result<V, Error>where
V: Primitive,
Reads whole numeric value from stream
§Errors
Passes along any I/O error from the underlying stream.
§Examples
use std::io::Read;
use bitstream_io::{BigEndian, ByteReader, ByteRead};
let data = [0b00000000, 0b11111111];
let mut reader = ByteReader::endian(data.as_slice(), BigEndian);
assert_eq!(reader.read::<u16>().unwrap(), 0b0000000011111111);use std::io::Read;
use bitstream_io::{LittleEndian, ByteReader, ByteRead};
let data = [0b00000000, 0b11111111];
let mut reader = ByteReader::endian(data.as_slice(), LittleEndian);
assert_eq!(reader.read::<u16>().unwrap(), 0b1111111100000000);Sourcefn read_as<F, V>(&mut self) -> Result<V, Error>where
F: Endianness,
V: Primitive,
fn read_as<F, V>(&mut self) -> Result<V, Error>where
F: Endianness,
V: Primitive,
Reads whole numeric value from stream in a potentially different endianness
§Errors
Passes along any I/O error from the underlying stream.
§Examples
use std::io::Read;
use bitstream_io::{BigEndian, ByteReader, ByteRead, LittleEndian};
let data = [0b00000000, 0b11111111];
let mut reader = ByteReader::endian(data.as_slice(), BigEndian);
assert_eq!(reader.read_as::<LittleEndian, u16>().unwrap(), 0b1111111100000000);use std::io::Read;
use bitstream_io::{BigEndian, ByteReader, ByteRead, LittleEndian};
let data = [0b00000000, 0b11111111];
let mut reader = ByteReader::endian(data.as_slice(), LittleEndian);
assert_eq!(reader.read_as::<BigEndian, u16>().unwrap(), 0b0000000011111111);Sourcefn skip(&mut self, bytes: u32) -> Result<()>
fn skip(&mut self, bytes: u32) -> Result<()>
Skips the given number of bytes in the stream.
§Errors
Passes along any I/O error from the underlying stream.
Sourcefn reader_ref(&mut self) -> &mut dyn Read
fn reader_ref(&mut self) -> &mut dyn Read
Returns mutable reference to underlying reader
Provided Methods§
Sourcefn read_bytes(&mut self, buf: &mut [u8]) -> Result<()>
fn read_bytes(&mut self, buf: &mut [u8]) -> Result<()>
Completely fills the given buffer with whole bytes.
§Errors
Passes along any I/O error from the underlying stream.
Sourcefn read_to_bytes<const SIZE: usize>(&mut self) -> Result<[u8; SIZE]>
👎Deprecated since 1.8.0: use read() method instead
fn read_to_bytes<const SIZE: usize>(&mut self) -> Result<[u8; SIZE]>
use read() method instead
Completely fills a whole buffer with bytes and returns it.
§Errors
Passes along any I/O error from the underlying stream.
Sourcefn read_to_vec(&mut self, bytes: usize) -> Result<Vec<u8>>
Available on crate feature alloc only.
fn read_to_vec(&mut self, bytes: usize) -> Result<Vec<u8>>
alloc only.Completely fills a vector of bytes and returns it.
§Errors
Passes along any I/O error from the underlying stream.
Sourcefn parse<F: FromByteStream>(&mut self) -> Result<F, F::Error>
fn parse<F: FromByteStream>(&mut self) -> Result<F, F::Error>
Parses and returns complex type
Sourcefn parse_with<'a, F: FromByteStreamWith<'a>>(
&mut self,
context: &F::Context,
) -> Result<F, F::Error>
fn parse_with<'a, F: FromByteStreamWith<'a>>( &mut self, context: &F::Context, ) -> Result<F, F::Error>
Parses and returns complex type with context
Sourcefn parse_using<F: FromByteStreamUsing>(
&mut self,
context: F::Context,
) -> Result<F, F::Error>
fn parse_using<F: FromByteStreamUsing>( &mut self, context: F::Context, ) -> Result<F, F::Error>
Parses and returns complex type with owned context
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".