From 1effc152f5d01e7107b76c158365d1138b652ea4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 15:13:09 +0200 Subject: [PATCH] former : experimenting --- .../inc/former_tests/a_primitives_manual.rs | 50 +++---- .../inc/former_tests/only_test/primitives.rs | 128 +++++++++++------- 2 files changed, 106 insertions(+), 72 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 1495f60c82..69a85e940e 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -201,30 +201,8 @@ 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 > + // 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 >, @@ -246,7 +224,29 @@ where // } #[ inline( always ) ] - pub fn begin + 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_explicit ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -308,7 +308,7 @@ where #[ inline( always ) ] pub fn new( on_end : Definition::End ) -> Self { - Self::begin( None, None, on_end ) + Self::begin_explicit( None, None, on_end ) } // zzz : update description diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 3ec5a77bca..c1f3c0fc34 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -43,43 +43,6 @@ tests_impls! // - fn begin() - { - - // begin with none - let got = Struct1Former::< Struct1FormerDefinition >::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(); - a_id!( got, exp ); - - // begin with context - let mut storage = Struct1FormerStorage::default(); - storage.int_1 = Some( 13 ); - let exp = Struct1Former::< Struct1FormerDefinition > - ::begin( Some( storage ), Some( () ), the_module::ReturnPreformed ) - .form(); - a_id!( got, exp ); - - } - - // - - fn new() - { - - let former = Struct1::former(); - let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); - a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); - - } - - // - fn custom_definition_params() { // zzz : make example of that @@ -127,15 +90,12 @@ tests_impls! // custom params let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, _ > > + ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > ::begin ( None, Some( 3 ), - former::FormingEndWrapper::new - ( - | storage : Struct1FormerStorage, context | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } - ), + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }, ) .int_1( 13 ) .form(); @@ -148,18 +108,16 @@ tests_impls! ( None, Some( 3 ), - ( - | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } - ).into(), + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }, ) .int_1( 13 ) .form(); a_id!( got, 32 ); - // custom params begin_with + // custom params begin let got = Struct1Former ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::begin_with + ::begin ( None, Some( 3 ), @@ -182,6 +140,81 @@ tests_impls! // + fn begin() + { + + // begin with none + let got = Struct1Former::< Struct1FormerDefinition >::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(); + a_id!( got, exp ); + + // begin with context + let mut storage = Struct1FormerStorage::default(); + storage.int_1 = Some( 13 ); + let exp = Struct1Former::< Struct1FormerDefinition > + ::begin( Some( storage ), Some( () ), the_module::ReturnPreformed ) + .form(); + a_id!( got, exp ); + + } + + // + + fn begin_explicit() + { + + // custom params + let got = Struct1Former + ::< Struct1FormerDefinition< i32, i32, _ > > + ::begin_explicit + ( + 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_explicit + ( + None, + Some( 3 ), + ( + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } + ).into(), + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); + + } + + // + + fn new() + { + + let former = Struct1::former(); + let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); + a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); + + } + + // + fn preform() { @@ -448,6 +481,7 @@ tests_index! { internals, begin, + begin_explicit, new, custom_definition_params, preform,