Skip to content

Commit

Permalink
Merge pull request #1320 from Wandalen/former_usability_2
Browse files Browse the repository at this point in the history
former : make former applicable to private structs
  • Loading branch information
Wandalen authored May 11, 2024
2 parents c7925cc + e2fc1b7 commit 7cc26ae
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#![ allow( dead_code ) ]

use super::*;

/// Parameter description.
#[ derive( Debug, Default, PartialEq, the_module::Former ) ]
struct Child
{
name : String,
data : 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 ) ]
struct Parent
{
#[ subform( name = _child ) ]
#[ container( name = children2 ) ]
#[ scalar( name = children3 ) ]
children : Vec< Child >,
}

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

#[ inline( always ) ]
fn child( self, name : &str ) ->
ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > >
{
self._children_add
::< ChildFormer< _ >, _, >()
.name( name )
}

#[ inline( always ) ]
fn children( self ) -> &'static str
{
r#"
Scalar setter `children` should not be generated by default if subform is used.
It can only be generated if req
"#
}

}

// == begin of generated

// == end of generated

include!( "./only_test/subformer_subform_child.rs" );
include!( "./only_test/subformer_container_children2.rs" );
include!( "./only_test/subformer_scalar_children3.rs" );
2 changes: 2 additions & 0 deletions module/core/former/tests/inc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ mod former_tests
#[ cfg( any( not( feature = "no_std" ) ) ) ]
mod subformer_subform_and_container;
#[ cfg( any( not( feature = "no_std" ) ) ) ]
mod subformer_subform_and_container_private;
#[ cfg( any( not( feature = "no_std" ) ) ) ]
mod subformer_subform_and_container_parametrized;

}
Expand Down
11 changes: 6 additions & 5 deletions module/core/former_meta/src/derive_former.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream >

/* names */

let vis = &ast.vis;
let stru = &ast.ident;
let former_name = format!( "{}Former", stru );
let former = syn::Ident::new( &former_name, stru.span() );
Expand Down Expand Up @@ -385,7 +386,7 @@ specific needs of the broader forming context. It mandates the implementation of

/// Defines the generic parameters for formation behavior including context, form, and end conditions.
#[ derive( Debug ) ]
pub struct #former_definition_types < #former_definition_types_generics_with_defaults >
#vis struct #former_definition_types < #former_definition_types_generics_with_defaults >
where
#former_definition_types_generics_where
{
Expand Down Expand Up @@ -421,7 +422,7 @@ specific needs of the broader forming context. It mandates the implementation of

/// Holds the definition types used during the formation process.
#[ derive( Debug ) ]
pub struct #former_definition < #former_definition_generics_with_defaults >
#vis struct #former_definition < #former_definition_generics_with_defaults >
where
#former_definition_generics_where
{
Expand Down Expand Up @@ -464,7 +465,7 @@ specific needs of the broader forming context. It mandates the implementation of

#[ doc = "Stores potential values for fields during the formation process." ]
#[ allow( explicit_outlives_requirements ) ]
pub struct #former_storage < #struct_generics_with_defaults >
#vis struct #former_storage < #struct_generics_with_defaults >
where
#struct_generics_where
{
Expand Down Expand Up @@ -524,7 +525,7 @@ specific needs of the broader forming context. It mandates the implementation of
// = former

#[ doc = #doc_former_struct ]
pub struct #former < #former_generics_with_defaults >
#vis struct #former < #former_generics_with_defaults >
where
#former_generics_where
{
Expand Down Expand Up @@ -721,7 +722,7 @@ specific needs of the broader forming context. It mandates the implementation of
///
/// This type alias configures former of the structure with a specific definition to streamline its usage in broader contexts,
/// especially where structure needs to be integrated into larger structures with a clear termination condition.
pub type #as_subformer < #struct_generics_ty __Superformer, __End > = #former
#vis type #as_subformer < #struct_generics_ty __Superformer, __End > = #former
<
#struct_generics_ty
#former_definition
Expand Down

0 comments on commit 7cc26ae

Please sign in to comment.