From 8c8363fe993e20f2209173a9deae59e9fd02b574 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 27 Mar 2024 14:34:21 +0200 Subject: [PATCH] experimenting --- module/core/former/src/axiomatic.rs | 21 ++++++++++++++++++- module/core/former/src/vector.rs | 9 ++++---- .../inc/former_tests/container_former_vec.rs | 12 ++++++++--- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index c180edef24..879fa3ec60 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -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 > { @@ -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 diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index da59e7e122..c170e12368 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -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 >, @@ -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; } @@ -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 > {} } diff --git a/module/core/former/tests/inc/former_tests/container_former_vec.rs b/module/core/former/tests/inc/former_tests/container_former_vec.rs index 048af90f1f..7aeb920776 100644 --- a/module/core/former/tests/inc/former_tests/container_former_vec.rs +++ b/module/core/former/tests/inc/former_tests/container_former_vec.rs @@ -4,6 +4,8 @@ use super::*; #[ allow( unused_imports ) ] use collection_tools::Vec; +// + #[ test ] fn definitions() { @@ -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() ]; }