Skip to content

Commit

Permalink
former : experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 24, 2024
1 parent 28e23bf commit e55b71b
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 85 deletions.
184 changes: 103 additions & 81 deletions module/core/former/src/vector.rs
Original file line number Diff line number Diff line change
@@ -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 > >;
15 changes: 11 additions & 4 deletions module/core/former/tests/inc/former_tests/container_former_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 >,
Expand All @@ -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 );

//

Expand Down

0 comments on commit e55b71b

Please sign in to comment.