pub trait EntityToFormer<Definition>where
Definition: FormerDefinition,{
type Former;
// Provided method
fn __f(_: &Definition) { ... }
}Expand description
Maps a type of entity to its corresponding former (builder) implementation.
This trait establishes the connection between an entity and its builder struct, enabling the Former pattern to instantiate the correct builder type for a given entity. It’s a crucial part of the type system that ensures type safety across the formation process.
§Type Parameters
Definition: TheFormerDefinitionthat governs the formation process
§Purpose and Design
This trait enables :
- Type-Safe Builder Resolution : Ensures the correct builder is used for each entity
- Generic Parameter Preservation : Maintains generic constraints through builder creation
- Custom Former Support : Allows for specialized builder implementations
- Subform Integration : Enables nested builders with proper type relationships
§Usage in Generated Code
The #[ derive( Former ) ] macro automatically implements this trait :
// For a struct like :
#[ derive( Former ) ]
struct Config { setting: String }
// The macro generates :
impl EntityToFormer< ConfigDefinition > for Config
{
type Former = ConfigFormer< ConfigDefinition >;
}§Integration Points
This trait works with :
EntityToDefinition: For complete entity-to-formation mapping- [
FormerBegin] : For initiating the formation process - Generated former structs: For the actual builder implementation
Required Associated Types§
Sourcetype Former
type Former
The type of the former (builder) used for constructing the entity.
This type must implement the necessary builder pattern methods and integrate properly with the Former ecosystem. It typically includes :
- Setter methods for each field
- Subform support for nested structures
- Collection builders for container fields
- Generic parameter preservation
Provided Methods§
Sourcefn __f(_: &Definition)
fn __f(_: &Definition)
A placeholder function to reference the definition without operational logic.
This function exists solely to establish a compile-time relationship with the
Definition parameter and has no runtime behavior. It helps the compiler
understand the type relationships in complex generic scenarios.
§Implementation Note
This is a workaround for Rust’s type system limitations in expressing phantom type relationships. It should never be called in actual code.
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.