Skip to content

Commit

Permalink
experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 26, 2024
1 parent 4003634 commit 2fb1bfd
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 20 deletions.
40 changes: 33 additions & 7 deletions module/core/former/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,39 @@ where

}

impl< E, T, Types, Definition > ContainerSubformer< E, Definition >
// impl< E, T, Types, Definition > ContainerSubformer< E, Definition >
// where
// Types : FormerDefinitionTypes< Context = (), Storage = T, Formed = T >,
// Definition : FormerDefinition< Types = Types, End = ReturnStorage >,
// < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >,
// < Definition::Types as FormerDefinitionTypes >::Storage : StoragePerform< Formed = < Definition::Types as FormerDefinitionTypes >::Formed >,
// {
//
// // xxx : update description
// /// Initializes a new `ContainerSubformer` instance, starting with an empty formed.
// /// This function serves as the entry point for the builder pattern.
// ///
// /// # Returns
// /// A new instance of `ContainerSubformer` with an empty internal formed.
// ///
// #[ inline( always ) ]
// pub fn new_returning_storage() -> Self
// {
// Self::begin
// (
// None,
// None,
// ReturnStorage,
// )
// }
//
// }

impl< E, Storage, Formed, Types, Definition > ContainerSubformer< E, Definition >
where
Types : FormerDefinitionTypes< Context = (), Storage = T, Formed = T >,
Definition : FormerDefinition< Types = Types, End = ReturnStorage >,
Types : FormerDefinitionTypes< Context = (), Storage = Storage, Formed = Formed >,
Definition : FormerDefinition< Types = Types >,
< Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >,
< Definition::Types as FormerDefinitionTypes >::Storage : StoragePerform< Formed = < Definition::Types as FormerDefinitionTypes >::Formed >,
{

/// Initializes a new `ContainerSubformer` instance, starting with an empty formed.
Expand All @@ -288,14 +315,13 @@ where
/// A new instance of `ContainerSubformer` with an empty internal formed.
///
#[ inline( always ) ]
pub fn new() -> Self
pub fn new( end : Definition::End ) -> Self
{
Self::begin
(
None,
None,
ReturnStorage,
// ReturnFormed,
end,
)
}

Expand Down
2 changes: 1 addition & 1 deletion module/core/former/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl< E > VecExt< E > for Vec< E >
{
fn former() -> VectorSubformer< E, (), Vec< E >, ReturnStorage >
{
VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new()
VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new( Default::default() )
}
}

Expand Down
61 changes: 49 additions & 12 deletions module/core/former/tests/inc/former_tests/container_former_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn push()
let got : Vec< String > = the_module
::ContainerSubformer
::< String, former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > >
::new()
::new( former::ReturnStorage )
.push( "a" )
.push( "b" )
.form();
Expand All @@ -63,7 +63,7 @@ fn push()
<
String,
former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage >,
>::new()
>::new( former::ReturnStorage )
.push( "a" )
.push( "b" )
.form();
Expand All @@ -76,7 +76,7 @@ fn push()

//

let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage >::new()
let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage >::new( former::ReturnStorage )
.push( "a" )
.push( "b" )
.form();
Expand All @@ -89,7 +89,7 @@ fn push()

//

let got : Vec< String > = the_module::VectorSubformer::new()
let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage )
.push( "a" )
.push( "b" )
.form();
Expand Down Expand Up @@ -124,7 +124,7 @@ fn push()
fn replace()
{

let got : Vec< String > = the_module::VectorSubformer::new()
let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage )
.push( "x" )
.replace( vec![ "a".to_string(), "b".to_string() ] )
.form();
Expand All @@ -147,7 +147,7 @@ fn begin_and_custom_end()

// basic case

fn return_13( _storage : Vec< String >, context : Option< () > ) -> f32
fn return_13( _storage : Vec< String >, _context : Option< () > ) -> f32
{
13.1
}
Expand All @@ -158,6 +158,13 @@ fn begin_and_custom_end()
let exp = 13.1;
a_id!( got, exp );

let got = the_module::VectorSubformer::new( return_13 )
.push( "a" )
.push( "b" )
.form();
let exp = 13.1;
a_id!( got, exp );

// with a context

fn context_plus_13( _storage : Vec< String >, context : Option< f32 > ) -> f32
Expand Down Expand Up @@ -212,8 +219,8 @@ fn custom_definition()
fn call
(
&self,
storage : < Return13 as the_module::FormerDefinitionTypes >::Storage,
context : Option< < Return13 as the_module::FormerDefinitionTypes >::Context >
_storage : < Return13 as the_module::FormerDefinitionTypes >::Storage,
_context : Option< < Return13 as the_module::FormerDefinitionTypes >::Context >
) -> < Return13 as the_module::FormerDefinitionTypes >::Formed
{
13
Expand All @@ -231,6 +238,13 @@ fn custom_definition()
let exp = 13;
a_id!( got, exp );

let got = the_module::ContainerSubformer::< String, Return13 >::new( Return13 )
.push( "a" )
.push( "b" )
.form();
let exp = 13;
a_id!( got, exp );

//

}
Expand Down Expand Up @@ -275,16 +289,14 @@ fn custom_definition_parametrized()
fn call
(
&self,
storage : < Return13< E > as the_module::FormerDefinitionTypes >::Storage,
context : Option< < Return13< E > as the_module::FormerDefinitionTypes >::Context >
_storage : < Return13< E > as the_module::FormerDefinitionTypes >::Storage,
_context : Option< < Return13< E > as the_module::FormerDefinitionTypes >::Context >
) -> < Return13< E > as the_module::FormerDefinitionTypes >::Formed
{
13
}
}

// type MyContainer< Type >

//

let got = the_module::ContainerSubformer::< String, Return13< String > >::begin( None, None, Return13::new() )
Expand All @@ -294,6 +306,31 @@ fn custom_definition_parametrized()
let exp = 13;
a_id!( got, exp );

let got = the_module::ContainerSubformer::< String, Return13< String > >::new( Return13::new() )
.push( "a" )
.push( "b" )
.form();
let exp = 13;
a_id!( got, exp );

//

type MyContainer< E > = the_module::ContainerSubformer::< E, Return13< E > >;

let got = MyContainer::< String >::begin( None, None, Return13::new() )
.push( "a" )
.push( "b" )
.form();
let exp = 13;
a_id!( got, exp );

let got = MyContainer::< String >::new( Return13::new() )
.push( "a" )
.push( "b" )
.form();
let exp = 13;
a_id!( got, exp );

//

// xxx : make it working?
Expand Down

0 comments on commit 2fb1bfd

Please sign in to comment.