EntityToFormer

Trait EntityToFormer 

Source
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

§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§

Source

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§

Source

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.

Implementations on Foreign Types§

Source§

impl<E, Definition> EntityToFormer<Definition> for BinaryHeap<E>
where E: Ord, Definition: FormerDefinition<Storage = BinaryHeap<E>, Types = BinaryHeapDefinitionTypes<E, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed>>, Definition::End: FormingEnd<Definition::Types>,

Source§

type Former = CollectionFormer<E, BinaryHeapDefinition<E, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed, <Definition as FormerDefinition>::End>>

Source§

impl<E, Definition> EntityToFormer<Definition> for BTreeSet<E>
where E: Ord, Definition: FormerDefinition<Storage = BTreeSet<E>, Types = BTreeSetDefinitionTypes<E, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed>>, Definition::End: FormingEnd<Definition::Types>,

Source§

type Former = CollectionFormer<E, BTreeSetDefinition<E, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed, <Definition as FormerDefinition>::End>>

Source§

impl<E, Definition> EntityToFormer<Definition> for LinkedList<E>
where Definition: FormerDefinition<Storage = LinkedList<E>, Types = LinkedListDefinitionTypes<E, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed>>, Definition::End: FormingEnd<Definition::Types>,

Source§

type Former = CollectionFormer<E, LinkedListDefinition<E, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed, <Definition as FormerDefinition>::End>>

Source§

impl<E, Definition> EntityToFormer<Definition> for VecDeque<E>
where Definition: FormerDefinition<Storage = VecDeque<E>, Types = VecDequeDefinitionTypes<E, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed>>, Definition::End: FormingEnd<Definition::Types>,

Source§

type Former = CollectionFormer<E, VecDequeDefinition<E, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed, <Definition as FormerDefinition>::End>>

Source§

impl<E, Definition> EntityToFormer<Definition> for Vec<E>
where Definition: FormerDefinition<Storage = Vec<E>, Types = VectorDefinitionTypes<E, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed>>, Definition::End: FormingEnd<Definition::Types>,

Source§

type Former = CollectionFormer<E, VectorDefinition<E, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed, <Definition as FormerDefinition>::End>>

Source§

impl<K, Definition> EntityToFormer<Definition> for HashSet<K>
where K: Eq + Hash, Definition: FormerDefinition<Storage = HashSet<K>, Types = HashSetDefinitionTypes<K, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed>>, Definition::End: FormingEnd<Definition::Types>,

Source§

type Former = CollectionFormer<K, HashSetDefinition<K, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed, <Definition as FormerDefinition>::End>>

Source§

impl<K, E, Definition> EntityToFormer<Definition> for BTreeMap<K, E>
where K: Ord, Definition: FormerDefinition<Storage = BTreeMap<K, E>, Types = BTreeMapDefinitionTypes<K, E, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed>>, Definition::End: FormingEnd<Definition::Types>,

Source§

impl<K, E, Definition> EntityToFormer<Definition> for HashMap<K, E>
where K: Eq + Hash, Definition: FormerDefinition<Storage = HashMap<K, E>, Types = HashMapDefinitionTypes<K, E, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed>>, Definition::End: FormingEnd<Definition::Types>,

Source§

type Former = CollectionFormer<(K, E), HashMapDefinition<K, E, <Definition as FormerDefinition>::Context, <Definition as FormerDefinition>::Formed, <Definition as FormerDefinition>::End>>

Implementors§