FramedWrite

Struct FramedWrite 

Source
pub struct FramedWrite<T, E> { /* private fields */ }
Expand description

A Sink of frames encoded to an AsyncWrite.

§Example

use bytes::Bytes;
use asynchronous_codec::{FramedWrite, BytesCodec};
use futures::SinkExt;

let mut buf = Vec::new();
let mut framed = FramedWrite::new(&mut buf, BytesCodec {});

let bytes = Bytes::from("Hello World!");
framed.send(bytes.clone()).await?;

assert_eq!(&buf[..], &bytes[..]);

Implementations§

Source§

impl<T, E> FramedWrite<T, E>
where T: AsyncWrite, E: Encoder,

Source

pub fn new(inner: T, encoder: E) -> FramedWrite<T, E>

Creates a new FramedWrite transport with the given Encoder.

Source

pub fn from_parts(_: FramedWriteParts<T, E>) -> FramedWrite<T, E>

Creates a new FramedWrite from FramedWriteParts.

See also FramedWrite::into_parts.

Source

pub fn send_high_water_mark(&self) -> usize

High-water mark for writes, in bytes

The send high-water mark prevents the FramedWrite from accepting additional messages to send when its buffer exceeds this length, in bytes. Attempts to enqueue additional messages will be deferred until progress is made on the underlying AsyncWrite. This applies back-pressure on fast senders and prevents unbounded buffer growth.

See set_send_high_water_mark().

Source

pub fn set_send_high_water_mark(&mut self, hwm: usize)

Sets high-water mark for writes, in bytes

The send high-water mark prevents the FramedWrite from accepting additional messages to send when its buffer exceeds this length, in bytes. Attempts to enqueue additional messages will be deferred until progress is made on the underlying AsyncWrite. This applies back-pressure on fast senders and prevents unbounded buffer growth.

The default high-water mark is 2^17 bytes. Applications which desire low latency may wish to reduce this value. There is little point to increasing this value beyond your socket’s SO_SNDBUF size. On linux, this defaults to 212992 bytes but is user-adjustable.

Source

pub fn into_parts(self) -> FramedWriteParts<T, E>

Consumes the FramedWrite, returning its parts such that a new FramedWrite may be constructed, possibly with a different encoder.

See also FramedWrite::from_parts.

Source

pub fn into_inner(self) -> T

Consumes the FramedWrite, returning its underlying I/O stream.

Note that data that has already been written but not yet flushed is dropped. To retain any such potentially buffered data, use FramedWrite::into_parts().

Source

pub fn encoder(&self) -> &E

Returns a reference to the underlying encoder.

Note that care should be taken to not tamper with the underlying encoder as it may corrupt the stream of frames otherwise being worked with.

Source

pub fn encoder_mut(&mut self) -> &mut E

Returns a mutable reference to the underlying encoder.

Note that care should be taken to not tamper with the underlying encoder as it may corrupt the stream of frames otherwise being worked with.

Trait Implementations§

Source§

impl<T, E> Debug for FramedWrite<T, E>
where T: Debug, E: Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T, E> Deref for FramedWrite<T, E>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T, E> DerefMut for FramedWrite<T, E>

Source§

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

Mutably dereferences the value.
Source§

impl<T, E> Sink<<E as Encoder>::Item<'_>> for FramedWrite<T, E>
where T: AsyncWrite + Unpin, E: Encoder,

Source§

type Error = <E as Encoder>::Error

The type of value produced by the sink when an error occurs.
Source§

fn poll_ready( self: Pin<&mut FramedWrite<T, E>>, cx: &mut Context<'_>, ) -> Poll<Result<(), <FramedWrite<T, E> as Sink<<E as Encoder>::Item<'_>>>::Error>>

Attempts to prepare the Sink to receive a value. Read more
Source§

fn start_send( self: Pin<&mut FramedWrite<T, E>>, item: <E as Encoder>::Item<'_>, ) -> Result<(), <FramedWrite<T, E> as Sink<<E as Encoder>::Item<'_>>>::Error>

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more
Source§

fn poll_flush( self: Pin<&mut FramedWrite<T, E>>, cx: &mut Context<'_>, ) -> Poll<Result<(), <FramedWrite<T, E> as Sink<<E as Encoder>::Item<'_>>>::Error>>

Flush any remaining output from this sink. Read more
Source§

fn poll_close( self: Pin<&mut FramedWrite<T, E>>, cx: &mut Context<'_>, ) -> Poll<Result<(), <FramedWrite<T, E> as Sink<<E as Encoder>::Item<'_>>>::Error>>

Flush any remaining output and close this sink, if necessary. Read more
Source§

impl<'__pin, T, E> Unpin for FramedWrite<T, E>
where <PinnedFieldsOfHelperStruct<__Origin<'__pin, T, E>> as PinnedFieldsOfHelperTrait>::Actual: Unpin,

Auto Trait Implementations§

§

impl<T, E> Freeze for FramedWrite<T, E>
where T: Freeze, E: Freeze,

§

impl<T, E> RefUnwindSafe for FramedWrite<T, E>

§

impl<T, E> Send for FramedWrite<T, E>
where T: Send, E: Send,

§

impl<T, E> Sync for FramedWrite<T, E>
where T: Sync, E: Sync,

§

impl<T, E> UnwindSafe for FramedWrite<T, E>
where T: 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.