Skip to content

Commit

Permalink
former : experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 30, 2024
1 parent 8a30e61 commit d039502
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 42 deletions.
86 changes: 46 additions & 40 deletions module/core/former/tests/inc/former_tests/a_primitives_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ pub struct Struct1Former
>
where
Definition : former::FormerDefinition,
< Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform,
Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >,
< Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform,
{
storage : < Definition::Types as former::FormerDefinitionTypes >::Storage,
context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >,
Expand All @@ -190,8 +190,8 @@ where
impl< Definition > Struct1Former< Definition >
where
Definition : former::FormerDefinition,
< Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform,
Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >,
< Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform,
{

#[ inline( always ) ]
Expand All @@ -201,6 +201,50 @@ where
return result;
}

#[ inline( always ) ]
pub fn begin_with< IntoEnd >
(
mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >,
context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >,
on_end : IntoEnd,
) -> Self
where
IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >
{
if storage.is_none()
{
storage = Some( core::default::Default::default() );
}
Self
{
storage : storage.unwrap(),
context,
on_end : ::core::option::Option::Some( on_end.into() ),
}
}

// #[ inline( always ) ]
// pub fn begin< IntoEnd >
// (
// mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >,
// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >,
// on_end : IntoEnd,
// ) -> Self
// where
// IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >
// {
// if storage.is_none()
// {
// storage = Some( core::default::Default::default() );
// }
// Self
// {
// storage : storage.unwrap(),
// context,
// on_end : ::core::option::Option::Some( on_end.into() ),
// }
// }

#[ inline( always ) ]
pub fn begin
(
Expand Down Expand Up @@ -297,44 +341,6 @@ where

}

// // impl Struct1Former
//
// impl< Definition > Struct1Former< Definition >
// where
// // Types : FormerDefinitionTypes< Context = () >,
// Definition : former::FormerDefinition< End = former::ReturnPreformed >,
// Definition::Types : former::FormerDefinitionTypes
// <
// Storage = Struct1FormerStorage,
// Formed = Struct1,
// Context = (),
// >,
// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, // xxx : redundant?
// {
//
// // zzz : update description
// #[ inline( always ) ]
// pub fn new( on_end : Definition::End ) -> Self
// {
// Self::begin( None, None, on_end )
// }
//
// // zzz : update description
// #[ inline( always ) ]
// pub fn new_with< IntoEnd >( end : IntoEnd ) -> Self
// where
// IntoEnd : Into< Definition::End >,
// {
// Self::begin
// (
// None,
// None,
// end.into(),
// )
// }
//
// }

//

include!( "./only_test/primitives.rs" );
66 changes: 64 additions & 2 deletions module/core/former/tests/inc/former_tests/only_test/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ tests_impls!

fn custom_definition_params()
{
// zzz : make example of that

// default explicit params
let got = Struct1Former
Expand All @@ -92,7 +93,7 @@ tests_impls!
let exp = Struct1::former().int_1( 13 ).form();
a_id!( got, exp );

// default explicit params
// default explicit params with wrapper
fn f1( storage : Struct1FormerStorage, _context : Option< () > ) -> Struct1
{
former::StoragePreform::preform( storage )
Expand All @@ -101,12 +102,73 @@ tests_impls!
let got = Struct1Former
::< Struct1FormerDefinition< (), Struct1, _ > >
::new( end_wrapper )
// ::new( ( | storage : Struct1FormerStorage, _context | -> Struct1 { former::StoragePreform::preform( storage ) } ).into() )
.int_1( 13 )
.form();
let exp = Struct1::former().int_1( 13 ).form();
a_id!( got, exp );

// default explicit params with wrapper and closure
let got = Struct1Former
::< Struct1FormerDefinition< (), Struct1, _ > >
::new( former::FormingEndWrapper::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) )
.int_1( 13 )
.form();
let exp = Struct1::former().int_1( 13 ).form();
a_id!( got, exp );

// default explicit params with wrapper and closure, auto types
let got = Struct1Former
::< Struct1FormerDefinition< _, _, _ > >
::new( former::FormingEndWrapper::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) )
.int_1( 13 )
.form();
let exp = Struct1::former().int_1( 13 ).form();
a_id!( got, exp );

// custom params
let got = Struct1Former
::< Struct1FormerDefinition< i32, i32, _ > >
::begin
(
None,
Some( 3 ),
former::FormingEndWrapper::new
(
| storage : Struct1FormerStorage, context | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }
),
)
.int_1( 13 )
.form();
a_id!( got, 32 );

// custom params with into
let got = Struct1Former
::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > >
::begin
(
None,
Some( 3 ),
(
| storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }
).into(),
)
.int_1( 13 )
.form();
a_id!( got, 32 );

// custom params begin_with
let got = Struct1Former
::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > >
::begin_with
(
None,
Some( 3 ),
| storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }
)
.int_1( 13 )
.form();
a_id!( got, 32 );

// xxx2 : continue
// // default explicit params
// let got = Struct1Former
Expand Down

0 comments on commit d039502

Please sign in to comment.