1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Example demonstrating custom mutation logic using the `FormerMutator` trait with storage-specific fields.
// This example illustrates how to use the `FormerMutator` trait for implementing custom mutations
// and demonstrates the concept of storage-specific fields in the forming process.
//
// #### Storage-Specific Fields
//
// Storage-specific fields are intermediate fields that exist only in the storage structure during
// the forming process. These fields are not present in the final formed structure but are instrumental
// in complex forming operations, such as conditional mutations, temporary state tracking, or accumulations.
//
// These fields are used to manage intermediate data or state that aids in the construction
// of the final object but does not necessarily have a direct representation in the object's schema. For
// instance, counters, flags, or temporary computation results that determine the final state of the object.
//
// The `FormerMutator` trait facilitates the implementation of custom mutation logic. It acts on the internal
// state (context and storage) just before the final forming operation is completed, right before the `FormingEnd`
// callback is invoked. This trait is crucial for making last-minute adjustments or computations based on the
// accumulated state in the storage.
//
// In this example, the fields `a` and `b` are defined only within the storage and used
// within the custom mutator to enrich or modify the field `c` of the formed entity. This approach
// allows for a richer and more flexible formation logic that can adapt based on the intermediate state
// held within the storage.
//
// #### Differences from `FormingEnd`
//
// Unlike `FormingEnd`, which is primarily responsible for integrating and finalizing the formation process of a field
// within a parent former, `form_mutation` directly pertains to the entity itself. This method is designed to be independent
// of whether the forming process is occurring within the context of a superformer or if the structure is a standalone
// or nested field. This makes `form_mutation` suitable for entity-specific transformations that should not interfere
// with the hierarchical forming logic managed by `FormingEnd`.
//