Skip to content

Commit

Permalink
former : minor renames
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 20, 2024
1 parent e9fbac6 commit f5228eb
Show file tree
Hide file tree
Showing 21 changed files with 102 additions and 94 deletions.
8 changes: 4 additions & 4 deletions module/core/former/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct UserProfileFormer
FormerEnd = former::ReturnFormed,
>
where
FormerEnd : former::ToSuperFormer< UserProfile, FormerContext >,
FormerEnd : former::FormingEnd< UserProfile, FormerContext >,
{
storage : UserProfileFormerStorage,
context : Option< FormerContext >,
Expand All @@ -114,7 +114,7 @@ where

impl< FormerContext, FormerEnd > UserProfileFormer< FormerContext, FormerEnd >
where
FormerEnd : former::ToSuperFormer< UserProfile, FormerContext >,
FormerEnd : former::FormingEnd< UserProfile, FormerContext >,
{
#[ inline( always ) ]
pub fn form( mut self ) -> UserProfile
Expand Down Expand Up @@ -544,9 +544,9 @@ fn main()
// Use CommandFormer as custom subformer for AggregatorFormer to add commands by name.
impl< Context, End > AggregatorFormer< Context, End >
where
End : former::ToSuperFormer< Aggregator, Context >,
End : former::FormingEnd< Aggregator, Context >,
{
pub fn command< IntoName >( self, name : IntoName ) -> CommandFormer< Self, impl former::ToSuperFormer< Command, Self > >
pub fn command< IntoName >( self, name : IntoName ) -> CommandFormer< Self, impl former::FormingEnd< Command, Self > >
where
IntoName: core::convert::Into< String >,
{
Expand Down
4 changes: 2 additions & 2 deletions module/core/former/examples/former_custom_subformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ fn main()
// Use CommandFormer as custom subformer for AggregatorFormer to add commands by name.
impl< Context, End > AggregatorFormer< Context, End >
where
End : former::ToSuperFormer< Aggregator, Context >,
End : former::FormingEnd< Aggregator, Context >,
{
#[ inline( always ) ]
pub fn command< IntoName >( self, name : IntoName ) -> CommandFormer< Self, impl former::ToSuperFormer< Command, Self > >
pub fn command< IntoName >( self, name : IntoName ) -> CommandFormer< Self, impl former::FormingEnd< Command, Self > >
where
IntoName : core::convert::Into< String >,
{
Expand Down
4 changes: 2 additions & 2 deletions module/core/former/examples/former_trivial_expaned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn main()
FormerEnd = former::ReturnFormed,
>
where
FormerEnd : former::ToSuperFormer< UserProfile, FormerContext >,
FormerEnd : former::FormingEnd< UserProfile, FormerContext >,
{
storage : UserProfileFormerStorage,
context : Option< FormerContext >,
Expand All @@ -67,7 +67,7 @@ fn main()

impl< FormerContext, FormerEnd > UserProfileFormer< FormerContext, FormerEnd >
where
FormerEnd : former::ToSuperFormer< UserProfile, FormerContext >,
FormerEnd : former::FormingEnd< UserProfile, FormerContext >,
{
#[ inline( always ) ]
pub fn form( mut self ) -> UserProfile
Expand Down
42 changes: 21 additions & 21 deletions module/core/former/src/axiomatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// # Parameters
/// - `Formed`: The type of the container being processed.
/// - `Context`: The type of the context that might be altered or returned upon completion.
pub trait ToSuperFormer< Formed, Context >
pub trait FormingEnd< Formed, Context >
{
/// Called at the end of the subforming process to return the modified or original context.
///
Expand All @@ -22,7 +22,7 @@ pub trait ToSuperFormer< Formed, Context >
fn call( &self, storage : Formed, context : core::option::Option< Context > ) -> Context;
}

impl< Formed, Context, F > ToSuperFormer< Formed, Context > for F
impl< Formed, Context, F > FormingEnd< Formed, Context > for F
where
F : Fn( Formed, core::option::Option< Context > ) -> Context,
{
Expand All @@ -33,12 +33,12 @@ where
}
}

/// A wrapper around a closure to be used as a `ToSuperFormer`.
/// A wrapper around a closure to be used as a `FormingEnd`.
///
/// This struct allows for dynamic dispatch of a closure that matches the
/// `ToSuperFormer` trait's `call` method signature. It is useful for cases where
/// `FormingEnd` trait's `call` method signature. It is useful for cases where
/// a closure needs to be stored or passed around as an object implementing
/// `ToSuperFormer`.
/// `FormingEnd`.
///
/// # Type Parameters
///
Expand All @@ -47,26 +47,26 @@ where
/// * `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 ToSuperFormerWrapper< Formed, Context >
pub struct FormingEndWrapper< Formed, Context >
{
closure : Box< dyn Fn( Formed, Option< Context > ) -> Context >,
_marker : std::marker::PhantomData< Formed >,
}

#[ cfg( not( feature = "no_std" ) ) ]
impl< Formed, Context > ToSuperFormerWrapper< Formed, Context >
impl< Formed, Context > FormingEndWrapper< Formed, Context >
{
/// Constructs a new `ToSuperFormerWrapper` with the provided closure.
/// Constructs a new `FormingEndWrapper` with the provided closure.
///
/// # Parameters
///
/// * `closure` - A closure that matches the expected signature for transforming a container
/// and context into a new context. This closure is stored and called by the
/// `call` method of the `ToSuperFormer` trait implementation.
/// `call` method of the `FormingEnd` trait implementation.
///
/// # Returns
///
/// Returns an instance of `ToSuperFormerWrapper` encapsulating the provided closure.
/// Returns an instance of `FormingEndWrapper` encapsulating the provided closure.
pub fn new( closure : impl Fn( Formed, Option< Context > ) -> Context + 'static ) -> Self
{
Self
Expand All @@ -80,34 +80,34 @@ impl< Formed, Context > ToSuperFormerWrapper< Formed, Context >
#[ cfg( not( feature = "no_std" ) ) ]
use std::fmt;
#[ cfg( not( feature = "no_std" ) ) ]
impl< Formed, Context > fmt::Debug for ToSuperFormerWrapper< Formed, Context >
impl< Formed, Context > fmt::Debug for FormingEndWrapper< Formed, Context >
{
fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result
{
f.debug_struct( "ToSuperFormerWrapper" )
f.debug_struct( "FormingEndWrapper" )
.field( "closure", &format_args!{ "- closure -" } )
.field( "_marker", &self._marker )
.finish()
}
}

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

/// A `ToSuperFormer` implementation that returns the original context without any modifications.
/// 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 > ToSuperFormer< Formed, Context >
impl< Formed, Context > FormingEnd< Formed, Context >
for NoEnd
{
#[ inline( always ) ]
Expand All @@ -117,14 +117,14 @@ for NoEnd
}
}

/// A `ToSuperFormer` implementation that returns the formed container itself instead of the context.
/// A `FormingEnd` implementation that returns the formed container itself instead of the context.
///
/// This struct is useful when the forming process should result in the formed container being returned directly,
/// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result.
#[ derive( Debug, Default ) ]
pub struct ReturnFormed;

impl< Formed > ToSuperFormer< Formed, Formed >
impl< Formed > FormingEnd< Formed, Formed >
for ReturnFormed
{
#[ inline( always ) ]
Expand Down Expand Up @@ -153,7 +153,7 @@ for ReturnFormed
/// # Associated Types
///
/// * `End` - Specifies the trait bound for the closure or handler that gets called at the completion
/// of the subforming process. This type must implement the `ToSuperFormer<Formed, Context>`
/// of the subforming process. This type must implement the `FormingEnd<Formed, Context>`
/// trait, which defines how the final transformation or construction of `Formed` is handled,
/// potentially using the provided `Context`.
///
Expand All @@ -162,10 +162,10 @@ pub trait FormerBegin< Formed, Context >
{

/// * `End` - Specifies the trait bound for the closure or handler that gets called at the completion
/// of the subforming process. This type must implement the `ToSuperFormer<Formed, Context>`
/// of the subforming process. This type must implement the `FormingEnd<Formed, Context>`
/// trait, which defines how the final transformation or construction of `Formed` is handled,
/// potentially using the provided `Context`.
type End : ToSuperFormer< Formed, Context >;
type End : FormingEnd< Formed, Context >;

/// Initializes the subforming process by setting the context and specifying an `on_end` completion handler.
///
Expand Down
10 changes: 5 additions & 5 deletions module/core/former/src/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ where
/// Return former.
#[ inline( always ) ]
fn former( self )
-> HashMapSubformer< K, E, Self, Self, impl ToSuperFormer< Self, Self > >
-> HashMapSubformer< K, E, Self, Self, impl FormingEnd< Self, Self > >
{
HashMapSubformer::begin( Some( self ), None, ReturnFormed )
}
Expand All @@ -31,7 +31,7 @@ where
// #[ inline( always ) ]
// fn former_begin< Context, End >( self, context : Context, end : End )
// -> HashMapSubformer< K, E, Self, Context, End >
// where End : ToSuperFormer< Self, Context >
// where End : FormingEnd< Self, Context >
// {
// HashMapSubformer::begin( Some( self ), Some( context ), end )
// }
Expand Down Expand Up @@ -95,7 +95,7 @@ pub struct HashMapSubformer< K, E, Formed, Context, End >
where
K : core::cmp::Eq + core::hash::Hash,
Formed : HashMapLike< K, E > + core::default::Default,
End : ToSuperFormer< Formed, Context >,
End : FormingEnd< Formed, Context >,
{
formed : core::option::Option< Formed >,
context : core::option::Option< Context >,
Expand All @@ -109,7 +109,7 @@ HashMapSubformer< K, E, Formed, Context, End >
where
K : core::cmp::Eq + core::hash::Hash,
Formed : HashMapLike< K, E > + core::default::Default,
End : ToSuperFormer< Formed, Context >,
End : FormingEnd< Formed, Context >,
{

/// Form current former into target structure.
Expand Down Expand Up @@ -198,7 +198,7 @@ HashMapSubformer< K, E, Formed, Context, End >
where
K : core::cmp::Eq + core::hash::Hash,
Formed : HashMapLike< K, E > + core::default::Default,
End : ToSuperFormer< Formed, Context >,
End : FormingEnd< Formed, Context >,
{

/// Inserts a key-value pair into the formed. If the formed doesn't exist, it is created.
Expand Down
8 changes: 4 additions & 4 deletions module/core/former/src/hash_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct HashSetSubformer< E, Formed, Context, ContainerEnd >
where
E : core::cmp::Eq + core::hash::Hash,
Formed : HashSetLike< E > + core::default::Default,
ContainerEnd : ToSuperFormer< Formed, Context >,
ContainerEnd : FormingEnd< Formed, Context >,
{
formed : core::option::Option< Formed >,
context : core::option::Option< Context >,
Expand All @@ -83,7 +83,7 @@ HashSetSubformer< E, Formed, Context, ContainerEnd >
where
E : core::cmp::Eq + core::hash::Hash,
Formed : HashSetLike< E > + core::default::Default,
ContainerEnd : ToSuperFormer< Formed, Context >,
ContainerEnd : FormingEnd< Formed, Context >,
{

/// Form current former into target structure.
Expand Down Expand Up @@ -179,7 +179,7 @@ HashSetSubformer< E, Formed, Formed, crate::ReturnFormed >
where
E : core::cmp::Eq + core::hash::Hash,
Formed : HashSetLike< E > + core::default::Default,
// ContainerEnd : ToSuperFormer< Formed, Context >,
// ContainerEnd : FormingEnd< Formed, Context >,
{

/// Initializes a new instance of the builder with default settings.
Expand Down Expand Up @@ -208,7 +208,7 @@ HashSetSubformer< E, Formed, Context, ContainerEnd >
where
E : core::cmp::Eq + core::hash::Hash,
Formed : HashSetLike< E > + core::default::Default,
ContainerEnd : ToSuperFormer< Formed, Context >,
ContainerEnd : FormingEnd< Formed, Context >,
{

/// Inserts an element into the set, possibly replacing an existing element.
Expand Down
12 changes: 10 additions & 2 deletions module/core/former/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#[ cfg( feature = "enabled" ) ]
#[ cfg( feature = "derive_former" ) ]
mod axiomatic;

/// Interface for containers.
#[ cfg( feature = "enabled" ) ]
#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ]
#[ cfg( feature = "derive_former" ) ]
mod container;
/// Former of a vector.
Expand Down Expand Up @@ -72,21 +74,27 @@ pub mod orphan
#[ cfg( feature = "enabled" ) ]
pub mod exposed
{

#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::prelude::*;

#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use former_meta::*;

#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::prelude::*;
#[ cfg( feature = "enabled" ) ]
#[ cfg( feature = "derive_former" ) ]
pub use super::axiomatic::*;

#[ doc( inline ) ]
#[ allow( unused_imports ) ]
#[ cfg( feature = "enabled" ) ]
#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ]
#[ cfg( feature = "derive_former" ) ]
pub use super::{ axiomatic::*, container::* };
pub use super::container::*;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
#[ cfg( feature = "enabled" ) ]
Expand Down
10 changes: 5 additions & 5 deletions module/core/former/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl< E > VectorLike< E > for Vec< E >
pub struct VectorSubformer< E, Formed, Context, ContainerEnd >
where
Formed : VectorLike< E > + core::default::Default,
ContainerEnd : ToSuperFormer< Formed, Context >,
ContainerEnd : FormingEnd< Formed, Context >,
{
formed : core::option::Option< Formed >,
context : core::option::Option< Context >,
Expand All @@ -61,7 +61,7 @@ where
impl< E, Formed, Context, ContainerEnd > VectorSubformer< E, Formed, Context, ContainerEnd >
where
Formed : VectorLike< E > + core::default::Default,
ContainerEnd : ToSuperFormer< Formed, Context >,
ContainerEnd : FormingEnd< Formed, Context >,
{

/// Form current former into target structure.
Expand All @@ -87,7 +87,7 @@ where
// /// A new instance of `VectorSubformer` with an empty internal formed.
// ///
// #[ inline( always ) ]
// pub fn new() -> VectorSubformer< E, Formed, Formed, impl ToSuperFormer< Formed, Formed > >
// pub fn new() -> VectorSubformer< E, Formed, Formed, impl FormingEnd< Formed, Formed > >
// {
// VectorSubformer::begin
// (
Expand Down Expand Up @@ -162,7 +162,7 @@ where
impl< E, Formed, Context, ContainerEnd > VectorSubformer< E, Formed, Context, ContainerEnd >
where
Formed : VectorLike< E > + core::default::Default,
ContainerEnd : ToSuperFormer< Formed, Context >,
ContainerEnd : FormingEnd< Formed, Context >,
{

/// Appends an element to the end of the formed, expanding the internal collection.
Expand All @@ -188,7 +188,7 @@ where
impl< E, Formed, Context, End > FormerBegin< Formed, Context >
for VectorSubformer< E, Formed, Context, End >
where
End : ToSuperFormer< Formed, Context >,
End : FormingEnd< Formed, Context >,
Formed : VectorLike< E > + Default,
{
type End = End;
Expand Down
Loading

0 comments on commit f5228eb

Please sign in to comment.