FramedWriter

Struct FramedWriter 

Source
pub struct FramedWriter<W: AsyncWrite> { /* private fields */ }
Expand description

A writer which writes to a writeable sink in a framed manner. Frames written by this writer can be read using a FramedReader.

Implementations§

Source§

impl<W: AsyncWrite> FramedWriter<W>

Source

pub fn new(sink: W) -> Self

Creates a new framed writer which writes to the given writable sink.

Source

pub async fn write_frame(&mut self, frame: &[u8]) -> Result<(), WriteFrameError>

Writes a single frame to the writeable sink.

The framed writer uses a BufWriter under the hood, which means that written frames may not immediately be sent, but may stay buffered until the buffer is full enough, at which point all written frames will be flushed. If you need the frame to be flushed immediately, you can use flush.

§Cancel Safety

This function is not cancel safe, and so it shouldn’t be used as one of the branches of tokio::select, because it may cause data loss when cancelled.

If you want to write a frame in a cancel safe way, use write_frame_cancel_safe.

Source

pub async fn write_frame_cancel_safe( &mut self, frame: &[u8], ) -> Result<(), WriteFrameError>

Writes a single frame to the writeable sink in a cancel safe manner.

The framed writer uses a BufWriter under the hood, which means that written frames may not immediately be sent, but may stay buffered until the buffer is full enough, at which point all written frames will be flushed. If you need the frame to be flushed immediately, you can use flush.

This is more expensive than write_frame, but provides cancel safety.

§Cancel Safety

This function is cancel safe, and can be used as one of the branches of tokio::select without causing any data loss.

Source

pub async fn flush(&mut self) -> Result<(), WriteFrameError>

Flushes the framed writer, ensuring that any buffered data reaches its destination.

Auto Trait Implementations§

§

impl<W> Freeze for FramedWriter<W>

§

impl<W> RefUnwindSafe for FramedWriter<W>
where W: RefUnwindSafe,

§

impl<W> Send for FramedWriter<W>
where W: Send,

§

impl<W> Sync for FramedWriter<W>
where W: Sync,

§

impl<W> Unpin for FramedWriter<W>

§

impl<W> UnwindSafe for FramedWriter<W>
where W: 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.