pub trait Encode<E: ?Sized>:
Send
+ Sync
+ 'static {
type Error: Error + Send + Sync + 'static;
// Required method
fn encode(&self, event: &E) -> Result<Bytes, Self::Error>;
}Expand description
Serialize a typed value to bytes.
The write half of the codec story. Independent from Decode so
write-only adapters need not implement decoding, and so the encode path
can be bounded without forcing a decode strategy on the caller.
E: ?Sized allows unsized event types (e.g. Archived<MyEvent>).
Required Associated Types§
Required Methods§
Sourcefn encode(&self, event: &E) -> Result<Bytes, Self::Error>
fn encode(&self, event: &E) -> Result<Bytes, Self::Error>
Serialize a typed value to bytes.
Returns bytes::Bytes so the encoded payload can flow through
the store and wire layer without an intermediate Vec<u8> → Bytes
copy. Codecs that produce a Vec<u8> internally adapt via
Bytes::from(vec) (zero-copy ownership transfer of the backing
allocation); codecs that build incrementally may use
BytesMut::freeze().
§Errors
Returns Self::Error if the value cannot be serialized.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".