From 2fb1bfd52cc7d11f16de1ff1250c5c7e31cb3624 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 26 Mar 2024 14:49:50 +0200 Subject: [PATCH] experimenting --- module/core/former/src/container.rs | 40 +++++++++--- module/core/former/src/vector.rs | 2 +- .../inc/former_tests/container_former_vec.rs | 61 +++++++++++++++---- 3 files changed, 83 insertions(+), 20 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 57406a4eca..5fbf8cb7c4 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -273,12 +273,39 @@ where } -impl< E, T, Types, Definition > ContainerSubformer< E, Definition > +// impl< E, T, Types, Definition > ContainerSubformer< E, Definition > +// where +// Types : FormerDefinitionTypes< Context = (), Storage = T, Formed = T >, +// Definition : FormerDefinition< Types = Types, End = ReturnStorage >, +// < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, +// < Definition::Types as FormerDefinitionTypes >::Storage : StoragePerform< Formed = < Definition::Types as FormerDefinitionTypes >::Formed >, +// { +// +// // xxx : update description +// /// Initializes a new `ContainerSubformer` instance, starting with an empty formed. +// /// This function serves as the entry point for the builder pattern. +// /// +// /// # Returns +// /// A new instance of `ContainerSubformer` with an empty internal formed. +// /// +// #[ inline( always ) ] +// pub fn new_returning_storage() -> Self +// { +// Self::begin +// ( +// None, +// None, +// ReturnStorage, +// ) +// } +// +// } + +impl< E, Storage, Formed, Types, Definition > ContainerSubformer< E, Definition > where - Types : FormerDefinitionTypes< Context = (), Storage = T, Formed = T >, - Definition : FormerDefinition< Types = Types, End = ReturnStorage >, + Types : FormerDefinitionTypes< Context = (), Storage = Storage, Formed = Formed >, + Definition : FormerDefinition< Types = Types >, < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, - < Definition::Types as FormerDefinitionTypes >::Storage : StoragePerform< Formed = < Definition::Types as FormerDefinitionTypes >::Formed >, { /// Initializes a new `ContainerSubformer` instance, starting with an empty formed. @@ -288,14 +315,13 @@ where /// A new instance of `ContainerSubformer` with an empty internal formed. /// #[ inline( always ) ] - pub fn new() -> Self + pub fn new( end : Definition::End ) -> Self { Self::begin ( None, None, - ReturnStorage, - // ReturnFormed, + end, ) } diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 27a4589863..55abb524e3 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -113,7 +113,7 @@ impl< E > VecExt< E > for Vec< E > { fn former() -> VectorSubformer< E, (), Vec< E >, ReturnStorage > { - VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new() + VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new( Default::default() ) } } 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 925d9f9945..eeddcdf650 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 @@ -46,7 +46,7 @@ fn push() let got : Vec< String > = the_module ::ContainerSubformer ::< String, former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > > - ::new() + ::new( former::ReturnStorage ) .push( "a" ) .push( "b" ) .form(); @@ -63,7 +63,7 @@ fn push() < String, former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage >, - >::new() + >::new( former::ReturnStorage ) .push( "a" ) .push( "b" ) .form(); @@ -76,7 +76,7 @@ fn push() // - let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage >::new() + let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage >::new( former::ReturnStorage ) .push( "a" ) .push( "b" ) .form(); @@ -89,7 +89,7 @@ fn push() // - let got : Vec< String > = the_module::VectorSubformer::new() + let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) .push( "a" ) .push( "b" ) .form(); @@ -124,7 +124,7 @@ fn push() fn replace() { - let got : Vec< String > = the_module::VectorSubformer::new() + let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) .push( "x" ) .replace( vec![ "a".to_string(), "b".to_string() ] ) .form(); @@ -147,7 +147,7 @@ fn begin_and_custom_end() // basic case - fn return_13( _storage : Vec< String >, context : Option< () > ) -> f32 + fn return_13( _storage : Vec< String >, _context : Option< () > ) -> f32 { 13.1 } @@ -158,6 +158,13 @@ fn begin_and_custom_end() let exp = 13.1; a_id!( got, exp ); + let got = the_module::VectorSubformer::new( return_13 ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13.1; + a_id!( got, exp ); + // with a context fn context_plus_13( _storage : Vec< String >, context : Option< f32 > ) -> f32 @@ -212,8 +219,8 @@ fn custom_definition() fn call ( &self, - storage : < Return13 as the_module::FormerDefinitionTypes >::Storage, - context : Option< < Return13 as the_module::FormerDefinitionTypes >::Context > + _storage : < Return13 as the_module::FormerDefinitionTypes >::Storage, + _context : Option< < Return13 as the_module::FormerDefinitionTypes >::Context > ) -> < Return13 as the_module::FormerDefinitionTypes >::Formed { 13 @@ -231,6 +238,13 @@ fn custom_definition() let exp = 13; a_id!( got, exp ); + let got = the_module::ContainerSubformer::< String, Return13 >::new( Return13 ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + // } @@ -275,16 +289,14 @@ fn custom_definition_parametrized() fn call ( &self, - storage : < Return13< E > as the_module::FormerDefinitionTypes >::Storage, - context : Option< < Return13< E > as the_module::FormerDefinitionTypes >::Context > + _storage : < Return13< E > as the_module::FormerDefinitionTypes >::Storage, + _context : Option< < Return13< E > as the_module::FormerDefinitionTypes >::Context > ) -> < Return13< E > as the_module::FormerDefinitionTypes >::Formed { 13 } } - // type MyContainer< Type > - // let got = the_module::ContainerSubformer::< String, Return13< String > >::begin( None, None, Return13::new() ) @@ -294,6 +306,31 @@ fn custom_definition_parametrized() let exp = 13; a_id!( got, exp ); + let got = the_module::ContainerSubformer::< String, Return13< String > >::new( Return13::new() ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + // + + type MyContainer< E > = the_module::ContainerSubformer::< E, Return13< E > >; + + let got = MyContainer::< String >::begin( None, None, Return13::new() ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + let got = MyContainer::< String >::new( Return13::new() ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + // // xxx : make it working?