Skip to content

Commit

Permalink
former : experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Apr 13, 2024
1 parent fc2d60e commit f321d3e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 96 deletions.
75 changes: 40 additions & 35 deletions module/core/former/tests/inc/former_tests/a_basic_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ pub struct Struct1
impl Struct1
{

// #[ inline( always ) ]
// pub fn former() -> Struct1Former< >
// {
// Struct1Former::< >::new( former::ReturnPreformed )
// }

#[ inline( always ) ]
pub fn former() -> Struct1Former< (), Struct1, former::ReturnPreformed >
pub fn former() -> Struct1Former< >
{
Struct1Former::< _, _, _ >::new( former::ReturnPreformed )
Struct1Former::< >::new( former::ReturnPreformed )
}

// #[ inline( always ) ]
// // pub fn former() -> Struct1Former< (), Struct1, former::ReturnPreformed >
// pub fn former() -> Struct1Former
// {
// Struct1Former::< _, _, _ >::new( former::ReturnPreformed )
// }

}

// = definition types

#[ derive( Debug ) ]
pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 >
// pub struct Struct1FormerDefinitionTypes< Context, Formed >
// pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 >
pub struct Struct1FormerDefinitionTypes< Context, Formed >
{
_phantom : core::marker::PhantomData< ( Context, Formed ) >,
}
Expand All @@ -56,8 +57,8 @@ impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitio
// = definition

#[ derive( Debug ) ]
pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed >
// pub struct Struct1FormerDefinition< Context, Formed, End >
// pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed >
pub struct Struct1FormerDefinition< Context, Formed, End >
{
_phantom : core::marker::PhantomData< ( Context, Formed, End ) >,
}
Expand Down Expand Up @@ -138,33 +139,36 @@ impl former::StoragePreform for Struct1FormerStorage

// = former

// type Struct1Former< Definition > = Struct1Former< (), Struct1, former::ReturnPreformed, Definition >;

pub struct Struct1Former
<
Context = (),
Formed = Struct1,
End = former::ReturnPreformed,
Definition = Struct1FormerDefinition< Context, Formed, End >,
// Context = (),
// Formed = Struct1,
// End = former::ReturnPreformed,
Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >,
>
where
End : former::FormingEnd::< Definition::Types >,
Definition : former::FormerDefinition< End = End >,
Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Formed, Context = Context >,
// Definition : former::FormerDefinition,
// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >,
// End : former::FormingEnd::< Definition::Types >,
// Definition : former::FormerDefinition< End = End >,
// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Formed, Context = Context >,
Definition : former::FormerDefinition,
Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >,
{
storage : < Definition::Types as former::FormerDefinitionTypes >::Storage,
context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >,
on_end : core::option::Option< Definition::End >,
}

#[ automatically_derived ]
impl< Context, Formed, End, Definition > Struct1Former< Context, Formed, End, Definition >
// impl< Context, Formed, End, Definition > Struct1Former< Context, Formed, End, Definition >
impl< Definition > Struct1Former< Definition >
where
End : former::FormingEnd::< Definition::Types >,
Definition : former::FormerDefinition< End = End >,
Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Formed, Context = Context >,
// Definition : former::FormerDefinition,
// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >,
// End : former::FormingEnd::< Definition::Types >,
// Definition : former::FormerDefinition< End = End >,
// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Formed, Context = Context >,
Definition : former::FormerDefinition,
Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >,
{

#[ inline( always ) ]
Expand Down Expand Up @@ -257,16 +261,17 @@ where

// = preform with Storage::preform

impl< Context, End, Definition > Struct1Former< Context, Struct1, End, Definition >
// impl< Context, End, Definition > Struct1Former< Context, Struct1, End, Definition >
impl< Definition > Struct1Former< Definition >
where
End : former::FormingEnd::< Definition::Types >,
Definition : former::FormerDefinition< End = End >,
Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1, Context = Context >,
< Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform,
< Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Struct1 >,
// Definition : former::FormerDefinition,
// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >,
// End : former::FormingEnd::< Definition::Types >,
// Definition : former::FormerDefinition< End = End >,
// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1, Context = Context >,
// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform,
// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Struct1 >,
Definition : former::FormerDefinition,
Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >,
< Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform,
{
pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed
{
Expand Down
90 changes: 29 additions & 61 deletions module/core/former/tests/inc/former_tests/only_test/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ tests_impls!
a_id!( former.storage.int_1, None );
a_id!( former.context, None );
a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) );
let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed );
let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new( former::ReturnPreformed );
a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) );
// let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed );
// a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) );
// xxx : uncomment

let command = Struct1::former().form();
a_id!( command.int_1, 0 );
Expand All @@ -39,9 +42,6 @@ tests_impls!
let got = Struct1Former
::
<
_,
_,
_,
Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > >
>
::begin
Expand All @@ -58,9 +58,6 @@ tests_impls!
let got = Struct1Former
::
<
_,
_,
_,
Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > >
>
::begin
Expand All @@ -77,9 +74,7 @@ tests_impls!
let got = Struct1Former
::
<
_,
_,
_,

Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > >
>
::begin
Expand All @@ -96,9 +91,7 @@ tests_impls!
let got = Struct1Former
::
<
_,
_,
_,

Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > >
>
::begin
Expand All @@ -115,9 +108,7 @@ tests_impls!
let got = Struct1Former
::
<
_,
_,
_,

Struct1FormerDefinition< i32, i32, former::FormingEndClosure< _ > >
>
::begin
Expand All @@ -138,14 +129,14 @@ tests_impls!
{

// begin with none
let got = Struct1Former::< Struct1FormerDefinition >::begin( None, None, the_module::ReturnPreformed ).int_1( 13 ).form();
let got = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::begin( None, None, the_module::ReturnPreformed ).int_1( 13 ).form();
let exp = Struct1::former().int_1( 13 ).form();
a_id!( got, exp );

// begin with storage
let mut storage = Struct1FormerStorage::default();
storage.int_1 = Some( 13 );
let exp = Struct1Former::< Struct1FormerDefinition >::begin( Some( storage ), None, the_module::ReturnPreformed ).form();
let exp = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::begin( Some( storage ), None, the_module::ReturnPreformed ).form();
a_id!( got, exp );

// begin with context
Expand All @@ -154,10 +145,7 @@ tests_impls!
let exp = Struct1Former
::
<
_,
_,
_,
Struct1FormerDefinition
Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >
>
::begin( Some( storage ), Some( () ), the_module::ReturnPreformed )
.form();
Expand All @@ -175,9 +163,7 @@ tests_impls!
// ::< Struct1FormerDefinition< i32, i32, _ > >
::
<
_,
_,
_,

Struct1FormerDefinition< i32, i32, _ >
>
::_begin_precise
Expand All @@ -198,9 +184,7 @@ tests_impls!
// ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > >
::
<
_,
_,
_,

Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > >
>
::_begin_precise
Expand All @@ -224,7 +208,7 @@ tests_impls!

// basic case
let former = Struct1::former();
let former2 = Struct1Former::< Struct1FormerDefinition >::_new_precise( former::ReturnPreformed );
let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::_new_precise( former::ReturnPreformed );
a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) );
let exp = former.form();
let got = former2.form();
Expand All @@ -249,9 +233,7 @@ tests_impls!
// ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > >
::
<
_,
_,
_,

Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > >
>
::new( end_wrapper )
Expand All @@ -265,9 +247,7 @@ tests_impls!
// ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > >
::
<
_,
_,
_,

Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > >
>
::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) )
Expand All @@ -281,9 +261,7 @@ tests_impls!
// ::< Struct1FormerDefinition< _, _, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > >
::
<
_,
_,
_,

Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > >
>
::new( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) )
Expand All @@ -297,9 +275,7 @@ tests_impls!
// ::< Struct1FormerWithClosure< (), Struct1 > >
::
<
_,
_,
_,

Struct1FormerWithClosure< (), Struct1 >
>
::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) )
Expand All @@ -313,9 +289,7 @@ tests_impls!
// ::< Struct1FormerWithClosure< (), Struct1 > >
::
<
_,
_,
_,

Struct1FormerWithClosure< (), Struct1 >
>
::new( | storage, _context | { former::StoragePreform::preform( storage ) } )
Expand All @@ -333,7 +307,7 @@ tests_impls!

// basic case
let former = Struct1::former();
let former2 = Struct1Former::< Struct1FormerDefinition >::_new_precise( former::ReturnPreformed );
let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::_new_precise( former::ReturnPreformed );
a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) );
let exp = former.form();
let got = former2.form();
Expand All @@ -344,9 +318,7 @@ tests_impls!
// ::< Struct1FormerDefinition< (), Struct1, _ > >
::
<
_,
_,
_,

Struct1FormerDefinition< (), Struct1, _ >,
>
::_new_precise( former::ReturnPreformed )
Expand All @@ -365,9 +337,7 @@ tests_impls!
// ::< Struct1FormerDefinition< (), Struct1, _ > >
::
<
_,
_,
_,

Struct1FormerDefinition< (), Struct1, _ >,
>
::_new_precise( end_wrapper )
Expand All @@ -381,9 +351,7 @@ tests_impls!
// ::< Struct1FormerDefinition< (), Struct1, _ > >
::
<
_,
_,
_,

Struct1FormerDefinition< (), Struct1, _ >,
>
::_new_precise( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) )
Expand All @@ -397,9 +365,7 @@ tests_impls!
// ::< Struct1FormerDefinition< _, _, _ > >
::
<
_,
_,
_,

Struct1FormerDefinition< _, _, _ >,
>
::_new_precise( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) )
Expand Down Expand Up @@ -439,7 +405,7 @@ tests_impls!
{

// default is implemented for definition
let _default = Struct1FormerDefinition::< () >::default();
let _default = Struct1FormerDefinition::< (), Struct1, former::ReturnPreformed >::default();
// let _default = Struct1FormerDefinition::default(); // why does not work?

// definition types exists and has Formed
Expand All @@ -448,18 +414,20 @@ tests_impls!
a_id!( got, exp );

// definition types exists and has Formed
let got = < Struct1FormerDefinitionTypes as the_module::FormerDefinitionTypes >::Formed::former().form();
let got = < Struct1FormerDefinitionTypes< (), Struct1 > as the_module::FormerDefinitionTypes >::Formed::former().form();
let exp = Struct1::former().form();
a_id!( got, exp );

// definition types exists and has Storage
use former::StoragePreform;
let got = < Struct1FormerDefinitionTypes as the_module::FormerDefinitionTypes >::Storage::preform( Struct1::former().storage );
let got = < Struct1FormerDefinitionTypes< (), Struct1 > as the_module::FormerDefinitionTypes >::Storage
::preform( Struct1::former().storage );
let exp = Struct1::former().form();
a_id!( got, exp );

// definition exists and has Storage
let got = < < Struct1FormerDefinition as the_module::FormerDefinition >::Types as the_module::FormerDefinitionTypes >::Formed::former().form();
let got = < < Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > as the_module::FormerDefinition >::Types as the_module::FormerDefinitionTypes >::Formed
::former().form();
let exp = Struct1::former().form();
a_id!( got, exp );

Expand Down

0 comments on commit f321d3e

Please sign in to comment.