Skip to content

Commit

Permalink
former : experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Apr 30, 2024
1 parent 64d672b commit 5ae5546
Show file tree
Hide file tree
Showing 8 changed files with 405 additions and 436 deletions.
2 changes: 1 addition & 1 deletion module/core/former/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ where

// zzz : qqq : implement for hashset / hashmap
// zzz : qqq : cover by tests
// zzz : qqq : rid off bound `Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed``
// zzz : qqq : rid off bound `Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed` for all containers
impl< E, Definition > EntityToFormer< Definition > for Vec< E >
where
Definition : FormerDefinition< Storage = Vec< E > >,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#![ 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
{
// #[ subform ]
#[ subform( name = _child ) ]
#[ container( former::VectorDefinition ) ]
// #[ setter( false ) ]
children : Vec< Child >,
}

impl< Definition > ParentFormer< Definition >
where
Definition : former::FormerDefinition,
Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >,
{

#[ 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, _, >()
// }

}

// == begin of generated

// == end of generated

// xxx
include!( "./only_test/subformer_subform.rs" );
include!( "./only_test/subformer_container.rs" );
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" );
Loading

0 comments on commit 5ae5546

Please sign in to comment.