From be8af871067a769a5d437d42a2412959f4436408 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 17:44:24 +0200 Subject: [PATCH] former : experimenting --- .../inc/former_tests/a_primitives_manual.rs | 56 ++++++++-------- module/core/former/tests/inc/mod.rs | 2 +- module/core/former_meta/src/derive/former.rs | 67 ++++++++----------- 3 files changed, 57 insertions(+), 68 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 c2690cbe7e..72e549ff21 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 @@ -205,15 +205,33 @@ where return result; } + // zzz : update description #[ inline( always ) ] - pub fn begin< IntoEnd > + pub fn _new_precise( on_end : Definition::End ) -> Self + { + Self::_begin_precise( None, None, on_end ) + } + + #[ inline( always ) ] + pub fn new< IntoEnd >( end : IntoEnd ) -> Self + where + IntoEnd : Into< Definition::End >, + { + Self::begin + ( + None, + None, + end, + ) + } + + #[ inline( always ) ] + pub fn _begin_precise ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : IntoEnd, + on_end : < Definition as former::FormerDefinition >::End, ) -> Self - where - IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > { if storage.is_none() { @@ -223,17 +241,19 @@ where { storage : storage.unwrap(), context, - on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), + on_end : ::core::option::Option::Some( on_end ), } } #[ inline( always ) ] - pub fn _begin_precise + 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 : < Definition as former::FormerDefinition >::End, + on_end : IntoEnd, ) -> Self + where + IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > { if storage.is_none() { @@ -243,7 +263,7 @@ where { storage : storage.unwrap(), context, - on_end : ::core::option::Option::Some( on_end ), + on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), } } @@ -286,26 +306,6 @@ where self } - // zzz : update description - #[ inline( always ) ] - pub fn _new_precise( on_end : Definition::End ) -> Self - { - Self::_begin_precise( None, None, on_end ) - } - - #[ inline( always ) ] - pub fn new< IntoEnd >( end : IntoEnd ) -> Self - where - IntoEnd : Into< Definition::End >, - { - Self::begin - ( - None, - None, - end, - ) - } - } impl< Definition > Struct1Former< Definition > diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index b25ec0ee45..69a9418704 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -18,7 +18,7 @@ mod former_tests mod a_primitives_manual; // mod a_primitives_expanded; - // mod a_primitives; + mod a_primitives; // mod a_containers_without_subformer_manual; // mod a_containers_without_subformer; // #[ cfg( not( feature = "no_std" ) ) ] diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index b31ce41d32..938d9e28e6 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1118,6 +1118,33 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #perform } + /// + /// Construct new instance of former with default parameters. + /// + // zzz : improve description + #[ inline( always ) ] + pub fn _new_precise( on_end : Definition::End ) -> Self + { + Self::begin( None, None, on_end ) + } + + /// + /// Construct new instance of former with default parameters. + /// + // zzz : improve description + #[ inline( always ) ] + pub fn new< IntoEnd >( end : IntoEnd ) -> Self + where + IntoEnd : Into< Definition::End >, + { + Self::begin + ( + None, + None, + end, + ) + } + /// /// Begin the process of forming. Expects context of forming to return it after forming. /// @@ -1147,7 +1174,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// // zzz : improve description #[ 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 >, @@ -1168,28 +1195,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } -// #[ 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() ), -// } -// } - /// /// End the process of forming returning original context of forming. /// @@ -1233,22 +1238,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } - #[ automatically_derived ] - impl #generics_impl #former < #generics_params > - #generics_where - { - - /// - /// Construct new instance of former with default parameters. - /// - #[ inline( always ) ] - pub fn new( on_end : < #former_definition as former::FormerDefinition >::End ) -> Self - { - Self::begin( None, None, on_end ) - } - - } - }; if has_debug