From d83a1db64bc36029d6581bdc0f2c83589576cae1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 11:44:04 +0300 Subject: [PATCH] former : experimenting --- .../a_containers_with_subformer_implicit.rs | 394 -------------- .../a_containers_with_subformer_manual.rs | 512 ++++++++++-------- .../only_test/containers_with_subformer.rs | 12 +- .../only_test/subformer_subform.rs | 3 - .../inc/former_tests/subformer_custom.rs | 10 +- .../subformer_custom_experimental.rs | 4 +- .../subformer_implicit_container.rs | 29 + ...=> subformer_implicit_container_manual.rs} | 3 +- .../inc/former_tests/subformer_subform.rs | 2 +- .../former_tests/subformer_subform_manual.rs | 2 +- module/core/former/tests/inc/mod.rs | 9 +- module/core/former_meta/src/derive/former.rs | 129 ++++- 12 files changed, 446 insertions(+), 663 deletions(-) delete mode 100644 module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs create mode 100644 module/core/former/tests/inc/former_tests/subformer_implicit_container.rs rename module/core/former/tests/inc/former_tests/{subformer_subform_implicit_container.rs => subformer_implicit_container_manual.rs} (98%) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs deleted file mode 100644 index 71e71d6bc6..0000000000 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs +++ /dev/null @@ -1,394 +0,0 @@ -#[ allow( unused_imports ) ] -use super::*; - -#[ derive( Default, Debug, PartialEq, former::Former ) ] -// #[ derive( Default, Debug, PartialEq, former::Former ) ] #[ debug ] -// #[ derive( Default, Debug, PartialEq ) ] -pub struct Struct1 -{ - #[ container( former::VectorDefinition ) ] - // #[ container ] - vec_1 : Vec< String >, - #[ container( former::HashMapDefinition ) ] - hashmap_1 : std::collections::HashMap< String, String >, - #[ container( former::HashSetDefinition ) ] - hashset_1 : std::collections::HashSet< String >, -} - -// == generated begin - -// #[automatically_derived] -// impl < > Struct1 < > where -// { -// #[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 < -// Struct1FormerDefinition < (), Struct1 < > , former :: ReturnPreformed > > -// { -// Struct1Former :: < Struct1FormerDefinition < (), Struct1 < > , former -// :: ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) -// } -// } impl < Definition > former :: EntityToFormer < Definition > for Struct1 < > -// where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage -// < > > , { type Former = Struct1Former < Definition > ; } impl < > former :: -// EntityToStorage for Struct1 < > where -// { type Storage = Struct1FormerStorage < > ; } #[derive(Debug)] pub struct -// Struct1FormerDefinitionTypes < __Context = (), __Formed = Struct1 < > , > -// where { _phantom : core :: marker :: PhantomData < (__Context, __Formed) > , } -// impl < __Context, __Formed, > :: core :: default :: Default for -// Struct1FormerDefinitionTypes < __Context, __Formed, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, > former :: FormerDefinitionTypes for -// Struct1FormerDefinitionTypes < __Context, __Formed, > where -// { -// type Storage = Struct1FormerStorage < > ; type Formed = __Formed; type -// Context = __Context; -// } #[derive(Debug)] pub struct Struct1FormerDefinition < __Context = (), -// __Formed = Struct1 < > , __End = former :: ReturnPreformed, > where -// { -// _phantom : core :: marker :: PhantomData < (__Context, __Formed, __End) > -// , -// } impl < __Context, __Formed, __End, > :: core :: default :: Default for -// Struct1FormerDefinition < __Context, __Formed, __End, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, __End, > former :: FormerDefinition for -// Struct1FormerDefinition < __Context, __Formed, __End, > where __End : former -// :: FormingEnd < Struct1FormerDefinitionTypes < __Context, __Formed, > > , -// { -// type Types = Struct1FormerDefinitionTypes < __Context, __Formed, > ; type -// End = __End; type Storage = Struct1FormerStorage < > ; type Formed = -// __Formed; type Context = __Context; -// } #[doc = "Container of a corresponding former."] pub struct -// Struct1FormerStorage < > where -// { -// #[doc = r" A field"] pub vec_1 : :: core :: option :: Option < Vec < -// String > > , #[doc = r" A field"] pub hashmap_1 : :: core :: option :: -// Option < std :: collections :: HashMap < String, String > > , -// #[doc = r" A field"] pub hashset_1 : :: core :: option :: Option < std :: -// collections :: HashSet < String > > , -// } impl < > :: core :: default :: Default for Struct1FormerStorage < > where -// { -// #[inline(always)] fn default() -> Self -// { -// Self -// { -// vec_1 : :: core :: option :: Option :: None, hashmap_1 : :: core -// :: option :: Option :: None, hashset_1 : :: core :: option :: -// Option :: None, -// } -// } -// } impl < > former :: Storage for Struct1FormerStorage < > where -// { type Formed = Struct1 < > ; } impl < > former :: StoragePreform for -// Struct1FormerStorage < > where -// { -// type Preformed = Struct1 < > ; fn preform(mut self) -> Self :: Preformed -// { -// let vec_1 = if self.vec_1.is_some() { self.vec_1.take().unwrap() } -// else -// { -// { -// 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_1 = if self.hashmap_1.is_some() -// { self.hashmap_1.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'hashmap_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_1 = if self.hashset_1.is_some() -// { self.hashset_1.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'hashset_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() -// } -// }; let result = Struct1 :: < > { vec_1, hashmap_1, hashset_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 < (), Struct1 -// < > , former :: ReturnPreformed > , > where Definition : former :: -// FormerDefinition, 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 : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// #[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_coercing(None, None, on_end) } #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > -// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , -// { Self :: begin_coercing(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_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(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), 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 begin_coercing < 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 : 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 form(self) -> < Definition :: Types -// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[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 -// { -// let on_end = self.on_end.take().unwrap(); let context = -// self.context.take(); former :: FormingEnd :: < Definition :: Types > -// :: call(& on_end, self.storage, context) -// } -// #[doc = -// "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] -// #[inline(always)] pub fn _vec_1_assign < Former2 > (self) -> Former2 where -// Former2 : former :: FormerBegin < < Vec < String > as former :: -// EntityToDefinition < Self, Self, Struct1FormerAssignVec1End > > :: -// Definition > , -// { Former2 :: former_begin(None, Some(self), Struct1FormerAssignVec1End) } -// #[doc = -// "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] -// #[inline(always)] pub fn vec_1(self) -> former :: ContainerSubformer :: < -// String, < Vec < String > as former :: EntityToDefinition < Self, Self, -// Struct1FormerAssignVec1End > > :: Definition > -// { -// self._vec_1_assign :: < former :: ContainerSubformer :: < String, < -// Vec < String > as former :: EntityToDefinition < Self, Self, -// Struct1FormerAssignVec1End > > :: Definition >> () -// } -// #[doc = -// "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] -// #[inline(always)] pub fn _hashmap_1_assign < Former2 > (self) -> Former2 -// where Former2 : former :: FormerBegin < former :: HashMapDefinition < -// String, String, Self, Self, Struct1FormerAssignHashmap1End, > > , -// { -// Former2 :: -// former_begin(None, Some(self), Struct1FormerAssignHashmap1End) -// } -// #[doc = -// "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] -// #[inline(always)] pub fn hashmap_1(self) -> former :: ContainerSubformer -// :: < (String, String,), former :: HashMapDefinition < String, String, -// Self, Self, Struct1FormerAssignHashmap1End, > > -// { -// self._hashmap_1_assign :: < former :: ContainerSubformer :: < -// (String, String,), former :: HashMapDefinition < String, String, Self, -// Self, Struct1FormerAssignHashmap1End, > >> () -// } -// #[doc = -// "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] -// #[inline(always)] pub fn _hashset_1_assign < Former2 > (self) -> Former2 -// where Former2 : former :: FormerBegin < former :: HashSetDefinition < -// String, Self, Self, Struct1FormerAssignHashset1End, > > , -// { -// Former2 :: -// former_begin(None, Some(self), Struct1FormerAssignHashset1End) -// } -// #[doc = -// "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] -// #[inline(always)] pub fn hashset_1(self) -> former :: ContainerSubformer -// :: < String, former :: HashSetDefinition < String, Self, Self, -// Struct1FormerAssignHashset1End, > > -// { -// self._hashset_1_assign :: < former :: ContainerSubformer :: < String, -// former :: HashSetDefinition < String, Self, Self, -// Struct1FormerAssignHashset1End, > >> () -// } -// } impl < Definition, > Struct1Former < Definition, > where Definition : former -// :: FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = Struct1FormerStorage < > , Formed = Struct1 < > > , < Definition :: -// Types as former :: FormerDefinitionTypes > :: Storage : former :: -// StoragePreform, < Definition :: Types as former :: FormerDefinitionTypes > :: -// Storage : former :: StoragePreform < Preformed = Struct1 < > > , Definition : -// former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// pub fn preform(self) -> < Definition :: Types as former :: -// FormerDefinitionTypes > :: Formed -// { former :: StoragePreform :: preform(self.storage) } -// } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > -// where Definition : former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > , Formed = Struct1 -// < > > , -// { -// #[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) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { let result = self.form(); return result; } -// } impl < Definition > former :: FormerBegin < Definition > for Struct1Former < -// Definition, > where Definition : former :: FormerDefinition < Storage = -// Struct1FormerStorage < > > , -// { -// #[inline(always)] fn -// former_begin(storage : core :: option :: Option < Definition :: Storage > -// , context : core :: option :: Option < Definition :: Context > , on_end : -// Definition :: End,) -> Self -// { -// debug_assert! (storage.is_none()); Self :: -// begin_precise(None, context, on_end) -// } -// } -// #[doc = -// r" Use as subformer of a field during process of forming of super structure."] -// pub type Struct1Subformer < __Superformer, __End > = Struct1Former < -// Struct1FormerDefinition < __Superformer, __Superformer, __End, > , > ; -// #[doc = -// r" Use as subformer end of a field during process of forming of super structure."] -// pub trait Struct1SubformerEnd < SuperFormer > where Self : former :: -// FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, SuperFormer > , > , -// {} impl < SuperFormer, T > Struct1SubformerEnd < SuperFormer > for T where -// Self : former :: FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, -// SuperFormer > , > , {} -// #[doc = r" Return original former after container for `vec_1` is done."] -// #[allow(non_camel_case_types)] -// -// pub struct Struct1FormerAssignVec1End; -// #[automatically_derived] -// impl < Definition, > former :: FormingEnd -// < -// < Vec < String > as former :: EntityToDefinition -// < -// Struct1Former < Definition, > , Struct1Former < Definition, > , former :: NoEnd > -// > :: Definition, -// > -// for Struct1FormerAssignVec1End -// where -// Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// #[inline(always)] fn -// call(& self, storage : Vec < String > , super_former : Option < -// Struct1Former < Definition, > > ,) -> Struct1Former < Definition, > -// { -// let mut super_former = super_former.unwrap(); if let -// Some(ref mut field) = super_former.storage.vec_1 -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.vec_1 = Some(storage); } super_former -// } -// } -// -// #[doc = r" Return original former after container for `vec_1` is done."] -// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashmap1End; -// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: -// HashMapDefinition < String, String, Struct1Former < Definition, > , -// Struct1Former < Definition, > , former :: NoEnd > , > for -// Struct1FormerAssignHashmap1End where Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = -// Struct1FormerStorage < > > , Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = -// Struct1FormerStorage < > > , -// { -// #[inline(always)] fn -// call(& self, storage : std :: collections :: HashMap < String, String > , -// super_former : Option < Struct1Former < Definition, > > ,) -> -// Struct1Former < Definition, > -// { -// let mut super_former = super_former.unwrap(); if let -// Some(ref mut field) = super_former.storage.hashmap_1 -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.hashmap_1 = Some(storage); } super_former -// } -// } #[doc = r" Return original former after container for `vec_1` is done."] -// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashset1End; -// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: -// HashSetDefinition < String, Struct1Former < Definition, > , Struct1Former < -// Definition, > , former :: NoEnd > , > for Struct1FormerAssignHashset1End where -// Definition : former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , Definition : -// former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// #[inline(always)] fn -// call(& self, storage : std :: collections :: HashSet < String > , -// super_former : Option < Struct1Former < Definition, > > ,) -> -// Struct1Former < Definition, > -// { -// let mut super_former = super_former.unwrap(); if let -// Some(ref mut field) = super_former.storage.hashset_1 -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.hashset_1 = Some(storage); } super_former -// } -// } - -// == generated 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 6966aa8d71..2a4e07e94a 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 @@ -11,27 +11,43 @@ pub struct Struct1 // == begin of generated -#[ automatically_derived ] +#[automatically_derived] impl< > Struct1< > where { - #[ inline( always ) ] - pub fn former() -> Struct1Former< Struct1FormerDefinition< (), Struct1< >, former::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< + Struct1FormerDefinition<(), Struct1<>, former::ReturnPreformed> + > { - Struct1Former::< Struct1FormerDefinition< (), Struct1< >, former::ReturnPreformed > >::new_coercing( former::ReturnPreformed ) + Struct1Former::, former::ReturnPreformed>>::new_coercing(former::ReturnPreformed) } } -// = types +impl< Definition > former::EntityToFormer< Definition > for Struct1< > +where + Definition : former::FormerDefinition< Storage = Struct1FormerStorage<> >, +{ + type Former = Struct1Former< Definition >; +} -#[ derive( Debug ) ] -pub struct Struct1FormerDefinitionTypes< __Context = (), __Formed = Struct1< >, > +impl< > former::EntityToStorage for Struct1< > where { - _phantom : core::marker::PhantomData< ( __Context, __Formed ) >, + type Storage = Struct1FormerStorage<>; } -impl< __Context, __Formed, > ::core::default::Default for Struct1FormerDefinitionTypes< __Context, __Formed, > +#[derive(Debug)] +pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1<>, > +where +{ + _phantom : core::marker::PhantomData<(Context, Formed)>, +} + +impl< Context, Formed, > core::default::Default for Struct1FormerDefinitionTypes< Context, Formed, > where { fn default() -> Self @@ -43,25 +59,22 @@ where } } -impl< __Context, __Formed, > former::FormerDefinitionTypes -for Struct1FormerDefinitionTypes< __Context, __Formed, > +impl< Context, Formed, > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed, > where { - type Storage = Struct1FormerStorage< >; - type Formed = __Formed; - type Context = __Context; + type Storage = Struct1FormerStorage<>; + type Formed = Formed; + type Context = Context; } -// = definition - -#[ derive( Debug ) ] -pub struct Struct1FormerDefinition< __Context = (), __Formed = Struct1< >, __End = former::ReturnPreformed, > +#[derive(Debug)] +pub struct Struct1FormerDefinition< Context = (), Formed = Struct1<>, End = former::ReturnPreformed, > where { - _phantom : core::marker::PhantomData< ( __Context, __Formed, __End ) >, + _phantom : core::marker::PhantomData<(Context, Formed, End)>, } -impl< __Context, __Formed, __End, > ::core::default::Default for Struct1FormerDefinition< __Context, __Formed, __End, > +impl< Context, Formed, End, > core::default::Default for Struct1FormerDefinition< Context, Formed, End, > where { fn default() -> Self @@ -73,55 +86,56 @@ where } } -impl< __Context, __Formed, __End, > former::FormerDefinition -for Struct1FormerDefinition< __Context, __Formed, __End, > +impl< Context, Formed, End, > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End, > where - __End : former::FormingEnd< Struct1FormerDefinitionTypes< __Context, __Formed, > >, + End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed, > >, { - type Types = Struct1FormerDefinitionTypes< __Context, __Formed, >; - type End = __End; - type Storage = Struct1FormerStorage< >; - type Formed = __Formed; - type Context = __Context; + type Types = Struct1FormerDefinitionTypes< Context, Formed, >; + type End = End; + type Storage = Struct1FormerStorage<>; + type Formed = Formed; + type Context = Context; } -// = storage - -pub struct Struct1FormerStorage< > +#[doc = "Container of a corresponding former."] +pub struct Struct1FormerStorage<> where { - pub vec_1 : ::core::option::Option< Vec< String > >, - pub hashmap_1 : ::core::option::Option< std::collections::HashMap< String, String > >, - pub hashset_1 : ::core::option::Option< std::collections::HashSet< String > >, + #[doc = r" A field"] + pub vec_1 : core::option::Option>, + #[doc = r" A field"] + pub hashmap_1 : core::option::Option>, + #[doc = r" A field"] + pub hashset_1 : core::option::Option>, } -impl< > ::core::default::Default for Struct1FormerStorage< > +impl< > core::default::Default for Struct1FormerStorage<> where { - #[ inline( always ) ] + #[inline(always)] fn default() -> Self { Self { - vec_1 : ::core::option::Option::None, - hashmap_1 : ::core::option::Option::None, - hashset_1 : ::core::option::Option::None, + vec_1 : core::option::Option::None, + hashmap_1 : core::option::Option::None, + hashset_1 : core::option::Option::None, } } } -impl< > former::Storage for Struct1FormerStorage< > +impl< > former::Storage for Struct1FormerStorage<> where { - type Formed = Struct1< >; + type Formed = Struct1<>; } -impl< > former::StoragePreform for Struct1FormerStorage< > +impl< > former::StoragePreform for Struct1FormerStorage<> where { - type Preformed = Struct1< >; + type Preformed = Struct1<>; - fn preform( mut self ) -> Self::Preformed + fn preform(mut self) -> Self::Preformed { let vec_1 = if self.vec_1.is_some() { @@ -130,28 +144,27 @@ where else { { - trait MaybeDefault< T > + trait MaybeDefault { - fn maybe_default( self : & Self ) -> T + fn maybe_default(self: &Self) -> T { - panic!( "Field 'vec_1' isn't initialized" ) + panic!("Field 'vec_1' isn't initialized") } } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > - { - } + impl MaybeDefault for &core::marker::PhantomData {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where T : ::core::default::Default, + impl MaybeDefault for core::marker::PhantomData + where + T : core::default::Default, { - fn maybe_default( self : & Self ) -> T + fn maybe_default(self: &Self) -> T { T::default() } } - (&::core::marker::PhantomData::< Vec< String > >).maybe_default() + (&core::marker::PhantomData::>).maybe_default() } }; @@ -162,28 +175,27 @@ where else { { - trait MaybeDefault< T > + trait MaybeDefault { - fn maybe_default( self : & Self ) -> T + fn maybe_default(self: &Self) -> T { - panic!( "Field 'hashmap_1' isn't initialized" ) + panic!("Field 'hashmap_1' isn't initialized") } } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > - { - } + impl MaybeDefault for &core::marker::PhantomData {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where T : ::core::default::Default, + impl MaybeDefault for core::marker::PhantomData + where + T : core::default::Default, { - fn maybe_default( self : & Self ) -> T + fn maybe_default(self: &Self) -> T { T::default() } } - (&::core::marker::PhantomData::< std::collections::HashMap< String, String > >).maybe_default() + (&core::marker::PhantomData::>).maybe_default() } }; @@ -194,314 +206,378 @@ where else { { - trait MaybeDefault< T > + trait MaybeDefault { - fn maybe_default( self : &Self ) -> T + fn maybe_default(self: &Self) -> T { - panic!( "Field 'hashset_1' isn't initialized" ) + panic!("Field 'hashset_1' isn't initialized") } } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > - { - } + impl MaybeDefault for &core::marker::PhantomData {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where T : ::core::default::Default, + impl MaybeDefault for core::marker::PhantomData + where + T : core::default::Default, { - fn maybe_default( self : &Self ) -> T + fn maybe_default(self: &Self) -> T { T::default() } } - (&::core::marker::PhantomData::< std::collections::HashSet< String > >).maybe_default() + (&core::marker::PhantomData::>).maybe_default() } }; - let result = Struct1 + let result = Struct1::<> { - vec_1, - hashmap_1, - hashset_1, + vec_1, hashmap_1, hashset_1, }; return result; } } -// = former - -pub struct Struct1Former< Definition = Struct1FormerDefinition< (), Struct1< >, former::ReturnPreformed >, > +#[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<(), Struct1<>, former::ReturnPreformed>, > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, + 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 >, + storage : ::Storage, + context : core::option::Option<::Context>, + on_end : core::option::Option, } -#[ automatically_derived ] +#[automatically_derived] impl< Definition, > Struct1Former< Definition, > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { - - #[ inline( always ) ] - pub fn new_precise( on_end : Definition::End ) -> Self + #[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_coercing( None, None, on_end ) + Self::begin_coercing(None, None, on_end) } - #[ inline( always ) ] - pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self + #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] + #[inline(always)] + pub fn new_coercing(end: IntoEnd) -> Self where - IntoEnd : Into< Definition::End >, + IntoEnd : Into, { - Self::begin_coercing( None, None, end ) + Self::begin_coercing(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 : < Definition as former::FormerDefinition >::End, - ) -> Self + #[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_precise(mut storage: core::option::Option<::Storage>, context: core::option::Option<::Context>, on_end: ::End,) -> Self { if storage.is_none() { - storage = Some( ::core::default::Default::default() ); + storage = Some(core::default::Default::default()); } Self { - storage : storage.unwrap(), - context : context, - on_end : ::core::option::Option::Some( on_end ), + storage: storage.unwrap(), + context: context, + on_end: core::option::Option::Some(on_end), } } - #[ inline( always ) ] - pub fn begin_coercing< 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 + #[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_coercing(mut storage: core::option::Option<::Storage>, context: core::option::Option<::Context>, on_end: IntoEnd,) -> Self where - IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, + IntoEnd : core::convert::Into<::End>, { if storage.is_none() { - storage = Some( ::core::default::Default::default() ); + storage = Some(core::default::Default::default()); } Self { - storage : storage.unwrap(), - context : context, - on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), + storage: storage.unwrap(), + context: context, + on_end: core::option::Option::Some(core::convert::Into::into(on_end)), } } - #[ inline( always ) ] - pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + #[doc = r""] + #[doc = r" End the process of forming returning original context of forming."] + #[doc = r""] + #[inline(always)] + pub fn form(self) -> ::Formed { self.end() } - #[ inline( always ) ] - pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + #[doc = r""] + #[doc = r" End the process of forming returning original context of forming."] + #[doc = r""] + #[inline(always)] + pub fn end(mut self) -> ::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) + former::FormingEnd::::call(&on_end, self.storage, context) } - #[ inline( always ) ] - pub fn vec_1_set< Former2 >( self ) -> Former2 + #[doc = "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] + #[inline(always)] + pub fn _vec_1_assign(self) -> Former2 where - // Former2 : former::FormerBegin< former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End, > >, - Former2 : former::FormerBegin< < Vec< String > as former::EntityToDefinition< Self, Self, Struct1FormerAssignVec1End > >::Definition >, + Former2 : former::FormerBegin,>>, { - Former2::former_begin( None, Some( self ), Struct1FormerAssignVec1End ) + Former2::former_begin(None, Some(self), Struct1FormerAssignVec1End::::default()) } - #[ inline( always ) ] - pub fn vec_1( self ) -> - former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End > > + #[doc = "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] + #[inline(always)] + pub fn vec_1(self) -> former::ContainerSubformer::< + String, + former::VectorDefinition,> + > { - self.vec_1_set::< former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End > >>() + self._vec_1_assign::,>>> () } - #[ inline( always ) ] - pub fn hashmap_1_set< Former2 >( self ) -> Former2 + #[doc = "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] + #[inline(always)] + pub fn _hashmap_1_assign(self) -> Former2 where - Former2 : former::FormerBegin< former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End, > >, + Former2 : former::FormerBegin,>>, { - Former2::former_begin( None, Some( self ), Struct1FormerAssignHashmap1End ) + Former2::former_begin(None, Some(self), Struct1FormerAssignHashmap1End::::default()) } - - #[ inline( always ) ] - pub fn hashmap_1( self ) -> former::ContainerSubformer::< (String, String), former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End > > + #[doc = "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] + #[inline(always)] + pub fn hashmap_1(self) -> former::ContainerSubformer::< + (String, String,), + former::HashMapDefinition,> + > { - self.hashmap_1_set::< former::ContainerSubformer::< (String, String), former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End > >>() + self._hashmap_1_assign::,> + >> () } - - #[ inline( always ) ] - pub fn hashset_1_set< Former2 >( self ) -> Former2 + #[doc = "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] + #[inline(always)] + pub fn _hashset_1_assign(self) -> Former2 where - Former2 : former::FormerBegin< former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End, > >, + Former2 : former::FormerBegin,>>, { - Former2::former_begin( None, Some( self ), Struct1FormerAssignHashset1End ) + Former2::former_begin(None, Some(self), Struct1FormerAssignHashset1End::::default()) } - - #[ inline( always ) ] - pub fn hashset_1( self ) -> former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End > > + #[doc = "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] + #[inline(always)] + pub fn hashset_1(self) -> former::ContainerSubformer::< + String, + former::HashSetDefinition,> + > { - self.hashset_1_set::< former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End > >>() + self._hashset_1_assign::,> + >> () } } -// = former :: preform - impl< Definition, > Struct1Former< Definition, > where + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<>, Formed = Struct1<> >, Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< >, Formed = Struct1< > >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Struct1< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { - pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + pub fn preform(self) -> ::Formed { - former::StoragePreform::preform( self.storage ) + former::StoragePreform::preform(self.storage) } } -// = former :: perform - -#[ automatically_derived ] +#[automatically_derived] impl< Definition, > Struct1Former< Definition, > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< >, Formed = Struct1< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<>, Formed = Struct1<> >, { - #[ inline( always ) ] - pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + #[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) -> ::Formed { let result = self.form(); return result; } } -// = subformer - -#[ allow( dead_code ) ] -pub type Struct1Subformer< __Superformer, __End > -= Struct1Former< Struct1FormerDefinition< __Superformer, __Superformer, __End, >, >; - -// pub type Struct1FormerWithClosure< __Context, __Formed, > = Struct1FormerDefinition< __Context, __Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< __Context, __Formed, > > >; +impl< Definition > former::FormerBegin< Definition > for Struct1Former< Definition, > +where + Definition : former::FormerDefinition< Storage = Struct1FormerStorage<> >, +{ + #[inline(always)] + fn former_begin(storage: core::option::Option, context: core::option::Option, on_end: Definition::End,) -> Self + { + debug_assert!(storage.is_none()); + Self::begin_precise(None, context, on_end) + } +} -// = subformer end +#[doc = +r" Use as subformer of a field during process of forming of super structure."] +pub type Struct1AsSubformer = Struct1Former< + Struct1FormerDefinition, +>; -#[ allow( dead_code ) ] -pub trait Struct1SubformerEnd< SuperFormer > -where - Self : former::FormingEnd< Struct1FormerDefinitionTypes< SuperFormer, SuperFormer >, >, +#[doc = +"Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] +pub trait Struct1AsSubformerEnd where Self : former::FormingEnd< Struct1FormerDefinitionTypes, > {} -impl< SuperFormer, T > Struct1SubformerEnd< SuperFormer > for T +impl Struct1AsSubformerEnd for T where - Self : former::FormingEnd< Struct1FormerDefinitionTypes< SuperFormer, SuperFormer >, >, + Self : former::FormingEnd< Struct1FormerDefinitionTypes, >, {} -// = end handlers +#[doc = +"Callback to return original former after forming of container for `$Struct1` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] +pub struct Struct1FormerAssignVec1End +{ + _phantom : core::marker::PhantomData<(Definition,)>, +} -#[ allow( non_camel_case_types ) ] -pub struct Struct1FormerAssignVec1End; +impl Default for Struct1FormerAssignVec1End +{ + #[inline(always)] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} -#[ automatically_derived ] -impl< Definition, > former::FormingEnd -< former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, > -for Struct1FormerAssignVec1End +#[automatically_derived] +impl former::FormingEnd< former::VectorDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignVec1End where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { - #[ inline( always ) ] - fn call( &self, storage : Vec< String >, super_former : Option< Struct1Former< Definition, > >, ) -> - Struct1Former< Definition, > + #[inline(always)] + fn call(&self, storage: Vec, super_former: Option>,) -> Struct1Former { let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.vec_1 + if let Some(ref mut field) = super_former.storage.vec_1 { - former::ContainerAssign::assign( field, storage ); + former::ContainerAssign::assign(field, storage); } else { - super_former.storage.vec_1 = Some( storage ); + super_former.storage.vec_1 = Some(storage); } super_former } } -#[ allow( non_camel_case_types ) ] -pub struct Struct1FormerAssignHashmap1End; +#[doc = +"Callback to return original former after forming of container for `$Struct1` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] +pub struct Struct1FormerAssignHashmap1End +{ + _phantom : core::marker::PhantomData<(Definition,)>, +} + +impl Default for Struct1FormerAssignHashmap1End +{ + #[inline(always)] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} -#[ automatically_derived ] -impl< Definition, > -former::FormingEnd -< - former::HashMapDefinition< String, String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, -> -for Struct1FormerAssignHashmap1End +#[automatically_derived] +impl former::FormingEnd< former::HashMapDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignHashmap1End where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { - #[ inline( always ) ] - fn call( &self, storage : std::collections::HashMap< String, String >, super_former : Option< Struct1Former< Definition, > >, ) -> Struct1Former< Definition, > + #[inline(always)] + fn call(&self, storage: std::collections::HashMap, super_former: Option>,) -> Struct1Former { let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.hashmap_1 + if let Some(ref mut field) = super_former.storage.hashmap_1 { - former::ContainerAssign::assign( field, storage ); + former::ContainerAssign::assign(field, storage); } else { - super_former.storage.hashmap_1 = Some( storage ); + super_former.storage.hashmap_1 = Some(storage); } super_former } } -#[ allow( non_camel_case_types ) ] -pub struct Struct1FormerAssignHashset1End; +#[doc = +"Callback to return original former after forming of container for `$Struct1` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] +pub struct Struct1FormerAssignHashset1End +{ + _phantom : core::marker::PhantomData<(Definition,)>, +} + +impl Default for Struct1FormerAssignHashset1End +{ + #[inline(always)] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} -#[ automatically_derived ] -impl< Definition, > former::FormingEnd -< - former::HashSetDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, -> -for Struct1FormerAssignHashset1End +#[automatically_derived] +impl former::FormingEnd< former::HashSetDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignHashset1End where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { - #[ inline( always ) ] - fn call( &self, storage : std::collections::HashSet< String >, super_former : Option< Struct1Former< Definition, > >, ) -> Struct1Former< Definition, > + #[inline(always)] + fn call(&self, storage: std::collections::HashSet, super_former: Option>,) -> Struct1Former { let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.hashset_1 + if let Some(ref mut field) = super_former.storage.hashset_1 { - former::ContainerAssign::assign( field, storage ); + former::ContainerAssign::assign(field, storage); } else { - super_former.storage.hashset_1 = Some( storage ); + super_former.storage.hashset_1 = Some(storage); } super_former } diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index e6ac891448..78ac8522c3 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -122,15 +122,15 @@ tests_impls! { // Container subformers are defined - let _got = Struct1FormerAssignVec1End; - let _got = Struct1FormerAssignHashmap1End; - let _got = Struct1FormerAssignHashset1End; + let _got = Struct1FormerAssignVec1End::< Struct1FormerDefinition >::default(); + let _got = Struct1FormerAssignHashmap1End::< Struct1FormerDefinition >::default(); + let _got = Struct1FormerAssignHashset1End::< Struct1FormerDefinition >::default(); - // SubformerEnd is defined - fn _f1< End : Struct1SubformerEnd< Struct1Former > > + // AsSubformerEnd is defined + fn _f1< End : Struct1AsSubformerEnd< Struct1Former > > ( _end : End, - _subformer : Struct1Subformer< Struct1Former, impl Struct1SubformerEnd< Struct1Former > > + _subformer : Struct1AsSubformer< Struct1Former, impl Struct1AsSubformerEnd< Struct1Former > > ) { } diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs index 58bd50f517..e62dd67566 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs @@ -6,9 +6,6 @@ fn child() let got = Parent::former() .child( "a" ).end() .child( "b" ).end() - // .add( Child::former().name( "a" ).form() ) - // .add( Child::former().name( "b" ).form() ) - // .end() .form(); let children = vec! diff --git a/module/core/former/tests/inc/former_tests/subformer_custom.rs b/module/core/former/tests/inc/former_tests/subformer_custom.rs index 49b8ab0a5e..5bf0331956 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom.rs @@ -14,7 +14,7 @@ where // // = command subformer - generated // -// pub type CommandSubformer< K, Superformer, End > = CommandFormer +// pub type CommandAsSubformer< K, Superformer, End > = CommandFormer // < // K, // CommandFormerDefinition @@ -29,7 +29,7 @@ where // // // = command subformer end - generated // -// pub trait CommandSubformerEnd< K, SuperFormer > +// pub trait CommandAsSubformerEnd< K, SuperFormer > // where // K : core::hash::Hash + std::cmp::Eq, // Self : the_module::FormingEnd @@ -39,7 +39,7 @@ where // { // } // -// impl< K, SuperFormer, T > CommandSubformerEnd< K, SuperFormer > +// impl< K, SuperFormer, T > CommandAsSubformerEnd< K, SuperFormer > // for T // where // K : core::hash::Hash + std::cmp::Eq, @@ -81,7 +81,7 @@ where #[ inline( always ) ] pub fn command_with_closure< IntoName >( self, name : IntoName ) -> - CommandSubformer< K, Self, impl CommandSubformerEnd< K, Self > > + CommandAsSubformer< K, Self, impl CommandAsSubformerEnd< K, Self > > where IntoName : core::convert::Into< String >, { @@ -115,7 +115,7 @@ where #[ inline( always ) ] pub fn command_with_type< IntoName >( self, name : IntoName ) -> - CommandSubformer< K, Self, impl CommandSubformerEnd< K, Self > > + CommandAsSubformer< K, Self, impl CommandAsSubformerEnd< K, Self > > where IntoName : core::convert::Into< String >, { diff --git a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs index 0d54af871f..4d22cbf714 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs @@ -42,7 +42,7 @@ where #[ inline( always ) ] pub fn command_with_helper< IntoName >( self, name : IntoName ) -> - CommandSubformer< K, Self, impl CommandSubformerEnd< K, Self > > + CommandAsSubformer< K, Self, impl CommandAsSubformerEnd< K, Self > > where IntoName : core::convert::Into< String >, ContainerAddElement @@ -52,7 +52,7 @@ where Command< K > > : - CommandSubformerEnd< K, Self >, + CommandAsSubformerEnd< K, Self >, { let former = CommandFormer::begin_precise diff --git a/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs new file mode 100644 index 0000000000..df0d6dac08 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs @@ -0,0 +1,29 @@ +#![ allow( dead_code ) ] + +use super::*; + +/// Parameter description. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent required for the template. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + #[ container( former::VectorDefinition ) ] + #[ subform( name : child ) ] + // #[ setter( false ) ] + children : Vec< Child >, +} + +// + +// xxx +// include!( "./only_test/subformer_subform.rs" ); +include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs similarity index 98% rename from module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs rename to module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs index 55d8004e18..3a5f2e592a 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs @@ -2,7 +2,6 @@ use super::*; -// xxx : rename /// Parameter description. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] pub struct Child @@ -95,7 +94,7 @@ where #[ inline( always ) ] pub fn child( self, name : &str ) -> - ChildSubformer< Self, impl ChildSubformerEnd< Self > > + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { self._children_element_subformer ::< ChildFormer< _ >, _, >() diff --git a/module/core/former/tests/inc/former_tests/subformer_subform.rs b/module/core/former/tests/inc/former_tests/subformer_subform.rs index fe3ec1ffe9..a3325cbae2 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform.rs @@ -28,7 +28,7 @@ where { #[ inline( always ) ] - pub fn child( self, name : &str ) -> ChildSubformer< Self, impl ChildSubformerEnd< Self > > + pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { self._children_element_subformer::< ChildFormer< _ >, _, >() .name( name ) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 40409c8542..7295556e41 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -112,7 +112,7 @@ where #[ inline( always ) ] pub fn child( self, name : &str ) -> - ChildSubformer< Self, impl ChildSubformerEnd< Self > > + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { self._children_element_subformer ::< ChildFormer< _ >, _, >() diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index cb00c05876..2c7fd9548a 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -26,8 +26,6 @@ mod former_tests 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_implicit; mod attribute_default_container; mod attribute_default_primitive; @@ -70,10 +68,9 @@ mod former_tests mod subformer_subform_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_implicit_container; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_subform_implicit_container_manutal; - // xxx + mod subformer_implicit_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_implicit_container_manual; } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 37b7c56249..9b2bf54339 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -93,12 +93,15 @@ impl Attributes { match attr.meta { + syn::Meta::List( ref meta_list ) => + { + subform.replace( syn::parse2::< AttributeSubform >( meta_list.tokens.clone() )? ); + }, syn::Meta::Path( ref _path ) => { - // code_print!( _path ); subform.replace( syn::parse2::< AttributeSubform >( Default::default() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ subform ], but got:\n {}", qt!{ #attr } ), + _ => return_syn_err!( attr, "Expects an attribute of format #[ subform ] or #[ subform( name : child ) ], but got:\n {}", qt!{ #attr } ), } } "alias" => @@ -238,21 +241,79 @@ impl syn::parse::Parse for AttributeContainer } } -/// zzz : write description with example -#[ allow( dead_code ) ] +// /// zzz : write description with example +// #[ allow( dead_code ) ] +// struct AttributeSubform +// { +// // name : Option< syn::Ident >, +// // public : bolean, +// } +// +// impl syn::parse::Parse for AttributeSubform +// { +// fn parse( _input : syn::parse::ParseStream< '_ > ) -> Result< Self > +// { +// Ok( Self +// { +// // expr : input.parse()?, +// }) +// } +// } + struct AttributeSubform { - // expr : syn::Type, + name : Option< syn::Ident >, + public : bool, } impl syn::parse::Parse for AttributeSubform { - fn parse( _input : syn::parse::ParseStream< '_ > ) -> Result< Self > + fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > { - Ok( Self + let mut name : Option< syn::Ident > = None; + let mut public : bool = true; + + while !input.is_empty() { - // expr : input.parse()?, - }) + let lookahead = input.lookahead1(); + if lookahead.peek( syn::Ident ) + { + let ident : syn::Ident = input.parse()?; + if ident == "name" + { + input.parse::< syn::Token![:] >()?; // Expecting a colon + name = Some( input.parse()? ); // Parse the identifier + } + else if ident == "public" + { + input.parse::< syn::Token![:] >()?; // Expecting a colon + // Parse the boolean by checking next Ident if it's "true" or "false" + let value : syn::Ident = input.parse()?; + match value.to_string().as_str() + { + "true" => public = true, + "false" => public = false, + _ => return Err( syn::Error::new( value.span(), "expected `true` or `false`" ) ), + } + } + else + { + return Err( lookahead.error() ); + } + } + else + { + return Err( lookahead.error() ); + } + + // Optional comma handling + if input.peek( syn::Token![,] ) + { + input.parse::< syn::Token![,] >()?; + } + } + + Ok( Self { name, public } ) } } @@ -772,7 +833,7 @@ fn container_setter #( #params, )* Self, Self, - #former_assign_end, + #former_assign_end< Definition >, > } // former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End, > @@ -781,7 +842,7 @@ fn container_setter { qt! { - < #non_optional_ty as former::EntityToDefinition< Self, Self, #former_assign_end > >::Definition + < #non_optional_ty as former::EntityToDefinition< Self, Self, #former_assign_end< Definition > > >::Definition } // < Vec< String > as former::EntityToDefinition< Self, Self, Struct1FormerAssignVec1End > >::Definition }; @@ -806,7 +867,7 @@ fn container_setter #subformer_definition >, { - Former2::former_begin( None, Some( self ), #former_assign_end ) + Former2::former_begin( None, Some( self ), #former_assign_end::< Definition >::default() ) } }; @@ -995,16 +1056,34 @@ Callback replace content of container assigning new content from subformer's sto let r = qt! { - // zzz : description + // zzz : improve description #[ doc = #former_assign_end_doc ] - pub struct #former_assign_end; + pub struct #former_assign_end< Definition > + { + _phantom : core::marker::PhantomData< ( Definition, ) >, + } + + impl< Definition > Default + for #former_assign_end< Definition > + { + + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + + } #[ automatically_derived ] impl< #former_generics_impl > former::FormingEnd < #subformer_definition, > - for #former_assign_end + for #former_assign_end< Definition > where #former_generics_where { @@ -1287,13 +1366,13 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_definition = syn::Ident::new( &former_definition_name, stru.span() ); let former_definition_types_name = format!( "{}FormerDefinitionTypes", stru ); let former_definition_types = syn::Ident::new( &former_definition_types_name, stru.span() ); - let subformer_name = format!( "{}Subformer", stru ); - let subformer = syn::Ident::new( &subformer_name, stru.span() ); - let subformer_end_name = format!( "{}SubformerEnd", stru ); - let subformer_end = syn::Ident::new( &subformer_end_name, stru.span() ); + let as_subformer_name = format!( "{}AsSubformer", stru ); + let as_subformer = syn::Ident::new( &as_subformer_name, stru.span() ); + let as_subformer_end_name = format!( "{}AsSubformerEnd", stru ); + let as_subformer_end = syn::Ident::new( &as_subformer_end_name, stru.span() ); // zzz : improve - let subformer_end_doc = format!( "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure." ); + let as_subformer_end_doc = format!( "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure." ); /* parameters for structure */ @@ -1842,7 +1921,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // zzz : improve description /// Use as subformer of a field during process of forming of super structure. - pub type #subformer < #struct_generics_ty __Superformer, __End > = #former + pub type #as_subformer < #struct_generics_ty __Superformer, __End > = #former < #struct_generics_ty #former_definition @@ -1855,11 +1934,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > >, >; - // = subformer end + // = as subformer end // zzz : imporove documentation - #[ doc = #subformer_end_doc ] - pub trait #subformer_end < #struct_generics_impl SuperFormer > + #[ doc = #as_subformer_end_doc ] + pub trait #as_subformer_end < #struct_generics_impl SuperFormer > where #struct_generics_where Self : former::FormingEnd @@ -1869,7 +1948,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { } - impl< #struct_generics_impl SuperFormer, T > #subformer_end < #struct_generics_ty SuperFormer > + impl< #struct_generics_impl SuperFormer, T > #as_subformer_end < #struct_generics_ty SuperFormer > for T where #struct_generics_where