Encode

Trait Encode 

Source
pub trait Encode: Write + EncodeSize {
    // Provided method
    fn encode(&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§

Source

fn encode(&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.

Implementors§