Skip to content

Commit

Permalink
former : experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 24, 2024
1 parent 9bcd476 commit 30ab77c
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 73 deletions.
40 changes: 20 additions & 20 deletions module/core/former/src/axiomatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

pub trait Storage : ::core::default::Default
{
// type Definition : FormerDefinition< Storage = Self >;
// type Types : FormerDefinitionTypes< Storage = Self >;
type Formed;
}

/// xxx
pub trait StoragePerform : Storage
{
// fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed;
// fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed;
fn preform( self ) -> Self::Formed;
}

/// xxx
pub trait FormerDefinition : Sized
pub trait FormerDefinitionTypes : Sized
{
// type Storage : Storage< Definition = Self >;
// type Storage : Storage< Formed = Self::Formed >;
Expand All @@ -25,19 +25,19 @@ pub trait FormerDefinition : Sized
}

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

// pub trait FormerDefinition
// pub trait FormerDefinitionTypes
// {
// type Storage : StoragePerform< Formed = Self::Formed >;
// type Formed;
// type Context;
// type FormerDefinition : FormerDefinition< Storage = Self::Storage, Formed = Self::Formed >;
// type End : FormingEnd< Self::FormerDefinition, Self::Context >;
// type FormerDefinitionTypes : FormerDefinitionTypes< Storage = Self::Storage, Formed = Self::Formed >;
// type End : FormingEnd< Self::FormerDefinitionTypes, Self::Context >;
// }

/// Defines a handler for the end of a subforming process, enabling the return of the original context.
Expand All @@ -48,7 +48,7 @@ pub trait FormerDefinition2 : Sized
/// # Parameters
/// - `Storage`: The type of the container being processed.
/// - `Context`: The type of the context that might be altered or returned upon completion.
pub trait FormingEnd< Definition : FormerDefinition >
pub trait FormingEnd< Definition : FormerDefinitionTypes >
{
/// Called at the end of the subforming process to return the modified or original context.
///
Expand All @@ -64,7 +64,7 @@ pub trait FormingEnd< Definition : FormerDefinition >
impl< Definition, F > FormingEnd< Definition > for F
where
F : Fn( Definition::Storage, core::option::Option< Definition::Context > ) -> Definition::Formed,
Definition : FormerDefinition,
Definition : FormerDefinitionTypes,
{
#[ inline( always ) ]
fn call( &self, storage : Definition::Storage, context : core::option::Option< Definition::Context > ) -> Definition::Formed
Expand All @@ -84,7 +84,7 @@ where
// for ReturnFormed
// where
// Definition::Storage : StoragePerform< Formed = Definition::Formed >,
// Definition : FormerDefinition< Context = () >,
// Definition : FormerDefinitionTypes< Context = () >,
// {
// #[ inline( always ) ]
// fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed
Expand All @@ -100,7 +100,7 @@ pub struct ReturnStorage;
impl< Definition, T > FormingEnd< Definition >
for ReturnStorage
where
Definition : FormerDefinition< Context = (), Storage = T, Formed = T >,
Definition : FormerDefinitionTypes< Context = (), Storage = T, Formed = T >,
// Definition::End : FormingEnd< Definition >,
// Definition::End : Self,
// Definition::Storage : Default,
Expand All @@ -119,14 +119,14 @@ where
/// a closure needs to be stored or passed around as an object implementing
/// `FormingEnd`.
#[ cfg( not( feature = "no_std" ) ) ]
pub struct FormingEndWrapper< Definition : FormerDefinition >
pub struct FormingEndWrapper< Definition : FormerDefinitionTypes >
{
closure : Box< dyn Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed >,
_marker : std::marker::PhantomData< Definition::Storage >,
}

#[ cfg( not( feature = "no_std" ) ) ]
impl< Definition : FormerDefinition > FormingEndWrapper< Definition >
impl< Definition : FormerDefinitionTypes > FormingEndWrapper< Definition >
{
/// Constructs a new `FormingEndWrapper` with the provided closure.
///
Expand All @@ -152,7 +152,7 @@ impl< Definition : FormerDefinition > FormingEndWrapper< Definition >
#[ cfg( not( feature = "no_std" ) ) ]
use std::fmt;
#[ cfg( not( feature = "no_std" ) ) ]
impl< Definition : FormerDefinition > fmt::Debug for FormingEndWrapper< Definition >
impl< Definition : FormerDefinitionTypes > fmt::Debug for FormingEndWrapper< Definition >
{
fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result
{
Expand All @@ -164,7 +164,7 @@ impl< Definition : FormerDefinition > fmt::Debug for FormingEndWrapper< Definiti
}

#[ cfg( not( feature = "no_std" ) ) ]
impl< Definition : FormerDefinition > FormingEnd< Definition >
impl< Definition : FormerDefinitionTypes > FormingEnd< Definition >
for FormingEndWrapper< Definition >
{
fn call( &self, storage : Definition::Storage, context : Option< Definition::Context > ) -> Definition::Formed
Expand All @@ -188,7 +188,7 @@ for FormingEndWrapper< Definition >
/// sequences within builder patterns.

// xxx : update description
pub trait FormerBegin< Definition : FormerDefinition2 >
pub trait FormerBegin< Definition : FormerDefinition >
{

/// * `End` - A trait bound marking the closure or handler invoked upon completing the subforming process. Implementers
Expand All @@ -208,8 +208,8 @@ pub trait FormerBegin< Definition : FormerDefinition2 >
/// * `on_end` - A completion handler responsible for transforming the accumulated `Storage` into the final `Formed` structure.
fn _begin
(
storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >,
context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >,
storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >,
context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >,
on_end : Definition::End,
) -> Self;

Expand Down
46 changes: 23 additions & 23 deletions module/core/former/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,24 @@ where
pub struct ContainerSubformer< E, Definition >
where
// End : FormingEnd< Definition >,
Definition : FormerDefinition2,
< Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >,
Definition : FormerDefinition,
< Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >,
{
storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >,
context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >,
storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >,
context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >,
on_end : core::option::Option< Definition::End >,
}

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

/// Form current former into target structure.
#[ inline( always ) ]
pub fn storage( mut self ) -> < Definition::Definition as FormerDefinition >::Storage
pub fn storage( mut self ) -> < Definition::Types as FormerDefinitionTypes >::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::Definition as FormerDefinition >::Storage >,
context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >,
storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >,
context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::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::Definition as FormerDefinition >::Formed
pub fn end( mut self ) -> < Definition::Types as FormerDefinitionTypes >::Formed
{
let on_end = self.on_end.take().unwrap();
let context = self.context.take();
Expand All @@ -258,27 +258,27 @@ where

/// Finalizes the building process, returning the formed or a context incorporating it.
#[ inline( always ) ]
pub fn form( self ) -> < Definition::Definition as FormerDefinition >::Formed
pub fn form( self ) -> < Definition::Types as FormerDefinitionTypes >::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::Definition as FormerDefinition >::Storage ) -> Self
pub fn replace( mut self, vector : < Definition::Types as FormerDefinitionTypes >::Storage ) -> Self
{
self.storage = Some( vector );
self
}

}

impl< E, T, Definition, Definition1 > ContainerSubformer< E, Definition >
impl< E, T, Types, Definition > ContainerSubformer< E, Definition >
where
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 >,
Types : FormerDefinitionTypes< Context = (), Storage = T, Formed = T >,
Definition : FormerDefinition< Types = Types, End = ReturnStorage >,
< Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >,
< Definition::Types as FormerDefinitionTypes >::Storage : StoragePerform< Formed = < Definition::Types as FormerDefinitionTypes >::Formed >,
{

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

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

#[ inline( always ) ]
fn _begin
(
storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >,
context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >,
storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >,
context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >,
on_end : Definition::End,
)
-> Self
Expand Down
8 changes: 4 additions & 4 deletions module/core/former/src/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//
// // /// Return former.
// // #[ inline( always ) ]
// // fn former< Definition : FormerDefinition >( self )
// // fn former< Definition : FormerDefinitionTypes >( self )
// // ->
// // HashMapSubformer< K, E, Definition, (), impl FormingEnd< Self, Self > >
// // {
Expand Down Expand Up @@ -52,7 +52,7 @@
// where
// K : ::core::cmp::Eq + ::core::hash::Hash,
// {
// // type Definition = HashMapDefinition< K, E >;
// // type Types = HashMapDefinition< K, E >;
// type Formed = HashMap< K, E >;
// }
//
Expand All @@ -61,7 +61,7 @@
// where
// K : ::core::cmp::Eq + ::core::hash::Hash,
// {
// // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed
// // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed
// fn preform( self ) -> Self::Formed
// {
// self
Expand Down Expand Up @@ -90,7 +90,7 @@
// }
// }
//
// impl< K, E, Context, End > FormerDefinition
// impl< K, E, Context, End > FormerDefinitionTypes
// for HashMapDefinition< K, E, Context, End >
// where
// K : ::core::cmp::Eq + ::core::hash::Hash,
Expand Down
6 changes: 3 additions & 3 deletions module/core/former/src/hash_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// where
// K : ::core::cmp::Eq + ::core::hash::Hash,
// {
// // type Definition = HashSetDefinition< K >;
// // type Types = HashSetDefinition< K >;
// type Formed = HashSet< K >;
// }
//
Expand All @@ -49,7 +49,7 @@
// where
// K : ::core::cmp::Eq + ::core::hash::Hash,
// {
// // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed
// // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed
// fn preform( self ) -> Self::Formed
// {
// self
Expand Down Expand Up @@ -78,7 +78,7 @@
// }
// }
//
// impl< K, Context, End > FormerDefinition
// impl< K, Context, End > FormerDefinitionTypes
// for HashSetDefinition< K, Context, End >
// where
// K : ::core::cmp::Eq + ::core::hash::Hash,
Expand Down
8 changes: 4 additions & 4 deletions module/core/former/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ for Vec< E >
#[ derive( Debug ) ]
pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage >
// where
// Self : FormerDefinition,
// Self : FormerDefinitionTypes,
{
_phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >,
}
Expand All @@ -58,7 +58,7 @@ impl< E, Context, Formed > VectorDefinition< E, Context, Formed >
}
}

impl< E, Context, Formed > FormerDefinition
impl< E, Context, Formed > FormerDefinitionTypes
for VectorDefinition< E, Context, Formed >
{
type Storage = Vec< E >;
Expand All @@ -84,12 +84,12 @@ for VectorDefinition< E, Context, Formed >
// }
// }

impl< E, Context, Formed, End > FormerDefinition2
impl< E, Context, Formed, End > FormerDefinition
for VectorDefinition< E, Context, Formed, End >
where
End : FormingEnd< VectorDefinition< E, Context, Formed > >,
{
type Definition = VectorDefinition< E, Context, Formed >;
type Types = VectorDefinition< E, Context, Formed >;
type End = End;
}

Expand Down
Loading

0 comments on commit 30ab77c

Please sign in to comment.