From 7eceedbcfab8ac0a89bfdadf9378e60e86bd3821 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 19:09:22 +0200 Subject: [PATCH] former : experimenting --- .../a_containers_with_subformer.rs | 4 +- .../a_containers_with_subformer_2_manual.rs | 299 ++++++++++++ .../a_containers_with_subformer_manual.rs | 443 +++++++++++------- .../a_containers_without_subformer_manual.rs | 178 ------- module/core/former/tests/inc/mod.rs | 11 +- 5 files changed, 575 insertions(+), 360 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs delete mode 100644 module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 6a1cbc6892..53d8f86ad4 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -5,6 +5,7 @@ use super::*; // use std::collections::HashSet; #[ derive( Debug, PartialEq, the_module::Former ) ] +#[ debug ] pub struct Struct1 { #[ subformer( the_module::VectorSubformer ) ] @@ -15,4 +16,5 @@ pub struct Struct1 hashset_strings_1 : std::collections::HashSet< String >, } -include!( "./only_test/containers_with_subformer.rs" ); +// include!( "./only_test/containers_with_subformer.rs" ); +// xxx : uncomment \ No newline at end of file diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs new file mode 100644 index 0000000000..bd65a36594 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs @@ -0,0 +1,299 @@ +#[ allow( unused_imports ) ] +use super::*; + +// xxx : take care + +#[ derive( Debug, PartialEq ) ] +pub struct Struct1 +{ + vec_1 : Vec< String >, + hashmap_strings_1 : std::collections::HashMap< String, String >, + hashset_strings_1 : std::collections::HashSet< String >, +} + +// = formed + +impl Struct1 +{ + pub fn former() -> Struct1Former< Struct1, the_module::ReturnPreformed > + { + Struct1Former::< Struct1, the_module::ReturnPreformed >::new() + } +} + +// = storage + +// generated by former +pub struct Struct1FormerStorage +{ + pub vec_1 : ::core::option::Option< Vec< String > >, + pub hashmap_strings_1 : ::core::option::Option< std::collections::HashMap< String, String > >, + pub hashset_strings_1 : ::core::option::Option< std::collections::HashSet< String > >, +} + +impl Default for Struct1FormerStorage +{ + + #[ inline( always ) ] + fn default() -> Self + { + Self + { + vec_1 : None, + hashmap_strings_1 : None, + hashset_strings_1 : None, + } + } + +} + +// = former + +pub struct Struct1Former +< + Context = Struct1, + End = the_module::ReturnPreformed, +> +where + End : the_module::FormingEnd< Struct1, Context >, +{ + storage : Struct1FormerStorage, + context : ::core::option::Option< Context >, + on_end : ::core::option::Option< End >, +} + +impl< Context, End > Struct1Former< Context, End > +where + End : the_module::FormingEnd< Struct1, Context >, +{ + + #[ inline( always ) ] + fn form( mut self ) -> Struct1 + { + + let vec_1 = if self.storage.vec_1.is_some() + { + self.storage.vec_1.take().unwrap() + } + else + { + let val : Vec< String > = Default::default(); + val + }; + + let hashmap_strings_1 = if self.storage.hashmap_strings_1.is_some() + { + self.storage.hashmap_strings_1.take().unwrap() + } + else + { + let val : std::collections::HashMap< String, String > = Default::default(); + val + }; + + let hashset_strings_1 = if self.storage.hashset_strings_1.is_some() + { + self.storage.hashset_strings_1.take().unwrap() + } + else + { + let val : std::collections::HashSet< String > = Default::default(); + val + }; + + Struct1 + { + vec_1, + hashmap_strings_1, + hashset_strings_1, + } + + } + + #[ inline( always ) ] + pub fn perform(self) -> Struct1 + { + let result = self.form(); + return result; + } + + // #[ inline( always ) ] + // pub fn new() -> Struct1Former + // { + // Struct1Former:: + // < + // Struct1, + // the_module::ReturnPreformed, + // >::begin(None, the_module::ReturnPreformed) + // } + + #[ inline( always ) ] + pub fn begin + ( + mut storage : ::core::option::Option< Struct1FormerStorage >, + context : ::core::option::Option< Context >, + on_end : End, + ) -> Self + { + if storage.is_none() + { + storage = Some( Default::default() ); + } + Self + { + storage : storage.unwrap(), + context, + on_end : ::core::option::Option::Some( on_end ), + } + } + + #[ inline( always ) ] + pub fn end( mut self ) -> Context + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + let formed = self.form(); + on_end.call( formed, context ) + } + + #[ inline( always ) ] + pub fn __vec_1< Former2 >( self ) -> + Former2 + where + Former2 : former::FormerBegin + < + Vec< String >, + Vec< String >, + Self, End = former::FormingEndClosure< Vec< String >, Self >, + >, + { + let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.vec_1 + { + former::ContainerAssign::assign( field, formed ); + } + else + { + super_former.storage.vec_1 = Some( formed ); + } + super_former + }; + Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + } + + // xxx2 : continue + pub fn vec_1( self ) -> the_module::VectorSubformer + < + String, + Vec< String >, + Self, + impl the_module::FormingEnd< Vec< String >, Self >, + > + { + self.__vec_1::< the_module::VectorSubformer::< _, _, _, _ > >() + } + + // pub fn vec_1( mut self ) -> the_module::VectorSubformer + // < + // String, + // Vec< String >, + // Self, + // impl the_module::FormingEnd< Vec< String >, Self >, + // > + // { + // let formed = self.storage.vec_1.take(); + // let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self + // { + // let mut super_former = super_former.unwrap(); + // super_former.storage.vec_1 = Some( formed ); + // super_former + // }; + // the_module::VectorSubformer::< String, Vec< String >, Self, _ >::begin( Some( self ), formed, on_end ) + // } + + pub fn hashmap_strings_1( mut self ) -> the_module::HashMapSubformer + < + String, + String, + std::collections::HashMap< String, String >, + Self, + impl the_module::FormingEnd< std::collections::HashMap< String, String >, Self >, + > + { + let formed = self.storage.hashmap_strings_1.take(); + let on_end = | formed : std::collections::HashMap< String, String >, super_former : ::core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + super_former.storage.hashmap_strings_1 = Some( formed ); + super_former + }; + the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) + } + + pub fn hashset_strings_1( mut self ) -> the_module::HashSetSubformer + < + String, + std::collections::HashSet< String >, + Self, + impl the_module::FormingEnd< std::collections::HashSet< String >, Self >, + > + { + let formed = self.storage.hashset_strings_1.take(); + let on_end = | formed : std::collections::HashSet< String >, super_former : ::core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + super_former.storage.hashset_strings_1 = Some( formed ); + super_former + }; + the_module::HashSetSubformer::begin( formed, Some( self ), on_end ) + } + +} + +// impl< Context, End > Struct1Former< Context, End > +// where +// End: the_module::FormingEnd, + +impl Struct1Former< Struct1, the_module::ReturnPreformed > +{ + + #[ inline( always ) ] + pub fn new() -> Self + { + Self::begin( None, None, the_module::ReturnPreformed ) + } + +} + +// + +// impl< Context, End > Struct1Former< Context, End > +// where +// End : the_module::FormingEnd< Struct1, Context >, + +impl< Context, End > former::FormerBegin< Struct1FormerStorage, Struct1, Context > +for Struct1Former< Context, End > +where + End : the_module::FormingEnd< Struct1, Context >, +{ + type End = End; + + #[ inline( always ) ] + fn _begin + ( + storage : core::option::Option< Struct1FormerStorage >, /* xxx2 : that should be storage */ + context : core::option::Option< Context >, + on_end : End, + ) -> Self + { + debug_assert!( storage.is_none() ); + Self::begin( None, context, on_end ) + } + +} + +// + +include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 56309292bf..bb6cb149c3 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -9,289 +9,382 @@ pub struct Struct1 hashset_strings_1 : std::collections::HashSet< String >, } -// = formed +// = generated +#[ automatically_derived ] impl Struct1 { - pub fn former() -> Struct1Former< Struct1, the_module::ReturnPreformed > + #[ doc = r"" ] + #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn former() -> Struct1Former< > { - Struct1Former::< Struct1, the_module::ReturnPreformed >::new() + Struct1Former::<>::new( the_module::ReturnPreformed ) } } -// = storage +#[ derive( Debug ) ] +pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > +{ + _phantom : core::marker::PhantomData< ( Context, Formed ) >, +} -// generated by former -pub struct Struct1FormerStorage +impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > { - pub vec_1 : ::core::option::Option< Vec< String > >, - pub hashmap_strings_1 : ::core::option::Option< std::collections::HashMap< String, String > >, - pub hashset_strings_1 : ::core::option::Option< std::collections::HashSet< String > >, + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } } -impl Default for Struct1FormerStorage +#[ derive( Debug ) ] +pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > { + _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, +} - #[ inline( always ) ] +impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > +{ fn default() -> Self { Self { - vec_1 : None, - hashmap_strings_1 : None, - hashset_strings_1 : None, + _phantom : core::marker::PhantomData, } } - } -// = former +impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > +{ + type Storage = Struct1FormerStorage; + type Formed = Formed; + type Context = Context; +} -pub struct Struct1Former -< - Context = Struct1, - End = the_module::ReturnPreformed, -> +impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > where - End : the_module::FormingEnd< Struct1, Context >, + End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, { - storage : Struct1FormerStorage, - context : ::core::option::Option< Context >, - on_end : ::core::option::Option< End >, + type Types = Struct1FormerDefinitionTypes< Context, Formed >; + type End = End; } -impl< Context, End > Struct1Former< Context, End > -where - End : the_module::FormingEnd< Struct1, Context >, +pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; + +#[ doc = "Container of a corresponding former." ] +pub struct Struct1FormerStorage { + #[ doc = r" A field" ] + pub vec_1 : ::core::option::Option< Vec< String > >, + #[ doc = r" A field" ] + pub hashmap_strings_1 : ::core::option::Option< std::collections::HashMap< String, String > >, + + #[ doc = r" A field" ] + pub hashset_strings_1 : ::core::option::Option< std::collections::HashSet< String > >, +} + +impl ::core::default::Default for Struct1FormerStorage +{ #[ inline( always ) ] - fn form( mut self ) -> Struct1 + fn default() -> Self { + Self + { + vec_1 : ::core::option::Option::None, + hashmap_strings_1 : ::core::option::Option::None, + hashset_strings_1 : ::core::option::Option::None, + } + } +} + +impl former::Storage for Struct1FormerStorage +{ + type Formed = Struct1; +} - let vec_1 = if self.storage.vec_1.is_some() +impl former::StoragePreform for Struct1FormerStorage +{ + fn preform( mut self ) -> < Self as former::Storage >::Formed + { + let vec_1 = if self.vec_1.is_some() { - self.storage.vec_1.take().unwrap() + self.vec_1.take().unwrap() } else { - let val : Vec< String > = Default::default(); - val + { + trait MaybeDefault< T > + { + fn maybe_default( self : &Self ) -> T + { + panic!( "Field 'vec_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< Vec< String > > ).maybe_default() + } }; - - let hashmap_strings_1 = if self.storage.hashmap_strings_1.is_some() + let hashmap_strings_1 = if self.hashmap_strings_1.is_some() { - self.storage.hashmap_strings_1.take().unwrap() + self.hashmap_strings_1.take().unwrap() } else { - let val : std::collections::HashMap< String, String > = Default::default(); - val + { + trait MaybeDefault< T > + { + fn maybe_default( self : &Self ) -> T + { + panic!( "Field 'hashmap_strings_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< std::collections::HashMap< String, String > > ).maybe_default() + } }; - - let hashset_strings_1 = if self.storage.hashset_strings_1.is_some() + let hashset_strings_1 = if self.hashset_strings_1.is_some() { - self.storage.hashset_strings_1.take().unwrap() + self.hashset_strings_1.take().unwrap() } else { - let val : std::collections::HashSet< String > = Default::default(); - val + { + trait MaybeDefault< T > + { + fn maybe_default( self : &Self ) -> T + { + panic!( "Field 'hashset_strings_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< std::collections::HashSet< String > > ).maybe_default() + } }; - - Struct1 + let result = Struct1 { vec_1, hashmap_strings_1, hashset_strings_1, - } - + }; + return result; } +} +#[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[ default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] +pub struct Struct1Former< Definition = Struct1FormerDefinition > +where + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +{ + storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : core::option::Option< Definition::End >, +} + +#[ automatically_derived ] +impl< Definition > Struct1Former< Definition > +where + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +{ + #[ doc = r"" ] + #[ doc = r" Finish setting options and call perform on formed entity." ] + #[ doc = r"" ] + #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] + #[ doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str ) ]` returns `&str`." ] + #[ doc = r"" ] #[ inline( always ) ] - pub fn perform(self) -> Struct1 + pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { let result = self.form(); return result; } - // #[ inline( always ) ] - // pub fn new() -> Struct1Former - // { - // Struct1Former:: - // < - // Struct1, - // the_module::ReturnPreformed, - // >::begin(None, the_module::ReturnPreformed) - // } + #[ doc = r"" ] + #[ doc = r" Construct new instance of former with default parameters." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn _new_precise( on_end : Definition::End ) -> Self + { + Self::begin( None, None, on_end ) + } + + #[ doc = r"" ] + #[ doc = r" Construct new instance of former with default parameters." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn new< IntoEnd >( end : IntoEnd ) -> Self + where + IntoEnd : Into< Definition::End >, + { + Self::begin( None, None, end, ) + } + #[ doc = r"" ] + #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] + #[ doc = r"" ] #[ inline( always ) ] - pub fn begin - ( - mut storage : ::core::option::Option< Struct1FormerStorage >, - context : ::core::option::Option< Context >, - on_end : End, + 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 : < Definition as former::FormerDefinition >::End, ) -> Self { if storage.is_none() { - storage = Some( Default::default() ); + storage = Some( ::core::default::Default::default() ); } Self { storage : storage.unwrap(), - context, + context : context, on_end : ::core::option::Option::Some( on_end ), } } + #[ doc = r"" ] + #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] + #[ doc = r"" ] #[ inline( always ) ] - pub fn end( mut self ) -> Context + 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 >, { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), + } } + #[ doc = r"" ] + #[ doc = r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] #[ inline( always ) ] - pub fn __vec_1< Former2 >( self ) -> - Former2 - where - Former2 : former::FormerBegin - < - Vec< String >, - Vec< String >, - Self, End = former::FormingEndClosure< Vec< String >, Self >, - >, + pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { - let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.vec_1 - { - former::ContainerAssign::assign( field, formed ); - } - else - { - super_former.storage.vec_1 = Some( formed ); - } - super_former - }; - Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + self.end() } - // xxx2 : continue - pub fn vec_1( self ) -> the_module::VectorSubformer - < - String, - Vec< String >, - Self, - impl the_module::FormingEnd< Vec< String >, Self >, - > + #[ doc = r"" ] + #[ doc = r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { - self.__vec_1::< the_module::VectorSubformer::< _, _, _, _ > >() + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) } - // pub fn vec_1( mut self ) -> the_module::VectorSubformer - // < - // String, - // Vec< String >, - // Self, - // impl the_module::FormingEnd< Vec< String >, Self >, - // > + // #[ doc = "Subformer setter for the 'vec_1' field." ] + // #[ inline ] + // pub fn vec_1( mut self ) -> the_module::VectorSubformer< String, Vec< String >, Self, impl Fn( Vec< String >, core::option::Option< Self > ) -> Self, > // { // let formed = self.storage.vec_1.take(); - // let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self + // let on_end = | formed : Vec< String >, former : core::option::Option< Self > | -> Self // { - // let mut super_former = super_former.unwrap(); - // super_former.storage.vec_1 = Some( formed ); - // super_former + // let mut former = former.unwrap(); + // former.storage.vec_1 = Some( formed ); + // former // }; - // the_module::VectorSubformer::< String, Vec< String >, Self, _ >::begin( Some( self ), formed, on_end ) + // the_module::VectorSubformer::begin( formed, Some( self ), on_end ) // } - pub fn hashmap_strings_1( mut self ) -> the_module::HashMapSubformer - < - String, - String, - std::collections::HashMap< String, String >, - Self, - impl the_module::FormingEnd< std::collections::HashMap< String, String >, Self >, - > + pub fn vec_1( self ) -> + former::VectorSubformer::< String, (), Vec< String >, former::ReturnStorage > + // former::VectorSubformer + // < + // String, + // Vec< String >, + // Self, + // impl former::FormingEnd< Struct1FormerDefinitionTypes >, + // > + { + self.__vec_1::< former::VectorSubformer::< _, _, _, _ > >() + } + + #[ doc = "Subformer setter for the 'hashmap_strings_1' field." ] + #[ inline ] + pub fn hashmap_strings_1( mut self ) -> the_module::HashMapSubformer< String, String, std::collections::HashMap< String, String >, Self, impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self, > { let formed = self.storage.hashmap_strings_1.take(); - let on_end = | formed : std::collections::HashMap< String, String >, super_former : ::core::option::Option< Self > | -> Self + let on_end = | formed : std::collections::HashMap< String, String >, former : core::option::Option< Self > | -> Self { - let mut super_former = super_former.unwrap(); - super_former.storage.hashmap_strings_1 = Some( formed ); - super_former + let mut former = former.unwrap(); + former.storage.hashmap_strings_1 = Some( formed ); + former }; the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) } - pub fn hashset_strings_1( mut self ) -> the_module::HashSetSubformer - < - String, - std::collections::HashSet< String >, - Self, - impl the_module::FormingEnd< std::collections::HashSet< String >, Self >, - > + #[ doc = "Subformer setter for the 'hashset_strings_1' field." ] + #[ inline ] + pub fn hashset_strings_1( mut self ) -> the_module::HashSetSubformer< String, std::collections::HashSet< String >, Self, impl Fn( std::collections::HashSet< String >, core::option::Option< Self > ) -> Self, > { let formed = self.storage.hashset_strings_1.take(); - let on_end = | formed : std::collections::HashSet< String >, super_former : ::core::option::Option< Self > | -> Self + let on_end = | formed : std::collections::HashSet< String >, former : core::option::Option< Self > | -> Self { - let mut super_former = super_former.unwrap(); - super_former.storage.hashset_strings_1 = Some( formed ); - super_former + let mut former = former.unwrap(); + former.storage.hashset_strings_1 = Some( formed ); + former }; the_module::HashSetSubformer::begin( formed, Some( self ), on_end ) } - -} - -// impl< Context, End > Struct1Former< Context, End > -// where -// End: the_module::FormingEnd, - -impl Struct1Former< Struct1, the_module::ReturnPreformed > -{ - - #[ inline( always ) ] - pub fn new() -> Self - { - Self::begin( None, None, the_module::ReturnPreformed ) - } - } -// - -// impl< Context, End > Struct1Former< Context, End > -// where -// End : the_module::FormingEnd< Struct1, Context >, - -impl< Context, End > former::FormerBegin< Struct1FormerStorage, Struct1, Context > -for Struct1Former< Context, End > +impl< Definition > Struct1Former< Definition > where - End : the_module::FormingEnd< Struct1, Context >, + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, { - type End = End; - - #[ inline( always ) ] - fn _begin - ( - storage : core::option::Option< Struct1FormerStorage >, /* xxx2 : that should be storage */ - context : core::option::Option< Context >, - on_end : End, - ) -> Self + pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { - debug_assert!( storage.is_none() ); - Self::begin( None, context, on_end ) + former::StoragePreform::preform( self.storage ) } - } -// +// = end of generated -include!( "./only_test/containers_with_subformer.rs" ); +// include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs deleted file mode 100644 index c419520a98..0000000000 --- a/module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs +++ /dev/null @@ -1,178 +0,0 @@ -#[ allow( unused_imports ) ] -use super::*; - -#[ derive( Debug, PartialEq ) ] -pub struct Struct1 -{ - vec_1 : Vec< String >, - hashmap_strings_1 : std::collections::HashMap< String, String >, - hashset_strings_1 : std::collections::HashSet< String >, -} - -// - -impl Struct1 -{ - pub fn former() -> Struct1Former< Struct1, the_module::ReturnPreformed > - { - Struct1Former::< Struct1, the_module::ReturnPreformed >::new() - } -} - -// generated by former -pub struct Struct1FormerStorage -{ - pub vec_1 : core::option::Option< Vec< String > >, - pub hashmap_strings_1 : core::option::Option< std::collections::HashMap< String, String > >, - pub hashset_strings_1 : core::option::Option< std::collections::HashSet< String > >, -} - -impl Default for Struct1FormerStorage -{ - - #[ inline( always ) ] - fn default() -> Self - { - Self - { - vec_1 : None, - hashmap_strings_1 : None, - hashset_strings_1 : None, - } - } - -} - -// - -pub struct Struct1Former -< - __FormerContext = Struct1, - __FormerEnd = the_module::ReturnPreformed, -> -where - __FormerEnd : the_module::FormingEnd< Struct1, __FormerContext >, -{ - storage : Struct1FormerStorage, - context : core::option::Option< __FormerContext >, - on_end : core::option::Option< __FormerEnd >, -} - -impl< __FormerContext, __FormerEnd > Struct1Former< __FormerContext, __FormerEnd > -where - __FormerEnd: the_module::FormingEnd, -{ - - #[ inline( always ) ] - fn form( mut self ) -> Struct1 - { - - let vec_1 = if self.storage.vec_1.is_some() - { - self.storage.vec_1.take().unwrap() - } - else - { - let val : Vec< String > = Default::default(); - val - }; - - let hashmap_strings_1 = if self.storage.hashmap_strings_1.is_some() - { - self.storage.hashmap_strings_1.take().unwrap() - } - else - { - let val : std::collections::HashMap< String, String > = Default::default(); - val - }; - - let hashset_strings_1 = if self.storage.hashset_strings_1.is_some() - { - self.storage.hashset_strings_1.take().unwrap() - } - else - { - let val : std::collections::HashSet< String > = Default::default(); - val - }; - - Struct1 - { - vec_1, - hashmap_strings_1, - hashset_strings_1, - } - - } - - #[ inline( always ) ] - pub fn perform(self) -> Struct1 - { - let result = self.form(); - return result; - } - - #[ inline( always ) ] - pub fn new() -> Struct1Former - { - Struct1Former:: - < - Struct1, - the_module::ReturnPreformed, - >::begin(None, the_module::ReturnPreformed) - } - - #[ inline( always ) ] - pub fn begin - ( - context : core::option::Option< __FormerContext >, - on_end : __FormerEnd, - ) -> Self - { - Self - { - storage : core::default::Default::default(), - context : context, - on_end : ::core::option::Option::Some( on_end ), - } - } - - #[ inline( always ) ] - pub fn end( mut self ) -> __FormerContext - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) - } - - pub fn vec_1< Src >( mut self, src : Src ) -> Self - where Src : core::convert::Into< Vec< String > > - { - debug_assert!( self.storage.vec_1.is_none() ); - self.storage.vec_1 = Some( src.into() ); - self - } - - pub fn hashmap_strings_1< Src >( mut self, src : Src ) -> Self - where Src : core::convert::Into< std::collections::HashMap< String, String > > - { - debug_assert!( self.storage.hashmap_strings_1.is_none() ); - self.storage.hashmap_strings_1 = Some( src.into() ); - self - } - - pub fn hashset_strings_1< Src >( mut self, src : Src ) -> Self - where Src : core::convert::Into< std::collections::HashSet< String > > - { - debug_assert!( self.storage.hashset_strings_1.is_none() ); - self.storage.hashset_strings_1 = Some( src.into() ); - self - } - -} - -// - -include!( "./only_test/containers_without_subformer.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 49fe32b4c7..d9541ddf2c 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -19,13 +19,12 @@ mod former_tests mod a_primitives_manual; // mod a_primitives_expanded; mod a_primitives; - // mod a_containers_without_subformer_manual; mod a_containers_without_subformer; -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer_manual; -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer ; -// + // #[ cfg( not( feature = "no_std" ) ) ] + // mod a_containers_with_subformer_manual; + // #[ cfg( not( feature = "no_std" ) ) ] + // mod a_containers_with_subformer ; + // mod attribute_default_container; // mod attribute_default_primitive; // mod attribute_perform;