SerializeFieldsTrait

Trait SerializeFieldsTrait 

Source
pub trait SerializeFieldsTrait {
    type FieldSelector: FieldSelector;

    // Required methods
    fn serialize_fields(&self) -> Self::FieldSelector;
    fn serialize<__S>(
        &self,
        field_selector: &Self::FieldSelector,
        __serializer: __S,
    ) -> Result<__S::Ok, __S::Error>
       where __S: Serializer;
}
Expand description

Trait for types that can provide field selectors for dynamic serialization.

This trait is automatically implemented by the #[derive(SerializeFields)] macro and provides both field selector creation and serialization functionality.

§Examples

#[derive(SerializeFieldsDerive, Serialize, Deserialize)]
struct User {
    id: u32,
    name: String,
}

// Create a field selector using the trait method
let mut fields = user.serialize_fields();
fields.enable_dot_hierarchy("id");
fields.enable_dot_hierarchy("name");

Required Associated Types§

Source

type FieldSelector: FieldSelector

The type of field selector for this struct.

Required Methods§

Source

fn serialize_fields(&self) -> Self::FieldSelector

Create a new field selector for this type.

This is a convenience method that’s equivalent to calling {StructName}SerializeFieldSelector::new() but provides a more ergonomic API through the trait.

Source

fn serialize<__S>( &self, field_selector: &Self::FieldSelector, __serializer: __S, ) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this struct using the provided field selector.

This method is called by the generic Serialize implementation for SerializeFields and handles the actual serialization logic with field filtering.

§Arguments
  • field_selector - The field selector that determines which fields to include
  • serializer - The serde serializer to use

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.

Implementors§