pub trait Encode: Shape {
// Required method
fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R;
}Expand description
A type that can be written into a record.
Implemented for a borrowed form as well as an owned one, so that a lookup
can take &str where the collection holds String, exactly as
HashMap<String, _>::get does.
Required Methods§
Sourcefn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R
fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R
Hand the bytes of self to f.
A callback rather than a returned Vec because a returned Vec is an
allocation, and this is the write path. A type whose bytes are already
contiguous passes them straight through, and a fixed width one builds
them on the stack.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".