From 007007683c76c7b4fb3ce967f095ae3bd1a3b3e2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 25 Mar 2024 00:06:02 +0200 Subject: [PATCH] former : experimenting --- module/core/former/src/vector.rs | 39 ++++++++--------- .../inc/former_tests/container_former_vec.rs | 43 ++++++++++--------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 55548cc8f2..585157674d 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -45,14 +45,14 @@ for Vec< E > // = definition #[ derive( Debug ) ] -pub struct VectorDefinitionTypes< E, Context = () > +pub struct VectorDefinitionTypes< E, Context = (), Formed = Vec< E > > where Self : FormerDefinition, { - _phantom : core::marker::PhantomData< ( E, Context ) >, + _phantom : core::marker::PhantomData< ( E, Context, Formed ) >, } -impl< E, Context > VectorDefinitionTypes< E, Context > +impl< E, Context, Formed > VectorDefinitionTypes< E, Context, Formed > { pub fn new() -> Self { @@ -60,26 +60,25 @@ impl< E, Context > VectorDefinitionTypes< E, Context > } } -impl< E, Context > FormerDefinition -for VectorDefinitionTypes< E, Context > +impl< E, Context, Formed > FormerDefinition +for VectorDefinitionTypes< E, Context, Formed > { type Storage = Vec< E >; - type Formed = Vec< E >; + type Formed = Formed; type Context = Context; } #[ derive( Debug ) ] -pub struct VectorDefinition< E, Context = (), End = ReturnStorage > -// pub struct VectorDefinition< E, Context, End > +pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > where - End : FormingEnd< VectorDefinitionTypes< E, Context > >, + End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, { - _phantom : core::marker::PhantomData< ( E, Context, End ) >, + _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, } -impl< E, Context, End > VectorDefinition< E, Context, End > +impl< E, Context, Formed, End > VectorDefinition< E, Context, Formed, End > where - End : FormingEnd< VectorDefinitionTypes< E, Context > >, + End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, { pub fn new() -> Self { @@ -87,12 +86,12 @@ where } } -impl< E, Context, End > FormerDefinition2 -for VectorDefinition< E, Context, End > +impl< E, Context, Formed, End > FormerDefinition2 +for VectorDefinition< E, Context, Formed, End > where - End : FormingEnd< VectorDefinitionTypes< E, Context > >, + End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, { - type Definition = VectorDefinitionTypes< E, Context >; + type Definition = VectorDefinitionTypes< E, Context, Formed >; type End = End; } @@ -103,20 +102,20 @@ where /// `VectorSubformer` leverages the `VectorLike` trait to enable the construction and manipulation /// of vector-like containers in a builder pattern style, promoting readability and ease of use. -pub type VectorSubformer< E, Context, End > = ContainerSubformer::< E, VectorDefinition< E, Context, End > >; +pub type VectorSubformer< E, Context, Formed, End > = ContainerSubformer::< E, VectorDefinition< E, Context, Formed, End > >; // = extension pub trait VecExt< E > : sealed::Sealed { - fn former() -> VectorSubformer< E, (), ReturnStorage >; + fn former() -> VectorSubformer< E, (), Vec< E >, ReturnStorage >; } impl< E > VecExt< E > for Vec< E > { - fn former() -> VectorSubformer< E, (), ReturnStorage > + fn former() -> VectorSubformer< E, (), Vec< E >, ReturnStorage > { - VectorSubformer::< E, (), ReturnStorage >::new() + VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new() } } 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 1be6be27ca..30bd0b8dad 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 @@ -29,9 +29,9 @@ fn definitions() } f1( former::VectorDefinitionTypes::< String, () >::new() ); - f2( former::VectorDefinition::< String, (), the_module::ReturnStorage >::new() ); + f2( former::VectorDefinition::< String, (), Vec< String >, the_module::ReturnStorage >::new() ); f3::< former::VectorDefinitionTypes< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage ); - f3::< < former::VectorDefinition< String, (), the_module::ReturnStorage > as the_module::FormerDefinition2 >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage ); + f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > as the_module::FormerDefinition2 >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage ); } @@ -45,7 +45,7 @@ fn push() let got : Vec< String > = the_module ::ContainerSubformer - ::< String, former::VectorDefinition< String, (), the_module::ReturnStorage > > + ::< String, former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > > ::new() .push( "a" ) .push( "b" ) @@ -62,7 +62,7 @@ fn push() let got : Vec< String > = the_module::ContainerSubformer:: < String, - former::VectorDefinition< String, (), the_module::ReturnStorage >, + former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage >, >::new() .push( "a" ) .push( "b" ) @@ -76,7 +76,7 @@ fn push() // - let got : Vec< String > = the_module::VectorSubformer::< String, (), the_module::ReturnStorage >::new() + let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage >::new() .push( "a" ) .push( "b" ) .form(); @@ -144,27 +144,30 @@ fn custom_end() { // xxx2 : continue - // struct Return13; - // impl former::FormerDefinition for Return13 - // { - // type Storage = Vec< u32 >; - // type Formed = i32; - // type Context = (); - // } - - // fn return_13( _storage : Vec< i32 >, _context : Option< () > ) -> i32 - // { - // 13 - // } - // let end_wrapper = the_module::FormingEndWrapper::new( return_13 ); - - // let got : i32 = the_module::VectorSubformer::< String, (), return_13 >::new() + struct Return13; + impl former::FormerDefinition for Return13 + { + type Storage = Vec< String >; + type Formed = i32; + type Context = (); + } + + 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 : i32 = the_module::VectorSubformer::< String, (), _ >::begin( None, (), return_13 ) // .push( "a" ) // .push( "b" ) // .form(); // let exp = 13; // a_id!( got, exp ); + // pub type VectorSubformer< E, Context, End > = ContainerSubformer::< E, VectorDefinition< E, Context, End > >; + } //