From 71394ff416122d72792bf44cb225ba56ae57c9e8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 26 Mar 2024 16:16:07 +0200 Subject: [PATCH] experimenting --- module/core/former/src/axiomatic.rs | 16 +++++ .../inc/former_tests/container_former_vec.rs | 58 +++++++++++++++---- 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index d0df955b7c..b1677a41f9 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -118,6 +118,22 @@ pub struct FormingEndWrapper< Definition : FormerDefinitionTypes > _marker : std::marker::PhantomData< Definition::Storage >, } +impl< T, Definition > From< T > for FormingEndWrapper< Definition > +where + T : Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed + 'static, + Definition : FormerDefinitionTypes, +{ + #[ inline( always ) ] + fn from( closure : T ) -> Self + { + Self + { + closure : Box::new( closure ), + _marker : std::marker::PhantomData + } + } +} + #[ cfg( not( feature = "no_std" ) ) ] impl< Definition : FormerDefinitionTypes > FormingEndWrapper< Definition > { diff --git a/module/core/former/tests/inc/former_tests/container_former_vec.rs b/module/core/former/tests/inc/former_tests/container_former_vec.rs index eeddcdf650..1922543c4a 100644 --- a/module/core/former/tests/inc/former_tests/container_former_vec.rs +++ b/module/core/former/tests/inc/former_tests/container_former_vec.rs @@ -227,8 +227,6 @@ fn custom_definition() } } - // type MyContainer<> - // let got = the_module::ContainerSubformer::< String, Return13 >::begin( None, None, Return13 ) @@ -333,8 +331,31 @@ fn custom_definition_parametrized() // - // xxx : make it working? - // let got = the_module::ContainerSubformer::< String, Return13 >::new() +} + +// + +#[ test ] +fn custom_definition_custom_end() +{ + + struct Return13; + impl former::FormerDefinitionTypes for Return13 + { + type Storage = Vec< String >; + type Formed = i32; + type Context = (); + } + + impl former::FormerDefinition for Return13 + { + type Types = Return13; + type End = former::FormingEndWrapper< < Self as former::FormerDefinition >::Types >; + } + + // + + // let got = the_module::ContainerSubformer::< String, Return13 >::new( Return13 ) // .push( "a" ) // .push( "b" ) // .form(); @@ -343,14 +364,27 @@ fn custom_definition_parametrized() // -// // - -// -// fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 -// { -// 13 -// } -// -// let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); + fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 + { + 13 + } + + let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); + let got = the_module::ContainerSubformer::< String, Return13 >::new( end_wrapper ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + let got = the_module::ContainerSubformer::< String, Return13 >::new( return_13.into() ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + // }