Skip to content

Commit

Permalink
former : making subforming more friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 21, 2024
1 parent fed47e3 commit 3baa864
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 89 deletions.
20 changes: 10 additions & 10 deletions module/core/former/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,20 @@ pub struct UserProfileFormerStorage

pub struct UserProfileFormer
<
FormerContext = UserProfile,
FormerEnd = former::ReturnFormed,
Context = UserProfile,
End = former::ReturnFormed,
>
where
FormerEnd : former::FormingEnd< UserProfile, FormerContext >,
End : former::FormingEnd< UserProfile, Context >,
{
storage : UserProfileFormerStorage,
context : Option< FormerContext >,
on_end : Option< FormerEnd >,
context : Option< Context >,
on_end : Option< End >,
}

impl< FormerContext, FormerEnd > UserProfileFormer< FormerContext, FormerEnd >
impl< Context, End > UserProfileFormer< Context, End >
where
FormerEnd : former::FormingEnd< UserProfile, FormerContext >,
End : former::FormingEnd< UserProfile, Context >,
{
#[ inline( always ) ]
pub fn form( mut self ) -> UserProfile
Expand Down Expand Up @@ -212,8 +212,8 @@ where
#[ inline( always ) ]
pub fn begin
(
context : Option< FormerContext >,
on_end : FormerEnd,
context : Option< Context >,
on_end : End,
) -> Self
{
Self
Expand All @@ -225,7 +225,7 @@ where
}

#[ inline( always ) ]
pub fn end( mut self ) -> FormerContext
pub fn end( mut self ) -> Context
{
let on_end = self.on_end.take().unwrap();
let context = self.context.take();
Expand Down
20 changes: 10 additions & 10 deletions module/core/former/examples/former_trivial_expaned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ fn main()

pub struct UserProfileFormer
<
FormerContext = UserProfile,
FormerEnd = former::ReturnFormed,
Context = UserProfile,
End = former::ReturnFormed,
>
where
FormerEnd : former::FormingEnd< UserProfile, FormerContext >,
End : former::FormingEnd< UserProfile, Context >,
{
storage : UserProfileFormerStorage,
context : Option< FormerContext >,
on_end : Option< FormerEnd >,
context : Option< Context >,
on_end : Option< End >,
}

impl< FormerContext, FormerEnd > UserProfileFormer< FormerContext, FormerEnd >
impl< Context, End > UserProfileFormer< Context, End >
where
FormerEnd : former::FormingEnd< UserProfile, FormerContext >,
End : former::FormingEnd< UserProfile, Context >,
{
#[ inline( always ) ]
pub fn form( mut self ) -> UserProfile
Expand Down Expand Up @@ -165,8 +165,8 @@ fn main()
#[ inline( always ) ]
pub fn begin
(
context : Option< FormerContext >,
on_end : FormerEnd,
context : Option< Context >,
on_end : End,
) -> Self
{
Self
Expand All @@ -178,7 +178,7 @@ fn main()
}

#[ inline( always ) ]
pub fn end( mut self ) -> FormerContext
pub fn end( mut self ) -> Context
{
let on_end = self.on_end.take().unwrap();
let context = self.context.take();
Expand Down
34 changes: 17 additions & 17 deletions module/core/former/src/axiomatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,21 @@ for FormingEndWrapper< Formed, Context >
}
}

/// A `FormingEnd` implementation that returns the original context without any modifications.
///
/// This struct is used when no end-of-forming processing is needed, and the original context is to be returned as-is.
#[ derive( Debug, Default ) ]
pub struct NoEnd;

impl< Formed, Context > FormingEnd< Formed, Context >
for NoEnd
{
#[ inline( always ) ]
fn call( &self, _formed : Formed, context : core::option::Option< Context > ) -> Context
{
context.unwrap()
}
}
// /// A `FormingEnd` implementation that returns the original context without any modifications.
// ///
// /// This struct is used when no end-of-forming processing is needed, and the original context is to be returned as-is.
// #[ derive( Debug, Default ) ]
// pub struct NoEnd;
//
// impl< Formed, Context > FormingEnd< Formed, Context >
// for NoEnd
// {
// #[ inline( always ) ]
// fn call( &self, _formed : Formed, context : core::option::Option< Context > ) -> Context
// {
// context.unwrap()
// }
// }

/// A `FormingEnd` implementation that returns the formed container itself instead of the context.
///
Expand Down Expand Up @@ -158,7 +158,7 @@ for ReturnFormed
/// potentially using the provided `Context`.
///
pub trait FormerBegin< Formed, Context >
pub trait FormerBegin< Storage, Formed, Context >
{

/// * `End` - Specifies the trait bound for the closure or handler that gets called at the completion
Expand All @@ -184,7 +184,7 @@ pub trait FormerBegin< Formed, Context >
///
fn _begin
(
formed : core::option::Option< Formed >,
storage : core::option::Option< Storage >,
context : core::option::Option< Context >,
on_end : Self::End,
) -> Self;
Expand Down
2 changes: 1 addition & 1 deletion module/core/former/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ where

//

impl< E, Formed, Context, End > FormerBegin< Formed, Context >
impl< E, Formed, Context, End > FormerBegin< Formed, Formed, Context >
for VectorSubformer< E, Formed, Context, End >
where
End : FormingEnd< Formed, Context >,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ impl Default for Struct1FormerStorage

pub struct Struct1Former
<
FormerContext = Struct1,
FormerEnd = the_module::ReturnFormed,
Context = Struct1,
End = the_module::ReturnFormed,
>
where
FormerEnd : the_module::FormingEnd< Struct1, FormerContext >,
End : the_module::FormingEnd< Struct1, Context >,
{
storage : Struct1FormerStorage,
context : ::core::option::Option< FormerContext >,
on_end : ::core::option::Option< FormerEnd >,
context : ::core::option::Option< Context >,
on_end : ::core::option::Option< End >,
}

impl< FormerContext, FormerEnd > Struct1Former< FormerContext, FormerEnd >
impl< Context, End > Struct1Former< Context, End >
where
FormerEnd : the_module::FormingEnd< Struct1, FormerContext >,
End : the_module::FormingEnd< Struct1, Context >,
{

#[ inline( always ) ]
Expand Down Expand Up @@ -127,8 +127,8 @@ where
pub fn begin
(
mut storage : ::core::option::Option< Struct1FormerStorage >,
context : ::core::option::Option< FormerContext >,
on_end : FormerEnd,
context : ::core::option::Option< Context >,
on_end : End,
) -> Self
{
if storage.is_none()
Expand All @@ -144,7 +144,7 @@ where
}

#[ inline( always ) ]
pub fn end( mut self ) -> FormerContext
pub fn end( mut self ) -> Context
{
let on_end = self.on_end.take().unwrap();
let context = self.context.take();
Expand All @@ -156,7 +156,12 @@ where
pub fn __vec_1< Former2 >( self ) ->
Former2
where
Former2 : former::FormerBegin< Vec< String >, Self, End = former::FormingEndWrapper< Vec< String >, Self > >,
Former2 : former::FormerBegin
<
Vec< String >,
Vec< String >,
Self, End = former::FormingEndWrapper< Vec< String >, Self >,
>,
{
let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self
{
Expand Down Expand Up @@ -243,9 +248,9 @@ where

}

// impl< FormerContext, FormerEnd > Struct1Former< FormerContext, FormerEnd >
// impl< Context, End > Struct1Former< Context, End >
// where
// FormerEnd: the_module::FormingEnd<Struct1, FormerContext>,
// End: the_module::FormingEnd<Struct1, Context>,

impl Struct1Former< Struct1, the_module::ReturnFormed >
{
Expand All @@ -260,30 +265,30 @@ impl Struct1Former< Struct1, the_module::ReturnFormed >

//

// impl< FormerContext, FormerEnd > Struct1Former< FormerContext, FormerEnd >
// impl< Context, End > Struct1Former< Context, End >
// where
// FormerEnd : the_module::FormingEnd< Struct1, FormerContext >,
// End : the_module::FormingEnd< Struct1, Context >,

// impl< FormerContext, FormerEnd > former::FormerBegin< Struct1, FormerContext >
// for Struct1Former< FormerContext, FormerEnd >
// where
// End : the_module::FormingEnd< Struct1, FormerContext >,
// {
// type End = End;
//
// #[ inline( always ) ]
// fn _begin
// (
// storage : core::option::Option< Struct1FormerStorage >, /* xxx2 : that should be storage */
// context : core::option::Option< FormerContext >,
// on_end : End,
// ) -> Self
// {
// debug_assert!( storage.is_none() );
// Self::begin( None, context, on_end )
// }
//
// }
impl< Context, End > former::FormerBegin< Struct1FormerStorage, Struct1, Context >
for Struct1Former< Context, End >
where
End : the_module::FormingEnd< Struct1, Context >,
{
type End = End;

#[ inline( always ) ]
fn _begin
(
storage : core::option::Option< Struct1FormerStorage >, /* xxx2 : that should be storage */
context : core::option::Option< Context >,
on_end : End,
) -> Self
{
debug_assert!( storage.is_none() );
Self::begin( None, context, on_end )
}

}

//

Expand Down
4 changes: 2 additions & 2 deletions module/core/former/tests/inc/former_tests/attribute_setter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ pub struct StructWithCustomSetters
magic : String,
}

impl< FormerContext, FormerEnd > StructWithCustomSettersFormer< FormerContext, FormerEnd >
impl< Context, End > StructWithCustomSettersFormer< Context, End >
where
FormerEnd: the_module::FormingEnd< StructWithCustomSetters, FormerContext >,
End: the_module::FormingEnd< StructWithCustomSetters, Context >,
{

/// Custom alternative setter of ordinary field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct TemplateParameters

}

impl< Context, End > former::FormerBegin< TemplateParameterDescriptor, Context >
impl< Context, End > former::FormerBegin< TemplateParameterDescriptorFormerStorage, TemplateParameterDescriptor, Context >
for TemplateParameterDescriptorFormer< Context, End >
where
End : the_module::FormingEnd< TemplateParameterDescriptor, Context >,
Expand All @@ -36,7 +36,7 @@ where
#[ inline( always ) ]
fn _begin
(
storage : core::option::Option< TemplateParameterDescriptor >, /* xxx2 : that should be storage */
storage : core::option::Option< TemplateParameterDescriptorFormerStorage >, /* xxx2 : that should be storage */
context : core::option::Option< Context >,
on_end : End,
) -> Self
Expand All @@ -56,7 +56,7 @@ where
pub fn descriptor3< Former2 >( self ) ->
Former2
where
Former2 : former::FormerBegin< TemplateParameterDescriptor, Self, End = former::FormingEndWrapper< TemplateParameterDescriptor, Self > >,
Former2 : former::FormerBegin< TemplateParameterDescriptorFormerStorage, TemplateParameterDescriptor, Self, End = former::FormingEndWrapper< TemplateParameterDescriptor, Self > >,
// FieldContainer : ContainerAdd,
{
let on_end = | descriptor : TemplateParameterDescriptor, super_former : core::option::Option< Self > | -> Self
Expand Down
4 changes: 2 additions & 2 deletions module/core/former_meta/src/derive/former.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,9 +1073,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream >
{
let _example =
r#"
impl< FormerContext, FormerEnd > UserProfileFormer< FormerContext, FormerEnd >
impl< Context, End > UserProfileFormer< Context, End >
where
FormerEnd : former::FormingEnd< UserProfile, FormerContext >,
End : former::FormingEnd< UserProfile, Context >,
{
pub fn age< Src >( mut self, src : Src ) -> Self
where
Expand Down
18 changes: 9 additions & 9 deletions module/core/former_meta/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,20 @@ mod derive
///
/// pub struct UserProfileFormer
/// <
/// FormerContext = UserProfile,
/// FormerEnd = former::ReturnFormed,
/// Context = UserProfile,
/// End = former::ReturnFormed,
/// >
/// where
/// FormerEnd : former::FormingEnd< UserProfile, FormerContext >,
/// End : former::FormingEnd< UserProfile, Context >,
/// {
/// storage : UserProfileFormerStorage,
/// context : Option< FormerContext >,
/// on_end : Option< FormerEnd >,
/// context : Option< Context >,
/// on_end : Option< End >,
/// }
///
/// impl< FormerContext, FormerEnd > UserProfileFormer< FormerContext, FormerEnd >
/// impl< Context, End > UserProfileFormer< Context, End >
/// where
/// FormerEnd : former::FormingEnd< UserProfile, FormerContext >,
/// End : former::FormingEnd< UserProfile, Context >,
/// {
/// #[ inline( always ) ]
/// pub fn form( mut self ) -> UserProfile
Expand Down Expand Up @@ -195,7 +195,7 @@ mod derive
/// }
///
/// #[ inline( always ) ]
/// pub fn begin( context : Option< FormerContext >, on_end : FormerEnd ) -> Self
/// pub fn begin( context : Option< Context >, on_end : End ) -> Self
/// {
/// Self
/// {
Expand All @@ -206,7 +206,7 @@ mod derive
/// }
///
/// #[ inline( always ) ]
/// pub fn end( mut self ) -> FormerContext
/// pub fn end( mut self ) -> Context
/// {
/// let on_end = self.on_end.take().unwrap();
/// let context = self.context.take();
Expand Down

0 comments on commit 3baa864

Please sign in to comment.