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§
Sourcefn with_serializer(
&self,
f: &mut dyn FnMut(&mut FormatSerializer<'_>) -> Result<(), FormatError>,
context: &dyn Context,
) -> Result<Raw, FormatError>
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.
Sourcefn with_deserializer(
&self,
data: &[u8],
f: &mut dyn FnMut(&mut FormatDeserializer<'_>) -> Result<(), FormatError>,
ctx: &mut BoxContext,
) -> Result<(), FormatError>
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).
Sourcefn format_type_id(&self) -> FormatTypeId
fn format_type_id(&self) -> FormatTypeId
Returns this format’s type identifier.