pub trait SerializeBytes {
// Required method
fn serialize(
&self,
write_buf: impl BufMut,
) -> Result<(), SerializationError>;
// Provided method
fn serialize_slice(
slice: &[Self],
write_buf: impl BufMut,
) -> Result<(), SerializationError>
where Self: Sized { ... }
}Expand description
Serialize data to a byte buffer.
Required Methods§
fn serialize(&self, write_buf: impl BufMut) -> Result<(), SerializationError>
Provided Methods§
Sourcefn serialize_slice(
slice: &[Self],
write_buf: impl BufMut,
) -> Result<(), SerializationError>where
Self: Sized,
fn serialize_slice(
slice: &[Self],
write_buf: impl BufMut,
) -> Result<(), SerializationError>where
Self: Sized,
Serializes every element of slice back-to-back, with no length prefix.
The default loops, calling serialize once per element.
That default is always correct.
Overriding this method is an optimization, never a correctness requirement.
Override it only when slice’s byte layout already matches its serialized form.
Then the whole call collapses to one bulk copy instead of N small writes.
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.