Skip to content

Commit

Permalink
former : experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 30, 2024
1 parent af08892 commit 811f3e8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ pub struct Struct1

// = end of generated

include!( "./only_test/primitives.rs" );
include!( "./only_test/primitives.rs" );
10 changes: 5 additions & 5 deletions module/core/former/tests/inc/former_tests/a_primitives_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ where
{
storage : storage.unwrap(),
context,
on_end : ::core::option::Option::Some( on_end.into() ),
on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ),
}
}

Expand Down Expand Up @@ -266,23 +266,23 @@ where
where Src : core::convert::Into< i32 >,
{
debug_assert!( self.storage.int_1.is_none() );
self.storage.int_1 = Some( src.into() );
self.storage.int_1 = Some( ::core::convert::Into::into( src ) );
self
}

pub fn string_1< Src >( mut self, src : Src ) -> Self
where Src : core::convert::Into< String >,
{
debug_assert!( self.storage.string_1.is_none() );
self.storage.string_1 = Some( src.into() );
self.storage.string_1 = Some( ::core::convert::Into::into( src ) );
self
}

pub fn string_optional_1< Src >( mut self, src : Src ) -> Self
where Src : core::convert::Into< String >
{
debug_assert!( self.storage.string_optional_1.is_none() );
self.storage.string_optional_1 = Some( src.into() );
self.storage.string_optional_1 = Some( ::core::convert::Into::into( src ) );
self
}

Expand All @@ -302,7 +302,7 @@ where
(
None,
None,
end.into(),
end,
)
}

Expand Down
69 changes: 60 additions & 9 deletions module/core/former_meta/src/derive/former.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ fn field_name_map( field : &FormerField< '_ > ) -> syn::Ident
/// Src : ::core::convert::Into< i32 >,
/// {
/// debug_assert!( self.int_1.is_none() );
/// self.storage.int_1 = ::core::option::Option::Some( src.into() );
/// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) );
/// self
/// }
///
Expand All @@ -514,7 +514,7 @@ fn field_name_map( field : &FormerField< '_ > ) -> syn::Ident
/// Src : ::core::convert::Into< i32 >,
/// {
/// debug_assert!( self.int_1.is_none() );
/// self.storage.int_1 = ::core::option::Option::Some( src.into() );
/// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) );
/// self
/// }
/// ```
Expand Down Expand Up @@ -577,7 +577,7 @@ fn field_setter_map( field : &FormerField< '_ > ) -> Result< TokenStream >
/// Src : ::core::convert::Into< i32 >,
/// {
/// debug_assert!( self.int_1.is_none() );
/// self.storage.int_1 = ::core::option::Option::Some( src.into() );
/// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) );
/// self
/// }
/// ```
Expand Down Expand Up @@ -605,7 +605,7 @@ fn field_setter
where Src : ::core::convert::Into< #non_optional_type >,
{
debug_assert!( self.storage.#field_ident.is_none() );
self.storage.#field_ident = ::core::option::Option::Some( src.into() );
self.storage.#field_ident = ::core::option::Option::Some( ::core::convert::Into::into( src ) );
self
}
}
Expand Down Expand Up @@ -831,6 +831,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream >
let former_definition = syn::Ident::new( &former_definition_name, struct_name.span() );
let former_definition_types_name = format!( "{}FormerDefinitionTypes", struct_name );
let former_definition_types = syn::Ident::new( &former_definition_types_name, struct_name.span() );
let former_with_closure_name = format!( "{}FormerWithClosure", struct_name );
let former_with_closure = syn::Ident::new( &former_with_closure_name, struct_name.span() );

/* generic parameters */

Expand Down Expand Up @@ -1008,6 +1010,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream >
type End = End;
}

pub type #former_with_closure< Context, Formed > =
#former_definition< Context, Formed, former::FormingEndClosure< #former_definition_types< Context, Formed > > >;

// = storage

#[ doc = "Container of a corresponding former." ]
Expand Down Expand Up @@ -1116,15 +1121,13 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream >
///
/// Begin the process of forming. Expects context of forming to return it after forming.
///
// zzz : improve description
#[ inline( always ) ]
pub fn begin
pub fn _begin_precise
(
mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >,
context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >,
on_end : < Definition as former::FormerDefinition >::End,
// mut storage : core::option::Option< #former_storage #generics_ty >,
// context : core::option::Option< __FormerContext >,
// on_end : __FormerEnd,
) -> Self
{
if storage.is_none()
Expand All @@ -1139,6 +1142,54 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream >
}
}

///
/// Begin the process of forming. Expects context of forming to return it after forming.
///
// zzz : improve description
#[ inline( always ) ]
pub fn begin
(
mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >,
context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >,
on_end : IntoEnd,
) -> Self
where
IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >,
{
if storage.is_none()
{
storage = Some( ::core::default::Default::default() );
}
Self
{
storage : storage.unwrap(),
context : context,
on_end : ::core::option::Option::Some( on_end.into() ),
}
}

// #[ inline( always ) ]
// pub fn begin< IntoEnd >
// (
// mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >,
// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >,
// on_end : IntoEnd,
// ) -> Self
// where
// IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >
// {
// if storage.is_none()
// {
// storage = Some( core::default::Default::default() );
// }
// Self
// {
// storage : storage.unwrap(),
// context,
// on_end : ::core::option::Option::Some( on_end.into() ),
// }
// }

///
/// End the process of forming returning original context of forming.
///
Expand Down Expand Up @@ -1219,7 +1270,7 @@ where
Src : Into< i32 >,
{
debug_assert!( self.age.is_none() );
self.storage.age = ::core::option::Option::Some( src.into() );
self.storage.age = ::core::option::Option::Some( ::core::convert::Into::into( src ) );
self
}
}
Expand Down

0 comments on commit 811f3e8

Please sign in to comment.