Skip to content

Commit

Permalink
former : experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 23, 2024
1 parent 8432e7e commit aa64c2d
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 73 deletions.
20 changes: 18 additions & 2 deletions module/core/former/src/axiomatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ pub trait StoragePerform : Storage
}

/// xxx
pub trait FormerDefinition
pub trait FormerDefinition : Sized
{
// type Storage : Storage< Definition = Self >;
type Storage : Storage< Formed = Self::Formed >;
type Formed;
type Context;
type End : FormingEnd< Self >;
}

// pub trait FormerDefinition
Expand Down Expand Up @@ -74,7 +75,6 @@ pub struct ReturnFormed;
impl< Definition > FormingEnd< Definition >
for ReturnFormed
where
// Definition::Storage : StoragePerform< Definition = Definition >,
Definition::Storage : StoragePerform< Formed = Definition::Formed >,
Definition : FormerDefinition< Context = () >,
{
Expand All @@ -85,6 +85,22 @@ where
}
}

/// xxx
#[ derive( Debug, Default ) ]
pub struct ReturnStorage;

impl< Definition, T > FormingEnd< Definition >
for ReturnStorage
where
Definition : FormerDefinition< Context = (), Storage = T, Formed = T >,
{
#[ inline( always ) ]
fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed
{
storage
}
}

/// A wrapper around a closure to be used as a `FormingEnd`.
///
/// This struct allows for dynamic dispatch of a closure that matches the
Expand Down
33 changes: 17 additions & 16 deletions module/core/former/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,20 @@ where

/// A builder for constructing containers, facilitating a fluent and flexible interface.
#[ derive( Debug, Default ) ]
pub struct ContainerSubformer< E, Definition, End = ReturnFormed >
pub struct ContainerSubformer< E, Definition >
where
End : FormingEnd< Definition >,
// End : FormingEnd< Definition >,
Definition : FormerDefinition,
Definition::Storage : ContainerAdd< Element = E >,
{
storage : core::option::Option< Definition::Storage >,
context : core::option::Option< Definition::Context >,
on_end : core::option::Option< End >,
on_end : core::option::Option< Definition::End >,
}

impl< E, Definition, End > ContainerSubformer< E, Definition, End >
impl< E, Definition > ContainerSubformer< E, Definition >
where
End : FormingEnd< Definition >,
// End : FormingEnd< Definition >,
Definition : FormerDefinition,
Definition::Storage : ContainerAdd< Element = E >,
{
Expand All @@ -235,7 +235,7 @@ where
(
storage : core::option::Option< Definition::Storage >,
context : core::option::Option< Definition::Context >,
on_end : End
on_end : Definition::End,
) -> Self
{
Self
Expand Down Expand Up @@ -273,9 +273,9 @@ where

}

impl< E, Definition > ContainerSubformer< E, Definition, ReturnFormed >
impl< E, T, Definition > ContainerSubformer< E, Definition >
where
Definition : FormerDefinition< Context = () >,
Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = ReturnStorage >,
Definition::Storage : ContainerAdd< Element = E >,
Definition::Storage : StoragePerform< Formed = Definition::Formed >,
{
Expand All @@ -293,15 +293,16 @@ where
(
None,
None,
ReturnFormed,
ReturnStorage,
// ReturnFormed,
)
}

}

impl< E, Definition, End > ContainerSubformer< E, Definition, End >
impl< E, Definition > ContainerSubformer< E, Definition >
where
End : FormingEnd< Definition >,
// End : FormingEnd< Definition >,
Definition : FormerDefinition,
Definition::Storage : ContainerAdd< Element = E >,
{
Expand All @@ -327,21 +328,21 @@ where

//

impl< E, Definition, End > FormerBegin< Definition >
for ContainerSubformer< E, Definition, End >
impl< E, Definition > FormerBegin< Definition >
for ContainerSubformer< E, Definition >
where
End : FormingEnd< Definition >,
// End : FormingEnd< Definition >,
Definition : FormerDefinition,
Definition::Storage : ContainerAdd< Element = E >,
{
type End = End;
type End = Definition::End;

#[ inline( always ) ]
fn _begin
(
storage : core::option::Option< Definition::Storage >,
context : core::option::Option< Definition::Context >,
on_end : End,
on_end : Definition::End,
)
-> Self
{
Expand Down
20 changes: 12 additions & 8 deletions module/core/former/src/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where

}

//
// = storage

impl< K, E > Storage
for HashMap< K, E >
Expand All @@ -68,34 +68,38 @@ where
}
}

//
// = definition

#[ derive( Debug ) ]
pub struct HashMapDefinition< K, E, Context = () >
pub struct HashMapDefinition< K, E, Context, End >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
End : FormingEnd< Self >,
{
_phantom : ::core::marker::PhantomData< ( K, E, Context ) >,
_phantom : ::core::marker::PhantomData< ( K, E, Context, End ) >,
}

impl< K, E, Context > HashMapDefinition< K, E, Context >
impl< K, E, Context, End > HashMapDefinition< K, E, Context, End >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
End : FormingEnd< Self >,
{
pub fn new() -> Self
{
Self { _phantom : ::core::marker::PhantomData }
}
}

impl< K, E, Context > FormerDefinition
for HashMapDefinition< K, E, Context >
impl< K, E, Context, End > FormerDefinition
for HashMapDefinition< K, E, Context, End >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
End : FormingEnd< Self >,
{
type Storage = HashMap< K, E >;
type Formed = HashMap< K, E >;
type Context = Context;
type End = End;
}

/// A builder for constructing hash map-like structures with a fluent interface.
Expand Down Expand Up @@ -136,7 +140,7 @@ where
/// # }
/// ```

pub type HashMapSubformer< K, E, Context = () > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context > >;
pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, End > >;

// #[ derive( Debug, Default ) ]
// pub struct HashMapSubformer< K, E, Definition, Context, End >
Expand Down
20 changes: 12 additions & 8 deletions module/core/former/src/hash_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ where
}
}

//
// = storage

impl< K > Storage
for HashSet< K >
Expand All @@ -56,34 +56,38 @@ where
}
}

//
// = definition

#[ derive( Debug ) ]
pub struct HashSetDefinition< K, Context = () >
pub struct HashSetDefinition< K, Context, End >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
End : FormingEnd< Self >,
{
_phantom : ::core::marker::PhantomData< ( K, Context ) >,
_phantom : ::core::marker::PhantomData< ( K, Context, End ) >,
}

impl< K, Context > HashSetDefinition< K, Context >
impl< K, Context, End > HashSetDefinition< K, Context, End >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
End : FormingEnd< Self >,
{
pub fn new() -> Self
{
Self { _phantom : ::core::marker::PhantomData }
}
}

impl< K, Context > FormerDefinition
for HashSetDefinition< K, Context >
impl< K, Context, End > FormerDefinition
for HashSetDefinition< K, Context, End >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
End : FormingEnd< Self >,
{
type Storage = HashSet< K >;
type Formed = HashSet< K >;
type Context = Context;
type End = End;
}

/// Facilitates building `HashSetLike` containers with a fluent API.
Expand Down Expand Up @@ -118,7 +122,7 @@ where
/// # }
/// ```

pub type HashSetSubformer< K, Context = () > = ContainerSubformer::< K, HashSetDefinition< K, Context > >;
pub type HashSetSubformer< K, Context, End > = ContainerSubformer::< K, HashSetDefinition< K, Context, End > >;

// #[ derive( Debug, Default ) ]
// pub struct HashSetSubformer< K, Definition, Context, End >
Expand Down
19 changes: 13 additions & 6 deletions module/core/former/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,40 @@ for Vec< E >
//

#[ derive( Debug ) ]
pub struct VectorDefinition< E, Context = () >
pub struct VectorDefinition< E, Context, End >
where
End : FormingEnd< Self >
{
_phantom : core::marker::PhantomData< ( E, Context ) >,
_phantom : core::marker::PhantomData< ( E, Context, End ) >,
}

impl< E, Context > VectorDefinition< E, Context >
impl< E, Context, End > VectorDefinition< E, Context, End >
where
End : FormingEnd< Self >
{
pub fn new() -> Self
{
Self { _phantom : core::marker::PhantomData }
}
}

impl< E, Context > FormerDefinition
for VectorDefinition< E, Context >
impl< E, Context, End > FormerDefinition
for VectorDefinition< E, Context, End >
where
End : FormingEnd< Self >
{
type Storage = Vec< E >;
type Formed = Vec< E >;
type Context = Context;
type End = End;
}

/// A builder for constructing `VectorLike` containers, facilitating a fluent and flexible interface.
///
/// `VectorSubformer` leverages the `VectorLike` trait to enable the construction and manipulation
/// of vector-like containers in a builder pattern style, promoting readability and ease of use.

pub type VectorSubformer< E, Context = () > = ContainerSubformer::< E, VectorDefinition< E, Context > >;
pub type VectorSubformer< E, Context, End > = ContainerSubformer::< E, VectorDefinition< E, Context, End > >;

// #[ derive( Debug, Default ) ]
// pub struct VectorSubformer< E, Definition, Context, End >
Expand Down
70 changes: 37 additions & 33 deletions module/core/former/tests/inc/former_tests/container_former_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,46 @@ use collection_tools::Vec;
fn push()
{

let got : Vec< String > = the_module::ContainerSubformer::< String, former::VectorDefinition< String, () > >::new()
.push( "a" )
.push( "b" )
.form();
let exp = vec!
[
"a".to_string(),
"b".to_string(),
];
a_id!( got, exp );

//

let got : Vec< String > = the_module::ContainerSubformer::< String, former::VectorDefinition< String > >::new()
.push( "a" )
.push( "b" )
.form();
let exp = vec!
[
"a".to_string(),
"b".to_string(),
];
a_id!( got, exp );
// let got : Vec< String > = the_module::ContainerSubformer::
// <
// String,
// former::VectorDefinition< String, (), the_module::ReturnStorage >,
// >::new()
// .push( "a" )
// .push( "b" )
// .form();
// let exp = vec!
// [
// "a".to_string(),
// "b".to_string(),
// ];
// a_id!( got, exp );

//

let got : Vec< String > = the_module::VectorSubformer::< String, () >::new()
.push( "a" )
.push( "b" )
.form();
let exp = vec!
[
"a".to_string(),
"b".to_string(),
];
a_id!( got, exp );
// let got : Vec< String > = the_module::ContainerSubformer::< String, former::VectorDefinition< String > >::new()
// .push( "a" )
// .push( "b" )
// .form();
// let exp = vec!
// [
// "a".to_string(),
// "b".to_string(),
// ];
// a_id!( got, exp );
//
// //
//
// let got : Vec< String > = the_module::VectorSubformer::< String, () >::new()
// .push( "a" )
// .push( "b" )
// .form();
// let exp = vec!
// [
// "a".to_string(),
// "b".to_string(),
// ];
// a_id!( got, exp );

}

Expand Down

0 comments on commit aa64c2d

Please sign in to comment.