Skip to main content

Serialize

Trait Serialize 

Source
pub trait Serialize<C: Config>: SchemaWrite<C> {
    // Provided methods
    fn serialize(src: &Self::Src, config: C) -> WriteResult<Vec<u8>> { ... }
    fn serialize_into(
        dst: impl Writer,
        src: &Self::Src,
        config: C,
    ) -> WriteResult<()> { ... }
    fn serialized_size(src: &Self::Src, config: C) -> WriteResult<u64> { ... }
}
Expand description

Like crate::Serialize, but allows the caller to provide a custom configuration.

Provided Methods§

Source

fn serialize(src: &Self::Src, config: C) -> WriteResult<Vec<u8>>

Serialize a serializable type into a Vec of bytes.

Source

fn serialize_into( dst: impl Writer, src: &Self::Src, config: C, ) -> WriteResult<()>

Serialize a serializable type into the given Writer.

§Partial writes

This operation is not transactional. If it returns an error, the writer may already contain a prefix of the serialized value. Dynamically sized values in particular may discover insufficient capacity only after preceding fields have been written.

If the destination must remain unchanged on failure, serialize into a temporary buffer and copy the result only after serialization succeeds. For a fixed-size destination, callers can instead use Self::serialized_size with the same configuration to check that enough space is available first.

Source

fn serialized_size(src: &Self::Src, config: C) -> WriteResult<u64>

Get the size in bytes of the type when serialized.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T, C: Config> Serialize<C> for T
where T: SchemaWrite<C> + ?Sized,