Skip to main content

FrameWriter

Struct FrameWriter 

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

Writes frames of exactly N bytes to an AsyncWrite.

A frame is accepted as a whole and a partially written frame is kept inside, so unlike AsyncWriteExt::write_all writing a frame can be cancelled and resumed.

A frame that is not fully written yet is lost when this value is dropped, call flush to avoid it.

Implementations§

Source§

impl<W: AsyncWrite, const N: usize> FrameWriter<W, N>

Source

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

Wraps a given writer.

Source

pub async fn write_all( &mut self, frame: &[u8; N], ) -> Result<(), FrameWriterError<W::Error>>

Finishes writing the previous frame and accepts frame as the next one.

frame is written by the next call to write_all or flush.

§Errors

Returns an error if writing fails or if the stream accepts zero bytes.

§Cancel safety

This method is cancel safe.

Source

pub async fn flush(&mut self) -> Result<(), FrameWriterError<W::Error>>

Finishes writing the last accepted frame and flushes the wrapped writer.

§Errors

Returns an error if writing fails or if the stream accepts zero bytes.

§Cancel safety

This method is cancel safe.

Auto Trait Implementations§

§

impl<W, const N: usize> Forget for FrameWriter<W, N>

§

impl<W, const N: usize> Freeze for FrameWriter<W, N>
where W: Freeze, [u8; N]: Freeze,

§

impl<W, const N: usize> Move for FrameWriter<W, N>

§

impl<W, const N: usize> RefUnwindSafe for FrameWriter<W, N>

§

impl<W, const N: usize> Send for FrameWriter<W, N>
where W: Send, [u8; N]: Send,

§

impl<W, const N: usize> Sync for FrameWriter<W, N>
where W: Sync, [u8; N]: Sync,

§

impl<W, const N: usize> Unpin for FrameWriter<W, N>
where W: Unpin, [u8; N]: Unpin,

§

impl<W, const N: usize> UnsafeUnpin for FrameWriter<W, N>
where W: UnsafeUnpin, [u8; N]: UnsafeUnpin,

§

impl<W, const N: usize> UnwindSafe for FrameWriter<W, N>
where W: 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.