Skip to content

Commit

Permalink
former : experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Apr 6, 2024
1 parent 999db8f commit 93f26e4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
2 changes: 1 addition & 1 deletion module/core/former_meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ full = [
]
enabled = [ "macro_tools/enabled", "iter_tools/enabled" ]

derive_former = []
derive_former = [ "convert_case" ]
derive_components = []
derive_component_assign = []
derive_components_assign = [ "derive_components", "derive_component_assign", "convert_case" ]
Expand Down
29 changes: 20 additions & 9 deletions module/core/former_meta/src/derive/former.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,42 +617,53 @@ fn fields_setter_callback_descriptor_map
->
Result< TokenStream >
{
let ident = &field.ident;

if field.attrs.subformer.is_none()
{
return Ok( qt!{ } );
}

use convert_case::{ Case, Casing };

let ident = field.ident;
let field_descriptor_name = format!( "former{}End", ident.to_string().to_case( Case::Camel ) );
let field_descriptor = syn::Ident::new( &field_descriptor_name, ident.span() );

let field_ty = field.non_optional_ty;
// let xxx = field_ty;
// let generics = field_ty.generics
// let ( generics_impl, generics_ty, generics_where ) = generics.split_for_impl();


let r = qt!
{
xxx
// xxx

// zzz : description
/// Return original former after subformer for `vec_1` is done.
#[ allow( non_camel_case_types ) ]
pub struct Struct1FormerVec_1End;
pub struct #field_descriptor;
#[ automatically_derived ]
impl< Definition > former::FormingEnd
<
former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >,
former::VectorDefinition< String, #former< Definition >, #former< Definition >, former::NoEnd >,
>
for Struct1FormerVec_1End
for #field_descriptor
where
Definition : former::FormerDefinition,
Definition::Types : former::FormerDefinitionTypes
<
Storage = Struct1FormerStorage
Storage = #former_storage
>,
{
#[ inline( always ) ]
fn call
(
&self, storage : Vec< String >,
super_former : Option< Struct1Former< Definition > >,
&self,
storage : field_ty,
super_former : Option< #former< Definition > >,
)
-> Struct1Former< Definition >
-> #former< Definition >
{
let mut super_former = super_former.unwrap();
if let Some( ref mut field ) = super_former.storage.vec_1
Expand Down
27 changes: 23 additions & 4 deletions module/core/macro_tools/src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,23 @@ pub( crate ) mod private
result
}

/// Extract generics from a type.
pub fn extract_from_type( type_example : &syn::Type ) -> Option< syn::PathArguments >
{
if let syn::Type::Path( type_path ) = type_example
{
let segments = &type_path.path.segments;
let last_segment = segments.last()?;

if let syn::PathArguments::AngleBracketed( generics ) = &last_segment.arguments
{
return Some( generics.clone() );
}
}
None
}


}

#[ doc( inline ) ]
Expand All @@ -197,10 +214,12 @@ pub mod protected
pub use super::orphan::*;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::private::merge;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::private::params_names;
pub use super::private::
{
merge,
params_names,
extract_from_type,
};
}

/// Orphan namespace of the module.
Expand Down

0 comments on commit 93f26e4

Please sign in to comment.