former_types/
definition.rs

1//! Module `definition`
2//!
3//! Provides traits for defining the relationships between entities and their formation mechanisms.
4//! These traits are central to the implementation of a flexible and extensible formation system,
5//! enabling entities to be constructed using various configurations and complex logic.
6//!
7//! Key aspects of the module include:
8//! - **Entity to Definition Mapping**: Linking entities to their specific formation definitions,
9//!   which detail how they are to be constructed.
10//! - **Entity to Former Mapping**: Associating entities with formers that handle their construction
11//!   process.
12//! - **Entity to Storage Mapping**: Defining the storage structures that maintain the state of an
13//!   entity during its formation.
14//! - **Definition Traits**: Specifying the properties and ending conditions of the formation
15//!   process to ensure entities are formed according to specified rules and logic.
16//!
17
18/// Maps a type of entity to its corresponding former definition.
19/// This trait provides a linkage between the entity and its definition,
20/// allowing the formation logic to understand what definition to apply
21/// during the formation process.
22pub trait EntityToDefinition< Context, Formed, End >
23{
24  /// The specific [`FormerDefinition`] associated with this entity.
25  type Definition : FormerDefinition;
26  /// The specific [`FormerDefinitionTypes`] associated with this entity.
27  type Types : FormerDefinitionTypes;
28}
29
30/// Provides a mapping between a type of entity and its associated formation type definitions.
31pub trait EntityToDefinitionTypes< Context, Formed >
32{
33  /// Specifies the `FormerDefinitionTypes` that define the storage, formed entity, and context types used during formation.
34  /// This association is essential for ensuring that the formation process is carried out with the correct type-specific logic.
35  type Types : FormerDefinitionTypes;
36}
37
38/// Maps a type of entity to its corresponding former.
39/// This trait binds an entity type to a specific former, facilitating the use
40/// of custom formers in complex formation scenarios.
41pub trait EntityToFormer< Definition >
42where
43  Definition : FormerDefinition,
44{
45  /// The type of the former used for building the entity.
46  type Former;
47
48  /// A placeholder function to reference the definition without operational logic to calm compiler.
49  fn __f(_: &Definition) {}
50}
51
52/// Maps a type of entity to its storage type.
53/// This trait defines what storage structure is used to hold the interim state
54/// of an entity during its formation.
55pub trait EntityToStorage
56{
57  /// The storage type used for forming the entity.
58  type Storage;
59}
60
61/// Defines the fundamental components involved in the formation of an entity.
62/// This trait specifies the types of storage, the formed entity, and the context
63/// used during the formation process.
64pub trait FormerDefinitionTypes : Sized
65{
66  /// The type of storage used to maintain the state during formation.
67  type Storage : Default;
68
69  /// The type of the entity once fully formed.
70  type Formed;
71
72  /// The contextual information used during formation, if any.
73  type Context;
74}
75
76/// Expands on `FormerDefinitionTypes` by incorporating an ending mechanism for the formation process.
77/// This trait connects the formation types with a specific endpoint, defining
78/// how the formation process concludes, including any necessary transformations
79/// or validations.
80pub trait FormerDefinition : Sized
81{
82  /// Encapsulates the types related to the formation process including any mutators.
83  type Types : crate::FormerDefinitionTypes< Storage = Self::Storage, Formed = Self::Formed, Context = Self::Context >
84  + crate::FormerMutator;
85
86  /// Defines the ending condition or operation of the formation process.
87  type End: crate::FormingEnd< Self::Types >;
88
89  /// The storage type used during the formation.
90  type Storage : Default;
91
92  /// The type of the entity being formed. It is
93  /// generally the structure for which the `Former` is derived, representing the fully formed
94  /// state of the entity. However, it can differ if a custom `FormingEnd` or a different `Formed` type
95  /// is defined to handle specific forming logic or requirements.
96  type Formed;
97
98  /// The context used during the formation process.
99  type Context;
100}