pub struct ReadAdapter<'a> { /* private fields */ }
Expand description
An adapter of ByteReader to any type that implements std::io::Read
In particular, this covers things like std::fs::File, standard input, etc.
Implementations§
source§impl<'a> ReadAdapter<'a>
impl<'a> ReadAdapter<'a>
sourcepub fn new(reader: &'a mut dyn Read) -> Self
pub fn new(reader: &'a mut dyn Read) -> Self
Create a new ByteReader adapter for the given implementation of std::io::Read
Trait Implementations§
source§impl<'a> ByteReader for ReadAdapter<'a>
impl<'a> ByteReader for ReadAdapter<'a>
source§fn peek_u8(&self) -> Result<u8, DeserializationError>
fn peek_u8(&self) -> Result<u8, DeserializationError>
NOTE: If we happen to not have any bytes buffered yet when this is called, then we will be forced to try and read from the underlying reader. This requires a mutable reference, which is obtained dynamically via RefCell.
Callers must ensure that they do not hold any immutable references to the buffer of this
reader when calling this function so as to avoid a situtation in which the dynamic borrow
check fails. Specifically, you must not be holding a reference to the result of
[Self::read_slice] when this function is called.
source§fn read_u8(&mut self) -> Result<u8, DeserializationError>
fn read_u8(&mut self) -> Result<u8, DeserializationError>
Returns a single byte read from
self
. Read moresource§fn read_slice(&mut self, len: usize) -> Result<&[u8], DeserializationError>
fn read_slice(&mut self, len: usize) -> Result<&[u8], DeserializationError>
Returns a slice of bytes of the specified length read from
self
. Read moresource§fn read_array<const N: usize>(
&mut self,
) -> Result<[u8; N], DeserializationError>
fn read_array<const N: usize>( &mut self, ) -> Result<[u8; N], DeserializationError>
source§fn check_eor(&self, num_bytes: usize) -> Result<(), DeserializationError>
fn check_eor(&self, num_bytes: usize) -> Result<(), DeserializationError>
Checks if it is possible to read at least
num_bytes
bytes from this ByteReader Read moresource§fn has_more_bytes(&self) -> bool
fn has_more_bytes(&self) -> bool
Returns true if there are more bytes left to be read from
self
.source§fn read_bool(&mut self) -> Result<bool, DeserializationError>
fn read_bool(&mut self) -> Result<bool, DeserializationError>
Returns a boolean value read from
self
consuming 1 byte from the reader. Read moresource§fn read_u16(&mut self) -> Result<u16, DeserializationError>
fn read_u16(&mut self) -> Result<u16, DeserializationError>
Returns a u16 value read from
self
in little-endian byte order. Read moresource§fn read_u32(&mut self) -> Result<u32, DeserializationError>
fn read_u32(&mut self) -> Result<u32, DeserializationError>
Returns a u32 value read from
self
in little-endian byte order. Read moresource§fn read_u64(&mut self) -> Result<u64, DeserializationError>
fn read_u64(&mut self) -> Result<u64, DeserializationError>
Returns a u64 value read from
self
in little-endian byte order. Read moresource§fn read_u128(&mut self) -> Result<u128, DeserializationError>
fn read_u128(&mut self) -> Result<u128, DeserializationError>
Returns a u128 value read from
self
in little-endian byte order. Read moresource§fn read_usize(&mut self) -> Result<usize, DeserializationError>
fn read_usize(&mut self) -> Result<usize, DeserializationError>
source§fn read_vec(&mut self, len: usize) -> Result<Vec<u8>, DeserializationError>
fn read_vec(&mut self, len: usize) -> Result<Vec<u8>, DeserializationError>
Returns a byte vector of the specified length read from
self
. Read moresource§fn read_string(
&mut self,
num_bytes: usize,
) -> Result<String, DeserializationError>
fn read_string( &mut self, num_bytes: usize, ) -> Result<String, DeserializationError>
Returns a String of the specified length read from
self
. Read moresource§fn read<D>(&mut self) -> Result<D, DeserializationError>where
Self: Sized,
D: Deserializable,
fn read<D>(&mut self) -> Result<D, DeserializationError>where
Self: Sized,
D: Deserializable,
Reads a deserializable value from
self
. Read moresource§fn read_many<D>(
&mut self,
num_elements: usize,
) -> Result<Vec<D>, DeserializationError>where
Self: Sized,
D: Deserializable,
fn read_many<D>(
&mut self,
num_elements: usize,
) -> Result<Vec<D>, DeserializationError>where
Self: Sized,
D: Deserializable,
Reads a sequence of bytes from
self
, attempts to deserialize these bytes into a vector
with the specified number of D
elements, and returns the result. Read moreAuto Trait Implementations§
impl<'a> !Freeze for ReadAdapter<'a>
impl<'a> !RefUnwindSafe for ReadAdapter<'a>
impl<'a> !Send for ReadAdapter<'a>
impl<'a> !Sync for ReadAdapter<'a>
impl<'a> Unpin for ReadAdapter<'a>
impl<'a> !UnwindSafe for ReadAdapter<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more