Skip to content

Commit

Permalink
former : making subforming more friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 20, 2024
1 parent f049259 commit 5b22bf2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 44 deletions.
10 changes: 6 additions & 4 deletions module/core/former/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ pub trait ContainerAssign

/// Agging elements to the container.
fn assign< Elements >( &mut self, elements : Elements ) -> usize
where Elements : core::iter::Iterator< Item = Self::Element >;
where
Elements : IntoIterator< Item = Self::Element >;

}

Expand All @@ -146,7 +147,8 @@ impl< T > ContainerAssign for collection_tools::Vec< T >

#[ inline( always ) ]
fn assign< Elements >( &mut self, elements : Elements ) -> usize
where Elements : core::iter::Iterator< Item = Self::Element >
where
Elements : IntoIterator< Item = Self::Element >
{
let initial_len = self.len();
self.extend( elements );
Expand All @@ -163,7 +165,7 @@ where

fn assign< Elements >( &mut self, elements : Elements ) -> usize
where
Elements : IntoIterator< Item = Self::Element >,
Elements : IntoIterator< Item = Self::Element >
{
let initial_len = self.len();
self.extend( elements );
Expand All @@ -179,7 +181,7 @@ where

fn assign< Elements >( &mut self, elements : Elements ) -> usize
where
Elements : IntoIterator< Item = Self::Element >,
Elements : IntoIterator< Item = Self::Element >
{
let initial_len = self.len();
self.extend( elements );
Expand Down
31 changes: 22 additions & 9 deletions module/core/former/src/vector.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
use super::*;

// #[ cfg( feature = "use_alloc" ) ]
// extern crate alloc;
// #[ cfg( feature = "use_alloc" ) ]
// #[ allow( unused_imports ) ]
// use alloc::vec::Vec;
// #[ cfg( not( feature = "no_std" ) ) ]
// #[ allow( unused_imports ) ]
// use std::vec::Vec;

#[ allow( unused ) ]
use collection_tools::Vec;

Expand Down Expand Up @@ -191,3 +182,25 @@ where
}

}

//

impl< E, Container, Context, End > FormerBegin< Container, Context >
for VectorSubformer< E, Container, Context, End >
where
End : ToSuperFormer< Container, Context >,
Container : VectorLike< E > + Default,
{
type End = End;

#[ inline( always ) ]
fn _begin
(
context : core::option::Option< Context >,
on_end : End,
) -> Self
{
Self::begin( context, None, on_end )
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -147,47 +147,57 @@ where
on_end.call( container, context )
}

// #[ inline( always ) ]
// pub fn _vec_1< Former2 >( self ) ->
// Former2
// where
// Former2 : former::FormerBegin< Vec< String >, Self, End = former::ToSuperFormerWrapper< Vec< String >, Self > >,
// // FieldContainer : ContainerAssign,
// {
// let on_end = | formed : Vec< String >, super_former : core::option::Option< Self > | -> Self
// {
// let mut super_former = super_former.unwrap();
// if super_former.container.vec_1.is_none()
// {
// super_former.container.vec_1 = Some( Default::default() );
// }
// if let Some( ref mut field ) = super_former.container.vec_1
// {
// former::ContainerAssign::assign( field, formed );
// }
// super_former
// };
// Former2::_begin( Some( self ), former::ToSuperFormerWrapper::new( on_end ) )
// }
#[ inline( always ) ]
pub fn __vec_1< Former2 >( self ) ->
Former2
where
Former2 : former::FormerBegin< Vec< String >, Self, End = former::ToSuperFormerWrapper< Vec< String >, Self > >,
{
let on_end = | formed : Vec< String >, super_former : core::option::Option< Self > | -> Self
{
let mut super_former = super_former.unwrap();
if super_former.container.vec_1.is_none()
{
super_former.container.vec_1 = Some( Default::default() );
}
if let Some( ref mut field ) = super_former.container.vec_1
{
former::ContainerAssign::assign( field, formed );
}
super_former
};
Former2::_begin( Some( self ), former::ToSuperFormerWrapper::new( on_end ) )
}

pub fn vec_1( mut self ) -> the_module::VectorSubformer
pub fn vec_1( self ) -> the_module::VectorSubformer
<
String,
Vec< String >,
Self,
impl the_module::ToSuperFormer< Vec< String >, Self >,
>
{
let container = self.container.vec_1.take();
let on_end = | container : Vec< String >, super_former : core::option::Option< Self > | -> Self
{
let mut super_former = super_former.unwrap();
super_former.container.vec_1 = Some( container );
super_former
};
the_module::VectorSubformer::< String, Vec< String >, Self, _ >::begin( Some( self ), container, on_end )
self.__vec_1::< the_module::VectorSubformer::< _, _, _, _ > >()
}

// pub fn vec_1( mut self ) -> the_module::VectorSubformer
// <
// String,
// Vec< String >,
// Self,
// impl the_module::ToSuperFormer< Vec< String >, Self >,
// >
// {
// let container = self.container.vec_1.take();
// let on_end = | container : Vec< String >, super_former : core::option::Option< Self > | -> Self
// {
// let mut super_former = super_former.unwrap();
// super_former.container.vec_1 = Some( container );
// super_former
// };
// the_module::VectorSubformer::< String, Vec< String >, Self, _ >::begin( Some( self ), container, on_end )
// }

pub fn hashmap_strings_1( mut self ) -> the_module::HashMapSubformer
<
String,
Expand Down

0 comments on commit 5b22bf2

Please sign in to comment.