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 86d2e2b commit becb7ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
34 changes: 17 additions & 17 deletions module/core/former/src/axiomatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ pub trait FormingEnd< Formed, Context >
fn call( &self, storage : Formed, context : core::option::Option< Context > ) -> Context;
}

impl< Formed, Context, F > FormingEnd< Formed, Context > for F
impl< Storage, Context, F > FormingEnd< Storage, Context > for F
where
F : Fn( Formed, core::option::Option< Context > ) -> Context,
F : Fn( Storage, core::option::Option< Context > ) -> Context,
{
#[ inline( always ) ]
fn call( &self, storage : Formed, context : core::option::Option< Context > ) -> Context
fn call( &self, storage : Storage, context : core::option::Option< Context > ) -> Context
{
self( storage, context )
}
Expand All @@ -42,19 +42,19 @@ where
///
/// # Type Parameters
///
/// * `Formed` - The type of the container being processed. This type is passed to the closure
/// * `Storage` - The type of the container being processed. This type is passed to the closure
/// when it's called.
/// * `Context` - The type of the context that may be altered or returned by the closure.
/// This allows for flexible manipulation of context based on the container.
#[ cfg( not( feature = "no_std" ) ) ]
pub struct FormingEndWrapper< Formed, Context >
pub struct FormingEndWrapper< Storage, Context >
{
closure : Box< dyn Fn( Formed, Option< Context > ) -> Context >,
_marker : std::marker::PhantomData< Formed >,
closure : Box< dyn Fn( Storage, Option< Context > ) -> Context >,
_marker : std::marker::PhantomData< Storage >,
}

#[ cfg( not( feature = "no_std" ) ) ]
impl< Formed, Context > FormingEndWrapper< Formed, Context >
impl< Storage, Context > FormingEndWrapper< Storage, Context >
{
/// Constructs a new `FormingEndWrapper` with the provided closure.
///
Expand All @@ -67,7 +67,7 @@ impl< Formed, Context > FormingEndWrapper< Formed, Context >
/// # Returns
///
/// Returns an instance of `FormingEndWrapper` encapsulating the provided closure.
pub fn new( closure : impl Fn( Formed, Option< Context > ) -> Context + 'static ) -> Self
pub fn new( closure : impl Fn( Storage, Option< Context > ) -> Context + 'static ) -> Self
{
Self
{
Expand All @@ -80,7 +80,7 @@ impl< Formed, Context > FormingEndWrapper< Formed, Context >
#[ cfg( not( feature = "no_std" ) ) ]
use std::fmt;
#[ cfg( not( feature = "no_std" ) ) ]
impl< Formed, Context > fmt::Debug for FormingEndWrapper< Formed, Context >
impl< Storage, Context > fmt::Debug for FormingEndWrapper< Storage, Context >
{
fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result
{
Expand All @@ -92,12 +92,12 @@ impl< Formed, Context > fmt::Debug for FormingEndWrapper< Formed, Context >
}

#[ cfg( not( feature = "no_std" ) ) ]
impl< Formed, Context > FormingEnd< Formed, Context >
for FormingEndWrapper< Formed, Context >
impl< Storage, Context > FormingEnd< Storage, Context >
for FormingEndWrapper< Storage, Context >
{
fn call( &self, formed : Formed, context : Option< Context > ) -> Context
fn call( &self, storage : Storage, context : Option< Context > ) -> Context
{
( self.closure )( formed, context )
( self.closure )( storage, context )
}
}

Expand All @@ -124,13 +124,13 @@ for FormingEndWrapper< Formed, Context >
#[ derive( Debug, Default ) ]
pub struct ReturnFormed;

impl< Formed > FormingEnd< Formed, Formed >
impl< Storage > FormingEnd< Storage, Storage >
for ReturnFormed
{
#[ inline( always ) ]
fn call( &self, formed : Formed, _context : core::option::Option< Formed > ) -> Formed
fn call( &self, storage : Storage, _context : core::option::Option< Storage > ) -> Storage
{
formed
storage
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ where
pub fn descriptor3< Former2 >( self ) ->
Former2
where
Former2 : former::FormerBegin< TemplateParameterDescriptorFormerStorage, 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

0 comments on commit becb7ed

Please sign in to comment.