Skip to content

Commit

Permalink
former : experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Apr 27, 2024
1 parent 19f741a commit c482d19
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 54 deletions.
48 changes: 0 additions & 48 deletions module/core/former/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,54 +102,6 @@ pub trait ContainerAssign

}

impl< T > ContainerAssign for collection_tools::Vec< T >
{
type Element = T;

#[ inline( always ) ]
fn assign< Elements >( &mut self, elements : Elements ) -> usize
where
Elements : IntoIterator< Item = Self::Element >
{
let initial_len = self.len();
self.extend( elements );
self.len() - initial_len
}

}

impl< T > ContainerAssign for collection_tools::HashSet< T >
where
T : core::cmp::Eq + core::hash::Hash,
{
type Element = T;

fn assign< Elements >( &mut self, elements : Elements ) -> usize
where
Elements : IntoIterator< Item = Self::Element >
{
let initial_len = self.len();
self.extend( elements );
self.len() - initial_len
}
}

impl< K, V > ContainerAssign for collection_tools::HashMap< K, V >
where
K : core::cmp::Eq + core::hash::Hash,
{
type Element = ( K, V );

fn assign< Elements >( &mut self, elements : Elements ) -> usize
where
Elements : IntoIterator< Item = Self::Element >
{
let initial_len = self.len();
self.extend( elements );
self.len() - initial_len
}
}

// =

/// A builder for constructing containers, facilitating a fluent and flexible interface.
Expand Down
16 changes: 16 additions & 0 deletions module/core/former/src/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ where

}

impl< K, V > ContainerAssign for collection_tools::HashMap< K, V >
where
K : core::cmp::Eq + core::hash::Hash,
{
type Element = ( K, V );

fn assign< Elements >( &mut self, elements : Elements ) -> usize
where
Elements : IntoIterator< Item = Self::Element >
{
let initial_len = self.len();
self.extend( elements );
self.len() - initial_len
}
}

/// A trait for types that behave like hash maps, supporting insertion and custom forming behaviors.
///
/// This trait allows for generic operations on hash map-like data structures, enabling the insertion
Expand Down
16 changes: 16 additions & 0 deletions module/core/former/src/hash_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ where

}

impl< T > ContainerAssign for collection_tools::HashSet< T >
where
T : core::cmp::Eq + core::hash::Hash,
{
type Element = T;

fn assign< Elements >( &mut self, elements : Elements ) -> usize
where
Elements : IntoIterator< Item = Self::Element >
{
let initial_len = self.len();
self.extend( elements );
self.len() - initial_len
}
}

/// A trait for containers behaving like a `HashSet`, allowing insertion operations.
///
/// Implementing this trait enables the associated formed to be used with `HashSetSubformer`,
Expand Down
16 changes: 16 additions & 0 deletions module/core/former/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ impl< T > ContainerAdd for collection_tools::Vec< T >

}

impl< T > ContainerAssign for collection_tools::Vec< T >
{
type Element = T;

#[ inline( always ) ]
fn assign< Elements >( &mut self, elements : Elements ) -> usize
where
Elements : IntoIterator< Item = Self::Element >
{
let initial_len = self.len();
self.extend( elements );
self.len() - initial_len
}

}

/// 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,8 @@ where
pub struct Struct1FormerStorage< >
where
{

pub vec_1 : ::core::option::Option< Vec< String > >,

pub hashmap_1 : ::core::option::Option< std::collections::HashMap< String, String > >,

pub hashset_1 : ::core::option::Option< std::collections::HashSet< String > >,
}

Expand Down Expand Up @@ -330,7 +327,8 @@ where
}

#[ inline( always ) ]
pub fn vec_1( self ) -> former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End > >
pub fn vec_1( self ) ->
former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End > >
{
self.vec_1_set::< former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End > >>()
}
Expand Down Expand Up @@ -425,14 +423,16 @@ where
pub struct Struct1FormerAssignVec1End;

#[ automatically_derived ]
impl< Definition, > former::FormingEnd< former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, >
impl< Definition, > former::FormingEnd
< former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, >
for Struct1FormerAssignVec1End
where
Definition : former::FormerDefinition,
Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >,
{
#[ inline( always ) ]
fn call( &self, storage : Vec< String >, super_former : Option< Struct1Former< Definition, > >, ) -> Struct1Former< Definition, >
fn call( &self, storage : Vec< String >, super_former : Option< Struct1Former< Definition, > >, ) ->
Struct1Former< Definition, >
{
let mut super_former = super_former.unwrap();
if let Some( ref mut field ) = super_former.storage.vec_1
Expand Down

0 comments on commit c482d19

Please sign in to comment.