Skip to main content

Format

Trait Format 

Source
pub trait Format:
    Debug
    + Send
    + Sync {
    // Required methods
    fn with_serializer(
        &self,
        f: &mut dyn FnMut(&mut FormatSerializer<'_>) -> Result<(), FormatError>,
        context: &dyn Context,
    ) -> Result<Raw, FormatError>;
    fn with_deserializer(
        &self,
        data: &[u8],
        f: &mut dyn FnMut(&mut FormatDeserializer<'_>) -> Result<(), FormatError>,
        ctx: &mut BoxContext,
    ) -> Result<(), FormatError>;
    fn clone_box(&self) -> Box<dyn Format>;
    fn format_type_id(&self) -> FormatTypeId;
}
Expand description

Dyn-compatible serialization format.

Uses a callback-based API to work around lifetime constraints that would prevent returning serializers directly from trait methods.

§For Implementors

Implement with_serializer and with_deserializer to provide serialization/deserialization. The callback receives a FormatSerializer or FormatDeserializer that handles the actual conversion.

§For Callers

Use FormatExt::serialize and FormatExt::deserialize instead of calling the callback methods directly. The extension trait provides a cleaner API.

Required Methods§

Source

fn with_serializer( &self, f: &mut dyn FnMut(&mut FormatSerializer<'_>) -> Result<(), FormatError>, context: &dyn Context, ) -> Result<Raw, FormatError>

Serializes a value through a callback.

Creates a serializer, passes it to the callback, and returns the serialized bytes.

Source

fn with_deserializer( &self, data: &[u8], f: &mut dyn FnMut(&mut FormatDeserializer<'_>) -> Result<(), FormatError>, ctx: &mut BoxContext, ) -> Result<(), FormatError>

Deserializes a value through a callback.

Creates a deserializer from the data and passes it to the callback. The context can be modified during deserialization (e.g., to upgrade schema versions).

Source

fn clone_box(&self) -> Box<dyn Format>

Clones this format into a boxed trait object.

Source

fn format_type_id(&self) -> FormatTypeId

Returns this format’s type identifier.

Trait Implementations§

Source§

impl Clone for Box<dyn Format>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Format for Box<dyn Format>

Source§

fn with_serializer( &self, f: &mut dyn FnMut(&mut FormatSerializer<'_>) -> Result<(), FormatError>, context: &dyn Context, ) -> Result<Raw, FormatError>

Serializes a value through a callback. Read more
Source§

fn with_deserializer( &self, data: &[u8], f: &mut dyn FnMut(&mut FormatDeserializer<'_>) -> Result<(), FormatError>, ctx: &mut BoxContext, ) -> Result<(), FormatError>

Deserializes a value through a callback. Read more
Source§

fn clone_box(&self) -> Box<dyn Format>

Clones this format into a boxed trait object.
Source§

fn format_type_id(&self) -> FormatTypeId

Returns this format’s type identifier.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl Format for Arc<dyn Format>

Source§

fn with_serializer( &self, f: &mut dyn FnMut(&mut FormatSerializer<'_>) -> Result<(), FormatError>, context: &dyn Context, ) -> Result<Raw, FormatError>

Source§

fn with_deserializer( &self, data: &[u8], f: &mut dyn FnMut(&mut FormatDeserializer<'_>) -> Result<(), FormatError>, ctx: &mut BoxContext, ) -> Result<(), FormatError>

Source§

fn clone_box(&self) -> Box<dyn Format>

Source§

fn format_type_id(&self) -> FormatTypeId

Source§

impl Format for Box<dyn Format>

Source§

fn with_serializer( &self, f: &mut dyn FnMut(&mut FormatSerializer<'_>) -> Result<(), FormatError>, context: &dyn Context, ) -> Result<Raw, FormatError>

Source§

fn with_deserializer( &self, data: &[u8], f: &mut dyn FnMut(&mut FormatDeserializer<'_>) -> Result<(), FormatError>, ctx: &mut BoxContext, ) -> Result<(), FormatError>

Source§

fn clone_box(&self) -> Box<dyn Format>

Source§

fn format_type_id(&self) -> FormatTypeId

Implementors§

Source§

impl Format for BincodeFormat

Source§

impl Format for JsonFormat

Source§

impl Format for RkyvFormat

Available on crate feature rkyv_format only.
Source§

impl Format for RonFormat