From 96249d4a78ee656d335c02968e57677478f378c4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 19:17:09 +0300 Subject: [PATCH] former : experimenting --- .../inc/former_tests/subformer_container.rs | 28 ++ .../subformer_container_manual.rs | 271 ++++++++++++++++++ .../former_tests/subformer_subform_manual.rs | 3 +- module/core/former/tests/inc/mod.rs | 4 + 4 files changed, 304 insertions(+), 2 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/subformer_container.rs create mode 100644 module/core/former/tests/inc/former_tests/subformer_container_manual.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_container.rs b/module/core/former/tests/inc/former_tests/subformer_container.rs new file mode 100644 index 0000000000..98e04e4ffb --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_container.rs @@ -0,0 +1,28 @@ +#![ 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 ) ] + // #[ setter( false ) ] + children : Vec< Child >, +} + +// == begin of generated + +// == end of generated + +include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs new file mode 100644 index 0000000000..30705da33c --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs @@ -0,0 +1,271 @@ +#![ 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 ] + #[ setter( false ) ] + children : Vec< Child >, +} + +// == begin of generated for Parent in context of attribute subform + +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn _children_add_subformer_with_closure< Former2, Definition2, Types2 >( self ) -> + Former2 + where + Types2 : former::FormerDefinitionTypes + < + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2 : former::FormerDefinition + < + Types = Types2, + End = former::FormingEndClosure< Types2 >, + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2::End : former::FormingEnd< Definition2::Types >, + Former2 : former::FormerBegin + < + Definition2, + >, + { + let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + if super_former.storage.children.is_none() + { + super_former.storage.children = Some( Default::default() ); + } + if let Some( ref mut children ) = super_former.storage.children + { + former::ContainerAdd::add( children, former::StoragePreform::preform( substorage ) ); + } + super_former + }; + Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + } + + #[ inline( always ) ] + pub fn _children_add_subformer< Former2, Definition2 >( self ) -> + Former2 + where + Definition2 : former::FormerDefinition + < + End = ParentFormerAddChildrenEnd< Definition >, + Storage = < Child as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Definition2::Types : former::FormerDefinitionTypes + < + Storage = < Child as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Former2 : former::FormerBegin< Definition2 >, + { + Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) + } + + #[ inline( always ) ] + pub fn child( self, name : &str ) -> + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._children_add_subformer + ::< ChildFormer< _ >, _, >() + .name( name ) + } + + // #[ inline( always ) ] + // pub fn _child( self ) -> + // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + // { + // self._children_add_subformer + // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + // } + + #[ inline( always ) ] + pub fn _child( self ) -> + < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer + < + // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, + < + < Vec< Child > as former::ContainerAdd >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > + >::Definition, + > + >::Former + { + self._children_add_subformer + ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() + } + +} + +/// Handles the completion of and element of subformer's container. +pub struct ParentFormerAddChildrenEnd< Definition > +{ + _phantom : core::marker::PhantomData< fn( Definition ) >, +} + +impl< Definition > Default +for ParentFormerAddChildrenEnd< Definition > +{ + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} + +impl< Types2, Definition > former::FormingEnd< Types2, > +for ParentFormerAddChildrenEnd< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = < Parent as former::EntityToStorage >::Storage, + >, + Types2 : former::FormerDefinitionTypes + < + Storage = < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + Formed = ParentFormer< Definition >, + Context = ParentFormer< Definition >, + >, +{ + #[ inline( always ) ] + fn call + ( + &self, + substorage : Types2::Storage, + super_former : core::option::Option< Types2::Context >, + ) + -> Types2::Formed + { + let mut super_former = super_former.unwrap(); + if super_former.storage.children.is_none() + { + super_former.storage.children = Some( Default::default() ); + } + if let Some( ref mut fields ) = super_former.storage.children + { + former::ContainerAdd::add( fields, former::StoragePreform::preform( substorage ) ); + } + super_former + } +} + +// == end of generated for Parent in context of attribute subform + +// == begin of generated for Parent in context of attribute container( former::VectorDefinition ) ] + +#[ automatically_derived ] +impl< Definition, > ParentFormer< Definition, > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, +{ + + #[ inline( always ) ] + pub fn _children_assign< Former2 >( self ) -> Former2 + where + Former2 : former::FormerBegin< former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > >, + { + Former2::former_begin( None, Some( self ), ParentFormerAssignChildrenEnd::< Definition >::default() ) + } + #[ doc = + "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer." ] + #[ inline( always ) ] + pub fn children( self ) -> former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > + { + self._children_assign::< former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > >() + } + +} + +// + +#[ doc = r"Callback to return original former after forming of container for `vec_1` is done. Callback replace content of container assigning new content from subformer's storage." ] +pub struct ParentFormerAssignChildrenEnd< Definition > +{ + _phantom : core::marker::PhantomData< ( Definition, ) >, +} + +impl< Definition > Default for ParentFormerAssignChildrenEnd< Definition > +{ + + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + +} + +#[ automatically_derived ] +impl< Definition, > former::FormingEnd +// < former::VectorDefinition< Child, ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd >, > +< + < Vec< Child > as former::EntityToDefinition< ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd > >::Definition +> +for ParentFormerAssignChildrenEnd< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, +{ + #[ inline( always ) ] + fn call + ( + &self, + storage : Vec< Child >, + super_former : Option< ParentFormer< Definition, > >, + ) + -> ParentFormer< Definition, > + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.children + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.children = Some( storage ); + } + super_former + } +} + +// == end of generated for Parent in context of attribute container( former::VectorDefinition ) ] + +include!( "./only_test/subformer_subform.rs" ); +include!( "./only_test/subformer_container.rs" ); 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 554e8f288a..f12d4f78d2 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 @@ -22,8 +22,7 @@ pub struct Parent children : Vec< Child >, } -// xxx - +// = custom impl< Definition > ParentFormer< Definition > where diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index bdbbd03433..5429413205 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -66,6 +66,10 @@ mod former_tests mod subformer_subform; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_implicit_container;