Skip to content

Commit

Permalink
experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 27, 2024
1 parent cc34646 commit 8c8363f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
21 changes: 20 additions & 1 deletion module/core/former/src/axiomatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub trait FormerDefinition : Sized
/// - `Storage`: The type of the container being processed.
/// - `Context`: The type of the context that might be altered or returned upon completion.

// xxx2 : contunue. try
// xxx2 : continue. try
// pub trait FormingEnd< Definition : FormerDefinitionTypes > : Default
pub trait FormingEnd< Definition : FormerDefinitionTypes >
{
Expand Down Expand Up @@ -105,6 +105,25 @@ where
}
}

// xxx : improve description
/// Use `NoEnd` to fill parameter FormingEnd in struct where parameter exists, but it is not needed.
/// It might be needed if the same struct is used as `FormerDefinitionTypes` and as `FormerDefinition`, because the first one does not have information aboud End function.
/// Similar logic which `std::marker::PhantomData` has behind.
#[ derive( Debug, Default ) ]
pub struct NoEnd;

impl< Definition > FormingEnd< Definition >
for NoEnd
where
Definition : FormerDefinitionTypes< Context = () >,
{
#[ inline( always ) ]
fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed
{
unreachable!();
}
}

/// A wrapper around a closure to be used as a `FormingEnd`.
///
/// This struct allows for dynamic dispatch of a closure that matches the
Expand Down
9 changes: 4 additions & 5 deletions module/core/former/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnSto

impl< E, Context, Formed > FormerDefinitionTypes
// for VectorDefinition< E, Context, Formed >
for VectorDefinition< E, Context, Formed, ReturnStorage >
for VectorDefinition< E, Context, Formed, NoEnd >
// for VectorDefinition< E, Context, Formed, End >
// where
// End : FormingEnd< Self >,
Expand All @@ -64,9 +64,9 @@ for VectorDefinition< E, Context, Formed, ReturnStorage >
impl< E, Context, Formed, End > FormerDefinition
for VectorDefinition< E, Context, Formed, End >
where
End : FormingEnd< VectorDefinition< E, Context, Formed, ReturnStorage > >,
End : FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >,
{
type Types = VectorDefinition< E, Context, Formed, ReturnStorage >;
type Types = VectorDefinition< E, Context, Formed, NoEnd >;
type End = End;
}

Expand Down Expand Up @@ -99,7 +99,6 @@ impl< E > VecExt< E > for Vec< E >

mod sealed
{
use super::Vec;
pub trait Sealed {}
impl< E > Sealed for Vec< E > {}
impl< E > Sealed for super::Vec< E > {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use super::*;
#[ allow( unused_imports ) ]
use collection_tools::Vec;

//

#[ test ]
fn definitions()
{
Expand All @@ -28,9 +30,13 @@ fn definitions()
}

// f1( former::VectorDefinition::< String, () >::default() );
f2( former::VectorDefinition::< String, (), Vec< String >, the_module::ReturnStorage >::default() );
f3::< former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage >, the_module::ReturnStorage >( the_module::ReturnStorage );
f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > as the_module::FormerDefinition >::Types, the_module::ReturnStorage >( the_module::ReturnStorage );
f2( former::VectorDefinition::< String, (), Vec< String >, the_module::NoEnd >::default() );
f3::< former::VectorDefinition< String, (), Vec< String >, the_module::NoEnd >, the_module::ReturnStorage >( the_module::ReturnStorage );
f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::NoEnd > as the_module::FormerDefinition >::Types, the_module::ReturnStorage >( the_module::ReturnStorage );

// assert_eq!( 0, 1 );

let vec : Vec< String > = vec![ "a".into(), "b".into(), "c".into() ];

}

Expand Down

0 comments on commit 8c8363f

Please sign in to comment.