-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
304 additions
and
2 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
module/core/former/tests/inc/former_tests/subformer_container.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" ); |
271 changes: 271 additions & 0 deletions
271
module/core/former/tests/inc/former_tests/subformer_container_manual.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters