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 c5f9ccc commit 0070076
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
39 changes: 19 additions & 20 deletions module/core/former/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,54 +45,53 @@ for Vec< E >
// = definition

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

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

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

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

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

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

Expand All @@ -103,20 +102,20 @@ where
/// `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, VectorDefinition< E, Context, End > >;
pub type VectorSubformer< E, Context, Formed, End > = ContainerSubformer::< E, VectorDefinition< E, Context, Formed, End > >;

// = extension

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

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

Expand Down
43 changes: 23 additions & 20 deletions module/core/former/tests/inc/former_tests/container_former_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ fn definitions()
}

f1( former::VectorDefinitionTypes::< String, () >::new() );
f2( former::VectorDefinition::< String, (), the_module::ReturnStorage >::new() );
f2( former::VectorDefinition::< String, (), Vec< 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 );
f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > as the_module::FormerDefinition2 >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage );

}

Expand All @@ -45,7 +45,7 @@ fn push()

let got : Vec< String > = the_module
::ContainerSubformer
::< String, former::VectorDefinition< String, (), the_module::ReturnStorage > >
::< String, former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > >
::new()
.push( "a" )
.push( "b" )
Expand All @@ -62,7 +62,7 @@ fn push()
let got : Vec< String > = the_module::ContainerSubformer::
<
String,
former::VectorDefinition< String, (), the_module::ReturnStorage >,
former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage >,
>::new()
.push( "a" )
.push( "b" )
Expand All @@ -76,7 +76,7 @@ fn push()

//

let got : Vec< String > = the_module::VectorSubformer::< String, (), the_module::ReturnStorage >::new()
let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage >::new()
.push( "a" )
.push( "b" )
.form();
Expand Down Expand Up @@ -144,27 +144,30 @@ fn custom_end()
{

// xxx2 : continue
// struct Return13;
// impl former::FormerDefinition for Return13
// {
// type Storage = Vec< u32 >;
// type Formed = i32;
// type Context = ();
// }

// fn return_13( _storage : Vec< i32 >, _context : Option< () > ) -> i32
// {
// 13
// }
// let end_wrapper = the_module::FormingEndWrapper::new( return_13 );

// let got : i32 = the_module::VectorSubformer::< String, (), return_13 >::new()
struct Return13;
impl former::FormerDefinition for Return13
{
type Storage = Vec< String >;
type Formed = i32;
type Context = ();
}

fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32
{
13
}

let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 );

// let got : i32 = the_module::VectorSubformer::< String, (), _ >::begin( None, (), return_13 )
// .push( "a" )
// .push( "b" )
// .form();
// let exp = 13;
// a_id!( got, exp );

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

}

//

0 comments on commit 0070076

Please sign in to comment.