Encode

Trait Encode 

Source
pub trait Encode: Sized {
    type Format: FormatEncode;
    type Data: ?Sized;

    // Required methods
    fn init(data: &Self::Data) -> Self;
    fn poll_encode<W>(
        &mut self,
        format: &Self::Format,
        writer: &mut W,
        data: &Self::Data,
        cx: &mut Context<'_>,
    ) -> PollEncodeStatus<<<Self as Encode>::Format as Format>::Error>
       where W: AsyncWrite + Unpin;

    // Provided method
    fn start_encode<W>(
        format: &Self::Format,
        writer: &mut W,
        data: &Self::Data,
        cx: &mut Context<'_>,
    ) -> StartEncodeStatus<Self, <<Self as Encode>::Format as Format>::Error>
       where W: AsyncWrite + Unpin { ... }
}
Expand description

Attempt to encode a data structure to an asynchronous writer for a particular format.

Required Associated Types§

Source

type Format: FormatEncode

The concrete format to encode with.

Source

type Data: ?Sized

The concrete data structure to encode.

Required Methods§

Source

fn init(data: &Self::Data) -> Self

Initialize the internal state of the encoder.

Source

fn poll_encode<W>( &mut self, format: &Self::Format, writer: &mut W, data: &Self::Data, cx: &mut Context<'_>, ) -> PollEncodeStatus<<<Self as Encode>::Format as Format>::Error>
where W: AsyncWrite + Unpin,

Continue a pending Encode operation.

Provided Methods§

Source

fn start_encode<W>( format: &Self::Format, writer: &mut W, data: &Self::Data, cx: &mut Context<'_>, ) -> StartEncodeStatus<Self, <<Self as Encode>::Format as Format>::Error>
where W: AsyncWrite + Unpin,

Begin encoding bytes for the indicated format to the provided writer.

This is intended to be overriden whenever an optimized code path exists for the (usual) case where enough buffer space is available that the operation will succeed immediately without pending.

§Implementation

Implementions must ensure that start_encode is semantically equivalent to calling init followed by poll_encode

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> Encode for T
where T: BufferEncode,