Skip to main content

FrameReader

Struct FrameReader 

Source
pub struct FrameReader<R, const N: usize> { /* private fields */ }
Expand description

Reads frames of exactly N bytes from an AsyncRead.

A partially read frame is kept inside, so unlike AsyncReadExt::read_exact reading a frame can be cancelled and resumed.

Implementations§

Source§

impl<R: AsyncRead, const N: usize> FrameReader<R, N>

Source

pub const fn new(inner: R) -> Self

Wraps a given reader.

Source

pub async fn read_exact<S: State, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize>( &mut self, ctx: &Context<'_, S, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>, ) -> Result<Option<[u8; N]>, FrameReaderError<R::Error>>

Reads the next frame.

Returns None if the stream is closed before the first byte of the frame.

§Errors

Returns an error if:

  1. reading fails
  2. or if the stream is closed in the middle of the frame.
§Cancel safety

This method is cancel safe.

Source§

impl<R, const N: usize> FrameReader<R, N>

Source

pub const fn get_mut(&mut self) -> &mut R

Returns a mutable reference to the wrapped reader.

Trait Implementations§

Source§

impl<R, const N: usize> Debug for FrameReader<R, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R, const N: usize> Forget for FrameReader<R, N>

§

impl<R, const N: usize> Freeze for FrameReader<R, N>
where R: Freeze, [u8; N]: Freeze,

§

impl<R, const N: usize> Move for FrameReader<R, N>

§

impl<R, const N: usize> RefUnwindSafe for FrameReader<R, N>

§

impl<R, const N: usize> Send for FrameReader<R, N>
where R: Send, [u8; N]: Send,

§

impl<R, const N: usize> Sync for FrameReader<R, N>
where R: Sync, [u8; N]: Sync,

§

impl<R, const N: usize> Unpin for FrameReader<R, N>
where R: Unpin, [u8; N]: Unpin,

§

impl<R, const N: usize> UnsafeUnpin for FrameReader<R, N>
where R: UnsafeUnpin, [u8; N]: UnsafeUnpin,

§

impl<R, const N: usize> UnwindSafe for FrameReader<R, N>
where R: UnwindSafe, [u8; N]: 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.