diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 5eeb20c3b6..e1e24dfe2e 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -19,7 +19,7 @@ pub trait FormerDefinition // type Storage : Storage< Definition = Self >; type Storage : Storage< Formed = Self::Formed >; type Formed; - // type Context; + type Context; } // pub trait FormerDefinition diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 484b1fde3d..3788eecf67 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -47,52 +47,55 @@ where // -#[ derive( Debug ) ] -pub struct HashMapDefinition< K, E > +impl< K, E > Storage +for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - _phantom : ::core::marker::PhantomData< ( K, E ) >, + // type Definition = HashMapDefinition< K, E >; + type Formed = HashMap< K, E >; } -impl< K, E > HashMapDefinition< K, E > +impl< K, E > StoragePerform +for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - pub fn new() -> Self + // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed + fn preform( self ) -> Self::Formed { - Self { _phantom : ::core::marker::PhantomData } + self } } -impl< K, E > FormerDefinition -for HashMapDefinition< K, E > +// + +#[ derive( Debug ) ] +pub struct HashMapDefinition< K, E, Context = () > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Storage = HashMap< K, E >; - type Formed = HashMap< K, E >; + _phantom : ::core::marker::PhantomData< ( K, E, Context ) >, } -impl< K, E > Storage -for HashMap< K, E > +impl< K, E, Context > HashMapDefinition< K, E, Context > where K : ::core::cmp::Eq + ::core::hash::Hash, { - // type Definition = HashMapDefinition< K, E >; - type Formed = HashMap< K, E >; + pub fn new() -> Self + { + Self { _phantom : ::core::marker::PhantomData } + } } -impl< K, E > StoragePerform -for HashMap< K, E > +impl< K, E, Context > FormerDefinition +for HashMapDefinition< K, E, Context > where K : ::core::cmp::Eq + ::core::hash::Hash, { - // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed - fn preform( self ) -> Self::Formed - { - self - } + type Storage = HashMap< K, E >; + type Formed = HashMap< K, E >; + type Context = Context; } /// A builder for constructing hash map-like structures with a fluent interface. @@ -133,7 +136,7 @@ where /// # } /// ``` -pub type HashMapSubformer< K, E > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E > >; +pub type HashMapSubformer< K, E, Context = () > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context > >; // #[ derive( Debug, Default ) ] // pub struct HashMapSubformer< K, E, Definition, Context, End > diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 66ef30e701..9d8836b6d3 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -35,52 +35,55 @@ where // -#[ derive( Debug ) ] -pub struct HashSetDefinition< K > +impl< K > Storage +for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - _phantom : ::core::marker::PhantomData< ( K, K ) >, + // type Definition = HashSetDefinition< K >; + type Formed = HashSet< K >; } -impl< K > HashSetDefinition< K > +impl< K > StoragePerform +for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - pub fn new() -> Self + // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed + fn preform( self ) -> Self::Formed { - Self { _phantom : ::core::marker::PhantomData } + self } } -impl< K > Storage -for HashSet< K > +// + +#[ derive( Debug ) ] +pub struct HashSetDefinition< K, Context = () > where K : ::core::cmp::Eq + ::core::hash::Hash, { - // type Definition = HashSetDefinition< K >; - type Formed = HashSet< K >; + _phantom : ::core::marker::PhantomData< ( K, Context ) >, } -impl< K > StoragePerform -for HashSet< K > +impl< K, Context > HashSetDefinition< K, Context > where K : ::core::cmp::Eq + ::core::hash::Hash, { - // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed - fn preform( self ) -> Self::Formed + pub fn new() -> Self { - self + Self { _phantom : ::core::marker::PhantomData } } } -impl< K > FormerDefinition -for HashSetDefinition< K > +impl< K, Context > FormerDefinition +for HashSetDefinition< K, Context > where K : ::core::cmp::Eq + ::core::hash::Hash, { type Storage = HashSet< K >; type Formed = HashSet< K >; + type Context = Context; } /// Facilitates building `HashSetLike` containers with a fluent API. @@ -115,7 +118,7 @@ where /// # } /// ``` -pub type HashSetSubformer< K > = ContainerSubformer::< K, HashSetDefinition< K > >; +pub type HashSetSubformer< K, Context = () > = ContainerSubformer::< K, HashSetDefinition< K, Context > >; // #[ derive( Debug, Default ) ] // pub struct HashSetSubformer< K, Definition, Context, End > diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 4b056695eb..bab7601563 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -23,26 +23,7 @@ impl< E > VectorLike< E > for Vec< E > } } -#[ derive( Debug ) ] -pub struct VectorDefinition< E > -{ - _phantom : core::marker::PhantomData< E >, -} - -impl< E > VectorDefinition< E > -{ - pub fn new() -> Self - { - Self { _phantom : core::marker::PhantomData } - } -} - -impl< E > FormerDefinition -for VectorDefinition< E > -{ - type Storage = Vec< E >; - type Formed = Vec< E >; -} +// impl< E > Storage for Vec< E > @@ -61,12 +42,36 @@ for Vec< E > } } +// + +#[ derive( Debug ) ] +pub struct VectorDefinition< E, Context = () > +{ + _phantom : core::marker::PhantomData< ( E, Context ) >, +} + +impl< E, Context > VectorDefinition< E, Context > +{ + pub fn new() -> Self + { + Self { _phantom : core::marker::PhantomData } + } +} + +impl< E, Context > FormerDefinition +for VectorDefinition< E, Context > +{ + type Storage = Vec< E >; + type Formed = Vec< E >; + type Context = Context; +} + /// A builder for constructing `VectorLike` containers, facilitating a fluent and flexible interface. /// /// `VectorSubformer` leverages the `VectorLike` trait to enable the construction and manipulation /// of vector-like containers in a builder pattern style, promoting readability and ease of use. -pub type VectorSubformer< E > = ContainerSubformer::< E, VectorDefinition< E > >; +pub type VectorSubformer< E, Context = () > = ContainerSubformer::< E, VectorDefinition< E, Context > >; // #[ derive( Debug, Default ) ] // pub struct VectorSubformer< E, Definition, Context, End > 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 3eccc1475f..4f886ba463 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 @@ -8,6 +8,19 @@ use collection_tools::Vec; fn push() { + let got : Vec< String > = the_module::ContainerSubformer::< String, former::VectorDefinition< String, () > >::new() + .push( "a" ) + .push( "b" ) + .form(); + let exp = vec! + [ + "a".to_string(), + "b".to_string(), + ]; + a_id!( got, exp ); + + // + let got : Vec< String > = the_module::ContainerSubformer::< String, former::VectorDefinition< String > >::new() .push( "a" ) .push( "b" ) @@ -21,7 +34,7 @@ fn push() // - let got : Vec< String > = the_module::VectorSubformer::new() + let got : Vec< String > = the_module::VectorSubformer::< String, () >::new() .push( "a" ) .push( "b" ) .form();