Struct ByteReader

Source
pub struct ByteReader<R: AsyncRead + Unpin + Send + Sync, E: Endianness> { /* private fields */ }
Expand description

For reading aligned bytes from a stream of bytes in a given endianness.

This only reads aligned values and maintains no internal state.

Implementations§

Source§

impl<R: AsyncRead + Unpin + Send + Sync, E: Endianness> ByteReader<R, E>

Source

pub fn new(reader: R) -> ByteReader<R, E>

Wraps a ByteReader around something that implements Read

Source

pub fn endian(reader: R, _endian: E) -> ByteReader<R, E>

Wraps a ByteReader around something that implements Read with the given endianness.

Source

pub fn into_reader(self) -> R

Unwraps internal reader and disposes of ByteReader.

Source

pub fn reader(&mut self) -> &mut R

Provides mutable reference to internal reader

Source

pub fn into_bitreader(self) -> BitReader<R, E>

Converts ByteReader to BitReader in the same endianness.

Source

pub fn bitreader(&mut self) -> BitReader<&mut R, E>

Provides temporary BitReader in the same endianness.

§Warning

Any unread bits left over when BitReader is dropped are lost.

Trait Implementations§

Source§

impl<R: AsyncRead + Unpin + Send + Sync, E: Endianness> ByteRead for ByteReader<R, E>

Source§

fn read<'life0, 'async_trait, N>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<N, Error>> + Send + 'async_trait>>
where N: 'async_trait + Numeric, Self: 'async_trait, 'life0: 'async_trait,

Reads whole numeric value from stream Read more
Source§

fn read_bytes<'life0, 'life1, 'async_trait>( &'life0 mut self, buf: &'life1 mut [u8], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Completely fills the given buffer with whole bytes. Read more
Source§

fn skip<'life0, 'async_trait>( &'life0 mut self, bytes: u32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Skips the given number of bytes in the stream. Read more
Source§

fn read_to_bytes<'life0, 'async_trait, const SIZE: usize>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<[u8; SIZE]>> + Send + 'async_trait>>
where Self: Send + 'async_trait, 'life0: 'async_trait,

Completely fills a whole buffer with bytes and returns it. Read more
Source§

fn read_to_vec<'life0, 'async_trait>( &'life0 mut self, bytes: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>
where Self: Send + 'async_trait, 'life0: 'async_trait,

Completely fills a vector of bytes and returns it. Read more

Auto Trait Implementations§

§

impl<R, E> Freeze for ByteReader<R, E>
where R: Freeze,

§

impl<R, E> RefUnwindSafe for ByteReader<R, E>

§

impl<R, E> Send for ByteReader<R, E>

§

impl<R, E> Sync for ByteReader<R, E>

§

impl<R, E> Unpin for ByteReader<R, E>
where E: Unpin,

§

impl<R, E> UnwindSafe for ByteReader<R, E>
where R: UnwindSafe, E: UnwindSafe,

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>,

Source§

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>,

Source§

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.