diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index a928b06e29..990cea0bac 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -1,83 +1,105 @@ -// use super::*; -// use axiomatic::*; +use super::*; +use axiomatic::*; + +#[ allow( unused ) ] +use collection_tools::Vec; + +/// Trait for containers that behave like a vector, providing an interface for element addition. +/// +/// This trait enables the use of custom or standard vector-like containers within the builder pattern, +/// allowing for a unified and flexible approach to constructing collections. +/// +pub trait VectorLike< E > +{ + /// Appends an element to the back of a storage. + fn push( &mut self, element : E ); +} + +impl< E > VectorLike< E > for Vec< E > +{ + fn push( &mut self, element : E ) + { + Vec::push( self, element ); + } +} + // -// #[ allow( unused ) ] -// use collection_tools::Vec; + +impl< E > Storage +for Vec< E > +{ + // type Definition = VectorDefinition< E >; + type Formed = Vec< E >; +} + +impl< E > StoragePerform +for Vec< E > +{ + // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed + fn preform( self ) -> Self::Formed + { + self + } +} + // -// /// Trait for containers that behave like a vector, providing an interface for element addition. -// /// -// /// This trait enables the use of custom or standard vector-like containers within the builder pattern, -// /// allowing for a unified and flexible approach to constructing collections. -// /// -// pub trait VectorLike< E > -// { -// /// Appends an element to the back of a storage. -// fn push( &mut self, element : E ); -// } -// -// impl< E > VectorLike< E > for Vec< E > -// { -// fn push( &mut self, element : E ) -// { -// Vec::push( self, element ); -// } -// } -// -// // -// -// impl< E > Storage -// for Vec< E > -// { -// // type Definition = VectorDefinition< E >; -// type Formed = Vec< E >; -// } -// -// impl< E > StoragePerform -// for Vec< E > -// { -// // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed -// fn preform( self ) -> Self::Formed -// { -// self -// } -// } -// -// // -// -// #[ derive( Debug ) ] -// // pub struct VectorDefinition< E, Context = (), End = ReturnStorage > -// pub struct VectorDefinition< E, Context, End > -// where -// End : FormingEnd< Self >, -// Self : FormerDefinition, -// { -// _phantom : core::marker::PhantomData< ( E, Context, End ) >, -// } -// -// impl< E, Context, End > VectorDefinition< E, Context, End > -// where -// End : FormingEnd< Self > -// { -// pub fn new() -> Self -// { -// Self { _phantom : core::marker::PhantomData } -// } -// } -// -// impl< E, Context, End > FormerDefinition -// for VectorDefinition< E, Context, End > -// where -// End : FormingEnd< Self > -// { -// type Storage = Vec< E >; -// type Formed = Vec< E >; -// type Context = Context; -// type End = End; -// } -// -// /// 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, Context, End > = ContainerSubformer::< E, VectorDefinition< E, Context, End > >; + +#[ derive( Debug ) ] +// pub struct VectorDefinition1< E, Context = (), End = ReturnStorage > +pub struct VectorDefinition1< E, Context > +where + Self : FormerDefinition, +{ + _phantom : core::marker::PhantomData< ( E, Context ) >, +} + +impl< E, Context > VectorDefinition1< E, Context > +{ + pub fn new() -> Self + { + Self { _phantom : core::marker::PhantomData } + } +} + +impl< E, Context > FormerDefinition +for VectorDefinition1< E, Context > +{ + type Storage = Vec< E >; + type Formed = Vec< E >; + type Context = Context; +} + +#[ derive( Debug ) ] +// pub struct VectorDefinition2< E, Context = (), End = ReturnStorage > +pub struct VectorDefinition2< E, Context, End > +where + End : FormingEnd< VectorDefinition1< E, Context > >, +{ + _phantom : core::marker::PhantomData< ( E, Context, End ) >, +} + +impl< E, Context, End > VectorDefinition2< E, Context, End > +where + End : FormingEnd< VectorDefinition1< E, Context > >, +{ + pub fn new() -> Self + { + Self { _phantom : core::marker::PhantomData } + } +} + +impl< E, Context, End > FormerDefinition2 +for VectorDefinition2< E, Context, End > +where + End : FormingEnd< VectorDefinition1< E, Context > >, +{ + type Definition = VectorDefinition1< E, Context >; + type End = End; +} + +/// 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, Context, End > = ContainerSubformer::< E, VectorDefinition2< E, 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 1e9bc00448..23f26061a6 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 @@ -9,13 +9,19 @@ use collection_tools::Vec; // where // Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = Self >, -pub fn f0< Definition >( x : Definition ) +pub fn f1< Definition >( x : Definition ) where Definition : former::FormerDefinition, { } -pub fn f1< Definition, End >( x : End ) +pub fn f2< Definition >( x : Definition ) +where + Definition : former::FormerDefinition2, +{ +} + +pub fn f3< Definition, End >( x : End ) where Definition : former::FormerDefinition, End : former::FormingEnd< Definition >, @@ -32,8 +38,9 @@ where fn push() { - // f0( former::VectorDefinition::< String, (), the_module::ReturnStorage >::new() ); - // f1::< former::VectorDefinition< String, (), the_module::ReturnStorage >, _ >( the_module::ReturnStorage ); + f1( former::VectorDefinition1::< String, () >::new() ); + // f2( former::VectorDefinition2::< String, (), the_module::ReturnStorage >::new() ); + // f3::< former::VectorDefinition< String, (), the_module::ReturnStorage >, _ >( the_module::ReturnStorage ); //