Skip to content

Commit

Permalink
former : experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 30, 2024
1 parent d039502 commit 1effc15
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 72 deletions.
50 changes: 25 additions & 25 deletions module/core/former/tests/inc/former_tests/a_primitives_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,30 +201,8 @@ where
return result;
}

#[ inline( always ) ]
pub fn begin_with< IntoEnd >
(
mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >,
context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >,
on_end : IntoEnd,
) -> Self
where
IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >
{
if storage.is_none()
{
storage = Some( core::default::Default::default() );
}
Self
{
storage : storage.unwrap(),
context,
on_end : ::core::option::Option::Some( on_end.into() ),
}
}

// #[ inline( always ) ]
// pub fn begin< IntoEnd >
// pub fn begin_with< IntoEnd >
// (
// mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >,
// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >,
Expand All @@ -246,7 +224,29 @@ where
// }

#[ inline( always ) ]
pub fn begin
pub fn begin< IntoEnd >
(
mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >,
context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >,
on_end : IntoEnd,
) -> Self
where
IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >
{
if storage.is_none()
{
storage = Some( core::default::Default::default() );
}
Self
{
storage : storage.unwrap(),
context,
on_end : ::core::option::Option::Some( on_end.into() ),
}
}

#[ inline( always ) ]
pub fn begin_explicit
(
mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >,
context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >,
Expand Down Expand Up @@ -308,7 +308,7 @@ where
#[ inline( always ) ]
pub fn new( on_end : Definition::End ) -> Self
{
Self::begin( None, None, on_end )
Self::begin_explicit( None, None, on_end )
}

// zzz : update description
Expand Down
128 changes: 81 additions & 47 deletions module/core/former/tests/inc/former_tests/only_test/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,6 @@ tests_impls!

//

fn begin()
{

// begin with none
let got = Struct1Former::< Struct1FormerDefinition >::begin( None, None, the_module::ReturnPreformed ).int_1( 13 ).form();
let exp = Struct1::former().int_1( 13 ).form();
a_id!( got, exp );

// begin with storage
let mut storage = Struct1FormerStorage::default();
storage.int_1 = Some( 13 );
let exp = Struct1Former::< Struct1FormerDefinition >::begin( Some( storage ), None, the_module::ReturnPreformed ).form();
a_id!( got, exp );

// begin with context
let mut storage = Struct1FormerStorage::default();
storage.int_1 = Some( 13 );
let exp = Struct1Former::< Struct1FormerDefinition >
::begin( Some( storage ), Some( () ), the_module::ReturnPreformed )
.form();
a_id!( got, exp );

}

//

fn new()
{

let former = Struct1::former();
let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed );
a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) );

}

//

fn custom_definition_params()
{
// zzz : make example of that
Expand Down Expand Up @@ -127,15 +90,12 @@ tests_impls!

// custom params
let got = Struct1Former
::< Struct1FormerDefinition< i32, i32, _ > >
::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > >
::begin
(
None,
Some( 3 ),
former::FormingEndWrapper::new
(
| storage : Struct1FormerStorage, context | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }
),
| storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) },
)
.int_1( 13 )
.form();
Expand All @@ -148,18 +108,16 @@ tests_impls!
(
None,
Some( 3 ),
(
| storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }
).into(),
| storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) },
)
.int_1( 13 )
.form();
a_id!( got, 32 );

// custom params begin_with
// custom params begin
let got = Struct1Former
::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > >
::begin_with
::begin
(
None,
Some( 3 ),
Expand All @@ -182,6 +140,81 @@ tests_impls!

//

fn begin()
{

// begin with none
let got = Struct1Former::< Struct1FormerDefinition >::begin( None, None, the_module::ReturnPreformed ).int_1( 13 ).form();
let exp = Struct1::former().int_1( 13 ).form();
a_id!( got, exp );

// begin with storage
let mut storage = Struct1FormerStorage::default();
storage.int_1 = Some( 13 );
let exp = Struct1Former::< Struct1FormerDefinition >::begin( Some( storage ), None, the_module::ReturnPreformed ).form();
a_id!( got, exp );

// begin with context
let mut storage = Struct1FormerStorage::default();
storage.int_1 = Some( 13 );
let exp = Struct1Former::< Struct1FormerDefinition >
::begin( Some( storage ), Some( () ), the_module::ReturnPreformed )
.form();
a_id!( got, exp );

}

//

fn begin_explicit()
{

// custom params
let got = Struct1Former
::< Struct1FormerDefinition< i32, i32, _ > >
::begin_explicit
(
None,
Some( 3 ),
former::FormingEndWrapper::new
(
| storage : Struct1FormerStorage, context | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }
),
)
.int_1( 13 )
.form();
a_id!( got, 32 );

// custom params with into
let got = Struct1Former
::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > >
::begin_explicit
(
None,
Some( 3 ),
(
| storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }
).into(),
)
.int_1( 13 )
.form();
a_id!( got, 32 );

}

//

fn new()
{

let former = Struct1::former();
let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed );
a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) );

}

//

fn preform()
{

Expand Down Expand Up @@ -448,6 +481,7 @@ tests_index!
{
internals,
begin,
begin_explicit,
new,
custom_definition_params,
preform,
Expand Down

0 comments on commit 1effc15

Please sign in to comment.