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 1561c88 commit 750074e
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 63 deletions.
2 changes: 1 addition & 1 deletion module/core/former/src/axiomatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub trait FormerDefinition
// type Storage : Storage< Definition = Self >;
type Storage : Storage< Formed = Self::Formed >;
type Formed;
// type Context;
type Context;
}

// pub trait FormerDefinition
Expand Down
47 changes: 25 additions & 22 deletions module/core/former/src/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,52 +47,55 @@ where

//

#[ derive( Debug ) ]
pub struct HashMapDefinition< K, E >
impl< K, E > Storage
for HashMap< K, E >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
{
_phantom : ::core::marker::PhantomData< ( K, E ) >,
// type Definition = HashMapDefinition< K, E >;
type Formed = HashMap< K, E >;
}

impl< K, E > HashMapDefinition< K, E >
impl< K, E > StoragePerform
for HashMap< K, E >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
{
pub fn new() -> Self
// fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed
fn preform( self ) -> Self::Formed
{
Self { _phantom : ::core::marker::PhantomData }
self
}
}

impl< K, E > FormerDefinition
for HashMapDefinition< K, E >
//

#[ derive( Debug ) ]
pub struct HashMapDefinition< K, E, Context = () >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
{
type Storage = HashMap< K, E >;
type Formed = HashMap< K, E >;
_phantom : ::core::marker::PhantomData< ( K, E, Context ) >,
}

impl< K, E > Storage
for HashMap< K, E >
impl< K, E, Context > HashMapDefinition< K, E, Context >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
{
// type Definition = HashMapDefinition< K, E >;
type Formed = HashMap< K, E >;
pub fn new() -> Self
{
Self { _phantom : ::core::marker::PhantomData }
}
}

impl< K, E > StoragePerform
for HashMap< K, E >
impl< K, E, Context > FormerDefinition
for HashMapDefinition< K, E, Context >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
{
// fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed
fn preform( self ) -> Self::Formed
{
self
}
type Storage = HashMap< K, E >;
type Formed = HashMap< K, E >;
type Context = Context;
}

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

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

// #[ derive( Debug, Default ) ]
// pub struct HashMapSubformer< K, E, Definition, Context, End >
Expand Down
39 changes: 21 additions & 18 deletions module/core/former/src/hash_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,52 +35,55 @@ where

//

#[ derive( Debug ) ]
pub struct HashSetDefinition< K >
impl< K > Storage
for HashSet< K >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
{
_phantom : ::core::marker::PhantomData< ( K, K ) >,
// type Definition = HashSetDefinition< K >;
type Formed = HashSet< K >;
}

impl< K > HashSetDefinition< K >
impl< K > StoragePerform
for HashSet< K >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
{
pub fn new() -> Self
// fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed
fn preform( self ) -> Self::Formed
{
Self { _phantom : ::core::marker::PhantomData }
self
}
}

impl< K > Storage
for HashSet< K >
//

#[ derive( Debug ) ]
pub struct HashSetDefinition< K, Context = () >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
{
// type Definition = HashSetDefinition< K >;
type Formed = HashSet< K >;
_phantom : ::core::marker::PhantomData< ( K, Context ) >,
}

impl< K > StoragePerform
for HashSet< K >
impl< K, Context > HashSetDefinition< K, Context >
where
K : ::core::cmp::Eq + ::core::hash::Hash,
{
// fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed
fn preform( self ) -> Self::Formed
pub fn new() -> Self
{
self
Self { _phantom : ::core::marker::PhantomData }
}
}

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

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

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

// #[ derive( Debug, Default ) ]
// pub struct HashSetSubformer< K, Definition, Context, End >
Expand Down
47 changes: 26 additions & 21 deletions module/core/former/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,7 @@ impl< E > VectorLike< E > for Vec< E >
}
}

#[ derive( Debug ) ]
pub struct VectorDefinition< E >
{
_phantom : core::marker::PhantomData< E >,
}

impl< E > VectorDefinition< E >
{
pub fn new() -> Self
{
Self { _phantom : core::marker::PhantomData }
}
}

impl< E > FormerDefinition
for VectorDefinition< E >
{
type Storage = Vec< E >;
type Formed = Vec< E >;
}
//

impl< E > Storage
for Vec< E >
Expand All @@ -61,12 +42,36 @@ for Vec< E >
}
}

//

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

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

impl< E, Context > FormerDefinition
for VectorDefinition< E, Context >
{
type Storage = Vec< E >;
type Formed = Vec< E >;
type Context = Context;
}

/// 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 > = ContainerSubformer::< E, VectorDefinition< E > >;
pub type VectorSubformer< E, Context = () > = ContainerSubformer::< E, VectorDefinition< E, Context > >;

// #[ derive( Debug, Default ) ]
// pub struct VectorSubformer< E, Definition, Context, End >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ 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" )
Expand All @@ -21,7 +34,7 @@ fn push()

//

let got : Vec< String > = the_module::VectorSubformer::new()
let got : Vec< String > = the_module::VectorSubformer::< String, () >::new()
.push( "a" )
.push( "b" )
.form();
Expand Down

0 comments on commit 750074e

Please sign in to comment.