Expand description
§Former Meta - Procedural Macro Implementation
This crate provides the procedural macro implementation for the Former derive macro. It handles the complex code generation required to implement the builder pattern with advanced features like subforms, collections, and custom validation.
§Architecture Overview
The Former meta crate is organized around several key components:
§Core Processing Pipeline
- Input Parsing: Parse derive input and extract struct/enum information
- Attribute Processing: Parse and validate all Former-specific attributes
- Type Analysis: Analyze generic parameters, lifetimes, and field types
- Code Generation: Generate the complete Former ecosystem
- Output Assembly : Combine generated code into final token stream
§Key Modules
- [
derive_former] : Main entry point and orchestration logic - Field attribute processing and validation
- Struct attribute parsing and management
- Generic parameter handling for complex scenarios
- Code generation for structs and enums
§Supported Constructs
§Struct Support
- Simple Structs : Basic field-based structures
- Generic Structs : Complex generic parameters with constraints
- Lifetime Parameters : Full lifetime parameter support
- Tuple Structs : Positional field structures
§Enum Support
- Unit Variants : Simple enum variants without data
- Tuple Variants : Variants with positional fields
- Struct Variants : Variants with named fields
- Mixed Enums : Enums combining different variant types
§Advanced Features
§Collection Integration
- Automatic detection and handling of standard collections
- Custom collection support through trait implementations
- Specialized builders for Vec,
HashMap,HashSet, etc.
§Subform Support
- Nested structure building with full type safety
- Automatic trait bound propagation
- Context preservation across subform boundaries
§Validation and Mutation
- Pre-formation validation through custom mutators
- Storage field manipulation before final formation
- Custom end handlers for specialized formation logic
§Error Handling and Diagnostics
The macro provides comprehensive error reporting :
- Clear error messages for attribute misuse
- Helpful suggestions for common mistakes
- Debug output capabilities for troubleshooting
- Integration with Rust’s diagnostic system
§Performance Considerations
- Compile-time Generation : All code generated at compile time
- Minimal Runtime Overhead : Generated code is highly optimized
- Memory Efficient : Strategic use of references and zero-cost abstractions
- Lazy Evaluation : Complex analysis only when needed
§Module :: former_meta
A flexible implementation of the Builder pattern supporting nested builders and collection-specific subformers. Implementation of its derive macro. Should not be used independently, instead use module::former which relies on the module.
Not intended to be used without runtime. This module and runtime is aggregate in module::former is here.
§To add to your project
cargo add former_metaDerive Macros§
- Former
- Derive macro for generating a
Formerstruct, applying a Builder Pattern to the annotated struct.