pub trait Encode: Write + EncodeSize {
// Provided methods
fn encode(&self) -> Bytes { ... }
fn encode_mut(&self) -> BytesMut { ... }
}Expand description
Trait combining Write and EncodeSize for types that can be fully encoded.
This trait provides the convenience Encode::encode method which handles buffer allocation, writing, and size assertion in one go.
Provided Methods§
Sourcefn encode(&self) -> Bytes
fn encode(&self) -> Bytes
Encodes self into a new Bytes buffer.
This method calculates the required size using EncodeSize::encode_size, allocates a buffer of that exact capacity, writes the value using Write::write, and performs a sanity check assertion.
§Panics
Panics if encode_size() does not return the same number of bytes actually written by
write()
Sourcefn encode_mut(&self) -> BytesMut
fn encode_mut(&self) -> BytesMut
Encodes self into a new BytesMut buffer.
This method calculates the required size using EncodeSize::encode_size, allocates a buffer of that exact capacity, writes the value using Write::write, and performs a sanity check assertion.
§Panics
Panics if encode_size() does not return the same number of bytes actually written by
write()
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.