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§
Sourcetype Format: FormatEncode
type Format: FormatEncode
The concrete format to encode with.
Required Methods§
Sourcefn 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,
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 Methods§
Sourcefn 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,
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.