Skip to main content

Encode

Trait Encode 

Source
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§

Source

type Error: Error + Send + Sync + 'static

The error type for serialization failures.

Required Methods§

Source

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".

Implementors§

Source§

impl<E, F> Encode<E> for SerdeCodec<F>
where E: Serialize + Send + Sync + 'static, F: SerdeFormat,

Source§

impl<E> Encode<E> for BytemuckCodec
where E: NoUninit + Send + Sync + 'static,

Source§

impl<E> Encode<E> for RkyvCodec
where E: for<'a> Serialize<HighSerializer<AlignedVec, ArenaHandle<'a>, Error>> + Send + Sync + 'static,