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 2fb1bfd commit 71394ff
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 12 deletions.
16 changes: 16 additions & 0 deletions module/core/former/src/axiomatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ pub struct FormingEndWrapper< Definition : FormerDefinitionTypes >
_marker : std::marker::PhantomData< Definition::Storage >,
}

impl< T, Definition > From< T > for FormingEndWrapper< Definition >
where
T : Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed + 'static,
Definition : FormerDefinitionTypes,
{
#[ inline( always ) ]
fn from( closure : T ) -> Self
{
Self
{
closure : Box::new( closure ),
_marker : std::marker::PhantomData
}
}
}

#[ cfg( not( feature = "no_std" ) ) ]
impl< Definition : FormerDefinitionTypes > FormingEndWrapper< Definition >
{
Expand Down
58 changes: 46 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 @@ -227,8 +227,6 @@ fn custom_definition()
}
}

// type MyContainer<>

//

let got = the_module::ContainerSubformer::< String, Return13 >::begin( None, None, Return13 )
Expand Down Expand Up @@ -333,8 +331,31 @@ fn custom_definition_parametrized()

//

// xxx : make it working?
// let got = the_module::ContainerSubformer::< String, Return13 >::new()
}

//

#[ test ]
fn custom_definition_custom_end()
{

struct Return13;
impl former::FormerDefinitionTypes for Return13
{
type Storage = Vec< String >;
type Formed = i32;
type Context = ();
}

impl former::FormerDefinition for Return13
{
type Types = Return13;
type End = former::FormingEndWrapper< < Self as former::FormerDefinition >::Types >;
}

//

// let got = the_module::ContainerSubformer::< String, Return13 >::new( Return13 )
// .push( "a" )
// .push( "b" )
// .form();
Expand All @@ -343,14 +364,27 @@ fn custom_definition_parametrized()

//

// // -
//
// fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32
// {
// 13
// }
//
// let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 );
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 = the_module::ContainerSubformer::< String, Return13 >::new( end_wrapper )
.push( "a" )
.push( "b" )
.form();
let exp = 13;
a_id!( got, exp );

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

//

}

Expand Down

0 comments on commit 71394ff

Please sign in to comment.