Struct winter_utils::SliceReader

source ·
pub struct SliceReader<'a> { /* private fields */ }
Expand description

Implements ByteReader trait for a slice of bytes.

NOTE: If you are building with the std feature, you should probably prefer std::io::Cursor instead. However, SliceReader is still useful in no-std environments until stabilization of the core_io_borrowed_buf feature.

Implementations§

source§

impl<'a> SliceReader<'a>

source

pub fn new(source: &'a [u8]) -> Self

Creates a new slice reader from the specified slice.

Trait Implementations§

source§

impl<'a> ByteReader for SliceReader<'a>

source§

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

Returns a single byte read from self. Read more
source§

fn peek_u8(&self) -> Result<u8, DeserializationError>

Returns the next byte to be read from self without advancing the reader to the next byte. Read more
source§

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

Returns a slice of bytes of the specified length read from self. Read more
source§

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

Returns a byte array of length N read from self. Read more
source§

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 more
source§

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>

Returns a boolean value read from self consuming 1 byte from the reader. Read more
source§

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

Returns a u16 value read from self in little-endian byte order. Read more
source§

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

Returns a u32 value read from self in little-endian byte order. Read more
source§

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

Returns a u64 value read from self in little-endian byte order. Read more
source§

fn read_u128(&mut self) -> Result<u128, DeserializationError>

Returns a u128 value read from self in little-endian byte order. Read more
source§

fn read_usize(&mut self) -> Result<usize, DeserializationError>

Returns a usize value read from self in vint64 format. Read more
source§

fn read_vec(&mut self, len: usize) -> Result<Vec<u8>, DeserializationError>

Returns a byte vector of the specified length read from self. Read more
source§

fn read_string( &mut self, num_bytes: usize ) -> Result<String, DeserializationError>

Returns a String of the specified length read from self. Read more
source§

fn read<D>(&mut self) -> Result<D, DeserializationError>
where Self: Sized, D: Deserializable,

Reads a deserializable value from self. Read more
source§

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 more

Auto Trait Implementations§

§

impl<'a> Freeze for SliceReader<'a>

§

impl<'a> RefUnwindSafe for SliceReader<'a>

§

impl<'a> Send for SliceReader<'a>

§

impl<'a> Sync for SliceReader<'a>

§

impl<'a> Unpin for SliceReader<'a>

§

impl<'a> UnwindSafe for SliceReader<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.