Skip to main content

SerializableStruct

Trait SerializableStruct 

Source
pub trait SerializableStruct {
    // Required method
    fn serialize_members(
        &self,
        serializer: &mut dyn ShapeSerializer,
    ) -> Result<(), SerdeError>;
}
Expand description

Trait for structures that can be serialized via a schema.

Implemented by generated structure types. Because ShapeSerializer is object-safe, each struct gets one compiled serialize_members() that works with any serializer through dynamic dispatch.

§Example

impl SerializableStruct for MyStruct {
    fn serialize_members(&self, serializer: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        serializer.write_string(&NAME_SCHEMA, &self.name)?;
        serializer.write_integer(&AGE_SCHEMA, self.age)?;
        Ok(())
    }
}

Required Methods§

Source

fn serialize_members( &self, serializer: &mut dyn ShapeSerializer, ) -> Result<(), SerdeError>

Serializes this structure’s members using the provided serializer.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<T: SerializableStruct + ?Sized> SerializableStruct for Box<T>

Source§

fn serialize_members( &self, serializer: &mut dyn ShapeSerializer, ) -> Result<(), SerdeError>

Implementors§