SerializeFields
A Rust procedural macro that enables dynamic field selection for struct serialization. Control exactly which fields get serialized at runtime using a hierarchical field selector system.
Features
- 🎯 Dynamic Field Selection: Choose which fields to serialize at runtime
- 🌳 Hierarchical Selection: Use dot notation for nested structs (
"user.profile.name"
) - 🔧 Type Safe: Compile-time validation of field paths
- 🚀 Zero Runtime Cost: Only enabled fields are processed during serialization
- 📦 Serde Integration: Works seamlessly with the serde ecosystem
- 🔄 Collection Support: Handles
Vec
,Option
,HashMap
, and other containers - 🏗️ Generic Architecture: Single trait-based serialization implementation
Quick Start
use ;
use ;
let user = User ;
// Create field selector using the trait method
let mut fields = user.serialize_fields;
fields.enable_dot_hierarchy;
fields.enable_dot_hierarchy;
// Serialize with selected fields only
let json = to_string.unwrap;
// Output: {"id":123,"name":"Alice"}
Advanced Usage
Nested Structs
# use ;
# use ;
# let user = User ;
let mut fields = user.serialize_fields;
fields.enable_dot_hierarchy;
fields.enable_dot_hierarchy; // Nested field selection
let json = to_string.unwrap;
// Output: {"id":123,"profile":{"bio":"Software Engineer"}}
Dynamic Field Selection
# use ;
# use ;
#
#
# let user = User ;
// Usage: GET /users/123?fields=id,name
let fields = vec!;
let json = serialize_user_with_fields;