Trait former::exposed::FormerBegin

source ·
pub trait FormerBegin<Definition>
where Definition: FormerDefinition,
{ // Required method fn former_begin( storage: Option<Definition::Storage>, context: Option<Definition::Context>, on_end: Definition::End ) -> Self; }
Expand description

A trait for initiating a structured subforming process with contextual and intermediary storage linkage.

This trait is crucial for the derive(Former) macro implementation, where it facilitates the creation of a subformer that integrates seamlessly within a builder pattern chain. It handles intermediary storage to accumulate state or data before finally transforming it into the final Formed structure.

FormerBegin is particularly important in scenarios where complex, hierarchical structures are formed, allowing a former to be reused within another former. This reusability and the ability to maintain both transient state (Storage) and contextual information (Context) are essential for multi-step construction or transformation processes that culminate in the generation of a final product (Formed).

During code generation via the derive(Former) macro, FormerBegin provides the necessary scaffolding to initiate the subforming process. This setup is critical for ensuring that all elements involved in the formation are aligned from the onset, particularly when one former is nested within another, facilitating the creation of complex hierarchical data structures.

Required Methods§

source

fn former_begin( storage: Option<Definition::Storage>, context: Option<Definition::Context>, on_end: Definition::End ) -> Self

Launches the subforming process with an initial storage and context, setting up an on_end completion handler.

This method initializes the formation process by providing the foundational elements necessary for building the entity. It allows for the configuration of initial states and contextual parameters, which are critical for accurately reflecting the intended final state of the entity.

§Parameters
  • storage - An optional initial state for the intermediary storage structure. This parameter allows for the pre-configuration of storage, which can be crucial for entities requiring specific initial states.
  • context - An optional initial setting providing contextual information for the subforming process. This context can influence how the formation process progresses, especially in complex forming scenarios.
  • on_end - A completion handler responsible for transforming the accumulated Storage into the final Formed structure. This parameter is vital for ensuring that the transition from Storage to Formed is handled correctly, incorporating any last-minute adjustments or validations necessary for the entity’s integrity.
§Returns

Returns an instance of Former.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<E, Definition> FormerBegin<Definition> for CollectionFormer<E, Definition>
where Definition: FormerDefinition, Definition::Storage: CollectionAdd<Entry = E>,