pub trait Encode: Send + Sync {
// Required method
fn encode(&self, message: &dyn Any) -> Result<EncodedPayload, EncodeError>;
}Expand description
A type-erased encoder used by the registry.
Implementors take the captured message as &dyn Any so the registry can dispatch by
std::any::TypeId without naming the concrete type at the call site. Most callers
build encoders with TypedEncoder rather than implementing this trait directly.
Required Methods§
Sourcefn encode(&self, message: &dyn Any) -> Result<EncodedPayload, EncodeError>
fn encode(&self, message: &dyn Any) -> Result<EncodedPayload, EncodeError>
Encodes the supplied message into canonical payload bytes plus sidecar indices.
§Errors
Returns an error if message does not match the encoder’s expected type, or if the encoder
fails internally.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".