Trait bitstream_io::read::ByteRead
source · pub trait ByteRead {
// Required methods
fn read<V: Primitive>(&mut self) -> Result<V, Error>;
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<F: FromByteStreamWith>(
&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: Primitive>(&mut self) -> Result<V, Error>
fn read<V: Primitive>(&mut self) -> Result<V, Error>
Reads whole numeric value from stream
§Errors
Passes along any I/O error from the underlying stream.
§Examples
use std::io::{Read, Cursor};
use bitstream_io::{BigEndian, ByteReader, ByteRead};
let data = [0b00000000, 0b11111111];
let mut reader = ByteReader::endian(Cursor::new(&data), BigEndian);
assert_eq!(reader.read::<u16>().unwrap(), 0b0000000011111111);
use std::io::{Read, Cursor};
use bitstream_io::{LittleEndian, ByteReader, ByteRead};
let data = [0b00000000, 0b11111111];
let mut reader = ByteReader::endian(Cursor::new(&data), LittleEndian);
assert_eq!(reader.read::<u16>().unwrap(), 0b1111111100000000);
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]>
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>>
fn read_to_vec(&mut self, bytes: usize) -> Result<Vec<u8>>
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<F: FromByteStreamWith>(
&mut self,
context: &F::Context
) -> Result<F, F::Error>
fn parse_with<F: FromByteStreamWith>( &mut self, context: &F::Context ) -> Result<F, F::Error>
Parses and returns complex type with context
Object Safety§
This trait is not object safe.