Skip to content

Commit

Permalink
former : experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 23, 2024
1 parent babd9c7 commit 28e23bf
Show file tree
Hide file tree
Showing 5 changed files with 390 additions and 381 deletions.
24 changes: 16 additions & 8 deletions module/core/former/src/axiomatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ pub trait FormerDefinition : Sized
type Storage : Storage< Formed = Self::Formed >;
type Formed;
type Context;
type End : FormingEnd< Self >;
// type End : FormingEnd< Self >;
}

/// xxx
pub trait FormerDefinition2 : Sized
{
type Definition : FormerDefinition;
type End : FormingEnd< Self::Definition >;
}

// pub trait FormerDefinition
Expand Down Expand Up @@ -92,8 +99,8 @@ pub struct ReturnStorage;
impl< Definition, T > FormingEnd< Definition >
for ReturnStorage
where
Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = Self >,
Definition::End : FormingEnd< Definition >,
Definition : FormerDefinition< Context = (), Storage = T, Formed = T >,
// Definition::End : FormingEnd< Definition >,
// Definition::End : Self,
// Definition::Storage : Default,
{
Expand Down Expand Up @@ -180,15 +187,16 @@ for FormingEndWrapper< Definition >
/// sequences within builder patterns.
// xxx : update description
pub trait FormerBegin< Definition : FormerDefinition >
pub trait FormerBegin< Definition : FormerDefinition2 >
{

/// * `End` - A trait bound marking the closure or handler invoked upon completing the subforming process. Implementers
/// of this trait (`End`) are tasked with applying the final transformations that transition `Storage`
/// into `Formed`, optionally utilizing `Context` to guide this transformation. It is crucial that this
/// associated type satisfies the `FormingEnd< Formed >` trait, defining the precise mechanics of
/// how the subformer concludes its operation.
type End : FormingEnd< Definition >;
// type End : FormingEnd< Definition >;
// type End : Definition::End;

/// Launches the subforming process with an initial storage and context, setting up an `on_end` completion handler.
///
Expand All @@ -199,9 +207,9 @@ pub trait FormerBegin< Definition : FormerDefinition >
/// * `on_end` - A completion handler responsible for transforming the accumulated `Storage` into the final `Formed` structure.
fn _begin
(
storage : core::option::Option< Definition::Storage >,
context : core::option::Option< Definition::Context >,
on_end : Self::End,
storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >,
context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >,
on_end : Definition::End,
) -> Self;

}
49 changes: 25 additions & 24 deletions module/core/former/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,28 +194,28 @@ where
// =

/// A builder for constructing containers, facilitating a fluent and flexible interface.
#[ derive( Debug, Default ) ]
#[ derive( Default ) ]
pub struct ContainerSubformer< E, Definition >
where
// End : FormingEnd< Definition >,
Definition : FormerDefinition,
Definition::Storage : ContainerAdd< Element = E >,
Definition : FormerDefinition2,
< Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >,
{
storage : core::option::Option< Definition::Storage >,
context : core::option::Option< Definition::Context >,
storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >,
context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >,
on_end : core::option::Option< Definition::End >,
}

impl< E, Definition > ContainerSubformer< E, Definition >
where
// End : FormingEnd< Definition >,
Definition : FormerDefinition,
Definition::Storage : ContainerAdd< Element = E >,
Definition : FormerDefinition2,
< Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >,
{

/// Form current former into target structure.
#[ inline( always ) ]
pub fn storage( mut self ) -> Definition::Storage
pub fn storage( mut self ) -> < Definition::Definition as FormerDefinition >::Storage
{
let storage = if self.storage.is_some()
{
Expand All @@ -233,8 +233,8 @@ where
#[ inline( always ) ]
pub fn begin
(
storage : core::option::Option< Definition::Storage >,
context : core::option::Option< Definition::Context >,
storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >,
context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >,
on_end : Definition::End,
) -> Self
{
Expand All @@ -248,7 +248,7 @@ where

/// Finalizes the building process, returning the formed or a context incorporating it.
#[ inline( always ) ]
pub fn end( mut self ) -> Definition::Formed
pub fn end( mut self ) -> < Definition::Definition as FormerDefinition >::Formed
{
let on_end = self.on_end.take().unwrap();
let context = self.context.take();
Expand All @@ -258,26 +258,27 @@ where

/// Finalizes the building process, returning the formed or a context incorporating it.
#[ inline( always ) ]
pub fn form( self ) -> Definition::Formed
pub fn form( self ) -> < Definition::Definition as FormerDefinition >::Formed
{
self.end()
}

/// Replaces the current storage with a provided one, allowing for a reset or redirection of the building process.
#[ inline( always ) ]
pub fn replace( mut self, vector : Definition::Storage ) -> Self
pub fn replace( mut self, vector : < Definition::Definition as FormerDefinition >::Storage ) -> Self
{
self.storage = Some( vector );
self
}

}

impl< E, T, Definition > ContainerSubformer< E, Definition >
impl< E, T, Definition, Definition1 > ContainerSubformer< E, Definition >
where
Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = ReturnStorage >,
Definition::Storage : ContainerAdd< Element = E >,
Definition::Storage : StoragePerform< Formed = Definition::Formed >,
Definition1 : FormerDefinition< Context = (), Storage = T, Formed = T >,
Definition : FormerDefinition2< Definition = Definition1, End = ReturnStorage >,
< Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >,
< Definition::Definition as FormerDefinition >::Storage : StoragePerform< Formed = < Definition::Definition as FormerDefinition >::Formed >,
{

/// Initializes a new `ContainerSubformer` instance, starting with an empty formed.
Expand All @@ -303,8 +304,8 @@ where
impl< E, Definition > ContainerSubformer< E, Definition >
where
// End : FormingEnd< Definition >,
Definition : FormerDefinition,
Definition::Storage : ContainerAdd< Element = E >,
Definition : FormerDefinition2,
< Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >,
{

/// Appends an element to the end of the storage, expanding the internal collection.
Expand Down Expand Up @@ -332,16 +333,16 @@ impl< E, Definition > FormerBegin< Definition >
for ContainerSubformer< E, Definition >
where
// End : FormingEnd< Definition >,
Definition : FormerDefinition,
Definition::Storage : ContainerAdd< Element = E >,
Definition : FormerDefinition2,
< Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >,
{
type End = Definition::End;
// type End = Definition::End;

#[ inline( always ) ]
fn _begin
(
storage : core::option::Option< Definition::Storage >,
context : core::option::Option< Definition::Context >,
storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >,
context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >,
on_end : Definition::End,
)
-> Self
Expand Down
Loading

0 comments on commit 28e23bf

Please sign in to comment.