pub trait Transformable:
Send
+ Sync
+ 'static {
type Error: Error + Send + Sync + 'static;
// Required methods
fn encode(&self, dst: &mut [u8]) -> Result<usize, Self::Error>;
fn encoded_len(&self) -> usize;
fn decode(src: &[u8]) -> Result<(usize, Self), Self::Error>
where Self: Sized;
// Provided methods
fn encode_to_vec(&self) -> Result<Vec<u8>, Self::Error> { ... }
fn encode_to_writer<W>(&self, writer: &mut W) -> Result<usize, Error>
where W: Write { ... }
fn encode_to_async_writer<W>(
&self,
writer: &mut W,
) -> impl Future<Output = Result<usize, Error>> + Send
where W: AsyncWrite + Send + Unpin { ... }
fn decode_from_reader<R>(reader: &mut R) -> Result<(usize, Self), Error>
where R: Read,
Self: Sized { ... }
fn decode_from_async_reader<R>(
reader: &mut R,
) -> impl Future<Output = Result<(usize, Self), Error>> + Send
where R: AsyncRead + Send + Unpin,
Self: Sized { ... }
}Expand description
The type can transform its representation between structured and byte form.
Required Associated Types§
Required Methods§
Sourcefn encode(&self, dst: &mut [u8]) -> Result<usize, Self::Error>
fn encode(&self, dst: &mut [u8]) -> Result<usize, Self::Error>
Encodes the value into the given buffer for transmission.
Returns the number of bytes written to the buffer.
Sourcefn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Returns the encoded length of the value. This is used to pre-allocate a buffer for encoding.
Provided Methods§
Sourcefn encode_to_vec(&self) -> Result<Vec<u8>, Self::Error>
fn encode_to_vec(&self) -> Result<Vec<u8>, Self::Error>
Encodes the value into a vec for transmission.
Sourcefn encode_to_writer<W>(&self, writer: &mut W) -> Result<usize, Error>where
W: Write,
fn encode_to_writer<W>(&self, writer: &mut W) -> Result<usize, Error>where
W: Write,
Encodes the value into the given writer for transmission.
Sourcefn encode_to_async_writer<W>(
&self,
writer: &mut W,
) -> impl Future<Output = Result<usize, Error>> + Send
fn encode_to_async_writer<W>( &self, writer: &mut W, ) -> impl Future<Output = Result<usize, Error>> + Send
Encodes the value into the given async writer for transmission.
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.