Preview of the proposed up-rust native-frame-model branch (up-rust b6b99c6d, up-spec f0e9b17) — not released documentation. branch · write-up

Trait EncodePayload

Source
pub trait EncodePayload<T: ?Sized>: PayloadCodec {
    // Required methods
    fn payload_layout(value: &T) -> Result<PayloadLayout, UWireError>;
    fn encode_payload(value: &T, dst: &mut [u8]) -> Result<(), UWireError>;

    // Provided method
    fn encode_payload_owned(value: &T) -> Result<Bytes, UWireError> { ... }
}
Expand description

Encodes a typed value with a PayloadCodec.

Required Methods§

Source

fn payload_layout(value: &T) -> Result<PayloadLayout, UWireError>

Returns the exact payload layout required to encode value.

This is a measurement operation, not necessarily a constant-time size lookup. A variable-length codec may serialize or traverse value here and perform the work again in Self::encode_payload. Benchmarks and callers that care about this cost should label the probe and write phases separately. The returned length and alignment are the complete contract for the destination passed to encode_payload.

§Errors

Returns an error if the value cannot be measured for this codec.

Source

fn encode_payload(value: &T, dst: &mut [u8]) -> Result<(), UWireError>

Encodes value into dst.

§Errors

Returns an error if dst is too small or serialization fails.

Provided Methods§

Source

fn encode_payload_owned(value: &T) -> Result<Bytes, UWireError>

Encodes value into owned bytes.

§Errors

Returns an error if serialization fails.

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§