Skip to content

Commit

Permalink
former : experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 24, 2024
1 parent 773867b commit c559c9d
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 96 deletions.
52 changes: 37 additions & 15 deletions module/core/former/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl< E > VectorLike< E > for Vec< E >
}
}

//
// = storage

impl< E > Storage
for Vec< E >
Expand All @@ -42,18 +42,17 @@ for Vec< E >
}
}

//
// = definition

#[ derive( Debug ) ]
// pub struct VectorDefinition1< E, Context = (), End = ReturnStorage >
pub struct VectorDefinition1< E, Context >
pub struct VectorDefinitionTypes< E, Context = () >
where
Self : FormerDefinition,
{
_phantom : core::marker::PhantomData< ( E, Context ) >,
}

impl< E, Context > VectorDefinition1< E, Context >
impl< E, Context > VectorDefinitionTypes< E, Context >
{
pub fn new() -> Self
{
Expand All @@ -62,25 +61,25 @@ impl< E, Context > VectorDefinition1< E, Context >
}

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

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

impl< E, Context, End > VectorDefinition2< E, Context, End >
impl< E, Context, End > VectorDefinition< E, Context, End >
where
End : FormingEnd< VectorDefinition1< E, Context > >,
End : FormingEnd< VectorDefinitionTypes< E, Context > >,
{
pub fn new() -> Self
{
Expand All @@ -89,17 +88,40 @@ where
}

impl< E, Context, End > FormerDefinition2
for VectorDefinition2< E, Context, End >
for VectorDefinition< E, Context, End >
where
End : FormingEnd< VectorDefinition1< E, Context > >,
End : FormingEnd< VectorDefinitionTypes< E, Context > >,
{
type Definition = VectorDefinition1< E, Context >;
type Definition = VectorDefinitionTypes< E, Context >;
type End = End;
}

// = subformer

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

// = extension

pub trait VecExt< E > : sealed::Sealed
{
fn former() -> VectorSubformer< E, (), ReturnStorage >;
}

impl< E > VecExt< E > for Vec< E >
{
fn former() -> VectorSubformer< E, (), ReturnStorage >
{
VectorSubformer::< E, (), ReturnStorage >::new()
}
}

mod sealed
{
pub trait Sealed {}
impl< E > Sealed for Vec< E > {}
}
185 changes: 104 additions & 81 deletions module/core/former/tests/inc/former_tests/container_former_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,108 +4,131 @@ use super::*;
#[ allow( unused_imports ) ]
use collection_tools::Vec;

// impl< Definition, T > FormingEnd< Definition >
// for ReturnStorage
// where
// Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = Self >,

pub fn f1< Definition >( x : Definition )
where
Definition : former::FormerDefinition,
#[ test ]
fn definitions()
{
}

pub fn f2< Definition >( x : Definition )
where
Definition : former::FormerDefinition2,
{
}

pub fn f3< Definition, End >( x : End )
where
Definition : former::FormerDefinition,
End : former::FormingEnd< Definition >,
{
}
pub fn f1< Definition >( _x : Definition )
where
Definition : former::FormerDefinition,
{
}

pub fn f2< Definition >( _x : Definition )
where
Definition : former::FormerDefinition2,
{
}

pub fn f3< Definition, End >( _x : End )
where
Definition : former::FormerDefinition,
End : former::FormingEnd< Definition >,
{
}

// impl former::FormingEnd<former::VectorDefinition<String, (), former::ReturnStorage>> for former::ReturnStorage {
// fn call(&self, storage: former::VectorDefinition<String, (), former::ReturnStorage>::Storage, context: Option<former::VectorDefinition<String, (), former::ReturnStorage>::Context>) -> former::VectorDefinition<String, (), former::ReturnStorage>::Formed {
// storage
// }
// }
f1( former::VectorDefinitionTypes::< String, () >::new() );
f2( former::VectorDefinition::< String, (), the_module::ReturnStorage >::new() );
f3::< former::VectorDefinitionTypes< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage );
f3::< < former::VectorDefinition< String, (), the_module::ReturnStorage > as the_module::FormerDefinition2 >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage );

}

#[ test ]
fn push()
{

f1( former::VectorDefinition1::< String, () >::new() );
f2( former::VectorDefinition2::< String, (), the_module::ReturnStorage >::new() );
f3::< former::VectorDefinition1< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage );
// f3::< former::VectorDefinition2< String, (), _ >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage );
//

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::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
// ::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 );

// Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = Self >,
let got : Vec< String > = the_module::VectorSubformer::< 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::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::VectorSubformer::new()
.push( "a" )
.push( "b" )
.form();
let exp = vec!
[
"a".to_string(),
"b".to_string(),
];
a_id!( got, exp );

//

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

//

}

#[ test ]
fn replace()
{

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

}

0 comments on commit c559c9d

Please sign in to comment.