From fe787f8636aad9a5810fd06b0225c8fd8402ec38 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 01:27:13 +0200 Subject: [PATCH 001/533] former : experimenting --- module/core/former/Readme.md | 10 +- .../former/examples/former_trivial_expaned.rs | 10 +- module/core/former/src/axiomatic.rs | 4 +- module/core/former/src/axiomatic2.rs | 19 +- module/core/former/src/axiomatic3.rs | 204 ++++++++++++++++++ module/core/former/src/hash_map.rs | 172 +++++++++------ module/core/former/src/hash_set.rs | 116 ++++++---- module/core/former/src/lib.rs | 3 + module/core/former/src/vector.rs | 6 +- module/core/former/src/vector3.rs | 76 +++---- .../a_containers_with_runtime_manual.rs | 16 +- .../a_containers_without_runtime_manual.rs | 12 +- .../inc/former_tests/a_primitives_manual.rs | 12 +- .../parametrized_struct_manual.rs | 4 +- .../former_tests/subformer_basic_manual.rs | 8 +- .../inc/only_test/containers_with_runtime.rs | 4 +- .../only_test/containers_without_runtime.rs | 4 +- .../former/tests/inc/only_test/primitives.rs | 4 +- module/core/former_meta/src/derive/former.rs | 12 +- module/core/former_meta/src/lib.rs | 10 +- 20 files changed, 501 insertions(+), 205 deletions(-) create mode 100644 module/core/former/src/axiomatic3.rs diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index ec0a4f16ec..3fbcce7c94 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -86,9 +86,9 @@ pub struct UserProfile impl UserProfile { #[ inline( always ) ] - pub fn former() -> UserProfileFormer< UserProfile, former::ReturnFormed > + pub fn former() -> UserProfileFormer< UserProfile, former::ReturnStorage > { - UserProfileFormer::< UserProfile, former::ReturnFormed >::new() + UserProfileFormer::< UserProfile, former::ReturnStorage >::new() } } @@ -103,7 +103,7 @@ pub struct UserProfileFormerStorage pub struct UserProfileFormer < Context = UserProfile, - End = former::ReturnFormed, + End = former::ReturnStorage, > where End : former::FormingEnd< UserProfile, Context >, @@ -205,9 +205,9 @@ where } #[ inline( always ) ] - pub fn new() -> UserProfileFormer< UserProfile, former::ReturnFormed > + pub fn new() -> UserProfileFormer< UserProfile, former::ReturnStorage > { - UserProfileFormer::< UserProfile, former::ReturnFormed >::begin( None, former::ReturnFormed ) + UserProfileFormer::< UserProfile, former::ReturnStorage >::begin( None, former::ReturnStorage ) } #[ inline( always ) ] diff --git a/module/core/former/examples/former_trivial_expaned.rs b/module/core/former/examples/former_trivial_expaned.rs index 5b8d8cd8c2..ac46064cb4 100644 --- a/module/core/former/examples/former_trivial_expaned.rs +++ b/module/core/former/examples/former_trivial_expaned.rs @@ -38,9 +38,9 @@ fn main() impl UserProfile { #[ inline( always ) ] - pub fn former() -> UserProfileFormer< UserProfile, former::ReturnFormed > + pub fn former() -> UserProfileFormer< UserProfile, former::ReturnStorage > { - UserProfileFormer::< UserProfile, former::ReturnFormed >::new() + UserProfileFormer::< UserProfile, former::ReturnStorage >::new() } } @@ -55,7 +55,7 @@ fn main() pub struct UserProfileFormer < Context = UserProfile, - End = former::ReturnFormed, + End = former::ReturnStorage, > where End : former::FormingEnd< UserProfile, Context >, @@ -157,9 +157,9 @@ fn main() } #[ inline( always ) ] - pub fn new() -> UserProfileFormer< UserProfile, former::ReturnFormed > + pub fn new() -> UserProfileFormer< UserProfile, former::ReturnStorage > { - UserProfileFormer::< UserProfile, former::ReturnFormed >::begin( None, former::ReturnFormed ) + UserProfileFormer::< UserProfile, former::ReturnStorage >::begin( None, former::ReturnStorage ) } #[ inline( always ) ] diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 161a0f3ea8..f6aed1dacf 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -122,10 +122,10 @@ for FormingEndWrapper< Storage, Context > /// This struct is useful when the forming process should result in the formed container being returned directly, /// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. #[ derive( Debug, Default ) ] -pub struct ReturnFormed; +pub struct ReturnStorage; impl< Storage > FormingEnd< Storage, Storage > -for ReturnFormed +for ReturnStorage { #[ inline( always ) ] fn call( &self, storage : Storage, _context : core::option::Option< Storage > ) -> Storage diff --git a/module/core/former/src/axiomatic2.rs b/module/core/former/src/axiomatic2.rs index 16f43060ef..84f36512d5 100644 --- a/module/core/former/src/axiomatic2.rs +++ b/module/core/former/src/axiomatic2.rs @@ -15,14 +15,14 @@ pub trait FormerDescriptor // type Former; } -pub trait FormerDefinition -{ - type Storage : StoragePerform< Formed = Self::Formed >; - type Formed; - type Context; - type FormerDescriptor : FormerDescriptor< Storage = Self::Storage, Formed = Self::Formed >; - type End : FormingEnd2< Self::FormerDescriptor, Self::Context >; -} +// pub trait FormerDefinition +// { +// type Storage : StoragePerform< Formed = Self::Formed >; +// type Formed; +// type Context; +// type FormerDescriptor : FormerDescriptor< Storage = Self::Storage, Formed = Self::Formed >; +// type End : FormingEnd2< Self::FormerDescriptor, Self::Context >; +// } /// Defines a handler for the end of a subforming process, enabling the return of the original context. /// @@ -42,7 +42,6 @@ pub trait FormingEnd2< Former : FormerDescriptor, Context > /// /// # Returns /// Returns the transformed or original context based on the implementation. - // #[ allow( dead_code ) ] fn call( &self, storage : Former::Storage, context : core::option::Option< Context > ) -> Former::Formed; } @@ -66,8 +65,6 @@ pub struct ReturnStorage2; impl< Former : FormerDescriptor > FormingEnd2< Former, () > for ReturnStorage2 -// where - // Storage : StoragePreform<>, { #[ inline( always ) ] fn call( &self, storage : Former::Storage, _context : core::option::Option< () > ) -> Former::Formed diff --git a/module/core/former/src/axiomatic3.rs b/module/core/former/src/axiomatic3.rs new file mode 100644 index 0000000000..b618c9e289 --- /dev/null +++ b/module/core/former/src/axiomatic3.rs @@ -0,0 +1,204 @@ +//! .... + +/// xxx +pub trait StoragePerform : ::core::default::Default +{ + type Formed; + fn preform( self ) -> Self::Formed; +} + +/// xxx +pub trait FormerDescriptor +{ + type Storage : StoragePerform< Formed = Self::Formed >; + type Formed; + // type Former; +} + +// pub trait FormerDefinition +// { +// type Storage : StoragePerform< Formed = Self::Formed >; +// type Formed; +// type Context; +// type FormerDescriptor : FormerDescriptor< Storage = Self::Storage, Formed = Self::Formed >; +// type End : FormingEnd< Self::FormerDescriptor, Self::Context >; +// } + +/// Defines a handler for the end of a subforming process, enabling the return of the original context. +/// +/// This trait is designed to be flexible, allowing for various end-of-forming behaviors in builder patterns. +/// Implementors can define how to transform or pass through the context during the forming process's completion. +/// +/// # Parameters +/// - `Storage`: The type of the container being processed. +/// - `Context`: The type of the context that might be altered or returned upon completion. +pub trait FormingEnd< Former : FormerDescriptor, Context > +{ + /// Called at the end of the subforming process to return the modified or original context. + /// + /// # Parameters + /// - `container`: The container being processed. + /// - `context`: Optional context to be transformed or returned. + /// + /// # Returns + /// Returns the transformed or original context based on the implementation. + fn call( &self, storage : Former::Storage, context : core::option::Option< Context > ) -> Former::Formed; +} + +impl< Former : FormerDescriptor, Context, F > FormingEnd< Former, Context > for F +where + F : Fn( Former::Storage, core::option::Option< Context > ) -> Former::Formed, +{ + #[ inline( always ) ] + fn call( &self, storage : Former::Storage, context : core::option::Option< Context > ) -> Former::Formed + { + self( storage, context ) + } +} + +/// A `FormingEnd` implementation that returns the formed container itself instead of the context. +/// +/// This struct is useful when the forming process should result in the formed container being returned directly, +/// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. +#[ derive( Debug, Default ) ] +pub struct ReturnStorage; + +impl< Former : FormerDescriptor > FormingEnd< Former, () > +for ReturnStorage +{ + #[ inline( always ) ] + fn call( &self, storage : Former::Storage, _context : core::option::Option< () > ) -> Former::Formed + { + storage.preform() + } +} + +/// A wrapper around a closure to be used as a `FormingEnd`. +/// +/// This struct allows for dynamic dispatch of a closure that matches the +/// `FormingEnd` trait's `call` method signature. It is useful for cases where +/// a closure needs to be stored or passed around as an object implementing +/// `FormingEnd`. +/// +/// # Type Parameters +/// +/// * `Storage` - The type of the container being processed. This type is passed to the closure +/// when it's called. +/// * `Context` - The type of the context that may be altered or returned by the closure. +/// This allows for flexible manipulation of context based on the container. +#[ cfg( not( feature = "no_std" ) ) ] +pub struct FormingEndWrapper< Former : FormerDescriptor, Context > +{ + closure : Box< dyn Fn( Former::Storage, Option< Context > ) -> Former::Formed >, + _marker : std::marker::PhantomData< Former::Storage >, +} + +#[ cfg( not( feature = "no_std" ) ) ] +impl< Former : FormerDescriptor, Context > FormingEndWrapper< Former, Context > +{ + /// Constructs a new `FormingEndWrapper` with the provided closure. + /// + /// # Parameters + /// + /// * `closure` - A closure that matches the expected signature for transforming a container + /// and context into a new context. This closure is stored and called by the + /// `call` method of the `FormingEnd` trait implementation. + /// + /// # Returns + /// + /// Returns an instance of `FormingEndWrapper` encapsulating the provided closure. + pub fn new( closure : impl Fn( Former::Storage, Option< Context > ) -> Former::Formed + 'static ) -> Self + { + Self + { + closure : Box::new( closure ), + _marker : std::marker::PhantomData + } + } +} + +#[ cfg( not( feature = "no_std" ) ) ] +use std::fmt; +#[ cfg( not( feature = "no_std" ) ) ] +impl< Former : FormerDescriptor, Context > fmt::Debug for FormingEndWrapper< Former, Context > +{ + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f.debug_struct( "FormingEndWrapper" ) + .field( "closure", &format_args!{ "- closure -" } ) + .field( "_marker", &self._marker ) + .finish() + } +} + +#[ cfg( not( feature = "no_std" ) ) ] +impl< Former : FormerDescriptor, Context > FormingEnd< Former, Context > +for FormingEndWrapper< Former, Context > +{ + fn call( &self, storage : Former::Storage, context : Option< Context > ) -> Former::Formed + { + ( self.closure )( storage, context ) + } +} + +// + +/// A trait for initiating a structured subforming process with contextual and intermediary storage linkage. +/// +/// This trait facilitates the creation of a subformer that carries through a builder pattern chain, +/// utilizing intermediary storage for accumulating state or data before finally transforming it into +/// a `Formed` structure. It is designed for scenarios where a multi-step construction or transformation +/// process benefits from maintaining both transient state (`Storage`) and contextual information (`Context`), +/// before concluding with the generation of a final product (`Formed`). +/// +/// # Type Parameters +/// +/// * `Storage` - Represents a mutable intermediary storage structure used throughout the subforming process +/// to accumulate data, state, or partial computations. This storage is internal to the +/// subformer and is eventually converted into the final `Formed` structure by the subformer, +/// not directly by implementations of this trait. +/// +/// * `Formed` - Denotes the final type that results from the subforming process. This is the intended outcome +/// of the builder chain, constructed or transformed from the `Storage` with consideration of +/// the provided `Context`. +/// +/// * `Context` - Specifies the contextual backdrop against which the subforming process unfolds. This could +/// encompass references to parent builders, configuration data, or any state influencing how +/// `Storage` transitions into `Formed`. +/// +/// # Functions +/// +/// * `_begin` - This function launches the subforming process, marking the start of a construction or transformation +/// sequence defined by the implementing type. It establishes the foundational `Storage` and `Context`, +/// alongside specifying an `on_end` completion handler that dictates the final conversion into `Formed`. +/// +/// The `FormerBegin` trait, by decoupling `Storage` from `Formed` and introducing a contextual layer, enables +/// sophisticated and flexible construction patterns conducive to complex data transformations or object creation +/// sequences within builder patterns. + +// xxx : change sequence +pub trait FormerBegin< Former : FormerDescriptor, Context > +{ + + /// * `End` - A trait bound marking the closure or handler invoked upon completing the subforming process. Implementers + /// of this trait (`End`) are tasked with applying the final transformations that transition `Storage` + /// into `Formed`, optionally utilizing `Context` to guide this transformation. It is crucial that this + /// associated type satisfies the `FormingEnd` trait, defining the precise mechanics of + /// how the subformer concludes its operation. + type End : FormingEnd< Former, Context >; + + /// Launches the subforming process with an initial storage and context, setting up an `on_end` completion handler. + /// + /// # Parameters + /// + /// * `storage` - An optional initial state for the intermediary storage structure. + /// * `context` - An optional initial setting providing contextual information for the subforming process. + /// * `on_end` - A completion handler responsible for transforming the accumulated `Storage` into the final `Formed` structure. + fn _begin + ( + storage : core::option::Option< Former::Storage >, + context : core::option::Option< Context >, + on_end : Self::End, + ) -> Self; + +} diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 14c0831370..4f70292512 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -12,35 +12,28 @@ use collection_tools::HashMap; /// - `E`: The type of elements (values) stored in the hash map. pub trait HashMapLike< K, E > where - K : core::cmp::Eq + core::hash::Hash, + K : ::core::cmp::Eq + ::core::hash::Hash, Self : Sized + Default, { /// Inserts a key-value pair into the map. fn insert( &mut self, k : K, e : E ) -> Option< E >; - /// Return former. - #[ inline( always ) ] - fn former( self ) - -> HashMapSubformer< K, E, Self, Self, impl FormingEnd< Self, Self > > - { - HashMapSubformer::begin( Some( self ), None, ReturnFormed ) - } - - // /// Return former with a custom context. + // /// Return former. // #[ inline( always ) ] - // fn former_begin< Context, End >( self, context : Context, end : End ) - // -> HashMapSubformer< K, E, Self, Context, End > - // where End : FormingEnd< Self, Context > + // fn former< Descriptor : FormerDescriptor >( self ) + // -> + // HashMapSubformer< K, E, Descriptor, (), impl FormingEnd< Self, Self > > // { - // HashMapSubformer::begin( Some( self ), Some( context ), end ) + // HashMapSubformer::begin( Some( self ), None, ReturnStorage ) // } + // xxx : uncomment and cover by tests } impl< K, E > HashMapLike< K, E > for HashMap< K, E > where - K : core::cmp::Eq + core::hash::Hash, + K : ::core::cmp::Eq + ::core::hash::Hash, Self : Sized + Default, { @@ -52,6 +45,46 @@ where } +// + +pub struct HashMapDescriptor< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + _phantom : ::core::marker::PhantomData< ( K, E ) >, +} + +impl< K, E > HashMapDescriptor< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + fn new() -> Self + { + Self { _phantom : ::core::marker::PhantomData } + } +} + +impl< K, E > StoragePerform +for HashMap< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Formed = Self; + fn preform( self ) -> Self::Formed + { + self + } +} + +impl< K, E > FormerDescriptor +for HashMapDescriptor< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Storage = HashMap< K, E >; + type Formed = HashMap< K, E >; +} + /// A builder for constructing hash map-like structures with a fluent interface. /// /// `HashMapSubformer` leverages the `HashMapLike` trait to enable a flexible and customizable @@ -91,30 +124,35 @@ where /// ``` #[ derive( Debug, Default ) ] -pub struct HashMapSubformer< K, E, Formed, Context, End > +pub struct HashMapSubformer< K, E, Descriptor, Context, End > where - K : core::cmp::Eq + core::hash::Hash, - Formed : HashMapLike< K, E > + core::default::Default, - End : FormingEnd< Formed, Context >, + K : ::core::cmp::Eq + ::core::hash::Hash, + // Formed : HashMapLike< K, E > + ::core::default::Default, + End : FormingEnd< Descriptor, Context >, + Descriptor : FormerDescriptor, + Descriptor::Storage : ContainerAdd< Element = ( K, E ) >, { - formed : core::option::Option< Formed >, - context : core::option::Option< Context >, - on_end : core::option::Option< End >, - _e_phantom : core::marker::PhantomData< E >, - _k_phantom : core::marker::PhantomData< K >, + // xxx : rename + formed : ::core::option::Option< Descriptor::Storage >, + context : ::core::option::Option< Context >, + on_end : ::core::option::Option< End >, + _e_phantom : ::core::marker::PhantomData< E >, + _k_phantom : ::core::marker::PhantomData< K >, } -impl< K, E, Formed, Context, End > -HashMapSubformer< K, E, Formed, Context, End > +impl< K, E, Descriptor, Context, End > +HashMapSubformer< K, E, Descriptor, Context, End > where - K : core::cmp::Eq + core::hash::Hash, - Formed : HashMapLike< K, E > + core::default::Default, - End : FormingEnd< Formed, Context >, + K : ::core::cmp::Eq + ::core::hash::Hash, + // Formed : HashMapLike< K, E > + ::core::default::Default, + End : FormingEnd< Descriptor, Context >, + Descriptor : FormerDescriptor, + Descriptor::Storage : ContainerAdd< Element = ( K, E ) >, { /// Form current former into target structure. #[ inline( always ) ] - pub fn form( mut self ) -> Formed + pub fn preform( mut self ) -> Descriptor::Storage { let formed = if self.formed.is_some() { @@ -126,41 +164,51 @@ where val }; formed + // formed.preform() } + // xxx /// Make a new HashMapSubformer. It should be called by a context generated for your structure. /// The context is returned after completion of forming by function `on_end``. #[ inline( always ) ] pub fn begin ( - formed : core::option::Option< Formed >, - context : core::option::Option< Context >, + formed : ::core::option::Option< Descriptor::Storage >, + context : ::core::option::Option< Context >, on_end : End, - ) -> Self + ) + -> Self { Self { formed, context, on_end : Some( on_end ), - _e_phantom : core::marker::PhantomData, - _k_phantom : core::marker::PhantomData, + _e_phantom : ::core::marker::PhantomData, + _k_phantom : ::core::marker::PhantomData, } } /// Return context of your struct moving formed there. Should be called after configuring the formed. #[ inline( always ) ] - pub fn end( mut self ) -> Context + pub fn form( mut self ) -> Descriptor::Formed + { + self.end() + } + + /// Return context of your struct moving formed there. Should be called after configuring the formed. + #[ inline( always ) ] + pub fn end( mut self ) -> Descriptor::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) + let storage = self.preform(); + on_end.call( storage, context ) } /// Set the whole formed instead of setting each element individually. #[ inline( always ) ] - pub fn replace( mut self, formed : Formed ) -> Self + pub fn replace( mut self, formed : Descriptor::Storage ) -> Self { self.formed = Some( formed ); self @@ -168,15 +216,13 @@ where } -// impl< E, Formed > VectorSubformer< E, Formed, Formed, crate::ReturnFormed > -// where -// Formed : VectorLike< E > + core::default::Default, - -impl< K, E, Formed > -HashMapSubformer< K, E, Formed, Formed, crate::ReturnFormed > +impl< K, E, Descriptor > +HashMapSubformer< K, E, Descriptor, (), crate::ReturnStorage > where - K : core::cmp::Eq + core::hash::Hash, - Formed : HashMapLike< K, E > + core::default::Default, + K : ::core::cmp::Eq + ::core::hash::Hash, + Descriptor : FormerDescriptor, + Descriptor::Storage : ContainerAdd< Element = ( K, E ) >, + // Formed : HashMapLike< K, E > + ::core::default::Default, { /// Create a new instance without context or on end processing. It just returns continaer on end of forming. @@ -187,18 +233,20 @@ where ( None, None, - crate::ReturnFormed, + crate::ReturnStorage, ) } } -impl< K, E, Formed, Context, End > -HashMapSubformer< K, E, Formed, Context, End > +impl< K, E, Descriptor, Context, End > +HashMapSubformer< K, E, Descriptor, Context, End > where - K : core::cmp::Eq + core::hash::Hash, - Formed : HashMapLike< K, E > + core::default::Default, - End : FormingEnd< Formed, Context >, + K : ::core::cmp::Eq + ::core::hash::Hash, + // Formed : HashMapLike< K, E > + ::core::default::Default, + End : FormingEnd< Descriptor, Context >, + Descriptor : FormerDescriptor, + Descriptor::Storage : ContainerAdd< Element = ( K, E ) >, { /// Inserts a key-value pair into the formed. If the formed doesn't exist, it is created. @@ -211,18 +259,20 @@ where /// Returns `self` for chaining further insertions or operations. /// #[ inline( always ) ] - pub fn insert< K2, E2 >( mut self, k : K2, e : E2 ) -> Self + pub fn insert< K2, E2 >( self, k : K2, e : E2 ) -> Self where - K2 : core::convert::Into< K >, - E2 : core::convert::Into< E >, + K2 : ::core::convert::Into< K >, + E2 : ::core::convert::Into< E >, + // Descriptor::Storage : ContainerAdd< Element = ( K, E ) >, { if self.formed.is_none() { - self.formed = core::option::Option::Some( Default::default() ); + self.formed = ::core::option::Option::Some( Default::default() ); } - if let core::option::Option::Some( ref mut formed ) = self.formed + if let ::core::option::Option::Some( ref mut formed ) = self.formed { - formed.insert( k.into(), e.into() ); + ContainerAdd::add( formed, ( k.into(), e.into() ) ); + // formed.insert( k.into(), e.into() ); } self } @@ -239,8 +289,8 @@ where #[ inline( always ) ] pub fn push< K2, E2 >( self, k : K2, e : E2 ) -> Self where - K2 : core::convert::Into< K >, - E2 : core::convert::Into< E >, + K2 : ::core::convert::Into< K >, + E2 : ::core::convert::Into< E >, { self.insert( k, e ) } diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 20a521d3f6..2222a7461c 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -15,24 +15,64 @@ use collection_tools::HashSet; /// Implementing `HashSetLike` for `std::collections::HashSet`: /// -pub trait HashSetLike< E > +pub trait HashSetLike< K > where - E : core::cmp::Eq + core::hash::Hash, + K : core::cmp::Eq + core::hash::Hash, { /// Inserts a key-value pair into the map. - fn insert( &mut self, element : E ) -> Option< E >; + fn insert( &mut self, element : K ) -> Option< K >; } -impl< E > HashSetLike< E > for HashSet< E > +impl< K > HashSetLike< K > for HashSet< K > where - E : core::cmp::Eq + core::hash::Hash, + K : core::cmp::Eq + core::hash::Hash, { - fn insert( &mut self, element : E ) -> Option< E > + fn insert( &mut self, element : K ) -> Option< K > { HashSet::replace( self, element ) } } +// + +pub struct HashSetDescriptor< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + _phantom : ::core::marker::PhantomData< ( K, K ) >, +} + +impl< K > HashSetDescriptor< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + fn new() -> Self + { + Self { _phantom : ::core::marker::PhantomData } + } +} + +impl< K > StoragePerform +for HashSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Formed = Self; + fn preform( self ) -> Self::Formed + { + self + } +} + +impl< K > FormerDescriptor +for HashSetDescriptor< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Storage = HashSet< K >; + type Formed = HashSet< K >; +} + /// Facilitates building `HashSetLike` containers with a fluent API. /// /// `HashSetSubformer` leverages the `HashSetLike` trait to enable a concise and expressive way @@ -66,29 +106,30 @@ where /// ``` #[ derive( Debug, Default ) ] -pub struct HashSetSubformer< E, Formed, Context, ContainerEnd > +pub struct HashSetSubformer< K, Context, End > where - E : core::cmp::Eq + core::hash::Hash, - Formed : HashSetLike< E > + core::default::Default, - ContainerEnd : FormingEnd< Formed, Context >, + K : core::cmp::Eq + core::hash::Hash, + // Formed : HashSetLike< K > + core::default::Default, + End : FormingEnd< HashSetDescriptor< K >, Context >, { - formed : core::option::Option< Formed >, + formed : core::option::Option< < HashSetDescriptor< K > as axiomatic::FormerDescriptor >::Formed >, + // xxx : rename context : core::option::Option< Context >, - on_end : core::option::Option< ContainerEnd >, - _e_phantom : core::marker::PhantomData< E >, + on_end : core::option::Option< End >, + _e_phantom : core::marker::PhantomData< K >, } -impl< E, Formed, Context, ContainerEnd > -HashSetSubformer< E, Formed, Context, ContainerEnd > +impl< K, Context, End > +HashSetSubformer< K, Context, End > where - E : core::cmp::Eq + core::hash::Hash, - Formed : HashSetLike< E > + core::default::Default, - ContainerEnd : FormingEnd< Formed, Context >, + K : core::cmp::Eq + core::hash::Hash, + // Formed : HashSetLike< K > + core::default::Default, + End : FormingEnd< HashSetDescriptor< K >, Context >, { /// Form current former into target structure. #[ inline( always ) ] - pub fn form( mut self ) -> Formed + pub fn form( mut self ) -> < HashSetDescriptor< K > as axiomatic::FormerDescriptor >::Formed { let formed = if self.formed.is_some() { @@ -101,6 +142,7 @@ where }; formed } + // xxx /// Begins the building process with an optional context and formed. /// @@ -115,9 +157,9 @@ where #[ inline( always ) ] pub fn begin ( - formed : core::option::Option< Formed >, + formed : core::option::Option< < HashSetDescriptor< K > as axiomatic::FormerDescriptor >::Formed >, context : core::option::Option< Context >, - on_end : ContainerEnd, + on_end : End, ) -> Self { Self @@ -140,7 +182,7 @@ where /// constructed formed or a context that incorporates the formed. /// #[ inline( always ) ] - pub fn end( mut self ) -> Context + pub fn end( mut self ) -> < HashSetDescriptor< K > as axiomatic::FormerDescriptor >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); @@ -161,7 +203,7 @@ where /// The builder instance with the formed replaced, enabling further chained operations. /// #[ inline( always ) ] - pub fn replace( mut self, formed : Formed ) -> Self + pub fn replace( mut self, formed : < HashSetDescriptor< K > as axiomatic::FormerDescriptor >::Formed ) -> Self { self.formed = Some( formed ); self @@ -169,17 +211,17 @@ where } -// impl< E, Formed > VectorSubformer< E, Formed, Formed, crate::ReturnFormed > +// impl< K > VectorSubformer< K, Formed, crate::ReturnStorage > // where -// Formed : VectorLike< E > + core::default::Default, +// Formed : VectorLike< K > + core::default::Default, // { -impl< E, Formed > -HashSetSubformer< E, Formed, Formed, crate::ReturnFormed > +impl< K > +HashSetSubformer< K, (), crate::ReturnStorage > where - E : core::cmp::Eq + core::hash::Hash, - Formed : HashSetLike< E > + core::default::Default, - // ContainerEnd : FormingEnd< Formed, Context >, + K : core::cmp::Eq + core::hash::Hash, + // Formed : HashSetLike< K > + core::default::Default, + // End : FormingEnd< HashSetDescriptor< K >, Context >, { /// Initializes a new instance of the builder with default settings. @@ -197,18 +239,18 @@ where ( None, None, - crate::ReturnFormed, + crate::ReturnStorage, ) } } -impl< E, Formed, Context, ContainerEnd > -HashSetSubformer< E, Formed, Context, ContainerEnd > +impl< K, Context, End > +HashSetSubformer< K, Context, End > where - E : core::cmp::Eq + core::hash::Hash, - Formed : HashSetLike< E > + core::default::Default, - ContainerEnd : FormingEnd< Formed, Context >, + K : core::cmp::Eq + core::hash::Hash, + // Formed : HashSetLike< K > + core::default::Default, + End : FormingEnd< HashSetDescriptor< K >, Context >, { /// Inserts an element into the set, possibly replacing an existing element. @@ -226,7 +268,7 @@ where #[ inline( always ) ] pub fn insert< E2 >( mut self, element : E2 ) -> Self where - E2 : core::convert::Into< E >, + E2 : core::convert::Into< K >, { if self.formed.is_none() { diff --git a/module/core/former/src/lib.rs b/module/core/former/src/lib.rs index c3fdf25c49..978805cca1 100644 --- a/module/core/former/src/lib.rs +++ b/module/core/former/src/lib.rs @@ -9,6 +9,7 @@ /// Axiomatic things. #[ cfg( feature = "enabled" ) ] #[ cfg( feature = "derive_former" ) ] +#[ path = "axiomatic3.rs" ] mod axiomatic; /// Interface for containers. @@ -20,6 +21,7 @@ mod container; #[ cfg( feature = "enabled" ) ] #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] #[ cfg( feature = "derive_former" ) ] +#[ path = "vector3.rs" ] mod vector; /// Former of a hash map. #[ cfg( feature = "enabled" ) ] @@ -38,6 +40,7 @@ mod hash_set; mod component; // mod axiomatic2; +// mod axiomatic3; // mod vector2; // mod vector3; diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 46426d8733..1f3cfef82c 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -93,7 +93,7 @@ where // ( // None, // None, - // crate::ReturnFormed, + // crate::ReturnStorage, // ) // } @@ -135,7 +135,7 @@ where } -impl< E, Formed > VectorSubformer< E, Formed, Formed, crate::ReturnFormed > +impl< E, Formed > VectorSubformer< E, Formed, Formed, crate::ReturnStorage > where Formed : VectorLike< E > + core::default::Default, { @@ -153,7 +153,7 @@ where ( None, None, - crate::ReturnFormed, + crate::ReturnStorage, ) } diff --git a/module/core/former/src/vector3.rs b/module/core/former/src/vector3.rs index 4df4958ce3..005fd52025 100644 --- a/module/core/former/src/vector3.rs +++ b/module/core/former/src/vector3.rs @@ -1,5 +1,5 @@ use super::*; -use axiomatic2::*; +use axiomatic::*; #[ allow( unused ) ] use collection_tools::Vec; @@ -9,13 +9,13 @@ use collection_tools::Vec; /// 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 VectorLike2< E > +pub trait VectorLike< E > { /// Appends an element to the back of a formed. fn push( &mut self, element : E ); } -impl< E > VectorLike2< E > for Vec< E > +impl< E > VectorLike< E > for Vec< E > { fn push( &mut self, element : E ) { @@ -23,20 +23,12 @@ impl< E > VectorLike2< E > for Vec< E > } } -impl< E > StoragePerform for Vec< E > -{ - type Formed = Self; - fn preform( self ) -> Self::Formed - { - self - } -} -pub struct VectorSubformerDescriptor< E > +pub struct VectorDescriptor< E > { _phantom : core::marker::PhantomData< E >, } -impl< E > VectorSubformerDescriptor< E > +impl< E > VectorDescriptor< E > { fn new() -> Self { @@ -44,37 +36,45 @@ impl< E > VectorSubformerDescriptor< E > } } +impl< E > StoragePerform +for Vec< E > +{ + type Formed = Self; + fn preform( self ) -> Self::Formed + { + self + } +} + impl< E > FormerDescriptor -for VectorSubformerDescriptor< E > +for VectorDescriptor< E > { type Storage = Vec< E >; type Formed = Vec< E >; - // type Former = VectorSubformer2< E, Context, End >; } -/// A builder for constructing `VectorLike2` containers, facilitating a fluent and flexible interface. +/// A builder for constructing `VectorLike` containers, facilitating a fluent and flexible interface. /// -/// `VectorSubformer2` leverages the `VectorLike2` trait to enable the construction and manipulation +/// `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. -/// #[ derive( Debug, Default ) ] -pub struct VectorSubformer2< E, Context, End > +pub struct VectorSubformer< E, Context, End > where - End : FormingEnd2< VectorSubformerDescriptor< E >, Context >, + End : FormingEnd< VectorDescriptor< E >, Context >, { - formed : core::option::Option< < VectorSubformerDescriptor< E > as axiomatic2::FormerDescriptor >::Formed >, + formed : core::option::Option< < VectorDescriptor< E > as axiomatic::FormerDescriptor >::Formed >, context : core::option::Option< Context >, on_end : core::option::Option< End >, } -impl< E, Context, End > VectorSubformer2< E, Context, End > +impl< E, Context, End > VectorSubformer< E, Context, End > where - End : FormingEnd2< VectorSubformerDescriptor< E >, Context >, + End : FormingEnd< VectorDescriptor< E >, Context >, { /// Form current former into target structure. #[ inline( always ) ] - pub fn form( mut self ) -> < VectorSubformerDescriptor< E > as axiomatic2::FormerDescriptor >::Formed + pub fn form( mut self ) -> < VectorDescriptor< E > as axiomatic::FormerDescriptor >::Formed { let formed = if self.formed.is_some() { @@ -92,7 +92,7 @@ where #[ inline( always ) ] pub fn begin ( - formed : core::option::Option< < VectorSubformerDescriptor< E > as axiomatic2::FormerDescriptor >::Formed >, + formed : core::option::Option< < VectorDescriptor< E > as axiomatic::FormerDescriptor >::Formed >, context : core::option::Option< Context >, on_end : End ) -> Self @@ -107,7 +107,7 @@ where /// Finalizes the building process, returning the formed or a context incorporating it. #[ inline( always ) ] - pub fn end( mut self ) -> < VectorSubformerDescriptor< E > as axiomatic2::FormerDescriptor >::Formed + pub fn end( mut self ) -> < VectorDescriptor< E > as axiomatic::FormerDescriptor >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); @@ -117,7 +117,7 @@ where /// Replaces the current formed with a provided one, allowing for a reset or redirection of the building process. #[ inline( always ) ] - pub fn replace( mut self, vector : < VectorSubformerDescriptor< E > as axiomatic2::FormerDescriptor >::Formed ) -> Self + pub fn replace( mut self, vector : < VectorDescriptor< E > as axiomatic::FormerDescriptor >::Formed ) -> Self { self.formed = Some( vector ); self @@ -125,15 +125,15 @@ where } -impl< E > VectorSubformer2< E, (), ReturnStorage2 > +impl< E > VectorSubformer< E, (), ReturnStorage > where { - /// Initializes a new `VectorSubformer2` instance, starting with an empty formed. + /// Initializes a new `VectorSubformer` instance, starting with an empty formed. /// This function serves as the entry point for the builder pattern. /// /// # Returns - /// A new instance of `VectorSubformer2` with an empty internal formed. + /// A new instance of `VectorSubformer` with an empty internal formed. /// #[ inline( always ) ] pub fn new() -> Self @@ -142,21 +142,21 @@ where ( None, None, - ReturnStorage2, + ReturnStorage, ) } } -impl< E, Context, End > VectorSubformer2< E, Context, End > +impl< E, Context, End > VectorSubformer< E, Context, End > where - End : FormingEnd2< VectorSubformerDescriptor< E >, Context >, + End : FormingEnd< VectorDescriptor< E >, Context >, { /// Appends an element to the end of the formed, expanding the internal collection. #[ inline( always ) ] - pub fn push< E2 >( mut self, element : E2 ) -> Self - where E2 : core::convert::Into< E >, + pub fn push< IntoElement >( mut self, element : IntoElement ) -> Self + where IntoElement : core::convert::Into< E >, { if self.formed.is_none() { @@ -174,10 +174,10 @@ where // // impl< Former, Context, End > FormerBegin< Formed, Formed, Context > -// for VectorSubformer2< Former, Context, End > +// for VectorSubformer< Former, Context, End > // where -// End : FormingEnd2< VectorSubformerDescriptor< E >, Context >, -// // Formed : VectorLike2< E > + Default, +// End : FormingEnd< VectorDescriptor< E >, Context >, +// // Formed : VectorLike< E > + Default, // Former : FormerDescriptor, // { // type End = End; diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs index 87a3bec1eb..eaa107c5de 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs @@ -13,9 +13,9 @@ pub struct Struct1 impl Struct1 { - pub fn former() -> Struct1Former< Struct1, the_module::ReturnFormed > + pub fn former() -> Struct1Former< Struct1, the_module::ReturnStorage > { - Struct1Former::< Struct1, the_module::ReturnFormed >::new() + Struct1Former::< Struct1, the_module::ReturnStorage >::new() } } @@ -48,7 +48,7 @@ impl Default for Struct1FormerStorage pub struct Struct1Former < Context = Struct1, - End = the_module::ReturnFormed, + End = the_module::ReturnStorage, > where End : the_module::FormingEnd< Struct1, Context >, @@ -114,13 +114,13 @@ where } // #[ inline( always ) ] - // pub fn new() -> Struct1Former + // pub fn new() -> Struct1Former // { // Struct1Former:: // < // Struct1, - // the_module::ReturnFormed, - // >::begin(None, the_module::ReturnFormed) + // the_module::ReturnStorage, + // >::begin(None, the_module::ReturnStorage) // } #[ inline( always ) ] @@ -252,13 +252,13 @@ where // where // End: the_module::FormingEnd, -impl Struct1Former< Struct1, the_module::ReturnFormed > +impl Struct1Former< Struct1, the_module::ReturnStorage > { #[ inline( always ) ] pub fn new() -> Self { - Self::begin( None, None, the_module::ReturnFormed ) + Self::begin( None, None, the_module::ReturnStorage ) } } diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs index 9bea46cff7..fa6236f5d1 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs @@ -13,9 +13,9 @@ pub struct Struct1 impl Struct1 { - pub fn former() -> Struct1Former< Struct1, the_module::ReturnFormed > + pub fn former() -> Struct1Former< Struct1, the_module::ReturnStorage > { - Struct1Former::< Struct1, the_module::ReturnFormed >::new() + Struct1Former::< Struct1, the_module::ReturnStorage >::new() } } @@ -48,7 +48,7 @@ impl Default for Struct1FormerStorage pub struct Struct1Former < __FormerContext = Struct1, - __FormerEnd = the_module::ReturnFormed, + __FormerEnd = the_module::ReturnStorage, > where __FormerEnd : the_module::FormingEnd< Struct1, __FormerContext >, @@ -114,13 +114,13 @@ where } #[ inline( always ) ] - pub fn new() -> Struct1Former + pub fn new() -> Struct1Former { Struct1Former:: < Struct1, - the_module::ReturnFormed, - >::begin(None, the_module::ReturnFormed) + the_module::ReturnStorage, + >::begin(None, the_module::ReturnStorage) } #[ inline( always ) ] diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 0c5a011178..5461d21cff 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -15,9 +15,9 @@ pub struct Struct1 // generated by former impl Struct1 { - pub fn former() -> Struct1Former< Struct1, the_module::ReturnFormed > + pub fn former() -> Struct1Former< Struct1, the_module::ReturnStorage > { - Struct1Former::< Struct1, the_module::ReturnFormed >::new() + Struct1Former::< Struct1, the_module::ReturnStorage >::new() } } @@ -54,7 +54,7 @@ impl Default for Struct1FormerStorage pub struct Struct1Former < __FormerContext = Struct1, - __FormerEnd = the_module::ReturnFormed, + __FormerEnd = the_module::ReturnStorage, > where __FormerEnd : the_module::FormingEnd< Struct1, __FormerContext >, @@ -128,13 +128,13 @@ where } #[ inline( always ) ] - pub fn new() -> Struct1Former + pub fn new() -> Struct1Former { Struct1Former:: < Struct1, - the_module::ReturnFormed, - >::begin(None, the_module::ReturnFormed) + the_module::ReturnStorage, + >::begin(None, the_module::ReturnStorage) } #[ inline( always ) ] diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index ae57ca7e08..18d778bf2b 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -73,7 +73,7 @@ where // generated by former // #[ derive( Debug, Default ) ] -pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnFormed > +pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnStorage > where K : core::hash::Hash + std::cmp::Eq, End : the_module::FormingEnd< Command< K >, Context >, @@ -135,7 +135,7 @@ where ( None, None, - the_module::ReturnFormed, + the_module::ReturnStorage, ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs b/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs index cbb94f6e73..3acfa5bc03 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs @@ -93,7 +93,7 @@ where // generated by former // #[ derive( Debug, Default ) ] -pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnFormed > +pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnStorage > where K : core::hash::Hash + std::cmp::Eq, End : the_module::FormingEnd< Command< K >, Context >, @@ -166,7 +166,7 @@ where ( None, None, - the_module::ReturnFormed, + the_module::ReturnStorage, ) } @@ -301,7 +301,7 @@ where // generated by former // #[ derive( Debug, Default ) ] -pub struct AggregatorFormer< K, Context = Aggregator< K >, End = the_module::ReturnFormed > +pub struct AggregatorFormer< K, Context = Aggregator< K >, End = the_module::ReturnStorage > where K : core::hash::Hash + std::cmp::Eq, End : the_module::FormingEnd< Aggregator< K >, Context >, @@ -363,7 +363,7 @@ where AggregatorFormer::< K >::begin ( None, - the_module::ReturnFormed, + the_module::ReturnStorage, ) } diff --git a/module/core/former/tests/inc/only_test/containers_with_runtime.rs b/module/core/former/tests/inc/only_test/containers_with_runtime.rs index ceeb84abaa..02986f54d0 100644 --- a/module/core/former/tests/inc/only_test/containers_with_runtime.rs +++ b/module/core/former/tests/inc/only_test/containers_with_runtime.rs @@ -18,8 +18,8 @@ tests_impls_optional! a_id!( former.storage.hashmap_strings_1, None ); a_id!( former.storage.hashset_strings_1, None ); a_id!( former.context, None ); - a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnFormed ) ) ); - let former2 = Struct1Former::< Struct1, the_module::ReturnFormed >::new(); + a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnStorage ) ) ); + let former2 = Struct1Former::< Struct1, the_module::ReturnStorage >::new(); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); diff --git a/module/core/former/tests/inc/only_test/containers_without_runtime.rs b/module/core/former/tests/inc/only_test/containers_without_runtime.rs index 8141ddc9fd..3ffdb7dc94 100644 --- a/module/core/former/tests/inc/only_test/containers_without_runtime.rs +++ b/module/core/former/tests/inc/only_test/containers_without_runtime.rs @@ -18,8 +18,8 @@ tests_impls! a_id!( former.storage.hashmap_strings_1, None ); a_id!( former.storage.hashset_strings_1, None ); a_id!( former.context, None ); - a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnFormed ) ) ); - let former2 = Struct1Former::< Struct1, the_module::ReturnFormed >::new(); + a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnStorage ) ) ); + let former2 = Struct1Former::< Struct1, the_module::ReturnStorage >::new(); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); diff --git a/module/core/former/tests/inc/only_test/primitives.rs b/module/core/former/tests/inc/only_test/primitives.rs index 728105b6ad..1f82d9c424 100644 --- a/module/core/former/tests/inc/only_test/primitives.rs +++ b/module/core/former/tests/inc/only_test/primitives.rs @@ -23,8 +23,8 @@ tests_impls! a_id!( former.storage.int_optional_1, None ); a_id!( former.storage.string_optional_1, None ); a_id!( former.context, None ); - a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnFormed ) ) ); - let former2 = Struct1Former::< Struct1, the_module::ReturnFormed >::new(); + a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnStorage ) ) ); + let former2 = Struct1Former::< Struct1, the_module::ReturnStorage >::new(); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 5ca9feb66c..e3c1375893 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -842,7 +842,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // add embedded generic parameters let mut extra_generics : syn::Generics = parse_quote! { - < __FormerContext = #name_ident #generics_ty, __FormerEnd = former::ReturnFormed > + < __FormerContext = #name_ident #generics_ty, __FormerEnd = former::ReturnStorage > }; extra_generics.where_clause = parse_quote! { @@ -922,9 +922,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// Make former, variation of builder pattern to form structure defining values of fields step by step. /// #[ inline( always ) ] - pub fn former() -> #former_name_ident < #generics_params #name_ident #generics_ty, former::ReturnFormed > + pub fn former() -> #former_name_ident < #generics_params #name_ident #generics_ty, former::ReturnStorage > { - #former_name_ident :: < #generics_params #name_ident #generics_ty, former::ReturnFormed > :: new() + #former_name_ident :: < #generics_params #name_ident #generics_ty, former::ReturnStorage > :: new() } } @@ -1040,7 +1040,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } #[ automatically_derived ] - impl #generics_impl #former_name_ident < #generics_params #name_ident #generics_ty, former::ReturnFormed > + impl #generics_impl #former_name_ident < #generics_params #name_ident #generics_ty, former::ReturnStorage > #generics_where { @@ -1050,12 +1050,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ inline( always ) ] pub fn new() -> Self { - // #former_name_ident :: < #generics_params #name_ident #generics_ty, former::ReturnFormed > :: begin + // #former_name_ident :: < #generics_params #name_ident #generics_ty, former::ReturnStorage > :: begin Self :: begin ( None, None, - former::ReturnFormed, + former::ReturnStorage, ) } diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index e02c582eaf..1c13e11236 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -119,9 +119,9 @@ mod derive /// impl UserProfile /// { /// #[ inline( always ) ] -/// pub fn former() -> UserProfileFormer< UserProfile, former::ReturnFormed > +/// pub fn former() -> UserProfileFormer< UserProfile, former::ReturnStorage > /// { -/// UserProfileFormer::< UserProfile, former::ReturnFormed >::new() +/// UserProfileFormer::< UserProfile, former::ReturnStorage >::new() /// } /// } /// @@ -136,7 +136,7 @@ mod derive /// pub struct UserProfileFormer /// < /// Context = UserProfile, -/// End = former::ReturnFormed, +/// End = former::ReturnStorage, /// > /// where /// End : former::FormingEnd< UserProfile, Context >, @@ -189,9 +189,9 @@ mod derive /// /// // qqq : xxx : outdated, update /// #[ inline( always ) ] -/// pub fn new() -> UserProfileFormer< UserProfile, former::ReturnFormed > +/// pub fn new() -> UserProfileFormer< UserProfile, former::ReturnStorage > /// { -/// UserProfileFormer::< UserProfile, former::ReturnFormed >::begin( None, former::ReturnFormed ) +/// UserProfileFormer::< UserProfile, former::ReturnStorage >::begin( None, former::ReturnStorage ) /// } /// /// #[ inline( always ) ] From 590e5bc6226dd763bf29c3cfe0eb960ff1583d99 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 09:17:27 +0200 Subject: [PATCH 002/533] former : experimenting --- module/core/former/src/hash_map.rs | 58 ++++++++------- module/core/former/src/hash_set.rs | 99 +++++++++++++++---------- module/core/former/src/vector3.rs | 115 +++++++++++++++++------------ 3 files changed, 157 insertions(+), 115 deletions(-) diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 4f70292512..7837743d90 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -47,6 +47,7 @@ where // +#[ derive( Debug ) ] pub struct HashMapDescriptor< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, @@ -58,7 +59,7 @@ impl< K, E > HashMapDescriptor< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn new() -> Self + pub fn new() -> Self { Self { _phantom : ::core::marker::PhantomData } } @@ -132,8 +133,7 @@ where Descriptor : FormerDescriptor, Descriptor::Storage : ContainerAdd< Element = ( K, E ) >, { - // xxx : rename - formed : ::core::option::Option< Descriptor::Storage >, + storage : ::core::option::Option< Descriptor::Storage >, context : ::core::option::Option< Context >, on_end : ::core::option::Option< End >, _e_phantom : ::core::marker::PhantomData< E >, @@ -152,28 +152,30 @@ where /// Form current former into target structure. #[ inline( always ) ] - pub fn preform( mut self ) -> Descriptor::Storage + pub fn storage( mut self ) -> Descriptor::Storage { - let formed = if self.formed.is_some() + // xxx + let storage = if self.storage.is_some() { - self.formed.take().unwrap() + self.storage.take().unwrap() } else { let val = Default::default(); val }; - formed - // formed.preform() + storage + // storage.preform() } // xxx + /// Make a new HashMapSubformer. It should be called by a context generated for your structure. /// The context is returned after completion of forming by function `on_end``. #[ inline( always ) ] pub fn begin ( - formed : ::core::option::Option< Descriptor::Storage >, + storage : ::core::option::Option< Descriptor::Storage >, context : ::core::option::Option< Context >, on_end : End, ) @@ -181,7 +183,7 @@ where { Self { - formed, + storage, context, on_end : Some( on_end ), _e_phantom : ::core::marker::PhantomData, @@ -189,28 +191,28 @@ where } } - /// Return context of your struct moving formed there. Should be called after configuring the formed. - #[ inline( always ) ] - pub fn form( mut self ) -> Descriptor::Formed - { - self.end() - } - - /// Return context of your struct moving formed there. Should be called after configuring the formed. + /// Return context of your struct moving formed there. Should be called after forming process. #[ inline( always ) ] pub fn end( mut self ) -> Descriptor::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - let storage = self.preform(); + let storage = self.storage(); on_end.call( storage, context ) } - /// Set the whole formed instead of setting each element individually. + /// Return context of your struct moving formed there. Should be called after forming process. + #[ inline( always ) ] + pub fn form( self ) -> Descriptor::Formed + { + self.end() + } + + /// Set the whole storage instead of setting each element individually. #[ inline( always ) ] - pub fn replace( mut self, formed : Descriptor::Storage ) -> Self + pub fn replace( mut self, storage : Descriptor::Storage ) -> Self { - self.formed = Some( formed ); + self.storage = Some( storage ); self } @@ -259,20 +261,20 @@ where /// Returns `self` for chaining further insertions or operations. /// #[ inline( always ) ] - pub fn insert< K2, E2 >( self, k : K2, e : E2 ) -> Self + pub fn insert< K2, E2 >( mut self, k : K2, e : E2 ) -> Self where K2 : ::core::convert::Into< K >, E2 : ::core::convert::Into< E >, // Descriptor::Storage : ContainerAdd< Element = ( K, E ) >, { - if self.formed.is_none() + if self.storage.is_none() { - self.formed = ::core::option::Option::Some( Default::default() ); + self.storage = ::core::option::Option::Some( Default::default() ); } - if let ::core::option::Option::Some( ref mut formed ) = self.formed + if let ::core::option::Option::Some( ref mut storage ) = self.storage { - ContainerAdd::add( formed, ( k.into(), e.into() ) ); - // formed.insert( k.into(), e.into() ); + ContainerAdd::add( storage, ( k.into(), e.into() ) ); + // storage.insert( k.into(), e.into() ); } self } diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 2222a7461c..3b662e7f25 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -35,6 +35,7 @@ where // +#[ derive( Debug ) ] pub struct HashSetDescriptor< K > where K : ::core::cmp::Eq + ::core::hash::Hash, @@ -46,7 +47,7 @@ impl< K > HashSetDescriptor< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn new() -> Self + pub fn new() -> Self { Self { _phantom : ::core::marker::PhantomData } } @@ -106,65 +107,68 @@ where /// ``` #[ derive( Debug, Default ) ] -pub struct HashSetSubformer< K, Context, End > +pub struct HashSetSubformer< K, Descriptor, Context, End > where K : core::cmp::Eq + core::hash::Hash, // Formed : HashSetLike< K > + core::default::Default, - End : FormingEnd< HashSetDescriptor< K >, Context >, + End : FormingEnd< Descriptor, Context >, + Descriptor : FormerDescriptor, + Descriptor::Storage : ContainerAdd< Element = K >, { - formed : core::option::Option< < HashSetDescriptor< K > as axiomatic::FormerDescriptor >::Formed >, - // xxx : rename + storage : core::option::Option< Descriptor::Storage >, context : core::option::Option< Context >, on_end : core::option::Option< End >, _e_phantom : core::marker::PhantomData< K >, } -impl< K, Context, End > -HashSetSubformer< K, Context, End > +impl< K, Descriptor, Context, End > +HashSetSubformer< K, Descriptor, Context, End > where K : core::cmp::Eq + core::hash::Hash, // Formed : HashSetLike< K > + core::default::Default, - End : FormingEnd< HashSetDescriptor< K >, Context >, + End : FormingEnd< Descriptor, Context >, + Descriptor : FormerDescriptor, + Descriptor::Storage : ContainerAdd< Element = K >, { /// Form current former into target structure. #[ inline( always ) ] - pub fn form( mut self ) -> < HashSetDescriptor< K > as axiomatic::FormerDescriptor >::Formed + pub fn storage( mut self ) -> Descriptor::Storage { - let formed = if self.formed.is_some() + let storage = if self.storage.is_some() { - self.formed.take().unwrap() + self.storage.take().unwrap() } else { let val = Default::default(); val }; - formed + storage } // xxx - /// Begins the building process with an optional context and formed. + /// Begins the building process with an optional context and storage. /// /// This method is typically called internally by the builder but can be used directly /// to initialize the builder with specific contexts or containers. /// /// # Parameters /// - `context`: An optional context for the building process. - /// - `formed`: An optional initial formed to populate. + /// - `storage`: An optional initial storage to populate. /// - `on_end`: A handler to be called at the end of the building process. /// #[ inline( always ) ] pub fn begin ( - formed : core::option::Option< < HashSetDescriptor< K > as axiomatic::FormerDescriptor >::Formed >, + storage : core::option::Option< Descriptor::Storage >, context : core::option::Option< Context >, on_end : End, ) -> Self { Self { - formed, + storage, context : context, on_end : Some( on_end ), _e_phantom : core::marker::PhantomData, @@ -182,30 +186,46 @@ where /// constructed formed or a context that incorporates the formed. /// #[ inline( always ) ] - pub fn end( mut self ) -> < HashSetDescriptor< K > as axiomatic::FormerDescriptor >::Formed + pub fn form( self ) -> Descriptor::Formed + { + self.end() + } + + /// Finalizes the building process and returns the constructed formed or a context. + /// + /// This method concludes the building process by applying the `on_end` handler to transform + /// the formed or incorporate it into a given context. It's typically called at the end + /// of the builder chain to retrieve the final product of the building process. + /// + /// # Returns + /// Depending on the `on_end` handler's implementation, this method can return either the + /// constructed formed or a context that incorporates the formed. + /// + #[ inline( always ) ] + pub fn end( mut self ) -> Descriptor::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) + let storage = self.storage(); + on_end.call( storage, context ) } - /// Replaces the current formed with a new one. + /// Replaces the current storage with a new one. /// /// This method allows for replacing the entire set being built with a different one. /// It can be useful in scenarios where a pre-populated set needs to be modified or /// replaced entirely during the building process. /// /// # Parameters - /// - `formed`: The new formed to use for subsequent builder operations. + /// - `storage`: The new storage to use for subsequent builder operations. /// /// # Returns - /// The builder instance with the formed replaced, enabling further chained operations. + /// The builder instance with the storage replaced, enabling further chained operations. /// #[ inline( always ) ] - pub fn replace( mut self, formed : < HashSetDescriptor< K > as axiomatic::FormerDescriptor >::Formed ) -> Self + pub fn replace( mut self, storage : Descriptor::Storage ) -> Self { - self.formed = Some( formed ); + self.storage = Some( storage ); self } @@ -216,18 +236,20 @@ where // Formed : VectorLike< K > + core::default::Default, // { -impl< K > -HashSetSubformer< K, (), crate::ReturnStorage > +impl< K, Descriptor > +HashSetSubformer< K, Descriptor, (), crate::ReturnStorage > where K : core::cmp::Eq + core::hash::Hash, + Descriptor : FormerDescriptor, + Descriptor::Storage : ContainerAdd< Element = K >, // Formed : HashSetLike< K > + core::default::Default, - // End : FormingEnd< HashSetDescriptor< K >, Context >, + // End : FormingEnd< Descriptor, Context >, { /// Initializes a new instance of the builder with default settings. /// - /// This method provides a starting point for building a `HashSetLike` formed using - /// a fluent interface. It sets up an empty formed ready to be populated. + /// This method provides a starting point for forming a `HashSetLike` using + /// a fluent interface. /// /// # Returns /// A new instance of `HashSetSubformer` with no elements. @@ -245,18 +267,19 @@ where } -impl< K, Context, End > -HashSetSubformer< K, Context, End > +impl< K, Descriptor, Context, End > +HashSetSubformer< K, Descriptor, Context, End > where K : core::cmp::Eq + core::hash::Hash, - // Formed : HashSetLike< K > + core::default::Default, - End : FormingEnd< HashSetDescriptor< K >, Context >, + End : FormingEnd< Descriptor, Context >, + Descriptor : FormerDescriptor, + Descriptor::Storage : ContainerAdd< Element = K >, { /// Inserts an element into the set, possibly replacing an existing element. /// /// This method ensures that the set contains the given element, and if the element - /// was already present, it might replace it depending on the formed's behavior. + /// was already present, it might replace it depending on the storage's behavior. /// /// # Parameters /// - `element`: The element to insert into the set. @@ -270,13 +293,13 @@ where where E2 : core::convert::Into< K >, { - if self.formed.is_none() + if self.storage.is_none() { - self.formed = core::option::Option::Some( Default::default() ); + self.storage = core::option::Option::Some( Default::default() ); } - if let core::option::Option::Some( ref mut formed ) = self.formed + if let core::option::Option::Some( ref mut storage ) = self.storage { - formed.insert( element.into() ); + ContainerAdd::add( storage, element.into() ); } self } diff --git a/module/core/former/src/vector3.rs b/module/core/former/src/vector3.rs index 005fd52025..54517fbd38 100644 --- a/module/core/former/src/vector3.rs +++ b/module/core/former/src/vector3.rs @@ -11,7 +11,7 @@ use collection_tools::Vec; /// pub trait VectorLike< E > { - /// Appends an element to the back of a formed. + /// Appends an element to the back of a storage. fn push( &mut self, element : E ); } @@ -23,6 +23,7 @@ impl< E > VectorLike< E > for Vec< E > } } +#[ derive( Debug ) ] pub struct VectorDescriptor< E > { _phantom : core::marker::PhantomData< E >, @@ -30,7 +31,7 @@ pub struct VectorDescriptor< E > impl< E > VectorDescriptor< E > { - fn new() -> Self + pub fn new() -> Self { Self { _phantom : core::marker::PhantomData } } @@ -58,75 +59,88 @@ for VectorDescriptor< E > /// `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. #[ derive( Debug, Default ) ] -pub struct VectorSubformer< E, Context, End > +pub struct VectorSubformer< E, Descriptor, Context, End > where - End : FormingEnd< VectorDescriptor< E >, Context >, + End : FormingEnd< Descriptor, Context >, + Descriptor : FormerDescriptor, + Descriptor::Storage : ContainerAdd< Element = E >, { - formed : core::option::Option< < VectorDescriptor< E > as axiomatic::FormerDescriptor >::Formed >, + storage : core::option::Option< Descriptor::Storage >, context : core::option::Option< Context >, on_end : core::option::Option< End >, } -impl< E, Context, End > VectorSubformer< E, Context, End > +impl< E, Descriptor, Context, End > VectorSubformer< E, Descriptor, Context, End > where - End : FormingEnd< VectorDescriptor< E >, Context >, + End : FormingEnd< Descriptor, Context >, + Descriptor : FormerDescriptor, + Descriptor::Storage : ContainerAdd< Element = E >, { /// Form current former into target structure. #[ inline( always ) ] - pub fn form( mut self ) -> < VectorDescriptor< E > as axiomatic::FormerDescriptor >::Formed + pub fn storage( mut self ) -> Descriptor::Storage { - let formed = if self.formed.is_some() + let storage = if self.storage.is_some() { - self.formed.take().unwrap() + self.storage.take().unwrap() } else { let val = Default::default(); val }; - formed + storage } - /// Begins the building process, optionally initializing with a context and formed. + /// Begins the building process, optionally initializing with a context and storage. #[ inline( always ) ] pub fn begin ( - formed : core::option::Option< < VectorDescriptor< E > as axiomatic::FormerDescriptor >::Formed >, + storage : core::option::Option< Descriptor::Storage >, context : core::option::Option< Context >, on_end : End ) -> Self { Self { + storage, context, - formed, on_end : Some( on_end ), } } /// Finalizes the building process, returning the formed or a context incorporating it. #[ inline( always ) ] - pub fn end( mut self ) -> < VectorDescriptor< E > as axiomatic::FormerDescriptor >::Formed + pub fn form( self ) -> Descriptor::Formed + { + self.end() + } + + /// Finalizes the building process, returning the formed or a context incorporating it. + #[ inline( always ) ] + pub fn end( mut self ) -> Descriptor::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) + let storage = self.storage(); + on_end.call( storage, context ) } - /// Replaces the current formed with a provided one, allowing for a reset or redirection of the building process. + /// Replaces the current storage with a provided one, allowing for a reset or redirection of the building process. #[ inline( always ) ] - pub fn replace( mut self, vector : < VectorDescriptor< E > as axiomatic::FormerDescriptor >::Formed ) -> Self + pub fn replace( mut self, vector : Descriptor::Storage ) -> Self { - self.formed = Some( vector ); + self.storage = Some( vector ); self } } -impl< E > VectorSubformer< E, (), ReturnStorage > +impl< E, Descriptor > VectorSubformer< E, Descriptor, (), ReturnStorage > where + Descriptor : FormerDescriptor, + Descriptor::Storage : ContainerAdd< Element = E >, { /// Initializes a new `VectorSubformer` instance, starting with an empty formed. @@ -148,23 +162,26 @@ where } -impl< E, Context, End > VectorSubformer< E, Context, End > +impl< E, Descriptor, Context, End > VectorSubformer< E, Descriptor, Context, End > where - End : FormingEnd< VectorDescriptor< E >, Context >, + End : FormingEnd< Descriptor, Context >, + Descriptor : FormerDescriptor, + Descriptor::Storage : ContainerAdd< Element = E >, { - /// Appends an element to the end of the formed, expanding the internal collection. + /// Appends an element to the end of the storage, expanding the internal collection. #[ inline( always ) ] pub fn push< IntoElement >( mut self, element : IntoElement ) -> Self where IntoElement : core::convert::Into< E >, { - if self.formed.is_none() + if self.storage.is_none() { - self.formed = core::option::Option::Some( Default::default() ); + self.storage = core::option::Option::Some( Default::default() ); } - if let core::option::Option::Some( ref mut formed ) = self.formed + if let core::option::Option::Some( ref mut storage ) = self.storage { - formed.push( element.into() ); + ContainerAdd::add( storage, element.into() ); + // storage.push( element.into() ); } self } @@ -173,24 +190,24 @@ where // -// impl< Former, Context, End > FormerBegin< Formed, Formed, Context > -// for VectorSubformer< Former, Context, End > -// where -// End : FormingEnd< VectorDescriptor< E >, Context >, -// // Formed : VectorLike< E > + Default, -// Former : FormerDescriptor, -// { -// type End = End; -// -// #[ inline( always ) ] -// fn _begin -// ( -// formed : core::option::Option< Formed >, -// context : core::option::Option< Context >, -// on_end : End, -// ) -> Self -// { -// Self::begin( formed, context, on_end ) -// } -// -// } +impl< E, Descriptor, Context, End > FormerBegin< Descriptor, Context > +for VectorSubformer< E, Descriptor, Context, End > +where + End : FormingEnd< Descriptor, Context >, + Descriptor : FormerDescriptor, + Descriptor::Storage : ContainerAdd< Element = E >, +{ + type End = End; + + #[ inline( always ) ] + fn _begin + ( + storage : core::option::Option< Descriptor::Storage >, + context : core::option::Option< Context >, + on_end : End, + ) -> Self + { + Self::begin( storage, context, on_end ) + } + +} From 559afd224e98803755a2cec2c94a23fdc1e4cf38 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 12:01:59 +0200 Subject: [PATCH 003/533] former : experimenting --- Cargo.toml | 11 + .../former/examples/former_component_from.rs | 40 --- .../former/examples/former_custom_default.rs | 53 ---- .../former/examples/former_custom_setter.rs | 45 ---- .../former_custom_setter_overriden.rs | 39 --- .../examples/former_custom_subformer.rs | 82 ------ module/core/former/examples/former_debug.rs | 39 --- .../former/examples/former_many_fields.rs | 70 ------ .../examples/former_subformer_hashmap.rs | 29 --- .../examples/former_subformer_hashset.rs | 30 --- .../examples/former_subformer_vector.rs | 29 --- module/core/former/examples/former_trivial.rs | 49 ---- .../former/examples/former_trivial_expaned.rs | 234 ------------------ module/core/former/src/axiomatic2.rs | 204 --------------- module/core/former/src/vector2.rs | 195 --------------- module/core/former/src/vector3.rs | 14 +- .../inc/components_tests/component_assign.rs | 2 +- .../component_assign_manual.rs | 2 +- .../inc/components_tests/component_from.rs | 2 +- .../components_tests/component_from_manual.rs | 2 +- .../inc/components_tests/components_assign.rs | 2 +- .../components_assign_manual.rs | 2 +- .../tests/inc/components_tests/composite.rs | 2 +- .../inc/components_tests/composite_manual.rs | 2 +- .../inc/components_tests/from_components.rs | 2 +- .../from_components_manual.rs | 2 +- .../only_test/components_component_assign.rs | 0 .../only_test/components_component_from.rs | 0 .../only_test/components_components_assign.rs | 0 .../only_test/components_composite.rs | 0 .../only_test/components_from_components.rs | 0 .../former_tests/a_containers_with_runtime.rs | 2 +- .../a_containers_with_runtime_manual.rs | 2 +- .../a_containers_without_runtime.rs | 2 +- .../a_containers_without_runtime_manual.rs | 2 +- .../inc/former_tests/a_primitives_manual.rs | 185 ++++++++++---- .../a_primitives_manual_original.rs | 192 ++++++++++++++ .../tests/inc/former_tests/name_collisions.rs | 2 +- .../only_test/containers_with_runtime.rs | 0 .../only_test/containers_without_runtime.rs | 0 .../only_test/parametrized_struct.rs | 0 .../only_test/primitives.rs | 2 +- .../only_test/string_slice.rs | 0 .../only_test/subformer_basic.rs | 0 .../only_test/with_field_under_feature.rs | 0 .../former_tests/parametrized_struct_imm.rs | 2 +- .../parametrized_struct_manual.rs | 2 +- .../former_tests/parametrized_struct_where.rs | 2 +- .../tests/inc/former_tests/string_slice.rs | 2 +- .../inc/former_tests/string_slice_manual.rs | 2 +- .../tests/inc/former_tests/subformer_basic.rs | 2 +- .../former_tests/subformer_basic_manual.rs | 2 +- module/core/former/tests/inc/mod.rs | 115 +++++---- module/core/former_meta/src/derive/former.rs | 15 +- module/core/test_tools/Cargo.toml | 14 +- module/core/test_tools/src/lib.rs | 10 +- module/core/test_tools/src/test/smoke_test.rs | 3 +- 57 files changed, 468 insertions(+), 1275 deletions(-) delete mode 100644 module/core/former/examples/former_component_from.rs delete mode 100644 module/core/former/examples/former_custom_default.rs delete mode 100644 module/core/former/examples/former_custom_setter.rs delete mode 100644 module/core/former/examples/former_custom_setter_overriden.rs delete mode 100644 module/core/former/examples/former_custom_subformer.rs delete mode 100644 module/core/former/examples/former_debug.rs delete mode 100644 module/core/former/examples/former_many_fields.rs delete mode 100644 module/core/former/examples/former_subformer_hashmap.rs delete mode 100644 module/core/former/examples/former_subformer_hashset.rs delete mode 100644 module/core/former/examples/former_subformer_vector.rs delete mode 100644 module/core/former/examples/former_trivial.rs delete mode 100644 module/core/former/examples/former_trivial_expaned.rs delete mode 100644 module/core/former/src/axiomatic2.rs delete mode 100644 module/core/former/src/vector2.rs rename module/core/former/tests/inc/{ => components_tests}/only_test/components_component_assign.rs (100%) rename module/core/former/tests/inc/{ => components_tests}/only_test/components_component_from.rs (100%) rename module/core/former/tests/inc/{ => components_tests}/only_test/components_components_assign.rs (100%) rename module/core/former/tests/inc/{ => components_tests}/only_test/components_composite.rs (100%) rename module/core/former/tests/inc/{ => components_tests}/only_test/components_from_components.rs (100%) create mode 100644 module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs rename module/core/former/tests/inc/{ => former_tests}/only_test/containers_with_runtime.rs (100%) rename module/core/former/tests/inc/{ => former_tests}/only_test/containers_without_runtime.rs (100%) rename module/core/former/tests/inc/{ => former_tests}/only_test/parametrized_struct.rs (100%) rename module/core/former/tests/inc/{ => former_tests}/only_test/primitives.rs (98%) rename module/core/former/tests/inc/{ => former_tests}/only_test/string_slice.rs (100%) rename module/core/former/tests/inc/{ => former_tests}/only_test/subformer_basic.rs (100%) rename module/core/former/tests/inc/{ => former_tests}/only_test/with_field_under_feature.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 9bae29e730..d7dcf24295 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -204,6 +204,11 @@ version = "~0.15.0" path = "module/core/former" default-features = false +[workspace.dependencies.former_stable] +package = "former" +version = "=0.15.0" +default-features = false + [workspace.dependencies.former_meta] version = "~0.14.0" path = "module/core/former_meta" @@ -324,6 +329,7 @@ default-features = false version = "~0.2.0" path = "module/alias/wstring_tools" + ## fs tools / path tools [workspace.dependencies.fs_tools] @@ -349,6 +355,11 @@ version = "~0.2.0" path = "module/core/process_tools" default-features = false +[workspace.dependencies.process_tools_published] +package = "process_tools" +version = "~0.2.0" +default-features = false + ## test diff --git a/module/core/former/examples/former_component_from.rs b/module/core/former/examples/former_component_from.rs deleted file mode 100644 index e7cadbb335..0000000000 --- a/module/core/former/examples/former_component_from.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! -//! Macro to implement `From` for each component (field) of a structure. -//! This macro simplifies the creation of `From` trait implementations for struct fields, -//! enabling easy conversion from a struct reference to its field types. -//! -//! # Features -//! -//! - Requires the `derive_component_from` feature to be enabled for use. -//! - The `ComponentFrom` derive macro can be applied to structs to automatically generate -//! `From` implementations for each field. -//! -//! # Attributes -//! -//! - `debug` : Optional attribute to enable debug-level output during the macro expansion process. -//! - -#[ cfg( not( feature = "derive_component_from" ) ) ] -fn main() {} - -#[ cfg( feature = "derive_component_from" ) ] -fn main() -{ - - #[ derive( former::ComponentFrom ) ] - struct MyStruct - { - pub field1 : i32, - pub field2 : String, - } - - // Generated implementations allow for the following conversions : - let my_struct = MyStruct { field1 : 10, field2 : "Hello".into() }; - let field1 : i32 = From::from( &my_struct ); - let field2 : String = From::from( &my_struct ); - dbg!( field1 ); - dbg!( field2 ); - // > field1 = 10 - // > field2 = "Hello" - -} diff --git a/module/core/former/examples/former_custom_default.rs b/module/core/former/examples/former_custom_default.rs deleted file mode 100644 index 2cc73f3fc0..0000000000 --- a/module/core/former/examples/former_custom_default.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! The `Former` crate enhances struct initialization in Rust by allowing the specification of custom default values for fields through the `default` attribute. -//! -//! This feature not only provides a way to set initial values for struct fields without relying on the `Default` trait but also adds flexibility in handling cases where a field's type does not implement `Default`, or a non-standard default value is desired. -//! The above code snippet showcases the `Former` crate's ability to initialize struct fields with custom default values: -//! - The `number` field is initialized to `5`. -//! - The `greeting` field defaults to a greeting message, "Hello, Former!". -//! - The `numbers` field starts with a vector containing the integers `10`, `20`, and `30`. -//! -//! This approach significantly simplifies struct construction, particularly for complex types or where defaults beyond the `Default` trait's capability are required. By utilizing the `default` attribute, developers can ensure their structs are initialized safely and predictably, enhancing code clarity and maintainability. -//! - -#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] -fn main() {} - -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -fn main() -{ - use former::Former; - - /// Structure with default attributes. - #[ derive( Debug, PartialEq, Former ) ] - pub struct ExampleStruct - { - #[ default( 5 ) ] - number : i32, - #[ default( "Hello, Former!".to_string() ) ] - greeting : String, - #[ default( vec![ 10, 20, 30 ] ) ] - numbers : Vec< i32 >, - } - - // - - let instance = ExampleStruct::former().form(); - let expected = ExampleStruct - { - number : 5, - greeting : "Hello, Former!".to_string(), - numbers : vec![ 10, 20, 30 ], - }; - assert_eq!( instance, expected ); - dbg!( &instance ); - // > &instance = ExampleStruct { - // > number: 5, - // > greeting: "Hello, Former!", - // > numbers: [ - // > 10, - // > 20, - // > 30, - // > ], - // > } - -} diff --git a/module/core/former/examples/former_custom_setter.rs b/module/core/former/examples/former_custom_setter.rs deleted file mode 100644 index 10c592f913..0000000000 --- a/module/core/former/examples/former_custom_setter.rs +++ /dev/null @@ -1,45 +0,0 @@ -//! With help of `Former`, it is possible to define multiple versions of a setter for a single field, providing the flexibility to include custom logic within the setter methods. -//! -//! This feature is particularly useful when you need to preprocess data or enforce specific constraints before assigning values to fields. Custom setters should have unique names to differentiate them from the default setters generated by `Former`, allowing for specialized behavior while maintaining clarity in your code. -//! In the example showcases a custom alternative setter, `word_exclaimed`, which appends an exclamation mark to the input string before storing it. This approach allows for additional processing or validation of the input data without compromising the simplicity of the builder pattern. -//! - -#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] -fn main() {} - -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -fn main() -{ - use former::Former; - - /// Structure with a custom setter. - #[ derive( Debug, Former ) ] - pub struct StructWithCustomSetters - { - word : String, - } - - impl StructWithCustomSettersFormer - { - - // Custom alternative setter for `word` - pub fn word_exclaimed( mut self, value : impl Into< String > ) -> Self - { - debug_assert!( self.storage.word.is_none() ); - self.storage.word = Some( format!( "{}!", value.into() ) ); - self - } - - } - - let example = StructWithCustomSetters::former() - .word( "Hello" ) - .form(); - assert_eq!( example.word, "Hello".to_string() ); - - let example = StructWithCustomSetters::former() - .word_exclaimed( "Hello" ) - .form(); - assert_eq!( example.word, "Hello!".to_string() ); - -} diff --git a/module/core/former/examples/former_custom_setter_overriden.rs b/module/core/former/examples/former_custom_setter_overriden.rs deleted file mode 100644 index c817ab6872..0000000000 --- a/module/core/former/examples/former_custom_setter_overriden.rs +++ /dev/null @@ -1,39 +0,0 @@ -//! It's also possible to completely override setter and write its own from scratch. -//! -//! For that use attribe `[ setter( false ) ]` to disable setter. In the example, the default setter for `word` is disabled, and a custom setter is defined to automatically append an exclamation mark to the string. This method allows for complete control over the data assignment process, enabling the inclusion of any necessary logic or validation steps. -//! - -#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] -fn main() {} - -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -fn main() -{ - use former::Former; - - /// Structure with a custom setter. - #[ derive( Debug, Former ) ] - pub struct StructWithCustomSetters - { - #[ setter( false ) ] - word : String, - } - - impl StructWithCustomSettersFormer - { - - // Custom alternative setter for `word` - pub fn word( mut self, value : impl Into< String > ) -> Self - { - debug_assert!( self.storage.word.is_none() ); - self.storage.word = Some( format!( "{}!", value.into() ) ); - self - } - - } - - let example = StructWithCustomSetters::former() - .word( "Hello" ) - .form(); - assert_eq!( example.word, "Hello!".to_string() ); -} diff --git a/module/core/former/examples/former_custom_subformer.rs b/module/core/former/examples/former_custom_subformer.rs deleted file mode 100644 index 2cf8c2cc7a..0000000000 --- a/module/core/former/examples/former_custom_subformer.rs +++ /dev/null @@ -1,82 +0,0 @@ -//! example of how to use former of another structure as subformer of former of current one -//! function `command` integrate `CommandFormer` into `AggregatorFormer`. - -#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] -fn main() {} - -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -fn main() -{ - use std::collections::HashMap; - use former::Former; - - // Command struct with Former derived for builder pattern support - #[ derive( Debug, PartialEq, Former ) ] - pub struct Command - { - name : String, - description : String, - } - - // Aggregator struct to hold commands - #[ derive( Debug, PartialEq, Former ) ] - pub struct Aggregator - { - #[ setter( false ) ] - command : HashMap< String, Command >, - } - - // Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. - impl< Context, End > AggregatorFormer< Context, End > - where - End : former::FormingEnd< Aggregator, Context >, - { - #[ inline( always ) ] - pub fn command< IntoName >( self, name : IntoName ) -> CommandFormer< Self, impl former::FormingEnd< Command, Self > > - where - IntoName : core::convert::Into< String >, - { - let on_end = | command : Command, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut commands ) = super_former.storage.command - { - commands.insert( command.name.clone(), command ); - } - else - { - let mut commands: HashMap< String, Command > = Default::default(); - commands.insert( command.name.clone(), command ); - super_former.storage.command = Some( commands ); - } - super_former - }; - let former = CommandFormer::begin( None, Some( self ), on_end ); - former.name( name ) - } - // xxx : review - } - - let ca = Aggregator::former() - .command( "echo" ) - .description( "prints all subjects and properties" ) // sets additional properties using custom subformer - .end() - .command( "exit" ) - .description( "just exit" ) // Sets additional properties using using custom subformer - .end() - .form(); - - dbg!( &ca ); - // > &ca = Aggregator { - // > command: { - // > "echo": Command { - // > name: "echo", - // > description: "prints all subjects and properties", - // > }, - // > "exit": Command { - // > name: "exit", - // > description: "just exit", - // > }, - // > }, - // > } -} diff --git a/module/core/former/examples/former_debug.rs b/module/core/former/examples/former_debug.rs deleted file mode 100644 index 0a849f684a..0000000000 --- a/module/core/former/examples/former_debug.rs +++ /dev/null @@ -1,39 +0,0 @@ -//! -//! This is a demonstration of attribute debug. -//! The attribute `#[ debug ]` outputs generated code into the console during compilation. -//! - -#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] -fn main() {} - -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -fn main() -{ - use former::Former; - - - #[ derive( Debug, PartialEq, Former ) ] - // #[ debug ] - // Uncomment to see what derive expand into - pub struct UserProfile - { - age : i32, - username : String, - bio_optional : Option< String >, // Fields could be optional - } - - let profile = UserProfile::former() - .age( 30 ) - .username( "JohnDoe".to_string() ) - .bio_optional( "Software Developer".to_string() ) // Optionally provide a bio - .form(); - - dbg!( &profile ); - // Expected output: - // &profile = UserProfile { - // age: 30, - // username: "JohnDoe", - // bio_optional: Some("Software Developer"), - // } - -} diff --git a/module/core/former/examples/former_many_fields.rs b/module/core/former/examples/former_many_fields.rs deleted file mode 100644 index 6a193b1975..0000000000 --- a/module/core/former/examples/former_many_fields.rs +++ /dev/null @@ -1,70 +0,0 @@ -//! -//! Utilizing the Former Crate for Struct Initialization -//! -//! This example demonstrates the capability of the `Former` crate to simplify struct initialization through the builder pattern, particularly for structs with a mix of required and optional fields, as well as collections like vectors and hash maps. -//! -//! The `Structure1` struct is defined with various field types to showcase the flexibility of `Former`: -//! - `int_1`: A required integer field. -//! - `string_1`: A required string field. -//! - `vec_1`: A vector of unsigned integers, showcasing collection handling. -//! - `hashmap_strings_1`: A hash map storing key-value pairs, both strings, illustrating how `Former` can manage more complex data structures. -//! - `int_optional_1`: An optional integer field, demonstrating `Former`'s capability to handle optional fields seamlessly. -//! - `string_optional_1`: An optional string field, further exemplifying optional field handling. -//! -//! A hash map is first created and populated with two key-value pairs. The `Structure1` struct is then instantiated using the fluent builder pattern methods provided by `Former`. Each method corresponds to one of `Structure1`'s fields, allowing for intuitive and clear field assignment. The `.form()` method completes the construction of the `Structure1` instance. -//! -//! The builder pattern methods significantly streamline the process of struct initialization, especially for structs with complex or optional fields. By leveraging `Former`, developers can write more readable and maintainable initialization code, avoiding the verbosity and complexity often associated with manual struct instantiation. -//! -//! The `dbg!` macro is utilized to print the constructed `Structure1` instance, confirming that all fields are correctly assigned, including the handling of optional fields and collections. This example underscores the power and convenience of using `Former` for struct initialization in Rust projects. - -#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] -fn main() {} - -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -fn main() -{ - use former::Former; - - #[ derive( Debug, PartialEq, Eq, Former ) ] - pub struct Structure1 - { - int_1 : i32, - string_1 : String, - vec_1 : Vec< u32 >, - hashmap_strings_1 : std::collections::HashMap< String, String >, - int_optional_1 : core::option::Option< i32 >, - string_optional_1 : Option< String >, - } - let hashmap = std::collections::HashMap::from - ([ - ( "k1".to_string(), "v1".to_string() ), - ( "k2".to_string(), "v2".to_string() ), - ]); - - let struct1 = Structure1::former() - .int_1( 13 ) - .string_1( "Abcd".to_string() ) - .vec_1( vec![ 1, 3 ] ) - .hashmap_strings_1( hashmap ) - .string_optional_1( "dir1" ) - .form(); - dbg!( &struct1 ); - -// < &struct1 = Structure1 { -// < int_1: 13, -// < string_1: "Abcd", -// < vec_1: [ -// < 1, -// < 3, -// < ], -// < hashmap_strings_1: { -// < "k1": "v1", -// < "k2": "v2", -// < }, -// < int_optional_1: None, -// < string_optional_1: Some( -// < "dir1", -// < ), -// < } - -} diff --git a/module/core/former/examples/former_subformer_hashmap.rs b/module/core/former/examples/former_subformer_hashmap.rs deleted file mode 100644 index 0cfb6dff30..0000000000 --- a/module/core/former/examples/former_subformer_hashmap.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! # Example Usage -//! -//! Demonstrates how to use `HashMapSubformer` with the `HashMapLike` trait to build a `std::collections::HashMap`: -//! - -#[ cfg( not( all( feature = "derive_former", not( feature = "no_std" ) ) ) ) ] -fn main() {} - -#[ cfg( all( feature = "derive_former", not( feature = "no_std" ) ) ) ] -fn main() -{ - use test_tools::exposed::*; - - #[ derive( Debug, PartialEq, former::Former ) ] - pub struct StructWithMap - { - #[ subformer( former::HashMapSubformer ) ] - map : std::collections::HashMap< &'static str, &'static str >, - } - - let struct1 = StructWithMap::former() - .map() - .insert( "a", "b" ) - .insert( "c", "d" ) - .end() - .form() - ; - assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); -} diff --git a/module/core/former/examples/former_subformer_hashset.rs b/module/core/former/examples/former_subformer_hashset.rs deleted file mode 100644 index 7ce1d3a365..0000000000 --- a/module/core/former/examples/former_subformer_hashset.rs +++ /dev/null @@ -1,30 +0,0 @@ -//! # Example Usage -//! -//! Demonstrates how to use `HashMapSubformer` with the `HashMapLike` trait to build a `std::collections::HashMap`: -//! - -#[ cfg( not( all( feature = "derive_former", not( feature = "no_std" ) ) ) ) ] -fn main() {} - -#[ cfg( all( feature = "derive_former", not( feature = "no_std" ) ) ) ] -fn main() -{ - use test_tools::exposed::*; - - #[ derive( Debug, PartialEq, former::Former ) ] - pub struct StructWithSet - { - #[ subformer( former::HashSetSubformer ) ] - set : std::collections::HashSet< &'static str >, - } - - let instance = StructWithSet::former() - .set() - .insert("apple") - .insert("banana") - .end() - .form(); - - assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] }); - -} diff --git a/module/core/former/examples/former_subformer_vector.rs b/module/core/former/examples/former_subformer_vector.rs deleted file mode 100644 index 9d7b22bdc0..0000000000 --- a/module/core/former/examples/former_subformer_vector.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! # Example Usage -//! -//! Demonstrates how to use `HashMapSubformer` with the `HashMapLike` trait to build a `std::collections::HashMap`: -//! - -#[ cfg( not( all( feature = "derive_former", not( feature = "no_std" ) ) ) ) ] -fn main() {} - -#[ cfg( all( feature = "derive_former", not( feature = "no_std" ) ) ) ] -fn main() -{ - - #[ derive( Debug, PartialEq, former::Former ) ] - pub struct StructWithVec - { - #[ subformer( former::VectorSubformer ) ] - vec : Vec< &'static str >, - } - - let instance = StructWithVec::former() - .vec() - .push( "apple" ) - .push( "banana" ) - .end() - .form(); - - assert_eq!( instance, StructWithVec { vec: vec![ "apple", "banana" ] } ); - -} diff --git a/module/core/former/examples/former_trivial.rs b/module/core/former/examples/former_trivial.rs deleted file mode 100644 index 78331e5577..0000000000 --- a/module/core/former/examples/former_trivial.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! # Builder Pattern Implementation with Former -//! -//! This module demonstrates the use of the `Former` trait to apply the builder pattern for Rust structs. -//! The `Former` trait simplifies the instantiation of structs by enabling a fluent, method-chaining approach -//! to set fields before finalizing the instance with `.form()`. It is particularly useful for structs with optional fields -//! or when a clear and concise way to instantiate complex data structures is needed. -//! -//! ## How Former Works -//! -//! - **Trait Derivation** : By deriving `Former` on a struct, you automatically generate builder methods for each field. -//! - **Fluent Interface** : Each field's builder method allows for setting the value of that field and returns a mutable reference to the builder, -//! enabling method chaining. -//! - **Optional Fields** : Optional fields can be easily handled without needing to explicitly set them to `None`. -//! - **Finalization** : The `.form()` method finalizes the building process and returns the constructed struct instance. -//! -//! This approach abstracts away the need for manually implementing a builder for each struct, making code more readable and maintainable. -//! - -#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] -fn main() {} - -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -fn main() -{ - use former::Former; - - #[ derive( Debug, PartialEq, Former ) ] - pub struct UserProfile - { - age : i32, - username : String, - bio_optional : Option< String >, // Fields could be optional - } - - let profile = UserProfile::former() - .age( 30 ) - .username( "JohnDoe".to_string() ) - .bio_optional( "Software Developer".to_string() ) // Optionally provide a bio - .form(); - - dbg!( &profile ); - // Expected output: - // &profile = UserProfile { - // age: 30, - // username: "JohnDoe", - // bio_optional: Some("Software Developer"), - // } - -} diff --git a/module/core/former/examples/former_trivial_expaned.rs b/module/core/former/examples/former_trivial_expaned.rs deleted file mode 100644 index ac46064cb4..0000000000 --- a/module/core/former/examples/former_trivial_expaned.rs +++ /dev/null @@ -1,234 +0,0 @@ -//! # Builder Pattern Implementation with Former -//! -//! This module demonstrates the use of the `Former` trait to apply the builder pattern for Rust structs. -//! The `Former` trait simplifies the instantiation of structs by enabling a fluent, method-chaining approach -//! to set fields before finalizing the instance with `.form()`. It is particularly useful for structs with optional fields -//! or when a clear and concise way to instantiate complex data structures is needed. -//! -//! ## How Former Works -//! -//! - **Trait Derivation** : By deriving `Former` on a struct, you automatically generate builder methods for each field. -//! - **Fluent Interface** : Each field's builder method allows for setting the value of that field and returns a mutable reference to the builder, -//! enabling method chaining. -//! - **Optional Fields** : Optional fields can be easily handled without needing to explicitly set them to `None`. -//! - **Finalization** : The `.form()` method finalizes the building process and returns the constructed struct instance. -//! -//! This approach abstracts away the need for manually implementing a builder for each struct, making code more readable and maintainable. -//! - -// xxx : regenerate - -#![ allow( dead_code ) ] - -#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] -fn main(){} - -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -fn main() -{ - - #[ derive( Debug, PartialEq ) ] - pub struct UserProfile - { - age : i32, - username : String, - bio_optional : Option< String >, // Fields could be optional - } - - impl UserProfile - { - #[ inline( always ) ] - pub fn former() -> UserProfileFormer< UserProfile, former::ReturnStorage > - { - UserProfileFormer::< UserProfile, former::ReturnStorage >::new() - } - } - - #[ derive( Debug, Default ) ] - pub struct UserProfileFormerStorage - { - age : Option< i32 >, - username : Option< String >, - bio_optional : Option< String >, - } - - pub struct UserProfileFormer - < - Context = UserProfile, - End = former::ReturnStorage, - > - where - End : former::FormingEnd< UserProfile, Context >, - { - storage : UserProfileFormerStorage, - context : Option< Context >, - on_end : Option< End >, - } - - impl< Context, End > UserProfileFormer< Context, End > - where - End : former::FormingEnd< UserProfile, Context >, - { - #[ inline( always ) ] - pub fn form( mut self ) -> UserProfile - { - let age = if self.storage.age.is_some() - { - self.storage.age.take().unwrap() - } - else - { - let val : i32 = - { - trait NotDefault< T > - { - fn maybe_default( self : &Self ) -> T { panic!( "Field 'age' isn't initialized" ) } - } - trait WithDefault< T > - { - fn maybe_default( self : &Self ) -> T; - } - impl< T > NotDefault< T > for &::core::marker::PhantomData< T > {} - impl< T > WithDefault< T > for ::core::marker::PhantomData< T > - where - T : ::core::default::Default, - { - fn maybe_default( self : &Self ) -> T - { - T::default() - } - } - ( &::core::marker::PhantomData::< i32 > ).maybe_default() - }; - val - }; - let username = if self.storage.username.is_some() - { - self.storage.username.take().unwrap() - } - else - { - let val : String = - { - trait NotDefault< T > - { - fn maybe_default( self : &Self ) -> T { panic!( "Field 'username' isn't initialized" ) } - } - trait WithDefault< T > - { - fn maybe_default( self : &Self ) -> T; - } - impl< T > NotDefault< T > for &::core::marker::PhantomData< T > {} - impl< T > WithDefault< T > for ::core::marker::PhantomData< T > - where - T : ::core::default::Default, - { - fn maybe_default( self : &Self ) -> T - { - T::default() - } - } - ( &::core::marker::PhantomData::< String > ).maybe_default() - }; - val - }; - let bio_optional = if self.storage.bio_optional.is_some() - { - Option::Some( self.storage.bio_optional.take().unwrap() ) - } - else - { - Option::None - }; - let result = UserProfile - { - age, - username, - bio_optional, - }; - return result; - } - - #[ inline( always ) ] - pub fn perform( self ) -> UserProfile - { - let result = self.form(); - return result; - } - - #[ inline( always ) ] - pub fn new() -> UserProfileFormer< UserProfile, former::ReturnStorage > - { - UserProfileFormer::< UserProfile, former::ReturnStorage >::begin( None, former::ReturnStorage ) - } - - #[ inline( always ) ] - pub fn begin - ( - context : Option< Context >, - on_end : End, - ) -> Self - { - Self - { - storage : core::default::Default::default(), - context : context, - on_end : Option::Some( on_end ), - } - } - - #[ inline( always ) ] - pub fn end( mut self ) -> Context - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) - } - - #[ inline ] - pub fn age< Src >( mut self, src : Src ) -> Self - where - Src : Into< i32 >, - { - debug_assert!( self.storage.age.is_none() ); - self.storage.age = Option::Some( src.into() ); - self - } - - #[ inline ] - pub fn username< Src >( mut self, src : Src ) -> Self - where - Src : Into< String >, - { - debug_assert!( self.storage.username.is_none() ); - self.storage.username = Option::Some( src.into() ); - self - } - - #[ inline ] - pub fn bio_optional< Src >( mut self, src : Src ) -> Self - where - Src : Into< String >, - { - debug_assert!( self.storage.bio_optional.is_none() ); - self.storage.bio_optional = Option::Some( src.into() ); - self - } - } - - let profile = UserProfile::former() - .age( 30 ) - .username( "JohnDoe".to_string() ) - .bio_optional( "Software Developer".to_string() ) - .form(); - - dbg!( &profile ); - // Expected output: - // &profile = UserProfile { - // age: 30, - // username: "JohnDoe", - // bio_optional: Some("Software Developer"), - // } - -} diff --git a/module/core/former/src/axiomatic2.rs b/module/core/former/src/axiomatic2.rs deleted file mode 100644 index 84f36512d5..0000000000 --- a/module/core/former/src/axiomatic2.rs +++ /dev/null @@ -1,204 +0,0 @@ -//! .... - -/// xxx2 -pub trait StoragePerform -{ - type Formed; - fn preform( self ) -> Self::Formed; -} - -/// xxx2 -pub trait FormerDescriptor -{ - type Storage : StoragePerform< Formed = Self::Formed >; - type Formed; - // type Former; -} - -// pub trait FormerDefinition -// { -// type Storage : StoragePerform< Formed = Self::Formed >; -// type Formed; -// type Context; -// type FormerDescriptor : FormerDescriptor< Storage = Self::Storage, Formed = Self::Formed >; -// type End : FormingEnd2< Self::FormerDescriptor, Self::Context >; -// } - -/// Defines a handler for the end of a subforming process, enabling the return of the original context. -/// -/// This trait is designed to be flexible, allowing for various end-of-forming behaviors in builder patterns. -/// Implementors can define how to transform or pass through the context during the forming process's completion. -/// -/// # Parameters -/// - `Storage`: The type of the container being processed. -/// - `Context`: The type of the context that might be altered or returned upon completion. -pub trait FormingEnd2< Former : FormerDescriptor, Context > -{ - /// Called at the end of the subforming process to return the modified or original context. - /// - /// # Parameters - /// - `container`: The container being processed. - /// - `context`: Optional context to be transformed or returned. - /// - /// # Returns - /// Returns the transformed or original context based on the implementation. - fn call( &self, storage : Former::Storage, context : core::option::Option< Context > ) -> Former::Formed; -} - -impl< Former : FormerDescriptor, Context, F > FormingEnd2< Former, Context > for F -where - F : Fn( Former::Storage, core::option::Option< Context > ) -> Former::Formed, -{ - #[ inline( always ) ] - fn call( &self, storage : Former::Storage, context : core::option::Option< Context > ) -> Former::Formed - { - self( storage, context ) - } -} - -/// A `FormingEnd2` implementation that returns the formed container itself instead of the context. -/// -/// This struct is useful when the forming process should result in the formed container being returned directly, -/// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. -#[ derive( Debug, Default ) ] -pub struct ReturnStorage2; - -impl< Former : FormerDescriptor > FormingEnd2< Former, () > -for ReturnStorage2 -{ - #[ inline( always ) ] - fn call( &self, storage : Former::Storage, _context : core::option::Option< () > ) -> Former::Formed - { - storage.preform() - } -} - -/// A wrapper around a closure to be used as a `FormingEnd2`. -/// -/// This struct allows for dynamic dispatch of a closure that matches the -/// `FormingEnd2` trait's `call` method signature. It is useful for cases where -/// a closure needs to be stored or passed around as an object implementing -/// `FormingEnd2`. -/// -/// # Type Parameters -/// -/// * `Storage` - The type of the container being processed. This type is passed to the closure -/// when it's called. -/// * `Context` - The type of the context that may be altered or returned by the closure. -/// This allows for flexible manipulation of context based on the container. -#[ cfg( not( feature = "no_std" ) ) ] -pub struct FormingEndWrapper2< Former : FormerDescriptor, Context > -{ - closure : Box< dyn Fn( Former::Storage, Option< Context > ) -> Former::Formed >, - _marker : std::marker::PhantomData< Former::Storage >, -} - -#[ cfg( not( feature = "no_std" ) ) ] -impl< Former : FormerDescriptor, Context > FormingEndWrapper2< Former, Context > -{ - /// Constructs a new `FormingEndWrapper2` with the provided closure. - /// - /// # Parameters - /// - /// * `closure` - A closure that matches the expected signature for transforming a container - /// and context into a new context. This closure is stored and called by the - /// `call` method of the `FormingEnd2` trait implementation. - /// - /// # Returns - /// - /// Returns an instance of `FormingEndWrapper2` encapsulating the provided closure. - pub fn new( closure : impl Fn( Former::Storage, Option< Context > ) -> Former::Formed + 'static ) -> Self - { - Self - { - closure : Box::new( closure ), - _marker : std::marker::PhantomData - } - } -} - -#[ cfg( not( feature = "no_std" ) ) ] -use std::fmt; -#[ cfg( not( feature = "no_std" ) ) ] -impl< Former : FormerDescriptor, Context > fmt::Debug for FormingEndWrapper2< Former, Context > -{ - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result - { - f.debug_struct( "FormingEndWrapper2" ) - .field( "closure", &format_args!{ "- closure -" } ) - .field( "_marker", &self._marker ) - .finish() - } -} - -#[ cfg( not( feature = "no_std" ) ) ] -impl< Former : FormerDescriptor, Context > FormingEnd2< Former, Context > -for FormingEndWrapper2< Former, Context > -{ - fn call( &self, storage : Former::Storage, context : Option< Context > ) -> Former::Formed - { - ( self.closure )( storage, context ) - } -} - -// - -/// A trait for initiating a structured subforming process with contextual and intermediary storage linkage. -/// -/// This trait facilitates the creation of a subformer that carries through a builder pattern chain, -/// utilizing intermediary storage for accumulating state or data before finally transforming it into -/// a `Formed` structure. It is designed for scenarios where a multi-step construction or transformation -/// process benefits from maintaining both transient state (`Storage`) and contextual information (`Context`), -/// before concluding with the generation of a final product (`Formed`). -/// -/// # Type Parameters -/// -/// * `Storage` - Represents a mutable intermediary storage structure used throughout the subforming process -/// to accumulate data, state, or partial computations. This storage is internal to the -/// subformer and is eventually converted into the final `Formed` structure by the subformer, -/// not directly by implementations of this trait. -/// -/// * `Formed` - Denotes the final type that results from the subforming process. This is the intended outcome -/// of the builder chain, constructed or transformed from the `Storage` with consideration of -/// the provided `Context`. -/// -/// * `Context` - Specifies the contextual backdrop against which the subforming process unfolds. This could -/// encompass references to parent builders, configuration data, or any state influencing how -/// `Storage` transitions into `Formed`. -/// -/// # Functions -/// -/// * `_begin` - This function launches the subforming process, marking the start of a construction or transformation -/// sequence defined by the implementing type. It establishes the foundational `Storage` and `Context`, -/// alongside specifying an `on_end` completion handler that dictates the final conversion into `Formed`. -/// -/// The `FormerBegin2` trait, by decoupling `Storage` from `Formed` and introducing a contextual layer, enables -/// sophisticated and flexible construction patterns conducive to complex data transformations or object creation -/// sequences within builder patterns. - -// xxx2 : change sequence -pub trait FormerBegin2< Former : FormerDescriptor, Context > -{ - - /// * `End` - A trait bound marking the closure or handler invoked upon completing the subforming process. Implementers - /// of this trait (`End`) are tasked with applying the final transformations that transition `Storage` - /// into `Formed`, optionally utilizing `Context` to guide this transformation. It is crucial that this - /// associated type satisfies the `FormingEnd2` trait, defining the precise mechanics of - /// how the subformer concludes its operation. - type End : FormingEnd2< Former, Context >; - - /// Launches the subforming process with an initial storage and context, setting up an `on_end` completion handler. - /// - /// # Parameters - /// - /// * `storage` - An optional initial state for the intermediary storage structure. - /// * `context` - An optional initial setting providing contextual information for the subforming process. - /// * `on_end` - A completion handler responsible for transforming the accumulated `Storage` into the final `Formed` structure. - fn _begin - ( - storage : core::option::Option< Former::Storage >, - context : core::option::Option< Context >, - on_end : Self::End, - ) -> Self; - -} diff --git a/module/core/former/src/vector2.rs b/module/core/former/src/vector2.rs deleted file mode 100644 index 9c7e17beb5..0000000000 --- a/module/core/former/src/vector2.rs +++ /dev/null @@ -1,195 +0,0 @@ -use super::*; -use axiomatic2::*; - -#[ 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 VectorLike2< E > -{ - /// Appends an element to the back of a formed. - fn push( &mut self, element : E ); -} - -impl< E > VectorLike2< E > for Vec< E > -{ - fn push( &mut self, element : E ) - { - Vec::push( self, element ); - } -} - -impl< E > StoragePerform for Vec< E > -{ - type Formed = Self; - fn preform( self ) -> Self::Formed - { - self - } -} -pub struct VectorSubformerDescriptor< E > -{ - _phantom : core::marker::PhantomData< E >, -} - -impl< E > VectorSubformerDescriptor< E > -{ - fn new() -> Self - { - Self { _phantom : core::marker::PhantomData } - } -} - -impl< E > FormerDescriptor -for VectorSubformerDescriptor< E > -{ - type Storage = Vec< E >; - type Formed = Vec< E >; - // type Former = VectorSubformer2< E, Context, End >; -} - -/// A builder for constructing `VectorLike2` containers, facilitating a fluent and flexible interface. -/// -/// `VectorSubformer2` leverages the `VectorLike2` trait to enable the construction and manipulation -/// of vector-like containers in a builder pattern style, promoting readability and ease of use. -#[ derive( Debug, Default ) ] -pub struct VectorSubformer2< E, Context, End > -where - End : FormingEnd2< VectorSubformerDescriptor< E >, Context >, -{ - formed : core::option::Option< < VectorSubformerDescriptor< E > as axiomatic2::FormerDescriptor >::Formed >, - context : core::option::Option< Context >, - on_end : core::option::Option< End >, -} - -impl< E, Context, End > VectorSubformer2< E, Context, End > -where - End : FormingEnd2< VectorSubformerDescriptor< E >, Context >, -{ - - /// Form current former into target structure. - #[ inline( always ) ] - pub fn form( mut self ) -> < VectorSubformerDescriptor< E > as axiomatic2::FormerDescriptor >::Formed - { - let formed = if self.formed.is_some() - { - self.formed.take().unwrap() - } - else - { - let val = Default::default(); - val - }; - formed - } - - /// Begins the building process, optionally initializing with a context and formed. - #[ inline( always ) ] - pub fn begin - ( - formed : core::option::Option< < VectorSubformerDescriptor< E > as axiomatic2::FormerDescriptor >::Formed >, - context : core::option::Option< Context >, - on_end : End - ) -> Self - { - Self - { - context, - formed, - on_end : Some( on_end ), - } - } - - /// Finalizes the building process, returning the formed or a context incorporating it. - #[ inline( always ) ] - pub fn end( mut self ) -> < VectorSubformerDescriptor< E > as axiomatic2::FormerDescriptor >::Formed - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) - } - - /// Replaces the current formed with a provided one, allowing for a reset or redirection of the building process. - #[ inline( always ) ] - pub fn replace( mut self, vector : < VectorSubformerDescriptor< E > as axiomatic2::FormerDescriptor >::Formed ) -> Self - { - self.formed = Some( vector ); - self - } - -} - -impl< E > VectorSubformer2< E, (), ReturnStorage2 > -where -{ - - /// Initializes a new `VectorSubformer2` instance, starting with an empty formed. - /// This function serves as the entry point for the builder pattern. - /// - /// # Returns - /// A new instance of `VectorSubformer2` with an empty internal formed. - /// - #[ inline( always ) ] - pub fn new() -> Self - { - Self::begin - ( - None, - None, - ReturnStorage2, - ) - } - -} - -impl< E, Context, End > VectorSubformer2< E, Context, End > -where - End : FormingEnd2< VectorSubformerDescriptor< E >, Context >, -{ - - /// Appends an element to the end of the formed, expanding the internal collection. - #[ inline( always ) ] - pub fn push< E2 >( mut self, element : E2 ) -> Self - where E2 : core::convert::Into< E >, - { - if self.formed.is_none() - { - self.formed = core::option::Option::Some( Default::default() ); - } - if let core::option::Option::Some( ref mut formed ) = self.formed - { - formed.push( element.into() ); - } - self - } - -} - -// - -// impl< Former, Context, End > FormerBegin< Formed, Formed, Context > -// for VectorSubformer2< Former, Context, End > -// where -// End : FormingEnd2< VectorSubformerDescriptor< E >, Context >, -// // Formed : VectorLike2< E > + Default, -// Former : FormerDescriptor, -// { -// type End = End; -// -// #[ inline( always ) ] -// fn _begin -// ( -// formed : core::option::Option< Formed >, -// context : core::option::Option< Context >, -// on_end : End, -// ) -> Self -// { -// Self::begin( formed, context, on_end ) -// } -// -// } diff --git a/module/core/former/src/vector3.rs b/module/core/former/src/vector3.rs index 54517fbd38..b7fa2ccee5 100644 --- a/module/core/former/src/vector3.rs +++ b/module/core/former/src/vector3.rs @@ -37,6 +37,13 @@ impl< E > VectorDescriptor< E > } } +impl< E > FormerDescriptor +for VectorDescriptor< E > +{ + type Storage = Vec< E >; + type Formed = Vec< E >; +} + impl< E > StoragePerform for Vec< E > { @@ -47,13 +54,6 @@ for Vec< E > } } -impl< E > FormerDescriptor -for VectorDescriptor< E > -{ - type Storage = Vec< E >; - type Formed = Vec< E >; -} - /// A builder for constructing `VectorLike` containers, facilitating a fluent and flexible interface. /// /// `VectorSubformer` leverages the `VectorLike` trait to enable the construction and manipulation diff --git a/module/core/former/tests/inc/components_tests/component_assign.rs b/module/core/former/tests/inc/components_tests/component_assign.rs index aa82903577..9ca13cbcba 100644 --- a/module/core/former/tests/inc/components_tests/component_assign.rs +++ b/module/core/former/tests/inc/components_tests/component_assign.rs @@ -14,4 +14,4 @@ struct Person // -include!( "../only_test/components_component_assign.rs" ); +include!( "./only_test/components_component_assign.rs" ); diff --git a/module/core/former/tests/inc/components_tests/component_assign_manual.rs b/module/core/former/tests/inc/components_tests/component_assign_manual.rs index b71e4f9624..d2aff86d2c 100644 --- a/module/core/former/tests/inc/components_tests/component_assign_manual.rs +++ b/module/core/former/tests/inc/components_tests/component_assign_manual.rs @@ -33,4 +33,4 @@ where // -include!( "../only_test/components_component_assign.rs" ); +include!( "./only_test/components_component_assign.rs" ); diff --git a/module/core/former/tests/inc/components_tests/component_from.rs b/module/core/former/tests/inc/components_tests/component_from.rs index e716895ff5..965218114f 100644 --- a/module/core/former/tests/inc/components_tests/component_from.rs +++ b/module/core/former/tests/inc/components_tests/component_from.rs @@ -17,4 +17,4 @@ pub struct Options1 // -include!( "../only_test/components_component_from.rs" ); +include!( "./only_test/components_component_from.rs" ); diff --git a/module/core/former/tests/inc/components_tests/component_from_manual.rs b/module/core/former/tests/inc/components_tests/component_from_manual.rs index 72912f2fb1..215a1f6ff5 100644 --- a/module/core/former/tests/inc/components_tests/component_from_manual.rs +++ b/module/core/former/tests/inc/components_tests/component_from_manual.rs @@ -42,4 +42,4 @@ impl From< &Options1 > for f32 // -include!( "../only_test/components_component_from.rs" ); +include!( "./only_test/components_component_from.rs" ); diff --git a/module/core/former/tests/inc/components_tests/components_assign.rs b/module/core/former/tests/inc/components_tests/components_assign.rs index 2f95f9fb5c..e2dbb6fda4 100644 --- a/module/core/former/tests/inc/components_tests/components_assign.rs +++ b/module/core/former/tests/inc/components_tests/components_assign.rs @@ -73,4 +73,4 @@ impl From< &Options2 > for String // -include!( "../only_test/components_components_assign.rs" ); +include!( "./only_test/components_components_assign.rs" ); diff --git a/module/core/former/tests/inc/components_tests/components_assign_manual.rs b/module/core/former/tests/inc/components_tests/components_assign_manual.rs index 11c499cd04..182ad0dacf 100644 --- a/module/core/former/tests/inc/components_tests/components_assign_manual.rs +++ b/module/core/former/tests/inc/components_tests/components_assign_manual.rs @@ -192,4 +192,4 @@ where // -include!( "../only_test/components_components_assign.rs" ); +include!( "./only_test/components_components_assign.rs" ); diff --git a/module/core/former/tests/inc/components_tests/composite.rs b/module/core/former/tests/inc/components_tests/composite.rs index 1fab721fe4..7105ba0b0e 100644 --- a/module/core/former/tests/inc/components_tests/composite.rs +++ b/module/core/former/tests/inc/components_tests/composite.rs @@ -72,4 +72,4 @@ pub struct Options2 // -include!( "../only_test/components_composite.rs" ); +include!( "./only_test/components_composite.rs" ); diff --git a/module/core/former/tests/inc/components_tests/composite_manual.rs b/module/core/former/tests/inc/components_tests/composite_manual.rs index 14ba81afe1..34e77f09af 100644 --- a/module/core/former/tests/inc/components_tests/composite_manual.rs +++ b/module/core/former/tests/inc/components_tests/composite_manual.rs @@ -209,4 +209,4 @@ where // -include!( "../only_test/components_composite.rs" ); +include!( "./only_test/components_composite.rs" ); diff --git a/module/core/former/tests/inc/components_tests/from_components.rs b/module/core/former/tests/inc/components_tests/from_components.rs index 6a2a61d125..9f69aab624 100644 --- a/module/core/former/tests/inc/components_tests/from_components.rs +++ b/module/core/former/tests/inc/components_tests/from_components.rs @@ -72,4 +72,4 @@ pub struct Options2 // -include!( "../only_test/components_from_components.rs" ); +include!( "./only_test/components_from_components.rs" ); diff --git a/module/core/former/tests/inc/components_tests/from_components_manual.rs b/module/core/former/tests/inc/components_tests/from_components_manual.rs index 3f01fe56cb..6a6c29e323 100644 --- a/module/core/former/tests/inc/components_tests/from_components_manual.rs +++ b/module/core/former/tests/inc/components_tests/from_components_manual.rs @@ -72,4 +72,4 @@ where // -include!( "../only_test/components_from_components.rs" ); +include!( "./only_test/components_from_components.rs" ); diff --git a/module/core/former/tests/inc/only_test/components_component_assign.rs b/module/core/former/tests/inc/components_tests/only_test/components_component_assign.rs similarity index 100% rename from module/core/former/tests/inc/only_test/components_component_assign.rs rename to module/core/former/tests/inc/components_tests/only_test/components_component_assign.rs diff --git a/module/core/former/tests/inc/only_test/components_component_from.rs b/module/core/former/tests/inc/components_tests/only_test/components_component_from.rs similarity index 100% rename from module/core/former/tests/inc/only_test/components_component_from.rs rename to module/core/former/tests/inc/components_tests/only_test/components_component_from.rs diff --git a/module/core/former/tests/inc/only_test/components_components_assign.rs b/module/core/former/tests/inc/components_tests/only_test/components_components_assign.rs similarity index 100% rename from module/core/former/tests/inc/only_test/components_components_assign.rs rename to module/core/former/tests/inc/components_tests/only_test/components_components_assign.rs diff --git a/module/core/former/tests/inc/only_test/components_composite.rs b/module/core/former/tests/inc/components_tests/only_test/components_composite.rs similarity index 100% rename from module/core/former/tests/inc/only_test/components_composite.rs rename to module/core/former/tests/inc/components_tests/only_test/components_composite.rs diff --git a/module/core/former/tests/inc/only_test/components_from_components.rs b/module/core/former/tests/inc/components_tests/only_test/components_from_components.rs similarity index 100% rename from module/core/former/tests/inc/only_test/components_from_components.rs rename to module/core/former/tests/inc/components_tests/only_test/components_from_components.rs diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_runtime.rs b/module/core/former/tests/inc/former_tests/a_containers_with_runtime.rs index ead3284c94..8200225aeb 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_runtime.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_runtime.rs @@ -15,4 +15,4 @@ pub struct Struct1 hashset_strings_1 : std::collections::HashSet< String >, } -include!( "../only_test/containers_with_runtime.rs" ); +include!( "./only_test/containers_with_runtime.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs index eaa107c5de..0e2f2a2704 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs @@ -292,4 +292,4 @@ where // -include!( "../only_test/containers_with_runtime.rs" ); +include!( "./only_test/containers_with_runtime.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_runtime.rs b/module/core/former/tests/inc/former_tests/a_containers_without_runtime.rs index 26b9e6ef34..61ab910b75 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_without_runtime.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_without_runtime.rs @@ -15,4 +15,4 @@ pub struct Struct1 // -include!( "../only_test/containers_without_runtime.rs" ); +include!( "./only_test/containers_without_runtime.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs index fa6236f5d1..2d50928aff 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs @@ -175,4 +175,4 @@ where // -include!( "../only_test/containers_without_runtime.rs" ); +include!( "./only_test/containers_without_runtime.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 5461d21cff..6feb243a4b 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -15,9 +15,10 @@ pub struct Struct1 // generated by former impl Struct1 { - pub fn former() -> Struct1Former< Struct1, the_module::ReturnStorage > + // xxx : make sure it's covered by tests + pub fn former() -> Struct1Former< (), the_module::ReturnStorage > { - Struct1Former::< Struct1, the_module::ReturnStorage >::new() + Struct1Former::new() } } @@ -49,32 +50,35 @@ impl Default for Struct1FormerStorage } -// +#[ derive( Debug ) ] +pub struct Struct1FormerDescriptor; -pub struct Struct1Former -< - __FormerContext = Struct1, - __FormerEnd = the_module::ReturnStorage, -> -where - __FormerEnd : the_module::FormingEnd< Struct1, __FormerContext >, +impl Struct1FormerDescriptor { - storage : Struct1FormerStorage, - context : core::option::Option< __FormerContext >, - on_end : core::option::Option< __FormerEnd >, + pub fn new() -> Self + { + Self + } } -impl< __FormerContext, __FormerEnd > Struct1Former< __FormerContext, __FormerEnd > -where - __FormerEnd: the_module::FormingEnd, +impl former::FormerDescriptor +for Struct1FormerDescriptor { + type Storage = Struct1FormerStorage; + type Formed = Struct1; +} - fn form( mut self ) -> Struct1 +impl former::StoragePerform +for Struct1FormerStorage +{ + type Formed = Struct1; + + fn preform( mut self ) -> Self::Formed { - let int_1 = if self.storage.int_1.is_some() + let int_1 = if self.int_1.is_some() { - self.storage.int_1.take().unwrap() + self.int_1.take().unwrap() } else { @@ -82,9 +86,9 @@ where val }; - let string_1 = if self.storage.string_1.is_some() + let string_1 = if self.string_1.is_some() { - self.storage.string_1.take().unwrap() + self.string_1.take().unwrap() } else { @@ -92,25 +96,25 @@ where val }; - let int_optional_1 = if self.storage.int_optional_1.is_some() + let int_optional_1 = if self.int_optional_1.is_some() { - Some( self.storage.int_optional_1.take().unwrap() ) + Some( self.int_optional_1.take().unwrap() ) } else { None }; - let string_optional_1 = if self.storage.string_optional_1.is_some() + let string_optional_1 = if self.string_optional_1.is_some() { - Some( self.storage.string_optional_1.take().unwrap() ) + Some( self.string_optional_1.take().unwrap() ) } else { None }; - Struct1 + Self::Formed { int_1, string_1, @@ -120,45 +124,123 @@ where } - #[ inline( always ) ] - pub fn perform(self) -> Struct1 +} + +// + +pub struct Struct1Former +< + FormerContext = Struct1, + FormerEnd = the_module::ReturnStorage, +> +where + FormerEnd : the_module::FormingEnd< Struct1FormerDescriptor, FormerContext >, +{ + storage : Struct1FormerStorage, + context : core::option::Option< FormerContext >, + on_end : core::option::Option< FormerEnd >, +} + +impl< FormerContext, FormerEnd > Struct1Former< FormerContext, FormerEnd > +where + FormerEnd: the_module::FormingEnd< Struct1FormerDescriptor, FormerContext >, +{ + + // xxx : test that method exists + fn preform( mut self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed { - let result = self.form(); - return result; + + former::StoragePerform::preform( self.storage ) + +// let int_1 = if self.storage.int_1.is_some() +// { +// self.storage.int_1.take().unwrap() +// } +// else +// { +// let val : i32 = Default::default(); +// val +// }; +// +// let string_1 = if self.storage.string_1.is_some() +// { +// self.storage.string_1.take().unwrap() +// } +// else +// { +// let val : String = Default::default(); +// val +// }; +// +// let int_optional_1 = if self.storage.int_optional_1.is_some() +// { +// Some( self.storage.int_optional_1.take().unwrap() ) +// } +// else +// { +// None +// }; +// +// let string_optional_1 = if self.storage.string_optional_1.is_some() +// { +// Some( self.storage.string_optional_1.take().unwrap() ) +// } +// else +// { +// None +// }; +// +// Struct1 +// { +// int_1, +// string_1, +// int_optional_1, +// string_optional_1, +// } + } #[ inline( always ) ] - pub fn new() -> Struct1Former + pub fn perform(self) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed { - Struct1Former:: - < - Struct1, - the_module::ReturnStorage, - >::begin(None, the_module::ReturnStorage) + let result = self.form(); + return result; } #[ inline( always ) ] pub fn begin ( - context : core::option::Option< __FormerContext >, - on_end : __FormerEnd, + mut storage : core::option::Option< < Struct1FormerDescriptor as former::FormerDescriptor >::Storage >, + // xxx : cover by test existance of these 3 parameters in the function + context : core::option::Option< FormerContext >, + on_end : FormerEnd, ) -> Self { + if storage.is_none() + { + storage = Some( core::default::Default::default() ); + } Self { - storage : core::default::Default::default(), + storage : storage.unwrap(), context : context, on_end : ::core::option::Option::Some( on_end ), } } #[ inline( always ) ] - pub fn end( mut self ) -> __FormerContext + pub fn form( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + { + self.end() + } + + #[ inline( always ) ] + pub fn end( mut self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) + // let formed = self.preform(); + on_end.call( self.storage, context ) } pub fn int_1< Src >( mut self, src : Src ) -> Self @@ -187,6 +269,23 @@ where } +impl Struct1Former< (), the_module::ReturnStorage > +{ + + // xxx : make sure it's covered by tests + #[ inline( always ) ] + pub fn new() -> Struct1Former< (), the_module::ReturnStorage > + { + Struct1Former::< (), the_module::ReturnStorage >::begin( None, None, the_module::ReturnStorage ) + // Struct1Former:: + // < + // Struct1, + // the_module::ReturnStorage, + // >::begin( None, the_module::ReturnStorage ) + } + +} + // -include!( "../only_test/primitives.rs" ); +include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs new file mode 100644 index 0000000000..80d3b5f618 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs @@ -0,0 +1,192 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ derive( Debug, PartialEq ) ] +pub struct Struct1 +{ + pub int_1 : i32, + string_1 : String, + int_optional_1 : core::option::Option< i32 >, + string_optional_1 : Option< String >, +} + +// + +// generated by former +impl Struct1 +{ + pub fn former() -> Struct1Former< Struct1, the_module::ReturnFormed > + { + Struct1Former::< Struct1, the_module::ReturnFormed >::new() + } +} + +// + +// generated by former +pub struct Struct1FormerStorage +{ + pub int_1 : core::option::Option< i32 >, + pub string_1 : core::option::Option< String >, + pub int_optional_1 : core::option::Option< i32 >, + pub string_optional_1 : core::option::Option< String >, +} + +impl Default for Struct1FormerStorage +{ + + #[ inline( always ) ] + fn default() -> Self + { + Self + { + int_1 : core::option::Option::None, + string_1 : core::option::Option::None, + int_optional_1 : core::option::Option::None, + string_optional_1 : core::option::Option::None, + } + } + +} + +// + +pub struct Struct1Former +< + FormerContext = Struct1, + FormerEnd = the_module::ReturnFormed, +> +where + FormerEnd : the_module::FormingEnd< Struct1, FormerContext >, +{ + storage : Struct1FormerStorage, + context : core::option::Option< FormerContext >, + on_end : core::option::Option< FormerEnd >, +} + +impl< FormerContext, FormerEnd > Struct1Former< FormerContext, FormerEnd > +where + FormerEnd: the_module::FormingEnd, +{ + + fn form( mut self ) -> Struct1 + { + + let int_1 = if self.storage.int_1.is_some() + { + self.storage.int_1.take().unwrap() + } + else + { + let val : i32 = Default::default(); + val + }; + + let string_1 = if self.storage.string_1.is_some() + { + self.storage.string_1.take().unwrap() + } + else + { + let val : String = Default::default(); + val + }; + + let int_optional_1 = if self.storage.int_optional_1.is_some() + { + Some( self.storage.int_optional_1.take().unwrap() ) + } + else + { + None + }; + + let string_optional_1 = if self.storage.string_optional_1.is_some() + { + Some( self.storage.string_optional_1.take().unwrap() ) + } + else + { + None + }; + + Struct1 + { + int_1, + string_1, + int_optional_1, + string_optional_1, + } + + } + + #[ inline( always ) ] + pub fn perform(self) -> Struct1 + { + let result = self.form(); + return result; + } + + #[ inline( always ) ] + pub fn new() -> Struct1Former + { + Struct1Former:: + < + Struct1, + the_module::ReturnFormed, + >::begin(None, the_module::ReturnFormed) + } + + #[ inline( always ) ] + pub fn begin + ( + context : core::option::Option< FormerContext >, + on_end : FormerEnd, + ) -> Self + { + Self + { + storage : core::default::Default::default(), + context : context, + on_end : ::core::option::Option::Some( on_end ), + } + } + + #[ inline( always ) ] + pub fn end( mut self ) -> FormerContext + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + let formed = self.form(); + on_end.call( formed, context ) + } + + pub fn int_1< Src >( mut self, src : Src ) -> Self + where Src : core::convert::Into< i32 >, + { + debug_assert!( self.storage.int_1.is_none() ); + self.storage.int_1 = Some( src.into() ); + self + } + + pub fn string_1< Src >( mut self, src : Src ) -> Self + where Src : core::convert::Into< String >, + { + debug_assert!( self.storage.string_1.is_none() ); + self.storage.string_1 = Some( src.into() ); + self + } + + pub fn string_optional_1< Src >( mut self, src : Src ) -> Self + where Src : core::convert::Into< String > + { + debug_assert!( self.storage.string_optional_1.is_none() ); + self.storage.string_optional_1 = Some( src.into() ); + self + } + +} + +// + +include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/name_collisions.rs b/module/core/former/tests/inc/former_tests/name_collisions.rs index 5aef9ca9f1..28a379f137 100644 --- a/module/core/former/tests/inc/former_tests/name_collisions.rs +++ b/module/core/former/tests/inc/former_tests/name_collisions.rs @@ -34,4 +34,4 @@ pub struct Struct1 // -include!( "../only_test/containers_without_runtime.rs" ); +include!( "./only_test/containers_without_runtime.rs" ); diff --git a/module/core/former/tests/inc/only_test/containers_with_runtime.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_runtime.rs similarity index 100% rename from module/core/former/tests/inc/only_test/containers_with_runtime.rs rename to module/core/former/tests/inc/former_tests/only_test/containers_with_runtime.rs diff --git a/module/core/former/tests/inc/only_test/containers_without_runtime.rs b/module/core/former/tests/inc/former_tests/only_test/containers_without_runtime.rs similarity index 100% rename from module/core/former/tests/inc/only_test/containers_without_runtime.rs rename to module/core/former/tests/inc/former_tests/only_test/containers_without_runtime.rs diff --git a/module/core/former/tests/inc/only_test/parametrized_struct.rs b/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs similarity index 100% rename from module/core/former/tests/inc/only_test/parametrized_struct.rs rename to module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs diff --git a/module/core/former/tests/inc/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs similarity index 98% rename from module/core/former/tests/inc/only_test/primitives.rs rename to module/core/former/tests/inc/former_tests/only_test/primitives.rs index 1f82d9c424..35bd57ad36 100644 --- a/module/core/former/tests/inc/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -24,7 +24,7 @@ tests_impls! a_id!( former.storage.string_optional_1, None ); a_id!( former.context, None ); a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnStorage ) ) ); - let former2 = Struct1Former::< Struct1, the_module::ReturnStorage >::new(); + let former2 = Struct1Former::new(); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); diff --git a/module/core/former/tests/inc/only_test/string_slice.rs b/module/core/former/tests/inc/former_tests/only_test/string_slice.rs similarity index 100% rename from module/core/former/tests/inc/only_test/string_slice.rs rename to module/core/former/tests/inc/former_tests/only_test/string_slice.rs diff --git a/module/core/former/tests/inc/only_test/subformer_basic.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs similarity index 100% rename from module/core/former/tests/inc/only_test/subformer_basic.rs rename to module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs diff --git a/module/core/former/tests/inc/only_test/with_field_under_feature.rs b/module/core/former/tests/inc/former_tests/only_test/with_field_under_feature.rs similarity index 100% rename from module/core/former/tests/inc/only_test/with_field_under_feature.rs rename to module/core/former/tests/inc/former_tests/only_test/with_field_under_feature.rs diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs index 2212f4c08b..7318cacb1f 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs @@ -32,4 +32,4 @@ pub struct Command< K : core::hash::Hash + std::cmp::Eq > // == -include!( "../only_test/parametrized_struct.rs" ); +include!( "./only_test/parametrized_struct.rs" ); diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 18d778bf2b..6e201046bc 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -200,4 +200,4 @@ where // == -include!( "../only_test/parametrized_struct.rs" ); +include!( "./only_test/parametrized_struct.rs" ); diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs index c3b12924b7..7306f1b229 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs @@ -34,4 +34,4 @@ where // == -include!( "../only_test/parametrized_struct.rs" ); +include!( "./only_test/parametrized_struct.rs" ); diff --git a/module/core/former/tests/inc/former_tests/string_slice.rs b/module/core/former/tests/inc/former_tests/string_slice.rs index b0c032d9cd..63270eec4e 100644 --- a/module/core/former/tests/inc/former_tests/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/string_slice.rs @@ -8,4 +8,4 @@ pub struct Struct1< 'a > // -include!( "../only_test/string_slice.rs" ); +include!( "./only_test/string_slice.rs" ); diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 5d3143d25f..98988cb6cc 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -54,4 +54,4 @@ impl< 'a > Struct1Former< 'a > // -include!( "../only_test/string_slice.rs" ); +include!( "./only_test/string_slice.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index e847a543df..bee9c75113 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -143,4 +143,4 @@ where // == -include!( "../only_test/subformer_basic.rs" ); +include!( "./only_test/subformer_basic.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs b/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs index 3acfa5bc03..3bc5c46a73 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs @@ -462,4 +462,4 @@ where // == -include!( "../only_test/subformer_basic.rs" ); +include!( "./only_test/subformer_basic.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 8eff590826..6484e5c881 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -8,54 +8,54 @@ mod former_tests use super::*; mod a_primitives_manual; - mod a_containers_without_runtime_manual; - mod a_containers_without_runtime; - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_runtime_manual; - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_runtime ; - - mod attribute_default_container; - mod attribute_default_primitive; - mod attribute_perform; - mod attribute_setter; - mod attribute_alias; - - mod string_slice_manual; - mod string_slice; - mod unsigned_primitive_types; - mod default_user_type; - mod user_type_no_default; - mod user_type_no_debug; - - mod name_collision_former_hashmap_without_parameter; - mod name_collision_former_vector_without_parameter; - mod name_collisions; - mod name_collision_context; - mod name_collision_end; - mod name_collision_on_end; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_manual; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_imm; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_where; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_basic_manual; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_basic; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_vec; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_hashset; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_hashmap; - - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_shortcut; +// mod a_containers_without_runtime_manual; +// mod a_containers_without_runtime; +// #[ cfg( not( feature = "no_std" ) ) ] +// mod a_containers_with_runtime_manual; +// #[ cfg( not( feature = "no_std" ) ) ] +// mod a_containers_with_runtime ; +// +// mod attribute_default_container; +// mod attribute_default_primitive; +// mod attribute_perform; +// mod attribute_setter; +// mod attribute_alias; +// +// mod string_slice_manual; +// mod string_slice; +// mod unsigned_primitive_types; +// mod default_user_type; +// mod user_type_no_default; +// mod user_type_no_debug; +// +// mod name_collision_former_hashmap_without_parameter; +// mod name_collision_former_vector_without_parameter; +// mod name_collisions; +// mod name_collision_context; +// mod name_collision_end; +// mod name_collision_on_end; +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_manual; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_imm; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_where; +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_basic_manual; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_basic; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_vec; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_hashset; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_hashmap; +// +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_shortcut; } @@ -104,9 +104,22 @@ only_for_terminal_module! println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); let t = test_tools::compiletime::TestCases::new(); - t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); - t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); - t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); + // xxx + // t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); + // t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); + // t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); + + } + + // stable have different information about error + // that's why these tests are active only for nightly + #[ test_tools::nightly ] + #[ test ] + fn components_trybuild() + { + + println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); + let t = test_tools::compiletime::TestCases::new(); //t.compile_fail( "tests/inc/compiletime/components_component_from_debug.rs" ); diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index e3c1375893..38dd6c8d7d 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -846,7 +846,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > }; extra_generics.where_clause = parse_quote! { - where __FormerEnd : former::FormingEnd< #name_ident #generics_ty, __FormerContext >, + where + __FormerEnd : former::FormingEnd< #name_ident #generics_ty, __FormerContext >, }; // xxx : write helper to fix bug with where let generics_of_former = generics::merge( &generics, &extra_generics ); @@ -962,6 +963,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > storage : #former_storage_name_ident #generics_ty, context : core::option::Option< __FormerContext >, on_end : core::option::Option< __FormerEnd >, + // xxx : should on_end be optional? } #[ automatically_derived ] @@ -975,7 +977,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// `perform` has no effect on method `form`, but change behavior and returned type of method `perform`. /// #[ inline( always ) ] - pub fn form( mut self ) -> #name_ident #generics_ty + pub fn preform( mut self ) -> #name_ident #generics_ty { #( #fields_form )* let result = #name_ident @@ -1021,6 +1023,15 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } + /// + /// End the process of forming returning original context of forming. + /// + #[ inline( always ) ] + pub fn form( self ) -> __FormerContext + { + self.end() + } + /// /// End the process of forming returning original context of forming. /// diff --git a/module/core/test_tools/Cargo.toml b/module/core/test_tools/Cargo.toml index 26b95f2926..d3c8134dee 100644 --- a/module/core/test_tools/Cargo.toml +++ b/module/core/test_tools/Cargo.toml @@ -38,8 +38,8 @@ no_std = [ # "typing_tools/no_std", # "data_type/no_std", # "diagnostics_tools/no_std", - # "process_tools/no_std", - "former/use_alloc", + # "process_tools_published/no_std", + # "former_stable/use_alloc", ] use_alloc = [ "no_std", @@ -49,8 +49,8 @@ use_alloc = [ # "typing_tools/use_alloc", # "data_type/use_alloc", # "diagnostics_tools/use_alloc", - # "process_tools/use_alloc", - "former/use_alloc", + # "process_tools_published/use_alloc", + # "former_stable/use_alloc", ] enabled = [ "error_tools/enabled", @@ -59,7 +59,7 @@ enabled = [ "typing_tools/enabled", "data_type/enabled", "diagnostics_tools/enabled", - "process_tools/enabled", + "process_tools_published/enabled", ] # nightly = [ "typing_tools/nightly" ] @@ -82,8 +82,8 @@ mem_tools = { workspace = true, features = [ "full" ] } typing_tools = { workspace = true, features = [ "full" ] } data_type = { workspace = true, features = [ "full" ] } diagnostics_tools = { workspace = true, features = [ "full" ] } -process_tools = { workspace = true, features = [ "full" ] } -former = { workspace = true, features = [ "full" ] } +process_tools_published = { workspace = true, features = [ "full" ] } +# former_stable = { workspace = true, features = [ "full" ] } [build-dependencies] rustc_version = "0.4" diff --git a/module/core/test_tools/src/lib.rs b/module/core/test_tools/src/lib.rs index ed762f40fe..babcb96c49 100644 --- a/module/core/test_tools/src/lib.rs +++ b/module/core/test_tools/src/lib.rs @@ -39,9 +39,13 @@ pub mod dependency #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use ::diagnostics_tools; - // #[ doc( inline ) ] - // #[ allow( unused_imports ) ] - // pub use ::process_tools; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use ::process_tools_published; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use ::process_tools_published as process_tools; } diff --git a/module/core/test_tools/src/test/smoke_test.rs b/module/core/test_tools/src/test/smoke_test.rs index 8c671f72fc..29016a79bf 100644 --- a/module/core/test_tools/src/test/smoke_test.rs +++ b/module/core/test_tools/src/test/smoke_test.rs @@ -11,7 +11,8 @@ /// Internal namespace. pub( crate ) mod private { - use process_tools::environment; + use crate::*; + use dependency::process_tools::environment; // zzz : comment out // pub mod environment // { From 70f6390f27ead0a1dce0395939ac129ff0601e56 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 12:28:50 +0200 Subject: [PATCH 004/533] former : experimenting --- module/core/former/src/axiomatic3.rs | 8 ++-- module/core/former/src/hash_map.rs | 9 +++- module/core/former/src/hash_set.rs | 9 +++- module/core/former/src/vector3.rs | 5 ++- .../inc/former_tests/a_primitives_manual.rs | 13 +++--- .../inc/former_tests/only_test/primitives.rs | 45 ++++++++++++++++--- module/core/former/tests/inc/mod.rs | 4 +- 7 files changed, 70 insertions(+), 23 deletions(-) diff --git a/module/core/former/src/axiomatic3.rs b/module/core/former/src/axiomatic3.rs index b618c9e289..c1132e8599 100644 --- a/module/core/former/src/axiomatic3.rs +++ b/module/core/former/src/axiomatic3.rs @@ -3,14 +3,15 @@ /// xxx pub trait StoragePerform : ::core::default::Default { - type Formed; - fn preform( self ) -> Self::Formed; + // type FormedResult; + type Descriptor : FormerDescriptor< Storage = Self >; + fn preform( self ) -> < < Self as StoragePerform >::Descriptor as FormerDescriptor >::Formed; } /// xxx pub trait FormerDescriptor { - type Storage : StoragePerform< Formed = Self::Formed >; + type Storage : StoragePerform< Descriptor = Self >; type Formed; // type Former; } @@ -176,7 +177,6 @@ for FormingEndWrapper< Former, Context > /// sophisticated and flexible construction patterns conducive to complex data transformations or object creation /// sequences within builder patterns. -// xxx : change sequence pub trait FormerBegin< Former : FormerDescriptor, Context > { diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 7837743d90..169c9baa19 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -70,8 +70,13 @@ for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Formed = Self; - fn preform( self ) -> Self::Formed + // type Formed = Self; + // fn preform( self ) -> Self::Formed + // { + // self + // } + type Descriptor = HashMapDescriptor< K, E >; + fn preform( self ) -> < < Self as StoragePerform >::Descriptor as FormerDescriptor >::Formed { self } diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 3b662e7f25..a2ac818a72 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -58,11 +58,16 @@ for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Formed = Self; - fn preform( self ) -> Self::Formed + type Descriptor = HashSetDescriptor< K >; + fn preform( self ) -> < < Self as StoragePerform >::Descriptor as FormerDescriptor >::Formed { self } + // type Formed = Self; + // fn preform( self ) -> Self::Formed + // { + // self + // } } impl< K > FormerDescriptor diff --git a/module/core/former/src/vector3.rs b/module/core/former/src/vector3.rs index b7fa2ccee5..4fa91ea0a9 100644 --- a/module/core/former/src/vector3.rs +++ b/module/core/former/src/vector3.rs @@ -47,8 +47,9 @@ for VectorDescriptor< E > impl< E > StoragePerform for Vec< E > { - type Formed = Self; - fn preform( self ) -> Self::Formed + // type Formed = Self; + type Descriptor = VectorDescriptor< E >; + fn preform( self ) -> < < Self as StoragePerform >::Descriptor as FormerDescriptor >::Formed { self } diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 6feb243a4b..cfb72c929f 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -15,7 +15,6 @@ pub struct Struct1 // generated by former impl Struct1 { - // xxx : make sure it's covered by tests pub fn former() -> Struct1Former< (), the_module::ReturnStorage > { Struct1Former::new() @@ -71,9 +70,10 @@ for Struct1FormerDescriptor impl former::StoragePerform for Struct1FormerStorage { - type Formed = Struct1; + // type Formed = Struct1; + type Descriptor = Struct1FormerDescriptor; - fn preform( mut self ) -> Self::Formed + fn preform( mut self ) -> < < Self as former::StoragePerform >::Descriptor as former::FormerDescriptor >::Formed { let int_1 = if self.int_1.is_some() @@ -114,7 +114,9 @@ for Struct1FormerStorage None }; - Self::Formed + // < Self::Descriptor as former::FormerDescriptor >::Formed + // < < Self as former::StoragePerform >::Descriptor as former::FormerDescriptor >::Formed + Struct1 { int_1, string_1, @@ -147,9 +149,10 @@ where { // xxx : test that method exists - fn preform( mut self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + fn preform( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed { + // xxx : test that method exists former::StoragePerform::preform( self.storage ) // let int_1 = if self.storage.int_1.is_some() diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 35bd57ad36..09a40260f7 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -11,12 +11,6 @@ tests_impls! fn internals() { - // // test.case( "vector : construction" ); - // int_1, - // string_1, - // int_optional_1, - // string_optional_1, - let former = Struct1::former(); a_id!( former.storage.int_1, None ); a_id!( former.storage.string_1, None ); @@ -47,6 +41,43 @@ tests_impls! } + // + + fn preform() + { + + // formation should have method preform + let got = Struct1::former().preform(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + // storage should have method preform + let got = the_module::StoragePerform::preform( Struct1::former().storage ); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + // storage should have method preform + use the_module::StoragePerform; + let got = Struct1::former().storage.preform(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + } + + // + + fn descriptor() + { + + // descriptor exists + let got = < Struct1FormerDescriptor as the_module::FormerDescriptor >::Formed::former().form(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + } + + // + fn test_int() { @@ -229,6 +260,8 @@ tests_impls! tests_index! { internals, + preform, + descriptor, test_int, test_string, test_optional_string, diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 6484e5c881..8c608b2d62 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -102,7 +102,7 @@ only_for_terminal_module! { println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); - let t = test_tools::compiletime::TestCases::new(); + // let t = test_tools::compiletime::TestCases::new(); // xxx // t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); @@ -119,7 +119,7 @@ only_for_terminal_module! { println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); - let t = test_tools::compiletime::TestCases::new(); + let _t = test_tools::compiletime::TestCases::new(); //t.compile_fail( "tests/inc/compiletime/components_component_from_debug.rs" ); From b982849ce49281ad6119342b1df2d632cb17b7a5 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 13:13:50 +0200 Subject: [PATCH 005/533] former : experimenting --- module/core/former/src/axiomatic3.rs | 2 - .../inc/former_tests/a_primitives_manual.rs | 72 ++----------------- .../inc/former_tests/only_test/primitives.rs | 33 ++++++++- 3 files changed, 39 insertions(+), 68 deletions(-) diff --git a/module/core/former/src/axiomatic3.rs b/module/core/former/src/axiomatic3.rs index c1132e8599..6089a5a814 100644 --- a/module/core/former/src/axiomatic3.rs +++ b/module/core/former/src/axiomatic3.rs @@ -3,7 +3,6 @@ /// xxx pub trait StoragePerform : ::core::default::Default { - // type FormedResult; type Descriptor : FormerDescriptor< Storage = Self >; fn preform( self ) -> < < Self as StoragePerform >::Descriptor as FormerDescriptor >::Formed; } @@ -13,7 +12,6 @@ pub trait FormerDescriptor { type Storage : StoragePerform< Descriptor = Self >; type Formed; - // type Former; } // pub trait FormerDefinition diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index cfb72c929f..410af863b5 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -70,7 +70,6 @@ for Struct1FormerDescriptor impl former::StoragePerform for Struct1FormerStorage { - // type Formed = Struct1; type Descriptor = Struct1FormerDescriptor; fn preform( mut self ) -> < < Self as former::StoragePerform >::Descriptor as former::FormerDescriptor >::Formed @@ -114,7 +113,7 @@ for Struct1FormerStorage None }; - // < Self::Descriptor as former::FormerDescriptor >::Formed + // xxx : Rust failt to use parameter here // < < Self as former::StoragePerform >::Descriptor as former::FormerDescriptor >::Formed Struct1 { @@ -148,59 +147,9 @@ where FormerEnd: the_module::FormingEnd< Struct1FormerDescriptor, FormerContext >, { - // xxx : test that method exists fn preform( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed { - - // xxx : test that method exists former::StoragePerform::preform( self.storage ) - -// let int_1 = if self.storage.int_1.is_some() -// { -// self.storage.int_1.take().unwrap() -// } -// else -// { -// let val : i32 = Default::default(); -// val -// }; -// -// let string_1 = if self.storage.string_1.is_some() -// { -// self.storage.string_1.take().unwrap() -// } -// else -// { -// let val : String = Default::default(); -// val -// }; -// -// let int_optional_1 = if self.storage.int_optional_1.is_some() -// { -// Some( self.storage.int_optional_1.take().unwrap() ) -// } -// else -// { -// None -// }; -// -// let string_optional_1 = if self.storage.string_optional_1.is_some() -// { -// Some( self.storage.string_optional_1.take().unwrap() ) -// } -// else -// { -// None -// }; -// -// Struct1 -// { -// int_1, -// string_1, -// int_optional_1, -// string_optional_1, -// } - } #[ inline( always ) ] @@ -231,21 +180,20 @@ where } } - #[ inline( always ) ] - pub fn form( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed - { - self.end() - } - #[ inline( always ) ] pub fn end( mut self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - // let formed = self.preform(); on_end.call( self.storage, context ) } + #[ inline( always ) ] + pub fn form( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + { + self.end() + } + pub fn int_1< Src >( mut self, src : Src ) -> Self where Src : core::convert::Into< i32 >, { @@ -275,16 +223,10 @@ where impl Struct1Former< (), the_module::ReturnStorage > { - // xxx : make sure it's covered by tests #[ inline( always ) ] pub fn new() -> Struct1Former< (), the_module::ReturnStorage > { Struct1Former::< (), the_module::ReturnStorage >::begin( None, None, the_module::ReturnStorage ) - // Struct1Former:: - // < - // Struct1, - // the_module::ReturnStorage, - // >::begin( None, the_module::ReturnStorage ) } } diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 09a40260f7..064323516b 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -69,11 +69,41 @@ tests_impls! fn descriptor() { - // descriptor exists + // descriptor exists and has Formed let got = < Struct1FormerDescriptor as the_module::FormerDescriptor >::Formed::former().form(); let exp = Struct1::former().form(); a_id!( got, exp ); + // descriptor exists and has Storage + use former::StoragePerform; + let got = < Struct1FormerDescriptor as the_module::FormerDescriptor >::Storage::preform( Struct1::former().storage ); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + } + + // + + fn storage() + { + + // descriptor exists and has Storage + // use former::StoragePerform; + let got = < Struct1FormerStorage as the_module::StoragePerform >::preform( Struct1::former().storage ); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + // descriptor exists and has Storage + use former::StoragePerform; + let got = Struct1::former().storage.preform(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + // storage exists + let got = < < Struct1FormerStorage as the_module::StoragePerform >::Descriptor as the_module::FormerDescriptor >::Formed::former().form(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + } // @@ -262,6 +292,7 @@ tests_index! internals, preform, descriptor, + storage, test_int, test_string, test_optional_string, From 4094317269795305888df3086e023fa84a2fb26e Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 13:23:43 +0200 Subject: [PATCH 006/533] former : experimenting --- module/core/former/src/axiomatic3.rs | 10 +++++-- module/core/former/src/hash_map.rs | 30 +++++++++++-------- module/core/former/src/hash_set.rs | 20 ++++++++----- module/core/former/src/vector3.rs | 11 +++++-- .../inc/former_tests/a_primitives_manual.rs | 11 +++++-- .../inc/former_tests/only_test/primitives.rs | 2 +- 6 files changed, 55 insertions(+), 29 deletions(-) diff --git a/module/core/former/src/axiomatic3.rs b/module/core/former/src/axiomatic3.rs index 6089a5a814..1c16f54205 100644 --- a/module/core/former/src/axiomatic3.rs +++ b/module/core/former/src/axiomatic3.rs @@ -1,10 +1,14 @@ //! .... -/// xxx -pub trait StoragePerform : ::core::default::Default +pub trait Storage : ::core::default::Default { type Descriptor : FormerDescriptor< Storage = Self >; - fn preform( self ) -> < < Self as StoragePerform >::Descriptor as FormerDescriptor >::Formed; +} + +/// xxx +pub trait StoragePerform : Storage +{ + fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed; } /// xxx diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 169c9baa19..771a8b30cb 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -65,30 +65,36 @@ where } } -impl< K, E > StoragePerform +impl< K, E > FormerDescriptor +for HashMapDescriptor< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Storage = HashMap< K, E >; + type Formed = HashMap< K, E >; +} + +impl< K, E > Storage for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - // type Formed = Self; - // fn preform( self ) -> Self::Formed + type Descriptor = HashMapDescriptor< K, E >; + // fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed // { // self // } - type Descriptor = HashMapDescriptor< K, E >; - fn preform( self ) -> < < Self as StoragePerform >::Descriptor as FormerDescriptor >::Formed - { - self - } } -impl< K, E > FormerDescriptor -for HashMapDescriptor< K, E > +impl< K, E > StoragePerform +for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Storage = HashMap< K, E >; - type Formed = HashMap< K, E >; + fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed + { + self + } } /// A builder for constructing hash map-like structures with a fluent interface. diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index a2ac818a72..07b274b5c3 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -53,23 +53,29 @@ where } } -impl< K > StoragePerform +impl< K > Storage for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { type Descriptor = HashSetDescriptor< K >; - fn preform( self ) -> < < Self as StoragePerform >::Descriptor as FormerDescriptor >::Formed - { - self - } - // type Formed = Self; - // fn preform( self ) -> Self::Formed + // fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed // { // self // } } +impl< K > StoragePerform +for HashSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed + { + self + } +} + impl< K > FormerDescriptor for HashSetDescriptor< K > where diff --git a/module/core/former/src/vector3.rs b/module/core/former/src/vector3.rs index 4fa91ea0a9..c3300e25de 100644 --- a/module/core/former/src/vector3.rs +++ b/module/core/former/src/vector3.rs @@ -44,12 +44,17 @@ for VectorDescriptor< E > type Formed = Vec< E >; } -impl< E > StoragePerform +impl< E > Storage for Vec< E > { - // type Formed = Self; type Descriptor = VectorDescriptor< E >; - fn preform( self ) -> < < Self as StoragePerform >::Descriptor as FormerDescriptor >::Formed +} + +impl< E > StoragePerform +for Vec< E > +{ + // type Descriptor = VectorDescriptor< E >; + fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed { self } diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 410af863b5..cdb73bb74f 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -67,12 +67,17 @@ for Struct1FormerDescriptor type Formed = Struct1; } -impl former::StoragePerform +impl former::Storage for Struct1FormerStorage { type Descriptor = Struct1FormerDescriptor; +} + +impl former::StoragePerform +for Struct1FormerStorage +{ - fn preform( mut self ) -> < < Self as former::StoragePerform >::Descriptor as former::FormerDescriptor >::Formed + fn preform( mut self ) -> < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed { let int_1 = if self.int_1.is_some() @@ -114,7 +119,7 @@ for Struct1FormerStorage }; // xxx : Rust failt to use parameter here - // < < Self as former::StoragePerform >::Descriptor as former::FormerDescriptor >::Formed + // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed Struct1 { int_1, diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 064323516b..546e1679ae 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -100,7 +100,7 @@ tests_impls! a_id!( got, exp ); // storage exists - let got = < < Struct1FormerStorage as the_module::StoragePerform >::Descriptor as the_module::FormerDescriptor >::Formed::former().form(); + let got = < < Struct1FormerStorage as the_module::Storage >::Descriptor as the_module::FormerDescriptor >::Formed::former().form(); let exp = Struct1::former().form(); a_id!( got, exp ); From 058554bf75c1e71c78a08edf2f5cc1f3a9276137 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 15:35:17 +0200 Subject: [PATCH 007/533] former : experimenting --- module/core/former/src/vector3.rs | 3 +- .../tests/inc/former_tests/a_primitives.rs | 241 ++++++++++++++++++ .../inc/former_tests/a_primitives_expanded.rs | 18 ++ .../inc/former_tests/a_primitives_manual.rs | 168 ++++++------ .../a_primitives_manual_original.rs | 2 +- module/core/former/tests/inc/mod.rs | 2 + 6 files changed, 348 insertions(+), 86 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/a_primitives.rs create mode 100644 module/core/former/tests/inc/former_tests/a_primitives_expanded.rs diff --git a/module/core/former/src/vector3.rs b/module/core/former/src/vector3.rs index c3300e25de..00105bea11 100644 --- a/module/core/former/src/vector3.rs +++ b/module/core/former/src/vector3.rs @@ -211,7 +211,8 @@ where storage : core::option::Option< Descriptor::Storage >, context : core::option::Option< Context >, on_end : End, - ) -> Self + ) + -> Self { Self::begin( storage, context, on_end ) } diff --git a/module/core/former/tests/inc/former_tests/a_primitives.rs b/module/core/former/tests/inc/former_tests/a_primitives.rs new file mode 100644 index 0000000000..7a63846439 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/a_primitives.rs @@ -0,0 +1,241 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ derive( Debug, PartialEq, the_module::Former ) ] +pub struct Struct1 +{ + pub int_1 : i32, + string_1 : String, + int_optional_1 : core::option::Option< i32 >, + string_optional_1 : Option< String >, +} + +// + +// // generated by former +// impl Struct1 +// { +// pub fn former() -> Struct1Former< (), the_module::ReturnStorage > +// { +// Struct1Former::new() +// } +// } +// +// // +// +// // generated by former +// pub struct Struct1FormerStorage +// { +// pub int_1 : core::option::Option< i32 >, +// pub string_1 : core::option::Option< String >, +// pub int_optional_1 : core::option::Option< i32 >, +// pub string_optional_1 : core::option::Option< String >, +// } +// +// impl Default for Struct1FormerStorage +// { +// +// #[ inline( always ) ] +// fn default() -> Self +// { +// Self +// { +// int_1 : core::option::Option::None, +// string_1 : core::option::Option::None, +// int_optional_1 : core::option::Option::None, +// string_optional_1 : core::option::Option::None, +// } +// } +// +// } +// +// #[ derive( Debug ) ] +// pub struct Struct1FormerDescriptor; +// +// impl Struct1FormerDescriptor +// { +// pub fn new() -> Self +// { +// Self +// } +// } +// +// impl former::FormerDescriptor +// for Struct1FormerDescriptor +// { +// type Storage = Struct1FormerStorage; +// type Formed = Struct1; +// } +// +// impl former::Storage +// for Struct1FormerStorage +// { +// type Descriptor = Struct1FormerDescriptor; +// } +// +// impl former::StoragePerform +// for Struct1FormerStorage +// { +// +// fn preform( mut self ) -> < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed +// { +// +// let int_1 = if self.int_1.is_some() +// { +// self.int_1.take().unwrap() +// } +// else +// { +// let val : i32 = Default::default(); +// val +// }; +// +// let string_1 = if self.string_1.is_some() +// { +// self.string_1.take().unwrap() +// } +// else +// { +// let val : String = Default::default(); +// val +// }; +// +// let int_optional_1 = if self.int_optional_1.is_some() +// { +// Some( self.int_optional_1.take().unwrap() ) +// } +// else +// { +// None +// }; +// +// let string_optional_1 = if self.string_optional_1.is_some() +// { +// Some( self.string_optional_1.take().unwrap() ) +// } +// else +// { +// None +// }; +// +// // xxx : Rust failt to use parameter here +// // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed +// Struct1 +// { +// int_1, +// string_1, +// int_optional_1, +// string_optional_1, +// } +// +// } +// +// } +// +// // +// +// pub struct Struct1Former +// < +// FormerContext = Struct1, +// FormerEnd = the_module::ReturnStorage, +// > +// where +// FormerEnd : the_module::FormingEnd< Struct1FormerDescriptor, FormerContext >, +// { +// storage : Struct1FormerStorage, +// context : core::option::Option< FormerContext >, +// on_end : core::option::Option< FormerEnd >, +// } +// +// impl< FormerContext, FormerEnd > Struct1Former< FormerContext, FormerEnd > +// where +// FormerEnd: the_module::FormingEnd< Struct1FormerDescriptor, FormerContext >, +// { +// +// fn preform( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed +// { +// former::StoragePerform::preform( self.storage ) +// } +// +// #[ inline( always ) ] +// pub fn perform(self) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed +// { +// let result = self.form(); +// return result; +// } +// +// #[ inline( always ) ] +// pub fn begin +// ( +// mut storage : core::option::Option< < Struct1FormerDescriptor as former::FormerDescriptor >::Storage >, +// // xxx : cover by test existance of these 3 parameters in the function +// context : core::option::Option< FormerContext >, +// on_end : FormerEnd, +// ) -> Self +// { +// if storage.is_none() +// { +// storage = Some( core::default::Default::default() ); +// } +// Self +// { +// storage : storage.unwrap(), +// context : context, +// on_end : ::core::option::Option::Some( on_end ), +// } +// } +// +// #[ inline( always ) ] +// pub fn end( mut self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed +// { +// let on_end = self.on_end.take().unwrap(); +// let context = self.context.take(); +// on_end.call( self.storage, context ) +// } +// +// #[ inline( always ) ] +// pub fn form( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed +// { +// self.end() +// } +// +// pub fn int_1< Src >( mut self, src : Src ) -> Self +// where Src : core::convert::Into< i32 >, +// { +// debug_assert!( self.storage.int_1.is_none() ); +// self.storage.int_1 = Some( src.into() ); +// self +// } +// +// pub fn string_1< Src >( mut self, src : Src ) -> Self +// where Src : core::convert::Into< String >, +// { +// debug_assert!( self.storage.string_1.is_none() ); +// self.storage.string_1 = Some( src.into() ); +// self +// } +// +// pub fn string_optional_1< Src >( mut self, src : Src ) -> Self +// where Src : core::convert::Into< String > +// { +// debug_assert!( self.storage.string_optional_1.is_none() ); +// self.storage.string_optional_1 = Some( src.into() ); +// self +// } +// +// } +// +// impl Struct1Former< (), the_module::ReturnStorage > +// { +// +// #[ inline( always ) ] +// pub fn new() -> Struct1Former< (), the_module::ReturnStorage > +// { +// Struct1Former::< (), the_module::ReturnStorage >::begin( None, None, the_module::ReturnStorage ) +// } +// +// } + +// + +// include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs new file mode 100644 index 0000000000..1f1a5f72c4 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -0,0 +1,18 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ derive( Debug, PartialEq, the_module::Former ) ] +#[ debug ] +pub struct Struct1 +{ + pub int_1 : i32, + string_1 : String, + int_optional_1 : core::option::Option< i32 >, + string_optional_1 : Option< String >, +} + +// + +// + +// include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index cdb73bb74f..071c6d5aef 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -15,7 +15,7 @@ pub struct Struct1 // generated by former impl Struct1 { - pub fn former() -> Struct1Former< (), the_module::ReturnStorage > + pub fn former() -> Struct1Former< (), former::ReturnStorage > { Struct1Former::new() } @@ -49,89 +49,6 @@ impl Default for Struct1FormerStorage } -#[ derive( Debug ) ] -pub struct Struct1FormerDescriptor; - -impl Struct1FormerDescriptor -{ - pub fn new() -> Self - { - Self - } -} - -impl former::FormerDescriptor -for Struct1FormerDescriptor -{ - type Storage = Struct1FormerStorage; - type Formed = Struct1; -} - -impl former::Storage -for Struct1FormerStorage -{ - type Descriptor = Struct1FormerDescriptor; -} - -impl former::StoragePerform -for Struct1FormerStorage -{ - - fn preform( mut self ) -> < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed - { - - let int_1 = if self.int_1.is_some() - { - self.int_1.take().unwrap() - } - else - { - let val : i32 = Default::default(); - val - }; - - let string_1 = if self.string_1.is_some() - { - self.string_1.take().unwrap() - } - else - { - let val : String = Default::default(); - val - }; - - let int_optional_1 = if self.int_optional_1.is_some() - { - Some( self.int_optional_1.take().unwrap() ) - } - else - { - None - }; - - let string_optional_1 = if self.string_optional_1.is_some() - { - Some( self.string_optional_1.take().unwrap() ) - } - else - { - None - }; - - // xxx : Rust failt to use parameter here - // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed - Struct1 - { - int_1, - string_1, - int_optional_1, - string_optional_1, - } - - } - -} - // pub struct Struct1Former @@ -236,6 +153,89 @@ impl Struct1Former< (), the_module::ReturnStorage > } +#[ derive( Debug ) ] +pub struct Struct1FormerDescriptor; + +impl Struct1FormerDescriptor +{ + pub fn new() -> Self + { + Self + } +} + +impl former::FormerDescriptor +for Struct1FormerDescriptor +{ + type Storage = Struct1FormerStorage; + type Formed = Struct1; +} + +impl former::Storage +for Struct1FormerStorage +{ + type Descriptor = Struct1FormerDescriptor; +} + +impl former::StoragePerform +for Struct1FormerStorage +{ + + fn preform( mut self ) -> < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed + { + + let int_1 = if self.int_1.is_some() + { + self.int_1.take().unwrap() + } + else + { + let val : i32 = Default::default(); + val + }; + + let string_1 = if self.string_1.is_some() + { + self.string_1.take().unwrap() + } + else + { + let val : String = Default::default(); + val + }; + + let int_optional_1 = if self.int_optional_1.is_some() + { + Some( self.int_optional_1.take().unwrap() ) + } + else + { + None + }; + + let string_optional_1 = if self.string_optional_1.is_some() + { + Some( self.string_optional_1.take().unwrap() ) + } + else + { + None + }; + + // xxx : Rust failt to use parameter here + // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed + Struct1 + { + int_1, + string_1, + int_optional_1, + string_optional_1, + } + + } + +} + // include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs index 80d3b5f618..5db0ab5a74 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs @@ -15,7 +15,7 @@ pub struct Struct1 // generated by former impl Struct1 { - pub fn former() -> Struct1Former< Struct1, the_module::ReturnFormed > + pub fn former() -> Struct1Former< Struct1, Former::ReturnFormed > { Struct1Former::< Struct1, the_module::ReturnFormed >::new() } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 8c608b2d62..63cd87eede 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -8,6 +8,8 @@ mod former_tests use super::*; mod a_primitives_manual; + // mod a_primitives; + // mod a_primitives_expanded; // mod a_containers_without_runtime_manual; // mod a_containers_without_runtime; // #[ cfg( not( feature = "no_std" ) ) ] From 72b7efb3c01c19dfea6cc9bf35b122d24f2eef38 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 16:33:31 +0200 Subject: [PATCH 008/533] former : experimenting --- .../a_containers_with_runtime_manual.rs | 6 +- .../inc/former_tests/a_primitives_expanded.rs | 265 +++++++++++++++++- .../inc/former_tests/a_primitives_manual.rs | 1 + module/core/former/tests/inc/mod.rs | 2 +- module/core/former_meta/src/derive/former.rs | 92 ++++-- 5 files changed, 343 insertions(+), 23 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs index 0e2f2a2704..3cb0bfa769 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs @@ -9,7 +9,7 @@ pub struct Struct1 hashset_strings_1 : std::collections::HashSet< String >, } -// +// = formed impl Struct1 { @@ -19,6 +19,8 @@ impl Struct1 } } +// = storage + // generated by former pub struct Struct1FormerStorage { @@ -43,7 +45,7 @@ impl Default for Struct1FormerStorage } -// +// = former pub struct Struct1Former < diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs index 1f1a5f72c4..a31c9475cd 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -1,8 +1,9 @@ #[ allow( unused_imports ) ] use super::*; -#[ derive( Debug, PartialEq, the_module::Former ) ] -#[ debug ] +#[ derive( Debug, PartialEq ) ] +// #[ derive( Debug, PartialEq, the_module::Former ) ] +// #[ debug ] pub struct Struct1 { pub int_1 : i32, @@ -11,7 +12,265 @@ pub struct Struct1 string_optional_1 : Option< String >, } -// +// = formed + +impl Struct1 +{ + #[doc = r""] + #[doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step."] + #[doc = r""] + #[inline(always)] + pub fn former() -> Struct1Former<(), former::ReturnStorage> + { + Struct1Former::new() + } +} + +// = descriptor + +#[ derive( Debug ) ] +pub struct Struct1FormerDescriptor; + +impl Struct1FormerDescriptor +{ + pub fn new() -> Self + { + Self + } +} + +impl former::FormerDescriptor +for Struct1FormerDescriptor +{ + type Storage = Struct1FormerStorage; + type Formed = Struct1; +} + +// = storage + +pub struct Struct1FormerStorage +{ + #[doc = r" A field"] + pub int_1 : ::core::option::Option, + #[doc = r" A field"] + pub string_1 : ::core::option::Option, + #[doc = r" A field"] + pub int_optional_1 : core::option::Option, + #[doc = r" A field"] + pub string_optional_1 : Option, +} + +impl ::core::default::Default for Struct1FormerStorage +{ + #[inline(always)] + fn default() -> Self + { + Self + { + int_1 : ::core::option::Option::None, + string_1 : ::core::option::Option::None, + int_optional_1 : ::core::option::Option::None, + string_optional_1 : ::core::option::Option::None, + } + } +} + +impl former::Storage +for Struct1FormerStorage +{ + type Descriptor = Struct1FormerDescriptor; +} + +impl former::StoragePerform +for Struct1FormerStorage +{ + + fn preform( mut self ) -> Struct1 + { + + let int_1 = if self.int_1.is_some() + { + self.int_1.take().unwrap() + } + else + { + let val : i32 = Default::default(); + val + }; + + let string_1 = if self.string_1.is_some() + { + self.string_1.take().unwrap() + } + else + { + let val : String = Default::default(); + val + }; + + let int_optional_1 = if self.int_optional_1.is_some() + { + Some( self.int_optional_1.take().unwrap() ) + } + else + { + None + }; + + let string_optional_1 = if self.string_optional_1.is_some() + { + Some( self.string_optional_1.take().unwrap() ) + } + else + { + None + }; + + // xxx : Rust failt to use parameter here + // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed + Struct1 + { + int_1, + string_1, + int_optional_1, + string_optional_1, + } + + } + +} + +// = former + +#[automatically_derived] +pub struct Struct1Former +where FormerEnd : former::FormingEnd, +{ + storage : Struct1FormerStorage, + context : core::option::Option, + on_end : core::option::Option, +} + +#[automatically_derived] +impl Struct1Former +where FormerEnd : former::FormingEnd, +{ + #[doc = r""] + #[doc = r" Finish setting options and return formed entity."] + #[doc = r""] + #[doc = r" `perform` has no effect on method `form`, but change behavior and returned type of method `perform`."] + #[doc = r""] + #[inline(always)] + pub fn preform(self) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + { + < Struct1FormerStorage as former::StoragePerform >::preform( self.storage ) + } + + #[doc = r""] + #[doc = r" Finish setting options and call perform on formed entity."] + #[doc = r""] + #[doc = r" If `perform` defined then associated method is called and its result returned instead of entity."] + #[doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] + #[doc = r""] + #[inline(always)] + pub fn perform( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + { + let result = self.form(); + return result; + } + + #[doc = r""] + #[doc = r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] + #[inline(always)] + pub fn begin(mut storage : core::option::Option, context : core::option::Option, on_end : FormerEnd,) -> Self + { + if storage.is_none() + { + storage = Some(::core::default::Default::default()); + } + Self + { + storage: storage.unwrap(), + context: context, + on_end: ::core::option::Option::Some(on_end), + } + } + + #[doc = r""] + #[doc = r" End the process of forming returning original context of forming."] + #[doc = r""] + #[inline(always)] + pub fn form( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + { + self.end() + } + + #[doc = r""] + #[doc = r" End the process of forming returning original context of forming."] + #[doc = r""] + #[inline(always)] + pub fn end(mut self) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + // let storage = self.form(); + on_end.call(self.storage, context) + } + + #[doc = "Setter for the 'int_1' field."] + #[inline] + pub fn int_1(mut self, src: Src) -> Self + where Src: ::core::convert::Into, + { + debug_assert!(self.storage.int_1.is_none()); + self.storage.int_1 = ::core::option::Option::Some(src.into()); + self + } + + #[doc = "Setter for the 'string_1' field."] + #[inline] + pub fn string_1(mut self, src: Src) -> Self + where Src: ::core::convert::Into, + { + debug_assert!(self.storage.string_1.is_none()); + self.storage.string_1 = ::core::option::Option::Some(src.into()); + self + } + + #[doc = "Setter for the 'int_optional_1' field."] + #[inline] + pub fn int_optional_1(mut self, src: Src) -> Self + where Src: ::core::convert::Into, + { + debug_assert!(self.storage.int_optional_1.is_none()); + self.storage.int_optional_1 = ::core::option::Option::Some(src.into()); + self + } + + #[doc = "Setter for the 'string_optional_1' field."] + #[inline] + pub fn string_optional_1(mut self, src: Src) -> Self + where Src: ::core::convert::Into, + { + debug_assert!(self.storage.string_optional_1.is_none()); + self.storage.string_optional_1 = ::core::option::Option::Some(src.into()); + self + } +} + +#[automatically_derived] +impl Struct1Former<(), former::ReturnStorage> +{ + #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] + #[inline(always)] + pub fn new() -> Self + { + Self::begin(None, None, former::ReturnStorage,) + } +} // diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 071c6d5aef..7462251a80 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -32,6 +32,7 @@ pub struct Struct1FormerStorage pub string_optional_1 : core::option::Option< String >, } +// xxx : cover by test impl Default for Struct1FormerStorage { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 63cd87eede..8d654b850d 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -9,7 +9,7 @@ mod former_tests mod a_primitives_manual; // mod a_primitives; - // mod a_primitives_expanded; + mod a_primitives_expanded; // mod a_containers_without_runtime_manual; // mod a_containers_without_runtime; // #[ cfg( not( feature = "no_std" ) ) ] diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 38dd6c8d7d..3159903ea5 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -824,11 +824,14 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_name_ident = syn::Ident::new( &former_name, name_ident.span() ); let former_storage_name = format!( "{}FormerStorage", name_ident ); let former_storage_name_ident = syn::Ident::new( &former_storage_name, name_ident.span() ); + let former_descriptor_name = format!( "{}FormerDescriptor", name_ident ); + let former_descriptor_name_ident = syn::Ident::new( &former_descriptor_name, name_ident.span() ); /* generic parameters */ let generics = &ast.generics; let ( generics_impl, generics_ty, generics_where ) = generics.split_for_impl(); + // xxx : eliminate generics_params maybe let _generics_params = generics::params_names( generics ).params; let generics_params = if _generics_params.len() == 0 { @@ -847,7 +850,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > extra_generics.where_clause = parse_quote! { where - __FormerEnd : former::FormingEnd< #name_ident #generics_ty, __FormerContext >, + __FormerEnd : former::FormingEnd< #former_descriptor_name_ident #generics_ty, __FormerContext >, }; // xxx : write helper to fix bug with where let generics_of_former = generics::merge( &generics, &extra_generics ); @@ -915,6 +918,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let result = qt! { + // = formed + #[ automatically_derived ] impl #generics_impl #name_ident #generics_ty #generics_where @@ -923,12 +928,34 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// Make former, variation of builder pattern to form structure defining values of fields step by step. /// #[ inline( always ) ] - pub fn former() -> #former_name_ident < #generics_params #name_ident #generics_ty, former::ReturnStorage > + pub fn former() -> #former_name_ident < #generics_params (), former::ReturnStorage > { - #former_name_ident :: < #generics_params #name_ident #generics_ty, former::ReturnStorage > :: new() + #former_name_ident :: new() } } + // = descriptor + + #[ derive( Debug ) ] + pub struct #former_descriptor_name_ident #generics_impl; + + impl #generics_impl #former_descriptor_name_ident #generics_ty + { + pub fn new() -> Self + { + Self + } + } + + impl #generics_impl former::FormerDescriptor + for #former_descriptor_name_ident #generics_ty + { + type Storage = #former_storage_name_ident #generics_ty; + type Formed = #name_ident #generics_ty; + } + + // = storage + // xxx : rename to storage #[ doc = "Container of a corresponding former." ] pub struct #former_storage_name_ident #generics_ty @@ -955,6 +982,37 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } + impl #generics_impl former::Storage + for #former_storage_name_ident #generics_ty + #generics_where + { + // type Descriptor = Struct1FormerDescriptor; + type Descriptor = #former_descriptor_name_ident #generics_ty; + } + // generics_impl, generics_ty, generics_where + + impl former::StoragePerform + for #former_storage_name_ident #generics_ty + #generics_where + { + + fn preform( mut self ) -> #former_storage_name_ident #generics_ty + { + Self + { + #( #fields_form )* + let result = #name_ident + { + #( #fields_names, )* + }; + return result; + } + } + + } + + // = former + #[ doc = #doc_former_struct ] #[ automatically_derived ] pub struct #former_name_ident < #generics_of_former_with_defaults > @@ -974,17 +1032,17 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// /// Finish setting options and return formed entity. /// - /// `perform` has no effect on method `form`, but change behavior and returned type of method `perform`. - /// #[ inline( always ) ] - pub fn preform( mut self ) -> #name_ident #generics_ty + pub fn preform( self ) -> < former_descriptor_name_ident #generics_impl as former::FormerDescriptor >::Formed + // #name_ident #generics_ty { - #( #fields_form )* - let result = #name_ident - { - #( #fields_names, )* - }; - return result; + < #former_storage_name_ident #generics_ty as former::StoragePerform >::preform( self.storage ) + // #( #fields_form )* + // let result = #name_ident + // { + // #( #fields_names, )* + // }; + // return result; } /// @@ -1027,7 +1085,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn form( self ) -> __FormerContext + pub fn form( self ) -> < former_descriptor_name_ident #generics_impl as former::FormerDescriptor >::Formed { self.end() } @@ -1036,12 +1094,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn end( mut self ) -> __FormerContext + pub fn end( mut self ) -> < former_descriptor_name_ident #generics_impl as former::FormerDescriptor >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - let storage = self.form(); - on_end.call( storage, context ) + // let storage = self.form(); + on_end.call( self.storage, context ) } #( @@ -1051,7 +1109,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } #[ automatically_derived ] - impl #generics_impl #former_name_ident < #generics_params #name_ident #generics_ty, former::ReturnStorage > + impl #generics_impl #former_name_ident < #generics_params (), former::ReturnStorage > #generics_where { From e3c245f22535cf05cd75f6c3ea08cac34805252c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 16:39:46 +0200 Subject: [PATCH 009/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 3159903ea5..89411c17f1 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -742,7 +742,8 @@ For specifying custom default value use attribute `default`. For example: pub fn performer< 'a > ( - name_ident : &syn::Ident, + _name_ident : &syn::Ident, + former_descriptor_name_ident : &syn::Ident, generics_ty : &syn::TypeGenerics< '_ >, attrs : impl Iterator< Item = &'a syn::Attribute >, ) @@ -753,7 +754,9 @@ pub fn performer< 'a > { return result; }; - let mut perform_output = qt!{ #name_ident #generics_ty }; + // let mut perform_output = qt!{ #name_ident #generics_ty }; + let mut perform_output = qt!{ < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed }; + let mut perform_generics = qt!{}; for attr in attrs { @@ -864,6 +867,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( perform, perform_output, perform_generics ) = performer ( &name_ident, + &former_descriptor_name_ident, &generics_ty, ast.attrs.iter(), )?; @@ -937,7 +941,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = descriptor #[ derive( Debug ) ] - pub struct #former_descriptor_name_ident #generics_impl; + pub struct #former_descriptor_name_ident #generics_ty; impl #generics_impl #former_descriptor_name_ident #generics_ty { @@ -1033,7 +1037,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// Finish setting options and return formed entity. /// #[ inline( always ) ] - pub fn preform( self ) -> < former_descriptor_name_ident #generics_impl as former::FormerDescriptor >::Formed + pub fn preform( self ) -> < former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed // #name_ident #generics_ty { < #former_storage_name_ident #generics_ty as former::StoragePerform >::preform( self.storage ) @@ -1085,7 +1089,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn form( self ) -> < former_descriptor_name_ident #generics_impl as former::FormerDescriptor >::Formed + pub fn form( self ) -> < former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed { self.end() } @@ -1094,7 +1098,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn end( mut self ) -> < former_descriptor_name_ident #generics_impl as former::FormerDescriptor >::Formed + pub fn end( mut self ) -> < former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); From c5f9e9333dd7b7be1d0c11907c32ce6a7a53c463 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 16:52:12 +0200 Subject: [PATCH 010/533] former : experimenting --- .../inc/former_tests/a_primitives_expanded.rs | 145 +++++++----------- module/core/former_meta/src/derive/former.rs | 3 +- 2 files changed, 60 insertions(+), 88 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs index a31c9475cd..78c093d807 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -14,6 +14,7 @@ pub struct Struct1 // = formed +#[automatically_derived] impl Struct1 { #[doc = r""] @@ -26,9 +27,7 @@ impl Struct1 } } -// = descriptor - -#[ derive( Debug ) ] +#[derive(Debug)] pub struct Struct1FormerDescriptor; impl Struct1FormerDescriptor @@ -39,15 +38,13 @@ impl Struct1FormerDescriptor } } -impl former::FormerDescriptor -for Struct1FormerDescriptor +impl former::FormerDescriptor for Struct1FormerDescriptor { type Storage = Struct1FormerStorage; type Formed = Struct1; } -// = storage - +#[doc = "Container of a corresponding former."] pub struct Struct1FormerStorage { #[doc = r" A field"] @@ -75,115 +72,90 @@ impl ::core::default::Default for Struct1FormerStorage } } -impl former::Storage -for Struct1FormerStorage +impl former::Storage for Struct1FormerStorage { type Descriptor = Struct1FormerDescriptor; } -impl former::StoragePerform -for Struct1FormerStorage +impl former::StoragePerform for Struct1FormerStorage { - - fn preform( mut self ) -> Struct1 + fn preform(mut self) -> Struct1 { - - let int_1 = if self.int_1.is_some() - { - self.int_1.take().unwrap() - } - else - { - let val : i32 = Default::default(); - val - }; - - let string_1 = if self.string_1.is_some() - { - self.string_1.take().unwrap() - } - else - { - let val : String = Default::default(); - val - }; - - let int_optional_1 = if self.int_optional_1.is_some() - { - Some( self.int_optional_1.take().unwrap() ) - } - else - { - None - }; - - let string_optional_1 = if self.string_optional_1.is_some() - { - Some( self.string_optional_1.take().unwrap() ) - } - else - { - None - }; - - // xxx : Rust failt to use parameter here - // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed Struct1 { - int_1, - string_1, - int_optional_1, - string_optional_1, + int_1 : self.int_1.take().or_else(|| Some(::core::marker::PhantomData::::maybe_default())).unwrap(), + string_1 : self.string_1.take().or_else(|| Some(::core::marker::PhantomData::::maybe_default())).unwrap(), + int_optional_1 : self.int_optional_1, + string_optional_1 : self.string_optional_1, } - } +} +trait MaybeDefault +{ + fn maybe_default() -> T; } -// = former +impl MaybeDefault for ::core::marker::PhantomData +where i32 : ::core::default::Default, +{ + fn maybe_default() -> i32 + { + i32::default() + } +} + +impl MaybeDefault for ::core::marker::PhantomData +where String : ::core::default::Default, +{ + fn maybe_default() -> String + { + String::default() + } +} +#[doc = +" Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] #[automatically_derived] -pub struct Struct1Former -where FormerEnd : former::FormingEnd, +pub struct Struct1Former<__FormerContext = Struct1, __FormerEnd = former::ReturnStorage> +where __FormerEnd : former::FormingEnd, { storage : Struct1FormerStorage, - context : core::option::Option, - on_end : core::option::Option, + context : core::option::Option<__FormerContext>, + on_end : core::option::Option<__FormerEnd>, } #[automatically_derived] -impl Struct1Former -where FormerEnd : former::FormingEnd, +impl<__FormerContext, __FormerEnd> Struct1Former<__FormerContext, __FormerEnd> +where __FormerEnd : former::FormingEnd, { #[doc = r""] #[doc = r" Finish setting options and return formed entity."] #[doc = r""] - #[doc = r" `perform` has no effect on method `form`, but change behavior and returned type of method `perform`."] - #[doc = r""] #[inline(always)] - pub fn preform(self) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + pub fn preform(self) -> ::Formed { - < Struct1FormerStorage as former::StoragePerform >::preform( self.storage ) + ::preform(self.storage) } #[doc = r""] #[doc = r" Finish setting options and call perform on formed entity."] #[doc = r""] - #[doc = r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] + #[doc = r" If `perform` defined then associated method is called and its result returned instead of entity."] + #[doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] #[doc = r""] #[inline(always)] - pub fn perform( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + pub fn perform(self) -> ::Formed { let result = self.form(); return result; } #[doc = r""] - #[doc = r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r" Begin the process of forming. Expects context of forming to return it after forming."] #[doc = r""] #[inline(always)] - pub fn begin(mut storage : core::option::Option, context : core::option::Option, on_end : FormerEnd,) -> Self + pub fn begin(mut storage : core::option::Option, context : core::option::Option<__FormerContext>, on_end : __FormerEnd,) -> Self { if storage.is_none() { @@ -191,37 +163,36 @@ where FormerEnd : former::FormingEnd, } Self { - storage: storage.unwrap(), - context: context, - on_end: ::core::option::Option::Some(on_end), + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some(on_end), } } #[doc = r""] - #[doc = r" End the process of forming returning original context of forming."] + #[doc = r" End the process of forming returning original context of forming."] #[doc = r""] #[inline(always)] - pub fn form( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + pub fn form(self) -> ::Formed { self.end() } #[doc = r""] - #[doc = r" End the process of forming returning original context of forming."] + #[doc = r" End the process of forming returning original context of forming."] #[doc = r""] #[inline(always)] - pub fn end(mut self) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + pub fn end(mut self) -> ::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - // let storage = self.form(); on_end.call(self.storage, context) } #[doc = "Setter for the 'int_1' field."] #[inline] pub fn int_1(mut self, src: Src) -> Self - where Src: ::core::convert::Into, + where Src : ::core::convert::Into, { debug_assert!(self.storage.int_1.is_none()); self.storage.int_1 = ::core::option::Option::Some(src.into()); @@ -231,7 +202,7 @@ where FormerEnd : former::FormingEnd, #[doc = "Setter for the 'string_1' field."] #[inline] pub fn string_1(mut self, src: Src) -> Self - where Src: ::core::convert::Into, + where Src : ::core::convert::Into, { debug_assert!(self.storage.string_1.is_none()); self.storage.string_1 = ::core::option::Option::Some(src.into()); @@ -241,7 +212,7 @@ where FormerEnd : former::FormingEnd, #[doc = "Setter for the 'int_optional_1' field."] #[inline] pub fn int_optional_1(mut self, src: Src) -> Self - where Src: ::core::convert::Into, + where Src : ::core::convert::Into, { debug_assert!(self.storage.int_optional_1.is_none()); self.storage.int_optional_1 = ::core::option::Option::Some(src.into()); @@ -251,7 +222,7 @@ where FormerEnd : former::FormingEnd, #[doc = "Setter for the 'string_optional_1' field."] #[inline] pub fn string_optional_1(mut self, src: Src) -> Self - where Src: ::core::convert::Into, + where Src : ::core::convert::Into, { debug_assert!(self.storage.string_optional_1.is_none()); self.storage.string_optional_1 = ::core::option::Option::Some(src.into()); diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 89411c17f1..6a7162a36e 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1000,7 +1000,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #generics_where { - fn preform( mut self ) -> #former_storage_name_ident #generics_ty + // fn preform( mut self ) -> #former_storage_name_ident #generics_ty + fn preform( mut self ) -> < former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed { Self { From f325b76ef4077be8ee964ae1fd5f11b1e3eb8dca Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 17:22:47 +0200 Subject: [PATCH 011/533] former : experimenting --- .../inc/former_tests/a_primitives_expanded.rs | 234 +----------------- module/core/former_meta/src/derive/former.rs | 31 ++- 2 files changed, 17 insertions(+), 248 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs index 78c093d807..8771d29773 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -1,9 +1,8 @@ #[ allow( unused_imports ) ] use super::*; -#[ derive( Debug, PartialEq ) ] -// #[ derive( Debug, PartialEq, the_module::Former ) ] -// #[ debug ] +// #[ derive( Debug, PartialEq ) ] +#[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] pub struct Struct1 { pub int_1 : i32, @@ -14,235 +13,6 @@ pub struct Struct1 // = formed -#[automatically_derived] -impl Struct1 -{ - #[doc = r""] - #[doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step."] - #[doc = r""] - #[inline(always)] - pub fn former() -> Struct1Former<(), former::ReturnStorage> - { - Struct1Former::new() - } -} - -#[derive(Debug)] -pub struct Struct1FormerDescriptor; - -impl Struct1FormerDescriptor -{ - pub fn new() -> Self - { - Self - } -} - -impl former::FormerDescriptor for Struct1FormerDescriptor -{ - type Storage = Struct1FormerStorage; - type Formed = Struct1; -} - -#[doc = "Container of a corresponding former."] -pub struct Struct1FormerStorage -{ - #[doc = r" A field"] - pub int_1 : ::core::option::Option, - #[doc = r" A field"] - pub string_1 : ::core::option::Option, - #[doc = r" A field"] - pub int_optional_1 : core::option::Option, - #[doc = r" A field"] - pub string_optional_1 : Option, -} - -impl ::core::default::Default for Struct1FormerStorage -{ - #[inline(always)] - fn default() -> Self - { - Self - { - int_1 : ::core::option::Option::None, - string_1 : ::core::option::Option::None, - int_optional_1 : ::core::option::Option::None, - string_optional_1 : ::core::option::Option::None, - } - } -} - -impl former::Storage for Struct1FormerStorage -{ - type Descriptor = Struct1FormerDescriptor; -} - -impl former::StoragePerform for Struct1FormerStorage -{ - fn preform(mut self) -> Struct1 - { - Struct1 - { - int_1 : self.int_1.take().or_else(|| Some(::core::marker::PhantomData::::maybe_default())).unwrap(), - string_1 : self.string_1.take().or_else(|| Some(::core::marker::PhantomData::::maybe_default())).unwrap(), - int_optional_1 : self.int_optional_1, - string_optional_1 : self.string_optional_1, - } - } -} - -trait MaybeDefault -{ - fn maybe_default() -> T; -} - -impl MaybeDefault for ::core::marker::PhantomData -where i32 : ::core::default::Default, -{ - fn maybe_default() -> i32 - { - i32::default() - } -} - -impl MaybeDefault for ::core::marker::PhantomData -where String : ::core::default::Default, -{ - fn maybe_default() -> String - { - String::default() - } -} - -#[doc = -" Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -#[automatically_derived] -pub struct Struct1Former<__FormerContext = Struct1, __FormerEnd = former::ReturnStorage> -where __FormerEnd : former::FormingEnd, -{ - storage : Struct1FormerStorage, - context : core::option::Option<__FormerContext>, - on_end : core::option::Option<__FormerEnd>, -} - -#[automatically_derived] -impl<__FormerContext, __FormerEnd> Struct1Former<__FormerContext, __FormerEnd> -where __FormerEnd : former::FormingEnd, -{ - #[doc = r""] - #[doc = r" Finish setting options and return formed entity."] - #[doc = r""] - #[inline(always)] - pub fn preform(self) -> ::Formed - { - ::preform(self.storage) - } - - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] - #[doc = r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] - #[inline(always)] - pub fn perform(self) -> ::Formed - { - let result = self.form(); - return result; - } - - #[doc = r""] - #[doc = r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] - #[inline(always)] - pub fn begin(mut storage : core::option::Option, context : core::option::Option<__FormerContext>, on_end : __FormerEnd,) -> Self - { - if storage.is_none() - { - storage = Some(::core::default::Default::default()); - } - Self - { - storage : storage.unwrap(), - context : context, - on_end : ::core::option::Option::Some(on_end), - } - } - - #[doc = r""] - #[doc = r" End the process of forming returning original context of forming."] - #[doc = r""] - #[inline(always)] - pub fn form(self) -> ::Formed - { - self.end() - } - - #[doc = r""] - #[doc = r" End the process of forming returning original context of forming."] - #[doc = r""] - #[inline(always)] - pub fn end(mut self) -> ::Formed - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - on_end.call(self.storage, context) - } - - #[doc = "Setter for the 'int_1' field."] - #[inline] - pub fn int_1(mut self, src: Src) -> Self - where Src : ::core::convert::Into, - { - debug_assert!(self.storage.int_1.is_none()); - self.storage.int_1 = ::core::option::Option::Some(src.into()); - self - } - - #[doc = "Setter for the 'string_1' field."] - #[inline] - pub fn string_1(mut self, src: Src) -> Self - where Src : ::core::convert::Into, - { - debug_assert!(self.storage.string_1.is_none()); - self.storage.string_1 = ::core::option::Option::Some(src.into()); - self - } - - #[doc = "Setter for the 'int_optional_1' field."] - #[inline] - pub fn int_optional_1(mut self, src: Src) -> Self - where Src : ::core::convert::Into, - { - debug_assert!(self.storage.int_optional_1.is_none()); - self.storage.int_optional_1 = ::core::option::Option::Some(src.into()); - self - } - - #[doc = "Setter for the 'string_optional_1' field."] - #[inline] - pub fn string_optional_1(mut self, src: Src) -> Self - where Src : ::core::convert::Into, - { - debug_assert!(self.storage.string_optional_1.is_none()); - self.storage.string_optional_1 = ::core::option::Option::Some(src.into()); - self - } -} - -#[automatically_derived] -impl Struct1Former<(), former::ReturnStorage> -{ - #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] - #[inline(always)] - pub fn new() -> Self - { - Self::begin(None, None, former::ReturnStorage,) - } -} - // // include!( "./only_test/primitives.rs" ); diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 6a7162a36e..ec54b2ad41 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -404,9 +404,9 @@ fn field_form_map( field : &FormerField< '_ > ) -> Result< TokenStream > qt! { - let #ident = if self.storage.#ident.is_some() + let #ident = if self.#ident.is_some() { - ::core::option::Option::Some( self.storage.#ident.take().unwrap() ) + ::core::option::Option::Some( self.#ident.take().unwrap() ) } else { @@ -464,9 +464,9 @@ fn field_form_map( field : &FormerField< '_ > ) -> Result< TokenStream > qt! { - let #ident = if self.storage.#ident.is_some() + let #ident = if self.#ident.is_some() { - self.storage.#ident.take().unwrap() + self.#ident.take().unwrap() } else { @@ -1001,17 +1001,16 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { // fn preform( mut self ) -> #former_storage_name_ident #generics_ty - fn preform( mut self ) -> < former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + fn preform( mut self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed { - Self + #( #fields_form )* + // Rust does not support that, yet + // let result = < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + let result = #name_ident #generics_ty { - #( #fields_form )* - let result = #name_ident - { - #( #fields_names, )* - }; - return result; - } + #( #fields_names, )* + }; + return result; } } @@ -1038,7 +1037,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// Finish setting options and return formed entity. /// #[ inline( always ) ] - pub fn preform( self ) -> < former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + pub fn preform( self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed // #name_ident #generics_ty { < #former_storage_name_ident #generics_ty as former::StoragePerform >::preform( self.storage ) @@ -1090,7 +1089,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn form( self ) -> < former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + pub fn form( self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed { self.end() } @@ -1099,7 +1098,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn end( mut self ) -> < former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + pub fn end( mut self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); From e10f6a1e676160fc7630b14236540bdb7cea304f Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 17:41:28 +0200 Subject: [PATCH 012/533] former : experimenting --- .../tests/inc/former_tests/a_primitives.rs | 228 +----------------- .../inc/former_tests/a_primitives_expanded.rs | 4 +- .../inc/former_tests/a_primitives_manual.rs | 177 +++++++------- .../a_primitives_manual_original.rs | 192 --------------- .../inc/former_tests/only_test/primitives.rs | 19 +- module/core/former/tests/inc/mod.rs | 4 +- 6 files changed, 112 insertions(+), 512 deletions(-) delete mode 100644 module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs diff --git a/module/core/former/tests/inc/former_tests/a_primitives.rs b/module/core/former/tests/inc/former_tests/a_primitives.rs index 7a63846439..c39429b63a 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives.rs @@ -12,230 +12,4 @@ pub struct Struct1 // -// // generated by former -// impl Struct1 -// { -// pub fn former() -> Struct1Former< (), the_module::ReturnStorage > -// { -// Struct1Former::new() -// } -// } -// -// // -// -// // generated by former -// pub struct Struct1FormerStorage -// { -// pub int_1 : core::option::Option< i32 >, -// pub string_1 : core::option::Option< String >, -// pub int_optional_1 : core::option::Option< i32 >, -// pub string_optional_1 : core::option::Option< String >, -// } -// -// impl Default for Struct1FormerStorage -// { -// -// #[ inline( always ) ] -// fn default() -> Self -// { -// Self -// { -// int_1 : core::option::Option::None, -// string_1 : core::option::Option::None, -// int_optional_1 : core::option::Option::None, -// string_optional_1 : core::option::Option::None, -// } -// } -// -// } -// -// #[ derive( Debug ) ] -// pub struct Struct1FormerDescriptor; -// -// impl Struct1FormerDescriptor -// { -// pub fn new() -> Self -// { -// Self -// } -// } -// -// impl former::FormerDescriptor -// for Struct1FormerDescriptor -// { -// type Storage = Struct1FormerStorage; -// type Formed = Struct1; -// } -// -// impl former::Storage -// for Struct1FormerStorage -// { -// type Descriptor = Struct1FormerDescriptor; -// } -// -// impl former::StoragePerform -// for Struct1FormerStorage -// { -// -// fn preform( mut self ) -> < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed -// { -// -// let int_1 = if self.int_1.is_some() -// { -// self.int_1.take().unwrap() -// } -// else -// { -// let val : i32 = Default::default(); -// val -// }; -// -// let string_1 = if self.string_1.is_some() -// { -// self.string_1.take().unwrap() -// } -// else -// { -// let val : String = Default::default(); -// val -// }; -// -// let int_optional_1 = if self.int_optional_1.is_some() -// { -// Some( self.int_optional_1.take().unwrap() ) -// } -// else -// { -// None -// }; -// -// let string_optional_1 = if self.string_optional_1.is_some() -// { -// Some( self.string_optional_1.take().unwrap() ) -// } -// else -// { -// None -// }; -// -// // xxx : Rust failt to use parameter here -// // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed -// Struct1 -// { -// int_1, -// string_1, -// int_optional_1, -// string_optional_1, -// } -// -// } -// -// } -// -// // -// -// pub struct Struct1Former -// < -// FormerContext = Struct1, -// FormerEnd = the_module::ReturnStorage, -// > -// where -// FormerEnd : the_module::FormingEnd< Struct1FormerDescriptor, FormerContext >, -// { -// storage : Struct1FormerStorage, -// context : core::option::Option< FormerContext >, -// on_end : core::option::Option< FormerEnd >, -// } -// -// impl< FormerContext, FormerEnd > Struct1Former< FormerContext, FormerEnd > -// where -// FormerEnd: the_module::FormingEnd< Struct1FormerDescriptor, FormerContext >, -// { -// -// fn preform( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed -// { -// former::StoragePerform::preform( self.storage ) -// } -// -// #[ inline( always ) ] -// pub fn perform(self) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed -// { -// let result = self.form(); -// return result; -// } -// -// #[ inline( always ) ] -// pub fn begin -// ( -// mut storage : core::option::Option< < Struct1FormerDescriptor as former::FormerDescriptor >::Storage >, -// // xxx : cover by test existance of these 3 parameters in the function -// context : core::option::Option< FormerContext >, -// on_end : FormerEnd, -// ) -> Self -// { -// if storage.is_none() -// { -// storage = Some( core::default::Default::default() ); -// } -// Self -// { -// storage : storage.unwrap(), -// context : context, -// on_end : ::core::option::Option::Some( on_end ), -// } -// } -// -// #[ inline( always ) ] -// pub fn end( mut self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed -// { -// let on_end = self.on_end.take().unwrap(); -// let context = self.context.take(); -// on_end.call( self.storage, context ) -// } -// -// #[ inline( always ) ] -// pub fn form( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed -// { -// self.end() -// } -// -// pub fn int_1< Src >( mut self, src : Src ) -> Self -// where Src : core::convert::Into< i32 >, -// { -// debug_assert!( self.storage.int_1.is_none() ); -// self.storage.int_1 = Some( src.into() ); -// self -// } -// -// pub fn string_1< Src >( mut self, src : Src ) -> Self -// where Src : core::convert::Into< String >, -// { -// debug_assert!( self.storage.string_1.is_none() ); -// self.storage.string_1 = Some( src.into() ); -// self -// } -// -// pub fn string_optional_1< Src >( mut self, src : Src ) -> Self -// where Src : core::convert::Into< String > -// { -// debug_assert!( self.storage.string_optional_1.is_none() ); -// self.storage.string_optional_1 = Some( src.into() ); -// self -// } -// -// } -// -// impl Struct1Former< (), the_module::ReturnStorage > -// { -// -// #[ inline( always ) ] -// pub fn new() -> Struct1Former< (), the_module::ReturnStorage > -// { -// Struct1Former::< (), the_module::ReturnStorage >::begin( None, None, the_module::ReturnStorage ) -// } -// -// } - -// - -// include!( "./only_test/primitives.rs" ); +include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs index 8771d29773..812d40be6e 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -1,8 +1,8 @@ #[ allow( unused_imports ) ] use super::*; -// #[ derive( Debug, PartialEq ) ] -#[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] +#[ derive( Debug, PartialEq ) ] +// #[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] pub struct Struct1 { pub int_1 : i32, diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 7462251a80..054f83e6e0 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -10,7 +10,7 @@ pub struct Struct1 string_optional_1 : Option< String >, } -// +// = formed // generated by former impl Struct1 @@ -21,7 +21,27 @@ impl Struct1 } } -// +// = descriptor + +#[ derive( Debug ) ] +pub struct Struct1FormerDescriptor; + +impl Struct1FormerDescriptor +{ + pub fn new() -> Self + { + Self + } +} + +impl former::FormerDescriptor +for Struct1FormerDescriptor +{ + type Storage = Struct1FormerStorage; + type Formed = Struct1; +} + +// = storage // generated by former pub struct Struct1FormerStorage @@ -32,7 +52,6 @@ pub struct Struct1FormerStorage pub string_optional_1 : core::option::Option< String >, } -// xxx : cover by test impl Default for Struct1FormerStorage { @@ -50,7 +69,72 @@ impl Default for Struct1FormerStorage } -// +impl former::Storage +for Struct1FormerStorage +{ + type Descriptor = Struct1FormerDescriptor; +} + +impl former::StoragePerform +for Struct1FormerStorage +{ + + fn preform( mut self ) -> < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed + { + + let int_1 = if self.int_1.is_some() + { + self.int_1.take().unwrap() + } + else + { + let val : i32 = Default::default(); + val + }; + + let string_1 = if self.string_1.is_some() + { + self.string_1.take().unwrap() + } + else + { + let val : String = Default::default(); + val + }; + + let int_optional_1 = if self.int_optional_1.is_some() + { + Some( self.int_optional_1.take().unwrap() ) + } + else + { + None + }; + + let string_optional_1 = if self.string_optional_1.is_some() + { + Some( self.string_optional_1.take().unwrap() ) + } + else + { + None + }; + + // Rust failt to use parameter here + // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed + Struct1 + { + int_1, + string_1, + int_optional_1, + string_optional_1, + } + + } + +} + +// = former pub struct Struct1Former < @@ -86,9 +170,9 @@ where pub fn begin ( mut storage : core::option::Option< < Struct1FormerDescriptor as former::FormerDescriptor >::Storage >, - // xxx : cover by test existance of these 3 parameters in the function context : core::option::Option< FormerContext >, on_end : FormerEnd, + // xxx : cover by test existance of these 3 parameters in the function ) -> Self { if storage.is_none() @@ -154,89 +238,6 @@ impl Struct1Former< (), the_module::ReturnStorage > } -#[ derive( Debug ) ] -pub struct Struct1FormerDescriptor; - -impl Struct1FormerDescriptor -{ - pub fn new() -> Self - { - Self - } -} - -impl former::FormerDescriptor -for Struct1FormerDescriptor -{ - type Storage = Struct1FormerStorage; - type Formed = Struct1; -} - -impl former::Storage -for Struct1FormerStorage -{ - type Descriptor = Struct1FormerDescriptor; -} - -impl former::StoragePerform -for Struct1FormerStorage -{ - - fn preform( mut self ) -> < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed - { - - let int_1 = if self.int_1.is_some() - { - self.int_1.take().unwrap() - } - else - { - let val : i32 = Default::default(); - val - }; - - let string_1 = if self.string_1.is_some() - { - self.string_1.take().unwrap() - } - else - { - let val : String = Default::default(); - val - }; - - let int_optional_1 = if self.int_optional_1.is_some() - { - Some( self.int_optional_1.take().unwrap() ) - } - else - { - None - }; - - let string_optional_1 = if self.string_optional_1.is_some() - { - Some( self.string_optional_1.take().unwrap() ) - } - else - { - None - }; - - // xxx : Rust failt to use parameter here - // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed - Struct1 - { - int_1, - string_1, - int_optional_1, - string_optional_1, - } - - } - -} - // include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs deleted file mode 100644 index 5db0ab5a74..0000000000 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual_original.rs +++ /dev/null @@ -1,192 +0,0 @@ -#[ allow( unused_imports ) ] -use super::*; - -#[ derive( Debug, PartialEq ) ] -pub struct Struct1 -{ - pub int_1 : i32, - string_1 : String, - int_optional_1 : core::option::Option< i32 >, - string_optional_1 : Option< String >, -} - -// - -// generated by former -impl Struct1 -{ - pub fn former() -> Struct1Former< Struct1, Former::ReturnFormed > - { - Struct1Former::< Struct1, the_module::ReturnFormed >::new() - } -} - -// - -// generated by former -pub struct Struct1FormerStorage -{ - pub int_1 : core::option::Option< i32 >, - pub string_1 : core::option::Option< String >, - pub int_optional_1 : core::option::Option< i32 >, - pub string_optional_1 : core::option::Option< String >, -} - -impl Default for Struct1FormerStorage -{ - - #[ inline( always ) ] - fn default() -> Self - { - Self - { - int_1 : core::option::Option::None, - string_1 : core::option::Option::None, - int_optional_1 : core::option::Option::None, - string_optional_1 : core::option::Option::None, - } - } - -} - -// - -pub struct Struct1Former -< - FormerContext = Struct1, - FormerEnd = the_module::ReturnFormed, -> -where - FormerEnd : the_module::FormingEnd< Struct1, FormerContext >, -{ - storage : Struct1FormerStorage, - context : core::option::Option< FormerContext >, - on_end : core::option::Option< FormerEnd >, -} - -impl< FormerContext, FormerEnd > Struct1Former< FormerContext, FormerEnd > -where - FormerEnd: the_module::FormingEnd, -{ - - fn form( mut self ) -> Struct1 - { - - let int_1 = if self.storage.int_1.is_some() - { - self.storage.int_1.take().unwrap() - } - else - { - let val : i32 = Default::default(); - val - }; - - let string_1 = if self.storage.string_1.is_some() - { - self.storage.string_1.take().unwrap() - } - else - { - let val : String = Default::default(); - val - }; - - let int_optional_1 = if self.storage.int_optional_1.is_some() - { - Some( self.storage.int_optional_1.take().unwrap() ) - } - else - { - None - }; - - let string_optional_1 = if self.storage.string_optional_1.is_some() - { - Some( self.storage.string_optional_1.take().unwrap() ) - } - else - { - None - }; - - Struct1 - { - int_1, - string_1, - int_optional_1, - string_optional_1, - } - - } - - #[ inline( always ) ] - pub fn perform(self) -> Struct1 - { - let result = self.form(); - return result; - } - - #[ inline( always ) ] - pub fn new() -> Struct1Former - { - Struct1Former:: - < - Struct1, - the_module::ReturnFormed, - >::begin(None, the_module::ReturnFormed) - } - - #[ inline( always ) ] - pub fn begin - ( - context : core::option::Option< FormerContext >, - on_end : FormerEnd, - ) -> Self - { - Self - { - storage : core::default::Default::default(), - context : context, - on_end : ::core::option::Option::Some( on_end ), - } - } - - #[ inline( always ) ] - pub fn end( mut self ) -> FormerContext - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) - } - - pub fn int_1< Src >( mut self, src : Src ) -> Self - where Src : core::convert::Into< i32 >, - { - debug_assert!( self.storage.int_1.is_none() ); - self.storage.int_1 = Some( src.into() ); - self - } - - pub fn string_1< Src >( mut self, src : Src ) -> Self - where Src : core::convert::Into< String >, - { - debug_assert!( self.storage.string_1.is_none() ); - self.storage.string_1 = Some( src.into() ); - self - } - - pub fn string_optional_1< Src >( mut self, src : Src ) -> Self - where Src : core::convert::Into< String > - { - debug_assert!( self.storage.string_optional_1.is_none() ); - self.storage.string_optional_1 = Some( src.into() ); - self - } - -} - -// - -include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 546e1679ae..f57fa78f30 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -43,6 +43,18 @@ tests_impls! // + fn begin() + { + + let mut storage = Struct1FormerStorage::default(); + storage.int_1 = Some( 13 ); + // Struct1Former::< (), the_module::ReturnStorage >::begin( storage, None, the_module::ReturnStorage ) + // xxx + + } + + // + fn preform() { @@ -88,11 +100,15 @@ tests_impls! { // descriptor exists and has Storage - // use former::StoragePerform; let got = < Struct1FormerStorage as the_module::StoragePerform >::preform( Struct1::former().storage ); let exp = Struct1::former().form(); a_id!( got, exp ); + // default is implemented for Storage + let got = Struct1FormerStorage::default().preform(); + let exp = Struct1::former().storage.preform(); + a_id!( got, exp ); + // descriptor exists and has Storage use former::StoragePerform; let got = Struct1::former().storage.preform(); @@ -290,6 +306,7 @@ tests_impls! tests_index! { internals, + begin, preform, descriptor, storage, diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 8d654b850d..21d986470d 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -8,8 +8,8 @@ mod former_tests use super::*; mod a_primitives_manual; - // mod a_primitives; - mod a_primitives_expanded; + mod a_primitives; + // mod a_primitives_expanded; // mod a_containers_without_runtime_manual; // mod a_containers_without_runtime; // #[ cfg( not( feature = "no_std" ) ) ] From 3ee191533b7700bc7a6b0fd076152c0899ee30b4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 17:54:06 +0200 Subject: [PATCH 013/533] former : experimenting --- module/core/former/Readme.md | 10 +-- module/core/former/src/axiomatic.rs | 4 +- module/core/former/src/axiomatic3.rs | 59 ++++++++------- module/core/former/src/hash_map.rs | 74 +++++++++---------- module/core/former/src/hash_set.rs | 72 +++++++++--------- module/core/former/src/vector.rs | 6 +- module/core/former/src/vector3.rs | 71 +++++++++--------- .../a_containers_with_runtime_manual.rs | 16 ++-- .../a_containers_without_runtime_manual.rs | 12 +-- .../inc/former_tests/a_primitives_manual.rs | 38 +++++----- .../only_test/containers_with_runtime.rs | 4 +- .../only_test/containers_without_runtime.rs | 4 +- .../inc/former_tests/only_test/primitives.rs | 10 +-- .../parametrized_struct_manual.rs | 4 +- .../former_tests/subformer_basic_manual.rs | 8 +- .../inc/former_tests/subformer_shortcut.rs | 32 ++++---- module/core/former_meta/src/derive/former.rs | 32 ++++---- module/core/former_meta/src/lib.rs | 10 +-- 18 files changed, 233 insertions(+), 233 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 3fbcce7c94..ec0a4f16ec 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -86,9 +86,9 @@ pub struct UserProfile impl UserProfile { #[ inline( always ) ] - pub fn former() -> UserProfileFormer< UserProfile, former::ReturnStorage > + pub fn former() -> UserProfileFormer< UserProfile, former::ReturnFormed > { - UserProfileFormer::< UserProfile, former::ReturnStorage >::new() + UserProfileFormer::< UserProfile, former::ReturnFormed >::new() } } @@ -103,7 +103,7 @@ pub struct UserProfileFormerStorage pub struct UserProfileFormer < Context = UserProfile, - End = former::ReturnStorage, + End = former::ReturnFormed, > where End : former::FormingEnd< UserProfile, Context >, @@ -205,9 +205,9 @@ where } #[ inline( always ) ] - pub fn new() -> UserProfileFormer< UserProfile, former::ReturnStorage > + pub fn new() -> UserProfileFormer< UserProfile, former::ReturnFormed > { - UserProfileFormer::< UserProfile, former::ReturnStorage >::begin( None, former::ReturnStorage ) + UserProfileFormer::< UserProfile, former::ReturnFormed >::begin( None, former::ReturnFormed ) } #[ inline( always ) ] diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index f6aed1dacf..161a0f3ea8 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -122,10 +122,10 @@ for FormingEndWrapper< Storage, Context > /// This struct is useful when the forming process should result in the formed container being returned directly, /// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. #[ derive( Debug, Default ) ] -pub struct ReturnStorage; +pub struct ReturnFormed; impl< Storage > FormingEnd< Storage, Storage > -for ReturnStorage +for ReturnFormed { #[ inline( always ) ] fn call( &self, storage : Storage, _context : core::option::Option< Storage > ) -> Storage diff --git a/module/core/former/src/axiomatic3.rs b/module/core/former/src/axiomatic3.rs index 1c16f54205..1587a215ab 100644 --- a/module/core/former/src/axiomatic3.rs +++ b/module/core/former/src/axiomatic3.rs @@ -2,19 +2,20 @@ pub trait Storage : ::core::default::Default { - type Descriptor : FormerDescriptor< Storage = Self >; + type Definition : FormerDefinition< Storage = Self >; } /// xxx pub trait StoragePerform : Storage { - fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed; + fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed; } /// xxx -pub trait FormerDescriptor +pub trait FormerDefinition { - type Storage : StoragePerform< Descriptor = Self >; + // type Storage : StoragePerform< Definition = Self >; + type Storage : Storage< Definition = Self >; type Formed; } @@ -23,8 +24,8 @@ pub trait FormerDescriptor // type Storage : StoragePerform< Formed = Self::Formed >; // type Formed; // type Context; -// type FormerDescriptor : FormerDescriptor< Storage = Self::Storage, Formed = Self::Formed >; -// type End : FormingEnd< Self::FormerDescriptor, Self::Context >; +// type FormerDefinition : FormerDefinition< Storage = Self::Storage, Formed = Self::Formed >; +// type End : FormingEnd< Self::FormerDefinition, Self::Context >; // } /// Defines a handler for the end of a subforming process, enabling the return of the original context. @@ -35,7 +36,7 @@ pub trait FormerDescriptor /// # Parameters /// - `Storage`: The type of the container being processed. /// - `Context`: The type of the context that might be altered or returned upon completion. -pub trait FormingEnd< Former : FormerDescriptor, Context > +pub trait FormingEnd< Definition : FormerDefinition, Context > { /// Called at the end of the subforming process to return the modified or original context. /// @@ -45,15 +46,15 @@ pub trait FormingEnd< Former : FormerDescriptor, Context > /// /// # Returns /// Returns the transformed or original context based on the implementation. - fn call( &self, storage : Former::Storage, context : core::option::Option< Context > ) -> Former::Formed; + fn call( &self, storage : Definition::Storage, context : core::option::Option< Context > ) -> Definition::Formed; } -impl< Former : FormerDescriptor, Context, F > FormingEnd< Former, Context > for F +impl< Definition : FormerDefinition, Context, F > FormingEnd< Definition, Context > for F where - F : Fn( Former::Storage, core::option::Option< Context > ) -> Former::Formed, + F : Fn( Definition::Storage, core::option::Option< Context > ) -> Definition::Formed, { #[ inline( always ) ] - fn call( &self, storage : Former::Storage, context : core::option::Option< Context > ) -> Former::Formed + fn call( &self, storage : Definition::Storage, context : core::option::Option< Context > ) -> Definition::Formed { self( storage, context ) } @@ -64,13 +65,17 @@ where /// This struct is useful when the forming process should result in the formed container being returned directly, /// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. #[ derive( Debug, Default ) ] -pub struct ReturnStorage; +pub struct ReturnFormed; -impl< Former : FormerDescriptor > FormingEnd< Former, () > -for ReturnStorage +impl< Definition : FormerDefinition > FormingEnd< Definition, () > +for ReturnFormed +where + Definition::Storage : StoragePerform< Definition = Definition >, + // xxx : rename Former -> Definition + // xxx : rename Definition -> Definition { #[ inline( always ) ] - fn call( &self, storage : Former::Storage, _context : core::option::Option< () > ) -> Former::Formed + fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed { storage.preform() } @@ -90,14 +95,14 @@ for ReturnStorage /// * `Context` - The type of the context that may be altered or returned by the closure. /// This allows for flexible manipulation of context based on the container. #[ cfg( not( feature = "no_std" ) ) ] -pub struct FormingEndWrapper< Former : FormerDescriptor, Context > +pub struct FormingEndWrapper< Definition : FormerDefinition, Context > { - closure : Box< dyn Fn( Former::Storage, Option< Context > ) -> Former::Formed >, - _marker : std::marker::PhantomData< Former::Storage >, + closure : Box< dyn Fn( Definition::Storage, Option< Context > ) -> Definition::Formed >, + _marker : std::marker::PhantomData< Definition::Storage >, } #[ cfg( not( feature = "no_std" ) ) ] -impl< Former : FormerDescriptor, Context > FormingEndWrapper< Former, Context > +impl< Definition : FormerDefinition, Context > FormingEndWrapper< Definition, Context > { /// Constructs a new `FormingEndWrapper` with the provided closure. /// @@ -110,7 +115,7 @@ impl< Former : FormerDescriptor, Context > FormingEndWrapper< Former, Context > /// # Returns /// /// Returns an instance of `FormingEndWrapper` encapsulating the provided closure. - pub fn new( closure : impl Fn( Former::Storage, Option< Context > ) -> Former::Formed + 'static ) -> Self + pub fn new( closure : impl Fn( Definition::Storage, Option< Context > ) -> Definition::Formed + 'static ) -> Self { Self { @@ -123,7 +128,7 @@ impl< Former : FormerDescriptor, Context > FormingEndWrapper< Former, Context > #[ cfg( not( feature = "no_std" ) ) ] use std::fmt; #[ cfg( not( feature = "no_std" ) ) ] -impl< Former : FormerDescriptor, Context > fmt::Debug for FormingEndWrapper< Former, Context > +impl< Definition : FormerDefinition, Context > fmt::Debug for FormingEndWrapper< Definition, Context > { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { @@ -135,10 +140,10 @@ impl< Former : FormerDescriptor, Context > fmt::Debug for FormingEndWrapper< For } #[ cfg( not( feature = "no_std" ) ) ] -impl< Former : FormerDescriptor, Context > FormingEnd< Former, Context > -for FormingEndWrapper< Former, Context > +impl< Definition : FormerDefinition, Context > FormingEnd< Definition, Context > +for FormingEndWrapper< Definition, Context > { - fn call( &self, storage : Former::Storage, context : Option< Context > ) -> Former::Formed + fn call( &self, storage : Definition::Storage, context : Option< Context > ) -> Definition::Formed { ( self.closure )( storage, context ) } @@ -179,7 +184,7 @@ for FormingEndWrapper< Former, Context > /// sophisticated and flexible construction patterns conducive to complex data transformations or object creation /// sequences within builder patterns. -pub trait FormerBegin< Former : FormerDescriptor, Context > +pub trait FormerBegin< Definition : FormerDefinition, Context > { /// * `End` - A trait bound marking the closure or handler invoked upon completing the subforming process. Implementers @@ -187,7 +192,7 @@ pub trait FormerBegin< Former : FormerDescriptor, Context > /// into `Formed`, optionally utilizing `Context` to guide this transformation. It is crucial that this /// associated type satisfies the `FormingEnd` trait, defining the precise mechanics of /// how the subformer concludes its operation. - type End : FormingEnd< Former, Context >; + type End : FormingEnd< Definition, Context >; /// Launches the subforming process with an initial storage and context, setting up an `on_end` completion handler. /// @@ -198,7 +203,7 @@ pub trait FormerBegin< Former : FormerDescriptor, Context > /// * `on_end` - A completion handler responsible for transforming the accumulated `Storage` into the final `Formed` structure. fn _begin ( - storage : core::option::Option< Former::Storage >, + storage : core::option::Option< Definition::Storage >, context : core::option::Option< Context >, on_end : Self::End, ) -> Self; diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 771a8b30cb..d4f0d278d3 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -21,11 +21,11 @@ where // /// Return former. // #[ inline( always ) ] - // fn former< Descriptor : FormerDescriptor >( self ) + // fn former< Definition : FormerDefinition >( self ) // -> - // HashMapSubformer< K, E, Descriptor, (), impl FormingEnd< Self, Self > > + // HashMapSubformer< K, E, Definition, (), impl FormingEnd< Self, Self > > // { - // HashMapSubformer::begin( Some( self ), None, ReturnStorage ) + // HashMapSubformer::begin( Some( self ), None, ReturnFormed ) // } // xxx : uncomment and cover by tests @@ -48,14 +48,14 @@ where // #[ derive( Debug ) ] -pub struct HashMapDescriptor< K, E > +pub struct HashMapDefinition< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { _phantom : ::core::marker::PhantomData< ( K, E ) >, } -impl< K, E > HashMapDescriptor< K, E > +impl< K, E > HashMapDefinition< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { @@ -65,8 +65,8 @@ where } } -impl< K, E > FormerDescriptor -for HashMapDescriptor< K, E > +impl< K, E > FormerDefinition +for HashMapDefinition< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { @@ -79,8 +79,8 @@ for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Descriptor = HashMapDescriptor< K, E >; - // fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed + type Definition = HashMapDefinition< K, E >; + // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed // { // self // } @@ -91,7 +91,7 @@ for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed + fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed { self } @@ -136,34 +136,34 @@ where /// ``` #[ derive( Debug, Default ) ] -pub struct HashMapSubformer< K, E, Descriptor, Context, End > +pub struct HashMapSubformer< K, E, Definition, Context, End > where K : ::core::cmp::Eq + ::core::hash::Hash, // Formed : HashMapLike< K, E > + ::core::default::Default, - End : FormingEnd< Descriptor, Context >, - Descriptor : FormerDescriptor, - Descriptor::Storage : ContainerAdd< Element = ( K, E ) >, + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = ( K, E ) >, { - storage : ::core::option::Option< Descriptor::Storage >, + storage : ::core::option::Option< Definition::Storage >, context : ::core::option::Option< Context >, on_end : ::core::option::Option< End >, _e_phantom : ::core::marker::PhantomData< E >, _k_phantom : ::core::marker::PhantomData< K >, } -impl< K, E, Descriptor, Context, End > -HashMapSubformer< K, E, Descriptor, Context, End > +impl< K, E, Definition, Context, End > +HashMapSubformer< K, E, Definition, Context, End > where K : ::core::cmp::Eq + ::core::hash::Hash, // Formed : HashMapLike< K, E > + ::core::default::Default, - End : FormingEnd< Descriptor, Context >, - Descriptor : FormerDescriptor, - Descriptor::Storage : ContainerAdd< Element = ( K, E ) >, + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = ( K, E ) >, { /// Form current former into target structure. #[ inline( always ) ] - pub fn storage( mut self ) -> Descriptor::Storage + pub fn storage( mut self ) -> Definition::Storage { // xxx let storage = if self.storage.is_some() @@ -186,7 +186,7 @@ where #[ inline( always ) ] pub fn begin ( - storage : ::core::option::Option< Descriptor::Storage >, + storage : ::core::option::Option< Definition::Storage >, context : ::core::option::Option< Context >, on_end : End, ) @@ -204,7 +204,7 @@ where /// Return context of your struct moving formed there. Should be called after forming process. #[ inline( always ) ] - pub fn end( mut self ) -> Descriptor::Formed + pub fn end( mut self ) -> Definition::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); @@ -214,14 +214,14 @@ where /// Return context of your struct moving formed there. Should be called after forming process. #[ inline( always ) ] - pub fn form( self ) -> Descriptor::Formed + pub fn form( self ) -> Definition::Formed { self.end() } /// Set the whole storage instead of setting each element individually. #[ inline( always ) ] - pub fn replace( mut self, storage : Descriptor::Storage ) -> Self + pub fn replace( mut self, storage : Definition::Storage ) -> Self { self.storage = Some( storage ); self @@ -229,13 +229,13 @@ where } -impl< K, E, Descriptor > -HashMapSubformer< K, E, Descriptor, (), crate::ReturnStorage > +impl< K, E, Definition > +HashMapSubformer< K, E, Definition, (), crate::ReturnFormed > where K : ::core::cmp::Eq + ::core::hash::Hash, - Descriptor : FormerDescriptor, - Descriptor::Storage : ContainerAdd< Element = ( K, E ) >, - // Formed : HashMapLike< K, E > + ::core::default::Default, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = ( K, E ) >, + Definition::Storage : StoragePerform< Definition = Definition >, { /// Create a new instance without context or on end processing. It just returns continaer on end of forming. @@ -246,20 +246,20 @@ where ( None, None, - crate::ReturnStorage, + crate::ReturnFormed, ) } } -impl< K, E, Descriptor, Context, End > -HashMapSubformer< K, E, Descriptor, Context, End > +impl< K, E, Definition, Context, End > +HashMapSubformer< K, E, Definition, Context, End > where K : ::core::cmp::Eq + ::core::hash::Hash, // Formed : HashMapLike< K, E > + ::core::default::Default, - End : FormingEnd< Descriptor, Context >, - Descriptor : FormerDescriptor, - Descriptor::Storage : ContainerAdd< Element = ( K, E ) >, + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = ( K, E ) >, { /// Inserts a key-value pair into the formed. If the formed doesn't exist, it is created. @@ -276,7 +276,7 @@ where where K2 : ::core::convert::Into< K >, E2 : ::core::convert::Into< E >, - // Descriptor::Storage : ContainerAdd< Element = ( K, E ) >, + // Definition::Storage : ContainerAdd< Element = ( K, E ) >, { if self.storage.is_none() { diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 07b274b5c3..0959953156 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -36,14 +36,14 @@ where // #[ derive( Debug ) ] -pub struct HashSetDescriptor< K > +pub struct HashSetDefinition< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { _phantom : ::core::marker::PhantomData< ( K, K ) >, } -impl< K > HashSetDescriptor< K > +impl< K > HashSetDefinition< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { @@ -58,8 +58,8 @@ for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Descriptor = HashSetDescriptor< K >; - // fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed + type Definition = HashSetDefinition< K >; + // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed // { // self // } @@ -70,14 +70,14 @@ for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed + fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed { self } } -impl< K > FormerDescriptor -for HashSetDescriptor< K > +impl< K > FormerDefinition +for HashSetDefinition< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { @@ -118,33 +118,33 @@ where /// ``` #[ derive( Debug, Default ) ] -pub struct HashSetSubformer< K, Descriptor, Context, End > +pub struct HashSetSubformer< K, Definition, Context, End > where K : core::cmp::Eq + core::hash::Hash, // Formed : HashSetLike< K > + core::default::Default, - End : FormingEnd< Descriptor, Context >, - Descriptor : FormerDescriptor, - Descriptor::Storage : ContainerAdd< Element = K >, + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = K >, { - storage : core::option::Option< Descriptor::Storage >, + storage : core::option::Option< Definition::Storage >, context : core::option::Option< Context >, on_end : core::option::Option< End >, _e_phantom : core::marker::PhantomData< K >, } -impl< K, Descriptor, Context, End > -HashSetSubformer< K, Descriptor, Context, End > +impl< K, Definition, Context, End > +HashSetSubformer< K, Definition, Context, End > where K : core::cmp::Eq + core::hash::Hash, // Formed : HashSetLike< K > + core::default::Default, - End : FormingEnd< Descriptor, Context >, - Descriptor : FormerDescriptor, - Descriptor::Storage : ContainerAdd< Element = K >, + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = K >, { /// Form current former into target structure. #[ inline( always ) ] - pub fn storage( mut self ) -> Descriptor::Storage + pub fn storage( mut self ) -> Definition::Storage { let storage = if self.storage.is_some() { @@ -172,7 +172,7 @@ where #[ inline( always ) ] pub fn begin ( - storage : core::option::Option< Descriptor::Storage >, + storage : core::option::Option< Definition::Storage >, context : core::option::Option< Context >, on_end : End, ) -> Self @@ -197,7 +197,7 @@ where /// constructed formed or a context that incorporates the formed. /// #[ inline( always ) ] - pub fn form( self ) -> Descriptor::Formed + pub fn form( self ) -> Definition::Formed { self.end() } @@ -213,7 +213,7 @@ where /// constructed formed or a context that incorporates the formed. /// #[ inline( always ) ] - pub fn end( mut self ) -> Descriptor::Formed + pub fn end( mut self ) -> Definition::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); @@ -234,7 +234,7 @@ where /// The builder instance with the storage replaced, enabling further chained operations. /// #[ inline( always ) ] - pub fn replace( mut self, storage : Descriptor::Storage ) -> Self + pub fn replace( mut self, storage : Definition::Storage ) -> Self { self.storage = Some( storage ); self @@ -242,19 +242,13 @@ where } -// impl< K > VectorSubformer< K, Formed, crate::ReturnStorage > -// where -// Formed : VectorLike< K > + core::default::Default, -// { - -impl< K, Descriptor > -HashSetSubformer< K, Descriptor, (), crate::ReturnStorage > +impl< K, Definition > +HashSetSubformer< K, Definition, (), crate::ReturnFormed > where K : core::cmp::Eq + core::hash::Hash, - Descriptor : FormerDescriptor, - Descriptor::Storage : ContainerAdd< Element = K >, - // Formed : HashSetLike< K > + core::default::Default, - // End : FormingEnd< Descriptor, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = K >, + Definition::Storage : StoragePerform< Definition = Definition >, { /// Initializes a new instance of the builder with default settings. @@ -272,19 +266,19 @@ where ( None, None, - crate::ReturnStorage, + crate::ReturnFormed, ) } } -impl< K, Descriptor, Context, End > -HashSetSubformer< K, Descriptor, Context, End > +impl< K, Definition, Context, End > +HashSetSubformer< K, Definition, Context, End > where K : core::cmp::Eq + core::hash::Hash, - End : FormingEnd< Descriptor, Context >, - Descriptor : FormerDescriptor, - Descriptor::Storage : ContainerAdd< Element = K >, + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = K >, { /// Inserts an element into the set, possibly replacing an existing element. diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 1f3cfef82c..46426d8733 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -93,7 +93,7 @@ where // ( // None, // None, - // crate::ReturnStorage, + // crate::ReturnFormed, // ) // } @@ -135,7 +135,7 @@ where } -impl< E, Formed > VectorSubformer< E, Formed, Formed, crate::ReturnStorage > +impl< E, Formed > VectorSubformer< E, Formed, Formed, crate::ReturnFormed > where Formed : VectorLike< E > + core::default::Default, { @@ -153,7 +153,7 @@ where ( None, None, - crate::ReturnStorage, + crate::ReturnFormed, ) } diff --git a/module/core/former/src/vector3.rs b/module/core/former/src/vector3.rs index 00105bea11..51730a9ee9 100644 --- a/module/core/former/src/vector3.rs +++ b/module/core/former/src/vector3.rs @@ -24,12 +24,12 @@ impl< E > VectorLike< E > for Vec< E > } #[ derive( Debug ) ] -pub struct VectorDescriptor< E > +pub struct VectorDefinition< E > { _phantom : core::marker::PhantomData< E >, } -impl< E > VectorDescriptor< E > +impl< E > VectorDefinition< E > { pub fn new() -> Self { @@ -37,8 +37,8 @@ impl< E > VectorDescriptor< E > } } -impl< E > FormerDescriptor -for VectorDescriptor< E > +impl< E > FormerDefinition +for VectorDefinition< E > { type Storage = Vec< E >; type Formed = Vec< E >; @@ -47,14 +47,14 @@ for VectorDescriptor< E > impl< E > Storage for Vec< E > { - type Descriptor = VectorDescriptor< E >; + type Definition = VectorDefinition< E >; } impl< E > StoragePerform for Vec< E > { - // type Descriptor = VectorDescriptor< E >; - fn preform( self ) -> < < Self as Storage >::Descriptor as FormerDescriptor >::Formed + // type Definition = VectorDefinition< E >; + fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed { self } @@ -65,27 +65,27 @@ for Vec< E > /// `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. #[ derive( Debug, Default ) ] -pub struct VectorSubformer< E, Descriptor, Context, End > +pub struct VectorSubformer< E, Definition, Context, End > where - End : FormingEnd< Descriptor, Context >, - Descriptor : FormerDescriptor, - Descriptor::Storage : ContainerAdd< Element = E >, + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = E >, { - storage : core::option::Option< Descriptor::Storage >, + storage : core::option::Option< Definition::Storage >, context : core::option::Option< Context >, on_end : core::option::Option< End >, } -impl< E, Descriptor, Context, End > VectorSubformer< E, Descriptor, Context, End > +impl< E, Definition, Context, End > VectorSubformer< E, Definition, Context, End > where - End : FormingEnd< Descriptor, Context >, - Descriptor : FormerDescriptor, - Descriptor::Storage : ContainerAdd< Element = E >, + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = E >, { /// Form current former into target structure. #[ inline( always ) ] - pub fn storage( mut self ) -> Descriptor::Storage + pub fn storage( mut self ) -> Definition::Storage { let storage = if self.storage.is_some() { @@ -103,7 +103,7 @@ where #[ inline( always ) ] pub fn begin ( - storage : core::option::Option< Descriptor::Storage >, + storage : core::option::Option< Definition::Storage >, context : core::option::Option< Context >, on_end : End ) -> Self @@ -118,14 +118,14 @@ where /// Finalizes the building process, returning the formed or a context incorporating it. #[ inline( always ) ] - pub fn form( self ) -> Descriptor::Formed + pub fn form( self ) -> Definition::Formed { self.end() } /// Finalizes the building process, returning the formed or a context incorporating it. #[ inline( always ) ] - pub fn end( mut self ) -> Descriptor::Formed + pub fn end( mut self ) -> Definition::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); @@ -135,7 +135,7 @@ where /// Replaces the current storage with a provided one, allowing for a reset or redirection of the building process. #[ inline( always ) ] - pub fn replace( mut self, vector : Descriptor::Storage ) -> Self + pub fn replace( mut self, vector : Definition::Storage ) -> Self { self.storage = Some( vector ); self @@ -143,10 +143,11 @@ where } -impl< E, Descriptor > VectorSubformer< E, Descriptor, (), ReturnStorage > +impl< E, Definition > VectorSubformer< E, Definition, (), ReturnFormed > where - Descriptor : FormerDescriptor, - Descriptor::Storage : ContainerAdd< Element = E >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = E >, + Definition::Storage : StoragePerform< Definition = Definition >, { /// Initializes a new `VectorSubformer` instance, starting with an empty formed. @@ -162,17 +163,17 @@ where ( None, None, - ReturnStorage, + ReturnFormed, ) } } -impl< E, Descriptor, Context, End > VectorSubformer< E, Descriptor, Context, End > +impl< E, Definition, Context, End > VectorSubformer< E, Definition, Context, End > where - End : FormingEnd< Descriptor, Context >, - Descriptor : FormerDescriptor, - Descriptor::Storage : ContainerAdd< Element = E >, + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = E >, { /// Appends an element to the end of the storage, expanding the internal collection. @@ -196,19 +197,19 @@ where // -impl< E, Descriptor, Context, End > FormerBegin< Descriptor, Context > -for VectorSubformer< E, Descriptor, Context, End > +impl< E, Definition, Context, End > FormerBegin< Definition, Context > +for VectorSubformer< E, Definition, Context, End > where - End : FormingEnd< Descriptor, Context >, - Descriptor : FormerDescriptor, - Descriptor::Storage : ContainerAdd< Element = E >, + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = E >, { type End = End; #[ inline( always ) ] fn _begin ( - storage : core::option::Option< Descriptor::Storage >, + storage : core::option::Option< Definition::Storage >, context : core::option::Option< Context >, on_end : End, ) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs index 3cb0bfa769..10f801ce59 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs @@ -13,9 +13,9 @@ pub struct Struct1 impl Struct1 { - pub fn former() -> Struct1Former< Struct1, the_module::ReturnStorage > + pub fn former() -> Struct1Former< Struct1, the_module::ReturnFormed > { - Struct1Former::< Struct1, the_module::ReturnStorage >::new() + Struct1Former::< Struct1, the_module::ReturnFormed >::new() } } @@ -50,7 +50,7 @@ impl Default for Struct1FormerStorage pub struct Struct1Former < Context = Struct1, - End = the_module::ReturnStorage, + End = the_module::ReturnFormed, > where End : the_module::FormingEnd< Struct1, Context >, @@ -116,13 +116,13 @@ where } // #[ inline( always ) ] - // pub fn new() -> Struct1Former + // pub fn new() -> Struct1Former // { // Struct1Former:: // < // Struct1, - // the_module::ReturnStorage, - // >::begin(None, the_module::ReturnStorage) + // the_module::ReturnFormed, + // >::begin(None, the_module::ReturnFormed) // } #[ inline( always ) ] @@ -254,13 +254,13 @@ where // where // End: the_module::FormingEnd, -impl Struct1Former< Struct1, the_module::ReturnStorage > +impl Struct1Former< Struct1, the_module::ReturnFormed > { #[ inline( always ) ] pub fn new() -> Self { - Self::begin( None, None, the_module::ReturnStorage ) + Self::begin( None, None, the_module::ReturnFormed ) } } diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs index 2d50928aff..5779c6af72 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs @@ -13,9 +13,9 @@ pub struct Struct1 impl Struct1 { - pub fn former() -> Struct1Former< Struct1, the_module::ReturnStorage > + pub fn former() -> Struct1Former< Struct1, the_module::ReturnFormed > { - Struct1Former::< Struct1, the_module::ReturnStorage >::new() + Struct1Former::< Struct1, the_module::ReturnFormed >::new() } } @@ -48,7 +48,7 @@ impl Default for Struct1FormerStorage pub struct Struct1Former < __FormerContext = Struct1, - __FormerEnd = the_module::ReturnStorage, + __FormerEnd = the_module::ReturnFormed, > where __FormerEnd : the_module::FormingEnd< Struct1, __FormerContext >, @@ -114,13 +114,13 @@ where } #[ inline( always ) ] - pub fn new() -> Struct1Former + pub fn new() -> Struct1Former { Struct1Former:: < Struct1, - the_module::ReturnStorage, - >::begin(None, the_module::ReturnStorage) + the_module::ReturnFormed, + >::begin(None, the_module::ReturnFormed) } #[ inline( always ) ] diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 054f83e6e0..0edae1ced2 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -15,7 +15,7 @@ pub struct Struct1 // generated by former impl Struct1 { - pub fn former() -> Struct1Former< (), former::ReturnStorage > + pub fn former() -> Struct1Former< (), former::ReturnFormed > { Struct1Former::new() } @@ -24,9 +24,9 @@ impl Struct1 // = descriptor #[ derive( Debug ) ] -pub struct Struct1FormerDescriptor; +pub struct Struct1FormerDefinition; -impl Struct1FormerDescriptor +impl Struct1FormerDefinition { pub fn new() -> Self { @@ -34,8 +34,8 @@ impl Struct1FormerDescriptor } } -impl former::FormerDescriptor -for Struct1FormerDescriptor +impl former::FormerDefinition +for Struct1FormerDefinition { type Storage = Struct1FormerStorage; type Formed = Struct1; @@ -72,14 +72,14 @@ impl Default for Struct1FormerStorage impl former::Storage for Struct1FormerStorage { - type Descriptor = Struct1FormerDescriptor; + type Definition = Struct1FormerDefinition; } impl former::StoragePerform for Struct1FormerStorage { - fn preform( mut self ) -> < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed + fn preform( mut self ) -> < < Self as former::Storage >::Definition as former::FormerDefinition >::Formed { let int_1 = if self.int_1.is_some() @@ -121,7 +121,7 @@ for Struct1FormerStorage }; // Rust failt to use parameter here - // < < Self as former::Storage >::Descriptor as former::FormerDescriptor >::Formed + // < < Self as former::Storage >::Definition as former::FormerDefinition >::Formed Struct1 { int_1, @@ -139,10 +139,10 @@ for Struct1FormerStorage pub struct Struct1Former < FormerContext = Struct1, - FormerEnd = the_module::ReturnStorage, + FormerEnd = the_module::ReturnFormed, > where - FormerEnd : the_module::FormingEnd< Struct1FormerDescriptor, FormerContext >, + FormerEnd : the_module::FormingEnd< Struct1FormerDefinition, FormerContext >, { storage : Struct1FormerStorage, context : core::option::Option< FormerContext >, @@ -151,16 +151,16 @@ where impl< FormerContext, FormerEnd > Struct1Former< FormerContext, FormerEnd > where - FormerEnd: the_module::FormingEnd< Struct1FormerDescriptor, FormerContext >, + FormerEnd: the_module::FormingEnd< Struct1FormerDefinition, FormerContext >, { - fn preform( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + fn preform( self ) -> < Struct1FormerDefinition as former::FormerDefinition >::Formed { former::StoragePerform::preform( self.storage ) } #[ inline( always ) ] - pub fn perform(self) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + pub fn perform(self) -> < Struct1FormerDefinition as former::FormerDefinition >::Formed { let result = self.form(); return result; @@ -169,7 +169,7 @@ where #[ inline( always ) ] pub fn begin ( - mut storage : core::option::Option< < Struct1FormerDescriptor as former::FormerDescriptor >::Storage >, + mut storage : core::option::Option< < Struct1FormerDefinition as former::FormerDefinition >::Storage >, context : core::option::Option< FormerContext >, on_end : FormerEnd, // xxx : cover by test existance of these 3 parameters in the function @@ -188,7 +188,7 @@ where } #[ inline( always ) ] - pub fn end( mut self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + pub fn end( mut self ) -> < Struct1FormerDefinition as former::FormerDefinition >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); @@ -196,7 +196,7 @@ where } #[ inline( always ) ] - pub fn form( self ) -> < Struct1FormerDescriptor as former::FormerDescriptor >::Formed + pub fn form( self ) -> < Struct1FormerDefinition as former::FormerDefinition >::Formed { self.end() } @@ -227,13 +227,13 @@ where } -impl Struct1Former< (), the_module::ReturnStorage > +impl Struct1Former< (), the_module::ReturnFormed > { #[ inline( always ) ] - pub fn new() -> Struct1Former< (), the_module::ReturnStorage > + pub fn new() -> Struct1Former< (), the_module::ReturnFormed > { - Struct1Former::< (), the_module::ReturnStorage >::begin( None, None, the_module::ReturnStorage ) + Struct1Former::< (), the_module::ReturnFormed >::begin( None, None, the_module::ReturnFormed ) } } diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_runtime.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_runtime.rs index 02986f54d0..ceeb84abaa 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_runtime.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_runtime.rs @@ -18,8 +18,8 @@ tests_impls_optional! a_id!( former.storage.hashmap_strings_1, None ); a_id!( former.storage.hashset_strings_1, None ); a_id!( former.context, None ); - a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnStorage ) ) ); - let former2 = Struct1Former::< Struct1, the_module::ReturnStorage >::new(); + a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnFormed ) ) ); + let former2 = Struct1Former::< Struct1, the_module::ReturnFormed >::new(); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_without_runtime.rs b/module/core/former/tests/inc/former_tests/only_test/containers_without_runtime.rs index 3ffdb7dc94..8141ddc9fd 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_without_runtime.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_without_runtime.rs @@ -18,8 +18,8 @@ tests_impls! a_id!( former.storage.hashmap_strings_1, None ); a_id!( former.storage.hashset_strings_1, None ); a_id!( former.context, None ); - a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnStorage ) ) ); - let former2 = Struct1Former::< Struct1, the_module::ReturnStorage >::new(); + a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnFormed ) ) ); + let former2 = Struct1Former::< Struct1, the_module::ReturnFormed >::new(); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index f57fa78f30..1f587f690b 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -17,7 +17,7 @@ tests_impls! a_id!( former.storage.int_optional_1, None ); a_id!( former.storage.string_optional_1, None ); a_id!( former.context, None ); - a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnStorage ) ) ); + a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnFormed ) ) ); let former2 = Struct1Former::new(); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); @@ -48,7 +48,7 @@ tests_impls! let mut storage = Struct1FormerStorage::default(); storage.int_1 = Some( 13 ); - // Struct1Former::< (), the_module::ReturnStorage >::begin( storage, None, the_module::ReturnStorage ) + // Struct1Former::< (), the_module::ReturnFormed >::begin( storage, None, the_module::ReturnFormed ) // xxx } @@ -82,13 +82,13 @@ tests_impls! { // descriptor exists and has Formed - let got = < Struct1FormerDescriptor as the_module::FormerDescriptor >::Formed::former().form(); + let got = < Struct1FormerDefinition as the_module::FormerDefinition >::Formed::former().form(); let exp = Struct1::former().form(); a_id!( got, exp ); // descriptor exists and has Storage use former::StoragePerform; - let got = < Struct1FormerDescriptor as the_module::FormerDescriptor >::Storage::preform( Struct1::former().storage ); + let got = < Struct1FormerDefinition as the_module::FormerDefinition >::Storage::preform( Struct1::former().storage ); let exp = Struct1::former().form(); a_id!( got, exp ); @@ -116,7 +116,7 @@ tests_impls! a_id!( got, exp ); // storage exists - let got = < < Struct1FormerStorage as the_module::Storage >::Descriptor as the_module::FormerDescriptor >::Formed::former().form(); + let got = < < Struct1FormerStorage as the_module::Storage >::Definition as the_module::FormerDefinition >::Formed::former().form(); let exp = Struct1::former().form(); a_id!( got, exp ); diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 6e201046bc..9993204d16 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -73,7 +73,7 @@ where // generated by former // #[ derive( Debug, Default ) ] -pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnStorage > +pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnFormed > where K : core::hash::Hash + std::cmp::Eq, End : the_module::FormingEnd< Command< K >, Context >, @@ -135,7 +135,7 @@ where ( None, None, - the_module::ReturnStorage, + the_module::ReturnFormed, ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs b/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs index 3bc5c46a73..4c8ebd3b82 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs @@ -93,7 +93,7 @@ where // generated by former // #[ derive( Debug, Default ) ] -pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnStorage > +pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnFormed > where K : core::hash::Hash + std::cmp::Eq, End : the_module::FormingEnd< Command< K >, Context >, @@ -166,7 +166,7 @@ where ( None, None, - the_module::ReturnStorage, + the_module::ReturnFormed, ) } @@ -301,7 +301,7 @@ where // generated by former // #[ derive( Debug, Default ) ] -pub struct AggregatorFormer< K, Context = Aggregator< K >, End = the_module::ReturnStorage > +pub struct AggregatorFormer< K, Context = Aggregator< K >, End = the_module::ReturnFormed > where K : core::hash::Hash + std::cmp::Eq, End : the_module::FormingEnd< Aggregator< K >, Context >, @@ -363,7 +363,7 @@ where AggregatorFormer::< K >::begin ( None, - the_module::ReturnStorage, + the_module::ReturnFormed, ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index bf8c825690..da39a6c5a1 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -4,7 +4,7 @@ use super::*; /// Parameter description. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] -pub struct TemplateParameterDescriptor +pub struct TemplateParameterDefinition { descriptor : String, is_mandatory : bool, @@ -16,7 +16,7 @@ pub struct TemplateParameters { // #[ debug = the_module::VectorSubformer, descriptor, descriptor( name ) ] #[ subformer( the_module::VectorSubformer ) ] - descriptors : Vec< TemplateParameterDescriptor >, + descriptors : Vec< TemplateParameterDefinition >, // #[ subformer_setter = the_module::VectorSubformer ] // pub fn descriptor( self, name : &str ) @@ -26,17 +26,17 @@ pub struct TemplateParameters } -impl< Context, End > former::FormerBegin< TemplateParameterDescriptorFormerStorage, TemplateParameterDescriptor, Context > -for TemplateParameterDescriptorFormer< Context, End > +impl< Context, End > former::FormerBegin< TemplateParameterDefinitionFormerStorage, TemplateParameterDefinition, Context > +for TemplateParameterDefinitionFormer< Context, End > where - End : the_module::FormingEnd< TemplateParameterDescriptor, Context >, + End : the_module::FormingEnd< TemplateParameterDefinition, Context >, { type End = End; #[ inline( always ) ] fn _begin ( - storage : core::option::Option< TemplateParameterDescriptorFormerStorage >, /* xxx2 : that should be storage */ + storage : core::option::Option< TemplateParameterDefinitionFormerStorage >, /* xxx2 : that should be storage */ context : core::option::Option< Context >, on_end : End, ) -> Self @@ -58,14 +58,14 @@ where where Former2 : former::FormerBegin < - TemplateParameterDescriptorFormerStorage, - TemplateParameterDescriptor, + TemplateParameterDefinitionFormerStorage, + TemplateParameterDefinition, Self, - End = former::FormingEndWrapper< TemplateParameterDescriptor, Self >, + End = former::FormingEndWrapper< TemplateParameterDefinition, Self >, >, // FieldContainer : ContainerAdd, { - let on_end = | descriptor : TemplateParameterDescriptor, super_former : core::option::Option< Self > | -> Self + let on_end = | descriptor : TemplateParameterDefinition, super_former : core::option::Option< Self > | -> Self { let mut super_former = super_former.unwrap(); if super_former.storage.descriptors.is_none() @@ -85,9 +85,9 @@ where #[ inline( always ) ] pub fn descriptor( self, name : &str ) -> - TemplateParameterDescriptorFormer< Self, impl former::FormingEnd< TemplateParameterDescriptor, Self > > + TemplateParameterDefinitionFormer< Self, impl former::FormingEnd< TemplateParameterDefinition, Self > > { - self.descriptor3::< TemplateParameterDescriptorFormer< _, _ > >().descriptor( name ) + self.descriptor3::< TemplateParameterDefinitionFormer< _, _ > >().descriptor( name ) } } @@ -98,15 +98,15 @@ fn basic() let got = TemplateParameters::former() .descriptors() - .push( TemplateParameterDescriptor::former().descriptor( "a" ).form() ) - .push( TemplateParameterDescriptor::former().descriptor( "b" ).form() ) + .push( TemplateParameterDefinition::former().descriptor( "a" ).form() ) + .push( TemplateParameterDefinition::former().descriptor( "b" ).form() ) .end() .form(); let descriptors = vec! [ - TemplateParameterDescriptor { descriptor : "a".to_string(), is_mandatory : false }, - TemplateParameterDescriptor { descriptor : "b".to_string(), is_mandatory : false }, + TemplateParameterDefinition { descriptor : "a".to_string(), is_mandatory : false }, + TemplateParameterDefinition { descriptor : "b".to_string(), is_mandatory : false }, ]; let exp = TemplateParameters { descriptors }; a_id!( got, exp ); diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index ec54b2ad41..52d39080e2 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -5,7 +5,7 @@ use macro_tools::{ attr, diag, generics, container_kind, typ, Result }; use proc_macro2::TokenStream; /// -/// Descriptor of a field. +/// Definition of a field. /// #[ allow( dead_code ) ] @@ -755,7 +755,7 @@ pub fn performer< 'a > return result; }; // let mut perform_output = qt!{ #name_ident #generics_ty }; - let mut perform_output = qt!{ < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed }; + let mut perform_output = qt!{ < #former_descriptor_name_ident #generics_ty as former::FormerDefinition >::Formed }; let mut perform_generics = qt!{}; for attr in attrs @@ -827,7 +827,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_name_ident = syn::Ident::new( &former_name, name_ident.span() ); let former_storage_name = format!( "{}FormerStorage", name_ident ); let former_storage_name_ident = syn::Ident::new( &former_storage_name, name_ident.span() ); - let former_descriptor_name = format!( "{}FormerDescriptor", name_ident ); + let former_descriptor_name = format!( "{}FormerDefinition", name_ident ); let former_descriptor_name_ident = syn::Ident::new( &former_descriptor_name, name_ident.span() ); /* generic parameters */ @@ -848,7 +848,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // add embedded generic parameters let mut extra_generics : syn::Generics = parse_quote! { - < __FormerContext = #name_ident #generics_ty, __FormerEnd = former::ReturnStorage > + < __FormerContext = #name_ident #generics_ty, __FormerEnd = former::ReturnFormed > }; extra_generics.where_clause = parse_quote! { @@ -932,7 +932,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// Make former, variation of builder pattern to form structure defining values of fields step by step. /// #[ inline( always ) ] - pub fn former() -> #former_name_ident < #generics_params (), former::ReturnStorage > + pub fn former() -> #former_name_ident < #generics_params (), former::ReturnFormed > { #former_name_ident :: new() } @@ -951,7 +951,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } - impl #generics_impl former::FormerDescriptor + impl #generics_impl former::FormerDefinition for #former_descriptor_name_ident #generics_ty { type Storage = #former_storage_name_ident #generics_ty; @@ -990,8 +990,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > for #former_storage_name_ident #generics_ty #generics_where { - // type Descriptor = Struct1FormerDescriptor; - type Descriptor = #former_descriptor_name_ident #generics_ty; + // type Definition = Struct1FormerDefinition; + type Definition = #former_descriptor_name_ident #generics_ty; } // generics_impl, generics_ty, generics_where @@ -1001,11 +1001,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { // fn preform( mut self ) -> #former_storage_name_ident #generics_ty - fn preform( mut self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + fn preform( mut self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDefinition >::Formed { #( #fields_form )* // Rust does not support that, yet - // let result = < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + // let result = < #former_descriptor_name_ident #generics_ty as former::FormerDefinition >::Formed let result = #name_ident #generics_ty { #( #fields_names, )* @@ -1037,7 +1037,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// Finish setting options and return formed entity. /// #[ inline( always ) ] - pub fn preform( self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + pub fn preform( self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDefinition >::Formed // #name_ident #generics_ty { < #former_storage_name_ident #generics_ty as former::StoragePerform >::preform( self.storage ) @@ -1089,7 +1089,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn form( self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + pub fn form( self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDefinition >::Formed { self.end() } @@ -1098,7 +1098,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn end( mut self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDescriptor >::Formed + pub fn end( mut self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDefinition >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); @@ -1113,7 +1113,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } #[ automatically_derived ] - impl #generics_impl #former_name_ident < #generics_params (), former::ReturnStorage > + impl #generics_impl #former_name_ident < #generics_params (), former::ReturnFormed > #generics_where { @@ -1123,12 +1123,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ inline( always ) ] pub fn new() -> Self { - // #former_name_ident :: < #generics_params #name_ident #generics_ty, former::ReturnStorage > :: begin + // #former_name_ident :: < #generics_params #name_ident #generics_ty, former::ReturnFormed > :: begin Self :: begin ( None, None, - former::ReturnStorage, + former::ReturnFormed, ) } diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index 1c13e11236..e02c582eaf 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -119,9 +119,9 @@ mod derive /// impl UserProfile /// { /// #[ inline( always ) ] -/// pub fn former() -> UserProfileFormer< UserProfile, former::ReturnStorage > +/// pub fn former() -> UserProfileFormer< UserProfile, former::ReturnFormed > /// { -/// UserProfileFormer::< UserProfile, former::ReturnStorage >::new() +/// UserProfileFormer::< UserProfile, former::ReturnFormed >::new() /// } /// } /// @@ -136,7 +136,7 @@ mod derive /// pub struct UserProfileFormer /// < /// Context = UserProfile, -/// End = former::ReturnStorage, +/// End = former::ReturnFormed, /// > /// where /// End : former::FormingEnd< UserProfile, Context >, @@ -189,9 +189,9 @@ mod derive /// /// // qqq : xxx : outdated, update /// #[ inline( always ) ] -/// pub fn new() -> UserProfileFormer< UserProfile, former::ReturnStorage > +/// pub fn new() -> UserProfileFormer< UserProfile, former::ReturnFormed > /// { -/// UserProfileFormer::< UserProfile, former::ReturnStorage >::begin( None, former::ReturnStorage ) +/// UserProfileFormer::< UserProfile, former::ReturnFormed >::begin( None, former::ReturnFormed ) /// } /// /// #[ inline( always ) ] From 1daded7041f6e3595019f4693ca947f6dbbbc74a Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 19:52:34 +0200 Subject: [PATCH 014/533] former : experimenting --- module/core/former/src/axiomatic.rs | 183 +++++---- module/core/former/src/axiomatic3.rs | 211 ---------- module/core/former/src/container.rs | 162 ++++++++ module/core/former/src/hash_map.rs | 354 ++++++++-------- module/core/former/src/hash_set.rs | 386 +++++++++--------- module/core/former/src/lib.rs | 2 - module/core/former/src/vector.rs | 344 ++++++++-------- module/core/former/src/vector3.rs | 221 ---------- ...hashmap.rs => container_former_hashmap.rs} | 0 ...hashset.rs => container_former_hashset.rs} | 0 ...bformer_vec.rs => container_former_vec.rs} | 31 +- module/core/former/tests/inc/mod.rs | 18 +- 12 files changed, 843 insertions(+), 1069 deletions(-) delete mode 100644 module/core/former/src/axiomatic3.rs delete mode 100644 module/core/former/src/vector3.rs rename module/core/former/tests/inc/former_tests/{subformer_hashmap.rs => container_former_hashmap.rs} (100%) rename module/core/former/tests/inc/former_tests/{subformer_hashset.rs => container_former_hashset.rs} (100%) rename module/core/former/tests/inc/former_tests/{subformer_vec.rs => container_former_vec.rs} (52%) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 161a0f3ea8..1587a215ab 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -1,14 +1,42 @@ //! .... +pub trait Storage : ::core::default::Default +{ + type Definition : FormerDefinition< Storage = Self >; +} + +/// xxx +pub trait StoragePerform : Storage +{ + fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed; +} + +/// xxx +pub trait FormerDefinition +{ + // type Storage : StoragePerform< Definition = Self >; + type Storage : Storage< Definition = Self >; + type Formed; +} + +// pub trait FormerDefinition +// { +// type Storage : StoragePerform< Formed = Self::Formed >; +// type Formed; +// type Context; +// type FormerDefinition : FormerDefinition< Storage = Self::Storage, Formed = Self::Formed >; +// type End : FormingEnd< Self::FormerDefinition, Self::Context >; +// } + /// Defines a handler for the end of a subforming process, enabling the return of the original context. /// /// This trait is designed to be flexible, allowing for various end-of-forming behaviors in builder patterns. /// Implementors can define how to transform or pass through the context during the forming process's completion. /// /// # Parameters -/// - `Formed`: The type of the container being processed. +/// - `Storage`: The type of the container being processed. /// - `Context`: The type of the context that might be altered or returned upon completion. -pub trait FormingEnd< Formed, Context > +pub trait FormingEnd< Definition : FormerDefinition, Context > { /// Called at the end of the subforming process to return the modified or original context. /// @@ -18,21 +46,41 @@ pub trait FormingEnd< Formed, Context > /// /// # Returns /// Returns the transformed or original context based on the implementation. - #[ allow( dead_code ) ] - fn call( &self, storage : Formed, context : core::option::Option< Context > ) -> Context; + fn call( &self, storage : Definition::Storage, context : core::option::Option< Context > ) -> Definition::Formed; } -impl< Storage, Context, F > FormingEnd< Storage, Context > for F +impl< Definition : FormerDefinition, Context, F > FormingEnd< Definition, Context > for F where - F : Fn( Storage, core::option::Option< Context > ) -> Context, + F : Fn( Definition::Storage, core::option::Option< Context > ) -> Definition::Formed, { #[ inline( always ) ] - fn call( &self, storage : Storage, context : core::option::Option< Context > ) -> Context + fn call( &self, storage : Definition::Storage, context : core::option::Option< Context > ) -> Definition::Formed { self( storage, context ) } } +/// A `FormingEnd` implementation that returns the formed container itself instead of the context. +/// +/// This struct is useful when the forming process should result in the formed container being returned directly, +/// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. +#[ derive( Debug, Default ) ] +pub struct ReturnFormed; + +impl< Definition : FormerDefinition > FormingEnd< Definition, () > +for ReturnFormed +where + Definition::Storage : StoragePerform< Definition = Definition >, + // xxx : rename Former -> Definition + // xxx : rename Definition -> Definition +{ + #[ inline( always ) ] + fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed + { + storage.preform() + } +} + /// A wrapper around a closure to be used as a `FormingEnd`. /// /// This struct allows for dynamic dispatch of a closure that matches the @@ -47,14 +95,14 @@ where /// * `Context` - The type of the context that may be altered or returned by the closure. /// This allows for flexible manipulation of context based on the container. #[ cfg( not( feature = "no_std" ) ) ] -pub struct FormingEndWrapper< Storage, Context > +pub struct FormingEndWrapper< Definition : FormerDefinition, Context > { - closure : Box< dyn Fn( Storage, Option< Context > ) -> Context >, - _marker : std::marker::PhantomData< Storage >, + closure : Box< dyn Fn( Definition::Storage, Option< Context > ) -> Definition::Formed >, + _marker : std::marker::PhantomData< Definition::Storage >, } #[ cfg( not( feature = "no_std" ) ) ] -impl< Storage, Context > FormingEndWrapper< Storage, Context > +impl< Definition : FormerDefinition, Context > FormingEndWrapper< Definition, Context > { /// Constructs a new `FormingEndWrapper` with the provided closure. /// @@ -67,7 +115,7 @@ impl< Storage, Context > FormingEndWrapper< Storage, Context > /// # Returns /// /// Returns an instance of `FormingEndWrapper` encapsulating the provided closure. - pub fn new( closure : impl Fn( Storage, Option< Context > ) -> Context + 'static ) -> Self + pub fn new( closure : impl Fn( Definition::Storage, Option< Context > ) -> Definition::Formed + 'static ) -> Self { Self { @@ -80,7 +128,7 @@ impl< Storage, Context > FormingEndWrapper< Storage, Context > #[ cfg( not( feature = "no_std" ) ) ] use std::fmt; #[ cfg( not( feature = "no_std" ) ) ] -impl< Storage, Context > fmt::Debug for FormingEndWrapper< Storage, Context > +impl< Definition : FormerDefinition, Context > fmt::Debug for FormingEndWrapper< Definition, Context > { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { @@ -92,99 +140,70 @@ impl< Storage, Context > fmt::Debug for FormingEndWrapper< Storage, Context > } #[ cfg( not( feature = "no_std" ) ) ] -impl< Storage, Context > FormingEnd< Storage, Context > -for FormingEndWrapper< Storage, Context > +impl< Definition : FormerDefinition, Context > FormingEnd< Definition, Context > +for FormingEndWrapper< Definition, Context > { - fn call( &self, storage : Storage, context : Option< Context > ) -> Context + fn call( &self, storage : Definition::Storage, context : Option< Context > ) -> Definition::Formed { ( self.closure )( storage, context ) } } -// /// A `FormingEnd` implementation that returns the original context without any modifications. -// /// -// /// This struct is used when no end-of-forming processing is needed, and the original context is to be returned as-is. -// #[ derive( Debug, Default ) ] -// pub struct NoEnd; // -// impl< Formed, Context > FormingEnd< Formed, Context > -// for NoEnd -// { -// #[ inline( always ) ] -// fn call( &self, _formed : Formed, context : core::option::Option< Context > ) -> Context -// { -// context.unwrap() -// } -// } -/// A `FormingEnd` implementation that returns the formed container itself instead of the context. +/// A trait for initiating a structured subforming process with contextual and intermediary storage linkage. /// -/// This struct is useful when the forming process should result in the formed container being returned directly, -/// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. -#[ derive( Debug, Default ) ] -pub struct ReturnFormed; - -impl< Storage > FormingEnd< Storage, Storage > -for ReturnFormed -{ - #[ inline( always ) ] - fn call( &self, storage : Storage, _context : core::option::Option< Storage > ) -> Storage - { - storage - } -} - -// - -/// A trait defining the initialization process for a subformer with contextual linkage. -/// -/// This trait is designed for types that need to initiate a subforming process, -/// passing themselves as the context and specifying a closure or handler (`on_end`) to be -/// called upon completion. It facilitates the construction of builder pattern chains -/// that maintain stateful context through each step of the process. +/// This trait facilitates the creation of a subformer that carries through a builder pattern chain, +/// utilizing intermediary storage for accumulating state or data before finally transforming it into +/// a `Formed` structure. It is designed for scenarios where a multi-step construction or transformation +/// process benefits from maintaining both transient state (`Storage`) and contextual information (`Context`), +/// before concluding with the generation of a final product (`Formed`). /// /// # Type Parameters /// -/// * `Formed` - Represents the type that is being constructed or transformed by the subformer. -/// * `Context` - Denotes the contextual information or the environment in which `Formed` is being formed. -/// This could be a reference to a parent builder, configuration settings, or any other -/// relevant state. +/// * `Storage` - Represents a mutable intermediary storage structure used throughout the subforming process +/// to accumulate data, state, or partial computations. This storage is internal to the +/// subformer and is eventually converted into the final `Formed` structure by the subformer, +/// not directly by implementations of this trait. +/// +/// * `Formed` - Denotes the final type that results from the subforming process. This is the intended outcome +/// of the builder chain, constructed or transformed from the `Storage` with consideration of +/// the provided `Context`. +/// +/// * `Context` - Specifies the contextual backdrop against which the subforming process unfolds. This could +/// encompass references to parent builders, configuration data, or any state influencing how +/// `Storage` transitions into `Formed`. /// -/// # Associated Types +/// # Functions /// -/// * `End` - Specifies the trait bound for the closure or handler that gets called at the completion -/// of the subforming process. This type must implement the `FormingEnd` -/// trait, which defines how the final transformation or construction of `Formed` is handled, -/// potentially using the provided `Context`. +/// * `_begin` - This function launches the subforming process, marking the start of a construction or transformation +/// sequence defined by the implementing type. It establishes the foundational `Storage` and `Context`, +/// alongside specifying an `on_end` completion handler that dictates the final conversion into `Formed`. /// +/// The `FormerBegin` trait, by decoupling `Storage` from `Formed` and introducing a contextual layer, enables +/// sophisticated and flexible construction patterns conducive to complex data transformations or object creation +/// sequences within builder patterns. -pub trait FormerBegin< Storage, Formed, Context > +pub trait FormerBegin< Definition : FormerDefinition, Context > { - /// * `End` - Specifies the trait bound for the closure or handler that gets called at the completion - /// of the subforming process. This type must implement the `FormingEnd` - /// trait, which defines how the final transformation or construction of `Formed` is handled, - /// potentially using the provided `Context`. - type End : FormingEnd< Formed, Context >; + /// * `End` - A trait bound marking the closure or handler invoked upon completing the subforming process. Implementers + /// of this trait (`End`) are tasked with applying the final transformations that transition `Storage` + /// into `Formed`, optionally utilizing `Context` to guide this transformation. It is crucial that this + /// associated type satisfies the `FormingEnd` trait, defining the precise mechanics of + /// how the subformer concludes its operation. + type End : FormingEnd< Definition, Context >; - /// Initializes the subforming process by setting the context and specifying an `on_end` completion handler. - /// - /// This function is the entry point for initiating a subforming sequence, allowing the caller - /// to establish initial contextual information and define how the process concludes. + /// Launches the subforming process with an initial storage and context, setting up an `on_end` completion handler. /// /// # Parameters /// - /// * `context` - An optional parameter providing initial context for the subforming process. This - /// might include configuration data, references to parent structures, or any state - /// relevant to the formation of `Formed`. - /// - /// * `on_end` - A closure or handler of type `Self::End` that is invoked at the completion of - /// the subforming process. This handler is responsible for applying any final transformations - /// to `Formed` and potentially utilizing `Context` to influence the outcome. - /// + /// * `storage` - An optional initial state for the intermediary storage structure. + /// * `context` - An optional initial setting providing contextual information for the subforming process. + /// * `on_end` - A completion handler responsible for transforming the accumulated `Storage` into the final `Formed` structure. fn _begin ( - storage : core::option::Option< Storage >, + storage : core::option::Option< Definition::Storage >, context : core::option::Option< Context >, on_end : Self::End, ) -> Self; diff --git a/module/core/former/src/axiomatic3.rs b/module/core/former/src/axiomatic3.rs deleted file mode 100644 index 1587a215ab..0000000000 --- a/module/core/former/src/axiomatic3.rs +++ /dev/null @@ -1,211 +0,0 @@ -//! .... - -pub trait Storage : ::core::default::Default -{ - type Definition : FormerDefinition< Storage = Self >; -} - -/// xxx -pub trait StoragePerform : Storage -{ - fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed; -} - -/// xxx -pub trait FormerDefinition -{ - // type Storage : StoragePerform< Definition = Self >; - type Storage : Storage< Definition = Self >; - type Formed; -} - -// pub trait FormerDefinition -// { -// type Storage : StoragePerform< Formed = Self::Formed >; -// type Formed; -// type Context; -// type FormerDefinition : FormerDefinition< Storage = Self::Storage, Formed = Self::Formed >; -// type End : FormingEnd< Self::FormerDefinition, Self::Context >; -// } - -/// Defines a handler for the end of a subforming process, enabling the return of the original context. -/// -/// This trait is designed to be flexible, allowing for various end-of-forming behaviors in builder patterns. -/// Implementors can define how to transform or pass through the context during the forming process's completion. -/// -/// # Parameters -/// - `Storage`: The type of the container being processed. -/// - `Context`: The type of the context that might be altered or returned upon completion. -pub trait FormingEnd< Definition : FormerDefinition, Context > -{ - /// Called at the end of the subforming process to return the modified or original context. - /// - /// # Parameters - /// - `container`: The container being processed. - /// - `context`: Optional context to be transformed or returned. - /// - /// # Returns - /// Returns the transformed or original context based on the implementation. - fn call( &self, storage : Definition::Storage, context : core::option::Option< Context > ) -> Definition::Formed; -} - -impl< Definition : FormerDefinition, Context, F > FormingEnd< Definition, Context > for F -where - F : Fn( Definition::Storage, core::option::Option< Context > ) -> Definition::Formed, -{ - #[ inline( always ) ] - fn call( &self, storage : Definition::Storage, context : core::option::Option< Context > ) -> Definition::Formed - { - self( storage, context ) - } -} - -/// A `FormingEnd` implementation that returns the formed container itself instead of the context. -/// -/// This struct is useful when the forming process should result in the formed container being returned directly, -/// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. -#[ derive( Debug, Default ) ] -pub struct ReturnFormed; - -impl< Definition : FormerDefinition > FormingEnd< Definition, () > -for ReturnFormed -where - Definition::Storage : StoragePerform< Definition = Definition >, - // xxx : rename Former -> Definition - // xxx : rename Definition -> Definition -{ - #[ inline( always ) ] - fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed - { - storage.preform() - } -} - -/// A wrapper around a closure to be used as a `FormingEnd`. -/// -/// This struct allows for dynamic dispatch of a closure that matches the -/// `FormingEnd` trait's `call` method signature. It is useful for cases where -/// a closure needs to be stored or passed around as an object implementing -/// `FormingEnd`. -/// -/// # Type Parameters -/// -/// * `Storage` - The type of the container being processed. This type is passed to the closure -/// when it's called. -/// * `Context` - The type of the context that may be altered or returned by the closure. -/// This allows for flexible manipulation of context based on the container. -#[ cfg( not( feature = "no_std" ) ) ] -pub struct FormingEndWrapper< Definition : FormerDefinition, Context > -{ - closure : Box< dyn Fn( Definition::Storage, Option< Context > ) -> Definition::Formed >, - _marker : std::marker::PhantomData< Definition::Storage >, -} - -#[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinition, Context > FormingEndWrapper< Definition, Context > -{ - /// Constructs a new `FormingEndWrapper` with the provided closure. - /// - /// # Parameters - /// - /// * `closure` - A closure that matches the expected signature for transforming a container - /// and context into a new context. This closure is stored and called by the - /// `call` method of the `FormingEnd` trait implementation. - /// - /// # Returns - /// - /// Returns an instance of `FormingEndWrapper` encapsulating the provided closure. - pub fn new( closure : impl Fn( Definition::Storage, Option< Context > ) -> Definition::Formed + 'static ) -> Self - { - Self - { - closure : Box::new( closure ), - _marker : std::marker::PhantomData - } - } -} - -#[ cfg( not( feature = "no_std" ) ) ] -use std::fmt; -#[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinition, Context > fmt::Debug for FormingEndWrapper< Definition, Context > -{ - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result - { - f.debug_struct( "FormingEndWrapper" ) - .field( "closure", &format_args!{ "- closure -" } ) - .field( "_marker", &self._marker ) - .finish() - } -} - -#[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinition, Context > FormingEnd< Definition, Context > -for FormingEndWrapper< Definition, Context > -{ - fn call( &self, storage : Definition::Storage, context : Option< Context > ) -> Definition::Formed - { - ( self.closure )( storage, context ) - } -} - -// - -/// A trait for initiating a structured subforming process with contextual and intermediary storage linkage. -/// -/// This trait facilitates the creation of a subformer that carries through a builder pattern chain, -/// utilizing intermediary storage for accumulating state or data before finally transforming it into -/// a `Formed` structure. It is designed for scenarios where a multi-step construction or transformation -/// process benefits from maintaining both transient state (`Storage`) and contextual information (`Context`), -/// before concluding with the generation of a final product (`Formed`). -/// -/// # Type Parameters -/// -/// * `Storage` - Represents a mutable intermediary storage structure used throughout the subforming process -/// to accumulate data, state, or partial computations. This storage is internal to the -/// subformer and is eventually converted into the final `Formed` structure by the subformer, -/// not directly by implementations of this trait. -/// -/// * `Formed` - Denotes the final type that results from the subforming process. This is the intended outcome -/// of the builder chain, constructed or transformed from the `Storage` with consideration of -/// the provided `Context`. -/// -/// * `Context` - Specifies the contextual backdrop against which the subforming process unfolds. This could -/// encompass references to parent builders, configuration data, or any state influencing how -/// `Storage` transitions into `Formed`. -/// -/// # Functions -/// -/// * `_begin` - This function launches the subforming process, marking the start of a construction or transformation -/// sequence defined by the implementing type. It establishes the foundational `Storage` and `Context`, -/// alongside specifying an `on_end` completion handler that dictates the final conversion into `Formed`. -/// -/// The `FormerBegin` trait, by decoupling `Storage` from `Formed` and introducing a contextual layer, enables -/// sophisticated and flexible construction patterns conducive to complex data transformations or object creation -/// sequences within builder patterns. - -pub trait FormerBegin< Definition : FormerDefinition, Context > -{ - - /// * `End` - A trait bound marking the closure or handler invoked upon completing the subforming process. Implementers - /// of this trait (`End`) are tasked with applying the final transformations that transition `Storage` - /// into `Formed`, optionally utilizing `Context` to guide this transformation. It is crucial that this - /// associated type satisfies the `FormingEnd` trait, defining the precise mechanics of - /// how the subformer concludes its operation. - type End : FormingEnd< Definition, Context >; - - /// Launches the subforming process with an initial storage and context, setting up an `on_end` completion handler. - /// - /// # Parameters - /// - /// * `storage` - An optional initial state for the intermediary storage structure. - /// * `context` - An optional initial setting providing contextual information for the subforming process. - /// * `on_end` - A completion handler responsible for transforming the accumulated `Storage` into the final `Formed` structure. - fn _begin - ( - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Context >, - on_end : Self::End, - ) -> Self; - -} diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index cfdbfdb4d1..e68732dfa6 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -1,5 +1,7 @@ //! Interface for containers. +use crate::*; + /// A trait defining the capability to add elements to a container. /// /// This trait should be implemented by container types that require a generic interface @@ -188,3 +190,163 @@ where self.len() - initial_len } } + +// = + + +/// A builder for constructing containers, facilitating a fluent and flexible interface. +#[ derive( Debug, Default ) ] +pub struct ContainerSubformer< E, Definition, Context = (), End = ReturnFormed > +where + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = E >, +{ + storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Context >, + on_end : core::option::Option< End >, +} + +impl< E, Definition, Context, End > ContainerSubformer< E, Definition, Context, End > +where + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = E >, +{ + + /// Form current former into target structure. + #[ inline( always ) ] + pub fn storage( mut self ) -> Definition::Storage + { + let storage = if self.storage.is_some() + { + self.storage.take().unwrap() + } + else + { + let val = Default::default(); + val + }; + storage + } + + /// Begins the building process, optionally initializing with a context and storage. + #[ inline( always ) ] + pub fn begin + ( + storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Context >, + on_end : End + ) -> Self + { + Self + { + storage, + context, + on_end : Some( on_end ), + } + } + + /// Finalizes the building process, returning the formed or a context incorporating it. + #[ inline( always ) ] + pub fn end( mut self ) -> Definition::Formed + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + let storage = self.storage(); + on_end.call( storage, context ) + } + + /// Finalizes the building process, returning the formed or a context incorporating it. + #[ inline( always ) ] + pub fn form( self ) -> Definition::Formed + { + self.end() + } + + /// Replaces the current storage with a provided one, allowing for a reset or redirection of the building process. + #[ inline( always ) ] + pub fn replace( mut self, vector : Definition::Storage ) -> Self + { + self.storage = Some( vector ); + self + } + +} + +impl< E, Definition > ContainerSubformer< E, Definition, (), ReturnFormed > +where + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = E >, + Definition::Storage : StoragePerform< Definition = Definition >, +{ + + /// Initializes a new `ContainerSubformer` instance, starting with an empty formed. + /// This function serves as the entry point for the builder pattern. + /// + /// # Returns + /// A new instance of `ContainerSubformer` with an empty internal formed. + /// + #[ inline( always ) ] + pub fn new() -> Self + { + Self::begin + ( + None, + None, + ReturnFormed, + ) + } + +} + +impl< E, Definition, Context, End > ContainerSubformer< E, Definition, Context, End > +where + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = E >, +{ + + /// Appends an element to the end of the storage, expanding the internal collection. + #[ inline( always ) ] + pub fn push< IntoElement >( mut self, element : IntoElement ) -> Self + where IntoElement : core::convert::Into< E >, + { + if self.storage.is_none() + { + self.storage = core::option::Option::Some( Default::default() ); + } + if let core::option::Option::Some( ref mut storage ) = self.storage + { + ContainerAdd::add( storage, element.into() ); + // storage.push( element.into() ); + } + self + } + +} + +// + +impl< E, Definition, Context, End > FormerBegin< Definition, Context > +for ContainerSubformer< E, Definition, Context, End > +where + End : FormingEnd< Definition, Context >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Element = E >, +{ + type End = End; + + #[ inline( always ) ] + fn _begin + ( + storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Context >, + on_end : End, + ) + -> Self + { + Self::begin( storage, context, on_end ) + } + +} diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index d4f0d278d3..6448031d7f 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -80,10 +80,6 @@ where K : ::core::cmp::Eq + ::core::hash::Hash, { type Definition = HashMapDefinition< K, E >; - // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed - // { - // self - // } } impl< K, E > StoragePerform @@ -135,179 +131,181 @@ where /// # } /// ``` -#[ derive( Debug, Default ) ] -pub struct HashMapSubformer< K, E, Definition, Context, End > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - // Formed : HashMapLike< K, E > + ::core::default::Default, - End : FormingEnd< Definition, Context >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = ( K, E ) >, -{ - storage : ::core::option::Option< Definition::Storage >, - context : ::core::option::Option< Context >, - on_end : ::core::option::Option< End >, - _e_phantom : ::core::marker::PhantomData< E >, - _k_phantom : ::core::marker::PhantomData< K >, -} - -impl< K, E, Definition, Context, End > -HashMapSubformer< K, E, Definition, Context, End > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - // Formed : HashMapLike< K, E > + ::core::default::Default, - End : FormingEnd< Definition, Context >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = ( K, E ) >, -{ - - /// Form current former into target structure. - #[ inline( always ) ] - pub fn storage( mut self ) -> Definition::Storage - { - // xxx - let storage = if self.storage.is_some() - { - self.storage.take().unwrap() - } - else - { - let val = Default::default(); - val - }; - storage - // storage.preform() - } - // xxx - - - /// Make a new HashMapSubformer. It should be called by a context generated for your structure. - /// The context is returned after completion of forming by function `on_end``. - #[ inline( always ) ] - pub fn begin - ( - storage : ::core::option::Option< Definition::Storage >, - context : ::core::option::Option< Context >, - on_end : End, - ) - -> Self - { - Self - { - storage, - context, - on_end : Some( on_end ), - _e_phantom : ::core::marker::PhantomData, - _k_phantom : ::core::marker::PhantomData, - } - } - - /// Return context of your struct moving formed there. Should be called after forming process. - #[ inline( always ) ] - pub fn end( mut self ) -> Definition::Formed - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let storage = self.storage(); - on_end.call( storage, context ) - } - - /// Return context of your struct moving formed there. Should be called after forming process. - #[ inline( always ) ] - pub fn form( self ) -> Definition::Formed - { - self.end() - } - - /// Set the whole storage instead of setting each element individually. - #[ inline( always ) ] - pub fn replace( mut self, storage : Definition::Storage ) -> Self - { - self.storage = Some( storage ); - self - } - -} - -impl< K, E, Definition > -HashMapSubformer< K, E, Definition, (), crate::ReturnFormed > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = ( K, E ) >, - Definition::Storage : StoragePerform< Definition = Definition >, -{ - - /// Create a new instance without context or on end processing. It just returns continaer on end of forming. - #[ inline( always ) ] - pub fn new() -> Self - { - HashMapSubformer::begin - ( - None, - None, - crate::ReturnFormed, - ) - } - -} - -impl< K, E, Definition, Context, End > -HashMapSubformer< K, E, Definition, Context, End > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - // Formed : HashMapLike< K, E > + ::core::default::Default, - End : FormingEnd< Definition, Context >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = ( K, E ) >, -{ - - /// Inserts a key-value pair into the formed. If the formed doesn't exist, it is created. - /// - /// # Parameters - /// - `k`: The key for the value to be inserted. Will be converted into the formed's key type. - /// - `e`: The value to be inserted. Will be converted into the formed's value type. - /// - /// # Returns - /// Returns `self` for chaining further insertions or operations. - /// - #[ inline( always ) ] - pub fn insert< K2, E2 >( mut self, k : K2, e : E2 ) -> Self - where - K2 : ::core::convert::Into< K >, - E2 : ::core::convert::Into< E >, - // Definition::Storage : ContainerAdd< Element = ( K, E ) >, - { - if self.storage.is_none() - { - self.storage = ::core::option::Option::Some( Default::default() ); - } - if let ::core::option::Option::Some( ref mut storage ) = self.storage - { - ContainerAdd::add( storage, ( k.into(), e.into() ) ); - // storage.insert( k.into(), e.into() ); - } - self - } - - /// Alias for insert. - /// - /// # Parameters - /// - `k`: The key for the value to be inserted. Will be converted into the formed's key type. - /// - `e`: The value to be inserted. Will be converted into the formed's value type. - /// - /// # Returns - /// Returns `self` for chaining further insertions or operations. - /// - #[ inline( always ) ] - pub fn push< K2, E2 >( self, k : K2, e : E2 ) -> Self - where - K2 : ::core::convert::Into< K >, - E2 : ::core::convert::Into< E >, - { - self.insert( k, e ) - } - -} +pub type HashMapSubformer< K, E > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E > >; + +// #[ derive( Debug, Default ) ] +// pub struct HashMapSubformer< K, E, Definition, Context, End > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// // Formed : HashMapLike< K, E > + ::core::default::Default, +// End : FormingEnd< Definition, Context >, +// Definition : FormerDefinition, +// Definition::Storage : ContainerAdd< Element = ( K, E ) >, +// { +// storage : ::core::option::Option< Definition::Storage >, +// context : ::core::option::Option< Context >, +// on_end : ::core::option::Option< End >, +// _e_phantom : ::core::marker::PhantomData< E >, +// _k_phantom : ::core::marker::PhantomData< K >, +// } +// +// impl< K, E, Definition, Context, End > +// HashMapSubformer< K, E, Definition, Context, End > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// // Formed : HashMapLike< K, E > + ::core::default::Default, +// End : FormingEnd< Definition, Context >, +// Definition : FormerDefinition, +// Definition::Storage : ContainerAdd< Element = ( K, E ) >, +// { +// +// /// Form current former into target structure. +// #[ inline( always ) ] +// pub fn storage( mut self ) -> Definition::Storage +// { +// // xxx +// let storage = if self.storage.is_some() +// { +// self.storage.take().unwrap() +// } +// else +// { +// let val = Default::default(); +// val +// }; +// storage +// // storage.preform() +// } +// // xxx +// +// +// /// Make a new HashMapSubformer. It should be called by a context generated for your structure. +// /// The context is returned after completion of forming by function `on_end``. +// #[ inline( always ) ] +// pub fn begin +// ( +// storage : ::core::option::Option< Definition::Storage >, +// context : ::core::option::Option< Context >, +// on_end : End, +// ) +// -> Self +// { +// Self +// { +// storage, +// context, +// on_end : Some( on_end ), +// _e_phantom : ::core::marker::PhantomData, +// _k_phantom : ::core::marker::PhantomData, +// } +// } +// +// /// Return context of your struct moving formed there. Should be called after forming process. +// #[ inline( always ) ] +// pub fn end( mut self ) -> Definition::Formed +// { +// let on_end = self.on_end.take().unwrap(); +// let context = self.context.take(); +// let storage = self.storage(); +// on_end.call( storage, context ) +// } +// +// /// Return context of your struct moving formed there. Should be called after forming process. +// #[ inline( always ) ] +// pub fn form( self ) -> Definition::Formed +// { +// self.end() +// } +// +// /// Set the whole storage instead of setting each element individually. +// #[ inline( always ) ] +// pub fn replace( mut self, storage : Definition::Storage ) -> Self +// { +// self.storage = Some( storage ); +// self +// } +// +// } +// +// impl< K, E, Definition > +// HashMapSubformer< K, E, Definition, (), crate::ReturnFormed > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// Definition : FormerDefinition, +// Definition::Storage : ContainerAdd< Element = ( K, E ) >, +// Definition::Storage : StoragePerform< Definition = Definition >, +// { +// +// /// Create a new instance without context or on end processing. It just returns continaer on end of forming. +// #[ inline( always ) ] +// pub fn new() -> Self +// { +// HashMapSubformer::begin +// ( +// None, +// None, +// crate::ReturnFormed, +// ) +// } +// +// } +// +// impl< K, E, Definition, Context, End > +// HashMapSubformer< K, E, Definition, Context, End > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// // Formed : HashMapLike< K, E > + ::core::default::Default, +// End : FormingEnd< Definition, Context >, +// Definition : FormerDefinition, +// Definition::Storage : ContainerAdd< Element = ( K, E ) >, +// { +// +// /// Inserts a key-value pair into the formed. If the formed doesn't exist, it is created. +// /// +// /// # Parameters +// /// - `k`: The key for the value to be inserted. Will be converted into the formed's key type. +// /// - `e`: The value to be inserted. Will be converted into the formed's value type. +// /// +// /// # Returns +// /// Returns `self` for chaining further insertions or operations. +// /// +// #[ inline( always ) ] +// pub fn insert< K2, E2 >( mut self, k : K2, e : E2 ) -> Self +// where +// K2 : ::core::convert::Into< K >, +// E2 : ::core::convert::Into< E >, +// // Definition::Storage : ContainerAdd< Element = ( K, E ) >, +// { +// if self.storage.is_none() +// { +// self.storage = ::core::option::Option::Some( Default::default() ); +// } +// if let ::core::option::Option::Some( ref mut storage ) = self.storage +// { +// ContainerAdd::add( storage, ( k.into(), e.into() ) ); +// // storage.insert( k.into(), e.into() ); +// } +// self +// } +// +// /// Alias for insert. +// /// +// /// # Parameters +// /// - `k`: The key for the value to be inserted. Will be converted into the formed's key type. +// /// - `e`: The value to be inserted. Will be converted into the formed's value type. +// /// +// /// # Returns +// /// Returns `self` for chaining further insertions or operations. +// /// +// #[ inline( always ) ] +// pub fn push< K2, E2 >( self, k : K2, e : E2 ) -> Self +// where +// K2 : ::core::convert::Into< K >, +// E2 : ::core::convert::Into< E >, +// { +// self.insert( k, e ) +// } +// +// } // diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 0959953156..8c4cdb62f3 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -117,198 +117,200 @@ where /// # } /// ``` -#[ derive( Debug, Default ) ] -pub struct HashSetSubformer< K, Definition, Context, End > -where - K : core::cmp::Eq + core::hash::Hash, - // Formed : HashSetLike< K > + core::default::Default, - End : FormingEnd< Definition, Context >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = K >, -{ - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Context >, - on_end : core::option::Option< End >, - _e_phantom : core::marker::PhantomData< K >, -} - -impl< K, Definition, Context, End > -HashSetSubformer< K, Definition, Context, End > -where - K : core::cmp::Eq + core::hash::Hash, - // Formed : HashSetLike< K > + core::default::Default, - End : FormingEnd< Definition, Context >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = K >, -{ - - /// Form current former into target structure. - #[ inline( always ) ] - pub fn storage( mut self ) -> Definition::Storage - { - let storage = if self.storage.is_some() - { - self.storage.take().unwrap() - } - else - { - let val = Default::default(); - val - }; - storage - } - // xxx - - /// Begins the building process with an optional context and storage. - /// - /// This method is typically called internally by the builder but can be used directly - /// to initialize the builder with specific contexts or containers. - /// - /// # Parameters - /// - `context`: An optional context for the building process. - /// - `storage`: An optional initial storage to populate. - /// - `on_end`: A handler to be called at the end of the building process. - /// - #[ inline( always ) ] - pub fn begin - ( - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Context >, - on_end : End, - ) -> Self - { - Self - { - storage, - context : context, - on_end : Some( on_end ), - _e_phantom : core::marker::PhantomData, - } - } - - /// Finalizes the building process and returns the constructed formed or a context. - /// - /// This method concludes the building process by applying the `on_end` handler to transform - /// the formed or incorporate it into a given context. It's typically called at the end - /// of the builder chain to retrieve the final product of the building process. - /// - /// # Returns - /// Depending on the `on_end` handler's implementation, this method can return either the - /// constructed formed or a context that incorporates the formed. - /// - #[ inline( always ) ] - pub fn form( self ) -> Definition::Formed - { - self.end() - } - - /// Finalizes the building process and returns the constructed formed or a context. - /// - /// This method concludes the building process by applying the `on_end` handler to transform - /// the formed or incorporate it into a given context. It's typically called at the end - /// of the builder chain to retrieve the final product of the building process. - /// - /// # Returns - /// Depending on the `on_end` handler's implementation, this method can return either the - /// constructed formed or a context that incorporates the formed. - /// - #[ inline( always ) ] - pub fn end( mut self ) -> Definition::Formed - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let storage = self.storage(); - on_end.call( storage, context ) - } - - /// Replaces the current storage with a new one. - /// - /// This method allows for replacing the entire set being built with a different one. - /// It can be useful in scenarios where a pre-populated set needs to be modified or - /// replaced entirely during the building process. - /// - /// # Parameters - /// - `storage`: The new storage to use for subsequent builder operations. - /// - /// # Returns - /// The builder instance with the storage replaced, enabling further chained operations. - /// - #[ inline( always ) ] - pub fn replace( mut self, storage : Definition::Storage ) -> Self - { - self.storage = Some( storage ); - self - } - -} - -impl< K, Definition > -HashSetSubformer< K, Definition, (), crate::ReturnFormed > -where - K : core::cmp::Eq + core::hash::Hash, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = K >, - Definition::Storage : StoragePerform< Definition = Definition >, -{ - - /// Initializes a new instance of the builder with default settings. - /// - /// This method provides a starting point for forming a `HashSetLike` using - /// a fluent interface. - /// - /// # Returns - /// A new instance of `HashSetSubformer` with no elements. - /// - #[ inline( always ) ] - pub fn new() -> Self - { - HashSetSubformer::begin - ( - None, - None, - crate::ReturnFormed, - ) - } - -} - -impl< K, Definition, Context, End > -HashSetSubformer< K, Definition, Context, End > -where - K : core::cmp::Eq + core::hash::Hash, - End : FormingEnd< Definition, Context >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = K >, -{ - - /// Inserts an element into the set, possibly replacing an existing element. - /// - /// This method ensures that the set contains the given element, and if the element - /// was already present, it might replace it depending on the storage's behavior. - /// - /// # Parameters - /// - `element`: The element to insert into the set. - /// - /// # Returns - /// - `Some(element)` if the element was replaced. - /// - `None` if the element was newly inserted without replacing any existing element. - /// - #[ inline( always ) ] - pub fn insert< E2 >( mut self, element : E2 ) -> Self - where - E2 : core::convert::Into< K >, - { - if self.storage.is_none() - { - self.storage = core::option::Option::Some( Default::default() ); - } - if let core::option::Option::Some( ref mut storage ) = self.storage - { - ContainerAdd::add( storage, element.into() ); - } - self - } +pub type VectorSubformer< K > = ContainerSubformer::< K, HashSetDefinition< K > >; -} +// #[ derive( Debug, Default ) ] +// pub struct HashSetSubformer< K, Definition, Context, End > +// where +// K : core::cmp::Eq + core::hash::Hash, +// // Formed : HashSetLike< K > + core::default::Default, +// End : FormingEnd< Definition, Context >, +// Definition : FormerDefinition, +// Definition::Storage : ContainerAdd< Element = K >, +// { +// storage : core::option::Option< Definition::Storage >, +// context : core::option::Option< Context >, +// on_end : core::option::Option< End >, +// _e_phantom : core::marker::PhantomData< K >, +// } +// +// impl< K, Definition, Context, End > +// HashSetSubformer< K, Definition, Context, End > +// where +// K : core::cmp::Eq + core::hash::Hash, +// // Formed : HashSetLike< K > + core::default::Default, +// End : FormingEnd< Definition, Context >, +// Definition : FormerDefinition, +// Definition::Storage : ContainerAdd< Element = K >, +// { +// +// /// Form current former into target structure. +// #[ inline( always ) ] +// pub fn storage( mut self ) -> Definition::Storage +// { +// let storage = if self.storage.is_some() +// { +// self.storage.take().unwrap() +// } +// else +// { +// let val = Default::default(); +// val +// }; +// storage +// } +// // xxx +// +// /// Begins the building process with an optional context and storage. +// /// +// /// This method is typically called internally by the builder but can be used directly +// /// to initialize the builder with specific contexts or containers. +// /// +// /// # Parameters +// /// - `context`: An optional context for the building process. +// /// - `storage`: An optional initial storage to populate. +// /// - `on_end`: A handler to be called at the end of the building process. +// /// +// #[ inline( always ) ] +// pub fn begin +// ( +// storage : core::option::Option< Definition::Storage >, +// context : core::option::Option< Context >, +// on_end : End, +// ) -> Self +// { +// Self +// { +// storage, +// context : context, +// on_end : Some( on_end ), +// _e_phantom : core::marker::PhantomData, +// } +// } +// +// /// Finalizes the building process and returns the constructed formed or a context. +// /// +// /// This method concludes the building process by applying the `on_end` handler to transform +// /// the formed or incorporate it into a given context. It's typically called at the end +// /// of the builder chain to retrieve the final product of the building process. +// /// +// /// # Returns +// /// Depending on the `on_end` handler's implementation, this method can return either the +// /// constructed formed or a context that incorporates the formed. +// /// +// #[ inline( always ) ] +// pub fn form( self ) -> Definition::Formed +// { +// self.end() +// } +// +// /// Finalizes the building process and returns the constructed formed or a context. +// /// +// /// This method concludes the building process by applying the `on_end` handler to transform +// /// the formed or incorporate it into a given context. It's typically called at the end +// /// of the builder chain to retrieve the final product of the building process. +// /// +// /// # Returns +// /// Depending on the `on_end` handler's implementation, this method can return either the +// /// constructed formed or a context that incorporates the formed. +// /// +// #[ inline( always ) ] +// pub fn end( mut self ) -> Definition::Formed +// { +// let on_end = self.on_end.take().unwrap(); +// let context = self.context.take(); +// let storage = self.storage(); +// on_end.call( storage, context ) +// } +// +// /// Replaces the current storage with a new one. +// /// +// /// This method allows for replacing the entire set being built with a different one. +// /// It can be useful in scenarios where a pre-populated set needs to be modified or +// /// replaced entirely during the building process. +// /// +// /// # Parameters +// /// - `storage`: The new storage to use for subsequent builder operations. +// /// +// /// # Returns +// /// The builder instance with the storage replaced, enabling further chained operations. +// /// +// #[ inline( always ) ] +// pub fn replace( mut self, storage : Definition::Storage ) -> Self +// { +// self.storage = Some( storage ); +// self +// } +// +// } +// +// impl< K, Definition > +// HashSetSubformer< K, Definition, (), crate::ReturnFormed > +// where +// K : core::cmp::Eq + core::hash::Hash, +// Definition : FormerDefinition, +// Definition::Storage : ContainerAdd< Element = K >, +// Definition::Storage : StoragePerform< Definition = Definition >, +// { +// +// /// Initializes a new instance of the builder with default settings. +// /// +// /// This method provides a starting point for forming a `HashSetLike` using +// /// a fluent interface. +// /// +// /// # Returns +// /// A new instance of `HashSetSubformer` with no elements. +// /// +// #[ inline( always ) ] +// pub fn new() -> Self +// { +// HashSetSubformer::begin +// ( +// None, +// None, +// crate::ReturnFormed, +// ) +// } +// +// } +// +// impl< K, Definition, Context, End > +// HashSetSubformer< K, Definition, Context, End > +// where +// K : core::cmp::Eq + core::hash::Hash, +// End : FormingEnd< Definition, Context >, +// Definition : FormerDefinition, +// Definition::Storage : ContainerAdd< Element = K >, +// { +// +// /// Inserts an element into the set, possibly replacing an existing element. +// /// +// /// This method ensures that the set contains the given element, and if the element +// /// was already present, it might replace it depending on the storage's behavior. +// /// +// /// # Parameters +// /// - `element`: The element to insert into the set. +// /// +// /// # Returns +// /// - `Some(element)` if the element was replaced. +// /// - `None` if the element was newly inserted without replacing any existing element. +// /// +// #[ inline( always ) ] +// pub fn insert< E2 >( mut self, element : E2 ) -> Self +// where +// E2 : core::convert::Into< K >, +// { +// if self.storage.is_none() +// { +// self.storage = core::option::Option::Some( Default::default() ); +// } +// if let core::option::Option::Some( ref mut storage ) = self.storage +// { +// ContainerAdd::add( storage, element.into() ); +// } +// self +// } +// +// } // \ No newline at end of file diff --git a/module/core/former/src/lib.rs b/module/core/former/src/lib.rs index 978805cca1..4834d7a293 100644 --- a/module/core/former/src/lib.rs +++ b/module/core/former/src/lib.rs @@ -9,7 +9,6 @@ /// Axiomatic things. #[ cfg( feature = "enabled" ) ] #[ cfg( feature = "derive_former" ) ] -#[ path = "axiomatic3.rs" ] mod axiomatic; /// Interface for containers. @@ -21,7 +20,6 @@ mod container; #[ cfg( feature = "enabled" ) ] #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] #[ cfg( feature = "derive_former" ) ] -#[ path = "vector3.rs" ] mod vector; /// Former of a hash map. #[ cfg( feature = "enabled" ) ] diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 46426d8733..c7e2099e0a 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -1,4 +1,5 @@ use super::*; +use axiomatic::*; #[ allow( unused ) ] use collection_tools::Vec; @@ -10,7 +11,7 @@ use collection_tools::Vec; /// pub trait VectorLike< E > { - /// Appends an element to the back of a formed. + /// Appends an element to the back of a storage. fn push( &mut self, element : E ); } @@ -22,186 +23,201 @@ impl< E > VectorLike< E > for Vec< E > } } -/// 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. -/// -/// # Example -/// ```rust -/// #[ derive( Debug, PartialEq, former::Former ) ] -/// pub struct StructWithVec -/// { -/// #[ subformer( former::VectorSubformer ) ] -/// vec : Vec< &'static str >, -/// } -/// -/// let instance = StructWithVec::former() -/// .vec() -/// .push( "apple" ) -/// .push( "banana" ) -/// .end() -/// .form(); -/// -/// assert_eq!( instance, StructWithVec { vec: vec![ "apple", "banana" ] } ); -///``` -/// -#[ derive( Debug, Default ) ] -pub struct VectorSubformer< E, Formed, Context, ContainerEnd > -where - Formed : VectorLike< E > + core::default::Default, - ContainerEnd : FormingEnd< Formed, Context >, +#[ derive( Debug ) ] +pub struct VectorDefinition< E > { - formed : core::option::Option< Formed >, - context : core::option::Option< Context >, - on_end : core::option::Option< ContainerEnd >, _phantom : core::marker::PhantomData< E >, } -impl< E, Formed, Context, ContainerEnd > VectorSubformer< E, Formed, Context, ContainerEnd > -where - Formed : VectorLike< E > + core::default::Default, - ContainerEnd : FormingEnd< Formed, Context >, +impl< E > VectorDefinition< E > { - - /// Form current former into target structure. - #[ inline( always ) ] - pub fn form( mut self ) -> Formed - { - let formed = if self.formed.is_some() - { - self.formed.take().unwrap() - } - else - { - let val = Default::default(); - val - }; - formed - } - - // /// Initializes a new `VectorSubformer` instance, starting with an empty formed. - // /// This function serves as the entry point for the builder pattern. - // /// - // /// # Returns - // /// A new instance of `VectorSubformer` with an empty internal formed. - // /// - // #[ inline( always ) ] - // pub fn new() -> VectorSubformer< E, Formed, Formed, impl FormingEnd< Formed, Formed > > - // { - // VectorSubformer::begin - // ( - // None, - // None, - // crate::ReturnFormed, - // ) - // } - - /// Begins the building process, optionally initializing with a context and formed. - #[ inline( always ) ] - pub fn begin - ( - formed : core::option::Option< Formed >, - context : core::option::Option< Context >, - on_end : ContainerEnd - ) -> Self - { - Self - { - context, - formed, - on_end : Some( on_end ), - _phantom : core::marker::PhantomData, - } - } - - /// Finalizes the building process, returning the formed or a context incorporating it. - #[ inline( always ) ] - pub fn end( mut self ) -> Context - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) - } - - /// Replaces the current formed with a provided one, allowing for a reset or redirection of the building process. - #[ inline( always ) ] - pub fn replace( mut self, vector : Formed ) -> Self + pub fn new() -> Self { - self.formed = Some( vector ); - self + Self { _phantom : core::marker::PhantomData } } - } -impl< E, Formed > VectorSubformer< E, Formed, Formed, crate::ReturnFormed > -where - Formed : VectorLike< E > + core::default::Default, +impl< E > FormerDefinition +for VectorDefinition< E > { - - /// Initializes a new `VectorSubformer` instance, starting with an empty formed. - /// This function serves as the entry point for the builder pattern. - /// - /// # Returns - /// A new instance of `VectorSubformer` with an empty internal formed. - /// - #[ inline( always ) ] - pub fn new() -> Self - { - Self::begin - ( - None, - None, - crate::ReturnFormed, - ) - } - + type Storage = Vec< E >; + type Formed = Vec< E >; } -impl< E, Formed, Context, ContainerEnd > VectorSubformer< E, Formed, Context, ContainerEnd > -where - Formed : VectorLike< E > + core::default::Default, - ContainerEnd : FormingEnd< Formed, Context >, +impl< E > Storage +for Vec< E > { + type Definition = VectorDefinition< E >; +} - /// Appends an element to the end of the formed, expanding the internal collection. - #[ inline( always ) ] - pub fn push< E2 >( mut self, element : E2 ) -> Self - where E2 : core::convert::Into< E >, +impl< E > StoragePerform +for Vec< E > +{ + fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed { - if self.formed.is_none() - { - self.formed = core::option::Option::Some( Default::default() ); - } - if let core::option::Option::Some( ref mut formed ) = self.formed - { - formed.push( element.into() ); - } self } - } -// - -impl< E, Formed, Context, End > FormerBegin< Formed, Formed, Context > -for VectorSubformer< E, Formed, Context, End > -where - End : FormingEnd< Formed, Context >, - Formed : VectorLike< E > + Default, -{ - type End = End; - - #[ inline( always ) ] - fn _begin - ( - formed : core::option::Option< Formed >, - context : core::option::Option< Context >, - on_end : End, - ) -> Self - { - Self::begin( formed, context, on_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 > = ContainerSubformer::< E, VectorDefinition< E > >; + +// #[ derive( Debug, Default ) ] +// pub struct VectorSubformer< E, Definition, Context, End > +// where +// End : FormingEnd< Definition, Context >, +// Definition : FormerDefinition, +// Definition::Storage : ContainerAdd< Element = E >, +// { +// storage : core::option::Option< Definition::Storage >, +// context : core::option::Option< Context >, +// on_end : core::option::Option< End >, +// } +// +// impl< E, Definition, Context, End > VectorSubformer< E, Definition, Context, End > +// where +// End : FormingEnd< Definition, Context >, +// Definition : FormerDefinition, +// Definition::Storage : ContainerAdd< Element = E >, +// { +// +// /// Form current former into target structure. +// #[ inline( always ) ] +// pub fn storage( mut self ) -> Definition::Storage +// { +// let storage = if self.storage.is_some() +// { +// self.storage.take().unwrap() +// } +// else +// { +// let val = Default::default(); +// val +// }; +// storage +// } +// +// /// Begins the building process, optionally initializing with a context and storage. +// #[ inline( always ) ] +// pub fn begin +// ( +// storage : core::option::Option< Definition::Storage >, +// context : core::option::Option< Context >, +// on_end : End +// ) -> Self +// { +// Self +// { +// storage, +// context, +// on_end : Some( on_end ), +// } +// } +// +// /// Finalizes the building process, returning the formed or a context incorporating it. +// #[ inline( always ) ] +// pub fn form( self ) -> Definition::Formed +// { +// self.end() +// } +// +// /// Finalizes the building process, returning the formed or a context incorporating it. +// #[ inline( always ) ] +// pub fn end( mut self ) -> Definition::Formed +// { +// let on_end = self.on_end.take().unwrap(); +// let context = self.context.take(); +// let storage = self.storage(); +// on_end.call( storage, context ) +// } +// +// /// Replaces the current storage with a provided one, allowing for a reset or redirection of the building process. +// #[ inline( always ) ] +// pub fn replace( mut self, vector : Definition::Storage ) -> Self +// { +// self.storage = Some( vector ); +// self +// } +// +// } +// +// impl< E, Definition > VectorSubformer< E, Definition, (), ReturnFormed > +// where +// Definition : FormerDefinition, +// Definition::Storage : ContainerAdd< Element = E >, +// Definition::Storage : StoragePerform< Definition = Definition >, +// { +// +// /// Initializes a new `VectorSubformer` instance, starting with an empty formed. +// /// This function serves as the entry point for the builder pattern. +// /// +// /// # Returns +// /// A new instance of `VectorSubformer` with an empty internal formed. +// /// +// #[ inline( always ) ] +// pub fn new() -> Self +// { +// Self::begin +// ( +// None, +// None, +// ReturnFormed, +// ) +// } +// +// } +// +// impl< E, Definition, Context, End > VectorSubformer< E, Definition, Context, End > +// where +// End : FormingEnd< Definition, Context >, +// Definition : FormerDefinition, +// Definition::Storage : ContainerAdd< Element = E >, +// { +// +// /// Appends an element to the end of the storage, expanding the internal collection. +// #[ inline( always ) ] +// pub fn push< IntoElement >( mut self, element : IntoElement ) -> Self +// where IntoElement : core::convert::Into< E >, +// { +// if self.storage.is_none() +// { +// self.storage = core::option::Option::Some( Default::default() ); +// } +// if let core::option::Option::Some( ref mut storage ) = self.storage +// { +// ContainerAdd::add( storage, element.into() ); +// // storage.push( element.into() ); +// } +// self +// } +// +// } +// +// // +// +// impl< E, Definition, Context, End > FormerBegin< Definition, Context > +// for VectorSubformer< E, Definition, Context, End > +// where +// End : FormingEnd< Definition, Context >, +// Definition : FormerDefinition, +// Definition::Storage : ContainerAdd< Element = E >, +// { +// type End = End; +// +// #[ inline( always ) ] +// fn _begin +// ( +// storage : core::option::Option< Definition::Storage >, +// context : core::option::Option< Context >, +// on_end : End, +// ) +// -> Self +// { +// Self::begin( storage, context, on_end ) +// } +// +// } diff --git a/module/core/former/src/vector3.rs b/module/core/former/src/vector3.rs deleted file mode 100644 index 51730a9ee9..0000000000 --- a/module/core/former/src/vector3.rs +++ /dev/null @@ -1,221 +0,0 @@ -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 ); - } -} - -#[ 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 > -{ - type Definition = VectorDefinition< E >; -} - -impl< E > StoragePerform -for Vec< E > -{ - // type Definition = VectorDefinition< E >; - fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed - { - self - } -} - -/// 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. -#[ derive( Debug, Default ) ] -pub struct VectorSubformer< E, Definition, Context, End > -where - End : FormingEnd< Definition, Context >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, -{ - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Context >, - on_end : core::option::Option< End >, -} - -impl< E, Definition, Context, End > VectorSubformer< E, Definition, Context, End > -where - End : FormingEnd< Definition, Context >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, -{ - - /// Form current former into target structure. - #[ inline( always ) ] - pub fn storage( mut self ) -> Definition::Storage - { - let storage = if self.storage.is_some() - { - self.storage.take().unwrap() - } - else - { - let val = Default::default(); - val - }; - storage - } - - /// Begins the building process, optionally initializing with a context and storage. - #[ inline( always ) ] - pub fn begin - ( - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Context >, - on_end : End - ) -> Self - { - Self - { - storage, - context, - on_end : Some( on_end ), - } - } - - /// Finalizes the building process, returning the formed or a context incorporating it. - #[ inline( always ) ] - pub fn form( self ) -> Definition::Formed - { - self.end() - } - - /// Finalizes the building process, returning the formed or a context incorporating it. - #[ inline( always ) ] - pub fn end( mut self ) -> Definition::Formed - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let storage = self.storage(); - on_end.call( storage, context ) - } - - /// Replaces the current storage with a provided one, allowing for a reset or redirection of the building process. - #[ inline( always ) ] - pub fn replace( mut self, vector : Definition::Storage ) -> Self - { - self.storage = Some( vector ); - self - } - -} - -impl< E, Definition > VectorSubformer< E, Definition, (), ReturnFormed > -where - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, - Definition::Storage : StoragePerform< Definition = Definition >, -{ - - /// Initializes a new `VectorSubformer` instance, starting with an empty formed. - /// This function serves as the entry point for the builder pattern. - /// - /// # Returns - /// A new instance of `VectorSubformer` with an empty internal formed. - /// - #[ inline( always ) ] - pub fn new() -> Self - { - Self::begin - ( - None, - None, - ReturnFormed, - ) - } - -} - -impl< E, Definition, Context, End > VectorSubformer< E, Definition, Context, End > -where - End : FormingEnd< Definition, Context >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, -{ - - /// Appends an element to the end of the storage, expanding the internal collection. - #[ inline( always ) ] - pub fn push< IntoElement >( mut self, element : IntoElement ) -> Self - where IntoElement : core::convert::Into< E >, - { - if self.storage.is_none() - { - self.storage = core::option::Option::Some( Default::default() ); - } - if let core::option::Option::Some( ref mut storage ) = self.storage - { - ContainerAdd::add( storage, element.into() ); - // storage.push( element.into() ); - } - self - } - -} - -// - -impl< E, Definition, Context, End > FormerBegin< Definition, Context > -for VectorSubformer< E, Definition, Context, End > -where - End : FormingEnd< Definition, Context >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, -{ - type End = End; - - #[ inline( always ) ] - fn _begin - ( - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Context >, - on_end : End, - ) - -> Self - { - Self::begin( storage, context, on_end ) - } - -} diff --git a/module/core/former/tests/inc/former_tests/subformer_hashmap.rs b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs similarity index 100% rename from module/core/former/tests/inc/former_tests/subformer_hashmap.rs rename to module/core/former/tests/inc/former_tests/container_former_hashmap.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs similarity index 100% rename from module/core/former/tests/inc/former_tests/subformer_hashset.rs rename to module/core/former/tests/inc/former_tests/container_former_hashset.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_vec.rs b/module/core/former/tests/inc/former_tests/container_former_vec.rs similarity index 52% rename from module/core/former/tests/inc/former_tests/subformer_vec.rs rename to module/core/former/tests/inc/former_tests/container_former_vec.rs index 7a7244fece..3eccc1475f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_vec.rs +++ b/module/core/former/tests/inc/former_tests/container_former_vec.rs @@ -8,9 +8,7 @@ use collection_tools::Vec; fn push() { - // - - let got : Vec< String > = the_module::VectorSubformer::new() + let got : Vec< String > = the_module::ContainerSubformer::< String, former::VectorDefinition< String > >::new() .push( "a" ) .push( "b" ) .form(); @@ -21,15 +19,11 @@ fn push() ]; a_id!( got, exp ); -} - -#[ test ] -fn replace() -{ + // let got : Vec< String > = the_module::VectorSubformer::new() - .push( "x" ) - .replace( vec![ "a".to_string(), "b".to_string() ] ) + .push( "a" ) + .push( "b" ) .form(); let exp = vec! [ @@ -39,3 +33,20 @@ fn replace() a_id!( got, exp ); } + +#[ test ] +fn replace() +{ + + // let got : Vec< String > = the_module::VectorSubformer::new() + // .push( "x" ) + // .replace( vec![ "a".to_string(), "b".to_string() ] ) + // .form(); + // let exp = vec! + // [ + // "a".to_string(), + // "b".to_string(), + // ]; + // a_id!( got, exp ); + +} diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 21d986470d..d418d95951 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -7,8 +7,15 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; - mod a_primitives_manual; - mod a_primitives; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_vec; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod container_former_hashset; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod container_former_hashmap; + + // mod a_primitives_manual; + // mod a_primitives; // mod a_primitives_expanded; // mod a_containers_without_runtime_manual; // mod a_containers_without_runtime; @@ -48,13 +55,6 @@ mod former_tests // mod subformer_basic_manual; // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_vec; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_hashset; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_hashmap; -// // // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_shortcut; From e1f026af43dba94fb75772a771ecefc3d3dcac49 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 20:07:57 +0200 Subject: [PATCH 015/533] former : experimenting --- module/core/former/src/axiomatic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 1587a215ab..54fbe0698c 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -14,9 +14,9 @@ pub trait StoragePerform : Storage /// xxx pub trait FormerDefinition { - // type Storage : StoragePerform< Definition = Self >; type Storage : Storage< Definition = Self >; type Formed; + // type Contex; } // pub trait FormerDefinition From 1561c88cf19794a4124281e7affe9c1d2cdae0e1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 20:32:28 +0200 Subject: [PATCH 016/533] former : experimenting --- module/core/former/src/axiomatic.rs | 16 +++++++++------- module/core/former/src/container.rs | 2 +- module/core/former/src/hash_map.rs | 6 ++++-- module/core/former/src/hash_set.rs | 12 +++++------- module/core/former/src/vector.rs | 6 ++++-- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 54fbe0698c..5eeb20c3b6 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -2,21 +2,24 @@ pub trait Storage : ::core::default::Default { - type Definition : FormerDefinition< Storage = Self >; + // type Definition : FormerDefinition< Storage = Self >; + type Formed; } /// xxx pub trait StoragePerform : Storage { - fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed; + // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed; + fn preform( self ) -> Self::Formed; } /// xxx pub trait FormerDefinition { - type Storage : Storage< Definition = Self >; + // type Storage : Storage< Definition = Self >; + type Storage : Storage< Formed = Self::Formed >; type Formed; - // type Contex; + // type Context; } // pub trait FormerDefinition @@ -70,9 +73,8 @@ pub struct ReturnFormed; impl< Definition : FormerDefinition > FormingEnd< Definition, () > for ReturnFormed where - Definition::Storage : StoragePerform< Definition = Definition >, - // xxx : rename Former -> Definition - // xxx : rename Definition -> Definition + // Definition::Storage : StoragePerform< Definition = Definition >, + Definition::Storage : StoragePerform< Formed = Definition::Formed >, { #[ inline( always ) ] fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index e68732dfa6..3da836f5d7 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -278,7 +278,7 @@ impl< E, Definition > ContainerSubformer< E, Definition, (), ReturnFormed > where Definition : FormerDefinition, Definition::Storage : ContainerAdd< Element = E >, - Definition::Storage : StoragePerform< Definition = Definition >, + Definition::Storage : StoragePerform< Formed = Definition::Formed >, { /// Initializes a new `ContainerSubformer` instance, starting with an empty formed. diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 6448031d7f..484b1fde3d 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -79,7 +79,8 @@ for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Definition = HashMapDefinition< K, E >; + // type Definition = HashMapDefinition< K, E >; + type Formed = HashMap< K, E >; } impl< K, E > StoragePerform @@ -87,7 +88,8 @@ for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed + // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed + fn preform( self ) -> Self::Formed { self } diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 8c4cdb62f3..66ef30e701 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -58,11 +58,8 @@ for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Definition = HashSetDefinition< K >; - // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed - // { - // self - // } + // type Definition = HashSetDefinition< K >; + type Formed = HashSet< K >; } impl< K > StoragePerform @@ -70,7 +67,8 @@ for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed + // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed + fn preform( self ) -> Self::Formed { self } @@ -117,7 +115,7 @@ where /// # } /// ``` -pub type VectorSubformer< K > = ContainerSubformer::< K, HashSetDefinition< K > >; +pub type HashSetSubformer< K > = ContainerSubformer::< K, HashSetDefinition< K > >; // #[ 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 c7e2099e0a..4b056695eb 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -47,13 +47,15 @@ for VectorDefinition< E > impl< E > Storage for Vec< E > { - type Definition = VectorDefinition< 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 as Storage >::Definition as FormerDefinition >::Formed + fn preform( self ) -> Self::Formed { self } From 750074ece317d644e1c57fe59c15a0ffea65e7a5 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 20:52:24 +0200 Subject: [PATCH 017/533] former : experimenting --- module/core/former/src/axiomatic.rs | 2 +- module/core/former/src/hash_map.rs | 47 ++++++++++--------- module/core/former/src/hash_set.rs | 39 ++++++++------- module/core/former/src/vector.rs | 47 ++++++++++--------- .../inc/former_tests/container_former_vec.rs | 15 +++++- 5 files changed, 87 insertions(+), 63 deletions(-) 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(); From 8432e7e03d014fcfaeaa04409b2c8b5a80abe021 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 21:01:32 +0200 Subject: [PATCH 018/533] former : experimenting --- module/core/former/src/axiomatic.rs | 67 +++++++++-------------------- module/core/former/src/container.rs | 29 ++++++------- 2 files changed, 35 insertions(+), 61 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index e1e24dfe2e..084ce87db4 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -39,7 +39,7 @@ pub trait FormerDefinition /// # Parameters /// - `Storage`: The type of the container being processed. /// - `Context`: The type of the context that might be altered or returned upon completion. -pub trait FormingEnd< Definition : FormerDefinition, Context > +pub trait FormingEnd< Definition : FormerDefinition > { /// Called at the end of the subforming process to return the modified or original context. /// @@ -49,15 +49,16 @@ pub trait FormingEnd< Definition : FormerDefinition, Context > /// /// # Returns /// Returns the transformed or original context based on the implementation. - fn call( &self, storage : Definition::Storage, context : core::option::Option< Context > ) -> Definition::Formed; + fn call( &self, storage : Definition::Storage, context : core::option::Option< Definition::Context > ) -> Definition::Formed; } -impl< Definition : FormerDefinition, Context, F > FormingEnd< Definition, Context > for F +impl< Definition, F > FormingEnd< Definition > for F where - F : Fn( Definition::Storage, core::option::Option< Context > ) -> Definition::Formed, + F : Fn( Definition::Storage, core::option::Option< Definition::Context > ) -> Definition::Formed, + Definition : FormerDefinition, { #[ inline( always ) ] - fn call( &self, storage : Definition::Storage, context : core::option::Option< Context > ) -> Definition::Formed + fn call( &self, storage : Definition::Storage, context : core::option::Option< Definition::Context > ) -> Definition::Formed { self( storage, context ) } @@ -70,11 +71,12 @@ where #[ derive( Debug, Default ) ] pub struct ReturnFormed; -impl< Definition : FormerDefinition > FormingEnd< Definition, () > +impl< Definition > FormingEnd< Definition > for ReturnFormed where // Definition::Storage : StoragePerform< Definition = Definition >, Definition::Storage : StoragePerform< Formed = Definition::Formed >, + Definition : FormerDefinition< Context = () >, { #[ inline( always ) ] fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed @@ -89,22 +91,15 @@ where /// `FormingEnd` trait's `call` method signature. It is useful for cases where /// a closure needs to be stored or passed around as an object implementing /// `FormingEnd`. -/// -/// # Type Parameters -/// -/// * `Storage` - The type of the container being processed. This type is passed to the closure -/// when it's called. -/// * `Context` - The type of the context that may be altered or returned by the closure. -/// This allows for flexible manipulation of context based on the container. #[ cfg( not( feature = "no_std" ) ) ] -pub struct FormingEndWrapper< Definition : FormerDefinition, Context > +pub struct FormingEndWrapper< Definition : FormerDefinition > { - closure : Box< dyn Fn( Definition::Storage, Option< Context > ) -> Definition::Formed >, + closure : Box< dyn Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed >, _marker : std::marker::PhantomData< Definition::Storage >, } #[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinition, Context > FormingEndWrapper< Definition, Context > +impl< Definition : FormerDefinition > FormingEndWrapper< Definition > { /// Constructs a new `FormingEndWrapper` with the provided closure. /// @@ -117,7 +112,7 @@ impl< Definition : FormerDefinition, Context > FormingEndWrapper< Definition, Co /// # Returns /// /// Returns an instance of `FormingEndWrapper` encapsulating the provided closure. - pub fn new( closure : impl Fn( Definition::Storage, Option< Context > ) -> Definition::Formed + 'static ) -> Self + pub fn new( closure : impl Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed + 'static ) -> Self { Self { @@ -130,7 +125,7 @@ impl< Definition : FormerDefinition, Context > FormingEndWrapper< Definition, Co #[ cfg( not( feature = "no_std" ) ) ] use std::fmt; #[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinition, Context > fmt::Debug for FormingEndWrapper< Definition, Context > +impl< Definition : FormerDefinition > fmt::Debug for FormingEndWrapper< Definition > { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { @@ -142,10 +137,10 @@ impl< Definition : FormerDefinition, Context > fmt::Debug for FormingEndWrapper< } #[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinition, Context > FormingEnd< Definition, Context > -for FormingEndWrapper< Definition, Context > +impl< Definition : FormerDefinition > FormingEnd< Definition > +for FormingEndWrapper< Definition > { - fn call( &self, storage : Definition::Storage, context : Option< Context > ) -> Definition::Formed + fn call( &self, storage : Definition::Storage, context : Option< Definition::Context > ) -> Definition::Formed { ( self.closure )( storage, context ) } @@ -161,40 +156,20 @@ for FormingEndWrapper< Definition, Context > /// process benefits from maintaining both transient state (`Storage`) and contextual information (`Context`), /// before concluding with the generation of a final product (`Formed`). /// -/// # Type Parameters -/// -/// * `Storage` - Represents a mutable intermediary storage structure used throughout the subforming process -/// to accumulate data, state, or partial computations. This storage is internal to the -/// subformer and is eventually converted into the final `Formed` structure by the subformer, -/// not directly by implementations of this trait. -/// -/// * `Formed` - Denotes the final type that results from the subforming process. This is the intended outcome -/// of the builder chain, constructed or transformed from the `Storage` with consideration of -/// the provided `Context`. -/// -/// * `Context` - Specifies the contextual backdrop against which the subforming process unfolds. This could -/// encompass references to parent builders, configuration data, or any state influencing how -/// `Storage` transitions into `Formed`. -/// -/// # Functions -/// -/// * `_begin` - This function launches the subforming process, marking the start of a construction or transformation -/// sequence defined by the implementing type. It establishes the foundational `Storage` and `Context`, -/// alongside specifying an `on_end` completion handler that dictates the final conversion into `Formed`. -/// /// The `FormerBegin` trait, by decoupling `Storage` from `Formed` and introducing a contextual layer, enables /// sophisticated and flexible construction patterns conducive to complex data transformations or object creation /// sequences within builder patterns. -pub trait FormerBegin< Definition : FormerDefinition, Context > +// xxx : update description +pub trait FormerBegin< Definition : FormerDefinition > { /// * `End` - A trait bound marking the closure or handler invoked upon completing the subforming process. Implementers /// of this trait (`End`) are tasked with applying the final transformations that transition `Storage` /// into `Formed`, optionally utilizing `Context` to guide this transformation. It is crucial that this - /// associated type satisfies the `FormingEnd` trait, defining the precise mechanics of + /// associated type satisfies the `FormingEnd< Formed >` trait, defining the precise mechanics of /// how the subformer concludes its operation. - type End : FormingEnd< Definition, Context >; + type End : FormingEnd< Definition >; /// Launches the subforming process with an initial storage and context, setting up an `on_end` completion handler. /// @@ -206,7 +181,7 @@ pub trait FormerBegin< Definition : FormerDefinition, Context > fn _begin ( storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Context >, + context : core::option::Option< Definition::Context >, on_end : Self::End, ) -> Self; diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 3da836f5d7..a14882d04b 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -193,23 +193,22 @@ where // = - /// A builder for constructing containers, facilitating a fluent and flexible interface. #[ derive( Debug, Default ) ] -pub struct ContainerSubformer< E, Definition, Context = (), End = ReturnFormed > +pub struct ContainerSubformer< E, Definition, End = ReturnFormed > where - End : FormingEnd< Definition, Context >, + End : FormingEnd< Definition >, Definition : FormerDefinition, Definition::Storage : ContainerAdd< Element = E >, { storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Context >, + context : core::option::Option< Definition::Context >, on_end : core::option::Option< End >, } -impl< E, Definition, Context, End > ContainerSubformer< E, Definition, Context, End > +impl< E, Definition, End > ContainerSubformer< E, Definition, End > where - End : FormingEnd< Definition, Context >, + End : FormingEnd< Definition >, Definition : FormerDefinition, Definition::Storage : ContainerAdd< Element = E >, { @@ -235,7 +234,7 @@ where pub fn begin ( storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Context >, + context : core::option::Option< Definition::Context >, on_end : End ) -> Self { @@ -274,9 +273,9 @@ where } -impl< E, Definition > ContainerSubformer< E, Definition, (), ReturnFormed > +impl< E, Definition > ContainerSubformer< E, Definition, ReturnFormed > where - Definition : FormerDefinition, + Definition : FormerDefinition< Context = () >, Definition::Storage : ContainerAdd< Element = E >, Definition::Storage : StoragePerform< Formed = Definition::Formed >, { @@ -300,9 +299,9 @@ where } -impl< E, Definition, Context, End > ContainerSubformer< E, Definition, Context, End > +impl< E, Definition, End > ContainerSubformer< E, Definition, End > where - End : FormingEnd< Definition, Context >, + End : FormingEnd< Definition >, Definition : FormerDefinition, Definition::Storage : ContainerAdd< Element = E >, { @@ -328,10 +327,10 @@ where // -impl< E, Definition, Context, End > FormerBegin< Definition, Context > -for ContainerSubformer< E, Definition, Context, End > +impl< E, Definition, End > FormerBegin< Definition > +for ContainerSubformer< E, Definition, End > where - End : FormingEnd< Definition, Context >, + End : FormingEnd< Definition >, Definition : FormerDefinition, Definition::Storage : ContainerAdd< Element = E >, { @@ -341,7 +340,7 @@ where fn _begin ( storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Context >, + context : core::option::Option< Definition::Context >, on_end : End, ) -> Self From aa64c2d1cffbbaa02103389cf1268c3e09c6784a Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 22:53:48 +0200 Subject: [PATCH 019/533] former : experimenting --- module/core/former/src/axiomatic.rs | 20 +++++- module/core/former/src/container.rs | 33 ++++----- module/core/former/src/hash_map.rs | 20 +++--- module/core/former/src/hash_set.rs | 20 +++--- module/core/former/src/vector.rs | 19 +++-- .../inc/former_tests/container_former_vec.rs | 70 ++++++++++--------- 6 files changed, 109 insertions(+), 73 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 084ce87db4..241383491c 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -14,12 +14,13 @@ pub trait StoragePerform : Storage } /// xxx -pub trait FormerDefinition +pub trait FormerDefinition : Sized { // type Storage : Storage< Definition = Self >; type Storage : Storage< Formed = Self::Formed >; type Formed; type Context; + type End : FormingEnd< Self >; } // pub trait FormerDefinition @@ -74,7 +75,6 @@ pub struct ReturnFormed; impl< Definition > FormingEnd< Definition > for ReturnFormed where - // Definition::Storage : StoragePerform< Definition = Definition >, Definition::Storage : StoragePerform< Formed = Definition::Formed >, Definition : FormerDefinition< Context = () >, { @@ -85,6 +85,22 @@ where } } +/// xxx +#[ derive( Debug, Default ) ] +pub struct ReturnStorage; + +impl< Definition, T > FormingEnd< Definition > +for ReturnStorage +where + Definition : FormerDefinition< Context = (), Storage = T, Formed = T >, +{ + #[ inline( always ) ] + fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed + { + storage + } +} + /// A wrapper around a closure to be used as a `FormingEnd`. /// /// This struct allows for dynamic dispatch of a closure that matches the diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index a14882d04b..a7156befe3 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -195,20 +195,20 @@ where /// A builder for constructing containers, facilitating a fluent and flexible interface. #[ derive( Debug, Default ) ] -pub struct ContainerSubformer< E, Definition, End = ReturnFormed > +pub struct ContainerSubformer< E, Definition > where - End : FormingEnd< Definition >, + // End : FormingEnd< Definition >, Definition : FormerDefinition, Definition::Storage : ContainerAdd< Element = E >, { storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, - on_end : core::option::Option< End >, + on_end : core::option::Option< Definition::End >, } -impl< E, Definition, End > ContainerSubformer< E, Definition, End > +impl< E, Definition > ContainerSubformer< E, Definition > where - End : FormingEnd< Definition >, + // End : FormingEnd< Definition >, Definition : FormerDefinition, Definition::Storage : ContainerAdd< Element = E >, { @@ -235,7 +235,7 @@ where ( storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, - on_end : End + on_end : Definition::End, ) -> Self { Self @@ -273,9 +273,9 @@ where } -impl< E, Definition > ContainerSubformer< E, Definition, ReturnFormed > +impl< E, T, Definition > ContainerSubformer< E, Definition > where - Definition : FormerDefinition< Context = () >, + Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = ReturnStorage >, Definition::Storage : ContainerAdd< Element = E >, Definition::Storage : StoragePerform< Formed = Definition::Formed >, { @@ -293,15 +293,16 @@ where ( None, None, - ReturnFormed, + ReturnStorage, + // ReturnFormed, ) } } -impl< E, Definition, End > ContainerSubformer< E, Definition, End > +impl< E, Definition > ContainerSubformer< E, Definition > where - End : FormingEnd< Definition >, + // End : FormingEnd< Definition >, Definition : FormerDefinition, Definition::Storage : ContainerAdd< Element = E >, { @@ -327,21 +328,21 @@ where // -impl< E, Definition, End > FormerBegin< Definition > -for ContainerSubformer< E, Definition, End > +impl< E, Definition > FormerBegin< Definition > +for ContainerSubformer< E, Definition > where - End : FormingEnd< Definition >, + // End : FormingEnd< Definition >, Definition : FormerDefinition, Definition::Storage : ContainerAdd< Element = E >, { - type End = End; + type End = Definition::End; #[ inline( always ) ] fn _begin ( storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, - on_end : End, + on_end : Definition::End, ) -> Self { diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 3788eecf67..b2ea774f13 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -45,7 +45,7 @@ where } -// +// = storage impl< K, E > Storage for HashMap< K, E > @@ -68,19 +68,21 @@ where } } -// +// = definition #[ derive( Debug ) ] -pub struct HashMapDefinition< K, E, Context = () > +pub struct HashMapDefinition< K, E, Context, End > where K : ::core::cmp::Eq + ::core::hash::Hash, + End : FormingEnd< Self >, { - _phantom : ::core::marker::PhantomData< ( K, E, Context ) >, + _phantom : ::core::marker::PhantomData< ( K, E, Context, End ) >, } -impl< K, E, Context > HashMapDefinition< K, E, Context > +impl< K, E, Context, End > HashMapDefinition< K, E, Context, End > where K : ::core::cmp::Eq + ::core::hash::Hash, + End : FormingEnd< Self >, { pub fn new() -> Self { @@ -88,14 +90,16 @@ where } } -impl< K, E, Context > FormerDefinition -for HashMapDefinition< K, E, Context > +impl< K, E, Context, End > FormerDefinition +for HashMapDefinition< K, E, Context, End > where K : ::core::cmp::Eq + ::core::hash::Hash, + End : FormingEnd< Self >, { type Storage = HashMap< K, E >; type Formed = HashMap< K, E >; type Context = Context; + type End = End; } /// A builder for constructing hash map-like structures with a fluent interface. @@ -136,7 +140,7 @@ where /// # } /// ``` -pub type HashMapSubformer< K, E, Context = () > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context > >; +pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, End > >; // #[ 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 9d8836b6d3..4be2c7bbf5 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -33,7 +33,7 @@ where } } -// +// = storage impl< K > Storage for HashSet< K > @@ -56,19 +56,21 @@ where } } -// +// = definition #[ derive( Debug ) ] -pub struct HashSetDefinition< K, Context = () > +pub struct HashSetDefinition< K, Context, End > where K : ::core::cmp::Eq + ::core::hash::Hash, + End : FormingEnd< Self >, { - _phantom : ::core::marker::PhantomData< ( K, Context ) >, + _phantom : ::core::marker::PhantomData< ( K, Context, End ) >, } -impl< K, Context > HashSetDefinition< K, Context > +impl< K, Context, End > HashSetDefinition< K, Context, End > where K : ::core::cmp::Eq + ::core::hash::Hash, + End : FormingEnd< Self >, { pub fn new() -> Self { @@ -76,14 +78,16 @@ where } } -impl< K, Context > FormerDefinition -for HashSetDefinition< K, Context > +impl< K, Context, End > FormerDefinition +for HashSetDefinition< K, Context, End > where K : ::core::cmp::Eq + ::core::hash::Hash, + End : FormingEnd< Self >, { type Storage = HashSet< K >; type Formed = HashSet< K >; type Context = Context; + type End = End; } /// Facilitates building `HashSetLike` containers with a fluent API. @@ -118,7 +122,7 @@ where /// # } /// ``` -pub type HashSetSubformer< K, Context = () > = ContainerSubformer::< K, HashSetDefinition< K, Context > >; +pub type HashSetSubformer< K, Context, End > = ContainerSubformer::< K, HashSetDefinition< K, Context, End > >; // #[ 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 bab7601563..d35824cb55 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -45,12 +45,16 @@ for Vec< E > // #[ derive( Debug ) ] -pub struct VectorDefinition< E, Context = () > +pub struct VectorDefinition< E, Context, End > +where + End : FormingEnd< Self > { - _phantom : core::marker::PhantomData< ( E, Context ) >, + _phantom : core::marker::PhantomData< ( E, Context, End ) >, } -impl< E, Context > VectorDefinition< E, Context > +impl< E, Context, End > VectorDefinition< E, Context, End > +where + End : FormingEnd< Self > { pub fn new() -> Self { @@ -58,12 +62,15 @@ impl< E, Context > VectorDefinition< E, Context > } } -impl< E, Context > FormerDefinition -for VectorDefinition< E, Context > +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. @@ -71,7 +78,7 @@ for VectorDefinition< E, Context > /// `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 = () > = ContainerSubformer::< E, VectorDefinition< E, Context > >; +pub type VectorSubformer< E, Context, End > = ContainerSubformer::< E, VectorDefinition< E, Context, End > >; // #[ 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 4f886ba463..09fce459a0 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,42 +8,46 @@ 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" ) - .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, (), the_module::ReturnStorage >, + // >::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::VectorSubformer::< 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" ) +// .form(); +// let exp = vec! +// [ +// "a".to_string(), +// "b".to_string(), +// ]; +// a_id!( got, exp ); +// +// // +// +// let got : Vec< String > = the_module::VectorSubformer::< String, () >::new() +// .push( "a" ) +// .push( "b" ) +// .form(); +// let exp = vec! +// [ +// "a".to_string(), +// "b".to_string(), +// ]; +// a_id!( got, exp ); } From bfb321595a2acb3ae7499be423e0723e2fd2f437 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 24 Mar 2024 00:00:23 +0200 Subject: [PATCH 020/533] former : experimenting --- module/core/former/src/axiomatic.rs | 40 ++-- module/core/former/src/hash_map.rs | 177 ---------------- module/core/former/src/hash_set.rs | 196 ------------------ module/core/former/src/vector.rs | 158 +------------- .../inc/former_tests/container_former_vec.rs | 44 ++-- 5 files changed, 52 insertions(+), 563 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 241383491c..4066ae3661 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -65,25 +65,25 @@ where } } -/// A `FormingEnd` implementation that returns the formed container itself instead of the context. -/// -/// This struct is useful when the forming process should result in the formed container being returned directly, -/// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. -#[ derive( Debug, Default ) ] -pub struct ReturnFormed; - -impl< Definition > FormingEnd< Definition > -for ReturnFormed -where - Definition::Storage : StoragePerform< Formed = Definition::Formed >, - Definition : FormerDefinition< Context = () >, -{ - #[ inline( always ) ] - fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed - { - storage.preform() - } -} +// /// A `FormingEnd` implementation that returns the formed container itself instead of the context. +// /// +// /// This struct is useful when the forming process should result in the formed container being returned directly, +// /// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. +// #[ derive( Debug, Default ) ] +// pub struct ReturnFormed; +// +// impl< Definition > FormingEnd< Definition > +// for ReturnFormed +// where +// Definition::Storage : StoragePerform< Formed = Definition::Formed >, +// Definition : FormerDefinition< Context = () >, +// { +// #[ inline( always ) ] +// fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed +// { +// storage.preform() +// } +// } /// xxx #[ derive( Debug, Default ) ] @@ -92,7 +92,7 @@ pub struct ReturnStorage; impl< Definition, T > FormingEnd< Definition > for ReturnStorage where - Definition : FormerDefinition< Context = (), Storage = T, Formed = T >, + Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = Self >, { #[ inline( always ) ] fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index b2ea774f13..e3134e65ee 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -141,180 +141,3 @@ where /// ``` pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, End > >; - -// #[ derive( Debug, Default ) ] -// pub struct HashMapSubformer< K, E, Definition, Context, End > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// // Formed : HashMapLike< K, E > + ::core::default::Default, -// End : FormingEnd< Definition, Context >, -// Definition : FormerDefinition, -// Definition::Storage : ContainerAdd< Element = ( K, E ) >, -// { -// storage : ::core::option::Option< Definition::Storage >, -// context : ::core::option::Option< Context >, -// on_end : ::core::option::Option< End >, -// _e_phantom : ::core::marker::PhantomData< E >, -// _k_phantom : ::core::marker::PhantomData< K >, -// } -// -// impl< K, E, Definition, Context, End > -// HashMapSubformer< K, E, Definition, Context, End > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// // Formed : HashMapLike< K, E > + ::core::default::Default, -// End : FormingEnd< Definition, Context >, -// Definition : FormerDefinition, -// Definition::Storage : ContainerAdd< Element = ( K, E ) >, -// { -// -// /// Form current former into target structure. -// #[ inline( always ) ] -// pub fn storage( mut self ) -> Definition::Storage -// { -// // xxx -// let storage = if self.storage.is_some() -// { -// self.storage.take().unwrap() -// } -// else -// { -// let val = Default::default(); -// val -// }; -// storage -// // storage.preform() -// } -// // xxx -// -// -// /// Make a new HashMapSubformer. It should be called by a context generated for your structure. -// /// The context is returned after completion of forming by function `on_end``. -// #[ inline( always ) ] -// pub fn begin -// ( -// storage : ::core::option::Option< Definition::Storage >, -// context : ::core::option::Option< Context >, -// on_end : End, -// ) -// -> Self -// { -// Self -// { -// storage, -// context, -// on_end : Some( on_end ), -// _e_phantom : ::core::marker::PhantomData, -// _k_phantom : ::core::marker::PhantomData, -// } -// } -// -// /// Return context of your struct moving formed there. Should be called after forming process. -// #[ inline( always ) ] -// pub fn end( mut self ) -> Definition::Formed -// { -// let on_end = self.on_end.take().unwrap(); -// let context = self.context.take(); -// let storage = self.storage(); -// on_end.call( storage, context ) -// } -// -// /// Return context of your struct moving formed there. Should be called after forming process. -// #[ inline( always ) ] -// pub fn form( self ) -> Definition::Formed -// { -// self.end() -// } -// -// /// Set the whole storage instead of setting each element individually. -// #[ inline( always ) ] -// pub fn replace( mut self, storage : Definition::Storage ) -> Self -// { -// self.storage = Some( storage ); -// self -// } -// -// } -// -// impl< K, E, Definition > -// HashMapSubformer< K, E, Definition, (), crate::ReturnFormed > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// Definition : FormerDefinition, -// Definition::Storage : ContainerAdd< Element = ( K, E ) >, -// Definition::Storage : StoragePerform< Definition = Definition >, -// { -// -// /// Create a new instance without context or on end processing. It just returns continaer on end of forming. -// #[ inline( always ) ] -// pub fn new() -> Self -// { -// HashMapSubformer::begin -// ( -// None, -// None, -// crate::ReturnFormed, -// ) -// } -// -// } -// -// impl< K, E, Definition, Context, End > -// HashMapSubformer< K, E, Definition, Context, End > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// // Formed : HashMapLike< K, E > + ::core::default::Default, -// End : FormingEnd< Definition, Context >, -// Definition : FormerDefinition, -// Definition::Storage : ContainerAdd< Element = ( K, E ) >, -// { -// -// /// Inserts a key-value pair into the formed. If the formed doesn't exist, it is created. -// /// -// /// # Parameters -// /// - `k`: The key for the value to be inserted. Will be converted into the formed's key type. -// /// - `e`: The value to be inserted. Will be converted into the formed's value type. -// /// -// /// # Returns -// /// Returns `self` for chaining further insertions or operations. -// /// -// #[ inline( always ) ] -// pub fn insert< K2, E2 >( mut self, k : K2, e : E2 ) -> Self -// where -// K2 : ::core::convert::Into< K >, -// E2 : ::core::convert::Into< E >, -// // Definition::Storage : ContainerAdd< Element = ( K, E ) >, -// { -// if self.storage.is_none() -// { -// self.storage = ::core::option::Option::Some( Default::default() ); -// } -// if let ::core::option::Option::Some( ref mut storage ) = self.storage -// { -// ContainerAdd::add( storage, ( k.into(), e.into() ) ); -// // storage.insert( k.into(), e.into() ); -// } -// self -// } -// -// /// Alias for insert. -// /// -// /// # Parameters -// /// - `k`: The key for the value to be inserted. Will be converted into the formed's key type. -// /// - `e`: The value to be inserted. Will be converted into the formed's value type. -// /// -// /// # Returns -// /// Returns `self` for chaining further insertions or operations. -// /// -// #[ inline( always ) ] -// pub fn push< K2, E2 >( self, k : K2, e : E2 ) -> Self -// where -// K2 : ::core::convert::Into< K >, -// E2 : ::core::convert::Into< E >, -// { -// self.insert( k, e ) -// } -// -// } - -// diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 4be2c7bbf5..1f9c63836e 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -123,199 +123,3 @@ where /// ``` pub type HashSetSubformer< K, Context, End > = ContainerSubformer::< K, HashSetDefinition< K, Context, End > >; - -// #[ derive( Debug, Default ) ] -// pub struct HashSetSubformer< K, Definition, Context, End > -// where -// K : core::cmp::Eq + core::hash::Hash, -// // Formed : HashSetLike< K > + core::default::Default, -// End : FormingEnd< Definition, Context >, -// Definition : FormerDefinition, -// Definition::Storage : ContainerAdd< Element = K >, -// { -// storage : core::option::Option< Definition::Storage >, -// context : core::option::Option< Context >, -// on_end : core::option::Option< End >, -// _e_phantom : core::marker::PhantomData< K >, -// } -// -// impl< K, Definition, Context, End > -// HashSetSubformer< K, Definition, Context, End > -// where -// K : core::cmp::Eq + core::hash::Hash, -// // Formed : HashSetLike< K > + core::default::Default, -// End : FormingEnd< Definition, Context >, -// Definition : FormerDefinition, -// Definition::Storage : ContainerAdd< Element = K >, -// { -// -// /// Form current former into target structure. -// #[ inline( always ) ] -// pub fn storage( mut self ) -> Definition::Storage -// { -// let storage = if self.storage.is_some() -// { -// self.storage.take().unwrap() -// } -// else -// { -// let val = Default::default(); -// val -// }; -// storage -// } -// // xxx -// -// /// Begins the building process with an optional context and storage. -// /// -// /// This method is typically called internally by the builder but can be used directly -// /// to initialize the builder with specific contexts or containers. -// /// -// /// # Parameters -// /// - `context`: An optional context for the building process. -// /// - `storage`: An optional initial storage to populate. -// /// - `on_end`: A handler to be called at the end of the building process. -// /// -// #[ inline( always ) ] -// pub fn begin -// ( -// storage : core::option::Option< Definition::Storage >, -// context : core::option::Option< Context >, -// on_end : End, -// ) -> Self -// { -// Self -// { -// storage, -// context : context, -// on_end : Some( on_end ), -// _e_phantom : core::marker::PhantomData, -// } -// } -// -// /// Finalizes the building process and returns the constructed formed or a context. -// /// -// /// This method concludes the building process by applying the `on_end` handler to transform -// /// the formed or incorporate it into a given context. It's typically called at the end -// /// of the builder chain to retrieve the final product of the building process. -// /// -// /// # Returns -// /// Depending on the `on_end` handler's implementation, this method can return either the -// /// constructed formed or a context that incorporates the formed. -// /// -// #[ inline( always ) ] -// pub fn form( self ) -> Definition::Formed -// { -// self.end() -// } -// -// /// Finalizes the building process and returns the constructed formed or a context. -// /// -// /// This method concludes the building process by applying the `on_end` handler to transform -// /// the formed or incorporate it into a given context. It's typically called at the end -// /// of the builder chain to retrieve the final product of the building process. -// /// -// /// # Returns -// /// Depending on the `on_end` handler's implementation, this method can return either the -// /// constructed formed or a context that incorporates the formed. -// /// -// #[ inline( always ) ] -// pub fn end( mut self ) -> Definition::Formed -// { -// let on_end = self.on_end.take().unwrap(); -// let context = self.context.take(); -// let storage = self.storage(); -// on_end.call( storage, context ) -// } -// -// /// Replaces the current storage with a new one. -// /// -// /// This method allows for replacing the entire set being built with a different one. -// /// It can be useful in scenarios where a pre-populated set needs to be modified or -// /// replaced entirely during the building process. -// /// -// /// # Parameters -// /// - `storage`: The new storage to use for subsequent builder operations. -// /// -// /// # Returns -// /// The builder instance with the storage replaced, enabling further chained operations. -// /// -// #[ inline( always ) ] -// pub fn replace( mut self, storage : Definition::Storage ) -> Self -// { -// self.storage = Some( storage ); -// self -// } -// -// } -// -// impl< K, Definition > -// HashSetSubformer< K, Definition, (), crate::ReturnFormed > -// where -// K : core::cmp::Eq + core::hash::Hash, -// Definition : FormerDefinition, -// Definition::Storage : ContainerAdd< Element = K >, -// Definition::Storage : StoragePerform< Definition = Definition >, -// { -// -// /// Initializes a new instance of the builder with default settings. -// /// -// /// This method provides a starting point for forming a `HashSetLike` using -// /// a fluent interface. -// /// -// /// # Returns -// /// A new instance of `HashSetSubformer` with no elements. -// /// -// #[ inline( always ) ] -// pub fn new() -> Self -// { -// HashSetSubformer::begin -// ( -// None, -// None, -// crate::ReturnFormed, -// ) -// } -// -// } -// -// impl< K, Definition, Context, End > -// HashSetSubformer< K, Definition, Context, End > -// where -// K : core::cmp::Eq + core::hash::Hash, -// End : FormingEnd< Definition, Context >, -// Definition : FormerDefinition, -// Definition::Storage : ContainerAdd< Element = K >, -// { -// -// /// Inserts an element into the set, possibly replacing an existing element. -// /// -// /// This method ensures that the set contains the given element, and if the element -// /// was already present, it might replace it depending on the storage's behavior. -// /// -// /// # Parameters -// /// - `element`: The element to insert into the set. -// /// -// /// # Returns -// /// - `Some(element)` if the element was replaced. -// /// - `None` if the element was newly inserted without replacing any existing element. -// /// -// #[ inline( always ) ] -// pub fn insert< E2 >( mut self, element : E2 ) -> Self -// where -// E2 : core::convert::Into< K >, -// { -// if self.storage.is_none() -// { -// self.storage = core::option::Option::Some( Default::default() ); -// } -// if let core::option::Option::Some( ref mut storage ) = self.storage -// { -// ContainerAdd::add( storage, element.into() ); -// } -// self -// } -// -// } - -// \ No newline at end of file diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index d35824cb55..cc3ba6dbac 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -45,7 +45,7 @@ for Vec< E > // #[ derive( Debug ) ] -pub struct VectorDefinition< E, Context, End > +pub struct VectorDefinition< E, Context = (), End = ReturnStorage > where End : FormingEnd< Self > { @@ -79,159 +79,3 @@ where /// 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, Default ) ] -// pub struct VectorSubformer< E, Definition, Context, End > -// where -// End : FormingEnd< Definition, Context >, -// Definition : FormerDefinition, -// Definition::Storage : ContainerAdd< Element = E >, -// { -// storage : core::option::Option< Definition::Storage >, -// context : core::option::Option< Context >, -// on_end : core::option::Option< End >, -// } -// -// impl< E, Definition, Context, End > VectorSubformer< E, Definition, Context, End > -// where -// End : FormingEnd< Definition, Context >, -// Definition : FormerDefinition, -// Definition::Storage : ContainerAdd< Element = E >, -// { -// -// /// Form current former into target structure. -// #[ inline( always ) ] -// pub fn storage( mut self ) -> Definition::Storage -// { -// let storage = if self.storage.is_some() -// { -// self.storage.take().unwrap() -// } -// else -// { -// let val = Default::default(); -// val -// }; -// storage -// } -// -// /// Begins the building process, optionally initializing with a context and storage. -// #[ inline( always ) ] -// pub fn begin -// ( -// storage : core::option::Option< Definition::Storage >, -// context : core::option::Option< Context >, -// on_end : End -// ) -> Self -// { -// Self -// { -// storage, -// context, -// on_end : Some( on_end ), -// } -// } -// -// /// Finalizes the building process, returning the formed or a context incorporating it. -// #[ inline( always ) ] -// pub fn form( self ) -> Definition::Formed -// { -// self.end() -// } -// -// /// Finalizes the building process, returning the formed or a context incorporating it. -// #[ inline( always ) ] -// pub fn end( mut self ) -> Definition::Formed -// { -// let on_end = self.on_end.take().unwrap(); -// let context = self.context.take(); -// let storage = self.storage(); -// on_end.call( storage, context ) -// } -// -// /// Replaces the current storage with a provided one, allowing for a reset or redirection of the building process. -// #[ inline( always ) ] -// pub fn replace( mut self, vector : Definition::Storage ) -> Self -// { -// self.storage = Some( vector ); -// self -// } -// -// } -// -// impl< E, Definition > VectorSubformer< E, Definition, (), ReturnFormed > -// where -// Definition : FormerDefinition, -// Definition::Storage : ContainerAdd< Element = E >, -// Definition::Storage : StoragePerform< Definition = Definition >, -// { -// -// /// Initializes a new `VectorSubformer` instance, starting with an empty formed. -// /// This function serves as the entry point for the builder pattern. -// /// -// /// # Returns -// /// A new instance of `VectorSubformer` with an empty internal formed. -// /// -// #[ inline( always ) ] -// pub fn new() -> Self -// { -// Self::begin -// ( -// None, -// None, -// ReturnFormed, -// ) -// } -// -// } -// -// impl< E, Definition, Context, End > VectorSubformer< E, Definition, Context, End > -// where -// End : FormingEnd< Definition, Context >, -// Definition : FormerDefinition, -// Definition::Storage : ContainerAdd< Element = E >, -// { -// -// /// Appends an element to the end of the storage, expanding the internal collection. -// #[ inline( always ) ] -// pub fn push< IntoElement >( mut self, element : IntoElement ) -> Self -// where IntoElement : core::convert::Into< E >, -// { -// if self.storage.is_none() -// { -// self.storage = core::option::Option::Some( Default::default() ); -// } -// if let core::option::Option::Some( ref mut storage ) = self.storage -// { -// ContainerAdd::add( storage, element.into() ); -// // storage.push( element.into() ); -// } -// self -// } -// -// } -// -// // -// -// impl< E, Definition, Context, End > FormerBegin< Definition, Context > -// for VectorSubformer< E, Definition, Context, End > -// where -// End : FormingEnd< Definition, Context >, -// Definition : FormerDefinition, -// Definition::Storage : ContainerAdd< Element = E >, -// { -// type End = End; -// -// #[ inline( always ) ] -// fn _begin -// ( -// storage : core::option::Option< Definition::Storage >, -// context : core::option::Option< Context >, -// on_end : End, -// ) -// -> Self -// { -// Self::begin( storage, context, on_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 09fce459a0..68e27f6ca8 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 @@ -4,10 +4,41 @@ use super::*; #[ allow( unused_imports ) ] use collection_tools::Vec; +// impl< Definition, T > FormingEnd< Definition > +// for ReturnStorage +// where +// Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = Self >, + +pub fn f1< Definition : former::FormerDefinition >( x : Definition ) +{ +} + #[ test ] fn push() { + // f1( the_module::ReturnStorage ); + + // + + // let got : Vec< String > = the_module + // ::ContainerSubformer + // ::< String, former::VectorDefinition< String, (), the_module::ReturnStorage > > + // ::new() + // .push( "a" ) + // .push( "b" ) + // .form(); + // let exp = vec! + // [ + // "a".to_string(), + // "b".to_string(), + // ]; + // a_id!( got, exp ); + + // Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = Self >, + + // + // let got : Vec< String > = the_module::ContainerSubformer:: // < // String, @@ -22,19 +53,6 @@ fn push() // "b".to_string(), // ]; // a_id!( got, exp ); - - // - -// 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 ); // // // // From a8b227956196465279ec31fa1cec51bee71f4d6a Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 24 Mar 2024 00:24:28 +0200 Subject: [PATCH 021/533] former : experimenting --- module/core/former/src/axiomatic.rs | 1 + module/core/former/src/vector.rs | 3 ++- .../tests/inc/former_tests/container_former_vec.rs | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 4066ae3661..af916d18ae 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -93,6 +93,7 @@ impl< Definition, T > FormingEnd< Definition > for ReturnStorage where Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = Self >, + // Definition::Storage : Default, { #[ inline( always ) ] fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index cc3ba6dbac..05c695b712 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -45,7 +45,8 @@ for Vec< E > // #[ derive( Debug ) ] -pub struct VectorDefinition< E, Context = (), End = ReturnStorage > +// pub struct VectorDefinition< E, Context = (), End = ReturnStorage > +pub struct VectorDefinition< E, Context, End > where End : FormingEnd< Self > { 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 68e27f6ca8..f91b48c8b8 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,7 +9,16 @@ use collection_tools::Vec; // where // Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = Self >, -pub fn f1< Definition : former::FormerDefinition >( x : Definition ) +pub fn f0< Definition >( x : Definition ) +where + Definition : former::FormerDefinition, +{ +} + +pub fn f1< Definition, End >( x : End ) +where + Definition : former::FormerDefinition, + End : former::FormingEnd< Definition >, { } @@ -17,7 +26,8 @@ pub fn f1< Definition : former::FormerDefinition >( x : Definition ) fn push() { - // f1( the_module::ReturnStorage ); + // f0( former::VectorDefinition::< String, (), the_module::ReturnStorage >::new() ); + // f1::< former::VectorDefinition< String, (), the_module::ReturnStorage >, _ >( the_module::ReturnStorage ); // From babd9c7e7121f643108f62abdcd100261742dc11 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 24 Mar 2024 00:35:14 +0200 Subject: [PATCH 022/533] former : experimenting --- module/core/former/src/axiomatic.rs | 2 ++ module/core/former/src/vector.rs | 3 ++- .../former/tests/inc/former_tests/container_former_vec.rs | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index af916d18ae..3b8cfaef2c 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -93,6 +93,8 @@ impl< Definition, T > FormingEnd< Definition > for ReturnStorage where Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = Self >, + Definition::End : FormingEnd< Definition >, + // Definition::End : Self, // Definition::Storage : Default, { #[ inline( always ) ] diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 05c695b712..99132431a6 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -48,7 +48,8 @@ for Vec< E > // pub struct VectorDefinition< E, Context = (), End = ReturnStorage > pub struct VectorDefinition< E, Context, End > where - End : FormingEnd< Self > + End : FormingEnd< Self >, + Self : FormerDefinition, { _phantom : core::marker::PhantomData< ( 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 f91b48c8b8..1e9bc00448 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 @@ -22,6 +22,12 @@ where { } +// impl former::FormingEnd> for former::ReturnStorage { +// fn call(&self, storage: former::VectorDefinition::Storage, context: Option::Context>) -> former::VectorDefinition::Formed { +// storage +// } +// } + #[ test ] fn push() { From 28e23bf103a39720976039aec44daf5e89d8d0d1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 24 Mar 2024 01:06:00 +0200 Subject: [PATCH 023/533] former : experimenting --- module/core/former/src/axiomatic.rs | 24 ++- module/core/former/src/container.rs | 49 ++--- module/core/former/src/hash_map.rs | 286 ++++++++++++++-------------- module/core/former/src/hash_set.rs | 250 ++++++++++++------------ module/core/former/src/vector.rs | 162 ++++++++-------- 5 files changed, 390 insertions(+), 381 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 3b8cfaef2c..50ed77f42f 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -20,7 +20,14 @@ pub trait FormerDefinition : Sized type Storage : Storage< Formed = Self::Formed >; type Formed; type Context; - type End : FormingEnd< Self >; + // type End : FormingEnd< Self >; +} + +/// xxx +pub trait FormerDefinition2 : Sized +{ + type Definition : FormerDefinition; + type End : FormingEnd< Self::Definition >; } // pub trait FormerDefinition @@ -92,8 +99,8 @@ pub struct ReturnStorage; impl< Definition, T > FormingEnd< Definition > for ReturnStorage where - Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = Self >, - Definition::End : FormingEnd< Definition >, + Definition : FormerDefinition< Context = (), Storage = T, Formed = T >, + // Definition::End : FormingEnd< Definition >, // Definition::End : Self, // Definition::Storage : Default, { @@ -180,7 +187,7 @@ for FormingEndWrapper< Definition > /// sequences within builder patterns. // xxx : update description -pub trait FormerBegin< Definition : FormerDefinition > +pub trait FormerBegin< Definition : FormerDefinition2 > { /// * `End` - A trait bound marking the closure or handler invoked upon completing the subforming process. Implementers @@ -188,7 +195,8 @@ pub trait FormerBegin< Definition : FormerDefinition > /// into `Formed`, optionally utilizing `Context` to guide this transformation. It is crucial that this /// associated type satisfies the `FormingEnd< Formed >` trait, defining the precise mechanics of /// how the subformer concludes its operation. - type End : FormingEnd< Definition >; + // type End : FormingEnd< Definition >; + // type End : Definition::End; /// Launches the subforming process with an initial storage and context, setting up an `on_end` completion handler. /// @@ -199,9 +207,9 @@ pub trait FormerBegin< Definition : FormerDefinition > /// * `on_end` - A completion handler responsible for transforming the accumulated `Storage` into the final `Formed` structure. fn _begin ( - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Definition::Context >, - on_end : Self::End, + storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >, + context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >, + on_end : Definition::End, ) -> Self; } diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index a7156befe3..4a72d03220 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -194,28 +194,28 @@ where // = /// A builder for constructing containers, facilitating a fluent and flexible interface. -#[ derive( Debug, Default ) ] +#[ derive( Default ) ] pub struct ContainerSubformer< E, Definition > where // End : FormingEnd< Definition >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, + Definition : FormerDefinition2, + < Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >, { - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Definition::Context >, + storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >, + context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >, on_end : core::option::Option< Definition::End >, } impl< E, Definition > ContainerSubformer< E, Definition > where // End : FormingEnd< Definition >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, + Definition : FormerDefinition2, + < Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >, { /// Form current former into target structure. #[ inline( always ) ] - pub fn storage( mut self ) -> Definition::Storage + pub fn storage( mut self ) -> < Definition::Definition as FormerDefinition >::Storage { let storage = if self.storage.is_some() { @@ -233,8 +233,8 @@ where #[ inline( always ) ] pub fn begin ( - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Definition::Context >, + storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >, + context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >, on_end : Definition::End, ) -> Self { @@ -248,7 +248,7 @@ where /// Finalizes the building process, returning the formed or a context incorporating it. #[ inline( always ) ] - pub fn end( mut self ) -> Definition::Formed + pub fn end( mut self ) -> < Definition::Definition as FormerDefinition >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); @@ -258,14 +258,14 @@ where /// Finalizes the building process, returning the formed or a context incorporating it. #[ inline( always ) ] - pub fn form( self ) -> Definition::Formed + pub fn form( self ) -> < Definition::Definition as FormerDefinition >::Formed { self.end() } /// Replaces the current storage with a provided one, allowing for a reset or redirection of the building process. #[ inline( always ) ] - pub fn replace( mut self, vector : Definition::Storage ) -> Self + pub fn replace( mut self, vector : < Definition::Definition as FormerDefinition >::Storage ) -> Self { self.storage = Some( vector ); self @@ -273,11 +273,12 @@ where } -impl< E, T, Definition > ContainerSubformer< E, Definition > +impl< E, T, Definition, Definition1 > ContainerSubformer< E, Definition > where - Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = ReturnStorage >, - Definition::Storage : ContainerAdd< Element = E >, - Definition::Storage : StoragePerform< Formed = Definition::Formed >, + Definition1 : FormerDefinition< Context = (), Storage = T, Formed = T >, + Definition : FormerDefinition2< Definition = Definition1, End = ReturnStorage >, + < Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >, + < Definition::Definition as FormerDefinition >::Storage : StoragePerform< Formed = < Definition::Definition as FormerDefinition >::Formed >, { /// Initializes a new `ContainerSubformer` instance, starting with an empty formed. @@ -303,8 +304,8 @@ where impl< E, Definition > ContainerSubformer< E, Definition > where // End : FormingEnd< Definition >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, + Definition : FormerDefinition2, + < Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >, { /// Appends an element to the end of the storage, expanding the internal collection. @@ -332,16 +333,16 @@ impl< E, Definition > FormerBegin< Definition > for ContainerSubformer< E, Definition > where // End : FormingEnd< Definition >, - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, + Definition : FormerDefinition2, + < Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >, { - type End = Definition::End; + // type End = Definition::End; #[ inline( always ) ] fn _begin ( - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Definition::Context >, + storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >, + context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >, on_end : Definition::End, ) -> Self diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index e3134e65ee..293cfe2d19 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -1,143 +1,143 @@ -use super::*; - -use collection_tools::HashMap; - -/// 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 -/// of key-value pairs and the creation of formers for more complex construction patterns. -/// -/// # Type Parameters -/// - `K`: The type of keys stored in the hash map. Must implement `Eq` and `Hash`. -/// - `E`: The type of elements (values) stored in the hash map. -pub trait HashMapLike< K, E > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - Self : Sized + Default, -{ - - /// Inserts a key-value pair into the map. - fn insert( &mut self, k : K, e : E ) -> Option< E >; - - // /// Return former. - // #[ inline( always ) ] - // fn former< Definition : FormerDefinition >( self ) - // -> - // HashMapSubformer< K, E, Definition, (), impl FormingEnd< Self, Self > > - // { - // HashMapSubformer::begin( Some( self ), None, ReturnFormed ) - // } - // xxx : uncomment and cover by tests - -} - -impl< K, E > HashMapLike< K, E > for HashMap< K, E > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - Self : Sized + Default, -{ - - #[ inline( always ) ] - fn insert( &mut self, k : K, e : E ) -> Option< E > - { - HashMap::insert( self, k, e ) - } - -} - -// = storage - -impl< K, E > Storage -for HashMap< K, E > -where - K : ::core::cmp::Eq + ::core::hash::Hash, -{ - // type Definition = HashMapDefinition< K, E >; - type Formed = HashMap< K, E >; -} - -impl< K, E > StoragePerform -for HashMap< K, E > -where - K : ::core::cmp::Eq + ::core::hash::Hash, -{ - // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed - fn preform( self ) -> Self::Formed - { - self - } -} - -// = definition - -#[ derive( Debug ) ] -pub struct HashMapDefinition< K, E, Context, End > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - End : FormingEnd< Self >, -{ - _phantom : ::core::marker::PhantomData< ( K, E, Context, End ) >, -} - -impl< K, E, Context, End > HashMapDefinition< K, E, Context, End > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - End : FormingEnd< Self >, -{ - pub fn new() -> Self - { - Self { _phantom : ::core::marker::PhantomData } - } -} - -impl< K, E, Context, End > FormerDefinition -for HashMapDefinition< K, E, Context, End > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - End : FormingEnd< Self >, -{ - type Storage = HashMap< K, E >; - type Formed = HashMap< K, E >; - type Context = Context; - type End = End; -} - -/// A builder for constructing hash map-like structures with a fluent interface. -/// -/// `HashMapSubformer` leverages the `HashMapLike` trait to enable a flexible and customizable -/// way to build hash map-like structures. It supports the chaining of insert operations and -/// allows for the definition of custom end actions to finalize the building process. -/// -/// # Type Parameters -/// - `K`: Key type, must implement `Eq` and `Hash`. -/// - `E`: Element (value) type. -/// - `Formed`: The hash map-like formed being built. -/// - `Context`: Type of the optional context used during the building process. -/// - `End`: End-of-forming action to be executed upon completion. -/// -/// # Examples -/// ``` -/// # #[ cfg( all( feature = "enabled", not( feature = "no_std" ) ) ) ] -/// # { -/// # use test_tools::exposed::*; -/// -/// #[ derive( Debug, PartialEq, former::Former ) ] -/// pub struct StructWithMap -/// { -/// #[ subformer( former::HashMapSubformer ) ] -/// map : std::collections::HashMap< &'static str, &'static str >, -/// } -/// -/// let struct1 = StructWithMap::former() -/// .map() -/// .insert( "a", "b" ) -/// .insert( "c", "d" ) -/// .end() -/// .form() -/// ; -/// assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); -/// -/// # } -/// ``` - -pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, End > >; +// use super::*; +// +// use collection_tools::HashMap; +// +// /// 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 +// /// of key-value pairs and the creation of formers for more complex construction patterns. +// /// +// /// # Type Parameters +// /// - `K`: The type of keys stored in the hash map. Must implement `Eq` and `Hash`. +// /// - `E`: The type of elements (values) stored in the hash map. +// pub trait HashMapLike< K, E > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// Self : Sized + Default, +// { +// +// /// Inserts a key-value pair into the map. +// fn insert( &mut self, k : K, e : E ) -> Option< E >; +// +// // /// Return former. +// // #[ inline( always ) ] +// // fn former< Definition : FormerDefinition >( self ) +// // -> +// // HashMapSubformer< K, E, Definition, (), impl FormingEnd< Self, Self > > +// // { +// // HashMapSubformer::begin( Some( self ), None, ReturnFormed ) +// // } +// // xxx : uncomment and cover by tests +// +// } +// +// impl< K, E > HashMapLike< K, E > for HashMap< K, E > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// Self : Sized + Default, +// { +// +// #[ inline( always ) ] +// fn insert( &mut self, k : K, e : E ) -> Option< E > +// { +// HashMap::insert( self, k, e ) +// } +// +// } +// +// // = storage +// +// impl< K, E > Storage +// for HashMap< K, E > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// // type Definition = HashMapDefinition< K, E >; +// type Formed = HashMap< K, E >; +// } +// +// impl< K, E > StoragePerform +// for HashMap< K, E > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed +// fn preform( self ) -> Self::Formed +// { +// self +// } +// } +// +// // = definition +// +// #[ derive( Debug ) ] +// pub struct HashMapDefinition< K, E, Context, End > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// End : FormingEnd< Self >, +// { +// _phantom : ::core::marker::PhantomData< ( K, E, Context, End ) >, +// } +// +// impl< K, E, Context, End > HashMapDefinition< K, E, Context, End > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// End : FormingEnd< Self >, +// { +// pub fn new() -> Self +// { +// Self { _phantom : ::core::marker::PhantomData } +// } +// } +// +// impl< K, E, Context, End > FormerDefinition +// for HashMapDefinition< K, E, Context, End > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// End : FormingEnd< Self >, +// { +// type Storage = HashMap< K, E >; +// type Formed = HashMap< K, E >; +// type Context = Context; +// type End = End; +// } +// +// /// A builder for constructing hash map-like structures with a fluent interface. +// /// +// /// `HashMapSubformer` leverages the `HashMapLike` trait to enable a flexible and customizable +// /// way to build hash map-like structures. It supports the chaining of insert operations and +// /// allows for the definition of custom end actions to finalize the building process. +// /// +// /// # Type Parameters +// /// - `K`: Key type, must implement `Eq` and `Hash`. +// /// - `E`: Element (value) type. +// /// - `Formed`: The hash map-like formed being built. +// /// - `Context`: Type of the optional context used during the building process. +// /// - `End`: End-of-forming action to be executed upon completion. +// /// +// /// # Examples +// /// ``` +// /// # #[ cfg( all( feature = "enabled", not( feature = "no_std" ) ) ) ] +// /// # { +// /// # use test_tools::exposed::*; +// /// +// /// #[ derive( Debug, PartialEq, former::Former ) ] +// /// pub struct StructWithMap +// /// { +// /// #[ subformer( former::HashMapSubformer ) ] +// /// map : std::collections::HashMap< &'static str, &'static str >, +// /// } +// /// +// /// let struct1 = StructWithMap::former() +// /// .map() +// /// .insert( "a", "b" ) +// /// .insert( "c", "d" ) +// /// .end() +// /// .form() +// /// ; +// /// assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); +// /// +// /// # } +// /// ``` +// +// pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, End > >; diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 1f9c63836e..d2a156e166 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -1,125 +1,125 @@ -//! # HashSetLike Trait and HashSetSubformer Struct -//! -//! This part of the crate provides a flexible interface (`HashSetLike`) and a builder pattern implementation (`HashSetSubformer`) for `HashSet`-like containers. It's designed to extend the builder pattern, allowing for fluent and dynamic construction of sets within custom data structures. - -use super::*; -use collection_tools::HashSet; - -/// A trait for containers behaving like a `HashSet`, allowing insertion operations. -/// -/// Implementing this trait enables the associated formed to be used with `HashSetSubformer`, -/// facilitating a builder pattern that is both intuitive and concise. -/// -/// # Example Implementation -/// -/// Implementing `HashSetLike` for `std::collections::HashSet`: -/// - -pub trait HashSetLike< K > -where - K : core::cmp::Eq + core::hash::Hash, -{ - /// Inserts a key-value pair into the map. - fn insert( &mut self, element : K ) -> Option< K >; -} - -impl< K > HashSetLike< K > for HashSet< K > -where - K : core::cmp::Eq + core::hash::Hash, -{ - fn insert( &mut self, element : K ) -> Option< K > - { - HashSet::replace( self, element ) - } -} - -// = storage - -impl< K > Storage -for HashSet< K > -where - K : ::core::cmp::Eq + ::core::hash::Hash, -{ - // type Definition = HashSetDefinition< K >; - type Formed = HashSet< K >; -} - -impl< K > StoragePerform -for HashSet< K > -where - K : ::core::cmp::Eq + ::core::hash::Hash, -{ - // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed - fn preform( self ) -> Self::Formed - { - self - } -} - -// = definition - -#[ derive( Debug ) ] -pub struct HashSetDefinition< K, Context, End > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - End : FormingEnd< Self >, -{ - _phantom : ::core::marker::PhantomData< ( K, Context, End ) >, -} - -impl< K, Context, End > HashSetDefinition< K, Context, End > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - End : FormingEnd< Self >, -{ - pub fn new() -> Self - { - Self { _phantom : ::core::marker::PhantomData } - } -} - -impl< K, Context, End > FormerDefinition -for HashSetDefinition< K, Context, End > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - End : FormingEnd< Self >, -{ - type Storage = HashSet< K >; - type Formed = HashSet< K >; - type Context = Context; - type End = End; -} - -/// Facilitates building `HashSetLike` containers with a fluent API. -/// -/// `HashSetSubformer` leverages the `HashSetLike` trait to enable a concise and expressive way -/// of populating `HashSet`-like containers. It exemplifies the crate's builder pattern variation for sets. -/// -/// # Example Usage -/// -/// Using `HashSetSubformer` to populate a `HashSet` within a struct: -/// -/// ```rust -/// # #[ cfg( all( feature = "enabled", not( feature = "no_std" ) ) ) ] -/// # { -/// # use test_tools::exposed::*; -/// -/// #[ derive( Debug, PartialEq, former::Former ) ] -/// pub struct StructWithSet -/// { -/// #[ subformer( former::HashSetSubformer ) ] -/// set : std::collections::HashSet< &'static str >, -/// } -/// -/// let instance = StructWithSet::former() -/// .set() -/// .insert( "apple" ) -/// .insert( "banana" ) -/// .end() -/// .form(); -/// -/// assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] }); -/// # } -/// ``` - -pub type HashSetSubformer< K, Context, End > = ContainerSubformer::< K, HashSetDefinition< K, Context, End > >; +// //! # HashSetLike Trait and HashSetSubformer Struct +// //! +// //! This part of the crate provides a flexible interface (`HashSetLike`) and a builder pattern implementation (`HashSetSubformer`) for `HashSet`-like containers. It's designed to extend the builder pattern, allowing for fluent and dynamic construction of sets within custom data structures. +// +// use super::*; +// use collection_tools::HashSet; +// +// /// A trait for containers behaving like a `HashSet`, allowing insertion operations. +// /// +// /// Implementing this trait enables the associated formed to be used with `HashSetSubformer`, +// /// facilitating a builder pattern that is both intuitive and concise. +// /// +// /// # Example Implementation +// /// +// /// Implementing `HashSetLike` for `std::collections::HashSet`: +// /// +// +// pub trait HashSetLike< K > +// where +// K : core::cmp::Eq + core::hash::Hash, +// { +// /// Inserts a key-value pair into the map. +// fn insert( &mut self, element : K ) -> Option< K >; +// } +// +// impl< K > HashSetLike< K > for HashSet< K > +// where +// K : core::cmp::Eq + core::hash::Hash, +// { +// fn insert( &mut self, element : K ) -> Option< K > +// { +// HashSet::replace( self, element ) +// } +// } +// +// // = storage +// +// impl< K > Storage +// for HashSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// // type Definition = HashSetDefinition< K >; +// type Formed = HashSet< K >; +// } +// +// impl< K > StoragePerform +// for HashSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed +// fn preform( self ) -> Self::Formed +// { +// self +// } +// } +// +// // = definition +// +// #[ derive( Debug ) ] +// pub struct HashSetDefinition< K, Context, End > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// End : FormingEnd< Self >, +// { +// _phantom : ::core::marker::PhantomData< ( K, Context, End ) >, +// } +// +// impl< K, Context, End > HashSetDefinition< K, Context, End > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// End : FormingEnd< Self >, +// { +// pub fn new() -> Self +// { +// Self { _phantom : ::core::marker::PhantomData } +// } +// } +// +// impl< K, Context, End > FormerDefinition +// for HashSetDefinition< K, Context, End > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// End : FormingEnd< Self >, +// { +// type Storage = HashSet< K >; +// type Formed = HashSet< K >; +// type Context = Context; +// type End = End; +// } +// +// /// Facilitates building `HashSetLike` containers with a fluent API. +// /// +// /// `HashSetSubformer` leverages the `HashSetLike` trait to enable a concise and expressive way +// /// of populating `HashSet`-like containers. It exemplifies the crate's builder pattern variation for sets. +// /// +// /// # Example Usage +// /// +// /// Using `HashSetSubformer` to populate a `HashSet` within a struct: +// /// +// /// ```rust +// /// # #[ cfg( all( feature = "enabled", not( feature = "no_std" ) ) ) ] +// /// # { +// /// # use test_tools::exposed::*; +// /// +// /// #[ derive( Debug, PartialEq, former::Former ) ] +// /// pub struct StructWithSet +// /// { +// /// #[ subformer( former::HashSetSubformer ) ] +// /// set : std::collections::HashSet< &'static str >, +// /// } +// /// +// /// let instance = StructWithSet::former() +// /// .set() +// /// .insert( "apple" ) +// /// .insert( "banana" ) +// /// .end() +// /// .form(); +// /// +// /// assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] }); +// /// # } +// /// ``` +// +// pub type HashSetSubformer< K, Context, End > = ContainerSubformer::< K, HashSetDefinition< K, Context, End > >; diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 99132431a6..a928b06e29 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -1,83 +1,83 @@ -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 ); - } -} - +// use super::*; +// use axiomatic::*; // - -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 - } -} - +// #[ allow( unused ) ] +// use collection_tools::Vec; // - -#[ 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 > >; +// /// 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 > >; From e55b71be3acba0c6c0d856be827ad553f743cb8d Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 24 Mar 2024 09:42:57 +0200 Subject: [PATCH 024/533] former : experimenting --- module/core/former/src/vector.rs | 184 ++++++++++-------- .../inc/former_tests/container_former_vec.rs | 15 +- 2 files changed, 114 insertions(+), 85 deletions(-) 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 ); // From 008eec469b3850607068b4ba1ebf46d6e3854976 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 24 Mar 2024 09:44:20 +0200 Subject: [PATCH 025/533] former : experimenting --- .../former/tests/inc/former_tests/container_former_vec.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 23f26061a6..d4a6ec9251 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 @@ -39,8 +39,8 @@ fn push() { f1( former::VectorDefinition1::< String, () >::new() ); - // f2( former::VectorDefinition2::< String, (), the_module::ReturnStorage >::new() ); - // f3::< former::VectorDefinition< String, (), the_module::ReturnStorage >, _ >( the_module::ReturnStorage ); + f2( former::VectorDefinition2::< String, (), the_module::ReturnStorage >::new() ); + f3::< former::VectorDefinition1< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage ); // From 6840c75113a58e10738f92da449f0f81ee753eed Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 24 Mar 2024 09:45:22 +0200 Subject: [PATCH 026/533] former : experimenting --- .../core/former/tests/inc/former_tests/container_former_vec.rs | 1 + 1 file changed, 1 insertion(+) 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 d4a6ec9251..0425da377c 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 @@ -41,6 +41,7 @@ fn push() f1( former::VectorDefinition1::< String, () >::new() ); f2( former::VectorDefinition2::< String, (), the_module::ReturnStorage >::new() ); f3::< former::VectorDefinition1< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage ); + f3::< former::VectorDefinition2< String, (), _ >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage ); // From 773867bbd6a67e8d18c041123ca1864910a1427f Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 24 Mar 2024 09:45:38 +0200 Subject: [PATCH 027/533] former : experimenting --- .../core/former/tests/inc/former_tests/container_former_vec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0425da377c..df794eae7b 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 @@ -41,7 +41,7 @@ fn push() f1( former::VectorDefinition1::< String, () >::new() ); f2( former::VectorDefinition2::< String, (), the_module::ReturnStorage >::new() ); f3::< former::VectorDefinition1< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage ); - f3::< former::VectorDefinition2< String, (), _ >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage ); + // f3::< former::VectorDefinition2< String, (), _ >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage ); // From c559c9d4351a73f1f219094bdecc28eb609b0d86 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 24 Mar 2024 20:08:08 +0200 Subject: [PATCH 028/533] former : experimenting --- module/core/former/src/vector.rs | 52 +++-- .../inc/former_tests/container_former_vec.rs | 185 ++++++++++-------- 2 files changed, 141 insertions(+), 96 deletions(-) diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 990cea0bac..55548cc8f2 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -23,7 +23,7 @@ impl< E > VectorLike< E > for Vec< E > } } -// +// = storage impl< E > Storage for Vec< E > @@ -42,18 +42,17 @@ for Vec< E > } } -// +// = definition #[ derive( Debug ) ] -// pub struct VectorDefinition1< E, Context = (), End = ReturnStorage > -pub struct VectorDefinition1< E, Context > +pub struct VectorDefinitionTypes< E, Context = () > where Self : FormerDefinition, { _phantom : core::marker::PhantomData< ( E, Context ) >, } -impl< E, Context > VectorDefinition1< E, Context > +impl< E, Context > VectorDefinitionTypes< E, Context > { pub fn new() -> Self { @@ -62,7 +61,7 @@ impl< E, Context > VectorDefinition1< E, Context > } impl< E, Context > FormerDefinition -for VectorDefinition1< E, Context > +for VectorDefinitionTypes< E, Context > { type Storage = Vec< E >; type Formed = Vec< E >; @@ -70,17 +69,17 @@ for VectorDefinition1< E, Context > } #[ derive( Debug ) ] -// pub struct VectorDefinition2< E, Context = (), End = ReturnStorage > -pub struct VectorDefinition2< E, Context, End > +pub struct VectorDefinition< E, Context = (), End = ReturnStorage > +// pub struct VectorDefinition< E, Context, End > where - End : FormingEnd< VectorDefinition1< E, Context > >, + End : FormingEnd< VectorDefinitionTypes< E, Context > >, { _phantom : core::marker::PhantomData< ( E, Context, End ) >, } -impl< E, Context, End > VectorDefinition2< E, Context, End > +impl< E, Context, End > VectorDefinition< E, Context, End > where - End : FormingEnd< VectorDefinition1< E, Context > >, + End : FormingEnd< VectorDefinitionTypes< E, Context > >, { pub fn new() -> Self { @@ -89,17 +88,40 @@ where } impl< E, Context, End > FormerDefinition2 -for VectorDefinition2< E, Context, End > +for VectorDefinition< E, Context, End > where - End : FormingEnd< VectorDefinition1< E, Context > >, + End : FormingEnd< VectorDefinitionTypes< E, Context > >, { - type Definition = VectorDefinition1< E, Context >; + type Definition = VectorDefinitionTypes< E, Context >; type End = End; } +// = subformer + /// 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 > >; +pub type VectorSubformer< E, Context, End > = ContainerSubformer::< E, VectorDefinition< E, Context, End > >; + +// = extension + +pub trait VecExt< E > : sealed::Sealed +{ + fn former() -> VectorSubformer< E, (), ReturnStorage >; +} + +impl< E > VecExt< E > for Vec< E > +{ + fn former() -> VectorSubformer< E, (), ReturnStorage > + { + VectorSubformer::< E, (), ReturnStorage >::new() + } +} + +mod sealed +{ + pub trait Sealed {} + impl< E > Sealed for Vec< E > {} +} 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 df794eae7b..90d7e4d08a 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 @@ -4,92 +4,115 @@ use super::*; #[ allow( unused_imports ) ] use collection_tools::Vec; -// impl< Definition, T > FormingEnd< Definition > -// for ReturnStorage -// where -// Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = Self >, - -pub fn f1< Definition >( x : Definition ) -where - Definition : former::FormerDefinition, +#[ test ] +fn definitions() { -} -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 >, -{ -} + pub fn f1< Definition >( _x : Definition ) + where + Definition : former::FormerDefinition, + { + } + + 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 >, + { + } -// impl former::FormingEnd> for former::ReturnStorage { -// fn call(&self, storage: former::VectorDefinition::Storage, context: Option::Context>) -> former::VectorDefinition::Formed { -// storage -// } -// } + f1( former::VectorDefinitionTypes::< String, () >::new() ); + f2( former::VectorDefinition::< String, (), the_module::ReturnStorage >::new() ); + f3::< former::VectorDefinitionTypes< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage ); + f3::< < former::VectorDefinition< String, (), the_module::ReturnStorage > as the_module::FormerDefinition2 >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage ); + +} #[ test ] fn push() { - f1( former::VectorDefinition1::< String, () >::new() ); - f2( former::VectorDefinition2::< String, (), the_module::ReturnStorage >::new() ); - f3::< former::VectorDefinition1< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage ); - // f3::< former::VectorDefinition2< String, (), _ >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage ); + // + + let got : Vec< String > = the_module + ::ContainerSubformer + ::< String, former::VectorDefinition< String, (), the_module::ReturnStorage > > + ::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, (), the_module::ReturnStorage >, + >::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, (), the_module::ReturnStorage > > - // ::new() - // .push( "a" ) - // .push( "b" ) - // .form(); - // let exp = vec! - // [ - // "a".to_string(), - // "b".to_string(), - // ]; - // a_id!( got, exp ); - - // Definition : FormerDefinition< Context = (), Storage = T, Formed = T, End = Self >, + let got : Vec< String > = the_module::VectorSubformer::< String, (), the_module::ReturnStorage >::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, (), the_module::ReturnStorage >, - // >::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::VectorSubformer::< 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::VectorSubformer::new() + .push( "a" ) + .push( "b" ) + .form(); + let exp = vec! + [ + "a".to_string(), + "b".to_string(), + ]; + a_id!( got, exp ); + + // + + use the_module::VecExt; + let got : Vec< String > = Vec::former() + .push( "a" ) + .push( "b" ) + .form(); + let exp = vec! + [ + "a".to_string(), + "b".to_string(), + ]; + a_id!( got, exp ); + + // } @@ -97,15 +120,15 @@ fn push() fn replace() { - // let got : Vec< String > = the_module::VectorSubformer::new() - // .push( "x" ) - // .replace( vec![ "a".to_string(), "b".to_string() ] ) - // .form(); - // let exp = vec! - // [ - // "a".to_string(), - // "b".to_string(), - // ]; - // a_id!( got, exp ); + let got : Vec< String > = the_module::VectorSubformer::new() + .push( "x" ) + .replace( vec![ "a".to_string(), "b".to_string() ] ) + .form(); + let exp = vec! + [ + "a".to_string(), + "b".to_string(), + ]; + a_id!( got, exp ); } From c5f9ccc1d0d1133cc88902b5c6a1554b457094ce Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 24 Mar 2024 23:43:37 +0200 Subject: [PATCH 029/533] former : experimenting --- module/core/former/src/axiomatic.rs | 3 +- .../inc/former_tests/container_former_vec.rs | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 50ed77f42f..d233532744 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -17,7 +17,8 @@ pub trait StoragePerform : Storage pub trait FormerDefinition : Sized { // type Storage : Storage< Definition = Self >; - type Storage : Storage< Formed = Self::Formed >; + // type Storage : Storage< Formed = Self::Formed >; + type Storage : Default; type Formed; type Context; // type End : FormingEnd< Self >; 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 90d7e4d08a..1be6be27ca 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 @@ -35,6 +35,8 @@ fn definitions() } +// + #[ test ] fn push() { @@ -116,6 +118,8 @@ fn push() } +// + #[ test ] fn replace() { @@ -132,3 +136,35 @@ fn replace() a_id!( got, exp ); } + +// + +#[ test ] +fn custom_end() +{ + + // xxx2 : continue + // struct Return13; + // impl former::FormerDefinition for Return13 + // { + // type Storage = Vec< u32 >; + // type Formed = i32; + // type Context = (); + // } + + // fn return_13( _storage : Vec< i32 >, _context : Option< () > ) -> i32 + // { + // 13 + // } + // let end_wrapper = the_module::FormingEndWrapper::new( return_13 ); + + // let got : i32 = the_module::VectorSubformer::< String, (), return_13 >::new() + // .push( "a" ) + // .push( "b" ) + // .form(); + // let exp = 13; + // a_id!( got, exp ); + +} + +// From 007007683c76c7b4fb3ce967f095ae3bd1a3b3e2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 25 Mar 2024 00:06:02 +0200 Subject: [PATCH 030/533] former : experimenting --- module/core/former/src/vector.rs | 39 ++++++++--------- .../inc/former_tests/container_former_vec.rs | 43 ++++++++++--------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 55548cc8f2..585157674d 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -45,14 +45,14 @@ for Vec< E > // = definition #[ derive( Debug ) ] -pub struct VectorDefinitionTypes< E, Context = () > +pub struct VectorDefinitionTypes< E, Context = (), Formed = Vec< E > > where Self : FormerDefinition, { - _phantom : core::marker::PhantomData< ( E, Context ) >, + _phantom : core::marker::PhantomData< ( E, Context, Formed ) >, } -impl< E, Context > VectorDefinitionTypes< E, Context > +impl< E, Context, Formed > VectorDefinitionTypes< E, Context, Formed > { pub fn new() -> Self { @@ -60,26 +60,25 @@ impl< E, Context > VectorDefinitionTypes< E, Context > } } -impl< E, Context > FormerDefinition -for VectorDefinitionTypes< E, Context > +impl< E, Context, Formed > FormerDefinition +for VectorDefinitionTypes< E, Context, Formed > { type Storage = Vec< E >; - type Formed = Vec< E >; + type Formed = Formed; type Context = Context; } #[ derive( Debug ) ] -pub struct VectorDefinition< E, Context = (), End = ReturnStorage > -// pub struct VectorDefinition< E, Context, End > +pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > where - End : FormingEnd< VectorDefinitionTypes< E, Context > >, + End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, { - _phantom : core::marker::PhantomData< ( E, Context, End ) >, + _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, } -impl< E, Context, End > VectorDefinition< E, Context, End > +impl< E, Context, Formed, End > VectorDefinition< E, Context, Formed, End > where - End : FormingEnd< VectorDefinitionTypes< E, Context > >, + End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, { pub fn new() -> Self { @@ -87,12 +86,12 @@ where } } -impl< E, Context, End > FormerDefinition2 -for VectorDefinition< E, Context, End > +impl< E, Context, Formed, End > FormerDefinition2 +for VectorDefinition< E, Context, Formed, End > where - End : FormingEnd< VectorDefinitionTypes< E, Context > >, + End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, { - type Definition = VectorDefinitionTypes< E, Context >; + type Definition = VectorDefinitionTypes< E, Context, Formed >; type End = End; } @@ -103,20 +102,20 @@ where /// `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 > >; +pub type VectorSubformer< E, Context, Formed, End > = ContainerSubformer::< E, VectorDefinition< E, Context, Formed, End > >; // = extension pub trait VecExt< E > : sealed::Sealed { - fn former() -> VectorSubformer< E, (), ReturnStorage >; + fn former() -> VectorSubformer< E, (), Vec< E >, ReturnStorage >; } impl< E > VecExt< E > for Vec< E > { - fn former() -> VectorSubformer< E, (), ReturnStorage > + fn former() -> VectorSubformer< E, (), Vec< E >, ReturnStorage > { - VectorSubformer::< E, (), ReturnStorage >::new() + VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new() } } 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 1be6be27ca..30bd0b8dad 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 @@ -29,9 +29,9 @@ fn definitions() } f1( former::VectorDefinitionTypes::< String, () >::new() ); - f2( former::VectorDefinition::< String, (), the_module::ReturnStorage >::new() ); + f2( former::VectorDefinition::< String, (), Vec< String >, the_module::ReturnStorage >::new() ); f3::< former::VectorDefinitionTypes< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage ); - f3::< < former::VectorDefinition< String, (), the_module::ReturnStorage > as the_module::FormerDefinition2 >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage ); + f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > as the_module::FormerDefinition2 >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage ); } @@ -45,7 +45,7 @@ fn push() let got : Vec< String > = the_module ::ContainerSubformer - ::< String, former::VectorDefinition< String, (), the_module::ReturnStorage > > + ::< String, former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > > ::new() .push( "a" ) .push( "b" ) @@ -62,7 +62,7 @@ fn push() let got : Vec< String > = the_module::ContainerSubformer:: < String, - former::VectorDefinition< String, (), the_module::ReturnStorage >, + former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage >, >::new() .push( "a" ) .push( "b" ) @@ -76,7 +76,7 @@ fn push() // - let got : Vec< String > = the_module::VectorSubformer::< String, (), the_module::ReturnStorage >::new() + let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage >::new() .push( "a" ) .push( "b" ) .form(); @@ -144,27 +144,30 @@ fn custom_end() { // xxx2 : continue - // struct Return13; - // impl former::FormerDefinition for Return13 - // { - // type Storage = Vec< u32 >; - // type Formed = i32; - // type Context = (); - // } - - // fn return_13( _storage : Vec< i32 >, _context : Option< () > ) -> i32 - // { - // 13 - // } - // let end_wrapper = the_module::FormingEndWrapper::new( return_13 ); - - // let got : i32 = the_module::VectorSubformer::< String, (), return_13 >::new() + struct Return13; + impl former::FormerDefinition for Return13 + { + type Storage = Vec< String >; + type Formed = i32; + type Context = (); + } + + fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 + { + 13 + } + + let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); + + // let got : i32 = the_module::VectorSubformer::< String, (), _ >::begin( None, (), return_13 ) // .push( "a" ) // .push( "b" ) // .form(); // let exp = 13; // a_id!( got, exp ); + // pub type VectorSubformer< E, Context, End > = ContainerSubformer::< E, VectorDefinition< E, Context, End > >; + } // From 98995c6c28172da90d096b502e7964b3ffb272ec Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 25 Mar 2024 00:06:56 +0200 Subject: [PATCH 031/533] former : experimenting --- .../former/tests/inc/former_tests/container_former_vec.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 30bd0b8dad..a7c1494695 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 @@ -159,10 +159,10 @@ fn custom_end() let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); - // let got : i32 = the_module::VectorSubformer::< String, (), _ >::begin( None, (), return_13 ) - // .push( "a" ) - // .push( "b" ) - // .form(); + let got : i32 = the_module::VectorSubformer::< String, (), i32, _ >::begin( None, None, return_13 ) + .push( "a" ) + .push( "b" ) + .form(); // let exp = 13; // a_id!( got, exp ); From 2d9841efdca11530028e3beeca4c837fe58818d6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 25 Mar 2024 00:13:47 +0200 Subject: [PATCH 032/533] former : experimenting --- .../inc/former_tests/container_former_vec.rs | 58 ++++++++++++++----- 1 file changed, 43 insertions(+), 15 deletions(-) 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 a7c1494695..754b301026 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 @@ -140,33 +140,61 @@ fn replace() // #[ test ] -fn custom_end() +fn begin_and_custom_end() { // xxx2 : continue - struct Return13; - impl former::FormerDefinition for Return13 - { - type Storage = Vec< String >; - type Formed = i32; - type Context = (); - } + // struct Return13; + // impl former::FormerDefinition for Return13 + // { + // type Storage = Vec< String >; + // type Formed = i32; + // type Context = (); + // } +// +// fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 +// { +// 13 +// } +// +// let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); - fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 + // xxx : make example with that + + // basic case + + fn return_13( _storage : Vec< String >, context : Option< () > ) -> f32 { - 13 + 13.1 } + let got = the_module::VectorSubformer::begin( None, None, return_13 ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13.1; + a_id!( got, exp ); - let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); + // with a context - let got : i32 = the_module::VectorSubformer::< String, (), i32, _ >::begin( None, None, return_13 ) + fn context_plus_13( _storage : Vec< String >, context : Option< f32 > ) -> f32 + { + if let Some( context ) = context + { + 13.1 + context + } + else + { + 13.1 + } + } + let got = the_module::VectorSubformer::begin( None, Some( 10.0 ), context_plus_13 ) .push( "a" ) .push( "b" ) .form(); - // let exp = 13; - // a_id!( got, exp ); + let exp = 23.1; + a_id!( got, exp ); - // pub type VectorSubformer< E, Context, End > = ContainerSubformer::< E, VectorDefinition< E, Context, End > >; + // } From 9bcd4764b63a8d32e471b98520fad6cdc3972ca2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 25 Mar 2024 00:30:18 +0200 Subject: [PATCH 033/533] former : experimenting --- module/core/former/src/vector.rs | 52 +++++++++--------- .../inc/former_tests/container_former_vec.rs | 55 +++++++++++++------ 2 files changed, 62 insertions(+), 45 deletions(-) diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 585157674d..81e35bd96d 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -28,14 +28,12 @@ impl< E > VectorLike< E > for Vec< E > 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 @@ -45,14 +43,14 @@ for Vec< E > // = definition #[ derive( Debug ) ] -pub struct VectorDefinitionTypes< E, Context = (), Formed = Vec< E > > -where - Self : FormerDefinition, +pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > +// where + // Self : FormerDefinition, { - _phantom : core::marker::PhantomData< ( E, Context, Formed ) >, + _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, } -impl< E, Context, Formed > VectorDefinitionTypes< E, Context, Formed > +impl< E, Context, Formed > VectorDefinition< E, Context, Formed > { pub fn new() -> Self { @@ -61,37 +59,37 @@ impl< E, Context, Formed > VectorDefinitionTypes< E, Context, Formed > } impl< E, Context, Formed > FormerDefinition -for VectorDefinitionTypes< E, Context, Formed > +for VectorDefinition< E, Context, Formed > { type Storage = Vec< E >; type Formed = Formed; type Context = Context; } -#[ derive( Debug ) ] -pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > -where - End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, -{ - _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, -} - -impl< E, Context, Formed, End > VectorDefinition< E, Context, Formed, End > -where - End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, -{ - pub fn new() -> Self - { - Self { _phantom : core::marker::PhantomData } - } -} +// #[ derive( Debug ) ] +// pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > +// where +// End : FormingEnd< VectorDefinition< E, Context, Formed > >, +// { +// _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, +// } + +// impl< E, Context, Formed, End > VectorDefinition< E, Context, Formed, End > +// where +// End : FormingEnd< VectorDefinition< E, Context, Formed > >, +// { +// pub fn new() -> Self +// { +// Self { _phantom : core::marker::PhantomData } +// } +// } impl< E, Context, Formed, End > FormerDefinition2 for VectorDefinition< E, Context, Formed, End > where - End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, + End : FormingEnd< VectorDefinition< E, Context, Formed > >, { - type Definition = VectorDefinitionTypes< E, Context, Formed >; + type Definition = VectorDefinition< E, Context, Formed >; type End = 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 754b301026..cf4a77df49 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 @@ -28,9 +28,9 @@ fn definitions() { } - f1( former::VectorDefinitionTypes::< String, () >::new() ); + f1( former::VectorDefinition::< String, () >::new() ); f2( former::VectorDefinition::< String, (), Vec< String >, the_module::ReturnStorage >::new() ); - f3::< former::VectorDefinitionTypes< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage ); + f3::< former::VectorDefinition< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage ); f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > as the_module::FormerDefinition2 >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage ); } @@ -143,22 +143,6 @@ fn replace() fn begin_and_custom_end() { - // xxx2 : continue - // struct Return13; - // impl former::FormerDefinition for Return13 - // { - // type Storage = Vec< String >; - // type Formed = i32; - // type Context = (); - // } -// -// fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 -// { -// 13 -// } -// -// let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); - // xxx : make example with that // basic case @@ -199,3 +183,38 @@ fn begin_and_custom_end() } // + +#[ test ] +fn custom_definition() +{ + + // xxx2 : continue + struct Return13; + impl former::FormerDefinition for Return13 + { + type Storage = Vec< String >; + type Formed = i32; + type Context = (); + } + + // impl former::FormerDefinition2 for Return13 + // { + // type Definition = Return13; + // type End = former::ReturnStorage; + // } + + fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 + { + 13 + } + + let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); + + // + + // let got = ContainerSubformer::< E, VectorDefinition< E, Context, Formed, End > > + + +} + +// From 30ab77ca609dff5c3e75af43f502303b263edffd Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 25 Mar 2024 00:36:25 +0200 Subject: [PATCH 034/533] former : experimenting --- module/core/former/src/axiomatic.rs | 40 ++++++++-------- module/core/former/src/container.rs | 46 +++++++++---------- module/core/former/src/hash_map.rs | 8 ++-- module/core/former/src/hash_set.rs | 6 +-- module/core/former/src/vector.rs | 8 ++-- .../inc/former_tests/a_primitives_manual.rs | 18 ++++---- .../inc/former_tests/container_former_vec.rs | 14 +++--- .../inc/former_tests/only_test/primitives.rs | 6 +-- 8 files changed, 73 insertions(+), 73 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index d233532744..c945c0a954 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -2,19 +2,19 @@ pub trait Storage : ::core::default::Default { - // type Definition : FormerDefinition< Storage = Self >; + // type Types : FormerDefinitionTypes< Storage = Self >; type Formed; } /// xxx pub trait StoragePerform : Storage { - // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed; + // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed; fn preform( self ) -> Self::Formed; } /// xxx -pub trait FormerDefinition : Sized +pub trait FormerDefinitionTypes : Sized { // type Storage : Storage< Definition = Self >; // type Storage : Storage< Formed = Self::Formed >; @@ -25,19 +25,19 @@ pub trait FormerDefinition : Sized } /// xxx -pub trait FormerDefinition2 : Sized +pub trait FormerDefinition : Sized { - type Definition : FormerDefinition; - type End : FormingEnd< Self::Definition >; + type Types : FormerDefinitionTypes; + type End : FormingEnd< Self::Types >; } -// pub trait FormerDefinition +// pub trait FormerDefinitionTypes // { // type Storage : StoragePerform< Formed = Self::Formed >; // type Formed; // type Context; -// type FormerDefinition : FormerDefinition< Storage = Self::Storage, Formed = Self::Formed >; -// type End : FormingEnd< Self::FormerDefinition, Self::Context >; +// type FormerDefinitionTypes : FormerDefinitionTypes< Storage = Self::Storage, Formed = Self::Formed >; +// type End : FormingEnd< Self::FormerDefinitionTypes, Self::Context >; // } /// Defines a handler for the end of a subforming process, enabling the return of the original context. @@ -48,7 +48,7 @@ pub trait FormerDefinition2 : Sized /// # Parameters /// - `Storage`: The type of the container being processed. /// - `Context`: The type of the context that might be altered or returned upon completion. -pub trait FormingEnd< Definition : FormerDefinition > +pub trait FormingEnd< Definition : FormerDefinitionTypes > { /// Called at the end of the subforming process to return the modified or original context. /// @@ -64,7 +64,7 @@ pub trait FormingEnd< Definition : FormerDefinition > impl< Definition, F > FormingEnd< Definition > for F where F : Fn( Definition::Storage, core::option::Option< Definition::Context > ) -> Definition::Formed, - Definition : FormerDefinition, + Definition : FormerDefinitionTypes, { #[ inline( always ) ] fn call( &self, storage : Definition::Storage, context : core::option::Option< Definition::Context > ) -> Definition::Formed @@ -84,7 +84,7 @@ where // for ReturnFormed // where // Definition::Storage : StoragePerform< Formed = Definition::Formed >, -// Definition : FormerDefinition< Context = () >, +// Definition : FormerDefinitionTypes< Context = () >, // { // #[ inline( always ) ] // fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed @@ -100,7 +100,7 @@ pub struct ReturnStorage; impl< Definition, T > FormingEnd< Definition > for ReturnStorage where - Definition : FormerDefinition< Context = (), Storage = T, Formed = T >, + Definition : FormerDefinitionTypes< Context = (), Storage = T, Formed = T >, // Definition::End : FormingEnd< Definition >, // Definition::End : Self, // Definition::Storage : Default, @@ -119,14 +119,14 @@ where /// a closure needs to be stored or passed around as an object implementing /// `FormingEnd`. #[ cfg( not( feature = "no_std" ) ) ] -pub struct FormingEndWrapper< Definition : FormerDefinition > +pub struct FormingEndWrapper< Definition : FormerDefinitionTypes > { closure : Box< dyn Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed >, _marker : std::marker::PhantomData< Definition::Storage >, } #[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinition > FormingEndWrapper< Definition > +impl< Definition : FormerDefinitionTypes > FormingEndWrapper< Definition > { /// Constructs a new `FormingEndWrapper` with the provided closure. /// @@ -152,7 +152,7 @@ impl< Definition : FormerDefinition > FormingEndWrapper< Definition > #[ cfg( not( feature = "no_std" ) ) ] use std::fmt; #[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinition > fmt::Debug for FormingEndWrapper< Definition > +impl< Definition : FormerDefinitionTypes > fmt::Debug for FormingEndWrapper< Definition > { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { @@ -164,7 +164,7 @@ impl< Definition : FormerDefinition > fmt::Debug for FormingEndWrapper< Definiti } #[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinition > FormingEnd< Definition > +impl< Definition : FormerDefinitionTypes > FormingEnd< Definition > for FormingEndWrapper< Definition > { fn call( &self, storage : Definition::Storage, context : Option< Definition::Context > ) -> Definition::Formed @@ -188,7 +188,7 @@ for FormingEndWrapper< Definition > /// sequences within builder patterns. // xxx : update description -pub trait FormerBegin< Definition : FormerDefinition2 > +pub trait FormerBegin< Definition : FormerDefinition > { /// * `End` - A trait bound marking the closure or handler invoked upon completing the subforming process. Implementers @@ -208,8 +208,8 @@ pub trait FormerBegin< Definition : FormerDefinition2 > /// * `on_end` - A completion handler responsible for transforming the accumulated `Storage` into the final `Formed` structure. fn _begin ( - storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >, - context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >, + storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, on_end : Definition::End, ) -> Self; diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 4a72d03220..57406a4eca 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -198,24 +198,24 @@ where pub struct ContainerSubformer< E, Definition > where // End : FormingEnd< Definition >, - Definition : FormerDefinition2, - < Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >, + Definition : FormerDefinition, + < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, { - storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >, - context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >, + storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, on_end : core::option::Option< Definition::End >, } impl< E, Definition > ContainerSubformer< E, Definition > where // End : FormingEnd< Definition >, - Definition : FormerDefinition2, - < Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >, + Definition : FormerDefinition, + < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, { /// Form current former into target structure. #[ inline( always ) ] - pub fn storage( mut self ) -> < Definition::Definition as FormerDefinition >::Storage + pub fn storage( mut self ) -> < Definition::Types as FormerDefinitionTypes >::Storage { let storage = if self.storage.is_some() { @@ -233,8 +233,8 @@ where #[ inline( always ) ] pub fn begin ( - storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >, - context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >, + storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, on_end : Definition::End, ) -> Self { @@ -248,7 +248,7 @@ where /// Finalizes the building process, returning the formed or a context incorporating it. #[ inline( always ) ] - pub fn end( mut self ) -> < Definition::Definition as FormerDefinition >::Formed + pub fn end( mut self ) -> < Definition::Types as FormerDefinitionTypes >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); @@ -258,14 +258,14 @@ where /// Finalizes the building process, returning the formed or a context incorporating it. #[ inline( always ) ] - pub fn form( self ) -> < Definition::Definition as FormerDefinition >::Formed + pub fn form( self ) -> < Definition::Types as FormerDefinitionTypes >::Formed { self.end() } /// Replaces the current storage with a provided one, allowing for a reset or redirection of the building process. #[ inline( always ) ] - pub fn replace( mut self, vector : < Definition::Definition as FormerDefinition >::Storage ) -> Self + pub fn replace( mut self, vector : < Definition::Types as FormerDefinitionTypes >::Storage ) -> Self { self.storage = Some( vector ); self @@ -273,12 +273,12 @@ where } -impl< E, T, Definition, Definition1 > ContainerSubformer< E, Definition > +impl< E, T, Types, Definition > ContainerSubformer< E, Definition > where - Definition1 : FormerDefinition< Context = (), Storage = T, Formed = T >, - Definition : FormerDefinition2< Definition = Definition1, End = ReturnStorage >, - < Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >, - < Definition::Definition as FormerDefinition >::Storage : StoragePerform< Formed = < Definition::Definition as FormerDefinition >::Formed >, + Types : FormerDefinitionTypes< Context = (), Storage = T, Formed = T >, + Definition : FormerDefinition< Types = Types, End = ReturnStorage >, + < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, + < Definition::Types as FormerDefinitionTypes >::Storage : StoragePerform< Formed = < Definition::Types as FormerDefinitionTypes >::Formed >, { /// Initializes a new `ContainerSubformer` instance, starting with an empty formed. @@ -304,8 +304,8 @@ where impl< E, Definition > ContainerSubformer< E, Definition > where // End : FormingEnd< Definition >, - Definition : FormerDefinition2, - < Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >, + Definition : FormerDefinition, + < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, { /// Appends an element to the end of the storage, expanding the internal collection. @@ -333,16 +333,16 @@ impl< E, Definition > FormerBegin< Definition > for ContainerSubformer< E, Definition > where // End : FormingEnd< Definition >, - Definition : FormerDefinition2, - < Definition::Definition as FormerDefinition >::Storage : ContainerAdd< Element = E >, + Definition : FormerDefinition, + < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, { // type End = Definition::End; #[ inline( always ) ] fn _begin ( - storage : core::option::Option< < Definition::Definition as FormerDefinition >::Storage >, - context : core::option::Option< < Definition::Definition as FormerDefinition >::Context >, + storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, on_end : Definition::End, ) -> Self diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 293cfe2d19..4b54113128 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -21,7 +21,7 @@ // // // /// Return former. // // #[ inline( always ) ] -// // fn former< Definition : FormerDefinition >( self ) +// // fn former< Definition : FormerDefinitionTypes >( self ) // // -> // // HashMapSubformer< K, E, Definition, (), impl FormingEnd< Self, Self > > // // { @@ -52,7 +52,7 @@ // where // K : ::core::cmp::Eq + ::core::hash::Hash, // { -// // type Definition = HashMapDefinition< K, E >; +// // type Types = HashMapDefinition< K, E >; // type Formed = HashMap< K, E >; // } // @@ -61,7 +61,7 @@ // where // K : ::core::cmp::Eq + ::core::hash::Hash, // { -// // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed +// // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed // fn preform( self ) -> Self::Formed // { // self @@ -90,7 +90,7 @@ // } // } // -// impl< K, E, Context, End > FormerDefinition +// impl< K, E, Context, End > FormerDefinitionTypes // for HashMapDefinition< K, E, Context, End > // where // K : ::core::cmp::Eq + ::core::hash::Hash, diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index d2a156e166..60c3f974be 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -40,7 +40,7 @@ // where // K : ::core::cmp::Eq + ::core::hash::Hash, // { -// // type Definition = HashSetDefinition< K >; +// // type Types = HashSetDefinition< K >; // type Formed = HashSet< K >; // } // @@ -49,7 +49,7 @@ // where // K : ::core::cmp::Eq + ::core::hash::Hash, // { -// // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinition >::Formed +// // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed // fn preform( self ) -> Self::Formed // { // self @@ -78,7 +78,7 @@ // } // } // -// impl< K, Context, End > FormerDefinition +// impl< K, Context, End > FormerDefinitionTypes // for HashSetDefinition< K, Context, End > // where // K : ::core::cmp::Eq + ::core::hash::Hash, diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 81e35bd96d..27a4589863 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -45,7 +45,7 @@ for Vec< E > #[ derive( Debug ) ] pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > // where - // Self : FormerDefinition, + // Self : FormerDefinitionTypes, { _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, } @@ -58,7 +58,7 @@ impl< E, Context, Formed > VectorDefinition< E, Context, Formed > } } -impl< E, Context, Formed > FormerDefinition +impl< E, Context, Formed > FormerDefinitionTypes for VectorDefinition< E, Context, Formed > { type Storage = Vec< E >; @@ -84,12 +84,12 @@ for VectorDefinition< E, Context, Formed > // } // } -impl< E, Context, Formed, End > FormerDefinition2 +impl< E, Context, Formed, End > FormerDefinition for VectorDefinition< E, Context, Formed, End > where End : FormingEnd< VectorDefinition< E, Context, Formed > >, { - type Definition = VectorDefinition< E, Context, Formed >; + type Types = VectorDefinition< E, Context, Formed >; type End = End; } diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 0edae1ced2..2ae6d728fa 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -34,7 +34,7 @@ impl Struct1FormerDefinition } } -impl former::FormerDefinition +impl former::FormerDefinitionTypes for Struct1FormerDefinition { type Storage = Struct1FormerStorage; @@ -72,14 +72,14 @@ impl Default for Struct1FormerStorage impl former::Storage for Struct1FormerStorage { - type Definition = Struct1FormerDefinition; + type Types = Struct1FormerDefinition; } impl former::StoragePerform for Struct1FormerStorage { - fn preform( mut self ) -> < < Self as former::Storage >::Definition as former::FormerDefinition >::Formed + fn preform( mut self ) -> < < Self as former::Storage >::Definition as former::FormerDefinitionTypes >::Formed { let int_1 = if self.int_1.is_some() @@ -121,7 +121,7 @@ for Struct1FormerStorage }; // Rust failt to use parameter here - // < < Self as former::Storage >::Definition as former::FormerDefinition >::Formed + // < < Self as former::Storage >::Definition as former::FormerDefinitionTypes >::Formed Struct1 { int_1, @@ -154,13 +154,13 @@ where FormerEnd: the_module::FormingEnd< Struct1FormerDefinition, FormerContext >, { - fn preform( self ) -> < Struct1FormerDefinition as former::FormerDefinition >::Formed + fn preform( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed { former::StoragePerform::preform( self.storage ) } #[ inline( always ) ] - pub fn perform(self) -> < Struct1FormerDefinition as former::FormerDefinition >::Formed + pub fn perform(self) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed { let result = self.form(); return result; @@ -169,7 +169,7 @@ where #[ inline( always ) ] pub fn begin ( - mut storage : core::option::Option< < Struct1FormerDefinition as former::FormerDefinition >::Storage >, + mut storage : core::option::Option< < Struct1FormerDefinition as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< FormerContext >, on_end : FormerEnd, // xxx : cover by test existance of these 3 parameters in the function @@ -188,7 +188,7 @@ where } #[ inline( always ) ] - pub fn end( mut self ) -> < Struct1FormerDefinition as former::FormerDefinition >::Formed + pub fn end( mut self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); @@ -196,7 +196,7 @@ where } #[ inline( always ) ] - pub fn form( self ) -> < Struct1FormerDefinition as former::FormerDefinition >::Formed + pub fn form( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed { self.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 cf4a77df49..98adf95886 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 @@ -11,19 +11,19 @@ fn definitions() pub fn f1< Definition >( _x : Definition ) where - Definition : former::FormerDefinition, + Definition : former::FormerDefinitionTypes, { } pub fn f2< Definition >( _x : Definition ) where - Definition : former::FormerDefinition2, + Definition : former::FormerDefinition, { } pub fn f3< Definition, End >( _x : End ) where - Definition : former::FormerDefinition, + Definition : former::FormerDefinitionTypes, End : former::FormingEnd< Definition >, { } @@ -31,7 +31,7 @@ fn definitions() f1( former::VectorDefinition::< String, () >::new() ); f2( former::VectorDefinition::< String, (), Vec< String >, the_module::ReturnStorage >::new() ); f3::< former::VectorDefinition< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage ); - f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > as the_module::FormerDefinition2 >::Definition, the_module::ReturnStorage >( the_module::ReturnStorage ); + f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > as the_module::FormerDefinition >::Types, the_module::ReturnStorage >( the_module::ReturnStorage ); } @@ -190,16 +190,16 @@ fn custom_definition() // xxx2 : continue struct Return13; - impl former::FormerDefinition for Return13 + impl former::FormerDefinitionTypes for Return13 { type Storage = Vec< String >; type Formed = i32; type Context = (); } - // impl former::FormerDefinition2 for Return13 + // impl former::FormerDefinition for Return13 // { - // type Definition = Return13; + // type Types = Return13; // type End = former::ReturnStorage; // } diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 1f587f690b..e39bb0072d 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -82,13 +82,13 @@ tests_impls! { // descriptor exists and has Formed - let got = < Struct1FormerDefinition as the_module::FormerDefinition >::Formed::former().form(); + let got = < Struct1FormerDefinition as the_module::FormerDefinitionTypes >::Formed::former().form(); let exp = Struct1::former().form(); a_id!( got, exp ); // descriptor exists and has Storage use former::StoragePerform; - let got = < Struct1FormerDefinition as the_module::FormerDefinition >::Storage::preform( Struct1::former().storage ); + let got = < Struct1FormerDefinition as the_module::FormerDefinitionTypes >::Storage::preform( Struct1::former().storage ); let exp = Struct1::former().form(); a_id!( got, exp ); @@ -116,7 +116,7 @@ tests_impls! a_id!( got, exp ); // storage exists - let got = < < Struct1FormerStorage as the_module::Storage >::Definition as the_module::FormerDefinition >::Formed::former().form(); + let got = < < Struct1FormerStorage as the_module::Storage >::Definition as the_module::FormerDefinitionTypes >::Formed::former().form(); let exp = Struct1::former().form(); a_id!( got, exp ); From 9a3a30cf0fef3af0db16926ba39d3eb34cdacceb Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 25 Mar 2024 00:48:55 +0200 Subject: [PATCH 035/533] former : experimenting --- module/core/former/src/axiomatic.rs | 10 ----- .../inc/former_tests/container_former_vec.rs | 44 ++++++++++++++----- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index c945c0a954..f834430a71 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -21,7 +21,6 @@ pub trait FormerDefinitionTypes : Sized type Storage : Default; type Formed; type Context; - // type End : FormingEnd< Self >; } /// xxx @@ -31,15 +30,6 @@ pub trait FormerDefinition : Sized type End : FormingEnd< Self::Types >; } -// pub trait FormerDefinitionTypes -// { -// type Storage : StoragePerform< Formed = Self::Formed >; -// type Formed; -// type Context; -// type FormerDefinitionTypes : FormerDefinitionTypes< Storage = Self::Storage, Formed = Self::Formed >; -// type End : FormingEnd< Self::FormerDefinitionTypes, Self::Context >; -// } - /// Defines a handler for the end of a subforming process, enabling the return of the original context. /// /// This trait is designed to be flexible, allowing for various end-of-forming behaviors in builder patterns. 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 98adf95886..da15e4e5e2 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 @@ -197,23 +197,47 @@ fn custom_definition() type Context = (); } - // impl former::FormerDefinition for Return13 - // { - // type Types = Return13; - // type End = former::ReturnStorage; - // } - - fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 + impl former::FormerDefinition for Return13 { - 13 + type Types = Return13; + type End = Return13; } - let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); + // - + + impl the_module::FormingEnd< Return13 > + for Return13 + { + fn call + ( + &self, + storage : < Return13 as the_module::FormerDefinitionTypes >::Storage, + context : Option< < Return13 as the_module::FormerDefinitionTypes >::Context > + ) -> < Return13 as the_module::FormerDefinitionTypes >::Formed + { + 13 + } + } // - // let got = ContainerSubformer::< E, VectorDefinition< E, Context, Formed, End > > + let got = the_module::ContainerSubformer::< String, Return13 >::begin( None, None, Return13 ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + // +// // - +// +// fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 +// { +// 13 +// } +// +// let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); } From c7f2f18f86dc7a45ff238c4438aa443d54da31c8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 25 Mar 2024 00:49:13 +0200 Subject: [PATCH 036/533] former : experimenting --- .../tests/inc/former_tests/container_former_vec.rs | 9 +++++++++ 1 file changed, 9 insertions(+) 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 da15e4e5e2..b548a7d968 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 @@ -230,6 +230,15 @@ fn custom_definition() // + let got = the_module::ContainerSubformer::< String, Return13 >::new() + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + // + // // - // // fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 From 1e98874308edb70341060bccf5e7cbdf9289a661 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 25 Mar 2024 00:51:27 +0200 Subject: [PATCH 037/533] former : experimenting --- module/core/former/src/axiomatic.rs | 3 +++ .../tests/inc/former_tests/container_former_vec.rs | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index f834430a71..d0df955b7c 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -38,6 +38,9 @@ pub trait FormerDefinition : Sized /// # Parameters /// - `Storage`: The type of the container being processed. /// - `Context`: The type of the context that might be altered or returned upon completion. + +// xxx2 : contunue. try +// pub trait FormingEnd< Definition : FormerDefinitionTypes > : Default pub trait FormingEnd< Definition : FormerDefinitionTypes > { /// Called at the end of the subforming process to return the modified or original context. 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 b548a7d968..9d1b8acfef 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 @@ -230,12 +230,13 @@ fn custom_definition() // - let got = the_module::ContainerSubformer::< String, Return13 >::new() - .push( "a" ) - .push( "b" ) - .form(); - let exp = 13; - a_id!( got, exp ); + // xxx : make it working? + // let got = the_module::ContainerSubformer::< String, Return13 >::new() + // .push( "a" ) + // .push( "b" ) + // .form(); + // let exp = 13; + // a_id!( got, exp ); // From 400363403ecb7d19f3a2334d2c46c6da87f53861 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 26 Mar 2024 14:04:45 +0200 Subject: [PATCH 038/533] experimenting --- .../inc/former_tests/container_former_vec.rs | 68 ++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) 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 9d1b8acfef..925d9f9945 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 @@ -188,7 +188,8 @@ fn begin_and_custom_end() fn custom_definition() { - // xxx2 : continue + // xxx : make example of that + struct Return13; impl former::FormerDefinitionTypes for Return13 { @@ -219,6 +220,8 @@ fn custom_definition() } } + // type MyContainer<> + // let got = the_module::ContainerSubformer::< String, Return13 >::begin( None, None, Return13 ) @@ -230,6 +233,69 @@ fn custom_definition() // +} + +// + +#[ test ] +fn custom_definition_parametrized() +{ + + // xxx : make example of that + + // xxx2 : continue + struct Return13< E >( ::core::marker::PhantomData< E > ); + + impl< E > Return13< E > + { + pub fn new() -> Self + { + Self ( ::core::marker::PhantomData ) + } + } + + impl< E > former::FormerDefinitionTypes for Return13< E > + { + type Storage = Vec< E >; + type Formed = i32; + type Context = (); + } + + impl< E > former::FormerDefinition for Return13< E > + { + type Types = Return13< E >; + type End = Return13< E >; + } + + // - + + impl< E > the_module::FormingEnd< Return13< E > > + for Return13< E > + { + fn call + ( + &self, + storage : < Return13< E > as the_module::FormerDefinitionTypes >::Storage, + context : Option< < Return13< E > as the_module::FormerDefinitionTypes >::Context > + ) -> < Return13< E > as the_module::FormerDefinitionTypes >::Formed + { + 13 + } + } + + // type MyContainer< Type > + + // + + let got = the_module::ContainerSubformer::< String, Return13< String > >::begin( None, None, Return13::new() ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + // + // xxx : make it working? // let got = the_module::ContainerSubformer::< String, Return13 >::new() // .push( "a" ) From 2fb1bfd52cc7d11f16de1ff1250c5c7e31cb3624 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 26 Mar 2024 14:49:50 +0200 Subject: [PATCH 039/533] experimenting --- module/core/former/src/container.rs | 40 +++++++++--- module/core/former/src/vector.rs | 2 +- .../inc/former_tests/container_former_vec.rs | 61 +++++++++++++++---- 3 files changed, 83 insertions(+), 20 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 57406a4eca..5fbf8cb7c4 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -273,12 +273,39 @@ where } -impl< E, T, Types, Definition > ContainerSubformer< E, Definition > +// impl< E, T, Types, Definition > ContainerSubformer< E, Definition > +// where +// Types : FormerDefinitionTypes< Context = (), Storage = T, Formed = T >, +// Definition : FormerDefinition< Types = Types, End = ReturnStorage >, +// < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, +// < Definition::Types as FormerDefinitionTypes >::Storage : StoragePerform< Formed = < Definition::Types as FormerDefinitionTypes >::Formed >, +// { +// +// // xxx : update description +// /// Initializes a new `ContainerSubformer` instance, starting with an empty formed. +// /// This function serves as the entry point for the builder pattern. +// /// +// /// # Returns +// /// A new instance of `ContainerSubformer` with an empty internal formed. +// /// +// #[ inline( always ) ] +// pub fn new_returning_storage() -> Self +// { +// Self::begin +// ( +// None, +// None, +// ReturnStorage, +// ) +// } +// +// } + +impl< E, Storage, Formed, Types, Definition > ContainerSubformer< E, Definition > where - Types : FormerDefinitionTypes< Context = (), Storage = T, Formed = T >, - Definition : FormerDefinition< Types = Types, End = ReturnStorage >, + Types : FormerDefinitionTypes< Context = (), Storage = Storage, Formed = Formed >, + Definition : FormerDefinition< Types = Types >, < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, - < Definition::Types as FormerDefinitionTypes >::Storage : StoragePerform< Formed = < Definition::Types as FormerDefinitionTypes >::Formed >, { /// Initializes a new `ContainerSubformer` instance, starting with an empty formed. @@ -288,14 +315,13 @@ where /// A new instance of `ContainerSubformer` with an empty internal formed. /// #[ inline( always ) ] - pub fn new() -> Self + pub fn new( end : Definition::End ) -> Self { Self::begin ( None, None, - ReturnStorage, - // ReturnFormed, + end, ) } diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 27a4589863..55abb524e3 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -113,7 +113,7 @@ impl< E > VecExt< E > for Vec< E > { fn former() -> VectorSubformer< E, (), Vec< E >, ReturnStorage > { - VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new() + VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new( Default::default() ) } } 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 925d9f9945..eeddcdf650 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 @@ -46,7 +46,7 @@ fn push() let got : Vec< String > = the_module ::ContainerSubformer ::< String, former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > > - ::new() + ::new( former::ReturnStorage ) .push( "a" ) .push( "b" ) .form(); @@ -63,7 +63,7 @@ fn push() < String, former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage >, - >::new() + >::new( former::ReturnStorage ) .push( "a" ) .push( "b" ) .form(); @@ -76,7 +76,7 @@ fn push() // - let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage >::new() + let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage >::new( former::ReturnStorage ) .push( "a" ) .push( "b" ) .form(); @@ -89,7 +89,7 @@ fn push() // - let got : Vec< String > = the_module::VectorSubformer::new() + let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) .push( "a" ) .push( "b" ) .form(); @@ -124,7 +124,7 @@ fn push() fn replace() { - let got : Vec< String > = the_module::VectorSubformer::new() + let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) .push( "x" ) .replace( vec![ "a".to_string(), "b".to_string() ] ) .form(); @@ -147,7 +147,7 @@ fn begin_and_custom_end() // basic case - fn return_13( _storage : Vec< String >, context : Option< () > ) -> f32 + fn return_13( _storage : Vec< String >, _context : Option< () > ) -> f32 { 13.1 } @@ -158,6 +158,13 @@ fn begin_and_custom_end() let exp = 13.1; a_id!( got, exp ); + let got = the_module::VectorSubformer::new( return_13 ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13.1; + a_id!( got, exp ); + // with a context fn context_plus_13( _storage : Vec< String >, context : Option< f32 > ) -> f32 @@ -212,8 +219,8 @@ fn custom_definition() fn call ( &self, - storage : < Return13 as the_module::FormerDefinitionTypes >::Storage, - context : Option< < Return13 as the_module::FormerDefinitionTypes >::Context > + _storage : < Return13 as the_module::FormerDefinitionTypes >::Storage, + _context : Option< < Return13 as the_module::FormerDefinitionTypes >::Context > ) -> < Return13 as the_module::FormerDefinitionTypes >::Formed { 13 @@ -231,6 +238,13 @@ fn custom_definition() let exp = 13; a_id!( got, exp ); + let got = the_module::ContainerSubformer::< String, Return13 >::new( Return13 ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + // } @@ -275,16 +289,14 @@ fn custom_definition_parametrized() fn call ( &self, - storage : < Return13< E > as the_module::FormerDefinitionTypes >::Storage, - context : Option< < Return13< E > as the_module::FormerDefinitionTypes >::Context > + _storage : < Return13< E > as the_module::FormerDefinitionTypes >::Storage, + _context : Option< < Return13< E > as the_module::FormerDefinitionTypes >::Context > ) -> < Return13< E > as the_module::FormerDefinitionTypes >::Formed { 13 } } - // type MyContainer< Type > - // let got = the_module::ContainerSubformer::< String, Return13< String > >::begin( None, None, Return13::new() ) @@ -294,6 +306,31 @@ fn custom_definition_parametrized() let exp = 13; a_id!( got, exp ); + let got = the_module::ContainerSubformer::< String, Return13< String > >::new( Return13::new() ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + // + + type MyContainer< E > = the_module::ContainerSubformer::< E, Return13< E > >; + + let got = MyContainer::< String >::begin( None, None, Return13::new() ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + let got = MyContainer::< String >::new( Return13::new() ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + // // xxx : make it working? From 71394ff416122d72792bf44cb225ba56ae57c9e8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 26 Mar 2024 16:16:07 +0200 Subject: [PATCH 040/533] experimenting --- module/core/former/src/axiomatic.rs | 16 +++++ .../inc/former_tests/container_former_vec.rs | 58 +++++++++++++++---- 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index d0df955b7c..b1677a41f9 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -118,6 +118,22 @@ pub struct FormingEndWrapper< Definition : FormerDefinitionTypes > _marker : std::marker::PhantomData< Definition::Storage >, } +impl< T, Definition > From< T > for FormingEndWrapper< Definition > +where + T : Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed + 'static, + Definition : FormerDefinitionTypes, +{ + #[ inline( always ) ] + fn from( closure : T ) -> Self + { + Self + { + closure : Box::new( closure ), + _marker : std::marker::PhantomData + } + } +} + #[ cfg( not( feature = "no_std" ) ) ] impl< Definition : FormerDefinitionTypes > FormingEndWrapper< Definition > { 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 eeddcdf650..1922543c4a 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 @@ -227,8 +227,6 @@ fn custom_definition() } } - // type MyContainer<> - // let got = the_module::ContainerSubformer::< String, Return13 >::begin( None, None, Return13 ) @@ -333,8 +331,31 @@ fn custom_definition_parametrized() // - // xxx : make it working? - // let got = the_module::ContainerSubformer::< String, Return13 >::new() +} + +// + +#[ test ] +fn custom_definition_custom_end() +{ + + struct Return13; + impl former::FormerDefinitionTypes for Return13 + { + type Storage = Vec< String >; + type Formed = i32; + type Context = (); + } + + impl former::FormerDefinition for Return13 + { + type Types = Return13; + type End = former::FormingEndWrapper< < Self as former::FormerDefinition >::Types >; + } + + // + + // let got = the_module::ContainerSubformer::< String, Return13 >::new( Return13 ) // .push( "a" ) // .push( "b" ) // .form(); @@ -343,14 +364,27 @@ fn custom_definition_parametrized() // -// // - -// -// fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 -// { -// 13 -// } -// -// let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); + fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 + { + 13 + } + + let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); + let got = the_module::ContainerSubformer::< String, Return13 >::new( end_wrapper ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + let got = the_module::ContainerSubformer::< String, Return13 >::new( return_13.into() ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + // } From 71d14738170c5054fa77b8f86251580579a8d173 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 26 Mar 2024 16:54:28 +0200 Subject: [PATCH 041/533] experimenting --- module/core/former/src/axiomatic.rs | 2 +- module/core/former/src/container.rs | 19 +++++++++++++++---- module/core/former/src/vector.rs | 2 +- .../inc/former_tests/container_former_vec.rs | 7 +++++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index b1677a41f9..c180edef24 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -86,7 +86,7 @@ where // } // } -/// xxx +/// xxx : update description #[ derive( Debug, Default ) ] pub struct ReturnStorage; diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 5fbf8cb7c4..58940fd07e 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -197,7 +197,6 @@ where #[ derive( Default ) ] pub struct ContainerSubformer< E, Definition > where - // End : FormingEnd< Definition >, Definition : FormerDefinition, < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, { @@ -208,7 +207,6 @@ where impl< E, Definition > ContainerSubformer< E, Definition > where - // End : FormingEnd< Definition >, Definition : FormerDefinition, < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, { @@ -314,6 +312,7 @@ where /// # Returns /// A new instance of `ContainerSubformer` with an empty internal formed. /// + // xxx : update description #[ inline( always ) ] pub fn new( end : Definition::End ) -> Self { @@ -325,11 +324,24 @@ where ) } + // xxx : update description + #[ inline( always ) ] + pub fn new_with< IntoEnd >( end : IntoEnd ) -> Self + where + IntoEnd : Into< Definition::End >, + { + Self::begin + ( + None, + None, + end.into(), + ) + } + } impl< E, Definition > ContainerSubformer< E, Definition > where - // End : FormingEnd< Definition >, Definition : FormerDefinition, < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, { @@ -358,7 +370,6 @@ where impl< E, Definition > FormerBegin< Definition > for ContainerSubformer< E, Definition > where - // End : FormingEnd< Definition >, Definition : FormerDefinition, < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, { diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 55abb524e3..41e7266bad 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -113,7 +113,7 @@ impl< E > VecExt< E > for Vec< E > { fn former() -> VectorSubformer< E, (), Vec< E >, ReturnStorage > { - VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new( Default::default() ) + VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new( ReturnStorage::default() ) } } 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 1922543c4a..785db2b011 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 @@ -384,6 +384,13 @@ fn custom_definition_custom_end() let exp = 13; a_id!( got, exp ); + let got = the_module::ContainerSubformer::< String, Return13 >::new_with( return_13 ) + .push( "a" ) + .push( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + // } From f86a1766a96f3b257d2fbaf48590ff8a9e8862c2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 26 Mar 2024 16:58:06 +0200 Subject: [PATCH 042/533] experimenting --- .../tests/inc/former_tests/container_former_vec.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) 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 785db2b011..eac239b921 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 @@ -1,4 +1,4 @@ -#![ allow( dead_code ) ] +// #![ allow( dead_code ) ] use super::*; #[ allow( unused_imports ) ] @@ -8,7 +8,6 @@ use collection_tools::Vec; fn definitions() { - pub fn f1< Definition >( _x : Definition ) where Definition : former::FormerDefinitionTypes, @@ -346,7 +345,6 @@ fn custom_definition_custom_end() type Formed = i32; type Context = (); } - impl former::FormerDefinition for Return13 { type Types = Return13; @@ -355,15 +353,6 @@ fn custom_definition_custom_end() // - // let got = the_module::ContainerSubformer::< String, Return13 >::new( Return13 ) - // .push( "a" ) - // .push( "b" ) - // .form(); - // let exp = 13; - // a_id!( got, exp ); - - // - fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 { 13 From f3d6aa2d7782a9f8657b624e1237d8e65d9dfa2d Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 26 Mar 2024 19:13:14 +0200 Subject: [PATCH 043/533] experimenting --- module/core/former/src/hash_set.rs | 76 +++++++++++++++---- module/core/former/src/vector.rs | 42 ++++------ .../former_tests/container_former_hashset.rs | 1 - 3 files changed, 73 insertions(+), 46 deletions(-) diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 60c3f974be..e78d39b843 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -58,35 +58,50 @@ // // // = definition // -// #[ derive( Debug ) ] -// pub struct HashSetDefinition< K, Context, End > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// End : FormingEnd< Self >, +// // #[ derive( Debug, Default ) ] +// // pub struct HashSetDefinition< K, Context, End > +// // where +// // K : ::core::cmp::Eq + ::core::hash::Hash, +// // End : FormingEnd< Self >, +// // { +// // _phantom : ::core::marker::PhantomData< ( K, Context, End ) >, +// // } +// +// #[ derive( Debug, Default ) ] +// pub struct HashSetDefinition< K, Context = (), Formed = HashSet< K >, End = ReturnStorage > // { -// _phantom : ::core::marker::PhantomData< ( K, Context, End ) >, +// _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, // } // -// impl< K, Context, End > HashSetDefinition< K, Context, End > +// // impl< K, Context, End > HashSetDefinition< K, Context, End > +// // where +// // K : ::core::cmp::Eq + ::core::hash::Hash, +// // End : FormingEnd< Self >, +// // { +// // pub fn new() -> Self +// // { +// // Self { _phantom : ::core::marker::PhantomData } +// // } +// // } +// +// impl< K, Context, End > FormerDefinitionTypes +// for HashSetDefinition< K, Context, End > // where // K : ::core::cmp::Eq + ::core::hash::Hash, // End : FormingEnd< Self >, // { -// pub fn new() -> Self -// { -// Self { _phantom : ::core::marker::PhantomData } -// } +// type Storage = HashSet< K >; +// type Formed = HashSet< K >; +// type Context = Context; // } // -// impl< K, Context, End > FormerDefinitionTypes +// impl< K, Context, End > FormerDefinition // for HashSetDefinition< K, Context, End > // where // K : ::core::cmp::Eq + ::core::hash::Hash, // End : FormingEnd< Self >, // { -// type Storage = HashSet< K >; -// type Formed = HashSet< K >; -// type Context = Context; +// type Types = HashSetDefinition< K, Context, End >; // type End = End; // } // @@ -122,4 +137,33 @@ // /// # } // /// ``` // -// pub type HashSetSubformer< K, Context, End > = ContainerSubformer::< K, HashSetDefinition< K, Context, End > >; +// // xxx : update documentation +// // pub type HashSetSubformer< K, Context, End > = ContainerSubformer::< K, HashSetDefinition< K, Context, End > >; +// pub type HashSetSubformer< K, Context, Formed, End > = +// ContainerSubformer::< K, HashSetDefinition< K, Context, Formed, End > >; +// +// // = extension +// +// pub trait HashSetExt< K > : sealed::Sealed +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage >; +// } +// +// impl< K > HashSetExt< K > for HashSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage > +// { +// HashSetSubformer::< K, (), HashSet< K >, ReturnStorage >::new( ReturnStorage::default() ) +// } +// } +// +// mod sealed +// { +// use super::HashSet; +// pub trait Sealed {} +// impl< K > Sealed for HashSet< K > {} +// } diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 41e7266bad..a7fdb2d276 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -42,21 +42,19 @@ for Vec< E > // = definition -#[ derive( Debug ) ] +#[ derive( Debug, Default ) ] pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > -// where - // Self : FormerDefinitionTypes, { _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, } -impl< E, Context, Formed > VectorDefinition< E, Context, Formed > -{ - pub fn new() -> Self - { - Self { _phantom : core::marker::PhantomData } - } -} +// impl< E, Context, Formed > VectorDefinition< E, Context, Formed > +// { +// pub fn new() -> Self +// { +// Self { _phantom : core::marker::PhantomData } +// } +// } impl< E, Context, Formed > FormerDefinitionTypes for VectorDefinition< E, Context, Formed > @@ -66,24 +64,6 @@ for VectorDefinition< E, Context, Formed > type Context = Context; } -// #[ derive( Debug ) ] -// pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > -// where -// End : FormingEnd< VectorDefinition< E, Context, Formed > >, -// { -// _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, -// } - -// impl< E, Context, Formed, End > VectorDefinition< E, Context, Formed, End > -// where -// End : FormingEnd< VectorDefinition< E, Context, Formed > >, -// { -// pub fn new() -> Self -// { -// Self { _phantom : core::marker::PhantomData } -// } -// } - impl< E, Context, Formed, End > FormerDefinition for VectorDefinition< E, Context, Formed, End > where @@ -100,7 +80,10 @@ where /// `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, Formed, End > = ContainerSubformer::< E, VectorDefinition< E, Context, Formed, End > >; +// xxx : update documentation + +pub type VectorSubformer< E, Context, Formed, End > = +ContainerSubformer::< E, VectorDefinition< E, Context, Formed, End > >; // = extension @@ -119,6 +102,7 @@ impl< E > VecExt< E > for Vec< E > mod sealed { + use super::Vec; pub trait Sealed {} impl< E > Sealed for Vec< E > {} } diff --git a/module/core/former/tests/inc/former_tests/container_former_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs index eeca2ca81c..c1c63d9a32 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashset.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashset.rs @@ -5,7 +5,6 @@ use super::*; #[ allow( unused_imports ) ] use collection_tools::HashSet; - // qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] From d52713fd59aefb042768f2efc6432c94aec1f76d Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 26 Mar 2024 22:58:21 +0200 Subject: [PATCH 044/533] experimenting --- .../former/tests/inc/former_tests/container_former_vec.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 eac239b921..6f28a5764a 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 @@ -27,8 +27,8 @@ fn definitions() { } - f1( former::VectorDefinition::< String, () >::new() ); - f2( former::VectorDefinition::< String, (), Vec< String >, the_module::ReturnStorage >::new() ); + f1( former::VectorDefinition::< String, () >::default() ); + f2( former::VectorDefinition::< String, (), Vec< String >, the_module::ReturnStorage >::default() ); f3::< former::VectorDefinition< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage ); f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > as the_module::FormerDefinition >::Types, the_module::ReturnStorage >( the_module::ReturnStorage ); From 21fb198f7e7d5c30ab74fcb0e0f6e46232bcd52b Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 26 Mar 2024 23:26:14 +0200 Subject: [PATCH 045/533] rustql --- module/blank/rustql/Cargo.toml | 34 +++++++++++++++++++++ module/blank/rustql/License | 22 +++++++++++++ module/blank/rustql/Readme.md | 33 ++++++++++++++++++++ module/blank/rustql/src/lib.rs | 11 +++++++ module/blank/rustql/tests/inc/basic_test.rs | 7 +++++ module/blank/rustql/tests/inc/mod.rs | 4 +++ module/blank/rustql/tests/smoke_test.rs | 14 +++++++++ module/blank/rustql/tests/tests.rs | 10 ++++++ module/template/template_blank/Readme.md | 2 +- 9 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 module/blank/rustql/Cargo.toml create mode 100644 module/blank/rustql/License create mode 100644 module/blank/rustql/Readme.md create mode 100644 module/blank/rustql/src/lib.rs create mode 100644 module/blank/rustql/tests/inc/basic_test.rs create mode 100644 module/blank/rustql/tests/inc/mod.rs create mode 100644 module/blank/rustql/tests/smoke_test.rs create mode 100644 module/blank/rustql/tests/tests.rs diff --git a/module/blank/rustql/Cargo.toml b/module/blank/rustql/Cargo.toml new file mode 100644 index 0000000000..8d24519fb1 --- /dev/null +++ b/module/blank/rustql/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "rustql" +version = "0.1.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/rustql" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/rustql" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/rustql" +description = """ +Rust query language. +""" +categories = [ "algorithms", "development-tools" ] +keywords = [ "fundamental", "general-purpose" ] + +[lints] +workspace = true + +[package.metadata.docs.rs] +features = [ "full" ] +all-features = false + +[features] +default = [ "enabled" ] +full = [ "enabled" ] +enabled = [] + +[dependencies] + +[dev-dependencies] +test_tools = { workspace = true } diff --git a/module/blank/rustql/License b/module/blank/rustql/License new file mode 100644 index 0000000000..6d5ef8559f --- /dev/null +++ b/module/blank/rustql/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/blank/rustql/Readme.md b/module/blank/rustql/Readme.md new file mode 100644 index 0000000000..162de54d71 --- /dev/null +++ b/module/blank/rustql/Readme.md @@ -0,0 +1,33 @@ + + +# Module :: rustql +[![experimental](https://raster.shields.io/static/v1?label=stability&message=experimental&color=orange&logoColor=eee)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/ModulerustqlPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/ModulerustqlPush.yml) [![docs.rs](https://img.shields.io/docsrs/rustql?color=e3e8f0&logo=docs.rs)](https://docs.rs/rustql) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + +Rust query language. + + diff --git a/module/blank/rustql/src/lib.rs b/module/blank/rustql/src/lib.rs new file mode 100644 index 0000000000..e8dceed08a --- /dev/null +++ b/module/blank/rustql/src/lib.rs @@ -0,0 +1,11 @@ +#![ cfg_attr( feature = "no_std", no_std ) ] +#![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] +#![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] +#![ doc( html_root_url = "https://docs.rs/rustql/latest/rustql/" ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] + +/// Function description. +#[ cfg( feature = "enabled" ) ] +pub fn f1() +{ +} diff --git a/module/blank/rustql/tests/inc/basic_test.rs b/module/blank/rustql/tests/inc/basic_test.rs new file mode 100644 index 0000000000..60c9a81cfb --- /dev/null +++ b/module/blank/rustql/tests/inc/basic_test.rs @@ -0,0 +1,7 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn basic() +{ +} diff --git a/module/blank/rustql/tests/inc/mod.rs b/module/blank/rustql/tests/inc/mod.rs new file mode 100644 index 0000000000..dde9de6f94 --- /dev/null +++ b/module/blank/rustql/tests/inc/mod.rs @@ -0,0 +1,4 @@ +#[ allow( unused_imports ) ] +use super::*; + +mod basic_test; diff --git a/module/blank/rustql/tests/smoke_test.rs b/module/blank/rustql/tests/smoke_test.rs new file mode 100644 index 0000000000..7fd288e61d --- /dev/null +++ b/module/blank/rustql/tests/smoke_test.rs @@ -0,0 +1,14 @@ + +// #[ cfg( feature = "default" ) ] +#[ test ] +fn local_smoke_test() +{ + ::test_tools::smoke_test_for_local_run(); +} + +// #[ cfg( feature = "default" ) ] +#[ test ] +fn published_smoke_test() +{ + ::test_tools::smoke_test_for_published_run(); +} diff --git a/module/blank/rustql/tests/tests.rs b/module/blank/rustql/tests/tests.rs new file mode 100644 index 0000000000..5a21773934 --- /dev/null +++ b/module/blank/rustql/tests/tests.rs @@ -0,0 +1,10 @@ + +include!( "../../../../module/step/meta/src/module/terminal.rs" ); + +#[ allow( unused_imports ) ] +use rustql as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( feature = "enabled" ) ] +mod inc; diff --git a/module/template/template_blank/Readme.md b/module/template/template_blank/Readme.md index c1c128cd89..1651492515 100644 --- a/module/template/template_blank/Readme.md +++ b/module/template/template_blank/Readme.md @@ -1,7 +1,7 @@ # Module :: {{template_blank}} -[![experimental](https://raster.shields.io/static/v1?label=stability&message=experimental&color=orange&logoColor=eee)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/Module{{TemplateBlank}}Push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/Module{{TemplateBlank}}Push.yml) [![docs.rs](https://img.shields.io/docsrs/{{template_blank}}?color=e3e8f0&logo=docs.rs)](https://docs.rs/{{template_blank}}) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) +[![experimental](https://raster.shields.io/static/v1?label=stability&message=experimental&color=orange&logoColor=eee)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/Module{{template_blank}}Push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/Module{{template_blank}}Push.yml) [![docs.rs](https://img.shields.io/docsrs/{{template_blank}}?color=e3e8f0&logo=docs.rs)](https://docs.rs/{{template_blank}}) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) ___ From 6d38395077b070693a8339d1e3309638d2897db0 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 27 Mar 2024 00:56:12 +0200 Subject: [PATCH 046/533] experimenting --- module/core/former/src/hash_set.rs | 44 +++++++++++++++--------------- module/core/former/src/vector.rs | 12 +++----- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index e78d39b843..2c179181f3 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -84,24 +84,24 @@ // // } // // } // -// impl< K, Context, End > FormerDefinitionTypes -// for HashSetDefinition< K, Context, End > +// impl< K, Context, Formed > FormerDefinitionTypes +// for HashSetDefinition< K, Context, Formed > // where // K : ::core::cmp::Eq + ::core::hash::Hash, -// End : FormingEnd< Self >, +// // End : FormingEnd< Self >, // { // type Storage = HashSet< K >; -// type Formed = HashSet< K >; +// type Formed = Formed; // type Context = Context; // } // -// impl< K, Context, End > FormerDefinition -// for HashSetDefinition< K, Context, End > +// impl< K, Context, Formed, End > FormerDefinition +// for HashSetDefinition< K, Context, Formed, End > // where // K : ::core::cmp::Eq + ::core::hash::Hash, // End : FormingEnd< Self >, // { -// type Types = HashSetDefinition< K, Context, End >; +// type Types = HashSetDefinition< K, Context, Formed >; // type End = End; // } // @@ -144,22 +144,22 @@ // // // = extension // -// pub trait HashSetExt< K > : sealed::Sealed -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage >; -// } +// // pub trait HashSetExt< K > : sealed::Sealed +// // where +// // K : ::core::cmp::Eq + ::core::hash::Hash, +// // { +// // fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage >; +// // } // -// impl< K > HashSetExt< K > for HashSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage > -// { -// HashSetSubformer::< K, (), HashSet< K >, ReturnStorage >::new( ReturnStorage::default() ) -// } -// } +// // impl< K > HashSetExt< K > for HashSet< K > +// // where +// // K : ::core::cmp::Eq + ::core::hash::Hash, +// // { +// // fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage > +// // { +// // HashSetSubformer::< K, (), HashSet< K >, ReturnStorage >::new( ReturnStorage::default() ) +// // } +// // } // // mod sealed // { diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index a7fdb2d276..9fb40007f1 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -44,20 +44,16 @@ for Vec< E > #[ derive( Debug, Default ) ] pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > +// pub struct VectorDefinition< E, Context, Formed, End > { _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, } -// impl< E, Context, Formed > VectorDefinition< E, Context, Formed > -// { -// pub fn new() -> Self -// { -// Self { _phantom : core::marker::PhantomData } -// } -// } - impl< E, Context, Formed > FormerDefinitionTypes for VectorDefinition< E, Context, Formed > +// for VectorDefinition< E, Context, Formed, End > +// where + // End : FormingEnd< Self >, { type Storage = Vec< E >; type Formed = Formed; From 2938d06fba33037efcf4304ed0a7702f06144791 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 27 Mar 2024 01:00:01 +0200 Subject: [PATCH 047/533] experimenting --- module/core/former/src/vector.rs | 12 ++++++------ .../tests/inc/former_tests/container_former_vec.rs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 9fb40007f1..db986241c7 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -43,15 +43,15 @@ for Vec< E > // = definition #[ derive( Debug, Default ) ] -pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > -// pub struct VectorDefinition< E, Context, Formed, End > +// pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > +pub struct VectorDefinition< E, Context, Formed, End > { _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, } impl< E, Context, Formed > FormerDefinitionTypes -for VectorDefinition< E, Context, Formed > -// for VectorDefinition< E, Context, Formed, End > +// for VectorDefinition< E, Context, Formed > +for VectorDefinition< E, Context, Formed, ReturnStorage > // where // End : FormingEnd< Self >, { @@ -63,9 +63,9 @@ for VectorDefinition< E, Context, Formed > impl< E, Context, Formed, End > FormerDefinition for VectorDefinition< E, Context, Formed, End > where - End : FormingEnd< VectorDefinition< E, Context, Formed > >, + End : FormingEnd< VectorDefinition< E, Context, Formed, ReturnStorage > >, { - type Types = VectorDefinition< E, Context, Formed >; + type Types = VectorDefinition< E, Context, Formed, ReturnStorage >; type End = 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 6f28a5764a..048af90f1f 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 @@ -27,9 +27,9 @@ fn definitions() { } - f1( former::VectorDefinition::< String, () >::default() ); + // f1( former::VectorDefinition::< String, () >::default() ); f2( former::VectorDefinition::< String, (), Vec< String >, the_module::ReturnStorage >::default() ); - f3::< former::VectorDefinition< String, () >, the_module::ReturnStorage >( the_module::ReturnStorage ); + f3::< former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage >, the_module::ReturnStorage >( the_module::ReturnStorage ); f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > as the_module::FormerDefinition >::Types, the_module::ReturnStorage >( the_module::ReturnStorage ); } From 53cfb6d297f43aba866e206c5afcc975786b46cb Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 27 Mar 2024 01:02:58 +0200 Subject: [PATCH 048/533] experimenting --- module/core/former/src/vector.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index db986241c7..40df34f6c2 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -52,6 +52,7 @@ pub struct VectorDefinition< E, Context, Formed, End > impl< E, Context, Formed > FormerDefinitionTypes // for VectorDefinition< E, Context, Formed > for VectorDefinition< E, Context, Formed, ReturnStorage > +// for VectorDefinition< E, Context, Formed, End > // where // End : FormingEnd< Self >, { From cc3464624f104ae14265b82b93d98690c1005fb9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 27 Mar 2024 01:06:14 +0200 Subject: [PATCH 049/533] experimenting --- module/core/former/src/vector.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 40df34f6c2..da59e7e122 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -43,8 +43,8 @@ for Vec< E > // = definition #[ derive( Debug, Default ) ] -// pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > -pub struct VectorDefinition< E, Context, Formed, End > +pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > +// pub struct VectorDefinition< E, Context, Formed, End > { _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, } From 8c8363fe993e20f2209173a9deae59e9fd02b574 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 27 Mar 2024 14:34:21 +0200 Subject: [PATCH 050/533] experimenting --- module/core/former/src/axiomatic.rs | 21 ++++++++++++++++++- module/core/former/src/vector.rs | 9 ++++---- .../inc/former_tests/container_former_vec.rs | 12 ++++++++--- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index c180edef24..879fa3ec60 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -39,7 +39,7 @@ pub trait FormerDefinition : Sized /// - `Storage`: The type of the container being processed. /// - `Context`: The type of the context that might be altered or returned upon completion. -// xxx2 : contunue. try +// xxx2 : continue. try // pub trait FormingEnd< Definition : FormerDefinitionTypes > : Default pub trait FormingEnd< Definition : FormerDefinitionTypes > { @@ -105,6 +105,25 @@ where } } +// xxx : improve description +/// Use `NoEnd` to fill parameter FormingEnd in struct where parameter exists, but it is not needed. +/// It might be needed if the same struct is used as `FormerDefinitionTypes` and as `FormerDefinition`, because the first one does not have information aboud End function. +/// Similar logic which `std::marker::PhantomData` has behind. +#[ derive( Debug, Default ) ] +pub struct NoEnd; + +impl< Definition > FormingEnd< Definition > +for NoEnd +where + Definition : FormerDefinitionTypes< Context = () >, +{ + #[ inline( always ) ] + fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed + { + unreachable!(); + } +} + /// A wrapper around a closure to be used as a `FormingEnd`. /// /// This struct allows for dynamic dispatch of a closure that matches the diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index da59e7e122..c170e12368 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -51,7 +51,7 @@ pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnSto impl< E, Context, Formed > FormerDefinitionTypes // for VectorDefinition< E, Context, Formed > -for VectorDefinition< E, Context, Formed, ReturnStorage > +for VectorDefinition< E, Context, Formed, NoEnd > // for VectorDefinition< E, Context, Formed, End > // where // End : FormingEnd< Self >, @@ -64,9 +64,9 @@ for VectorDefinition< E, Context, Formed, ReturnStorage > impl< E, Context, Formed, End > FormerDefinition for VectorDefinition< E, Context, Formed, End > where - End : FormingEnd< VectorDefinition< E, Context, Formed, ReturnStorage > >, + End : FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, { - type Types = VectorDefinition< E, Context, Formed, ReturnStorage >; + type Types = VectorDefinition< E, Context, Formed, NoEnd >; type End = End; } @@ -99,7 +99,6 @@ impl< E > VecExt< E > for Vec< E > mod sealed { - use super::Vec; pub trait Sealed {} - impl< E > Sealed for Vec< E > {} + impl< E > Sealed for super::Vec< E > {} } 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 048af90f1f..7aeb920776 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 @@ -4,6 +4,8 @@ use super::*; #[ allow( unused_imports ) ] use collection_tools::Vec; +// + #[ test ] fn definitions() { @@ -28,9 +30,13 @@ fn definitions() } // f1( former::VectorDefinition::< String, () >::default() ); - f2( former::VectorDefinition::< String, (), Vec< String >, the_module::ReturnStorage >::default() ); - f3::< former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage >, the_module::ReturnStorage >( the_module::ReturnStorage ); - f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > as the_module::FormerDefinition >::Types, the_module::ReturnStorage >( the_module::ReturnStorage ); + f2( former::VectorDefinition::< String, (), Vec< String >, the_module::NoEnd >::default() ); + f3::< former::VectorDefinition< String, (), Vec< String >, the_module::NoEnd >, the_module::ReturnStorage >( the_module::ReturnStorage ); + f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::NoEnd > as the_module::FormerDefinition >::Types, the_module::ReturnStorage >( the_module::ReturnStorage ); + + // assert_eq!( 0, 1 ); + + let vec : Vec< String > = vec![ "a".into(), "b".into(), "c".into() ]; } From 630816a27137a2dd0b13d89577c47f64a005d41f Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 27 Mar 2024 14:51:45 +0200 Subject: [PATCH 051/533] experimenting --- module/core/former/src/hash_map.rs | 48 +++-- module/core/former/src/hash_set.rs | 317 ++++++++++++++--------------- module/core/former/src/vector.rs | 8 +- 3 files changed, 185 insertions(+), 188 deletions(-) diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 4b54113128..91bae2fd5e 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -70,8 +70,8 @@ // // // = definition // -// #[ derive( Debug ) ] -// pub struct HashMapDefinition< K, E, Context, End > +// #[ derive( Debug, Default ) ] +// pub struct HashMapDefinition< K, E, Context = (), Formed = HashMap< K, E >, End = ReturnStorage > // where // K : ::core::cmp::Eq + ::core::hash::Hash, // End : FormingEnd< Self >, @@ -79,17 +79,6 @@ // _phantom : ::core::marker::PhantomData< ( K, E, Context, End ) >, // } // -// impl< K, E, Context, End > HashMapDefinition< K, E, Context, End > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// End : FormingEnd< Self >, -// { -// pub fn new() -> Self -// { -// Self { _phantom : ::core::marker::PhantomData } -// } -// } -// // impl< K, E, Context, End > FormerDefinitionTypes // for HashMapDefinition< K, E, Context, End > // where @@ -140,4 +129,35 @@ // /// # } // /// ``` // -// pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, End > >; +// // pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, End > >; +// +// // xxx : update documentation +// // pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< K, HashMapDefinition< K, Context, End > >; +// pub type HashMapSubformer< K, E, Context, Formed, End > = +// ContainerSubformer::< K, HashMapDefinition< K, Context, Formed, End > >; +// +// // = extension +// +// pub trait HashMapExt< K, E > : sealed::Sealed +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// fn former() -> HashMapSubformer< K, E, (), HashMap< K, E >, ReturnStorage >; +// } +// +// impl< K, E > HashMapExt< K, E > for HashMap< K, E > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// fn former() -> HashMapSubformer< K, E, (), HashMap< K, E >, ReturnStorage > +// { +// HashMapSubformer::< K, (), HashMap< K, E >, ReturnStorage >::new( ReturnStorage::default() ) +// } +// } +// +// mod sealed +// { +// use super::HashMap; +// pub trait Sealed {} +// impl< K, E > Sealed for HashMap< K, E > {} +// } diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 2c179181f3..d143fe68b6 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -1,169 +1,148 @@ -// //! # HashSetLike Trait and HashSetSubformer Struct -// //! -// //! This part of the crate provides a flexible interface (`HashSetLike`) and a builder pattern implementation (`HashSetSubformer`) for `HashSet`-like containers. It's designed to extend the builder pattern, allowing for fluent and dynamic construction of sets within custom data structures. -// -// use super::*; -// use collection_tools::HashSet; -// -// /// A trait for containers behaving like a `HashSet`, allowing insertion operations. -// /// -// /// Implementing this trait enables the associated formed to be used with `HashSetSubformer`, -// /// facilitating a builder pattern that is both intuitive and concise. -// /// -// /// # Example Implementation -// /// -// /// Implementing `HashSetLike` for `std::collections::HashSet`: -// /// -// -// pub trait HashSetLike< K > -// where -// K : core::cmp::Eq + core::hash::Hash, -// { -// /// Inserts a key-value pair into the map. -// fn insert( &mut self, element : K ) -> Option< K >; -// } -// -// impl< K > HashSetLike< K > for HashSet< K > -// where -// K : core::cmp::Eq + core::hash::Hash, -// { -// fn insert( &mut self, element : K ) -> Option< K > -// { -// HashSet::replace( self, element ) -// } -// } -// -// // = storage -// -// impl< K > Storage -// for HashSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// // type Types = HashSetDefinition< K >; -// type Formed = HashSet< K >; -// } -// -// impl< K > StoragePerform -// for HashSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed -// fn preform( self ) -> Self::Formed -// { -// self -// } -// } -// -// // = definition -// -// // #[ derive( Debug, Default ) ] -// // pub struct HashSetDefinition< K, Context, End > -// // where -// // K : ::core::cmp::Eq + ::core::hash::Hash, -// // End : FormingEnd< Self >, -// // { -// // _phantom : ::core::marker::PhantomData< ( K, Context, End ) >, -// // } -// -// #[ derive( Debug, Default ) ] -// pub struct HashSetDefinition< K, Context = (), Formed = HashSet< K >, End = ReturnStorage > -// { -// _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, -// } -// -// // impl< K, Context, End > HashSetDefinition< K, Context, End > -// // where -// // K : ::core::cmp::Eq + ::core::hash::Hash, -// // End : FormingEnd< Self >, -// // { -// // pub fn new() -> Self -// // { -// // Self { _phantom : ::core::marker::PhantomData } -// // } -// // } -// -// impl< K, Context, Formed > FormerDefinitionTypes -// for HashSetDefinition< K, Context, Formed > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// // End : FormingEnd< Self >, -// { -// type Storage = HashSet< K >; -// type Formed = Formed; -// type Context = Context; -// } -// -// impl< K, Context, Formed, End > FormerDefinition -// for HashSetDefinition< K, Context, Formed, End > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// End : FormingEnd< Self >, -// { -// type Types = HashSetDefinition< K, Context, Formed >; -// type End = End; -// } -// -// /// Facilitates building `HashSetLike` containers with a fluent API. -// /// -// /// `HashSetSubformer` leverages the `HashSetLike` trait to enable a concise and expressive way -// /// of populating `HashSet`-like containers. It exemplifies the crate's builder pattern variation for sets. -// /// -// /// # Example Usage -// /// -// /// Using `HashSetSubformer` to populate a `HashSet` within a struct: -// /// -// /// ```rust -// /// # #[ cfg( all( feature = "enabled", not( feature = "no_std" ) ) ) ] -// /// # { -// /// # use test_tools::exposed::*; -// /// -// /// #[ derive( Debug, PartialEq, former::Former ) ] -// /// pub struct StructWithSet -// /// { -// /// #[ subformer( former::HashSetSubformer ) ] -// /// set : std::collections::HashSet< &'static str >, -// /// } -// /// -// /// let instance = StructWithSet::former() -// /// .set() -// /// .insert( "apple" ) -// /// .insert( "banana" ) -// /// .end() -// /// .form(); -// /// -// /// assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] }); -// /// # } -// /// ``` -// -// // xxx : update documentation -// // pub type HashSetSubformer< K, Context, End > = ContainerSubformer::< K, HashSetDefinition< K, Context, End > >; -// pub type HashSetSubformer< K, Context, Formed, End > = -// ContainerSubformer::< K, HashSetDefinition< K, Context, Formed, End > >; -// -// // = extension -// -// // pub trait HashSetExt< K > : sealed::Sealed -// // where -// // K : ::core::cmp::Eq + ::core::hash::Hash, -// // { -// // fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage >; -// // } -// -// // impl< K > HashSetExt< K > for HashSet< K > -// // where -// // K : ::core::cmp::Eq + ::core::hash::Hash, -// // { -// // fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage > -// // { -// // HashSetSubformer::< K, (), HashSet< K >, ReturnStorage >::new( ReturnStorage::default() ) -// // } -// // } -// -// mod sealed -// { -// use super::HashSet; -// pub trait Sealed {} -// impl< K > Sealed for HashSet< K > {} -// } +//! # HashSetLike Trait and HashSetSubformer Struct +//! +//! This part of the crate provides a flexible interface (`HashSetLike`) and a builder pattern implementation (`HashSetSubformer`) for `HashSet`-like containers. It's designed to extend the builder pattern, allowing for fluent and dynamic construction of sets within custom data structures. + +use super::*; +use collection_tools::HashSet; + +/// A trait for containers behaving like a `HashSet`, allowing insertion operations. +/// +/// Implementing this trait enables the associated formed to be used with `HashSetSubformer`, +/// facilitating a builder pattern that is both intuitive and concise. +/// +/// # Example Implementation +/// +/// Implementing `HashSetLike` for `std::collections::HashSet`: +/// + +pub trait HashSetLike< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + /// Inserts a key-value pair into the map. + fn insert( &mut self, element : K ) -> Option< K >; +} + +impl< K > HashSetLike< K > for HashSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + fn insert( &mut self, element : K ) -> Option< K > + { + HashSet::replace( self, element ) + } +} + +// = storage + +impl< K > Storage +for HashSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + // type Types = HashSetDefinition< K >; + type Formed = HashSet< K >; +} + +impl< K > StoragePerform +for HashSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed + fn preform( self ) -> Self::Formed + { + self + } +} + +// = definition + +#[ derive( Debug, Default ) ] +pub struct HashSetDefinition< K, Context = (), Formed = HashSet< K >, End = ReturnStorage > +{ + _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, +} + +impl< K, Context, Formed > FormerDefinitionTypes +for HashSetDefinition< K, Context, Formed, NoEnd > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Storage = HashSet< K >; + type Formed = Formed; + type Context = Context; +} + +impl< K, Context, Formed, End > FormerDefinition +for HashSetDefinition< K, Context, Formed, End > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + End : FormingEnd< HashSetDefinition< K, Context, Formed, NoEnd > >, +{ + type Types = HashSetDefinition< K, Context, Formed, NoEnd >; + type End = End; +} + +/// Facilitates building `HashSetLike` containers with a fluent API. +/// +/// `HashSetSubformer` leverages the `HashSetLike` trait to enable a concise and expressive way +/// of populating `HashSet`-like containers. It exemplifies the crate's builder pattern variation for sets. +/// +/// # Example Usage +/// +/// Using `HashSetSubformer` to populate a `HashSet` within a struct: +/// +/// ```rust +/// # #[ cfg( all( feature = "enabled", not( feature = "no_std" ) ) ) ] +/// # { +/// # use test_tools::exposed::*; +/// +/// #[ derive( Debug, PartialEq, former::Former ) ] +/// pub struct StructWithSet +/// { +/// #[ subformer( former::HashSetSubformer ) ] +/// set : std::collections::HashSet< &'static str >, +/// } +/// +/// let instance = StructWithSet::former() +/// .set() +/// .insert( "apple" ) +/// .insert( "banana" ) +/// .end() +/// .form(); +/// +/// assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] }); +/// # } +/// ``` + +// xxx : update documentation +// pub type HashSetSubformer< K, Context, End > = ContainerSubformer::< K, HashSetDefinition< K, Context, End > >; +pub type HashSetSubformer< K, Context, Formed, End > = +ContainerSubformer::< K, HashSetDefinition< K, Context, Formed, End > >; + +// = extension + +pub trait HashSetExt< K > : sealed::Sealed +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage >; +} + +impl< K > HashSetExt< K > for HashSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage > + { + HashSetSubformer::< K, (), HashSet< K >, ReturnStorage >::new( ReturnStorage::default() ) + } +} + +mod sealed +{ + use super::HashSet; + pub trait Sealed {} + impl< K > Sealed for HashSet< K > {} +} diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index c170e12368..fd6fe22f6e 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -44,17 +44,15 @@ for Vec< E > #[ derive( Debug, Default ) ] pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > -// pub struct VectorDefinition< E, Context, Formed, End > +where + End : FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, + // axiomatic::NoEnd: axiomatic::FormingEnd>, { _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, } impl< E, Context, Formed > FormerDefinitionTypes -// for VectorDefinition< E, Context, Formed > for VectorDefinition< E, Context, Formed, NoEnd > -// for VectorDefinition< E, Context, Formed, End > -// where - // End : FormingEnd< Self >, { type Storage = Vec< E >; type Formed = Formed; From 55c1058cf97621ee5b94d9dbaf8465bb76633968 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 27 Mar 2024 15:21:22 +0200 Subject: [PATCH 052/533] experimenting --- module/core/former/src/axiomatic.rs | 4 +- module/core/former/src/hash_map.rs | 317 ++++++++++++++++------------ module/core/former/src/hash_set.rs | 2 + module/core/former/src/vector.rs | 5 +- 4 files changed, 184 insertions(+), 144 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 879fa3ec60..e6da43dd8e 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -115,10 +115,10 @@ pub struct NoEnd; impl< Definition > FormingEnd< Definition > for NoEnd where - Definition : FormerDefinitionTypes< Context = () >, + Definition : FormerDefinitionTypes, { #[ inline( always ) ] - fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed + fn call( &self, storage : Definition::Storage, _context : core::option::Option< Definition::Context > ) -> Definition::Formed { unreachable!(); } diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 91bae2fd5e..77d5b03bc6 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -1,80 +1,105 @@ -// use super::*; -// -// use collection_tools::HashMap; -// -// /// 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 -// /// of key-value pairs and the creation of formers for more complex construction patterns. -// /// -// /// # Type Parameters -// /// - `K`: The type of keys stored in the hash map. Must implement `Eq` and `Hash`. -// /// - `E`: The type of elements (values) stored in the hash map. -// pub trait HashMapLike< K, E > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// Self : Sized + Default, -// { -// -// /// Inserts a key-value pair into the map. -// fn insert( &mut self, k : K, e : E ) -> Option< E >; -// -// // /// Return former. -// // #[ inline( always ) ] -// // fn former< Definition : FormerDefinitionTypes >( self ) -// // -> -// // HashMapSubformer< K, E, Definition, (), impl FormingEnd< Self, Self > > -// // { -// // HashMapSubformer::begin( Some( self ), None, ReturnFormed ) -// // } -// // xxx : uncomment and cover by tests -// -// } -// -// impl< K, E > HashMapLike< K, E > for HashMap< K, E > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// Self : Sized + Default, -// { -// -// #[ inline( always ) ] -// fn insert( &mut self, k : K, e : E ) -> Option< E > -// { -// HashMap::insert( self, k, e ) -// } -// -// } -// -// // = storage -// -// impl< K, E > Storage -// for HashMap< K, E > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// // type Types = HashMapDefinition< K, E >; -// type Formed = HashMap< K, E >; -// } -// -// impl< K, E > StoragePerform -// for HashMap< K, E > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed -// fn preform( self ) -> Self::Formed -// { -// self -// } -// } -// -// // = definition -// +use super::*; + +use collection_tools::HashMap; + +/// 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 +/// of key-value pairs and the creation of formers for more complex construction patterns. +/// +/// # Type Parameters +/// - `K`: The type of keys stored in the hash map. Must implement `Eq` and `Hash`. +/// - `E`: The type of elements (values) stored in the hash map. +pub trait HashMapLike< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + Self : Sized + Default, +{ + + /// Inserts a key-value pair into the map. + fn insert( &mut self, k : K, e : E ) -> Option< E >; + + // /// Return former. + // #[ inline( always ) ] + // fn former< Definition : FormerDefinitionTypes >( self ) + // -> + // HashMapSubformer< K, E, Definition, (), impl FormingEnd< Self, Self > > + // { + // HashMapSubformer::begin( Some( self ), None, ReturnFormed ) + // } + // xxx : uncomment and cover by tests + +} + +impl< K, E > HashMapLike< K, E > for HashMap< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + Self : Sized + Default, +{ + + #[ inline( always ) ] + fn insert( &mut self, k : K, e : E ) -> Option< E > + { + HashMap::insert( self, k, e ) + } + +} + +// = storage + +impl< K, E > Storage +for HashMap< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + // type Types = HashMapDefinition< K, E >; + type Formed = HashMap< K, E >; +} + +impl< K, E > StoragePerform +for HashMap< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed + fn preform( self ) -> Self::Formed + { + self + } +} + +// = definition + +#[ derive( Debug, Default ) ] +pub struct HashMapDefinition< K, E, Context = (), Formed = HashMap< K, E >, End = ReturnStorage > +{ + _phantom : core::marker::PhantomData< ( K, E, Context, Formed, End ) >, +} + +impl< K, E, Context, Formed > FormerDefinitionTypes +for HashMapDefinition< K, E, Context, Formed, NoEnd > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Storage = HashMap< K, E >; + type Formed = Formed; + type Context = Context; +} + +impl< K, E, Context, Formed, End > FormerDefinition +for HashMapDefinition< K, E, Context, Formed, End > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + End : FormingEnd< HashMapDefinition< K, E, Context, Formed, NoEnd > >, +{ + type Types = HashMapDefinition< K, E, Context, Formed, NoEnd >; + type End = End; +} + // #[ derive( Debug, Default ) ] // pub struct HashMapDefinition< K, E, Context = (), Formed = HashMap< K, E >, End = ReturnStorage > // where // K : ::core::cmp::Eq + ::core::hash::Hash, -// End : FormingEnd< Self >, // { // _phantom : ::core::marker::PhantomData< ( K, E, Context, End ) >, // } @@ -91,73 +116,87 @@ // type End = End; // } // -// /// A builder for constructing hash map-like structures with a fluent interface. -// /// -// /// `HashMapSubformer` leverages the `HashMapLike` trait to enable a flexible and customizable -// /// way to build hash map-like structures. It supports the chaining of insert operations and -// /// allows for the definition of custom end actions to finalize the building process. -// /// -// /// # Type Parameters -// /// - `K`: Key type, must implement `Eq` and `Hash`. -// /// - `E`: Element (value) type. -// /// - `Formed`: The hash map-like formed being built. -// /// - `Context`: Type of the optional context used during the building process. -// /// - `End`: End-of-forming action to be executed upon completion. -// /// -// /// # Examples -// /// ``` -// /// # #[ cfg( all( feature = "enabled", not( feature = "no_std" ) ) ) ] -// /// # { -// /// # use test_tools::exposed::*; -// /// -// /// #[ derive( Debug, PartialEq, former::Former ) ] -// /// pub struct StructWithMap -// /// { -// /// #[ subformer( former::HashMapSubformer ) ] -// /// map : std::collections::HashMap< &'static str, &'static str >, -// /// } -// /// -// /// let struct1 = StructWithMap::former() -// /// .map() -// /// .insert( "a", "b" ) -// /// .insert( "c", "d" ) -// /// .end() -// /// .form() -// /// ; -// /// assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); -// /// -// /// # } -// /// ``` -// -// // pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, End > >; -// -// // xxx : update documentation -// // pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< K, HashMapDefinition< K, Context, End > >; -// pub type HashMapSubformer< K, E, Context, Formed, End > = -// ContainerSubformer::< K, HashMapDefinition< K, Context, Formed, End > >; -// -// // = extension -// -// pub trait HashMapExt< K, E > : sealed::Sealed -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// fn former() -> HashMapSubformer< K, E, (), HashMap< K, E >, ReturnStorage >; -// } -// -// impl< K, E > HashMapExt< K, E > for HashMap< K, E > +// impl< K, E, Context, End > FormerDefinitionTypes +// for HashMapDefinition< K, E, Context, End > // where // K : ::core::cmp::Eq + ::core::hash::Hash, +// End : FormingEnd< Self >, // { -// fn former() -> HashMapSubformer< K, E, (), HashMap< K, E >, ReturnStorage > -// { -// HashMapSubformer::< K, (), HashMap< K, E >, ReturnStorage >::new( ReturnStorage::default() ) -// } -// } -// -// mod sealed -// { -// use super::HashMap; -// pub trait Sealed {} -// impl< K, E > Sealed for HashMap< K, E > {} +// type Storage = HashMap< K, E >; +// type Formed = HashMap< K, E >; +// type Context = Context; +// type End = End; // } + +// = subformer + +/// A builder for constructing hash map-like structures with a fluent interface. +/// +/// `HashMapSubformer` leverages the `HashMapLike` trait to enable a flexible and customizable +/// way to build hash map-like structures. It supports the chaining of insert operations and +/// allows for the definition of custom end actions to finalize the building process. +/// +/// # Type Parameters +/// - `K`: Key type, must implement `Eq` and `Hash`. +/// - `E`: Element (value) type. +/// - `Formed`: The hash map-like formed being built. +/// - `Context`: Type of the optional context used during the building process. +/// - `End`: End-of-forming action to be executed upon completion. +/// +/// # Examples +/// ``` +/// # #[ cfg( all( feature = "enabled", not( feature = "no_std" ) ) ) ] +/// # { +/// # use test_tools::exposed::*; +/// +/// #[ derive( Debug, PartialEq, former::Former ) ] +/// pub struct StructWithMap +/// { +/// #[ subformer( former::HashMapSubformer ) ] +/// map : std::collections::HashMap< &'static str, &'static str >, +/// } +/// +/// let struct1 = StructWithMap::former() +/// .map() +/// .insert( "a", "b" ) +/// .insert( "c", "d" ) +/// .end() +/// .form() +/// ; +/// assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); +/// +/// # } +/// ``` + +// pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, End > >; + +// xxx : update documentation +// pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< K, HashMapDefinition< K, E, Context, End > >; +pub type HashMapSubformer< K, E, Context, Formed, End > = +ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, Formed, End > >; + +// = extension + +pub trait HashMapExt< K, E > : sealed::Sealed +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + fn former() -> HashMapSubformer< K, E, (), HashMap< K, E >, ReturnStorage >; +} + +impl< K, E > HashMapExt< K, E > for HashMap< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + fn former() -> HashMapSubformer< K, E, (), HashMap< K, E >, ReturnStorage > + { + HashMapSubformer::< K, E, (), HashMap< K, E >, ReturnStorage >::new( ReturnStorage::default() ) + } +} + +mod sealed +{ + use super::HashMap; + pub trait Sealed {} + impl< K, E > Sealed for HashMap< K, E > {} +} diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index d143fe68b6..0f5bde873a 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -84,6 +84,8 @@ where type End = End; } +// = subformer + /// Facilitates building `HashSetLike` containers with a fluent API. /// /// `HashSetSubformer` leverages the `HashSetLike` trait to enable a concise and expressive way diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index fd6fe22f6e..9f69ba7221 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -44,9 +44,8 @@ for Vec< E > #[ derive( Debug, Default ) ] pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > -where - End : FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, - // axiomatic::NoEnd: axiomatic::FormingEnd>, +// where +// End : FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, { _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, } From 32c2fee9c83dd557102b092d8a18f72a4a712589 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 27 Mar 2024 15:24:43 +0200 Subject: [PATCH 053/533] experimenting --- module/core/former/src/container.rs | 3 +- .../former_tests/container_former_hashset.rs | 10 +-- .../inc/former_tests/container_former_vec.rs | 72 +++++++++---------- module/core/former/tests/inc/mod.rs | 4 +- 4 files changed, 44 insertions(+), 45 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 58940fd07e..37824b3049 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -348,7 +348,7 @@ where /// Appends an element to the end of the storage, expanding the internal collection. #[ inline( always ) ] - pub fn push< IntoElement >( mut self, element : IntoElement ) -> Self + pub fn add< IntoElement >( mut self, element : IntoElement ) -> Self where IntoElement : core::convert::Into< E >, { if self.storage.is_none() @@ -358,7 +358,6 @@ where if let core::option::Option::Some( ref mut storage ) = self.storage { ContainerAdd::add( storage, element.into() ); - // storage.push( element.into() ); } self } diff --git a/module/core/former/tests/inc/former_tests/container_former_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs index c1c63d9a32..eb80142068 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashset.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashset.rs @@ -11,9 +11,9 @@ use collection_tools::HashSet; fn push() { - let got : HashSet< String > = the_module::HashSetSubformer::new() - .insert( "a" ) - .insert( "b" ) + let got : HashSet< String > = the_module::HashSetSubformer::new( former::ReturnStorage ) + .add( "a" ) + .add( "b" ) .form(); let exp = hset! [ @@ -30,8 +30,8 @@ fn push() fn replace() { - let got : HashSet< String > = the_module::HashSetSubformer::new() - .insert( "x" ) + let got : HashSet< String > = the_module::HashSetSubformer::new( former::ReturnStorage ) + .add( "x" ) .replace( hset![ "a".to_string(), "b".to_string() ] ) .form(); let exp = hset! 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 7aeb920776..7bb3ad4644 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 @@ -43,7 +43,7 @@ fn definitions() // #[ test ] -fn push() +fn add() { // @@ -52,8 +52,8 @@ fn push() ::ContainerSubformer ::< String, former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > > ::new( former::ReturnStorage ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = vec! [ @@ -69,8 +69,8 @@ fn push() String, former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage >, >::new( former::ReturnStorage ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = vec! [ @@ -82,8 +82,8 @@ fn push() // let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage >::new( former::ReturnStorage ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = vec! [ @@ -95,8 +95,8 @@ fn push() // let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = vec! [ @@ -109,8 +109,8 @@ fn push() use the_module::VecExt; let got : Vec< String > = Vec::former() - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = vec! [ @@ -130,7 +130,7 @@ fn replace() { let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) - .push( "x" ) + .add( "x" ) .replace( vec![ "a".to_string(), "b".to_string() ] ) .form(); let exp = vec! @@ -157,15 +157,15 @@ fn begin_and_custom_end() 13.1 } let got = the_module::VectorSubformer::begin( None, None, return_13 ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = 13.1; a_id!( got, exp ); let got = the_module::VectorSubformer::new( return_13 ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = 13.1; a_id!( got, exp ); @@ -184,8 +184,8 @@ fn begin_and_custom_end() } } let got = the_module::VectorSubformer::begin( None, Some( 10.0 ), context_plus_13 ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = 23.1; a_id!( got, exp ); @@ -235,15 +235,15 @@ fn custom_definition() // let got = the_module::ContainerSubformer::< String, Return13 >::begin( None, None, Return13 ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); let got = the_module::ContainerSubformer::< String, Return13 >::new( Return13 ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); @@ -303,15 +303,15 @@ fn custom_definition_parametrized() // let got = the_module::ContainerSubformer::< String, Return13< String > >::begin( None, None, Return13::new() ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); let got = the_module::ContainerSubformer::< String, Return13< String > >::new( Return13::new() ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); @@ -321,15 +321,15 @@ fn custom_definition_parametrized() type MyContainer< E > = the_module::ContainerSubformer::< E, Return13< E > >; let got = MyContainer::< String >::begin( None, None, Return13::new() ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); let got = MyContainer::< String >::new( Return13::new() ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); @@ -366,22 +366,22 @@ fn custom_definition_custom_end() let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); let got = the_module::ContainerSubformer::< String, Return13 >::new( end_wrapper ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); let got = the_module::ContainerSubformer::< String, Return13 >::new( return_13.into() ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); let got = the_module::ContainerSubformer::< String, Return13 >::new_with( return_13 ) - .push( "a" ) - .push( "b" ) + .add( "a" ) + .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index d418d95951..ab7c1c47c9 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -9,8 +9,8 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod container_former_vec; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod container_former_hashset; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashset; // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod container_former_hashmap; From 84c19a9a1ecc94d7854cad0983ff808bd5bfb624 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 27 Mar 2024 15:38:02 +0200 Subject: [PATCH 054/533] experimenting --- .../former_tests/container_former_common.rs | 290 +++++++++++++++++ .../former_tests/container_former_hashset.rs | 63 +++- .../inc/former_tests/container_former_vec.rs | 307 +----------------- module/core/former/tests/inc/mod.rs | 2 + 4 files changed, 364 insertions(+), 298 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/container_former_common.rs diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs new file mode 100644 index 0000000000..a251cef936 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -0,0 +1,290 @@ +// #![ allow( dead_code ) ] + +use super::*; +#[ allow( unused_imports ) ] +use collection_tools::Vec; + +// + +#[ test ] +fn definitions() +{ + + pub fn f1< Definition >( _x : Definition ) + where + Definition : former::FormerDefinitionTypes, + { + } + + pub fn f2< Definition >( _x : Definition ) + where + Definition : former::FormerDefinition, + { + } + + pub fn f3< Definition, End >( _x : End ) + where + Definition : former::FormerDefinitionTypes, + End : former::FormingEnd< Definition >, + { + } + + // f1( former::VectorDefinition::< String, () >::default() ); + f2( former::VectorDefinition::< String, (), Vec< String >, the_module::NoEnd >::default() ); + f3::< former::VectorDefinition< String, (), Vec< String >, the_module::NoEnd >, the_module::ReturnStorage >( the_module::ReturnStorage ); + f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::NoEnd > as the_module::FormerDefinition >::Types, the_module::ReturnStorage >( the_module::ReturnStorage ); + + // assert_eq!( 0, 1 ); + + let vec : Vec< String > = vec![ "a".into(), "b".into(), "c".into() ]; + +} + +// + +#[ test ] +fn begin_and_custom_end() +{ + + // xxx : make example with that + + // basic case + + fn return_13( _storage : Vec< String >, _context : Option< () > ) -> f32 + { + 13.1 + } + let got = the_module::VectorSubformer::begin( None, None, return_13 ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = 13.1; + a_id!( got, exp ); + + let got = the_module::VectorSubformer::new( return_13 ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = 13.1; + a_id!( got, exp ); + + // with a context + + fn context_plus_13( _storage : Vec< String >, context : Option< f32 > ) -> f32 + { + if let Some( context ) = context + { + 13.1 + context + } + else + { + 13.1 + } + } + let got = the_module::VectorSubformer::begin( None, Some( 10.0 ), context_plus_13 ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = 23.1; + a_id!( got, exp ); + + // + +} + +// + +#[ test ] +fn custom_definition() +{ + + // xxx : make example of that + + struct Return13; + impl former::FormerDefinitionTypes for Return13 + { + type Storage = Vec< String >; + type Formed = i32; + type Context = (); + } + + impl former::FormerDefinition for Return13 + { + type Types = Return13; + type End = Return13; + } + + // - + + impl the_module::FormingEnd< Return13 > + for Return13 + { + fn call + ( + &self, + _storage : < Return13 as the_module::FormerDefinitionTypes >::Storage, + _context : Option< < Return13 as the_module::FormerDefinitionTypes >::Context > + ) -> < Return13 as the_module::FormerDefinitionTypes >::Formed + { + 13 + } + } + + // + + let got = the_module::ContainerSubformer::< String, Return13 >::begin( None, None, Return13 ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + let got = the_module::ContainerSubformer::< String, Return13 >::new( Return13 ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + // + +} + +// + +#[ test ] +fn custom_definition_parametrized() +{ + + // xxx : make example of that + + struct Return13< E >( ::core::marker::PhantomData< E > ); + + impl< E > Return13< E > + { + pub fn new() -> Self + { + Self ( ::core::marker::PhantomData ) + } + } + + impl< E > former::FormerDefinitionTypes for Return13< E > + { + type Storage = Vec< E >; + type Formed = i32; + type Context = (); + } + + impl< E > former::FormerDefinition for Return13< E > + { + type Types = Return13< E >; + type End = Return13< E >; + } + + // - + + impl< E > the_module::FormingEnd< Return13< E > > + for Return13< E > + { + fn call + ( + &self, + _storage : < Return13< E > as the_module::FormerDefinitionTypes >::Storage, + _context : Option< < Return13< E > as the_module::FormerDefinitionTypes >::Context > + ) -> < Return13< E > as the_module::FormerDefinitionTypes >::Formed + { + 13 + } + } + + // + + let got = the_module::ContainerSubformer::< String, Return13< String > >::begin( None, None, Return13::new() ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + let got = the_module::ContainerSubformer::< String, Return13< String > >::new( Return13::new() ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + // + + type MyContainer< E > = the_module::ContainerSubformer::< E, Return13< E > >; + + let got = MyContainer::< String >::begin( None, None, Return13::new() ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + let got = MyContainer::< String >::new( Return13::new() ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + // + +} + +// + +#[ test ] +fn custom_definition_custom_end() +{ + + struct Return13; + impl former::FormerDefinitionTypes for Return13 + { + type Storage = Vec< String >; + type Formed = i32; + type Context = (); + } + impl former::FormerDefinition for Return13 + { + type Types = Return13; + type End = former::FormingEndWrapper< < Self as former::FormerDefinition >::Types >; + } + + // + + fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 + { + 13 + } + + let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); + let got = the_module::ContainerSubformer::< String, Return13 >::new( end_wrapper ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + let got = the_module::ContainerSubformer::< String, Return13 >::new( return_13.into() ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + let got = the_module::ContainerSubformer::< String, Return13 >::new_with( return_13 ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = 13; + a_id!( got, exp ); + + // + +} + +// diff --git a/module/core/former/tests/inc/former_tests/container_former_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs index eb80142068..a84a716f45 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashset.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashset.rs @@ -8,9 +8,41 @@ use collection_tools::HashSet; // qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] -fn push() +fn add() { + // expliccit with ContainerSubformer + + let got : HashSet< String > = the_module + ::ContainerSubformer + ::< String, former::HashSetDefinition< String, (), HashSet< String >, the_module::ReturnStorage > > + ::new( former::ReturnStorage ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = hset! + [ + "a".to_string(), + "b".to_string(), + ]; + a_id!( got, exp ); + + // expliccit with HashSetSubformer + + let got : HashSet< String > = the_module::HashSetSubformer::< String, (), HashSet< String >, the_module::ReturnStorage > + ::new( former::ReturnStorage ) + .add( "a" ) + .add( "b" ) + .form(); + let exp = hset! + [ + "a".to_string(), + "b".to_string(), + ]; + a_id!( got, exp ); + + // compact with HashSetSubformer + let got : HashSet< String > = the_module::HashSetSubformer::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) @@ -22,6 +54,35 @@ fn push() ]; a_id!( got, exp ); + // with begin + + let got : HashSet< String > = the_module::HashSetSubformer + ::begin( Some( hset![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) + .add( "b" ) + .form(); + let exp = hset! + [ + "a".to_string(), + "b".to_string(), + ]; + a_id!( got, exp ); + + // with help of ext + + use the_module::HashSetExt; + let got : HashSet< String > = HashSet::former() + .add( "a" ) + .add( "b" ) + .form(); + let exp = hset! + [ + "a".to_string(), + "b".to_string(), + ]; + a_id!( got, exp ); + + // + } // qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] 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 7bb3ad4644..8d4aea60fe 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 @@ -6,47 +6,11 @@ use collection_tools::Vec; // -#[ test ] -fn definitions() -{ - - pub fn f1< Definition >( _x : Definition ) - where - Definition : former::FormerDefinitionTypes, - { - } - - pub fn f2< Definition >( _x : Definition ) - where - Definition : former::FormerDefinition, - { - } - - pub fn f3< Definition, End >( _x : End ) - where - Definition : former::FormerDefinitionTypes, - End : former::FormingEnd< Definition >, - { - } - - // f1( former::VectorDefinition::< String, () >::default() ); - f2( former::VectorDefinition::< String, (), Vec< String >, the_module::NoEnd >::default() ); - f3::< former::VectorDefinition< String, (), Vec< String >, the_module::NoEnd >, the_module::ReturnStorage >( the_module::ReturnStorage ); - f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::NoEnd > as the_module::FormerDefinition >::Types, the_module::ReturnStorage >( the_module::ReturnStorage ); - - // assert_eq!( 0, 1 ); - - let vec : Vec< String > = vec![ "a".into(), "b".into(), "c".into() ]; - -} - -// - #[ test ] fn add() { - // + // expliccit with ContainerSubformer let got : Vec< String > = the_module ::ContainerSubformer @@ -62,13 +26,10 @@ fn add() ]; a_id!( got, exp ); - // + // expliccit with VectorSubformer - let got : Vec< String > = the_module::ContainerSubformer:: - < - String, - former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage >, - >::new( former::ReturnStorage ) + let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage > + ::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -79,9 +40,9 @@ fn add() ]; a_id!( got, exp ); - // + // compact with VectorSubformer - let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage >::new( former::ReturnStorage ) + let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -92,10 +53,10 @@ fn add() ]; a_id!( got, exp ); - // + // with begin - let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) - .add( "a" ) + let got : Vec< String > = the_module::VectorSubformer + ::begin( Some( vec![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) .add( "b" ) .form(); let exp = vec! @@ -105,7 +66,7 @@ fn add() ]; a_id!( got, exp ); - // + // with help of ext use the_module::VecExt; let got : Vec< String > = Vec::former() @@ -143,251 +104,3 @@ fn replace() } // - -#[ test ] -fn begin_and_custom_end() -{ - - // xxx : make example with that - - // basic case - - fn return_13( _storage : Vec< String >, _context : Option< () > ) -> f32 - { - 13.1 - } - let got = the_module::VectorSubformer::begin( None, None, return_13 ) - .add( "a" ) - .add( "b" ) - .form(); - let exp = 13.1; - a_id!( got, exp ); - - let got = the_module::VectorSubformer::new( return_13 ) - .add( "a" ) - .add( "b" ) - .form(); - let exp = 13.1; - a_id!( got, exp ); - - // with a context - - fn context_plus_13( _storage : Vec< String >, context : Option< f32 > ) -> f32 - { - if let Some( context ) = context - { - 13.1 + context - } - else - { - 13.1 - } - } - let got = the_module::VectorSubformer::begin( None, Some( 10.0 ), context_plus_13 ) - .add( "a" ) - .add( "b" ) - .form(); - let exp = 23.1; - a_id!( got, exp ); - - // - -} - -// - -#[ test ] -fn custom_definition() -{ - - // xxx : make example of that - - struct Return13; - impl former::FormerDefinitionTypes for Return13 - { - type Storage = Vec< String >; - type Formed = i32; - type Context = (); - } - - impl former::FormerDefinition for Return13 - { - type Types = Return13; - type End = Return13; - } - - // - - - impl the_module::FormingEnd< Return13 > - for Return13 - { - fn call - ( - &self, - _storage : < Return13 as the_module::FormerDefinitionTypes >::Storage, - _context : Option< < Return13 as the_module::FormerDefinitionTypes >::Context > - ) -> < Return13 as the_module::FormerDefinitionTypes >::Formed - { - 13 - } - } - - // - - let got = the_module::ContainerSubformer::< String, Return13 >::begin( None, None, Return13 ) - .add( "a" ) - .add( "b" ) - .form(); - let exp = 13; - a_id!( got, exp ); - - let got = the_module::ContainerSubformer::< String, Return13 >::new( Return13 ) - .add( "a" ) - .add( "b" ) - .form(); - let exp = 13; - a_id!( got, exp ); - - // - -} - -// - -#[ test ] -fn custom_definition_parametrized() -{ - - // xxx : make example of that - - // xxx2 : continue - struct Return13< E >( ::core::marker::PhantomData< E > ); - - impl< E > Return13< E > - { - pub fn new() -> Self - { - Self ( ::core::marker::PhantomData ) - } - } - - impl< E > former::FormerDefinitionTypes for Return13< E > - { - type Storage = Vec< E >; - type Formed = i32; - type Context = (); - } - - impl< E > former::FormerDefinition for Return13< E > - { - type Types = Return13< E >; - type End = Return13< E >; - } - - // - - - impl< E > the_module::FormingEnd< Return13< E > > - for Return13< E > - { - fn call - ( - &self, - _storage : < Return13< E > as the_module::FormerDefinitionTypes >::Storage, - _context : Option< < Return13< E > as the_module::FormerDefinitionTypes >::Context > - ) -> < Return13< E > as the_module::FormerDefinitionTypes >::Formed - { - 13 - } - } - - // - - let got = the_module::ContainerSubformer::< String, Return13< String > >::begin( None, None, Return13::new() ) - .add( "a" ) - .add( "b" ) - .form(); - let exp = 13; - a_id!( got, exp ); - - let got = the_module::ContainerSubformer::< String, Return13< String > >::new( Return13::new() ) - .add( "a" ) - .add( "b" ) - .form(); - let exp = 13; - a_id!( got, exp ); - - // - - type MyContainer< E > = the_module::ContainerSubformer::< E, Return13< E > >; - - let got = MyContainer::< String >::begin( None, None, Return13::new() ) - .add( "a" ) - .add( "b" ) - .form(); - let exp = 13; - a_id!( got, exp ); - - let got = MyContainer::< String >::new( Return13::new() ) - .add( "a" ) - .add( "b" ) - .form(); - let exp = 13; - a_id!( got, exp ); - - // - -} - -// - -#[ test ] -fn custom_definition_custom_end() -{ - - struct Return13; - impl former::FormerDefinitionTypes for Return13 - { - type Storage = Vec< String >; - type Formed = i32; - type Context = (); - } - impl former::FormerDefinition for Return13 - { - type Types = Return13; - type End = former::FormingEndWrapper< < Self as former::FormerDefinition >::Types >; - } - - // - - fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 - { - 13 - } - - let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); - let got = the_module::ContainerSubformer::< String, Return13 >::new( end_wrapper ) - .add( "a" ) - .add( "b" ) - .form(); - let exp = 13; - a_id!( got, exp ); - - let got = the_module::ContainerSubformer::< String, Return13 >::new( return_13.into() ) - .add( "a" ) - .add( "b" ) - .form(); - let exp = 13; - a_id!( got, exp ); - - let got = the_module::ContainerSubformer::< String, Return13 >::new_with( return_13 ) - .add( "a" ) - .add( "b" ) - .form(); - let exp = 13; - a_id!( got, exp ); - - // - -} - -// diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index ab7c1c47c9..e8b2ed3c47 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -7,6 +7,8 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_common; #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod container_former_vec; #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] From aaf6119af2a1b1486c8f877fb5c24b55385eabdb Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 27 Mar 2024 22:28:09 +0200 Subject: [PATCH 055/533] experimenting --- .../former_tests/container_former_common.rs | 6 +- .../former_tests/container_former_hashmap.rs | 76 ++++++++++++++++--- module/core/former/tests/inc/mod.rs | 4 +- 3 files changed, 70 insertions(+), 16 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index a251cef936..954e887892 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -29,15 +29,11 @@ fn definitions() { } - // f1( former::VectorDefinition::< String, () >::default() ); + f1( former::VectorDefinition::< String, (), Vec< String >, the_module::NoEnd >::default() ); f2( former::VectorDefinition::< String, (), Vec< String >, the_module::NoEnd >::default() ); f3::< former::VectorDefinition< String, (), Vec< String >, the_module::NoEnd >, the_module::ReturnStorage >( the_module::ReturnStorage ); f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::NoEnd > as the_module::FormerDefinition >::Types, the_module::ReturnStorage >( the_module::ReturnStorage ); - // assert_eq!( 0, 1 ); - - let vec : Vec< String > = vec![ "a".into(), "b".into(), "c".into() ]; - } // diff --git a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs index cfe3574aed..da24fc1ec1 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs @@ -8,14 +8,71 @@ use collection_tools::HashMap; // qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] -fn push() +fn add() { - // + // expliccit with ContainerSubformer + + let got : HashMap< String, String > = the_module + ::ContainerSubformer + ::< ( String, String ), former::HashMapDefinition< String, String, (), HashMap< String, String >, the_module::ReturnStorage > > + ::new( former::ReturnStorage ) + .add( ( "a".into(), "x".into() ) ) + .add( ( "b".into(), "y".into() ) ) + .form(); + let exp = hmap! + [ + "a".to_string() => "x".to_string(), + "b".to_string() => "y".to_string(), + ]; + a_id!( got, exp ); + + // expliccit with HashMapSubformer + + let got : HashMap< String, String > = the_module::HashMapSubformer::< String, String, (), HashMap< String, String >, the_module::ReturnStorage > + ::new( former::ReturnStorage ) + .add( ( "a".into(), "x".into() ) ) + .add( ( "b".into(), "y".into() ) ) + .form(); + let exp = hmap! + [ + "a".to_string() => "x".to_string(), + "b".to_string() => "y".to_string(), + ]; + a_id!( got, exp ); + + // compact with HashMapSubformer + + let got : HashMap< String, String > = the_module::HashMapSubformer::new( former::ReturnStorage ) + .add( ( "a".into(), "x".into() ) ) + .add( ( "b".into(), "y".into() ) ) + .form(); + let exp = hmap! + [ + "a".to_string() => "x".to_string(), + "b".to_string() => "y".to_string(), + ]; + a_id!( got, exp ); + + // with begin + + let got : HashMap< String, String > = the_module::HashMapSubformer + ::begin( Some( hmap![ "a".to_string() => "x".to_string() ] ), Some( () ), former::ReturnStorage ) + .add( ( "b".into(), "y".into() ) ) + .form(); + let exp = hmap! + [ + "a".to_string() => "x".to_string(), + "b".to_string() => "y".to_string(), + ]; + a_id!( got, exp ); + + // with help of ext - let got : HashMap< String, String > = the_module::HashMapSubformer::new() - .insert( "a", "x" ) - .insert( "b", "y" ) + use the_module::HashMapExt; + let got : HashMap< String, String > = HashMap::former() + .add( ( "a".into(), "x".into() ) ) + .add( ( "b".into(), "y".into() ) ) .form(); let exp = hmap! [ @@ -24,6 +81,8 @@ fn push() ]; a_id!( got, exp ); + // + } // qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] @@ -32,9 +91,9 @@ fn push() fn replace() { - let got : HashMap< String, String > = the_module::HashMapSubformer::new() - .insert( "x", "x" ) - .replace( hmap![ "a".to_string() => "x".to_string(), "b".to_string() => "y".to_string() ] ) + let got : HashMap< String, String > = the_module::HashMapSubformer::new( former::ReturnStorage ) + .add( ( "x".to_string(), "y".to_string() ) ) + .replace( hmap![ "a".to_string() => "x".to_string(), "b".to_string() => "y".to_string(), ] ) .form(); let exp = hmap! [ @@ -44,4 +103,3 @@ fn replace() a_id!( got, exp ); } - diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index e8b2ed3c47..6e963751ab 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -13,8 +13,8 @@ mod former_tests mod container_former_vec; #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod container_former_hashset; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod container_former_hashmap; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashmap; // mod a_primitives_manual; // mod a_primitives; From 3cf75d0b50f9f53cbdbcadde59db0de287b3e0ef Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 27 Mar 2024 23:45:16 +0200 Subject: [PATCH 056/533] experimenting --- module/core/former/src/axiomatic.rs | 27 ++++++++++--------- .../inc/former_tests/a_primitives_manual.rs | 4 ++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index e6da43dd8e..8c70343deb 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -1,5 +1,5 @@ -//! .... +/// xxx pub trait Storage : ::core::default::Default { // type Types : FormerDefinitionTypes< Storage = Self >; @@ -21,6 +21,9 @@ pub trait FormerDefinitionTypes : Sized type Storage : Default; type Formed; type Context; + + // fn preform( storage : Self::Storage, context : Self::Context ) -> Self::Formed; + } /// xxx @@ -66,23 +69,23 @@ where } } -// /// A `FormingEnd` implementation that returns the formed container itself instead of the context. -// /// -// /// This struct is useful when the forming process should result in the formed container being returned directly, -// /// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. -// #[ derive( Debug, Default ) ] -// pub struct ReturnFormed; -// +/// A `FormingEnd` implementation that returns the formed container itself instead of the context. +/// +/// This struct is useful when the forming process should result in the formed container being returned directly, +/// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. +#[ derive( Debug, Default ) ] +pub struct ReturnFormed; + // impl< Definition > FormingEnd< Definition > // for ReturnFormed // where -// Definition::Storage : StoragePerform< Formed = Definition::Formed >, -// Definition : FormerDefinitionTypes< Context = () >, +// // Definition::Storage : StoragePerform< Formed = Definition::Formed >, +// Definition : FormerDefinitionTypes< Definition::Context >, // { // #[ inline( always ) ] -// fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed +// fn call( &self, storage : Definition::Storage, context : core::option::Option< Context > ) -> Definition::Formed // { -// storage.preform() +// storage.preform( context ) // } // } diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 2ae6d728fa..5a9321884b 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -39,6 +39,7 @@ for Struct1FormerDefinition { type Storage = Struct1FormerStorage; type Formed = Struct1; + type End = former::ReturnFormed; } // = storage @@ -72,7 +73,8 @@ impl Default for Struct1FormerStorage impl former::Storage for Struct1FormerStorage { - type Types = Struct1FormerDefinition; + // type Types = Struct1FormerDefinition; + type Formed = Struct1; } impl former::StoragePerform From 8790e5f2bf62447d3728081420229d6704848907 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 28 Mar 2024 08:42:00 +0200 Subject: [PATCH 057/533] experimenting --- module/core/former/src/axiomatic.rs | 33 +++++++++++-------- .../inc/former_tests/a_primitives_manual.rs | 12 +++++-- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 8c70343deb..c30c460681 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -10,6 +10,11 @@ pub trait Storage : ::core::default::Default pub trait StoragePerform : Storage { // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed; + /// Default implementation of routine transforming storage into formed structure. + /// Does not have to be implemented and does not have to be used, especially if there is complex logic behind tranfromation, but can be used if algorithm is traight-forward and does not require any context. + /// + /// `former::ReturnPreformed` rely on `StoragePerform::preform` returning its result. + /// fn preform( self ) -> Self::Formed; } @@ -74,20 +79,20 @@ where /// This struct is useful when the forming process should result in the formed container being returned directly, /// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. #[ derive( Debug, Default ) ] -pub struct ReturnFormed; - -// impl< Definition > FormingEnd< Definition > -// for ReturnFormed -// where -// // Definition::Storage : StoragePerform< Formed = Definition::Formed >, -// Definition : FormerDefinitionTypes< Definition::Context >, -// { -// #[ inline( always ) ] -// fn call( &self, storage : Definition::Storage, context : core::option::Option< Context > ) -> Definition::Formed -// { -// storage.preform( context ) -// } -// } +pub struct ReturnPreformed; + +impl< Definition > FormingEnd< Definition > +for ReturnPreformed +where + Definition::Storage : StoragePerform< Formed = Definition::Formed >, + Definition : FormerDefinitionTypes, +{ + #[ inline( always ) ] + fn call( &self, storage : Definition::Storage, context : core::option::Option< Definition::Context > ) -> Definition::Formed + { + storage.preform() + } +} /// xxx : update description #[ derive( Debug, Default ) ] diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 5a9321884b..3eb873e040 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -39,6 +39,14 @@ for Struct1FormerDefinition { type Storage = Struct1FormerStorage; type Formed = Struct1; + type Context = (); + // type End = former::ReturnFormed; +} + +impl former::FormerDefinition +for Struct1FormerDefinition +{ + type Types = Struct1FormerDefinition; type End = former::ReturnFormed; } @@ -81,7 +89,7 @@ impl former::StoragePerform for Struct1FormerStorage { - fn preform( mut self ) -> < < Self as former::Storage >::Definition as former::FormerDefinitionTypes >::Formed + fn preform( mut self ) -> < Self as former::Storage >::Formed { let int_1 = if self.int_1.is_some() @@ -242,4 +250,4 @@ impl Struct1Former< (), the_module::ReturnFormed > // -include!( "./only_test/primitives.rs" ); +// include!( "./only_test/primitives.rs" ); From 27c8f4aadbece1e4b0628fa1b8db8564d2d27cae Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 28 Mar 2024 08:52:33 +0200 Subject: [PATCH 058/533] experimenting --- .../inc/former_tests/a_primitives_manual.rs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 3eb873e040..96a278a3e2 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -15,7 +15,7 @@ pub struct Struct1 // generated by former impl Struct1 { - pub fn former() -> Struct1Former< (), former::ReturnFormed > + pub fn former() -> Struct1Former { Struct1Former::new() } @@ -40,14 +40,14 @@ for Struct1FormerDefinition type Storage = Struct1FormerStorage; type Formed = Struct1; type Context = (); - // type End = former::ReturnFormed; + // type End = former::ReturnPreformed; } impl former::FormerDefinition for Struct1FormerDefinition { type Types = Struct1FormerDefinition; - type End = former::ReturnFormed; + type End = former::ReturnPreformed; } // = storage @@ -148,20 +148,20 @@ for Struct1FormerStorage pub struct Struct1Former < - FormerContext = Struct1, - FormerEnd = the_module::ReturnFormed, + // FormerContext = Struct1, + // FormerEnd = the_module::ReturnPreformed, > -where - FormerEnd : the_module::FormingEnd< Struct1FormerDefinition, FormerContext >, +// where + // FormerEnd : the_module::FormingEnd< Struct1FormerDefinition >, { storage : Struct1FormerStorage, - context : core::option::Option< FormerContext >, - on_end : core::option::Option< FormerEnd >, + context : core::option::Option< < Struct1FormerDefinition as former::FormerDefinitionTypes >::Context >, + on_end : core::option::Option< < Struct1FormerDefinition as former::FormerDefinition >::End >, } -impl< FormerContext, FormerEnd > Struct1Former< FormerContext, FormerEnd > -where - FormerEnd: the_module::FormingEnd< Struct1FormerDefinition, FormerContext >, +impl Struct1Former +// where + // FormerEnd: the_module::FormingEnd< Struct1FormerDefinition, FormerContext >, { fn preform( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed @@ -180,8 +180,8 @@ where pub fn begin ( mut storage : core::option::Option< < Struct1FormerDefinition as former::FormerDefinitionTypes >::Storage >, - context : core::option::Option< FormerContext >, - on_end : FormerEnd, + context : core::option::Option< < Struct1FormerDefinition as former::FormerDefinitionTypes >::Context >, + on_end : < Struct1FormerDefinition as former::FormerDefinition >::End, // xxx : cover by test existance of these 3 parameters in the function ) -> Self { @@ -202,7 +202,7 @@ where { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - on_end.call( self.storage, context ) + former::FormingEnd::call( &on_end, self.storage, context ) } #[ inline( always ) ] @@ -237,13 +237,13 @@ where } -impl Struct1Former< (), the_module::ReturnFormed > +impl Struct1Former { #[ inline( always ) ] - pub fn new() -> Struct1Former< (), the_module::ReturnFormed > + pub fn new() -> Struct1Former { - Struct1Former::< (), the_module::ReturnFormed >::begin( None, None, the_module::ReturnFormed ) + Struct1Former::begin( None, None, the_module::ReturnPreformed ) } } From 44857f5ce5c18e5e2e95fad8c287433d57b1c0fe Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 29 Mar 2024 09:59:42 +0200 Subject: [PATCH 059/533] experimenting --- .../core/former/tests/inc/former_tests/a_primitives_manual.rs | 4 ++-- module/core/former/tests/inc/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 96a278a3e2..61015f26ac 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -21,7 +21,7 @@ impl Struct1 } } -// = descriptor +// = definition #[ derive( Debug ) ] pub struct Struct1FormerDefinition; @@ -202,7 +202,7 @@ impl Struct1Former { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - former::FormingEnd::call( &on_end, self.storage, context ) + former::FormingEnd::< Struct1FormerDefinition >::call( &on_end, self.storage, context ) } #[ inline( always ) ] diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 6e963751ab..c9b4a5805f 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -16,7 +16,7 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod container_former_hashmap; - // mod a_primitives_manual; + mod a_primitives_manual; // mod a_primitives; // mod a_primitives_expanded; // mod a_containers_without_runtime_manual; From 844dc449bba6bfb662ba3cacbdde970a24ab096a Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 29 Mar 2024 10:19:04 +0200 Subject: [PATCH 060/533] experimenting --- .../core/former/tests/inc/former_tests/a_primitives_manual.rs | 4 ++-- .../former/tests/inc/former_tests/only_test/primitives.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 61015f26ac..8f00f1937a 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -192,7 +192,7 @@ impl Struct1Former Self { storage : storage.unwrap(), - context : context, + context, on_end : ::core::option::Option::Some( on_end ), } } @@ -250,4 +250,4 @@ impl Struct1Former // -// include!( "./only_test/primitives.rs" ); +include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index e39bb0072d..1f6fff6151 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -17,7 +17,7 @@ tests_impls! a_id!( former.storage.int_optional_1, None ); a_id!( former.storage.string_optional_1, None ); a_id!( former.context, None ); - a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnFormed ) ) ); + a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); let former2 = Struct1Former::new(); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); @@ -116,7 +116,7 @@ tests_impls! a_id!( got, exp ); // storage exists - let got = < < Struct1FormerStorage as the_module::Storage >::Definition as the_module::FormerDefinitionTypes >::Formed::former().form(); + let got = < Struct1FormerStorage as the_module::Storage >::Formed::former().form(); let exp = Struct1::former().form(); a_id!( got, exp ); From ea514cfadee2225ac07eeb01c7a651131fade409 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 29 Mar 2024 10:32:06 +0200 Subject: [PATCH 061/533] experimenting --- module/core/former/src/axiomatic.rs | 4 ++-- module/core/former/src/container.rs | 17 ++++++++++++++++ module/core/former/src/lib.rs | 3 +++ .../inc/former_tests/a_primitives_manual.rs | 16 +++++++-------- .../inc/former_tests/only_test/primitives.rs | 20 +++++++++++++------ 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index c30c460681..27bdfbe899 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -88,7 +88,7 @@ where Definition : FormerDefinitionTypes, { #[ inline( always ) ] - fn call( &self, storage : Definition::Storage, context : core::option::Option< Definition::Context > ) -> Definition::Formed + fn call( &self, storage : Definition::Storage, _context : core::option::Option< Definition::Context > ) -> Definition::Formed { storage.preform() } @@ -126,7 +126,7 @@ where Definition : FormerDefinitionTypes, { #[ inline( always ) ] - fn call( &self, storage : Definition::Storage, _context : core::option::Option< Definition::Context > ) -> Definition::Formed + fn call( &self, _storage : Definition::Storage, _context : core::option::Option< Definition::Context > ) -> Definition::Formed { unreachable!(); } diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 37824b3049..437d1bf16b 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -205,6 +205,23 @@ where on_end : core::option::Option< Definition::End >, } +// xxx : cover by test +use std::fmt; +impl< E, Definition > fmt::Debug for ContainerSubformer< E, Definition > +where + Definition : FormerDefinition, + < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, +{ + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f.debug_struct( "ContainerSubformer" ) + .field( "storage", &self.storage.as_ref().map( |_| "Storage Present" ) ) + .field( "context", &self.context.as_ref().map( |_| "Context Present" ) ) + .field( "on_end", &self.on_end.as_ref().map( |_| "End Present" ) ) + .finish() + } +} + impl< E, Definition > ContainerSubformer< E, Definition > where Definition : FormerDefinition, diff --git a/module/core/former/src/lib.rs b/module/core/former/src/lib.rs index 4834d7a293..15c66baa2f 100644 --- a/module/core/former/src/lib.rs +++ b/module/core/former/src/lib.rs @@ -4,6 +4,9 @@ #![ doc( html_root_url = "https://docs.rs/former/latest/former/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] +// xxx : remove +#![ allow( missing_docs ) ] + // xxx : describe "Context-aware forming process" /// Axiomatic things. diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 8f00f1937a..f05665a731 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -23,16 +23,16 @@ impl Struct1 // = definition -#[ derive( Debug ) ] +#[ derive( Debug, Default ) ] pub struct Struct1FormerDefinition; -impl Struct1FormerDefinition -{ - pub fn new() -> Self - { - Self - } -} +// impl Struct1FormerDefinition +// { +// pub fn new() -> Self +// { +// Self +// } +// } impl former::FormerDefinitionTypes for Struct1FormerDefinition diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 1f6fff6151..b09e881925 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -78,20 +78,28 @@ tests_impls! // - fn descriptor() + fn definition() { - // descriptor exists and has Formed + // default is implemented for definition + let _default = Struct1FormerDefinition::default(); + + // definition types exists and has Formed let got = < Struct1FormerDefinition as the_module::FormerDefinitionTypes >::Formed::former().form(); let exp = Struct1::former().form(); a_id!( got, exp ); - // descriptor exists and has Storage + // definition types exists and has Storage use former::StoragePerform; let got = < Struct1FormerDefinition as the_module::FormerDefinitionTypes >::Storage::preform( Struct1::former().storage ); let exp = Struct1::former().form(); a_id!( got, exp ); + // definition exists and has Storage + let got = < < Struct1FormerDefinition as the_module::FormerDefinition >::Types as the_module::FormerDefinitionTypes >::Formed::former().form(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + } // @@ -99,7 +107,7 @@ tests_impls! fn storage() { - // descriptor exists and has Storage + // definition exists and has Storage let got = < Struct1FormerStorage as the_module::StoragePerform >::preform( Struct1::former().storage ); let exp = Struct1::former().form(); a_id!( got, exp ); @@ -109,7 +117,7 @@ tests_impls! let exp = Struct1::former().storage.preform(); a_id!( got, exp ); - // descriptor exists and has Storage + // definition exists and has Storage use former::StoragePerform; let got = Struct1::former().storage.preform(); let exp = Struct1::former().form(); @@ -308,7 +316,7 @@ tests_index! internals, begin, preform, - descriptor, + definition, storage, test_int, test_string, From 9ef619d0dde74b0e9360d1602abde333ec0f1410 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 29 Mar 2024 11:40:49 +0200 Subject: [PATCH 062/533] experimenting --- .../tests/inc/former_tests/a_primitives.rs | 3 +- .../inc/former_tests/a_primitives_expanded.rs | 273 +++++++++++++++++- .../inc/former_tests/a_primitives_manual.rs | 1 - module/core/former/tests/inc/mod.rs | 2 +- module/core/former_meta/src/derive/former.rs | 79 +++-- 5 files changed, 324 insertions(+), 34 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives.rs b/module/core/former/tests/inc/former_tests/a_primitives.rs index c39429b63a..676ee5752c 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives.rs @@ -12,4 +12,5 @@ pub struct Struct1 // -include!( "./only_test/primitives.rs" ); +// xxx : uncomment +// include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs index 812d40be6e..ea4eee4e00 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -11,7 +11,278 @@ pub struct Struct1 string_optional_1 : Option< String >, } -// = formed +// = generated + +// #[ automatically_derived ] +// impl Struct1 +// { +// #[ doc = r"" ] +// #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// // pub fn former() -> Struct1Former< (), former::ReturnPreformed > +// pub fn former() -> Struct1Former<> +// { +// Struct1Former::new() +// } +// } +// +// #[ derive( Debug, Default ) ] +// pub struct Struct1FormerDefinition; +// +// impl former::FormerDefinitionTypes for Struct1FormerDefinition +// { +// type Storage = Struct1FormerStorage; +// type Formed = Struct1; +// type Context = (); +// } +// +// impl former::FormerDefinition for Struct1FormerDefinition +// { +// type Types = Struct1FormerDefinition; +// type End = former::ReturnPreformed; +// } +// +// #[ doc = "Container of a corresponding former." ] +// pub struct Struct1FormerStorage +// { +// #[ doc = r" A field" ] +// pub int_1 : ::core::option::Option< i32 >, +// #[ doc = r" A field" ] +// pub string_1 : ::core::option::Option< String >, +// #[ doc = r" A field" ] +// pub int_optional_1 : core::option::Option< i32 >, +// #[ doc = r" A field" ] +// pub string_optional_1 : Option< String >, +// } +// +// impl ::core::default::Default for Struct1FormerStorage +// { +// #[ inline( always ) ] +// fn default() -> Self +// { +// Self +// { +// int_1 : ::core::option::Option::None, +// string_1 : ::core::option::Option::None, +// int_optional_1 : ::core::option::Option::None, +// string_optional_1 : ::core::option::Option::None, +// } +// } +// } +// +// impl former::Storage for Struct1FormerStorage +// { +// // type Definition = Struct1FormerDefinition; +// type Formed = Struct1; +// } +// +// impl former::StoragePerform for Struct1FormerStorage +// { +// fn preform( mut self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed +// { +// let int_1 = if self.int_1.is_some() +// { +// self.int_1.take().unwrap() +// } +// else +// { +// { +// trait MaybeDefault< T > +// { +// fn maybe_default( self : &Self ) -> T +// { +// panic!( "Field 'int_1' isn't initialized" ) +// } +// } +// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} +// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > +// where T : ::core::default::Default, +// { +// fn maybe_default( self : &Self ) -> T +// { +// T::default() +// } +// } +// ( &::core::marker::PhantomData::< i32 > ).maybe_default() +// } +// }; +// let string_1 = if self.string_1.is_some() +// { +// self.string_1.take().unwrap() +// } +// else +// { +// { +// trait MaybeDefault< T > +// { +// fn maybe_default( self : &Self ) -> T +// { +// panic!( "Field 'string_1' isn't initialized" ) +// } +// } +// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} +// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > +// where T : ::core::default::Default, +// { +// fn maybe_default( self : &Self ) -> T +// { +// T::default() +// } +// } +// ( &::core::marker::PhantomData::< String > ).maybe_default() +// } +// }; +// let int_optional_1 = if self.int_optional_1.is_some() +// { +// ::core::option::Option::Some( self.int_optional_1.take().unwrap() ) +// } +// else +// { +// ::core::option::Option::None +// }; +// let string_optional_1 = if self.string_optional_1.is_some() +// { +// ::core::option::Option::Some( self.string_optional_1.take().unwrap() ) +// } +// else +// { +// ::core::option::Option::None +// }; +// let result = Struct1 +// { +// int_1, +// string_1, +// int_optional_1, +// string_optional_1, +// }; +// return result; +// } +// } +// +// pub struct Struct1Former +// < +// // FormerContext = Struct1, +// // FormerEnd = former::ReturnPreformed, +// > +// // where +// // FormerEnd : former::FormingEnd< Struct1FormerDefinition >, +// { +// storage : Struct1FormerStorage, +// context : core::option::Option< FormerContext >, +// on_end : core::option::Option< FormerEnd >, +// } +// +// #[ automatically_derived ] +// impl< FormerContext, FormerEnd > Struct1Former< FormerContext, FormerEnd > +// // where +// // FormerEnd : former::FormingEnd< Struct1FormerDefinition >, +// { +// #[ doc = r"" ] +// #[ doc = r" Finish setting options and return formed entity." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn preform( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed +// { +// < Struct1FormerStorage as former::StoragePerform >::preform( self.storage ) +// } +// +// #[ inline( always ) ] +// pub fn perform( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed +// { +// let result = self.form(); +// return result; +// } +// #[ doc = r"" ] +// #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn begin( mut storage : core::option::Option< Struct1FormerStorage >, context : core::option::Option< FormerContext >, on_end : FormerEnd, ) -> Self +// { +// if storage.is_none() +// { +// storage = Some( ::core::default::Default::default() ); +// } +// Self +// { +// storage : storage.unwrap(), +// context : context, +// on_end : ::core::option::Option::Some( on_end ), +// } +// } +// #[ doc = r"" ] +// #[ doc = r" End the process of forming returning original context of forming." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn form( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed +// { +// self.end() +// } +// #[ doc = r"" ] +// #[ doc = r" End the process of forming returning original context of forming." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn end( mut self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed +// { +// let on_end = self.on_end.take().unwrap(); +// let context = self.context.take(); +// // on_end.call( self.storage, context ) +// former::FormingEnd::< Struct1FormerDefinition >::call( &on_end, self.storage, context ) +// } +// #[ doc = "Setter for the 'int_1' field." ] +// #[ inline ] +// pub fn int_1< Src >( mut self, src : Src ) -> Self +// where +// Src : ::core::convert::Into< i32 >, +// { +// debug_assert!( self.storage.int_1.is_none() ); +// self.storage.int_1 = ::core::option::Option::Some( src.into() ); +// self +// } +// #[ doc = "Setter for the 'string_1' field." ] +// #[ inline ] +// pub fn string_1< Src >( mut self, src : Src ) -> Self +// where +// Src : ::core::convert::Into< String >, +// { +// debug_assert!( self.storage.string_1.is_none() ); +// self.storage.string_1 = ::core::option::Option::Some( src.into() ); +// self +// } +// #[ doc = "Setter for the 'int_optional_1' field." ] +// #[ inline ] +// pub fn int_optional_1< Src >( mut self, src : Src ) -> Self +// where +// Src : ::core::convert::Into< i32 >, +// { +// debug_assert!( self.storage.int_optional_1.is_none() ); +// self.storage.int_optional_1 = ::core::option::Option::Some( src.into() ); +// self +// } +// #[ doc = "Setter for the 'string_optional_1' field." ] +// #[ inline ] +// pub fn string_optional_1< Src >( mut self, src : Src ) -> Self +// where +// Src : ::core::convert::Into< String >, +// { +// debug_assert!( self.storage.string_optional_1.is_none() ); +// self.storage.string_optional_1 = ::core::option::Option::Some( src.into() ); +// self +// } +// } +// +// #[ automatically_derived ] +// impl Struct1Former< (), former::ReturnPreformed > +// { +// #[ doc = r"" ] +// #[ doc = r" Construct new instance of former with default parameters." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn new() -> Self +// { +// Self::begin( None, None, former::ReturnPreformed, ) +// } +// } // diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index f05665a731..ee225ae1fc 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -40,7 +40,6 @@ for Struct1FormerDefinition type Storage = Struct1FormerStorage; type Formed = Struct1; type Context = (); - // type End = former::ReturnPreformed; } impl former::FormerDefinition diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index c9b4a5805f..68ee5ba65e 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -17,8 +17,8 @@ mod former_tests mod container_former_hashmap; mod a_primitives_manual; + mod a_primitives_expanded; // mod a_primitives; - // mod a_primitives_expanded; // mod a_containers_without_runtime_manual; // mod a_containers_without_runtime; // #[ cfg( not( feature = "no_std" ) ) ] diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 52d39080e2..6727879445 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -743,7 +743,7 @@ For specifying custom default value use attribute `default`. For example: pub fn performer< 'a > ( _name_ident : &syn::Ident, - former_descriptor_name_ident : &syn::Ident, + former_definition_name_ident : &syn::Ident, generics_ty : &syn::TypeGenerics< '_ >, attrs : impl Iterator< Item = &'a syn::Attribute >, ) @@ -755,7 +755,7 @@ pub fn performer< 'a > return result; }; // let mut perform_output = qt!{ #name_ident #generics_ty }; - let mut perform_output = qt!{ < #former_descriptor_name_ident #generics_ty as former::FormerDefinition >::Formed }; + let mut perform_output = qt!{ < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed }; let mut perform_generics = qt!{}; for attr in attrs @@ -827,8 +827,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_name_ident = syn::Ident::new( &former_name, name_ident.span() ); let former_storage_name = format!( "{}FormerStorage", name_ident ); let former_storage_name_ident = syn::Ident::new( &former_storage_name, name_ident.span() ); - let former_descriptor_name = format!( "{}FormerDefinition", name_ident ); - let former_descriptor_name_ident = syn::Ident::new( &former_descriptor_name, name_ident.span() ); + let former_definition_name = format!( "{}FormerDefinition", name_ident ); + let former_definition_name_ident = syn::Ident::new( &former_definition_name, name_ident.span() ); + // let former_definition_type_name = format!( "{}FormerDefinitionTypes", name_ident ); + // let former_definition_type_name_ident = syn::Ident::new( &former_definition_name, name_ident.span() ); /* generic parameters */ @@ -848,12 +850,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // add embedded generic parameters let mut extra_generics : syn::Generics = parse_quote! { - < __FormerContext = #name_ident #generics_ty, __FormerEnd = former::ReturnFormed > + < __FormerContext = #name_ident #generics_ty, __FormerEnd = former::ReturnPreformed > }; extra_generics.where_clause = parse_quote! { where - __FormerEnd : former::FormingEnd< #former_descriptor_name_ident #generics_ty, __FormerContext >, + __FormerEnd : former::FormingEnd< #former_definition_name_ident #generics_ty >, }; // xxx : write helper to fix bug with where let generics_of_former = generics::merge( &generics, &extra_generics ); @@ -867,7 +869,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( perform, perform_output, perform_generics ) = performer ( &name_ident, - &former_descriptor_name_ident, + &former_definition_name_ident, &generics_ty, ast.attrs.iter(), )?; @@ -932,32 +934,48 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// Make former, variation of builder pattern to form structure defining values of fields step by step. /// #[ inline( always ) ] - pub fn former() -> #former_name_ident < #generics_params (), former::ReturnFormed > + // pub fn former() -> #former_name_ident < #generics_params (), former::ReturnPreformed > + pub fn former() -> #former_name_ident < #generics_params > { #former_name_ident :: new() } } - // = descriptor + // = definition - #[ derive( Debug ) ] - pub struct #former_descriptor_name_ident #generics_ty; + #[ derive( Debug, Default ) ] + pub struct #former_definition_name_ident #generics_ty; - impl #generics_impl #former_descriptor_name_ident #generics_ty + impl #generics_impl former::FormerDefinitionTypes + for #former_definition_name_ident #generics_ty { - pub fn new() -> Self - { - Self - } + type Storage = #former_storage_name_ident #generics_ty; + type Formed = #name_ident #generics_ty; + type Context = (); } impl #generics_impl former::FormerDefinition - for #former_descriptor_name_ident #generics_ty + for #former_definition_name_ident #generics_ty { - type Storage = #former_storage_name_ident #generics_ty; - type Formed = #name_ident #generics_ty; + type Types = #former_definition_name_ident #generics_ty; + type End = former::ReturnPreformed; } +// impl former::FormerDefinitionTypes +// for Struct1FormerDefinition +// { +// type Storage = Struct1FormerStorage; +// type Formed = Struct1; +// type Context = (); +// } +// +// impl former::FormerDefinition +// for Struct1FormerDefinition +// { +// type Types = Struct1FormerDefinition; +// type End = former::ReturnPreformed; +// } + // = storage // xxx : rename to storage @@ -991,7 +1009,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #generics_where { // type Definition = Struct1FormerDefinition; - type Definition = #former_descriptor_name_ident #generics_ty; + // type Definition = #former_definition_name_ident #generics_ty; + type Formed = #name_ident #generics_ty; } // generics_impl, generics_ty, generics_where @@ -1001,11 +1020,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { // fn preform( mut self ) -> #former_storage_name_ident #generics_ty - fn preform( mut self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDefinition >::Formed + fn preform( mut self ) -> < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed { #( #fields_form )* // Rust does not support that, yet - // let result = < #former_descriptor_name_ident #generics_ty as former::FormerDefinition >::Formed + // let result = < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed let result = #name_ident #generics_ty { #( #fields_names, )* @@ -1018,7 +1037,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = former #[ doc = #doc_former_struct ] - #[ automatically_derived ] pub struct #former_name_ident < #generics_of_former_with_defaults > #generics_of_former_where { @@ -1037,7 +1055,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// Finish setting options and return formed entity. /// #[ inline( always ) ] - pub fn preform( self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDefinition >::Formed + pub fn preform( self ) -> < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed // #name_ident #generics_ty { < #former_storage_name_ident #generics_ty as former::StoragePerform >::preform( self.storage ) @@ -1089,7 +1107,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn form( self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDefinition >::Formed + pub fn form( self ) -> < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed { self.end() } @@ -1098,12 +1116,13 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn end( mut self ) -> < #former_descriptor_name_ident #generics_ty as former::FormerDefinition >::Formed + pub fn end( mut self ) -> < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); // let storage = self.form(); - on_end.call( self.storage, context ) + // on_end.call( self.storage, context ) + former::FormingEnd::< #former_definition_name_ident #generics_ty >::call( &on_end, self.storage, context ) } #( @@ -1113,7 +1132,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } #[ automatically_derived ] - impl #generics_impl #former_name_ident < #generics_params (), former::ReturnFormed > + impl #generics_impl #former_name_ident < #generics_params (), former::ReturnPreformed > #generics_where { @@ -1123,12 +1142,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ inline( always ) ] pub fn new() -> Self { - // #former_name_ident :: < #generics_params #name_ident #generics_ty, former::ReturnFormed > :: begin + // #former_name_ident :: < #generics_params #name_ident #generics_ty, former::ReturnPreformed > :: begin Self :: begin ( None, None, - former::ReturnFormed, + former::ReturnPreformed, ) } From c9be2d1236e48a0171d8892e8ec5c9447b6c7d6d Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 29 Mar 2024 12:47:19 +0200 Subject: [PATCH 063/533] experimenting --- .../inc/former_tests/a_primitives_manual.rs | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index ee225ae1fc..e10466747b 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -26,12 +26,23 @@ impl Struct1 #[ derive( Debug, Default ) ] pub struct Struct1FormerDefinition; -// impl Struct1FormerDefinition +#[ derive( Debug, Default ) ] +pub struct Struct1FormerDefinition2< E, Context = (), Formed = Struct1, End = former::ReturnPreformed > +// where +// End : FormingEnd< Struct1FormerDefinition< E, Context, Formed, NoEnd > >, +{ + _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, +} + +// #[ derive( Default ) ] +// pub struct ContainerSubformer< E, Definition > +// where +// Definition : FormerDefinition, +// // < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, // { -// pub fn new() -> Self -// { -// Self -// } +// storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, +// context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, +// on_end : core::option::Option< Definition::End >, // } impl former::FormerDefinitionTypes @@ -249,4 +260,5 @@ impl Struct1Former // -include!( "./only_test/primitives.rs" ); +// xxx : uncomment +// include!( "./only_test/primitives.rs" ); From b577754848af62b0905dfff6475beec88e9c3d1f Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 29 Mar 2024 14:25:34 +0200 Subject: [PATCH 064/533] experimenting --- .../inc/former_tests/a_primitives_manual.rs | 36 ++++++++++--------- module/core/former/tests/inc/mod.rs | 2 +- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index e10466747b..42d5f66064 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -23,28 +23,17 @@ impl Struct1 // = definition -#[ derive( Debug, Default ) ] -pub struct Struct1FormerDefinition; +// #[ derive( Debug, Default ) ] +// pub struct Struct1FormerDefinition; #[ derive( Debug, Default ) ] -pub struct Struct1FormerDefinition2< E, Context = (), Formed = Struct1, End = former::ReturnPreformed > +pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > // where -// End : FormingEnd< Struct1FormerDefinition< E, Context, Formed, NoEnd > >, +// End : FormingEnd< Struct1FormerDefinition< Context, Formed, NoEnd > >, { - _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, + _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } -// #[ derive( Default ) ] -// pub struct ContainerSubformer< E, Definition > -// where -// Definition : FormerDefinition, -// // < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, -// { -// storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, -// context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, -// on_end : core::option::Option< Definition::End >, -// } - impl former::FormerDefinitionTypes for Struct1FormerDefinition { @@ -156,12 +145,25 @@ for Struct1FormerStorage // = former +// #[ derive( Default ) ] +// pub struct ContainerSubformer< E, Definition > +// where +// Definition : FormerDefinition, +// // < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, +// { +// storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, +// context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, +// on_end : core::option::Option< Definition::End >, +// } + pub struct Struct1Former < + // Definition, // FormerContext = Struct1, // FormerEnd = the_module::ReturnPreformed, > -// where +where + // Definition : FormerDefinition, // FormerEnd : the_module::FormingEnd< Struct1FormerDefinition >, { storage : Struct1FormerStorage, diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 68ee5ba65e..7cbd0487ae 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -17,7 +17,7 @@ mod former_tests mod container_former_hashmap; mod a_primitives_manual; - mod a_primitives_expanded; + // mod a_primitives_expanded; // mod a_primitives; // mod a_containers_without_runtime_manual; // mod a_containers_without_runtime; From 87a175591dcd1697331ed81f48d512b36b15ed0e Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 29 Mar 2024 15:18:16 +0200 Subject: [PATCH 065/533] experimenting --- .../inc/former_tests/a_primitives_manual.rs | 62 +++++++++++-------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 42d5f66064..1af869d454 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -28,25 +28,29 @@ impl Struct1 #[ derive( Debug, Default ) ] pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +// xxx : use? // where // End : FormingEnd< Struct1FormerDefinition< Context, Formed, NoEnd > >, { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } -impl former::FormerDefinitionTypes -for Struct1FormerDefinition +impl< Context, Formed > former::FormerDefinitionTypes +for Struct1FormerDefinition< Context, Formed, former::NoEnd > { type Storage = Struct1FormerStorage; - type Formed = Struct1; - type Context = (); + type Formed = Formed; + type Context = Context; } -impl former::FormerDefinition -for Struct1FormerDefinition +impl< Context, Formed, End > former::FormerDefinition +for Struct1FormerDefinition< Context, Formed, End > +where + End : former::FormingEnd< Struct1FormerDefinition< Context, Formed, former::NoEnd > >, { - type Types = Struct1FormerDefinition; - type End = former::ReturnPreformed; + // type Types = Struct1FormerDefinition; + type Types = Struct1FormerDefinition< Context, Formed, former::NoEnd >; + type End = End; } // = storage @@ -80,7 +84,6 @@ impl Default for Struct1FormerStorage impl former::Storage for Struct1FormerStorage { - // type Types = Struct1FormerDefinition; type Formed = Struct1; } @@ -130,7 +133,7 @@ for Struct1FormerStorage }; // Rust failt to use parameter here - // < < Self as former::Storage >::Definition as former::FormerDefinitionTypes >::Formed + // < < Self as former::Storage >::Definition::Types as former::FormerDefinitionTypes >::Formed Struct1 { int_1, @@ -158,31 +161,39 @@ for Struct1FormerStorage pub struct Struct1Former < - // Definition, + Definition = Struct1FormerDefinition, // FormerContext = Struct1, // FormerEnd = the_module::ReturnPreformed, > where - // Definition : FormerDefinition, + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = < Definition::Types as former::FormerDefinitionTypes >::Formed >, // FormerEnd : the_module::FormingEnd< Struct1FormerDefinition >, { - storage : Struct1FormerStorage, - context : core::option::Option< < Struct1FormerDefinition as former::FormerDefinitionTypes >::Context >, - on_end : core::option::Option< < Struct1FormerDefinition as former::FormerDefinition >::End >, + storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : core::option::Option< Definition::End >, + // storage : Struct1FormerStorage, + // context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + // on_end : core::option::Option< < Definition as former::FormerDefinition >::End >, } -impl Struct1Former -// where +impl< Definition > Struct1Former< Definition > +where + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = < Definition::Types as former::FormerDefinitionTypes >::Formed >, // FormerEnd: the_module::FormingEnd< Struct1FormerDefinition, FormerContext >, { - fn preform( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { former::StoragePerform::preform( self.storage ) } #[ inline( always ) ] - pub fn perform(self) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + pub fn perform(self) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { let result = self.form(); return result; @@ -191,9 +202,9 @@ impl Struct1Former #[ inline( always ) ] pub fn begin ( - mut storage : core::option::Option< < Struct1FormerDefinition as former::FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Struct1FormerDefinition as former::FormerDefinitionTypes >::Context >, - on_end : < Struct1FormerDefinition as former::FormerDefinition >::End, + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : < Definition as former::FormerDefinition >::End, // xxx : cover by test existance of these 3 parameters in the function ) -> Self { @@ -210,15 +221,16 @@ impl Struct1Former } #[ inline( always ) ] - pub fn end( mut self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - former::FormingEnd::< Struct1FormerDefinition >::call( &on_end, self.storage, context ) + former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) + // former::FormingEnd::< Struct1FormerDefinition >::call( &on_end, self.storage, context ) } #[ inline( always ) ] - pub fn form( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { self.end() } From 638f7e1fc3ce60e128f861f9051e834a81784209 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 29 Mar 2024 15:30:02 +0200 Subject: [PATCH 066/533] experimenting --- .../tests/inc/former_tests/a_primitives_manual.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 1af869d454..5cf8fb2bb3 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -159,6 +159,7 @@ for Struct1FormerStorage // on_end : core::option::Option< Definition::End >, // } +// Storage = Struct1FormerStorage pub struct Struct1Former < Definition = Struct1FormerDefinition, @@ -168,7 +169,8 @@ pub struct Struct1Former where Definition : former::FormerDefinition, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = < Definition::Types as former::FormerDefinitionTypes >::Formed >, + // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = < Definition::Types as former::FormerDefinitionTypes >::Formed >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, // FormerEnd : the_module::FormingEnd< Struct1FormerDefinition >, { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, @@ -183,11 +185,13 @@ impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = < Definition::Types as former::FormerDefinitionTypes >::Formed >, + // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = < Definition::Types as former::FormerDefinitionTypes >::Formed >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, // FormerEnd: the_module::FormingEnd< Struct1FormerDefinition, FormerContext >, { - fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + // fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + fn preform( self ) -> Struct1 { former::StoragePerform::preform( self.storage ) } From a3a3b64f21742fe9692e431da3e469f8511e65e7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 29 Mar 2024 23:23:40 +0200 Subject: [PATCH 067/533] former : experimenting --- .../inc/former_tests/a_primitives_manual.rs | 20 +++++++++++++++++-- .../inc/former_tests/only_test/primitives.rs | 18 +++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 5cf8fb2bb3..b26549a0c3 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -26,7 +26,7 @@ impl Struct1 // #[ derive( Debug, Default ) ] // pub struct Struct1FormerDefinition; -#[ derive( Debug, Default ) ] +#[ derive( Debug ) ] pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > // xxx : use? // where @@ -35,6 +35,22 @@ pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } +impl< Context, Formed, End > Default +for Struct1FormerDefinition< Context, Formed, End > +// where +// Context : Default, +// Formed : Default, +// End : Default, +{ + fn default() -> Self + { + Struct1FormerDefinition + { + _phantom : core::marker::PhantomData, + } + } +} + impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinition< Context, Formed, former::NoEnd > { @@ -279,4 +295,4 @@ impl Struct1Former // // xxx : uncomment -// include!( "./only_test/primitives.rs" ); +include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index b09e881925..9697da9b4a 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -82,16 +82,22 @@ tests_impls! { // default is implemented for definition - let _default = Struct1FormerDefinition::default(); + let _default = Struct1FormerDefinition::< () >::default(); + // let _default = Struct1FormerDefinition::default(); // why does not work? - // definition types exists and has Formed - let got = < Struct1FormerDefinition as the_module::FormerDefinitionTypes >::Formed::former().form(); - let exp = Struct1::former().form(); - a_id!( got, exp ); + // impl< Context, Formed, End > Default + + // // definition types exists and has Formed + // let got = < Struct1FormerDefinition as the_module::FormerDefinitionTypes >::Formed::former().form(); + // let exp = Struct1::former().form(); + // a_id!( got, exp ); + // xxx : uncomment + + // < Context = (), Formed = Struct1, End = former::ReturnPreformed > // definition types exists and has Storage use former::StoragePerform; - let got = < Struct1FormerDefinition as the_module::FormerDefinitionTypes >::Storage::preform( Struct1::former().storage ); + let got = < Struct1FormerDefinition< (), Struct1, former::NoEnd > as the_module::FormerDefinitionTypes >::Storage::preform( Struct1::former().storage ); let exp = Struct1::former().form(); a_id!( got, exp ); From 10fbde300f294f10b6c5e60eb1c8fff755c4906c Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 29 Mar 2024 23:25:43 +0200 Subject: [PATCH 068/533] former : experimenting --- .../tests/inc/former_tests/only_test/primitives.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 9697da9b4a..37c27d85f7 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -87,10 +87,11 @@ tests_impls! // impl< Context, Formed, End > Default - // // definition types exists and has Formed - // let got = < Struct1FormerDefinition as the_module::FormerDefinitionTypes >::Formed::former().form(); - // let exp = Struct1::former().form(); - // a_id!( got, exp ); + // definition types exists and has Formed + let got = < Struct1FormerDefinition< (), Struct1, former::NoEnd > as the_module::FormerDefinitionTypes >::Formed::former().form(); + // let got = < Struct1FormerDefinition as the_module::FormerDefinitionTypes >::Formed::former().form(); // xxx : make it working + let exp = Struct1::former().form(); + a_id!( got, exp ); // xxx : uncomment // < Context = (), Formed = Struct1, End = former::ReturnPreformed > From 68bd732e214c134c3b525da03d1409095f3b9b61 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 29 Mar 2024 23:54:03 +0200 Subject: [PATCH 069/533] former : experimenting --- .../tests/inc/former_tests/a_primitives_manual.rs | 11 +++++++++-- .../tests/inc/former_tests/only_test/primitives.rs | 4 +--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index b26549a0c3..430dbd8b4e 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -30,7 +30,9 @@ impl Struct1 pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > // xxx : use? // where -// End : FormingEnd< Struct1FormerDefinition< Context, Formed, NoEnd > >, +// End : former::FormingEnd< Struct1FormerDefinition< Context, Formed, NoEnd > >, +// where + // End : former::FormingEnd< Self >, { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } @@ -53,6 +55,10 @@ for Struct1FormerDefinition< Context, Formed, End > impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinition< Context, Formed, former::NoEnd > +// impl< Context, Formed, End > former::FormerDefinitionTypes +// for Struct1FormerDefinition< Context, Formed, End > +// where +// End : former::FormingEnd< Self >, { type Storage = Struct1FormerStorage; type Formed = Formed; @@ -63,9 +69,10 @@ impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > where End : former::FormingEnd< Struct1FormerDefinition< Context, Formed, former::NoEnd > >, + // End : former::FormingEnd< Self >, { - // type Types = Struct1FormerDefinition; type Types = Struct1FormerDefinition< Context, Formed, former::NoEnd >; + // type Types = Self; type End = End; } diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 37c27d85f7..3ea0a9aafc 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -85,11 +85,9 @@ tests_impls! let _default = Struct1FormerDefinition::< () >::default(); // let _default = Struct1FormerDefinition::default(); // why does not work? - // impl< Context, Formed, End > Default - // definition types exists and has Formed let got = < Struct1FormerDefinition< (), Struct1, former::NoEnd > as the_module::FormerDefinitionTypes >::Formed::former().form(); - // let got = < Struct1FormerDefinition as the_module::FormerDefinitionTypes >::Formed::former().form(); // xxx : make it working + // let got = < Struct1FormerDefinition<> as the_module::FormerDefinitionTypes >::Formed::former().form(); let exp = Struct1::former().form(); a_id!( got, exp ); // xxx : uncomment From 79af2519de16cb3eb644471728941288990802d6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 00:39:34 +0200 Subject: [PATCH 070/533] former : experimenting --- .../inc/former_tests/a_primitives_expanded.rs | 566 ++++++++++-------- .../inc/former_tests/a_primitives_manual.rs | 25 +- module/core/former/tests/inc/mod.rs | 2 +- module/core/former_meta/src/derive/former.rs | 67 ++- 4 files changed, 346 insertions(+), 314 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs index ea4eee4e00..5c0887703a 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -12,278 +12,318 @@ pub struct Struct1 } // = generated +#[ automatically_derived ] +impl Struct1 +{ + #[ doc = r"" ] + #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn former() -> Struct1Former< > + { + Struct1Former::new() + } +} + +#[ derive( Debug ) ] +pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +// where +// End : former::FormingEnd< Struct1FormerDefinition< Context, Formed, NoEnd > >, +{ + _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, +} + +impl< Context, Formed, End > Default +for Struct1FormerDefinition< Context, Formed, End > +{ + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} -// #[ automatically_derived ] -// impl Struct1 -// { -// #[ doc = r"" ] -// #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// // pub fn former() -> Struct1Former< (), former::ReturnPreformed > -// pub fn former() -> Struct1Former<> -// { -// Struct1Former::new() -// } -// } -// // #[ derive( Debug, Default ) ] // pub struct Struct1FormerDefinition; -// -// impl former::FormerDefinitionTypes for Struct1FormerDefinition -// { -// type Storage = Struct1FormerStorage; -// type Formed = Struct1; -// type Context = (); -// } -// -// impl former::FormerDefinition for Struct1FormerDefinition -// { -// type Types = Struct1FormerDefinition; -// type End = former::ReturnPreformed; -// } -// -// #[ doc = "Container of a corresponding former." ] -// pub struct Struct1FormerStorage -// { -// #[ doc = r" A field" ] -// pub int_1 : ::core::option::Option< i32 >, -// #[ doc = r" A field" ] -// pub string_1 : ::core::option::Option< String >, -// #[ doc = r" A field" ] -// pub int_optional_1 : core::option::Option< i32 >, -// #[ doc = r" A field" ] -// pub string_optional_1 : Option< String >, -// } -// -// impl ::core::default::Default for Struct1FormerStorage -// { -// #[ inline( always ) ] -// fn default() -> Self -// { -// Self -// { -// int_1 : ::core::option::Option::None, -// string_1 : ::core::option::Option::None, -// int_optional_1 : ::core::option::Option::None, -// string_optional_1 : ::core::option::Option::None, -// } -// } -// } -// -// impl former::Storage for Struct1FormerStorage -// { -// // type Definition = Struct1FormerDefinition; -// type Formed = Struct1; -// } -// -// impl former::StoragePerform for Struct1FormerStorage -// { -// fn preform( mut self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed -// { -// let int_1 = if self.int_1.is_some() -// { -// self.int_1.take().unwrap() -// } -// else -// { -// { -// trait MaybeDefault< T > -// { -// fn maybe_default( self : &Self ) -> T -// { -// panic!( "Field 'int_1' isn't initialized" ) -// } -// } -// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} -// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > -// where T : ::core::default::Default, -// { -// fn maybe_default( self : &Self ) -> T -// { -// T::default() -// } -// } -// ( &::core::marker::PhantomData::< i32 > ).maybe_default() -// } -// }; -// let string_1 = if self.string_1.is_some() -// { -// self.string_1.take().unwrap() -// } -// else -// { -// { -// trait MaybeDefault< T > -// { -// fn maybe_default( self : &Self ) -> T -// { -// panic!( "Field 'string_1' isn't initialized" ) -// } -// } -// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} -// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > -// where T : ::core::default::Default, -// { -// fn maybe_default( self : &Self ) -> T -// { -// T::default() -// } -// } -// ( &::core::marker::PhantomData::< String > ).maybe_default() -// } -// }; -// let int_optional_1 = if self.int_optional_1.is_some() -// { -// ::core::option::Option::Some( self.int_optional_1.take().unwrap() ) -// } -// else -// { -// ::core::option::Option::None -// }; -// let string_optional_1 = if self.string_optional_1.is_some() -// { -// ::core::option::Option::Some( self.string_optional_1.take().unwrap() ) -// } -// else -// { -// ::core::option::Option::None -// }; -// let result = Struct1 -// { -// int_1, -// string_1, -// int_optional_1, -// string_optional_1, -// }; -// return result; -// } -// } -// + +impl former::FormerDefinitionTypes for Struct1FormerDefinition +{ + type Storage = Struct1FormerStorage; + type Formed = Struct1; + type Context = (); +} + +impl former::FormerDefinition for Struct1FormerDefinition +{ + type Types = Struct1FormerDefinition; + type End = former::ReturnPreformed; +} + +#[ doc = "Container of a corresponding former." ] +pub struct Struct1FormerStorage +{ + #[ doc = r" A field" ] + pub int_1 : ::core::option::Option< i32 >, + #[ doc = r" A field" ] + pub string_1 : ::core::option::Option< String >, + #[ doc = r" A field" ] + pub int_optional_1 : core::option::Option< i32 >, + #[ doc = r" A field" ] + pub string_optional_1 : Option< String >, +} + +impl ::core::default::Default for Struct1FormerStorage +{ + #[ inline( always ) ] + fn default() -> Self + { + Self + { + int_1 : ::core::option::Option::None, + string_1 : ::core::option::Option::None, + int_optional_1 : ::core::option::Option::None, + string_optional_1 : ::core::option::Option::None, + } + } +} + +impl former::Storage for Struct1FormerStorage +{ + type Formed = Struct1; +} + +impl former::StoragePerform for Struct1FormerStorage +{ + // fn preform( mut self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + fn preform( mut self ) -> < Self as former::Storage >::Formed + { + let int_1 = if self.int_1.is_some() + { + self.int_1.take().unwrap() + } + else + { + { + trait MaybeDefault< T > + { + fn maybe_default( self : &Self ) -> T + { + panic!( "Field 'int_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< i32 > ).maybe_default() + } + }; + let string_1 = if self.string_1.is_some() + { + self.string_1.take().unwrap() + } + else + { + { + trait MaybeDefault< T > + { + fn maybe_default( self : &Self ) -> T + { + panic!( "Field 'string_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< String > ).maybe_default() + } + }; + let int_optional_1 = if self.int_optional_1.is_some() + { + ::core::option::Option::Some( self.int_optional_1.take().unwrap() ) + } + else + { + ::core::option::Option::None + }; + let string_optional_1 = if self.string_optional_1.is_some() + { + ::core::option::Option::Some( self.string_optional_1.take().unwrap() ) + } + else + { + ::core::option::Option::None + }; + let result = Struct1 + { + int_1, + string_1, + int_optional_1, + string_optional_1, + }; + return result; + } +} + // pub struct Struct1Former -// < -// // FormerContext = Struct1, -// // FormerEnd = former::ReturnPreformed, -// > -// // where -// // FormerEnd : former::FormingEnd< Struct1FormerDefinition >, +// < FormerContext = Struct1, FormerEnd = former::ReturnPreformed > +// where FormerEnd : former::FormingEnd< Struct1FormerDefinition >, // { // storage : Struct1FormerStorage, // context : core::option::Option< FormerContext >, // on_end : core::option::Option< FormerEnd >, // } -// -// #[ automatically_derived ] -// impl< FormerContext, FormerEnd > Struct1Former< FormerContext, FormerEnd > -// // where -// // FormerEnd : former::FormingEnd< Struct1FormerDefinition >, -// { -// #[ doc = r"" ] -// #[ doc = r" Finish setting options and return formed entity." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn preform( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed -// { -// < Struct1FormerStorage as former::StoragePerform >::preform( self.storage ) -// } -// -// #[ inline( always ) ] -// pub fn perform( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed -// { -// let result = self.form(); -// return result; -// } -// #[ doc = r"" ] -// #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn begin( mut storage : core::option::Option< Struct1FormerStorage >, context : core::option::Option< FormerContext >, on_end : FormerEnd, ) -> Self -// { -// if storage.is_none() -// { -// storage = Some( ::core::default::Default::default() ); -// } -// Self -// { -// storage : storage.unwrap(), -// context : context, -// on_end : ::core::option::Option::Some( on_end ), -// } -// } -// #[ doc = r"" ] -// #[ doc = r" End the process of forming returning original context of forming." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn form( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed -// { -// self.end() -// } -// #[ doc = r"" ] -// #[ doc = r" End the process of forming returning original context of forming." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn end( mut self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed -// { -// let on_end = self.on_end.take().unwrap(); -// let context = self.context.take(); -// // on_end.call( self.storage, context ) -// former::FormingEnd::< Struct1FormerDefinition >::call( &on_end, self.storage, context ) -// } -// #[ doc = "Setter for the 'int_1' field." ] -// #[ inline ] -// pub fn int_1< Src >( mut self, src : Src ) -> Self -// where -// Src : ::core::convert::Into< i32 >, -// { -// debug_assert!( self.storage.int_1.is_none() ); -// self.storage.int_1 = ::core::option::Option::Some( src.into() ); -// self -// } -// #[ doc = "Setter for the 'string_1' field." ] -// #[ inline ] -// pub fn string_1< Src >( mut self, src : Src ) -> Self -// where -// Src : ::core::convert::Into< String >, -// { -// debug_assert!( self.storage.string_1.is_none() ); -// self.storage.string_1 = ::core::option::Option::Some( src.into() ); -// self -// } -// #[ doc = "Setter for the 'int_optional_1' field." ] -// #[ inline ] -// pub fn int_optional_1< Src >( mut self, src : Src ) -> Self -// where -// Src : ::core::convert::Into< i32 >, -// { -// debug_assert!( self.storage.int_optional_1.is_none() ); -// self.storage.int_optional_1 = ::core::option::Option::Some( src.into() ); -// self -// } -// #[ doc = "Setter for the 'string_optional_1' field." ] -// #[ inline ] -// pub fn string_optional_1< Src >( mut self, src : Src ) -> Self -// where -// Src : ::core::convert::Into< String >, -// { -// debug_assert!( self.storage.string_optional_1.is_none() ); -// self.storage.string_optional_1 = ::core::option::Option::Some( src.into() ); -// self -// } -// } -// -// #[ automatically_derived ] -// impl Struct1Former< (), former::ReturnPreformed > -// { -// #[ doc = r"" ] -// #[ doc = r" Construct new instance of former with default parameters." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn new() -> Self -// { -// Self::begin( None, None, former::ReturnPreformed, ) -// } -// } -// +pub struct Struct1Former +< + Definition = Struct1FormerDefinition, +> +where + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +{ + storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : core::option::Option< Definition::End >, +} + +#[ automatically_derived ] +impl< Definition > Struct1Former< Definition > +where + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +{ + #[ doc = r"" ] + #[ doc = r" Finish setting options and return formed entity." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn preform( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + { + < Struct1FormerStorage as former::StoragePerform >::preform( self.storage ) + } + #[ doc = r"" ] + #[ doc = r" Finish setting options and call perform on formed entity." ] + #[ doc = r"" ] + #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] + #[ doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn perform( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + { + let result = self.form(); + return result; + } + #[ doc = r"" ] + #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn begin + ( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : < Definition as former::FormerDefinition >::End, + ) -> Self + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some( on_end ), + } + } + #[ doc = r"" ] + #[ doc = r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn form( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + { + self.end() + } + #[ doc = r"" ] + #[ doc = r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn end( mut self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) + // former::FormingEnd::< Struct1FormerDefinition >::call( &on_end, self.storage, context ) + } + #[ doc = "Setter for the 'int_1' field." ] + #[ inline ] + pub fn int_1< Src >( mut self, src : Src ) -> Self + where + Src : ::core::convert::Into< i32 >, + { + debug_assert!( self.storage.int_1.is_none() ); + self.storage.int_1 = ::core::option::Option::Some( src.into() ); + self + } + #[ doc = "Setter for the 'string_1' field." ] + #[ inline ] + pub fn string_1< Src >( mut self, src : Src ) -> Self + where + Src : ::core::convert::Into< String >, + { + debug_assert!( self.storage.string_1.is_none() ); + self.storage.string_1 = ::core::option::Option::Some( src.into() ); + self + } + #[ doc = "Setter for the 'int_optional_1' field." ] + #[ inline ] + pub fn int_optional_1< Src >( mut self, src : Src ) -> Self + where + Src : ::core::convert::Into< i32 >, + { + debug_assert!( self.storage.int_optional_1.is_none() ); + self.storage.int_optional_1 = ::core::option::Option::Some( src.into() ); + self + } + #[ doc = "Setter for the 'string_optional_1' field." ] + #[ inline ] + pub fn string_optional_1< Src >( mut self, src : Src ) -> Self + where + Src : ::core::convert::Into< String >, + { + debug_assert!( self.storage.string_optional_1.is_none() ); + self.storage.string_optional_1 = ::core::option::Option::Some( src.into() ); + self + } +} + +#[ automatically_derived ] +impl Struct1Former +{ + #[ doc = r"" ] + #[ doc = r" Construct new instance of former with default parameters." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn new() -> Self + { + Self::begin( None, None, former::ReturnPreformed, ) + } +} + +// = end of generated // include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 430dbd8b4e..2866b74981 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -23,30 +23,20 @@ impl Struct1 // = definition -// #[ derive( Debug, Default ) ] -// pub struct Struct1FormerDefinition; - #[ derive( Debug ) ] pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > -// xxx : use? // where // End : former::FormingEnd< Struct1FormerDefinition< Context, Formed, NoEnd > >, -// where - // End : former::FormingEnd< Self >, { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > -// where -// Context : Default, -// Formed : Default, -// End : Default, { fn default() -> Self { - Struct1FormerDefinition + Self { _phantom : core::marker::PhantomData, } @@ -55,8 +45,6 @@ for Struct1FormerDefinition< Context, Formed, End > impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinition< Context, Formed, former::NoEnd > -// impl< Context, Formed, End > former::FormerDefinitionTypes -// for Struct1FormerDefinition< Context, Formed, End > // where // End : former::FormingEnd< Self >, { @@ -182,35 +170,25 @@ for Struct1FormerStorage // on_end : core::option::Option< Definition::End >, // } -// Storage = Struct1FormerStorage pub struct Struct1Former < Definition = Struct1FormerDefinition, - // FormerContext = Struct1, - // FormerEnd = the_module::ReturnPreformed, > where Definition : former::FormerDefinition, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, - // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = < Definition::Types as former::FormerDefinitionTypes >::Formed >, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, - // FormerEnd : the_module::FormingEnd< Struct1FormerDefinition >, { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : core::option::Option< Definition::End >, - // storage : Struct1FormerStorage, - // context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - // on_end : core::option::Option< < Definition as former::FormerDefinition >::End >, } impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, - // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = < Definition::Types as former::FormerDefinitionTypes >::Formed >, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, - // FormerEnd: the_module::FormingEnd< Struct1FormerDefinition, FormerContext >, { // fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed @@ -291,6 +269,7 @@ where impl Struct1Former { + // xxx : should pass callback #[ inline( always ) ] pub fn new() -> Struct1Former { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 7cbd0487ae..68ee5ba65e 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -17,7 +17,7 @@ mod former_tests mod container_former_hashmap; mod a_primitives_manual; - // mod a_primitives_expanded; + mod a_primitives_expanded; // mod a_primitives; // mod a_containers_without_runtime_manual; // mod a_containers_without_runtime; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 6727879445..fc870ca310 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -829,8 +829,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_storage_name_ident = syn::Ident::new( &former_storage_name, name_ident.span() ); let former_definition_name = format!( "{}FormerDefinition", name_ident ); let former_definition_name_ident = syn::Ident::new( &former_definition_name, name_ident.span() ); - // let former_definition_type_name = format!( "{}FormerDefinitionTypes", name_ident ); - // let former_definition_type_name_ident = syn::Ident::new( &former_definition_name, name_ident.span() ); /* generic parameters */ @@ -850,12 +848,16 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // add embedded generic parameters let mut extra_generics : syn::Generics = parse_quote! { - < __FormerContext = #name_ident #generics_ty, __FormerEnd = former::ReturnPreformed > + // < __FormerContext = #name_ident #generics_ty, __FormerEnd = former::ReturnPreformed > + < Definition = #former_definition_name_ident #generics_ty > }; extra_generics.where_clause = parse_quote! { where - __FormerEnd : former::FormingEnd< #former_definition_name_ident #generics_ty >, + // __FormerEnd : former::FormingEnd< #former_definition_name_ident #generics_ty >, + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, + Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage_name_ident #generics_ty >, }; // xxx : write helper to fix bug with where let generics_of_former = generics::merge( &generics, &extra_generics ); @@ -943,8 +945,28 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = definition - #[ derive( Debug, Default ) ] - pub struct #former_definition_name_ident #generics_ty; + // #[ derive( Debug, Default ) ] + // pub struct #former_definition_name_ident #generics_ty; + + #[ derive( Debug ) ] + pub struct #former_definition_name_ident< Context = (), Formed = #name_ident #generics_ty, End = former::ReturnPreformed > + // where + // End : former::FormingEnd< #former_definition_name_ident< Context, Formed, NoEnd > >, + { + _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, + } + + impl< Context, Formed, End > Default + for #former_definition_name_ident< Context, Formed, End > + { + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + } impl #generics_impl former::FormerDefinitionTypes for #former_definition_name_ident #generics_ty @@ -961,21 +983,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > type End = former::ReturnPreformed; } -// impl former::FormerDefinitionTypes -// for Struct1FormerDefinition -// { -// type Storage = Struct1FormerStorage; -// type Formed = Struct1; -// type Context = (); -// } -// -// impl former::FormerDefinition -// for Struct1FormerDefinition -// { -// type Types = Struct1FormerDefinition; -// type End = former::ReturnPreformed; -// } - // = storage // xxx : rename to storage @@ -1020,7 +1027,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { // fn preform( mut self ) -> #former_storage_name_ident #generics_ty - fn preform( mut self ) -> < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed + // fn preform( mut self ) -> < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed + fn preform( mut self ) -> < Self as former::Storage >::Formed { #( #fields_form )* // Rust does not support that, yet @@ -1086,9 +1094,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ inline( always ) ] pub fn begin ( - mut storage : core::option::Option< #former_storage_name_ident #generics_ty >, - context : core::option::Option< __FormerContext >, - on_end : __FormerEnd, + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : < Definition as former::FormerDefinition >::End, + // mut storage : core::option::Option< #former_storage_name_ident #generics_ty >, + // context : core::option::Option< __FormerContext >, + // on_end : __FormerEnd, ) -> Self { if storage.is_none() @@ -1122,7 +1133,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let context = self.context.take(); // let storage = self.form(); // on_end.call( self.storage, context ) - former::FormingEnd::< #former_definition_name_ident #generics_ty >::call( &on_end, self.storage, context ) + // former::FormingEnd::< #former_definition_name_ident #generics_ty >::call( &on_end, self.storage, context ) + former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) } #( @@ -1132,7 +1144,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } #[ automatically_derived ] - impl #generics_impl #former_name_ident < #generics_params (), former::ReturnPreformed > + // impl #generics_impl #former_name_ident < #generics_params (), former::ReturnPreformed > + impl #generics_impl #former_name_ident < #generics_params > #generics_where { From 1dab7e27a0f520cdda7e6007385188daa1e1ee62 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 00:57:30 +0200 Subject: [PATCH 071/533] former : experimenting --- .../inc/former_tests/a_primitives_expanded.rs | 39 +++++++++++----- .../inc/former_tests/a_primitives_manual.rs | 4 -- module/core/former/tests/inc/mod.rs | 2 +- module/core/former_meta/src/derive/former.rs | 45 +++++++++++++------ 4 files changed, 60 insertions(+), 30 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs index 5c0887703a..e31e120396 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -48,17 +48,34 @@ for Struct1FormerDefinition< Context, Formed, End > // #[ derive( Debug, Default ) ] // pub struct Struct1FormerDefinition; -impl former::FormerDefinitionTypes for Struct1FormerDefinition +// impl former::FormerDefinitionTypes for Struct1FormerDefinition +// { +// type Storage = Struct1FormerStorage; +// type Formed = Struct1; +// type Context = (); +// } +// +// impl former::FormerDefinition for Struct1FormerDefinition +// { +// type Types = Struct1FormerDefinition; +// type End = former::ReturnPreformed; +// } + +impl< Context, Formed > former::FormerDefinitionTypes +for Struct1FormerDefinition< Context, Formed, former::NoEnd > { type Storage = Struct1FormerStorage; - type Formed = Struct1; - type Context = (); + type Formed = Formed; + type Context = Context; } -impl former::FormerDefinition for Struct1FormerDefinition +impl< Context, Formed, End > former::FormerDefinition +for Struct1FormerDefinition< Context, Formed, End > +where + End : former::FormingEnd< Struct1FormerDefinition< Context, Formed, former::NoEnd > >, { - type Types = Struct1FormerDefinition; - type End = former::ReturnPreformed; + type Types = Struct1FormerDefinition< Context, Formed, former::NoEnd >; + type End = End; } #[ doc = "Container of a corresponding former." ] @@ -96,7 +113,7 @@ impl former::Storage for Struct1FormerStorage impl former::StoragePerform for Struct1FormerStorage { - // fn preform( mut self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + // fn preform( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed fn preform( mut self ) -> < Self as former::Storage >::Formed { let int_1 = if self.int_1.is_some() @@ -212,7 +229,7 @@ where #[ doc = r" Finish setting options and return formed entity." ] #[ doc = r"" ] #[ inline( always ) ] - pub fn preform( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { < Struct1FormerStorage as former::StoragePerform >::preform( self.storage ) } @@ -223,7 +240,7 @@ where #[ doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`." ] #[ doc = r"" ] #[ inline( always ) ] - pub fn perform( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { let result = self.form(); return result; @@ -254,7 +271,7 @@ where #[ doc = r" End the process of forming returning original context of forming." ] #[ doc = r"" ] #[ inline( always ) ] - pub fn form( self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { self.end() } @@ -262,7 +279,7 @@ where #[ doc = r" End the process of forming returning original context of forming." ] #[ doc = r"" ] #[ inline( always ) ] - pub fn end( mut self ) -> < Struct1FormerDefinition as former::FormerDefinitionTypes >::Formed + pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 2866b74981..7a72d0d8f9 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -45,8 +45,6 @@ for Struct1FormerDefinition< Context, Formed, End > impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinition< Context, Formed, former::NoEnd > -// where -// End : former::FormingEnd< Self >, { type Storage = Struct1FormerStorage; type Formed = Formed; @@ -57,10 +55,8 @@ impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > where End : former::FormingEnd< Struct1FormerDefinition< Context, Formed, former::NoEnd > >, - // End : former::FormingEnd< Self >, { type Types = Struct1FormerDefinition< Context, Formed, former::NoEnd >; - // type Types = Self; type End = End; } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 68ee5ba65e..7cbd0487ae 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -17,7 +17,7 @@ mod former_tests mod container_former_hashmap; mod a_primitives_manual; - mod a_primitives_expanded; + // mod a_primitives_expanded; // mod a_primitives; // mod a_containers_without_runtime_manual; // mod a_containers_without_runtime; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index fc870ca310..9e341b6e87 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -755,7 +755,7 @@ pub fn performer< 'a > return result; }; // let mut perform_output = qt!{ #name_ident #generics_ty }; - let mut perform_output = qt!{ < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed }; + let mut perform_output = qt!{ < Definition::Types as former::FormerDefinitionTypes >::Formed }; let mut perform_generics = qt!{}; for attr in attrs @@ -968,21 +968,38 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } - impl #generics_impl former::FormerDefinitionTypes - for #former_definition_name_ident #generics_ty + impl< Context, Formed > former::FormerDefinitionTypes + for #former_definition_name_ident< Context, Formed, former::NoEnd > { type Storage = #former_storage_name_ident #generics_ty; - type Formed = #name_ident #generics_ty; - type Context = (); + type Formed = Formed; + type Context = Context; } - impl #generics_impl former::FormerDefinition - for #former_definition_name_ident #generics_ty + impl< Context, Formed, End > former::FormerDefinition + for #former_definition_name_ident< Context, Formed, End > + where + End : former::FormingEnd< #former_definition_name_ident< Context, Formed, former::NoEnd > >, { - type Types = #former_definition_name_ident #generics_ty; - type End = former::ReturnPreformed; + type Types = #former_definition_name_ident< Context, Formed, former::NoEnd >; + type End = End; } +// impl #generics_impl former::FormerDefinitionTypes +// for #former_definition_name_ident #generics_ty +// { +// type Storage = #former_storage_name_ident #generics_ty; +// type Formed = #name_ident #generics_ty; +// type Context = (); +// } +// +// impl #generics_impl former::FormerDefinition +// for #former_definition_name_ident #generics_ty +// { +// type Types = #former_definition_name_ident #generics_ty; +// type End = former::ReturnPreformed; +// } + // = storage // xxx : rename to storage @@ -1027,12 +1044,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { // fn preform( mut self ) -> #former_storage_name_ident #generics_ty - // fn preform( mut self ) -> < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed + // fn preform( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed fn preform( mut self ) -> < Self as former::Storage >::Formed { #( #fields_form )* // Rust does not support that, yet - // let result = < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed + // let result = < Definition::Types as former::FormerDefinitionTypes >::Formed let result = #name_ident #generics_ty { #( #fields_names, )* @@ -1063,7 +1080,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// Finish setting options and return formed entity. /// #[ inline( always ) ] - pub fn preform( self ) -> < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed + pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed // #name_ident #generics_ty { < #former_storage_name_ident #generics_ty as former::StoragePerform >::preform( self.storage ) @@ -1118,7 +1135,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn form( self ) -> < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed + pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { self.end() } @@ -1127,7 +1144,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// End the process of forming returning original context of forming. /// #[ inline( always ) ] - pub fn end( mut self ) -> < #former_definition_name_ident #generics_ty as former::FormerDefinitionTypes >::Formed + pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); From 7d475f88fb492a001e37b11edc758926283372bc Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 01:19:03 +0200 Subject: [PATCH 072/533] former : experimenting --- .../tests/inc/former_tests/a_primitives.rs | 3 +- .../inc/former_tests/a_primitives_expanded.rs | 517 +++++++----------- .../inc/former_tests/a_primitives_manual.rs | 21 +- module/core/former/tests/inc/mod.rs | 2 +- module/core/former_meta/src/derive/former.rs | 70 +-- 5 files changed, 248 insertions(+), 365 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives.rs b/module/core/former/tests/inc/former_tests/a_primitives.rs index 676ee5752c..c39429b63a 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives.rs @@ -12,5 +12,4 @@ pub struct Struct1 // -// xxx : uncomment -// include!( "./only_test/primitives.rs" ); +include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs index e31e120396..8c87153d6d 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -1,8 +1,8 @@ #[ allow( unused_imports ) ] use super::*; -#[ derive( Debug, PartialEq ) ] -// #[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, PartialEq ) ] +#[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] pub struct Struct1 { pub int_1 : i32, @@ -12,335 +12,206 @@ pub struct Struct1 } // = generated -#[ automatically_derived ] -impl Struct1 -{ - #[ doc = r"" ] - #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn former() -> Struct1Former< > - { - Struct1Former::new() - } -} -#[ derive( Debug ) ] -pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > -// where -// End : former::FormingEnd< Struct1FormerDefinition< Context, Formed, NoEnd > >, -{ - _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, -} - -impl< Context, Formed, End > Default -for Struct1FormerDefinition< Context, Formed, End > -{ - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } -} - -// #[ derive( Debug, Default ) ] -// pub struct Struct1FormerDefinition; - -// impl former::FormerDefinitionTypes for Struct1FormerDefinition +// #[automatically_derived] impl Struct1 +// { +// #[doc = r""] +// #[doc = +// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] +// #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < > +// { Struct1Former :: new() } +// } #[derive(Debug)] pub struct Struct1FormerDefinition < Context = (), Formed = +// Struct1, End = former :: ReturnPreformed > +// { _phantom : core :: marker :: PhantomData < (Context, Formed, End) >, } impl +// < Context, Formed, End > Default for Struct1FormerDefinition < Context, +// Formed, End > +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < Context, Formed > former :: FormerDefinitionTypes for +// Struct1FormerDefinition < Context, Formed, former :: NoEnd > +// { +// type Storage = Struct1FormerStorage ; type Formed = Formed ; type Context +// = Context ; +// } impl < Context, Formed, End > former :: FormerDefinition for +// Struct1FormerDefinition < Context, Formed, End > where End : former :: +// FormingEnd < Struct1FormerDefinition < Context, Formed, former :: NoEnd > >, // { -// type Storage = Struct1FormerStorage; -// type Formed = Struct1; -// type Context = (); +// type Types = Struct1FormerDefinition < Context, Formed, former :: NoEnd > +// ; type End = End ; +// } #[doc = "Container of a corresponding former."] pub struct +// Struct1FormerStorage +// { +// #[doc = r" A field"] pub int_1 : :: core :: option :: Option < i32 >, +// #[doc = r" A field"] pub string_1 : :: core :: option :: Option < String +// >, #[doc = r" A field"] pub int_optional_1 : core :: option :: Option < +// i32 >, #[doc = r" A field"] pub string_optional_1 : Option < String >, +// } impl :: core :: default :: Default for Struct1FormerStorage +// { +// #[inline(always)] fn default() -> Self +// { +// Self +// { +// int_1 : :: core :: option :: Option :: None, string_1 : :: core :: +// option :: Option :: None, int_optional_1 : :: core :: option :: +// Option :: None, string_optional_1 : :: core :: option :: Option :: +// None, +// } +// } +// } impl former :: Storage for Struct1FormerStorage { type Formed = Struct1 ; } +// impl former :: StoragePerform for Struct1FormerStorage +// { +// fn preform(mut self) -> < Self as former :: Storage > :: Formed +// { +// let int_1 = if self.int_1.is_some() { self.int_1.take().unwrap() } +// else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'int_1' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < i32 +// >).maybe_default() +// } +// } ; let string_1 = if self.string_1.is_some() +// { self.string_1.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'string_1' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < String +// >).maybe_default() +// } +// } ; let int_optional_1 = if self.int_optional_1.is_some() +// { +// :: core :: option :: Option :: +// Some(self.int_optional_1.take().unwrap()) +// } else { :: core :: option :: Option :: None } ; let string_optional_1 +// = if self.string_optional_1.is_some() +// { +// :: core :: option :: Option :: +// Some(self.string_optional_1.take().unwrap()) +// } else { :: core :: option :: Option :: None } ; let result = Struct1 +// { int_1, string_1, int_optional_1, string_optional_1, } ; return +// result ; +// } // } -// -// impl former::FormerDefinition for Struct1FormerDefinition +// #[doc = +// " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +// pub struct Struct1Former < Definition = Struct1FormerDefinition > where +// Definition : former :: FormerDefinition, < Definition :: Types as former :: +// FormerDefinitionTypes > :: Storage : former :: StoragePerform, Definition :: +// Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage >, +// { +// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: +// Storage, context : core :: option :: Option < < Definition :: Types as +// former :: FormerDefinitionTypes > :: Context >, on_end : core :: option :: +// Option < Definition :: End >, +// } #[automatically_derived] impl < Definition > Struct1Former < Definition > +// where Definition : former :: FormerDefinition, < Definition :: Types as former +// :: FormerDefinitionTypes > :: Storage : former :: StoragePerform, Definition +// :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage >, +// { +// #[doc = r""] +// #[doc = r" Finish setting options and call perform on formed entity."] +// #[doc = r""] +// #[doc = +// r" If `perform` defined then associated method is called and its result returned instead of entity."] +// #[doc = +// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] +// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { let result = self.form() ; return result ; } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn +// begin(mut storage : core :: option :: Option < < Definition :: Types as +// former :: FormerDefinitionTypes > :: Storage >, context : core :: option +// :: Option < < Definition :: Types as former :: FormerDefinitionTypes > :: +// Context >, on_end : < Definition as former :: FormerDefinition > :: End,) +// -> Self +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()) ; } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: Some(on_end), +// } +// } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types +// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { +// let on_end = self.on_end.take().unwrap() ; let context = +// self.context.take() ; former :: FormingEnd :: < Definition :: Types > +// :: call(& on_end, self.storage, context) +// } #[doc = "Setter for the 'int_1' field."] #[inline] pub fn int_1 < Src > +// (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < i32 +// >, +// { +// debug_assert! (self.storage.int_1.is_none()) ; self.storage.int_1 = :: +// core :: option :: Option :: Some(src.into()) ; self +// } #[doc = "Setter for the 'string_1' field."] #[inline] pub fn string_1 < +// Src > (mut self, src : Src) -> Self where Src : :: core :: convert :: Into +// < String >, +// { +// debug_assert! (self.storage.string_1.is_none()) ; +// self.storage.string_1 = :: core :: option :: Option :: +// Some(src.into()) ; self +// } #[doc = "Setter for the 'int_optional_1' field."] #[inline] pub fn +// int_optional_1 < Src > (mut self, src : Src) -> Self where Src : :: core +// :: convert :: Into < i32 >, +// { +// debug_assert! (self.storage.int_optional_1.is_none()) ; +// self.storage.int_optional_1 = :: core :: option :: Option :: +// Some(src.into()) ; self +// } #[doc = "Setter for the 'string_optional_1' field."] #[inline] pub fn +// string_optional_1 < Src > (mut self, src : Src) -> Self where Src : :: +// core :: convert :: Into < String >, +// { +// debug_assert! (self.storage.string_optional_1.is_none()) ; +// self.storage.string_optional_1 = :: core :: option :: Option :: +// Some(src.into()) ; self +// } +// } #[automatically_derived] impl Struct1Former < > // { -// type Types = Struct1FormerDefinition; -// type End = former::ReturnPreformed; +// #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn new() -> Self +// { Self :: begin(None, None, former :: ReturnPreformed,) } // } - -impl< Context, Formed > former::FormerDefinitionTypes -for Struct1FormerDefinition< Context, Formed, former::NoEnd > -{ - type Storage = Struct1FormerStorage; - type Formed = Formed; - type Context = Context; -} - -impl< Context, Formed, End > former::FormerDefinition -for Struct1FormerDefinition< Context, Formed, End > -where - End : former::FormingEnd< Struct1FormerDefinition< Context, Formed, former::NoEnd > >, -{ - type Types = Struct1FormerDefinition< Context, Formed, former::NoEnd >; - type End = End; -} - -#[ doc = "Container of a corresponding former." ] -pub struct Struct1FormerStorage -{ - #[ doc = r" A field" ] - pub int_1 : ::core::option::Option< i32 >, - #[ doc = r" A field" ] - pub string_1 : ::core::option::Option< String >, - #[ doc = r" A field" ] - pub int_optional_1 : core::option::Option< i32 >, - #[ doc = r" A field" ] - pub string_optional_1 : Option< String >, -} - -impl ::core::default::Default for Struct1FormerStorage -{ - #[ inline( always ) ] - fn default() -> Self - { - Self - { - int_1 : ::core::option::Option::None, - string_1 : ::core::option::Option::None, - int_optional_1 : ::core::option::Option::None, - string_optional_1 : ::core::option::Option::None, - } - } -} - -impl former::Storage for Struct1FormerStorage -{ - type Formed = Struct1; -} - -impl former::StoragePerform for Struct1FormerStorage -{ - // fn preform( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - fn preform( mut self ) -> < Self as former::Storage >::Formed - { - let int_1 = if self.int_1.is_some() - { - self.int_1.take().unwrap() - } - else - { - { - trait MaybeDefault< T > - { - fn maybe_default( self : &Self ) -> T - { - panic!( "Field 'int_1' isn't initialized" ) - } - } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where T : ::core::default::Default, - { - fn maybe_default( self : &Self ) -> T - { - T::default() - } - } - ( &::core::marker::PhantomData::< i32 > ).maybe_default() - } - }; - let string_1 = if self.string_1.is_some() - { - self.string_1.take().unwrap() - } - else - { - { - trait MaybeDefault< T > - { - fn maybe_default( self : &Self ) -> T - { - panic!( "Field 'string_1' isn't initialized" ) - } - } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where T : ::core::default::Default, - { - fn maybe_default( self : &Self ) -> T - { - T::default() - } - } - ( &::core::marker::PhantomData::< String > ).maybe_default() - } - }; - let int_optional_1 = if self.int_optional_1.is_some() - { - ::core::option::Option::Some( self.int_optional_1.take().unwrap() ) - } - else - { - ::core::option::Option::None - }; - let string_optional_1 = if self.string_optional_1.is_some() - { - ::core::option::Option::Some( self.string_optional_1.take().unwrap() ) - } - else - { - ::core::option::Option::None - }; - let result = Struct1 - { - int_1, - string_1, - int_optional_1, - string_optional_1, - }; - return result; - } -} - -// pub struct Struct1Former -// < FormerContext = Struct1, FormerEnd = former::ReturnPreformed > -// where FormerEnd : former::FormingEnd< Struct1FormerDefinition >, +// +// impl < Definition > Struct1FormerDefinition < Definition > +// where +// Definition : former :: FormerDefinition, +// < +// Definition :: Types as former :: FormerDefinitionTypes > :: Storage : former :: StoragePerform, Definition :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage, +// Formed = Struct1 >, // { -// storage : Struct1FormerStorage, -// context : core::option::Option< FormerContext >, -// on_end : core::option::Option< FormerEnd >, +// pub fn preform(self) -> < Definition :: Types as former :: FormerDefinitionTypes > :: Formed +// { +// former :: StoragePerform :: preform(self.storage) +// } // } -pub struct Struct1Former -< - Definition = Struct1FormerDefinition, -> -where - Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, -{ - storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : core::option::Option< Definition::End >, -} - -#[ automatically_derived ] -impl< Definition > Struct1Former< Definition > -where - Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, -{ - #[ doc = r"" ] - #[ doc = r" Finish setting options and return formed entity." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - { - < Struct1FormerStorage as former::StoragePerform >::preform( self.storage ) - } - #[ doc = r"" ] - #[ doc = r" Finish setting options and call perform on formed entity." ] - #[ doc = r"" ] - #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] - #[ doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - { - let result = self.form(); - return result; - } - #[ doc = r"" ] - #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn begin - ( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : < Definition as former::FormerDefinition >::End, - ) -> Self - { - if storage.is_none() - { - storage = Some( ::core::default::Default::default() ); - } - Self - { - storage : storage.unwrap(), - context : context, - on_end : ::core::option::Option::Some( on_end ), - } - } - #[ doc = r"" ] - #[ doc = r" End the process of forming returning original context of forming." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - { - self.end() - } - #[ doc = r"" ] - #[ doc = r" End the process of forming returning original context of forming." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) - // former::FormingEnd::< Struct1FormerDefinition >::call( &on_end, self.storage, context ) - } - #[ doc = "Setter for the 'int_1' field." ] - #[ inline ] - pub fn int_1< Src >( mut self, src : Src ) -> Self - where - Src : ::core::convert::Into< i32 >, - { - debug_assert!( self.storage.int_1.is_none() ); - self.storage.int_1 = ::core::option::Option::Some( src.into() ); - self - } - #[ doc = "Setter for the 'string_1' field." ] - #[ inline ] - pub fn string_1< Src >( mut self, src : Src ) -> Self - where - Src : ::core::convert::Into< String >, - { - debug_assert!( self.storage.string_1.is_none() ); - self.storage.string_1 = ::core::option::Option::Some( src.into() ); - self - } - #[ doc = "Setter for the 'int_optional_1' field." ] - #[ inline ] - pub fn int_optional_1< Src >( mut self, src : Src ) -> Self - where - Src : ::core::convert::Into< i32 >, - { - debug_assert!( self.storage.int_optional_1.is_none() ); - self.storage.int_optional_1 = ::core::option::Option::Some( src.into() ); - self - } - #[ doc = "Setter for the 'string_optional_1' field." ] - #[ inline ] - pub fn string_optional_1< Src >( mut self, src : Src ) -> Self - where - Src : ::core::convert::Into< String >, - { - debug_assert!( self.storage.string_optional_1.is_none() ); - self.storage.string_optional_1 = ::core::option::Option::Some( src.into() ); - self - } -} - -#[ automatically_derived ] -impl Struct1Former -{ - #[ doc = r"" ] - #[ doc = r" Construct new instance of former with default parameters." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn new() -> Self - { - Self::begin( None, None, former::ReturnPreformed, ) - } -} - // = end of generated // include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 7a72d0d8f9..bbf63a4a65 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -187,12 +187,6 @@ where Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { - // fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - fn preform( self ) -> Struct1 - { - former::StoragePerform::preform( self.storage ) - } - #[ inline( always ) ] pub fn perform(self) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { @@ -262,6 +256,21 @@ where } +impl< Definition > Struct1Former< Definition > +where + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, +{ + + pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + // pub fn preform( self ) -> Struct1 + { + former::StoragePerform::preform( self.storage ) + } + +} + impl Struct1Former { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 7cbd0487ae..0a292a45b7 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -18,7 +18,7 @@ mod former_tests mod a_primitives_manual; // mod a_primitives_expanded; - // mod a_primitives; + mod a_primitives; // mod a_containers_without_runtime_manual; // mod a_containers_without_runtime; // #[ cfg( not( feature = "no_std" ) ) ] diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 9e341b6e87..98befec60b 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -985,21 +985,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > type End = End; } -// impl #generics_impl former::FormerDefinitionTypes -// for #former_definition_name_ident #generics_ty -// { -// type Storage = #former_storage_name_ident #generics_ty; -// type Formed = #name_ident #generics_ty; -// type Context = (); -// } -// -// impl #generics_impl former::FormerDefinition -// for #former_definition_name_ident #generics_ty -// { -// type Types = #former_definition_name_ident #generics_ty; -// type End = former::ReturnPreformed; -// } - // = storage // xxx : rename to storage @@ -1065,9 +1050,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > pub struct #former_name_ident < #generics_of_former_with_defaults > #generics_of_former_where { - storage : #former_storage_name_ident #generics_ty, - context : core::option::Option< __FormerContext >, - on_end : core::option::Option< __FormerEnd >, + storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : core::option::Option< Definition::End >, + // storage : #former_storage_name_ident #generics_ty, + // context : core::option::Option< __FormerContext >, + // on_end : core::option::Option< __FormerEnd >, // xxx : should on_end be optional? } @@ -1076,21 +1064,22 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #generics_of_former_where { - /// - /// Finish setting options and return formed entity. - /// - #[ inline( always ) ] - pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - // #name_ident #generics_ty - { - < #former_storage_name_ident #generics_ty as former::StoragePerform >::preform( self.storage ) - // #( #fields_form )* - // let result = #name_ident - // { - // #( #fields_names, )* - // }; - // return result; - } + // /// + // /// Finish setting options and return formed entity. + // /// + // #[ inline( always ) ] + // pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + // // #name_ident #generics_ty + // { + // former::StoragePerform::preform( self.storage ) + // // < #former_storage_name_ident #generics_ty as former::StoragePerform >::preform( self.storage ) + // // #( #fields_form )* + // // let result = #name_ident + // // { + // // #( #fields_names, )* + // // }; + // // return result; + // } /// /// Finish setting options and call perform on formed entity. @@ -1183,6 +1172,21 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } + impl< Definition > #former_name_ident< Definition > + where + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, + Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage_name_ident #generics_ty, Formed = #name_ident #generics_ty >, + { + + pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + // pub fn preform( self ) -> Struct1 + { + former::StoragePerform::preform( self.storage ) + } + + } + }; if has_debug From 45f23d9414ca9442bcfe34be7631e0b1e662ea53 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 10:26:27 +0200 Subject: [PATCH 073/533] former : experimenting --- .../inc/former_tests/a_primitives_expanded.rs | 199 ------------------ .../inc/former_tests/a_primitives_manual.rs | 24 ++- .../former_tests/container_former_common.rs | 2 - .../inc/former_tests/only_test/primitives.rs | 11 +- module/core/former_meta/src/derive/former.rs | 33 ++- 5 files changed, 51 insertions(+), 218 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs index 8c87153d6d..c34dc11b37 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -13,205 +13,6 @@ pub struct Struct1 // = generated -// #[automatically_derived] impl Struct1 -// { -// #[doc = r""] -// #[doc = -// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] -// #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < > -// { Struct1Former :: new() } -// } #[derive(Debug)] pub struct Struct1FormerDefinition < Context = (), Formed = -// Struct1, End = former :: ReturnPreformed > -// { _phantom : core :: marker :: PhantomData < (Context, Formed, End) >, } impl -// < Context, Formed, End > Default for Struct1FormerDefinition < Context, -// Formed, End > -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < Context, Formed > former :: FormerDefinitionTypes for -// Struct1FormerDefinition < Context, Formed, former :: NoEnd > -// { -// type Storage = Struct1FormerStorage ; type Formed = Formed ; type Context -// = Context ; -// } impl < Context, Formed, End > former :: FormerDefinition for -// Struct1FormerDefinition < Context, Formed, End > where End : former :: -// FormingEnd < Struct1FormerDefinition < Context, Formed, former :: NoEnd > >, -// { -// type Types = Struct1FormerDefinition < Context, Formed, former :: NoEnd > -// ; type End = End ; -// } #[doc = "Container of a corresponding former."] pub struct -// Struct1FormerStorage -// { -// #[doc = r" A field"] pub int_1 : :: core :: option :: Option < i32 >, -// #[doc = r" A field"] pub string_1 : :: core :: option :: Option < String -// >, #[doc = r" A field"] pub int_optional_1 : core :: option :: Option < -// i32 >, #[doc = r" A field"] pub string_optional_1 : Option < String >, -// } impl :: core :: default :: Default for Struct1FormerStorage -// { -// #[inline(always)] fn default() -> Self -// { -// Self -// { -// int_1 : :: core :: option :: Option :: None, string_1 : :: core :: -// option :: Option :: None, int_optional_1 : :: core :: option :: -// Option :: None, string_optional_1 : :: core :: option :: Option :: -// None, -// } -// } -// } impl former :: Storage for Struct1FormerStorage { type Formed = Struct1 ; } -// impl former :: StoragePerform for Struct1FormerStorage -// { -// fn preform(mut self) -> < Self as former :: Storage > :: Formed -// { -// let int_1 = if self.int_1.is_some() { self.int_1.take().unwrap() } -// else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'int_1' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < i32 -// >).maybe_default() -// } -// } ; let string_1 = if self.string_1.is_some() -// { self.string_1.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'string_1' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < String -// >).maybe_default() -// } -// } ; let int_optional_1 = if self.int_optional_1.is_some() -// { -// :: core :: option :: Option :: -// Some(self.int_optional_1.take().unwrap()) -// } else { :: core :: option :: Option :: None } ; let string_optional_1 -// = if self.string_optional_1.is_some() -// { -// :: core :: option :: Option :: -// Some(self.string_optional_1.take().unwrap()) -// } else { :: core :: option :: Option :: None } ; let result = Struct1 -// { int_1, string_1, int_optional_1, string_optional_1, } ; return -// result ; -// } -// } -// #[doc = -// " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -// pub struct Struct1Former < Definition = Struct1FormerDefinition > where -// Definition : former :: FormerDefinition, < Definition :: Types as former :: -// FormerDefinitionTypes > :: Storage : former :: StoragePerform, Definition :: -// Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage >, -// { -// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: -// Storage, context : core :: option :: Option < < Definition :: Types as -// former :: FormerDefinitionTypes > :: Context >, on_end : core :: option :: -// Option < Definition :: End >, -// } #[automatically_derived] impl < Definition > Struct1Former < Definition > -// where Definition : former :: FormerDefinition, < Definition :: Types as former -// :: FormerDefinitionTypes > :: Storage : former :: StoragePerform, Definition -// :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage >, -// { -// #[doc = r""] -// #[doc = r" Finish setting options and call perform on formed entity."] -// #[doc = r""] -// #[doc = -// r" If `perform` defined then associated method is called and its result returned instead of entity."] -// #[doc = -// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] -// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { let result = self.form() ; return result ; } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn -// begin(mut storage : core :: option :: Option < < Definition :: Types as -// former :: FormerDefinitionTypes > :: Storage >, context : core :: option -// :: Option < < Definition :: Types as former :: FormerDefinitionTypes > :: -// Context >, on_end : < Definition as former :: FormerDefinition > :: End,) -// -> Self -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()) ; } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: Some(on_end), -// } -// } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types -// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { -// let on_end = self.on_end.take().unwrap() ; let context = -// self.context.take() ; former :: FormingEnd :: < Definition :: Types > -// :: call(& on_end, self.storage, context) -// } #[doc = "Setter for the 'int_1' field."] #[inline] pub fn int_1 < Src > -// (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < i32 -// >, -// { -// debug_assert! (self.storage.int_1.is_none()) ; self.storage.int_1 = :: -// core :: option :: Option :: Some(src.into()) ; self -// } #[doc = "Setter for the 'string_1' field."] #[inline] pub fn string_1 < -// Src > (mut self, src : Src) -> Self where Src : :: core :: convert :: Into -// < String >, -// { -// debug_assert! (self.storage.string_1.is_none()) ; -// self.storage.string_1 = :: core :: option :: Option :: -// Some(src.into()) ; self -// } #[doc = "Setter for the 'int_optional_1' field."] #[inline] pub fn -// int_optional_1 < Src > (mut self, src : Src) -> Self where Src : :: core -// :: convert :: Into < i32 >, -// { -// debug_assert! (self.storage.int_optional_1.is_none()) ; -// self.storage.int_optional_1 = :: core :: option :: Option :: -// Some(src.into()) ; self -// } #[doc = "Setter for the 'string_optional_1' field."] #[inline] pub fn -// string_optional_1 < Src > (mut self, src : Src) -> Self where Src : :: -// core :: convert :: Into < String >, -// { -// debug_assert! (self.storage.string_optional_1.is_none()) ; -// self.storage.string_optional_1 = :: core :: option :: Option :: -// Some(src.into()) ; self -// } -// } #[automatically_derived] impl Struct1Former < > -// { -// #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new() -> Self -// { Self :: begin(None, None, former :: ReturnPreformed,) } -// } -// -// impl < Definition > Struct1FormerDefinition < Definition > -// where -// Definition : former :: FormerDefinition, -// < -// Definition :: Types as former :: FormerDefinitionTypes > :: Storage : former :: StoragePerform, Definition :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage, -// Formed = Struct1 >, -// { -// pub fn preform(self) -> < Definition :: Types as former :: FormerDefinitionTypes > :: Formed -// { -// former :: StoragePerform :: preform(self.storage) -// } -// } - // = end of generated // include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index bbf63a4a65..8cc4d60574 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -43,8 +43,26 @@ for Struct1FormerDefinition< Context, Formed, End > } } +#[ derive( Debug ) ] +pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > +{ + _phantom : core::marker::PhantomData< ( Context, Formed ) >, +} + +impl< Context, Formed > Default +for Struct1FormerDefinitionTypes< Context, Formed > +{ + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} + impl< Context, Formed > former::FormerDefinitionTypes -for Struct1FormerDefinition< Context, Formed, former::NoEnd > +for Struct1FormerDefinitionTypes< Context, Formed > { type Storage = Struct1FormerStorage; type Formed = Formed; @@ -54,9 +72,9 @@ for Struct1FormerDefinition< Context, Formed, former::NoEnd > impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > where - End : former::FormingEnd< Struct1FormerDefinition< Context, Formed, former::NoEnd > >, + End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, { - type Types = Struct1FormerDefinition< Context, Formed, former::NoEnd >; + type Types = Struct1FormerDefinitionTypes< Context, Formed >; type End = End; } diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index 954e887892..a4bb1ca1e1 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -250,8 +250,6 @@ fn custom_definition_custom_end() type End = former::FormingEndWrapper< < Self as former::FormerDefinition >::Types >; } - // - fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 { 13 diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 3ea0a9aafc..973bc04dd8 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -86,17 +86,18 @@ tests_impls! // let _default = Struct1FormerDefinition::default(); // why does not work? // definition types exists and has Formed - let got = < Struct1FormerDefinition< (), Struct1, former::NoEnd > as the_module::FormerDefinitionTypes >::Formed::former().form(); - // let got = < Struct1FormerDefinition<> as the_module::FormerDefinitionTypes >::Formed::former().form(); + let got = < Struct1FormerDefinitionTypes< (), Struct1 > as the_module::FormerDefinitionTypes >::Formed::former().form(); let exp = Struct1::former().form(); a_id!( got, exp ); - // xxx : uncomment - // < Context = (), Formed = Struct1, End = former::ReturnPreformed > + // definition types exists and has Formed + let got = < Struct1FormerDefinitionTypes as the_module::FormerDefinitionTypes >::Formed::former().form(); + let exp = Struct1::former().form(); + a_id!( got, exp ); // definition types exists and has Storage use former::StoragePerform; - let got = < Struct1FormerDefinition< (), Struct1, former::NoEnd > as the_module::FormerDefinitionTypes >::Storage::preform( Struct1::former().storage ); + let got = < Struct1FormerDefinitionTypes as the_module::FormerDefinitionTypes >::Storage::preform( Struct1::former().storage ); let exp = Struct1::former().form(); a_id!( got, exp ); diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 98befec60b..07d43f1b2b 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -743,8 +743,8 @@ For specifying custom default value use attribute `default`. For example: pub fn performer< 'a > ( _name_ident : &syn::Ident, - former_definition_name_ident : &syn::Ident, - generics_ty : &syn::TypeGenerics< '_ >, + _former_definition_name_ident : &syn::Ident, + _generics_ty : &syn::TypeGenerics< '_ >, attrs : impl Iterator< Item = &'a syn::Attribute >, ) -> Result< ( TokenStream, TokenStream, TokenStream ) > @@ -829,6 +829,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_storage_name_ident = syn::Ident::new( &former_storage_name, name_ident.span() ); let former_definition_name = format!( "{}FormerDefinition", name_ident ); let former_definition_name_ident = syn::Ident::new( &former_definition_name, name_ident.span() ); + let former_definition_types_name = format!( "{}FormerDefinitionTypes", name_ident ); + let former_definition_types_name_ident = syn::Ident::new( &former_definition_types_name, name_ident.span() ); /* generic parameters */ @@ -848,13 +850,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // add embedded generic parameters let mut extra_generics : syn::Generics = parse_quote! { - // < __FormerContext = #name_ident #generics_ty, __FormerEnd = former::ReturnPreformed > < Definition = #former_definition_name_ident #generics_ty > }; extra_generics.where_clause = parse_quote! { where - // __FormerEnd : former::FormingEnd< #former_definition_name_ident #generics_ty >, Definition : former::FormerDefinition, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage_name_ident #generics_ty >, @@ -945,8 +945,23 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = definition - // #[ derive( Debug, Default ) ] - // pub struct #former_definition_name_ident #generics_ty; + #[ derive( Debug ) ] + pub struct #former_definition_types_name_ident< Context = (), Formed = #name_ident #generics_ty > + { + _phantom : core::marker::PhantomData< ( Context, Formed ) >, + } + + impl< Context, Formed > Default + for #former_definition_types_name_ident< Context, Formed > + { + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + } #[ derive( Debug ) ] pub struct #former_definition_name_ident< Context = (), Formed = #name_ident #generics_ty, End = former::ReturnPreformed > @@ -969,7 +984,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } impl< Context, Formed > former::FormerDefinitionTypes - for #former_definition_name_ident< Context, Formed, former::NoEnd > + for #former_definition_types_name_ident< Context, Formed > { type Storage = #former_storage_name_ident #generics_ty; type Formed = Formed; @@ -979,9 +994,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl< Context, Formed, End > former::FormerDefinition for #former_definition_name_ident< Context, Formed, End > where - End : former::FormingEnd< #former_definition_name_ident< Context, Formed, former::NoEnd > >, + End : former::FormingEnd< #former_definition_types_name_ident< Context, Formed > >, { - type Types = #former_definition_name_ident< Context, Formed, former::NoEnd >; + type Types = #former_definition_types_name_ident< Context, Formed >; type End = End; } From 5763010bc1efbff68b93252ac26e806535bbf5ba Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 10:33:44 +0200 Subject: [PATCH 074/533] former : experimenting --- module/core/former/src/axiomatic.rs | 21 +++++++------------ ...time.rs => a_containers_with_subformer.rs} | 2 +- ... => a_containers_with_subformer_manual.rs} | 2 +- ...e.rs => a_containers_without_subformer.rs} | 2 +- ... a_containers_without_subformer_manual.rs} | 2 +- .../tests/inc/former_tests/name_collisions.rs | 2 +- ...untime.rs => containers_with_subformer.rs} | 0 ...ime.rs => containers_without_subformer.rs} | 0 .../inc/former_tests/subformer_shortcut.rs | 2 +- module/core/former/tests/inc/mod.rs | 8 +++---- module/core/former_meta/src/derive/former.rs | 14 +++++-------- 11 files changed, 22 insertions(+), 33 deletions(-) rename module/core/former/tests/inc/former_tests/{a_containers_with_runtime.rs => a_containers_with_subformer.rs} (89%) rename module/core/former/tests/inc/former_tests/{a_containers_with_runtime_manual.rs => a_containers_with_subformer_manual.rs} (99%) rename module/core/former/tests/inc/former_tests/{a_containers_without_runtime.rs => a_containers_without_subformer.rs} (84%) rename module/core/former/tests/inc/former_tests/{a_containers_without_runtime_manual.rs => a_containers_without_subformer_manual.rs} (98%) rename module/core/former/tests/inc/former_tests/only_test/{containers_with_runtime.rs => containers_with_subformer.rs} (100%) rename module/core/former/tests/inc/former_tests/only_test/{containers_without_runtime.rs => containers_without_subformer.rs} (100%) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 27bdfbe899..d9abbd710c 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -1,24 +1,17 @@ -/// xxx +/// zzz : write description pub trait Storage : ::core::default::Default { - // type Types : FormerDefinitionTypes< Storage = Self >; type Formed; } -/// xxx +/// zzz : write description pub trait StoragePerform : Storage { - // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed; - /// Default implementation of routine transforming storage into formed structure. - /// Does not have to be implemented and does not have to be used, especially if there is complex logic behind tranfromation, but can be used if algorithm is traight-forward and does not require any context. - /// - /// `former::ReturnPreformed` rely on `StoragePerform::preform` returning its result. - /// fn preform( self ) -> Self::Formed; } -/// xxx +/// zzz : write description pub trait FormerDefinitionTypes : Sized { // type Storage : Storage< Definition = Self >; @@ -31,7 +24,7 @@ pub trait FormerDefinitionTypes : Sized } -/// xxx +/// zzz : write description pub trait FormerDefinition : Sized { type Types : FormerDefinitionTypes; @@ -94,7 +87,7 @@ where } } -/// xxx : update description +/// zzz : update description #[ derive( Debug, Default ) ] pub struct ReturnStorage; @@ -113,7 +106,7 @@ where } } -// xxx : improve description +// zzz : improve description /// Use `NoEnd` to fill parameter FormingEnd in struct where parameter exists, but it is not needed. /// It might be needed if the same struct is used as `FormerDefinitionTypes` and as `FormerDefinition`, because the first one does not have information aboud End function. /// Similar logic which `std::marker::PhantomData` has behind. @@ -223,7 +216,7 @@ for FormingEndWrapper< Definition > /// sophisticated and flexible construction patterns conducive to complex data transformations or object creation /// sequences within builder patterns. -// xxx : update description +// zzz : update description pub trait FormerBegin< Definition : FormerDefinition > { diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_runtime.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs similarity index 89% rename from module/core/former/tests/inc/former_tests/a_containers_with_runtime.rs rename to module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 8200225aeb..6a1cbc6892 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_runtime.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -15,4 +15,4 @@ pub struct Struct1 hashset_strings_1 : std::collections::HashSet< String >, } -include!( "./only_test/containers_with_runtime.rs" ); +include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs similarity index 99% rename from module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs rename to module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 10f801ce59..3c32c0012a 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_runtime_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -294,4 +294,4 @@ where // -include!( "./only_test/containers_with_runtime.rs" ); +include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_runtime.rs b/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs similarity index 84% rename from module/core/former/tests/inc/former_tests/a_containers_without_runtime.rs rename to module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs index 61ab910b75..9cd61f41eb 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_without_runtime.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs @@ -15,4 +15,4 @@ pub struct Struct1 // -include!( "./only_test/containers_without_runtime.rs" ); +include!( "./only_test/containers_without_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs similarity index 98% rename from module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs rename to module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs index 5779c6af72..b835ed8141 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_without_runtime_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs @@ -175,4 +175,4 @@ where // -include!( "./only_test/containers_without_runtime.rs" ); +include!( "./only_test/containers_without_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/name_collisions.rs b/module/core/former/tests/inc/former_tests/name_collisions.rs index 28a379f137..6b318a809e 100644 --- a/module/core/former/tests/inc/former_tests/name_collisions.rs +++ b/module/core/former/tests/inc/former_tests/name_collisions.rs @@ -34,4 +34,4 @@ pub struct Struct1 // -include!( "./only_test/containers_without_runtime.rs" ); +include!( "./only_test/containers_without_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_runtime.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs similarity index 100% rename from module/core/former/tests/inc/former_tests/only_test/containers_with_runtime.rs rename to module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_without_runtime.rs b/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs similarity index 100% rename from module/core/former/tests/inc/former_tests/only_test/containers_without_runtime.rs rename to module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index da39a6c5a1..9ab7e6933f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -36,7 +36,7 @@ where #[ inline( always ) ] fn _begin ( - storage : core::option::Option< TemplateParameterDefinitionFormerStorage >, /* xxx2 : that should be storage */ + storage : core::option::Option< TemplateParameterDefinitionFormerStorage >, context : core::option::Option< Context >, on_end : End, ) -> Self diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 0a292a45b7..3b159029a1 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -19,12 +19,12 @@ mod former_tests mod a_primitives_manual; // mod a_primitives_expanded; mod a_primitives; -// mod a_containers_without_runtime_manual; -// mod a_containers_without_runtime; + // mod a_containers_without_subformer_manual; + // mod a_containers_without_subformer; // #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_runtime_manual; +// mod a_containers_with_subformer_manual; // #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_runtime ; +// mod a_containers_with_subformer ; // // mod attribute_default_container; // mod attribute_default_primitive; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 07d43f1b2b..0b8a136b45 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -836,7 +836,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let generics = &ast.generics; let ( generics_impl, generics_ty, generics_where ) = generics.split_for_impl(); - // xxx : eliminate generics_params maybe + // zzz : eliminate generics_params maybe let _generics_params = generics::params_names( generics ).params; let generics_params = if _generics_params.len() == 0 { @@ -859,7 +859,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage_name_ident #generics_ty >, }; - // xxx : write helper to fix bug with where + // zzz : write helper to fix bug with where let generics_of_former = generics::merge( &generics, &extra_generics ); let ( generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generics_of_former.split_for_impl(); let generics_of_former_with_defaults = generics_of_former.params.clone(); @@ -1002,7 +1002,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = storage - // xxx : rename to storage #[ doc = "Container of a corresponding former." ] pub struct #former_storage_name_ident #generics_ty #generics_where @@ -1068,10 +1067,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : core::option::Option< Definition::End >, - // storage : #former_storage_name_ident #generics_ty, - // context : core::option::Option< __FormerContext >, - // on_end : core::option::Option< __FormerEnd >, - // xxx : should on_end be optional? + // zzz : should on_end be optional? } #[ automatically_derived ] @@ -1209,7 +1205,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > diag::debug_report_print( "derive : Former", original_input, &result ); } - // xxx : implement + // zzz : implement hints if example_of_custom_setter { let _example = @@ -1233,4 +1229,4 @@ where Ok( result ) } -// xxx : explain concept of Storage +// zzz : explain concept of Storage From 4ef26f4d9ad085de9af4904576f0a30b04291115 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 11:17:42 +0200 Subject: [PATCH 075/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 16 ++++++++-------- .../a_containers_without_subformer_manual.rs | 12 ++++++------ .../inc/former_tests/a_primitives_manual.rs | 11 ----------- .../only_test/containers_with_subformer.rs | 4 ++-- .../only_test/containers_without_subformer.rs | 4 ++-- .../inc/former_tests/only_test/primitives.rs | 18 ++++++++++++++++-- .../former_tests/parametrized_struct_manual.rs | 4 ++-- .../inc/former_tests/subformer_basic_manual.rs | 8 ++++---- module/core/former/tests/inc/mod.rs | 2 +- 9 files changed, 41 insertions(+), 38 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 3c32c0012a..f9b0f1f976 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -13,9 +13,9 @@ pub struct Struct1 impl Struct1 { - pub fn former() -> Struct1Former< Struct1, the_module::ReturnFormed > + pub fn former() -> Struct1Former< Struct1, the_module::ReturnPreformed > { - Struct1Former::< Struct1, the_module::ReturnFormed >::new() + Struct1Former::< Struct1, the_module::ReturnPreformed >::new() } } @@ -50,7 +50,7 @@ impl Default for Struct1FormerStorage pub struct Struct1Former < Context = Struct1, - End = the_module::ReturnFormed, + End = the_module::ReturnPreformed, > where End : the_module::FormingEnd< Struct1, Context >, @@ -116,13 +116,13 @@ where } // #[ inline( always ) ] - // pub fn new() -> Struct1Former + // pub fn new() -> Struct1Former // { // Struct1Former:: // < // Struct1, - // the_module::ReturnFormed, - // >::begin(None, the_module::ReturnFormed) + // the_module::ReturnPreformed, + // >::begin(None, the_module::ReturnPreformed) // } #[ inline( always ) ] @@ -254,13 +254,13 @@ where // where // End: the_module::FormingEnd, -impl Struct1Former< Struct1, the_module::ReturnFormed > +impl Struct1Former< Struct1, the_module::ReturnPreformed > { #[ inline( always ) ] pub fn new() -> Self { - Self::begin( None, None, the_module::ReturnFormed ) + Self::begin( None, None, the_module::ReturnPreformed ) } } diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs index b835ed8141..c419520a98 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs @@ -13,9 +13,9 @@ pub struct Struct1 impl Struct1 { - pub fn former() -> Struct1Former< Struct1, the_module::ReturnFormed > + pub fn former() -> Struct1Former< Struct1, the_module::ReturnPreformed > { - Struct1Former::< Struct1, the_module::ReturnFormed >::new() + Struct1Former::< Struct1, the_module::ReturnPreformed >::new() } } @@ -48,7 +48,7 @@ impl Default for Struct1FormerStorage pub struct Struct1Former < __FormerContext = Struct1, - __FormerEnd = the_module::ReturnFormed, + __FormerEnd = the_module::ReturnPreformed, > where __FormerEnd : the_module::FormingEnd< Struct1, __FormerContext >, @@ -114,13 +114,13 @@ where } #[ inline( always ) ] - pub fn new() -> Struct1Former + pub fn new() -> Struct1Former { Struct1Former:: < Struct1, - the_module::ReturnFormed, - >::begin(None, the_module::ReturnFormed) + the_module::ReturnPreformed, + >::begin(None, the_module::ReturnPreformed) } #[ inline( always ) ] diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 8cc4d60574..13c057ec0b 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -173,17 +173,6 @@ for Struct1FormerStorage // = former -// #[ derive( Default ) ] -// pub struct ContainerSubformer< E, Definition > -// where -// Definition : FormerDefinition, -// // < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, -// { -// storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, -// context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, -// on_end : core::option::Option< Definition::End >, -// } - pub struct Struct1Former < Definition = Struct1FormerDefinition, diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index ceeb84abaa..5381a86227 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -18,8 +18,8 @@ tests_impls_optional! a_id!( former.storage.hashmap_strings_1, None ); a_id!( former.storage.hashset_strings_1, None ); a_id!( former.context, None ); - a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnFormed ) ) ); - let former2 = Struct1Former::< Struct1, the_module::ReturnFormed >::new(); + a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); + let former2 = Struct1Former::< Struct1, the_module::ReturnPreformed >::new(); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs index 8141ddc9fd..e0d058ea4a 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs @@ -18,8 +18,8 @@ tests_impls! a_id!( former.storage.hashmap_strings_1, None ); a_id!( former.storage.hashset_strings_1, None ); a_id!( former.context, None ); - a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnFormed ) ) ); - let former2 = Struct1Former::< Struct1, the_module::ReturnFormed >::new(); + a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); + let former2 = Struct1Former::< Struct1, the_module::ReturnPreformed >::new(); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 973bc04dd8..80d455ac81 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -46,10 +46,24 @@ tests_impls! fn begin() { + // begin with none + let got = Struct1Former::< Struct1FormerDefinition >::begin( None, None, the_module::ReturnPreformed ).int_1( 13 ).form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // begin with storage + let mut storage = Struct1FormerStorage::default(); + storage.int_1 = Some( 13 ); + let exp = Struct1Former::< Struct1FormerDefinition >::begin( Some( storage ), None, the_module::ReturnPreformed ).form(); + a_id!( got, exp ); + + // begin with context let mut storage = Struct1FormerStorage::default(); storage.int_1 = Some( 13 ); - // Struct1Former::< (), the_module::ReturnFormed >::begin( storage, None, the_module::ReturnFormed ) - // xxx + let exp = Struct1Former::< Struct1FormerDefinition > + ::begin( Some( storage ), Some( () ), the_module::ReturnPreformed ) + .form(); + a_id!( got, exp ); } diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 9993204d16..f599ddceb0 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -73,7 +73,7 @@ where // generated by former // #[ derive( Debug, Default ) ] -pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnFormed > +pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnPreformed > where K : core::hash::Hash + std::cmp::Eq, End : the_module::FormingEnd< Command< K >, Context >, @@ -135,7 +135,7 @@ where ( None, None, - the_module::ReturnFormed, + the_module::ReturnPreformed, ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs b/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs index 4c8ebd3b82..c336a55bcd 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs @@ -93,7 +93,7 @@ where // generated by former // #[ derive( Debug, Default ) ] -pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnFormed > +pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnPreformed > where K : core::hash::Hash + std::cmp::Eq, End : the_module::FormingEnd< Command< K >, Context >, @@ -166,7 +166,7 @@ where ( None, None, - the_module::ReturnFormed, + the_module::ReturnPreformed, ) } @@ -301,7 +301,7 @@ where // generated by former // #[ derive( Debug, Default ) ] -pub struct AggregatorFormer< K, Context = Aggregator< K >, End = the_module::ReturnFormed > +pub struct AggregatorFormer< K, Context = Aggregator< K >, End = the_module::ReturnPreformed > where K : core::hash::Hash + std::cmp::Eq, End : the_module::FormingEnd< Aggregator< K >, Context >, @@ -363,7 +363,7 @@ where AggregatorFormer::< K >::begin ( None, - the_module::ReturnFormed, + the_module::ReturnPreformed, ) } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 3b159029a1..58a9efa8f8 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -18,7 +18,7 @@ mod former_tests mod a_primitives_manual; // mod a_primitives_expanded; - mod a_primitives; + // mod a_primitives; // mod a_containers_without_subformer_manual; // mod a_containers_without_subformer; // #[ cfg( not( feature = "no_std" ) ) ] From a4c8b20fc0a67a0b9d46cdb45a6b022741f0cc6e Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 11:47:57 +0200 Subject: [PATCH 076/533] former : experimenting --- .../inc/former_tests/a_primitives_expanded.rs | 2 +- .../inc/former_tests/a_primitives_manual.rs | 10 +- .../inc/former_tests/only_test/primitives.rs | 14 +- module/core/former/tests/inc/mod.rs | 2 +- module/core/former_meta/src/derive/former.rs | 162 ++++++++++-------- 5 files changed, 107 insertions(+), 83 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs index c34dc11b37..bcf31514bd 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -15,4 +15,4 @@ pub struct Struct1 // = end of generated -// include!( "./only_test/primitives.rs" ); + include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 13c057ec0b..abac9bd9fb 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -17,7 +17,7 @@ impl Struct1 { pub fn former() -> Struct1Former { - Struct1Former::new() + Struct1Former::new( the_module::ReturnPreformed ) } } @@ -207,7 +207,6 @@ where mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, - // xxx : cover by test existance of these 3 parameters in the function ) -> Self { if storage.is_none() @@ -271,7 +270,6 @@ where { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - // pub fn preform( self ) -> Struct1 { former::StoragePerform::preform( self.storage ) } @@ -281,16 +279,14 @@ where impl Struct1Former { - // xxx : should pass callback #[ inline( always ) ] - pub fn new() -> Struct1Former + pub fn new( on_end : < Struct1FormerDefinition as former::FormerDefinition >::End ) -> Self { - Struct1Former::begin( None, None, the_module::ReturnPreformed ) + Self::begin( None, None, on_end ) } } // -// xxx : uncomment include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 80d455ac81..0f209c90a9 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -18,7 +18,7 @@ tests_impls! a_id!( former.storage.string_optional_1, None ); a_id!( former.context, None ); a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); - let former2 = Struct1Former::new(); + let former2 = Struct1Former::new( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); @@ -69,6 +69,17 @@ tests_impls! // + fn new() + { + + let former = Struct1::former(); + let former2 = Struct1Former::new( former::ReturnPreformed ); + a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); + + } + + // + fn preform() { @@ -335,6 +346,7 @@ tests_index! { internals, begin, + new, preform, definition, storage, diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 58a9efa8f8..3b159029a1 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -18,7 +18,7 @@ mod former_tests mod a_primitives_manual; // mod a_primitives_expanded; - // mod a_primitives; + mod a_primitives; // mod a_containers_without_subformer_manual; // mod a_containers_without_subformer; // #[ cfg( not( feature = "no_std" ) ) ] diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 0b8a136b45..2ecea72127 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -686,14 +686,14 @@ fn subformer_field_setter /// Generate documentation for the former. /// -fn doc_generate( name_ident : &syn::Ident ) -> ( String, String ) +fn doc_generate( struct_name : &syn::Ident ) -> ( String, String ) { let doc_former_mod = format! ( r#" Implementation of former for [{}]. "#, - name_ident + struct_name ); let doc_example1 = @@ -716,7 +716,7 @@ For specifying custom default value use attribute `default`. For example: {} ``` "#, - name_ident, doc_example1 + struct_name, doc_example1 ); ( doc_former_mod, doc_former_struct ) @@ -742,8 +742,8 @@ For specifying custom default value use attribute `default`. For example: pub fn performer< 'a > ( - _name_ident : &syn::Ident, - _former_definition_name_ident : &syn::Ident, + _struct_name : &syn::Ident, + _former_definition : &syn::Ident, _generics_ty : &syn::TypeGenerics< '_ >, attrs : impl Iterator< Item = &'a syn::Attribute >, ) @@ -754,7 +754,7 @@ pub fn performer< 'a > { return result; }; - // let mut perform_output = qt!{ #name_ident #generics_ty }; + // let mut perform_output = qt!{ #struct_name #generics_ty }; let mut perform_output = qt!{ < Definition::Types as former::FormerDefinitionTypes >::Formed }; let mut perform_generics = qt!{}; @@ -822,15 +822,15 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /* names */ - let name_ident = &ast.ident; - let former_name = format!( "{}Former", name_ident ); - let former_name_ident = syn::Ident::new( &former_name, name_ident.span() ); - let former_storage_name = format!( "{}FormerStorage", name_ident ); - let former_storage_name_ident = syn::Ident::new( &former_storage_name, name_ident.span() ); - let former_definition_name = format!( "{}FormerDefinition", name_ident ); - let former_definition_name_ident = syn::Ident::new( &former_definition_name, name_ident.span() ); - let former_definition_types_name = format!( "{}FormerDefinitionTypes", name_ident ); - let former_definition_types_name_ident = syn::Ident::new( &former_definition_types_name, name_ident.span() ); + let struct_name = &ast.ident; + let former_name = format!( "{}Former", struct_name ); + let former = syn::Ident::new( &former_name, struct_name.span() ); + let former_storage_name = format!( "{}FormerStorage", struct_name ); + let former_storage = syn::Ident::new( &former_storage_name, struct_name.span() ); + let former_definition_name = format!( "{}FormerDefinition", struct_name ); + let former_definition = syn::Ident::new( &former_definition_name, struct_name.span() ); + let former_definition_types_name = format!( "{}FormerDefinitionTypes", struct_name ); + let former_definition_types = syn::Ident::new( &former_definition_types_name, struct_name.span() ); /* generic parameters */ @@ -850,14 +850,14 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // add embedded generic parameters let mut extra_generics : syn::Generics = parse_quote! { - < Definition = #former_definition_name_ident #generics_ty > + < Definition = #former_definition #generics_ty > }; extra_generics.where_clause = parse_quote! { where Definition : former::FormerDefinition, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, - Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage_name_ident #generics_ty >, + Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, }; // zzz : write helper to fix bug with where let generics_of_former = generics::merge( &generics, &extra_generics ); @@ -870,8 +870,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( perform, perform_output, perform_generics ) = performer ( - &name_ident, - &former_definition_name_ident, + &struct_name, + &former_definition, &generics_ty, ast.attrs.iter(), )?; @@ -919,7 +919,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field_setter_map( former_field ), )}).multiunzip(); - let ( _doc_former_mod, doc_former_struct ) = doc_generate( name_ident ); + let ( _doc_former_mod, doc_former_struct ) = doc_generate( struct_name ); let fields_setter : Vec< _ > = process_results( fields_setter, | iter | iter.collect() )?; let fields_form : Vec< _ > = process_results( fields_form, | iter | iter.collect() )?; @@ -929,30 +929,38 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = formed #[ automatically_derived ] - impl #generics_impl #name_ident #generics_ty + impl #generics_impl #struct_name #generics_ty #generics_where { /// /// Make former, variation of builder pattern to form structure defining values of fields step by step. /// + + // #[ inline( always ) ] + // // pub fn former() -> #former < #generics_params (), former::ReturnPreformed > + // pub fn former() -> #former < #generics_params > + // { + // #former :: new() + // } + #[ inline( always ) ] - // pub fn former() -> #former_name_ident < #generics_params (), former::ReturnPreformed > - pub fn former() -> #former_name_ident < #generics_params > + pub fn former() -> #former < #generics_params > { - #former_name_ident :: new() + #former :: < #generics_params > :: new( the_module::ReturnPreformed ) } + } // = definition #[ derive( Debug ) ] - pub struct #former_definition_types_name_ident< Context = (), Formed = #name_ident #generics_ty > + pub struct #former_definition_types< Context = (), Formed = #struct_name #generics_ty > { _phantom : core::marker::PhantomData< ( Context, Formed ) >, } impl< Context, Formed > Default - for #former_definition_types_name_ident< Context, Formed > + for #former_definition_types< Context, Formed > { fn default() -> Self { @@ -964,15 +972,15 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } #[ derive( Debug ) ] - pub struct #former_definition_name_ident< Context = (), Formed = #name_ident #generics_ty, End = former::ReturnPreformed > + pub struct #former_definition< Context = (), Formed = #struct_name #generics_ty, End = former::ReturnPreformed > // where - // End : former::FormingEnd< #former_definition_name_ident< Context, Formed, NoEnd > >, + // End : former::FormingEnd< #former_definition< Context, Formed, NoEnd > >, { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } impl< Context, Formed, End > Default - for #former_definition_name_ident< Context, Formed, End > + for #former_definition< Context, Formed, End > { fn default() -> Self { @@ -984,26 +992,26 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } impl< Context, Formed > former::FormerDefinitionTypes - for #former_definition_types_name_ident< Context, Formed > + for #former_definition_types< Context, Formed > { - type Storage = #former_storage_name_ident #generics_ty; + type Storage = #former_storage #generics_ty; type Formed = Formed; type Context = Context; } impl< Context, Formed, End > former::FormerDefinition - for #former_definition_name_ident< Context, Formed, End > + for #former_definition< Context, Formed, End > where - End : former::FormingEnd< #former_definition_types_name_ident< Context, Formed > >, + End : former::FormingEnd< #former_definition_types< Context, Formed > >, { - type Types = #former_definition_types_name_ident< Context, Formed >; + type Types = #former_definition_types< Context, Formed >; type End = End; } // = storage #[ doc = "Container of a corresponding former." ] - pub struct #former_storage_name_ident #generics_ty + pub struct #former_storage #generics_ty #generics_where { #( @@ -1012,7 +1020,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > )* } - impl #generics_impl ::core::default::Default for #former_storage_name_ident #generics_ty + impl #generics_impl ::core::default::Default for #former_storage #generics_ty #generics_where { @@ -1028,28 +1036,28 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } impl #generics_impl former::Storage - for #former_storage_name_ident #generics_ty + for #former_storage #generics_ty #generics_where { // type Definition = Struct1FormerDefinition; - // type Definition = #former_definition_name_ident #generics_ty; - type Formed = #name_ident #generics_ty; + // type Definition = #former_definition #generics_ty; + type Formed = #struct_name #generics_ty; } // generics_impl, generics_ty, generics_where impl former::StoragePerform - for #former_storage_name_ident #generics_ty + for #former_storage #generics_ty #generics_where { - // fn preform( mut self ) -> #former_storage_name_ident #generics_ty + // fn preform( mut self ) -> #former_storage #generics_ty // fn preform( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed fn preform( mut self ) -> < Self as former::Storage >::Formed { #( #fields_form )* // Rust does not support that, yet // let result = < Definition::Types as former::FormerDefinitionTypes >::Formed - let result = #name_ident #generics_ty + let result = #struct_name #generics_ty { #( #fields_names, )* }; @@ -1061,7 +1069,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = former #[ doc = #doc_former_struct ] - pub struct #former_name_ident < #generics_of_former_with_defaults > + pub struct #former < #generics_of_former_with_defaults > #generics_of_former_where { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, @@ -1071,7 +1079,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } #[ automatically_derived ] - impl #generics_of_former_impl #former_name_ident #generics_of_former_ty + impl #generics_of_former_impl #former #generics_of_former_ty #generics_of_former_where { @@ -1080,12 +1088,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // /// // #[ inline( always ) ] // pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - // // #name_ident #generics_ty + // // #struct_name #generics_ty // { // former::StoragePerform::preform( self.storage ) - // // < #former_storage_name_ident #generics_ty as former::StoragePerform >::preform( self.storage ) + // // < #former_storage #generics_ty as former::StoragePerform >::preform( self.storage ) // // #( #fields_form )* - // // let result = #name_ident + // // let result = #struct_name // // { // // #( #fields_names, )* // // }; @@ -1114,7 +1122,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, - // mut storage : core::option::Option< #former_storage_name_ident #generics_ty >, + // mut storage : core::option::Option< #former_storage #generics_ty >, // context : core::option::Option< __FormerContext >, // on_end : __FormerEnd, ) -> Self @@ -1150,7 +1158,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let context = self.context.take(); // let storage = self.form(); // on_end.call( self.storage, context ) - // former::FormingEnd::< #former_definition_name_ident #generics_ty >::call( &on_end, self.storage, context ) + // former::FormingEnd::< #former_definition #generics_ty >::call( &on_end, self.storage, context ) former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) } @@ -1160,40 +1168,48 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } - #[ automatically_derived ] - // impl #generics_impl #former_name_ident < #generics_params (), former::ReturnPreformed > - impl #generics_impl #former_name_ident < #generics_params > - #generics_where + impl< Definition > #former< Definition > + where + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, + Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty, Formed = #struct_name #generics_ty >, { - /// - /// Construct new instance of former with default parameters. - /// - #[ inline( always ) ] - pub fn new() -> Self + pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { - // #former_name_ident :: < #generics_params #name_ident #generics_ty, former::ReturnPreformed > :: begin - Self :: begin - ( - None, - None, - former::ReturnPreformed, - ) + former::StoragePerform::preform( self.storage ) } } - impl< Definition > #former_name_ident< Definition > - where - Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, - Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage_name_ident #generics_ty, Formed = #name_ident #generics_ty >, + #[ automatically_derived ] + // impl #generics_impl #former < #generics_params (), former::ReturnPreformed > + impl #generics_impl #former < #generics_params > + #generics_where { - pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - // pub fn preform( self ) -> Struct1 + // /// + // /// Construct new instance of former with default parameters. + // /// + // #[ inline( always ) ] + // pub fn new( ) -> Self + // { + // // #former :: < #generics_params #struct_name #generics_ty, former::ReturnPreformed > :: begin + // Self :: begin + // ( + // None, + // None, + // former::ReturnPreformed, + // ) + // } + + /// + /// Construct new instance of former with default parameters. + /// + #[ inline( always ) ] + pub fn new( on_end : < #former_definition as former::FormerDefinition >::End ) -> Self { - former::StoragePerform::preform( self.storage ) + Self::begin( None, None, on_end ) } } From 9edb6844745f56d924c7d5cd0ccf04e25e42ea66 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 11:50:11 +0200 Subject: [PATCH 077/533] former : experimenting --- module/core/former/src/lib.rs | 6 +++--- module/core/former/tests/inc/mod.rs | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/module/core/former/src/lib.rs b/module/core/former/src/lib.rs index 15c66baa2f..02106c368f 100644 --- a/module/core/former/src/lib.rs +++ b/module/core/former/src/lib.rs @@ -4,10 +4,11 @@ #![ doc( html_root_url = "https://docs.rs/former/latest/former/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -// xxx : remove +// zzz : remove #![ allow( missing_docs ) ] -// xxx : describe "Context-aware forming process" +// zzz : describe "Context-aware forming process" +// zzz : explain role of container in former /// Axiomatic things. #[ cfg( feature = "enabled" ) ] @@ -135,4 +136,3 @@ pub mod prelude pub use super::component::*; } -// xxx : explain role of container in former diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 3b159029a1..69a9418704 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -61,6 +61,8 @@ mod former_tests // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_shortcut; +// xxx : uncomment + } #[ cfg( feature = "derive_components" ) ] @@ -108,7 +110,7 @@ only_for_terminal_module! println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); // let t = test_tools::compiletime::TestCases::new(); - // xxx + // zzz : uncomment // t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); // t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); // t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); @@ -125,7 +127,8 @@ only_for_terminal_module! println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); let _t = test_tools::compiletime::TestCases::new(); - //t.compile_fail( "tests/inc/compiletime/components_component_from_debug.rs" ); + // zzz : make it working test + //t.run( "tests/inc/compiletime/components_component_from_debug.rs" ); } From 8a5d4980f162d400cc605ed9cdb77cfb23e63b49 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 11:52:26 +0200 Subject: [PATCH 078/533] former : experimenting --- module/core/former/src/axiomatic.rs | 2 -- module/core/former/src/container.rs | 2 +- module/core/former/src/vector.rs | 2 +- module/core/former_meta/src/derive/former.rs | 16 ---------------- 4 files changed, 2 insertions(+), 20 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index d9abbd710c..8886cf027b 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -40,8 +40,6 @@ pub trait FormerDefinition : Sized /// - `Storage`: The type of the container being processed. /// - `Context`: The type of the context that might be altered or returned upon completion. -// xxx2 : continue. try -// pub trait FormingEnd< Definition : FormerDefinitionTypes > : Default pub trait FormingEnd< Definition : FormerDefinitionTypes > { /// Called at the end of the subforming process to return the modified or original context. diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 437d1bf16b..055bd791ad 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -205,7 +205,7 @@ where on_end : core::option::Option< Definition::End >, } -// xxx : cover by test +// zzz : cover by test use std::fmt; impl< E, Definition > fmt::Debug for ContainerSubformer< E, Definition > where diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 9f69ba7221..f8d312735e 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -74,7 +74,7 @@ where /// `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. -// xxx : update documentation +// zzz : update documentation pub type VectorSubformer< E, Context, Formed, End > = ContainerSubformer::< E, VectorDefinition< E, Context, Formed, End > >; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 2ecea72127..4df477efae 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1183,26 +1183,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } #[ automatically_derived ] - // impl #generics_impl #former < #generics_params (), former::ReturnPreformed > impl #generics_impl #former < #generics_params > #generics_where { - // /// - // /// Construct new instance of former with default parameters. - // /// - // #[ inline( always ) ] - // pub fn new( ) -> Self - // { - // // #former :: < #generics_params #struct_name #generics_ty, former::ReturnPreformed > :: begin - // Self :: begin - // ( - // None, - // None, - // former::ReturnPreformed, - // ) - // } - /// /// Construct new instance of former with default parameters. /// From 6f6b7e746272b28e94d355bcc47a2353c86e63d0 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 12:00:46 +0200 Subject: [PATCH 079/533] former : experimenting --- module/core/former/src/container.rs | 64 +++++++++++++++-------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 055bd791ad..f88733b132 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -200,7 +200,7 @@ where Definition : FormerDefinition, < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, { - storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, + storage : < Definition::Types as FormerDefinitionTypes >::Storage, context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, on_end : core::option::Option< Definition::End >, } @@ -215,7 +215,7 @@ where fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { f.debug_struct( "ContainerSubformer" ) - .field( "storage", &self.storage.as_ref().map( |_| "Storage Present" ) ) + .field( "storage", &"Storage Present" ) .field( "context", &self.context.as_ref().map( |_| "Context Present" ) ) .field( "on_end", &self.on_end.as_ref().map( |_| "End Present" ) ) .finish() @@ -228,34 +228,38 @@ where < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, { - /// Form current former into target structure. - #[ inline( always ) ] - pub fn storage( mut self ) -> < Definition::Types as FormerDefinitionTypes >::Storage - { - let storage = if self.storage.is_some() - { - self.storage.take().unwrap() - } - else - { - let val = Default::default(); - val - }; - storage - } + // /// Form current former into target structure. + // #[ inline( always ) ] + // pub fn storage( mut self ) -> < Definition::Types as FormerDefinitionTypes >::Storage + // { + // let storage = if self.storage.is_some() + // { + // self.storage.take().unwrap() + // } + // else + // { + // let val = Default::default(); + // val + // }; + // storage + // } /// Begins the building process, optionally initializing with a context and storage. #[ inline( always ) ] pub fn begin ( - storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, + mut storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, on_end : Definition::End, ) -> Self { + if storage.is_none() + { + storage = Some( core::default::Default::default() ); + } Self { - storage, + storage : storage.unwrap(), context, on_end : Some( on_end ), } @@ -267,8 +271,8 @@ where { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - let storage = self.storage(); - on_end.call( storage, context ) + // let storage = self.storage(); + on_end.call( self.storage, context ) } /// Finalizes the building process, returning the formed or a context incorporating it. @@ -282,7 +286,7 @@ where #[ inline( always ) ] pub fn replace( mut self, vector : < Definition::Types as FormerDefinitionTypes >::Storage ) -> Self { - self.storage = Some( vector ); + self.storage = vector; self } @@ -368,14 +372,14 @@ where pub fn add< IntoElement >( mut self, element : IntoElement ) -> Self where IntoElement : core::convert::Into< E >, { - if self.storage.is_none() - { - self.storage = core::option::Option::Some( Default::default() ); - } - if let core::option::Option::Some( ref mut storage ) = self.storage - { - ContainerAdd::add( storage, element.into() ); - } + // if self.storage.is_none() + // { + // self.storage = core::option::Option::Some( Default::default() ); + // } + // if let core::option::Option::Some( ref mut storage ) = self.storage + // { + ContainerAdd::add( &mut self.storage, element.into() ); + // } self } From b7bf2a34a9cf3074623e8f17384d9900cd3f9365 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 12:22:15 +0200 Subject: [PATCH 080/533] former : experimenting --- module/core/former/src/container.rs | 32 +-------- .../inc/former_tests/a_primitives_manual.rs | 68 ++++++++++++++++--- .../inc/former_tests/only_test/primitives.rs | 30 +++++++- module/core/former/tests/inc/mod.rs | 2 +- 4 files changed, 89 insertions(+), 43 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index f88733b132..e9ba9590e5 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -292,34 +292,6 @@ where } -// impl< E, T, Types, Definition > ContainerSubformer< E, Definition > -// where -// Types : FormerDefinitionTypes< Context = (), Storage = T, Formed = T >, -// Definition : FormerDefinition< Types = Types, End = ReturnStorage >, -// < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, -// < Definition::Types as FormerDefinitionTypes >::Storage : StoragePerform< Formed = < Definition::Types as FormerDefinitionTypes >::Formed >, -// { -// -// // xxx : update description -// /// Initializes a new `ContainerSubformer` instance, starting with an empty formed. -// /// This function serves as the entry point for the builder pattern. -// /// -// /// # Returns -// /// A new instance of `ContainerSubformer` with an empty internal formed. -// /// -// #[ inline( always ) ] -// pub fn new_returning_storage() -> Self -// { -// Self::begin -// ( -// None, -// None, -// ReturnStorage, -// ) -// } -// -// } - impl< E, Storage, Formed, Types, Definition > ContainerSubformer< E, Definition > where Types : FormerDefinitionTypes< Context = (), Storage = Storage, Formed = Formed >, @@ -333,7 +305,7 @@ where /// # Returns /// A new instance of `ContainerSubformer` with an empty internal formed. /// - // xxx : update description + // zzz : update description #[ inline( always ) ] pub fn new( end : Definition::End ) -> Self { @@ -345,7 +317,7 @@ where ) } - // xxx : update description + // zzz : update description #[ inline( always ) ] pub fn new_with< IntoEnd >( end : IntoEnd ) -> Self where diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index abac9bd9fb..8e34bec30b 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -260,6 +260,27 @@ where self } + // zzz : update description + #[ inline( always ) ] + pub fn new( on_end : Definition::End ) -> Self + { + Self::begin( None, None, on_end ) + } + + // zzz : update description + #[ inline( always ) ] + pub fn new_with< IntoEnd >( end : IntoEnd ) -> Self + where + IntoEnd : Into< Definition::End >, + { + Self::begin + ( + None, + None, + end.into(), + ) + } + } impl< Definition > Struct1Former< Definition > @@ -276,16 +297,43 @@ where } -impl Struct1Former -{ - - #[ inline( always ) ] - pub fn new( on_end : < Struct1FormerDefinition as former::FormerDefinition >::End ) -> Self - { - Self::begin( None, None, on_end ) - } - -} +// // impl Struct1Former +// +// impl< Definition > Struct1Former< Definition > +// where +// // Types : FormerDefinitionTypes< Context = () >, +// Definition : former::FormerDefinition< End = former::ReturnPreformed >, +// Definition::Types : former::FormerDefinitionTypes +// < +// Storage = Struct1FormerStorage, +// Formed = Struct1, +// Context = (), +// >, +// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, // xxx : redundant? +// { +// +// // zzz : update description +// #[ inline( always ) ] +// pub fn new( on_end : Definition::End ) -> Self +// { +// Self::begin( None, None, on_end ) +// } +// +// // zzz : update description +// #[ inline( always ) ] +// pub fn new_with< IntoEnd >( end : IntoEnd ) -> Self +// where +// IntoEnd : Into< Definition::End >, +// { +// Self::begin +// ( +// None, +// None, +// end.into(), +// ) +// } +// +// } // diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 0f209c90a9..e3b2632785 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -18,7 +18,7 @@ tests_impls! a_id!( former.storage.string_optional_1, None ); a_id!( former.context, None ); a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); - let former2 = Struct1Former::new( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); @@ -73,13 +73,38 @@ tests_impls! { let former = Struct1::former(); - let former2 = Struct1Former::new( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); } // + fn custom_definition_params() + { + + // default explicit params + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::new( former::ReturnPreformed ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // xxx2 : continue + // // default explicit params + // let got = Struct1Former + // ::< Struct1FormerDefinition< (), i32, _ > > + // ::new( ( | storage : Struct1FormerStorage, _context | storage.int_1.unwrap()*2 ).into() ) + // .int_1( 13 ) + // .form(); + // // a_id!( got, 26 ); + + } + + // + fn preform() { @@ -347,6 +372,7 @@ tests_index! internals, begin, new, + custom_definition_params, preform, definition, storage, diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 69a9418704..b25ec0ee45 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -18,7 +18,7 @@ mod former_tests mod a_primitives_manual; // mod a_primitives_expanded; - mod a_primitives; + // mod a_primitives; // mod a_containers_without_subformer_manual; // mod a_containers_without_subformer; // #[ cfg( not( feature = "no_std" ) ) ] From 8a30e617a7f8b87aeff0d353485ec61fa1e237e4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 14:09:31 +0200 Subject: [PATCH 081/533] former : experimenting --- module/core/former/src/axiomatic.rs | 4 +-- module/core/former/src/hash_map.rs | 2 +- module/core/former/src/hash_set.rs | 2 +- module/core/former/src/vector.rs | 2 +- .../inc/former_tests/a_primitives_manual.rs | 12 ++++----- .../inc/former_tests/only_test/primitives.rs | 25 +++++++++++++++---- module/core/former_meta/src/derive/former.rs | 12 ++++----- 7 files changed, 37 insertions(+), 22 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 8886cf027b..2a92db76bc 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -6,7 +6,7 @@ pub trait Storage : ::core::default::Default } /// zzz : write description -pub trait StoragePerform : Storage +pub trait StoragePreform : Storage { fn preform( self ) -> Self::Formed; } @@ -75,7 +75,7 @@ pub struct ReturnPreformed; impl< Definition > FormingEnd< Definition > for ReturnPreformed where - Definition::Storage : StoragePerform< Formed = Definition::Formed >, + Definition::Storage : StoragePreform< Formed = Definition::Formed >, Definition : FormerDefinitionTypes, { #[ inline( always ) ] diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 77d5b03bc6..9e4ade2a37 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -56,7 +56,7 @@ where type Formed = HashMap< K, E >; } -impl< K, E > StoragePerform +impl< K, E > StoragePreform for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 0f5bde873a..ca26ad27eb 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -44,7 +44,7 @@ where type Formed = HashSet< K >; } -impl< K > StoragePerform +impl< K > StoragePreform for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index f8d312735e..26b18c5704 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -31,7 +31,7 @@ for Vec< E > type Formed = Vec< E >; } -impl< E > StoragePerform +impl< E > StoragePreform for Vec< E > { fn preform( self ) -> Self::Formed diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 8e34bec30b..2be272c70d 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -112,7 +112,7 @@ for Struct1FormerStorage type Formed = Struct1; } -impl former::StoragePerform +impl former::StoragePreform for Struct1FormerStorage { @@ -179,7 +179,7 @@ pub struct Struct1Former > where Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, @@ -190,7 +190,7 @@ where impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { @@ -286,13 +286,13 @@ where impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { - former::StoragePerform::preform( self.storage ) + former::StoragePreform::preform( self.storage ) } } @@ -309,7 +309,7 @@ where // Formed = Struct1, // Context = (), // >, -// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, // xxx : redundant? +// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, // xxx : redundant? // { // // // zzz : update description diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index e3b2632785..34ca0ac6fb 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -92,6 +92,21 @@ tests_impls! let exp = Struct1::former().int_1( 13 ).form(); a_id!( got, exp ); + // default explicit params + fn f1( storage : Struct1FormerStorage, _context : Option< () > ) -> Struct1 + { + former::StoragePreform::preform( storage ) + } + let end_wrapper : former::FormingEndWrapper< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndWrapper::new( f1 ); + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::new( end_wrapper ) + // ::new( ( | storage : Struct1FormerStorage, _context | -> Struct1 { former::StoragePreform::preform( storage ) } ).into() ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + // xxx2 : continue // // default explicit params // let got = Struct1Former @@ -114,12 +129,12 @@ tests_impls! a_id!( got, exp ); // storage should have method preform - let got = the_module::StoragePerform::preform( Struct1::former().storage ); + let got = the_module::StoragePreform::preform( Struct1::former().storage ); let exp = Struct1::former().form(); a_id!( got, exp ); // storage should have method preform - use the_module::StoragePerform; + use the_module::StoragePreform; let got = Struct1::former().storage.preform(); let exp = Struct1::former().form(); a_id!( got, exp ); @@ -146,7 +161,7 @@ tests_impls! a_id!( got, exp ); // definition types exists and has Storage - use former::StoragePerform; + use former::StoragePreform; let got = < Struct1FormerDefinitionTypes as the_module::FormerDefinitionTypes >::Storage::preform( Struct1::former().storage ); let exp = Struct1::former().form(); a_id!( got, exp ); @@ -164,7 +179,7 @@ tests_impls! { // definition exists and has Storage - let got = < Struct1FormerStorage as the_module::StoragePerform >::preform( Struct1::former().storage ); + let got = < Struct1FormerStorage as the_module::StoragePreform >::preform( Struct1::former().storage ); let exp = Struct1::former().form(); a_id!( got, exp ); @@ -174,7 +189,7 @@ tests_impls! a_id!( got, exp ); // definition exists and has Storage - use former::StoragePerform; + use former::StoragePreform; let got = Struct1::former().storage.preform(); let exp = Struct1::former().form(); a_id!( got, exp ); diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 4df477efae..0a4f9cc84e 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -856,7 +856,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { where Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, }; // zzz : write helper to fix bug with where @@ -1045,7 +1045,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } // generics_impl, generics_ty, generics_where - impl former::StoragePerform + impl former::StoragePreform for #former_storage #generics_ty #generics_where { @@ -1090,8 +1090,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed // // #struct_name #generics_ty // { - // former::StoragePerform::preform( self.storage ) - // // < #former_storage #generics_ty as former::StoragePerform >::preform( self.storage ) + // former::StoragePreform::preform( self.storage ) + // // < #former_storage #generics_ty as former::StoragePreform >::preform( self.storage ) // // #( #fields_form )* // // let result = #struct_name // // { @@ -1171,13 +1171,13 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl< Definition > #former< Definition > where Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePerform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty, Formed = #struct_name #generics_ty >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { - former::StoragePerform::preform( self.storage ) + former::StoragePreform::preform( self.storage ) } } From d0395021f60b607d74ec5b9f74997de5cc16b94d Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 15:00:41 +0200 Subject: [PATCH 082/533] former : experimenting --- .../inc/former_tests/a_primitives_manual.rs | 86 ++++++++++--------- .../inc/former_tests/only_test/primitives.rs | 66 +++++++++++++- 2 files changed, 110 insertions(+), 42 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 2be272c70d..1495f60c82 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -179,8 +179,8 @@ pub struct Struct1Former > where Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -190,8 +190,8 @@ where impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, { #[ inline( always ) ] @@ -201,6 +201,50 @@ where return result; } + #[ inline( always ) ] + pub fn begin_with< IntoEnd > + ( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : IntoEnd, + ) -> Self + where + IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > + { + if storage.is_none() + { + storage = Some( core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context, + on_end : ::core::option::Option::Some( on_end.into() ), + } + } + + // #[ inline( always ) ] + // pub fn begin< IntoEnd > + // ( + // mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + // context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + // on_end : IntoEnd, + // ) -> Self + // where + // IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > + // { + // if storage.is_none() + // { + // storage = Some( core::default::Default::default() ); + // } + // Self + // { + // storage : storage.unwrap(), + // context, + // on_end : ::core::option::Option::Some( on_end.into() ), + // } + // } + #[ inline( always ) ] pub fn begin ( @@ -297,44 +341,6 @@ where } -// // impl Struct1Former -// -// impl< Definition > Struct1Former< Definition > -// where -// // Types : FormerDefinitionTypes< Context = () >, -// Definition : former::FormerDefinition< End = former::ReturnPreformed >, -// Definition::Types : former::FormerDefinitionTypes -// < -// Storage = Struct1FormerStorage, -// Formed = Struct1, -// Context = (), -// >, -// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, // xxx : redundant? -// { -// -// // zzz : update description -// #[ inline( always ) ] -// pub fn new( on_end : Definition::End ) -> Self -// { -// Self::begin( None, None, on_end ) -// } -// -// // zzz : update description -// #[ inline( always ) ] -// pub fn new_with< IntoEnd >( end : IntoEnd ) -> Self -// where -// IntoEnd : Into< Definition::End >, -// { -// Self::begin -// ( -// None, -// None, -// end.into(), -// ) -// } -// -// } - // include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 34ca0ac6fb..3ec5a77bca 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -82,6 +82,7 @@ tests_impls! fn custom_definition_params() { + // zzz : make example of that // default explicit params let got = Struct1Former @@ -92,7 +93,7 @@ tests_impls! let exp = Struct1::former().int_1( 13 ).form(); a_id!( got, exp ); - // default explicit params + // default explicit params with wrapper fn f1( storage : Struct1FormerStorage, _context : Option< () > ) -> Struct1 { former::StoragePreform::preform( storage ) @@ -101,12 +102,73 @@ tests_impls! let got = Struct1Former ::< Struct1FormerDefinition< (), Struct1, _ > > ::new( end_wrapper ) - // ::new( ( | storage : Struct1FormerStorage, _context | -> Struct1 { former::StoragePreform::preform( storage ) } ).into() ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); a_id!( got, exp ); + // default explicit params with wrapper and closure + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::new( former::FormingEndWrapper::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure, auto types + let got = Struct1Former + ::< Struct1FormerDefinition< _, _, _ > > + ::new( former::FormingEndWrapper::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // custom params + let got = Struct1Former + ::< Struct1FormerDefinition< i32, i32, _ > > + ::begin + ( + None, + Some( 3 ), + former::FormingEndWrapper::new + ( + | storage : Struct1FormerStorage, context | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } + ), + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); + + // custom params with into + let got = Struct1Former + ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > + ::begin + ( + None, + Some( 3 ), + ( + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } + ).into(), + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); + + // custom params begin_with + let got = Struct1Former + ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > + ::begin_with + ( + None, + Some( 3 ), + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); + // xxx2 : continue // // default explicit params // let got = Struct1Former From 1effc152f5d01e7107b76c158365d1138b652ea4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 15:13:09 +0200 Subject: [PATCH 083/533] former : experimenting --- .../inc/former_tests/a_primitives_manual.rs | 50 +++---- .../inc/former_tests/only_test/primitives.rs | 128 +++++++++++------- 2 files changed, 106 insertions(+), 72 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 1495f60c82..69a85e940e 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -201,30 +201,8 @@ where return result; } - #[ inline( always ) ] - pub fn begin_with< IntoEnd > - ( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : IntoEnd, - ) -> Self - where - IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > - { - if storage.is_none() - { - storage = Some( core::default::Default::default() ); - } - Self - { - storage : storage.unwrap(), - context, - on_end : ::core::option::Option::Some( on_end.into() ), - } - } - // #[ inline( always ) ] - // pub fn begin< IntoEnd > + // pub fn begin_with< IntoEnd > // ( // mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, // context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -246,7 +224,29 @@ where // } #[ inline( always ) ] - pub fn begin + pub fn begin< IntoEnd > + ( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : IntoEnd, + ) -> Self + where + IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > + { + if storage.is_none() + { + storage = Some( core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context, + on_end : ::core::option::Option::Some( on_end.into() ), + } + } + + #[ inline( always ) ] + pub fn begin_explicit ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -308,7 +308,7 @@ where #[ inline( always ) ] pub fn new( on_end : Definition::End ) -> Self { - Self::begin( None, None, on_end ) + Self::begin_explicit( None, None, on_end ) } // zzz : update description diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 3ec5a77bca..c1f3c0fc34 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -43,43 +43,6 @@ tests_impls! // - fn begin() - { - - // begin with none - let got = Struct1Former::< Struct1FormerDefinition >::begin( None, None, the_module::ReturnPreformed ).int_1( 13 ).form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // begin with storage - let mut storage = Struct1FormerStorage::default(); - storage.int_1 = Some( 13 ); - let exp = Struct1Former::< Struct1FormerDefinition >::begin( Some( storage ), None, the_module::ReturnPreformed ).form(); - a_id!( got, exp ); - - // begin with context - let mut storage = Struct1FormerStorage::default(); - storage.int_1 = Some( 13 ); - let exp = Struct1Former::< Struct1FormerDefinition > - ::begin( Some( storage ), Some( () ), the_module::ReturnPreformed ) - .form(); - a_id!( got, exp ); - - } - - // - - fn new() - { - - let former = Struct1::former(); - let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); - a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); - - } - - // - fn custom_definition_params() { // zzz : make example of that @@ -127,15 +90,12 @@ tests_impls! // custom params let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, _ > > + ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > ::begin ( None, Some( 3 ), - former::FormingEndWrapper::new - ( - | storage : Struct1FormerStorage, context | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } - ), + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }, ) .int_1( 13 ) .form(); @@ -148,18 +108,16 @@ tests_impls! ( None, Some( 3 ), - ( - | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } - ).into(), + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }, ) .int_1( 13 ) .form(); a_id!( got, 32 ); - // custom params begin_with + // custom params begin let got = Struct1Former ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::begin_with + ::begin ( None, Some( 3 ), @@ -182,6 +140,81 @@ tests_impls! // + fn begin() + { + + // begin with none + let got = Struct1Former::< Struct1FormerDefinition >::begin( None, None, the_module::ReturnPreformed ).int_1( 13 ).form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // begin with storage + let mut storage = Struct1FormerStorage::default(); + storage.int_1 = Some( 13 ); + let exp = Struct1Former::< Struct1FormerDefinition >::begin( Some( storage ), None, the_module::ReturnPreformed ).form(); + a_id!( got, exp ); + + // begin with context + let mut storage = Struct1FormerStorage::default(); + storage.int_1 = Some( 13 ); + let exp = Struct1Former::< Struct1FormerDefinition > + ::begin( Some( storage ), Some( () ), the_module::ReturnPreformed ) + .form(); + a_id!( got, exp ); + + } + + // + + fn begin_explicit() + { + + // custom params + let got = Struct1Former + ::< Struct1FormerDefinition< i32, i32, _ > > + ::begin_explicit + ( + None, + Some( 3 ), + former::FormingEndWrapper::new + ( + | storage : Struct1FormerStorage, context | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } + ), + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); + + // custom params with into + let got = Struct1Former + ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > + ::begin_explicit + ( + None, + Some( 3 ), + ( + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } + ).into(), + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); + + } + + // + + fn new() + { + + let former = Struct1::former(); + let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); + a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); + + } + + // + fn preform() { @@ -448,6 +481,7 @@ tests_index! { internals, begin, + begin_explicit, new, custom_definition_params, preform, From 2d07383bfa7e23f06baeebfdae3e675da5da8eb6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 15:17:29 +0200 Subject: [PATCH 084/533] former : experimenting --- .../inc/former_tests/a_primitives_manual.rs | 32 +++++++++++-------- .../inc/former_tests/only_test/primitives.rs | 18 ++++++++--- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 69a85e940e..79fa37d884 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -246,7 +246,7 @@ where } #[ inline( always ) ] - pub fn begin_explicit + pub fn begin_precise ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -306,25 +306,31 @@ where // zzz : update description #[ inline( always ) ] - pub fn new( on_end : Definition::End ) -> Self + pub fn new_precise( on_end : Definition::End ) -> Self { - Self::begin_explicit( None, None, on_end ) + Self::begin_precise( None, None, on_end ) } - // zzz : update description #[ inline( always ) ] - pub fn new_with< IntoEnd >( end : IntoEnd ) -> Self - where - IntoEnd : Into< Definition::End >, + pub fn new( on_end : Definition::End ) -> Self { - Self::begin - ( - None, - None, - end.into(), - ) + Self::begin_precise( None, None, on_end ) } + // zzz : use + // #[ inline( always ) ] + // pub fn new< IntoEnd >( end : IntoEnd ) -> Self + // where + // IntoEnd : Into< Definition::End >, + // { + // Self::begin + // ( + // None, + // None, + // end.into(), + // ) + // } + } impl< Definition > Struct1Former< Definition > diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index c1f3c0fc34..ba8a0a30d9 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -166,13 +166,13 @@ tests_impls! // - fn begin_explicit() + fn begin_precise() { // custom params let got = Struct1Former ::< Struct1FormerDefinition< i32, i32, _ > > - ::begin_explicit + ::begin_precise ( None, Some( 3 ), @@ -188,7 +188,7 @@ tests_impls! // custom params with into let got = Struct1Former ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::begin_explicit + ::begin_precise ( None, Some( 3 ), @@ -207,9 +207,19 @@ tests_impls! fn new() { + let former = Struct1::former(); + let former2 = Struct1Former::< Struct1FormerDefinition >::new_precise( former::ReturnPreformed ); + a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); + let exp = former.form(); + let got = former2.form(); + a_id!( got, exp ); + let former = Struct1::former(); let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); + let exp = former.form(); + let got = former2.form(); + a_id!( got, exp ); } @@ -481,7 +491,7 @@ tests_index! { internals, begin, - begin_explicit, + begin_precise, new, custom_definition_params, preform, From 6fe0f951c6ca0b94f6e07b25ca9b636665314c82 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 16:51:23 +0200 Subject: [PATCH 085/533] former : experimenting --- .../inc/former_tests/a_primitives_manual.rs | 32 ++--- .../inc/former_tests/only_test/primitives.rs | 135 ++++++++++++------ 2 files changed, 109 insertions(+), 58 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 79fa37d884..fa99e0cf9f 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -311,26 +311,26 @@ where Self::begin_precise( None, None, on_end ) } - #[ inline( always ) ] - pub fn new( on_end : Definition::End ) -> Self - { - Self::begin_precise( None, None, on_end ) - } - - // zzz : use // #[ inline( always ) ] - // pub fn new< IntoEnd >( end : IntoEnd ) -> Self - // where - // IntoEnd : Into< Definition::End >, + // pub fn new( on_end : Definition::End ) -> Self // { - // Self::begin - // ( - // None, - // None, - // end.into(), - // ) + // Self::begin_precise( None, None, on_end ) // } + // zzz : use + #[ inline( always ) ] + pub fn new< IntoEnd >( end : IntoEnd ) -> Self + where + IntoEnd : Into< Definition::End >, + { + Self::begin + ( + None, + None, + end.into(), + ) + } + } impl< Definition > Struct1Former< Definition > diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index ba8a0a30d9..d851a52976 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -47,47 +47,6 @@ tests_impls! { // zzz : make example of that - // default explicit params - let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, _ > > - ::new( former::ReturnPreformed ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // default explicit params with wrapper - fn f1( storage : Struct1FormerStorage, _context : Option< () > ) -> Struct1 - { - former::StoragePreform::preform( storage ) - } - let end_wrapper : former::FormingEndWrapper< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndWrapper::new( f1 ); - let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, _ > > - ::new( end_wrapper ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // default explicit params with wrapper and closure - let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, _ > > - ::new( former::FormingEndWrapper::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // default explicit params with wrapper and closure, auto types - let got = Struct1Former - ::< Struct1FormerDefinition< _, _, _ > > - ::new( former::FormingEndWrapper::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - // custom params let got = Struct1Former ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > @@ -207,6 +166,7 @@ tests_impls! fn new() { + // basic case let former = Struct1::former(); let former2 = Struct1Former::< Struct1FormerDefinition >::new_precise( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); @@ -214,13 +174,103 @@ tests_impls! let got = former2.form(); a_id!( got, exp ); + // default explicit params + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > + ::new( former::ReturnPreformed ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper + fn f1( storage : Struct1FormerStorage, _context : Option< () > ) -> Struct1 + { + former::StoragePreform::preform( storage ) + } + let end_wrapper : former::FormingEndWrapper< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndWrapper::new( f1 ); + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, former::FormingEndWrapper< Struct1FormerDefinitionTypes< (), Struct1 > > > > + ::new( end_wrapper ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, former::FormingEndWrapper< Struct1FormerDefinitionTypes< (), Struct1 > > > > + ::new( former::FormingEndWrapper::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure, auto types + let got = Struct1Former + ::< Struct1FormerDefinition< _, _, former::FormingEndWrapper< Struct1FormerDefinitionTypes< (), Struct1 > > > > + ::new( former::FormingEndWrapper::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + } + + // + + fn new_precise() + { + + // basic case let former = Struct1::former(); - let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition >::new_precise( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let exp = former.form(); let got = former2.form(); a_id!( got, exp ); + // default explicit params + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::new_precise( former::ReturnPreformed ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper + fn f1( storage : Struct1FormerStorage, _context : Option< () > ) -> Struct1 + { + former::StoragePreform::preform( storage ) + } + let end_wrapper : former::FormingEndWrapper< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndWrapper::new( f1 ); + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::new_precise( end_wrapper ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::new_precise( former::FormingEndWrapper::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure, auto types + let got = Struct1Former + ::< Struct1FormerDefinition< _, _, _ > > + ::new_precise( former::FormingEndWrapper::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + } // @@ -493,6 +543,7 @@ tests_index! begin, begin_precise, new, + new_precise, custom_definition_params, preform, definition, From 130812296893e39587cf4f704c8a4f1998948544 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 16:52:27 +0200 Subject: [PATCH 086/533] former : experimenting --- .../inc/former_tests/a_primitives_manual.rs | 35 ++----------------- .../inc/former_tests/only_test/primitives.rs | 24 ++++++------- 2 files changed, 15 insertions(+), 44 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index fa99e0cf9f..25351e9bed 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -201,28 +201,6 @@ where return result; } - // #[ inline( always ) ] - // pub fn begin_with< IntoEnd > - // ( - // mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, - // context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - // on_end : IntoEnd, - // ) -> Self - // where - // IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > - // { - // if storage.is_none() - // { - // storage = Some( core::default::Default::default() ); - // } - // Self - // { - // storage : storage.unwrap(), - // context, - // on_end : ::core::option::Option::Some( on_end.into() ), - // } - // } - #[ inline( always ) ] pub fn begin< IntoEnd > ( @@ -246,7 +224,7 @@ where } #[ inline( always ) ] - pub fn begin_precise + pub fn _begin_precise ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -306,18 +284,11 @@ where // zzz : update description #[ inline( always ) ] - pub fn new_precise( on_end : Definition::End ) -> Self + pub fn _new_precise( on_end : Definition::End ) -> Self { - Self::begin_precise( None, None, on_end ) + Self::_begin_precise( None, None, on_end ) } - // #[ inline( always ) ] - // pub fn new( on_end : Definition::End ) -> Self - // { - // Self::begin_precise( None, None, on_end ) - // } - - // zzz : use #[ inline( always ) ] pub fn new< IntoEnd >( end : IntoEnd ) -> Self where diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index d851a52976..8731712fbb 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -125,13 +125,13 @@ tests_impls! // - fn begin_precise() + fn _begin_precise() { // custom params let got = Struct1Former ::< Struct1FormerDefinition< i32, i32, _ > > - ::begin_precise + ::_begin_precise ( None, Some( 3 ), @@ -147,7 +147,7 @@ tests_impls! // custom params with into let got = Struct1Former ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::begin_precise + ::_begin_precise ( None, Some( 3 ), @@ -168,7 +168,7 @@ tests_impls! // basic case let former = Struct1::former(); - let former2 = Struct1Former::< Struct1FormerDefinition >::new_precise( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition >::_new_precise( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let exp = former.form(); let got = former2.form(); @@ -219,12 +219,12 @@ tests_impls! // - fn new_precise() + fn _new_precise() { // basic case let former = Struct1::former(); - let former2 = Struct1Former::< Struct1FormerDefinition >::new_precise( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition >::_new_precise( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let exp = former.form(); let got = former2.form(); @@ -233,7 +233,7 @@ tests_impls! // default explicit params let got = Struct1Former ::< Struct1FormerDefinition< (), Struct1, _ > > - ::new_precise( former::ReturnPreformed ) + ::_new_precise( former::ReturnPreformed ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -247,7 +247,7 @@ tests_impls! let end_wrapper : former::FormingEndWrapper< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndWrapper::new( f1 ); let got = Struct1Former ::< Struct1FormerDefinition< (), Struct1, _ > > - ::new_precise( end_wrapper ) + ::_new_precise( end_wrapper ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -256,7 +256,7 @@ tests_impls! // default explicit params with wrapper and closure let got = Struct1Former ::< Struct1FormerDefinition< (), Struct1, _ > > - ::new_precise( former::FormingEndWrapper::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + ::_new_precise( former::FormingEndWrapper::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -265,7 +265,7 @@ tests_impls! // default explicit params with wrapper and closure, auto types let got = Struct1Former ::< Struct1FormerDefinition< _, _, _ > > - ::new_precise( former::FormingEndWrapper::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) + ::_new_precise( former::FormingEndWrapper::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -541,9 +541,9 @@ tests_index! { internals, begin, - begin_precise, + _begin_precise, new, - new_precise, + _new_precise, custom_definition_params, preform, definition, From 2fb4a30af2f9be2f8e3e394494db8b5d483b67b4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 17:06:23 +0200 Subject: [PATCH 087/533] former : experimenting --- module/core/former/src/axiomatic.rs | 16 +++---- .../a_containers_with_subformer_manual.rs | 4 +- .../inc/former_tests/a_primitives_manual.rs | 4 ++ .../former_tests/container_former_common.rs | 4 +- .../inc/former_tests/only_test/primitives.rs | 46 +++++++++++++------ .../inc/former_tests/subformer_shortcut.rs | 4 +- 6 files changed, 50 insertions(+), 28 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 2a92db76bc..b0f1dc4b0b 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -130,13 +130,13 @@ where /// a closure needs to be stored or passed around as an object implementing /// `FormingEnd`. #[ cfg( not( feature = "no_std" ) ) ] -pub struct FormingEndWrapper< Definition : FormerDefinitionTypes > +pub struct FormingEndClosure< Definition : FormerDefinitionTypes > { closure : Box< dyn Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed >, _marker : std::marker::PhantomData< Definition::Storage >, } -impl< T, Definition > From< T > for FormingEndWrapper< Definition > +impl< T, Definition > From< T > for FormingEndClosure< Definition > where T : Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed + 'static, Definition : FormerDefinitionTypes, @@ -153,9 +153,9 @@ where } #[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinitionTypes > FormingEndWrapper< Definition > +impl< Definition : FormerDefinitionTypes > FormingEndClosure< Definition > { - /// Constructs a new `FormingEndWrapper` with the provided closure. + /// Constructs a new `FormingEndClosure` with the provided closure. /// /// # Parameters /// @@ -165,7 +165,7 @@ impl< Definition : FormerDefinitionTypes > FormingEndWrapper< Definition > /// /// # Returns /// - /// Returns an instance of `FormingEndWrapper` encapsulating the provided closure. + /// Returns an instance of `FormingEndClosure` encapsulating the provided closure. pub fn new( closure : impl Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed + 'static ) -> Self { Self @@ -179,11 +179,11 @@ impl< Definition : FormerDefinitionTypes > FormingEndWrapper< Definition > #[ cfg( not( feature = "no_std" ) ) ] use std::fmt; #[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinitionTypes > fmt::Debug for FormingEndWrapper< Definition > +impl< Definition : FormerDefinitionTypes > fmt::Debug for FormingEndClosure< Definition > { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { - f.debug_struct( "FormingEndWrapper" ) + f.debug_struct( "FormingEndClosure" ) .field( "closure", &format_args!{ "- closure -" } ) .field( "_marker", &self._marker ) .finish() @@ -192,7 +192,7 @@ impl< Definition : FormerDefinitionTypes > fmt::Debug for FormingEndWrapper< Def #[ cfg( not( feature = "no_std" ) ) ] impl< Definition : FormerDefinitionTypes > FormingEnd< Definition > -for FormingEndWrapper< Definition > +for FormingEndClosure< Definition > { fn call( &self, storage : Definition::Storage, context : Option< Definition::Context > ) -> Definition::Formed { diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index f9b0f1f976..56309292bf 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -162,7 +162,7 @@ where < Vec< String >, Vec< String >, - Self, End = former::FormingEndWrapper< Vec< String >, Self >, + Self, End = former::FormingEndClosure< Vec< String >, Self >, >, { let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self @@ -178,7 +178,7 @@ where } super_former }; - Former2::_begin( None, Some( self ), former::FormingEndWrapper::new( on_end ) ) + Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) } // xxx2 : continue diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 25351e9bed..39131d9cce 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -78,6 +78,10 @@ where type End = End; } +// zzz : documentation +pub type Struct1FormerWithClosure< Context, Formed > = +Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; + // = storage // generated by former diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index a4bb1ca1e1..228662f385 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -247,7 +247,7 @@ fn custom_definition_custom_end() impl former::FormerDefinition for Return13 { type Types = Return13; - type End = former::FormingEndWrapper< < Self as former::FormerDefinition >::Types >; + type End = former::FormingEndClosure< < Self as former::FormerDefinition >::Types >; } fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 @@ -255,7 +255,7 @@ fn custom_definition_custom_end() 13 } - let end_wrapper : the_module::FormingEndWrapper< Return13 > = the_module::FormingEndWrapper::new( return_13 ); + let end_wrapper : the_module::FormingEndClosure< Return13 > = the_module::FormingEndClosure::new( return_13 ); let got = the_module::ContainerSubformer::< String, Return13 >::new( end_wrapper ) .add( "a" ) .add( "b" ) diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 8731712fbb..c7c26b01e4 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -49,7 +49,7 @@ tests_impls! // custom params let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > + ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > ::begin ( None, @@ -62,7 +62,7 @@ tests_impls! // custom params with into let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > + ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > ::begin ( None, @@ -75,7 +75,7 @@ tests_impls! // custom params begin let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > + ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > ::begin ( None, @@ -135,7 +135,7 @@ tests_impls! ( None, Some( 3 ), - former::FormingEndWrapper::new + former::FormingEndClosure::new ( | storage : Struct1FormerStorage, context | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } ), @@ -146,7 +146,7 @@ tests_impls! // custom params with into let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, former::FormingEndWrapper< Struct1FormerDefinitionTypes< i32, i32 > > > > + ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > ::_begin_precise ( None, @@ -188,9 +188,9 @@ tests_impls! { former::StoragePreform::preform( storage ) } - let end_wrapper : former::FormingEndWrapper< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndWrapper::new( f1 ); + let end_wrapper : former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndClosure::new( f1 ); let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, former::FormingEndWrapper< Struct1FormerDefinitionTypes< (), Struct1 > > > > + ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > ::new( end_wrapper ) .int_1( 13 ) .form(); @@ -199,8 +199,8 @@ tests_impls! // default explicit params with wrapper and closure let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, former::FormingEndWrapper< Struct1FormerDefinitionTypes< (), Struct1 > > > > - ::new( former::FormingEndWrapper::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > + ::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -208,8 +208,26 @@ tests_impls! // default explicit params with wrapper and closure, auto types let got = Struct1Former - ::< Struct1FormerDefinition< _, _, former::FormingEndWrapper< Struct1FormerDefinitionTypes< (), Struct1 > > > > - ::new( former::FormingEndWrapper::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) + ::< Struct1FormerDefinition< _, _, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > + ::new( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure + let got = Struct1Former + ::< Struct1FormerWithClosure< (), Struct1 > > + ::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure + let got = Struct1Former + ::< Struct1FormerWithClosure< (), Struct1 > > + ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -244,7 +262,7 @@ tests_impls! { former::StoragePreform::preform( storage ) } - let end_wrapper : former::FormingEndWrapper< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndWrapper::new( f1 ); + let end_wrapper : former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndClosure::new( f1 ); let got = Struct1Former ::< Struct1FormerDefinition< (), Struct1, _ > > ::_new_precise( end_wrapper ) @@ -256,7 +274,7 @@ tests_impls! // default explicit params with wrapper and closure let got = Struct1Former ::< Struct1FormerDefinition< (), Struct1, _ > > - ::_new_precise( former::FormingEndWrapper::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + ::_new_precise( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -265,7 +283,7 @@ tests_impls! // default explicit params with wrapper and closure, auto types let got = Struct1Former ::< Struct1FormerDefinition< _, _, _ > > - ::_new_precise( former::FormingEndWrapper::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) + ::_new_precise( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 9ab7e6933f..bf36125847 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -61,7 +61,7 @@ where TemplateParameterDefinitionFormerStorage, TemplateParameterDefinition, Self, - End = former::FormingEndWrapper< TemplateParameterDefinition, Self >, + End = former::FormingEndClosure< TemplateParameterDefinition, Self >, >, // FieldContainer : ContainerAdd, { @@ -78,7 +78,7 @@ where } super_former }; - Former2::_begin( None, Some( self ), former::FormingEndWrapper::new( on_end ) ) + Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) } // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help From af08892e3ced64d26ced5b0c43890c5c68aa87fa Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 17:08:40 +0200 Subject: [PATCH 088/533] former : experimenting --- .../inc/former_tests/only_test/primitives.rs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index c7c26b01e4..3b20fe8cd1 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -86,14 +86,18 @@ tests_impls! .form(); a_id!( got, 32 ); - // xxx2 : continue - // // default explicit params - // let got = Struct1Former - // ::< Struct1FormerDefinition< (), i32, _ > > - // ::new( ( | storage : Struct1FormerStorage, _context | storage.int_1.unwrap()*2 ).into() ) - // .int_1( 13 ) - // .form(); - // // a_id!( got, 26 ); + // custom params begin with Struct1FormerWithClosure + let got = Struct1Former + ::< Struct1FormerWithClosure< i32, i32 > > + ::begin + ( + None, + Some( 3 ), + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); } From 811f3e8935156bf9d933a10cad39b27ad3894ce4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 17:20:24 +0200 Subject: [PATCH 089/533] former : experimenting --- .../inc/former_tests/a_primitives_expanded.rs | 2 +- .../inc/former_tests/a_primitives_manual.rs | 10 +-- module/core/former_meta/src/derive/former.rs | 69 ++++++++++++++++--- 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs index bcf31514bd..1fb79bc568 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs @@ -15,4 +15,4 @@ pub struct Struct1 // = end of generated - include!( "./only_test/primitives.rs" ); +include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 39131d9cce..c2690cbe7e 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -223,7 +223,7 @@ where { storage : storage.unwrap(), context, - on_end : ::core::option::Option::Some( on_end.into() ), + on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), } } @@ -266,7 +266,7 @@ where where Src : core::convert::Into< i32 >, { debug_assert!( self.storage.int_1.is_none() ); - self.storage.int_1 = Some( src.into() ); + self.storage.int_1 = Some( ::core::convert::Into::into( src ) ); self } @@ -274,7 +274,7 @@ where where Src : core::convert::Into< String >, { debug_assert!( self.storage.string_1.is_none() ); - self.storage.string_1 = Some( src.into() ); + self.storage.string_1 = Some( ::core::convert::Into::into( src ) ); self } @@ -282,7 +282,7 @@ where where Src : core::convert::Into< String > { debug_assert!( self.storage.string_optional_1.is_none() ); - self.storage.string_optional_1 = Some( src.into() ); + self.storage.string_optional_1 = Some( ::core::convert::Into::into( src ) ); self } @@ -302,7 +302,7 @@ where ( None, None, - end.into(), + end, ) } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 0a4f9cc84e..14d8d636f7 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -503,7 +503,7 @@ fn field_name_map( field : &FormerField< '_ > ) -> syn::Ident /// Src : ::core::convert::Into< i32 >, /// { /// debug_assert!( self.int_1.is_none() ); -/// self.storage.int_1 = ::core::option::Option::Some( src.into() ); +/// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); /// self /// } /// @@ -514,7 +514,7 @@ fn field_name_map( field : &FormerField< '_ > ) -> syn::Ident /// Src : ::core::convert::Into< i32 >, /// { /// debug_assert!( self.int_1.is_none() ); -/// self.storage.int_1 = ::core::option::Option::Some( src.into() ); +/// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); /// self /// } /// ``` @@ -577,7 +577,7 @@ fn field_setter_map( field : &FormerField< '_ > ) -> Result< TokenStream > /// Src : ::core::convert::Into< i32 >, /// { /// debug_assert!( self.int_1.is_none() ); -/// self.storage.int_1 = ::core::option::Option::Some( src.into() ); +/// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); /// self /// } /// ``` @@ -605,7 +605,7 @@ fn field_setter where Src : ::core::convert::Into< #non_optional_type >, { debug_assert!( self.storage.#field_ident.is_none() ); - self.storage.#field_ident = ::core::option::Option::Some( src.into() ); + self.storage.#field_ident = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); self } } @@ -831,6 +831,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_definition = syn::Ident::new( &former_definition_name, struct_name.span() ); let former_definition_types_name = format!( "{}FormerDefinitionTypes", struct_name ); let former_definition_types = syn::Ident::new( &former_definition_types_name, struct_name.span() ); + let former_with_closure_name = format!( "{}FormerWithClosure", struct_name ); + let former_with_closure = syn::Ident::new( &former_with_closure_name, struct_name.span() ); /* generic parameters */ @@ -1008,6 +1010,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > type End = End; } + pub type #former_with_closure< Context, Formed > = + #former_definition< Context, Formed, former::FormingEndClosure< #former_definition_types< Context, Formed > > >; + // = storage #[ doc = "Container of a corresponding former." ] @@ -1116,15 +1121,13 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// /// Begin the process of forming. Expects context of forming to return it after forming. /// + // zzz : improve description #[ inline( always ) ] - pub fn begin + pub fn _begin_precise ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, - // mut storage : core::option::Option< #former_storage #generics_ty >, - // context : core::option::Option< __FormerContext >, - // on_end : __FormerEnd, ) -> Self { if storage.is_none() @@ -1139,6 +1142,54 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } + /// + /// Begin the process of forming. Expects context of forming to return it after forming. + /// + // zzz : improve description + #[ inline( always ) ] + pub fn begin + ( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : IntoEnd, + ) -> Self + where + IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some( on_end.into() ), + } + } + +// #[ inline( always ) ] +// pub fn begin< IntoEnd > +// ( +// mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, +// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, +// on_end : IntoEnd, +// ) -> Self +// where +// IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > +// { +// if storage.is_none() +// { +// storage = Some( core::default::Default::default() ); +// } +// Self +// { +// storage : storage.unwrap(), +// context, +// on_end : ::core::option::Option::Some( on_end.into() ), +// } +// } + /// /// End the process of forming returning original context of forming. /// @@ -1219,7 +1270,7 @@ where Src : Into< i32 >, { debug_assert!( self.age.is_none() ); - self.storage.age = ::core::option::Option::Some( src.into() ); + self.storage.age = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); self } } From 6849acf5faa16bf96eba85e563c00c0396079fbf Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 17:21:29 +0200 Subject: [PATCH 090/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 14d8d636f7..b31ce41d32 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -397,7 +397,7 @@ fn field_form_map( field : &FormerField< '_ > ) -> Result< TokenStream > { qt! { - ::core::option::Option::Some( ( #default_val ).into() ) + ::core::option::Option::Some( ::core::convert::Into::into( #default_val ) ) } } }; @@ -457,7 +457,7 @@ fn field_form_map( field : &FormerField< '_ > ) -> Result< TokenStream > { qt! { - ( #default_val ).into() + ::core::convert::Into::into( #default_val ) } } }; @@ -1164,7 +1164,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { storage : storage.unwrap(), context : context, - on_end : ::core::option::Option::Some( on_end.into() ), + on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), } } From be8af871067a769a5d437d42a2412959f4436408 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 17:44:24 +0200 Subject: [PATCH 091/533] former : experimenting --- .../inc/former_tests/a_primitives_manual.rs | 56 ++++++++-------- module/core/former/tests/inc/mod.rs | 2 +- module/core/former_meta/src/derive/former.rs | 67 ++++++++----------- 3 files changed, 57 insertions(+), 68 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index c2690cbe7e..72e549ff21 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -205,15 +205,33 @@ where return result; } + // zzz : update description #[ inline( always ) ] - pub fn begin< IntoEnd > + pub fn _new_precise( on_end : Definition::End ) -> Self + { + Self::_begin_precise( None, None, on_end ) + } + + #[ inline( always ) ] + pub fn new< IntoEnd >( end : IntoEnd ) -> Self + where + IntoEnd : Into< Definition::End >, + { + Self::begin + ( + None, + None, + end, + ) + } + + #[ inline( always ) ] + pub fn _begin_precise ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : IntoEnd, + on_end : < Definition as former::FormerDefinition >::End, ) -> Self - where - IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > { if storage.is_none() { @@ -223,17 +241,19 @@ where { storage : storage.unwrap(), context, - on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), + on_end : ::core::option::Option::Some( on_end ), } } #[ inline( always ) ] - pub fn _begin_precise + pub fn begin< IntoEnd > ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : < Definition as former::FormerDefinition >::End, + on_end : IntoEnd, ) -> Self + where + IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > { if storage.is_none() { @@ -243,7 +263,7 @@ where { storage : storage.unwrap(), context, - on_end : ::core::option::Option::Some( on_end ), + on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), } } @@ -286,26 +306,6 @@ where self } - // zzz : update description - #[ inline( always ) ] - pub fn _new_precise( on_end : Definition::End ) -> Self - { - Self::_begin_precise( None, None, on_end ) - } - - #[ inline( always ) ] - pub fn new< IntoEnd >( end : IntoEnd ) -> Self - where - IntoEnd : Into< Definition::End >, - { - Self::begin - ( - None, - None, - end, - ) - } - } impl< Definition > Struct1Former< Definition > diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index b25ec0ee45..69a9418704 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -18,7 +18,7 @@ mod former_tests mod a_primitives_manual; // mod a_primitives_expanded; - // mod a_primitives; + mod a_primitives; // mod a_containers_without_subformer_manual; // mod a_containers_without_subformer; // #[ cfg( not( feature = "no_std" ) ) ] diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index b31ce41d32..938d9e28e6 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1118,6 +1118,33 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #perform } + /// + /// Construct new instance of former with default parameters. + /// + // zzz : improve description + #[ inline( always ) ] + pub fn _new_precise( on_end : Definition::End ) -> Self + { + Self::begin( None, None, on_end ) + } + + /// + /// Construct new instance of former with default parameters. + /// + // zzz : improve description + #[ inline( always ) ] + pub fn new< IntoEnd >( end : IntoEnd ) -> Self + where + IntoEnd : Into< Definition::End >, + { + Self::begin + ( + None, + None, + end, + ) + } + /// /// Begin the process of forming. Expects context of forming to return it after forming. /// @@ -1147,7 +1174,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// // zzz : improve description #[ inline( always ) ] - pub fn begin + pub fn begin< IntoEnd > ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -1168,28 +1195,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } -// #[ inline( always ) ] -// pub fn begin< IntoEnd > -// ( -// mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, -// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, -// on_end : IntoEnd, -// ) -> Self -// where -// IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > -// { -// if storage.is_none() -// { -// storage = Some( core::default::Default::default() ); -// } -// Self -// { -// storage : storage.unwrap(), -// context, -// on_end : ::core::option::Option::Some( on_end.into() ), -// } -// } - /// /// End the process of forming returning original context of forming. /// @@ -1233,22 +1238,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } - #[ automatically_derived ] - impl #generics_impl #former < #generics_params > - #generics_where - { - - /// - /// Construct new instance of former with default parameters. - /// - #[ inline( always ) ] - pub fn new( on_end : < #former_definition as former::FormerDefinition >::End ) -> Self - { - Self::begin( None, None, on_end ) - } - - } - }; if has_debug From baf94c4d17d4d5fa1739cc1950c35d83f609f8d7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 17:47:29 +0200 Subject: [PATCH 092/533] former : experimenting --- .../inc/former_tests/only_test/containers_without_subformer.rs | 2 +- module/core/former/tests/inc/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs index e0d058ea4a..990ae7e8cf 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs @@ -19,7 +19,7 @@ tests_impls! a_id!( former.storage.hashset_strings_1, None ); a_id!( former.context, None ); a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); - let former2 = Struct1Former::< Struct1, the_module::ReturnPreformed >::new(); + let former2 = Struct1Former::< Struct1FormerDefinition >::new( the_module::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 69a9418704..49fe32b4c7 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -20,7 +20,7 @@ mod former_tests // mod a_primitives_expanded; mod a_primitives; // mod a_containers_without_subformer_manual; - // mod a_containers_without_subformer; + mod a_containers_without_subformer; // #[ cfg( not( feature = "no_std" ) ) ] // mod a_containers_with_subformer_manual; // #[ cfg( not( feature = "no_std" ) ) ] From 7eceedbcfab8ac0a89bfdadf9378e60e86bd3821 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 19:09:22 +0200 Subject: [PATCH 093/533] former : experimenting --- .../a_containers_with_subformer.rs | 4 +- .../a_containers_with_subformer_2_manual.rs | 299 ++++++++++++ .../a_containers_with_subformer_manual.rs | 443 +++++++++++------- .../a_containers_without_subformer_manual.rs | 178 ------- module/core/former/tests/inc/mod.rs | 11 +- 5 files changed, 575 insertions(+), 360 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs delete mode 100644 module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 6a1cbc6892..53d8f86ad4 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -5,6 +5,7 @@ use super::*; // use std::collections::HashSet; #[ derive( Debug, PartialEq, the_module::Former ) ] +#[ debug ] pub struct Struct1 { #[ subformer( the_module::VectorSubformer ) ] @@ -15,4 +16,5 @@ pub struct Struct1 hashset_strings_1 : std::collections::HashSet< String >, } -include!( "./only_test/containers_with_subformer.rs" ); +// include!( "./only_test/containers_with_subformer.rs" ); +// xxx : uncomment \ No newline at end of file diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs new file mode 100644 index 0000000000..bd65a36594 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs @@ -0,0 +1,299 @@ +#[ allow( unused_imports ) ] +use super::*; + +// xxx : take care + +#[ derive( Debug, PartialEq ) ] +pub struct Struct1 +{ + vec_1 : Vec< String >, + hashmap_strings_1 : std::collections::HashMap< String, String >, + hashset_strings_1 : std::collections::HashSet< String >, +} + +// = formed + +impl Struct1 +{ + pub fn former() -> Struct1Former< Struct1, the_module::ReturnPreformed > + { + Struct1Former::< Struct1, the_module::ReturnPreformed >::new() + } +} + +// = storage + +// generated by former +pub struct Struct1FormerStorage +{ + pub vec_1 : ::core::option::Option< Vec< String > >, + pub hashmap_strings_1 : ::core::option::Option< std::collections::HashMap< String, String > >, + pub hashset_strings_1 : ::core::option::Option< std::collections::HashSet< String > >, +} + +impl Default for Struct1FormerStorage +{ + + #[ inline( always ) ] + fn default() -> Self + { + Self + { + vec_1 : None, + hashmap_strings_1 : None, + hashset_strings_1 : None, + } + } + +} + +// = former + +pub struct Struct1Former +< + Context = Struct1, + End = the_module::ReturnPreformed, +> +where + End : the_module::FormingEnd< Struct1, Context >, +{ + storage : Struct1FormerStorage, + context : ::core::option::Option< Context >, + on_end : ::core::option::Option< End >, +} + +impl< Context, End > Struct1Former< Context, End > +where + End : the_module::FormingEnd< Struct1, Context >, +{ + + #[ inline( always ) ] + fn form( mut self ) -> Struct1 + { + + let vec_1 = if self.storage.vec_1.is_some() + { + self.storage.vec_1.take().unwrap() + } + else + { + let val : Vec< String > = Default::default(); + val + }; + + let hashmap_strings_1 = if self.storage.hashmap_strings_1.is_some() + { + self.storage.hashmap_strings_1.take().unwrap() + } + else + { + let val : std::collections::HashMap< String, String > = Default::default(); + val + }; + + let hashset_strings_1 = if self.storage.hashset_strings_1.is_some() + { + self.storage.hashset_strings_1.take().unwrap() + } + else + { + let val : std::collections::HashSet< String > = Default::default(); + val + }; + + Struct1 + { + vec_1, + hashmap_strings_1, + hashset_strings_1, + } + + } + + #[ inline( always ) ] + pub fn perform(self) -> Struct1 + { + let result = self.form(); + return result; + } + + // #[ inline( always ) ] + // pub fn new() -> Struct1Former + // { + // Struct1Former:: + // < + // Struct1, + // the_module::ReturnPreformed, + // >::begin(None, the_module::ReturnPreformed) + // } + + #[ inline( always ) ] + pub fn begin + ( + mut storage : ::core::option::Option< Struct1FormerStorage >, + context : ::core::option::Option< Context >, + on_end : End, + ) -> Self + { + if storage.is_none() + { + storage = Some( Default::default() ); + } + Self + { + storage : storage.unwrap(), + context, + on_end : ::core::option::Option::Some( on_end ), + } + } + + #[ inline( always ) ] + pub fn end( mut self ) -> Context + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + let formed = self.form(); + on_end.call( formed, context ) + } + + #[ inline( always ) ] + pub fn __vec_1< Former2 >( self ) -> + Former2 + where + Former2 : former::FormerBegin + < + Vec< String >, + Vec< String >, + Self, End = former::FormingEndClosure< Vec< String >, Self >, + >, + { + let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.vec_1 + { + former::ContainerAssign::assign( field, formed ); + } + else + { + super_former.storage.vec_1 = Some( formed ); + } + super_former + }; + Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + } + + // xxx2 : continue + pub fn vec_1( self ) -> the_module::VectorSubformer + < + String, + Vec< String >, + Self, + impl the_module::FormingEnd< Vec< String >, Self >, + > + { + self.__vec_1::< the_module::VectorSubformer::< _, _, _, _ > >() + } + + // pub fn vec_1( mut self ) -> the_module::VectorSubformer + // < + // String, + // Vec< String >, + // Self, + // impl the_module::FormingEnd< Vec< String >, Self >, + // > + // { + // let formed = self.storage.vec_1.take(); + // let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self + // { + // let mut super_former = super_former.unwrap(); + // super_former.storage.vec_1 = Some( formed ); + // super_former + // }; + // the_module::VectorSubformer::< String, Vec< String >, Self, _ >::begin( Some( self ), formed, on_end ) + // } + + pub fn hashmap_strings_1( mut self ) -> the_module::HashMapSubformer + < + String, + String, + std::collections::HashMap< String, String >, + Self, + impl the_module::FormingEnd< std::collections::HashMap< String, String >, Self >, + > + { + let formed = self.storage.hashmap_strings_1.take(); + let on_end = | formed : std::collections::HashMap< String, String >, super_former : ::core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + super_former.storage.hashmap_strings_1 = Some( formed ); + super_former + }; + the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) + } + + pub fn hashset_strings_1( mut self ) -> the_module::HashSetSubformer + < + String, + std::collections::HashSet< String >, + Self, + impl the_module::FormingEnd< std::collections::HashSet< String >, Self >, + > + { + let formed = self.storage.hashset_strings_1.take(); + let on_end = | formed : std::collections::HashSet< String >, super_former : ::core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + super_former.storage.hashset_strings_1 = Some( formed ); + super_former + }; + the_module::HashSetSubformer::begin( formed, Some( self ), on_end ) + } + +} + +// impl< Context, End > Struct1Former< Context, End > +// where +// End: the_module::FormingEnd, + +impl Struct1Former< Struct1, the_module::ReturnPreformed > +{ + + #[ inline( always ) ] + pub fn new() -> Self + { + Self::begin( None, None, the_module::ReturnPreformed ) + } + +} + +// + +// impl< Context, End > Struct1Former< Context, End > +// where +// End : the_module::FormingEnd< Struct1, Context >, + +impl< Context, End > former::FormerBegin< Struct1FormerStorage, Struct1, Context > +for Struct1Former< Context, End > +where + End : the_module::FormingEnd< Struct1, Context >, +{ + type End = End; + + #[ inline( always ) ] + fn _begin + ( + storage : core::option::Option< Struct1FormerStorage >, /* xxx2 : that should be storage */ + context : core::option::Option< Context >, + on_end : End, + ) -> Self + { + debug_assert!( storage.is_none() ); + Self::begin( None, context, on_end ) + } + +} + +// + +include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 56309292bf..bb6cb149c3 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -9,289 +9,382 @@ pub struct Struct1 hashset_strings_1 : std::collections::HashSet< String >, } -// = formed +// = generated +#[ automatically_derived ] impl Struct1 { - pub fn former() -> Struct1Former< Struct1, the_module::ReturnPreformed > + #[ doc = r"" ] + #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn former() -> Struct1Former< > { - Struct1Former::< Struct1, the_module::ReturnPreformed >::new() + Struct1Former::<>::new( the_module::ReturnPreformed ) } } -// = storage +#[ derive( Debug ) ] +pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > +{ + _phantom : core::marker::PhantomData< ( Context, Formed ) >, +} -// generated by former -pub struct Struct1FormerStorage +impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > { - pub vec_1 : ::core::option::Option< Vec< String > >, - pub hashmap_strings_1 : ::core::option::Option< std::collections::HashMap< String, String > >, - pub hashset_strings_1 : ::core::option::Option< std::collections::HashSet< String > >, + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } } -impl Default for Struct1FormerStorage +#[ derive( Debug ) ] +pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > { + _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, +} - #[ inline( always ) ] +impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > +{ fn default() -> Self { Self { - vec_1 : None, - hashmap_strings_1 : None, - hashset_strings_1 : None, + _phantom : core::marker::PhantomData, } } - } -// = former +impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > +{ + type Storage = Struct1FormerStorage; + type Formed = Formed; + type Context = Context; +} -pub struct Struct1Former -< - Context = Struct1, - End = the_module::ReturnPreformed, -> +impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > where - End : the_module::FormingEnd< Struct1, Context >, + End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, { - storage : Struct1FormerStorage, - context : ::core::option::Option< Context >, - on_end : ::core::option::Option< End >, + type Types = Struct1FormerDefinitionTypes< Context, Formed >; + type End = End; } -impl< Context, End > Struct1Former< Context, End > -where - End : the_module::FormingEnd< Struct1, Context >, +pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; + +#[ doc = "Container of a corresponding former." ] +pub struct Struct1FormerStorage { + #[ doc = r" A field" ] + pub vec_1 : ::core::option::Option< Vec< String > >, + #[ doc = r" A field" ] + pub hashmap_strings_1 : ::core::option::Option< std::collections::HashMap< String, String > >, + + #[ doc = r" A field" ] + pub hashset_strings_1 : ::core::option::Option< std::collections::HashSet< String > >, +} + +impl ::core::default::Default for Struct1FormerStorage +{ #[ inline( always ) ] - fn form( mut self ) -> Struct1 + fn default() -> Self { + Self + { + vec_1 : ::core::option::Option::None, + hashmap_strings_1 : ::core::option::Option::None, + hashset_strings_1 : ::core::option::Option::None, + } + } +} + +impl former::Storage for Struct1FormerStorage +{ + type Formed = Struct1; +} - let vec_1 = if self.storage.vec_1.is_some() +impl former::StoragePreform for Struct1FormerStorage +{ + fn preform( mut self ) -> < Self as former::Storage >::Formed + { + let vec_1 = if self.vec_1.is_some() { - self.storage.vec_1.take().unwrap() + self.vec_1.take().unwrap() } else { - let val : Vec< String > = Default::default(); - val + { + trait MaybeDefault< T > + { + fn maybe_default( self : &Self ) -> T + { + panic!( "Field 'vec_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< Vec< String > > ).maybe_default() + } }; - - let hashmap_strings_1 = if self.storage.hashmap_strings_1.is_some() + let hashmap_strings_1 = if self.hashmap_strings_1.is_some() { - self.storage.hashmap_strings_1.take().unwrap() + self.hashmap_strings_1.take().unwrap() } else { - let val : std::collections::HashMap< String, String > = Default::default(); - val + { + trait MaybeDefault< T > + { + fn maybe_default( self : &Self ) -> T + { + panic!( "Field 'hashmap_strings_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< std::collections::HashMap< String, String > > ).maybe_default() + } }; - - let hashset_strings_1 = if self.storage.hashset_strings_1.is_some() + let hashset_strings_1 = if self.hashset_strings_1.is_some() { - self.storage.hashset_strings_1.take().unwrap() + self.hashset_strings_1.take().unwrap() } else { - let val : std::collections::HashSet< String > = Default::default(); - val + { + trait MaybeDefault< T > + { + fn maybe_default( self : &Self ) -> T + { + panic!( "Field 'hashset_strings_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< std::collections::HashSet< String > > ).maybe_default() + } }; - - Struct1 + let result = Struct1 { vec_1, hashmap_strings_1, hashset_strings_1, - } - + }; + return result; } +} +#[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[ default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] +pub struct Struct1Former< Definition = Struct1FormerDefinition > +where + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +{ + storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : core::option::Option< Definition::End >, +} + +#[ automatically_derived ] +impl< Definition > Struct1Former< Definition > +where + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +{ + #[ doc = r"" ] + #[ doc = r" Finish setting options and call perform on formed entity." ] + #[ doc = r"" ] + #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] + #[ doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str ) ]` returns `&str`." ] + #[ doc = r"" ] #[ inline( always ) ] - pub fn perform(self) -> Struct1 + pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { let result = self.form(); return result; } - // #[ inline( always ) ] - // pub fn new() -> Struct1Former - // { - // Struct1Former:: - // < - // Struct1, - // the_module::ReturnPreformed, - // >::begin(None, the_module::ReturnPreformed) - // } + #[ doc = r"" ] + #[ doc = r" Construct new instance of former with default parameters." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn _new_precise( on_end : Definition::End ) -> Self + { + Self::begin( None, None, on_end ) + } + + #[ doc = r"" ] + #[ doc = r" Construct new instance of former with default parameters." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn new< IntoEnd >( end : IntoEnd ) -> Self + where + IntoEnd : Into< Definition::End >, + { + Self::begin( None, None, end, ) + } + #[ doc = r"" ] + #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] + #[ doc = r"" ] #[ inline( always ) ] - pub fn begin - ( - mut storage : ::core::option::Option< Struct1FormerStorage >, - context : ::core::option::Option< Context >, - on_end : End, + pub fn _begin_precise( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : < Definition as former::FormerDefinition >::End, ) -> Self { if storage.is_none() { - storage = Some( Default::default() ); + storage = Some( ::core::default::Default::default() ); } Self { storage : storage.unwrap(), - context, + context : context, on_end : ::core::option::Option::Some( on_end ), } } + #[ doc = r"" ] + #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] + #[ doc = r"" ] #[ inline( always ) ] - pub fn end( mut self ) -> Context + pub fn begin< IntoEnd >( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : IntoEnd, + ) -> Self + where + IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), + } } + #[ doc = r"" ] + #[ doc = r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] #[ inline( always ) ] - pub fn __vec_1< Former2 >( self ) -> - Former2 - where - Former2 : former::FormerBegin - < - Vec< String >, - Vec< String >, - Self, End = former::FormingEndClosure< Vec< String >, Self >, - >, + pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { - let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.vec_1 - { - former::ContainerAssign::assign( field, formed ); - } - else - { - super_former.storage.vec_1 = Some( formed ); - } - super_former - }; - Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + self.end() } - // xxx2 : continue - pub fn vec_1( self ) -> the_module::VectorSubformer - < - String, - Vec< String >, - Self, - impl the_module::FormingEnd< Vec< String >, Self >, - > + #[ doc = r"" ] + #[ doc = r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { - self.__vec_1::< the_module::VectorSubformer::< _, _, _, _ > >() + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) } - // pub fn vec_1( mut self ) -> the_module::VectorSubformer - // < - // String, - // Vec< String >, - // Self, - // impl the_module::FormingEnd< Vec< String >, Self >, - // > + // #[ doc = "Subformer setter for the 'vec_1' field." ] + // #[ inline ] + // pub fn vec_1( mut self ) -> the_module::VectorSubformer< String, Vec< String >, Self, impl Fn( Vec< String >, core::option::Option< Self > ) -> Self, > // { // let formed = self.storage.vec_1.take(); - // let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self + // let on_end = | formed : Vec< String >, former : core::option::Option< Self > | -> Self // { - // let mut super_former = super_former.unwrap(); - // super_former.storage.vec_1 = Some( formed ); - // super_former + // let mut former = former.unwrap(); + // former.storage.vec_1 = Some( formed ); + // former // }; - // the_module::VectorSubformer::< String, Vec< String >, Self, _ >::begin( Some( self ), formed, on_end ) + // the_module::VectorSubformer::begin( formed, Some( self ), on_end ) // } - pub fn hashmap_strings_1( mut self ) -> the_module::HashMapSubformer - < - String, - String, - std::collections::HashMap< String, String >, - Self, - impl the_module::FormingEnd< std::collections::HashMap< String, String >, Self >, - > + pub fn vec_1( self ) -> + former::VectorSubformer::< String, (), Vec< String >, former::ReturnStorage > + // former::VectorSubformer + // < + // String, + // Vec< String >, + // Self, + // impl former::FormingEnd< Struct1FormerDefinitionTypes >, + // > + { + self.__vec_1::< former::VectorSubformer::< _, _, _, _ > >() + } + + #[ doc = "Subformer setter for the 'hashmap_strings_1' field." ] + #[ inline ] + pub fn hashmap_strings_1( mut self ) -> the_module::HashMapSubformer< String, String, std::collections::HashMap< String, String >, Self, impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self, > { let formed = self.storage.hashmap_strings_1.take(); - let on_end = | formed : std::collections::HashMap< String, String >, super_former : ::core::option::Option< Self > | -> Self + let on_end = | formed : std::collections::HashMap< String, String >, former : core::option::Option< Self > | -> Self { - let mut super_former = super_former.unwrap(); - super_former.storage.hashmap_strings_1 = Some( formed ); - super_former + let mut former = former.unwrap(); + former.storage.hashmap_strings_1 = Some( formed ); + former }; the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) } - pub fn hashset_strings_1( mut self ) -> the_module::HashSetSubformer - < - String, - std::collections::HashSet< String >, - Self, - impl the_module::FormingEnd< std::collections::HashSet< String >, Self >, - > + #[ doc = "Subformer setter for the 'hashset_strings_1' field." ] + #[ inline ] + pub fn hashset_strings_1( mut self ) -> the_module::HashSetSubformer< String, std::collections::HashSet< String >, Self, impl Fn( std::collections::HashSet< String >, core::option::Option< Self > ) -> Self, > { let formed = self.storage.hashset_strings_1.take(); - let on_end = | formed : std::collections::HashSet< String >, super_former : ::core::option::Option< Self > | -> Self + let on_end = | formed : std::collections::HashSet< String >, former : core::option::Option< Self > | -> Self { - let mut super_former = super_former.unwrap(); - super_former.storage.hashset_strings_1 = Some( formed ); - super_former + let mut former = former.unwrap(); + former.storage.hashset_strings_1 = Some( formed ); + former }; the_module::HashSetSubformer::begin( formed, Some( self ), on_end ) } - -} - -// impl< Context, End > Struct1Former< Context, End > -// where -// End: the_module::FormingEnd, - -impl Struct1Former< Struct1, the_module::ReturnPreformed > -{ - - #[ inline( always ) ] - pub fn new() -> Self - { - Self::begin( None, None, the_module::ReturnPreformed ) - } - } -// - -// impl< Context, End > Struct1Former< Context, End > -// where -// End : the_module::FormingEnd< Struct1, Context >, - -impl< Context, End > former::FormerBegin< Struct1FormerStorage, Struct1, Context > -for Struct1Former< Context, End > +impl< Definition > Struct1Former< Definition > where - End : the_module::FormingEnd< Struct1, Context >, + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, { - type End = End; - - #[ inline( always ) ] - fn _begin - ( - storage : core::option::Option< Struct1FormerStorage >, /* xxx2 : that should be storage */ - context : core::option::Option< Context >, - on_end : End, - ) -> Self + pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { - debug_assert!( storage.is_none() ); - Self::begin( None, context, on_end ) + former::StoragePreform::preform( self.storage ) } - } -// +// = end of generated -include!( "./only_test/containers_with_subformer.rs" ); +// include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs deleted file mode 100644 index c419520a98..0000000000 --- a/module/core/former/tests/inc/former_tests/a_containers_without_subformer_manual.rs +++ /dev/null @@ -1,178 +0,0 @@ -#[ allow( unused_imports ) ] -use super::*; - -#[ derive( Debug, PartialEq ) ] -pub struct Struct1 -{ - vec_1 : Vec< String >, - hashmap_strings_1 : std::collections::HashMap< String, String >, - hashset_strings_1 : std::collections::HashSet< String >, -} - -// - -impl Struct1 -{ - pub fn former() -> Struct1Former< Struct1, the_module::ReturnPreformed > - { - Struct1Former::< Struct1, the_module::ReturnPreformed >::new() - } -} - -// generated by former -pub struct Struct1FormerStorage -{ - pub vec_1 : core::option::Option< Vec< String > >, - pub hashmap_strings_1 : core::option::Option< std::collections::HashMap< String, String > >, - pub hashset_strings_1 : core::option::Option< std::collections::HashSet< String > >, -} - -impl Default for Struct1FormerStorage -{ - - #[ inline( always ) ] - fn default() -> Self - { - Self - { - vec_1 : None, - hashmap_strings_1 : None, - hashset_strings_1 : None, - } - } - -} - -// - -pub struct Struct1Former -< - __FormerContext = Struct1, - __FormerEnd = the_module::ReturnPreformed, -> -where - __FormerEnd : the_module::FormingEnd< Struct1, __FormerContext >, -{ - storage : Struct1FormerStorage, - context : core::option::Option< __FormerContext >, - on_end : core::option::Option< __FormerEnd >, -} - -impl< __FormerContext, __FormerEnd > Struct1Former< __FormerContext, __FormerEnd > -where - __FormerEnd: the_module::FormingEnd, -{ - - #[ inline( always ) ] - fn form( mut self ) -> Struct1 - { - - let vec_1 = if self.storage.vec_1.is_some() - { - self.storage.vec_1.take().unwrap() - } - else - { - let val : Vec< String > = Default::default(); - val - }; - - let hashmap_strings_1 = if self.storage.hashmap_strings_1.is_some() - { - self.storage.hashmap_strings_1.take().unwrap() - } - else - { - let val : std::collections::HashMap< String, String > = Default::default(); - val - }; - - let hashset_strings_1 = if self.storage.hashset_strings_1.is_some() - { - self.storage.hashset_strings_1.take().unwrap() - } - else - { - let val : std::collections::HashSet< String > = Default::default(); - val - }; - - Struct1 - { - vec_1, - hashmap_strings_1, - hashset_strings_1, - } - - } - - #[ inline( always ) ] - pub fn perform(self) -> Struct1 - { - let result = self.form(); - return result; - } - - #[ inline( always ) ] - pub fn new() -> Struct1Former - { - Struct1Former:: - < - Struct1, - the_module::ReturnPreformed, - >::begin(None, the_module::ReturnPreformed) - } - - #[ inline( always ) ] - pub fn begin - ( - context : core::option::Option< __FormerContext >, - on_end : __FormerEnd, - ) -> Self - { - Self - { - storage : core::default::Default::default(), - context : context, - on_end : ::core::option::Option::Some( on_end ), - } - } - - #[ inline( always ) ] - pub fn end( mut self ) -> __FormerContext - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) - } - - pub fn vec_1< Src >( mut self, src : Src ) -> Self - where Src : core::convert::Into< Vec< String > > - { - debug_assert!( self.storage.vec_1.is_none() ); - self.storage.vec_1 = Some( src.into() ); - self - } - - pub fn hashmap_strings_1< Src >( mut self, src : Src ) -> Self - where Src : core::convert::Into< std::collections::HashMap< String, String > > - { - debug_assert!( self.storage.hashmap_strings_1.is_none() ); - self.storage.hashmap_strings_1 = Some( src.into() ); - self - } - - pub fn hashset_strings_1< Src >( mut self, src : Src ) -> Self - where Src : core::convert::Into< std::collections::HashSet< String > > - { - debug_assert!( self.storage.hashset_strings_1.is_none() ); - self.storage.hashset_strings_1 = Some( src.into() ); - self - } - -} - -// - -include!( "./only_test/containers_without_subformer.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 49fe32b4c7..d9541ddf2c 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -19,13 +19,12 @@ mod former_tests mod a_primitives_manual; // mod a_primitives_expanded; mod a_primitives; - // mod a_containers_without_subformer_manual; mod a_containers_without_subformer; -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer_manual; -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer ; -// + // #[ cfg( not( feature = "no_std" ) ) ] + // mod a_containers_with_subformer_manual; + // #[ cfg( not( feature = "no_std" ) ) ] + // mod a_containers_with_subformer ; + // mod attribute_default_container; // mod attribute_default_primitive; // mod attribute_perform; From 97e0d2c5cf687d9296ad817e4aa764e209eafc80 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 21:28:17 +0200 Subject: [PATCH 094/533] former : experimenting --- .../a_containers_with_subformer_2_manual.rs | 3 +- .../a_containers_with_subformer_manual.rs | 144 +++++++++++++----- module/core/former/tests/inc/mod.rs | 4 +- module/core/former_meta/src/derive/former.rs | 4 +- 4 files changed, 115 insertions(+), 40 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs index bd65a36594..b080a71ca2 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs @@ -157,8 +157,7 @@ where } #[ inline( always ) ] - pub fn __vec_1< Former2 >( self ) -> - Former2 + pub fn __vec_1< Former2 >( self ) -> Former2 where Former2 : former::FormerBegin < diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index bb6cb149c3..699ef902b5 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -331,46 +331,92 @@ where // the_module::VectorSubformer::begin( formed, Some( self ), on_end ) // } - pub fn vec_1( self ) -> - former::VectorSubformer::< String, (), Vec< String >, former::ReturnStorage > - // former::VectorSubformer + #[ inline( always ) ] + pub fn vec_1_set< Former2 >( self ) -> Former2 + where + Former2 : former::FormerBegin + < + former::VectorDefinition + < + String, + Self, + Self, + __Vec1End, + // impl former::FormingEnd::< former::VectorDefinition< String, Self, Self, former::NoEnd > >, + // former::FormingEndClosure< former::VectorDefinition< String, Self, Self, former::NoEnd > >, + > + >, + { + + // let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self + // { + // let mut super_former = super_former.unwrap(); + // if let Some( ref mut field ) = super_former.storage.vec_1 + // { + // former::ContainerAssign::assign( field, formed ); + // } + // else + // { + // super_former.storage.vec_1 = Some( formed ); + // } + // super_former + // }; + + // Definition : former::FormerDefinition, + // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + + Former2::_begin( None, Some( self ), __Vec1End ) + // Former2::_begin( None, Some( self ), on_end ) + // Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + } + + // pub fn vec_1( self ) -> + // former::VectorSubformer:: // < // String, - // Vec< String >, // Self, - // impl former::FormingEnd< Struct1FormerDefinitionTypes >, + // Self, + // former::FormingEndClosure< former::VectorDefinition< String, Self, Self, former::NoEnd > >, // > - { - self.__vec_1::< former::VectorSubformer::< _, _, _, _ > >() - } + // { + // self.vec_1_set::< former::VectorSubformer:: + // < + // String, + // Self, + // Self, + // former::FormingEndClosure< former::VectorDefinition< String, Self, Self, former::NoEnd > > >, + // >() + // } - #[ doc = "Subformer setter for the 'hashmap_strings_1' field." ] - #[ inline ] - pub fn hashmap_strings_1( mut self ) -> the_module::HashMapSubformer< String, String, std::collections::HashMap< String, String >, Self, impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self, > - { - let formed = self.storage.hashmap_strings_1.take(); - let on_end = | formed : std::collections::HashMap< String, String >, former : core::option::Option< Self > | -> Self - { - let mut former = former.unwrap(); - former.storage.hashmap_strings_1 = Some( formed ); - former - }; - the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) - } +// #[ doc = "Subformer setter for the 'hashmap_strings_1' field." ] +// #[ inline ] +// pub fn hashmap_strings_1( mut self ) -> the_module::HashMapSubformer< String, String, std::collections::HashMap< String, String >, Self, impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self, > +// { +// let formed = self.storage.hashmap_strings_1.take(); +// let on_end = | formed : std::collections::HashMap< String, String >, former : core::option::Option< Self > | -> Self +// { +// let mut former = former.unwrap(); +// former.storage.hashmap_strings_1 = Some( formed ); +// former +// }; +// the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) +// } +// +// #[ doc = "Subformer setter for the 'hashset_strings_1' field." ] +// #[ inline ] +// pub fn hashset_strings_1( mut self ) -> the_module::HashSetSubformer< String, std::collections::HashSet< String >, Self, impl Fn( std::collections::HashSet< String >, core::option::Option< Self > ) -> Self, > +// { +// let formed = self.storage.hashset_strings_1.take(); +// let on_end = | formed : std::collections::HashSet< String >, former : core::option::Option< Self > | -> Self +// { +// let mut former = former.unwrap(); +// former.storage.hashset_strings_1 = Some( formed ); +// former +// }; +// the_module::HashSetSubformer::begin( formed, Some( self ), on_end ) +// } - #[ doc = "Subformer setter for the 'hashset_strings_1' field." ] - #[ inline ] - pub fn hashset_strings_1( mut self ) -> the_module::HashSetSubformer< String, std::collections::HashSet< String >, Self, impl Fn( std::collections::HashSet< String >, core::option::Option< Self > ) -> Self, > - { - let formed = self.storage.hashset_strings_1.take(); - let on_end = | formed : std::collections::HashSet< String >, former : core::option::Option< Self > | -> Self - { - let mut former = former.unwrap(); - former.storage.hashset_strings_1 = Some( formed ); - former - }; - the_module::HashSetSubformer::begin( formed, Some( self ), on_end ) - } } impl< Definition > Struct1Former< Definition > @@ -385,6 +431,36 @@ where } } +struct __Vec1End; +#[ automatically_derived ] +impl< Definition > former::FormingEnd +< + former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, +> +for __Vec1End +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = Struct1FormerStorage + >, + // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +{ + 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 + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.vec_1 = Some( storage ); + } + super_former + } +} + // = end of generated // include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index d9541ddf2c..0483e2a4eb 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -20,8 +20,8 @@ mod former_tests // mod a_primitives_expanded; mod a_primitives; mod a_containers_without_subformer; - // #[ cfg( not( feature = "no_std" ) ) ] - // mod a_containers_with_subformer_manual; + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer_manual; // #[ cfg( not( feature = "no_std" ) ) ] // mod a_containers_with_subformer ; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 938d9e28e6..1025c4c795 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -858,8 +858,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { where Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, }; // zzz : write helper to fix bug with where let generics_of_former = generics::merge( &generics, &extra_generics ); @@ -1227,8 +1227,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl< Definition > #former< Definition > where Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty, Formed = #struct_name #generics_ty >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed From 971847b21b6937a3665c40d1d6df0b20de2ec543 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 30 Mar 2024 21:33:41 +0200 Subject: [PATCH 095/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 61 ++++++------------- 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 699ef902b5..978bacf9a8 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -342,52 +342,29 @@ where Self, Self, __Vec1End, - // impl former::FormingEnd::< former::VectorDefinition< String, Self, Self, former::NoEnd > >, - // former::FormingEndClosure< former::VectorDefinition< String, Self, Self, former::NoEnd > >, > >, { - - // let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self - // { - // let mut super_former = super_former.unwrap(); - // if let Some( ref mut field ) = super_former.storage.vec_1 - // { - // former::ContainerAssign::assign( field, formed ); - // } - // else - // { - // super_former.storage.vec_1 = Some( formed ); - // } - // super_former - // }; - - // Definition : former::FormerDefinition, - // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, - Former2::_begin( None, Some( self ), __Vec1End ) - // Former2::_begin( None, Some( self ), on_end ) - // Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) } - // pub fn vec_1( self ) -> - // former::VectorSubformer:: - // < - // String, - // Self, - // Self, - // former::FormingEndClosure< former::VectorDefinition< String, Self, Self, former::NoEnd > >, - // > - // { - // self.vec_1_set::< former::VectorSubformer:: - // < - // String, - // Self, - // Self, - // former::FormingEndClosure< former::VectorDefinition< String, Self, Self, former::NoEnd > > >, - // >() - // } + pub fn vec_1( self ) -> + former::VectorSubformer:: + < + String, + Self, + Self, + __Vec1End, + > + { + self.vec_1_set::< former::VectorSubformer:: + < + String, + Self, + Self, + __Vec1End, + > >() + } // #[ doc = "Subformer setter for the 'hashmap_strings_1' field." ] // #[ inline ] @@ -431,7 +408,7 @@ where } } -struct __Vec1End; +pub struct __Vec1End; #[ automatically_derived ] impl< Definition > former::FormingEnd < @@ -444,8 +421,8 @@ where < Storage = Struct1FormerStorage >, - // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, { + #[ inline( always ) ] fn call( &self, storage : Vec< String >, super_former : Option< Struct1Former< Definition > > ) -> Struct1Former< Definition > { let mut super_former = super_former.unwrap(); From 6328c607762a37a831195f9f528693899c36dc83 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 31 Mar 2024 00:33:10 +0200 Subject: [PATCH 096/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 978bacf9a8..4920efd0c4 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -14,9 +14,6 @@ pub struct Struct1 #[ automatically_derived ] impl Struct1 { - #[ doc = r"" ] - #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] - #[ doc = r"" ] #[ inline( always ) ] pub fn former() -> Struct1Former< > { @@ -408,6 +405,8 @@ where } } +// zzz : description +/// Return original former after subformer for vec1 is done. pub struct __Vec1End; #[ automatically_derived ] impl< Definition > former::FormingEnd @@ -438,6 +437,38 @@ where } } +// zzz : description +/// Return original former after subformer for vec1 is done. +pub struct __HashMapEnd; +#[ automatically_derived ] +impl< Definition > former::FormingEnd +< + former::HashMapDefinition< String, String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, +> +for __HashMapEnd +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = Struct1FormerStorage + >, +{ + #[ inline( always ) ] + fn call( &self, storage : std::collections::HashMap< String, String >, super_former : Option< Struct1Former< Definition > > ) -> Struct1Former< Definition > + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.hashmap_strings_1 + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.hashmap_strings_1 = Some( storage ); + } + super_former + } +} + // = end of generated // include!( "./only_test/containers_with_subformer.rs" ); From 0b8013702e7a6af44f0194e13a71759115125643 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 31 Mar 2024 01:04:47 +0200 Subject: [PATCH 097/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 52 +++++++++++++++---- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 4920efd0c4..d4d3652349 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -338,11 +338,11 @@ where String, Self, Self, - __Vec1End, + __vec1_end, > >, { - Former2::_begin( None, Some( self ), __Vec1End ) + Former2::_begin( None, Some( self ), __vec1_end ) } pub fn vec_1( self ) -> @@ -351,7 +351,7 @@ where String, Self, Self, - __Vec1End, + __vec1_end, > { self.vec_1_set::< former::VectorSubformer:: @@ -359,7 +359,7 @@ where String, Self, Self, - __Vec1End, + __vec1_end, > >() } @@ -406,14 +406,14 @@ where } // zzz : description -/// Return original former after subformer for vec1 is done. -pub struct __Vec1End; +/// Return original former after subformer for `vec_1` is done. +pub struct __vec1_end; #[ automatically_derived ] impl< Definition > former::FormingEnd < former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > -for __Vec1End +for __vec1_end where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes @@ -438,14 +438,14 @@ where } // zzz : description -/// Return original former after subformer for vec1 is done. -pub struct __HashMapEnd; +/// Return original former after subformer for `hashmap_string_1` is done. +pub struct __hashmap_strings_1_end; #[ automatically_derived ] impl< Definition > former::FormingEnd < former::HashMapDefinition< String, String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > -for __HashMapEnd +for __hashmap_strings_1_end where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes @@ -469,6 +469,38 @@ where } } +// zzz : description +/// Return original former after subformer for `hashset_string_1` is done. +pub struct __hashset_strings_1_end; +#[ automatically_derived ] +impl< Definition > former::FormingEnd +< + former::HashSetDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, +> +for __hashset_strings_1_end +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = Struct1FormerStorage + >, +{ + #[ inline( always ) ] + fn call( &self, storage : std::collections::HashSet< String >, super_former : Option< Struct1Former< Definition > > ) -> Struct1Former< Definition > + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.hashset_strings_1 + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.hashset_strings_1 = Some( storage ); + } + super_former + } +} + // = end of generated // include!( "./only_test/containers_with_subformer.rs" ); From 738c75eb36b106290d745d023e72105284a888e3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 31 Mar 2024 01:07:40 +0200 Subject: [PATCH 098/533] former : experimenting --- .../inc/former_tests/a_containers_with_subformer_manual.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index d4d3652349..c6a9e8c3eb 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -407,6 +407,7 @@ where // zzz : description /// Return original former after subformer for `vec_1` is done. +#[ allow( non_camel_case_types ) ] pub struct __vec1_end; #[ automatically_derived ] impl< Definition > former::FormingEnd @@ -439,6 +440,7 @@ where // zzz : description /// Return original former after subformer for `hashmap_string_1` is done. +#[ allow( non_camel_case_types ) ] pub struct __hashmap_strings_1_end; #[ automatically_derived ] impl< Definition > former::FormingEnd @@ -471,6 +473,7 @@ where // zzz : description /// Return original former after subformer for `hashset_string_1` is done. +#[ allow( non_camel_case_types ) ] pub struct __hashset_strings_1_end; #[ automatically_derived ] impl< Definition > former::FormingEnd From 6f0c19cc6ee88d0e91ef77fb3daacfce53f62c90 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 2 Apr 2024 01:23:14 +0300 Subject: [PATCH 099/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index c6a9e8c3eb..4888264ab0 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -363,6 +363,79 @@ where > >() } + #[ inline( always ) ] + pub fn hashmap_strings_1_set< Former2 >( self ) -> Former2 + where + Former2 : former::FormerBegin + < + former::HashMapDefinition + < + String, + String, + Self, + Self, + __hashmap_strings_1_end, + > + >, + { + Former2::_begin( None, Some( self ), __hashmap_strings_1_end ) + } + + pub fn hashmap_strings_1( self ) -> + former::HashMapSubformer:: + < + String, + String, + Self, + Self, + __hashmap_strings_1_end, + > + { + self.hashmap_strings_1_set::< former::HashMapSubformer:: + < + String, + String, + Self, + Self, + __hashmap_strings_1_end, + > >() + } + + #[ inline( always ) ] + pub fn hashset_strings_1_set< Former2 >( self ) -> Former2 + where + Former2 : former::FormerBegin + < + former::HashSetDefinition + < + String, + Self, + Self, + __hashset_strings_1_end, + > + >, + { + Former2::_begin( None, Some( self ), __hashset_strings_1_end ) + } + + pub fn hashset_strings_1( self ) -> + former::HashSetSubformer:: + < + String, + Self, + Self, + __hashset_strings_1_end, + > + { + self.hashset_strings_1_set::< former::HashSetSubformer:: + < + String, + Self, + Self, + __hashset_strings_1_end, + > >() + } + // #[ doc = "Subformer setter for the 'hashmap_strings_1' field." ] // #[ inline ] // pub fn hashmap_strings_1( mut self ) -> the_module::HashMapSubformer< String, String, std::collections::HashMap< String, String >, Self, impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self, > From ccf0d301ebafa7dc12ecac7c4b4f49340d86ab08 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 2 Apr 2024 11:27:20 +0300 Subject: [PATCH 100/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 8 ++- .../only_test/containers_with_subformer.rs | 72 ++++++++++++++----- 2 files changed, 61 insertions(+), 19 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 4888264ab0..6862781110 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -21,6 +21,8 @@ impl Struct1 } } +// = definition + #[ derive( Debug ) ] pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > { @@ -72,6 +74,8 @@ where pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; +// = storage + #[ doc = "Container of a corresponding former." ] pub struct Struct1FormerStorage { @@ -196,6 +200,8 @@ impl former::StoragePreform for Struct1FormerStorage } } +// = former + #[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[ default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] pub struct Struct1Former< Definition = Struct1FormerDefinition > where @@ -579,4 +585,4 @@ where // = end of generated -// include!( "./only_test/containers_with_subformer.rs" ); +include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index 5381a86227..3fb1978db6 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -13,25 +13,26 @@ tests_impls_optional! // test.case( "vector : construction" ); + // fields let former = Struct1::former(); a_id!( former.storage.vec_1, None ); a_id!( former.storage.hashmap_strings_1, None ); a_id!( former.storage.hashset_strings_1, None ); a_id!( former.context, None ); - a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); - let former2 = Struct1Former::< Struct1, the_module::ReturnPreformed >::new(); - a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); + // forming let command = Struct1::former().form(); a_id!( command.vec_1, Vec::< String >::new() ); a_id!( command.hashmap_strings_1, hmap!{} ); a_id!( command.hashset_strings_1, hset![] ); + // performing let command = Struct1::former().perform(); a_id!( command.vec_1, Vec::< String >::new() ); a_id!( command.hashmap_strings_1, hmap!{} ); a_id!( command.hashset_strings_1, hset![] ); + // ending let command = Struct1::former().end(); a_id!( command.vec_1, Vec::< String >::new() ); a_id!( command.hashmap_strings_1, hmap!{} ); @@ -41,13 +42,46 @@ tests_impls_optional! // + fn new() + { + + // former with explicit definition + let former = Struct1::former(); + a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); + let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); + a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); + + // default parameters + let former = Struct1::former(); + let former2 : Struct1Former = Struct1Former::new( former::ReturnPreformed ); + a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); + + // default explicit params with wrapper and closure + let got : Struct1 = Struct1Former + ::< Struct1FormerWithClosure< (), Struct1 > > + ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) + .vec_1().replace( vec![ "a".to_string(), "b".to_string() ] ) + .form(); + let exp : Struct1 = Struct1 + { + vec_1 : vec![ "a".to_string(), "b".to_string() ], + hashmap_strings_1 : hmap!{}, + hashset_strings_1 : hset!{}, + }; + // a_id!( got, exp ); + // xxx : ? + + } + + // + fn test_vector() { // test.case( "vector : implicit construction" ); let command = Struct1::former() - .vec_1().push( "ghi" ).push( "klm" ).end() + .vec_1().add( "ghi" ).add( "klm" ).end() .form() ; // dbg!( &command ); @@ -74,7 +108,7 @@ tests_impls_optional! a_id!( command, expected ); let command = Struct1::former() - .vec_1().push( "x" ).replace( vec![ "a".to_string(), "bc".to_string(), "def".to_string() ] ).end() + .vec_1().add( "x" ).replace( vec![ "a".to_string(), "bc".to_string(), "def".to_string() ] ).end() .form(); let expected = Struct1 { @@ -84,10 +118,10 @@ tests_impls_optional! }; a_id!( command, expected ); - // test.case( "vector : replace and push" ); + // test.case( "vector : replace and add" ); let command = Struct1::former() - .vec_1().replace( vec![ "a".to_string(), "bc".to_string(), "def".to_string() ] ).push( "gh" ).end() + .vec_1().replace( vec![ "a".to_string(), "bc".to_string(), "def".to_string() ] ).add( "gh" ).end() .form(); // dbg!( &command ); @@ -108,7 +142,7 @@ tests_impls_optional! // test.case( "implicit construction" ); let command = Struct1::former() - .hashmap_strings_1().insert( "k1", "v1" ).insert( "k2", "v2" ).end() + .hashmap_strings_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() .form() ; // dbg!( &command ); @@ -136,7 +170,7 @@ tests_impls_optional! a_id!( command, expected ); let command = Struct1::former() - .hashmap_strings_1().insert( "x", "v1" ).replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() + .hashmap_strings_1().add( ( "x".to_string(), "v1".to_string() ) ).replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() .form() ; let expected = Struct1 @@ -147,10 +181,11 @@ tests_impls_optional! }; a_id!( command, expected ); - // test.case( "replace and insert" ); + // test.case( "replace and add" ); let command = Struct1::former() - .hashmap_strings_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).insert( "k3", "v3" ).end() + .hashmap_strings_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ) + .add( ( "k3".to_string(), "v3".to_string() ) ).end() .form() ; // dbg!( &command ); @@ -172,7 +207,7 @@ tests_impls_optional! // test.case( "implicit construction" ); let command = Struct1::former() - .hashset_strings_1().insert( "v1" ).insert( "v2" ).end() + .hashset_strings_1().add( "v1" ).add( "v2" ).end() .form() ; // dbg!( &command ); @@ -200,7 +235,7 @@ tests_impls_optional! a_id!( command, expected ); let command = Struct1::former() - .hashset_strings_1().insert( "x" ).replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() + .hashset_strings_1().add( "x" ).replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() .form() ; let expected = Struct1 @@ -211,10 +246,10 @@ tests_impls_optional! }; a_id!( command, expected ); - // test.case( "replace and insert" ); + // test.case( "replace and add" ); let command = Struct1::former() - .hashset_strings_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).insert( "v3" ).end() + .hashset_strings_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).add( "v3" ).end() .form() ; // dbg!( &command ); @@ -234,9 +269,9 @@ tests_impls_optional! { let command = Struct1::former() - .vec_1().push( "ghi" ).push( "klm" ).end() - .hashmap_strings_1().insert( "k1", "v1" ).insert( "k2", "v2" ).end() - .hashset_strings_1().insert( "k1" ).end() + .vec_1().add( "ghi" ).add( "klm" ).end() + .hashmap_strings_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() + .hashset_strings_1().add( "k1" ).end() .form(); // dbg!( &command ); @@ -257,6 +292,7 @@ tests_impls_optional! tests_index! { internals, + new, test_vector, test_hashmap, test_hashset, From 789d39420be2de4b2a2f2ebdf9becac99281f3c8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 2 Apr 2024 11:37:08 +0300 Subject: [PATCH 101/533] former : experimenting --- .../only_test/containers_with_subformer.rs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index 3fb1978db6..b749668a65 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -56,11 +56,25 @@ tests_impls_optional! let former2 : Struct1Former = Struct1Former::new( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); - // default explicit params with wrapper and closure + // closure without helper + let got : Struct1 = Struct1Former + ::< Struct1FormerDefinition< _, _, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > + ::new( | storage : Struct1FormerStorage, _context | { former::StoragePreform::preform( storage ) } ) + .vec_1().replace( vec![ "a".to_string(), "b".to_string() ] ).end() + .form(); + let exp : Struct1 = Struct1 + { + vec_1 : vec![ "a".to_string(), "b".to_string() ], + hashmap_strings_1 : hmap!{}, + hashset_strings_1 : hset!{}, + }; + a_id!( got, exp ); + + // closure with helper let got : Struct1 = Struct1Former ::< Struct1FormerWithClosure< (), Struct1 > > - ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) - .vec_1().replace( vec![ "a".to_string(), "b".to_string() ] ) + ::new( | storage : Struct1FormerStorage, _context | { former::StoragePreform::preform( storage ) } ) + .vec_1().replace( vec![ "a".to_string(), "b".to_string() ] ).end() .form(); let exp : Struct1 = Struct1 { @@ -68,8 +82,7 @@ tests_impls_optional! hashmap_strings_1 : hmap!{}, hashset_strings_1 : hset!{}, }; - // a_id!( got, exp ); - // xxx : ? + a_id!( got, exp ); } From f2221205aa73cefab2d68026f55b18331bbcbea4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 2 Apr 2024 11:41:54 +0300 Subject: [PATCH 102/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 2 +- .../only_test/containers_with_subformer.rs | 36 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 6862781110..ba6c99c982 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -1,7 +1,7 @@ #[ allow( unused_imports ) ] use super::*; -#[ derive( Debug, PartialEq ) ] +#[ derive( Default, Debug, PartialEq ) ] pub struct Struct1 { vec_1 : Vec< String >, diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index b749668a65..c0117b5473 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -20,23 +20,25 @@ tests_impls_optional! a_id!( former.storage.hashset_strings_1, None ); a_id!( former.context, None ); - // forming - let command = Struct1::former().form(); - a_id!( command.vec_1, Vec::< String >::new() ); - a_id!( command.hashmap_strings_1, hmap!{} ); - a_id!( command.hashset_strings_1, hset![] ); - - // performing - let command = Struct1::former().perform(); - a_id!( command.vec_1, Vec::< String >::new() ); - a_id!( command.hashmap_strings_1, hmap!{} ); - a_id!( command.hashset_strings_1, hset![] ); - - // ending - let command = Struct1::former().end(); - a_id!( command.vec_1, Vec::< String >::new() ); - a_id!( command.hashmap_strings_1, hmap!{} ); - a_id!( command.hashset_strings_1, hset![] ); + // form + let got = Struct1::former().form(); + let exp = Struct1::default(); + a_id!( got, exp ); + + // preform + let got = Struct1::former().preform(); + let exp = Struct1::default(); + a_id!( got, exp ); + + // perform + let got = Struct1::former().perform(); + let exp = Struct1::default(); + a_id!( got, exp ); + + // end + let got = Struct1::former().end(); + let exp = Struct1::default(); + a_id!( got, exp ); } From a633aeda4b94088df80b9c64976e9e3872945dfa Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 2 Apr 2024 11:47:44 +0300 Subject: [PATCH 103/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 44 +++---------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index ba6c99c982..e751aaa4ff 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -425,51 +425,17 @@ where } pub fn hashset_strings_1( self ) -> - former::HashSetSubformer:: + former::ContainerSubformer:: < - String, - Self, - Self, - __hashset_strings_1_end, + String, former::HashSetDefinition< String, Self, Self, __hashset_strings_1_end > > { - self.hashset_strings_1_set::< former::HashSetSubformer:: + self.hashset_strings_1_set::< former::ContainerSubformer:: < - String, - Self, - Self, - __hashset_strings_1_end, - > >() + String, former::HashSetDefinition< String, Self, Self, __hashset_strings_1_end > + >>() } -// #[ doc = "Subformer setter for the 'hashmap_strings_1' field." ] -// #[ inline ] -// pub fn hashmap_strings_1( mut self ) -> the_module::HashMapSubformer< String, String, std::collections::HashMap< String, String >, Self, impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self, > -// { -// let formed = self.storage.hashmap_strings_1.take(); -// let on_end = | formed : std::collections::HashMap< String, String >, former : core::option::Option< Self > | -> Self -// { -// let mut former = former.unwrap(); -// former.storage.hashmap_strings_1 = Some( formed ); -// former -// }; -// the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) -// } -// -// #[ doc = "Subformer setter for the 'hashset_strings_1' field." ] -// #[ inline ] -// pub fn hashset_strings_1( mut self ) -> the_module::HashSetSubformer< String, std::collections::HashSet< String >, Self, impl Fn( std::collections::HashSet< String >, core::option::Option< Self > ) -> Self, > -// { -// let formed = self.storage.hashset_strings_1.take(); -// let on_end = | formed : std::collections::HashSet< String >, former : core::option::Option< Self > | -> Self -// { -// let mut former = former.unwrap(); -// former.storage.hashset_strings_1 = Some( formed ); -// former -// }; -// the_module::HashSetSubformer::begin( formed, Some( self ), on_end ) -// } - } impl< Definition > Struct1Former< Definition > From 6db00737819ebd1a5e46d801763b69759e77f22b Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 2 Apr 2024 11:50:54 +0300 Subject: [PATCH 104/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 56 ++++++++++++++----- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index e751aaa4ff..678c39c755 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -388,25 +388,55 @@ where } pub fn hashmap_strings_1( self ) -> - former::HashMapSubformer:: + former::ContainerSubformer:: < - String, - String, - Self, - Self, - __hashmap_strings_1_end, + ( String, String ), former::HashMapDefinition< String, String, Self, Self, __hashmap_strings_1_end > > { - self.hashmap_strings_1_set::< former::HashMapSubformer:: + self.hashmap_strings_1_set::< former::ContainerSubformer:: < - String, - String, - Self, - Self, - __hashmap_strings_1_end, - > >() + ( String, String ), former::HashMapDefinition< String, String, Self, Self, __hashmap_strings_1_end > + >>() } +// #[ inline( always ) ] +// pub fn hashmap_strings_1_set< Former2 >( self ) -> Former2 +// where +// Former2 : former::FormerBegin +// < +// former::HashMapDefinition +// < +// String, +// String, +// Self, +// Self, +// __hashmap_strings_1_end, +// > +// >, +// { +// Former2::_begin( None, Some( self ), __hashmap_strings_1_end ) +// } +// +// pub fn hashmap_strings_1( self ) -> +// former::HashMapSubformer:: +// < +// String, +// String, +// Self, +// Self, +// __hashmap_strings_1_end, +// > +// { +// self.hashmap_strings_1_set::< former::HashMapSubformer:: +// < +// String, +// String, +// Self, +// Self, +// __hashmap_strings_1_end, +// > >() +// } + #[ inline( always ) ] pub fn hashset_strings_1_set< Former2 >( self ) -> Former2 where From 9eaa170493ae842858fd2c80d4efc6432c66e645 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 2 Apr 2024 11:57:54 +0300 Subject: [PATCH 105/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 111 +++++++----------- 1 file changed, 44 insertions(+), 67 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 678c39c755..7fdd798d2b 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -320,20 +320,6 @@ where former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) } - // #[ doc = "Subformer setter for the 'vec_1' field." ] - // #[ inline ] - // pub fn vec_1( mut self ) -> the_module::VectorSubformer< String, Vec< String >, Self, impl Fn( Vec< String >, core::option::Option< Self > ) -> Self, > - // { - // let formed = self.storage.vec_1.take(); - // let on_end = | formed : Vec< String >, former : core::option::Option< Self > | -> Self - // { - // let mut former = former.unwrap(); - // former.storage.vec_1 = Some( formed ); - // former - // }; - // the_module::VectorSubformer::begin( formed, Some( self ), on_end ) - // } - #[ inline( always ) ] pub fn vec_1_set< Former2 >( self ) -> Former2 where @@ -344,31 +330,60 @@ where String, Self, Self, - __vec1_end, + __vec_1_end, > >, { - Former2::_begin( None, Some( self ), __vec1_end ) + Former2::_begin( None, Some( self ), __vec_1_end ) } pub fn vec_1( self ) -> - former::VectorSubformer:: + former::ContainerSubformer:: < - String, - Self, - Self, - __vec1_end, + String, former::VectorDefinition< String, Self, Self, __vec_1_end > > { - self.vec_1_set::< former::VectorSubformer:: + self.vec_1_set::< former::ContainerSubformer:: < - String, - Self, - Self, - __vec1_end, - > >() + String, former::VectorDefinition< String, Self, Self, __vec_1_end > + >>() } +// #[ inline( always ) ] +// pub fn vec_1_set< Former2 >( self ) -> Former2 +// where +// Former2 : former::FormerBegin +// < +// former::VectorDefinition +// < +// String, +// Self, +// Self, +// __vec_1_end, +// > +// >, +// { +// Former2::_begin( None, Some( self ), __vec_1_end ) +// } +// +// pub fn vec_1( self ) -> +// former::VectorSubformer:: +// < +// String, +// Self, +// Self, +// __vec_1_end, +// > +// { +// self.vec_1_set::< former::VectorSubformer:: +// < +// String, +// Self, +// Self, +// __vec_1_end, +// > >() +// } + #[ inline( always ) ] pub fn hashmap_strings_1_set< Former2 >( self ) -> Former2 where @@ -399,44 +414,6 @@ where >>() } -// #[ inline( always ) ] -// pub fn hashmap_strings_1_set< Former2 >( self ) -> Former2 -// where -// Former2 : former::FormerBegin -// < -// former::HashMapDefinition -// < -// String, -// String, -// Self, -// Self, -// __hashmap_strings_1_end, -// > -// >, -// { -// Former2::_begin( None, Some( self ), __hashmap_strings_1_end ) -// } -// -// pub fn hashmap_strings_1( self ) -> -// former::HashMapSubformer:: -// < -// String, -// String, -// Self, -// Self, -// __hashmap_strings_1_end, -// > -// { -// self.hashmap_strings_1_set::< former::HashMapSubformer:: -// < -// String, -// String, -// Self, -// Self, -// __hashmap_strings_1_end, -// > >() -// } - #[ inline( always ) ] pub fn hashset_strings_1_set< Former2 >( self ) -> Former2 where @@ -483,13 +460,13 @@ where // zzz : description /// Return original former after subformer for `vec_1` is done. #[ allow( non_camel_case_types ) ] -pub struct __vec1_end; +pub struct __vec_1_end; #[ automatically_derived ] impl< Definition > former::FormingEnd < former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > -for __vec1_end +for __vec_1_end where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes From 46e46b3eb54265d6c8d26e427f8b887d8dc44abf Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 2 Apr 2024 12:08:45 +0300 Subject: [PATCH 106/533] former : experimenting --- .../a_containers_with_subformer.rs | 4 +- .../a_containers_with_subformer_2_manual.rs | 36 ++++---- .../a_containers_with_subformer_manual.rs | 72 ++++++++-------- .../a_containers_without_subformer.rs | 4 +- .../attribute_default_primitive.rs | 8 +- .../tests/inc/former_tests/name_collisions.rs | 4 +- .../only_test/containers_with_subformer.rs | 84 +++++++++---------- .../only_test/containers_without_subformer.rs | 42 +++++----- .../inc/former_tests/only_test/primitives.rs | 2 +- 9 files changed, 128 insertions(+), 128 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 53d8f86ad4..5a4c492d11 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -11,9 +11,9 @@ pub struct Struct1 #[ subformer( the_module::VectorSubformer ) ] vec_1 : Vec< String >, #[ subformer( the_module::HashMapSubformer ) ] - hashmap_strings_1 : std::collections::HashMap< String, String >, + hashmap_1 : std::collections::HashMap< String, String >, #[ subformer( the_module::HashSetSubformer ) ] - hashset_strings_1 : std::collections::HashSet< String >, + hashset_1 : std::collections::HashSet< String >, } // include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs index b080a71ca2..3332a2f999 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs @@ -7,8 +7,8 @@ use super::*; pub struct Struct1 { vec_1 : Vec< String >, - hashmap_strings_1 : std::collections::HashMap< String, String >, - hashset_strings_1 : std::collections::HashSet< String >, + hashmap_1 : std::collections::HashMap< String, String >, + hashset_1 : std::collections::HashSet< String >, } // = formed @@ -27,8 +27,8 @@ impl Struct1 pub struct Struct1FormerStorage { pub vec_1 : ::core::option::Option< Vec< String > >, - pub hashmap_strings_1 : ::core::option::Option< std::collections::HashMap< String, String > >, - pub hashset_strings_1 : ::core::option::Option< std::collections::HashSet< String > >, + pub hashmap_1 : ::core::option::Option< std::collections::HashMap< String, String > >, + pub hashset_1 : ::core::option::Option< std::collections::HashSet< String > >, } impl Default for Struct1FormerStorage @@ -40,8 +40,8 @@ impl Default for Struct1FormerStorage Self { vec_1 : None, - hashmap_strings_1 : None, - hashset_strings_1 : None, + hashmap_1 : None, + hashset_1 : None, } } @@ -81,9 +81,9 @@ where val }; - let hashmap_strings_1 = if self.storage.hashmap_strings_1.is_some() + let hashmap_1 = if self.storage.hashmap_1.is_some() { - self.storage.hashmap_strings_1.take().unwrap() + self.storage.hashmap_1.take().unwrap() } else { @@ -91,9 +91,9 @@ where val }; - let hashset_strings_1 = if self.storage.hashset_strings_1.is_some() + let hashset_1 = if self.storage.hashset_1.is_some() { - self.storage.hashset_strings_1.take().unwrap() + self.storage.hashset_1.take().unwrap() } else { @@ -104,8 +104,8 @@ where Struct1 { vec_1, - hashmap_strings_1, - hashset_strings_1, + hashmap_1, + hashset_1, } } @@ -212,7 +212,7 @@ where // the_module::VectorSubformer::< String, Vec< String >, Self, _ >::begin( Some( self ), formed, on_end ) // } - pub fn hashmap_strings_1( mut self ) -> the_module::HashMapSubformer + pub fn hashmap_1( mut self ) -> the_module::HashMapSubformer < String, String, @@ -221,17 +221,17 @@ where impl the_module::FormingEnd< std::collections::HashMap< String, String >, Self >, > { - let formed = self.storage.hashmap_strings_1.take(); + let formed = self.storage.hashmap_1.take(); let on_end = | formed : std::collections::HashMap< String, String >, super_former : ::core::option::Option< Self > | -> Self { let mut super_former = super_former.unwrap(); - super_former.storage.hashmap_strings_1 = Some( formed ); + super_former.storage.hashmap_1 = Some( formed ); super_former }; the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) } - pub fn hashset_strings_1( mut self ) -> the_module::HashSetSubformer + pub fn hashset_1( mut self ) -> the_module::HashSetSubformer < String, std::collections::HashSet< String >, @@ -239,11 +239,11 @@ where impl the_module::FormingEnd< std::collections::HashSet< String >, Self >, > { - let formed = self.storage.hashset_strings_1.take(); + let formed = self.storage.hashset_1.take(); let on_end = | formed : std::collections::HashSet< String >, super_former : ::core::option::Option< Self > | -> Self { let mut super_former = super_former.unwrap(); - super_former.storage.hashset_strings_1 = Some( formed ); + super_former.storage.hashset_1 = Some( formed ); super_former }; the_module::HashSetSubformer::begin( formed, Some( self ), on_end ) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 7fdd798d2b..1959d449b9 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -5,8 +5,8 @@ use super::*; pub struct Struct1 { vec_1 : Vec< String >, - hashmap_strings_1 : std::collections::HashMap< String, String >, - hashset_strings_1 : std::collections::HashSet< String >, + hashmap_1 : std::collections::HashMap< String, String >, + hashset_1 : std::collections::HashSet< String >, } // = generated @@ -83,10 +83,10 @@ pub struct Struct1FormerStorage pub vec_1 : ::core::option::Option< Vec< String > >, #[ doc = r" A field" ] - pub hashmap_strings_1 : ::core::option::Option< std::collections::HashMap< String, String > >, + pub hashmap_1 : ::core::option::Option< std::collections::HashMap< String, String > >, #[ doc = r" A field" ] - pub hashset_strings_1 : ::core::option::Option< std::collections::HashSet< String > >, + pub hashset_1 : ::core::option::Option< std::collections::HashSet< String > >, } impl ::core::default::Default for Struct1FormerStorage @@ -97,8 +97,8 @@ impl ::core::default::Default for Struct1FormerStorage Self { vec_1 : ::core::option::Option::None, - hashmap_strings_1 : ::core::option::Option::None, - hashset_strings_1 : ::core::option::Option::None, + hashmap_1 : ::core::option::Option::None, + hashset_1 : ::core::option::Option::None, } } } @@ -138,9 +138,9 @@ impl former::StoragePreform for Struct1FormerStorage ( &::core::marker::PhantomData::< Vec< String > > ).maybe_default() } }; - let hashmap_strings_1 = if self.hashmap_strings_1.is_some() + let hashmap_1 = if self.hashmap_1.is_some() { - self.hashmap_strings_1.take().unwrap() + self.hashmap_1.take().unwrap() } else { @@ -149,7 +149,7 @@ impl former::StoragePreform for Struct1FormerStorage { fn maybe_default( self : &Self ) -> T { - panic!( "Field 'hashmap_strings_1' isn't initialized" ) + panic!( "Field 'hashmap_1' isn't initialized" ) } } impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} @@ -164,9 +164,9 @@ impl former::StoragePreform for Struct1FormerStorage ( &::core::marker::PhantomData::< std::collections::HashMap< String, String > > ).maybe_default() } }; - let hashset_strings_1 = if self.hashset_strings_1.is_some() + let hashset_1 = if self.hashset_1.is_some() { - self.hashset_strings_1.take().unwrap() + self.hashset_1.take().unwrap() } else { @@ -175,7 +175,7 @@ impl former::StoragePreform for Struct1FormerStorage { fn maybe_default( self : &Self ) -> T { - panic!( "Field 'hashset_strings_1' isn't initialized" ) + panic!( "Field 'hashset_1' isn't initialized" ) } } impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} @@ -193,8 +193,8 @@ impl former::StoragePreform for Struct1FormerStorage let result = Struct1 { vec_1, - hashmap_strings_1, - hashset_strings_1, + hashmap_1, + hashset_1, }; return result; } @@ -385,7 +385,7 @@ where // } #[ inline( always ) ] - pub fn hashmap_strings_1_set< Former2 >( self ) -> Former2 + pub fn hashmap_1_set< Former2 >( self ) -> Former2 where Former2 : former::FormerBegin < @@ -395,27 +395,27 @@ where String, Self, Self, - __hashmap_strings_1_end, + __hashmap_1_end, > >, { - Former2::_begin( None, Some( self ), __hashmap_strings_1_end ) + Former2::_begin( None, Some( self ), __hashmap_1_end ) } - pub fn hashmap_strings_1( self ) -> + pub fn hashmap_1( self ) -> former::ContainerSubformer:: < - ( String, String ), former::HashMapDefinition< String, String, Self, Self, __hashmap_strings_1_end > + ( String, String ), former::HashMapDefinition< String, String, Self, Self, __hashmap_1_end > > { - self.hashmap_strings_1_set::< former::ContainerSubformer:: + self.hashmap_1_set::< former::ContainerSubformer:: < - ( String, String ), former::HashMapDefinition< String, String, Self, Self, __hashmap_strings_1_end > + ( String, String ), former::HashMapDefinition< String, String, Self, Self, __hashmap_1_end > >>() } #[ inline( always ) ] - pub fn hashset_strings_1_set< Former2 >( self ) -> Former2 + pub fn hashset_1_set< Former2 >( self ) -> Former2 where Former2 : former::FormerBegin < @@ -424,22 +424,22 @@ where String, Self, Self, - __hashset_strings_1_end, + __hashset_1_end, > >, { - Former2::_begin( None, Some( self ), __hashset_strings_1_end ) + Former2::_begin( None, Some( self ), __hashset_1_end ) } - pub fn hashset_strings_1( self ) -> + pub fn hashset_1( self ) -> former::ContainerSubformer:: < - String, former::HashSetDefinition< String, Self, Self, __hashset_strings_1_end > + String, former::HashSetDefinition< String, Self, Self, __hashset_1_end > > { - self.hashset_strings_1_set::< former::ContainerSubformer:: + self.hashset_1_set::< former::ContainerSubformer:: < - String, former::HashSetDefinition< String, Self, Self, __hashset_strings_1_end > + String, former::HashSetDefinition< String, Self, Self, __hashset_1_end > >>() } @@ -493,13 +493,13 @@ where // zzz : description /// Return original former after subformer for `hashmap_string_1` is done. #[ allow( non_camel_case_types ) ] -pub struct __hashmap_strings_1_end; +pub struct __hashmap_1_end; #[ automatically_derived ] impl< Definition > former::FormingEnd < former::HashMapDefinition< String, String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > -for __hashmap_strings_1_end +for __hashmap_1_end where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes @@ -511,13 +511,13 @@ where fn call( &self, storage : std::collections::HashMap< String, String >, super_former : Option< Struct1Former< Definition > > ) -> Struct1Former< Definition > { let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.hashmap_strings_1 + if let Some( ref mut field ) = super_former.storage.hashmap_1 { former::ContainerAssign::assign( field, storage ); } else { - super_former.storage.hashmap_strings_1 = Some( storage ); + super_former.storage.hashmap_1 = Some( storage ); } super_former } @@ -526,13 +526,13 @@ where // zzz : description /// Return original former after subformer for `hashset_string_1` is done. #[ allow( non_camel_case_types ) ] -pub struct __hashset_strings_1_end; +pub struct __hashset_1_end; #[ automatically_derived ] impl< Definition > former::FormingEnd < former::HashSetDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > -for __hashset_strings_1_end +for __hashset_1_end where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes @@ -544,13 +544,13 @@ where fn call( &self, storage : std::collections::HashSet< String >, super_former : Option< Struct1Former< Definition > > ) -> Struct1Former< Definition > { let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.hashset_strings_1 + if let Some( ref mut field ) = super_former.storage.hashset_1 { former::ContainerAssign::assign( field, storage ); } else { - super_former.storage.hashset_strings_1 = Some( storage ); + super_former.storage.hashset_1 = Some( storage ); } super_former } diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs index 9cd61f41eb..4b09b320a5 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs @@ -9,8 +9,8 @@ use std::collections::HashSet; pub struct Struct1 { vec_1 : Vec< String >, - hashmap_strings_1 : HashMap< String, String >, - hashset_strings_1 : HashSet< String >, + hashmap_1 : HashMap< String, String >, + hashset_1 : HashSet< String >, } // diff --git a/module/core/former/tests/inc/former_tests/attribute_default_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_default_primitive.rs index e81ac264bf..21538d87c4 100644 --- a/module/core/former/tests/inc/former_tests/attribute_default_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_default_primitive.rs @@ -36,8 +36,8 @@ pub struct Struct1 string_optional_1 : Option< String >, vec_1 : Vec< String >, - hashmap_strings_1 : HashMap< String, String >, - hashset_strings_1 : HashSet< String >, + hashmap_1 : HashMap< String, String >, + hashset_1 : HashSet< String >, } // @@ -55,8 +55,8 @@ tests_impls! int_optional_1 : Some( 31 ), string_optional_1 : Some( "abc".to_string() ), vec_1 : vec![], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{}, + hashset_1 : hset!{}, }; a_id!( command, expected ); } diff --git a/module/core/former/tests/inc/former_tests/name_collisions.rs b/module/core/former/tests/inc/former_tests/name_collisions.rs index 6b318a809e..843af61803 100644 --- a/module/core/former/tests/inc/former_tests/name_collisions.rs +++ b/module/core/former/tests/inc/former_tests/name_collisions.rs @@ -28,8 +28,8 @@ type HashMap = (); pub struct Struct1 { vec_1 : Vec< String >, - hashmap_strings_1 : std::collections::HashMap< String, String >, - hashset_strings_1 : std::collections::HashSet< String >, + hashmap_1 : std::collections::HashMap< String, String >, + hashset_1 : std::collections::HashSet< String >, } // diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index c0117b5473..a161ec02c5 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -16,8 +16,8 @@ tests_impls_optional! // fields let former = Struct1::former(); a_id!( former.storage.vec_1, None ); - a_id!( former.storage.hashmap_strings_1, None ); - a_id!( former.storage.hashset_strings_1, None ); + a_id!( former.storage.hashmap_1, None ); + a_id!( former.storage.hashset_1, None ); a_id!( former.context, None ); // form @@ -67,8 +67,8 @@ tests_impls_optional! let exp : Struct1 = Struct1 { vec_1 : vec![ "a".to_string(), "b".to_string() ], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{}, + hashset_1 : hset!{}, }; a_id!( got, exp ); @@ -81,8 +81,8 @@ tests_impls_optional! let exp : Struct1 = Struct1 { vec_1 : vec![ "a".to_string(), "b".to_string() ], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{}, + hashset_1 : hset!{}, }; a_id!( got, exp ); @@ -104,8 +104,8 @@ tests_impls_optional! let expected = Struct1 { vec_1 : vec![ "ghi".to_string(), "klm".to_string() ], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{}, + hashset_1 : hset!{}, }; a_id!( command, expected ); @@ -117,8 +117,8 @@ tests_impls_optional! let expected = Struct1 { vec_1 : vec![ "a".to_string(), "bc".to_string(), "def".to_string() ], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{}, + hashset_1 : hset!{}, }; a_id!( command, expected ); @@ -128,8 +128,8 @@ tests_impls_optional! let expected = Struct1 { vec_1 : vec![ "a".to_string(), "bc".to_string(), "def".to_string() ], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{}, + hashset_1 : hset!{}, }; a_id!( command, expected ); @@ -143,8 +143,8 @@ tests_impls_optional! let expected = Struct1 { vec_1 : vec![ "a".to_string(), "bc".to_string(), "def".to_string(), "gh".to_string() ], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{}, + hashset_1 : hset!{}, }; a_id!( command, expected ); } @@ -157,7 +157,7 @@ tests_impls_optional! // test.case( "implicit construction" ); let command = Struct1::former() - .hashmap_strings_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() + .hashmap_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() .form() ; // dbg!( &command ); @@ -165,41 +165,41 @@ tests_impls_optional! let expected = Struct1 { vec_1 : vec![], - hashmap_strings_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, + hashset_1 : hset!{}, }; a_id!( command, expected ); // test.case( "replace" ); let command = Struct1::former() - .hashmap_strings_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() + .hashmap_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() .form() ; let expected = Struct1 { vec_1 : vec![], - hashmap_strings_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, + hashset_1 : hset!{}, }; a_id!( command, expected ); let command = Struct1::former() - .hashmap_strings_1().add( ( "x".to_string(), "v1".to_string() ) ).replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() + .hashmap_1().add( ( "x".to_string(), "v1".to_string() ) ).replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() .form() ; let expected = Struct1 { vec_1 : vec![], - hashmap_strings_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, + hashset_1 : hset!{}, }; a_id!( command, expected ); // test.case( "replace and add" ); let command = Struct1::former() - .hashmap_strings_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ) + .hashmap_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ) .add( ( "k3".to_string(), "v3".to_string() ) ).end() .form() ; @@ -208,8 +208,8 @@ tests_impls_optional! let expected = Struct1 { vec_1 : vec![], - hashmap_strings_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string(), "k3".to_string() => "v3".to_string() }, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string(), "k3".to_string() => "v3".to_string() }, + hashset_1 : hset!{}, }; a_id!( command, expected ); } @@ -222,7 +222,7 @@ tests_impls_optional! // test.case( "implicit construction" ); let command = Struct1::former() - .hashset_strings_1().add( "v1" ).add( "v2" ).end() + .hashset_1().add( "v1" ).add( "v2" ).end() .form() ; // dbg!( &command ); @@ -230,41 +230,41 @@ tests_impls_optional! let expected = Struct1 { vec_1 : vec![], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{ "v1".to_string(), "v2".to_string() }, + hashmap_1 : hmap!{}, + hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, }; a_id!( command, expected ); // test.case( "replace" ); let command = Struct1::former() - .hashset_strings_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() + .hashset_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() .form() ; let expected = Struct1 { vec_1 : vec![], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{ "v1".to_string(), "v2".to_string() }, + hashmap_1 : hmap!{}, + hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, }; a_id!( command, expected ); let command = Struct1::former() - .hashset_strings_1().add( "x" ).replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() + .hashset_1().add( "x" ).replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() .form() ; let expected = Struct1 { vec_1 : vec![], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{ "v1".to_string(), "v2".to_string() }, + hashmap_1 : hmap!{}, + hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, }; a_id!( command, expected ); // test.case( "replace and add" ); let command = Struct1::former() - .hashset_strings_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).add( "v3" ).end() + .hashset_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).add( "v3" ).end() .form() ; // dbg!( &command ); @@ -272,8 +272,8 @@ tests_impls_optional! let expected = Struct1 { vec_1 : vec![], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{ "v1".to_string(), "v2".to_string(), "v3".to_string() }, + hashmap_1 : hmap!{}, + hashset_1 : hset!{ "v1".to_string(), "v2".to_string(), "v3".to_string() }, }; a_id!( command, expected ); } @@ -285,16 +285,16 @@ tests_impls_optional! let command = Struct1::former() .vec_1().add( "ghi" ).add( "klm" ).end() - .hashmap_strings_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() - .hashset_strings_1().add( "k1" ).end() + .hashmap_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() + .hashset_1().add( "k1" ).end() .form(); // dbg!( &command ); let expected = Struct1 { vec_1 : vec![ "ghi".to_string(), "klm".to_string() ], - hashmap_strings_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, - hashset_strings_1 : hset!{ "k1".to_string() }, + hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, + hashset_1 : hset!{ "k1".to_string() }, }; a_id!( command, expected ); diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs index 990ae7e8cf..72b86f7fe0 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs @@ -15,8 +15,8 @@ tests_impls! let former = Struct1::former(); a_id!( former.storage.vec_1, None ); - a_id!( former.storage.hashmap_strings_1, None ); - a_id!( former.storage.hashset_strings_1, None ); + a_id!( former.storage.hashmap_1, None ); + a_id!( former.storage.hashset_1, None ); a_id!( former.context, None ); a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); let former2 = Struct1Former::< Struct1FormerDefinition >::new( the_module::ReturnPreformed ); @@ -24,18 +24,18 @@ tests_impls! let command = Struct1::former().form(); a_id!( command.vec_1, Vec::< String >::new() ); - a_id!( command.hashmap_strings_1, hmap!{} ); - a_id!( command.hashset_strings_1, hset![] ); + a_id!( command.hashmap_1, hmap!{} ); + a_id!( command.hashset_1, hset![] ); let command = Struct1::former().perform(); a_id!( command.vec_1, Vec::< String >::new() ); - a_id!( command.hashmap_strings_1, hmap!{} ); - a_id!( command.hashset_strings_1, hset![] ); + a_id!( command.hashmap_1, hmap!{} ); + a_id!( command.hashset_1, hset![] ); let command = Struct1::former().end(); a_id!( command.vec_1, Vec::< String >::new() ); - a_id!( command.hashmap_strings_1, hmap!{} ); - a_id!( command.hashset_strings_1, hset![] ); + a_id!( command.hashmap_1, hmap!{} ); + a_id!( command.hashset_1, hset![] ); } @@ -55,8 +55,8 @@ tests_impls! let expected = Struct1 { vec_1 : vec![ "ghi".to_string(), "klm".to_string() ], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{}, + hashset_1 : hset!{}, }; a_id!( command, expected ); } @@ -69,7 +69,7 @@ tests_impls! // test.case( "construction" ); let command = Struct1::former() - .hashmap_strings_1( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ) + .hashmap_1( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ) .form() ; // dbg!( &command ); @@ -77,8 +77,8 @@ tests_impls! let expected = Struct1 { vec_1 : vec![], - hashmap_strings_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, + hashset_1 : hset!{}, }; a_id!( command, expected ); } @@ -90,7 +90,7 @@ tests_impls! // test.case( "construction" ); let command = Struct1::former() - .hashset_strings_1( hset!{ "v1".to_string(), "v2".to_string() } ) + .hashset_1( hset!{ "v1".to_string(), "v2".to_string() } ) .form() ; // dbg!( &command ); @@ -98,8 +98,8 @@ tests_impls! let expected = Struct1 { vec_1 : vec![], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{ "v1".to_string(), "v2".to_string() }, + hashmap_1 : hmap!{}, + hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, }; a_id!( command, expected ); } @@ -115,8 +115,8 @@ tests_impls! let expected = Struct1 { vec_1 : vec![], - hashmap_strings_1 : hmap!{}, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{}, + hashset_1 : hset!{}, }; a_id!( command, expected ); } @@ -127,15 +127,15 @@ tests_impls! { let command = Struct1::former() .vec_1( vec![ "ghi".to_string(), "klm".to_string() ] ) - .hashmap_strings_1( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ) + .hashmap_1( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ) .form(); // dbg!( &command ); let expected = Struct1 { vec_1 : vec![ "ghi".to_string(), "klm".to_string() ], - hashmap_strings_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, - hashset_strings_1 : hset!{}, + hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, + hashset_1 : hset!{}, }; a_id!( command, expected ); diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 3b20fe8cd1..4d0aede6cf 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -535,7 +535,7 @@ tests_impls! .int_1( 13 ) .string_1( "Abcd".to_string() ) // .vec_1().push( "ghi" ).push( "klm" ).end() - // .hashmap_strings_1().insert( "k1", "v1" ).insert( "k2", "v2" ).end() + // .hashmap_1().insert( "k1", "v1" ).insert( "k2", "v2" ).end() .string_optional_1( "dir1" ) .form(); // dbg!( &command ); From b3f750d051f008f0ca84f3218cb8c6452f22715b Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 2 Apr 2024 12:45:48 +0300 Subject: [PATCH 107/533] former : experimenting --- module/core/former/src/hash_set.rs | 3 +- .../a_containers_with_subformer_manual.rs | 37 +------------------ 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index ca26ad27eb..bf65f0229c 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -119,7 +119,8 @@ where /// ``` // xxx : update documentation -// pub type HashSetSubformer< K, Context, End > = ContainerSubformer::< K, HashSetDefinition< K, Context, End > >; +// write: instead of writing long version with ContainerSubformer it's possible to be more concise with help of the type alias +// pub type HashSetSubformer< K, Context, Formed, End > = ContainerSubformer::< K, HashSetDefinition< K, Context, Formed, End > >; diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 1959d449b9..44317f1a6d 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -349,41 +349,6 @@ where >>() } -// #[ inline( always ) ] -// pub fn vec_1_set< Former2 >( self ) -> Former2 -// where -// Former2 : former::FormerBegin -// < -// former::VectorDefinition -// < -// String, -// Self, -// Self, -// __vec_1_end, -// > -// >, -// { -// Former2::_begin( None, Some( self ), __vec_1_end ) -// } -// -// pub fn vec_1( self ) -> -// former::VectorSubformer:: -// < -// String, -// Self, -// Self, -// __vec_1_end, -// > -// { -// self.vec_1_set::< former::VectorSubformer:: -// < -// String, -// Self, -// Self, -// __vec_1_end, -// > >() -// } - #[ inline( always ) ] pub fn hashmap_1_set< Former2 >( self ) -> Former2 where @@ -411,7 +376,7 @@ where self.hashmap_1_set::< former::ContainerSubformer:: < ( String, String ), former::HashMapDefinition< String, String, Self, Self, __hashmap_1_end > - >>() + > >() } #[ inline( always ) ] From 27021d6838cd1f0c15264a7406435d7528a670cb Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 5 Apr 2024 09:56:59 +0300 Subject: [PATCH 108/533] former : experimenting --- .../a_containers_with_subformer_2_manual.rs | 588 +++++++++--------- .../a_containers_with_subformer_manual.rs | 36 +- .../only_test/containers_with_subformer.rs | 11 + 3 files changed, 323 insertions(+), 312 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs index 3332a2f999..4dd9293b71 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs @@ -1,298 +1,298 @@ -#[ allow( unused_imports ) ] -use super::*; - -// xxx : take care - -#[ derive( Debug, PartialEq ) ] -pub struct Struct1 -{ - vec_1 : Vec< String >, - hashmap_1 : std::collections::HashMap< String, String >, - hashset_1 : std::collections::HashSet< String >, -} - -// = formed - -impl Struct1 -{ - pub fn former() -> Struct1Former< Struct1, the_module::ReturnPreformed > - { - Struct1Former::< Struct1, the_module::ReturnPreformed >::new() - } -} - -// = storage - -// generated by former -pub struct Struct1FormerStorage -{ - 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 > >, -} - -impl Default for Struct1FormerStorage -{ - - #[ inline( always ) ] - fn default() -> Self - { - Self - { - vec_1 : None, - hashmap_1 : None, - hashset_1 : None, - } - } - -} - -// = former - -pub struct Struct1Former -< - Context = Struct1, - End = the_module::ReturnPreformed, -> -where - End : the_module::FormingEnd< Struct1, Context >, -{ - storage : Struct1FormerStorage, - context : ::core::option::Option< Context >, - on_end : ::core::option::Option< End >, -} - -impl< Context, End > Struct1Former< Context, End > -where - End : the_module::FormingEnd< Struct1, Context >, -{ - - #[ inline( always ) ] - fn form( mut self ) -> Struct1 - { - - let vec_1 = if self.storage.vec_1.is_some() - { - self.storage.vec_1.take().unwrap() - } - else - { - let val : Vec< String > = Default::default(); - val - }; - - let hashmap_1 = if self.storage.hashmap_1.is_some() - { - self.storage.hashmap_1.take().unwrap() - } - else - { - let val : std::collections::HashMap< String, String > = Default::default(); - val - }; - - let hashset_1 = if self.storage.hashset_1.is_some() - { - self.storage.hashset_1.take().unwrap() - } - else - { - let val : std::collections::HashSet< String > = Default::default(); - val - }; - - Struct1 - { - vec_1, - hashmap_1, - hashset_1, - } - - } - - #[ inline( always ) ] - pub fn perform(self) -> Struct1 - { - let result = self.form(); - return result; - } - - // #[ inline( always ) ] - // pub fn new() -> Struct1Former - // { - // Struct1Former:: - // < - // Struct1, - // the_module::ReturnPreformed, - // >::begin(None, the_module::ReturnPreformed) - // } - - #[ inline( always ) ] - pub fn begin - ( - mut storage : ::core::option::Option< Struct1FormerStorage >, - context : ::core::option::Option< Context >, - on_end : End, - ) -> Self - { - if storage.is_none() - { - storage = Some( Default::default() ); - } - Self - { - storage : storage.unwrap(), - context, - on_end : ::core::option::Option::Some( on_end ), - } - } - - #[ inline( always ) ] - pub fn end( mut self ) -> Context - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) - } - - #[ inline( always ) ] - pub fn __vec_1< Former2 >( self ) -> Former2 - where - Former2 : former::FormerBegin - < - Vec< String >, - Vec< String >, - Self, End = former::FormingEndClosure< Vec< String >, Self >, - >, - { - let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.vec_1 - { - former::ContainerAssign::assign( field, formed ); - } - else - { - super_former.storage.vec_1 = Some( formed ); - } - super_former - }; - Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) - } - - // xxx2 : continue - pub fn vec_1( self ) -> the_module::VectorSubformer - < - String, - Vec< String >, - Self, - impl the_module::FormingEnd< Vec< String >, Self >, - > - { - self.__vec_1::< the_module::VectorSubformer::< _, _, _, _ > >() - } - - // pub fn vec_1( mut self ) -> the_module::VectorSubformer - // < - // String, - // Vec< String >, - // Self, - // impl the_module::FormingEnd< Vec< String >, Self >, - // > - // { - // let formed = self.storage.vec_1.take(); - // let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self - // { - // let mut super_former = super_former.unwrap(); - // super_former.storage.vec_1 = Some( formed ); - // super_former - // }; - // the_module::VectorSubformer::< String, Vec< String >, Self, _ >::begin( Some( self ), formed, on_end ) - // } - - pub fn hashmap_1( mut self ) -> the_module::HashMapSubformer - < - String, - String, - std::collections::HashMap< String, String >, - Self, - impl the_module::FormingEnd< std::collections::HashMap< String, String >, Self >, - > - { - let formed = self.storage.hashmap_1.take(); - let on_end = | formed : std::collections::HashMap< String, String >, super_former : ::core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - super_former.storage.hashmap_1 = Some( formed ); - super_former - }; - the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) - } - - pub fn hashset_1( mut self ) -> the_module::HashSetSubformer - < - String, - std::collections::HashSet< String >, - Self, - impl the_module::FormingEnd< std::collections::HashSet< String >, Self >, - > - { - let formed = self.storage.hashset_1.take(); - let on_end = | formed : std::collections::HashSet< String >, super_former : ::core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - super_former.storage.hashset_1 = Some( formed ); - super_former - }; - the_module::HashSetSubformer::begin( formed, Some( self ), on_end ) - } - -} - -// impl< Context, End > Struct1Former< Context, End > +// #[ allow( unused_imports ) ] +// use super::*; +// +// // xxx : take care +// +// #[ derive( Debug, PartialEq ) ] +// pub struct Struct1 +// { +// vec_1 : Vec< String >, +// hashmap_1 : std::collections::HashMap< String, String >, +// hashset_1 : std::collections::HashSet< String >, +// } +// +// // = formed +// +// impl Struct1 +// { +// pub fn former() -> Struct1Former< Struct1, the_module::ReturnPreformed > +// { +// Struct1Former::< Struct1, the_module::ReturnPreformed >::new() +// } +// } +// +// // = storage +// +// // generated by former +// pub struct Struct1FormerStorage +// { +// 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 > >, +// } +// +// impl Default for Struct1FormerStorage +// { +// +// #[ inline( always ) ] +// fn default() -> Self +// { +// Self +// { +// vec_1 : None, +// hashmap_1 : None, +// hashset_1 : None, +// } +// } +// +// } +// +// // = former +// +// pub struct Struct1Former +// < +// Context = Struct1, +// End = the_module::ReturnPreformed, +// > // where -// End: the_module::FormingEnd, - -impl Struct1Former< Struct1, the_module::ReturnPreformed > -{ - - #[ inline( always ) ] - pub fn new() -> Self - { - Self::begin( None, None, the_module::ReturnPreformed ) - } - -} - -// - +// End : the_module::FormingEnd< Struct1, Context >, +// { +// storage : Struct1FormerStorage, +// context : ::core::option::Option< Context >, +// on_end : ::core::option::Option< End >, +// } +// // impl< Context, End > Struct1Former< Context, End > // where // End : the_module::FormingEnd< Struct1, Context >, - -impl< Context, End > former::FormerBegin< Struct1FormerStorage, Struct1, Context > -for Struct1Former< Context, End > -where - End : the_module::FormingEnd< Struct1, Context >, -{ - type End = End; - - #[ inline( always ) ] - fn _begin - ( - storage : core::option::Option< Struct1FormerStorage >, /* xxx2 : that should be storage */ - context : core::option::Option< Context >, - on_end : End, - ) -> Self - { - debug_assert!( storage.is_none() ); - Self::begin( None, context, on_end ) - } - -} - -// - -include!( "./only_test/containers_with_subformer.rs" ); +// { +// +// #[ inline( always ) ] +// fn form( mut self ) -> Struct1 +// { +// +// let vec_1 = if self.storage.vec_1.is_some() +// { +// self.storage.vec_1.take().unwrap() +// } +// else +// { +// let val : Vec< String > = Default::default(); +// val +// }; +// +// let hashmap_1 = if self.storage.hashmap_1.is_some() +// { +// self.storage.hashmap_1.take().unwrap() +// } +// else +// { +// let val : std::collections::HashMap< String, String > = Default::default(); +// val +// }; +// +// let hashset_1 = if self.storage.hashset_1.is_some() +// { +// self.storage.hashset_1.take().unwrap() +// } +// else +// { +// let val : std::collections::HashSet< String > = Default::default(); +// val +// }; +// +// Struct1 +// { +// vec_1, +// hashmap_1, +// hashset_1, +// } +// +// } +// +// #[ inline( always ) ] +// pub fn perform(self) -> Struct1 +// { +// let result = self.form(); +// return result; +// } +// +// // #[ inline( always ) ] +// // pub fn new() -> Struct1Former +// // { +// // Struct1Former:: +// // < +// // Struct1, +// // the_module::ReturnPreformed, +// // >::begin(None, the_module::ReturnPreformed) +// // } +// +// #[ inline( always ) ] +// pub fn begin +// ( +// mut storage : ::core::option::Option< Struct1FormerStorage >, +// context : ::core::option::Option< Context >, +// on_end : End, +// ) -> Self +// { +// if storage.is_none() +// { +// storage = Some( Default::default() ); +// } +// Self +// { +// storage : storage.unwrap(), +// context, +// on_end : ::core::option::Option::Some( on_end ), +// } +// } +// +// #[ inline( always ) ] +// pub fn end( mut self ) -> Context +// { +// let on_end = self.on_end.take().unwrap(); +// let context = self.context.take(); +// let formed = self.form(); +// on_end.call( formed, context ) +// } +// +// #[ inline( always ) ] +// pub fn __vec_1< Former2 >( self ) -> Former2 +// where +// Former2 : former::FormerBegin +// < +// Vec< String >, +// Vec< String >, +// Self, End = former::FormingEndClosure< Vec< String >, Self >, +// >, +// { +// let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self +// { +// let mut super_former = super_former.unwrap(); +// if let Some( ref mut field ) = super_former.storage.vec_1 +// { +// former::ContainerAssign::assign( field, formed ); +// } +// else +// { +// super_former.storage.vec_1 = Some( formed ); +// } +// super_former +// }; +// Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) +// } +// +// // xxx2 : continue +// pub fn vec_1( self ) -> the_module::VectorSubformer +// < +// String, +// Vec< String >, +// Self, +// impl the_module::FormingEnd< Vec< String >, Self >, +// > +// { +// self.__vec_1::< the_module::VectorSubformer::< _, _, _, _ > >() +// } +// +// // pub fn vec_1( mut self ) -> the_module::VectorSubformer +// // < +// // String, +// // Vec< String >, +// // Self, +// // impl the_module::FormingEnd< Vec< String >, Self >, +// // > +// // { +// // let formed = self.storage.vec_1.take(); +// // let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self +// // { +// // let mut super_former = super_former.unwrap(); +// // super_former.storage.vec_1 = Some( formed ); +// // super_former +// // }; +// // the_module::VectorSubformer::< String, Vec< String >, Self, _ >::begin( Some( self ), formed, on_end ) +// // } +// +// pub fn hashmap_1( mut self ) -> the_module::HashMapSubformer +// < +// String, +// String, +// std::collections::HashMap< String, String >, +// Self, +// impl the_module::FormingEnd< std::collections::HashMap< String, String >, Self >, +// > +// { +// let formed = self.storage.hashmap_1.take(); +// let on_end = | formed : std::collections::HashMap< String, String >, super_former : ::core::option::Option< Self > | -> Self +// { +// let mut super_former = super_former.unwrap(); +// super_former.storage.hashmap_1 = Some( formed ); +// super_former +// }; +// the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) +// } +// +// pub fn hashset_1( mut self ) -> the_module::HashSetSubformer +// < +// String, +// std::collections::HashSet< String >, +// Self, +// impl the_module::FormingEnd< std::collections::HashSet< String >, Self >, +// > +// { +// let formed = self.storage.hashset_1.take(); +// let on_end = | formed : std::collections::HashSet< String >, super_former : ::core::option::Option< Self > | -> Self +// { +// let mut super_former = super_former.unwrap(); +// super_former.storage.hashset_1 = Some( formed ); +// super_former +// }; +// the_module::HashSetSubformer::begin( formed, Some( self ), on_end ) +// } +// +// } +// +// // impl< Context, End > Struct1Former< Context, End > +// // where +// // End: the_module::FormingEnd, +// +// impl Struct1Former< Struct1, the_module::ReturnPreformed > +// { +// +// #[ inline( always ) ] +// pub fn new() -> Self +// { +// Self::begin( None, None, the_module::ReturnPreformed ) +// } +// +// } +// +// // +// +// // impl< Context, End > Struct1Former< Context, End > +// // where +// // End : the_module::FormingEnd< Struct1, Context >, +// +// impl< Context, End > former::FormerBegin< Struct1FormerStorage, Struct1, Context > +// for Struct1Former< Context, End > +// where +// End : the_module::FormingEnd< Struct1, Context >, +// { +// type End = End; +// +// #[ inline( always ) ] +// fn _begin +// ( +// storage : core::option::Option< Struct1FormerStorage >, /* xxx2 : that should be storage */ +// context : core::option::Option< Context >, +// on_end : End, +// ) -> Self +// { +// debug_assert!( storage.is_none() ); +// Self::begin( None, context, on_end ) +// } +// +// } +// +// // +// +// include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 44317f1a6d..e1eef17936 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -330,22 +330,22 @@ where String, Self, Self, - __vec_1_end, + Struct1FormerVec_1End, > >, { - Former2::_begin( None, Some( self ), __vec_1_end ) + Former2::_begin( None, Some( self ), Struct1FormerVec_1End ) } pub fn vec_1( self ) -> former::ContainerSubformer:: < - String, former::VectorDefinition< String, Self, Self, __vec_1_end > + String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > > { self.vec_1_set::< former::ContainerSubformer:: < - String, former::VectorDefinition< String, Self, Self, __vec_1_end > + String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > >>() } @@ -360,22 +360,22 @@ where String, Self, Self, - __hashmap_1_end, + Struct1FormerHashmap_1End, > >, { - Former2::_begin( None, Some( self ), __hashmap_1_end ) + Former2::_begin( None, Some( self ), Struct1FormerHashmap_1End ) } pub fn hashmap_1( self ) -> former::ContainerSubformer:: < - ( String, String ), former::HashMapDefinition< String, String, Self, Self, __hashmap_1_end > + ( String, String ), former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap_1End > > { self.hashmap_1_set::< former::ContainerSubformer:: < - ( String, String ), former::HashMapDefinition< String, String, Self, Self, __hashmap_1_end > + ( String, String ), former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap_1End > > >() } @@ -389,22 +389,22 @@ where String, Self, Self, - __hashset_1_end, + Struct1FormerHashset_1End, > >, { - Former2::_begin( None, Some( self ), __hashset_1_end ) + Former2::_begin( None, Some( self ), Struct1FormerHashset_1End ) } pub fn hashset_1( self ) -> former::ContainerSubformer:: < - String, former::HashSetDefinition< String, Self, Self, __hashset_1_end > + String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset_1End > > { self.hashset_1_set::< former::ContainerSubformer:: < - String, former::HashSetDefinition< String, Self, Self, __hashset_1_end > + String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset_1End > >>() } @@ -425,13 +425,13 @@ where // zzz : description /// Return original former after subformer for `vec_1` is done. #[ allow( non_camel_case_types ) ] -pub struct __vec_1_end; +pub struct Struct1FormerVec_1End; #[ automatically_derived ] impl< Definition > former::FormingEnd < former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > -for __vec_1_end +for Struct1FormerVec_1End where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes @@ -458,13 +458,13 @@ where // zzz : description /// Return original former after subformer for `hashmap_string_1` is done. #[ allow( non_camel_case_types ) ] -pub struct __hashmap_1_end; +pub struct Struct1FormerHashmap_1End; #[ automatically_derived ] impl< Definition > former::FormingEnd < former::HashMapDefinition< String, String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > -for __hashmap_1_end +for Struct1FormerHashmap_1End where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes @@ -491,13 +491,13 @@ where // zzz : description /// Return original former after subformer for `hashset_string_1` is done. #[ allow( non_camel_case_types ) ] -pub struct __hashset_1_end; +pub struct Struct1FormerHashset_1End; #[ automatically_derived ] impl< Definition > former::FormingEnd < former::HashSetDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > -for __hashset_1_end +for Struct1FormerHashset_1End where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index a161ec02c5..0e8a90a361 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -90,6 +90,17 @@ tests_impls_optional! // + fn end_descriptors() + { + + let _got = Struct1FormerVec_1End::new(); + let _got = Struct1FormerHashmap_1End::new(); + let _got = Struct1FormerHashset_1End::new(); + + } + + // + fn test_vector() { From 12c258b00d654d0f9f81e904de9bdcf9c9934d32 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 6 Apr 2024 11:02:50 +0300 Subject: [PATCH 109/533] former : experimenting --- .../a_containers_with_subformer.rs | 379 +++++++++++++++++- module/core/former/tests/inc/mod.rs | 4 +- module/core/former_meta/src/derive/former.rs | 2 +- 3 files changed, 376 insertions(+), 9 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 5a4c492d11..b33801ad92 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -4,17 +4,384 @@ use super::*; // use std::collections::HashMap; // use std::collections::HashSet; -#[ derive( Debug, PartialEq, the_module::Former ) ] -#[ debug ] +// #[ derive( Debug, PartialEq, former::Former ) ] +// #[ debug ] +#[ derive( Debug, PartialEq ) ] pub struct Struct1 { - #[ subformer( the_module::VectorSubformer ) ] + // #[ subformer( former::VectorSubformer ) ] vec_1 : Vec< String >, - #[ subformer( the_module::HashMapSubformer ) ] + // #[ subformer( former::HashMapSubformer ) ] hashmap_1 : std::collections::HashMap< String, String >, - #[ subformer( the_module::HashSetSubformer ) ] + // #[ subformer( former::HashSetSubformer ) ] hashset_1 : std::collections::HashSet< String >, } +// = generated + +#[ automatically_derived ] +impl Struct1 +{ + #[ doc = r"" ] + #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn former() -> Struct1Former< > + { + Struct1Former::<>::new( former::ReturnPreformed ) + } +} + +#[ derive( Debug ) ] +pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > +{ + _phantom : core::marker::PhantomData< ( Context, Formed ) >, +} + +impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > +{ + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} + +#[ derive( Debug ) ] +pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +{ + _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, +} + +impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > +{ + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} + +impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > +{ + type Storage = Struct1FormerStorage; + type Formed = Formed; + type Context = Context; +} + +impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > +where + End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, +{ + type Types = Struct1FormerDefinitionTypes< Context, Formed >; + type End = End; +} + +pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; + +#[ doc = "Container of a corresponding former." ] +pub struct Struct1FormerStorage +{ + #[ doc = r" A field" ] + pub vec_1 : ::core::option::Option< Vec< String > >, + + #[ doc = r" A field" ] + pub hashmap_1 : ::core::option::Option< std::collections::HashMap< String, String > >, + + #[ doc = r" A field" ] + pub hashset_1 : ::core::option::Option< std::collections::HashSet< String > >, +} + +impl ::core::default::Default for Struct1FormerStorage +{ + #[ inline( always ) ] + fn default() -> Self + { + Self + { + vec_1 : ::core::option::Option::None, + hashmap_1 : ::core::option::Option::None, + hashset_1 : ::core::option::Option::None, + } + } +} + +impl former::Storage for Struct1FormerStorage +{ + type Formed = Struct1; +} + +impl former::StoragePreform for Struct1FormerStorage +{ + fn preform( mut self ) -> < Self as former::Storage >::Formed + { + let vec_1 = if self.vec_1.is_some() + { + self.vec_1.take().unwrap() + } + else + { + { + trait MaybeDefault< T > + { + fn maybe_default( self : &Self ) -> T + { + panic!( "Field 'vec_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< Vec< String > > ).maybe_default() + } + }; + let hashmap_1 = if self.hashmap_1.is_some() + { + self.hashmap_1.take().unwrap() + } + else + { + { + trait MaybeDefault< T > + { + fn maybe_default( self : &Self ) -> T + { + panic!( "Field 'hashmap_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< std::collections::HashMap< String, String > > ).maybe_default() + } + }; + let hashset_1 = if self.hashset_1.is_some() + { + self.hashset_1.take().unwrap() + } + else + { + { + trait MaybeDefault< T > + { + fn maybe_default( self : &Self ) -> T + { + panic!( "Field 'hashset_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< std::collections::HashSet< String > > ).maybe_default() + } + }; + let result = Struct1 + { + vec_1, + hashmap_1, + hashset_1, + }; + return result; + } +} + +#[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[ default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] +pub struct Struct1Former< Definition = Struct1FormerDefinition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +{ + storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : core::option::Option< Definition::End >, +} + +#[ automatically_derived ] +impl< Definition > Struct1Former< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +{ + #[ doc = r"" ] + #[ doc = r" Finish setting options and call perform on formed entity." ] + #[ doc = r"" ] + #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] + #[ doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str ) ]` returns `&str`." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + let result = self.form(); + return result; + } + + #[ doc = r"" ] + #[ doc = r" Construct new instance of former with default parameters." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn _new_precise( on_end : Definition::End ) -> Self + { + Self::begin( None, None, on_end ) + } + + #[ doc = r"" ] + #[ doc = r" Construct new instance of former with default parameters." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn new< IntoEnd >( end : IntoEnd ) -> Self + where + IntoEnd : Into< Definition::End >, + { + Self::begin( None, None, end, ) + } + + #[ doc = r"" ] + #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn _begin_precise( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : < Definition as former::FormerDefinition >::End, + ) -> Self + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some( on_end ), + } + } + + #[ doc = r"" ] + #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn begin< IntoEnd >( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : IntoEnd, + ) -> Self + where + IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), + } + } + + #[ doc = r"" ] + #[ doc = r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + self.end() + } + + #[ doc = r"" ] + #[ doc = r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) + } + + // #[ doc = "Subformer setter for the 'vec_1' field." ] + // #[ inline ] + // pub fn vec_1( mut self ) -> former::VectorSubformer< String, Vec< String >, Self, impl Fn( Vec< String >, core::option::Option< Self > ) -> Self, > + // { + // let formed = self.storage.vec_1.take(); + // let on_end = | formed : Vec< String >, former : core::option::Option< Self > | -> Self + // { + // let mut former = former.unwrap(); + // former.storage.vec_1 = Some( formed ); + // former + // }; + // former::VectorSubformer::begin( formed, Some( self ), on_end ) + // } + +// #[ doc = "Subformer setter for the 'hashmap_1' field." ] +// #[ inline ] +// pub fn hashmap_1( mut self ) -> former::HashMapSubformer< String, String, std::collections::HashMap< String, String >, Self, impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self, > +// { +// let formed = self.storage.hashmap_1.take(); +// let on_end = | formed : std::collections::HashMap< String, String >, former : core::option::Option< Self > | -> Self +// { +// let mut former = former.unwrap(); +// former.storage.hashmap_1 = Some( formed ); +// former +// }; +// former::HashMapSubformer::begin( formed, Some( self ), on_end ) +// } +// +// #[ doc = "Subformer setter for the 'hashset_1' field." ] +// #[ inline ] +// pub fn hashset_1( mut self ) -> former::HashSetSubformer< String, std::collections::HashSet< String >, Self, impl Fn( std::collections::HashSet< String >, core::option::Option< Self > ) -> Self, > +// { +// let formed = self.storage.hashset_1.take(); +// let on_end = | formed : std::collections::HashSet< String >, former : core::option::Option< Self > | -> Self +// { +// let mut former = former.unwrap(); +// former.storage.hashset_1 = Some( formed ); +// former +// }; +// former::HashSetSubformer::begin( formed, Some( self ), on_end ) +// } + +} + +impl< Definition > Struct1Former< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +{ + pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + former::StoragePreform::preform( self.storage ) + } +} + +// = generated + // include!( "./only_test/containers_with_subformer.rs" ); -// xxx : uncomment \ No newline at end of file +// xxx : uncomment diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 0483e2a4eb..918c16ab7b 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -22,8 +22,8 @@ mod former_tests mod a_containers_without_subformer; #[ cfg( not( feature = "no_std" ) ) ] mod a_containers_with_subformer_manual; - // #[ cfg( not( feature = "no_std" ) ) ] - // mod a_containers_with_subformer ; + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer ; // mod attribute_default_container; // mod attribute_default_primitive; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 1025c4c795..fa57b6c3ca 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -948,7 +948,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ inline( always ) ] pub fn former() -> #former < #generics_params > { - #former :: < #generics_params > :: new( the_module::ReturnPreformed ) + #former :: < #generics_params > :: new( former::ReturnPreformed ) } } From 999db8f2df4f72bea8e181d93b2ba90545399da1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 6 Apr 2024 12:02:55 +0300 Subject: [PATCH 110/533] former : experimenting --- .../a_containers_with_subformer.rs | 62 ++++++++ .../a_containers_with_subformer_manual.rs | 8 +- module/core/former_meta/src/derive/former.rs | 139 ++++++++++++++++-- 3 files changed, 195 insertions(+), 14 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index b33801ad92..95345db37b 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -339,6 +339,35 @@ where // former::VectorSubformer::begin( formed, Some( self ), on_end ) // } + #[ inline( always ) ] + pub fn vec_1_set< Former2 >( self ) -> Former2 + where + Former2 : former::FormerBegin + < + former::VectorDefinition + < + String, + Self, + Self, + Struct1FormerVec_1End, + > + >, + { + Former2::_begin( None, Some( self ), Struct1FormerVec_1End ) + } + + pub fn vec_1( self ) -> + former::ContainerSubformer:: + < + String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > + > + { + self.vec_1_set::< former::ContainerSubformer:: + < + String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > + >>() + } + // #[ doc = "Subformer setter for the 'hashmap_1' field." ] // #[ inline ] // pub fn hashmap_1( mut self ) -> former::HashMapSubformer< String, String, std::collections::HashMap< String, String >, Self, impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self, > @@ -381,6 +410,39 @@ where } } +// zzz : description +/// Return original former after subformer for `vec_1` is done. +#[ allow( non_camel_case_types ) ] +pub struct Struct1FormerVec_1End; +#[ automatically_derived ] +impl< Definition > former::FormingEnd +< + former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, +> +for Struct1FormerVec_1End +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 > + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.vec_1 + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.vec_1 = Some( storage ); + } + super_former + } +} + // = generated // include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index e1eef17936..d361d5f070 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -473,7 +473,13 @@ where >, { #[ inline( always ) ] - fn call( &self, storage : std::collections::HashMap< String, String >, super_former : Option< Struct1Former< Definition > > ) -> Struct1Former< Definition > + fn call + ( + &self, + storage : std::collections::HashMap< String, String >, + super_former : Option< Struct1Former< Definition > >, + ) + -> Struct1Former< Definition > { let mut super_former = super_former.unwrap(); if let Some( ref mut field ) = super_former.storage.hashmap_1 diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index fa57b6c3ca..c75631b19c 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -29,7 +29,6 @@ struct Attributes { default : Option< AttributeDefault >, setter : Option< AttributeSetter >, - // #[ allow( dead_code ) ] subformer : Option< AttributeFormer >, alias : Option< AttributeAlias >, } @@ -494,7 +493,8 @@ fn field_name_map( field : &FormerField< '_ > ) -> syn::Ident /// /// If aliases provided, also generate aliases /// -/// # Example of output +/// # Example of generated code +/// /// ```ignore /// #[ doc = "Setter for the 'int_1' field." ] /// #[ inline ] @@ -537,7 +537,6 @@ fn field_setter_map( field : &FormerField< '_ > ) -> Result< TokenStream > let setter_tokens = if let Some( subformer_ty ) = &field.attrs.subformer { subformer_field_setter( ident, ident, non_optional_ty, &subformer_ty.expr ) - // field_setter( ident, ident, non_optional_ty ) } else { @@ -563,12 +562,123 @@ fn field_setter_map( field : &FormerField< '_ > ) -> Result< TokenStream > r } +// zzz : description and exmaple + +/// Generate unit struct which is descriptor of callback which should be called after subforming process of a specific field. Descriptors are used insted of closures to inline code and let optimizer play with optimization. +/// +/// # Example of generated code +/// +/// ```rust, ignore +/// #[ allow( non_camel_case_types ) ] +/// pub struct Struct1FormerVec_1End; +/// #[ automatically_derived ] +/// impl< Definition > former::FormingEnd +/// < +/// former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, +/// > +/// for Struct1FormerVec_1End +/// 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 > +/// { +/// let mut super_former = super_former.unwrap(); +/// if let Some( ref mut field ) = super_former.storage.vec_1 +/// { +/// former::ContainerAssign::assign( field, storage ); +/// } +/// else +/// { +/// super_former.storage.vec_1 = Some( storage ); +/// } +/// super_former +/// } +/// } +/// ``` + +#[ inline ] +fn fields_setter_callback_descriptor_map +( + field : &FormerField< '_ >, + former : &syn::Ident, + former_storage : &syn::Ident, + former_definition : &syn::Ident, +) +-> +Result< TokenStream > +{ + let ident = &field.ident; + + if field.attrs.subformer.is_none() + { + return Ok( qt!{ } ); + } + + + let r = qt! + { + xxx + + // zzz : description + /// Return original former after subformer for `vec_1` is done. + #[ allow( non_camel_case_types ) ] + pub struct Struct1FormerVec_1End; + #[ automatically_derived ] + impl< Definition > former::FormingEnd + < + former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, + > + for Struct1FormerVec_1End + 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 > + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.vec_1 + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.vec_1 = Some( storage ); + } + super_former + } + } + + }; + + // tree_print!( r.as_ref().unwrap() ); + Ok( r ) +} + /// /// Generate a single setter for the 'field_ident' with the 'setter_name' name. /// /// Used as a helper function for field_setter_map(), which generates all alias setters /// -/// # Example of output +/// # Example of generated code /// ```ignore /// #[ doc = "Setter for the 'int_1' field." ] /// #[ inline ] @@ -910,8 +1020,17 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_fields : Vec< _ > = process_results( former_fields, | iter | iter.collect() )?; - let ( fields_none, fields_optional, fields_form, fields_names, fields_setter ) - : ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) + let + ( + fields_none, + fields_optional, + fields_form, + fields_names, + fields_setter, + fields_setter_callback_descriptor, + ) + : + ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) = former_fields.iter().map( | former_field | {( field_none_map( former_field ), @@ -919,6 +1038,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field_form_map( former_field ), field_name_map( former_field ), field_setter_map( former_field ), + fields_setter_callback_descriptor_map( former_field, &former, &former_storage, &former_definition ), )}).multiunzip(); let ( _doc_former_mod, doc_former_struct ) = doc_generate( struct_name ); @@ -938,13 +1058,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// Make former, variation of builder pattern to form structure defining values of fields step by step. /// - // #[ inline( always ) ] - // // pub fn former() -> #former < #generics_params (), former::ReturnPreformed > - // pub fn former() -> #former < #generics_params > - // { - // #former :: new() - // } - #[ inline( always ) ] pub fn former() -> #former < #generics_params > { From 93f26e44b3aaab128219dca8efc21506ca304518 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 6 Apr 2024 20:20:23 +0300 Subject: [PATCH 111/533] former : experimenting --- module/core/former_meta/Cargo.toml | 2 +- module/core/former_meta/src/derive/former.rs | 29 ++++++++++++++------ module/core/macro_tools/src/generics.rs | 27 +++++++++++++++--- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/module/core/former_meta/Cargo.toml b/module/core/former_meta/Cargo.toml index d5b80364a1..87f531a9f9 100644 --- a/module/core/former_meta/Cargo.toml +++ b/module/core/former_meta/Cargo.toml @@ -46,7 +46,7 @@ full = [ ] enabled = [ "macro_tools/enabled", "iter_tools/enabled" ] -derive_former = [] +derive_former = [ "convert_case" ] derive_components = [] derive_component_assign = [] derive_components_assign = [ "derive_components", "derive_component_assign", "convert_case" ] diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index c75631b19c..8a816eb9bc 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -617,42 +617,53 @@ fn fields_setter_callback_descriptor_map -> Result< TokenStream > { - let ident = &field.ident; if field.attrs.subformer.is_none() { return Ok( qt!{ } ); } + use convert_case::{ Case, Casing }; + + let ident = field.ident; + let field_descriptor_name = format!( "former{}End", ident.to_string().to_case( Case::Camel ) ); + let field_descriptor = syn::Ident::new( &field_descriptor_name, ident.span() ); + + let field_ty = field.non_optional_ty; + // let xxx = field_ty; + // let generics = field_ty.generics + // let ( generics_impl, generics_ty, generics_where ) = generics.split_for_impl(); + let r = qt! { - xxx + // xxx // zzz : description /// Return original former after subformer for `vec_1` is done. #[ allow( non_camel_case_types ) ] - pub struct Struct1FormerVec_1End; + pub struct #field_descriptor; #[ automatically_derived ] impl< Definition > former::FormingEnd < - former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, + former::VectorDefinition< String, #former< Definition >, #former< Definition >, former::NoEnd >, > - for Struct1FormerVec_1End + for #field_descriptor where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes < - Storage = Struct1FormerStorage + Storage = #former_storage >, { #[ inline( always ) ] fn call ( - &self, storage : Vec< String >, - super_former : Option< Struct1Former< Definition > >, + &self, + storage : field_ty, + super_former : Option< #former< Definition > >, ) - -> Struct1Former< Definition > + -> #former< Definition > { let mut super_former = super_former.unwrap(); if let Some( ref mut field ) = super_former.storage.vec_1 diff --git a/module/core/macro_tools/src/generics.rs b/module/core/macro_tools/src/generics.rs index 63f8496495..05810d7943 100644 --- a/module/core/macro_tools/src/generics.rs +++ b/module/core/macro_tools/src/generics.rs @@ -183,6 +183,23 @@ pub( crate ) mod private result } + /// Extract generics from a type. + pub fn extract_from_type( type_example : &syn::Type ) -> Option< syn::PathArguments > + { + if let syn::Type::Path( type_path ) = type_example + { + let segments = &type_path.path.segments; + let last_segment = segments.last()?; + + if let syn::PathArguments::AngleBracketed( generics ) = &last_segment.arguments + { + return Some( generics.clone() ); + } + } + None + } + + } #[ doc( inline ) ] @@ -197,10 +214,12 @@ pub mod protected pub use super::orphan::*; #[ doc( inline ) ] #[ allow( unused_imports ) ] - pub use super::private::merge; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - pub use super::private::params_names; + pub use super::private:: + { + merge, + params_names, + extract_from_type, + }; } /// Orphan namespace of the module. From c145cefc327a20b84db095872858eae098333d81 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 10 Apr 2024 14:38:51 +0300 Subject: [PATCH 112/533] former : experimenting --- module/core/macro_tools/src/generics.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/module/core/macro_tools/src/generics.rs b/module/core/macro_tools/src/generics.rs index 05810d7943..43aa92b40b 100644 --- a/module/core/macro_tools/src/generics.rs +++ b/module/core/macro_tools/src/generics.rs @@ -184,7 +184,10 @@ pub( crate ) mod private } /// Extract generics from a type. - pub fn extract_from_type( type_example : &syn::Type ) -> Option< syn::PathArguments > + // pub fn extract_from_type( type_example : &syn::Type ) -> Option< syn::PathArguments > + pub fn extract_from_type( type_example : &syn::Type ) + -> + Option< syn::punctuated::Punctuated< syn::GenericArgument, syn::token::Comma > > { if let syn::Type::Path( type_path ) = type_example { @@ -193,7 +196,7 @@ pub( crate ) mod private if let syn::PathArguments::AngleBracketed( generics ) = &last_segment.arguments { - return Some( generics.clone() ); + return Some( generics.args.clone() ); } } None From 19427e99d7d5c2bf4426d9d85980699ab5cbf234 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 10 Apr 2024 17:30:12 +0300 Subject: [PATCH 113/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 351 ++++++++++++------- module/core/macro_tools/src/generics.rs | 21 -- module/core/macro_tools/src/typ.rs | 21 +- 3 files changed, 241 insertions(+), 152 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 8a816eb9bc..705f75ea7a 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -202,6 +202,7 @@ impl syn::parse::Parse for AttributeSetter /// /// `#[ subformer( former::VectorSubformer ) ]` /// +// qqq : update documentation #[ allow( dead_code ) ] struct AttributeFormer @@ -536,7 +537,8 @@ fn field_setter_map( field : &FormerField< '_ > ) -> Result< TokenStream > // Either subformer or ordinary setter. let setter_tokens = if let Some( subformer_ty ) = &field.attrs.subformer { - subformer_field_setter( ident, ident, non_optional_ty, &subformer_ty.expr ) + // subformer_field_setter( ident, ident, non_optional_ty, &subformer_ty.expr ) + subformer_field_setter( field, &subformer_ty.expr ) } else { @@ -562,8 +564,206 @@ fn field_setter_map( field : &FormerField< '_ > ) -> Result< TokenStream > r } -// zzz : description and exmaple +/// +/// Generate a single setter for the 'field_ident' with the 'setter_name' name. +/// +/// Used as a helper function for field_setter_map(), which generates all alias setters +/// +/// # Example of generated code +/// ```ignore +/// #[ doc = "Setter for the 'int_1' field." ] +/// #[ inline ] +/// pub fn int_1< Src >( mut self, src : Src ) -> Self +/// where +/// Src : ::core::convert::Into< i32 >, +/// { +/// debug_assert!( self.int_1.is_none() ); +/// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); +/// self +/// } +/// ``` + +#[ inline ] +fn field_setter +( + field_ident : &syn::Ident, + setter_name : &syn::Ident, + non_optional_type : &syn::Type, +) +-> TokenStream +{ + let doc = format! + ( + "Setter for the '{}' field.", + field_ident, + ); + + qt! + { + #[ doc = #doc ] + #[ inline ] + pub fn #setter_name< Src >( mut self, src : Src ) -> Self + where Src : ::core::convert::Into< #non_optional_type >, + { + debug_assert!( self.storage.#field_ident.is_none() ); + self.storage.#field_ident = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + self + } + } +} + +/// +/// Generate a sub-former setter for the 'field_ident' with the 'setter_name' name. +/// +/// # Example of generated code +/// +/// ```ignore +/// pub fn hashmap_strings_1( mut self ) -> former::HashMapSubformer +/// < +/// String, +/// String, +/// std::collections::HashMap< String, String >, +/// Struct1Former, +/// impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self +/// > +/// { +/// let formed = self.hashmap_strings_1.take(); +/// let on_end = | formed : std::collections::HashMap< String, String >, mut former : core::option::Option< Self > | -> Self +/// { +/// former.hashmap_strings_1 = Some( formed ); +/// former +/// }; +/// former::HashMapSubformer::begin( formed, self, on_end ) +/// } +/// ``` +/// zzz : update example + +#[ inline ] +fn subformer_field_setter +( + field : &FormerField< '_ >, + // field_ident : &syn::Ident, + // setter_name : &syn::Ident, + // non_optional_type : &syn::Type, + subformer_type : &syn::Type, +) +-> TokenStream +{ + let field_ident = &field.ident; + let doc = format! + ( + "Subformer setter for the '{}' field.", + field_ident + ); + + let non_optional_ty = &field.non_optional_ty; + + // tree_print!( non_optional_type ); + // code_print!( non_optional_type ); + let params = typ::type_parameters( &non_optional_ty, .. ); + // params.iter().for_each( | e | println!( "{}", qt!( #e ) ) ); + // let genertic_params = typ::all_type_parameters( non_optional_type ); + // xxx : try `all_type_parameters`` instead + + let subformer_definition = &field.attrs.subformer.as_ref().unwrap().expr; + // for example : former::VectorDefinition + + use convert_case::{ Case, Casing }; + // let ident = field_ident; + let field_forming_end_name = format!( "former{}End", field_ident.to_string().to_case( Case::Camel ) ); + let field_forming_end = syn::Ident::new( &field_forming_end_name, field_ident.span() ); + let field_set_name = format!( "{}_set", field_ident ); + let field_set = syn::Ident::new( &field_forming_end_name, field_ident.span() ); + + qt! + { + #[ inline( always ) ] + pub fn #field_set< Former2 >( self ) -> Former2 + where + Former2 : former::FormerBegin + < + #subformer_definition + < + #( #params, )*, + Self, + Self, + #field_set, + > + >, + { + Former2::_begin( None, Some( self ), #field_set ) + } + + pub fn #field_ident( self ) -> + former::ContainerSubformer:: + < + #( #params, )*, #subformer_definition< #( #params, )*, Self, Self, #field_set > + > + { + self.#field_set::< former::ContainerSubformer:: + < + #( #params, )*, #subformer_definition< #( #params, )*, Self, Self, #field_set > + >>() + } + + } + + // qt! + // { + // #[ doc = #doc ] + // #[ inline ] + // pub fn #setter_name( mut self ) -> #subformer_type + // < + // #( #params, )* + // #non_optional_type, + // Self, + // impl Fn( #non_optional_type, core::option::Option< Self > ) -> Self, + // > + // { + // let formed = self.storage.#setter_name.take(); + // let on_end = | formed : #non_optional_type, former : core::option::Option< Self > | -> Self + // { + // let mut former = former.unwrap(); + // former.storage.#setter_name = Some( formed ); + // former + // }; + // #subformer_type::begin( formed, Some( self ), on_end ) + // } + // } + +// #[ inline( always ) ] +// pub fn vec_1_set< Former2 >( self ) -> Former2 +// where +// Former2 : former::FormerBegin +// < +// former::VectorDefinition +// < +// String, +// Self, +// Self, +// Struct1FormerVec_1End, +// > +// >, +// { +// Former2::_begin( None, Some( self ), Struct1FormerVec_1End ) +// } +// +// pub fn vec_1( self ) -> +// former::ContainerSubformer:: +// < +// String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > +// > +// { +// self.vec_1_set::< former::ContainerSubformer:: +// < +// String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > +// >>() +// } + +} + +// zzz : description and exmaple /// Generate unit struct which is descriptor of callback which should be called after subforming process of a specific field. Descriptors are used insted of closures to inline code and let optimizer play with optimization. /// /// # Example of generated code @@ -623,18 +823,22 @@ Result< TokenStream > return Ok( qt!{ } ); } - use convert_case::{ Case, Casing }; + let subformer = field.attrs.subformer.as_ref().unwrap(); + // former::VectorSubformer + // former::VectorDefinition + // xxx + use convert_case::{ Case, Casing }; let ident = field.ident; - let field_descriptor_name = format!( "former{}End", ident.to_string().to_case( Case::Camel ) ); - let field_descriptor = syn::Ident::new( &field_descriptor_name, ident.span() ); + let field_forming_end_name = format!( "former{}End", ident.to_string().to_case( Case::Camel ) ); + let field_forming_end = syn::Ident::new( &field_forming_end_name, ident.span() ); let field_ty = field.non_optional_ty; + let field_set = typ::all_type_parameters( field_ty ); // let xxx = field_ty; // let generics = field_ty.generics // let ( generics_impl, generics_ty, generics_where ) = generics.split_for_impl(); - let r = qt! { // xxx @@ -642,13 +846,14 @@ Result< TokenStream > // zzz : description /// Return original former after subformer for `vec_1` is done. #[ allow( non_camel_case_types ) ] - pub struct #field_descriptor; + pub struct #field_forming_end; #[ automatically_derived ] impl< Definition > former::FormingEnd < - former::VectorDefinition< String, #former< Definition >, #former< Definition >, former::NoEnd >, + former::VectorDefinition< #field_set, #former< Definition >, #former< Definition >, former::NoEnd >, + // xxx : what is there is no generic parameters? > - for #field_descriptor + for #field_forming_end where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes @@ -666,13 +871,13 @@ Result< TokenStream > -> #former< Definition > { let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.vec_1 + if let Some( ref mut field ) = super_former.storage.#ident { former::ContainerAssign::assign( field, storage ); } else { - super_former.storage.vec_1 = Some( storage ); + super_former.storage.#ident = Some( storage ); } super_former } @@ -684,125 +889,6 @@ Result< TokenStream > Ok( r ) } -/// -/// Generate a single setter for the 'field_ident' with the 'setter_name' name. -/// -/// Used as a helper function for field_setter_map(), which generates all alias setters -/// -/// # Example of generated code -/// ```ignore -/// #[ doc = "Setter for the 'int_1' field." ] -/// #[ inline ] -/// pub fn int_1< Src >( mut self, src : Src ) -> Self -/// where -/// Src : ::core::convert::Into< i32 >, -/// { -/// debug_assert!( self.int_1.is_none() ); -/// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); -/// self -/// } -/// ``` - -#[ inline ] -fn field_setter -( - field_ident : &syn::Ident, - setter_name : &syn::Ident, - non_optional_type : &syn::Type, -) --> TokenStream -{ - let doc = format! - ( - "Setter for the '{}' field.", - field_ident, - ); - - qt! - { - #[ doc = #doc ] - #[ inline ] - pub fn #setter_name< Src >( mut self, src : Src ) -> Self - where Src : ::core::convert::Into< #non_optional_type >, - { - debug_assert!( self.storage.#field_ident.is_none() ); - self.storage.#field_ident = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); - self - } - } -} - -/// -/// Generate a sub-former setter for the 'field_ident' with the 'setter_name' name. -/// -/// # Example of generated code -/// -/// ```ignore -/// pub fn hashmap_strings_1( mut self ) -> former::HashMapSubformer -/// < -/// String, -/// String, -/// std::collections::HashMap< String, String >, -/// Struct1Former, -/// impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self -/// > -/// { -/// let formed = self.hashmap_strings_1.take(); -/// let on_end = | formed : std::collections::HashMap< String, String >, mut former : core::option::Option< Self > | -> Self -/// { -/// former.hashmap_strings_1 = Some( formed ); -/// former -/// }; -/// former::HashMapSubformer::begin( formed, self, on_end ) -/// } -/// ``` - -#[ inline ] -fn subformer_field_setter -( - field_ident : &syn::Ident, - setter_name : &syn::Ident, - non_optional_type : &syn::Type, - subformer_type : &syn::Type, -) --> TokenStream -{ - let doc = format! - ( - "Subformer setter for the '{}' field.", - field_ident - ); - - // tree_print!( non_optional_type ); - // code_print!( non_optional_type ); - let params = typ::type_parameters( &non_optional_type, .. ); - // params.iter().for_each( | e | println!( "{}", qt!( #e ) ) ); - - qt! - { - #[ doc = #doc ] - #[ inline ] - pub fn #setter_name( mut self ) -> #subformer_type - < - #( #params, )* - #non_optional_type, - Self, - impl Fn( #non_optional_type, core::option::Option< Self > ) -> Self, - > - { - let formed = self.storage.#setter_name.take(); - let on_end = | formed : #non_optional_type, former : core::option::Option< Self > | -> Self - { - let mut former = former.unwrap(); - former.storage.#setter_name = Some( formed ); - former - }; - #subformer_type::begin( formed, Some( self ), on_end ) - } - } - -} - /// /// Generate documentation for the former. /// @@ -1055,6 +1141,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( _doc_former_mod, doc_former_struct ) = doc_generate( struct_name ); let fields_setter : Vec< _ > = process_results( fields_setter, | iter | iter.collect() )?; let fields_form : Vec< _ > = process_results( fields_form, | iter | iter.collect() )?; + let fields_setter_callback_descriptor : Vec< _ > = process_results( fields_setter_callback_descriptor, | iter | iter.collect() )?; let result = qt! { @@ -1362,6 +1449,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } + #( + #fields_setter_callback_descriptor + )* + }; if has_debug diff --git a/module/core/macro_tools/src/generics.rs b/module/core/macro_tools/src/generics.rs index 43aa92b40b..f7e4617f2f 100644 --- a/module/core/macro_tools/src/generics.rs +++ b/module/core/macro_tools/src/generics.rs @@ -183,26 +183,6 @@ pub( crate ) mod private result } - /// Extract generics from a type. - // pub fn extract_from_type( type_example : &syn::Type ) -> Option< syn::PathArguments > - pub fn extract_from_type( type_example : &syn::Type ) - -> - Option< syn::punctuated::Punctuated< syn::GenericArgument, syn::token::Comma > > - { - if let syn::Type::Path( type_path ) = type_example - { - let segments = &type_path.path.segments; - let last_segment = segments.last()?; - - if let syn::PathArguments::AngleBracketed( generics ) = &last_segment.arguments - { - return Some( generics.args.clone() ); - } - } - None - } - - } #[ doc( inline ) ] @@ -221,7 +201,6 @@ pub mod protected { merge, params_names, - extract_from_type, }; } diff --git a/module/core/macro_tools/src/typ.rs b/module/core/macro_tools/src/typ.rs index 81b48b675b..9218ecd297 100644 --- a/module/core/macro_tools/src/typ.rs +++ b/module/core/macro_tools/src/typ.rs @@ -90,6 +90,25 @@ pub( crate ) mod private vec![ ty ] } + // xxx : cover by tests + /// Extract generics from a type. + pub fn all_type_parameters( type_example : &syn::Type ) + -> + Option< syn::punctuated::Punctuated< syn::GenericArgument, syn::token::Comma > > + { + if let syn::Type::Path( type_path ) = type_example + { + let segments = &type_path.path.segments; + let last_segment = segments.last()?; + + if let syn::PathArguments::AngleBracketed( generics ) = &last_segment.arguments + { + return Some( generics.args.clone() ); + } + } + None + } + } #[ doc( inline ) ] @@ -108,7 +127,7 @@ pub mod protected { type_rightmost, type_parameters, - // xxx : rename + all_type_parameters, }; } From 998363550411ee01411472fe95102b917970b960 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 10 Apr 2024 17:32:41 +0300 Subject: [PATCH 114/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 705f75ea7a..5f4bf42490 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -833,8 +833,9 @@ Result< TokenStream > let field_forming_end_name = format!( "former{}End", ident.to_string().to_case( Case::Camel ) ); let field_forming_end = syn::Ident::new( &field_forming_end_name, ident.span() ); - let field_ty = field.non_optional_ty; - let field_set = typ::all_type_parameters( field_ty ); + // let field_ty = field.non_optional_ty; + let params = typ::type_parameters( &field.non_optional_ty, .. ); + // let params = typ::all_type_parameters( field.non_optional_ty ); // let xxx = field_ty; // let generics = field_ty.generics // let ( generics_impl, generics_ty, generics_where ) = generics.split_for_impl(); @@ -850,7 +851,7 @@ Result< TokenStream > #[ automatically_derived ] impl< Definition > former::FormingEnd < - former::VectorDefinition< #field_set, #former< Definition >, #former< Definition >, former::NoEnd >, + former::VectorDefinition< #( #params, )* #former< Definition >, #former< Definition >, former::NoEnd >, // xxx : what is there is no generic parameters? > for #field_forming_end From 4b6f5c4e410ea9f12c97580f9fca0468dabdfd26 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 10 Apr 2024 17:40:54 +0300 Subject: [PATCH 115/533] former : experimenting --- .../a_containers_with_subformer.rs | 840 +++++++++--------- .../only_test/containers_with_subformer.rs | 302 +++---- module/core/former_meta/src/derive/former.rs | 1 - 3 files changed, 571 insertions(+), 572 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 95345db37b..80a30288bc 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -4,444 +4,444 @@ use super::*; // use std::collections::HashMap; // use std::collections::HashSet; -// #[ derive( Debug, PartialEq, former::Former ) ] -// #[ debug ] -#[ derive( Debug, PartialEq ) ] +#[ derive( Default, Debug, PartialEq, former::Former ) ] +#[ debug ] +// #[ derive( Default, Debug, PartialEq ) ] pub struct Struct1 { - // #[ subformer( former::VectorSubformer ) ] + // #[ subformer( former::VectorDefinition ) ] vec_1 : Vec< String >, // #[ subformer( former::HashMapSubformer ) ] hashmap_1 : std::collections::HashMap< String, String >, - // #[ subformer( former::HashSetSubformer ) ] + // // #[ subformer( former::HashSetSubformer ) ] hashset_1 : std::collections::HashSet< String >, } // = generated -#[ automatically_derived ] -impl Struct1 -{ - #[ doc = r"" ] - #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn former() -> Struct1Former< > - { - Struct1Former::<>::new( former::ReturnPreformed ) - } -} - -#[ derive( Debug ) ] -pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > -{ - _phantom : core::marker::PhantomData< ( Context, Formed ) >, -} - -impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > -{ - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } -} - -#[ derive( Debug ) ] -pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > -{ - _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, -} - -impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > -{ - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } -} - -impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > -{ - type Storage = Struct1FormerStorage; - type Formed = Formed; - type Context = Context; -} - -impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > -where - End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, -{ - type Types = Struct1FormerDefinitionTypes< Context, Formed >; - type End = End; -} - -pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; - -#[ doc = "Container of a corresponding former." ] -pub struct Struct1FormerStorage -{ - #[ doc = r" A field" ] - pub vec_1 : ::core::option::Option< Vec< String > >, - - #[ doc = r" A field" ] - pub hashmap_1 : ::core::option::Option< std::collections::HashMap< String, String > >, - - #[ doc = r" A field" ] - pub hashset_1 : ::core::option::Option< std::collections::HashSet< String > >, -} - -impl ::core::default::Default for Struct1FormerStorage -{ - #[ inline( always ) ] - fn default() -> Self - { - Self - { - vec_1 : ::core::option::Option::None, - hashmap_1 : ::core::option::Option::None, - hashset_1 : ::core::option::Option::None, - } - } -} - -impl former::Storage for Struct1FormerStorage -{ - type Formed = Struct1; -} - -impl former::StoragePreform for Struct1FormerStorage -{ - fn preform( mut self ) -> < Self as former::Storage >::Formed - { - let vec_1 = if self.vec_1.is_some() - { - self.vec_1.take().unwrap() - } - else - { - { - trait MaybeDefault< T > - { - fn maybe_default( self : &Self ) -> T - { - panic!( "Field 'vec_1' isn't initialized" ) - } - } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where T : ::core::default::Default, - { - fn maybe_default( self : &Self ) -> T - { - T::default() - } - } - ( &::core::marker::PhantomData::< Vec< String > > ).maybe_default() - } - }; - let hashmap_1 = if self.hashmap_1.is_some() - { - self.hashmap_1.take().unwrap() - } - else - { - { - trait MaybeDefault< T > - { - fn maybe_default( self : &Self ) -> T - { - panic!( "Field 'hashmap_1' isn't initialized" ) - } - } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where T : ::core::default::Default, - { - fn maybe_default( self : &Self ) -> T - { - T::default() - } - } - ( &::core::marker::PhantomData::< std::collections::HashMap< String, String > > ).maybe_default() - } - }; - let hashset_1 = if self.hashset_1.is_some() - { - self.hashset_1.take().unwrap() - } - else - { - { - trait MaybeDefault< T > - { - fn maybe_default( self : &Self ) -> T - { - panic!( "Field 'hashset_1' isn't initialized" ) - } - } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where T : ::core::default::Default, - { - fn maybe_default( self : &Self ) -> T - { - T::default() - } - } - ( &::core::marker::PhantomData::< std::collections::HashSet< String > > ).maybe_default() - } - }; - let result = Struct1 - { - vec_1, - hashmap_1, - hashset_1, - }; - return result; - } -} - -#[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[ default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] -pub struct Struct1Former< Definition = Struct1FormerDefinition > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, -{ - storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : core::option::Option< Definition::End >, -} - -#[ automatically_derived ] -impl< Definition > Struct1Former< Definition > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, -{ - #[ doc = r"" ] - #[ doc = r" Finish setting options and call perform on formed entity." ] - #[ doc = r"" ] - #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] - #[ doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str ) ]` returns `&str`." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - { - let result = self.form(); - return result; - } - - #[ doc = r"" ] - #[ doc = r" Construct new instance of former with default parameters." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn _new_precise( on_end : Definition::End ) -> Self - { - Self::begin( None, None, on_end ) - } - - #[ doc = r"" ] - #[ doc = r" Construct new instance of former with default parameters." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn new< IntoEnd >( end : IntoEnd ) -> Self - where - IntoEnd : Into< Definition::End >, - { - Self::begin( None, None, end, ) - } - - #[ doc = r"" ] - #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn _begin_precise( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : < Definition as former::FormerDefinition >::End, - ) -> Self - { - if storage.is_none() - { - storage = Some( ::core::default::Default::default() ); - } - Self - { - storage : storage.unwrap(), - context : context, - on_end : ::core::option::Option::Some( on_end ), - } - } - - #[ doc = r"" ] - #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn begin< IntoEnd >( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : IntoEnd, - ) -> Self - where - IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, - { - if storage.is_none() - { - storage = Some( ::core::default::Default::default() ); - } - Self - { - storage : storage.unwrap(), - context : context, - on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), - } - } - - #[ doc = r"" ] - #[ doc = r" End the process of forming returning original context of forming." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - { - self.end() - } - - #[ doc = r"" ] - #[ doc = r" End the process of forming returning original context of forming." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) - } - - // #[ doc = "Subformer setter for the 'vec_1' field." ] - // #[ inline ] - // pub fn vec_1( mut self ) -> former::VectorSubformer< String, Vec< String >, Self, impl Fn( Vec< String >, core::option::Option< Self > ) -> Self, > - // { - // let formed = self.storage.vec_1.take(); - // let on_end = | formed : Vec< String >, former : core::option::Option< Self > | -> Self - // { - // let mut former = former.unwrap(); - // former.storage.vec_1 = Some( formed ); - // former - // }; - // former::VectorSubformer::begin( formed, Some( self ), on_end ) - // } - - #[ inline( always ) ] - pub fn vec_1_set< Former2 >( self ) -> Former2 - where - Former2 : former::FormerBegin - < - former::VectorDefinition - < - String, - Self, - Self, - Struct1FormerVec_1End, - > - >, - { - Former2::_begin( None, Some( self ), Struct1FormerVec_1End ) - } - - pub fn vec_1( self ) -> - former::ContainerSubformer:: - < - String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > - > - { - self.vec_1_set::< former::ContainerSubformer:: - < - String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > - >>() - } - -// #[ doc = "Subformer setter for the 'hashmap_1' field." ] -// #[ inline ] -// pub fn hashmap_1( mut self ) -> former::HashMapSubformer< String, String, std::collections::HashMap< String, String >, Self, impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self, > +// #[ automatically_derived ] +// impl Struct1 +// { +// #[ doc = r"" ] +// #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn former() -> Struct1Former< > // { -// let formed = self.storage.hashmap_1.take(); -// let on_end = | formed : std::collections::HashMap< String, String >, former : core::option::Option< Self > | -> Self +// Struct1Former::<>::new( former::ReturnPreformed ) +// } +// } +// +// #[ derive( Debug ) ] +// pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > +// { +// _phantom : core::marker::PhantomData< ( Context, Formed ) >, +// } +// +// impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > +// { +// fn default() -> Self +// { +// Self // { -// let mut former = former.unwrap(); -// former.storage.hashmap_1 = Some( formed ); -// former -// }; -// former::HashMapSubformer::begin( formed, Some( self ), on_end ) +// _phantom : core::marker::PhantomData, +// } +// } +// } +// +// #[ derive( Debug ) ] +// pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +// { +// _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, +// } +// +// impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > +// { +// fn default() -> Self +// { +// Self +// { +// _phantom : core::marker::PhantomData, +// } // } +// } +// +// impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > +// { +// type Storage = Struct1FormerStorage; +// type Formed = Formed; +// type Context = Context; +// } +// +// impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > +// where +// End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, +// { +// type Types = Struct1FormerDefinitionTypes< Context, Formed >; +// type End = End; +// } +// +// pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; +// +// #[ doc = "Container of a corresponding former." ] +// pub struct Struct1FormerStorage +// { +// #[ doc = r" A field" ] +// pub vec_1 : ::core::option::Option< Vec< String > >, +// +// #[ doc = r" A field" ] +// pub hashmap_1 : ::core::option::Option< std::collections::HashMap< String, String > >, +// +// #[ doc = r" A field" ] +// pub hashset_1 : ::core::option::Option< std::collections::HashSet< String > >, +// } // -// #[ doc = "Subformer setter for the 'hashset_1' field." ] -// #[ inline ] -// pub fn hashset_1( mut self ) -> former::HashSetSubformer< String, std::collections::HashSet< String >, Self, impl Fn( std::collections::HashSet< String >, core::option::Option< Self > ) -> Self, > +// impl ::core::default::Default for Struct1FormerStorage +// { +// #[ inline( always ) ] +// fn default() -> Self // { -// let formed = self.storage.hashset_1.take(); -// let on_end = | formed : std::collections::HashSet< String >, former : core::option::Option< Self > | -> Self +// Self // { -// let mut former = former.unwrap(); -// former.storage.hashset_1 = Some( formed ); -// former +// vec_1 : ::core::option::Option::None, +// hashmap_1 : ::core::option::Option::None, +// hashset_1 : ::core::option::Option::None, +// } +// } +// } +// +// impl former::Storage for Struct1FormerStorage +// { +// type Formed = Struct1; +// } +// +// impl former::StoragePreform for Struct1FormerStorage +// { +// fn preform( mut self ) -> < Self as former::Storage >::Formed +// { +// let vec_1 = if self.vec_1.is_some() +// { +// self.vec_1.take().unwrap() +// } +// else +// { +// { +// trait MaybeDefault< T > +// { +// fn maybe_default( self : &Self ) -> T +// { +// panic!( "Field 'vec_1' isn't initialized" ) +// } +// } +// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} +// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > +// where T : ::core::default::Default, +// { +// fn maybe_default( self : &Self ) -> T +// { +// T::default() +// } +// } +// ( &::core::marker::PhantomData::< Vec< String > > ).maybe_default() +// } +// }; +// let hashmap_1 = if self.hashmap_1.is_some() +// { +// self.hashmap_1.take().unwrap() +// } +// else +// { +// { +// trait MaybeDefault< T > +// { +// fn maybe_default( self : &Self ) -> T +// { +// panic!( "Field 'hashmap_1' isn't initialized" ) +// } +// } +// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} +// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > +// where T : ::core::default::Default, +// { +// fn maybe_default( self : &Self ) -> T +// { +// T::default() +// } +// } +// ( &::core::marker::PhantomData::< std::collections::HashMap< String, String > > ).maybe_default() +// } // }; -// former::HashSetSubformer::begin( formed, Some( self ), on_end ) +// let hashset_1 = if self.hashset_1.is_some() +// { +// self.hashset_1.take().unwrap() +// } +// else +// { +// { +// trait MaybeDefault< T > +// { +// fn maybe_default( self : &Self ) -> T +// { +// panic!( "Field 'hashset_1' isn't initialized" ) +// } +// } +// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} +// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > +// where T : ::core::default::Default, +// { +// fn maybe_default( self : &Self ) -> T +// { +// T::default() +// } +// } +// ( &::core::marker::PhantomData::< std::collections::HashSet< String > > ).maybe_default() +// } +// }; +// let result = Struct1 +// { +// vec_1, +// hashmap_1, +// hashset_1, +// }; +// return result; // } - -} - -impl< Definition > Struct1Former< Definition > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, -{ - pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - { - former::StoragePreform::preform( self.storage ) - } -} - -// zzz : description -/// Return original former after subformer for `vec_1` is done. -#[ allow( non_camel_case_types ) ] -pub struct Struct1FormerVec_1End; -#[ automatically_derived ] -impl< Definition > former::FormingEnd -< - former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, -> -for Struct1FormerVec_1End -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 > - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.vec_1 - { - former::ContainerAssign::assign( field, storage ); - } - else - { - super_former.storage.vec_1 = Some( storage ); - } - super_former - } -} +// } +// +// #[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[ default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] +// pub struct Struct1Former< Definition = Struct1FormerDefinition > +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +// { +// storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, +// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, +// on_end : core::option::Option< Definition::End >, +// } +// +// #[ automatically_derived ] +// impl< Definition > Struct1Former< Definition > +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +// { +// #[ doc = r"" ] +// #[ doc = r" Finish setting options and call perform on formed entity." ] +// #[ doc = r"" ] +// #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] +// #[ doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str ) ]` returns `&str`." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed +// { +// let result = self.form(); +// return result; +// } +// +// #[ doc = r"" ] +// #[ doc = r" Construct new instance of former with default parameters." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn _new_precise( on_end : Definition::End ) -> Self +// { +// Self::begin( None, None, on_end ) +// } +// +// #[ doc = r"" ] +// #[ doc = r" Construct new instance of former with default parameters." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn new< IntoEnd >( end : IntoEnd ) -> Self +// where +// IntoEnd : Into< Definition::End >, +// { +// Self::begin( None, None, end, ) +// } +// +// #[ doc = r"" ] +// #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn _begin_precise( +// mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, +// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, +// on_end : < Definition as former::FormerDefinition >::End, +// ) -> Self +// { +// if storage.is_none() +// { +// storage = Some( ::core::default::Default::default() ); +// } +// Self +// { +// storage : storage.unwrap(), +// context : context, +// on_end : ::core::option::Option::Some( on_end ), +// } +// } +// +// #[ doc = r"" ] +// #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn begin< IntoEnd >( +// mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, +// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, +// on_end : IntoEnd, +// ) -> Self +// where +// IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, +// { +// if storage.is_none() +// { +// storage = Some( ::core::default::Default::default() ); +// } +// Self +// { +// storage : storage.unwrap(), +// context : context, +// on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), +// } +// } +// +// #[ doc = r"" ] +// #[ doc = r" End the process of forming returning original context of forming." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed +// { +// self.end() +// } +// +// #[ doc = r"" ] +// #[ doc = r" End the process of forming returning original context of forming." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed +// { +// let on_end = self.on_end.take().unwrap(); +// let context = self.context.take(); +// former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) +// } +// +// // #[ doc = "Subformer setter for the 'vec_1' field." ] +// // #[ inline ] +// // pub fn vec_1( mut self ) -> former::VectorSubformer< String, Vec< String >, Self, impl Fn( Vec< String >, core::option::Option< Self > ) -> Self, > +// // { +// // let formed = self.storage.vec_1.take(); +// // let on_end = | formed : Vec< String >, former : core::option::Option< Self > | -> Self +// // { +// // let mut former = former.unwrap(); +// // former.storage.vec_1 = Some( formed ); +// // former +// // }; +// // former::VectorSubformer::begin( formed, Some( self ), on_end ) +// // } +// +// #[ inline( always ) ] +// pub fn vec_1_set< Former2 >( self ) -> Former2 +// where +// Former2 : former::FormerBegin +// < +// former::VectorDefinition +// < +// String, +// Self, +// Self, +// Struct1FormerVec_1End, +// > +// >, +// { +// Former2::_begin( None, Some( self ), Struct1FormerVec_1End ) +// } +// +// pub fn vec_1( self ) -> +// former::ContainerSubformer:: +// < +// String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > +// > +// { +// self.vec_1_set::< former::ContainerSubformer:: +// < +// String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > +// >>() +// } +// +// // #[ doc = "Subformer setter for the 'hashmap_1' field." ] +// // #[ inline ] +// // pub fn hashmap_1( mut self ) -> former::HashMapSubformer< String, String, std::collections::HashMap< String, String >, Self, impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self, > +// // { +// // let formed = self.storage.hashmap_1.take(); +// // let on_end = | formed : std::collections::HashMap< String, String >, former : core::option::Option< Self > | -> Self +// // { +// // let mut former = former.unwrap(); +// // former.storage.hashmap_1 = Some( formed ); +// // former +// // }; +// // former::HashMapSubformer::begin( formed, Some( self ), on_end ) +// // } +// // +// // #[ doc = "Subformer setter for the 'hashset_1' field." ] +// // #[ inline ] +// // pub fn hashset_1( mut self ) -> former::HashSetSubformer< String, std::collections::HashSet< String >, Self, impl Fn( std::collections::HashSet< String >, core::option::Option< Self > ) -> Self, > +// // { +// // let formed = self.storage.hashset_1.take(); +// // let on_end = | formed : std::collections::HashSet< String >, former : core::option::Option< Self > | -> Self +// // { +// // let mut former = former.unwrap(); +// // former.storage.hashset_1 = Some( formed ); +// // former +// // }; +// // former::HashSetSubformer::begin( formed, Some( self ), on_end ) +// // } +// +// } +// +// impl< Definition > Struct1Former< Definition > +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, +// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +// { +// pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed +// { +// former::StoragePreform::preform( self.storage ) +// } +// } +// +// // zzz : description +// /// Return original former after subformer for `vec_1` is done. +// #[ allow( non_camel_case_types ) ] +// pub struct Struct1FormerVec_1End; +// #[ automatically_derived ] +// impl< Definition > former::FormingEnd +// < +// former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, +// > +// for Struct1FormerVec_1End +// 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 > +// { +// let mut super_former = super_former.unwrap(); +// if let Some( ref mut field ) = super_former.storage.vec_1 +// { +// former::ContainerAssign::assign( field, storage ); +// } +// else +// { +// super_former.storage.vec_1 = Some( storage ); +// } +// super_former +// } +// } // = generated diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index 0e8a90a361..a778a6b6b6 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -162,154 +162,154 @@ tests_impls_optional! // - fn test_hashmap() - { - - // test.case( "implicit construction" ); - - let command = Struct1::former() - .hashmap_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() - .form() - ; - // dbg!( &command ); - - let expected = Struct1 - { - vec_1 : vec![], - hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, - hashset_1 : hset!{}, - }; - a_id!( command, expected ); - - // test.case( "replace" ); - - let command = Struct1::former() - .hashmap_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() - .form() - ; - let expected = Struct1 - { - vec_1 : vec![], - hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, - hashset_1 : hset!{}, - }; - a_id!( command, expected ); - - let command = Struct1::former() - .hashmap_1().add( ( "x".to_string(), "v1".to_string() ) ).replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() - .form() - ; - let expected = Struct1 - { - vec_1 : vec![], - hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, - hashset_1 : hset!{}, - }; - a_id!( command, expected ); - - // test.case( "replace and add" ); - - let command = Struct1::former() - .hashmap_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ) - .add( ( "k3".to_string(), "v3".to_string() ) ).end() - .form() - ; - // dbg!( &command ); - - let expected = Struct1 - { - vec_1 : vec![], - hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string(), "k3".to_string() => "v3".to_string() }, - hashset_1 : hset!{}, - }; - a_id!( command, expected ); - } - - // - - fn test_hashset() - { - - // test.case( "implicit construction" ); - - let command = Struct1::former() - .hashset_1().add( "v1" ).add( "v2" ).end() - .form() - ; - // dbg!( &command ); - - let expected = Struct1 - { - vec_1 : vec![], - hashmap_1 : hmap!{}, - hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, - }; - a_id!( command, expected ); - - // test.case( "replace" ); - - let command = Struct1::former() - .hashset_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() - .form() - ; - let expected = Struct1 - { - vec_1 : vec![], - hashmap_1 : hmap!{}, - hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, - }; - a_id!( command, expected ); - - let command = Struct1::former() - .hashset_1().add( "x" ).replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() - .form() - ; - let expected = Struct1 - { - vec_1 : vec![], - hashmap_1 : hmap!{}, - hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, - }; - a_id!( command, expected ); - - // test.case( "replace and add" ); - - let command = Struct1::former() - .hashset_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).add( "v3" ).end() - .form() - ; - // dbg!( &command ); - - let expected = Struct1 - { - vec_1 : vec![], - hashmap_1 : hmap!{}, - hashset_1 : hset!{ "v1".to_string(), "v2".to_string(), "v3".to_string() }, - }; - a_id!( command, expected ); - } - - // - - fn test_complex() - { - - let command = Struct1::former() - .vec_1().add( "ghi" ).add( "klm" ).end() - .hashmap_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() - .hashset_1().add( "k1" ).end() - .form(); - // dbg!( &command ); - - let expected = Struct1 - { - vec_1 : vec![ "ghi".to_string(), "klm".to_string() ], - hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, - hashset_1 : hset!{ "k1".to_string() }, - }; - a_id!( command, expected ); - - } +// fn test_hashmap() +// { +// +// // test.case( "implicit construction" ); +// +// let command = Struct1::former() +// .hashmap_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() +// .form() +// ; +// // dbg!( &command ); +// +// let expected = Struct1 +// { +// vec_1 : vec![], +// hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, +// hashset_1 : hset!{}, +// }; +// a_id!( command, expected ); +// +// // test.case( "replace" ); +// +// let command = Struct1::former() +// .hashmap_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() +// .form() +// ; +// let expected = Struct1 +// { +// vec_1 : vec![], +// hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, +// hashset_1 : hset!{}, +// }; +// a_id!( command, expected ); +// +// let command = Struct1::former() +// .hashmap_1().add( ( "x".to_string(), "v1".to_string() ) ).replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() +// .form() +// ; +// let expected = Struct1 +// { +// vec_1 : vec![], +// hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, +// hashset_1 : hset!{}, +// }; +// a_id!( command, expected ); +// +// // test.case( "replace and add" ); +// +// let command = Struct1::former() +// .hashmap_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ) +// .add( ( "k3".to_string(), "v3".to_string() ) ).end() +// .form() +// ; +// // dbg!( &command ); +// +// let expected = Struct1 +// { +// vec_1 : vec![], +// hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string(), "k3".to_string() => "v3".to_string() }, +// hashset_1 : hset!{}, +// }; +// a_id!( command, expected ); +// } +// +// // +// +// fn test_hashset() +// { +// +// // test.case( "implicit construction" ); +// +// let command = Struct1::former() +// .hashset_1().add( "v1" ).add( "v2" ).end() +// .form() +// ; +// // dbg!( &command ); +// +// let expected = Struct1 +// { +// vec_1 : vec![], +// hashmap_1 : hmap!{}, +// hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, +// }; +// a_id!( command, expected ); +// +// // test.case( "replace" ); +// +// let command = Struct1::former() +// .hashset_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() +// .form() +// ; +// let expected = Struct1 +// { +// vec_1 : vec![], +// hashmap_1 : hmap!{}, +// hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, +// }; +// a_id!( command, expected ); +// +// let command = Struct1::former() +// .hashset_1().add( "x" ).replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() +// .form() +// ; +// let expected = Struct1 +// { +// vec_1 : vec![], +// hashmap_1 : hmap!{}, +// hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, +// }; +// a_id!( command, expected ); +// +// // test.case( "replace and add" ); +// +// let command = Struct1::former() +// .hashset_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).add( "v3" ).end() +// .form() +// ; +// // dbg!( &command ); +// +// let expected = Struct1 +// { +// vec_1 : vec![], +// hashmap_1 : hmap!{}, +// hashset_1 : hset!{ "v1".to_string(), "v2".to_string(), "v3".to_string() }, +// }; +// a_id!( command, expected ); +// } +// +// // +// +// fn test_complex() +// { +// +// let command = Struct1::former() +// .vec_1().add( "ghi" ).add( "klm" ).end() +// .hashmap_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() +// .hashset_1().add( "k1" ).end() +// .form(); +// // dbg!( &command ); +// +// let expected = Struct1 +// { +// vec_1 : vec![ "ghi".to_string(), "klm".to_string() ], +// hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, +// hashset_1 : hset!{ "k1".to_string() }, +// }; +// a_id!( command, expected ); +// +// } } @@ -320,7 +320,7 @@ tests_index! internals, new, test_vector, - test_hashmap, - test_hashset, - test_complex, + // test_hashmap, + // test_hashset, + // test_complex, } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 5f4bf42490..3a71dbdea0 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -824,7 +824,6 @@ Result< TokenStream > } let subformer = field.attrs.subformer.as_ref().unwrap(); - // former::VectorSubformer // former::VectorDefinition // xxx From b3ef175d2fa624ea328a1b19ec789060106be202 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 10 Apr 2024 17:41:01 +0300 Subject: [PATCH 116/533] former : experimenting --- .../inc/former_tests/only_test/containers_with_subformer.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index a778a6b6b6..2b6c95fb5b 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -323,4 +323,5 @@ tests_index! // test_hashmap, // test_hashset, // test_complex, + // xxx } From c89aa33484e4f95b2302c3cc0cc7f4717a95d31d Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 10 Apr 2024 17:45:18 +0300 Subject: [PATCH 117/533] former : experimenting --- .../a_containers_with_subformer.rs | 427 +----------------- module/core/former_meta/src/derive/former.rs | 10 +- 2 files changed, 7 insertions(+), 430 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 80a30288bc..f1609bf0a4 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -9,7 +9,7 @@ use super::*; // #[ derive( Default, Debug, PartialEq ) ] pub struct Struct1 { - // #[ subformer( former::VectorDefinition ) ] + #[ subformer( former::VectorDefinition ) ] vec_1 : Vec< String >, // #[ subformer( former::HashMapSubformer ) ] hashmap_1 : std::collections::HashMap< String, String >, @@ -19,431 +19,8 @@ pub struct Struct1 // = generated -// #[ automatically_derived ] -// impl Struct1 -// { -// #[ doc = r"" ] -// #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn former() -> Struct1Former< > -// { -// Struct1Former::<>::new( former::ReturnPreformed ) -// } -// } -// -// #[ derive( Debug ) ] -// pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > -// { -// _phantom : core::marker::PhantomData< ( Context, Formed ) >, -// } -// -// impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > -// { -// fn default() -> Self -// { -// Self -// { -// _phantom : core::marker::PhantomData, -// } -// } -// } -// -// #[ derive( Debug ) ] -// pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > -// { -// _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, -// } -// -// impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > -// { -// fn default() -> Self -// { -// Self -// { -// _phantom : core::marker::PhantomData, -// } -// } -// } -// -// impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > -// { -// type Storage = Struct1FormerStorage; -// type Formed = Formed; -// type Context = Context; -// } -// -// impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > -// where -// End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, -// { -// type Types = Struct1FormerDefinitionTypes< Context, Formed >; -// type End = End; -// } -// -// pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; -// -// #[ doc = "Container of a corresponding former." ] -// pub struct Struct1FormerStorage -// { -// #[ doc = r" A field" ] -// pub vec_1 : ::core::option::Option< Vec< String > >, -// -// #[ doc = r" A field" ] -// pub hashmap_1 : ::core::option::Option< std::collections::HashMap< String, String > >, -// -// #[ doc = r" A field" ] -// pub hashset_1 : ::core::option::Option< std::collections::HashSet< String > >, -// } -// -// impl ::core::default::Default for Struct1FormerStorage -// { -// #[ inline( always ) ] -// fn default() -> Self -// { -// Self -// { -// vec_1 : ::core::option::Option::None, -// hashmap_1 : ::core::option::Option::None, -// hashset_1 : ::core::option::Option::None, -// } -// } -// } -// -// impl former::Storage for Struct1FormerStorage -// { -// type Formed = Struct1; -// } -// -// impl former::StoragePreform for Struct1FormerStorage -// { -// fn preform( mut self ) -> < Self as former::Storage >::Formed -// { -// let vec_1 = if self.vec_1.is_some() -// { -// self.vec_1.take().unwrap() -// } -// else -// { -// { -// trait MaybeDefault< T > -// { -// fn maybe_default( self : &Self ) -> T -// { -// panic!( "Field 'vec_1' isn't initialized" ) -// } -// } -// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} -// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > -// where T : ::core::default::Default, -// { -// fn maybe_default( self : &Self ) -> T -// { -// T::default() -// } -// } -// ( &::core::marker::PhantomData::< Vec< String > > ).maybe_default() -// } -// }; -// let hashmap_1 = if self.hashmap_1.is_some() -// { -// self.hashmap_1.take().unwrap() -// } -// else -// { -// { -// trait MaybeDefault< T > -// { -// fn maybe_default( self : &Self ) -> T -// { -// panic!( "Field 'hashmap_1' isn't initialized" ) -// } -// } -// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} -// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > -// where T : ::core::default::Default, -// { -// fn maybe_default( self : &Self ) -> T -// { -// T::default() -// } -// } -// ( &::core::marker::PhantomData::< std::collections::HashMap< String, String > > ).maybe_default() -// } -// }; -// let hashset_1 = if self.hashset_1.is_some() -// { -// self.hashset_1.take().unwrap() -// } -// else -// { -// { -// trait MaybeDefault< T > -// { -// fn maybe_default( self : &Self ) -> T -// { -// panic!( "Field 'hashset_1' isn't initialized" ) -// } -// } -// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} -// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > -// where T : ::core::default::Default, -// { -// fn maybe_default( self : &Self ) -> T -// { -// T::default() -// } -// } -// ( &::core::marker::PhantomData::< std::collections::HashSet< String > > ).maybe_default() -// } -// }; -// let result = Struct1 -// { -// vec_1, -// hashmap_1, -// hashset_1, -// }; -// return result; -// } -// } -// -// #[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[ default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] -// pub struct Struct1Former< Definition = Struct1FormerDefinition > -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, -// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, -// { -// storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, -// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, -// on_end : core::option::Option< Definition::End >, -// } -// -// #[ automatically_derived ] -// impl< Definition > Struct1Former< Definition > -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, -// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, -// { -// #[ doc = r"" ] -// #[ doc = r" Finish setting options and call perform on formed entity." ] -// #[ doc = r"" ] -// #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] -// #[ doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str ) ]` returns `&str`." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed -// { -// let result = self.form(); -// return result; -// } -// -// #[ doc = r"" ] -// #[ doc = r" Construct new instance of former with default parameters." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn _new_precise( on_end : Definition::End ) -> Self -// { -// Self::begin( None, None, on_end ) -// } -// -// #[ doc = r"" ] -// #[ doc = r" Construct new instance of former with default parameters." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn new< IntoEnd >( end : IntoEnd ) -> Self -// where -// IntoEnd : Into< Definition::End >, -// { -// Self::begin( None, None, end, ) -// } -// -// #[ doc = r"" ] -// #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn _begin_precise( -// mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, -// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, -// on_end : < Definition as former::FormerDefinition >::End, -// ) -> Self -// { -// if storage.is_none() -// { -// storage = Some( ::core::default::Default::default() ); -// } -// Self -// { -// storage : storage.unwrap(), -// context : context, -// on_end : ::core::option::Option::Some( on_end ), -// } -// } -// -// #[ doc = r"" ] -// #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn begin< IntoEnd >( -// mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, -// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, -// on_end : IntoEnd, -// ) -> Self -// where -// IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, -// { -// if storage.is_none() -// { -// storage = Some( ::core::default::Default::default() ); -// } -// Self -// { -// storage : storage.unwrap(), -// context : context, -// on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), -// } -// } -// -// #[ doc = r"" ] -// #[ doc = r" End the process of forming returning original context of forming." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed -// { -// self.end() -// } -// -// #[ doc = r"" ] -// #[ doc = r" End the process of forming returning original context of forming." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed -// { -// let on_end = self.on_end.take().unwrap(); -// let context = self.context.take(); -// former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) -// } -// -// // #[ doc = "Subformer setter for the 'vec_1' field." ] -// // #[ inline ] -// // pub fn vec_1( mut self ) -> former::VectorSubformer< String, Vec< String >, Self, impl Fn( Vec< String >, core::option::Option< Self > ) -> Self, > -// // { -// // let formed = self.storage.vec_1.take(); -// // let on_end = | formed : Vec< String >, former : core::option::Option< Self > | -> Self -// // { -// // let mut former = former.unwrap(); -// // former.storage.vec_1 = Some( formed ); -// // former -// // }; -// // former::VectorSubformer::begin( formed, Some( self ), on_end ) -// // } -// -// #[ inline( always ) ] -// pub fn vec_1_set< Former2 >( self ) -> Former2 -// where -// Former2 : former::FormerBegin -// < -// former::VectorDefinition -// < -// String, -// Self, -// Self, -// Struct1FormerVec_1End, -// > -// >, -// { -// Former2::_begin( None, Some( self ), Struct1FormerVec_1End ) -// } -// -// pub fn vec_1( self ) -> -// former::ContainerSubformer:: -// < -// String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > -// > -// { -// self.vec_1_set::< former::ContainerSubformer:: -// < -// String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > -// >>() -// } -// -// // #[ doc = "Subformer setter for the 'hashmap_1' field." ] -// // #[ inline ] -// // pub fn hashmap_1( mut self ) -> former::HashMapSubformer< String, String, std::collections::HashMap< String, String >, Self, impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self, > -// // { -// // let formed = self.storage.hashmap_1.take(); -// // let on_end = | formed : std::collections::HashMap< String, String >, former : core::option::Option< Self > | -> Self -// // { -// // let mut former = former.unwrap(); -// // former.storage.hashmap_1 = Some( formed ); -// // former -// // }; -// // former::HashMapSubformer::begin( formed, Some( self ), on_end ) -// // } -// // -// // #[ doc = "Subformer setter for the 'hashset_1' field." ] -// // #[ inline ] -// // pub fn hashset_1( mut self ) -> former::HashSetSubformer< String, std::collections::HashSet< String >, Self, impl Fn( std::collections::HashSet< String >, core::option::Option< Self > ) -> Self, > -// // { -// // let formed = self.storage.hashset_1.take(); -// // let on_end = | formed : std::collections::HashSet< String >, former : core::option::Option< Self > | -> Self -// // { -// // let mut former = former.unwrap(); -// // former.storage.hashset_1 = Some( formed ); -// // former -// // }; -// // former::HashSetSubformer::begin( formed, Some( self ), on_end ) -// // } -// -// } -// -// impl< Definition > Struct1Former< Definition > -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, -// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, -// { -// pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed -// { -// former::StoragePreform::preform( self.storage ) -// } -// } -// -// // zzz : description -// /// Return original former after subformer for `vec_1` is done. -// #[ allow( non_camel_case_types ) ] -// pub struct Struct1FormerVec_1End; -// #[ automatically_derived ] -// impl< Definition > former::FormingEnd -// < -// former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, -// > -// for Struct1FormerVec_1End -// 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 > -// { -// let mut super_former = super_former.unwrap(); -// if let Some( ref mut field ) = super_former.storage.vec_1 -// { -// former::ContainerAssign::assign( field, storage ); -// } -// else -// { -// super_former.storage.vec_1 = Some( storage ); -// } -// super_former -// } -// } // = generated -// include!( "./only_test/containers_with_subformer.rs" ); +include!( "./only_test/containers_with_subformer.rs" ); // xxx : uncomment diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 3a71dbdea0..9df0002226 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -685,7 +685,7 @@ fn subformer_field_setter < #subformer_definition < - #( #params, )*, + #( #params, )* Self, Self, #field_set, @@ -698,12 +698,12 @@ fn subformer_field_setter pub fn #field_ident( self ) -> former::ContainerSubformer:: < - #( #params, )*, #subformer_definition< #( #params, )*, Self, Self, #field_set > + #( #params, )* #subformer_definition< #( #params, )* Self, Self, #field_set > > { self.#field_set::< former::ContainerSubformer:: < - #( #params, )*, #subformer_definition< #( #params, )*, Self, Self, #field_set > + #( #params, )* #subformer_definition< #( #params, )* Self, Self, #field_set > >>() } @@ -832,7 +832,7 @@ Result< TokenStream > let field_forming_end_name = format!( "former{}End", ident.to_string().to_case( Case::Camel ) ); let field_forming_end = syn::Ident::new( &field_forming_end_name, ident.span() ); - // let field_ty = field.non_optional_ty; + let field_ty = field.non_optional_ty; let params = typ::type_parameters( &field.non_optional_ty, .. ); // let params = typ::all_type_parameters( field.non_optional_ty ); // let xxx = field_ty; @@ -865,7 +865,7 @@ Result< TokenStream > fn call ( &self, - storage : field_ty, + storage : #field_ty, super_former : Option< #former< Definition > >, ) -> #former< Definition > From c6d2fc4ac2648c7203bbabebc06f15a047d60d9f Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 10 Apr 2024 18:04:09 +0300 Subject: [PATCH 118/533] former : experimenting --- .../a_containers_with_subformer.rs | 8 +- .../only_test/containers_with_subformer.rs | 136 +++++++++--------- module/core/former_meta/src/derive/former.rs | 24 ++-- 3 files changed, 86 insertions(+), 82 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index f1609bf0a4..f38879d356 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -11,16 +11,18 @@ pub struct Struct1 { #[ subformer( former::VectorDefinition ) ] vec_1 : Vec< String >, - // #[ subformer( former::HashMapSubformer ) ] + // #[ subformer( former::HashMapDefinition ) ] hashmap_1 : std::collections::HashMap< String, String >, - // // #[ subformer( former::HashSetSubformer ) ] + #[ subformer( former::HashSetDefinition ) ] hashset_1 : std::collections::HashSet< String >, } // = generated + + // = generated -include!( "./only_test/containers_with_subformer.rs" ); +// include!( "./only_test/containers_with_subformer.rs" ); // xxx : uncomment diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index 2b6c95fb5b..c763a9db3c 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -224,73 +224,73 @@ tests_impls_optional! // }; // a_id!( command, expected ); // } -// -// // -// -// fn test_hashset() -// { -// -// // test.case( "implicit construction" ); -// -// let command = Struct1::former() -// .hashset_1().add( "v1" ).add( "v2" ).end() -// .form() -// ; -// // dbg!( &command ); -// -// let expected = Struct1 -// { -// vec_1 : vec![], -// hashmap_1 : hmap!{}, -// hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, -// }; -// a_id!( command, expected ); -// -// // test.case( "replace" ); -// -// let command = Struct1::former() -// .hashset_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() -// .form() -// ; -// let expected = Struct1 -// { -// vec_1 : vec![], -// hashmap_1 : hmap!{}, -// hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, -// }; -// a_id!( command, expected ); -// -// let command = Struct1::former() -// .hashset_1().add( "x" ).replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() -// .form() -// ; -// let expected = Struct1 -// { -// vec_1 : vec![], -// hashmap_1 : hmap!{}, -// hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, -// }; -// a_id!( command, expected ); -// -// // test.case( "replace and add" ); -// -// let command = Struct1::former() -// .hashset_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).add( "v3" ).end() -// .form() -// ; -// // dbg!( &command ); -// -// let expected = Struct1 -// { -// vec_1 : vec![], -// hashmap_1 : hmap!{}, -// hashset_1 : hset!{ "v1".to_string(), "v2".to_string(), "v3".to_string() }, -// }; -// a_id!( command, expected ); -// } -// -// // -// + + // + + fn test_hashset() + { + + // test.case( "implicit construction" ); + + let command = Struct1::former() + .hashset_1().add( "v1" ).add( "v2" ).end() + .form() + ; + // dbg!( &command ); + + let expected = Struct1 + { + vec_1 : vec![], + hashmap_1 : hmap!{}, + hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, + }; + a_id!( command, expected ); + + // test.case( "replace" ); + + let command = Struct1::former() + .hashset_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() + .form() + ; + let expected = Struct1 + { + vec_1 : vec![], + hashmap_1 : hmap!{}, + hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, + }; + a_id!( command, expected ); + + let command = Struct1::former() + .hashset_1().add( "x" ).replace( hset!{ "v1".to_string(), "v2".to_string() } ).end() + .form() + ; + let expected = Struct1 + { + vec_1 : vec![], + hashmap_1 : hmap!{}, + hashset_1 : hset!{ "v1".to_string(), "v2".to_string() }, + }; + a_id!( command, expected ); + + // test.case( "replace and add" ); + + let command = Struct1::former() + .hashset_1().replace( hset!{ "v1".to_string(), "v2".to_string() } ).add( "v3" ).end() + .form() + ; + // dbg!( &command ); + + let expected = Struct1 + { + vec_1 : vec![], + hashmap_1 : hmap!{}, + hashset_1 : hset!{ "v1".to_string(), "v2".to_string(), "v3".to_string() }, + }; + a_id!( command, expected ); + } + + // + // fn test_complex() // { // @@ -321,7 +321,7 @@ tests_index! new, test_vector, // test_hashmap, - // test_hashset, + test_hashset, // test_complex, // xxx } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 9df0002226..5c6798a499 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -521,7 +521,7 @@ fn field_name_map( field : &FormerField< '_ > ) -> syn::Ident /// ``` #[ inline ] -fn field_setter_map( field : &FormerField< '_ > ) -> Result< TokenStream > +fn field_setter_map( field : &FormerField< '_ >, struct_name : &syn::Ident ) -> Result< TokenStream > { let ident = &field.ident; @@ -538,7 +538,7 @@ fn field_setter_map( field : &FormerField< '_ > ) -> Result< TokenStream > let setter_tokens = if let Some( subformer_ty ) = &field.attrs.subformer { // subformer_field_setter( ident, ident, non_optional_ty, &subformer_ty.expr ) - subformer_field_setter( field, &subformer_ty.expr ) + subformer_field_setter( field, struct_name, &subformer_ty.expr ) } else { @@ -643,6 +643,7 @@ fn field_setter fn subformer_field_setter ( field : &FormerField< '_ >, + struct_name : &syn::Ident, // field_ident : &syn::Ident, // setter_name : &syn::Ident, // non_optional_type : &syn::Type, @@ -671,10 +672,10 @@ fn subformer_field_setter use convert_case::{ Case, Casing }; // let ident = field_ident; - let field_forming_end_name = format!( "former{}End", field_ident.to_string().to_case( Case::Camel ) ); + let field_forming_end_name = format!( "{}Former{}End", struct_name, field_ident.to_string().to_case( Case::Camel ) ); let field_forming_end = syn::Ident::new( &field_forming_end_name, field_ident.span() ); let field_set_name = format!( "{}_set", field_ident ); - let field_set = syn::Ident::new( &field_forming_end_name, field_ident.span() ); + let field_set = syn::Ident::new( &field_set_name, field_ident.span() ); qt! { @@ -688,22 +689,22 @@ fn subformer_field_setter #( #params, )* Self, Self, - #field_set, + #field_forming_end, > >, { - Former2::_begin( None, Some( self ), #field_set ) + Former2::_begin( None, Some( self ), #field_forming_end ) } pub fn #field_ident( self ) -> former::ContainerSubformer:: < - #( #params, )* #subformer_definition< #( #params, )* Self, Self, #field_set > + #( #params, )* #subformer_definition< #( #params, )* Self, Self, #field_forming_end > > { self.#field_set::< former::ContainerSubformer:: < - #( #params, )* #subformer_definition< #( #params, )* Self, Self, #field_set > + #( #params, )* #subformer_definition< #( #params, )* Self, Self, #field_forming_end > >>() } @@ -810,6 +811,7 @@ fn subformer_field_setter fn fields_setter_callback_descriptor_map ( field : &FormerField< '_ >, + struct_name : &syn::Ident, former : &syn::Ident, former_storage : &syn::Ident, former_definition : &syn::Ident, @@ -829,7 +831,7 @@ Result< TokenStream > use convert_case::{ Case, Casing }; let ident = field.ident; - let field_forming_end_name = format!( "former{}End", ident.to_string().to_case( Case::Camel ) ); + let field_forming_end_name = format!( "{}Former{}End", struct_name, field.ident.to_string().to_case( Case::Camel ) ); let field_forming_end = syn::Ident::new( &field_forming_end_name, ident.span() ); let field_ty = field.non_optional_ty; @@ -1134,8 +1136,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field_optional_map( former_field ), field_form_map( former_field ), field_name_map( former_field ), - field_setter_map( former_field ), - fields_setter_callback_descriptor_map( former_field, &former, &former_storage, &former_definition ), + field_setter_map( former_field, &struct_name ), + fields_setter_callback_descriptor_map( former_field, &struct_name, &former, &former_storage, &former_definition ), )}).multiunzip(); let ( _doc_former_mod, doc_former_struct ) = doc_generate( struct_name ); From a363b9fa6a2aeb9fe981152f8569357446036230 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 10 Apr 2024 18:15:13 +0300 Subject: [PATCH 119/533] former : experimenting --- .../a_containers_with_subformer.rs | 404 +++++++++++++++++- .../a_containers_with_subformer_manual.rs | 8 +- module/core/former_meta/src/derive/former.rs | 6 +- 3 files changed, 403 insertions(+), 15 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index f38879d356..b2e9a803ea 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -4,22 +4,416 @@ use super::*; // use std::collections::HashMap; // use std::collections::HashSet; -#[ derive( Default, Debug, PartialEq, former::Former ) ] -#[ debug ] -// #[ derive( Default, Debug, PartialEq ) ] +// #[ derive( Default, Debug, PartialEq, former::Former ) ] +// #[ debug ] +#[ derive( Default, Debug, PartialEq ) ] pub struct Struct1 { - #[ subformer( former::VectorDefinition ) ] + // #[ subformer( former::VectorDefinition ) ] vec_1 : Vec< String >, // #[ subformer( former::HashMapDefinition ) ] hashmap_1 : std::collections::HashMap< String, String >, - #[ subformer( former::HashSetDefinition ) ] + // #[ subformer( former::HashSetDefinition ) ] hashset_1 : std::collections::HashSet< String >, } // = generated +#[ automatically_derived ] +impl Struct1 +{ + #[ doc = r"" ] + #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn former() -> Struct1Former< > + { + Struct1Former::< >::new( former::ReturnPreformed ) + } +} + +#[ derive( Debug ) ] +pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > +{ + _phantom: core::marker::PhantomData<( Context, Formed )>, +} + +impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > +{ + fn default() -> Self + { + Self + { + _phantom: core::marker::PhantomData, + } + } +} + +#[ derive( Debug ) ] +pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +{ + _phantom: core::marker::PhantomData<( Context, Formed, End )>, +} + +impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > +{ + fn default() -> Self + { + Self + { + _phantom: core::marker::PhantomData, + } + } +} + +impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > +{ + type Storage = Struct1FormerStorage; + type Formed = Formed; + type Context = Context; +} + +impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > +where + End: former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, +{ + type Types = Struct1FormerDefinitionTypes< Context, Formed >; + type End = End; +} + +pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; + +#[ doc = "Container of a corresponding former." ] +pub struct Struct1FormerStorage +{ + #[ doc = r" A field" ] + pub vec_1: ::core::option::Option< Vec< String > >, + #[ doc = r" A field" ] + pub hashmap_1: ::core::option::Option< std::collections::HashMap< String, String > >, + #[ doc = r" A field" ] + pub hashset_1: ::core::option::Option< std::collections::HashSet< String > >, +} + +impl ::core::default::Default for Struct1FormerStorage +{ + #[ inline( always ) ] + fn default() -> Self + { + Self + { + vec_1: ::core::option::Option::None, + hashmap_1: ::core::option::Option::None, + hashset_1: ::core::option::Option::None, + } + } +} + +impl former::Storage for Struct1FormerStorage +{ + type Formed = Struct1; +} +impl former::StoragePreform for Struct1FormerStorage +{ + fn preform( mut self ) -> ::Formed + { + let vec_1 = if self.vec_1.is_some() + { + self.vec_1.take().unwrap() + } + else + { + { + trait MaybeDefault< T > + { + fn maybe_default( self: &Self ) -> T + { + panic!( "Field 'vec_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where + T: ::core::default::Default, + { + fn maybe_default( self: &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< Vec< String > > ).maybe_default() + } + }; + let hashmap_1 = if self.hashmap_1.is_some() + { + self.hashmap_1.take().unwrap() + } + else + { + { + trait MaybeDefault< T > + { + fn maybe_default( self: &Self ) -> T + { + panic!( "Field 'hashmap_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where + T: ::core::default::Default, + { + fn maybe_default( self: &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< std::collections::HashMap< String, String > > ).maybe_default() + } + }; + let hashset_1 = if self.hashset_1.is_some() + { + self.hashset_1.take().unwrap() + } + else + { + { + trait MaybeDefault< T > + { + fn maybe_default( self: &Self ) -> T + { + panic!( "Field 'hashset_1' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where + T: ::core::default::Default, + { + fn maybe_default( self: &Self ) -> T + { + T::default() + } + } + ( &::core::marker::PhantomData::< std::collections::HashSet< String > > ).maybe_default() + } + }; + let result = Struct1 { vec_1, hashmap_1, hashset_1, }; + return result; + } +} + +#[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[ default( 31 ) ]\n field1: i32,\n}\n\n```\n" ] +pub struct Struct1Former< Definition = Struct1FormerDefinition > +where + Definition: former::FormerDefinition, + Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + ::Storage: former::StoragePreform, +{ + storage: ::Storage, + context: core::option::Option< ::Context >, + on_end: core::option::Option< Definition::End >, +} + +#[ automatically_derived ] +impl< Definition > Struct1Former< Definition > +where + Definition: former::FormerDefinition, + Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + ::Storage: former::StoragePreform, +{ + #[ doc = r"" ] + #[ doc = r" Finish setting options and call perform on formed entity." ] + #[ doc = r"" ] + #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] + #[ doc = r" For example `perform()` of structure with: `#[ perform( fn after1() -> &str ) ]` returns `&str`." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn perform( self ) -> ::Formed + { + let result = self.form(); + return result; + } + + #[ doc = r"" ] + #[ doc = r" Construct new instance of former with default parameters." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn _new_precise( on_end: Definition::End ) -> Self + { + Self::begin( None, None, on_end ) + } + + #[ doc = r"" ] + #[ doc = r" Construct new instance of former with default parameters." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn new< IntoEnd >( end: IntoEnd ) -> Self + where + IntoEnd: Into< Definition::End >, + { + Self::begin( None, None, end, ) + } + + #[ doc = r"" ] + #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn _begin_precise( mut storage: core::option::Option< ::Storage >, context: core::option::Option< ::Context >, on_end: ::End, ) -> Self + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage: storage.unwrap(), + context: context, + on_end: ::core::option::Option::Some( on_end ), + } + } + + #[ doc = r"" ] + #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn begin< IntoEnd >( mut storage: core::option::Option< ::Storage >, context: core::option::Option< ::Context >, on_end: IntoEnd, ) -> Self + where + IntoEnd: ::core::convert::Into< ::End >, + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage: storage.unwrap(), + context: context, + on_end: ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), + } + } + + #[ doc = r"" ] + #[ doc = r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn form( self ) -> ::Formed + { + self.end() + } + + #[ doc = r"" ] + #[ doc = r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn end( mut self ) -> ::Formed + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) + } + + #[ inline( always ) ] + pub fn vec_1_set< Former2 >( self ) -> Former2 + where + Former2: former::FormerBegin< former::VectorDefinition< String, Self, Self, Struct1Formervec1End, > >, + { + Former2::_begin( None, Some( self ), Struct1Formervec1End ) + } + + pub fn vec_1( self ) -> former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1Formervec1End > > + { + self.vec_1_set::< former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1Formervec1End > > >() + } + + #[ doc = "Setter for the 'hashmap_1' field." ] + #[ inline ] + pub fn hashmap_1< Src >( mut self, src: Src ) -> Self + where + Src: ::core::convert::Into< std::collections::HashMap< String, String > >, + { + debug_assert!( self.storage.hashmap_1.is_none() ); + self.storage.hashmap_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + self + } + + #[ inline( always ) ] + pub fn hashset_1_set< Former2 >( self ) -> Former2 + where + Former2: former::FormerBegin< former::HashSetDefinition< String, Self, Self, Struct1Formerhashset1End, > >, + { + Former2::_begin( None, Some( self ), Struct1Formerhashset1End ) + } + + pub fn hashset_1( self ) -> former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1Formerhashset1End > > + { + self.hashset_1_set::< former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1Formerhashset1End > > >() + } +} + +impl< Definition > Struct1Former< Definition > +where + Definition: former::FormerDefinition, + Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, + ::Storage: former::StoragePreform, +{ + pub fn preform( self ) -> ::Formed + { + former::StoragePreform::preform( self.storage ) + } +} + +#[ doc = r" Return original former after subformer for `vec_1` is done." ] +#[ allow( non_camel_case_types ) ] +pub struct Struct1Formervec1End; + +#[ automatically_derived ] +impl< Definition > former::FormingEnd< former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > for Struct1Formervec1End +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 > + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.vec_1 + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.vec_1 = Some( storage ); + } + super_former + } +} + +#[ doc = r" Return original former after subformer for `vec_1` is done." ] +#[ allow( non_camel_case_types ) ] +pub struct Struct1Formerhashset1End; + +#[ automatically_derived ] +impl< Definition > former::FormingEnd< former::HashSetDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > for Struct1Formerhashset1End +where + Definition: former::FormerDefinition, + Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +{ + #[ inline( always ) ] + fn call( &self, storage: std::collections::HashSet< String >, super_former: Option< Struct1Former< Definition > >, ) -> Struct1Former< Definition > + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.hashset_1 + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.hashset_1 = Some( storage ); + } + super_former + } +} // = generated diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index d361d5f070..e1eef17936 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -473,13 +473,7 @@ where >, { #[ inline( always ) ] - fn call - ( - &self, - storage : std::collections::HashMap< String, String >, - super_former : Option< Struct1Former< Definition > >, - ) - -> Struct1Former< Definition > + fn call( &self, storage : std::collections::HashMap< String, String >, super_former : Option< Struct1Former< Definition > > ) -> Struct1Former< Definition > { let mut super_former = super_former.unwrap(); if let Some( ref mut field ) = super_former.storage.hashmap_1 diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 5c6798a499..fd7fbd160d 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -825,7 +825,8 @@ Result< TokenStream > return Ok( qt!{ } ); } - let subformer = field.attrs.subformer.as_ref().unwrap(); + let subformer_definition = &field.attrs.subformer.as_ref().unwrap().expr; + // let subformer = field.attrs.subformer.as_ref().unwrap(); // former::VectorDefinition // xxx @@ -852,8 +853,7 @@ Result< TokenStream > #[ automatically_derived ] impl< Definition > former::FormingEnd < - former::VectorDefinition< #( #params, )* #former< Definition >, #former< Definition >, former::NoEnd >, - // xxx : what is there is no generic parameters? + #subformer_definition < #( #params, )* #former< Definition >, #former< Definition >, former::NoEnd >, > for #field_forming_end where From 2c3858af6ad3a4089b246e141868f716ba0fd1dd Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 11 Apr 2024 14:45:50 +0300 Subject: [PATCH 120/533] former : experimenting --- .../a_containers_with_subformer.rs | 803 +++++++++--------- 1 file changed, 402 insertions(+), 401 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index b2e9a803ea..94fbd7c742 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -4,416 +4,417 @@ use super::*; // use std::collections::HashMap; // use std::collections::HashSet; -// #[ derive( Default, Debug, PartialEq, former::Former ) ] -// #[ debug ] -#[ derive( Default, Debug, PartialEq ) ] +#[ derive( Default, Debug, PartialEq, former::Former ) ] +#[ debug ] +// #[ derive( Default, Debug, PartialEq ) ] pub struct Struct1 { - // #[ subformer( former::VectorDefinition ) ] + #[ subformer( former::VectorDefinition ) ] vec_1 : Vec< String >, - // #[ subformer( former::HashMapDefinition ) ] + #[ subformer( former::HashMapDefinition ) ] hashmap_1 : std::collections::HashMap< String, String >, - // #[ subformer( former::HashSetDefinition ) ] + #[ subformer( former::HashSetDefinition ) ] hashset_1 : std::collections::HashSet< String >, } // = generated -#[ automatically_derived ] -impl Struct1 -{ - #[ doc = r"" ] - #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn former() -> Struct1Former< > - { - Struct1Former::< >::new( former::ReturnPreformed ) - } -} - -#[ derive( Debug ) ] -pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > -{ - _phantom: core::marker::PhantomData<( Context, Formed )>, -} - -impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > -{ - fn default() -> Self - { - Self - { - _phantom: core::marker::PhantomData, - } - } -} - -#[ derive( Debug ) ] -pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > -{ - _phantom: core::marker::PhantomData<( Context, Formed, End )>, -} - -impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > -{ - fn default() -> Self - { - Self - { - _phantom: core::marker::PhantomData, - } - } -} - -impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > -{ - type Storage = Struct1FormerStorage; - type Formed = Formed; - type Context = Context; -} - -impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > -where - End: former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, -{ - type Types = Struct1FormerDefinitionTypes< Context, Formed >; - type End = End; -} - -pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; - -#[ doc = "Container of a corresponding former." ] -pub struct Struct1FormerStorage -{ - #[ doc = r" A field" ] - pub vec_1: ::core::option::Option< Vec< String > >, - #[ doc = r" A field" ] - pub hashmap_1: ::core::option::Option< std::collections::HashMap< String, String > >, - #[ doc = r" A field" ] - pub hashset_1: ::core::option::Option< std::collections::HashSet< String > >, -} - -impl ::core::default::Default for Struct1FormerStorage -{ - #[ inline( always ) ] - fn default() -> Self - { - Self - { - vec_1: ::core::option::Option::None, - hashmap_1: ::core::option::Option::None, - hashset_1: ::core::option::Option::None, - } - } -} - -impl former::Storage for Struct1FormerStorage -{ - type Formed = Struct1; -} - -impl former::StoragePreform for Struct1FormerStorage -{ - fn preform( mut self ) -> ::Formed - { - let vec_1 = if self.vec_1.is_some() - { - self.vec_1.take().unwrap() - } - else - { - { - trait MaybeDefault< T > - { - fn maybe_default( self: &Self ) -> T - { - panic!( "Field 'vec_1' isn't initialized" ) - } - } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where - T: ::core::default::Default, - { - fn maybe_default( self: &Self ) -> T - { - T::default() - } - } - ( &::core::marker::PhantomData::< Vec< String > > ).maybe_default() - } - }; - let hashmap_1 = if self.hashmap_1.is_some() - { - self.hashmap_1.take().unwrap() - } - else - { - { - trait MaybeDefault< T > - { - fn maybe_default( self: &Self ) -> T - { - panic!( "Field 'hashmap_1' isn't initialized" ) - } - } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where - T: ::core::default::Default, - { - fn maybe_default( self: &Self ) -> T - { - T::default() - } - } - ( &::core::marker::PhantomData::< std::collections::HashMap< String, String > > ).maybe_default() - } - }; - let hashset_1 = if self.hashset_1.is_some() - { - self.hashset_1.take().unwrap() - } - else - { - { - trait MaybeDefault< T > - { - fn maybe_default( self: &Self ) -> T - { - panic!( "Field 'hashset_1' isn't initialized" ) - } - } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where - T: ::core::default::Default, - { - fn maybe_default( self: &Self ) -> T - { - T::default() - } - } - ( &::core::marker::PhantomData::< std::collections::HashSet< String > > ).maybe_default() - } - }; - let result = Struct1 { vec_1, hashmap_1, hashset_1, }; - return result; - } -} - -#[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[ default( 31 ) ]\n field1: i32,\n}\n\n```\n" ] -pub struct Struct1Former< Definition = Struct1FormerDefinition > -where - Definition: former::FormerDefinition, - Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, - ::Storage: former::StoragePreform, -{ - storage: ::Storage, - context: core::option::Option< ::Context >, - on_end: core::option::Option< Definition::End >, -} - -#[ automatically_derived ] -impl< Definition > Struct1Former< Definition > -where - Definition: former::FormerDefinition, - Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, - ::Storage: former::StoragePreform, -{ - #[ doc = r"" ] - #[ doc = r" Finish setting options and call perform on formed entity." ] - #[ doc = r"" ] - #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] - #[ doc = r" For example `perform()` of structure with: `#[ perform( fn after1() -> &str ) ]` returns `&str`." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn perform( self ) -> ::Formed - { - let result = self.form(); - return result; - } - - #[ doc = r"" ] - #[ doc = r" Construct new instance of former with default parameters." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn _new_precise( on_end: Definition::End ) -> Self - { - Self::begin( None, None, on_end ) - } - - #[ doc = r"" ] - #[ doc = r" Construct new instance of former with default parameters." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn new< IntoEnd >( end: IntoEnd ) -> Self - where - IntoEnd: Into< Definition::End >, - { - Self::begin( None, None, end, ) - } - - #[ doc = r"" ] - #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn _begin_precise( mut storage: core::option::Option< ::Storage >, context: core::option::Option< ::Context >, on_end: ::End, ) -> Self - { - if storage.is_none() - { - storage = Some( ::core::default::Default::default() ); - } - Self - { - storage: storage.unwrap(), - context: context, - on_end: ::core::option::Option::Some( on_end ), - } - } - - #[ doc = r"" ] - #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn begin< IntoEnd >( mut storage: core::option::Option< ::Storage >, context: core::option::Option< ::Context >, on_end: IntoEnd, ) -> Self - where - IntoEnd: ::core::convert::Into< ::End >, - { - if storage.is_none() - { - storage = Some( ::core::default::Default::default() ); - } - Self - { - storage: storage.unwrap(), - context: context, - on_end: ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), - } - } - - #[ doc = r"" ] - #[ doc = r" End the process of forming returning original context of forming." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn form( self ) -> ::Formed - { - self.end() - } - - #[ doc = r"" ] - #[ doc = r" End the process of forming returning original context of forming." ] - #[ doc = r"" ] - #[ inline( always ) ] - pub fn end( mut self ) -> ::Formed - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) - } - - #[ inline( always ) ] - pub fn vec_1_set< Former2 >( self ) -> Former2 - where - Former2: former::FormerBegin< former::VectorDefinition< String, Self, Self, Struct1Formervec1End, > >, - { - Former2::_begin( None, Some( self ), Struct1Formervec1End ) - } - - pub fn vec_1( self ) -> former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1Formervec1End > > - { - self.vec_1_set::< former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1Formervec1End > > >() - } - - #[ doc = "Setter for the 'hashmap_1' field." ] - #[ inline ] - pub fn hashmap_1< Src >( mut self, src: Src ) -> Self - where - Src: ::core::convert::Into< std::collections::HashMap< String, String > >, - { - debug_assert!( self.storage.hashmap_1.is_none() ); - self.storage.hashmap_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); - self - } - - #[ inline( always ) ] - pub fn hashset_1_set< Former2 >( self ) -> Former2 - where - Former2: former::FormerBegin< former::HashSetDefinition< String, Self, Self, Struct1Formerhashset1End, > >, - { - Former2::_begin( None, Some( self ), Struct1Formerhashset1End ) - } - - pub fn hashset_1( self ) -> former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1Formerhashset1End > > - { - self.hashset_1_set::< former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1Formerhashset1End > > >() - } -} - -impl< Definition > Struct1Former< Definition > -where - Definition: former::FormerDefinition, - Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, - ::Storage: former::StoragePreform, -{ - pub fn preform( self ) -> ::Formed - { - former::StoragePreform::preform( self.storage ) - } -} - -#[ doc = r" Return original former after subformer for `vec_1` is done." ] -#[ allow( non_camel_case_types ) ] -pub struct Struct1Formervec1End; - -#[ automatically_derived ] -impl< Definition > former::FormingEnd< former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > for Struct1Formervec1End -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 > - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.vec_1 - { - former::ContainerAssign::assign( field, storage ); - } - else - { - super_former.storage.vec_1 = Some( storage ); - } - super_former - } -} - -#[ doc = r" Return original former after subformer for `vec_1` is done." ] -#[ allow( non_camel_case_types ) ] -pub struct Struct1Formerhashset1End; - -#[ automatically_derived ] -impl< Definition > former::FormingEnd< former::HashSetDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > for Struct1Formerhashset1End -where - Definition: former::FormerDefinition, - Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, -{ - #[ inline( always ) ] - fn call( &self, storage: std::collections::HashSet< String >, super_former: Option< Struct1Former< Definition > >, ) -> Struct1Former< Definition > - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.hashset_1 - { - former::ContainerAssign::assign( field, storage ); - } - else - { - super_former.storage.hashset_1 = Some( storage ); - } - super_former - } -} +// #[ automatically_derived ] +// impl Struct1 +// { +// #[ doc = r"" ] +// #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn former() -> Struct1Former< > +// { +// Struct1Former::< >::new( former::ReturnPreformed ) +// } +// } +// +// #[ derive( Debug ) ] +// pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > +// { +// _phantom: core::marker::PhantomData<( Context, Formed )>, +// } +// +// impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > +// { +// fn default() -> Self +// { +// Self +// { +// _phantom: core::marker::PhantomData, +// } +// } +// } +// +// #[ derive( Debug ) ] +// pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +// { +// _phantom: core::marker::PhantomData<( Context, Formed, End )>, +// } +// +// impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > +// { +// fn default() -> Self +// { +// Self +// { +// _phantom: core::marker::PhantomData, +// } +// } +// } +// +// impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > +// { +// type Storage = Struct1FormerStorage; +// type Formed = Formed; +// type Context = Context; +// } +// +// impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > +// where +// End: former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, +// { +// type Types = Struct1FormerDefinitionTypes< Context, Formed >; +// type End = End; +// } +// +// pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; +// +// #[ doc = "Container of a corresponding former." ] +// pub struct Struct1FormerStorage +// { +// #[ doc = r" A field" ] +// pub vec_1: ::core::option::Option< Vec< String > >, +// #[ doc = r" A field" ] +// pub hashmap_1: ::core::option::Option< std::collections::HashMap< String, String > >, +// #[ doc = r" A field" ] +// pub hashset_1: ::core::option::Option< std::collections::HashSet< String > >, +// } +// +// impl ::core::default::Default for Struct1FormerStorage +// { +// #[ inline( always ) ] +// fn default() -> Self +// { +// Self +// { +// vec_1: ::core::option::Option::None, +// hashmap_1: ::core::option::Option::None, +// hashset_1: ::core::option::Option::None, +// } +// } +// } +// +// impl former::Storage for Struct1FormerStorage +// { +// type Formed = Struct1; +// } +// +// impl former::StoragePreform for Struct1FormerStorage +// { +// fn preform( mut self ) -> ::Formed +// { +// let vec_1 = if self.vec_1.is_some() +// { +// self.vec_1.take().unwrap() +// } +// else +// { +// { +// trait MaybeDefault< T > +// { +// fn maybe_default( self: &Self ) -> T +// { +// panic!( "Field 'vec_1' isn't initialized" ) +// } +// } +// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} +// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > +// where +// T: ::core::default::Default, +// { +// fn maybe_default( self: &Self ) -> T +// { +// T::default() +// } +// } +// ( &::core::marker::PhantomData::< Vec< String > > ).maybe_default() +// } +// }; +// let hashmap_1 = if self.hashmap_1.is_some() +// { +// self.hashmap_1.take().unwrap() +// } +// else +// { +// { +// trait MaybeDefault< T > +// { +// fn maybe_default( self: &Self ) -> T +// { +// panic!( "Field 'hashmap_1' isn't initialized" ) +// } +// } +// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} +// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > +// where +// T: ::core::default::Default, +// { +// fn maybe_default( self: &Self ) -> T +// { +// T::default() +// } +// } +// ( &::core::marker::PhantomData::< std::collections::HashMap< String, String > > ).maybe_default() +// } +// }; +// let hashset_1 = if self.hashset_1.is_some() +// { +// self.hashset_1.take().unwrap() +// } +// else +// { +// { +// trait MaybeDefault< T > +// { +// fn maybe_default( self: &Self ) -> T +// { +// panic!( "Field 'hashset_1' isn't initialized" ) +// } +// } +// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} +// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > +// where +// T: ::core::default::Default, +// { +// fn maybe_default( self: &Self ) -> T +// { +// T::default() +// } +// } +// ( &::core::marker::PhantomData::< std::collections::HashSet< String > > ).maybe_default() +// } +// }; +// let result = Struct1 { vec_1, hashmap_1, hashset_1, }; +// return result; +// } +// } +// +// #[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[ default( 31 ) ]\n field1: i32,\n}\n\n```\n" ] +// pub struct Struct1Former< Definition = Struct1FormerDefinition > +// where +// Definition: former::FormerDefinition, +// Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +// ::Storage: former::StoragePreform, +// { +// storage: ::Storage, +// context: core::option::Option< ::Context >, +// on_end: core::option::Option< Definition::End >, +// } +// +// #[ automatically_derived ] +// impl< Definition > Struct1Former< Definition > +// where +// Definition: former::FormerDefinition, +// Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +// ::Storage: former::StoragePreform, +// { +// #[ doc = r"" ] +// #[ doc = r" Finish setting options and call perform on formed entity." ] +// #[ doc = r"" ] +// #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] +// #[ doc = r" For example `perform()` of structure with: `#[ perform( fn after1() -> &str ) ]` returns `&str`." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn perform( self ) -> ::Formed +// { +// let result = self.form(); +// return result; +// } +// +// #[ doc = r"" ] +// #[ doc = r" Construct new instance of former with default parameters." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn _new_precise( on_end: Definition::End ) -> Self +// { +// Self::begin( None, None, on_end ) +// } +// +// #[ doc = r"" ] +// #[ doc = r" Construct new instance of former with default parameters." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn new< IntoEnd >( end: IntoEnd ) -> Self +// where +// IntoEnd: Into< Definition::End >, +// { +// Self::begin( None, None, end, ) +// } +// +// #[ doc = r"" ] +// #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn _begin_precise( mut storage: core::option::Option< ::Storage >, context: core::option::Option< ::Context >, on_end: ::End, ) -> Self +// { +// if storage.is_none() +// { +// storage = Some( ::core::default::Default::default() ); +// } +// Self +// { +// storage: storage.unwrap(), +// context: context, +// on_end: ::core::option::Option::Some( on_end ), +// } +// } +// +// #[ doc = r"" ] +// #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn begin< IntoEnd >( mut storage: core::option::Option< ::Storage >, context: core::option::Option< ::Context >, on_end: IntoEnd, ) -> Self +// where +// IntoEnd: ::core::convert::Into< ::End >, +// { +// if storage.is_none() +// { +// storage = Some( ::core::default::Default::default() ); +// } +// Self +// { +// storage: storage.unwrap(), +// context: context, +// on_end: ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), +// } +// } +// +// #[ doc = r"" ] +// #[ doc = r" End the process of forming returning original context of forming." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn form( self ) -> ::Formed +// { +// self.end() +// } +// +// #[ doc = r"" ] +// #[ doc = r" End the process of forming returning original context of forming." ] +// #[ doc = r"" ] +// #[ inline( always ) ] +// pub fn end( mut self ) -> ::Formed +// { +// let on_end = self.on_end.take().unwrap(); +// let context = self.context.take(); +// former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) +// } +// +// #[ inline( always ) ] +// pub fn vec_1_set< Former2 >( self ) -> Former2 +// where +// Former2: former::FormerBegin< former::VectorDefinition< String, Self, Self, Struct1Formervec1End, > >, +// { +// Former2::_begin( None, Some( self ), Struct1Formervec1End ) +// } +// +// pub fn vec_1( self ) -> former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1Formervec1End > > +// { +// self.vec_1_set::< former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1Formervec1End > > >() +// } +// +// #[ doc = "Setter for the 'hashmap_1' field." ] +// #[ inline ] +// pub fn hashmap_1< Src >( mut self, src: Src ) -> Self +// where +// Src: ::core::convert::Into< std::collections::HashMap< String, String > >, +// { +// debug_assert!( self.storage.hashmap_1.is_none() ); +// self.storage.hashmap_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); +// self +// } +// +// #[ inline( always ) ] +// pub fn hashset_1_set< Former2 >( self ) -> Former2 +// where +// Former2: former::FormerBegin< former::HashSetDefinition< String, Self, Self, Struct1Formerhashset1End, > >, +// { +// Former2::_begin( None, Some( self ), Struct1Formerhashset1End ) +// } +// +// pub fn hashset_1( self ) -> former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1Formerhashset1End > > +// { +// self.hashset_1_set::< former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1Formerhashset1End > > >() +// } +// } +// +// impl< Definition > Struct1Former< Definition > +// where +// Definition: former::FormerDefinition, +// Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, +// ::Storage: former::StoragePreform, +// { +// pub fn preform( self ) -> ::Formed +// { +// former::StoragePreform::preform( self.storage ) +// } +// } +// +// #[ doc = r" Return original former after subformer for `vec_1` is done." ] +// #[ allow( non_camel_case_types ) ] +// pub struct Struct1Formervec1End; +// +// #[ automatically_derived ] +// impl< Definition > former::FormingEnd< former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > for Struct1Formervec1End +// 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 > +// { +// let mut super_former = super_former.unwrap(); +// if let Some( ref mut field ) = super_former.storage.vec_1 +// { +// former::ContainerAssign::assign( field, storage ); +// } +// else +// { +// super_former.storage.vec_1 = Some( storage ); +// } +// super_former +// } +// } +// +// #[ doc = r" Return original former after subformer for `vec_1` is done." ] +// #[ allow( non_camel_case_types ) ] +// pub struct Struct1Formerhashset1End; +// +// #[ automatically_derived ] +// impl< Definition > former::FormingEnd< former::HashSetDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > for Struct1Formerhashset1End +// where +// Definition: former::FormerDefinition, +// Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +// { +// #[ inline( always ) ] +// fn call( &self, storage: std::collections::HashSet< String >, super_former: Option< Struct1Former< Definition > >, ) +// -> Struct1Former< Definition > +// { +// let mut super_former = super_former.unwrap(); +// if let Some( ref mut field ) = super_former.storage.hashset_1 +// { +// former::ContainerAssign::assign( field, storage ); +// } +// else +// { +// super_former.storage.hashset_1 = Some( storage ); +// } +// super_former +// } +// } // = generated From 6789c2e68ccc731f9b7e7b2994ae82cc8c91e8db Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 11 Apr 2024 15:02:08 +0300 Subject: [PATCH 121/533] former : experimenting --- .../a_containers_with_subformer.rs | 703 ++++++++---------- 1 file changed, 301 insertions(+), 402 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 94fbd7c742..7828d80d95 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -4,417 +4,316 @@ use super::*; // use std::collections::HashMap; // use std::collections::HashSet; -#[ derive( Default, Debug, PartialEq, former::Former ) ] -#[ debug ] -// #[ derive( Default, Debug, PartialEq ) ] +// #[ derive( Default, Debug, PartialEq, former::Former ) ] +// #[ debug ] +#[ derive( Default, Debug, PartialEq ) ] pub struct Struct1 { - #[ subformer( former::VectorDefinition ) ] + // #[ subformer( former::VectorDefinition ) ] vec_1 : Vec< String >, - #[ subformer( former::HashMapDefinition ) ] + // #[ subformer( former::HashMapDefinition ) ] hashmap_1 : std::collections::HashMap< String, String >, - #[ subformer( former::HashSetDefinition ) ] + // #[ subformer( former::HashSetDefinition ) ] hashset_1 : std::collections::HashSet< String >, } // = generated -// #[ automatically_derived ] -// impl Struct1 -// { -// #[ doc = r"" ] -// #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn former() -> Struct1Former< > -// { -// Struct1Former::< >::new( former::ReturnPreformed ) -// } -// } -// -// #[ derive( Debug ) ] -// pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > -// { -// _phantom: core::marker::PhantomData<( Context, Formed )>, -// } -// -// impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > -// { -// fn default() -> Self -// { -// Self -// { -// _phantom: core::marker::PhantomData, -// } -// } -// } -// -// #[ derive( Debug ) ] -// pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > -// { -// _phantom: core::marker::PhantomData<( Context, Formed, End )>, -// } -// -// impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > -// { -// fn default() -> Self -// { -// Self -// { -// _phantom: core::marker::PhantomData, -// } -// } -// } -// -// impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > -// { -// type Storage = Struct1FormerStorage; -// type Formed = Formed; -// type Context = Context; -// } -// -// impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > -// where -// End: former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, -// { -// type Types = Struct1FormerDefinitionTypes< Context, Formed >; -// type End = End; -// } -// -// pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; -// -// #[ doc = "Container of a corresponding former." ] -// pub struct Struct1FormerStorage -// { -// #[ doc = r" A field" ] -// pub vec_1: ::core::option::Option< Vec< String > >, -// #[ doc = r" A field" ] -// pub hashmap_1: ::core::option::Option< std::collections::HashMap< String, String > >, -// #[ doc = r" A field" ] -// pub hashset_1: ::core::option::Option< std::collections::HashSet< String > >, -// } -// -// impl ::core::default::Default for Struct1FormerStorage -// { -// #[ inline( always ) ] -// fn default() -> Self -// { -// Self -// { -// vec_1: ::core::option::Option::None, -// hashmap_1: ::core::option::Option::None, -// hashset_1: ::core::option::Option::None, -// } -// } -// } -// -// impl former::Storage for Struct1FormerStorage -// { -// type Formed = Struct1; -// } -// -// impl former::StoragePreform for Struct1FormerStorage -// { -// fn preform( mut self ) -> ::Formed -// { -// let vec_1 = if self.vec_1.is_some() -// { -// self.vec_1.take().unwrap() -// } -// else -// { -// { -// trait MaybeDefault< T > -// { -// fn maybe_default( self: &Self ) -> T -// { -// panic!( "Field 'vec_1' isn't initialized" ) -// } -// } -// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} -// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > -// where -// T: ::core::default::Default, -// { -// fn maybe_default( self: &Self ) -> T -// { -// T::default() -// } -// } -// ( &::core::marker::PhantomData::< Vec< String > > ).maybe_default() -// } -// }; -// let hashmap_1 = if self.hashmap_1.is_some() -// { -// self.hashmap_1.take().unwrap() -// } -// else -// { -// { -// trait MaybeDefault< T > -// { -// fn maybe_default( self: &Self ) -> T -// { -// panic!( "Field 'hashmap_1' isn't initialized" ) -// } -// } -// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} -// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > -// where -// T: ::core::default::Default, -// { -// fn maybe_default( self: &Self ) -> T -// { -// T::default() -// } -// } -// ( &::core::marker::PhantomData::< std::collections::HashMap< String, String > > ).maybe_default() -// } -// }; -// let hashset_1 = if self.hashset_1.is_some() -// { -// self.hashset_1.take().unwrap() -// } -// else -// { -// { -// trait MaybeDefault< T > -// { -// fn maybe_default( self: &Self ) -> T -// { -// panic!( "Field 'hashset_1' isn't initialized" ) -// } -// } -// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} -// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > -// where -// T: ::core::default::Default, -// { -// fn maybe_default( self: &Self ) -> T -// { -// T::default() -// } -// } -// ( &::core::marker::PhantomData::< std::collections::HashSet< String > > ).maybe_default() -// } -// }; -// let result = Struct1 { vec_1, hashmap_1, hashset_1, }; -// return result; -// } -// } -// -// #[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[ default( 31 ) ]\n field1: i32,\n}\n\n```\n" ] -// pub struct Struct1Former< Definition = Struct1FormerDefinition > -// where -// Definition: former::FormerDefinition, -// Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, -// ::Storage: former::StoragePreform, -// { -// storage: ::Storage, -// context: core::option::Option< ::Context >, -// on_end: core::option::Option< Definition::End >, -// } -// -// #[ automatically_derived ] -// impl< Definition > Struct1Former< Definition > -// where -// Definition: former::FormerDefinition, -// Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, -// ::Storage: former::StoragePreform, -// { -// #[ doc = r"" ] -// #[ doc = r" Finish setting options and call perform on formed entity." ] -// #[ doc = r"" ] -// #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] -// #[ doc = r" For example `perform()` of structure with: `#[ perform( fn after1() -> &str ) ]` returns `&str`." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn perform( self ) -> ::Formed -// { -// let result = self.form(); -// return result; -// } -// -// #[ doc = r"" ] -// #[ doc = r" Construct new instance of former with default parameters." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn _new_precise( on_end: Definition::End ) -> Self -// { -// Self::begin( None, None, on_end ) -// } -// -// #[ doc = r"" ] -// #[ doc = r" Construct new instance of former with default parameters." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn new< IntoEnd >( end: IntoEnd ) -> Self -// where -// IntoEnd: Into< Definition::End >, -// { -// Self::begin( None, None, end, ) -// } -// -// #[ doc = r"" ] -// #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn _begin_precise( mut storage: core::option::Option< ::Storage >, context: core::option::Option< ::Context >, on_end: ::End, ) -> Self -// { -// if storage.is_none() -// { -// storage = Some( ::core::default::Default::default() ); -// } -// Self -// { -// storage: storage.unwrap(), -// context: context, -// on_end: ::core::option::Option::Some( on_end ), -// } -// } -// -// #[ doc = r"" ] -// #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn begin< IntoEnd >( mut storage: core::option::Option< ::Storage >, context: core::option::Option< ::Context >, on_end: IntoEnd, ) -> Self -// where -// IntoEnd: ::core::convert::Into< ::End >, -// { -// if storage.is_none() -// { -// storage = Some( ::core::default::Default::default() ); -// } -// Self -// { -// storage: storage.unwrap(), -// context: context, -// on_end: ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), -// } -// } -// -// #[ doc = r"" ] -// #[ doc = r" End the process of forming returning original context of forming." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn form( self ) -> ::Formed -// { -// self.end() -// } -// -// #[ doc = r"" ] -// #[ doc = r" End the process of forming returning original context of forming." ] -// #[ doc = r"" ] -// #[ inline( always ) ] -// pub fn end( mut self ) -> ::Formed -// { -// let on_end = self.on_end.take().unwrap(); -// let context = self.context.take(); -// former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) -// } -// -// #[ inline( always ) ] -// pub fn vec_1_set< Former2 >( self ) -> Former2 -// where -// Former2: former::FormerBegin< former::VectorDefinition< String, Self, Self, Struct1Formervec1End, > >, -// { -// Former2::_begin( None, Some( self ), Struct1Formervec1End ) -// } -// -// pub fn vec_1( self ) -> former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1Formervec1End > > -// { -// self.vec_1_set::< former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1Formervec1End > > >() -// } -// -// #[ doc = "Setter for the 'hashmap_1' field." ] -// #[ inline ] -// pub fn hashmap_1< Src >( mut self, src: Src ) -> Self -// where -// Src: ::core::convert::Into< std::collections::HashMap< String, String > >, -// { -// debug_assert!( self.storage.hashmap_1.is_none() ); -// self.storage.hashmap_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); -// self -// } -// -// #[ inline( always ) ] -// pub fn hashset_1_set< Former2 >( self ) -> Former2 -// where -// Former2: former::FormerBegin< former::HashSetDefinition< String, Self, Self, Struct1Formerhashset1End, > >, -// { -// Former2::_begin( None, Some( self ), Struct1Formerhashset1End ) -// } -// -// pub fn hashset_1( self ) -> former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1Formerhashset1End > > -// { -// self.hashset_1_set::< former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1Formerhashset1End > > >() -// } -// } -// -// impl< Definition > Struct1Former< Definition > -// where -// Definition: former::FormerDefinition, -// Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, -// ::Storage: former::StoragePreform, -// { -// pub fn preform( self ) -> ::Formed -// { -// former::StoragePreform::preform( self.storage ) -// } -// } -// -// #[ doc = r" Return original former after subformer for `vec_1` is done." ] -// #[ allow( non_camel_case_types ) ] -// pub struct Struct1Formervec1End; -// -// #[ automatically_derived ] -// impl< Definition > former::FormingEnd< former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > for Struct1Formervec1End -// 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 > -// { -// let mut super_former = super_former.unwrap(); -// if let Some( ref mut field ) = super_former.storage.vec_1 -// { -// former::ContainerAssign::assign( field, storage ); -// } -// else -// { -// super_former.storage.vec_1 = Some( storage ); -// } -// super_former -// } -// } -// -// #[ doc = r" Return original former after subformer for `vec_1` is done." ] -// #[ allow( non_camel_case_types ) ] -// pub struct Struct1Formerhashset1End; -// -// #[ automatically_derived ] -// impl< Definition > former::FormingEnd< former::HashSetDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > for Struct1Formerhashset1End -// where -// Definition: former::FormerDefinition, -// Definition::Types: former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, -// { -// #[ inline( always ) ] -// fn call( &self, storage: std::collections::HashSet< String >, super_former: Option< Struct1Former< Definition > >, ) -// -> Struct1Former< Definition > -// { -// let mut super_former = super_former.unwrap(); -// if let Some( ref mut field ) = super_former.storage.hashset_1 -// { -// former::ContainerAssign::assign( field, storage ); -// } -// else -// { -// super_former.storage.hashset_1 = Some( storage ); -// } -// super_former -// } -// } +#[automatically_derived] impl Struct1 +{ + #[doc = r""] + #[doc = + r" Make former, variation of builder pattern to form structure defining values of fields step by step."] + #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < > + { Struct1Former :: < > :: new(former :: ReturnPreformed) } +} #[derive(Debug)] pub struct Struct1FormerDefinitionTypes < Context = (), +Formed = Struct1 > +{ _phantom : core :: marker :: PhantomData < (Context, Formed) >, } impl < +Context, Formed > Default for Struct1FormerDefinitionTypes < Context, Formed > +{ + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } +} #[derive(Debug)] pub struct Struct1FormerDefinition < Context = (), Formed = +Struct1, End = former :: ReturnPreformed > +{ _phantom : core :: marker :: PhantomData < (Context, Formed, End) >, } impl +< Context, Formed, End > Default for Struct1FormerDefinition < Context, +Formed, End > +{ + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } +} impl < Context, Formed > former :: FormerDefinitionTypes for +Struct1FormerDefinitionTypes < Context, Formed > +{ + type Storage = Struct1FormerStorage ; type Formed = Formed ; type Context + = Context ; +} impl < Context, Formed, End > former :: FormerDefinition for +Struct1FormerDefinition < Context, Formed, End > where End : former :: +FormingEnd < Struct1FormerDefinitionTypes < Context, Formed > >, +{ + type Types = Struct1FormerDefinitionTypes < Context, Formed > ; type End = + End ; +} pub type Struct1FormerWithClosure < Context, Formed > = +Struct1FormerDefinition < Context, Formed, former :: FormingEndClosure < +Struct1FormerDefinitionTypes < Context, Formed > > > ; +#[doc = "Container of a corresponding former."] pub struct +Struct1FormerStorage +{ + #[doc = r" A field"] pub vec_1 : :: core :: option :: Option < Vec < + String > >, #[doc = r" A field"] pub hashmap_1 : :: core :: option :: + Option < std :: collections :: HashMap < String, String > >, + #[doc = r" A field"] pub hashset_1 : :: core :: option :: Option < std :: + collections :: HashSet < String > >, +} impl :: core :: default :: Default for Struct1FormerStorage +{ + #[inline(always)] fn default() -> Self + { + Self + { + vec_1 : :: core :: option :: Option :: None, hashmap_1 : :: core + :: option :: Option :: None, hashset_1 : :: core :: option :: + Option :: None, + } + } +} impl former :: Storage for Struct1FormerStorage { type Formed = Struct1 ; } +impl former :: StoragePreform for Struct1FormerStorage +{ + fn preform(mut self) -> < Self as former :: Storage > :: Formed + { + let vec_1 = if self.vec_1.is_some() { self.vec_1.take().unwrap() } + else + { + { + trait MaybeDefault < T > + { + fn maybe_default(self : & Self) -> T + { panic! ("Field 'vec_1' isn't initialized") } + } impl < T > MaybeDefault < T > for & :: core :: marker :: + PhantomData < T > {} impl < T > MaybeDefault < T > for :: core + :: marker :: PhantomData < T > where T : :: core :: default :: + Default, + { fn maybe_default(self : & Self) -> T { T :: default() } } + (& :: core :: marker :: PhantomData :: < Vec < String > + >).maybe_default() + } + } ; let hashmap_1 = if self.hashmap_1.is_some() + { self.hashmap_1.take().unwrap() } else + { + { + trait MaybeDefault < T > + { + fn maybe_default(self : & Self) -> T + { panic! ("Field 'hashmap_1' isn't initialized") } + } impl < T > MaybeDefault < T > for & :: core :: marker :: + PhantomData < T > {} impl < T > MaybeDefault < T > for :: core + :: marker :: PhantomData < T > where T : :: core :: default :: + Default, + { fn maybe_default(self : & Self) -> T { T :: default() } } + (& :: core :: marker :: PhantomData :: < std :: collections :: + HashMap < String, String > >).maybe_default() + } + } ; let hashset_1 = if self.hashset_1.is_some() + { self.hashset_1.take().unwrap() } else + { + { + trait MaybeDefault < T > + { + fn maybe_default(self : & Self) -> T + { panic! ("Field 'hashset_1' isn't initialized") } + } impl < T > MaybeDefault < T > for & :: core :: marker :: + PhantomData < T > {} impl < T > MaybeDefault < T > for :: core + :: marker :: PhantomData < T > where T : :: core :: default :: + Default, + { fn maybe_default(self : & Self) -> T { T :: default() } } + (& :: core :: marker :: PhantomData :: < std :: collections :: + HashSet < String > >).maybe_default() + } + } ; let result = Struct1 { vec_1, hashmap_1, hashset_1, } ; return + result ; + } +} +#[doc = +" Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +pub struct Struct1Former < Definition = Struct1FormerDefinition > where +Definition : former :: FormerDefinition, Definition :: Types : former :: +FormerDefinitionTypes < Storage = Struct1FormerStorage >, < Definition :: +Types as former :: FormerDefinitionTypes > :: Storage : former :: +StoragePreform, +{ + storage : < Definition :: Types as former :: FormerDefinitionTypes > :: + Storage, context : core :: option :: Option < < Definition :: Types as + former :: FormerDefinitionTypes > :: Context >, on_end : core :: option :: + Option < Definition :: End >, +} #[automatically_derived] impl < Definition > Struct1Former < Definition > +where Definition : former :: FormerDefinition, Definition :: Types : former :: +FormerDefinitionTypes < Storage = Struct1FormerStorage >, < Definition :: +Types as former :: FormerDefinitionTypes > :: Storage : former :: +StoragePreform, +{ + #[doc = r""] + #[doc = r" Finish setting options and call perform on formed entity."] + #[doc = r""] + #[doc = + r" If `perform` defined then associated method is called and its result returned instead of entity."] + #[doc = + r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] + #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { let result = self.form() ; return result ; } #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn + _new_precise(on_end : Definition :: End) -> Self + { Self :: begin(None, None, on_end) } #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new < IntoEnd > (end : IntoEnd) -> + Self where IntoEnd : Into < Definition :: End >, + { Self :: begin(None, None, end,) } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn + _begin_precise(mut storage : core :: option :: Option < < Definition :: + Types as former :: FormerDefinitionTypes > :: Storage >, context : core :: + option :: Option < < Definition :: Types as former :: + FormerDefinitionTypes > :: Context >, on_end : < Definition as former :: + FormerDefinition > :: End,) -> Self + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()) ; } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: Some(on_end), + } + } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn begin < IntoEnd > + (mut storage : core :: option :: Option < < Definition :: Types as former + :: FormerDefinitionTypes > :: Storage >, context : core :: option :: + Option < < Definition :: Types as former :: FormerDefinitionTypes > :: + Context >, on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert + :: Into < < Definition as former :: FormerDefinition > :: End >, + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()) ; } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: + Some(:: core :: convert :: Into :: into(on_end)), + } + } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types + as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { + let on_end = self.on_end.take().unwrap() ; let context = + self.context.take() ; former :: FormingEnd :: < Definition :: Types > + :: call(& on_end, self.storage, context) + } #[inline(always)] pub fn vec_1_set < Former2 > (self) -> Former2 where + Former2 : former :: FormerBegin < former :: VectorDefinition < String, + Self, Self, Struct1Formervec1End, > >, + { Former2 :: _begin(None, Some(self), Struct1Formervec1End) } pub fn + vec_1(self) -> former :: ContainerSubformer :: < String, former :: + VectorDefinition < String, Self, Self, Struct1Formervec1End > > + { + self.vec_1_set :: < former :: ContainerSubformer :: < String, former + :: VectorDefinition < String, Self, Self, Struct1Formervec1End > >> () + } #[inline(always)] + + + pub fn hashmap_1_set < Former2 > (self) -> Former2 + where Former2 : former :: FormerBegin < former :: HashMapDefinition < + String, String, Self, Self, Struct1Formerhashmap1End, > >, + { Former2 :: _begin(None, Some(self), Struct1Formerhashmap1End) } + + pub fn + hashmap_1(self) -> former :: ContainerSubformer :: < ( String, String ), + former :: HashMapDefinition < String, String, Self, Self, + Struct1Formerhashmap1End > > + { + self.hashmap_1_set :: < former :: ContainerSubformer :: < ( String, + String ), former :: HashMapDefinition < String, String, Self, Self, + Struct1Formerhashmap1End > >> () + } + + #[inline(always)] + pub fn hashset_1_set < Former2 > (self) -> Former2 + where Former2 : former :: FormerBegin < former :: HashSetDefinition < + String, Self, Self, Struct1Formerhashset1End, > >, + { Former2 :: _begin(None, Some(self), Struct1Formerhashset1End) } pub fn + hashset_1(self) -> former :: ContainerSubformer :: < ( String ), former :: + HashSetDefinition < ( String ), Self, Self, Struct1Formerhashset1End > > + { + self.hashset_1_set :: < former :: ContainerSubformer :: < ( String ), + former :: HashSetDefinition < ( String ), Self, Self, + Struct1Formerhashset1End > >> () + } +} impl < Definition > Struct1Former < Definition > where Definition : former +:: FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +Storage = Struct1FormerStorage, Formed = Struct1 >, < Definition :: Types as +former :: FormerDefinitionTypes > :: Storage : former :: StoragePreform, +{ + pub fn preform(self) -> < Definition :: Types as former :: + FormerDefinitionTypes > :: Formed + { former :: StoragePreform :: preform(self.storage) } +} #[doc = r" Return original former after subformer for `vec_1` is done."] +#[allow(non_camel_case_types)] pub struct Struct1Formervec1End ; +#[automatically_derived] impl < Definition > former :: FormingEnd < former :: +VectorDefinition < String, Struct1Former < Definition >, Struct1Former < +Definition >, former :: NoEnd >, > for Struct1Formervec1End 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 > + { + let mut super_former = super_former.unwrap() ; if let + Some(ref mut field) = super_former.storage.vec_1 + { former :: ContainerAssign :: assign(field, storage) ; } else + { super_former.storage.vec_1 = Some(storage) ; } super_former + } +} #[doc = r" Return original former after subformer for `vec_1` is done."] +#[allow(non_camel_case_types)] pub struct Struct1Formerhashmap1End ; +#[automatically_derived] impl < Definition > former :: FormingEnd < former :: +HashMapDefinition < String, String, Struct1Former < Definition >, +Struct1Former < Definition >, former :: NoEnd >, > for +Struct1Formerhashmap1End where Definition : former :: FormerDefinition, +Definition :: Types : former :: FormerDefinitionTypes < Storage = +Struct1FormerStorage >, +{ + #[inline(always)] fn + call(& self, storage : std :: collections :: HashMap < String, String >, + super_former : Option < Struct1Former < Definition > >,) -> Struct1Former + < Definition > + { + let mut super_former = super_former.unwrap() ; if let + Some(ref mut field) = super_former.storage.hashmap_1 + { former :: ContainerAssign :: assign(field, storage) ; } else + { super_former.storage.hashmap_1 = Some(storage) ; } super_former + } +} #[doc = r" Return original former after subformer for `vec_1` is done."] +#[allow(non_camel_case_types)] pub struct Struct1Formerhashset1End ; +#[automatically_derived] impl < Definition > former :: FormingEnd < former :: +HashSetDefinition < String, Struct1Former < Definition >, Struct1Former < +Definition >, former :: NoEnd >, > for Struct1Formerhashset1End where +Definition : former :: FormerDefinition, Definition :: Types : former :: +FormerDefinitionTypes < Storage = Struct1FormerStorage >, +{ + #[inline(always)] fn + call(& self, storage : std :: collections :: HashSet < String >, + super_former : Option < Struct1Former < Definition > >,) -> Struct1Former + < Definition > + { + let mut super_former = super_former.unwrap() ; if let + Some(ref mut field) = super_former.storage.hashset_1 + { former :: ContainerAssign :: assign(field, storage) ; } else + { super_former.storage.hashset_1 = Some(storage) ; } super_former + } +} // = generated From d37cfd0df455385346a14bc6ab4919f1256f8233 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 12 Apr 2024 10:34:08 +0300 Subject: [PATCH 122/533] former : experimenting --- .../a_containers_with_subformer.rs | 308 +----------------- .../a_containers_with_subformer_2_manual.rs | 298 ----------------- .../a_containers_with_subformer_manual.rs | 36 +- .../only_test/containers_with_subformer.rs | 177 +++++----- module/core/former_meta/src/derive/former.rs | 80 +++-- 5 files changed, 173 insertions(+), 726 deletions(-) delete mode 100644 module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 7828d80d95..a3c1b9017b 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -4,319 +4,23 @@ use super::*; // use std::collections::HashMap; // use std::collections::HashSet; -// #[ derive( Default, Debug, PartialEq, former::Former ) ] +#[ derive( Default, Debug, PartialEq, former::Former ) ] // #[ debug ] -#[ derive( Default, Debug, PartialEq ) ] +// #[ derive( Default, Debug, PartialEq ) ] pub struct Struct1 { - // #[ subformer( former::VectorDefinition ) ] + #[ subformer( former::VectorDefinition ) ] vec_1 : Vec< String >, - // #[ subformer( former::HashMapDefinition ) ] + #[ subformer( former::HashMapDefinition ) ] hashmap_1 : std::collections::HashMap< String, String >, - // #[ subformer( former::HashSetDefinition ) ] + #[ subformer( former::HashSetDefinition ) ] hashset_1 : std::collections::HashSet< String >, } // = generated -#[automatically_derived] impl Struct1 -{ - #[doc = r""] - #[doc = - r" Make former, variation of builder pattern to form structure defining values of fields step by step."] - #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < > - { Struct1Former :: < > :: new(former :: ReturnPreformed) } -} #[derive(Debug)] pub struct Struct1FormerDefinitionTypes < Context = (), -Formed = Struct1 > -{ _phantom : core :: marker :: PhantomData < (Context, Formed) >, } impl < -Context, Formed > Default for Struct1FormerDefinitionTypes < Context, Formed > -{ - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } -} #[derive(Debug)] pub struct Struct1FormerDefinition < Context = (), Formed = -Struct1, End = former :: ReturnPreformed > -{ _phantom : core :: marker :: PhantomData < (Context, Formed, End) >, } impl -< Context, Formed, End > Default for Struct1FormerDefinition < Context, -Formed, End > -{ - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } -} impl < Context, Formed > former :: FormerDefinitionTypes for -Struct1FormerDefinitionTypes < Context, Formed > -{ - type Storage = Struct1FormerStorage ; type Formed = Formed ; type Context - = Context ; -} impl < Context, Formed, End > former :: FormerDefinition for -Struct1FormerDefinition < Context, Formed, End > where End : former :: -FormingEnd < Struct1FormerDefinitionTypes < Context, Formed > >, -{ - type Types = Struct1FormerDefinitionTypes < Context, Formed > ; type End = - End ; -} pub type Struct1FormerWithClosure < Context, Formed > = -Struct1FormerDefinition < Context, Formed, former :: FormingEndClosure < -Struct1FormerDefinitionTypes < Context, Formed > > > ; -#[doc = "Container of a corresponding former."] pub struct -Struct1FormerStorage -{ - #[doc = r" A field"] pub vec_1 : :: core :: option :: Option < Vec < - String > >, #[doc = r" A field"] pub hashmap_1 : :: core :: option :: - Option < std :: collections :: HashMap < String, String > >, - #[doc = r" A field"] pub hashset_1 : :: core :: option :: Option < std :: - collections :: HashSet < String > >, -} impl :: core :: default :: Default for Struct1FormerStorage -{ - #[inline(always)] fn default() -> Self - { - Self - { - vec_1 : :: core :: option :: Option :: None, hashmap_1 : :: core - :: option :: Option :: None, hashset_1 : :: core :: option :: - Option :: None, - } - } -} impl former :: Storage for Struct1FormerStorage { type Formed = Struct1 ; } -impl former :: StoragePreform for Struct1FormerStorage -{ - fn preform(mut self) -> < Self as former :: Storage > :: Formed - { - let vec_1 = if self.vec_1.is_some() { self.vec_1.take().unwrap() } - else - { - { - trait MaybeDefault < T > - { - fn maybe_default(self : & Self) -> T - { panic! ("Field 'vec_1' isn't initialized") } - } impl < T > MaybeDefault < T > for & :: core :: marker :: - PhantomData < T > {} impl < T > MaybeDefault < T > for :: core - :: marker :: PhantomData < T > where T : :: core :: default :: - Default, - { fn maybe_default(self : & Self) -> T { T :: default() } } - (& :: core :: marker :: PhantomData :: < Vec < String > - >).maybe_default() - } - } ; let hashmap_1 = if self.hashmap_1.is_some() - { self.hashmap_1.take().unwrap() } else - { - { - trait MaybeDefault < T > - { - fn maybe_default(self : & Self) -> T - { panic! ("Field 'hashmap_1' isn't initialized") } - } impl < T > MaybeDefault < T > for & :: core :: marker :: - PhantomData < T > {} impl < T > MaybeDefault < T > for :: core - :: marker :: PhantomData < T > where T : :: core :: default :: - Default, - { fn maybe_default(self : & Self) -> T { T :: default() } } - (& :: core :: marker :: PhantomData :: < std :: collections :: - HashMap < String, String > >).maybe_default() - } - } ; let hashset_1 = if self.hashset_1.is_some() - { self.hashset_1.take().unwrap() } else - { - { - trait MaybeDefault < T > - { - fn maybe_default(self : & Self) -> T - { panic! ("Field 'hashset_1' isn't initialized") } - } impl < T > MaybeDefault < T > for & :: core :: marker :: - PhantomData < T > {} impl < T > MaybeDefault < T > for :: core - :: marker :: PhantomData < T > where T : :: core :: default :: - Default, - { fn maybe_default(self : & Self) -> T { T :: default() } } - (& :: core :: marker :: PhantomData :: < std :: collections :: - HashSet < String > >).maybe_default() - } - } ; let result = Struct1 { vec_1, hashmap_1, hashset_1, } ; return - result ; - } -} -#[doc = -" Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -pub struct Struct1Former < Definition = Struct1FormerDefinition > where -Definition : former :: FormerDefinition, Definition :: Types : former :: -FormerDefinitionTypes < Storage = Struct1FormerStorage >, < Definition :: -Types as former :: FormerDefinitionTypes > :: Storage : former :: -StoragePreform, -{ - storage : < Definition :: Types as former :: FormerDefinitionTypes > :: - Storage, context : core :: option :: Option < < Definition :: Types as - former :: FormerDefinitionTypes > :: Context >, on_end : core :: option :: - Option < Definition :: End >, -} #[automatically_derived] impl < Definition > Struct1Former < Definition > -where Definition : former :: FormerDefinition, Definition :: Types : former :: -FormerDefinitionTypes < Storage = Struct1FormerStorage >, < Definition :: -Types as former :: FormerDefinitionTypes > :: Storage : former :: -StoragePreform, -{ - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] - #[doc = - r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = - r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { let result = self.form() ; return result ; } #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn - _new_precise(on_end : Definition :: End) -> Self - { Self :: begin(None, None, on_end) } #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new < IntoEnd > (end : IntoEnd) -> - Self where IntoEnd : Into < Definition :: End >, - { Self :: begin(None, None, end,) } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn - _begin_precise(mut storage : core :: option :: Option < < Definition :: - Types as former :: FormerDefinitionTypes > :: Storage >, context : core :: - option :: Option < < Definition :: Types as former :: - FormerDefinitionTypes > :: Context >, on_end : < Definition as former :: - FormerDefinition > :: End,) -> Self - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()) ; } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: Some(on_end), - } - } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn begin < IntoEnd > - (mut storage : core :: option :: Option < < Definition :: Types as former - :: FormerDefinitionTypes > :: Storage >, context : core :: option :: - Option < < Definition :: Types as former :: FormerDefinitionTypes > :: - Context >, on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert - :: Into < < Definition as former :: FormerDefinition > :: End >, - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()) ; } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: - Some(:: core :: convert :: Into :: into(on_end)), - } - } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types - as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { - let on_end = self.on_end.take().unwrap() ; let context = - self.context.take() ; former :: FormingEnd :: < Definition :: Types > - :: call(& on_end, self.storage, context) - } #[inline(always)] pub fn vec_1_set < Former2 > (self) -> Former2 where - Former2 : former :: FormerBegin < former :: VectorDefinition < String, - Self, Self, Struct1Formervec1End, > >, - { Former2 :: _begin(None, Some(self), Struct1Formervec1End) } pub fn - vec_1(self) -> former :: ContainerSubformer :: < String, former :: - VectorDefinition < String, Self, Self, Struct1Formervec1End > > - { - self.vec_1_set :: < former :: ContainerSubformer :: < String, former - :: VectorDefinition < String, Self, Self, Struct1Formervec1End > >> () - } #[inline(always)] - - - pub fn hashmap_1_set < Former2 > (self) -> Former2 - where Former2 : former :: FormerBegin < former :: HashMapDefinition < - String, String, Self, Self, Struct1Formerhashmap1End, > >, - { Former2 :: _begin(None, Some(self), Struct1Formerhashmap1End) } - - pub fn - hashmap_1(self) -> former :: ContainerSubformer :: < ( String, String ), - former :: HashMapDefinition < String, String, Self, Self, - Struct1Formerhashmap1End > > - { - self.hashmap_1_set :: < former :: ContainerSubformer :: < ( String, - String ), former :: HashMapDefinition < String, String, Self, Self, - Struct1Formerhashmap1End > >> () - } - - #[inline(always)] - pub fn hashset_1_set < Former2 > (self) -> Former2 - where Former2 : former :: FormerBegin < former :: HashSetDefinition < - String, Self, Self, Struct1Formerhashset1End, > >, - { Former2 :: _begin(None, Some(self), Struct1Formerhashset1End) } pub fn - hashset_1(self) -> former :: ContainerSubformer :: < ( String ), former :: - HashSetDefinition < ( String ), Self, Self, Struct1Formerhashset1End > > - { - self.hashset_1_set :: < former :: ContainerSubformer :: < ( String ), - former :: HashSetDefinition < ( String ), Self, Self, - Struct1Formerhashset1End > >> () - } -} impl < Definition > Struct1Former < Definition > where Definition : former -:: FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -Storage = Struct1FormerStorage, Formed = Struct1 >, < Definition :: Types as -former :: FormerDefinitionTypes > :: Storage : former :: StoragePreform, -{ - pub fn preform(self) -> < Definition :: Types as former :: - FormerDefinitionTypes > :: Formed - { former :: StoragePreform :: preform(self.storage) } -} #[doc = r" Return original former after subformer for `vec_1` is done."] -#[allow(non_camel_case_types)] pub struct Struct1Formervec1End ; -#[automatically_derived] impl < Definition > former :: FormingEnd < former :: -VectorDefinition < String, Struct1Former < Definition >, Struct1Former < -Definition >, former :: NoEnd >, > for Struct1Formervec1End 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 > - { - let mut super_former = super_former.unwrap() ; if let - Some(ref mut field) = super_former.storage.vec_1 - { former :: ContainerAssign :: assign(field, storage) ; } else - { super_former.storage.vec_1 = Some(storage) ; } super_former - } -} #[doc = r" Return original former after subformer for `vec_1` is done."] -#[allow(non_camel_case_types)] pub struct Struct1Formerhashmap1End ; -#[automatically_derived] impl < Definition > former :: FormingEnd < former :: -HashMapDefinition < String, String, Struct1Former < Definition >, -Struct1Former < Definition >, former :: NoEnd >, > for -Struct1Formerhashmap1End where Definition : former :: FormerDefinition, -Definition :: Types : former :: FormerDefinitionTypes < Storage = -Struct1FormerStorage >, -{ - #[inline(always)] fn - call(& self, storage : std :: collections :: HashMap < String, String >, - super_former : Option < Struct1Former < Definition > >,) -> Struct1Former - < Definition > - { - let mut super_former = super_former.unwrap() ; if let - Some(ref mut field) = super_former.storage.hashmap_1 - { former :: ContainerAssign :: assign(field, storage) ; } else - { super_former.storage.hashmap_1 = Some(storage) ; } super_former - } -} #[doc = r" Return original former after subformer for `vec_1` is done."] -#[allow(non_camel_case_types)] pub struct Struct1Formerhashset1End ; -#[automatically_derived] impl < Definition > former :: FormingEnd < former :: -HashSetDefinition < String, Struct1Former < Definition >, Struct1Former < -Definition >, former :: NoEnd >, > for Struct1Formerhashset1End where -Definition : former :: FormerDefinition, Definition :: Types : former :: -FormerDefinitionTypes < Storage = Struct1FormerStorage >, -{ - #[inline(always)] fn - call(& self, storage : std :: collections :: HashSet < String >, - super_former : Option < Struct1Former < Definition > >,) -> Struct1Former - < Definition > - { - let mut super_former = super_former.unwrap() ; if let - Some(ref mut field) = super_former.storage.hashset_1 - { former :: ContainerAssign :: assign(field, storage) ; } else - { super_former.storage.hashset_1 = Some(storage) ; } super_former - } -} - // = generated -// include!( "./only_test/containers_with_subformer.rs" ); +include!( "./only_test/containers_with_subformer.rs" ); // xxx : uncomment diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs deleted file mode 100644 index 4dd9293b71..0000000000 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_2_manual.rs +++ /dev/null @@ -1,298 +0,0 @@ -// #[ allow( unused_imports ) ] -// use super::*; -// -// // xxx : take care -// -// #[ derive( Debug, PartialEq ) ] -// pub struct Struct1 -// { -// vec_1 : Vec< String >, -// hashmap_1 : std::collections::HashMap< String, String >, -// hashset_1 : std::collections::HashSet< String >, -// } -// -// // = formed -// -// impl Struct1 -// { -// pub fn former() -> Struct1Former< Struct1, the_module::ReturnPreformed > -// { -// Struct1Former::< Struct1, the_module::ReturnPreformed >::new() -// } -// } -// -// // = storage -// -// // generated by former -// pub struct Struct1FormerStorage -// { -// 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 > >, -// } -// -// impl Default for Struct1FormerStorage -// { -// -// #[ inline( always ) ] -// fn default() -> Self -// { -// Self -// { -// vec_1 : None, -// hashmap_1 : None, -// hashset_1 : None, -// } -// } -// -// } -// -// // = former -// -// pub struct Struct1Former -// < -// Context = Struct1, -// End = the_module::ReturnPreformed, -// > -// where -// End : the_module::FormingEnd< Struct1, Context >, -// { -// storage : Struct1FormerStorage, -// context : ::core::option::Option< Context >, -// on_end : ::core::option::Option< End >, -// } -// -// impl< Context, End > Struct1Former< Context, End > -// where -// End : the_module::FormingEnd< Struct1, Context >, -// { -// -// #[ inline( always ) ] -// fn form( mut self ) -> Struct1 -// { -// -// let vec_1 = if self.storage.vec_1.is_some() -// { -// self.storage.vec_1.take().unwrap() -// } -// else -// { -// let val : Vec< String > = Default::default(); -// val -// }; -// -// let hashmap_1 = if self.storage.hashmap_1.is_some() -// { -// self.storage.hashmap_1.take().unwrap() -// } -// else -// { -// let val : std::collections::HashMap< String, String > = Default::default(); -// val -// }; -// -// let hashset_1 = if self.storage.hashset_1.is_some() -// { -// self.storage.hashset_1.take().unwrap() -// } -// else -// { -// let val : std::collections::HashSet< String > = Default::default(); -// val -// }; -// -// Struct1 -// { -// vec_1, -// hashmap_1, -// hashset_1, -// } -// -// } -// -// #[ inline( always ) ] -// pub fn perform(self) -> Struct1 -// { -// let result = self.form(); -// return result; -// } -// -// // #[ inline( always ) ] -// // pub fn new() -> Struct1Former -// // { -// // Struct1Former:: -// // < -// // Struct1, -// // the_module::ReturnPreformed, -// // >::begin(None, the_module::ReturnPreformed) -// // } -// -// #[ inline( always ) ] -// pub fn begin -// ( -// mut storage : ::core::option::Option< Struct1FormerStorage >, -// context : ::core::option::Option< Context >, -// on_end : End, -// ) -> Self -// { -// if storage.is_none() -// { -// storage = Some( Default::default() ); -// } -// Self -// { -// storage : storage.unwrap(), -// context, -// on_end : ::core::option::Option::Some( on_end ), -// } -// } -// -// #[ inline( always ) ] -// pub fn end( mut self ) -> Context -// { -// let on_end = self.on_end.take().unwrap(); -// let context = self.context.take(); -// let formed = self.form(); -// on_end.call( formed, context ) -// } -// -// #[ inline( always ) ] -// pub fn __vec_1< Former2 >( self ) -> Former2 -// where -// Former2 : former::FormerBegin -// < -// Vec< String >, -// Vec< String >, -// Self, End = former::FormingEndClosure< Vec< String >, Self >, -// >, -// { -// let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self -// { -// let mut super_former = super_former.unwrap(); -// if let Some( ref mut field ) = super_former.storage.vec_1 -// { -// former::ContainerAssign::assign( field, formed ); -// } -// else -// { -// super_former.storage.vec_1 = Some( formed ); -// } -// super_former -// }; -// Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) -// } -// -// // xxx2 : continue -// pub fn vec_1( self ) -> the_module::VectorSubformer -// < -// String, -// Vec< String >, -// Self, -// impl the_module::FormingEnd< Vec< String >, Self >, -// > -// { -// self.__vec_1::< the_module::VectorSubformer::< _, _, _, _ > >() -// } -// -// // pub fn vec_1( mut self ) -> the_module::VectorSubformer -// // < -// // String, -// // Vec< String >, -// // Self, -// // impl the_module::FormingEnd< Vec< String >, Self >, -// // > -// // { -// // let formed = self.storage.vec_1.take(); -// // let on_end = | formed : Vec< String >, super_former : ::core::option::Option< Self > | -> Self -// // { -// // let mut super_former = super_former.unwrap(); -// // super_former.storage.vec_1 = Some( formed ); -// // super_former -// // }; -// // the_module::VectorSubformer::< String, Vec< String >, Self, _ >::begin( Some( self ), formed, on_end ) -// // } -// -// pub fn hashmap_1( mut self ) -> the_module::HashMapSubformer -// < -// String, -// String, -// std::collections::HashMap< String, String >, -// Self, -// impl the_module::FormingEnd< std::collections::HashMap< String, String >, Self >, -// > -// { -// let formed = self.storage.hashmap_1.take(); -// let on_end = | formed : std::collections::HashMap< String, String >, super_former : ::core::option::Option< Self > | -> Self -// { -// let mut super_former = super_former.unwrap(); -// super_former.storage.hashmap_1 = Some( formed ); -// super_former -// }; -// the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) -// } -// -// pub fn hashset_1( mut self ) -> the_module::HashSetSubformer -// < -// String, -// std::collections::HashSet< String >, -// Self, -// impl the_module::FormingEnd< std::collections::HashSet< String >, Self >, -// > -// { -// let formed = self.storage.hashset_1.take(); -// let on_end = | formed : std::collections::HashSet< String >, super_former : ::core::option::Option< Self > | -> Self -// { -// let mut super_former = super_former.unwrap(); -// super_former.storage.hashset_1 = Some( formed ); -// super_former -// }; -// the_module::HashSetSubformer::begin( formed, Some( self ), on_end ) -// } -// -// } -// -// // impl< Context, End > Struct1Former< Context, End > -// // where -// // End: the_module::FormingEnd, -// -// impl Struct1Former< Struct1, the_module::ReturnPreformed > -// { -// -// #[ inline( always ) ] -// pub fn new() -> Self -// { -// Self::begin( None, None, the_module::ReturnPreformed ) -// } -// -// } -// -// // -// -// // impl< Context, End > Struct1Former< Context, End > -// // where -// // End : the_module::FormingEnd< Struct1, Context >, -// -// impl< Context, End > former::FormerBegin< Struct1FormerStorage, Struct1, Context > -// for Struct1Former< Context, End > -// where -// End : the_module::FormingEnd< Struct1, Context >, -// { -// type End = End; -// -// #[ inline( always ) ] -// fn _begin -// ( -// storage : core::option::Option< Struct1FormerStorage >, /* xxx2 : that should be storage */ -// context : core::option::Option< Context >, -// on_end : End, -// ) -> Self -// { -// debug_assert!( storage.is_none() ); -// Self::begin( None, context, on_end ) -// } -// -// } -// -// // -// -// include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index e1eef17936..b3a9d0b152 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -330,22 +330,22 @@ where String, Self, Self, - Struct1FormerVec_1End, + Struct1FormerVec1End, > >, { - Former2::_begin( None, Some( self ), Struct1FormerVec_1End ) + Former2::_begin( None, Some( self ), Struct1FormerVec1End ) } pub fn vec_1( self ) -> former::ContainerSubformer:: < - String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > + String, former::VectorDefinition< String, Self, Self, Struct1FormerVec1End > > { self.vec_1_set::< former::ContainerSubformer:: < - String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > + String, former::VectorDefinition< String, Self, Self, Struct1FormerVec1End > >>() } @@ -360,22 +360,22 @@ where String, Self, Self, - Struct1FormerHashmap_1End, + Struct1FormerHashmap1End, > >, { - Former2::_begin( None, Some( self ), Struct1FormerHashmap_1End ) + Former2::_begin( None, Some( self ), Struct1FormerHashmap1End ) } pub fn hashmap_1( self ) -> former::ContainerSubformer:: < - ( String, String ), former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap_1End > + ( String, String ), former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap1End > > { self.hashmap_1_set::< former::ContainerSubformer:: < - ( String, String ), former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap_1End > + ( String, String ), former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap1End > > >() } @@ -389,22 +389,22 @@ where String, Self, Self, - Struct1FormerHashset_1End, + Struct1FormerHashset1End, > >, { - Former2::_begin( None, Some( self ), Struct1FormerHashset_1End ) + Former2::_begin( None, Some( self ), Struct1FormerHashset1End ) } pub fn hashset_1( self ) -> former::ContainerSubformer:: < - String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset_1End > + String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End > > { self.hashset_1_set::< former::ContainerSubformer:: < - String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset_1End > + String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End > >>() } @@ -425,13 +425,13 @@ where // zzz : description /// Return original former after subformer for `vec_1` is done. #[ allow( non_camel_case_types ) ] -pub struct Struct1FormerVec_1End; +pub struct Struct1FormerVec1End; #[ automatically_derived ] impl< Definition > former::FormingEnd < former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > -for Struct1FormerVec_1End +for Struct1FormerVec1End where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes @@ -458,13 +458,13 @@ where // zzz : description /// Return original former after subformer for `hashmap_string_1` is done. #[ allow( non_camel_case_types ) ] -pub struct Struct1FormerHashmap_1End; +pub struct Struct1FormerHashmap1End; #[ automatically_derived ] impl< Definition > former::FormingEnd < former::HashMapDefinition< String, String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > -for Struct1FormerHashmap_1End +for Struct1FormerHashmap1End where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes @@ -491,13 +491,13 @@ where // zzz : description /// Return original former after subformer for `hashset_string_1` is done. #[ allow( non_camel_case_types ) ] -pub struct Struct1FormerHashset_1End; +pub struct Struct1FormerHashset1End; #[ automatically_derived ] impl< Definition > former::FormingEnd < former::HashSetDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, > -for Struct1FormerHashset_1End +for Struct1FormerHashset1End where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index c763a9db3c..1968c27eca 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -90,12 +90,13 @@ tests_impls_optional! // - fn end_descriptors() + fn field_forming_end() { - let _got = Struct1FormerVec_1End::new(); - let _got = Struct1FormerHashmap_1End::new(); - let _got = Struct1FormerHashset_1End::new(); + // use super::*; + let _got = Struct1FormerVec1End; + let _got = Struct1FormerHashmap1End; + let _got = Struct1FormerHashset1End; } @@ -162,68 +163,68 @@ tests_impls_optional! // -// fn test_hashmap() -// { -// -// // test.case( "implicit construction" ); -// -// let command = Struct1::former() -// .hashmap_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() -// .form() -// ; -// // dbg!( &command ); -// -// let expected = Struct1 -// { -// vec_1 : vec![], -// hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, -// hashset_1 : hset!{}, -// }; -// a_id!( command, expected ); -// -// // test.case( "replace" ); -// -// let command = Struct1::former() -// .hashmap_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() -// .form() -// ; -// let expected = Struct1 -// { -// vec_1 : vec![], -// hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, -// hashset_1 : hset!{}, -// }; -// a_id!( command, expected ); -// -// let command = Struct1::former() -// .hashmap_1().add( ( "x".to_string(), "v1".to_string() ) ).replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() -// .form() -// ; -// let expected = Struct1 -// { -// vec_1 : vec![], -// hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, -// hashset_1 : hset!{}, -// }; -// a_id!( command, expected ); -// -// // test.case( "replace and add" ); -// -// let command = Struct1::former() -// .hashmap_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ) -// .add( ( "k3".to_string(), "v3".to_string() ) ).end() -// .form() -// ; -// // dbg!( &command ); -// -// let expected = Struct1 -// { -// vec_1 : vec![], -// hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string(), "k3".to_string() => "v3".to_string() }, -// hashset_1 : hset!{}, -// }; -// a_id!( command, expected ); -// } + fn test_hashmap() + { + + // test.case( "implicit construction" ); + + let command = Struct1::former() + .hashmap_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() + .form() + ; + // dbg!( &command ); + + let expected = Struct1 + { + vec_1 : vec![], + hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, + hashset_1 : hset!{}, + }; + a_id!( command, expected ); + + // test.case( "replace" ); + + let command = Struct1::former() + .hashmap_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() + .form() + ; + let expected = Struct1 + { + vec_1 : vec![], + hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, + hashset_1 : hset!{}, + }; + a_id!( command, expected ); + + let command = Struct1::former() + .hashmap_1().add( ( "x".to_string(), "v1".to_string() ) ).replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ).end() + .form() + ; + let expected = Struct1 + { + vec_1 : vec![], + hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, + hashset_1 : hset!{}, + }; + a_id!( command, expected ); + + // test.case( "replace and add" ); + + let command = Struct1::former() + .hashmap_1().replace( hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() } ) + .add( ( "k3".to_string(), "v3".to_string() ) ).end() + .form() + ; + // dbg!( &command ); + + let expected = Struct1 + { + vec_1 : vec![], + hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string(), "k3".to_string() => "v3".to_string() }, + hashset_1 : hset!{}, + }; + a_id!( command, expected ); + } // @@ -291,25 +292,25 @@ tests_impls_optional! // -// fn test_complex() -// { -// -// let command = Struct1::former() -// .vec_1().add( "ghi" ).add( "klm" ).end() -// .hashmap_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() -// .hashset_1().add( "k1" ).end() -// .form(); -// // dbg!( &command ); -// -// let expected = Struct1 -// { -// vec_1 : vec![ "ghi".to_string(), "klm".to_string() ], -// hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, -// hashset_1 : hset!{ "k1".to_string() }, -// }; -// a_id!( command, expected ); -// -// } + fn test_complex() + { + + let command = Struct1::former() + .vec_1().add( "ghi" ).add( "klm" ).end() + .hashmap_1().add( ( "k1".to_string(), "v1".to_string() ) ).add( ( "k2".to_string(), "v2".to_string() ) ).end() + .hashset_1().add( "k1" ).end() + .form(); + // dbg!( &command ); + + let expected = Struct1 + { + vec_1 : vec![ "ghi".to_string(), "klm".to_string() ], + hashmap_1 : hmap!{ "k1".to_string() => "v1".to_string(), "k2".to_string() => "v2".to_string() }, + hashset_1 : hset!{ "k1".to_string() }, + }; + a_id!( command, expected ); + + } } @@ -319,9 +320,9 @@ tests_index! { internals, new, + field_forming_end, test_vector, - // test_hashmap, + test_hashmap, test_hashset, - // test_complex, - // xxx + test_complex, } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index fd7fbd160d..038abf855d 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -535,10 +535,10 @@ fn field_setter_map( field : &FormerField< '_ >, struct_name : &syn::Ident ) -> let non_optional_ty = &field.non_optional_ty; // Either subformer or ordinary setter. - let setter_tokens = if let Some( subformer_ty ) = &field.attrs.subformer + let setter_tokens = if let Some( _subformer_ty ) = &field.attrs.subformer { // subformer_field_setter( ident, ident, non_optional_ty, &subformer_ty.expr ) - subformer_field_setter( field, struct_name, &subformer_ty.expr ) + subformer_field_setter( field, struct_name ) } else { @@ -647,17 +647,11 @@ fn subformer_field_setter // field_ident : &syn::Ident, // setter_name : &syn::Ident, // non_optional_type : &syn::Type, - subformer_type : &syn::Type, + // subformer_type : &syn::Type, ) -> TokenStream { let field_ident = &field.ident; - let doc = format! - ( - "Subformer setter for the '{}' field.", - field_ident - ); - let non_optional_ty = &field.non_optional_ty; // tree_print!( non_optional_type ); @@ -672,13 +666,23 @@ fn subformer_field_setter use convert_case::{ Case, Casing }; // let ident = field_ident; - let field_forming_end_name = format!( "{}Former{}End", struct_name, field_ident.to_string().to_case( Case::Camel ) ); + let field_forming_end_name = format!( "{}Former{}End", struct_name, field_ident.to_string().to_case( Case::Pascal ) ); let field_forming_end = syn::Ident::new( &field_forming_end_name, field_ident.span() ); let field_set_name = format!( "{}_set", field_ident ); let field_set = syn::Ident::new( &field_set_name, field_ident.span() ); + let doc = format! + ( + "Subformer setter for the '{}' field. Method {} unlike method {} accept custom subformer.", + field_ident, + field_set_name, + field_ident, + ); + + let setter1 = qt! { + #[ doc = #doc ] #[ inline( always ) ] pub fn #field_set< Former2 >( self ) -> Former2 where @@ -695,19 +699,55 @@ fn subformer_field_setter { Former2::_begin( None, Some( self ), #field_forming_end ) } + }; - pub fn #field_ident( self ) -> - former::ContainerSubformer:: - < - #( #params, )* #subformer_definition< #( #params, )* Self, Self, #field_forming_end > - > + let setter2 = if params.len() > 1 + { + qt! + { + + #[ doc = #doc ] + #[ inline( always ) ] + pub fn #field_ident( self ) -> + former::ContainerSubformer:: + < + ( #( #params, )* ), #subformer_definition< #( #params, )* Self, Self, #field_forming_end > + > + { + self.#field_set::< former::ContainerSubformer:: + < + ( #( #params, )* ), #subformer_definition< #( #params, )* Self, Self, #field_forming_end > + >>() + } + + } + } + else + { + qt! { - self.#field_set::< former::ContainerSubformer:: + + #[ doc = #doc ] + #[ inline( always ) ] + pub fn #field_ident( self ) -> + former::ContainerSubformer:: < #( #params, )* #subformer_definition< #( #params, )* Self, Self, #field_forming_end > - >>() + > + { + self.#field_set::< former::ContainerSubformer:: + < + #( #params, )* #subformer_definition< #( #params, )* Self, Self, #field_forming_end > + >>() + } + } + }; + qt! + { + #setter1 + #setter2 } // qt! @@ -814,7 +854,7 @@ fn fields_setter_callback_descriptor_map struct_name : &syn::Ident, former : &syn::Ident, former_storage : &syn::Ident, - former_definition : &syn::Ident, + // former_definition : &syn::Ident, ) -> Result< TokenStream > @@ -832,7 +872,7 @@ Result< TokenStream > use convert_case::{ Case, Casing }; let ident = field.ident; - let field_forming_end_name = format!( "{}Former{}End", struct_name, field.ident.to_string().to_case( Case::Camel ) ); + let field_forming_end_name = format!( "{}Former{}End", struct_name, field.ident.to_string().to_case( Case::Pascal ) ); let field_forming_end = syn::Ident::new( &field_forming_end_name, ident.span() ); let field_ty = field.non_optional_ty; @@ -1137,7 +1177,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field_form_map( former_field ), field_name_map( former_field ), field_setter_map( former_field, &struct_name ), - fields_setter_callback_descriptor_map( former_field, &struct_name, &former, &former_storage, &former_definition ), + fields_setter_callback_descriptor_map( former_field, &struct_name, &former, &former_storage /*, &former_definition */ ), )}).multiunzip(); let ( _doc_former_mod, doc_former_struct ) = doc_generate( struct_name ); From 0a17a7f86602133199c2353dc22468b814f7c68a Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 12 Apr 2024 10:46:36 +0300 Subject: [PATCH 123/533] former : experimenting --- .../a_containers_with_subformer.rs | 1 - module/core/former_meta/src/derive/former.rs | 11 +----- module/core/macro_tools/src/typ.rs | 37 +++++++++---------- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index a3c1b9017b..0720ed37de 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -23,4 +23,3 @@ pub struct Struct1 // = generated include!( "./only_test/containers_with_subformer.rs" ); -// xxx : uncomment diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 038abf855d..10e76bc1cd 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -658,8 +658,6 @@ fn subformer_field_setter // code_print!( non_optional_type ); let params = typ::type_parameters( &non_optional_ty, .. ); // params.iter().for_each( | e | println!( "{}", qt!( #e ) ) ); - // let genertic_params = typ::all_type_parameters( non_optional_type ); - // xxx : try `all_type_parameters`` instead let subformer_definition = &field.attrs.subformer.as_ref().unwrap().expr; // for example : former::VectorDefinition @@ -866,9 +864,7 @@ Result< TokenStream > } let subformer_definition = &field.attrs.subformer.as_ref().unwrap().expr; - // let subformer = field.attrs.subformer.as_ref().unwrap(); - // former::VectorDefinition - // xxx + // Expected: "former::VectorDefinition" use convert_case::{ Case, Casing }; let ident = field.ident; @@ -877,14 +873,9 @@ Result< TokenStream > let field_ty = field.non_optional_ty; let params = typ::type_parameters( &field.non_optional_ty, .. ); - // let params = typ::all_type_parameters( field.non_optional_ty ); - // let xxx = field_ty; - // let generics = field_ty.generics - // let ( generics_impl, generics_ty, generics_where ) = generics.split_for_impl(); let r = qt! { - // xxx // zzz : description /// Return original former after subformer for `vec_1` is done. diff --git a/module/core/macro_tools/src/typ.rs b/module/core/macro_tools/src/typ.rs index 9218ecd297..10fe4047b1 100644 --- a/module/core/macro_tools/src/typ.rs +++ b/module/core/macro_tools/src/typ.rs @@ -90,24 +90,23 @@ pub( crate ) mod private vec![ ty ] } - // xxx : cover by tests - /// Extract generics from a type. - pub fn all_type_parameters( type_example : &syn::Type ) - -> - Option< syn::punctuated::Punctuated< syn::GenericArgument, syn::token::Comma > > - { - if let syn::Type::Path( type_path ) = type_example - { - let segments = &type_path.path.segments; - let last_segment = segments.last()?; - - if let syn::PathArguments::AngleBracketed( generics ) = &last_segment.arguments - { - return Some( generics.args.clone() ); - } - } - None - } +// /// Extract generics from a type. +// pub fn all_type_parameters( type_example : &syn::Type ) +// -> +// Option< syn::punctuated::Punctuated< syn::GenericArgument, syn::token::Comma > > +// { +// if let syn::Type::Path( type_path ) = type_example +// { +// let segments = &type_path.path.segments; +// let last_segment = segments.last()?; +// +// if let syn::PathArguments::AngleBracketed( generics ) = &last_segment.arguments +// { +// return Some( generics.args.clone() ); +// } +// } +// None +// } } @@ -127,7 +126,7 @@ pub mod protected { type_rightmost, type_parameters, - all_type_parameters, + // all_type_parameters, }; } From 08c74d869f2d0a1d1b0036dab406dc0da50660bb Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 12 Apr 2024 11:13:08 +0300 Subject: [PATCH 124/533] former : experimenting --- .../tests/inc/former_tests/a_primitives_manual.rs | 4 ++-- module/core/former/tests/inc/mod.rs | 12 ++++++------ module/core/former_meta/src/derive/former.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 72e549ff21..025b55386b 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -184,7 +184,7 @@ pub struct Struct1Former where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -195,7 +195,7 @@ impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, { #[ inline( always ) ] diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 918c16ab7b..08d122dc6e 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -25,12 +25,12 @@ mod former_tests #[ cfg( not( feature = "no_std" ) ) ] mod a_containers_with_subformer ; -// mod attribute_default_container; -// mod attribute_default_primitive; -// mod attribute_perform; -// mod attribute_setter; -// mod attribute_alias; -// + mod attribute_default_container; + mod attribute_default_primitive; + // mod attribute_perform; + // mod attribute_setter; + mod attribute_alias; + // mod string_slice_manual; // mod string_slice; // mod unsigned_primitive_types; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 10e76bc1cd..9f9957cbb1 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1099,7 +1099,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, }; // zzz : write helper to fix bug with where let generics_of_former = generics::merge( &generics, &extra_generics ); From 00b54afa29c71870c537302b1dd9482f9cf9bf17 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 12 Apr 2024 16:48:52 +0300 Subject: [PATCH 125/533] former : experimenting --- module/core/former/src/axiomatic.rs | 8 - .../inc/former_tests/a_primitives_manual.rs | 7 +- .../inc/former_tests/attribute_setter.rs | 10 +- .../former_tests/parametrized_struct_imm.rs | 3 +- .../former_tests/parametrized_struct_where.rs | 3 +- .../tests/inc/former_tests/subformer_basic.rs | 3 +- .../inc/former_tests/subformer_shortcut.rs | 175 +++++++++++------- module/core/former/tests/inc/mod.rs | 8 +- module/core/former_meta/src/derive/former.rs | 2 +- module/core/former_meta/src/lib.rs | 1 + 10 files changed, 133 insertions(+), 87 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index b0f1dc4b0b..34f191ded4 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -218,14 +218,6 @@ for FormingEndClosure< Definition > pub trait FormerBegin< Definition : FormerDefinition > { - /// * `End` - A trait bound marking the closure or handler invoked upon completing the subforming process. Implementers - /// of this trait (`End`) are tasked with applying the final transformations that transition `Storage` - /// into `Formed`, optionally utilizing `Context` to guide this transformation. It is crucial that this - /// associated type satisfies the `FormingEnd< Formed >` trait, defining the precise mechanics of - /// how the subformer concludes its operation. - // type End : FormingEnd< Definition >; - // type End : Definition::End; - /// Launches the subforming process with an initial storage and context, setting up an `on_end` completion handler. /// /// # Parameters diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 025b55386b..29b3a817b6 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -177,14 +177,10 @@ for Struct1FormerStorage // = former -pub struct Struct1Former -< - Definition = Struct1FormerDefinition, -> +pub struct Struct1Former< Definition = Struct1FormerDefinition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, - // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -195,7 +191,6 @@ impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, - // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, { #[ inline( always ) ] diff --git a/module/core/former/tests/inc/former_tests/attribute_setter.rs b/module/core/former/tests/inc/former_tests/attribute_setter.rs index 14e852373e..c3111256cc 100644 --- a/module/core/former/tests/inc/former_tests/attribute_setter.rs +++ b/module/core/former/tests/inc/former_tests/attribute_setter.rs @@ -9,9 +9,15 @@ pub struct StructWithCustomSetters magic : String, } -impl< Context, End > StructWithCustomSettersFormer< Context, End > +// impl< Context, End > StructWithCustomSettersFormer< Context, End > +// where +// End: the_module::FormingEnd< StructWithCustomSetters, Context >, +// { + +impl< Definition > StructWithCustomSettersFormer< Definition > where - End: the_module::FormingEnd< StructWithCustomSetters, Context >, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = StructWithCustomSettersFormerStorage >, { /// Custom alternative setter of ordinary field. diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs index 7318cacb1f..40943ddd1f 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs @@ -26,7 +26,8 @@ impl< Name > Property< Name > pub struct Command< K : core::hash::Hash + std::cmp::Eq > { pub name : String, - #[ subformer( the_module::HashMapSubformer ) ] + // #[ subformer( the_module::HashMapSubformer ) ] + #[ subformer( former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs index 7306f1b229..ba358b14f9 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs @@ -28,7 +28,8 @@ where K : core::hash::Hash + std::cmp::Eq, { pub name : String, - #[ subformer( the_module::HashMapSubformer ) ] + // #[ subformer( the_module::HashMapSubformer ) ] + #[ subformer( former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index bee9c75113..6d45926eba 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -53,7 +53,8 @@ where { pub name : String, pub subject : String, - #[ subformer( the_module::HashMapSubformer ) ] + // #[ subformer( the_module::HashMapSubformer ) ] + #[ subformer( former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index bf36125847..ecaa7c5223 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -4,7 +4,7 @@ use super::*; /// Parameter description. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] -pub struct TemplateParameterDefinition +pub struct TemplateParameterDescriptor { descriptor : String, is_mandatory : bool, @@ -15,8 +15,9 @@ pub struct TemplateParameterDefinition pub struct TemplateParameters { // #[ debug = the_module::VectorSubformer, descriptor, descriptor( name ) ] - #[ subformer( the_module::VectorSubformer ) ] - descriptors : Vec< TemplateParameterDefinition >, + // #[ subformer( the_module::VectorSubformer ) ] + #[ subformer( former::VectorDefinition ) ] + descriptors : Vec< TemplateParameterDescriptor >, // #[ subformer_setter = the_module::VectorSubformer ] // pub fn descriptor( self, name : &str ) @@ -26,19 +27,35 @@ pub struct TemplateParameters } -impl< Context, End > former::FormerBegin< TemplateParameterDefinitionFormerStorage, TemplateParameterDefinition, Context > -for TemplateParameterDefinitionFormer< Context, End > +// impl< Definition > TemplateParametersFormer< Definition > +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = TemplateParameterDescriptorFormerStorage >, +// { + +// impl< Context, End > former::FormerBegin< TemplateParameterDescriptorFormerStorage, TemplateParameterDescriptor, Context > +// for TemplateParameterDescriptorFormer< Context, End > +// where +// End : the_module::FormingEnd< TemplateParameterDescriptor, Context >, +impl< Definition > former::FormerBegin< Definition > +for TemplateParameterDescriptorFormer< Definition > where - End : the_module::FormingEnd< TemplateParameterDefinition, Context >, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = TemplateParameterDescriptorFormerStorage >, + // End : the_module::FormingEnd< TemplateParameterDescriptor, Context >, { - type End = End; + + // type End = End; #[ inline( always ) ] fn _begin ( - storage : core::option::Option< TemplateParameterDefinitionFormerStorage >, - context : core::option::Option< Context >, - on_end : End, + // storage : core::option::Option< TemplateParameterDescriptorFormerStorage >, + // context : core::option::Option< Context >, + // on_end : End, + storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : Definition::End, ) -> Self { debug_assert!( storage.is_none() ); @@ -47,68 +64,100 @@ where } -impl< Context, End > TemplateParametersFormer< Context, End > +// impl< Context, End > TemplateParametersFormer< Context, End > +// where +// End : former::FormingEnd< TemplateParameters, Context >, +impl< Definition > TemplateParametersFormer< Definition > where - End : former::FormingEnd< TemplateParameters, Context >, + // End : former::FormingEnd< TemplateParameters, Context >, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = TemplateParametersFormerStorage >, { + // pub trait FormerDefinitionTypes : Sized + // { + // type Storage : Default; + // type Formed; + // type Context; + // } + #[ inline( always ) ] - pub fn descriptor3< Former2 >( self ) -> + pub fn descriptor3< Former2, Definition2, End >( self ) -> Former2 where - Former2 : former::FormerBegin - < - TemplateParameterDefinitionFormerStorage, - TemplateParameterDefinition, - Self, - End = former::FormingEndClosure< TemplateParameterDefinition, Self >, - >, - // FieldContainer : ContainerAdd, - { - let on_end = | descriptor : TemplateParameterDefinition, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if super_former.storage.descriptors.is_none() - { - super_former.storage.descriptors = Some( Default::default() ); - } - if let Some( ref mut descriptors ) = super_former.storage.descriptors - { - former::ContainerAdd::add( descriptors, descriptor ); - } - super_former - }; - Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) - } + // Definition2 : former::FormerDefinition< End = former::FormingEndClosure< Definition2::Types > >, + Definition2 : former::FormerDefinition, + Definition2::End : former::FormingEnd< Definition2::Types >, + + // Definition2 : former::FormerDefinition< Types = Former2::Types, End = End >, + // Former2 : former::FormerBegin< Definition2 >, + // End : former::FormingEnd< Former2::Types >, + +// xxx : uncomment +// Definition2::Types : former::FormerDefinitionTypes +// < +// Storage = TemplateParameterDescriptorFormerStorage, +// Formed = TemplateParameterDescriptor, +// Context = Self, +// >, +// Former2 : former::FormerBegin +// < +// Definition2, +// // TemplateParameterDescriptorFormerStorage, +// // TemplateParameterDescriptor, +// // Self, +// // End = former::FormingEndClosure< TemplateParameterDescriptor, Self >, +// >, +// // FieldContainer : ContainerAdd, +// { +// +// let on_end = | descriptor : TemplateParameterDescriptor, super_former : core::option::Option< Self > | -> Self +// { +// let mut super_former = super_former.unwrap(); +// if super_former.storage.descriptors.is_none() +// { +// super_former.storage.descriptors = Some( Default::default() ); +// } +// if let Some( ref mut descriptors ) = super_former.storage.descriptors +// { +// former::ContainerAdd::add( descriptors, descriptor ); +// } +// super_former +// }; +// Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) +// } // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help - #[ inline( always ) ] - pub fn descriptor( self, name : &str ) -> - TemplateParameterDefinitionFormer< Self, impl former::FormingEnd< TemplateParameterDefinition, Self > > - { - self.descriptor3::< TemplateParameterDefinitionFormer< _, _ > >().descriptor( name ) - } +// xxx : uncomment + // #[ inline( always ) ] + // pub fn descriptor( self, name : &str ) -> + // // TemplateParameterDescriptorFormer< Self, impl former::FormingEnd< TemplateParameterDescriptor, Self > > + // TemplateParameterDescriptorFormer< Definition > + // { + // self.descriptor3::< TemplateParameterDescriptorFormer< _ > >().descriptor( name ) + // } } -#[ test ] -fn basic() -{ - - let got = TemplateParameters::former() - .descriptors() - .push( TemplateParameterDefinition::former().descriptor( "a" ).form() ) - .push( TemplateParameterDefinition::former().descriptor( "b" ).form() ) - .end() - .form(); - - let descriptors = vec! - [ - TemplateParameterDefinition { descriptor : "a".to_string(), is_mandatory : false }, - TemplateParameterDefinition { descriptor : "b".to_string(), is_mandatory : false }, - ]; - let exp = TemplateParameters { descriptors }; - a_id!( got, exp ); - -} +// xxx : uncomment +// #[ test ] +// fn basic() +// { +// +// let got = TemplateParameters::former() +// .descriptors() +// .push( TemplateParameterDescriptor::former().descriptor( "a" ).form() ) +// .push( TemplateParameterDescriptor::former().descriptor( "b" ).form() ) +// .end() +// .form(); +// +// let descriptors = vec! +// [ +// TemplateParameterDescriptor { descriptor : "a".to_string(), is_mandatory : false }, +// TemplateParameterDescriptor { descriptor : "b".to_string(), is_mandatory : false }, +// ]; +// let exp = TemplateParameters { descriptors }; +// a_id!( got, exp ); +// +// } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 08d122dc6e..84c9262f3e 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -28,7 +28,7 @@ mod former_tests mod attribute_default_container; mod attribute_default_primitive; // mod attribute_perform; - // mod attribute_setter; + mod attribute_setter; mod attribute_alias; // mod string_slice_manual; @@ -56,9 +56,9 @@ mod former_tests // mod subformer_basic_manual; // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic; -// -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_shortcut; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_shortcut; // xxx : uncomment diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 9f9957cbb1..528d0e8d80 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1493,7 +1493,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > diag::debug_report_print( "derive : Former", original_input, &result ); } - // zzz : implement hints + // zzz : implement hints, rewrite if example_of_custom_setter { let _example = diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index e02c582eaf..b585a95113 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -140,6 +140,7 @@ mod derive /// > /// where /// End : former::FormingEnd< UserProfile, Context >, +/// // zzz : update /// { /// storage : UserProfileFormerStorage, /// context : Option< Context >, From bdc614cd3f0dc8665eafa7c46c71c9762be8c217 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 12 Apr 2024 16:49:47 +0300 Subject: [PATCH 126/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index ecaa7c5223..25b59244ec 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -81,19 +81,19 @@ where // type Context; // } - #[ inline( always ) ] - pub fn descriptor3< Former2, Definition2, End >( self ) -> - Former2 - where - // Definition2 : former::FormerDefinition< End = former::FormingEndClosure< Definition2::Types > >, - Definition2 : former::FormerDefinition, - Definition2::End : former::FormingEnd< Definition2::Types >, - - // Definition2 : former::FormerDefinition< Types = Former2::Types, End = End >, - // Former2 : former::FormerBegin< Definition2 >, - // End : former::FormingEnd< Former2::Types >, - // xxx : uncomment +// #[ inline( always ) ] +// pub fn descriptor3< Former2, Definition2, End >( self ) -> +// Former2 +// where +// // Definition2 : former::FormerDefinition< End = former::FormingEndClosure< Definition2::Types > >, +// Definition2 : former::FormerDefinition, +// Definition2::End : former::FormingEnd< Definition2::Types >, +// +// // Definition2 : former::FormerDefinition< Types = Former2::Types, End = End >, +// // Former2 : former::FormerBegin< Definition2 >, +// // End : former::FormingEnd< Former2::Types >, +// // Definition2::Types : former::FormerDefinitionTypes // < // Storage = TemplateParameterDescriptorFormerStorage, From 7511be8e318619bb40ce31bc15859cfbe7248c64 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 08:42:34 +0300 Subject: [PATCH 127/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 97 ++++++++++--------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 25b59244ec..f03c0cd2e8 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -82,50 +82,59 @@ where // } // xxx : uncomment -// #[ inline( always ) ] -// pub fn descriptor3< Former2, Definition2, End >( self ) -> -// Former2 -// where -// // Definition2 : former::FormerDefinition< End = former::FormingEndClosure< Definition2::Types > >, -// Definition2 : former::FormerDefinition, -// Definition2::End : former::FormingEnd< Definition2::Types >, -// -// // Definition2 : former::FormerDefinition< Types = Former2::Types, End = End >, -// // Former2 : former::FormerBegin< Definition2 >, -// // End : former::FormingEnd< Former2::Types >, -// -// Definition2::Types : former::FormerDefinitionTypes -// < -// Storage = TemplateParameterDescriptorFormerStorage, -// Formed = TemplateParameterDescriptor, -// Context = Self, -// >, -// Former2 : former::FormerBegin -// < -// Definition2, -// // TemplateParameterDescriptorFormerStorage, -// // TemplateParameterDescriptor, -// // Self, -// // End = former::FormingEndClosure< TemplateParameterDescriptor, Self >, -// >, -// // FieldContainer : ContainerAdd, -// { -// -// let on_end = | descriptor : TemplateParameterDescriptor, super_former : core::option::Option< Self > | -> Self -// { -// let mut super_former = super_former.unwrap(); -// if super_former.storage.descriptors.is_none() -// { -// super_former.storage.descriptors = Some( Default::default() ); -// } -// if let Some( ref mut descriptors ) = super_former.storage.descriptors -// { -// former::ContainerAdd::add( descriptors, descriptor ); -// } -// super_former -// }; -// Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) -// } + #[ inline( always ) ] + pub fn descriptor3< Former2, Definition2, Types2, End >( self ) -> + Former2 + where + Types2 : former::FormerDefinitionTypes + < + Storage = TemplateParameterDescriptor, + Formed = Self, + Context = Self, + >, + // Definition2 : former::FormerDefinition< End = former::FormingEndClosure< Definition2::Types > >, + Definition2 : former::FormerDefinition< End = former::FormingEndClosure< Types2 >, Types = Types2 >, + // Definition2 : former::FormerDefinition< End = End >, + Definition2 : former::FormerDefinition, + Definition2::End : former::FormingEnd< Definition2::Types >, + + // Definition2 : former::FormerDefinition< Types = Former2::Types, End = End >, + // Former2 : former::FormerBegin< Definition2 >, + // End : former::FormingEnd< Former2::Types >, + + // Definition2::Types : former::FormerDefinitionTypes + // < + // Storage = TemplateParameterDescriptorFormerStorage, + // Formed = TemplateParameterDescriptor, + // Context = Self, + // >, + + Former2 : former::FormerBegin + < + Definition2, + // TemplateParameterDescriptorFormerStorage, + // TemplateParameterDescriptor, + // Self, + // End = former::FormingEndClosure< TemplateParameterDescriptor, Self >, + >, + // FieldContainer : ContainerAdd, + { + + let on_end = | descriptor : TemplateParameterDescriptor, super_former : core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + if super_former.storage.descriptors.is_none() + { + super_former.storage.descriptors = Some( Default::default() ); + } + if let Some( ref mut descriptors ) = super_former.storage.descriptors + { + former::ContainerAdd::add( descriptors, descriptor ); + } + super_former + }; + Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + } // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help From 8e2d58698ab41dfae5dbf2457af271ac85f9e0e3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 08:55:25 +0300 Subject: [PATCH 128/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index f03c0cd2e8..070a25036f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -83,12 +83,12 @@ where // xxx : uncomment #[ inline( always ) ] - pub fn descriptor3< Former2, Definition2, Types2, End >( self ) -> + pub fn descriptor3< Former2, Definition2, Types2 >( self ) -> Former2 where Types2 : former::FormerDefinitionTypes < - Storage = TemplateParameterDescriptor, + Storage = TemplateParameterDescriptorFormerStorage, Formed = Self, Context = Self, >, @@ -120,7 +120,7 @@ where // FieldContainer : ContainerAdd, { - let on_end = | descriptor : TemplateParameterDescriptor, super_former : core::option::Option< Self > | -> Self + let on_end = | descriptor : TemplateParameterDescriptorFormerStorage, super_former : core::option::Option< Self > | -> Self { let mut super_former = super_former.unwrap(); if super_former.storage.descriptors.is_none() @@ -129,7 +129,7 @@ where } if let Some( ref mut descriptors ) = super_former.storage.descriptors { - former::ContainerAdd::add( descriptors, descriptor ); + former::ContainerAdd::add( descriptors, former::StoragePreform::preform( descriptor ) ); } super_former }; @@ -142,9 +142,17 @@ where // #[ inline( always ) ] // pub fn descriptor( self, name : &str ) -> // // TemplateParameterDescriptorFormer< Self, impl former::FormingEnd< TemplateParameterDescriptor, Self > > - // TemplateParameterDescriptorFormer< Definition > + // TemplateParameterDescriptorFormer< TemplateParameterDescriptorFormerDefinition > // { - // self.descriptor3::< TemplateParameterDescriptorFormer< _ > >().descriptor( name ) + // self.descriptor3 + // :: + // < + // TemplateParameterDescriptorFormer< TemplateParameterDescriptorFormerDefinition >, + // TemplateParameterDescriptorFormerDefinition, + // // < TemplateParameterDescriptorFormerDefinition as former::FormerDefinition >::Types, + // _, + // // _, + // >().descriptor( name ) // } } From 0ffc8219a17144983ea1c69e212e284b5898a0d6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 08:57:46 +0300 Subject: [PATCH 129/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 30 +------------------ 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 070a25036f..968153b682 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -69,19 +69,10 @@ where // End : former::FormingEnd< TemplateParameters, Context >, impl< Definition > TemplateParametersFormer< Definition > where - // End : former::FormingEnd< TemplateParameters, Context >, Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = TemplateParametersFormerStorage >, { - // pub trait FormerDefinitionTypes : Sized - // { - // type Storage : Default; - // type Formed; - // type Context; - // } - -// xxx : uncomment #[ inline( always ) ] pub fn descriptor3< Former2, Definition2, Types2 >( self ) -> Former2 @@ -92,32 +83,13 @@ where Formed = Self, Context = Self, >, - // Definition2 : former::FormerDefinition< End = former::FormingEndClosure< Definition2::Types > >, Definition2 : former::FormerDefinition< End = former::FormingEndClosure< Types2 >, Types = Types2 >, - // Definition2 : former::FormerDefinition< End = End >, Definition2 : former::FormerDefinition, Definition2::End : former::FormingEnd< Definition2::Types >, - - // Definition2 : former::FormerDefinition< Types = Former2::Types, End = End >, - // Former2 : former::FormerBegin< Definition2 >, - // End : former::FormingEnd< Former2::Types >, - - // Definition2::Types : former::FormerDefinitionTypes - // < - // Storage = TemplateParameterDescriptorFormerStorage, - // Formed = TemplateParameterDescriptor, - // Context = Self, - // >, - Former2 : former::FormerBegin < Definition2, - // TemplateParameterDescriptorFormerStorage, - // TemplateParameterDescriptor, - // Self, - // End = former::FormingEndClosure< TemplateParameterDescriptor, Self >, >, - // FieldContainer : ContainerAdd, { let on_end = | descriptor : TemplateParameterDescriptorFormerStorage, super_former : core::option::Option< Self > | -> Self @@ -138,7 +110,7 @@ where // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help -// xxx : uncomment + // xxx : uncomment // #[ inline( always ) ] // pub fn descriptor( self, name : &str ) -> // // TemplateParameterDescriptorFormer< Self, impl former::FormingEnd< TemplateParameterDescriptor, Self > > From b19d1399b13c8d8d62769e82ab686a9b6d2abdfb Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 09:31:25 +0300 Subject: [PATCH 130/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 968153b682..abf53f7445 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -64,6 +64,9 @@ where } +// pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +// pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > + // impl< Context, End > TemplateParametersFormer< Context, End > // where // End : former::FormingEnd< TemplateParameters, Context >, @@ -110,8 +113,29 @@ where // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help + // pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > // xxx : uncomment - // #[ inline( always ) ] + #[ inline( always ) ] + pub fn descriptor( self, name: &str ) -> + TemplateParameterDescriptorFormer + < + TemplateParameterDescriptorFormerDefinition + < + Self, + Self, + former::FormingEndClosure< TemplateParameterDescriptorFormerDefinitionTypes< Self, Self > > + > + > + { + self.descriptor3:: + < + TemplateParameterDescriptorFormer< _ >, + _, + _, // Define or adjust this type to meet the constraints + >() + .descriptor( name ) + } + // pub fn descriptor( self, name : &str ) -> // // TemplateParameterDescriptorFormer< Self, impl former::FormingEnd< TemplateParameterDescriptor, Self > > // TemplateParameterDescriptorFormer< TemplateParameterDescriptorFormerDefinition > From 39bb1f73cdc37dfd4b2f2e60332c897496ec249f Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 09:35:58 +0300 Subject: [PATCH 131/533] former : experimenting --- .../inc/former_tests/a_primitives_manual.rs | 4 +-- .../inc/former_tests/subformer_shortcut.rs | 25 +++---------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 29b3a817b6..e2f5fe7114 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -23,10 +23,9 @@ impl Struct1 // = definition +// xxx : should context and formed be here? #[ derive( Debug ) ] pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > -// where -// End : former::FormingEnd< Struct1FormerDefinition< Context, Formed, NoEnd > >, { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } @@ -268,7 +267,6 @@ where let on_end = self.on_end.take().unwrap(); let context = self.context.take(); former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) - // former::FormingEnd::< Struct1FormerDefinition >::call( &on_end, self.storage, context ) } #[ inline( always ) ] diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index abf53f7445..15c867b0fa 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -64,9 +64,6 @@ where } -// pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > -// pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > - // impl< Context, End > TemplateParametersFormer< Context, End > // where // End : former::FormingEnd< TemplateParameters, Context >, @@ -113,8 +110,9 @@ where // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help - // pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > - // xxx : uncomment +// pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +// pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > + #[ inline( always ) ] pub fn descriptor( self, name: &str ) -> TemplateParameterDescriptorFormer @@ -131,26 +129,11 @@ where < TemplateParameterDescriptorFormer< _ >, _, - _, // Define or adjust this type to meet the constraints + _, >() .descriptor( name ) } - // pub fn descriptor( self, name : &str ) -> - // // TemplateParameterDescriptorFormer< Self, impl former::FormingEnd< TemplateParameterDescriptor, Self > > - // TemplateParameterDescriptorFormer< TemplateParameterDescriptorFormerDefinition > - // { - // self.descriptor3 - // :: - // < - // TemplateParameterDescriptorFormer< TemplateParameterDescriptorFormerDefinition >, - // TemplateParameterDescriptorFormerDefinition, - // // < TemplateParameterDescriptorFormerDefinition as former::FormerDefinition >::Types, - // _, - // // _, - // >().descriptor( name ) - // } - } // xxx : uncomment From a6fdc74aa9f697b59f9af57ae6d60be361fbfb21 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 13:02:24 +0300 Subject: [PATCH 132/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 77 ++++++------------- 1 file changed, 23 insertions(+), 54 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 15c867b0fa..50f92f771e 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -6,7 +6,7 @@ use super::*; #[ derive( Debug, Default, PartialEq, the_module::Former ) ] pub struct TemplateParameterDescriptor { - descriptor : String, + name : String, is_mandatory : bool, } @@ -14,45 +14,20 @@ pub struct TemplateParameterDescriptor #[ derive( Debug, Default, PartialEq, the_module::Former ) ] pub struct TemplateParameters { - // #[ debug = the_module::VectorSubformer, descriptor, descriptor( name ) ] - // #[ subformer( the_module::VectorSubformer ) ] #[ subformer( former::VectorDefinition ) ] descriptors : Vec< TemplateParameterDescriptor >, - - // #[ subformer_setter = the_module::VectorSubformer ] - // pub fn descriptor( self, name : &str ) - // { - // descriptor( name ) - // } - } -// impl< Definition > TemplateParametersFormer< Definition > -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = TemplateParameterDescriptorFormerStorage >, -// { - -// impl< Context, End > former::FormerBegin< TemplateParameterDescriptorFormerStorage, TemplateParameterDescriptor, Context > -// for TemplateParameterDescriptorFormer< Context, End > -// where -// End : the_module::FormingEnd< TemplateParameterDescriptor, Context >, impl< Definition > former::FormerBegin< Definition > for TemplateParameterDescriptorFormer< Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = TemplateParameterDescriptorFormerStorage >, - // End : the_module::FormingEnd< TemplateParameterDescriptor, Context >, { - // type End = End; - #[ inline( always ) ] fn _begin ( - // storage : core::option::Option< TemplateParameterDescriptorFormerStorage >, - // context : core::option::Option< Context >, - // on_end : End, storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : Definition::End, @@ -64,9 +39,6 @@ where } -// impl< Context, End > TemplateParametersFormer< Context, End > -// where -// End : former::FormingEnd< TemplateParameters, Context >, impl< Definition > TemplateParametersFormer< Definition > where Definition : former::FormerDefinition, @@ -110,11 +82,8 @@ where // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help -// pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > -// pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > - #[ inline( always ) ] - pub fn descriptor( self, name: &str ) -> + pub fn descriptor( self, name : &str ) -> TemplateParameterDescriptorFormer < TemplateParameterDescriptorFormerDefinition @@ -131,29 +100,29 @@ where _, _, >() - .descriptor( name ) + .name( name ) } } // xxx : uncomment -// #[ test ] -// fn basic() -// { -// -// let got = TemplateParameters::former() -// .descriptors() -// .push( TemplateParameterDescriptor::former().descriptor( "a" ).form() ) -// .push( TemplateParameterDescriptor::former().descriptor( "b" ).form() ) -// .end() -// .form(); -// -// let descriptors = vec! -// [ -// TemplateParameterDescriptor { descriptor : "a".to_string(), is_mandatory : false }, -// TemplateParameterDescriptor { descriptor : "b".to_string(), is_mandatory : false }, -// ]; -// let exp = TemplateParameters { descriptors }; -// a_id!( got, exp ); -// -// } +#[ test ] +fn basic() +{ + + let got = TemplateParameters::former() + .descriptors() + .add( TemplateParameterDescriptor::former().name( "a" ).form() ) + .add( TemplateParameterDescriptor::former().name( "b" ).form() ) + .end() + .form(); + + let descriptors = vec! + [ + TemplateParameterDescriptor { name : "a".to_string(), is_mandatory : false }, + TemplateParameterDescriptor { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = TemplateParameters { descriptors }; + a_id!( got, exp ); + +} From af10b9090ddf7895378b7d152edfcc58f80680b6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 13:42:59 +0300 Subject: [PATCH 133/533] former : experimenting --- .../core/former/tests/inc/former_tests/a_primitives_manual.rs | 1 - module/core/former/tests/inc/mod.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index e2f5fe7114..3038918978 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -23,7 +23,6 @@ impl Struct1 // = definition -// xxx : should context and formed be here? #[ derive( Debug ) ] pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 84c9262f3e..9f7c70070e 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -31,7 +31,7 @@ mod former_tests mod attribute_setter; mod attribute_alias; -// mod string_slice_manual; + mod string_slice_manual; // mod string_slice; // mod unsigned_primitive_types; // mod default_user_type; From b522b3c62043b9cc0ae5af8b2cee43f9c1354191 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 13:56:07 +0300 Subject: [PATCH 134/533] former : experimenting --- .../former/tests/inc/former_tests/a_basic.rs | 16 + .../tests/inc/former_tests/a_basic_manual.rs | 14 + .../tests/inc/former_tests/a_primitives.rs | 8 +- .../inc/former_tests/a_primitives_expanded.rs | 18 - .../tests/inc/former_tests/only_test/basic.rs | 435 ++++++++++++++++++ .../inc/former_tests/only_test/primitives.rs | 305 +----------- module/core/former/tests/inc/mod.rs | 17 +- 7 files changed, 481 insertions(+), 332 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/a_basic.rs create mode 100644 module/core/former/tests/inc/former_tests/a_basic_manual.rs delete mode 100644 module/core/former/tests/inc/former_tests/a_primitives_expanded.rs create mode 100644 module/core/former/tests/inc/former_tests/only_test/basic.rs diff --git a/module/core/former/tests/inc/former_tests/a_basic.rs b/module/core/former/tests/inc/former_tests/a_basic.rs new file mode 100644 index 0000000000..50d1bc7e0d --- /dev/null +++ b/module/core/former/tests/inc/former_tests/a_basic.rs @@ -0,0 +1,16 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ derive( Debug, PartialEq, former::Former ) ] +// #[ derive( Debug, PartialEq, former::Former ) ] #[ debug ] +// #[ derive( Debug, PartialEq ) ] #[ debug ] +pub struct Struct1 +{ + pub int_1 : i32, +} + +// = begin of generated + +// = end of generated + +include!( "./only_test/basic.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs new file mode 100644 index 0000000000..af40c456a4 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -0,0 +1,14 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ derive( Debug, PartialEq ) ] +pub struct Struct1 +{ + pub int_1 : i32, +} + +// = formed + +// + +include!( "./only_test/basic.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives.rs b/module/core/former/tests/inc/former_tests/a_primitives.rs index c39429b63a..dc4963c069 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives.rs @@ -1,7 +1,9 @@ #[ allow( unused_imports ) ] use super::*; -#[ derive( Debug, PartialEq, the_module::Former ) ] +#[ derive( Debug, PartialEq, former::Former ) ] +// #[ derive( Debug, PartialEq, former::Former ) ] #[ debug ] +// #[ derive( Debug, PartialEq ) ] #[ debug ] pub struct Struct1 { pub int_1 : i32, @@ -10,6 +12,8 @@ pub struct Struct1 string_optional_1 : Option< String >, } -// +// = begin of generated + +// = end of generated include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs b/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs deleted file mode 100644 index 1fb79bc568..0000000000 --- a/module/core/former/tests/inc/former_tests/a_primitives_expanded.rs +++ /dev/null @@ -1,18 +0,0 @@ -#[ allow( unused_imports ) ] -use super::*; - -// #[ derive( Debug, PartialEq ) ] -#[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] -pub struct Struct1 -{ - pub int_1 : i32, - string_1 : String, - int_optional_1 : core::option::Option< i32 >, - string_optional_1 : Option< String >, -} - -// = generated - -// = end of generated - -include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs new file mode 100644 index 0000000000..0808110ac3 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -0,0 +1,435 @@ +#[ allow( unused_imports ) ] +use super::*; + +// + +tests_impls! +{ + + // + + fn internals() + { + + let former = Struct1::former(); + a_id!( former.storage.int_1, None ); + a_id!( former.context, None ); + a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); + let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); + a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); + + let command = Struct1::former().form(); + a_id!( command.int_1, 0 ); + + let command = Struct1::former().perform(); + a_id!( command.int_1, 0 ); + + let command = Struct1::former().end(); + a_id!( command.int_1, 0 ); + + } + + // + + fn custom_definition_params() + { + // zzz : make example of that + + // custom params + let got = Struct1Former + ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > + ::begin + ( + None, + Some( 3 ), + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }, + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); + + // custom params with into + let got = Struct1Former + ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > + ::begin + ( + None, + Some( 3 ), + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }, + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); + + // custom params begin + let got = Struct1Former + ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > + ::begin + ( + None, + Some( 3 ), + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); + + // custom params begin with Struct1FormerWithClosure + let got = Struct1Former + ::< Struct1FormerWithClosure< i32, i32 > > + ::begin + ( + None, + Some( 3 ), + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); + + } + + // + + fn begin() + { + + // begin with none + let got = Struct1Former::< Struct1FormerDefinition >::begin( None, None, the_module::ReturnPreformed ).int_1( 13 ).form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // begin with storage + let mut storage = Struct1FormerStorage::default(); + storage.int_1 = Some( 13 ); + let exp = Struct1Former::< Struct1FormerDefinition >::begin( Some( storage ), None, the_module::ReturnPreformed ).form(); + a_id!( got, exp ); + + // begin with context + let mut storage = Struct1FormerStorage::default(); + storage.int_1 = Some( 13 ); + let exp = Struct1Former::< Struct1FormerDefinition > + ::begin( Some( storage ), Some( () ), the_module::ReturnPreformed ) + .form(); + a_id!( got, exp ); + + } + + // + + fn _begin_precise() + { + + // custom params + let got = Struct1Former + ::< Struct1FormerDefinition< i32, i32, _ > > + ::_begin_precise + ( + None, + Some( 3 ), + former::FormingEndClosure::new + ( + | storage : Struct1FormerStorage, context | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } + ), + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); + + // custom params with into + let got = Struct1Former + ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > + ::_begin_precise + ( + None, + Some( 3 ), + ( + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } + ).into(), + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); + + } + + // + + fn new() + { + + // basic case + let former = Struct1::former(); + let former2 = Struct1Former::< Struct1FormerDefinition >::_new_precise( former::ReturnPreformed ); + a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); + let exp = former.form(); + let got = former2.form(); + a_id!( got, exp ); + + // default explicit params + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > + ::new( former::ReturnPreformed ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper + fn f1( storage : Struct1FormerStorage, _context : Option< () > ) -> Struct1 + { + former::StoragePreform::preform( storage ) + } + let end_wrapper : former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndClosure::new( f1 ); + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > + ::new( end_wrapper ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > + ::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure, auto types + let got = Struct1Former + ::< Struct1FormerDefinition< _, _, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > + ::new( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure + let got = Struct1Former + ::< Struct1FormerWithClosure< (), Struct1 > > + ::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure + let got = Struct1Former + ::< Struct1FormerWithClosure< (), Struct1 > > + ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + } + + // + + fn _new_precise() + { + + // basic case + let former = Struct1::former(); + let former2 = Struct1Former::< Struct1FormerDefinition >::_new_precise( former::ReturnPreformed ); + a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); + let exp = former.form(); + let got = former2.form(); + a_id!( got, exp ); + + // default explicit params + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::_new_precise( former::ReturnPreformed ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper + fn f1( storage : Struct1FormerStorage, _context : Option< () > ) -> Struct1 + { + former::StoragePreform::preform( storage ) + } + let end_wrapper : former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndClosure::new( f1 ); + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::_new_precise( end_wrapper ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::_new_precise( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure, auto types + let got = Struct1Former + ::< Struct1FormerDefinition< _, _, _ > > + ::_new_precise( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + } + + // + + fn preform() + { + + // formation should have method preform + let got = Struct1::former().preform(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + // storage should have method preform + let got = the_module::StoragePreform::preform( Struct1::former().storage ); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + // storage should have method preform + use the_module::StoragePreform; + let got = Struct1::former().storage.preform(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + } + + // + + fn definition() + { + + // default is implemented for definition + let _default = Struct1FormerDefinition::< () >::default(); + // let _default = Struct1FormerDefinition::default(); // why does not work? + + // definition types exists and has Formed + let got = < Struct1FormerDefinitionTypes< (), Struct1 > as the_module::FormerDefinitionTypes >::Formed::former().form(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + // definition types exists and has Formed + let got = < Struct1FormerDefinitionTypes as the_module::FormerDefinitionTypes >::Formed::former().form(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + // definition types exists and has Storage + use former::StoragePreform; + let got = < Struct1FormerDefinitionTypes as the_module::FormerDefinitionTypes >::Storage::preform( Struct1::former().storage ); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + // definition exists and has Storage + let got = < < Struct1FormerDefinition as the_module::FormerDefinition >::Types as the_module::FormerDefinitionTypes >::Formed::former().form(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + } + + // + + fn storage() + { + + // definition exists and has Storage + let got = < Struct1FormerStorage as the_module::StoragePreform >::preform( Struct1::former().storage ); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + // default is implemented for Storage + let got = Struct1FormerStorage::default().preform(); + let exp = Struct1::former().storage.preform(); + a_id!( got, exp ); + + // definition exists and has Storage + use former::StoragePreform; + let got = Struct1::former().storage.preform(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + // storage exists + let got = < Struct1FormerStorage as the_module::Storage >::Formed::former().form(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + } + + // + + fn test_int() + { + + // test.case( "basic" ); + + let command = Struct1::former() + .int_1( 13 ) + .form(); + // dbg!( &command ); + + let expected = Struct1 + { + int_1 : 13, + }; + a_id!( command, expected ); + + // test.case( "rewriting" ); + + // should_throw( || + // { + // let _command = Struct1::former() + // .int_1( 1 ) + // .int_1( 3 ) + // .form(); + // Ok( () ) + // })?; + } + + // + + fn test_underscored_form() + { + // test.case( "basic" ); + let command = Struct1::former() + .int_1( 13 ) + .form(); + + let expected = Struct1 + { + int_1 : 13, + }; + a_id!( command, expected ); + } + + // + + +} + +// + +tests_index! +{ + internals, + custom_definition_params, + begin, + _begin_precise, + new, + _new_precise, + preform, + definition, + storage, + test_int, + test_underscored_form, +} diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 4d0aede6cf..3e536af161 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -43,191 +43,9 @@ tests_impls! // - fn custom_definition_params() - { - // zzz : make example of that - - // custom params - let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::begin - ( - None, - Some( 3 ), - | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }, - ) - .int_1( 13 ) - .form(); - a_id!( got, 32 ); - - // custom params with into - let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::begin - ( - None, - Some( 3 ), - | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) }, - ) - .int_1( 13 ) - .form(); - a_id!( got, 32 ); - - // custom params begin - let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::begin - ( - None, - Some( 3 ), - | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } - ) - .int_1( 13 ) - .form(); - a_id!( got, 32 ); - - // custom params begin with Struct1FormerWithClosure - let got = Struct1Former - ::< Struct1FormerWithClosure< i32, i32 > > - ::begin - ( - None, - Some( 3 ), - | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } - ) - .int_1( 13 ) - .form(); - a_id!( got, 32 ); - - } - - // - - fn begin() - { - - // begin with none - let got = Struct1Former::< Struct1FormerDefinition >::begin( None, None, the_module::ReturnPreformed ).int_1( 13 ).form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // begin with storage - let mut storage = Struct1FormerStorage::default(); - storage.int_1 = Some( 13 ); - let exp = Struct1Former::< Struct1FormerDefinition >::begin( Some( storage ), None, the_module::ReturnPreformed ).form(); - a_id!( got, exp ); - - // begin with context - let mut storage = Struct1FormerStorage::default(); - storage.int_1 = Some( 13 ); - let exp = Struct1Former::< Struct1FormerDefinition > - ::begin( Some( storage ), Some( () ), the_module::ReturnPreformed ) - .form(); - a_id!( got, exp ); - - } - - // - - fn _begin_precise() - { - - // custom params - let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, _ > > - ::_begin_precise - ( - None, - Some( 3 ), - former::FormingEndClosure::new - ( - | storage : Struct1FormerStorage, context | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } - ), - ) - .int_1( 13 ) - .form(); - a_id!( got, 32 ); - - // custom params with into - let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::_begin_precise - ( - None, - Some( 3 ), - ( - | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } - ).into(), - ) - .int_1( 13 ) - .form(); - a_id!( got, 32 ); - - } - - // - fn new() { - // basic case - let former = Struct1::former(); - let former2 = Struct1Former::< Struct1FormerDefinition >::_new_precise( former::ReturnPreformed ); - a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); - let exp = former.form(); - let got = former2.form(); - a_id!( got, exp ); - - // default explicit params - let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > - ::new( former::ReturnPreformed ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // default explicit params with wrapper - fn f1( storage : Struct1FormerStorage, _context : Option< () > ) -> Struct1 - { - former::StoragePreform::preform( storage ) - } - let end_wrapper : former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndClosure::new( f1 ); - let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > - ::new( end_wrapper ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // default explicit params with wrapper and closure - let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > - ::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // default explicit params with wrapper and closure, auto types - let got = Struct1Former - ::< Struct1FormerDefinition< _, _, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > - ::new( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // default explicit params with wrapper and closure - let got = Struct1Former - ::< Struct1FormerWithClosure< (), Struct1 > > - ::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - // default explicit params with wrapper and closure let got = Struct1Former ::< Struct1FormerWithClosure< (), Struct1 > > @@ -241,62 +59,6 @@ tests_impls! // - fn _new_precise() - { - - // basic case - let former = Struct1::former(); - let former2 = Struct1Former::< Struct1FormerDefinition >::_new_precise( former::ReturnPreformed ); - a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); - let exp = former.form(); - let got = former2.form(); - a_id!( got, exp ); - - // default explicit params - let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, _ > > - ::_new_precise( former::ReturnPreformed ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // default explicit params with wrapper - fn f1( storage : Struct1FormerStorage, _context : Option< () > ) -> Struct1 - { - former::StoragePreform::preform( storage ) - } - let end_wrapper : former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndClosure::new( f1 ); - let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, _ > > - ::_new_precise( end_wrapper ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // default explicit params with wrapper and closure - let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, _ > > - ::_new_precise( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // default explicit params with wrapper and closure, auto types - let got = Struct1Former - ::< Struct1FormerDefinition< _, _, _ > > - ::_new_precise( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - } - - // - fn preform() { @@ -320,66 +82,6 @@ tests_impls! // - fn definition() - { - - // default is implemented for definition - let _default = Struct1FormerDefinition::< () >::default(); - // let _default = Struct1FormerDefinition::default(); // why does not work? - - // definition types exists and has Formed - let got = < Struct1FormerDefinitionTypes< (), Struct1 > as the_module::FormerDefinitionTypes >::Formed::former().form(); - let exp = Struct1::former().form(); - a_id!( got, exp ); - - // definition types exists and has Formed - let got = < Struct1FormerDefinitionTypes as the_module::FormerDefinitionTypes >::Formed::former().form(); - let exp = Struct1::former().form(); - a_id!( got, exp ); - - // definition types exists and has Storage - use former::StoragePreform; - let got = < Struct1FormerDefinitionTypes as the_module::FormerDefinitionTypes >::Storage::preform( Struct1::former().storage ); - let exp = Struct1::former().form(); - a_id!( got, exp ); - - // definition exists and has Storage - let got = < < Struct1FormerDefinition as the_module::FormerDefinition >::Types as the_module::FormerDefinitionTypes >::Formed::former().form(); - let exp = Struct1::former().form(); - a_id!( got, exp ); - - } - - // - - fn storage() - { - - // definition exists and has Storage - let got = < Struct1FormerStorage as the_module::StoragePreform >::preform( Struct1::former().storage ); - let exp = Struct1::former().form(); - a_id!( got, exp ); - - // default is implemented for Storage - let got = Struct1FormerStorage::default().preform(); - let exp = Struct1::former().storage.preform(); - a_id!( got, exp ); - - // definition exists and has Storage - use former::StoragePreform; - let got = Struct1::former().storage.preform(); - let exp = Struct1::former().form(); - a_id!( got, exp ); - - // storage exists - let got = < Struct1FormerStorage as the_module::Storage >::Formed::former().form(); - let exp = Struct1::former().form(); - a_id!( got, exp ); - - } - - // - fn test_int() { @@ -562,14 +264,9 @@ tests_impls! tests_index! { internals, - begin, - _begin_precise, new, - _new_precise, - custom_definition_params, preform, - definition, - storage, + test_int, test_string, test_optional_string, diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 9f7c70070e..9180e0351a 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -16,8 +16,9 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod container_former_hashmap; + // mod a_basic_manual; + mod a_basic; mod a_primitives_manual; - // mod a_primitives_expanded; mod a_primitives; mod a_containers_without_subformer; #[ cfg( not( feature = "no_std" ) ) ] @@ -27,17 +28,17 @@ mod former_tests mod attribute_default_container; mod attribute_default_primitive; - // mod attribute_perform; + // mod attribute_perform; // xxx mod attribute_setter; mod attribute_alias; mod string_slice_manual; -// mod string_slice; -// mod unsigned_primitive_types; -// mod default_user_type; -// mod user_type_no_default; -// mod user_type_no_debug; -// + // mod string_slice; + mod unsigned_primitive_types; + mod default_user_type; + mod user_type_no_default; + mod user_type_no_debug; + // mod name_collision_former_hashmap_without_parameter; // mod name_collision_former_vector_without_parameter; // mod name_collisions; From e448f48ae28b9a04b0f0d2c0977b6c8384f267f6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 14:02:49 +0300 Subject: [PATCH 135/533] former : experimenting --- .../former/tests/inc/former_tests/a_basic.rs | 2 +- .../tests/inc/former_tests/a_basic_manual.rs | 209 +++++++++++++++++- module/core/former/tests/inc/mod.rs | 2 +- module/core/former_meta/src/lib.rs | 2 +- 4 files changed, 210 insertions(+), 5 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic.rs b/module/core/former/tests/inc/former_tests/a_basic.rs index 50d1bc7e0d..31ec06d07d 100644 --- a/module/core/former/tests/inc/former_tests/a_basic.rs +++ b/module/core/former/tests/inc/former_tests/a_basic.rs @@ -3,7 +3,7 @@ use super::*; #[ derive( Debug, PartialEq, former::Former ) ] // #[ derive( Debug, PartialEq, former::Former ) ] #[ debug ] -// #[ derive( Debug, PartialEq ) ] #[ debug ] +// #[ derive( Debug, PartialEq ) ] pub struct Struct1 { pub int_1 : i32, diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index af40c456a4..ac5ca1f03f 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -7,8 +7,213 @@ pub struct Struct1 pub int_1 : i32, } -// = formed +// = begin of generated -// +#[ automatically_derived ] +impl Struct1 +{ + #[ inline( always ) ] + pub fn former() -> Struct1Former< > + { + Struct1Former::< >::new( former::ReturnPreformed ) + } +} + +#[ derive( Debug ) ] +pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > +{ + _phantom : core::marker::PhantomData< ( Context, Formed ) >, +} + +impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > +{ + fn default() -> Self + { + Self { _phantom : core::marker::PhantomData, } + } +} + +#[ derive( Debug ) ] +pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +{ + _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, +} + +impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > +{ + fn default() -> Self + { + Self { _phantom : core::marker::PhantomData, } + } +} + +impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > +{ + type Storage = Struct1FormerStorage; + type Formed = Formed; + type Context = Context; +} + +impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > +where End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > > +{ + type Types = Struct1FormerDefinitionTypes< Context, Formed >; + type End = End; +} + +pub type Struct1FormerWithClosure< Context, Formed > = + Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; +pub struct Struct1FormerStorage +{ + pub int_1 : ::core::option::Option< i32 >, +} + +impl ::core::default::Default for Struct1FormerStorage +{ + #[ inline( always ) ] + fn default() -> Self + { + Self { int_1 : ::core::option::Option::None, } + } +} + +impl former::Storage for Struct1FormerStorage +{ + type Formed = Struct1; +} + +impl former::StoragePreform for Struct1FormerStorage +{ + fn preform( mut self ) -> < Self as former::Storage >::Formed + { + let int_1 = if self.int_1.is_some() + { + self.int_1.take().unwrap() + } + else + { + { + trait MaybeDefault< T > + { + fn maybe_default( self : & Self ) -> T + { + panic!( "Field 'int_1' isn't initialized" ) + } + } + + impl< T > MaybeDefault< T > for & ::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : & Self ) -> T { T::default() } + } + + (& ::core::marker::PhantomData::< i32 >).maybe_default() + } + }; + let result = Struct1 { int_1, }; + return result; + } +} +pub struct Struct1Former< Definition = Struct1FormerDefinition > +where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +{ + storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : core::option::Option< Definition::End >, +} + +#[ automatically_derived ] +impl< Definition > Struct1Former< Definition > +where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +{ + #[ inline( always ) ] + pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + let result = self.form(); + return result; + } + #[ inline( always ) ] + pub fn _new_precise( on_end : Definition::End ) -> Self + { + Self::begin( None, None, on_end ) + } + #[ inline( always ) ] + pub fn new< IntoEnd >( end : IntoEnd ) -> Self + where IntoEnd : Into< Definition::End >, + { + Self::begin( None, None, end, ) + } + #[ inline( always ) ] + pub fn _begin_precise + ( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : < Definition as former::FormerDefinition >::End, + ) -> Self + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some( on_end ), + } + } + #[ inline( always ) ] + pub fn begin< IntoEnd > + ( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : IntoEnd, + ) -> Self + where IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), + } + } + #[ inline( always ) ] + pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + self.end() + } + #[ inline( always ) ] + pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + former::FormingEnd::< Definition::Types >::call( & on_end, self.storage, context ) + } + #[ inline ] + pub fn int_1< Src >( mut self, src : Src ) -> Self + where Src : ::core::convert::Into< i32 >, + { + debug_assert!( self.storage.int_1.is_none() ); + self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + self + } +} + +impl< Definition > Struct1Former< Definition > +where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +{ + pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + former::StoragePreform::preform( self.storage ) + } +} + +// = end of generated include!( "./only_test/basic.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 9180e0351a..8e35ae8e1c 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -16,7 +16,7 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod container_former_hashmap; - // mod a_basic_manual; + mod a_basic_manual; mod a_basic; mod a_primitives_manual; mod a_primitives; diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index b585a95113..3f0dab9097 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -188,7 +188,7 @@ mod derive /// return result.greet_user(); /// } /// -/// // qqq : xxx : outdated, update +/// // qqq : zzz : outdated, update /// #[ inline( always ) ] /// pub fn new() -> UserProfileFormer< UserProfile, former::ReturnFormed > /// { From 78c70ad338812e9be1903148b4070817085e11e5 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 14:06:22 +0300 Subject: [PATCH 136/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index ac5ca1f03f..a9b2e3c7ea 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -12,6 +12,7 @@ pub struct Struct1 #[ automatically_derived ] impl Struct1 { + #[ inline( always ) ] pub fn former() -> Struct1Former< > { @@ -70,6 +71,7 @@ pub struct Struct1FormerStorage impl ::core::default::Default for Struct1FormerStorage { + #[ inline( always ) ] fn default() -> Self { @@ -115,6 +117,7 @@ impl former::StoragePreform for Struct1FormerStorage return result; } } + pub struct Struct1Former< Definition = Struct1FormerDefinition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { @@ -127,30 +130,35 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { + #[ inline( always ) ] pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { let result = self.form(); return result; } + #[ inline( always ) ] pub fn _new_precise( on_end : Definition::End ) -> Self { Self::begin( None, None, on_end ) } + #[ inline( always ) ] pub fn new< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End >, { Self::begin( None, None, end, ) } + #[ inline( always ) ] pub fn _begin_precise ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, - ) -> Self + ) + -> Self { if storage.is_none() { @@ -163,6 +171,7 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD on_end : ::core::option::Option::Some( on_end ), } } + #[ inline( always ) ] pub fn begin< IntoEnd > ( @@ -170,7 +179,8 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : IntoEnd, ) -> Self - where IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, + where + IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, { if storage.is_none() { @@ -183,11 +193,13 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), } } + #[ inline( always ) ] pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { self.end() } + #[ inline( always ) ] pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { @@ -206,7 +218,10 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD } impl< Definition > Struct1Former< Definition > -where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { From 6bc54ca57525e4fd6bc16d7a4c6ad21e4c24b881 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 14:11:54 +0300 Subject: [PATCH 137/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 33 ++++++++++++++----- module/core/former_meta/src/derive/former.rs | 28 ++++++++-------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index a9b2e3c7ea..d71be09000 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -7,7 +7,9 @@ pub struct Struct1 pub int_1 : i32, } -// = begin of generated +// === begin of generated + +// = formed #[ automatically_derived ] impl Struct1 @@ -20,6 +22,8 @@ impl Struct1 } } +// = definition types + #[ derive( Debug ) ] pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > { @@ -34,6 +38,15 @@ impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Forme } } +impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > +{ + type Storage = Struct1FormerStorage; + type Formed = Formed; + type Context = Context; +} + +// = definition + #[ derive( Debug ) ] pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > { @@ -48,13 +61,6 @@ impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Forme } } -impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > -{ - type Storage = Struct1FormerStorage; - type Formed = Formed; - type Context = Context; -} - impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > where End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > > { @@ -64,6 +70,9 @@ where End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; + +// = storage + pub struct Struct1FormerStorage { pub int_1 : ::core::option::Option< i32 >, @@ -118,6 +127,8 @@ impl former::StoragePreform for Struct1FormerStorage } } +// = former + pub struct Struct1Former< Definition = Struct1FormerDefinition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { @@ -207,6 +218,7 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD let context = self.context.take(); former::FormingEnd::< Definition::Types >::call( & on_end, self.storage, context ) } + #[ inline ] pub fn int_1< Src >( mut self, src : Src ) -> Self where Src : ::core::convert::Into< i32 >, @@ -215,8 +227,11 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); self } + } +// = preform with Storage::preform + impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition, @@ -229,6 +244,6 @@ where } } -// = end of generated +// === end of generated include!( "./only_test/basic.rs" ); diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 528d0e8d80..fbb9979670 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1197,7 +1197,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } - // = definition + // = definition types #[ derive( Debug ) ] pub struct #former_definition_types< Context = (), Formed = #struct_name #generics_ty > @@ -1217,10 +1217,18 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } + impl< Context, Formed > former::FormerDefinitionTypes + for #former_definition_types< Context, Formed > + { + type Storage = #former_storage #generics_ty; + type Formed = Formed; + type Context = Context; + } + + // = definition + #[ derive( Debug ) ] pub struct #former_definition< Context = (), Formed = #struct_name #generics_ty, End = former::ReturnPreformed > - // where - // End : former::FormingEnd< #former_definition< Context, Formed, NoEnd > >, { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } @@ -1237,14 +1245,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } - impl< Context, Formed > former::FormerDefinitionTypes - for #former_definition_types< Context, Formed > - { - type Storage = #former_storage #generics_ty; - type Formed = Formed; - type Context = Context; - } - impl< Context, Formed, End > former::FormerDefinition for #former_definition< Context, Formed, End > where @@ -1288,8 +1288,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > for #former_storage #generics_ty #generics_where { - // type Definition = Struct1FormerDefinition; - // type Definition = #former_definition #generics_ty; type Formed = #struct_name #generics_ty; } // generics_impl, generics_ty, generics_where @@ -1299,8 +1297,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #generics_where { - // fn preform( mut self ) -> #former_storage #generics_ty - // fn preform( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed fn preform( mut self ) -> < Self as former::Storage >::Formed { #( #fields_form )* @@ -1468,6 +1464,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } + // = preform with Storage::preform + impl< Definition > #former< Definition > where Definition : former::FormerDefinition, From e07238c860ae152dcbca17f7da42135056ac3963 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 14:13:53 +0300 Subject: [PATCH 138/533] former : experimenting --- .../tests/inc/former_tests/string_slice.rs | 4 +- .../inc/former_tests/string_slice_manual.rs | 48 ++----------------- 2 files changed, 7 insertions(+), 45 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/string_slice.rs b/module/core/former/tests/inc/former_tests/string_slice.rs index 63270eec4e..729e995a4f 100644 --- a/module/core/former/tests/inc/former_tests/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/string_slice.rs @@ -1,6 +1,7 @@ use super::*; #[ derive( Debug, PartialEq, the_module::Former ) ] +// #[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] pub struct Struct1< 'a > { pub string_slice_1 : &'a str, @@ -8,4 +9,5 @@ pub struct Struct1< 'a > // -include!( "./only_test/string_slice.rs" ); +// include!( "./only_test/string_slice.rs" ); +// xxx : uncomment diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 98988cb6cc..96ba351334 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -7,51 +7,11 @@ pub struct Struct1< 'a > pub string_slice_1 : &'a str, } -impl< 'a > Struct1< 'a > -{ - #[ inline ] - pub fn former() -> Struct1Former< 'a > - { - Struct1Former - { - string_slice_1 : ::core::option::Option::None, - } - } -} +// === begin of generated -pub struct Struct1Former< 'a > -{ - string_slice_1 : ::core::option::Option< &'a str >, -} -impl< 'a > Struct1Former< 'a > -{ - #[ inline ] - pub fn form( mut self ) -> Struct1< 'a > - { - let string_slice_1 = if self.string_slice_1.is_some() - { - self.string_slice_1.take().unwrap() - } - else - { - let val : &'a str = ::core::default::Default::default(); - val - }; - Struct1 { string_slice_1 } - } - - #[ inline ] - pub fn string_slice_1< Src >( mut self, src : Src ) -> Self - where - Src : ::core::convert::Into< &'a str >, - { - debug_assert!( self.string_slice_1.is_none() ); - self.string_slice_1 = ::core::option::Option::Some( src.into() ); - self - } -} -// +// === end of generated -include!( "./only_test/string_slice.rs" ); +// include!( "./only_test/string_slice.rs" ); +// xxx : uncomment From 11ef4a418c58a431b45f3eec6096d916c5691533 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 14:18:44 +0300 Subject: [PATCH 139/533] former : experimenting --- .../tests/inc/former_tests/string_slice.rs | 4 +- .../inc/former_tests/string_slice_manual.rs | 242 ++++++++++++++++++ module/core/former/tests/inc/mod.rs | 2 +- 3 files changed, 245 insertions(+), 3 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/string_slice.rs b/module/core/former/tests/inc/former_tests/string_slice.rs index 729e995a4f..abd69806c1 100644 --- a/module/core/former/tests/inc/former_tests/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/string_slice.rs @@ -1,7 +1,7 @@ use super::*; -#[ derive( Debug, PartialEq, the_module::Former ) ] -// #[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, PartialEq, the_module::Former ) ] +#[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] pub struct Struct1< 'a > { pub string_slice_1 : &'a str, diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 96ba351334..10643b0701 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -9,7 +9,249 @@ pub struct Struct1< 'a > // === begin of generated +#[ automatically_derived ] +impl< 'a > Struct1< 'a > +{ + #[ doc = r"" ] + #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn former() -> Struct1Former< 'a, > + { + Struct1Former::< 'a, >::new( former::ReturnPreformed ) + } +} + +#[ derive( Debug ) ] +pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1< 'a > > +{ + _phantom : core::marker::PhantomData< ( Context, Formed ) >, +} + +impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > +{ + fn default() -> Self + { + Self { _phantom : core::marker::PhantomData, } + } +} + +impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > +{ + type Storage = Struct1FormerStorage< 'a >; + type Formed = Formed; + type Context = Context; +} + +#[ derive( Debug ) ] +pub struct Struct1FormerDefinition< Context = (), Formed = Struct1< 'a >, End = former::ReturnPreformed > +{ + _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, +} + +impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > +{ + fn default() -> Self + { + Self { _phantom : core::marker::PhantomData, } + } +} + +impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > +where End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > > +{ + type Types = Struct1FormerDefinitionTypes< Context, Formed >; + type End = End; +} + +pub type Struct1FormerWithClosure< Context, Formed > = + Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; + +#[ doc = "Container of a corresponding former." ] +pub struct Struct1FormerStorage< 'a > +{ + #[ doc = r" A field" ] + pub string_slice_1 : ::core::option::Option< &'a str >, +} + +impl< 'a > ::core::default::Default for Struct1FormerStorage< 'a > +{ + #[ inline( always ) ] + fn default() -> Self + { + Self { string_slice_1 : ::core::option::Option::None, } + } +} + +impl< 'a > former::Storage for Struct1FormerStorage< 'a > +{ + type Formed = Struct1< 'a >; +} + +impl former::StoragePreform for Struct1FormerStorage< 'a > +{ + fn preform( mut self ) -> < Self as former::Storage >::Formed + { + let string_slice_1 = if self.string_slice_1.is_some() + { + self.string_slice_1.take().unwrap() + } + else + { + { + trait MaybeDefault< T > + { + fn maybe_default( self : & Self ) -> T + { + panic!( "Field 'string_slice_1' isn't initialized" ) + } + } + + impl< T > MaybeDefault< T > for & ::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : & Self ) -> T { T::default() } + } + + (& ::core::marker::PhantomData::< &'a str >).maybe_default() + } + }; + let result = Struct1< 'a > { string_slice_1, }; + return result; + } +} + +#[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] +pub struct Struct1Former< 'a, Definition = Struct1FormerDefinition< 'a > > +where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a > >, +{ + storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : core::option::Option< Definition::End >, +} +#[ automatically_derived ] +impl< 'a, Definition > Struct1Former< 'a, Definition > +where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a > >, +{ + #[ doc = r"" ] + #[ doc = r" Finish setting options and call perform on formed entity." ] + #[ doc = r"" ] + #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] + #[ doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + let result = self.form(); + return result; + } + + #[ doc = r"" ] + #[ doc = r" Construct new instance of former with default parameters." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn _new_precise( on_end : Definition::End ) -> Self + { + Self::begin( None, None, on_end ) + } + + #[ doc = r"" ] + #[ doc = r" Construct new instance of former with default parameters." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn new< IntoEnd >( end : IntoEnd ) -> Self + where IntoEnd : Into< Definition::End >, + { + Self::begin( None, None, end, ) + } + + #[ doc = r"" ] + #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn _begin_precise( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : < Definition as former::FormerDefinition >::End, + ) -> Self + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some( on_end ), + } + } + + #[ doc = r"" ] + #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn begin< IntoEnd > + ( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : IntoEnd, + ) -> Self + where IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), + } + } + + #[ doc = r"" ] + #[ doc = r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + self.end() + } + + #[ doc = r"" ] + #[ doc = r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] + #[ inline( always ) ] + pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + former::FormingEnd::< Definition::Types >::call( & on_end, self.storage, context ) + } + + #[ doc = "Setter for the 'string_slice_1' field." ] + #[ inline ] + pub fn string_slice_1< Src >( mut self, src : Src ) -> Self + where Src : ::core::convert::Into< &'a str >, + { + debug_assert!( self.storage.string_slice_1.is_none() ); + self.storage.string_slice_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + self + } +} + +impl< Definition > Struct1Former< Definition > +where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a > >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +{ + pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + former::StoragePreform::preform( self.storage ) + } +} // === end of generated diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 8e35ae8e1c..92d71d877d 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -32,7 +32,7 @@ mod former_tests mod attribute_setter; mod attribute_alias; - mod string_slice_manual; + // mod string_slice_manual; // mod string_slice; mod unsigned_primitive_types; mod default_user_type; From 927f55a3a450853a8c63bec35f700a8ea308e79e Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 14:18:54 +0300 Subject: [PATCH 140/533] former : experimenting --- .../core/former/tests/inc/former_tests/string_slice_manual.rs | 2 +- module/core/former/tests/inc/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 10643b0701..43fc6f3386 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -117,7 +117,7 @@ impl former::StoragePreform for Struct1FormerStorage< 'a > (& ::core::marker::PhantomData::< &'a str >).maybe_default() } }; - let result = Struct1< 'a > { string_slice_1, }; + let result = Struct1::< 'a > { string_slice_1, }; return result; } } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 92d71d877d..8e35ae8e1c 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -32,7 +32,7 @@ mod former_tests mod attribute_setter; mod attribute_alias; - // mod string_slice_manual; + mod string_slice_manual; // mod string_slice; mod unsigned_primitive_types; mod default_user_type; From 74daca583d6d0797b9995d4807ccfc7df5ad3ad3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 14:19:03 +0300 Subject: [PATCH 141/533] former : experimenting --- .../core/former/tests/inc/former_tests/string_slice_manual.rs | 2 +- module/core/former/tests/inc/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 43fc6f3386..10643b0701 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -117,7 +117,7 @@ impl former::StoragePreform for Struct1FormerStorage< 'a > (& ::core::marker::PhantomData::< &'a str >).maybe_default() } }; - let result = Struct1::< 'a > { string_slice_1, }; + let result = Struct1< 'a > { string_slice_1, }; return result; } } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 8e35ae8e1c..92d71d877d 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -32,7 +32,7 @@ mod former_tests mod attribute_setter; mod attribute_alias; - mod string_slice_manual; + // mod string_slice_manual; // mod string_slice; mod unsigned_primitive_types; mod default_user_type; From 00e07f54e712519368b9fd68b13b85915fcd5067 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 15:16:23 +0300 Subject: [PATCH 142/533] former : experimenting --- .../inc/former_tests/string_slice_manual.rs | 127 +++++++++--------- module/core/former/tests/inc/mod.rs | 2 +- 2 files changed, 66 insertions(+), 63 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 10643b0701..1b4878efda 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -12,23 +12,24 @@ pub struct Struct1< 'a > #[ automatically_derived ] impl< 'a > Struct1< 'a > { - #[ doc = r"" ] - #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] - #[ doc = r"" ] + #[ inline( always ) ] - pub fn former() -> Struct1Former< 'a, > + pub fn former() -> Struct1Former< 'a, (), Struct1< 'a >, former::ReturnPreformed > { - Struct1Former::< 'a, >::new( former::ReturnPreformed ) + Struct1Former::< 'a, _, _, _ >::new( former::ReturnPreformed ) } } +// = definition types + #[ derive( Debug ) ] -pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1< 'a > > +// pub struct Struct1FormerDefinitionTypes< 'a, Context = (), Formed = Struct1< 'a > > +pub struct Struct1FormerDefinitionTypes< 'a, Context, Formed > { - _phantom : core::marker::PhantomData< ( Context, Formed ) >, + _phantom : core::marker::PhantomData< ( &'a(), Context, Formed ) >, } -impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > +impl< 'a, Context, Formed > Default for Struct1FormerDefinitionTypes< 'a, Context, Formed > { fn default() -> Self { @@ -36,20 +37,23 @@ impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Forme } } -impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > +impl< 'a, Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< 'a, Context, Formed > { type Storage = Struct1FormerStorage< 'a >; type Formed = Formed; type Context = Context; } +// = definition + #[ derive( Debug ) ] -pub struct Struct1FormerDefinition< Context = (), Formed = Struct1< 'a >, End = former::ReturnPreformed > +pub struct Struct1FormerDefinition< 'a, Context, Formed, End > +// pub struct Struct1FormerDefinition< 'a, Context = (), Formed = Struct1< 'a >, End = former::ReturnPreformed > { - _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, + _phantom : core::marker::PhantomData< ( &'a(), Context, Formed, End ) >, } -impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > +impl< 'a, Context, Formed, End > Default for Struct1FormerDefinition< 'a, Context, Formed, End > { fn default() -> Self { @@ -57,20 +61,21 @@ impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Forme } } -impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > -where End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > > +impl< 'a, Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< 'a, Context, Formed, End > +where End : former::FormingEnd< Struct1FormerDefinitionTypes< 'a, Context, Formed > > { - type Types = Struct1FormerDefinitionTypes< Context, Formed >; + type Types = Struct1FormerDefinitionTypes< 'a, Context, Formed >; type End = End; } -pub type Struct1FormerWithClosure< Context, Formed > = - Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; +pub type Struct1FormerWithClosure< 'a, Context, Formed > = + Struct1FormerDefinition< 'a, Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< 'a, Context, Formed > > >; + +// = storage -#[ doc = "Container of a corresponding former." ] pub struct Struct1FormerStorage< 'a > { - #[ doc = r" A field" ] + pub string_slice_1 : ::core::option::Option< &'a str >, } @@ -87,8 +92,16 @@ impl< 'a > former::Storage for Struct1FormerStorage< 'a > { type Formed = Struct1< 'a >; } +// impl<'a> former::StoragePreform for Struct1FormerStorage<'a> { +// fn preform(mut self) -> Self::Formed { +// let string_slice_1 = self.string_slice_1.take().unwrap_or_else(|| { +// panic!("Field 'string_slice_1' isn't initialized"); +// }); +// Struct1 { string_slice_1 } +// } +// } -impl former::StoragePreform for Struct1FormerStorage< 'a > +impl< 'a > former::StoragePreform for Struct1FormerStorage< 'a > { fn preform( mut self ) -> < Self as former::Storage >::Formed { @@ -117,30 +130,30 @@ impl former::StoragePreform for Struct1FormerStorage< 'a > (& ::core::marker::PhantomData::< &'a str >).maybe_default() } }; - let result = Struct1< 'a > { string_slice_1, }; + let result = Struct1 { string_slice_1, }; return result; } } -#[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] -pub struct Struct1Former< 'a, Definition = Struct1FormerDefinition< 'a > > -where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a > >, +pub struct Struct1Former< 'a, Context, Formed, End, Definition = Struct1FormerDefinition< 'a, Context, Formed, End > > +where + Definition : former::FormerDefinition< End = End >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Formed, Context = Context >, + End : former::FormingEnd::< Definition::Types >, { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : core::option::Option< Definition::End >, + context : core::option::Option< Context >, + on_end : core::option::Option< End >, } #[ automatically_derived ] -impl< 'a, Definition > Struct1Former< 'a, Definition > -where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a > >, +impl< 'a, Context, Formed, End, Definition > Struct1Former< 'a, Context, Formed, End, Definition > +where + Definition : former::FormerDefinition< End = End >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Formed, Context = Context >, + End : former::FormingEnd::< Definition::Types >, { - #[ doc = r"" ] - #[ doc = r" Finish setting options and call perform on formed entity." ] - #[ doc = r"" ] - #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] - #[ doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`." ] - #[ doc = r"" ] + #[ inline( always ) ] pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { @@ -148,18 +161,12 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD return result; } - #[ doc = r"" ] - #[ doc = r" Construct new instance of former with default parameters." ] - #[ doc = r"" ] #[ inline( always ) ] pub fn _new_precise( on_end : Definition::End ) -> Self { Self::begin( None, None, on_end ) } - #[ doc = r"" ] - #[ doc = r" Construct new instance of former with default parameters." ] - #[ doc = r"" ] #[ inline( always ) ] pub fn new< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End >, @@ -167,11 +174,9 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD Self::begin( None, None, end, ) } - #[ doc = r"" ] - #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] - #[ doc = r"" ] #[ inline( always ) ] - pub fn _begin_precise( + pub fn _begin_precise + ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, @@ -189,9 +194,6 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD } } - #[ doc = r"" ] - #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] - #[ doc = r"" ] #[ inline( always ) ] pub fn begin< IntoEnd > ( @@ -213,18 +215,12 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD } } - #[ doc = r"" ] - #[ doc = r" End the process of forming returning original context of forming." ] - #[ doc = r"" ] #[ inline( always ) ] pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { self.end() } - #[ doc = r"" ] - #[ doc = r" End the process of forming returning original context of forming." ] - #[ doc = r"" ] #[ inline( always ) ] pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { @@ -233,7 +229,6 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD former::FormingEnd::< Definition::Types >::call( & on_end, self.storage, context ) } - #[ doc = "Setter for the 'string_slice_1' field." ] #[ inline ] pub fn string_slice_1< Src >( mut self, src : Src ) -> Self where Src : ::core::convert::Into< &'a str >, @@ -244,14 +239,22 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD } } -impl< Definition > Struct1Former< Definition > -where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a > >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, -{ - pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - { - former::StoragePreform::preform( self.storage ) - } -} +// impl< 'a, Definition > Struct1Former< 'a, Definition > +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a > >, +// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +// { +// pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed +// { +// former::StoragePreform::preform( self.storage ) +// } +// } + +// impl< 'a > former::Storage for Struct1FormerStorage< 'a > +// { +// type Formed = Struct1< 'a >; +// } // === end of generated diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 92d71d877d..8e35ae8e1c 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -32,7 +32,7 @@ mod former_tests mod attribute_setter; mod attribute_alias; - // mod string_slice_manual; + mod string_slice_manual; // mod string_slice; mod unsigned_primitive_types; mod default_user_type; From df6f593e2e5c369697d9f4e61264f0b16e5a4f17 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 15:45:02 +0300 Subject: [PATCH 143/533] former : experimenting --- .../inc/former_tests/string_slice_manual.rs | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 1b4878efda..4b99da91dd 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -75,7 +75,6 @@ pub type Struct1FormerWithClosure< 'a, Context, Formed > = pub struct Struct1FormerStorage< 'a > { - pub string_slice_1 : ::core::option::Option< &'a str >, } @@ -92,6 +91,7 @@ impl< 'a > former::Storage for Struct1FormerStorage< 'a > { type Formed = Struct1< 'a >; } + // impl<'a> former::StoragePreform for Struct1FormerStorage<'a> { // fn preform(mut self) -> Self::Formed { // let string_slice_1 = self.string_slice_1.take().unwrap_or_else(|| { @@ -103,7 +103,8 @@ impl< 'a > former::Storage for Struct1FormerStorage< 'a > impl< 'a > former::StoragePreform for Struct1FormerStorage< 'a > { - fn preform( mut self ) -> < Self as former::Storage >::Formed + // fn preform( mut self ) -> < Self as former::Storage >::Formed + fn preform( mut self ) -> Struct1< 'a > { let string_slice_1 = if self.string_slice_1.is_some() { @@ -239,17 +240,25 @@ where } } -// impl< 'a, Definition > Struct1Former< 'a, Definition > -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a > >, -// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, -// { -// pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed -// { -// former::StoragePreform::preform( self.storage ) -// } -// } +// pub struct Struct1Former< 'a, Context, Formed, End, Definition = Struct1FormerDefinition< 'a, Context, Formed, End > > +impl< 'a, Context, End, Definition > Struct1Former< 'a, Context, Struct1< 'a >, End, Definition > +where + + End : former::FormingEnd::< Definition::Types >, + Definition : former::FormerDefinition< End = End >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a >, Context = Context >, + + // Definition : former::FormerDefinition, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a > >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Struct1< 'a > >, +{ + pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + // panic!(); + former::StoragePreform::preform( self.storage ) + } +} // impl< 'a > former::Storage for Struct1FormerStorage< 'a > // { From 8978d9d049d920a42006c06ef601e5e8da5d7e79 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 15:45:18 +0300 Subject: [PATCH 144/533] former : experimenting --- .../former/tests/inc/former_tests/string_slice_manual.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 4b99da91dd..04db37d729 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -260,12 +260,7 @@ where } } -// impl< 'a > former::Storage for Struct1FormerStorage< 'a > -// { -// type Formed = Struct1< 'a >; -// } - // === end of generated -// include!( "./only_test/string_slice.rs" ); +include!( "./only_test/string_slice.rs" ); // xxx : uncomment From ce77a059ae2c11ee900b2dcd031c92eca0853219 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 16:31:25 +0300 Subject: [PATCH 145/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 49 ++++++++++++++----- .../inc/former_tests/string_slice_manual.rs | 9 ++-- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index d71be09000..9c53ca94d9 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -15,17 +15,25 @@ pub struct Struct1 impl Struct1 { + // #[ inline( always ) ] + // pub fn former() -> Struct1Former< > + // { + // Struct1Former::< >::new( former::ReturnPreformed ) + // } + #[ inline( always ) ] - pub fn former() -> Struct1Former< > + pub fn former() -> Struct1Former< (), Struct1, former::ReturnPreformed > { - Struct1Former::< >::new( former::ReturnPreformed ) + Struct1Former::< _, _, _ >::new( former::ReturnPreformed ) } + } // = definition types #[ derive( Debug ) ] -pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > +// pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > +pub struct Struct1FormerDefinitionTypes< Context, Formed > { _phantom : core::marker::PhantomData< ( Context, Formed ) >, } @@ -48,7 +56,8 @@ impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitio // = definition #[ derive( Debug ) ] -pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +// pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +pub struct Struct1FormerDefinition< Context, Formed, End > { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } @@ -129,8 +138,13 @@ impl former::StoragePreform for Struct1FormerStorage // = former -pub struct Struct1Former< Definition = Struct1FormerDefinition > -where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +pub struct Struct1Former< Context, Formed, End, Definition = Struct1FormerDefinition< Context, Formed, End > > +where + End : former::FormingEnd::< Definition::Types >, + Definition : former::FormerDefinition< End = End >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Formed, Context = Context >, + // Definition : former::FormerDefinition, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -138,8 +152,13 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD } #[ automatically_derived ] -impl< Definition > Struct1Former< Definition > -where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +impl< Context, Formed, End, Definition > Struct1Former< Context, Formed, End, Definition > +where + End : former::FormingEnd::< Definition::Types >, + Definition : former::FormerDefinition< End = End >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Formed, Context = Context >, + // Definition : former::FormerDefinition, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { #[ inline( always ) ] @@ -232,11 +251,16 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerD // = preform with Storage::preform -impl< Definition > Struct1Former< Definition > +impl< Context, End, Definition > Struct1Former< Context, Struct1, End, Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, + End : former::FormingEnd::< Definition::Types >, + Definition : former::FormerDefinition< End = End >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1, Context = Context >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Struct1 >, + // Definition : former::FormerDefinition, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, + // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { @@ -246,4 +270,5 @@ where // === end of generated -include!( "./only_test/basic.rs" ); +// include!( "./only_test/basic.rs" ); +// xxx : uncomment \ No newline at end of file diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 04db37d729..8d7b2d5c14 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -18,6 +18,7 @@ impl< 'a > Struct1< 'a > { Struct1Former::< 'a, _, _, _ >::new( former::ReturnPreformed ) } + } // = definition types @@ -138,9 +139,9 @@ impl< 'a > former::StoragePreform for Struct1FormerStorage< 'a > pub struct Struct1Former< 'a, Context, Formed, End, Definition = Struct1FormerDefinition< 'a, Context, Formed, End > > where + End : former::FormingEnd::< Definition::Types >, Definition : former::FormerDefinition< End = End >, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Formed, Context = Context >, - End : former::FormingEnd::< Definition::Types >, { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, context : core::option::Option< Context >, @@ -150,9 +151,9 @@ where #[ automatically_derived ] impl< 'a, Context, Formed, End, Definition > Struct1Former< 'a, Context, Formed, End, Definition > where + End : former::FormingEnd::< Definition::Types >, Definition : former::FormerDefinition< End = End >, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Formed, Context = Context >, - End : former::FormingEnd::< Definition::Types >, { #[ inline( always ) ] @@ -243,13 +244,9 @@ where // pub struct Struct1Former< 'a, Context, Formed, End, Definition = Struct1FormerDefinition< 'a, Context, Formed, End > > impl< 'a, Context, End, Definition > Struct1Former< 'a, Context, Struct1< 'a >, End, Definition > where - End : former::FormingEnd::< Definition::Types >, Definition : former::FormerDefinition< End = End >, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a >, Context = Context >, - - // Definition : former::FormerDefinition, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a > >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Struct1< 'a > >, { From fc2d60e932466e19a8220403d7cdf53ec716ec67 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 17:06:44 +0300 Subject: [PATCH 146/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 20 ++- .../tests/inc/former_tests/only_test/basic.rs | 161 ++++++++++++++++-- module/core/former/tests/inc/mod.rs | 2 +- 3 files changed, 158 insertions(+), 25 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 9c53ca94d9..4aae2cdeae 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -32,8 +32,8 @@ impl Struct1 // = definition types #[ derive( Debug ) ] -// pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > -pub struct Struct1FormerDefinitionTypes< Context, Formed > +pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > +// pub struct Struct1FormerDefinitionTypes< Context, Formed > { _phantom : core::marker::PhantomData< ( Context, Formed ) >, } @@ -56,8 +56,8 @@ impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitio // = definition #[ derive( Debug ) ] -// pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > -pub struct Struct1FormerDefinition< Context, Formed, End > +pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +// pub struct Struct1FormerDefinition< Context, Formed, End > { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } @@ -138,7 +138,13 @@ impl former::StoragePreform for Struct1FormerStorage // = former -pub struct Struct1Former< Context, Formed, End, Definition = Struct1FormerDefinition< Context, Formed, End > > +pub struct Struct1Former +< + Context = (), + Formed = Struct1, + End = former::ReturnPreformed, + Definition = Struct1FormerDefinition< Context, Formed, End >, +> where End : former::FormingEnd::< Definition::Types >, Definition : former::FormerDefinition< End = End >, @@ -270,5 +276,5 @@ where // === end of generated -// include!( "./only_test/basic.rs" ); -// xxx : uncomment \ No newline at end of file +include!( "./only_test/basic.rs" ); +// xxx : uncomment diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index 0808110ac3..ae4cc70666 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -31,13 +31,19 @@ tests_impls! // +// xxx : uncomment fn custom_definition_params() { - // zzz : make example of that // custom params let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > + :: + < + _, + _, + _, + Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > + > ::begin ( None, @@ -50,7 +56,13 @@ tests_impls! // custom params with into let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > + :: + < + _, + _, + _, + Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > + > ::begin ( None, @@ -63,7 +75,13 @@ tests_impls! // custom params begin let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > + :: + < + _, + _, + _, + Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > + > ::begin ( None, @@ -76,7 +94,32 @@ tests_impls! // custom params begin with Struct1FormerWithClosure let got = Struct1Former - ::< Struct1FormerWithClosure< i32, i32 > > + :: + < + _, + _, + _, + Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > + > + ::begin + ( + None, + Some( 3 ), + | storage : Struct1FormerStorage, context : Option< i32 > | { 2 * ( storage.int_1.unwrap() + context.unwrap() ) } + ) + .int_1( 13 ) + .form(); + a_id!( got, 32 ); + + // less explicit + let got = Struct1Former + :: + < + _, + _, + _, + Struct1FormerDefinition< i32, i32, former::FormingEndClosure< _ > > + > ::begin ( None, @@ -108,7 +151,14 @@ tests_impls! // begin with context let mut storage = Struct1FormerStorage::default(); storage.int_1 = Some( 13 ); - let exp = Struct1Former::< Struct1FormerDefinition > + let exp = Struct1Former + :: + < + _, + _, + _, + Struct1FormerDefinition + > ::begin( Some( storage ), Some( () ), the_module::ReturnPreformed ) .form(); a_id!( got, exp ); @@ -122,7 +172,14 @@ tests_impls! // custom params let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, _ > > + // ::< Struct1FormerDefinition< i32, i32, _ > > + :: + < + _, + _, + _, + Struct1FormerDefinition< i32, i32, _ > + > ::_begin_precise ( None, @@ -138,7 +195,14 @@ tests_impls! // custom params with into let got = Struct1Former - ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > + // ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > + :: + < + _, + _, + _, + Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > + > ::_begin_precise ( None, @@ -182,7 +246,14 @@ tests_impls! } let end_wrapper : former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndClosure::new( f1 ); let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > + // ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > + :: + < + _, + _, + _, + Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > + > ::new( end_wrapper ) .int_1( 13 ) .form(); @@ -191,7 +262,14 @@ tests_impls! // default explicit params with wrapper and closure let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > + // ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > + :: + < + _, + _, + _, + Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > + > ::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); @@ -200,7 +278,14 @@ tests_impls! // default explicit params with wrapper and closure, auto types let got = Struct1Former - ::< Struct1FormerDefinition< _, _, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > + // ::< Struct1FormerDefinition< _, _, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > + :: + < + _, + _, + _, + Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > + > ::new( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); @@ -209,7 +294,14 @@ tests_impls! // default explicit params with wrapper and closure let got = Struct1Former - ::< Struct1FormerWithClosure< (), Struct1 > > + // ::< Struct1FormerWithClosure< (), Struct1 > > + :: + < + _, + _, + _, + Struct1FormerWithClosure< (), Struct1 > + > ::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); @@ -218,7 +310,14 @@ tests_impls! // default explicit params with wrapper and closure let got = Struct1Former - ::< Struct1FormerWithClosure< (), Struct1 > > + // ::< Struct1FormerWithClosure< (), Struct1 > > + :: + < + _, + _, + _, + Struct1FormerWithClosure< (), Struct1 > + > ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) .int_1( 13 ) .form(); @@ -242,7 +341,14 @@ tests_impls! // default explicit params let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, _ > > + // ::< Struct1FormerDefinition< (), Struct1, _ > > + :: + < + _, + _, + _, + Struct1FormerDefinition< (), Struct1, _ >, + > ::_new_precise( former::ReturnPreformed ) .int_1( 13 ) .form(); @@ -256,7 +362,14 @@ tests_impls! } let end_wrapper : former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > = former::FormingEndClosure::new( f1 ); let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, _ > > + // ::< Struct1FormerDefinition< (), Struct1, _ > > + :: + < + _, + _, + _, + Struct1FormerDefinition< (), Struct1, _ >, + > ::_new_precise( end_wrapper ) .int_1( 13 ) .form(); @@ -265,7 +378,14 @@ tests_impls! // default explicit params with wrapper and closure let got = Struct1Former - ::< Struct1FormerDefinition< (), Struct1, _ > > + // ::< Struct1FormerDefinition< (), Struct1, _ > > + :: + < + _, + _, + _, + Struct1FormerDefinition< (), Struct1, _ >, + > ::_new_precise( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); @@ -274,7 +394,14 @@ tests_impls! // default explicit params with wrapper and closure, auto types let got = Struct1Former - ::< Struct1FormerDefinition< _, _, _ > > + // ::< Struct1FormerDefinition< _, _, _ > > + :: + < + _, + _, + _, + Struct1FormerDefinition< _, _, _ >, + > ::_new_precise( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 8e35ae8e1c..d1b3cec0d8 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -17,7 +17,7 @@ mod former_tests mod container_former_hashmap; mod a_basic_manual; - mod a_basic; + // mod a_basic; // xxx mod a_primitives_manual; mod a_primitives; mod a_containers_without_subformer; From f321d3ee92907c6b0a9f225efb79358b3079f77f Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 17:27:10 +0300 Subject: [PATCH 147/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 75 ++++++++-------- .../tests/inc/former_tests/only_test/basic.rs | 90 ++++++------------- 2 files changed, 69 insertions(+), 96 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 4aae2cdeae..4d61b762d0 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -15,25 +15,26 @@ pub struct Struct1 impl Struct1 { - // #[ inline( always ) ] - // pub fn former() -> Struct1Former< > - // { - // Struct1Former::< >::new( former::ReturnPreformed ) - // } - #[ inline( always ) ] - pub fn former() -> Struct1Former< (), Struct1, former::ReturnPreformed > + pub fn former() -> Struct1Former< > { - Struct1Former::< _, _, _ >::new( former::ReturnPreformed ) + Struct1Former::< >::new( former::ReturnPreformed ) } + // #[ inline( always ) ] + // // pub fn former() -> Struct1Former< (), Struct1, former::ReturnPreformed > + // pub fn former() -> Struct1Former + // { + // Struct1Former::< _, _, _ >::new( former::ReturnPreformed ) + // } + } // = definition types #[ derive( Debug ) ] -pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > -// pub struct Struct1FormerDefinitionTypes< Context, Formed > +// pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > +pub struct Struct1FormerDefinitionTypes< Context, Formed > { _phantom : core::marker::PhantomData< ( Context, Formed ) >, } @@ -56,8 +57,8 @@ impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitio // = definition #[ derive( Debug ) ] -pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > -// pub struct Struct1FormerDefinition< Context, Formed, End > +// pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +pub struct Struct1FormerDefinition< Context, Formed, End > { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } @@ -138,19 +139,21 @@ impl former::StoragePreform for Struct1FormerStorage // = former +// type Struct1Former< Definition > = Struct1Former< (), Struct1, former::ReturnPreformed, Definition >; + pub struct Struct1Former < - Context = (), - Formed = Struct1, - End = former::ReturnPreformed, - Definition = Struct1FormerDefinition< Context, Formed, End >, + // Context = (), + // Formed = Struct1, + // End = former::ReturnPreformed, + Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, > where - End : former::FormingEnd::< Definition::Types >, - Definition : former::FormerDefinition< End = End >, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Formed, Context = Context >, - // Definition : former::FormerDefinition, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + // End : former::FormingEnd::< Definition::Types >, + // Definition : former::FormerDefinition< End = End >, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Formed, Context = Context >, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -158,13 +161,14 @@ where } #[ automatically_derived ] -impl< Context, Formed, End, Definition > Struct1Former< Context, Formed, End, Definition > +// impl< Context, Formed, End, Definition > Struct1Former< Context, Formed, End, Definition > +impl< Definition > Struct1Former< Definition > where - End : former::FormingEnd::< Definition::Types >, - Definition : former::FormerDefinition< End = End >, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Formed, Context = Context >, - // Definition : former::FormerDefinition, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + // End : former::FormingEnd::< Definition::Types >, + // Definition : former::FormerDefinition< End = End >, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Formed, Context = Context >, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { #[ inline( always ) ] @@ -257,16 +261,17 @@ where // = preform with Storage::preform -impl< Context, End, Definition > Struct1Former< Context, Struct1, End, Definition > +// impl< Context, End, Definition > Struct1Former< Context, Struct1, End, Definition > +impl< Definition > Struct1Former< Definition > where - End : former::FormingEnd::< Definition::Types >, - Definition : former::FormerDefinition< End = End >, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1, Context = Context >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Struct1 >, - // Definition : former::FormerDefinition, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, + // End : former::FormingEnd::< Definition::Types >, + // Definition : former::FormerDefinition< End = End >, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1, Context = Context >, // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Struct1 >, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index ae4cc70666..18e20a953b 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -15,8 +15,11 @@ tests_impls! a_id!( former.storage.int_1, None ); a_id!( former.context, None ); a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); - let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); + // let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); + // a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); + // xxx : uncomment let command = Struct1::former().form(); a_id!( command.int_1, 0 ); @@ -39,9 +42,6 @@ tests_impls! let got = Struct1Former :: < - _, - _, - _, Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > ::begin @@ -58,9 +58,6 @@ tests_impls! let got = Struct1Former :: < - _, - _, - _, Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > ::begin @@ -77,9 +74,7 @@ tests_impls! let got = Struct1Former :: < - _, - _, - _, + Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > ::begin @@ -96,9 +91,7 @@ tests_impls! let got = Struct1Former :: < - _, - _, - _, + Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > ::begin @@ -115,9 +108,7 @@ tests_impls! let got = Struct1Former :: < - _, - _, - _, + Struct1FormerDefinition< i32, i32, former::FormingEndClosure< _ > > > ::begin @@ -138,14 +129,14 @@ tests_impls! { // begin with none - let got = Struct1Former::< Struct1FormerDefinition >::begin( None, None, the_module::ReturnPreformed ).int_1( 13 ).form(); + let got = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::begin( None, None, the_module::ReturnPreformed ).int_1( 13 ).form(); let exp = Struct1::former().int_1( 13 ).form(); a_id!( got, exp ); // begin with storage let mut storage = Struct1FormerStorage::default(); storage.int_1 = Some( 13 ); - let exp = Struct1Former::< Struct1FormerDefinition >::begin( Some( storage ), None, the_module::ReturnPreformed ).form(); + let exp = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::begin( Some( storage ), None, the_module::ReturnPreformed ).form(); a_id!( got, exp ); // begin with context @@ -154,10 +145,7 @@ tests_impls! let exp = Struct1Former :: < - _, - _, - _, - Struct1FormerDefinition + Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > ::begin( Some( storage ), Some( () ), the_module::ReturnPreformed ) .form(); @@ -175,9 +163,7 @@ tests_impls! // ::< Struct1FormerDefinition< i32, i32, _ > > :: < - _, - _, - _, + Struct1FormerDefinition< i32, i32, _ > > ::_begin_precise @@ -198,9 +184,7 @@ tests_impls! // ::< Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > :: < - _, - _, - _, + Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > ::_begin_precise @@ -224,7 +208,7 @@ tests_impls! // basic case let former = Struct1::former(); - let former2 = Struct1Former::< Struct1FormerDefinition >::_new_precise( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::_new_precise( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let exp = former.form(); let got = former2.form(); @@ -249,9 +233,7 @@ tests_impls! // ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > :: < - _, - _, - _, + Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > ::new( end_wrapper ) @@ -265,9 +247,7 @@ tests_impls! // ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > :: < - _, - _, - _, + Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > ::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) @@ -281,9 +261,7 @@ tests_impls! // ::< Struct1FormerDefinition< _, _, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > :: < - _, - _, - _, + Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > ::new( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) @@ -297,9 +275,7 @@ tests_impls! // ::< Struct1FormerWithClosure< (), Struct1 > > :: < - _, - _, - _, + Struct1FormerWithClosure< (), Struct1 > > ::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) @@ -313,9 +289,7 @@ tests_impls! // ::< Struct1FormerWithClosure< (), Struct1 > > :: < - _, - _, - _, + Struct1FormerWithClosure< (), Struct1 > > ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) @@ -333,7 +307,7 @@ tests_impls! // basic case let former = Struct1::former(); - let former2 = Struct1Former::< Struct1FormerDefinition >::_new_precise( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::_new_precise( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let exp = former.form(); let got = former2.form(); @@ -344,9 +318,7 @@ tests_impls! // ::< Struct1FormerDefinition< (), Struct1, _ > > :: < - _, - _, - _, + Struct1FormerDefinition< (), Struct1, _ >, > ::_new_precise( former::ReturnPreformed ) @@ -365,9 +337,7 @@ tests_impls! // ::< Struct1FormerDefinition< (), Struct1, _ > > :: < - _, - _, - _, + Struct1FormerDefinition< (), Struct1, _ >, > ::_new_precise( end_wrapper ) @@ -381,9 +351,7 @@ tests_impls! // ::< Struct1FormerDefinition< (), Struct1, _ > > :: < - _, - _, - _, + Struct1FormerDefinition< (), Struct1, _ >, > ::_new_precise( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) @@ -397,9 +365,7 @@ tests_impls! // ::< Struct1FormerDefinition< _, _, _ > > :: < - _, - _, - _, + Struct1FormerDefinition< _, _, _ >, > ::_new_precise( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) @@ -439,7 +405,7 @@ tests_impls! { // default is implemented for definition - let _default = Struct1FormerDefinition::< () >::default(); + let _default = Struct1FormerDefinition::< (), Struct1, former::ReturnPreformed >::default(); // let _default = Struct1FormerDefinition::default(); // why does not work? // definition types exists and has Formed @@ -448,18 +414,20 @@ tests_impls! a_id!( got, exp ); // definition types exists and has Formed - let got = < Struct1FormerDefinitionTypes as the_module::FormerDefinitionTypes >::Formed::former().form(); + let got = < Struct1FormerDefinitionTypes< (), Struct1 > as the_module::FormerDefinitionTypes >::Formed::former().form(); let exp = Struct1::former().form(); a_id!( got, exp ); // definition types exists and has Storage use former::StoragePreform; - let got = < Struct1FormerDefinitionTypes as the_module::FormerDefinitionTypes >::Storage::preform( Struct1::former().storage ); + let got = < Struct1FormerDefinitionTypes< (), Struct1 > as the_module::FormerDefinitionTypes >::Storage + ::preform( Struct1::former().storage ); let exp = Struct1::former().form(); a_id!( got, exp ); // definition exists and has Storage - let got = < < Struct1FormerDefinition as the_module::FormerDefinition >::Types as the_module::FormerDefinitionTypes >::Formed::former().form(); + let got = < < Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > as the_module::FormerDefinition >::Types as the_module::FormerDefinitionTypes >::Formed + ::former().form(); let exp = Struct1::former().form(); a_id!( got, exp ); From 8515097920f0f6fef2fc7d28596334d93ff33401 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 17:42:03 +0300 Subject: [PATCH 148/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 8 +-- .../inc/former_tests/only_test/primitives.rs | 56 ++++-------------- .../former_tests/only_test/string_slice.rs | 41 +++++++++++++ .../inc/former_tests/string_slice_manual.rs | 59 ++++++++++--------- module/core/former/tests/inc/mod.rs | 1 + 5 files changed, 85 insertions(+), 80 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 4d61b762d0..51640b3422 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -261,17 +261,13 @@ where // = preform with Storage::preform -// impl< Context, End, Definition > Struct1Former< Context, Struct1, End, Definition > impl< Definition > Struct1Former< Definition > where - // End : former::FormingEnd::< Definition::Types >, - // Definition : former::FormerDefinition< End = End >, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1, Context = Context >, - // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Struct1 >, Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Struct1 >, + { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 3e536af161..45a9dc02cd 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -8,43 +8,34 @@ tests_impls! // - fn internals() + fn api() { - let former = Struct1::former(); - a_id!( former.storage.int_1, None ); - a_id!( former.storage.string_1, None ); - a_id!( former.storage.int_optional_1, None ); - a_id!( former.storage.string_optional_1, None ); - a_id!( former.context, None ); - a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); - let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); - a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); - + // form let command = Struct1::former().form(); a_id!( command.int_1, 0 ); a_id!( command.string_1, "".to_string() ); a_id!( command.int_optional_1, None ); a_id!( command.string_optional_1, None ); - let command = Struct1::former().perform(); + // end + let command = Struct1::former().end(); a_id!( command.int_1, 0 ); a_id!( command.string_1, "".to_string() ); a_id!( command.int_optional_1, None ); a_id!( command.string_optional_1, None ); - let command = Struct1::former().end(); + // perform + let command = Struct1::former().perform(); a_id!( command.int_1, 0 ); a_id!( command.string_1, "".to_string() ); a_id!( command.int_optional_1, None ); a_id!( command.string_optional_1, None ); - } - - // - - fn new() - { + // formation should have method preform + let got = Struct1::former().preform(); + let exp = Struct1::former().form(); + a_id!( got, exp ); // default explicit params with wrapper and closure let got = Struct1Former @@ -59,29 +50,6 @@ tests_impls! // - fn preform() - { - - // formation should have method preform - let got = Struct1::former().preform(); - let exp = Struct1::former().form(); - a_id!( got, exp ); - - // storage should have method preform - let got = the_module::StoragePreform::preform( Struct1::former().storage ); - let exp = Struct1::former().form(); - a_id!( got, exp ); - - // storage should have method preform - use the_module::StoragePreform; - let got = Struct1::former().storage.preform(); - let exp = Struct1::former().form(); - a_id!( got, exp ); - - } - - // - fn test_int() { @@ -263,9 +231,7 @@ tests_impls! tests_index! { - internals, - new, - preform, + api, test_int, test_string, diff --git a/module/core/former/tests/inc/former_tests/only_test/string_slice.rs b/module/core/former/tests/inc/former_tests/only_test/string_slice.rs index cd07841dd3..315d2c8942 100644 --- a/module/core/former/tests/inc/former_tests/only_test/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/only_test/string_slice.rs @@ -7,6 +7,43 @@ use test_tools::exposed::*; tests_impls! { + + + // + + fn api() + { + + // form + let command = Struct1::former().form(); + a_id!( command.string_slice_1, "" ); + + // end + let command = Struct1::former().end(); + a_id!( command.string_slice_1, "" ); + + // perform + let command = Struct1::former().perform(); + a_id!( command.string_slice_1, "" ); + + // formation should have method preform + let got = Struct1::former().preform(); + let exp = Struct1::former().form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure + let got = Struct1Former + ::< Struct1FormerWithClosure< (), Struct1 > > + ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) + .string_slice_1( "abc" ) + .form(); + let exp = Struct1::former().string_slice_1( "abc" ).form(); + a_id!( got, exp ); + + } + + // + fn test_complex() { // test.case( "default" ); @@ -41,11 +78,15 @@ tests_impls! // a_id!( command, expected ); } + + // + } // tests_index! { + api, test_complex, } diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 8d7b2d5c14..9f093b3074 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -13,10 +13,16 @@ pub struct Struct1< 'a > impl< 'a > Struct1< 'a > { + // #[ inline( always ) ] + // pub fn former() -> Struct1Former< 'a, (), Struct1< 'a >, former::ReturnPreformed > + // { + // Struct1Former::< 'a, _, _, _ >::new( former::ReturnPreformed ) + // } + #[ inline( always ) ] - pub fn former() -> Struct1Former< 'a, (), Struct1< 'a >, former::ReturnPreformed > + pub fn former() -> Struct1Former< 'a > { - Struct1Former::< 'a, _, _, _ >::new( former::ReturnPreformed ) + Struct1Former::new( former::ReturnPreformed ) } } @@ -48,8 +54,8 @@ impl< 'a, Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefin // = definition #[ derive( Debug ) ] -pub struct Struct1FormerDefinition< 'a, Context, Formed, End > // pub struct Struct1FormerDefinition< 'a, Context = (), Formed = Struct1< 'a >, End = former::ReturnPreformed > +pub struct Struct1FormerDefinition< 'a, Context, Formed, End > { _phantom : core::marker::PhantomData< ( &'a(), Context, Formed, End ) >, } @@ -93,19 +99,10 @@ impl< 'a > former::Storage for Struct1FormerStorage< 'a > type Formed = Struct1< 'a >; } -// impl<'a> former::StoragePreform for Struct1FormerStorage<'a> { -// fn preform(mut self) -> Self::Formed { -// let string_slice_1 = self.string_slice_1.take().unwrap_or_else(|| { -// panic!("Field 'string_slice_1' isn't initialized"); -// }); -// Struct1 { string_slice_1 } -// } -// } - impl< 'a > former::StoragePreform for Struct1FormerStorage< 'a > { - // fn preform( mut self ) -> < Self as former::Storage >::Formed - fn preform( mut self ) -> Struct1< 'a > + fn preform( mut self ) -> < Self as former::Storage >::Formed + // fn preform( mut self ) -> Struct1< 'a > { let string_slice_1 = if self.string_slice_1.is_some() { @@ -137,23 +134,29 @@ impl< 'a > former::StoragePreform for Struct1FormerStorage< 'a > } } -pub struct Struct1Former< 'a, Context, Formed, End, Definition = Struct1FormerDefinition< 'a, Context, Formed, End > > +// = former + +pub struct Struct1Former< 'a, Definition = Struct1FormerDefinition< 'a, (), Struct1< 'a >, former::ReturnPreformed > > where - End : former::FormingEnd::< Definition::Types >, - Definition : former::FormerDefinition< End = End >, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Formed, Context = Context >, + // End : former::FormingEnd::< Definition::Types >, + // Definition : former::FormerDefinition< End = End >, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Formed, Context = Context >, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a > >, { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, - context : core::option::Option< Context >, - on_end : core::option::Option< End >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : core::option::Option< Definition::End >, } #[ automatically_derived ] -impl< 'a, Context, Formed, End, Definition > Struct1Former< 'a, Context, Formed, End, Definition > +impl< 'a, Definition > Struct1Former< 'a, Definition > where - End : former::FormingEnd::< Definition::Types >, - Definition : former::FormerDefinition< End = End >, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Formed, Context = Context >, + // End : former::FormingEnd::< Definition::Types >, + // Definition : former::FormerDefinition< End = End >, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Formed, Context = Context >, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a > >, { #[ inline( always ) ] @@ -241,12 +244,10 @@ where } } -// pub struct Struct1Former< 'a, Context, Formed, End, Definition = Struct1FormerDefinition< 'a, Context, Formed, End > > -impl< 'a, Context, End, Definition > Struct1Former< 'a, Context, Struct1< 'a >, End, Definition > +impl< 'a, Definition > Struct1Former< 'a, Definition > where - End : former::FormingEnd::< Definition::Types >, - Definition : former::FormerDefinition< End = End >, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a >, Context = Context >, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a > >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Struct1< 'a > >, { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index d1b3cec0d8..1af11f924a 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -32,6 +32,7 @@ mod former_tests mod attribute_setter; mod attribute_alias; + // xxx mod string_slice_manual; // mod string_slice; mod unsigned_primitive_types; From 1a213d1652b0018f28a724e9b8595a8a5674facc Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 17:43:20 +0300 Subject: [PATCH 149/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 19 ------------------- module/core/former/tests/inc/mod.rs | 2 +- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 51640b3422..b93ca40b20 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -21,13 +21,6 @@ impl Struct1 Struct1Former::< >::new( former::ReturnPreformed ) } - // #[ inline( always ) ] - // // pub fn former() -> Struct1Former< (), Struct1, former::ReturnPreformed > - // pub fn former() -> Struct1Former - // { - // Struct1Former::< _, _, _ >::new( former::ReturnPreformed ) - // } - } // = definition types @@ -139,19 +132,11 @@ impl former::StoragePreform for Struct1FormerStorage // = former -// type Struct1Former< Definition > = Struct1Former< (), Struct1, former::ReturnPreformed, Definition >; - pub struct Struct1Former < - // Context = (), - // Formed = Struct1, - // End = former::ReturnPreformed, Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, > where - // End : former::FormingEnd::< Definition::Types >, - // Definition : former::FormerDefinition< End = End >, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Formed, Context = Context >, Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { @@ -161,12 +146,8 @@ where } #[ automatically_derived ] -// impl< Context, Formed, End, Definition > Struct1Former< Context, Formed, End, Definition > impl< Definition > Struct1Former< Definition > where - // End : former::FormingEnd::< Definition::Types >, - // Definition : former::FormerDefinition< End = End >, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Formed, Context = Context >, Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 1af11f924a..b9a8901c9d 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -17,7 +17,7 @@ mod former_tests mod container_former_hashmap; mod a_basic_manual; - // mod a_basic; // xxx + mod a_basic; mod a_primitives_manual; mod a_primitives; mod a_containers_without_subformer; From 72541fe7dfd9985838c9533aeb98a31698217731 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 13 Apr 2024 21:40:18 +0300 Subject: [PATCH 150/533] former : experimenting --- module/core/former/tests/inc/mod.rs | 66 ++++++++++---------- module/core/former_meta/src/derive/former.rs | 35 ++++------- 2 files changed, 45 insertions(+), 56 deletions(-) diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index b9a8901c9d..61fac6055c 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -7,38 +7,40 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_common; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_vec; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_hashset; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_hashmap; + // xxx + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod container_former_common; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod container_former_vec; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod container_former_hashset; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod container_former_hashmap; mod a_basic_manual; mod a_basic; - mod a_primitives_manual; - mod a_primitives; - mod a_containers_without_subformer; - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer_manual; - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer ; - - mod attribute_default_container; - mod attribute_default_primitive; - // mod attribute_perform; // xxx - mod attribute_setter; - mod attribute_alias; - - // xxx - mod string_slice_manual; - // mod string_slice; - mod unsigned_primitive_types; - mod default_user_type; - mod user_type_no_default; - mod user_type_no_debug; +// mod a_primitives_manual; +// mod a_primitives; +// mod a_containers_without_subformer; +// #[ cfg( not( feature = "no_std" ) ) ] +// mod a_containers_with_subformer_manual; +// #[ cfg( not( feature = "no_std" ) ) ] +// mod a_containers_with_subformer ; +// +// mod attribute_default_container; +// mod attribute_default_primitive; +// // mod attribute_perform; // xxx +// mod attribute_setter; +// mod attribute_alias; +// +// // xxx +// mod string_slice_manual; +// // mod string_slice; +// mod unsigned_primitive_types; +// mod default_user_type; +// mod user_type_no_default; +// mod user_type_no_debug; +// xxx // mod name_collision_former_hashmap_without_parameter; // mod name_collision_former_vector_without_parameter; @@ -58,9 +60,9 @@ mod former_tests // mod subformer_basic_manual; // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_shortcut; +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_shortcut; // xxx : uncomment diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index fbb9979670..d34ddea355 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1092,7 +1092,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // add embedded generic parameters let mut extra_generics : syn::Generics = parse_quote! { - < Definition = #former_definition #generics_ty > + < Definition = #former_definition < #generics_ty (), #struct_name, former::ReturnPreformed > > + // Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, + // xxx }; extra_generics.where_clause = parse_quote! { @@ -1168,7 +1170,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field_form_map( former_field ), field_name_map( former_field ), field_setter_map( former_field, &struct_name ), - fields_setter_callback_descriptor_map( former_field, &struct_name, &former, &former_storage /*, &former_definition */ ), + fields_setter_callback_descriptor_map( former_field, &struct_name, &former, &former_storage ), )}).multiunzip(); let ( _doc_former_mod, doc_former_struct ) = doc_generate( struct_name ); @@ -1200,7 +1202,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = definition types #[ derive( Debug ) ] - pub struct #former_definition_types< Context = (), Formed = #struct_name #generics_ty > + // xxx : revert later + // pub struct #former_definition_types< Context = (), Formed = #struct_name #generics_ty > + pub struct #former_definition_types< Context, Formed > { _phantom : core::marker::PhantomData< ( Context, Formed ) >, } @@ -1228,7 +1232,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = definition #[ derive( Debug ) ] - pub struct #former_definition< Context = (), Formed = #struct_name #generics_ty, End = former::ReturnPreformed > + // xxx : revert later + // pub struct #former_definition< Context = (), Formed = #struct_name #generics_ty, End = former::ReturnPreformed > + pub struct #former_definition< Context, Formed, End > { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } @@ -1328,23 +1334,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #generics_of_former_where { - // /// - // /// Finish setting options and return formed entity. - // /// - // #[ inline( always ) ] - // pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - // // #struct_name #generics_ty - // { - // former::StoragePreform::preform( self.storage ) - // // < #former_storage #generics_ty as former::StoragePreform >::preform( self.storage ) - // // #( #fields_form )* - // // let result = #struct_name - // // { - // // #( #fields_names, )* - // // }; - // // return result; - // } - /// /// Finish setting options and call perform on formed entity. /// @@ -1452,9 +1441,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - // let storage = self.form(); - // on_end.call( self.storage, context ) - // former::FormingEnd::< #former_definition #generics_ty >::call( &on_end, self.storage, context ) former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) } @@ -1471,6 +1457,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty, Formed = #struct_name #generics_ty >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = #struct_name #generics_ty >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed From 7b719c792ea842a431977854a4ae92163362ca6f Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 15 Apr 2024 07:40:31 +0300 Subject: [PATCH 151/533] former : experimenting --- module/core/former/tests/inc/mod.rs | 69 +++++++++++++++-------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 61fac6055c..1a67d97599 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -7,41 +7,42 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; - // xxx - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod container_former_common; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod container_former_vec; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod container_former_hashset; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod container_former_hashmap; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_common; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_vec; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashset; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashmap; mod a_basic_manual; mod a_basic; -// mod a_primitives_manual; -// mod a_primitives; -// mod a_containers_without_subformer; -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer_manual; -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer ; -// -// mod attribute_default_container; -// mod attribute_default_primitive; -// // mod attribute_perform; // xxx -// mod attribute_setter; -// mod attribute_alias; -// -// // xxx -// mod string_slice_manual; -// // mod string_slice; -// mod unsigned_primitive_types; -// mod default_user_type; -// mod user_type_no_default; -// mod user_type_no_debug; -// xxx + mod a_primitives_manual; + mod a_primitives; + // mod a_containers_without_subformer; + // xxx + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer_manual; + // #[ cfg( not( feature = "no_std" ) ) ] + // mod a_containers_with_subformer ; + // xxx + mod attribute_default_container; + mod attribute_default_primitive; + // mod attribute_perform; // xxx + mod attribute_setter; + mod attribute_alias; + + // xxx + mod string_slice_manual; + // mod string_slice; + mod unsigned_primitive_types; + mod default_user_type; + mod user_type_no_default; + mod user_type_no_debug; + +// xxx // mod name_collision_former_hashmap_without_parameter; // mod name_collision_former_vector_without_parameter; // mod name_collisions; @@ -60,9 +61,9 @@ mod former_tests // mod subformer_basic_manual; // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic; -// -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_shortcut; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_shortcut; // xxx : uncomment From a1c42b48505fc6c4fd57dc3fedf7e0a7abd246ef Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 15 Apr 2024 16:55:51 +0300 Subject: [PATCH 152/533] macro_tools : introduce GenericsWithWhere --- .../former/tests/inc/former_tests/a_basic.rs | 2 + .../tests/inc/former_tests/string_slice.rs | 10 +- .../inc/former_tests/string_slice_manual.rs | 1 - module/core/former/tests/inc/mod.rs | 2 +- module/core/former_meta/src/derive/former.rs | 16 +++- module/core/macro_tools/src/generics.rs | 92 +++++++++++++++++++ .../macro_tools/tests/inc/generics_test.rs | 38 +++++++- module/core/meta_tools/src/lib.rs | 5 - 8 files changed, 154 insertions(+), 12 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic.rs b/module/core/former/tests/inc/former_tests/a_basic.rs index 31ec06d07d..aca44f31fc 100644 --- a/module/core/former/tests/inc/former_tests/a_basic.rs +++ b/module/core/former/tests/inc/former_tests/a_basic.rs @@ -11,6 +11,8 @@ pub struct Struct1 // = begin of generated + + // = end of generated include!( "./only_test/basic.rs" ); diff --git a/module/core/former/tests/inc/former_tests/string_slice.rs b/module/core/former/tests/inc/former_tests/string_slice.rs index abd69806c1..3ec14fc4df 100644 --- a/module/core/former/tests/inc/former_tests/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/string_slice.rs @@ -1,13 +1,17 @@ use super::*; -// #[ derive( Debug, PartialEq, the_module::Former ) ] -#[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, PartialEq, former::Former ) ] +#[ derive( Debug, PartialEq, former::Former ) ] #[ debug ] pub struct Struct1< 'a > { pub string_slice_1 : &'a str, } -// +// === begin of generated + + + +// === end of generated // include!( "./only_test/string_slice.rs" ); // xxx : uncomment diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 9f093b3074..e9ccab8df6 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -261,4 +261,3 @@ where // === end of generated include!( "./only_test/string_slice.rs" ); -// xxx : uncomment diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 1a67d97599..3273a00edb 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -36,7 +36,7 @@ mod former_tests // xxx mod string_slice_manual; - // mod string_slice; + mod string_slice; mod unsigned_primitive_types; mod default_user_type; mod user_type_no_default; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index d34ddea355..8c2fc8ec9b 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1059,7 +1059,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let has_debug = attr::has_debug( ast.attrs.iter() )?; let example_of_custom_setter = false; - /* names */ let struct_name = &ast.ident; @@ -1089,6 +1088,18 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > qt!{ #_generics_params, } }; + // xxx + // if has_debug + // { + // let q = qt! + // { + // < Definition = #former_definition < #generics_ty > >; + // }; + // println!( "= a =" ); + // // diag::debug_report_print( "derive : Former", original_input, &result ); + // macro_tools::code_print!( q ); + // } + // add embedded generic parameters let mut extra_generics : syn::Generics = parse_quote! { @@ -1096,6 +1107,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, // xxx }; + extra_generics.where_clause = parse_quote! { where @@ -1103,8 +1115,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, }; + // zzz : write helper to fix bug with where let generics_of_former = generics::merge( &generics, &extra_generics ); + let ( generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generics_of_former.split_for_impl(); let generics_of_former_with_defaults = generics_of_former.params.clone(); // macro_tools::code_print!( generics_of_former_with_defaults ); diff --git a/module/core/macro_tools/src/generics.rs b/module/core/macro_tools/src/generics.rs index f7e4617f2f..8e2181d8c3 100644 --- a/module/core/macro_tools/src/generics.rs +++ b/module/core/macro_tools/src/generics.rs @@ -24,6 +24,73 @@ pub( crate ) mod private { + /// A `GenericsWithWhere` struct to handle the parsing of Rust generics with an explicit `where` clause. + /// + /// This wrapper addresses the limitation in the `syn` crate where parsing `Generics` directly from a `ParseStream` + /// does not automatically handle associated `where` clauses. By integrating `where` clause parsing into the + /// `GenericsWithWhere`, this struct provides a seamless way to capture both the generics and their constraints + /// in scenarios where the `where` clause is crucial for type constraints and bounds in Rust macros and code generation. + /// + /// Usage: + /// ``` + /// let parsed_generics : macro_tools::GenericsWithWhere = syn::parse_str( "< T : Clone, U : Default = Default1 > where T : Default").unwrap(); + /// assert!( parsed_generics.generics.params.len() == 2 ); + /// assert!( parsed_generics.generics.where_clause.is_some() ); + /// ``` + /// + + #[ derive( Debug ) ] + pub struct GenericsWithWhere + { + /// Syn's generics parameters. + pub generics : syn::Generics, + } + + impl GenericsWithWhere + { + /// Unwraps the `GenericsWithWhere` to retrieve the inner `syn::Generics`. + pub fn unwrap( self ) -> syn::Generics + { + self.generics + } + + /// Parses a string to a `GenericsWithWhere`, specifically designed to handle generics syntax with where clauses effectively. + pub fn parse_from_str( s : &str ) -> syn::Result< GenericsWithWhere > + { + syn::parse_str::< GenericsWithWhere >( s ) + } + } + + impl syn::parse::Parse for GenericsWithWhere + { + fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > + { + let generics : syn::Generics = input.parse()?; + let where_clause : Option< syn::WhereClause > = input.parse()?; + + let mut generics_clone = generics.clone(); + generics_clone.where_clause = where_clause; + + Ok( GenericsWithWhere + { + generics : generics_clone, + }) + } + } + + impl quote::ToTokens for GenericsWithWhere + { + fn to_tokens( &self, tokens : &mut proc_macro2::TokenStream ) + { + self.generics.to_tokens( tokens ); + } + } + +// pub fn make< IntoTokens : Into< proc_macro2::TokenStream > >( input : IntoTokens ) +// { +// +// } + /// Merges two `syn::Generics` instances into a new one. /// /// This function takes two references to `syn::Generics` and combines their @@ -110,6 +177,25 @@ pub( crate ) mod private result } +// // add embedded generic parameters +// let mut extra_generics : syn::Generics = parse_quote! +// { +// < Definition = #former_definition < #generics_ty (), #struct_name, former::ReturnPreformed > > +// // Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, +// // xxx +// }; +// +// extra_generics.where_clause = parse_quote! +// { +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, +// // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +// }; +// +// // zzz : write helper to fix bug with where +// let generics_of_former = generics::merge( &generics, &extra_generics ); + /// Extracts parameter names from the given `Generics`, /// dropping bounds, defaults, and the where clause. /// @@ -210,6 +296,12 @@ pub mod orphan #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::exposed::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + GenericsWithWhere, + }; } /// Exposed namespace of the module. diff --git a/module/core/macro_tools/tests/inc/generics_test.rs b/module/core/macro_tools/tests/inc/generics_test.rs index 84c5090d0c..e2179e02a7 100644 --- a/module/core/macro_tools/tests/inc/generics_test.rs +++ b/module/core/macro_tools/tests/inc/generics_test.rs @@ -4,7 +4,7 @@ use super::*; // #[ test ] -fn basic() +fn assumptions() { let mut generics_a : syn::Generics = parse_quote!{ < T : Clone, U : Default > }; @@ -38,6 +38,42 @@ fn basic() // +#[ test ] +fn where_assumptions() +{ + + let got : the_module::GenericsWithWhere = parse_quote! + { + < 'a, T : Clone, U : Default > + where + Definition : former::FormerDefinition, + }; + let got = got.unwrap(); + + let mut exp : syn::Generics = parse_quote! + { + < 'a, T : Clone, U : Default, V : std::fmt::Debug > + }; + exp.where_clause = parse_quote! + { + where + Definition : former::FormerDefinition, + }; + + // a_id!( tree_print!( got ), tree_print!( exp ) ); + // code_print!( got ); + // code_print!( exp ); + // code_print!( got.where_clause ); + // code_print!( exp.where_clause ); + + assert_eq!( got.params, exp.params ); + assert_eq!( got.where_clause, exp.where_clause ); + assert_eq!( got, exp ); + +} + +// + #[ test ] fn merge_defaults() { diff --git a/module/core/meta_tools/src/lib.rs b/module/core/meta_tools/src/lib.rs index 4511f3c3ca..cd49c9841e 100644 --- a/module/core/meta_tools/src/lib.rs +++ b/module/core/meta_tools/src/lib.rs @@ -2,11 +2,6 @@ #![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] #![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] #![ doc( html_root_url = "https://docs.rs/meta_tools/latest/meta_tools/" ) ] - -//! -//! Collection of general purpose meta tools. -//! - #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] /// Namespace with dependencies. From 33c0608981a69e09ba33dd3f10425d0817bbf945 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 15 Apr 2024 16:56:22 +0300 Subject: [PATCH 153/533] macro_tools : introduce GenericsWithWhere --- module/core/macro_tools/tests/inc/generics_test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/core/macro_tools/tests/inc/generics_test.rs b/module/core/macro_tools/tests/inc/generics_test.rs index e2179e02a7..adb49b3fb9 100644 --- a/module/core/macro_tools/tests/inc/generics_test.rs +++ b/module/core/macro_tools/tests/inc/generics_test.rs @@ -44,7 +44,7 @@ fn where_assumptions() let got : the_module::GenericsWithWhere = parse_quote! { - < 'a, T : Clone, U : Default > + < 'a, T : Clone, U : Default, V : std::fmt::Debug > where Definition : former::FormerDefinition, }; From 65a3e3804e562b1574ef98e6ded530a0f5b263cc Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 15 Apr 2024 17:21:15 +0300 Subject: [PATCH 154/533] macro_tools : improving GenericsWithWhere --- module/core/former_meta/src/derive/former.rs | 29 ++++++++++++++----- module/core/macro_tools/src/generics.rs | 23 +++++++++++++++ .../macro_tools/tests/inc/generics_test.rs | 2 +- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 8c2fc8ec9b..bf03b50682 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1100,29 +1100,42 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // macro_tools::code_print!( q ); // } - // add embedded generic parameters - let mut extra_generics : syn::Generics = parse_quote! + // parameters for definition + let mut definition_extra_generics : macro_tools::GenericsWithWhere = parse_quote! { < Definition = #former_definition < #generics_ty (), #struct_name, former::ReturnPreformed > > - // Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, - // xxx + where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, }; + let generics_of_former = generics::merge( &generics, &definition_extra_generics ); - extra_generics.where_clause = parse_quote! + // parameters for former + let mut former_extra_generics : macro_tools::GenericsWithWhere = parse_quote! { + < Definition = #former_definition < #generics_ty (), #struct_name, former::ReturnPreformed > > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, - // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + // Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, + // xxx }; + // former_extra_generics.where_clause = parse_quote! + // { + // where + // Definition : former::FormerDefinition, + // Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, + // // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + // }; + // zzz : write helper to fix bug with where - let generics_of_former = generics::merge( &generics, &extra_generics ); + let generics_of_former = generics::merge( &generics, &former_extra_generics ); let ( generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generics_of_former.split_for_impl(); let generics_of_former_with_defaults = generics_of_former.params.clone(); // macro_tools::code_print!( generics_of_former_with_defaults ); - // macro_tools::code_print!( extra_generics ); + // macro_tools::code_print!( former_extra_generics ); /* structure attribute */ diff --git a/module/core/macro_tools/src/generics.rs b/module/core/macro_tools/src/generics.rs index 8e2181d8c3..d2d2c0966b 100644 --- a/module/core/macro_tools/src/generics.rs +++ b/module/core/macro_tools/src/generics.rs @@ -86,6 +86,22 @@ pub( crate ) mod private } } + impl From for syn::Generics + { + fn from( g : GenericsWithWhere ) -> Self + { + g.generics + } + } + + impl From for GenericsWithWhere + { + fn from( generics : syn::Generics ) -> Self + { + GenericsWithWhere { generics } + } + } + // pub fn make< IntoTokens : Into< proc_macro2::TokenStream > >( input : IntoTokens ) // { // @@ -133,7 +149,13 @@ pub( crate ) mod private /// assert_eq!( got, exp ); pub fn merge( a : &syn::Generics, b : &syn::Generics ) -> syn::Generics + // pub fn merge< A, B >( a : A, b : B ) -> syn::Generics + // where + // A : AsRef< syn::Generics >, + // B : AsRef< syn::Generics >, { + // let a : &syn::Generics = a.as_ref(); + // let b : &syn::Generics = b.as_ref(); let mut result = syn::Generics { @@ -144,6 +166,7 @@ pub( crate ) mod private }; // Merge params + // result.params.extend( a.params.iter().chain( b.params.iter() ) ); for param in &a.params { result.params.push( param.clone() ); diff --git a/module/core/macro_tools/tests/inc/generics_test.rs b/module/core/macro_tools/tests/inc/generics_test.rs index adb49b3fb9..3933448155 100644 --- a/module/core/macro_tools/tests/inc/generics_test.rs +++ b/module/core/macro_tools/tests/inc/generics_test.rs @@ -39,7 +39,7 @@ fn assumptions() // #[ test ] -fn where_assumptions() +fn generics_with_where() { let got : the_module::GenericsWithWhere = parse_quote! From 17a42c2e0f35ab5b610bcd12f1ac9aeb3cf6ebbf Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 15 Apr 2024 17:22:50 +0300 Subject: [PATCH 155/533] macro_tools : improving GenericsWithWhere --- module/core/former_meta/src/derive/former.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index bf03b50682..02c1866627 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1108,7 +1108,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, }; - let generics_of_former = generics::merge( &generics, &definition_extra_generics ); + let generics_of_former = generics::merge( &generics, &definition_extra_generics.into() ); // parameters for former let mut former_extra_generics : macro_tools::GenericsWithWhere = parse_quote! @@ -1130,7 +1130,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // }; // zzz : write helper to fix bug with where - let generics_of_former = generics::merge( &generics, &former_extra_generics ); + let generics_of_former = generics::merge( &generics, &former_extra_generics.into() ); let ( generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generics_of_former.split_for_impl(); let generics_of_former_with_defaults = generics_of_former.params.clone(); From b7271e4e34a638dc5d456e5335f2953823bde58d Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 00:16:03 +0300 Subject: [PATCH 156/533] former : experimenting --- .../former/tests/inc/former_tests/a_basic.rs | 4 +- module/core/former/tests/inc/mod.rs | 66 +++++++++---------- module/core/former_meta/src/derive/former.rs | 48 +++++--------- .../macro_tools/tests/inc/generics_test.rs | 28 ++++++++ 4 files changed, 81 insertions(+), 65 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic.rs b/module/core/former/tests/inc/former_tests/a_basic.rs index aca44f31fc..d1c209ab44 100644 --- a/module/core/former/tests/inc/former_tests/a_basic.rs +++ b/module/core/former/tests/inc/former_tests/a_basic.rs @@ -1,8 +1,8 @@ #[ allow( unused_imports ) ] use super::*; -#[ derive( Debug, PartialEq, former::Former ) ] -// #[ derive( Debug, PartialEq, former::Former ) ] #[ debug ] +// #[ derive( Debug, PartialEq, former::Former ) ] +#[ derive( Debug, PartialEq, former::Former ) ] #[ debug ] // #[ derive( Debug, PartialEq ) ] pub struct Struct1 { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 3273a00edb..bfc5a6480b 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -7,40 +7,40 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_common; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_vec; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_hashset; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_hashmap; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_common; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_vec; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_hashset; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_hashmap; mod a_basic_manual; mod a_basic; - mod a_primitives_manual; - mod a_primitives; - // mod a_containers_without_subformer; - // xxx - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer_manual; - // #[ cfg( not( feature = "no_std" ) ) ] - // mod a_containers_with_subformer ; - // xxx - - mod attribute_default_container; - mod attribute_default_primitive; - // mod attribute_perform; // xxx - mod attribute_setter; - mod attribute_alias; - - // xxx - mod string_slice_manual; - mod string_slice; - mod unsigned_primitive_types; - mod default_user_type; - mod user_type_no_default; - mod user_type_no_debug; +// mod a_primitives_manual; +// mod a_primitives; +// // mod a_containers_without_subformer; +// // xxx +// #[ cfg( not( feature = "no_std" ) ) ] +// mod a_containers_with_subformer_manual; +// // #[ cfg( not( feature = "no_std" ) ) ] +// // mod a_containers_with_subformer ; +// // xxx +// +// mod attribute_default_container; +// mod attribute_default_primitive; +// // mod attribute_perform; // xxx +// mod attribute_setter; +// mod attribute_alias; +// +// // xxx +// mod string_slice_manual; +// // mod string_slice; +// mod unsigned_primitive_types; +// mod default_user_type; +// mod user_type_no_default; +// mod user_type_no_debug; // xxx // mod name_collision_former_hashmap_without_parameter; @@ -62,8 +62,8 @@ mod former_tests // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_shortcut; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_shortcut; // xxx : uncomment diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 02c1866627..76aabfbfae 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1088,48 +1088,36 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > qt!{ #_generics_params, } }; - // xxx - // if has_debug - // { - // let q = qt! - // { - // < Definition = #former_definition < #generics_ty > >; - // }; - // println!( "= a =" ); - // // diag::debug_report_print( "derive : Former", original_input, &result ); - // macro_tools::code_print!( q ); - // } + + if has_debug + { + println!( "= a =" ); + } // parameters for definition - let mut definition_extra_generics : macro_tools::GenericsWithWhere = parse_quote! + // let mut definition_extra_generics : macro_tools::GenericsWithWhere = parse_quote! + let mut definition_extra_generics : macro_tools::syn::AngleBracketedGenericArguments = parse_quote! { - < Definition = #former_definition < #generics_ty (), #struct_name, former::ReturnPreformed > > - where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, + < (), #struct_name, former::ReturnPreformed > }; - let generics_of_former = generics::merge( &generics, &definition_extra_generics.into() ); + // xxx : uncomment + // let generics_of_definition = generics::merge( &generics, &definition_extra_generics.into() ); + let generics_of_definition = definition_extra_generics; + + // xxx + if has_debug + { + println!( "= b =" ); + } // parameters for former let mut former_extra_generics : macro_tools::GenericsWithWhere = parse_quote! { - < Definition = #former_definition < #generics_ty (), #struct_name, former::ReturnPreformed > > + < Definition = #former_definition #generics_of_definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, - // Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, - // xxx }; - - // former_extra_generics.where_clause = parse_quote! - // { - // where - // Definition : former::FormerDefinition, - // Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, - // // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - // }; - - // zzz : write helper to fix bug with where let generics_of_former = generics::merge( &generics, &former_extra_generics.into() ); let ( generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generics_of_former.split_for_impl(); diff --git a/module/core/macro_tools/tests/inc/generics_test.rs b/module/core/macro_tools/tests/inc/generics_test.rs index 3933448155..c2d71004e9 100644 --- a/module/core/macro_tools/tests/inc/generics_test.rs +++ b/module/core/macro_tools/tests/inc/generics_test.rs @@ -38,6 +38,34 @@ fn assumptions() // +#[ test ] +fn assumptions2() +{ + + let code : syn::ItemStruct = syn::parse_quote! + { + pub struct Struct1Former + < + Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, + > + {} + }; + tree_print!( code ); + + // let mut _got : syn::Generics = parse_quote! + // { + // < Struct1, former::ReturnPreformed > + // }; + + // let mut _got : syn::Generics = parse_quote! + // { + // < (), Struct1, former::ReturnPreformed > + // }; + +} + +// + #[ test ] fn generics_with_where() { From bf04a0046d5076e7bda17b13ba88b83a56d86ffa Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 00:25:50 +0300 Subject: [PATCH 157/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 76aabfbfae..9120ce8a05 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1089,10 +1089,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > }; - if has_debug - { - println!( "= a =" ); - } + // xxx + // if has_debug + // { + // println!( "= a =" ); + // } // parameters for definition // let mut definition_extra_generics : macro_tools::GenericsWithWhere = parse_quote! @@ -1104,11 +1105,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // let generics_of_definition = generics::merge( &generics, &definition_extra_generics.into() ); let generics_of_definition = definition_extra_generics; - // xxx - if has_debug - { - println!( "= b =" ); - } + // // xxx + // if has_debug + // { + // println!( "= b =" ); + // } // parameters for former let mut former_extra_generics : macro_tools::GenericsWithWhere = parse_quote! From 84679901e1b8a14abaf54624724c0800ecafca45 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 10:17:23 +0300 Subject: [PATCH 158/533] macro_tools : more functions to manipulate generics, small refactoring --- module/core/macro_tools/src/generic_args.rs | 56 +++++++++++++++++++ .../src/{generics.rs => generic_params.rs} | 6 -- module/core/macro_tools/src/lib.rs | 8 +-- .../tests/inc/{attr_test.rs => attr.rs} | 0 .../tests/inc/{basic_test.rs => basic.rs} | 0 .../macro_tools/tests/inc/generic_args.rs | 41 ++++++++++++++ .../{generics_test.rs => generic_params.rs} | 28 ---------- module/core/macro_tools/tests/inc/mod.rs | 28 +++++----- .../inc/{quantifier_test.rs => quantifier.rs} | 0 .../tests/inc/{syntax_test.rs => syntax.rs} | 0 .../tests/inc/{tokens_test.rs => tokens.rs} | 0 11 files changed, 116 insertions(+), 51 deletions(-) create mode 100644 module/core/macro_tools/src/generic_args.rs rename module/core/macro_tools/src/{generics.rs => generic_params.rs} (97%) rename module/core/macro_tools/tests/inc/{attr_test.rs => attr.rs} (100%) rename module/core/macro_tools/tests/inc/{basic_test.rs => basic.rs} (100%) create mode 100644 module/core/macro_tools/tests/inc/generic_args.rs rename module/core/macro_tools/tests/inc/{generics_test.rs => generic_params.rs} (87%) rename module/core/macro_tools/tests/inc/{quantifier_test.rs => quantifier.rs} (100%) rename module/core/macro_tools/tests/inc/{syntax_test.rs => syntax.rs} (100%) rename module/core/macro_tools/tests/inc/{tokens_test.rs => tokens.rs} (100%) diff --git a/module/core/macro_tools/src/generic_args.rs b/module/core/macro_tools/src/generic_args.rs new file mode 100644 index 0000000000..1f5e234613 --- /dev/null +++ b/module/core/macro_tools/src/generic_args.rs @@ -0,0 +1,56 @@ +//! +//! Manipulations on generic arguments. +//! + +/// Internal namespace. +pub( crate ) mod private +{ + +} + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + }; +} + +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + }; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + pub use super::protected as generics; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super:: + { + prelude::*, + }; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/core/macro_tools/src/generics.rs b/module/core/macro_tools/src/generic_params.rs similarity index 97% rename from module/core/macro_tools/src/generics.rs rename to module/core/macro_tools/src/generic_params.rs index d2d2c0966b..c6f72ffa3e 100644 --- a/module/core/macro_tools/src/generics.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -149,13 +149,7 @@ pub( crate ) mod private /// assert_eq!( got, exp ); pub fn merge( a : &syn::Generics, b : &syn::Generics ) -> syn::Generics - // pub fn merge< A, B >( a : A, b : B ) -> syn::Generics - // where - // A : AsRef< syn::Generics >, - // B : AsRef< syn::Generics >, { - // let a : &syn::Generics = a.as_ref(); - // let b : &syn::Generics = b.as_ref(); let mut result = syn::Generics { diff --git a/module/core/macro_tools/src/lib.rs b/module/core/macro_tools/src/lib.rs index 6bf4f43554..10a65d1dae 100644 --- a/module/core/macro_tools/src/lib.rs +++ b/module/core/macro_tools/src/lib.rs @@ -12,7 +12,7 @@ pub mod diag; #[ cfg( feature = "enabled" ) ] pub mod generic_analyze; #[ cfg( feature = "enabled" ) ] -pub mod generics; +pub mod generic_params; #[ cfg( feature = "enabled" ) ] pub mod name; #[ cfg( feature = "enabled" ) ] @@ -56,7 +56,7 @@ pub mod protected container_kind::orphan::*, diag::orphan::*, generic_analyze::orphan::*, - generics::orphan::*, + generic_params::orphan::*, name::orphan::*, quantifier::orphan::*, tokens::orphan::*, @@ -95,7 +95,7 @@ pub mod exposed container_kind::exposed::*, diag::exposed::*, generic_analyze::exposed::*, - generics::exposed::*, + generic_params::exposed::*, name::exposed::*, quantifier::exposed::*, tokens::exposed::*, @@ -163,7 +163,7 @@ pub mod prelude container_kind::prelude::*, diag::prelude::*, generic_analyze::prelude::*, - generics::prelude::*, + generic_params::prelude::*, name::prelude::*, quantifier::prelude::*, tokens::prelude::*, diff --git a/module/core/macro_tools/tests/inc/attr_test.rs b/module/core/macro_tools/tests/inc/attr.rs similarity index 100% rename from module/core/macro_tools/tests/inc/attr_test.rs rename to module/core/macro_tools/tests/inc/attr.rs diff --git a/module/core/macro_tools/tests/inc/basic_test.rs b/module/core/macro_tools/tests/inc/basic.rs similarity index 100% rename from module/core/macro_tools/tests/inc/basic_test.rs rename to module/core/macro_tools/tests/inc/basic.rs diff --git a/module/core/macro_tools/tests/inc/generic_args.rs b/module/core/macro_tools/tests/inc/generic_args.rs new file mode 100644 index 0000000000..aad19c7a25 --- /dev/null +++ b/module/core/macro_tools/tests/inc/generic_args.rs @@ -0,0 +1,41 @@ + +use super::*; + +// + +#[ test ] +fn assumptions() +{ + + // let code : syn::ItemStruct = syn::parse_quote! + // { + // pub struct Struct1Former + // < + // Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, + // > + // {} + // }; + // tree_print!( code ); + + // let mut a : syn::Generics = parse_quote! + // { + // < 'a, T > + // }; + // let mut b : syn::AngleBracketedGenericArguments = parse_quote! + // { + // < (), Struct1, former::ReturnPreformed > + // }; + // let got = generics::merge( &a.into(), &b.into() ); + // // let got = definition_extra_generics; + + // let mut _got : syn::Generics = parse_quote! + // { + // < Struct1, former::ReturnPreformed > + // }; + + // let mut _got : syn::Generics = parse_quote! + // { + // < (), Struct1, former::ReturnPreformed > + // }; + +} diff --git a/module/core/macro_tools/tests/inc/generics_test.rs b/module/core/macro_tools/tests/inc/generic_params.rs similarity index 87% rename from module/core/macro_tools/tests/inc/generics_test.rs rename to module/core/macro_tools/tests/inc/generic_params.rs index c2d71004e9..3933448155 100644 --- a/module/core/macro_tools/tests/inc/generics_test.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -38,34 +38,6 @@ fn assumptions() // -#[ test ] -fn assumptions2() -{ - - let code : syn::ItemStruct = syn::parse_quote! - { - pub struct Struct1Former - < - Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, - > - {} - }; - tree_print!( code ); - - // let mut _got : syn::Generics = parse_quote! - // { - // < Struct1, former::ReturnPreformed > - // }; - - // let mut _got : syn::Generics = parse_quote! - // { - // < (), Struct1, former::ReturnPreformed > - // }; - -} - -// - #[ test ] fn generics_with_where() { diff --git a/module/core/macro_tools/tests/inc/mod.rs b/module/core/macro_tools/tests/inc/mod.rs index c4063e67eb..223aa4b5b4 100644 --- a/module/core/macro_tools/tests/inc/mod.rs +++ b/module/core/macro_tools/tests/inc/mod.rs @@ -6,17 +6,19 @@ use test_tools::exposed::*; #[ allow( unused_imports ) ] #[ cfg( feature = "enabled" ) ] -use the_module::exposed::*; +#[ path = "." ] +mod if_enabled +{ -#[ cfg( feature = "enabled" ) ] -mod attr_test; -#[ cfg( feature = "enabled" ) ] -mod basic_test; -#[ cfg( feature = "enabled" ) ] -mod generics_test; -#[ cfg( feature = "enabled" ) ] -mod quantifier_test; -#[ cfg( feature = "enabled" ) ] -mod syntax_test; -#[ cfg( feature = "enabled" ) ] -mod tokens_test; + use super::*; + use the_module::exposed::*; + + mod attr; + mod basic; + mod generic_args; + mod generic_params; + mod quantifier; + mod syntax; + mod tokens; + +} diff --git a/module/core/macro_tools/tests/inc/quantifier_test.rs b/module/core/macro_tools/tests/inc/quantifier.rs similarity index 100% rename from module/core/macro_tools/tests/inc/quantifier_test.rs rename to module/core/macro_tools/tests/inc/quantifier.rs diff --git a/module/core/macro_tools/tests/inc/syntax_test.rs b/module/core/macro_tools/tests/inc/syntax.rs similarity index 100% rename from module/core/macro_tools/tests/inc/syntax_test.rs rename to module/core/macro_tools/tests/inc/syntax.rs diff --git a/module/core/macro_tools/tests/inc/tokens_test.rs b/module/core/macro_tools/tests/inc/tokens.rs similarity index 100% rename from module/core/macro_tools/tests/inc/tokens_test.rs rename to module/core/macro_tools/tests/inc/tokens.rs From b483d28bc9b1d4d01b01713929778e2e3b54b06e Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 11:45:06 +0300 Subject: [PATCH 159/533] macro_tools : more functions to manipulate generics, small refactoring --- module/core/macro_tools/src/attr.rs | 1 - module/core/macro_tools/src/generic_args.rs | 57 +++++- module/core/macro_tools/src/generic_params.rs | 5 +- module/core/macro_tools/src/lib.rs | 5 + .../macro_tools/tests/inc/generic_args.rs | 189 ++++++++++++++---- module/core/macro_tools/tests/inc/mod.rs | 12 +- 6 files changed, 218 insertions(+), 51 deletions(-) diff --git a/module/core/macro_tools/src/attr.rs b/module/core/macro_tools/src/attr.rs index 51a3fbe10d..8a9d37cb81 100644 --- a/module/core/macro_tools/src/attr.rs +++ b/module/core/macro_tools/src/attr.rs @@ -326,4 +326,3 @@ pub mod exposed pub mod prelude { } - diff --git a/module/core/macro_tools/src/generic_args.rs b/module/core/macro_tools/src/generic_args.rs index 1f5e234613..10881f8dc5 100644 --- a/module/core/macro_tools/src/generic_args.rs +++ b/module/core/macro_tools/src/generic_args.rs @@ -6,6 +6,60 @@ pub( crate ) mod private { + /// A trait for converting a reference to an existing type into a `syn::AngleBracketedGenericArguments`. + /// + /// This trait provides a mechanism to transform various types that represent generic parameters, + /// such as `syn::Generics`, into a uniform `syn::AngleBracketedGenericArguments`. This is particularly + /// useful when working with Rust syntax trees in procedural macros, allowing for the manipulation + /// and merging of generic parameters from different syntactic elements. + pub trait IntoGenericsArgs + { + /// Converts a reference of the implementing type into `syn::AngleBracketedGenericArguments`. + /// + /// This method should handle the conversion logic necessary to transform the implementing + /// type's generic parameter representations into the structured format required by + /// `syn::AngleBracketedGenericArguments`, which is commonly used to represent generic parameters + /// enclosed in angle brackets. + /// + /// # Returns + /// A new instance of `syn::AngleBracketedGenericArguments` representing the generic parameters + /// of the original type. + fn into_generics_args( &self ) -> syn::AngleBracketedGenericArguments; + } + + impl IntoGenericsArgs for syn::Generics + { + fn into_generics_args( &self ) -> syn::AngleBracketedGenericArguments + { + let args = self.params.iter().map( | param | + { + match param + { + syn::GenericParam::Type( ty ) => syn::GenericArgument::Type( syn::Type::Path( syn::TypePath + { + qself: None, + path: ty.ident.clone().into(), + })), + syn::GenericParam::Lifetime( lifetime ) => syn::GenericArgument::Lifetime( lifetime.lifetime.clone() ), + syn::GenericParam::Const( const_param ) => syn::GenericArgument::Const( syn::Expr::Path( syn::ExprPath + { + attrs: vec![], + qself: None, + path: const_param.ident.clone().into(), + })), + } + }).collect(); + + syn::AngleBracketedGenericArguments + { + colon2_token: None, + lt_token: syn::token::Lt::default(), + args, + gt_token: syn::token::Gt::default(), + } + } + } + } #[ doc( inline ) ] @@ -35,13 +89,14 @@ pub mod orphan #[ allow( unused_imports ) ] pub use super::private:: { + IntoGenericsArgs, }; } /// Exposed namespace of the module. pub mod exposed { - pub use super::protected as generics; + pub use super::protected as generics_args; #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super:: diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index c6f72ffa3e..9d0535c0f8 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -236,7 +236,7 @@ pub( crate ) mod private /// let mut generics : syn::Generics = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > }; /// generics.where_clause = parse_quote!{ where T: std::fmt::Debug }; /// // let generics : Generics = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > where T: std::fmt::Debug }; - /// let simplified_generics = macro_tools::generics::params_names( &generics ); + /// let simplified_generics = macro_tools::generic_params::params_names( &generics ); /// /// assert_eq!( simplified_generics.params.len(), 4 ); // Contains T, U, 'a, and N /// assert!( simplified_generics.where_clause.is_none() ); // Where clause is removed @@ -307,6 +307,7 @@ pub mod protected }; } +// xxx : external attr instead of internal? /// Orphan namespace of the module. pub mod orphan { @@ -324,7 +325,7 @@ pub mod orphan /// Exposed namespace of the module. pub mod exposed { - pub use super::protected as generics; + pub use super::protected as generics_params; #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super:: diff --git a/module/core/macro_tools/src/lib.rs b/module/core/macro_tools/src/lib.rs index 10a65d1dae..1fdfc6d07a 100644 --- a/module/core/macro_tools/src/lib.rs +++ b/module/core/macro_tools/src/lib.rs @@ -12,6 +12,8 @@ pub mod diag; #[ cfg( feature = "enabled" ) ] pub mod generic_analyze; #[ cfg( feature = "enabled" ) ] +pub mod generic_args; +#[ cfg( feature = "enabled" ) ] pub mod generic_params; #[ cfg( feature = "enabled" ) ] pub mod name; @@ -56,6 +58,7 @@ pub mod protected container_kind::orphan::*, diag::orphan::*, generic_analyze::orphan::*, + generic_args::orphan::*, generic_params::orphan::*, name::orphan::*, quantifier::orphan::*, @@ -95,6 +98,7 @@ pub mod exposed container_kind::exposed::*, diag::exposed::*, generic_analyze::exposed::*, + generic_args::exposed::*, generic_params::exposed::*, name::exposed::*, quantifier::exposed::*, @@ -163,6 +167,7 @@ pub mod prelude container_kind::prelude::*, diag::prelude::*, generic_analyze::prelude::*, + generic_args::prelude::*, generic_params::prelude::*, name::prelude::*, quantifier::prelude::*, diff --git a/module/core/macro_tools/tests/inc/generic_args.rs b/module/core/macro_tools/tests/inc/generic_args.rs index aad19c7a25..50a22208ed 100644 --- a/module/core/macro_tools/tests/inc/generic_args.rs +++ b/module/core/macro_tools/tests/inc/generic_args.rs @@ -1,41 +1,148 @@ - -use super::*; - -// - -#[ test ] -fn assumptions() -{ - - // let code : syn::ItemStruct = syn::parse_quote! - // { - // pub struct Struct1Former - // < - // Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, - // > - // {} - // }; - // tree_print!( code ); - - // let mut a : syn::Generics = parse_quote! - // { - // < 'a, T > - // }; - // let mut b : syn::AngleBracketedGenericArguments = parse_quote! - // { - // < (), Struct1, former::ReturnPreformed > - // }; - // let got = generics::merge( &a.into(), &b.into() ); - // // let got = definition_extra_generics; - - // let mut _got : syn::Generics = parse_quote! - // { - // < Struct1, former::ReturnPreformed > - // }; - - // let mut _got : syn::Generics = parse_quote! - // { - // < (), Struct1, former::ReturnPreformed > - // }; - -} +// +// use super::*; +// +// // +// +// #[ test ] +// fn assumptions() +// { +// +// // let code : syn::ItemStruct = syn::parse_quote! +// // { +// // pub struct Struct1Former +// // < +// // Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, +// // > +// // {} +// // }; +// // tree_print!( code ); +// +// // let mut a : syn::Generics = parse_quote! +// // { +// // < 'a, T > +// // }; +// // let mut b : syn::IntoGenericsArgs = parse_quote! +// // { +// // < (), Struct1, former::ReturnPreformed > +// // }; +// // let got = generics::merge( &a.into(), &b.into() ); +// // // let got = definition_extra_generics; +// +// // let mut _got : syn::Generics = parse_quote! +// // { +// // < Struct1, former::ReturnPreformed > +// // }; +// +// // let mut _got : syn::Generics = parse_quote! +// // { +// // < (), Struct1, former::ReturnPreformed > +// // }; +// +// } +// +// // +// +// #[ test ] +// fn into_generics_args_empty_generics() +// { +// use syn::{ Generics, IntoGenericsArgs }; +// +// let generics = Generics::default(); +// let exp = IntoGenericsArgs::default(); +// let got = generics.into_generics_args(); +// assert_eq!( exp, got, "Failed into_generics_args_empty_generics: expected {:?}, got {:?}", exp, got ); +// } +// +// // +// +// #[ test ] +// fn into_generics_args_single_type_parameter() +// { +// use syn::{ Generics, GenericParam, IntoGenericsArgs, GenericArgument, Type, TypePath, Ident }; +// +// let generics = Generics +// { +// params: vec![ GenericParam::Type( syn::TypeParam { ident: Ident::new( "T", proc_macro2::Span::call_site() ), ..Default::default() } ) ].into(), +// ..Default::default() +// }; +// let exp = IntoGenericsArgs +// { +// args: vec![ GenericArgument::Type( Type::Path( TypePath { qself: None, path: "T".into() } ) ) ], +// ..Default::default() +// }; +// let got = generics.into_generics_args(); +// assert_eq!( exp, got, "Failed into_generics_args_single_type_parameter: expected {:?}, got {:?}", exp, got ); +// } +// +// // +// +// #[ test ] +// fn into_generics_args_single_lifetime_parameter() +// { +// use syn::{ Generics, GenericParam, IntoGenericsArgs, GenericArgument, Lifetime }; +// +// let generics = Generics +// { +// params: vec![ GenericParam::Lifetime( syn::LifetimeDef { lifetime: Lifetime::new( "'a", proc_macro2::Span::call_site() ), ..Default::default() } ) ].into(), +// ..Default::default() +// }; +// let exp = IntoGenericsArgs +// { +// args: vec![ GenericArgument::Lifetime( Lifetime::new( "'a", proc_macro2::Span::call_site() ) ) ], +// ..Default::default() +// }; +// let got = generics.into_generics_args(); +// assert_eq!( exp, got, "Failed into_generics_args_single_lifetime_parameter: expected {:?}, got {:?}", exp, got ); +// } +// +// // +// +// #[ test ] +// fn into_generics_args_single_const_parameter() +// { +// use syn::{ Generics, GenericParam, IntoGenericsArgs, GenericArgument, Expr, ExprPath, Ident }; +// +// let generics = Generics +// { +// params: vec![ GenericParam::Const( syn::ConstParam { ident: Ident::new( "N", proc_macro2::Span::call_site() ), ..Default::default() } ) ].into(), +// ..Default::default() +// }; +// let exp = IntoGenericsArgs +// { +// args: vec![ GenericArgument::Const( Expr::Path( ExprPath { attrs: vec![], qself: None, path: "N".into() } ) ) ], +// ..Default::default() +// }; +// let got = generics.into_generics_args(); +// assert_eq!( exp, got, "Failed into_generics_args_single_const_parameter: expected {:?}, got {:?}", exp, got ); +// } +// +// // +// +// #[ test ] +// fn into_generics_args_mixed_parameters() +// { +// use syn::{ Generics, GenericParam, IntoGenericsArgs, GenericArgument, Type, TypePath, Lifetime, Expr, ExprPath, Ident }; +// +// let generics = Generics +// { +// params : vec! +// [ +// GenericParam::Type( syn::TypeParam { ident: Ident::new( "T", proc_macro2::Span::call_site() ), ..Default::default() } ), +// GenericParam::Lifetime( syn::LifetimeDef { lifetime: Lifetime::new( "'a", proc_macro2::Span::call_site() ), ..Default::default() } ), +// GenericParam::Const( syn::ConstParam { ident: Ident::new( "N", proc_macro2::Span::call_site() ), ..Default::default() } ) +// ].into(), +// ..Default::default() +// }; +// let exp = IntoGenericsArgs +// { +// args : vec! +// [ +// GenericArgument::Type( Type::Path( TypePath { qself: None, path: "T".into() } ) ), +// GenericArgument::Lifetime( Lifetime::new( "'a", proc_macro2::Span::call_site() ) ), +// GenericArgument::Const( Expr::Path( ExprPath { attrs: vec![], qself: None, path: "N".into() } ) ) +// ], +// ..Default::default() +// }; +// let got = generics.into_generics_args(); +// assert_eq!( exp, got, "Failed into_generics_args_mixed_parameters: expected {:?}, got {:?}", exp, got ); +// } diff --git a/module/core/macro_tools/tests/inc/mod.rs b/module/core/macro_tools/tests/inc/mod.rs index 223aa4b5b4..85edd86ef4 100644 --- a/module/core/macro_tools/tests/inc/mod.rs +++ b/module/core/macro_tools/tests/inc/mod.rs @@ -14,11 +14,11 @@ mod if_enabled use the_module::exposed::*; mod attr; - mod basic; - mod generic_args; - mod generic_params; - mod quantifier; - mod syntax; - mod tokens; + // mod basic; + // mod generic_args; + // mod generic_params; + // mod quantifier; + // mod syntax; + // mod tokens; } From 75d317426f223a707e014fd1a1863dbd5f121bcb Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 11:53:15 +0300 Subject: [PATCH 160/533] macro_tools : more functions to manipulate generics, small refactoring --- module/core/macro_tools/src/generic_params.rs | 2 +- module/core/macro_tools/src/lib.rs | 55 +++++++++---------- module/core/mod_interface_meta/src/lib.rs | 11 ++++ 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index 9d0535c0f8..3b5c36987f 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -325,7 +325,7 @@ pub mod orphan /// Exposed namespace of the module. pub mod exposed { - pub use super::protected as generics_params; + pub use super::protected as generic_params; #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super:: diff --git a/module/core/macro_tools/src/lib.rs b/module/core/macro_tools/src/lib.rs index 1fdfc6d07a..0094bc92a3 100644 --- a/module/core/macro_tools/src/lib.rs +++ b/module/core/macro_tools/src/lib.rs @@ -3,28 +3,24 @@ #![ doc( html_root_url = "https://docs.rs/proc_macro_tools/latest/proc_macro_tools/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] +/// Modular files. #[ cfg( feature = "enabled" ) ] -pub mod attr; -#[ cfg( feature = "enabled" ) ] -pub mod container_kind; -#[ cfg( feature = "enabled" ) ] -pub mod diag; -#[ cfg( feature = "enabled" ) ] -pub mod generic_analyze; -#[ cfg( feature = "enabled" ) ] -pub mod generic_args; -#[ cfg( feature = "enabled" ) ] -pub mod generic_params; -#[ cfg( feature = "enabled" ) ] -pub mod name; -#[ cfg( feature = "enabled" ) ] -pub mod quantifier; -#[ cfg( feature = "enabled" ) ] -pub mod tokens; -#[ cfg( feature = "enabled" ) ] -pub mod typ; -#[ cfg( feature = "enabled" ) ] -pub mod type_struct; +#[ path = "." ] +mod file +{ + use super::*; + pub mod attr; + pub mod container_kind; + pub mod diag; + pub mod generic_analyze; + pub mod generic_args; + pub mod generic_params; + pub mod name; + pub mod quantifier; + pub mod tokens; + pub mod typ; + pub mod type_struct; +} /// /// Dependencies of the module. @@ -37,7 +33,6 @@ pub mod dependency pub use ::quote; pub use ::proc_macro2; pub use ::interval_adapter; - // pub use ::type_constructor; } #[ doc( inline ) ] @@ -54,6 +49,10 @@ pub mod protected pub use super:: { orphan::*, + }; + + pub use super::file:: + { attr::orphan::*, container_kind::orphan::*, diag::orphan::*, @@ -94,6 +93,9 @@ pub mod exposed pub use super:: { prelude::*, + }; + pub use super::file:: + { attr::exposed::*, container_kind::exposed::*, diag::exposed::*, @@ -106,13 +108,6 @@ pub mod exposed typ::exposed::*, type_struct::exposed::*, }; - // #[ doc( inline ) ] - // #[ allow( unused_imports ) ] - // pub use super::quantifier:: - // { - // Pair, - // Many, - // }; } /// Prelude to use essentials: `use my_module::prelude::*`. @@ -161,7 +156,7 @@ pub mod prelude #[ doc( inline ) ] #[ allow( unused_imports ) ] - pub use super:: + pub use super::file:: { attr::prelude::*, container_kind::prelude::*, diff --git a/module/core/mod_interface_meta/src/lib.rs b/module/core/mod_interface_meta/src/lib.rs index c8e6d54d54..622fcd83d6 100644 --- a/module/core/mod_interface_meta/src/lib.rs +++ b/module/core/mod_interface_meta/src/lib.rs @@ -27,6 +27,17 @@ // xxx : make use proper_path_tools::protected::path working +// xxx : put modular files into a namespace `file` maybe +// #[ cfg( feature = "enabled" ) ] +// #[ path = "." ] +// mod file +// { +// use super::*; +// pub mod tokens; +// pub mod typ; +// pub mod type_struct; +// } + mod impls; #[ allow( unused_imports ) ] use impls::exposed::*; From e76ef6719d593e7e8b8ace16c9360b40ff839470 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 12:24:28 +0300 Subject: [PATCH 161/533] macro_tools : more functions to manipulate generics, small refactoring --- module/core/clone_dyn_meta/src/derive.rs | 10 +- module/core/former_meta/src/derive/former.rs | 20 +-- module/core/macro_tools/src/generic_args.rs | 2 +- module/core/macro_tools/src/generic_params.rs | 10 +- .../macro_tools/tests/inc/generic_args.rs | 170 +++++++++--------- .../macro_tools/tests/inc/generic_params.rs | 46 ++--- module/core/macro_tools/tests/inc/mod.rs | 12 +- 7 files changed, 139 insertions(+), 131 deletions(-) diff --git a/module/core/clone_dyn_meta/src/derive.rs b/module/core/clone_dyn_meta/src/derive.rs index 883d7b9bf6..023e852b39 100644 --- a/module/core/clone_dyn_meta/src/derive.rs +++ b/module/core/clone_dyn_meta/src/derive.rs @@ -16,7 +16,7 @@ pub fn clone_dyn( _attr : proc_macro::TokenStream, item : proc_macro::TokenStrea let name_ident = &item_parsed.ident; // let generics = &item_parsed.generics; let generics_analyzed = item_parsed.generics_analyze(); - let generics_params = &generics_analyzed.generics.params; + let generic_params = &generics_analyzed.generics.params; let generics_where = &generics_analyzed.generics.where_clause; let generics_names = &generics_analyzed.names; @@ -25,7 +25,7 @@ pub fn clone_dyn( _attr : proc_macro::TokenStream, item : proc_macro::TokenStrea #item_parsed #[ allow( non_local_definitions ) ] - impl < 'c, #generics_params > Clone + impl < 'c, #generic_params > Clone for Box< dyn #name_ident< #( #generics_names ),* > + 'c > // where #generics_where @@ -35,7 +35,7 @@ pub fn clone_dyn( _attr : proc_macro::TokenStream, item : proc_macro::TokenStrea } #[ allow( non_local_definitions ) ] - impl < 'c, #generics_params > Clone + impl < 'c, #generic_params > Clone for Box< dyn #name_ident< #( #generics_names ),* > + Send + 'c > // where #generics_where @@ -45,7 +45,7 @@ pub fn clone_dyn( _attr : proc_macro::TokenStream, item : proc_macro::TokenStrea } #[ allow( non_local_definitions ) ] - impl < 'c, #generics_params > Clone + impl < 'c, #generic_params > Clone for Box< dyn #name_ident< #( #generics_names ),* > + Sync + 'c > // where #generics_where @@ -55,7 +55,7 @@ pub fn clone_dyn( _attr : proc_macro::TokenStream, item : proc_macro::TokenStrea } #[ allow( non_local_definitions ) ] - impl < 'c, #generics_params > Clone + impl < 'c, #generic_params > Clone for Box< dyn #name_ident< #( #generics_names ),* > + Send + Sync + 'c > // where #generics_where diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 9120ce8a05..57c696265a 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1,7 +1,7 @@ use super::*; use iter_tools::{ Itertools, process_results }; -use macro_tools::{ attr, diag, generics, container_kind, typ, Result }; +use macro_tools::{ attr, diag, generic_params, generic_args, container_kind, typ, Result }; use proc_macro2::TokenStream; /// @@ -1077,9 +1077,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let generics = &ast.generics; let ( generics_impl, generics_ty, generics_where ) = generics.split_for_impl(); - // zzz : eliminate generics_params maybe - let _generics_params = generics::params_names( generics ).params; - let generics_params = if _generics_params.len() == 0 + // zzz : eliminate generic_params maybe + let _generics_params = generic_params::names( generics ).params; + let generic_params = if _generics_params.len() == 0 { qt!{} } @@ -1097,12 +1097,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // parameters for definition // let mut definition_extra_generics : macro_tools::GenericsWithWhere = parse_quote! - let mut definition_extra_generics : macro_tools::syn::AngleBracketedGenericArguments = parse_quote! + let definition_extra_generics : macro_tools::syn::AngleBracketedGenericArguments = parse_quote! { < (), #struct_name, former::ReturnPreformed > }; // xxx : uncomment - // let generics_of_definition = generics::merge( &generics, &definition_extra_generics.into() ); + // let generics_of_definition = generic_params::merge( &generics, &definition_extra_generics.into() ); let generics_of_definition = definition_extra_generics; // // xxx @@ -1112,14 +1112,14 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // } // parameters for former - let mut former_extra_generics : macro_tools::GenericsWithWhere = parse_quote! + let former_extra_generics : macro_tools::GenericsWithWhere = parse_quote! { < Definition = #former_definition #generics_of_definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, }; - let generics_of_former = generics::merge( &generics, &former_extra_generics.into() ); + let generics_of_former = generic_params::merge( &generics, &former_extra_generics.into() ); let ( generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generics_of_former.split_for_impl(); let generics_of_former_with_defaults = generics_of_former.params.clone(); @@ -1208,9 +1208,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// #[ inline( always ) ] - pub fn former() -> #former < #generics_params > + pub fn former() -> #former < #generic_params > { - #former :: < #generics_params > :: new( former::ReturnPreformed ) + #former :: < #generic_params > :: new( former::ReturnPreformed ) } } diff --git a/module/core/macro_tools/src/generic_args.rs b/module/core/macro_tools/src/generic_args.rs index 10881f8dc5..a18f210bcd 100644 --- a/module/core/macro_tools/src/generic_args.rs +++ b/module/core/macro_tools/src/generic_args.rs @@ -96,7 +96,7 @@ pub mod orphan /// Exposed namespace of the module. pub mod exposed { - pub use super::protected as generics_args; + pub use super::protected as generic_args; #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super:: diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index 3b5c36987f..b7b1699b6d 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -133,7 +133,7 @@ pub( crate ) mod private /// generics_a.where_clause = parse_quote!{ where T : Default }; /// let mut generics_b : syn::Generics = parse_quote!{ < V : std::fmt::Debug > }; /// generics_b.where_clause = parse_quote!{ where V : Sized }; - /// let got = generics::merge( &generics_a, &generics_b ); + /// let got = generic_params::merge( &generics_a, &generics_b ); /// /// let mut exp : syn::Generics = parse_quote! /// { @@ -211,7 +211,7 @@ pub( crate ) mod private // }; // // // zzz : write helper to fix bug with where -// let generics_of_former = generics::merge( &generics, &extra_generics ); +// let generics_of_former = generic_params::merge( &generics, &extra_generics ); /// Extracts parameter names from the given `Generics`, /// dropping bounds, defaults, and the where clause. @@ -236,13 +236,13 @@ pub( crate ) mod private /// let mut generics : syn::Generics = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > }; /// generics.where_clause = parse_quote!{ where T: std::fmt::Debug }; /// // let generics : Generics = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > where T: std::fmt::Debug }; - /// let simplified_generics = macro_tools::generic_params::params_names( &generics ); + /// let simplified_generics = macro_tools::generic_params::names( &generics ); /// /// assert_eq!( simplified_generics.params.len(), 4 ); // Contains T, U, 'a, and N /// assert!( simplified_generics.where_clause.is_none() ); // Where clause is removed /// ``` - pub fn params_names( generics : &syn::Generics ) -> syn::Generics + pub fn names( generics : &syn::Generics ) -> syn::Generics { // use syn::{ Generics, GenericParam, LifetimeDef, TypeParam, ConstParam }; use syn::{ Generics, GenericParam, LifetimeParam, TypeParam, ConstParam }; @@ -303,7 +303,7 @@ pub mod protected pub use super::private:: { merge, - params_names, + names, }; } diff --git a/module/core/macro_tools/tests/inc/generic_args.rs b/module/core/macro_tools/tests/inc/generic_args.rs index 50a22208ed..7948bb6dbd 100644 --- a/module/core/macro_tools/tests/inc/generic_args.rs +++ b/module/core/macro_tools/tests/inc/generic_args.rs @@ -1,92 +1,100 @@ -// -// use super::*; -// -// // -// -// #[ test ] -// fn assumptions() -// { -// -// // let code : syn::ItemStruct = syn::parse_quote! -// // { -// // pub struct Struct1Former -// // < -// // Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, -// // > -// // {} -// // }; -// // tree_print!( code ); -// -// // let mut a : syn::Generics = parse_quote! -// // { -// // < 'a, T > -// // }; -// // let mut b : syn::IntoGenericsArgs = parse_quote! -// // { -// // < (), Struct1, former::ReturnPreformed > -// // }; -// // let got = generics::merge( &a.into(), &b.into() ); -// // // let got = definition_extra_generics; -// -// // let mut _got : syn::Generics = parse_quote! -// // { -// // < Struct1, former::ReturnPreformed > -// // }; -// -// // let mut _got : syn::Generics = parse_quote! -// // { -// // < (), Struct1, former::ReturnPreformed > -// // }; -// -// } -// -// // -// -// #[ test ] -// fn into_generics_args_empty_generics() -// { -// use syn::{ Generics, IntoGenericsArgs }; -// -// let generics = Generics::default(); -// let exp = IntoGenericsArgs::default(); -// let got = generics.into_generics_args(); -// assert_eq!( exp, got, "Failed into_generics_args_empty_generics: expected {:?}, got {:?}", exp, got ); -// } -// -// // -// + +use super::*; + +// + +#[ test ] +fn assumptions() +{ + + // let code : syn::ItemStruct = syn::parse_quote! + // { + // pub struct Struct1Former + // < + // Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, + // > + // {} + // }; + // tree_print!( code ); + + // let mut a : syn::Generics = parse_quote! + // { + // < 'a, T > + // }; + // let mut b : syn::IntoGenericsArgs = parse_quote! + // { + // < (), Struct1, former::ReturnPreformed > + // }; + // let got = generic_params::merge( &a.into(), &b.into() ); + // // let got = definition_extra_generics; + + // let mut _got : syn::Generics = parse_quote! + // { + // < Struct1, former::ReturnPreformed > + // }; + + // let mut _got : syn::Generics = parse_quote! + // { + // < (), Struct1, former::ReturnPreformed > + // }; + +} + +// + +#[ test ] +fn into_generics_args_empty_generics() +{ + use syn::{ Generics, AngleBracketedGenericArguments, token }; + use macro_tools::IntoGenericsArgs; + use proc_macro2::Span; + + let generics = Generics::default(); + let exp = AngleBracketedGenericArguments + { + colon2_token: None, + lt_token: token::Lt::default(), + args: syn::punctuated::Punctuated::new(), + gt_token: token::Gt::default(), + }; + let got = generics.into_generics_args(); + assert_eq!( exp, got, "Failed into_generics_args_empty_generics: expected {:?}, got {:?}", exp, got ); +} + +// + // #[ test ] // fn into_generics_args_single_type_parameter() // { -// use syn::{ Generics, GenericParam, IntoGenericsArgs, GenericArgument, Type, TypePath, Ident }; +// use syn::{ Generics, GenericParam, TypeParam, AngleBracketedGenericArguments, GenericArgument, Type, TypePath, Ident }; +// use macro_tools::IntoGenericsArgs; // // let generics = Generics // { -// params: vec![ GenericParam::Type( syn::TypeParam { ident: Ident::new( "T", proc_macro2::Span::call_site() ), ..Default::default() } ) ].into(), +// params : Some( GenericParam::Type( TypeParam { ident: Ident::new( "T", proc_macro2::Span::call_site() ) } ) ).into_iter().collect(), // ..Default::default() // }; -// let exp = IntoGenericsArgs +// let exp = AngleBracketedGenericArguments // { -// args: vec![ GenericArgument::Type( Type::Path( TypePath { qself: None, path: "T".into() } ) ) ], +// args : vec![ GenericArgument::Type( Type::Path( TypePath { qself: None, path: Ident::new( "T", proc_macro2::Span::call_site() ).into() } ) ) ], // ..Default::default() // }; // let got = generics.into_generics_args(); // assert_eq!( exp, got, "Failed into_generics_args_single_type_parameter: expected {:?}, got {:?}", exp, got ); // } // -// // -// // #[ test ] // fn into_generics_args_single_lifetime_parameter() // { -// use syn::{ Generics, GenericParam, IntoGenericsArgs, GenericArgument, Lifetime }; +// use syn::{ Generics, GenericParam, LifetimeDef, Lifetime, AngleBracketedGenericArguments, GenericArgument }; +// use macro_tools::IntoGenericsArgs; // // let generics = Generics // { -// params: vec![ GenericParam::Lifetime( syn::LifetimeDef { lifetime: Lifetime::new( "'a", proc_macro2::Span::call_site() ), ..Default::default() } ) ].into(), +// params: Some( GenericParam::Lifetime( LifetimeDef { lifetime: Lifetime::new( "'a", proc_macro2::Span::call_site() ) } ) ).into_iter().collect(), // ..Default::default() // }; -// let exp = IntoGenericsArgs +// let exp = AngleBracketedGenericArguments // { // args: vec![ GenericArgument::Lifetime( Lifetime::new( "'a", proc_macro2::Span::call_site() ) ) ], // ..Default::default() @@ -95,51 +103,49 @@ // assert_eq!( exp, got, "Failed into_generics_args_single_lifetime_parameter: expected {:?}, got {:?}", exp, got ); // } // -// // -// // #[ test ] // fn into_generics_args_single_const_parameter() // { -// use syn::{ Generics, GenericParam, IntoGenericsArgs, GenericArgument, Expr, ExprPath, Ident }; +// use syn::{ Generics, GenericParam, ConstParam, AngleBracketedGenericArguments, GenericArgument, Expr, ExprPath, Ident }; +// use macro_tools::IntoGenericsArgs; // // let generics = Generics // { -// params: vec![ GenericParam::Const( syn::ConstParam { ident: Ident::new( "N", proc_macro2::Span::call_site() ), ..Default::default() } ) ].into(), +// params: Some( GenericParam::Const( ConstParam { ident: Ident::new( "N", proc_macro2::Span::call_site() ) } ) ).into_iter().collect(), // ..Default::default() // }; -// let exp = IntoGenericsArgs +// let exp = AngleBracketedGenericArguments // { -// args: vec![ GenericArgument::Const( Expr::Path( ExprPath { attrs: vec![], qself: None, path: "N".into() } ) ) ], +// args: vec![ GenericArgument::Const( Expr::Path( ExprPath { attrs: vec![], qself: None, path: Ident::new( "N", proc_macro2::Span::call_site() ).into() } ) ) ], // ..Default::default() // }; // let got = generics.into_generics_args(); // assert_eq!( exp, got, "Failed into_generics_args_single_const_parameter: expected {:?}, got {:?}", exp, got ); // } // -// // -// // #[ test ] // fn into_generics_args_mixed_parameters() // { -// use syn::{ Generics, GenericParam, IntoGenericsArgs, GenericArgument, Type, TypePath, Lifetime, Expr, ExprPath, Ident }; +// use syn::{ Generics, GenericParam, TypeParam, LifetimeDef, Lifetime, ConstParam, AngleBracketedGenericArguments, GenericArgument, Type, TypePath, Expr, ExprPath, Ident }; +// use macro_tools::IntoGenericsArgs; // // let generics = Generics // { // params : vec! // [ -// GenericParam::Type( syn::TypeParam { ident: Ident::new( "T", proc_macro2::Span::call_site() ), ..Default::default() } ), -// GenericParam::Lifetime( syn::LifetimeDef { lifetime: Lifetime::new( "'a", proc_macro2::Span::call_site() ), ..Default::default() } ), -// GenericParam::Const( syn::ConstParam { ident: Ident::new( "N", proc_macro2::Span::call_site() ), ..Default::default() } ) -// ].into(), +// GenericParam::Type( TypeParam { ident: Ident::new( "T", proc_macro2::Span::call_site() ) } ), +// GenericParam::Lifetime( LifetimeDef { lifetime: Lifetime::new( "'a", proc_macro2::Span::call_site() ) } ), +// GenericParam::Const( ConstParam { ident: Ident::new( "N", proc_macro2::Span::call_site() ) } ) +// ].into_iter().collect(), // ..Default::default() // }; -// let exp = IntoGenericsArgs +// let exp = AngleBracketedGenericArguments // { // args : vec! // [ -// GenericArgument::Type( Type::Path( TypePath { qself: None, path: "T".into() } ) ), +// GenericArgument::Type( Type::Path( TypePath { qself: None, path: Ident::new( "T", proc_macro2::Span::call_site() ).into() } ) ), // GenericArgument::Lifetime( Lifetime::new( "'a", proc_macro2::Span::call_site() ) ), -// GenericArgument::Const( Expr::Path( ExprPath { attrs: vec![], qself: None, path: "N".into() } ) ) +// GenericArgument::Const( Expr::Path( ExprPath { attrs: vec![], qself: None, path: Ident::new( "N", proc_macro2::Span::call_site() ).into() } ) ) // ], // ..Default::default() // }; diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index 3933448155..2f691ecb4e 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -4,24 +4,25 @@ use super::*; // #[ test ] -fn assumptions() +fn generics_with_where() { - let mut generics_a : syn::Generics = parse_quote!{ < T : Clone, U : Default > }; - generics_a.where_clause = parse_quote!{ where T : Default }; - let mut generics_b : syn::Generics = parse_quote!{ < V : std::fmt::Debug > }; - generics_b.where_clause = parse_quote!{ where V : Sized }; - let got = generics::merge( &generics_a, &generics_b ); + let got : the_module::GenericsWithWhere = parse_quote! + { + < 'a, T : Clone, U : Default, V : std::fmt::Debug > + where + Definition : former::FormerDefinition, + }; + let got = got.unwrap(); let mut exp : syn::Generics = parse_quote! { - < T : Clone, U : Default, V : std::fmt::Debug > + < 'a, T : Clone, U : Default, V : std::fmt::Debug > }; exp.where_clause = parse_quote! { where - T : Default, - V : Sized + Definition : former::FormerDefinition, }; // a_id!( tree_print!( got ), tree_print!( exp ) ); @@ -39,25 +40,25 @@ fn assumptions() // #[ test ] -fn generics_with_where() +fn merge_assumptions() { + use the_module::generic_params; - let got : the_module::GenericsWithWhere = parse_quote! - { - < 'a, T : Clone, U : Default, V : std::fmt::Debug > - where - Definition : former::FormerDefinition, - }; - let got = got.unwrap(); + let mut generics_a : syn::Generics = parse_quote!{ < T : Clone, U : Default > }; + generics_a.where_clause = parse_quote!{ where T : Default }; + let mut generics_b : syn::Generics = parse_quote!{ < V : std::fmt::Debug > }; + generics_b.where_clause = parse_quote!{ where V : Sized }; + let got = generic_params::merge( &generics_a, &generics_b ); let mut exp : syn::Generics = parse_quote! { - < 'a, T : Clone, U : Default, V : std::fmt::Debug > + < T : Clone, U : Default, V : std::fmt::Debug > }; exp.where_clause = parse_quote! { where - Definition : former::FormerDefinition, + T : Default, + V : Sized }; // a_id!( tree_print!( got ), tree_print!( exp ) ); @@ -77,12 +78,13 @@ fn generics_with_where() #[ test ] fn merge_defaults() { + use the_module::generic_params; let mut generics_a : syn::Generics = parse_quote!{ < T : Clone, U : Default = Default1 > }; generics_a.where_clause = parse_quote!{ where T : Default }; let mut generics_b : syn::Generics = parse_quote!{ < V : std::fmt::Debug = Debug1 > }; generics_b.where_clause = parse_quote!{ where V : Sized }; - let got = generics::merge( &generics_a, &generics_b ); + let got = generic_params::merge( &generics_a, &generics_b ); let mut exp : syn::Generics = parse_quote! { @@ -110,7 +112,7 @@ fn merge_defaults() // #[ test ] -fn params_names() +fn names() { use macro_tools::syn::parse_quote; @@ -118,7 +120,7 @@ fn params_names() let mut generics : syn::Generics = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > }; generics.where_clause = parse_quote!{ where T: std::fmt::Debug }; // let generics : Generics = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > where T: std::fmt::Debug }; - let simplified_generics = macro_tools::generics::params_names( &generics ); + let simplified_generics = macro_tools::generic_params::names( &generics ); assert_eq!( simplified_generics.params.len(), 4 ); // Contains T, U, 'a, and N assert!( simplified_generics.where_clause.is_none() ); // Where clause is removed diff --git a/module/core/macro_tools/tests/inc/mod.rs b/module/core/macro_tools/tests/inc/mod.rs index 85edd86ef4..223aa4b5b4 100644 --- a/module/core/macro_tools/tests/inc/mod.rs +++ b/module/core/macro_tools/tests/inc/mod.rs @@ -14,11 +14,11 @@ mod if_enabled use the_module::exposed::*; mod attr; - // mod basic; - // mod generic_args; - // mod generic_params; - // mod quantifier; - // mod syntax; - // mod tokens; + mod basic; + mod generic_args; + mod generic_params; + mod quantifier; + mod syntax; + mod tokens; } From b52ee767152090c64eb9ccc12a3f64a818444cdb Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 15:03:59 +0300 Subject: [PATCH 162/533] macro_tools : more functions to manipulate generics, small refactoring --- module/core/macro_tools/src/generic_args.rs | 10 +- .../macro_tools/tests/inc/generic_args.rs | 302 ++++++++++++------ 2 files changed, 214 insertions(+), 98 deletions(-) diff --git a/module/core/macro_tools/src/generic_args.rs b/module/core/macro_tools/src/generic_args.rs index a18f210bcd..55e5756c89 100644 --- a/module/core/macro_tools/src/generic_args.rs +++ b/module/core/macro_tools/src/generic_args.rs @@ -12,7 +12,7 @@ pub( crate ) mod private /// such as `syn::Generics`, into a uniform `syn::AngleBracketedGenericArguments`. This is particularly /// useful when working with Rust syntax trees in procedural macros, allowing for the manipulation /// and merging of generic parameters from different syntactic elements. - pub trait IntoGenericsArgs + pub trait IntoGenericArgs { /// Converts a reference of the implementing type into `syn::AngleBracketedGenericArguments`. /// @@ -24,12 +24,12 @@ pub( crate ) mod private /// # Returns /// A new instance of `syn::AngleBracketedGenericArguments` representing the generic parameters /// of the original type. - fn into_generics_args( &self ) -> syn::AngleBracketedGenericArguments; + fn into_generic_args( &self ) -> syn::AngleBracketedGenericArguments; } - impl IntoGenericsArgs for syn::Generics + impl IntoGenericArgs for syn::Generics { - fn into_generics_args( &self ) -> syn::AngleBracketedGenericArguments + fn into_generic_args( &self ) -> syn::AngleBracketedGenericArguments { let args = self.params.iter().map( | param | { @@ -89,7 +89,7 @@ pub mod orphan #[ allow( unused_imports ) ] pub use super::private:: { - IntoGenericsArgs, + IntoGenericArgs, }; } diff --git a/module/core/macro_tools/tests/inc/generic_args.rs b/module/core/macro_tools/tests/inc/generic_args.rs index 7948bb6dbd..e357b51d8e 100644 --- a/module/core/macro_tools/tests/inc/generic_args.rs +++ b/module/core/macro_tools/tests/inc/generic_args.rs @@ -21,7 +21,7 @@ fn assumptions() // { // < 'a, T > // }; - // let mut b : syn::IntoGenericsArgs = parse_quote! + // let mut b : syn::IntoGenericArgs = parse_quote! // { // < (), Struct1, former::ReturnPreformed > // }; @@ -43,13 +43,14 @@ fn assumptions() // #[ test ] -fn into_generics_args_empty_generics() +fn into_generic_args_empty_generics() { use syn::{ Generics, AngleBracketedGenericArguments, token }; - use macro_tools::IntoGenericsArgs; + use macro_tools::IntoGenericArgs; use proc_macro2::Span; let generics = Generics::default(); + let got = generics.into_generic_args(); let exp = AngleBracketedGenericArguments { colon2_token: None, @@ -57,98 +58,213 @@ fn into_generics_args_empty_generics() args: syn::punctuated::Punctuated::new(), gt_token: token::Gt::default(), }; - let got = generics.into_generics_args(); - assert_eq!( exp, got, "Failed into_generics_args_empty_generics: expected {:?}, got {:?}", exp, got ); + assert_eq!( exp, got, "Failed into_generic_args_empty_generics: expected {:?}, got {:?}", exp, got ); } // -// #[ test ] -// fn into_generics_args_single_type_parameter() -// { -// use syn::{ Generics, GenericParam, TypeParam, AngleBracketedGenericArguments, GenericArgument, Type, TypePath, Ident }; -// use macro_tools::IntoGenericsArgs; -// -// let generics = Generics -// { -// params : Some( GenericParam::Type( TypeParam { ident: Ident::new( "T", proc_macro2::Span::call_site() ) } ) ).into_iter().collect(), -// ..Default::default() -// }; -// let exp = AngleBracketedGenericArguments -// { -// args : vec![ GenericArgument::Type( Type::Path( TypePath { qself: None, path: Ident::new( "T", proc_macro2::Span::call_site() ).into() } ) ) ], -// ..Default::default() -// }; -// let got = generics.into_generics_args(); -// assert_eq!( exp, got, "Failed into_generics_args_single_type_parameter: expected {:?}, got {:?}", exp, got ); -// } -// -// #[ test ] -// fn into_generics_args_single_lifetime_parameter() -// { -// use syn::{ Generics, GenericParam, LifetimeDef, Lifetime, AngleBracketedGenericArguments, GenericArgument }; -// use macro_tools::IntoGenericsArgs; -// -// let generics = Generics -// { -// params: Some( GenericParam::Lifetime( LifetimeDef { lifetime: Lifetime::new( "'a", proc_macro2::Span::call_site() ) } ) ).into_iter().collect(), -// ..Default::default() -// }; -// let exp = AngleBracketedGenericArguments -// { -// args: vec![ GenericArgument::Lifetime( Lifetime::new( "'a", proc_macro2::Span::call_site() ) ) ], -// ..Default::default() -// }; -// let got = generics.into_generics_args(); -// assert_eq!( exp, got, "Failed into_generics_args_single_lifetime_parameter: expected {:?}, got {:?}", exp, got ); -// } -// -// #[ test ] -// fn into_generics_args_single_const_parameter() -// { -// use syn::{ Generics, GenericParam, ConstParam, AngleBracketedGenericArguments, GenericArgument, Expr, ExprPath, Ident }; -// use macro_tools::IntoGenericsArgs; -// -// let generics = Generics -// { -// params: Some( GenericParam::Const( ConstParam { ident: Ident::new( "N", proc_macro2::Span::call_site() ) } ) ).into_iter().collect(), -// ..Default::default() -// }; -// let exp = AngleBracketedGenericArguments -// { -// args: vec![ GenericArgument::Const( Expr::Path( ExprPath { attrs: vec![], qself: None, path: Ident::new( "N", proc_macro2::Span::call_site() ).into() } ) ) ], -// ..Default::default() -// }; -// let got = generics.into_generics_args(); -// assert_eq!( exp, got, "Failed into_generics_args_single_const_parameter: expected {:?}, got {:?}", exp, got ); -// } -// -// #[ test ] -// fn into_generics_args_mixed_parameters() -// { -// use syn::{ Generics, GenericParam, TypeParam, LifetimeDef, Lifetime, ConstParam, AngleBracketedGenericArguments, GenericArgument, Type, TypePath, Expr, ExprPath, Ident }; -// use macro_tools::IntoGenericsArgs; +#[ test ] +fn into_generic_args_single_type_parameter() +{ + use macro_tools::IntoGenericArgs; + use syn:: + { + Generics, + GenericParam, + TypeParam, + AngleBracketedGenericArguments, + GenericArgument, + Type, + TypePath, + Ident, + token, + punctuated::Punctuated, + }; + + let mut args = Punctuated::new(); + args.push(GenericArgument::Type(Type::Path(TypePath { + qself: None, + path: Ident::new("T", proc_macro2::Span::call_site()).into(), + }))); + + let generics = Generics + { + params: Some(GenericParam::Type(TypeParam { + attrs: Vec::new(), + ident: Ident::new("T", proc_macro2::Span::call_site()), + colon_token: None, + bounds: Punctuated::new(), + eq_token: None, + default: None, + })).into_iter().collect(), + ..Default::default() + }; + + let exp = AngleBracketedGenericArguments + { + colon2_token: None, + lt_token: token::Lt::default(), + args, + gt_token: token::Gt::default(), + }; + + let got = generics.into_generic_args(); + assert_eq!(exp, got, "Failed into_generic_args_single_type_parameter: expected {:?}, got {:?}", exp, got); +} + +#[ test ] +fn into_generic_args_single_lifetime_parameter() +{ + use syn:: + { + Generics, + GenericParam, + LifetimeParam, + Lifetime, + AngleBracketedGenericArguments, + GenericArgument, + token, + punctuated::Punctuated, + }; + use macro_tools::IntoGenericArgs; // Correct trait name if necessary + + let mut args = Punctuated::new(); + args.push( GenericArgument::Lifetime( Lifetime::new( "'a", proc_macro2::Span::call_site() ))); + + let generics = Generics + { + params: Some( GenericParam::Lifetime( LifetimeParam + { + attrs: Vec::new(), + lifetime: Lifetime::new( "'a", proc_macro2::Span::call_site() ), + colon_token: None, + bounds: Punctuated::new(), + })).into_iter().collect(), + ..Default::default() + }; + + let exp = AngleBracketedGenericArguments + { + colon2_token: None, + lt_token: token::Lt::default(), + args, + gt_token: token::Gt::default(), + }; + + let got = generics.into_generic_args(); // Ensure the method name is correct + assert_eq!( exp, got, "Failed into_generic_args_single_lifetime_parameter: expected {:?}, got {:?}", exp, got ); +} + +#[ test ] +fn into_generic_args_single_const_parameter() +{ + use syn:: + { + Generics, + AngleBracketedGenericArguments, + GenericArgument, + Expr, + ExprPath, + Ident, + token::{ self, Lt, Gt }, + punctuated::Punctuated + }; + use macro_tools::IntoGenericArgs; + + // Use parse_quote to create the generic parameters + let generics : Generics = parse_quote! + { + < const N: usize > + }; + + let got = generics.into_generic_args(); + + // Manually construct the expected value + let mut args = Punctuated::new(); + args.push_value( GenericArgument::Const( Expr::Path( ExprPath + { + attrs: vec![], + qself: None, + path: syn::Path::from( Ident::new( "N", proc_macro2::Span::call_site() )), + }))); + + let exp = AngleBracketedGenericArguments + { + colon2_token: None, + lt_token: Lt::default(), + args, + gt_token: Gt::default(), + }; + + // Debug prints for better traceability in case of failure + println!( "Expected: {:?}", exp ); + println!( "Got: {:?}", got ); + + assert_eq!( exp, got, "Failed into_generic_args_single_const_parameter: expected {:?}, got {:?}", exp, got ); +} + + // -// let generics = Generics -// { -// params : vec! -// [ -// GenericParam::Type( TypeParam { ident: Ident::new( "T", proc_macro2::Span::call_site() ) } ), -// GenericParam::Lifetime( LifetimeDef { lifetime: Lifetime::new( "'a", proc_macro2::Span::call_site() ) } ), -// GenericParam::Const( ConstParam { ident: Ident::new( "N", proc_macro2::Span::call_site() ) } ) -// ].into_iter().collect(), -// ..Default::default() -// }; -// let exp = AngleBracketedGenericArguments -// { -// args : vec! -// [ -// GenericArgument::Type( Type::Path( TypePath { qself: None, path: Ident::new( "T", proc_macro2::Span::call_site() ).into() } ) ), -// GenericArgument::Lifetime( Lifetime::new( "'a", proc_macro2::Span::call_site() ) ), -// GenericArgument::Const( Expr::Path( ExprPath { attrs: vec![], qself: None, path: Ident::new( "N", proc_macro2::Span::call_site() ).into() } ) ) -// ], -// ..Default::default() -// }; -// let got = generics.into_generics_args(); -// assert_eq!( exp, got, "Failed into_generics_args_mixed_parameters: expected {:?}, got {:?}", exp, got ); -// } + +#[ test ] +fn into_generic_args_mixed_parameters() +{ + use syn:: + { + Generics, + AngleBracketedGenericArguments, + GenericArgument, + Type, + TypePath, + Expr, + ExprPath, + Ident, + Lifetime, + token::{ self, Comma }, + punctuated::Punctuated, + parse_quote + }; + use macro_tools::IntoGenericArgs; + + // Generate the actual value using the implementation + let generics : Generics = parse_quote! + { + + }; + let got = generics.into_generic_args(); + + // Manually construct the expected value + let mut args = Punctuated::new(); + let t_type : GenericArgument = GenericArgument::Type( Type::Path( TypePath + { + qself: None, + path: Ident::new( "T", proc_macro2::Span::call_site() ).into(), + })); + args.push_value( t_type ); + args.push_punct( Comma::default() ); + + let a_lifetime = GenericArgument::Lifetime( Lifetime::new( "'a", proc_macro2::Span::call_site() )); + args.push_value( a_lifetime ); + args.push_punct( Comma::default() ); + + let n_const : GenericArgument = GenericArgument::Const( Expr::Path( ExprPath + { + attrs: vec![], + qself: None, + path: Ident::new( "N", proc_macro2::Span::call_site() ).into(), + })); + args.push_value( n_const ); + + let exp = AngleBracketedGenericArguments + { + colon2_token: None, + lt_token: token::Lt::default(), + args, + gt_token: token::Gt::default(), + }; + + // tree_print!( got ); + // tree_print!( exp ); + // a_id!(tree_diagnostics_str!( exp ), tree_diagnostics_str!( got ) ); + a_id!( exp, got, "Failed into_generic_args_mixed_parameters: expected {:?}, got {:?}", exp, got ); +} From d3b74455f082b899dea6377a12b108f403d17b37 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 15:05:30 +0300 Subject: [PATCH 163/533] macro_tools : more functions to manipulate generics, small refactoring --- .../macro_tools/tests/inc/generic_args.rs | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/module/core/macro_tools/tests/inc/generic_args.rs b/module/core/macro_tools/tests/inc/generic_args.rs index e357b51d8e..0bef13c083 100644 --- a/module/core/macro_tools/tests/inc/generic_args.rs +++ b/module/core/macro_tools/tests/inc/generic_args.rs @@ -118,40 +118,33 @@ fn into_generic_args_single_lifetime_parameter() use syn:: { Generics, - GenericParam, - LifetimeParam, - Lifetime, AngleBracketedGenericArguments, GenericArgument, - token, - punctuated::Punctuated, + parse_quote, + punctuated::Punctuated }; - use macro_tools::IntoGenericArgs; // Correct trait name if necessary - - let mut args = Punctuated::new(); - args.push( GenericArgument::Lifetime( Lifetime::new( "'a", proc_macro2::Span::call_site() ))); + use macro_tools::IntoGenericArgs; - let generics = Generics + // Generate the generics using parse_quote to include a lifetime parameter + let generics : Generics = parse_quote! { - params: Some( GenericParam::Lifetime( LifetimeParam - { - attrs: Vec::new(), - lifetime: Lifetime::new( "'a", proc_macro2::Span::call_site() ), - colon_token: None, - bounds: Punctuated::new(), - })).into_iter().collect(), - ..Default::default() + < 'a > }; - let exp = AngleBracketedGenericArguments + // Create the expected AngleBracketedGenericArguments using parse_quote + let exp : AngleBracketedGenericArguments = parse_quote! { - colon2_token: None, - lt_token: token::Lt::default(), - args, - gt_token: token::Gt::default(), + < 'a > }; - let got = generics.into_generic_args(); // Ensure the method name is correct + // Use the implementation to generate the actual output + let got = generics.into_generic_args(); + + // Debug prints for better traceability in case of failure + println!( "Expected: {:?}", exp ); + println!( "Got: {:?}", got ); + + // Assert to check if the expected matches the got assert_eq!( exp, got, "Failed into_generic_args_single_lifetime_parameter: expected {:?}, got {:?}", exp, got ); } From e942276ddc3641b725d655ac460458c16f5d2ac7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 15:08:48 +0300 Subject: [PATCH 164/533] macro_tools : more functions to manipulate generics, small refactoring --- .../macro_tools/tests/inc/generic_args.rs | 43 +++++-------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/module/core/macro_tools/tests/inc/generic_args.rs b/module/core/macro_tools/tests/inc/generic_args.rs index 0bef13c083..81b3bef786 100644 --- a/module/core/macro_tools/tests/inc/generic_args.rs +++ b/module/core/macro_tools/tests/inc/generic_args.rs @@ -62,56 +62,35 @@ fn into_generic_args_empty_generics() } // - #[ test ] fn into_generic_args_single_type_parameter() { - use macro_tools::IntoGenericArgs; use syn:: { Generics, - GenericParam, - TypeParam, AngleBracketedGenericArguments, - GenericArgument, - Type, - TypePath, - Ident, - token, - punctuated::Punctuated, + parse_quote }; + use macro_tools::IntoGenericArgs; - let mut args = Punctuated::new(); - args.push(GenericArgument::Type(Type::Path(TypePath { - qself: None, - path: Ident::new("T", proc_macro2::Span::call_site()).into(), - }))); - - let generics = Generics + // Generate the generics with a single type parameter using parse_quote + let generics : Generics = parse_quote! { - params: Some(GenericParam::Type(TypeParam { - attrs: Vec::new(), - ident: Ident::new("T", proc_macro2::Span::call_site()), - colon_token: None, - bounds: Punctuated::new(), - eq_token: None, - default: None, - })).into_iter().collect(), - ..Default::default() + < T > }; - let exp = AngleBracketedGenericArguments + // Create the expected AngleBracketedGenericArguments using parse_quote + let exp : AngleBracketedGenericArguments = parse_quote! { - colon2_token: None, - lt_token: token::Lt::default(), - args, - gt_token: token::Gt::default(), + < T > }; let got = generics.into_generic_args(); - assert_eq!(exp, got, "Failed into_generic_args_single_type_parameter: expected {:?}, got {:?}", exp, got); + assert_eq!( exp, got, "Failed into_generic_args_single_type_parameter: expected {:?}, got {:?}", exp, got ); } +/// + #[ test ] fn into_generic_args_single_lifetime_parameter() { From 8c350a72ec58788dbfcdb43eaf284380fb4e96eb Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 15:24:51 +0300 Subject: [PATCH 165/533] macro_tools : more functions to manipulate generics, small refactoring --- module/core/macro_tools/src/generic_args.rs | 52 +++++++++++++++++++ module/core/macro_tools/src/generic_params.rs | 5 -- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/module/core/macro_tools/src/generic_args.rs b/module/core/macro_tools/src/generic_args.rs index 55e5756c89..7f1e7e747a 100644 --- a/module/core/macro_tools/src/generic_args.rs +++ b/module/core/macro_tools/src/generic_args.rs @@ -60,6 +60,57 @@ pub( crate ) mod private } } + /// Merges two `syn::AngleBracketedGenericArguments` instances into a new one. + /// + /// This function takes two references to `syn::AngleBracketedGenericArguments` and combines + /// their arguments into a single `syn::AngleBracketedGenericArguments` instance. + /// + /// # Arguments + /// + /// * `a` - A reference to the first `syn::AngleBracketedGenericArguments` instance. + /// * `b` - A reference to the second `syn::AngleBracketedGenericArguments` instance. + /// + /// # Returns + /// + /// Returns a new `syn::AngleBracketedGenericArguments` instance containing the combined + /// arguments from both `a` and `b`. + /// + /// # Examples + /// + /// ``` + /// use macro_tools:: + /// { + /// generic_args, + /// syn::{ parse_quote, AngleBracketedGenericArguments }, + /// }; + /// + /// let a : AngleBracketedGenericArguments = parse_quote!{ }; + /// let b : AngleBracketedGenericArguments = parse_quote!{ }; + /// let merged = generic_args::merge( &a, &b ); + /// + /// let expected : AngleBracketedGenericArguments = parse_quote!{ < T: Clone, U: Default, V: std::fmt::Debug > }; + /// assert_eq!( merged, expected ); + /// ``` + pub fn merge + ( + a : &syn::AngleBracketedGenericArguments, + b : &syn::AngleBracketedGenericArguments + ) -> syn::AngleBracketedGenericArguments + { + let mut args = syn::punctuated::Punctuated::new(); + + args.extend( a.args.iter().cloned() ); + args.extend( b.args.iter().cloned() ); + + syn::AngleBracketedGenericArguments + { + colon2_token: None, + lt_token: syn::token::Lt::default(), + args, + gt_token: syn::token::Gt::default(), + } + } + } #[ doc( inline ) ] @@ -76,6 +127,7 @@ pub mod protected #[ allow( unused_imports ) ] pub use super::private:: { + merge, }; } diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index b7b1699b6d..eed5322341 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -102,11 +102,6 @@ pub( crate ) mod private } } -// pub fn make< IntoTokens : Into< proc_macro2::TokenStream > >( input : IntoTokens ) -// { -// -// } - /// Merges two `syn::Generics` instances into a new one. /// /// This function takes two references to `syn::Generics` and combines their From bb2e8cf2008844120b4729238f3c8b206acc9fd2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 15:58:11 +0300 Subject: [PATCH 166/533] macro_tools : more functions to manipulate generics, small refactoring --- module/core/former_meta/src/derive/former.rs | 4 +- module/core/macro_tools/src/generic_args.rs | 65 ++++++--- .../macro_tools/tests/inc/generic_args.rs | 136 ++++++++++++++++-- 3 files changed, 173 insertions(+), 32 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 57c696265a..3747f33bf3 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1102,8 +1102,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > < (), #struct_name, former::ReturnPreformed > }; // xxx : uncomment - // let generics_of_definition = generic_params::merge( &generics, &definition_extra_generics.into() ); - let generics_of_definition = definition_extra_generics; + let generics_of_definition = generic_args::merge( &generics.into_into_generic_args(), &definition_extra_generics.into() ); + // let generics_of_definition = definition_extra_generics; // // xxx // if has_debug diff --git a/module/core/macro_tools/src/generic_args.rs b/module/core/macro_tools/src/generic_args.rs index 7f1e7e747a..4c41e8d33e 100644 --- a/module/core/macro_tools/src/generic_args.rs +++ b/module/core/macro_tools/src/generic_args.rs @@ -60,51 +60,78 @@ pub( crate ) mod private } } - /// Merges two `syn::AngleBracketedGenericArguments` instances into a new one. + /// Merges two `syn::AngleBracketedGenericArguments` instances into a new one, + /// prioritizing lifetime parameters before other types of generic arguments. /// - /// This function takes two references to `syn::AngleBracketedGenericArguments` and combines - /// their arguments into a single `syn::AngleBracketedGenericArguments` instance. + /// This function takes two references to `syn::AngleBracketedGenericArguments` and + /// categorizes their arguments into lifetimes and other types. It then combines + /// them such that all lifetimes from both instances precede any other arguments in the + /// resulting `syn::AngleBracketedGenericArguments` instance. This is particularly useful + /// for ensuring that the merged generics conform to typical Rust syntax requirements where + /// lifetimes are declared before other generic parameters. /// /// # Arguments /// - /// * `a` - A reference to the first `syn::AngleBracketedGenericArguments` instance. - /// * `b` - A reference to the second `syn::AngleBracketedGenericArguments` instance. + /// * `a` - A reference to the first `syn::AngleBracketedGenericArguments` instance, containing one or more generic arguments. + /// * `b` - A reference to the second `syn::AngleBracketedGenericArguments` instance, containing one or more generic arguments. /// /// # Returns /// - /// Returns a new `syn::AngleBracketedGenericArguments` instance containing the combined - /// arguments from both `a` and `b`. + /// Returns a new `syn::AngleBracketedGenericArguments` instance containing the merged + /// arguments from both `a` and `b`, with lifetimes appearing first. /// /// # Examples /// /// ``` - /// use macro_tools:: - /// { + /// use macro_tools::{ /// generic_args, - /// syn::{ parse_quote, AngleBracketedGenericArguments }, + /// syn::{parse_quote, AngleBracketedGenericArguments}, /// }; /// - /// let a : AngleBracketedGenericArguments = parse_quote!{ }; - /// let b : AngleBracketedGenericArguments = parse_quote!{ }; - /// let merged = generic_args::merge( &a, &b ); + /// let a: AngleBracketedGenericArguments = parse_quote! { <'a, T: Clone, U: Default> }; + /// let b: AngleBracketedGenericArguments = parse_quote! { <'b, V: std::fmt::Debug> }; + /// let merged = generic_args::merge(&a, &b); /// - /// let expected : AngleBracketedGenericArguments = parse_quote!{ < T: Clone, U: Default, V: std::fmt::Debug > }; - /// assert_eq!( merged, expected ); + /// let expected: AngleBracketedGenericArguments = parse_quote! { <'a, 'b, T: Clone, U: Default, V: std::fmt::Debug> }; + /// assert_eq!(merged, expected); /// ``` + /// + /// This example demonstrates how lifetimes `'a` and `'b` are placed before other generic parameters + /// like `T`, `U`, and `V` in the merged result, adhering to the expected syntax order in Rust generics. pub fn merge ( a : &syn::AngleBracketedGenericArguments, b : &syn::AngleBracketedGenericArguments ) -> syn::AngleBracketedGenericArguments { - let mut args = syn::punctuated::Punctuated::new(); + let mut lifetimes : syn::punctuated::Punctuated< syn::GenericArgument, syn::token::Comma > = syn::punctuated::Punctuated::new(); + let mut others : syn::punctuated::Punctuated< syn::GenericArgument, syn::token::Comma > = syn::punctuated::Punctuated::new(); + + // Function to categorize and collect arguments into lifetimes and others + let mut categorize_and_collect = |args : &syn::punctuated::Punctuated| + { + for arg in args.iter() + { + match arg + { + syn::GenericArgument::Lifetime( _ ) => lifetimes.push( arg.clone() ), + _ => others.push( arg.clone() ), + } + } + }; - args.extend( a.args.iter().cloned() ); - args.extend( b.args.iter().cloned() ); + // Categorize and collect from both input arguments + categorize_and_collect( &a.args ); + categorize_and_collect( &b.args ); + + // Combine lifetimes and other arguments into final merged arguments + let mut args = syn::punctuated::Punctuated::new(); + args.extend( lifetimes ); + args.extend( others ); syn::AngleBracketedGenericArguments { - colon2_token: None, + colon2_token: None, // Adjust if needed based on context lt_token: syn::token::Lt::default(), args, gt_token: syn::token::Gt::default(), diff --git a/module/core/macro_tools/tests/inc/generic_args.rs b/module/core/macro_tools/tests/inc/generic_args.rs index 81b3bef786..0ad7085baa 100644 --- a/module/core/macro_tools/tests/inc/generic_args.rs +++ b/module/core/macro_tools/tests/inc/generic_args.rs @@ -25,7 +25,7 @@ fn assumptions() // { // < (), Struct1, former::ReturnPreformed > // }; - // let got = generic_params::merge( &a.into(), &b.into() ); + // let got = generic_params::generic_args::merge( &a.into(), &b.into() ); // // let got = definition_extra_generics; // let mut _got : syn::Generics = parse_quote! @@ -58,7 +58,7 @@ fn into_generic_args_empty_generics() args: syn::punctuated::Punctuated::new(), gt_token: token::Gt::default(), }; - assert_eq!( exp, got, "Failed into_generic_args_empty_generics: expected {:?}, got {:?}", exp, got ); + a_id!( exp, got, "Failed into_generic_args_empty_generics: exp {:?}, got {:?}", exp, got ); } // @@ -79,14 +79,14 @@ fn into_generic_args_single_type_parameter() < T > }; - // Create the expected AngleBracketedGenericArguments using parse_quote + // Create the exp AngleBracketedGenericArguments using parse_quote let exp : AngleBracketedGenericArguments = parse_quote! { < T > }; let got = generics.into_generic_args(); - assert_eq!( exp, got, "Failed into_generic_args_single_type_parameter: expected {:?}, got {:?}", exp, got ); + a_id!( exp, got, "Failed into_generic_args_single_type_parameter: exp {:?}, got {:?}", exp, got ); } /// @@ -110,7 +110,7 @@ fn into_generic_args_single_lifetime_parameter() < 'a > }; - // Create the expected AngleBracketedGenericArguments using parse_quote + // Create the exp AngleBracketedGenericArguments using parse_quote let exp : AngleBracketedGenericArguments = parse_quote! { < 'a > @@ -123,8 +123,8 @@ fn into_generic_args_single_lifetime_parameter() println!( "Expected: {:?}", exp ); println!( "Got: {:?}", got ); - // Assert to check if the expected matches the got - assert_eq!( exp, got, "Failed into_generic_args_single_lifetime_parameter: expected {:?}, got {:?}", exp, got ); + // Assert to check if the exp matches the got + a_id!( exp, got, "Failed into_generic_args_single_lifetime_parameter: exp {:?}, got {:?}", exp, got ); } #[ test ] @@ -151,7 +151,7 @@ fn into_generic_args_single_const_parameter() let got = generics.into_generic_args(); - // Manually construct the expected value + // Manually construct the exp value let mut args = Punctuated::new(); args.push_value( GenericArgument::Const( Expr::Path( ExprPath { @@ -172,7 +172,7 @@ fn into_generic_args_single_const_parameter() println!( "Expected: {:?}", exp ); println!( "Got: {:?}", got ); - assert_eq!( exp, got, "Failed into_generic_args_single_const_parameter: expected {:?}, got {:?}", exp, got ); + a_id!( exp, got, "Failed into_generic_args_single_const_parameter: exp {:?}, got {:?}", exp, got ); } @@ -205,7 +205,7 @@ fn into_generic_args_mixed_parameters() }; let got = generics.into_generic_args(); - // Manually construct the expected value + // Manually construct the exp value let mut args = Punctuated::new(); let t_type : GenericArgument = GenericArgument::Type( Type::Path( TypePath { @@ -238,5 +238,119 @@ fn into_generic_args_mixed_parameters() // tree_print!( got ); // tree_print!( exp ); // a_id!(tree_diagnostics_str!( exp ), tree_diagnostics_str!( got ) ); - a_id!( exp, got, "Failed into_generic_args_mixed_parameters: expected {:?}, got {:?}", exp, got ); + a_id!( exp, got, "Failed into_generic_args_mixed_parameters: exp {:?}, got {:?}", exp, got ); +} + +// = generic_args::merge + +#[ test ] +fn merge_empty_arguments() +{ + use syn::AngleBracketedGenericArguments; + use macro_tools::generic_args; + + let a : AngleBracketedGenericArguments = parse_quote! { <> }; + let b : AngleBracketedGenericArguments = parse_quote! { <> }; + let exp : AngleBracketedGenericArguments = parse_quote! { <> }; + + let got = generic_args::merge( &a, &b ); + a_id!( got, exp, "Merging two empty arguments should got in empty arguments" ); +} + +// + +#[ test ] +fn merge_one_empty_one_non_empty() +{ + use syn::AngleBracketedGenericArguments; + use macro_tools::generic_args; + + let a : AngleBracketedGenericArguments = parse_quote! { < T, U > }; + let b : AngleBracketedGenericArguments = parse_quote! { <> }; + let exp : AngleBracketedGenericArguments = parse_quote! { < T, U > }; + + let got = generic_args::merge( &a, &b ); + a_id!( got, exp, "Merging non-empty with empty should got in the non-empty" ); +} + +// + +#[ test ] +fn merge_duplicate_arguments() +{ + use syn::AngleBracketedGenericArguments; + use macro_tools::generic_args; + + let a : AngleBracketedGenericArguments = parse_quote! { < T > }; + let b : AngleBracketedGenericArguments = parse_quote! { < T > }; + let exp : AngleBracketedGenericArguments = parse_quote! { < T, T > }; + + let got = generic_args::merge( &a, &b ); + a_id!( got, exp, "Duplicates should be preserved in the output" ); +} + +// + +#[ test ] +fn merge_large_number_of_arguments() +{ + use syn::AngleBracketedGenericArguments; + use macro_tools::generic_args; + + let a : AngleBracketedGenericArguments = parse_quote! { }; + let b : AngleBracketedGenericArguments = parse_quote! { }; + let exp : AngleBracketedGenericArguments = parse_quote! { }; + + let got = generic_args::merge( &a, &b ); + a_id!( got, exp, "Merging large number of arguments should succeed without altering order or count" ); +} + +// + +#[ test ] +fn merge_complex_generic_constraints() +{ + use syn::AngleBracketedGenericArguments; + use macro_tools::generic_args; + + let a : AngleBracketedGenericArguments = parse_quote! { < T : Clone + Send, U: Default > }; + let b : AngleBracketedGenericArguments = parse_quote! { < V : std::fmt::Debug + Sync > }; + let exp : AngleBracketedGenericArguments = parse_quote! { < T: Clone + Send, U: Default, V: std::fmt::Debug + Sync > }; + + let got = generic_args::merge( &a, &b ); + a_id!( got, exp, "Complex constraints should be merged correctly" ); +} + +// + +#[ test ] +fn merge_different_orders_of_arguments() +{ + use syn::AngleBracketedGenericArguments; + use macro_tools::generic_args; + + let a : AngleBracketedGenericArguments = parse_quote! { < T, U > }; + let b : AngleBracketedGenericArguments = parse_quote! { < V, W > }; + let exp : AngleBracketedGenericArguments = parse_quote! { < T, U, V, W > }; + + let got = generic_args::merge( &a, &b ); + a_id!( got, exp, "Order of arguments should be preserved as per the inputs" ); +} + +// + +#[ test ] +fn merge_interaction_with_lifetimes_and_constants() +{ + use syn::AngleBracketedGenericArguments; + use macro_tools::generic_args; + + let a : AngleBracketedGenericArguments = parse_quote! { < 'a, M : T > }; + let b : AngleBracketedGenericArguments = parse_quote! { < 'b, N > }; + let exp : AngleBracketedGenericArguments = parse_quote! { <'a, 'b, M : T, N > }; + + let got = generic_args::merge( &a, &b ); + // a_id!(tree_diagnostics_str!( exp ), tree_diagnostics_str!( got ) ); + a_id!( got, exp, "Lifetimes and constants should be interleaved correctly" ); + } From add1c72acf4e9d20a0beb1fcad5c02b6338d2318 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 16:00:35 +0300 Subject: [PATCH 167/533] macro_tools : more functions to manipulate generics, small refactoring --- .../former/tests/inc/former_tests/a_basic.rs | 6 +- .../tests/inc/former_tests/a_basic_manual.rs | 1 - module/core/former/tests/inc/mod.rs | 66 +++++++++---------- module/core/former_meta/src/derive/former.rs | 13 +--- 4 files changed, 37 insertions(+), 49 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic.rs b/module/core/former/tests/inc/former_tests/a_basic.rs index d1c209ab44..31ec06d07d 100644 --- a/module/core/former/tests/inc/former_tests/a_basic.rs +++ b/module/core/former/tests/inc/former_tests/a_basic.rs @@ -1,8 +1,8 @@ #[ allow( unused_imports ) ] use super::*; -// #[ derive( Debug, PartialEq, former::Former ) ] -#[ derive( Debug, PartialEq, former::Former ) ] #[ debug ] +#[ derive( Debug, PartialEq, former::Former ) ] +// #[ derive( Debug, PartialEq, former::Former ) ] #[ debug ] // #[ derive( Debug, PartialEq ) ] pub struct Struct1 { @@ -11,8 +11,6 @@ pub struct Struct1 // = begin of generated - - // = end of generated include!( "./only_test/basic.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index b93ca40b20..0e55b9c516 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -259,4 +259,3 @@ where // === end of generated include!( "./only_test/basic.rs" ); -// xxx : uncomment diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index bfc5a6480b..1a67d97599 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -7,40 +7,40 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_common; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_vec; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_hashset; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_hashmap; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_common; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_vec; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashset; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashmap; mod a_basic_manual; mod a_basic; -// mod a_primitives_manual; -// mod a_primitives; -// // mod a_containers_without_subformer; -// // xxx -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer_manual; -// // #[ cfg( not( feature = "no_std" ) ) ] -// // mod a_containers_with_subformer ; -// // xxx -// -// mod attribute_default_container; -// mod attribute_default_primitive; -// // mod attribute_perform; // xxx -// mod attribute_setter; -// mod attribute_alias; -// -// // xxx -// mod string_slice_manual; -// // mod string_slice; -// mod unsigned_primitive_types; -// mod default_user_type; -// mod user_type_no_default; -// mod user_type_no_debug; + mod a_primitives_manual; + mod a_primitives; + // mod a_containers_without_subformer; + // xxx + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer_manual; + // #[ cfg( not( feature = "no_std" ) ) ] + // mod a_containers_with_subformer ; + // xxx + + mod attribute_default_container; + mod attribute_default_primitive; + // mod attribute_perform; // xxx + mod attribute_setter; + mod attribute_alias; + + // xxx + mod string_slice_manual; + // mod string_slice; + mod unsigned_primitive_types; + mod default_user_type; + mod user_type_no_default; + mod user_type_no_debug; // xxx // mod name_collision_former_hashmap_without_parameter; @@ -62,8 +62,8 @@ mod former_tests // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_shortcut; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_shortcut; // xxx : uncomment diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 3747f33bf3..4436effd47 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1049,6 +1049,7 @@ pub fn performer< 'a > pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { + use macro_tools::IntoGenericArgs; let original_input = input.clone(); let ast = match syn::parse::< syn::DeriveInput >( input ) @@ -1089,27 +1090,17 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > }; - // xxx // if has_debug // { // println!( "= a =" ); // } // parameters for definition - // let mut definition_extra_generics : macro_tools::GenericsWithWhere = parse_quote! let definition_extra_generics : macro_tools::syn::AngleBracketedGenericArguments = parse_quote! { < (), #struct_name, former::ReturnPreformed > }; - // xxx : uncomment - let generics_of_definition = generic_args::merge( &generics.into_into_generic_args(), &definition_extra_generics.into() ); - // let generics_of_definition = definition_extra_generics; - - // // xxx - // if has_debug - // { - // println!( "= b =" ); - // } + let generics_of_definition = generic_args::merge( &generics.into_generic_args(), &definition_extra_generics.into() ); // parameters for former let former_extra_generics : macro_tools::GenericsWithWhere = parse_quote! From a05476b7b2f97688fbb34f5feaf99cd2f74e12f2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 16:11:48 +0300 Subject: [PATCH 168/533] macro_tools : more functions to manipulate generics, small refactoring --- .../a_containers_without_subformer.rs | 5 +- .../tests/inc/former_tests/string_slice.rs | 102 +++++++++++++++++- module/core/former_meta/src/derive/former.rs | 2 +- 3 files changed, 106 insertions(+), 3 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs index 4b09b320a5..7a64f958dc 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs @@ -6,6 +6,7 @@ use std::collections::HashSet; #[ derive( Debug, PartialEq, the_module::Former ) ] // #[ debug ] +// #[ derive( Debug, PartialEq ) ] pub struct Struct1 { vec_1 : Vec< String >, @@ -13,6 +14,8 @@ pub struct Struct1 hashset_1 : HashSet< String >, } -// +// = begin of generated + +// = end of generated include!( "./only_test/containers_without_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/string_slice.rs b/module/core/former/tests/inc/former_tests/string_slice.rs index 3ec14fc4df..1d8523ccf7 100644 --- a/module/core/former/tests/inc/former_tests/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/string_slice.rs @@ -1,7 +1,8 @@ use super::*; // #[ derive( Debug, PartialEq, former::Former ) ] -#[ derive( Debug, PartialEq, former::Former ) ] #[ debug ] +// #[ derive( Debug, PartialEq, former::Former ) ] #[ debug ] +#[ derive( Debug, PartialEq ) ] pub struct Struct1< 'a > { pub string_slice_1 : &'a str, @@ -9,7 +10,106 @@ pub struct Struct1< 'a > // === begin of generated +#[ automatically_derived ] +impl< 'a > Struct1< 'a > +{ + #[ doc = r"" ] + #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] + #[ doc = r"" ] #[ inline( always ) ] + pub fn former() -> Struct1Former< 'a, > + { + Struct1Former::< 'a, >::new( former::ReturnPreformed ) + } +} + +#[ derive( Debug ) ] +pub struct Struct1FormerDefinitionTypes< Context, Formed > +{ + _phantom : core::marker::PhantomData< ( Context, Formed ) >, +} + +impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > +{ + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} + +impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > +{ + type Storage = Struct1FormerStorage< 'a >; + type Formed = Formed; + type Context = Context; +} + +#[ derive( Debug ) ] +pub struct Struct1FormerDefinition< Context, Formed, End > +{ + _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, +} + +impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > +{ + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} + +impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > +where End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > > +{ + type Types = Struct1FormerDefinitionTypes< Context, Formed >; + type End = End; +} + +pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; + +#[ doc = "Container of a corresponding former." ] +pub struct Struct1FormerStorage< 'a > +{ + #[ doc = r" A field" ] + pub string_slice_1 : ::core::option::Option< &'a str >, +} +impl< 'a > ::core::default::Default for Struct1FormerStorage< 'a > +{ + #[ inline( always ) ] + fn default() -> Self + { + Self + { + string_slice_1 : ::core::option::Option::None, + } + } +} + +impl< 'a > former::Storage for Struct1FormerStorage< 'a > +{ + type Formed = Struct1< 'a >; +} + +impl< 'a > former::StoragePreform for Struct1FormerStorage< 'a > +{ + fn preform( mut self ) -> < Self as former::Storage >::Formed + { + let string_slice_1 = self.string_slice_1.take().unwrap_or_else( || + { + panic!( "Field 'string_slice_1' isn't initialized" ) + }); + Struct1::< 'a > + { + string_slice_1, + } + } +} // === end of generated diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 4436effd47..955f5c43d7 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1305,7 +1305,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } // generics_impl, generics_ty, generics_where - impl former::StoragePreform + impl #generics_impl former::StoragePreform for #former_storage #generics_ty #generics_where { From 27247727ebcdeeb3f30c05e81df694f524b5172b Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 16:39:20 +0300 Subject: [PATCH 169/533] former : experimenting --- .../tests/inc/former_tests/string_slice.rs | 233 ++++++++++++------ module/core/former/tests/inc/mod.rs | 58 ++--- module/core/former_meta/src/derive/former.rs | 77 +++--- 3 files changed, 229 insertions(+), 139 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/string_slice.rs b/module/core/former/tests/inc/former_tests/string_slice.rs index 1d8523ccf7..ef59c3d3f3 100644 --- a/module/core/former/tests/inc/former_tests/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/string_slice.rs @@ -10,107 +10,178 @@ pub struct Struct1< 'a > // === begin of generated -#[ automatically_derived ] -impl< 'a > Struct1< 'a > +#[automatically_derived] impl < 'a > Struct1 < 'a > { - #[ doc = r"" ] - #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] - #[ doc = r"" ] #[ inline( always ) ] - pub fn former() -> Struct1Former< 'a, > - { - Struct1Former::< 'a, >::new( former::ReturnPreformed ) - } -} - -#[ derive( Debug ) ] -pub struct Struct1FormerDefinitionTypes< Context, Formed > + #[doc = r""] + #[doc = + r" Make former, variation of builder pattern to form structure defining values of fields step by step."] + #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < 'a, > + { Struct1Former :: < 'a, > :: new(former :: ReturnPreformed) } +} #[derive(Debug)] pub struct Struct1FormerDefinitionTypes < 'a, Context, +Formed > { _phantom : core :: marker :: PhantomData < (Context, Formed) >, } +impl < 'a, Context, Formed > Default for Struct1FormerDefinitionTypes < 'a, +Context, Formed > { - _phantom : core::marker::PhantomData< ( Context, Formed ) >, -} - -impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } +} impl < 'a, Context, Formed > former :: FormerDefinitionTypes for +Struct1FormerDefinitionTypes < 'a, Context, Formed > { - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } -} - -impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > + type Storage = Struct1FormerStorage < 'a > ; type Formed = Formed ; type + Context = Context ; +} #[derive(Debug)] pub struct Struct1FormerDefinition < 'a, Context, Formed, +End > { _phantom : core :: marker :: PhantomData < (Context, Formed, End) >, } +impl < 'a, Context, Formed, End > Default for Struct1FormerDefinition < 'a, +Context, Formed, End > { - type Storage = Struct1FormerStorage< 'a >; - type Formed = Formed; - type Context = Context; -} - -#[ derive( Debug ) ] -pub struct Struct1FormerDefinition< Context, Formed, End > + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } +} impl < 'a, Context, Formed, End > former :: FormerDefinition for +Struct1FormerDefinition < 'a, Context, Formed, End > where End : former :: +FormingEnd < Struct1FormerDefinitionTypes < 'a, Context, Formed > >, { - _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, + type Types = Struct1FormerDefinitionTypes < 'a, Context, Formed > ; type + End = End ; } -impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > -{ - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } -} +pub type Struct1FormerWithClosure +< 'a, Context, Formed > = Struct1FormerDefinition < Context, Formed, former :: FormingEndClosure < +Struct1FormerDefinitionTypes < 'a, Context, Formed > > > ; -impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > -where End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > > -{ - type Types = Struct1FormerDefinitionTypes< Context, Formed >; - type End = End; -} -pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; - -#[ doc = "Container of a corresponding former." ] -pub struct Struct1FormerStorage< 'a > +#[doc = "Container of a corresponding former."] pub struct +Struct1FormerStorage < 'a > { - #[ doc = r" A field" ] - pub string_slice_1 : ::core::option::Option< &'a str >, -} - -impl< 'a > ::core::default::Default for Struct1FormerStorage< 'a > + #[doc = r" A field"] pub string_slice_1 : :: core :: option :: Option < & + 'a str >, +} impl < 'a > :: core :: default :: Default for Struct1FormerStorage < 'a > +{ + #[inline(always)] fn default() -> Self + { Self { string_slice_1 : :: core :: option :: Option :: None, } } +} impl < 'a > former :: Storage for Struct1FormerStorage < 'a > +{ type Formed = Struct1 < 'a > ; } impl < 'a > former :: StoragePreform for +Struct1FormerStorage < 'a > { - #[ inline( always ) ] - fn default() -> Self - { - Self + fn preform(mut self) -> < Self as former :: Storage > :: Formed { - string_slice_1 : ::core::option::Option::None, + let string_slice_1 = if self.string_slice_1.is_some() + { self.string_slice_1.take().unwrap() } else + { + { + trait MaybeDefault < T > + { + fn maybe_default(self : & Self) -> T + { panic! ("Field 'string_slice_1' isn't initialized") } + } impl < T > MaybeDefault < T > for & :: core :: marker :: + PhantomData < T > {} impl < T > MaybeDefault < T > for :: core + :: marker :: PhantomData < T > where T : :: core :: default :: + Default, + { fn maybe_default(self : & Self) -> T { T :: default() } } + (& :: core :: marker :: PhantomData :: < & 'a str + >).maybe_default() + } + } ; let result = Struct1 :: < 'a > { string_slice_1, } ; return result + ; } - } } - -impl< 'a > former::Storage for Struct1FormerStorage< 'a > +#[doc = +" Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +pub struct Struct1Former < 'a, Definition = Struct1FormerDefinition < 'a, (), +Struct1, former :: ReturnPreformed > > where Definition : former :: +FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +Storage = Struct1FormerStorage < 'a > >, { - type Formed = Struct1< 'a >; -} - -impl< 'a > former::StoragePreform for Struct1FormerStorage< 'a > + storage : < Definition :: Types as former :: FormerDefinitionTypes > :: + Storage, context : core :: option :: Option < < Definition :: Types as + former :: FormerDefinitionTypes > :: Context >, on_end : core :: option :: + Option < Definition :: End >, +} #[automatically_derived] impl < 'a, Definition > Struct1Former < 'a, +Definition > where Definition : former :: FormerDefinition, Definition :: +Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < 'a +> >, { - fn preform( mut self ) -> < Self as former::Storage >::Formed - { - let string_slice_1 = self.string_slice_1.take().unwrap_or_else( || + #[doc = r""] + #[doc = r" Finish setting options and call perform on formed entity."] + #[doc = r""] + #[doc = + r" If `perform` defined then associated method is called and its result returned instead of entity."] + #[doc = + r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] + #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { let result = self.form() ; return result ; } #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn + _new_precise(on_end : Definition :: End) -> Self + { Self :: begin(None, None, on_end) } #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new < IntoEnd > (end : IntoEnd) -> + Self where IntoEnd : Into < Definition :: End >, + { Self :: begin(None, None, end,) } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn + _begin_precise(mut storage : core :: option :: Option < < Definition :: + Types as former :: FormerDefinitionTypes > :: Storage >, context : core :: + option :: Option < < Definition :: Types as former :: + FormerDefinitionTypes > :: Context >, on_end : < Definition as former :: + FormerDefinition > :: End,) -> Self + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()) ; } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: Some(on_end), + } + } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn begin < IntoEnd > + (mut storage : core :: option :: Option < < Definition :: Types as former + :: FormerDefinitionTypes > :: Storage >, context : core :: option :: + Option < < Definition :: Types as former :: FormerDefinitionTypes > :: + Context >, on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert + :: Into < < Definition as former :: FormerDefinition > :: End >, { - panic!( "Field 'string_slice_1' isn't initialized" ) - }); - Struct1::< 'a > + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()) ; } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: + Some(:: core :: convert :: Into :: into(on_end)), + } + } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types + as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed { - string_slice_1, + let on_end = self.on_end.take().unwrap() ; let context = + self.context.take() ; former :: FormingEnd :: < Definition :: Types > + :: call(& on_end, self.storage, context) + } #[doc = "Setter for the 'string_slice_1' field."] #[inline] pub fn + string_slice_1 < Src > (mut self, src : Src) -> Self where Src : :: core + :: convert :: Into < & 'a str >, + { + debug_assert! (self.storage.string_slice_1.is_none()) ; + self.storage.string_slice_1 = :: core :: option :: Option :: + Some(:: core :: convert :: Into :: into(src)) ; self } - } +} impl < Definition > Struct1Former < Definition > where Definition : former +:: FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +Storage = Struct1FormerStorage < 'a >, Formed = Struct1 < 'a > >, < Definition +:: Types as former :: FormerDefinitionTypes > :: Storage : former :: +StoragePreform, < Definition :: Types as former :: FormerDefinitionTypes > :: +Storage : former :: Storage < Formed = Struct1 < 'a > >, +{ + pub fn preform(self) -> < Definition :: Types as former :: + FormerDefinitionTypes > :: Formed + { former :: StoragePreform :: preform(self.storage) } } - // === end of generated // include!( "./only_test/string_slice.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 1a67d97599..cf17e9f6cd 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -7,40 +7,40 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_common; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_vec; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_hashset; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_hashmap; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod container_former_common; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod container_former_vec; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod container_former_hashset; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod container_former_hashmap; mod a_basic_manual; mod a_basic; - mod a_primitives_manual; - mod a_primitives; - // mod a_containers_without_subformer; - // xxx - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer_manual; - // #[ cfg( not( feature = "no_std" ) ) ] - // mod a_containers_with_subformer ; - // xxx - - mod attribute_default_container; - mod attribute_default_primitive; - // mod attribute_perform; // xxx - mod attribute_setter; - mod attribute_alias; +// mod a_primitives_manual; +// mod a_primitives; +// // mod a_containers_without_subformer; +// // xxx +// #[ cfg( not( feature = "no_std" ) ) ] +// mod a_containers_with_subformer_manual; +// // #[ cfg( not( feature = "no_std" ) ) ] +// // mod a_containers_with_subformer ; +// // xxx +// +// mod attribute_default_container; +// mod attribute_default_primitive; +// // mod attribute_perform; // xxx +// mod attribute_setter; +// mod attribute_alias; // xxx mod string_slice_manual; // mod string_slice; - mod unsigned_primitive_types; - mod default_user_type; - mod user_type_no_default; - mod user_type_no_debug; + // mod unsigned_primitive_types; + // mod default_user_type; + // mod user_type_no_default; + // mod user_type_no_debug; // xxx // mod name_collision_former_hashmap_without_parameter; @@ -62,8 +62,8 @@ mod former_tests // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_shortcut; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_shortcut; // xxx : uncomment diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 955f5c43d7..ec70afdfe4 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1078,6 +1078,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let generics = &ast.generics; let ( generics_impl, generics_ty, generics_where ) = generics.split_for_impl(); + let generics_ty_turbofish = generics_ty.as_turbofish(); // zzz : eliminate generic_params maybe let _generics_params = generic_params::names( generics ).params; let generic_params = if _generics_params.len() == 0 @@ -1089,33 +1090,43 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > qt!{ #_generics_params, } }; - - // if has_debug - // { - // println!( "= a =" ); - // } - - // parameters for definition - let definition_extra_generics : macro_tools::syn::AngleBracketedGenericArguments = parse_quote! + /* parameters for definition */ + let extra : macro_tools::syn::AngleBracketedGenericArguments = parse_quote! { < (), #struct_name, former::ReturnPreformed > }; - let generics_of_definition = generic_args::merge( &generics.into_generic_args(), &definition_extra_generics.into() ); + let generics_of_definition = generic_args::merge( &generics.into_generic_args(), &extra.into() ); - // parameters for former - let former_extra_generics : macro_tools::GenericsWithWhere = parse_quote! + /* parameters for former */ + let extra : macro_tools::GenericsWithWhere = parse_quote! { < Definition = #former_definition #generics_of_definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, }; - let generics_of_former = generic_params::merge( &generics, &former_extra_generics.into() ); + let generics_of_former = generic_params::merge( &generics, &extra.into() ); let ( generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generics_of_former.split_for_impl(); - let generics_of_former_with_defaults = generics_of_former.params.clone(); + let generics_of_former_with_defaults = generics_of_former.params.clone(); // xxx : remove? // macro_tools::code_print!( generics_of_former_with_defaults ); - // macro_tools::code_print!( former_extra_generics ); + // macro_tools::code_print!( extra ); + + /* parameters for definition types */ + let extra : macro_tools::GenericsWithWhere = parse_quote! + { + < Context, Formed > + }; + let generics_of_definition_type = generic_params::merge( &generics, &extra.into() ); + let ( generics_of_definition_type_impl, generics_of_definition_type_ty, generics_of_definition_type_where ) = generics_of_definition_type.split_for_impl(); + + /* parameters for definition */ + let extra : macro_tools::GenericsWithWhere = parse_quote! + { + < Context, Formed, End > + }; + let generics_of_definition = generic_params::merge( &generics, &extra.into() ); + let ( generics_of_definition_impl, _generics_of_definition_ty, generics_of_definition_where ) = generics_of_definition.split_for_impl(); /* structure attribute */ @@ -1211,13 +1222,15 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ derive( Debug ) ] // xxx : revert later // pub struct #former_definition_types< Context = (), Formed = #struct_name #generics_ty > - pub struct #former_definition_types< Context, Formed > + pub struct #former_definition_types #generics_of_definition_type_impl + #generics_of_definition_type_where { _phantom : core::marker::PhantomData< ( Context, Formed ) >, } - impl< Context, Formed > Default - for #former_definition_types< Context, Formed > + impl #generics_of_definition_type_impl Default + for #former_definition_types #generics_of_definition_type_ty + #generics_of_definition_type_where { fn default() -> Self { @@ -1228,8 +1241,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } - impl< Context, Formed > former::FormerDefinitionTypes - for #former_definition_types< Context, Formed > + impl #generics_of_definition_type_impl former::FormerDefinitionTypes + for #former_definition_types #generics_of_definition_type_ty { type Storage = #former_storage #generics_ty; type Formed = Formed; @@ -1241,13 +1254,17 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ derive( Debug ) ] // xxx : revert later // pub struct #former_definition< Context = (), Formed = #struct_name #generics_ty, End = former::ReturnPreformed > - pub struct #former_definition< Context, Formed, End > + pub struct #former_definition #generics_of_definition_impl + #generics_of_definition_where { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } - impl< Context, Formed, End > Default - for #former_definition< Context, Formed, End > + // let ( generics_of_definition_impl, generics_of_definition_ty, generics_of_definition_where ) = generics_of_definition.split_for_impl(); + + impl #generics_of_definition_impl Default + for #former_definition #generics_of_definition_impl + #generics_of_definition_where { fn default() -> Self { @@ -1258,17 +1275,19 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } - impl< Context, Formed, End > former::FormerDefinition - for #former_definition< Context, Formed, End > + impl #generics_of_definition_impl former::FormerDefinition + for #former_definition #generics_of_definition_impl where - End : former::FormingEnd< #former_definition_types< Context, Formed > >, + End : former::FormingEnd< #former_definition_types #generics_of_definition_type_ty >, + #generics_of_definition_where { - type Types = #former_definition_types< Context, Formed >; + type Types = #former_definition_types #generics_of_definition_type_ty; type End = End; } - pub type #former_with_closure< Context, Formed > = - #former_definition< Context, Formed, former::FormingEndClosure< #former_definition_types< Context, Formed > > >; + pub type #former_with_closure #generics_of_definition_type_ty = + #former_definition< Context, Formed, former::FormingEndClosure< #former_definition_types #generics_of_definition_type_ty > >; + // xxx2 : use unwrapped generics better // = storage @@ -1315,7 +1334,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #( #fields_form )* // Rust does not support that, yet // let result = < Definition::Types as former::FormerDefinitionTypes >::Formed - let result = #struct_name #generics_ty + let result = #struct_name #generics_ty_turbofish { #( #fields_names, )* }; From 20c01fd57873d6654e12e538480f998d76d3c052 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 23:14:04 +0300 Subject: [PATCH 170/533] macro_tools : more functions to manipulate generics --- .../tests/inc/former_tests/string_slice.rs | 1 + module/core/former/tests/inc/mod.rs | 6 ++ module/core/macro_tools/src/generic_params.rs | 75 +++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/module/core/former/tests/inc/former_tests/string_slice.rs b/module/core/former/tests/inc/former_tests/string_slice.rs index ef59c3d3f3..b9ea5afe79 100644 --- a/module/core/former/tests/inc/former_tests/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/string_slice.rs @@ -182,6 +182,7 @@ Storage : former :: Storage < Formed = Struct1 < 'a > >, FormerDefinitionTypes > :: Formed { former :: StoragePreform :: preform(self.storage) } } + // === end of generated // include!( "./only_test/string_slice.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index cf17e9f6cd..d0765ee383 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -1,6 +1,12 @@ #[ allow( unused_imports ) ] use super::*; +// struct Struct1< 'a, const N : i32, T > +// where +// { +// _phantom : core::marker::PhantomData< ( &'a (), T, ) >, +// } + #[ cfg( feature = "derive_former" ) ] mod former_tests { diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index eed5322341..64ca1af1df 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -281,6 +281,80 @@ pub( crate ) mod private result } + /// Splits generics into three parts suitable for use in impls, converting to `syn::punctuated::Punctuated` types. + /// + /// This function utilizes `syn::Generics::split_for_impl` from the `syn` crate and adapts + /// the results to return simple `syn::punctuated::Punctuated` structures for generic parameters and + /// where predicates. + /// + /// Split a type’s generics into the pieces required for impl’ing a trait for that type. + /// + /// ```rust + /// let ( generics_impl, generics_ty, generics_where ) = macro_tools::generic_params::decompose(); + /// + /// macro_tools::qt! + /// { + /// impl < #generics_impl > MyTrait for Struct1 < #generics_ty > + /// where + /// #generics_where + /// { + /// // ... + /// } + /// }; + /// ``` + /// + /// # Arguments + /// + /// * `generics` - A reference to the `syn::Generics` to be decomposed. + /// + /// # Returns + /// + /// Returns a tuple containing: + /// - `syn::punctuated::Punctuated` for use with `impl` + /// - `syn::punctuated::Punctuated` for use with type definition + /// - `syn::punctuated::Punctuated` for the where clause + /// + pub fn decompose( generics : &syn::Generics ) -> + ( + syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, + ) + { + // use quote::ToTokens; + // let ( generics_impl, generics_ty, generics_where ) = generics.split_for_impl(); + + // let generics_impl = generics_impl.into_iter().collect::< syn::punctuated::Punctuated< _, syn::token::Comma > >(); + // let generics_ty = generics_ty.into_iter().collect::< syn::punctuated::Punctuated< _, syn::token::Comma > >(); + // let generics_impl = generics_impl.into_token_stream().into(); + // let generics_ty = generics_ty.into_token_stream().into(); + + // let generics_where = if let Some( generics_where ) = generics_where + // { + // generics_where.predicates + // } + // else + // { + // syn::punctuated::Punctuated::new() + // }; + + // Clone the parameters for use in both `impl` and type definition contexts + let generics_impl = generics.params.clone(); + let generics_ty = generics.params.clone(); + + // Clone where predicates if present + let generics_where = if let Some( where_clause ) = &generics.where_clause + { + where_clause.predicates.clone() + } + else + { + syn::punctuated::Punctuated::new() + }; + + ( generics_impl, generics_ty, generics_where ) + } + } #[ doc( inline ) ] @@ -299,6 +373,7 @@ pub mod protected { merge, names, + decompose, }; } From e6ac9c06c74bdff61e5df60a4368e3365eb4f8db Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 23:29:52 +0300 Subject: [PATCH 171/533] macro_tools : more functions to manipulate generics --- module/core/macro_tools/src/generic_params.rs | 3 +- .../macro_tools/tests/inc/generic_params.rs | 124 ++++++++++++++++++ 2 files changed, 126 insertions(+), 1 deletion(-) diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index 64ca1af1df..d1ee7bab19 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -290,7 +290,8 @@ pub( crate ) mod private /// Split a type’s generics into the pieces required for impl’ing a trait for that type. /// /// ```rust - /// let ( generics_impl, generics_ty, generics_where ) = macro_tools::generic_params::decompose(); + /// let code : syn::Generics = syn::parse_quote!{ < T1, T2 > }; + /// let ( generics_impl, generics_ty, generics_where ) = macro_tools::generic_params::decompose( &code ); /// /// macro_tools::qt! /// { diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index 2f691ecb4e..e4f6b733e2 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -126,3 +126,127 @@ fn names() assert!( simplified_generics.where_clause.is_none() ); // Where clause is removed } + +// xxx + +#[ test ] +fn decompose_empty_generics() +{ + let generics : syn::Generics = syn::parse_quote! {}; + let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + + assert!( impl_gen.is_empty(), "Impl generics should be empty" ); + assert!( ty_gen.is_empty(), "Type generics should be empty" ); + assert!( where_gen.is_empty(), "Where generics should be empty" ); +} + +// #[ test ] +// fn decompose_generics_without_where_clause() +// { +// let generics : syn::Generics = syn::parse_quote! { }; +// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); +// +// assert_eq!( impl_gen.len(), 2, "Impl generics should have two parameters" ); +// assert_eq!( ty_gen.len(), 2, "Type generics should have two parameters" ); +// assert!( where_gen.is_empty(), "Where generics should be empty" ); +// } +// +// #[ test ] +// fn decompose_generics_with_where_clause() +// { +// let generics : syn::Generics = syn::parse_quote! { where T: Clone, U: Default }; +// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); +// +// assert_eq!( impl_gen.len(), 2, "Impl generics should have two parameters" ); +// assert_eq!( ty_gen.len(), 2, "Type generics should have two parameters" ); +// assert_eq!( where_gen.len(), 2, "Where generics should have two predicates" ); +// +// let where_clauses : Vec<_> = where_gen.iter().collect(); +// assert_eq!( where_clauses[0].bounded_ty.to_token_stream().to_string(), "T" ); +// assert_eq!( where_clauses[1].bounded_ty.to_token_stream().to_string(), "U" ); +// } +// +// #[ test ] +// fn decompose_generics_with_only_where_clause() +// { +// let generics : syn::Generics = syn::parse_quote! { where T: Clone, U: Default }; +// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); +// +// assert!( impl_gen.is_empty(), "Impl generics should be empty" ); +// assert!( ty_gen.is_empty(), "Type generics should be empty" ); +// assert_eq!( where_gen.len(), 2, "Where generics should have two predicates" ); +// } +// +// #[ test ] +// fn decompose_generics_with_complex_constraints() +// { +// let generics : syn::Generics = syn::parse_quote! { where T: Send, U: Default }; +// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); +// +// assert_eq!( impl_gen.len(), 2, "Impl generics should reflect complex constraints" ); +// assert_eq!( ty_gen.len(), 2, "Type generics should reflect complex constraints" ); +// assert_eq!( where_gen.len(), 2, "Where generics should reflect complex constraints" ); +// +// let where_clauses : Vec<_> = where_gen.iter().collect(); +// assert_eq!( where_clauses[0].bounded_ty.to_token_stream().to_string(), "T" ); +// assert_eq!( where_clauses[1].bounded_ty.to_token_stream().to_string(), "U" ); +// } +// +// #[ test ] +// fn decompose_generics_with_nested_generic_types() +// { +// let generics : syn::Generics = syn::parse_quote! { , U> }; +// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); +// +// assert_eq!( impl_gen.len(), 2, "Impl generics should handle nested generics" ); +// assert_eq!( ty_gen.len(), 2, "Type generics should handle nested generics" ); +// assert!( where_gen.is_empty(), "Where generics should be empty for non-conditional types" ); +// } +// +// #[ test ] +// fn decompose_generics_with_lifetime_parameters_only() +// { +// let generics : syn::Generics = syn::parse_quote! { <'a, 'b> }; +// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); +// +// assert_eq!( impl_gen.len(), 2, "Impl generics should contain only lifetimes" ); +// assert_eq!( ty_gen.len(), 2, "Type generics should contain only lifetimes" ); +// assert!( where_gen.is_empty(), "Where generics should be empty" ); +// } +// +// #[ test ] +// fn decompose_generics_with_constants_only() +// { +// let generics : syn::Generics = syn::parse_quote! { }; +// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); +// +// assert_eq!( impl_gen.len(), 2, "Impl generics should contain constants" ); +// assert_eq!( ty_gen.len(), 2, "Type generics should contain constants" ); +// assert!( where_gen.is_empty(), "Where generics should be empty" ); +// } +// +// #[ test ] +// fn decompose_generics_with_default_values() +// { +// let generics : syn::Generics = syn::parse_quote! { }; +// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); +// +// assert_eq!( impl_gen.len(), 2, "Impl generics should retain default types" ); +// assert_eq!( ty_gen.len(), 2, "Type generics should retain default types" ); +// assert!( where_gen.is_empty(), "Where generics should be empty" ); +// } +// +// #[ test ] +// fn decompose_mixed_generics_types() +// { +// let generics : syn::Generics = syn::parse_quote! { <'a, T, const N: usize, U='static> where T: Clone, U: Default }; +// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); +// +// assert_eq!( impl_gen.len(), 4, "Impl generics should correctly interleave types" ); +// assert_eq!( ty_gen.len(), 4, "Type generics should correctly interleave types" ); +// assert_eq!( where_gen.len(), 2, "Where generics should include conditions for T and U" ); +// +// let where_clauses : Vec<_> = where_gen.iter().collect(); +// assert_eq!( where_clauses[0].bounded_ty.to_token_stream().to_string(), "T" ); +// assert_eq!( where_clauses[1].bounded_ty.to_token_stream().to_string(), "U" ); +// } From 6c7c3ec0cf7226618faeaa9b0d69d4226c7bea80 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 16 Apr 2024 23:34:07 +0300 Subject: [PATCH 172/533] macro_tools : more functions to manipulate generics --- .../macro_tools/tests/inc/generic_params.rs | 72 ++++++++++++------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index e4f6b733e2..d5ac3d9c75 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -140,32 +140,52 @@ fn decompose_empty_generics() assert!( where_gen.is_empty(), "Where generics should be empty" ); } -// #[ test ] -// fn decompose_generics_without_where_clause() -// { -// let generics : syn::Generics = syn::parse_quote! { }; -// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); -// -// assert_eq!( impl_gen.len(), 2, "Impl generics should have two parameters" ); -// assert_eq!( ty_gen.len(), 2, "Type generics should have two parameters" ); -// assert!( where_gen.is_empty(), "Where generics should be empty" ); -// } -// -// #[ test ] -// fn decompose_generics_with_where_clause() -// { -// let generics : syn::Generics = syn::parse_quote! { where T: Clone, U: Default }; -// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); -// -// assert_eq!( impl_gen.len(), 2, "Impl generics should have two parameters" ); -// assert_eq!( ty_gen.len(), 2, "Type generics should have two parameters" ); -// assert_eq!( where_gen.len(), 2, "Where generics should have two predicates" ); -// -// let where_clauses : Vec<_> = where_gen.iter().collect(); -// assert_eq!( where_clauses[0].bounded_ty.to_token_stream().to_string(), "T" ); -// assert_eq!( where_clauses[1].bounded_ty.to_token_stream().to_string(), "U" ); -// } -// +#[ test ] +fn decompose_generics_without_where_clause() +{ + let generics : syn::Generics = syn::parse_quote! { < T, U > }; + let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + + assert_eq!( impl_gen.len(), 2, "Impl generics should have two parameters" ); + assert_eq!( ty_gen.len(), 2, "Type generics should have two parameters" ); + assert!( where_gen.is_empty(), "Where generics should be empty" ); +} + +#[ test ] +fn decompose_generics_with_where_clause() +{ + use macro_tools::quote::ToTokens; + + let generics : the_module::GenericsWithWhere = syn::parse_quote! { where T: Clone, U: Default }; + let generics = generics.unwrap(); + let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + + assert_eq!( impl_gen.len(), 2, "Impl generics should have two parameters" ); + assert_eq!( ty_gen.len(), 2, "Type generics should have two parameters" ); + assert_eq!( where_gen.len(), 2, "Where generics should have two predicates" ); + + let where_clauses : Vec<_> = where_gen.iter().collect(); + + // Properly match against the `syn::WherePredicate::Type` variant to extract `bounded_ty` + if let syn::WherePredicate::Type( pt ) = &where_clauses[0] + { + assert_eq!( pt.bounded_ty.to_token_stream().to_string(), "T", "The first where clause should be for T" ); + } + else + { + panic!( "First where clause is not a Type predicate as expected." ); + } + + if let syn::WherePredicate::Type( pt ) = &where_clauses[1] + { + assert_eq!( pt.bounded_ty.to_token_stream().to_string(), "U", "The second where clause should be for U" ); + } + else + { + panic!( "Second where clause is not a Type predicate as expected." ); + } +} + // #[ test ] // fn decompose_generics_with_only_where_clause() // { From 3ae42e197ad931082570ee64030d593d5d613daa Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 17 Apr 2024 08:23:31 +0300 Subject: [PATCH 173/533] macro_tools : more functions to manipulate generics --- .../macro_tools/tests/inc/generic_params.rs | 116 ++++++++++-------- 1 file changed, 68 insertions(+), 48 deletions(-) diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index d5ac3d9c75..eae61c2b7a 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -186,54 +186,74 @@ fn decompose_generics_with_where_clause() } } -// #[ test ] -// fn decompose_generics_with_only_where_clause() -// { -// let generics : syn::Generics = syn::parse_quote! { where T: Clone, U: Default }; -// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); -// -// assert!( impl_gen.is_empty(), "Impl generics should be empty" ); -// assert!( ty_gen.is_empty(), "Type generics should be empty" ); -// assert_eq!( where_gen.len(), 2, "Where generics should have two predicates" ); -// } -// -// #[ test ] -// fn decompose_generics_with_complex_constraints() -// { -// let generics : syn::Generics = syn::parse_quote! { where T: Send, U: Default }; -// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); -// -// assert_eq!( impl_gen.len(), 2, "Impl generics should reflect complex constraints" ); -// assert_eq!( ty_gen.len(), 2, "Type generics should reflect complex constraints" ); -// assert_eq!( where_gen.len(), 2, "Where generics should reflect complex constraints" ); -// -// let where_clauses : Vec<_> = where_gen.iter().collect(); -// assert_eq!( where_clauses[0].bounded_ty.to_token_stream().to_string(), "T" ); -// assert_eq!( where_clauses[1].bounded_ty.to_token_stream().to_string(), "U" ); -// } -// -// #[ test ] -// fn decompose_generics_with_nested_generic_types() -// { -// let generics : syn::Generics = syn::parse_quote! { , U> }; -// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); -// -// assert_eq!( impl_gen.len(), 2, "Impl generics should handle nested generics" ); -// assert_eq!( ty_gen.len(), 2, "Type generics should handle nested generics" ); -// assert!( where_gen.is_empty(), "Where generics should be empty for non-conditional types" ); -// } -// -// #[ test ] -// fn decompose_generics_with_lifetime_parameters_only() -// { -// let generics : syn::Generics = syn::parse_quote! { <'a, 'b> }; -// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); -// -// assert_eq!( impl_gen.len(), 2, "Impl generics should contain only lifetimes" ); -// assert_eq!( ty_gen.len(), 2, "Type generics should contain only lifetimes" ); -// assert!( where_gen.is_empty(), "Where generics should be empty" ); -// } -// +#[ test ] +fn decompose_generics_with_only_where_clause() +{ + let generics : the_module::GenericsWithWhere = syn::parse_quote! { where T : Clone, U : Default }; + let generics = generics.unwrap(); + let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + + assert!( impl_gen.is_empty(), "Impl generics should be empty" ); + assert!( ty_gen.is_empty(), "Type generics should be empty" ); + assert_eq!( where_gen.len(), 2, "Where generics should have two predicates" ); +} + +#[ test ] +fn decompose_generics_with_complex_constraints() +{ + use macro_tools::quote::ToTokens; + let generics : the_module::GenericsWithWhere = syn::parse_quote! { < T : Clone + Send, U : Default > where T: Send, U: Default }; + let generics = generics.unwrap(); + let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + + assert_eq!( impl_gen.len(), 2, "Impl generics should reflect complex constraints" ); + assert_eq!( ty_gen.len(), 2, "Type generics should reflect complex constraints" ); + assert_eq!( where_gen.len(), 2, "Where generics should reflect complex constraints" ); + + let where_clauses : Vec<_> = where_gen.iter().collect(); + + // Properly matching against the WherePredicate::Type variant + if let syn::WherePredicate::Type( pt ) = &where_clauses[0] + { + assert_eq!( pt.bounded_ty.to_token_stream().to_string(), "T", "The first where clause should be for T" ); + } + else + { + panic!( "First where clause is not a Type predicate as expected." ); + } + + if let syn::WherePredicate::Type( pt ) = &where_clauses[1] + { + assert_eq!( pt.bounded_ty.to_token_stream().to_string(), "U", "The second where clause should be for U" ); + } + else + { + panic!( "Second where clause is not a Type predicate as expected." ); + } +} + +#[ test ] +fn decompose_generics_with_nested_generic_types() +{ + let generics : syn::Generics = syn::parse_quote! { < T : Iterator< Item = U >, U > }; + let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + + assert_eq!( impl_gen.len(), 2, "Impl generics should handle nested generics" ); + assert_eq!( ty_gen.len(), 2, "Type generics should handle nested generics" ); + assert!( where_gen.is_empty(), "Where generics should be empty for non-conditional types" ); +} + +#[ test ] +fn decompose_generics_with_lifetime_parameters_only() +{ + let generics : syn::Generics = syn::parse_quote! { <'a, 'b> }; + let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + + assert_eq!( impl_gen.len(), 2, "Impl generics should contain only lifetimes" ); + assert_eq!( ty_gen.len(), 2, "Type generics should contain only lifetimes" ); + assert!( where_gen.is_empty(), "Where generics should be empty" ); +} + // #[ test ] // fn decompose_generics_with_constants_only() // { From 990f4b2de2f361a14966e5c01da0cf453b7dec12 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 17 Apr 2024 08:29:05 +0300 Subject: [PATCH 174/533] macro_tools : more functions to manipulate generics --- .../macro_tools/tests/inc/generic_params.rs | 93 +++++++++++-------- 1 file changed, 56 insertions(+), 37 deletions(-) diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index eae61c2b7a..bb8da655a8 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -246,7 +246,7 @@ fn decompose_generics_with_nested_generic_types() #[ test ] fn decompose_generics_with_lifetime_parameters_only() { - let generics : syn::Generics = syn::parse_quote! { <'a, 'b> }; + let generics : syn::Generics = syn::parse_quote! { < 'a, 'b > }; let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); assert_eq!( impl_gen.len(), 2, "Impl generics should contain only lifetimes" ); @@ -254,39 +254,58 @@ fn decompose_generics_with_lifetime_parameters_only() assert!( where_gen.is_empty(), "Where generics should be empty" ); } -// #[ test ] -// fn decompose_generics_with_constants_only() -// { -// let generics : syn::Generics = syn::parse_quote! { }; -// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); -// -// assert_eq!( impl_gen.len(), 2, "Impl generics should contain constants" ); -// assert_eq!( ty_gen.len(), 2, "Type generics should contain constants" ); -// assert!( where_gen.is_empty(), "Where generics should be empty" ); -// } -// -// #[ test ] -// fn decompose_generics_with_default_values() -// { -// let generics : syn::Generics = syn::parse_quote! { }; -// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); -// -// assert_eq!( impl_gen.len(), 2, "Impl generics should retain default types" ); -// assert_eq!( ty_gen.len(), 2, "Type generics should retain default types" ); -// assert!( where_gen.is_empty(), "Where generics should be empty" ); -// } -// -// #[ test ] -// fn decompose_mixed_generics_types() -// { -// let generics : syn::Generics = syn::parse_quote! { <'a, T, const N: usize, U='static> where T: Clone, U: Default }; -// let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); -// -// assert_eq!( impl_gen.len(), 4, "Impl generics should correctly interleave types" ); -// assert_eq!( ty_gen.len(), 4, "Type generics should correctly interleave types" ); -// assert_eq!( where_gen.len(), 2, "Where generics should include conditions for T and U" ); -// -// let where_clauses : Vec<_> = where_gen.iter().collect(); -// assert_eq!( where_clauses[0].bounded_ty.to_token_stream().to_string(), "T" ); -// assert_eq!( where_clauses[1].bounded_ty.to_token_stream().to_string(), "U" ); -// } +#[ test ] +fn decompose_generics_with_constants_only() +{ + let generics : syn::Generics = syn::parse_quote! { }; + let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + + assert_eq!( impl_gen.len(), 2, "Impl generics should contain constants" ); + assert_eq!( ty_gen.len(), 2, "Type generics should contain constants" ); + assert!( where_gen.is_empty(), "Where generics should be empty" ); +} + +#[ test ] +fn decompose_generics_with_default_values() +{ + let generics : syn::Generics = syn::parse_quote! { < T = usize, U = i32 > }; + let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + + assert_eq!( impl_gen.len(), 2, "Impl generics should retain default types" ); + assert_eq!( ty_gen.len(), 2, "Type generics should retain default types" ); + assert!( where_gen.is_empty(), "Where generics should be empty" ); +} + +#[ test ] +fn decompose_mixed_generics_types() +{ + use macro_tools::quote::ToTokens; + let generics : the_module::GenericsWithWhere = syn::parse_quote! { < 'a, T, const N : usize, U > where T : Clone, U : Default }; + let generics = generics.unwrap(); + let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + + assert_eq!( impl_gen.len(), 4, "Impl generics should correctly interleave types" ); + assert_eq!( ty_gen.len(), 4, "Type generics should correctly interleave types" ); + assert_eq!( where_gen.len(), 2, "Where generics should include conditions for T and U" ); + + // Correctly handling the pattern matching for WherePredicate::Type + let where_clauses : Vec<_> = where_gen.iter().collect(); + if let syn::WherePredicate::Type( pt ) = &where_clauses[0] + { + assert_eq!( pt.bounded_ty.to_token_stream().to_string(), "T", "The first where clause should be for T" ); + } + else + { + panic!( "First where clause is not a Type predicate as expected." ); + } + + if let syn::WherePredicate::Type( pt ) = &where_clauses[1] + { + assert_eq!( pt.bounded_ty.to_token_stream().to_string(), "U", "The second where clause should be for U" ); + } + else + { + panic!( "Second where clause is not a Type predicate as expected." ); + } + +} From 52fa87f5612ecfe48920353000e143984db4d73f Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 17 Apr 2024 08:44:39 +0300 Subject: [PATCH 175/533] macro_tools : more functions to manipulate generics --- module/core/macro_tools/src/generic_params.rs | 45 ++++++-------- module/core/macro_tools/src/lib.rs | 4 ++ module/core/macro_tools/src/punctuated.rs | 59 +++++++++++++++++++ .../macro_tools/tests/inc/generic_params.rs | 7 +++ 4 files changed, 88 insertions(+), 27 deletions(-) create mode 100644 module/core/macro_tools/src/punctuated.rs diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index d1ee7bab19..278df84bb9 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -23,6 +23,7 @@ /// Internal namespace. pub( crate ) mod private { + use super::super::*; /// A `GenericsWithWhere` struct to handle the parsing of Rust generics with an explicit `where` clause. /// @@ -315,38 +316,28 @@ pub( crate ) mod private /// - `syn::punctuated::Punctuated` for use with type definition /// - `syn::punctuated::Punctuated` for the where clause /// - pub fn decompose( generics : &syn::Generics ) -> + pub fn decompose ( - syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, + generics : &syn::Generics + ) + -> + ( + syn::punctuated::Punctuated, + syn::punctuated::Punctuated, + syn::punctuated::Punctuated, ) { - // use quote::ToTokens; - // let ( generics_impl, generics_ty, generics_where ) = generics.split_for_impl(); - - // let generics_impl = generics_impl.into_iter().collect::< syn::punctuated::Punctuated< _, syn::token::Comma > >(); - // let generics_ty = generics_ty.into_iter().collect::< syn::punctuated::Punctuated< _, syn::token::Comma > >(); - // let generics_impl = generics_impl.into_token_stream().into(); - // let generics_ty = generics_ty.into_token_stream().into(); - - // let generics_where = if let Some( generics_where ) = generics_where - // { - // generics_where.predicates - // } - // else - // { - // syn::punctuated::Punctuated::new() - // }; - - // Clone the parameters for use in both `impl` and type definition contexts - let generics_impl = generics.params.clone(); - let generics_ty = generics.params.clone(); - - // Clone where predicates if present + let mut generics_impl = generics.params.clone(); + punctuated::ensure_trailing_comma( &mut generics_impl ); + + let mut generics_ty = generics.params.clone(); + punctuated::ensure_trailing_comma( &mut generics_ty ); + let generics_where = if let Some( where_clause ) = &generics.where_clause { - where_clause.predicates.clone() + let mut predicates = where_clause.predicates.clone(); + punctuated::ensure_trailing_comma( &mut predicates ); + predicates } else { diff --git a/module/core/macro_tools/src/lib.rs b/module/core/macro_tools/src/lib.rs index 0094bc92a3..1f08d5ec3c 100644 --- a/module/core/macro_tools/src/lib.rs +++ b/module/core/macro_tools/src/lib.rs @@ -16,6 +16,7 @@ mod file pub mod generic_args; pub mod generic_params; pub mod name; + pub mod punctuated; pub mod quantifier; pub mod tokens; pub mod typ; @@ -60,6 +61,7 @@ pub mod protected generic_args::orphan::*, generic_params::orphan::*, name::orphan::*, + punctuated::orphan::*, quantifier::orphan::*, tokens::orphan::*, typ::orphan::*, @@ -103,6 +105,7 @@ pub mod exposed generic_args::exposed::*, generic_params::exposed::*, name::exposed::*, + punctuated::orphan::*, quantifier::exposed::*, tokens::exposed::*, typ::exposed::*, @@ -165,6 +168,7 @@ pub mod prelude generic_args::prelude::*, generic_params::prelude::*, name::prelude::*, + punctuated::orphan::*, quantifier::prelude::*, tokens::prelude::*, typ::prelude::*, diff --git a/module/core/macro_tools/src/punctuated.rs b/module/core/macro_tools/src/punctuated.rs new file mode 100644 index 0000000000..2d19ce5c3d --- /dev/null +++ b/module/core/macro_tools/src/punctuated.rs @@ -0,0 +1,59 @@ +// ! xxx : write description + +/// Internal namespace. +pub( crate ) mod private +{ + + /// Ensures that a `syn::punctuated::Punctuated` collection ends with a comma if it contains elements. + pub fn ensure_trailing_comma( punctuated : &mut syn::punctuated::Punctuated ) + { + if !punctuated.empty_or_trailing() + { + punctuated.push_punct( syn::token::Comma::default() ); + } + } + +} + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + ensure_trailing_comma, + }; +} + +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + pub use super::protected as punctuated; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super:: + { + prelude::*, + }; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index bb8da655a8..987562458d 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -149,6 +149,13 @@ fn decompose_generics_without_where_clause() assert_eq!( impl_gen.len(), 2, "Impl generics should have two parameters" ); assert_eq!( ty_gen.len(), 2, "Type generics should have two parameters" ); assert!( where_gen.is_empty(), "Where generics should be empty" ); + + let exp : syn::Generics = syn::parse_quote! { < T, U, > }; + a_id!( impl_gen, exp.params ); + let exp : syn::Generics = syn::parse_quote! { < T, U, > }; + a_id!( ty_gen, exp.params ); + // xxx : extend other tests + } #[ test ] From 45ef0ff79483d0297d0f2d09aca96d6757fd2550 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 18 Apr 2024 00:12:22 +0300 Subject: [PATCH 176/533] former : experimenting --- .../inc/former_tests/string_slice_manual.rs | 1 - module/core/former/tests/inc/mod.rs | 2 +- module/core/former_meta/src/derive/former.rs | 98 ++++++++++--------- 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index e9ccab8df6..19b47882ed 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -24,7 +24,6 @@ impl< 'a > Struct1< 'a > { Struct1Former::new( former::ReturnPreformed ) } - } // = definition types diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index d0765ee383..446868163f 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -41,7 +41,7 @@ mod former_tests // mod attribute_alias; // xxx - mod string_slice_manual; + // mod string_slice_manual; // mod string_slice; // mod unsigned_primitive_types; // mod default_user_type; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index ec70afdfe4..3f31002e32 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -994,7 +994,7 @@ pub fn performer< 'a > { return result; }; - // let mut perform_output = qt!{ #struct_name #generics_ty }; + // let mut perform_output = qt!{ #struct_name #generics_ty_ }; let mut perform_output = qt!{ < Definition::Types as former::FormerDefinitionTypes >::Formed }; let mut perform_generics = qt!{}; @@ -1077,18 +1077,21 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /* generic parameters */ let generics = &ast.generics; - let ( generics_impl, generics_ty, generics_where ) = generics.split_for_impl(); - let generics_ty_turbofish = generics_ty.as_turbofish(); + let ( generics_impl, generics_ty, generics_where ) = generic_params::decompose( generics ); + + // xxx : rid off + let ( generics_impl_, generics_ty_, generics_where_ ) = generics.split_for_impl(); + // let generics_ty_turbofish = generics_ty_.as_turbofish(); // zzz : eliminate generic_params maybe - let _generics_params = generic_params::names( generics ).params; - let generic_params = if _generics_params.len() == 0 - { - qt!{} - } - else - { - qt!{ #_generics_params, } - }; + // let _generics_params = generic_params::names( generics ).params; + // let generic_params = if _generics_params.len() == 0 + // { + // qt!{} + // } + // else + // { + // qt!{ #_generics_params, } + // }; /* parameters for definition */ let extra : macro_tools::syn::AngleBracketedGenericArguments = parse_quote! @@ -1103,7 +1106,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > < Definition = #former_definition #generics_of_definition > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, + Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty_ >, }; let generics_of_former = generic_params::merge( &generics, &extra.into() ); @@ -1126,7 +1129,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > < Context, Formed, End > }; let generics_of_definition = generic_params::merge( &generics, &extra.into() ); - let ( generics_of_definition_impl, _generics_of_definition_ty, generics_of_definition_where ) = generics_of_definition.split_for_impl(); + // let ( generics_of_definition_impl, _generics_of_definition_ty, generics_of_definition_where ) = generics_of_definition.split_for_impl(); + let ( generics_of_definition_impl, generics_of_definition_ty, generics_of_definition_where ) = generic_params::decompose( &generics_of_definition ); /* structure attribute */ @@ -1134,7 +1138,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > ( &struct_name, &former_definition, - &generics_ty, + &generics_ty_, ast.attrs.iter(), )?; @@ -1202,17 +1206,17 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = formed #[ automatically_derived ] - impl #generics_impl #struct_name #generics_ty - #generics_where + impl #generics_impl_ #struct_name #generics_ty_ + #generics_where_ { /// /// Make former, variation of builder pattern to form structure defining values of fields step by step. /// #[ inline( always ) ] - pub fn former() -> #former < #generic_params > + pub fn former() -> #former < #generics_ty > { - #former :: < #generic_params > :: new( former::ReturnPreformed ) + #former :: < #generics_ty > :: new( former::ReturnPreformed ) } } @@ -1221,7 +1225,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ derive( Debug ) ] // xxx : revert later - // pub struct #former_definition_types< Context = (), Formed = #struct_name #generics_ty > + // pub struct #former_definition_types< Context = (), Formed = #struct_name #generics_ty_ > pub struct #former_definition_types #generics_of_definition_type_impl #generics_of_definition_type_where { @@ -1244,7 +1248,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl #generics_of_definition_type_impl former::FormerDefinitionTypes for #former_definition_types #generics_of_definition_type_ty { - type Storage = #former_storage #generics_ty; + type Storage = #former_storage #generics_ty_; type Formed = Formed; type Context = Context; } @@ -1253,18 +1257,18 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ derive( Debug ) ] // xxx : revert later - // pub struct #former_definition< Context = (), Formed = #struct_name #generics_ty, End = former::ReturnPreformed > - pub struct #former_definition #generics_of_definition_impl - #generics_of_definition_where + // pub struct #former_definition< Context = (), Formed = #struct_name #generics_ty_, End = former::ReturnPreformed > + pub struct #former_definition < #generics_of_definition_impl > + where + #generics_of_definition_where { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } - // let ( generics_of_definition_impl, generics_of_definition_ty, generics_of_definition_where ) = generics_of_definition.split_for_impl(); - - impl #generics_of_definition_impl Default - for #former_definition #generics_of_definition_impl - #generics_of_definition_where + impl < #generics_of_definition_impl > Default + for #former_definition < #generics_of_definition_ty > + where + #generics_of_definition_where { fn default() -> Self { @@ -1275,11 +1279,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } - impl #generics_of_definition_impl former::FormerDefinition - for #former_definition #generics_of_definition_impl + impl < #generics_of_definition_impl > former::FormerDefinition + for #former_definition < #generics_of_definition_ty > where End : former::FormingEnd< #former_definition_types #generics_of_definition_type_ty >, - #generics_of_definition_where + #generics_of_definition_where { type Types = #former_definition_types #generics_of_definition_type_ty; type End = End; @@ -1292,8 +1296,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = storage #[ doc = "Container of a corresponding former." ] - pub struct #former_storage #generics_ty - #generics_where + pub struct #former_storage #generics_ty_ + #generics_where_ { #( /// A field @@ -1301,8 +1305,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > )* } - impl #generics_impl ::core::default::Default for #former_storage #generics_ty - #generics_where + impl #generics_impl_ ::core::default::Default for #former_storage #generics_ty_ + #generics_where_ { #[ inline( always ) ] @@ -1316,17 +1320,17 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } - impl #generics_impl former::Storage - for #former_storage #generics_ty - #generics_where + impl #generics_impl_ former::Storage + for #former_storage #generics_ty_ + #generics_where_ { - type Formed = #struct_name #generics_ty; + type Formed = #struct_name #generics_ty_; } - // generics_impl, generics_ty, generics_where + // generics_impl_, generics_ty_, generics_where_ - impl #generics_impl former::StoragePreform - for #former_storage #generics_ty - #generics_where + impl #generics_impl_ former::StoragePreform + for #former_storage #generics_ty_ + #generics_where_ { fn preform( mut self ) -> < Self as former::Storage >::Formed @@ -1334,7 +1338,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #( #fields_form )* // Rust does not support that, yet // let result = < Definition::Types as former::FormerDefinitionTypes >::Formed - let result = #struct_name #generics_ty_turbofish + let result = #struct_name :: < #generics_ty > { #( #fields_names, )* }; @@ -1481,9 +1485,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl< Definition > #former< Definition > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty, Formed = #struct_name #generics_ty >, + Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty_, Formed = #struct_name #generics_ty_ >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = #struct_name #generics_ty >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = #struct_name #generics_ty_ >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed From ce1f6f98bd7567962d1d07509cfb784edb4310aa Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 18 Apr 2024 00:12:54 +0300 Subject: [PATCH 177/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 3f31002e32..8220dfdd9d 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1122,6 +1122,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > }; let generics_of_definition_type = generic_params::merge( &generics, &extra.into() ); let ( generics_of_definition_type_impl, generics_of_definition_type_ty, generics_of_definition_type_where ) = generics_of_definition_type.split_for_impl(); + // xxx : rid off all split_for_impl, replacing them by generic_params::decompose /* parameters for definition */ let extra : macro_tools::GenericsWithWhere = parse_quote! From 8dd059b863a6a74d647593c2f996afd4e3053727 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 18 Apr 2024 08:31:19 +0300 Subject: [PATCH 178/533] former : experimenting --- module/core/former/tests/inc/mod.rs | 2 +- module/core/former_meta/src/derive/former.rs | 53 +++++++++++--------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 446868163f..d0765ee383 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -41,7 +41,7 @@ mod former_tests // mod attribute_alias; // xxx - // mod string_slice_manual; + mod string_slice_manual; // mod string_slice; // mod unsigned_primitive_types; // mod default_user_type; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 8220dfdd9d..ef56de4958 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -983,8 +983,8 @@ For specifying custom default value use attribute `default`. For example: pub fn performer< 'a > ( _struct_name : &syn::Ident, - _former_definition : &syn::Ident, - _generics_ty : &syn::TypeGenerics< '_ >, + // _former_definition : &syn::Ident, + // _generics_ty : &syn::TypeGenerics< '_ >, attrs : impl Iterator< Item = &'a syn::Attribute >, ) -> Result< ( TokenStream, TokenStream, TokenStream ) > @@ -1080,7 +1080,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( generics_impl, generics_ty, generics_where ) = generic_params::decompose( generics ); // xxx : rid off - let ( generics_impl_, generics_ty_, generics_where_ ) = generics.split_for_impl(); + // let ( generics_impl_, generics_ty_, generics_where_ ) = generics.split_for_impl(); // let generics_ty_turbofish = generics_ty_.as_turbofish(); // zzz : eliminate generic_params maybe // let _generics_params = generic_params::names( generics ).params; @@ -1106,7 +1106,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > < Definition = #former_definition #generics_of_definition > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty_ >, + Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #generics_ty > >, }; let generics_of_former = generic_params::merge( &generics, &extra.into() ); @@ -1138,8 +1138,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( perform, perform_output, perform_generics ) = performer ( &struct_name, - &former_definition, - &generics_ty_, + // &former_definition, + // &generics_ty, ast.attrs.iter(), )?; @@ -1207,8 +1207,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = formed #[ automatically_derived ] - impl #generics_impl_ #struct_name #generics_ty_ - #generics_where_ + impl < #generics_impl > #struct_name < #generics_ty > + where + #generics_where { /// /// Make former, variation of builder pattern to form structure defining values of fields step by step. @@ -1228,7 +1229,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // xxx : revert later // pub struct #former_definition_types< Context = (), Formed = #struct_name #generics_ty_ > pub struct #former_definition_types #generics_of_definition_type_impl - #generics_of_definition_type_where + where + #generics_of_definition_type_where { _phantom : core::marker::PhantomData< ( Context, Formed ) >, } @@ -1249,7 +1251,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl #generics_of_definition_type_impl former::FormerDefinitionTypes for #former_definition_types #generics_of_definition_type_ty { - type Storage = #former_storage #generics_ty_; + type Storage = #former_storage < #generics_ty >; type Formed = Formed; type Context = Context; } @@ -1297,8 +1299,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = storage #[ doc = "Container of a corresponding former." ] - pub struct #former_storage #generics_ty_ - #generics_where_ + pub struct #former_storage < #generics_ty > + where + #generics_where { #( /// A field @@ -1306,8 +1309,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > )* } - impl #generics_impl_ ::core::default::Default for #former_storage #generics_ty_ - #generics_where_ + impl < #generics_impl > ::core::default::Default for #former_storage < #generics_ty > + where + #generics_where { #[ inline( always ) ] @@ -1321,17 +1325,18 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } - impl #generics_impl_ former::Storage - for #former_storage #generics_ty_ - #generics_where_ + impl < #generics_impl > former::Storage + for #former_storage < #generics_ty > + where + #generics_where { - type Formed = #struct_name #generics_ty_; + type Formed = #struct_name < #generics_ty >; } - // generics_impl_, generics_ty_, generics_where_ - impl #generics_impl_ former::StoragePreform - for #former_storage #generics_ty_ - #generics_where_ + impl < #generics_impl > former::StoragePreform + for #former_storage < #generics_ty > + where + #generics_where { fn preform( mut self ) -> < Self as former::Storage >::Formed @@ -1486,9 +1491,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl< Definition > #former< Definition > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty_, Formed = #struct_name #generics_ty_ >, + Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #generics_ty >, Formed = #struct_name < #generics_ty > >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = #struct_name #generics_ty_ >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = #struct_name < #generics_ty > >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed From 1db10520dfeecb6254d7b66584853e453ad5b0c6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 00:35:23 +0300 Subject: [PATCH 179/533] macro_tools : improve decompose --- .../tests/inc/former_tests/a_basic_manual.rs | 3 +- module/core/macro_tools/src/generic_params.rs | 110 +++++++++++++++--- module/core/macro_tools/src/punctuated.rs | 3 +- .../macro_tools/tests/inc/generic_params.rs | 8 +- 4 files changed, 105 insertions(+), 19 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 0e55b9c516..095c3c1482 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -40,7 +40,8 @@ impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Forme } } -impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > +impl< Context, Formed > former::FormerDefinitionTypes +for Struct1FormerDefinitionTypes< Context, Formed > { type Storage = Struct1FormerStorage; type Formed = Formed; diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index 278df84bb9..490bf498bf 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -282,16 +282,18 @@ pub( crate ) mod private result } - /// Splits generics into three parts suitable for use in impls, converting to `syn::punctuated::Punctuated` types. + /// Decomposes `syn::Generics` into three parts suitable for use in implementing traits or types, + /// simplifying type and const parameters for type definitions. /// - /// This function utilizes `syn::Generics::split_for_impl` from the `syn` crate and adapts - /// the results to return simple `syn::punctuated::Punctuated` structures for generic parameters and - /// where predicates. + /// This function clones generic parameters for use with `impl` declarations directly. For type + /// definitions, it simplifies type and const parameters to include only identifiers, removing + /// any associated bounds or default values. Where clauses are cloned as-is, with a check to ensure + /// they end with a comma if not empty. /// - /// Split a type’s generics into the pieces required for impl’ing a trait for that type. + /// # Examples /// /// ```rust - /// let code : syn::Generics = syn::parse_quote!{ < T1, T2 > }; + /// let code : syn::Generics = syn::parse_quote!{ < 'a, T, const N : usize, U : Trait1 > }; /// let ( generics_impl, generics_ty, generics_where ) = macro_tools::generic_params::decompose( &code ); /// /// macro_tools::qt! @@ -300,11 +302,18 @@ pub( crate ) mod private /// where /// #generics_where /// { - /// // ... + /// // implementation details... /// } /// }; /// ``` /// + /// # Usage + /// + /// - `generics_impl` : Retains full structure of the original generic parameters for use in `impl` blocks. + /// - `generics_ty` : Simplifies generic parameters for type declarations by stripping bounds and modifiers, + /// leaving only the identifiers. Lifetimes are included as is. + /// - `generics_where` : Directly clones where clauses if present and ensures they are properly punctuated. + /// /// # Arguments /// /// * `generics` - A reference to the `syn::Generics` to be decomposed. @@ -312,26 +321,64 @@ pub( crate ) mod private /// # Returns /// /// Returns a tuple containing: - /// - `syn::punctuated::Punctuated` for use with `impl` - /// - `syn::punctuated::Punctuated` for use with type definition - /// - `syn::punctuated::Punctuated` for the where clause - /// + /// - `syn::punctuated::Punctuated` : For use with `impl` blocks. + /// - `syn::punctuated::Punctuated` : For use with type definitions, simplified. + /// - `syn::punctuated::Punctuated` : For where clauses, properly punctuated. + pub fn decompose ( generics : &syn::Generics ) -> ( - syn::punctuated::Punctuated, - syn::punctuated::Punctuated, - syn::punctuated::Punctuated, + syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, ) { let mut generics_impl = generics.params.clone(); punctuated::ensure_trailing_comma( &mut generics_impl ); - let mut generics_ty = generics.params.clone(); - punctuated::ensure_trailing_comma( &mut generics_ty ); + let mut generics_ty = syn::punctuated::Punctuated::new(); + for param in &generics.params + { + match param + { + syn::GenericParam::Type( type_param ) => + { + let simplified = syn::GenericParam::Type( syn::TypeParam + { + attrs : vec![], + ident : type_param.ident.clone(), + colon_token : None, + bounds : syn::punctuated::Punctuated::new(), + eq_token : None, + default : None, + }); + generics_ty.push_value( simplified ); + generics_ty.push_punct( syn::token::Comma::default() ); + }, + syn::GenericParam::Const( const_param ) => + { + let simplified = syn::GenericParam::Type( syn::TypeParam + { + attrs : vec![], + ident : const_param.ident.clone(), + colon_token : None, + bounds : syn::punctuated::Punctuated::new(), + eq_token : None, + default : None, + }); + generics_ty.push_value( simplified ); + generics_ty.push_punct( syn::token::Comma::default() ); + }, + syn::GenericParam::Lifetime( lifetime_param ) => + { + generics_ty.push_value( syn::GenericParam::Lifetime( lifetime_param.clone() ) ); + generics_ty.push_punct( syn::token::Comma::default() ); + } + } + } let generics_where = if let Some( where_clause ) = &generics.where_clause { @@ -347,6 +394,37 @@ pub( crate ) mod private ( generics_impl, generics_ty, generics_where ) } +// pub fn decompose +// ( +// generics : &syn::Generics +// ) +// -> +// ( +// syn::punctuated::Punctuated, +// syn::punctuated::Punctuated, +// syn::punctuated::Punctuated, +// ) +// { +// let mut generics_impl = generics.params.clone(); +// punctuated::ensure_trailing_comma( &mut generics_impl ); +// +// let mut generics_ty = generics.params.clone(); +// punctuated::ensure_trailing_comma( &mut generics_ty ); +// +// let generics_where = if let Some( where_clause ) = &generics.where_clause +// { +// let mut predicates = where_clause.predicates.clone(); +// punctuated::ensure_trailing_comma( &mut predicates ); +// predicates +// } +// else +// { +// syn::punctuated::Punctuated::new() +// }; +// +// ( generics_impl, generics_ty, generics_where ) +// } + } #[ doc( inline ) ] diff --git a/module/core/macro_tools/src/punctuated.rs b/module/core/macro_tools/src/punctuated.rs index 2d19ce5c3d..5ea50730c4 100644 --- a/module/core/macro_tools/src/punctuated.rs +++ b/module/core/macro_tools/src/punctuated.rs @@ -5,7 +5,8 @@ pub( crate ) mod private { /// Ensures that a `syn::punctuated::Punctuated` collection ends with a comma if it contains elements. - pub fn ensure_trailing_comma( punctuated : &mut syn::punctuated::Punctuated ) + pub fn ensure_trailing_comma< T : Clone > + ( punctuated : &mut syn::punctuated::Punctuated< T, syn::token::Comma > ) { if !punctuated.empty_or_trailing() { diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index 987562458d..1807c48a59 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -287,10 +287,16 @@ fn decompose_generics_with_default_values() fn decompose_mixed_generics_types() { use macro_tools::quote::ToTokens; - let generics : the_module::GenericsWithWhere = syn::parse_quote! { < 'a, T, const N : usize, U > where T : Clone, U : Default }; + let generics : the_module::GenericsWithWhere = syn::parse_quote! { < 'a, T, const N : usize, U : Trait1 > where T : Clone, U : Default }; let generics = generics.unwrap(); let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let impl_exp : syn::Generics = syn::parse_quote! { < 'a, T, const N : usize, U : Trait1, > }; + let ty_exp : syn::Generics = syn::parse_quote! { < 'a, T, N, U, > }; + + a_id!( impl_gen, impl_exp.params ); + a_id!( ty_gen, ty_exp.params ); + assert_eq!( impl_gen.len(), 4, "Impl generics should correctly interleave types" ); assert_eq!( ty_gen.len(), 4, "Type generics should correctly interleave types" ); assert_eq!( where_gen.len(), 2, "Where generics should include conditions for T and U" ); From a4dfd08e2919778efb3a63be916266082936cf60 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 00:46:47 +0300 Subject: [PATCH 180/533] macro_tools : improve decompose --- module/core/macro_tools/src/generic_params.rs | 31 ------------- .../macro_tools/tests/inc/generic_params.rs | 43 +++++++++++++++---- 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index 490bf498bf..c60a129b9b 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -394,37 +394,6 @@ pub( crate ) mod private ( generics_impl, generics_ty, generics_where ) } -// pub fn decompose -// ( -// generics : &syn::Generics -// ) -// -> -// ( -// syn::punctuated::Punctuated, -// syn::punctuated::Punctuated, -// syn::punctuated::Punctuated, -// ) -// { -// let mut generics_impl = generics.params.clone(); -// punctuated::ensure_trailing_comma( &mut generics_impl ); -// -// let mut generics_ty = generics.params.clone(); -// punctuated::ensure_trailing_comma( &mut generics_ty ); -// -// let generics_where = if let Some( where_clause ) = &generics.where_clause -// { -// let mut predicates = where_clause.predicates.clone(); -// punctuated::ensure_trailing_comma( &mut predicates ); -// predicates -// } -// else -// { -// syn::punctuated::Punctuated::new() -// }; -// -// ( generics_impl, generics_ty, generics_where ) -// } - } #[ doc( inline ) ] diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index 1807c48a59..4c48c3e0cc 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -117,17 +117,15 @@ fn names() use macro_tools::syn::parse_quote; - let mut generics : syn::Generics = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > }; - generics.where_clause = parse_quote!{ where T: std::fmt::Debug }; - // let generics : Generics = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > where T: std::fmt::Debug }; - let simplified_generics = macro_tools::generic_params::names( &generics ); + let generics : the_module::GenericsWithWhere = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > where T: std::fmt::Debug }; + let simplified_generics = macro_tools::generic_params::names( &generics.unwrap() ); assert_eq!( simplified_generics.params.len(), 4 ); // Contains T, U, 'a, and N assert!( simplified_generics.where_clause.is_none() ); // Where clause is removed } -// xxx +// #[ test ] fn decompose_empty_generics() @@ -163,10 +161,15 @@ fn decompose_generics_with_where_clause() { use macro_tools::quote::ToTokens; - let generics : the_module::GenericsWithWhere = syn::parse_quote! { where T: Clone, U: Default }; + let generics : the_module::GenericsWithWhere = syn::parse_quote! { < T, U > where T : Clone, U : Default }; let generics = generics.unwrap(); let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let impl_exp : syn::Generics = syn::parse_quote! { < T, U, > }; + let ty_exp : syn::Generics = syn::parse_quote! { < T, U, > }; + a_id!( impl_gen, impl_exp.params ); + a_id!( ty_gen, ty_exp.params ); + assert_eq!( impl_gen.len(), 2, "Impl generics should have two parameters" ); assert_eq!( ty_gen.len(), 2, "Type generics should have two parameters" ); assert_eq!( where_gen.len(), 2, "Where generics should have two predicates" ); @@ -213,6 +216,11 @@ fn decompose_generics_with_complex_constraints() let generics = generics.unwrap(); let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let impl_exp : syn::Generics = syn::parse_quote! { < T : Clone + Send, U : Default, > }; + let ty_exp : syn::Generics = syn::parse_quote! { < T, U, > }; + a_id!( impl_gen, impl_exp.params ); + a_id!( ty_gen, ty_exp.params ); + assert_eq!( impl_gen.len(), 2, "Impl generics should reflect complex constraints" ); assert_eq!( ty_gen.len(), 2, "Type generics should reflect complex constraints" ); assert_eq!( where_gen.len(), 2, "Where generics should reflect complex constraints" ); @@ -245,6 +253,11 @@ fn decompose_generics_with_nested_generic_types() let generics : syn::Generics = syn::parse_quote! { < T : Iterator< Item = U >, U > }; let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let impl_exp : syn::Generics = syn::parse_quote! { < T : Iterator< Item = U >, U, > }; + let ty_exp : syn::Generics = syn::parse_quote! { < T, U, > }; + a_id!( impl_gen, impl_exp.params ); + a_id!( ty_gen, ty_exp.params ); + assert_eq!( impl_gen.len(), 2, "Impl generics should handle nested generics" ); assert_eq!( ty_gen.len(), 2, "Type generics should handle nested generics" ); assert!( where_gen.is_empty(), "Where generics should be empty for non-conditional types" ); @@ -256,6 +269,11 @@ fn decompose_generics_with_lifetime_parameters_only() let generics : syn::Generics = syn::parse_quote! { < 'a, 'b > }; let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let impl_exp : syn::Generics = syn::parse_quote! { < 'a, 'b, > }; + let ty_exp : syn::Generics = syn::parse_quote! { < 'a, 'b, > }; + a_id!( impl_gen, impl_exp.params ); + a_id!( ty_gen, ty_exp.params ); + assert_eq!( impl_gen.len(), 2, "Impl generics should contain only lifetimes" ); assert_eq!( ty_gen.len(), 2, "Type generics should contain only lifetimes" ); assert!( where_gen.is_empty(), "Where generics should be empty" ); @@ -264,9 +282,14 @@ fn decompose_generics_with_lifetime_parameters_only() #[ test ] fn decompose_generics_with_constants_only() { - let generics : syn::Generics = syn::parse_quote! { }; + let generics : syn::Generics = syn::parse_quote! { < const N : usize, const M : usize > }; let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let impl_exp : syn::Generics = syn::parse_quote! { < const N : usize, const M : usize, > }; + let ty_exp : syn::Generics = syn::parse_quote! { < N, M, > }; + a_id!( impl_gen, impl_exp.params ); + a_id!( ty_gen, ty_exp.params ); + assert_eq!( impl_gen.len(), 2, "Impl generics should contain constants" ); assert_eq!( ty_gen.len(), 2, "Type generics should contain constants" ); assert!( where_gen.is_empty(), "Where generics should be empty" ); @@ -278,6 +301,11 @@ fn decompose_generics_with_default_values() let generics : syn::Generics = syn::parse_quote! { < T = usize, U = i32 > }; let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let impl_exp : syn::Generics = syn::parse_quote! { < T = usize, U = i32, > }; + let ty_exp : syn::Generics = syn::parse_quote! { < T, U, > }; + a_id!( impl_gen, impl_exp.params ); + a_id!( ty_gen, ty_exp.params ); + assert_eq!( impl_gen.len(), 2, "Impl generics should retain default types" ); assert_eq!( ty_gen.len(), 2, "Type generics should retain default types" ); assert!( where_gen.is_empty(), "Where generics should be empty" ); @@ -293,7 +321,6 @@ fn decompose_mixed_generics_types() let impl_exp : syn::Generics = syn::parse_quote! { < 'a, T, const N : usize, U : Trait1, > }; let ty_exp : syn::Generics = syn::parse_quote! { < 'a, T, N, U, > }; - a_id!( impl_gen, impl_exp.params ); a_id!( ty_gen, ty_exp.params ); From 18fd574814512746018ebf4ad2d7799b40fadeb5 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 08:54:08 +0300 Subject: [PATCH 181/533] macro_tools : improve decompose --- module/core/former_meta/src/derive/former.rs | 12 +- module/core/macro_tools/src/generic_params.rs | 119 ++++++++++++++++-- .../macro_tools/tests/inc/generic_params.rs | 2 +- 3 files changed, 119 insertions(+), 14 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index ef56de4958..2100f7b5e2 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1110,7 +1110,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > }; let generics_of_former = generic_params::merge( &generics, &extra.into() ); - let ( generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generics_of_former.split_for_impl(); + let ( generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generic_params::decompose( &generics_of_former ); + + // let ( generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generics_of_former.split_for_impl(); let generics_of_former_with_defaults = generics_of_former.params.clone(); // xxx : remove? // macro_tools::code_print!( generics_of_former_with_defaults ); // macro_tools::code_print!( extra ); @@ -1357,7 +1359,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ doc = #doc_former_struct ] pub struct #former < #generics_of_former_with_defaults > - #generics_of_former_where + where + #generics_of_former_where { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -1366,8 +1369,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } #[ automatically_derived ] - impl #generics_of_former_impl #former #generics_of_former_ty - #generics_of_former_where + impl < #generics_of_former_impl > #former < #generics_of_former_ty > + where + #generics_of_former_where { /// diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index c60a129b9b..946cd39ab2 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -327,7 +327,7 @@ pub( crate ) mod private pub fn decompose ( - generics : &syn::Generics + generics : &syn::Generics, ) -> ( @@ -336,17 +336,31 @@ pub( crate ) mod private syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, ) { - let mut generics_impl = generics.params.clone(); - punctuated::ensure_trailing_comma( &mut generics_impl ); - + let mut generics_impl = syn::punctuated::Punctuated::new(); let mut generics_ty = syn::punctuated::Punctuated::new(); + + // Process each generic parameter for param in &generics.params { match param { syn::GenericParam::Type( type_param ) => { - let simplified = syn::GenericParam::Type( syn::TypeParam + // Retain bounds for generics_impl, remove defaults + let impl_param = syn::GenericParam::Type( syn::TypeParam + { + attrs : vec![], + ident : type_param.ident.clone(), + colon_token : type_param.colon_token, + bounds : type_param.bounds.clone(), + eq_token : None, // Remove default token + default : None, // Remove default value + } ); + generics_impl.push_value( impl_param ); + generics_impl.push_punct( syn::token::Comma::default() ); + + // Simplify for generics_ty by removing all except identifiers + let ty_param = syn::GenericParam::Type( syn::TypeParam { attrs : vec![], ident : type_param.ident.clone(), @@ -354,13 +368,27 @@ pub( crate ) mod private bounds : syn::punctuated::Punctuated::new(), eq_token : None, default : None, - }); - generics_ty.push_value( simplified ); + } ); + generics_ty.push_value( ty_param ); generics_ty.push_punct( syn::token::Comma::default() ); }, syn::GenericParam::Const( const_param ) => { - let simplified = syn::GenericParam::Type( syn::TypeParam + // Simplify const parameters by removing all details except the identifier + let impl_param = syn::GenericParam::Const( syn::ConstParam + { + attrs : vec![], + const_token : const_param.const_token, + ident : const_param.ident.clone(), + colon_token : const_param.colon_token, + ty : const_param.ty.clone(), + eq_token : None, + default : None, + } ); + generics_impl.push_value( impl_param ); + generics_impl.push_punct( syn::token::Comma::default() ); + + let ty_param = syn::GenericParam::Type( syn::TypeParam { attrs : vec![], ident : const_param.ident.clone(), @@ -369,17 +397,21 @@ pub( crate ) mod private eq_token : None, default : None, }); - generics_ty.push_value( simplified ); + generics_ty.push_value( ty_param ); generics_ty.push_punct( syn::token::Comma::default() ); }, syn::GenericParam::Lifetime( lifetime_param ) => { + // Lifetimes are added as-is to both generics_impl and generics_ty + generics_impl.push_value( syn::GenericParam::Lifetime( lifetime_param.clone() ) ); + generics_impl.push_punct( syn::token::Comma::default() ); generics_ty.push_value( syn::GenericParam::Lifetime( lifetime_param.clone() ) ); generics_ty.push_punct( syn::token::Comma::default() ); } } } + // Clone where predicates if present, ensuring they end with a comma let generics_where = if let Some( where_clause ) = &generics.where_clause { let mut predicates = where_clause.predicates.clone(); @@ -394,6 +426,75 @@ pub( crate ) mod private ( generics_impl, generics_ty, generics_where ) } +// pub fn decompose +// ( +// generics : &syn::Generics +// ) +// -> +// ( +// syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, +// syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, +// syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, +// ) +// { +// let mut generics_impl = generics.params.clone(); +// punctuated::ensure_trailing_comma( &mut generics_impl ); +// +// let mut generics_ty = syn::punctuated::Punctuated::new(); +// for param in &generics.params +// { +// match param +// { +// syn::GenericParam::Type( type_param ) => +// { +// let simplified = syn::GenericParam::Type( syn::TypeParam +// { +// attrs : vec![], +// ident : type_param.ident.clone(), +// colon_token : None, +// bounds : syn::punctuated::Punctuated::new(), +// eq_token : None, +// default : None, +// }); +// generics_ty.push_value( simplified ); +// generics_ty.push_punct( syn::token::Comma::default() ); +// }, +// syn::GenericParam::Const( const_param ) => +// { +// let simplified = syn::GenericParam::Type( syn::TypeParam +// { +// attrs : vec![], +// ident : const_param.ident.clone(), +// colon_token : None, +// bounds : syn::punctuated::Punctuated::new(), +// eq_token : None, +// default : None, +// }); +// generics_ty.push_value( simplified ); +// generics_ty.push_punct( syn::token::Comma::default() ); +// }, +// syn::GenericParam::Lifetime( lifetime_param ) => +// { +// generics_ty.push_value( syn::GenericParam::Lifetime( lifetime_param.clone() ) ); +// generics_ty.push_punct( syn::token::Comma::default() ); +// } +// } +// } +// +// let generics_where = if let Some( where_clause ) = &generics.where_clause +// { +// let mut predicates = where_clause.predicates.clone(); +// punctuated::ensure_trailing_comma( &mut predicates ); +// predicates +// } +// else +// { +// syn::punctuated::Punctuated::new() +// }; +// +// ( generics_impl, generics_ty, generics_where ) +// } + } #[ doc( inline ) ] diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index 4c48c3e0cc..fbf87f39d0 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -301,7 +301,7 @@ fn decompose_generics_with_default_values() let generics : syn::Generics = syn::parse_quote! { < T = usize, U = i32 > }; let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); - let impl_exp : syn::Generics = syn::parse_quote! { < T = usize, U = i32, > }; + let impl_exp : syn::Generics = syn::parse_quote! { < T, U, > }; let ty_exp : syn::Generics = syn::parse_quote! { < T, U, > }; a_id!( impl_gen, impl_exp.params ); a_id!( ty_gen, ty_exp.params ); From 18356e1c2cc73d3c674d777df83cbe1da861f738 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 09:23:16 +0300 Subject: [PATCH 182/533] macro_tools : improve decompose --- .../former/tests/inc/former_tests/a_basic.rs | 1 + module/core/former_meta/src/derive/former.rs | 44 +++++--- module/core/macro_tools/src/generic_params.rs | 101 +++++++++--------- .../macro_tools/tests/inc/generic_params.rs | 22 ++-- 4 files changed, 92 insertions(+), 76 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic.rs b/module/core/former/tests/inc/former_tests/a_basic.rs index 31ec06d07d..1ec026c49b 100644 --- a/module/core/former/tests/inc/former_tests/a_basic.rs +++ b/module/core/former/tests/inc/former_tests/a_basic.rs @@ -11,6 +11,7 @@ pub struct Struct1 // = begin of generated + // = end of generated include!( "./only_test/basic.rs" ); diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 2100f7b5e2..2de948d74e 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1077,7 +1077,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /* generic parameters */ let generics = &ast.generics; - let ( generics_impl, generics_ty, generics_where ) = generic_params::decompose( generics ); + let ( generics_with_defaults, generics_impl, generics_ty, generics_where ) + = generic_params::decompose( generics ); // xxx : rid off // let ( generics_impl_, generics_ty_, generics_where_ ) = generics.split_for_impl(); @@ -1110,10 +1111,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > }; let generics_of_former = generic_params::merge( &generics, &extra.into() ); - let ( generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generic_params::decompose( &generics_of_former ); + let ( generics_of_former_with_defaults, generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) + = generic_params::decompose( &generics_of_former ); // let ( generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generics_of_former.split_for_impl(); - let generics_of_former_with_defaults = generics_of_former.params.clone(); // xxx : remove? + // let generics_of_former_with_defaults = generics_of_former.params.clone(); // xxx : remove? // macro_tools::code_print!( generics_of_former_with_defaults ); // macro_tools::code_print!( extra ); @@ -1123,7 +1125,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > < Context, Formed > }; let generics_of_definition_type = generic_params::merge( &generics, &extra.into() ); - let ( generics_of_definition_type_impl, generics_of_definition_type_ty, generics_of_definition_type_where ) = generics_of_definition_type.split_for_impl(); + let ( generics_of_definition_type_with_defaults, generics_of_definition_type_impl, generics_of_definition_type_ty, generics_of_definition_type_where ) + = generic_params::decompose( &generics_of_definition_type ); + + // let ( generics_of_definition_type_impl, generics_of_definition_type_ty, generics_of_definition_type_where ) = generics_of_definition_type.split_for_impl(); // xxx : rid off all split_for_impl, replacing them by generic_params::decompose /* parameters for definition */ @@ -1133,7 +1138,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > }; let generics_of_definition = generic_params::merge( &generics, &extra.into() ); // let ( generics_of_definition_impl, _generics_of_definition_ty, generics_of_definition_where ) = generics_of_definition.split_for_impl(); - let ( generics_of_definition_impl, generics_of_definition_ty, generics_of_definition_where ) = generic_params::decompose( &generics_of_definition ); + let ( generics_of_definition_with_defaults, generics_of_definition_impl, generics_of_definition_ty, generics_of_definition_where ) + = generic_params::decompose( &generics_of_definition ); /* structure attribute */ @@ -1230,16 +1236,18 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ derive( Debug ) ] // xxx : revert later // pub struct #former_definition_types< Context = (), Formed = #struct_name #generics_ty_ > - pub struct #former_definition_types #generics_of_definition_type_impl + // pub struct #former_definition_types #generics_of_definition_type_impl + pub struct #former_definition_types < #generics_of_definition_type_with_defaults > where #generics_of_definition_type_where { _phantom : core::marker::PhantomData< ( Context, Formed ) >, } - impl #generics_of_definition_type_impl Default - for #former_definition_types #generics_of_definition_type_ty - #generics_of_definition_type_where + impl < #generics_of_definition_type_impl > Default + for #former_definition_types < #generics_of_definition_type_ty > + where + #generics_of_definition_type_where { fn default() -> Self { @@ -1250,8 +1258,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } - impl #generics_of_definition_type_impl former::FormerDefinitionTypes - for #former_definition_types #generics_of_definition_type_ty + impl < #generics_of_definition_type_impl > former::FormerDefinitionTypes + for #former_definition_types < #generics_of_definition_type_ty > { type Storage = #former_storage < #generics_ty >; type Formed = Formed; @@ -1263,7 +1271,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ derive( Debug ) ] // xxx : revert later // pub struct #former_definition< Context = (), Formed = #struct_name #generics_ty_, End = former::ReturnPreformed > - pub struct #former_definition < #generics_of_definition_impl > + // pub struct #former_definition < #generics_of_definition_impl > + pub struct #former_definition < #generics_of_definition_with_defaults > where #generics_of_definition_where { @@ -1287,21 +1296,22 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl < #generics_of_definition_impl > former::FormerDefinition for #former_definition < #generics_of_definition_ty > where - End : former::FormingEnd< #former_definition_types #generics_of_definition_type_ty >, + End : former::FormingEnd< #former_definition_types < #generics_of_definition_type_ty > >, #generics_of_definition_where { - type Types = #former_definition_types #generics_of_definition_type_ty; + type Types = #former_definition_types < #generics_of_definition_type_ty >; type End = End; } - pub type #former_with_closure #generics_of_definition_type_ty = - #former_definition< Context, Formed, former::FormingEndClosure< #former_definition_types #generics_of_definition_type_ty > >; + pub type #former_with_closure < #generics_of_definition_type_ty > = + #former_definition< Context, Formed, former::FormingEndClosure< #former_definition_types < #generics_of_definition_type_ty > > >; // xxx2 : use unwrapped generics better // = storage #[ doc = "Container of a corresponding former." ] - pub struct #former_storage < #generics_ty > + // pub struct #former_storage < #generics_ty > + pub struct #former_storage < #generics_with_defaults > where #generics_where { diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index 946cd39ab2..5e3d9f1d28 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -193,7 +193,7 @@ pub( crate ) mod private // // add embedded generic parameters // let mut extra_generics : syn::Generics = parse_quote! // { -// < Definition = #former_definition < #generics_ty (), #struct_name, former::ReturnPreformed > > +// < Definition = #former_definition < #generics_for_ty (), #struct_name, former::ReturnPreformed > > // // Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, // // xxx // }; @@ -202,7 +202,7 @@ pub( crate ) mod private // { // where // Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_ty >, +// Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_for_ty >, // // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, // }; // @@ -282,23 +282,27 @@ pub( crate ) mod private result } - /// Decomposes `syn::Generics` into three parts suitable for use in implementing traits or types, - /// simplifying type and const parameters for type definitions. + /// Decomposes `syn::Generics` into components suitable for different usage contexts in Rust implementations, + /// specifically focusing on different requirements for `impl` blocks and type definitions. /// - /// This function clones generic parameters for use with `impl` declarations directly. For type - /// definitions, it simplifies type and const parameters to include only identifiers, removing - /// any associated bounds or default values. Where clauses are cloned as-is, with a check to ensure - /// they end with a comma if not empty. + /// This function prepares three versions of the generics: + /// - One preserving the full structure for `impl` declarations. + /// - One simplified for type definitions, removing bounds and defaults from type and const parameters, retaining only identifiers. + /// - One for the where clauses, if present, ensuring they are correctly punctuated. + /// + /// This helps in situations where you need different representations of generics for implementing traits, + /// defining types, or specifying trait bounds and conditions. /// /// # Examples /// /// ```rust - /// let code : syn::Generics = syn::parse_quote!{ < 'a, T, const N : usize, U : Trait1 > }; - /// let ( generics_impl, generics_ty, generics_where ) = macro_tools::generic_params::decompose( &code ); + /// let code : syn::Generics = syn::parse_quote!{ <'a, T, const N : usize, U : Trait1> }; + /// let ( generics_with_defaults, generics_for_impl, generics_for_ty, generics_where ) = macro_tools::generic_params::decompose( &code ); /// + /// // Use in a macro for generating code /// macro_tools::qt! /// { - /// impl < #generics_impl > MyTrait for Struct1 < #generics_ty > + /// impl < #generics_for_impl > MyTrait for Struct1 < #generics_for_ty > /// where /// #generics_where /// { @@ -307,13 +311,6 @@ pub( crate ) mod private /// }; /// ``` /// - /// # Usage - /// - /// - `generics_impl` : Retains full structure of the original generic parameters for use in `impl` blocks. - /// - `generics_ty` : Simplifies generic parameters for type declarations by stripping bounds and modifiers, - /// leaving only the identifiers. Lifetimes are included as is. - /// - `generics_where` : Directly clones where clauses if present and ensures they are properly punctuated. - /// /// # Arguments /// /// * `generics` - A reference to the `syn::Generics` to be decomposed. @@ -321,9 +318,10 @@ pub( crate ) mod private /// # Returns /// /// Returns a tuple containing: - /// - `syn::punctuated::Punctuated` : For use with `impl` blocks. - /// - `syn::punctuated::Punctuated` : For use with type definitions, simplified. - /// - `syn::punctuated::Punctuated` : For where clauses, properly punctuated. + /// - `syn::punctuated::Punctuated`: Original generics with defaults, used where full specification is needed. + /// - `syn::punctuated::Punctuated`: Generics for `impl` blocks, retaining bounds but no defaults. + /// - `syn::punctuated::Punctuated`: Simplified generics for type definitions, only identifiers. + /// - `syn::punctuated::Punctuated`: Where clauses, properly punctuated for use in where conditions. pub fn decompose ( @@ -331,13 +329,18 @@ pub( crate ) mod private ) -> ( + syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, ) { - let mut generics_impl = syn::punctuated::Punctuated::new(); - let mut generics_ty = syn::punctuated::Punctuated::new(); + + let mut generics_with_defaults = generics.params.clone(); + punctuated::ensure_trailing_comma( &mut generics_with_defaults ); + + let mut generics_for_impl = syn::punctuated::Punctuated::new(); + let mut generics_for_ty = syn::punctuated::Punctuated::new(); // Process each generic parameter for param in &generics.params @@ -346,7 +349,7 @@ pub( crate ) mod private { syn::GenericParam::Type( type_param ) => { - // Retain bounds for generics_impl, remove defaults + // Retain bounds for generics_for_impl, remove defaults let impl_param = syn::GenericParam::Type( syn::TypeParam { attrs : vec![], @@ -356,10 +359,10 @@ pub( crate ) mod private eq_token : None, // Remove default token default : None, // Remove default value } ); - generics_impl.push_value( impl_param ); - generics_impl.push_punct( syn::token::Comma::default() ); + generics_for_impl.push_value( impl_param ); + generics_for_impl.push_punct( syn::token::Comma::default() ); - // Simplify for generics_ty by removing all except identifiers + // Simplify for generics_for_ty by removing all except identifiers let ty_param = syn::GenericParam::Type( syn::TypeParam { attrs : vec![], @@ -369,8 +372,8 @@ pub( crate ) mod private eq_token : None, default : None, } ); - generics_ty.push_value( ty_param ); - generics_ty.push_punct( syn::token::Comma::default() ); + generics_for_ty.push_value( ty_param ); + generics_for_ty.push_punct( syn::token::Comma::default() ); }, syn::GenericParam::Const( const_param ) => { @@ -385,8 +388,8 @@ pub( crate ) mod private eq_token : None, default : None, } ); - generics_impl.push_value( impl_param ); - generics_impl.push_punct( syn::token::Comma::default() ); + generics_for_impl.push_value( impl_param ); + generics_for_impl.push_punct( syn::token::Comma::default() ); let ty_param = syn::GenericParam::Type( syn::TypeParam { @@ -397,16 +400,16 @@ pub( crate ) mod private eq_token : None, default : None, }); - generics_ty.push_value( ty_param ); - generics_ty.push_punct( syn::token::Comma::default() ); + generics_for_ty.push_value( ty_param ); + generics_for_ty.push_punct( syn::token::Comma::default() ); }, syn::GenericParam::Lifetime( lifetime_param ) => { - // Lifetimes are added as-is to both generics_impl and generics_ty - generics_impl.push_value( syn::GenericParam::Lifetime( lifetime_param.clone() ) ); - generics_impl.push_punct( syn::token::Comma::default() ); - generics_ty.push_value( syn::GenericParam::Lifetime( lifetime_param.clone() ) ); - generics_ty.push_punct( syn::token::Comma::default() ); + // Lifetimes are added as-is to both generics_for_impl and generics_for_ty + generics_for_impl.push_value( syn::GenericParam::Lifetime( lifetime_param.clone() ) ); + generics_for_impl.push_punct( syn::token::Comma::default() ); + generics_for_ty.push_value( syn::GenericParam::Lifetime( lifetime_param.clone() ) ); + generics_for_ty.push_punct( syn::token::Comma::default() ); } } } @@ -423,7 +426,7 @@ pub( crate ) mod private syn::punctuated::Punctuated::new() }; - ( generics_impl, generics_ty, generics_where ) + ( generics_with_defaults, generics_for_impl, generics_for_ty, generics_where ) } // pub fn decompose @@ -437,10 +440,10 @@ pub( crate ) mod private // syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, // ) // { -// let mut generics_impl = generics.params.clone(); -// punctuated::ensure_trailing_comma( &mut generics_impl ); +// let mut generics_for_impl = generics.params.clone(); +// punctuated::ensure_trailing_comma( &mut generics_for_impl ); // -// let mut generics_ty = syn::punctuated::Punctuated::new(); +// let mut generics_for_ty = syn::punctuated::Punctuated::new(); // for param in &generics.params // { // match param @@ -456,8 +459,8 @@ pub( crate ) mod private // eq_token : None, // default : None, // }); -// generics_ty.push_value( simplified ); -// generics_ty.push_punct( syn::token::Comma::default() ); +// generics_for_ty.push_value( simplified ); +// generics_for_ty.push_punct( syn::token::Comma::default() ); // }, // syn::GenericParam::Const( const_param ) => // { @@ -470,13 +473,13 @@ pub( crate ) mod private // eq_token : None, // default : None, // }); -// generics_ty.push_value( simplified ); -// generics_ty.push_punct( syn::token::Comma::default() ); +// generics_for_ty.push_value( simplified ); +// generics_for_ty.push_punct( syn::token::Comma::default() ); // }, // syn::GenericParam::Lifetime( lifetime_param ) => // { -// generics_ty.push_value( syn::GenericParam::Lifetime( lifetime_param.clone() ) ); -// generics_ty.push_punct( syn::token::Comma::default() ); +// generics_for_ty.push_value( syn::GenericParam::Lifetime( lifetime_param.clone() ) ); +// generics_for_ty.push_punct( syn::token::Comma::default() ); // } // } // } @@ -492,7 +495,7 @@ pub( crate ) mod private // syn::punctuated::Punctuated::new() // }; // -// ( generics_impl, generics_ty, generics_where ) +// ( generics_for_impl, generics_for_ty, generics_where ) // } } diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index fbf87f39d0..3d985461d6 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -131,7 +131,7 @@ fn names() fn decompose_empty_generics() { let generics : syn::Generics = syn::parse_quote! {}; - let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let ( _impl_with_def, impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); assert!( impl_gen.is_empty(), "Impl generics should be empty" ); assert!( ty_gen.is_empty(), "Type generics should be empty" ); @@ -142,7 +142,7 @@ fn decompose_empty_generics() fn decompose_generics_without_where_clause() { let generics : syn::Generics = syn::parse_quote! { < T, U > }; - let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let ( _impl_with_def, impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); assert_eq!( impl_gen.len(), 2, "Impl generics should have two parameters" ); assert_eq!( ty_gen.len(), 2, "Type generics should have two parameters" ); @@ -163,7 +163,7 @@ fn decompose_generics_with_where_clause() let generics : the_module::GenericsWithWhere = syn::parse_quote! { < T, U > where T : Clone, U : Default }; let generics = generics.unwrap(); - let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let ( _impl_with_def, impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); let impl_exp : syn::Generics = syn::parse_quote! { < T, U, > }; let ty_exp : syn::Generics = syn::parse_quote! { < T, U, > }; @@ -201,7 +201,7 @@ fn decompose_generics_with_only_where_clause() { let generics : the_module::GenericsWithWhere = syn::parse_quote! { where T : Clone, U : Default }; let generics = generics.unwrap(); - let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let ( _impl_with_def, impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); assert!( impl_gen.is_empty(), "Impl generics should be empty" ); assert!( ty_gen.is_empty(), "Type generics should be empty" ); @@ -214,7 +214,7 @@ fn decompose_generics_with_complex_constraints() use macro_tools::quote::ToTokens; let generics : the_module::GenericsWithWhere = syn::parse_quote! { < T : Clone + Send, U : Default > where T: Send, U: Default }; let generics = generics.unwrap(); - let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let ( _impl_with_def, impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); let impl_exp : syn::Generics = syn::parse_quote! { < T : Clone + Send, U : Default, > }; let ty_exp : syn::Generics = syn::parse_quote! { < T, U, > }; @@ -251,7 +251,7 @@ fn decompose_generics_with_complex_constraints() fn decompose_generics_with_nested_generic_types() { let generics : syn::Generics = syn::parse_quote! { < T : Iterator< Item = U >, U > }; - let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let ( _impl_with_def, impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); let impl_exp : syn::Generics = syn::parse_quote! { < T : Iterator< Item = U >, U, > }; let ty_exp : syn::Generics = syn::parse_quote! { < T, U, > }; @@ -267,7 +267,7 @@ fn decompose_generics_with_nested_generic_types() fn decompose_generics_with_lifetime_parameters_only() { let generics : syn::Generics = syn::parse_quote! { < 'a, 'b > }; - let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let ( _impl_with_def, impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); let impl_exp : syn::Generics = syn::parse_quote! { < 'a, 'b, > }; let ty_exp : syn::Generics = syn::parse_quote! { < 'a, 'b, > }; @@ -283,7 +283,7 @@ fn decompose_generics_with_lifetime_parameters_only() fn decompose_generics_with_constants_only() { let generics : syn::Generics = syn::parse_quote! { < const N : usize, const M : usize > }; - let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let ( _impl_with_def, impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); let impl_exp : syn::Generics = syn::parse_quote! { < const N : usize, const M : usize, > }; let ty_exp : syn::Generics = syn::parse_quote! { < N, M, > }; @@ -299,10 +299,12 @@ fn decompose_generics_with_constants_only() fn decompose_generics_with_default_values() { let generics : syn::Generics = syn::parse_quote! { < T = usize, U = i32 > }; - let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let ( impl_with_def, impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let impl_with_exp : syn::Generics = syn::parse_quote! { < T = usize, U = i32, > }; let impl_exp : syn::Generics = syn::parse_quote! { < T, U, > }; let ty_exp : syn::Generics = syn::parse_quote! { < T, U, > }; + a_id!( impl_with_def, impl_with_exp.params ); a_id!( impl_gen, impl_exp.params ); a_id!( ty_gen, ty_exp.params ); @@ -317,7 +319,7 @@ fn decompose_mixed_generics_types() use macro_tools::quote::ToTokens; let generics : the_module::GenericsWithWhere = syn::parse_quote! { < 'a, T, const N : usize, U : Trait1 > where T : Clone, U : Default }; let generics = generics.unwrap(); - let ( impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); + let ( _impl_with_def, impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); let impl_exp : syn::Generics = syn::parse_quote! { < 'a, T, const N : usize, U : Trait1, > }; let ty_exp : syn::Generics = syn::parse_quote! { < 'a, T, N, U, > }; From 04670b9c621b3b11f354ab5feccde5ffe6dda5de Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 09:25:42 +0300 Subject: [PATCH 183/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 34 +++----------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 2de948d74e..a144932bce 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1080,20 +1080,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( generics_with_defaults, generics_impl, generics_ty, generics_where ) = generic_params::decompose( generics ); - // xxx : rid off - // let ( generics_impl_, generics_ty_, generics_where_ ) = generics.split_for_impl(); - // let generics_ty_turbofish = generics_ty_.as_turbofish(); - // zzz : eliminate generic_params maybe - // let _generics_params = generic_params::names( generics ).params; - // let generic_params = if _generics_params.len() == 0 - // { - // qt!{} - // } - // else - // { - // qt!{ #_generics_params, } - // }; - + /* parameters for definition */ /* parameters for definition */ let extra : macro_tools::syn::AngleBracketedGenericArguments = parse_quote! { @@ -1114,11 +1101,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( generics_of_former_with_defaults, generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generic_params::decompose( &generics_of_former ); - // let ( generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) = generics_of_former.split_for_impl(); - // let generics_of_former_with_defaults = generics_of_former.params.clone(); // xxx : remove? - // macro_tools::code_print!( generics_of_former_with_defaults ); - // macro_tools::code_print!( extra ); - /* parameters for definition types */ let extra : macro_tools::GenericsWithWhere = parse_quote! { @@ -1128,16 +1110,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( generics_of_definition_type_with_defaults, generics_of_definition_type_impl, generics_of_definition_type_ty, generics_of_definition_type_where ) = generic_params::decompose( &generics_of_definition_type ); - // let ( generics_of_definition_type_impl, generics_of_definition_type_ty, generics_of_definition_type_where ) = generics_of_definition_type.split_for_impl(); - // xxx : rid off all split_for_impl, replacing them by generic_params::decompose - /* parameters for definition */ let extra : macro_tools::GenericsWithWhere = parse_quote! { < Context, Formed, End > }; let generics_of_definition = generic_params::merge( &generics, &extra.into() ); - // let ( generics_of_definition_impl, _generics_of_definition_ty, generics_of_definition_where ) = generics_of_definition.split_for_impl(); let ( generics_of_definition_with_defaults, generics_of_definition_impl, generics_of_definition_ty, generics_of_definition_where ) = generic_params::decompose( &generics_of_definition ); @@ -1235,9 +1213,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ derive( Debug ) ] // xxx : revert later - // pub struct #former_definition_types< Context = (), Formed = #struct_name #generics_ty_ > - // pub struct #former_definition_types #generics_of_definition_type_impl - pub struct #former_definition_types < #generics_of_definition_type_with_defaults > + pub struct #former_definition_types < #generics_of_definition_type_impl > + // pub struct #former_definition_types < #generics_of_definition_type_with_defaults > where #generics_of_definition_type_where { @@ -1270,9 +1247,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ derive( Debug ) ] // xxx : revert later - // pub struct #former_definition< Context = (), Formed = #struct_name #generics_ty_, End = former::ReturnPreformed > - // pub struct #former_definition < #generics_of_definition_impl > - pub struct #former_definition < #generics_of_definition_with_defaults > + // pub struct #former_definition < #generics_of_definition_with_defaults > + pub struct #former_definition < #generics_of_definition_impl > where #generics_of_definition_where { From 67425713f3c370506f9018c4c1323227231a13d7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 11:57:06 +0300 Subject: [PATCH 184/533] former : experimenting --- .../former/tests/inc/former_tests/a_basic.rs | 1 - .../tests/inc/former_tests/a_basic_manual.rs | 4 +- .../tests/inc/former_tests/string_slice.rs | 344 +++++++++--------- module/core/former_meta/src/derive/former.rs | 37 +- 4 files changed, 199 insertions(+), 187 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic.rs b/module/core/former/tests/inc/former_tests/a_basic.rs index 1ec026c49b..31ec06d07d 100644 --- a/module/core/former/tests/inc/former_tests/a_basic.rs +++ b/module/core/former/tests/inc/former_tests/a_basic.rs @@ -11,7 +11,6 @@ pub struct Struct1 // = begin of generated - // = end of generated include!( "./only_test/basic.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 095c3c1482..de5b1e47c8 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -16,9 +16,9 @@ impl Struct1 { #[ inline( always ) ] - pub fn former() -> Struct1Former< > + pub fn former() -> Struct1Former< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > { - Struct1Former::< >::new( former::ReturnPreformed ) + Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new( former::ReturnPreformed ) } } diff --git a/module/core/former/tests/inc/former_tests/string_slice.rs b/module/core/former/tests/inc/former_tests/string_slice.rs index b9ea5afe79..2d4e2a8255 100644 --- a/module/core/former/tests/inc/former_tests/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/string_slice.rs @@ -10,178 +10,180 @@ pub struct Struct1< 'a > // === begin of generated -#[automatically_derived] impl < 'a > Struct1 < 'a > -{ - #[doc = r""] - #[doc = - r" Make former, variation of builder pattern to form structure defining values of fields step by step."] - #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < 'a, > - { Struct1Former :: < 'a, > :: new(former :: ReturnPreformed) } -} #[derive(Debug)] pub struct Struct1FormerDefinitionTypes < 'a, Context, -Formed > { _phantom : core :: marker :: PhantomData < (Context, Formed) >, } -impl < 'a, Context, Formed > Default for Struct1FormerDefinitionTypes < 'a, -Context, Formed > -{ - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } -} impl < 'a, Context, Formed > former :: FormerDefinitionTypes for -Struct1FormerDefinitionTypes < 'a, Context, Formed > -{ - type Storage = Struct1FormerStorage < 'a > ; type Formed = Formed ; type - Context = Context ; -} #[derive(Debug)] pub struct Struct1FormerDefinition < 'a, Context, Formed, -End > { _phantom : core :: marker :: PhantomData < (Context, Formed, End) >, } -impl < 'a, Context, Formed, End > Default for Struct1FormerDefinition < 'a, -Context, Formed, End > -{ - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } -} impl < 'a, Context, Formed, End > former :: FormerDefinition for -Struct1FormerDefinition < 'a, Context, Formed, End > where End : former :: -FormingEnd < Struct1FormerDefinitionTypes < 'a, Context, Formed > >, -{ - type Types = Struct1FormerDefinitionTypes < 'a, Context, Formed > ; type - End = End ; -} - -pub type Struct1FormerWithClosure -< 'a, Context, Formed > = Struct1FormerDefinition < Context, Formed, former :: FormingEndClosure < -Struct1FormerDefinitionTypes < 'a, Context, Formed > > > ; - -#[doc = "Container of a corresponding former."] pub struct -Struct1FormerStorage < 'a > -{ - #[doc = r" A field"] pub string_slice_1 : :: core :: option :: Option < & - 'a str >, -} impl < 'a > :: core :: default :: Default for Struct1FormerStorage < 'a > -{ - #[inline(always)] fn default() -> Self - { Self { string_slice_1 : :: core :: option :: Option :: None, } } -} impl < 'a > former :: Storage for Struct1FormerStorage < 'a > -{ type Formed = Struct1 < 'a > ; } impl < 'a > former :: StoragePreform for -Struct1FormerStorage < 'a > -{ - fn preform(mut self) -> < Self as former :: Storage > :: Formed - { - let string_slice_1 = if self.string_slice_1.is_some() - { self.string_slice_1.take().unwrap() } else - { - { - trait MaybeDefault < T > - { - fn maybe_default(self : & Self) -> T - { panic! ("Field 'string_slice_1' isn't initialized") } - } impl < T > MaybeDefault < T > for & :: core :: marker :: - PhantomData < T > {} impl < T > MaybeDefault < T > for :: core - :: marker :: PhantomData < T > where T : :: core :: default :: - Default, - { fn maybe_default(self : & Self) -> T { T :: default() } } - (& :: core :: marker :: PhantomData :: < & 'a str - >).maybe_default() - } - } ; let result = Struct1 :: < 'a > { string_slice_1, } ; return result - ; - } -} -#[doc = -" Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -pub struct Struct1Former < 'a, Definition = Struct1FormerDefinition < 'a, (), -Struct1, former :: ReturnPreformed > > where Definition : former :: -FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -Storage = Struct1FormerStorage < 'a > >, -{ - storage : < Definition :: Types as former :: FormerDefinitionTypes > :: - Storage, context : core :: option :: Option < < Definition :: Types as - former :: FormerDefinitionTypes > :: Context >, on_end : core :: option :: - Option < Definition :: End >, -} #[automatically_derived] impl < 'a, Definition > Struct1Former < 'a, -Definition > where Definition : former :: FormerDefinition, Definition :: -Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < 'a -> >, -{ - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] - #[doc = - r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = - r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { let result = self.form() ; return result ; } #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn - _new_precise(on_end : Definition :: End) -> Self - { Self :: begin(None, None, on_end) } #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new < IntoEnd > (end : IntoEnd) -> - Self where IntoEnd : Into < Definition :: End >, - { Self :: begin(None, None, end,) } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn - _begin_precise(mut storage : core :: option :: Option < < Definition :: - Types as former :: FormerDefinitionTypes > :: Storage >, context : core :: - option :: Option < < Definition :: Types as former :: - FormerDefinitionTypes > :: Context >, on_end : < Definition as former :: - FormerDefinition > :: End,) -> Self - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()) ; } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: Some(on_end), - } - } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn begin < IntoEnd > - (mut storage : core :: option :: Option < < Definition :: Types as former - :: FormerDefinitionTypes > :: Storage >, context : core :: option :: - Option < < Definition :: Types as former :: FormerDefinitionTypes > :: - Context >, on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert - :: Into < < Definition as former :: FormerDefinition > :: End >, - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()) ; } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: - Some(:: core :: convert :: Into :: into(on_end)), - } - } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types - as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { - let on_end = self.on_end.take().unwrap() ; let context = - self.context.take() ; former :: FormingEnd :: < Definition :: Types > - :: call(& on_end, self.storage, context) - } #[doc = "Setter for the 'string_slice_1' field."] #[inline] pub fn - string_slice_1 < Src > (mut self, src : Src) -> Self where Src : :: core - :: convert :: Into < & 'a str >, - { - debug_assert! (self.storage.string_slice_1.is_none()) ; - self.storage.string_slice_1 = :: core :: option :: Option :: - Some(:: core :: convert :: Into :: into(src)) ; self - } -} impl < Definition > Struct1Former < Definition > where Definition : former -:: FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -Storage = Struct1FormerStorage < 'a >, Formed = Struct1 < 'a > >, < Definition -:: Types as former :: FormerDefinitionTypes > :: Storage : former :: -StoragePreform, < Definition :: Types as former :: FormerDefinitionTypes > :: -Storage : former :: Storage < Formed = Struct1 < 'a > >, -{ - pub fn preform(self) -> < Definition :: Types as former :: - FormerDefinitionTypes > :: Formed - { former :: StoragePreform :: preform(self.storage) } -} + #[automatically_derived] impl < 'a, > Struct1 < 'a, > where + { + #[doc = r""] + #[doc = + r" Make former, variation of builder pattern to form structure defining values of fields step by step."] + #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < 'a, + Definition, > + { Struct1Former :: < 'a, Definition, > :: new(former :: ReturnPreformed) } + } #[derive(Debug)] pub struct Struct1FormerDefinitionTypes < 'a, Context, + Formed, > where + { _phantom : core :: marker :: PhantomData < (Context, Formed) >, } impl < 'a, + Context, Formed, > Default for Struct1FormerDefinitionTypes < 'a, Context, + Formed, > where + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } impl < 'a, Context, Formed, > former :: FormerDefinitionTypes for + Struct1FormerDefinitionTypes < 'a, Context, Formed, > + { + type Storage = Struct1FormerStorage < 'a, > ; type Formed = Formed ; type + Context = Context ; + } #[derive(Debug)] pub struct Struct1FormerDefinition < 'a, Context, Formed, + End, > where + { _phantom : core :: marker :: PhantomData < (Context, Formed, End) >, } impl + < 'a, Context, Formed, End, > Default for Struct1FormerDefinition < 'a, + Context, Formed, End, > where + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } impl < 'a, Context, Formed, End, > former :: FormerDefinition for + Struct1FormerDefinition < 'a, Context, Formed, End, > where End : former :: + FormingEnd < Struct1FormerDefinitionTypes < 'a, Context, Formed, > >, + { + type Types = Struct1FormerDefinitionTypes < 'a, Context, Formed, > ; type + End = End ; + } pub type Struct1FormerWithClosure < 'a, Context, Formed, > = + Struct1FormerDefinition < 'a, Context, Formed, former :: FormingEndClosure < + Struct1FormerDefinitionTypes < 'a, Context, Formed, > > > ; + #[doc = "Container of a corresponding former."] pub struct + Struct1FormerStorage < 'a, > where + { + #[doc = r" A field"] pub string_slice_1 : :: core :: option :: Option < & + 'a str >, + } impl < 'a, > :: core :: default :: Default for Struct1FormerStorage < 'a, > + where + { + #[inline(always)] fn default() -> Self + { Self { string_slice_1 : :: core :: option :: Option :: None, } } + } impl < 'a, > former :: Storage for Struct1FormerStorage < 'a, > where + { type Formed = Struct1 < 'a, > ; } impl < 'a, > former :: StoragePreform for + Struct1FormerStorage < 'a, > where + { + fn preform(mut self) -> < Self as former :: Storage > :: Formed + { + let string_slice_1 = if self.string_slice_1.is_some() + { self.string_slice_1.take().unwrap() } else + { + { + trait MaybeDefault < T > + { + fn maybe_default(self : & Self) -> T + { panic! ("Field 'string_slice_1' isn't initialized") } + } impl < T > MaybeDefault < T > for & :: core :: marker :: + PhantomData < T > {} impl < T > MaybeDefault < T > for :: core + :: marker :: PhantomData < T > where T : :: core :: default :: + Default, + { fn maybe_default(self : & Self) -> T { T :: default() } } + (& :: core :: marker :: PhantomData :: < & 'a str + >).maybe_default() + } + } ; let result = Struct1 :: < 'a, > { string_slice_1, } ; return + result ; + } + } + #[doc = + " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] + pub struct Struct1Former < 'a, Definition = Struct1FormerDefinition < 'a, (), + Struct1 < 'a, >, former :: ReturnPreformed >, > where Definition : former :: + FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < + Storage = Struct1FormerStorage < 'a, > >, + { + storage : < Definition :: Types as former :: FormerDefinitionTypes > :: + Storage, context : core :: option :: Option < < Definition :: Types as + former :: FormerDefinitionTypes > :: Context >, on_end : core :: option :: + Option < Definition :: End >, + } #[automatically_derived] impl < 'a, Definition, > Struct1Former < 'a, + Definition, > where Definition : former :: FormerDefinition, Definition :: + Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < 'a, + > >, + { + #[doc = r""] + #[doc = r" Finish setting options and call perform on formed entity."] + #[doc = r""] + #[doc = + r" If `perform` defined then associated method is called and its result returned instead of entity."] + #[doc = + r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] + #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { let result = self.form() ; return result ; } #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn + _new_precise(on_end : Definition :: End) -> Self + { Self :: begin(None, None, on_end) } #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new < IntoEnd > (end : IntoEnd) -> + Self where IntoEnd : Into < Definition :: End >, + { Self :: begin(None, None, end,) } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn + _begin_precise(mut storage : core :: option :: Option < < Definition :: + Types as former :: FormerDefinitionTypes > :: Storage >, context : core :: + option :: Option < < Definition :: Types as former :: + FormerDefinitionTypes > :: Context >, on_end : < Definition as former :: + FormerDefinition > :: End,) -> Self + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()) ; } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: Some(on_end), + } + } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn begin < IntoEnd > + (mut storage : core :: option :: Option < < Definition :: Types as former + :: FormerDefinitionTypes > :: Storage >, context : core :: option :: + Option < < Definition :: Types as former :: FormerDefinitionTypes > :: + Context >, on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert + :: Into < < Definition as former :: FormerDefinition > :: End >, + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()) ; } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: + Some(:: core :: convert :: Into :: into(on_end)), + } + } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types + as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { + let on_end = self.on_end.take().unwrap() ; let context = + self.context.take() ; former :: FormingEnd :: < Definition :: Types > + :: call(& on_end, self.storage, context) + } #[doc = "Setter for the 'string_slice_1' field."] #[inline] pub fn + string_slice_1 < Src > (mut self, src : Src) -> Self where Src : :: core + :: convert :: Into < & 'a str >, + { + debug_assert! (self.storage.string_slice_1.is_none()) ; + self.storage.string_slice_1 = :: core :: option :: Option :: + Some(:: core :: convert :: Into :: into(src)) ; self + } + } impl < 'a, Definition, > Struct1Former < 'a, Definition, > where Definition + : former :: FormerDefinition, Definition :: Types : former :: + FormerDefinitionTypes < Storage = Struct1FormerStorage < 'a, >, Formed = + Struct1 < 'a, > >, < Definition :: Types as former :: FormerDefinitionTypes > + :: Storage : former :: StoragePreform, < Definition :: Types as former :: + FormerDefinitionTypes > :: Storage : former :: Storage < Formed = Struct1 < + 'a, > >, + { + pub fn preform(self) -> < Definition :: Types as former :: + FormerDefinitionTypes > :: Formed + { former :: StoragePreform :: preform(self.storage) } + } // === end of generated diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index a144932bce..13075cf850 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -852,6 +852,8 @@ fn fields_setter_callback_descriptor_map struct_name : &syn::Ident, former : &syn::Ident, former_storage : &syn::Ident, + generics_of_former_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + generics_of_former_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, // former_definition : &syn::Ident, ) -> @@ -882,9 +884,9 @@ Result< TokenStream > #[ allow( non_camel_case_types ) ] pub struct #field_forming_end; #[ automatically_derived ] - impl< Definition > former::FormingEnd + impl< #generics_of_former_impl > former::FormingEnd < - #subformer_definition < #( #params, )* #former< Definition >, #former< Definition >, former::NoEnd >, + #subformer_definition < #( #params, )* #former< #generics_of_former_ty >, #former< #generics_of_former_ty >, former::NoEnd >, > for #field_forming_end where @@ -899,9 +901,9 @@ Result< TokenStream > ( &self, storage : #field_ty, - super_former : Option< #former< Definition > >, + super_former : Option< #former< #generics_of_former_ty > >, ) - -> #former< Definition > + -> #former< #generics_of_former_ty > { let mut super_former = super_former.unwrap(); if let Some( ref mut field ) = super_former.storage.#ident @@ -1084,14 +1086,14 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /* parameters for definition */ let extra : macro_tools::syn::AngleBracketedGenericArguments = parse_quote! { - < (), #struct_name, former::ReturnPreformed > + < (), #struct_name < #generics_ty >, former::ReturnPreformed > }; - let generics_of_definition = generic_args::merge( &generics.into_generic_args(), &extra.into() ); + let args_of_definition = generic_args::merge( &generics.into_generic_args(), &extra.into() ).args; /* parameters for former */ let extra : macro_tools::GenericsWithWhere = parse_quote! { - < Definition = #former_definition #generics_of_definition > + < Definition = #former_definition < #args_of_definition > > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #generics_ty > >, @@ -1179,7 +1181,15 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field_form_map( former_field ), field_name_map( former_field ), field_setter_map( former_field, &struct_name ), - fields_setter_callback_descriptor_map( former_field, &struct_name, &former, &former_storage ), + fields_setter_callback_descriptor_map + ( + former_field, + &struct_name, + &former, + &former_storage, + &generics_of_former_impl, + &generics_of_former_ty, + ), )}).multiunzip(); let ( _doc_former_mod, doc_former_struct ) = doc_generate( struct_name ); @@ -1202,9 +1212,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// #[ inline( always ) ] - pub fn former() -> #former < #generics_ty > + pub fn former() -> #former < #former_definition< #args_of_definition > > { - #former :: < #generics_ty > :: new( former::ReturnPreformed ) + #former :: < #former_definition< #args_of_definition > > :: new( former::ReturnPreformed ) + } } @@ -1270,7 +1281,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } impl < #generics_of_definition_impl > former::FormerDefinition - for #former_definition < #generics_of_definition_ty > + for #former_definition < #generics_of_definition_ty > // xxx where End : former::FormingEnd< #former_definition_types < #generics_of_definition_type_ty > >, #generics_of_definition_where @@ -1280,7 +1291,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } pub type #former_with_closure < #generics_of_definition_type_ty > = - #former_definition< Context, Formed, former::FormingEndClosure< #former_definition_types < #generics_of_definition_type_ty > > >; + #former_definition< #generics_of_definition_type_ty former::FormingEndClosure< #former_definition_types < #generics_of_definition_type_ty > > >; // xxx2 : use unwrapped generics better // = storage @@ -1478,7 +1489,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = preform with Storage::preform - impl< Definition > #former< Definition > + impl< #generics_of_former_impl > #former< #generics_of_former_ty > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #generics_ty >, Formed = #struct_name < #generics_ty > >, From de73fa61436ae98ef923cf7ca10a0a1a65d8504d Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 12:20:52 +0300 Subject: [PATCH 185/533] former : experimenting --- .../tests/inc/former_tests/string_slice.rs | 21 ++- module/core/former_meta/src/derive/former.rs | 138 +++++++++--------- 2 files changed, 85 insertions(+), 74 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/string_slice.rs b/module/core/former/tests/inc/former_tests/string_slice.rs index 2d4e2a8255..449e6c6289 100644 --- a/module/core/former/tests/inc/former_tests/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/string_slice.rs @@ -10,24 +10,33 @@ pub struct Struct1< 'a > // === begin of generated - #[automatically_derived] impl < 'a, > Struct1 < 'a, > where { #[doc = r""] #[doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step."] #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < 'a, - Definition, > - { Struct1Former :: < 'a, Definition, > :: new(former :: ReturnPreformed) } - } #[derive(Debug)] pub struct Struct1FormerDefinitionTypes < 'a, Context, + Struct1FormerDefinition < 'a, (), Struct1 < 'a, >, former :: + ReturnPreformed > > + { + Struct1Former :: < 'a, Struct1FormerDefinition < 'a, (), Struct1 < 'a, + >, former :: ReturnPreformed > > :: new(former :: ReturnPreformed) + } + } + + #[derive(Debug)] pub struct Struct1FormerDefinitionTypes < 'a, Context, Formed, > where - { _phantom : core :: marker :: PhantomData < (Context, Formed) >, } impl < 'a, + { _phantom : core :: marker :: PhantomData < (Context, Formed) >, } + + impl < 'a, Context, Formed, > Default for Struct1FormerDefinitionTypes < 'a, Context, Formed, > where { fn default() -> Self { Self { _phantom : core :: marker :: PhantomData, } } - } impl < 'a, Context, Formed, > former :: FormerDefinitionTypes for + } + + impl < 'a, Context, Formed, > former :: FormerDefinitionTypes for Struct1FormerDefinitionTypes < 'a, Context, Formed, > { type Storage = Struct1FormerStorage < 'a, > ; type Formed = Formed ; type diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 13075cf850..6afd97dbf2 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -852,8 +852,8 @@ fn fields_setter_callback_descriptor_map struct_name : &syn::Ident, former : &syn::Ident, former_storage : &syn::Ident, - generics_of_former_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - generics_of_former_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, // former_definition : &syn::Ident, ) -> @@ -884,9 +884,9 @@ Result< TokenStream > #[ allow( non_camel_case_types ) ] pub struct #field_forming_end; #[ automatically_derived ] - impl< #generics_of_former_impl > former::FormingEnd + impl< #former_generics_impl > former::FormingEnd < - #subformer_definition < #( #params, )* #former< #generics_of_former_ty >, #former< #generics_of_former_ty >, former::NoEnd >, + #subformer_definition < #( #params, )* #former< #former_generics_ty >, #former< #former_generics_ty >, former::NoEnd >, > for #field_forming_end where @@ -901,9 +901,9 @@ Result< TokenStream > ( &self, storage : #field_ty, - super_former : Option< #former< #generics_of_former_ty > >, + super_former : Option< #former< #former_generics_ty > >, ) - -> #former< #generics_of_former_ty > + -> #former< #former_generics_ty > { let mut super_former = super_former.unwrap(); if let Some( ref mut field ) = super_former.storage.#ident @@ -1079,38 +1079,38 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /* generic parameters */ let generics = &ast.generics; - let ( generics_with_defaults, generics_impl, generics_ty, generics_where ) + let ( struct_generics_with_defaults, struct_generics_impl, struct_generics_ty, struct_generics_where ) = generic_params::decompose( generics ); /* parameters for definition */ /* parameters for definition */ let extra : macro_tools::syn::AngleBracketedGenericArguments = parse_quote! { - < (), #struct_name < #generics_ty >, former::ReturnPreformed > + < (), #struct_name < #struct_generics_ty >, former::ReturnPreformed > }; - let args_of_definition = generic_args::merge( &generics.into_generic_args(), &extra.into() ).args; + let former_definition_args = generic_args::merge( &generics.into_generic_args(), &extra.into() ).args; /* parameters for former */ let extra : macro_tools::GenericsWithWhere = parse_quote! { - < Definition = #former_definition < #args_of_definition > > + < Definition = #former_definition < #former_definition_args > > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #generics_ty > >, + Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #struct_generics_ty > >, }; - let generics_of_former = generic_params::merge( &generics, &extra.into() ); + let extra = generic_params::merge( &generics, &extra.into() ); - let ( generics_of_former_with_defaults, generics_of_former_impl, generics_of_former_ty, generics_of_former_where ) - = generic_params::decompose( &generics_of_former ); + let ( former_generics_with_defaults, former_generics_impl, former_generics_ty, former_generics_where ) + = generic_params::decompose( &extra ); /* parameters for definition types */ let extra : macro_tools::GenericsWithWhere = parse_quote! { < Context, Formed > }; - let generics_of_definition_type = generic_params::merge( &generics, &extra.into() ); - let ( generics_of_definition_type_with_defaults, generics_of_definition_type_impl, generics_of_definition_type_ty, generics_of_definition_type_where ) - = generic_params::decompose( &generics_of_definition_type ); + let former_definition_generics_type = generic_params::merge( &generics, &extra.into() ); + let ( former_definition_generics_type_with_defaults, former_definition_generics_type_impl, former_definition_generics_type_ty, former_definition_generics_type_where ) + = generic_params::decompose( &former_definition_generics_type ); /* parameters for definition */ let extra : macro_tools::GenericsWithWhere = parse_quote! @@ -1118,7 +1118,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > < Context, Formed, End > }; let generics_of_definition = generic_params::merge( &generics, &extra.into() ); - let ( generics_of_definition_with_defaults, generics_of_definition_impl, generics_of_definition_ty, generics_of_definition_where ) + let ( former_definition_generics_with_defaults, former_definition_generics_impl, former_definition_generics_ty, former_definition_generics_where ) = generic_params::decompose( &generics_of_definition ); /* structure attribute */ @@ -1127,7 +1127,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > ( &struct_name, // &former_definition, - // &generics_ty, + // &struct_generics_ty, ast.attrs.iter(), )?; @@ -1187,8 +1187,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > &struct_name, &former, &former_storage, - &generics_of_former_impl, - &generics_of_former_ty, + &former_generics_impl, + &former_generics_ty, ), )}).multiunzip(); @@ -1203,18 +1203,18 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = formed #[ automatically_derived ] - impl < #generics_impl > #struct_name < #generics_ty > + impl < #struct_generics_impl > #struct_name < #struct_generics_ty > where - #generics_where + #struct_generics_where { /// /// Make former, variation of builder pattern to form structure defining values of fields step by step. /// #[ inline( always ) ] - pub fn former() -> #former < #former_definition< #args_of_definition > > + pub fn former() -> #former < #struct_generics_impl #former_definition< #former_definition_args > > { - #former :: < #former_definition< #args_of_definition > > :: new( former::ReturnPreformed ) + #former :: < #struct_generics_impl #former_definition< #former_definition_args > > :: new( former::ReturnPreformed ) } @@ -1224,18 +1224,18 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ derive( Debug ) ] // xxx : revert later - pub struct #former_definition_types < #generics_of_definition_type_impl > - // pub struct #former_definition_types < #generics_of_definition_type_with_defaults > + pub struct #former_definition_types < #former_definition_generics_type_impl > + // pub struct #former_definition_types < #former_definition_generics_type_with_defaults > where - #generics_of_definition_type_where + #former_definition_generics_type_where { _phantom : core::marker::PhantomData< ( Context, Formed ) >, } - impl < #generics_of_definition_type_impl > Default - for #former_definition_types < #generics_of_definition_type_ty > + impl < #former_definition_generics_type_impl > Default + for #former_definition_types < #former_definition_generics_type_ty > where - #generics_of_definition_type_where + #former_definition_generics_type_where { fn default() -> Self { @@ -1246,10 +1246,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } - impl < #generics_of_definition_type_impl > former::FormerDefinitionTypes - for #former_definition_types < #generics_of_definition_type_ty > + impl < #former_definition_generics_type_impl > former::FormerDefinitionTypes + for #former_definition_types < #former_definition_generics_type_ty > { - type Storage = #former_storage < #generics_ty >; + type Storage = #former_storage < #struct_generics_ty >; type Formed = Formed; type Context = Context; } @@ -1258,18 +1258,18 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ derive( Debug ) ] // xxx : revert later - // pub struct #former_definition < #generics_of_definition_with_defaults > - pub struct #former_definition < #generics_of_definition_impl > + // pub struct #former_definition < #former_definition_generics_with_defaults > + pub struct #former_definition < #former_definition_generics_impl > where - #generics_of_definition_where + #former_definition_generics_where { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } - impl < #generics_of_definition_impl > Default - for #former_definition < #generics_of_definition_ty > + impl < #former_definition_generics_impl > Default + for #former_definition < #former_definition_generics_ty > where - #generics_of_definition_where + #former_definition_generics_where { fn default() -> Self { @@ -1280,27 +1280,29 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } - impl < #generics_of_definition_impl > former::FormerDefinition - for #former_definition < #generics_of_definition_ty > // xxx + impl < #former_definition_generics_impl > former::FormerDefinition + for #former_definition < #former_definition_generics_ty > // xxx where - End : former::FormingEnd< #former_definition_types < #generics_of_definition_type_ty > >, - #generics_of_definition_where + End : former::FormingEnd< #former_definition_types < #former_definition_generics_type_ty > >, + #former_definition_generics_where { - type Types = #former_definition_types < #generics_of_definition_type_ty >; + type Types = #former_definition_types < #former_definition_generics_type_ty >; type End = End; } - pub type #former_with_closure < #generics_of_definition_type_ty > = - #former_definition< #generics_of_definition_type_ty former::FormingEndClosure< #former_definition_types < #generics_of_definition_type_ty > > >; - // xxx2 : use unwrapped generics better + pub type #former_with_closure < #former_definition_generics_type_ty > = + #former_definition + < + #former_definition_generics_type_ty former::FormingEndClosure< #former_definition_types < #former_definition_generics_type_ty > > + >; // = storage #[ doc = "Container of a corresponding former." ] - // pub struct #former_storage < #generics_ty > - pub struct #former_storage < #generics_with_defaults > + // pub struct #former_storage < #struct_generics_ty > + pub struct #former_storage < #struct_generics_with_defaults > where - #generics_where + #struct_generics_where { #( /// A field @@ -1308,9 +1310,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > )* } - impl < #generics_impl > ::core::default::Default for #former_storage < #generics_ty > + impl < #struct_generics_impl > ::core::default::Default for #former_storage < #struct_generics_ty > where - #generics_where + #struct_generics_where { #[ inline( always ) ] @@ -1324,18 +1326,18 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } - impl < #generics_impl > former::Storage - for #former_storage < #generics_ty > + impl < #struct_generics_impl > former::Storage + for #former_storage < #struct_generics_ty > where - #generics_where + #struct_generics_where { - type Formed = #struct_name < #generics_ty >; + type Formed = #struct_name < #struct_generics_ty >; } - impl < #generics_impl > former::StoragePreform - for #former_storage < #generics_ty > + impl < #struct_generics_impl > former::StoragePreform + for #former_storage < #struct_generics_ty > where - #generics_where + #struct_generics_where { fn preform( mut self ) -> < Self as former::Storage >::Formed @@ -1343,7 +1345,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #( #fields_form )* // Rust does not support that, yet // let result = < Definition::Types as former::FormerDefinitionTypes >::Formed - let result = #struct_name :: < #generics_ty > + let result = #struct_name :: < #struct_generics_ty > { #( #fields_names, )* }; @@ -1355,9 +1357,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = former #[ doc = #doc_former_struct ] - pub struct #former < #generics_of_former_with_defaults > + pub struct #former < #former_generics_with_defaults > where - #generics_of_former_where + #former_generics_where { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -1366,9 +1368,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } #[ automatically_derived ] - impl < #generics_of_former_impl > #former < #generics_of_former_ty > + impl < #former_generics_impl > #former < #former_generics_ty > where - #generics_of_former_where + #former_generics_where { /// @@ -1489,12 +1491,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = preform with Storage::preform - impl< #generics_of_former_impl > #former< #generics_of_former_ty > + impl< #former_generics_impl > #former< #former_generics_ty > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #generics_ty >, Formed = #struct_name < #generics_ty > >, + Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #struct_generics_ty >, Formed = #struct_name < #struct_generics_ty > >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = #struct_name < #generics_ty > >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = #struct_name < #struct_generics_ty > >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed From 818e3daf93936cc3187c4e219157f50afd5d6d20 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 13:14:41 +0300 Subject: [PATCH 186/533] macro_tools : implement item::phantom_add --- module/core/macro_tools/src/generic_args.rs | 1 + module/core/macro_tools/src/generic_params.rs | 1 + module/core/macro_tools/src/item.rs | 169 ++++++++++++++++++ module/core/macro_tools/src/lib.rs | 9 +- module/core/macro_tools/tests/inc/item.rs | 30 ++++ module/core/macro_tools/tests/inc/mod.rs | 1 + 6 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 module/core/macro_tools/src/item.rs create mode 100644 module/core/macro_tools/tests/inc/item.rs diff --git a/module/core/macro_tools/src/generic_args.rs b/module/core/macro_tools/src/generic_args.rs index 4c41e8d33e..81cf77cd73 100644 --- a/module/core/macro_tools/src/generic_args.rs +++ b/module/core/macro_tools/src/generic_args.rs @@ -1,6 +1,7 @@ //! //! Manipulations on generic arguments. //! +//! xxx : update documentation of file /// Internal namespace. pub( crate ) mod private diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index 5e3d9f1d28..3eec786c34 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -19,6 +19,7 @@ //! K : core::hash::Hash + std::cmp::Eq, //! {} //!``` +//! xxx : update documentation of file /// Internal namespace. pub( crate ) mod private diff --git a/module/core/macro_tools/src/item.rs b/module/core/macro_tools/src/item.rs new file mode 100644 index 0000000000..a3e14ab0df --- /dev/null +++ b/module/core/macro_tools/src/item.rs @@ -0,0 +1,169 @@ +//! xxx : update documentation of file + +/// Internal namespace. +pub( crate ) mod private +{ + use super::super::*; + + pub fn phantom_add( input : &syn::ItemStruct ) -> syn::ItemStruct + { + use proc_macro2::Span; + + // Clone the input struct to work on a modifiable copy + let mut input = input.clone(); + + // Prepare the tuple type for PhantomData based on the struct's generics + let generics_tuple = if !input.generics.params.is_empty() + { + let generics_list = input.generics.params.iter().map( | param | + { + match param + { + syn::GenericParam::Type( type_param ) => + { + syn::Type::Path( syn::TypePath + { + qself : None, + path : type_param.ident.clone().into(), + }) + }, + syn::GenericParam::Lifetime( lifetime_param ) => + { + syn::Type::Path( syn::TypePath + { + qself : None, + path : lifetime_param.lifetime.ident.clone().into(), + }) + }, + syn::GenericParam::Const( const_param ) => + { + syn::Type::Path( syn::TypePath + { + qself : None, + path : const_param.ident.clone().into(), + }) + }, + } + }).collect::>(); + + syn::Type::Tuple( syn::TypeTuple + { + paren_token : syn::token::Paren( Span::call_site() ), + elems : generics_list, + }) + } + else + { + // Use unit type if there are no generics + syn::Type::Tuple( syn::TypeTuple + { + paren_token : syn::token::Paren( Span::call_site() ), + elems : syn::punctuated::Punctuated::new(), + }) + }; + + // Create the PhantomData field + let phantom_field = syn::Field + { + attrs : Vec::new(), + vis : syn::Visibility::Inherited, + ident : Some( syn::Ident::new( "_phantom", Span::call_site() ) ), + colon_token : Some( Default::default() ), + mutability : syn::FieldMutability::None, + ty : syn::Type::Path( syn::TypePath + { + qself : None, + path : syn::Path + { + leading_colon : None, + segments : + { + let mut segments = syn::punctuated::Punctuated::new(); + segments.push_value( syn::PathSegment + { + ident : syn::Ident::new( "std", Span::call_site() ), + arguments : syn::PathArguments::None, + }); + segments.push_punct( Default::default() ); + segments.push_value( syn::PathSegment + { + ident : syn::Ident::new( "marker", Span::call_site() ), + arguments : syn::PathArguments::None, + }); + segments.push_punct( Default::default() ); + segments.push_value( syn::PathSegment + { + ident : syn::Ident::new( "PhantomData", Span::call_site() ), + arguments : syn::PathArguments::AngleBracketed( syn::AngleBracketedGenericArguments + { + colon2_token : None, + lt_token : Default::default(), + args : syn::punctuated::Punctuated::from_iter( vec![ syn::GenericArgument::Type( generics_tuple )] ), + gt_token : Default::default(), + }), + }); + segments + }, + }, + }), + }; + + // Add the new field to the existing fields of the struct + if let syn::Fields::Named( ref mut fields ) = input.fields + { + fields.named.push( phantom_field ); + } + + input + } + +} + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + phantom_add, + }; +} + +// xxx : external attr instead of internal? +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + }; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + pub use super::protected as item; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super:: + { + prelude::*, + }; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/core/macro_tools/src/lib.rs b/module/core/macro_tools/src/lib.rs index 1f08d5ec3c..3cd03d4a5b 100644 --- a/module/core/macro_tools/src/lib.rs +++ b/module/core/macro_tools/src/lib.rs @@ -15,6 +15,7 @@ mod file pub mod generic_analyze; pub mod generic_args; pub mod generic_params; + pub mod item; pub mod name; pub mod punctuated; pub mod quantifier; @@ -51,7 +52,8 @@ pub mod protected { orphan::*, }; - + #[ doc( inline ) ] + #[ allow( unused_imports ) ] pub use super::file:: { attr::orphan::*, @@ -60,6 +62,7 @@ pub mod protected generic_analyze::orphan::*, generic_args::orphan::*, generic_params::orphan::*, + item::orphan::*, name::orphan::*, punctuated::orphan::*, quantifier::orphan::*, @@ -96,6 +99,8 @@ pub mod exposed { prelude::*, }; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] pub use super::file:: { attr::exposed::*, @@ -104,6 +109,7 @@ pub mod exposed generic_analyze::exposed::*, generic_args::exposed::*, generic_params::exposed::*, + item::exposed::*, name::exposed::*, punctuated::orphan::*, quantifier::exposed::*, @@ -167,6 +173,7 @@ pub mod prelude generic_analyze::prelude::*, generic_args::prelude::*, generic_params::prelude::*, + item::exposed::*, name::prelude::*, punctuated::orphan::*, quantifier::prelude::*, diff --git a/module/core/macro_tools/tests/inc/item.rs b/module/core/macro_tools/tests/inc/item.rs new file mode 100644 index 0000000000..52020a0a78 --- /dev/null +++ b/module/core/macro_tools/tests/inc/item.rs @@ -0,0 +1,30 @@ + +use super::*; + +// + +#[ test ] +fn basic() +{ + + let item : syn::Item = syn::parse_quote! + { + pub struct Struct1< 'a, Context, Formed > + { + f1 : int32, + } + }; + + let exp : syn::Item = syn::parse_quote! + { + pub struct Struct1FormerDefinitionTypes< 'a, Context, Formed > + { + f1 : int32, + _phantom : core::marker::PhantomData< ( &'a(), Context, Formed ) >, + } + } + + // let got = item::phantom_add( item ); + // a_id!( got, exp ); + +} diff --git a/module/core/macro_tools/tests/inc/mod.rs b/module/core/macro_tools/tests/inc/mod.rs index 223aa4b5b4..3f0a2dfb87 100644 --- a/module/core/macro_tools/tests/inc/mod.rs +++ b/module/core/macro_tools/tests/inc/mod.rs @@ -17,6 +17,7 @@ mod if_enabled mod basic; mod generic_args; mod generic_params; + mod item; mod quantifier; mod syntax; mod tokens; From cee84b3ecba397c26b55c4b8be90afed59d5bf2f Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 16:39:37 +0300 Subject: [PATCH 187/533] macro_tools : phantom_add --- module/core/macro_tools/src/item.rs | 67 +++++-- .../macro_tools/tests/inc/generic_params.rs | 3 +- module/core/macro_tools/tests/inc/item.rs | 164 +++++++++++++++++- 3 files changed, 215 insertions(+), 19 deletions(-) diff --git a/module/core/macro_tools/src/item.rs b/module/core/macro_tools/src/item.rs index a3e14ab0df..2b0d6f949f 100644 --- a/module/core/macro_tools/src/item.rs +++ b/module/core/macro_tools/src/item.rs @@ -5,9 +5,45 @@ pub( crate ) mod private { use super::super::*; + /// Adds a `PhantomData` field to a struct to manage generic parameter usage. + /// + /// This function clones a given `syn::ItemStruct`, calculates the appropriate `PhantomData` usage + /// based on the struct's generic parameters, and adds a corresponding `PhantomData` field. This field + /// helps in handling ownership and lifetime indications for generic parameters, ensuring that they + /// are correctly accounted for in type checking, even if they are not directly used in the struct's + /// fields. + /// + /// # Parameters + /// - `input`: A reference to the `syn::ItemStruct` which describes the structure to which the + /// `PhantomData` field will be added. + /// + /// # Returns + /// Returns a new `syn::ItemStruct` with the `PhantomData` field added to its list of fields. + /// + /// # Examples + /// ```rust + /// use syn::{ parse_quote, ItemStruct }; + /// use macro_tools::item::phantom_add; + /// + /// let input_struct: ItemStruct = parse_quote! + /// { + /// pub struct MyStruct< T, U > + /// { + /// data : T, + /// } + /// }; + /// + /// let modified_struct = phantom_add(&input_struct); + /// println!( "{:#?}", modified_struct ); + /// + /// // Output will include a _phantom field of type `PhantomData<(T, U)>` + /// ``` + /// + pub fn phantom_add( input : &syn::ItemStruct ) -> syn::ItemStruct { use proc_macro2::Span; + use syn::{ GenericParam, Type }; // Clone the input struct to work on a modifiable copy let mut input = input.clone(); @@ -19,25 +55,31 @@ pub( crate ) mod private { match param { - syn::GenericParam::Type( type_param ) => + GenericParam::Type( type_param ) => { - syn::Type::Path( syn::TypePath + Type::Path( syn::TypePath { qself : None, path : type_param.ident.clone().into(), }) }, - syn::GenericParam::Lifetime( lifetime_param ) => + GenericParam::Lifetime( lifetime_param ) => { - syn::Type::Path( syn::TypePath + Type::Reference( syn::TypeReference { - qself : None, - path : lifetime_param.lifetime.ident.clone().into(), + and_token : Default::default(), + lifetime : Some( lifetime_param.lifetime.clone() ), + mutability : None, + elem : Box::new( Type::Tuple( syn::TypeTuple + { + paren_token : syn::token::Paren( Span::call_site() ), + elems : syn::punctuated::Punctuated::new(), + })) }) }, - syn::GenericParam::Const( const_param ) => + GenericParam::Const( const_param ) => { - syn::Type::Path( syn::TypePath + Type::Path( syn::TypePath { qself : None, path : const_param.ident.clone().into(), @@ -46,7 +88,7 @@ pub( crate ) mod private } }).collect::>(); - syn::Type::Tuple( syn::TypeTuple + Type::Tuple( syn::TypeTuple { paren_token : syn::token::Paren( Span::call_site() ), elems : generics_list, @@ -55,7 +97,7 @@ pub( crate ) mod private else { // Use unit type if there are no generics - syn::Type::Tuple( syn::TypeTuple + Type::Tuple( syn::TypeTuple { paren_token : syn::token::Paren( Span::call_site() ), elems : syn::punctuated::Punctuated::new(), @@ -81,7 +123,7 @@ pub( crate ) mod private let mut segments = syn::punctuated::Punctuated::new(); segments.push_value( syn::PathSegment { - ident : syn::Ident::new( "std", Span::call_site() ), + ident : syn::Ident::new( "core", Span::call_site() ), arguments : syn::PathArguments::None, }); segments.push_punct( Default::default() ); @@ -108,10 +150,11 @@ pub( crate ) mod private }), }; - // Add the new field to the existing fields of the struct + // Add the new field to the existing fields of the struct, including a comma if let syn::Fields::Named( ref mut fields ) = input.fields { fields.named.push( phantom_field ); + fields.named.push_punct( Default::default() ); // Add the comma after the phantom field } input diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index 3d985461d6..d0bb3b0dbe 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -174,7 +174,7 @@ fn decompose_generics_with_where_clause() assert_eq!( ty_gen.len(), 2, "Type generics should have two parameters" ); assert_eq!( where_gen.len(), 2, "Where generics should have two predicates" ); - let where_clauses : Vec<_> = where_gen.iter().collect(); + let where_clauses : Vec< _ > = where_gen.iter().collect(); // Properly match against the `syn::WherePredicate::Type` variant to extract `bounded_ty` if let syn::WherePredicate::Type( pt ) = &where_clauses[0] @@ -206,6 +206,7 @@ fn decompose_generics_with_only_where_clause() assert!( impl_gen.is_empty(), "Impl generics should be empty" ); assert!( ty_gen.is_empty(), "Type generics should be empty" ); assert_eq!( where_gen.len(), 2, "Where generics should have two predicates" ); + } #[ test ] diff --git a/module/core/macro_tools/tests/inc/item.rs b/module/core/macro_tools/tests/inc/item.rs index 52020a0a78..793d6f295f 100644 --- a/module/core/macro_tools/tests/inc/item.rs +++ b/module/core/macro_tools/tests/inc/item.rs @@ -7,7 +7,7 @@ use super::*; fn basic() { - let item : syn::Item = syn::parse_quote! + let item : syn::ItemStruct = syn::parse_quote! { pub struct Struct1< 'a, Context, Formed > { @@ -15,16 +15,168 @@ fn basic() } }; - let exp : syn::Item = syn::parse_quote! + let exp : syn::ItemStruct = syn::parse_quote! { - pub struct Struct1FormerDefinitionTypes< 'a, Context, Formed > + pub struct Struct1< 'a, Context, Formed > { f1 : int32, _phantom : core::marker::PhantomData< ( &'a(), Context, Formed ) >, } - } + }; + + let got = the_module::item::phantom_add( &item ); + // a_id!( tree_print!( got ), tree_print!( exp ) ); + a_id!( got, exp ); + +} + +// + +#[ test ] +fn phantom_add_no_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct {} }; + let got = the_module::item::phantom_add( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct + { + _phantom : core::marker::PhantomData<()>, + // xxx : ? + } + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_type_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< T, U > {} }; + let got = the_module::item::phantom_add( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< T, U > + { + _phantom : core::marker::PhantomData< ( T, U ) >, + } + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_lifetime_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< 'a, 'b > {} }; + let got = the_module::item::phantom_add( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< 'a, 'b > + { + _phantom : core::marker::PhantomData< ( &'a (), &'b () ) >, + } + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_const_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< const N : usize > {} }; + let got = the_module::item::phantom_add( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< const N : usize > + { + _phantom : core::marker::PhantomData< ( N, ) >, + } + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_mixed_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< T, 'a, const N : usize > {} }; + let got = the_module::item::phantom_add( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< T, 'a, const N : usize > + { + _phantom : core::marker::PhantomData< ( T, &'a (), N ) >, + } + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_named_fields() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct { field1 : i32, field2 : f64 } }; + let got = the_module::item::phantom_add( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct + { + field1 : i32, + field2 : f64, + _phantom : core::marker::PhantomData< () >, + // xxx : ? + } + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_unnamed_fields() +{ + use syn::parse_quote; + use quote::ToTokens; - // let got = item::phantom_add( item ); - // a_id!( got, exp ); + let input : syn::ItemStruct = parse_quote! { struct TestStruct( i32, f64 ); }; + let got = the_module::item::phantom_add( &input ); + let exp : syn::ItemStruct = parse_quote! { struct TestStruct( i32, f64 ); }; + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); } From 3fcb85c10808956b5f682dc6b8a96b77a5ca3c4e Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 18:40:01 +0300 Subject: [PATCH 188/533] macro_tools : phantom_add --- module/core/macro_tools/src/item.rs | 217 +++++++++++++--------- module/core/macro_tools/tests/inc/item.rs | 194 ++++++++++++++++++- 2 files changed, 320 insertions(+), 91 deletions(-) diff --git a/module/core/macro_tools/src/item.rs b/module/core/macro_tools/src/item.rs index 2b0d6f949f..381c13526d 100644 --- a/module/core/macro_tools/src/item.rs +++ b/module/core/macro_tools/src/item.rs @@ -5,6 +5,78 @@ pub( crate ) mod private { use super::super::*; + /// Ensures the last field in a struct has a trailing comma. + /// + /// This function checks and modifies the fields of a given struct, `input`, ensuring that the last field, whether in + /// named or unnamed structs, ends with a trailing comma. This adjustment is commonly needed in macro-generated + /// code to maintain consistency and syntactical correctness across different struct types, including unit structs + /// which are unaffected as they do not contain fields. + /// + /// # Arguments + /// + /// * `input` - A reference to the struct (`syn::ItemStruct`) whose fields are to be checked and modified. + /// + /// # Returns + /// + /// Returns a modified clone of the input struct (`syn::ItemStruct`) where the last field in named or unnamed + /// structs has a trailing comma. Unit structs remain unchanged as they do not contain fields. + /// + /// # Examples + /// + /// ``` + /// use macro_tools:: + /// { + /// syn::{ parse_quote, ItemStruct }, + /// quote::quote, + /// }; + /// + /// // Create a struct using `parse_quote!` macro + /// let input_struct : ItemStruct = parse_quote! + /// { + /// struct Example + /// { + /// field1 : i32, + /// field2 : String + /// } + /// }; + /// + /// // Apply `ensure_comma` to ensure the last field has a trailing comma + /// let modified_struct = macro_tools::item::ensure_comma( &input_struct ); + /// + /// // Now `modified_struct` will have a trailing comma after `field2` + /// assert_eq!( quote!( #modified_struct ).to_string(), quote! + /// { + /// struct Example + /// { + /// field1 : i32, + /// field2 : String, + /// } + /// }.to_string() ); + /// ``` + + pub fn ensure_comma( input : &syn::ItemStruct ) -> syn::ItemStruct + { + let mut new_input = input.clone(); // Clone the input to modify it + + match &mut new_input.fields + { + // Handle named fields + syn::Fields::Named( syn::FieldsNamed { named, .. } ) => + { + punctuated::ensure_trailing_comma( named ) + }, + // Handle unnamed fields (tuples) + syn::Fields::Unnamed( syn::FieldsUnnamed { unnamed, .. } ) => + { + punctuated::ensure_trailing_comma( unnamed ) + }, + // Do nothing for unit structs + syn::Fields::Unit => {} + } + + new_input + } + /// Adds a `PhantomData` field to a struct to manage generic parameter usage. /// /// This function clones a given `syn::ItemStruct`, calculates the appropriate `PhantomData` usage @@ -45,117 +117,91 @@ pub( crate ) mod private use proc_macro2::Span; use syn::{ GenericParam, Type }; + // Only proceed if there are generics + if input.generics.params.is_empty() + { + return ensure_comma( input ); + } + // Clone the input struct to work on a modifiable copy let mut input = input.clone(); // Prepare the tuple type for PhantomData based on the struct's generics - let generics_tuple = if !input.generics.params.is_empty() + let generics_tuple_type = { let generics_list = input.generics.params.iter().map( | param | { match param { - GenericParam::Type( type_param ) => + GenericParam::Type( type_param ) => Type::Path( syn::TypePath { - Type::Path( syn::TypePath - { - qself : None, - path : type_param.ident.clone().into(), - }) - }, - GenericParam::Lifetime( lifetime_param ) => + qself : None, + path : type_param.ident.clone().into(), + }), + GenericParam::Lifetime( lifetime_param ) => Type::Reference( syn::TypeReference { - Type::Reference( syn::TypeReference + and_token : Default::default(), + lifetime : Some( lifetime_param.lifetime.clone() ), + mutability : None, + elem : Box::new( Type::Tuple( syn::TypeTuple { - and_token : Default::default(), - lifetime : Some( lifetime_param.lifetime.clone() ), - mutability : None, - elem : Box::new( Type::Tuple( syn::TypeTuple - { - paren_token : syn::token::Paren( Span::call_site() ), - elems : syn::punctuated::Punctuated::new(), - })) - }) - }, - GenericParam::Const( const_param ) => + paren_token : syn::token::Paren( Span::call_site() ), + elems : syn::punctuated::Punctuated::new(), + })), + }), + GenericParam::Const( const_param ) => Type::Path( syn::TypePath { - Type::Path( syn::TypePath - { - qself : None, - path : const_param.ident.clone().into(), - }) - }, + qself : None, + path : const_param.ident.clone().into(), + }), } - }).collect::>(); + }).collect::>(); Type::Tuple( syn::TypeTuple { paren_token : syn::token::Paren( Span::call_site() ), elems : generics_list, }) - } - else - { - // Use unit type if there are no generics - Type::Tuple( syn::TypeTuple - { - paren_token : syn::token::Paren( Span::call_site() ), - elems : syn::punctuated::Punctuated::new(), - }) }; - // Create the PhantomData field - let phantom_field = syn::Field + // Handle different field types: Named, Unnamed, or Unit + match &mut input.fields { - attrs : Vec::new(), - vis : syn::Visibility::Inherited, - ident : Some( syn::Ident::new( "_phantom", Span::call_site() ) ), - colon_token : Some( Default::default() ), - mutability : syn::FieldMutability::None, - ty : syn::Type::Path( syn::TypePath + syn::Fields::Named( fields ) => { - qself : None, - path : syn::Path + let phantom_field : syn::Field = syn::parse_quote! { - leading_colon : None, - segments : - { - let mut segments = syn::punctuated::Punctuated::new(); - segments.push_value( syn::PathSegment - { - ident : syn::Ident::new( "core", Span::call_site() ), - arguments : syn::PathArguments::None, - }); - segments.push_punct( Default::default() ); - segments.push_value( syn::PathSegment - { - ident : syn::Ident::new( "marker", Span::call_site() ), - arguments : syn::PathArguments::None, - }); - segments.push_punct( Default::default() ); - segments.push_value( syn::PathSegment - { - ident : syn::Ident::new( "PhantomData", Span::call_site() ), - arguments : syn::PathArguments::AngleBracketed( syn::AngleBracketedGenericArguments - { - colon2_token : None, - lt_token : Default::default(), - args : syn::punctuated::Punctuated::from_iter( vec![ syn::GenericArgument::Type( generics_tuple )] ), - gt_token : Default::default(), - }), - }); - segments - }, - }, - }), - }; + _phantom : core::marker::PhantomData< #generics_tuple_type > + }; - // Add the new field to the existing fields of the struct, including a comma - if let syn::Fields::Named( ref mut fields ) = input.fields - { - fields.named.push( phantom_field ); - fields.named.push_punct( Default::default() ); // Add the comma after the phantom field - } + // Ensure there is a trailing comma if fields are already present + if !fields.named.empty_or_trailing() + { + fields.named.push_punct( Default::default() ); + } + fields.named.push( phantom_field ); + fields.named.push_punct( Default::default() ); // Add trailing comma after adding PhantomData + }, + syn::Fields::Unnamed( fields ) => + { + let phantom_field : syn::Field = syn::parse_quote! + { + core::marker::PhantomData< #generics_tuple_type > + }; + + // Ensure there is a trailing comma if fields are already present + if !fields.unnamed.empty_or_trailing() + { + fields.unnamed.push_punct( Default::default() ); + } + fields.unnamed.push_value( phantom_field ); + fields.unnamed.push_punct( Default::default() ); // Ensure to add the trailing comma after PhantomData + }, + syn::Fields::Unit => + { + // No fields to modify in a unit struct + } + }; input } @@ -176,6 +222,7 @@ pub mod protected #[ allow( unused_imports ) ] pub use super::private:: { + ensure_comma, phantom_add, }; } diff --git a/module/core/macro_tools/tests/inc/item.rs b/module/core/macro_tools/tests/inc/item.rs index 793d6f295f..546182c286 100644 --- a/module/core/macro_tools/tests/inc/item.rs +++ b/module/core/macro_tools/tests/inc/item.rs @@ -1,10 +1,126 @@ use super::*; +#[ test ] +fn ensure_comma_named_struct_with_multiple_fields() +{ + use syn::{ parse_quote, ItemStruct }; + + let input_struct : ItemStruct = parse_quote! + { + struct Example + { + field1 : i32, + field2 : String + } + }; + + let got = the_module::item::ensure_comma( &input_struct ); + // let exp = "struct Example { field1 : i32, field2 : String, }"; + let exp : syn::ItemStruct = parse_quote! { struct Example { field1 : i32, field2 : String, } }; + // let got = quote!( #got ).to_string(); + // assert_eq!( exp, got ); + a_id!( got, exp ); + +} + +#[ test ] +fn ensure_comma_named_struct_with_single_field() +{ + use syn::{ parse_quote, ItemStruct }; + + let input_struct : ItemStruct = parse_quote! + { + struct Example + { + field1 : i32 + } + }; + + let got = the_module::item::ensure_comma( &input_struct ); + let exp : ItemStruct = parse_quote! { struct Example { field1 : i32, } }; + assert_eq!( got, exp ); +} + +#[ test ] +fn ensure_comma_named_struct_with_no_fields() +{ + use syn::{ parse_quote, ItemStruct }; + + let input_struct : ItemStruct = parse_quote! + { + struct Example { } + }; + + let got = the_module::item::ensure_comma( &input_struct ); + let exp : ItemStruct = parse_quote! { struct Example { } }; + assert_eq!( got, exp ); +} + +#[ test ] +fn ensure_comma_unnamed_struct_with_multiple_fields() +{ + use syn::{ parse_quote, ItemStruct }; + + let input_struct : ItemStruct = parse_quote! + { + struct Example( i32, String ); + }; + + let got = the_module::item::ensure_comma( &input_struct ); + let exp : ItemStruct = parse_quote! { struct Example( i32, String, ); }; + assert_eq!( got, exp ); +} + +#[ test ] +fn ensure_comma_unnamed_struct_with_single_field() +{ + use syn::{ parse_quote, ItemStruct }; + + let input_struct : ItemStruct = parse_quote! + { + struct Example( i32 ); + }; + + let got = the_module::item::ensure_comma( &input_struct ); + let exp : ItemStruct = parse_quote! { struct Example( i32, ); }; + assert_eq!( got, exp ); +} + +#[ test ] +fn ensure_comma_unnamed_struct_with_no_fields() +{ + use syn::{ parse_quote, ItemStruct }; + + let input_struct : ItemStruct = parse_quote! + { + struct Example( ); + }; + + let got = the_module::item::ensure_comma( &input_struct ); + let exp : ItemStruct = parse_quote! { struct Example( ); }; + assert_eq!( got, exp ); +} + +#[ test ] +fn ensure_comma_unit_struct_with_no_fields() +{ + use syn::{ parse_quote, ItemStruct }; + + let input_struct : ItemStruct = parse_quote! + { + struct Example; + }; + + let got = the_module::item::ensure_comma( &input_struct ); + let exp : ItemStruct = parse_quote! { struct Example; }; + assert_eq!( got, exp ); +} + // #[ test ] -fn basic() +fn phantom_add_basic() { let item : syn::ItemStruct = syn::parse_quote! @@ -45,8 +161,6 @@ fn phantom_add_no_generics() { struct TestStruct { - _phantom : core::marker::PhantomData<()>, - // xxx : ? } }; @@ -158,8 +272,6 @@ fn phantom_add_named_fields() { field1 : i32, field2 : f64, - _phantom : core::marker::PhantomData< () >, - // xxx : ? } }; @@ -176,7 +288,77 @@ fn phantom_add_unnamed_fields() let input : syn::ItemStruct = parse_quote! { struct TestStruct( i32, f64 ); }; let got = the_module::item::phantom_add( &input ); - let exp : syn::ItemStruct = parse_quote! { struct TestStruct( i32, f64 ); }; + let exp : syn::ItemStruct = parse_quote! { struct TestStruct( i32, f64, ); }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_unnamed_fields_with_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< T, U >( T, U ); }; + let got = the_module::item::phantom_add( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< T, U > + ( + T, U, + core::marker::PhantomData< ( T, U ) >, + ); + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_unnamed_fields_lifetime_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< 'a, 'b >( &'a i32, &'b f64 ); }; + let got = the_module::item::phantom_add( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< 'a, 'b > + ( + &'a i32, + &'b f64, + core::marker::PhantomData< ( &'a (), &'b () ) >, + ); + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_unnamed_fields_const_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< const N : usize >( [ i32 ; N ] ); }; + let got = the_module::item::phantom_add( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< const N : usize > + ( + [ i32 ; N ], + core::marker::PhantomData< ( N, ) >, + ); + }; assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); } From 0464f0b9fe603ddc25ab4a28bfcc6494adcbd475 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 21:06:24 +0300 Subject: [PATCH 189/533] macro_tools: phantom generator --- module/core/macro_tools/src/item.rs | 130 -------- module/core/macro_tools/src/lib.rs | 10 +- module/core/macro_tools/src/phantom.rs | 223 ++++++++++++++ module/core/macro_tools/tests/inc/item.rs | 246 --------------- module/core/macro_tools/tests/inc/mod.rs | 1 + module/core/macro_tools/tests/inc/phantom.rs | 298 +++++++++++++++++++ 6 files changed, 529 insertions(+), 379 deletions(-) create mode 100644 module/core/macro_tools/src/phantom.rs create mode 100644 module/core/macro_tools/tests/inc/phantom.rs diff --git a/module/core/macro_tools/src/item.rs b/module/core/macro_tools/src/item.rs index 381c13526d..64897375e7 100644 --- a/module/core/macro_tools/src/item.rs +++ b/module/core/macro_tools/src/item.rs @@ -77,135 +77,6 @@ pub( crate ) mod private new_input } - /// Adds a `PhantomData` field to a struct to manage generic parameter usage. - /// - /// This function clones a given `syn::ItemStruct`, calculates the appropriate `PhantomData` usage - /// based on the struct's generic parameters, and adds a corresponding `PhantomData` field. This field - /// helps in handling ownership and lifetime indications for generic parameters, ensuring that they - /// are correctly accounted for in type checking, even if they are not directly used in the struct's - /// fields. - /// - /// # Parameters - /// - `input`: A reference to the `syn::ItemStruct` which describes the structure to which the - /// `PhantomData` field will be added. - /// - /// # Returns - /// Returns a new `syn::ItemStruct` with the `PhantomData` field added to its list of fields. - /// - /// # Examples - /// ```rust - /// use syn::{ parse_quote, ItemStruct }; - /// use macro_tools::item::phantom_add; - /// - /// let input_struct: ItemStruct = parse_quote! - /// { - /// pub struct MyStruct< T, U > - /// { - /// data : T, - /// } - /// }; - /// - /// let modified_struct = phantom_add(&input_struct); - /// println!( "{:#?}", modified_struct ); - /// - /// // Output will include a _phantom field of type `PhantomData<(T, U)>` - /// ``` - /// - - pub fn phantom_add( input : &syn::ItemStruct ) -> syn::ItemStruct - { - use proc_macro2::Span; - use syn::{ GenericParam, Type }; - - // Only proceed if there are generics - if input.generics.params.is_empty() - { - return ensure_comma( input ); - } - - // Clone the input struct to work on a modifiable copy - let mut input = input.clone(); - - // Prepare the tuple type for PhantomData based on the struct's generics - let generics_tuple_type = - { - let generics_list = input.generics.params.iter().map( | param | - { - match param - { - GenericParam::Type( type_param ) => Type::Path( syn::TypePath - { - qself : None, - path : type_param.ident.clone().into(), - }), - GenericParam::Lifetime( lifetime_param ) => Type::Reference( syn::TypeReference - { - and_token : Default::default(), - lifetime : Some( lifetime_param.lifetime.clone() ), - mutability : None, - elem : Box::new( Type::Tuple( syn::TypeTuple - { - paren_token : syn::token::Paren( Span::call_site() ), - elems : syn::punctuated::Punctuated::new(), - })), - }), - GenericParam::Const( const_param ) => Type::Path( syn::TypePath - { - qself : None, - path : const_param.ident.clone().into(), - }), - } - }).collect::>(); - - Type::Tuple( syn::TypeTuple - { - paren_token : syn::token::Paren( Span::call_site() ), - elems : generics_list, - }) - }; - - // Handle different field types: Named, Unnamed, or Unit - match &mut input.fields - { - syn::Fields::Named( fields ) => - { - let phantom_field : syn::Field = syn::parse_quote! - { - _phantom : core::marker::PhantomData< #generics_tuple_type > - }; - - // Ensure there is a trailing comma if fields are already present - if !fields.named.empty_or_trailing() - { - fields.named.push_punct( Default::default() ); - } - fields.named.push( phantom_field ); - fields.named.push_punct( Default::default() ); // Add trailing comma after adding PhantomData - }, - syn::Fields::Unnamed( fields ) => - { - let phantom_field : syn::Field = syn::parse_quote! - { - core::marker::PhantomData< #generics_tuple_type > - }; - - // Ensure there is a trailing comma if fields are already present - if !fields.unnamed.empty_or_trailing() - { - fields.unnamed.push_punct( Default::default() ); - } - fields.unnamed.push_value( phantom_field ); - fields.unnamed.push_punct( Default::default() ); // Ensure to add the trailing comma after PhantomData - }, - syn::Fields::Unit => - { - // No fields to modify in a unit struct - } - }; - - input - } - } #[ doc( inline ) ] @@ -223,7 +94,6 @@ pub mod protected pub use super::private:: { ensure_comma, - phantom_add, }; } diff --git a/module/core/macro_tools/src/lib.rs b/module/core/macro_tools/src/lib.rs index 3cd03d4a5b..2d1977760c 100644 --- a/module/core/macro_tools/src/lib.rs +++ b/module/core/macro_tools/src/lib.rs @@ -17,6 +17,7 @@ mod file pub mod generic_params; pub mod item; pub mod name; + pub mod phantom; pub mod punctuated; pub mod quantifier; pub mod tokens; @@ -64,6 +65,7 @@ pub mod protected generic_params::orphan::*, item::orphan::*, name::orphan::*, + phantom::orphan::*, punctuated::orphan::*, quantifier::orphan::*, tokens::orphan::*, @@ -111,7 +113,8 @@ pub mod exposed generic_params::exposed::*, item::exposed::*, name::exposed::*, - punctuated::orphan::*, + phantom::exposed::*, + punctuated::exposed::*, quantifier::exposed::*, tokens::exposed::*, typ::exposed::*, @@ -173,9 +176,10 @@ pub mod prelude generic_analyze::prelude::*, generic_args::prelude::*, generic_params::prelude::*, - item::exposed::*, + item::prelude::*, name::prelude::*, - punctuated::orphan::*, + phantom::prelude::*, + punctuated::prelude::*, quantifier::prelude::*, tokens::prelude::*, typ::prelude::*, diff --git a/module/core/macro_tools/src/phantom.rs b/module/core/macro_tools/src/phantom.rs new file mode 100644 index 0000000000..8a34b35ad0 --- /dev/null +++ b/module/core/macro_tools/src/phantom.rs @@ -0,0 +1,223 @@ +//! xxx : update documentation of file + +/// Internal namespace. +pub( crate ) mod private +{ + use super::super::*; + + /// Adds a `PhantomData` field to a struct to manage generic parameter usage. + /// + /// This function clones a given `syn::ItemStruct`, calculates the appropriate `PhantomData` usage + /// based on the struct's generic parameters, and adds a corresponding `PhantomData` field. This field + /// helps in handling ownership and lifetime indications for generic parameters, ensuring that they + /// are correctly accounted for in type checking, even if they are not directly used in the struct's + /// fields. + /// + /// # Parameters + /// - `input`: A reference to the `syn::ItemStruct` which describes the structure to which the + /// `PhantomData` field will be added. + /// + /// # Returns + /// Returns a new `syn::ItemStruct` with the `PhantomData` field added to its list of fields. + /// + /// # Examples + /// ```rust + /// use syn::{ parse_quote, ItemStruct }; + /// + /// let input_struct: ItemStruct = parse_quote! + /// { + /// pub struct MyStruct< T, U > + /// { + /// data : T, + /// } + /// }; + /// + /// let modified_struct = macro_tools::phantom::add_to_item( &input_struct ); + /// println!( "{:#?}", modified_struct ); + /// + /// // Output will include a _phantom field of type `PhantomData< ( T, U ) >` + /// ``` + /// + + pub fn add_to_item( input : &syn::ItemStruct ) -> syn::ItemStruct + { + + // Only proceed if there are generics + if input.generics.params.is_empty() + { + return item::ensure_comma( input ); + } + + // Clone the input struct to work on a modifiable copy + let mut input = input.clone(); + + // Prepare the tuple type for PhantomData based on the struct's generics + let phantom = tuple( &input.generics.params ); + + // Handle different field types: Named, Unnamed, or Unit + match &mut input.fields + { + syn::Fields::Named( fields ) => + { + let phantom_field : syn::Field = syn::parse_quote! + { + _phantom : #phantom + }; + + // Ensure there is a trailing comma if fields are already present + if !fields.named.empty_or_trailing() + { + fields.named.push_punct( Default::default() ); + } + fields.named.push( phantom_field ); + fields.named.push_punct( Default::default() ); // Add trailing comma after adding PhantomData + }, + syn::Fields::Unnamed( fields ) => + { + let phantom_field : syn::Field = syn::parse_quote! + { + #phantom + }; + + // Ensure there is a trailing comma if fields are already present + if !fields.unnamed.empty_or_trailing() + { + fields.unnamed.push_punct( Default::default() ); + } + fields.unnamed.push_value( phantom_field ); + fields.unnamed.push_punct( Default::default() ); // Ensure to add the trailing comma after PhantomData + }, + syn::Fields::Unit => + { + // No fields to modify in a unit struct + } + }; + + input + } + + /// Constructs a `PhantomData` type tuple from the generic parameters of a struct. + /// + /// This function generates a tuple type for `PhantomData` using the given generic parameters, + /// which includes types, lifetimes, and const generics. It ensures that the generated tuple + /// use all parameters. + /// + /// # Parameters + /// - `input`: A reference to a `Punctuated< GenericParam, Comma>` containing the generic parameters. + /// + /// # Returns + /// Returns a `syn::Type` that represents a `PhantomData` tuple incorporating all the generic parameters. + /// + /// # Examples + /// ```rust + /// use syn::{parse_quote, punctuated::Punctuated, GenericParam, token::Comma}; + /// use macro_tools::phantom::tuple; + /// + /// let generics: Punctuated< GenericParam, Comma > = parse_quote! { T, 'a, const N : usize }; + /// let phantom_type = tuple( &generics ); + /// println!( "{}", quote::quote! { #phantom_type } ); + /// // Output: core::marker::PhantomData< ( T, &'a (), N ) > + /// ``` + /// + pub fn tuple( input : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma > ) -> syn::Type + { + use proc_macro2::Span; + use syn::{ GenericParam, Type }; + + // Prepare the tuple type for PhantomData based on the struct's generics + let generics_tuple_type = + { + let generics_list = input.iter().map( | param | + { + match param + { + GenericParam::Type( type_param ) => Type::Path( syn::TypePath + { + qself : None, + path : type_param.ident.clone().into(), + }), + GenericParam::Lifetime( lifetime_param ) => Type::Reference( syn::TypeReference + { + and_token : Default::default(), + lifetime : Some( lifetime_param.lifetime.clone() ), + mutability : None, + elem : Box::new( Type::Tuple( syn::TypeTuple + { + paren_token : syn::token::Paren( Span::call_site() ), + elems : syn::punctuated::Punctuated::new(), + })), + }), + GenericParam::Const( const_param ) => Type::Path( syn::TypePath + { + qself : None, + path : const_param.ident.clone().into(), + }), + } + }).collect::>(); + + Type::Tuple( syn::TypeTuple + { + paren_token : syn::token::Paren( Span::call_site() ), + elems : generics_list, + }) + }; + + let result : syn::Type = syn::parse_quote! + { + core::marker::PhantomData< #generics_tuple_type > + }; + + result + } + +} + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + add_to_item, + tuple, + }; +} + +// xxx : external attr instead of internal? +/// Orphan namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + }; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + pub use super::protected as phantom; + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super:: + { + prelude::*, + }; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ +} diff --git a/module/core/macro_tools/tests/inc/item.rs b/module/core/macro_tools/tests/inc/item.rs index 546182c286..a9652f81cd 100644 --- a/module/core/macro_tools/tests/inc/item.rs +++ b/module/core/macro_tools/tests/inc/item.rs @@ -116,249 +116,3 @@ fn ensure_comma_unit_struct_with_no_fields() let exp : ItemStruct = parse_quote! { struct Example; }; assert_eq!( got, exp ); } - -// - -#[ test ] -fn phantom_add_basic() -{ - - let item : syn::ItemStruct = syn::parse_quote! - { - pub struct Struct1< 'a, Context, Formed > - { - f1 : int32, - } - }; - - let exp : syn::ItemStruct = syn::parse_quote! - { - pub struct Struct1< 'a, Context, Formed > - { - f1 : int32, - _phantom : core::marker::PhantomData< ( &'a(), Context, Formed ) >, - } - }; - - let got = the_module::item::phantom_add( &item ); - // a_id!( tree_print!( got ), tree_print!( exp ) ); - a_id!( got, exp ); - -} - -// - -#[ test ] -fn phantom_add_no_generics() -{ - use syn::parse_quote; - use quote::ToTokens; - - let input : syn::ItemStruct = parse_quote! { struct TestStruct {} }; - let got = the_module::item::phantom_add( &input ); - - let exp : syn::ItemStruct = parse_quote! - { - struct TestStruct - { - } - }; - - assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); -} - -// - -#[ test ] -fn phantom_add_type_generics() -{ - use syn::parse_quote; - use quote::ToTokens; - - let input : syn::ItemStruct = parse_quote! { struct TestStruct< T, U > {} }; - let got = the_module::item::phantom_add( &input ); - - let exp : syn::ItemStruct = parse_quote! - { - struct TestStruct< T, U > - { - _phantom : core::marker::PhantomData< ( T, U ) >, - } - }; - - assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); -} - -// - -#[ test ] -fn phantom_add_lifetime_generics() -{ - use syn::parse_quote; - use quote::ToTokens; - - let input : syn::ItemStruct = parse_quote! { struct TestStruct< 'a, 'b > {} }; - let got = the_module::item::phantom_add( &input ); - - let exp : syn::ItemStruct = parse_quote! - { - struct TestStruct< 'a, 'b > - { - _phantom : core::marker::PhantomData< ( &'a (), &'b () ) >, - } - }; - - assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); -} - -// - -#[ test ] -fn phantom_add_const_generics() -{ - use syn::parse_quote; - use quote::ToTokens; - - let input : syn::ItemStruct = parse_quote! { struct TestStruct< const N : usize > {} }; - let got = the_module::item::phantom_add( &input ); - - let exp : syn::ItemStruct = parse_quote! - { - struct TestStruct< const N : usize > - { - _phantom : core::marker::PhantomData< ( N, ) >, - } - }; - - assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); -} - -// - -#[ test ] -fn phantom_add_mixed_generics() -{ - use syn::parse_quote; - use quote::ToTokens; - - let input : syn::ItemStruct = parse_quote! { struct TestStruct< T, 'a, const N : usize > {} }; - let got = the_module::item::phantom_add( &input ); - - let exp : syn::ItemStruct = parse_quote! - { - struct TestStruct< T, 'a, const N : usize > - { - _phantom : core::marker::PhantomData< ( T, &'a (), N ) >, - } - }; - - assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); -} - -// - -#[ test ] -fn phantom_add_named_fields() -{ - use syn::parse_quote; - use quote::ToTokens; - - let input : syn::ItemStruct = parse_quote! { struct TestStruct { field1 : i32, field2 : f64 } }; - let got = the_module::item::phantom_add( &input ); - - let exp : syn::ItemStruct = parse_quote! - { - struct TestStruct - { - field1 : i32, - field2 : f64, - } - }; - - assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); -} - -// - -#[ test ] -fn phantom_add_unnamed_fields() -{ - use syn::parse_quote; - use quote::ToTokens; - - let input : syn::ItemStruct = parse_quote! { struct TestStruct( i32, f64 ); }; - let got = the_module::item::phantom_add( &input ); - let exp : syn::ItemStruct = parse_quote! { struct TestStruct( i32, f64, ); }; - - assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); -} - -// - -#[ test ] -fn phantom_add_unnamed_fields_with_generics() -{ - use syn::parse_quote; - use quote::ToTokens; - - let input : syn::ItemStruct = parse_quote! { struct TestStruct< T, U >( T, U ); }; - let got = the_module::item::phantom_add( &input ); - - let exp : syn::ItemStruct = parse_quote! - { - struct TestStruct< T, U > - ( - T, U, - core::marker::PhantomData< ( T, U ) >, - ); - }; - - assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); -} - -// - -#[ test ] -fn phantom_add_unnamed_fields_lifetime_generics() -{ - use syn::parse_quote; - use quote::ToTokens; - - let input : syn::ItemStruct = parse_quote! { struct TestStruct< 'a, 'b >( &'a i32, &'b f64 ); }; - let got = the_module::item::phantom_add( &input ); - - let exp : syn::ItemStruct = parse_quote! - { - struct TestStruct< 'a, 'b > - ( - &'a i32, - &'b f64, - core::marker::PhantomData< ( &'a (), &'b () ) >, - ); - }; - - assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); -} - -// - -#[ test ] -fn phantom_add_unnamed_fields_const_generics() -{ - use syn::parse_quote; - use quote::ToTokens; - - let input : syn::ItemStruct = parse_quote! { struct TestStruct< const N : usize >( [ i32 ; N ] ); }; - let got = the_module::item::phantom_add( &input ); - - let exp : syn::ItemStruct = parse_quote! - { - struct TestStruct< const N : usize > - ( - [ i32 ; N ], - core::marker::PhantomData< ( N, ) >, - ); - }; - - assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); -} diff --git a/module/core/macro_tools/tests/inc/mod.rs b/module/core/macro_tools/tests/inc/mod.rs index 3f0a2dfb87..2d0cb908c8 100644 --- a/module/core/macro_tools/tests/inc/mod.rs +++ b/module/core/macro_tools/tests/inc/mod.rs @@ -18,6 +18,7 @@ mod if_enabled mod generic_args; mod generic_params; mod item; + mod phantom; mod quantifier; mod syntax; mod tokens; diff --git a/module/core/macro_tools/tests/inc/phantom.rs b/module/core/macro_tools/tests/inc/phantom.rs new file mode 100644 index 0000000000..e0e4754035 --- /dev/null +++ b/module/core/macro_tools/tests/inc/phantom.rs @@ -0,0 +1,298 @@ + +use super::*; + +#[ test ] +fn phantom_add_basic() +{ + + let item : syn::ItemStruct = syn::parse_quote! + { + pub struct Struct1< 'a, Context, Formed > + { + f1 : int32, + } + }; + + let exp : syn::ItemStruct = syn::parse_quote! + { + pub struct Struct1< 'a, Context, Formed > + { + f1 : int32, + _phantom : core::marker::PhantomData< ( &'a(), Context, Formed ) >, + } + }; + + let got = the_module::phantom::add_to_item( &item ); + // a_id!( tree_print!( got ), tree_print!( exp ) ); + a_id!( got, exp ); + +} + +// + +#[ test ] +fn phantom_add_no_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct {} }; + let got = the_module::phantom::add_to_item( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct + { + } + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_type_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< T, U > {} }; + let got = the_module::phantom::add_to_item( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< T, U > + { + _phantom : core::marker::PhantomData< ( T, U ) >, + } + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_lifetime_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< 'a, 'b > {} }; + let got = the_module::phantom::add_to_item( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< 'a, 'b > + { + _phantom : core::marker::PhantomData< ( &'a (), &'b () ) >, + } + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_const_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< const N : usize > {} }; + let got = the_module::phantom::add_to_item( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< const N : usize > + { + _phantom : core::marker::PhantomData< ( N, ) >, + } + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_mixed_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< T, 'a, const N : usize > {} }; + let got = the_module::phantom::add_to_item( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< T, 'a, const N : usize > + { + _phantom : core::marker::PhantomData< ( T, &'a (), N ) >, + } + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_named_fields() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct { field1 : i32, field2 : f64 } }; + let got = the_module::phantom::add_to_item( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct + { + field1 : i32, + field2 : f64, + } + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_unnamed_fields() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct( i32, f64 ); }; + let got = the_module::phantom::add_to_item( &input ); + let exp : syn::ItemStruct = parse_quote! { struct TestStruct( i32, f64, ); }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_unnamed_fields_with_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< T, U >( T, U ); }; + let got = the_module::phantom::add_to_item( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< T, U > + ( + T, U, + core::marker::PhantomData< ( T, U ) >, + ); + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_unnamed_fields_lifetime_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< 'a, 'b >( &'a i32, &'b f64 ); }; + let got = the_module::phantom::add_to_item( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< 'a, 'b > + ( + &'a i32, + &'b f64, + core::marker::PhantomData< ( &'a (), &'b () ) >, + ); + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +#[ test ] +fn phantom_add_unnamed_fields_const_generics() +{ + use syn::parse_quote; + use quote::ToTokens; + + let input : syn::ItemStruct = parse_quote! { struct TestStruct< const N : usize >( [ i32 ; N ] ); }; + let got = the_module::phantom::add_to_item( &input ); + + let exp : syn::ItemStruct = parse_quote! + { + struct TestStruct< const N : usize > + ( + [ i32 ; N ], + core::marker::PhantomData< ( N, ) >, + ); + }; + + assert_eq!( got.to_token_stream().to_string(), exp.to_token_stream().to_string() ); +} + +// + +// +#[ test ] +fn phantom_tuple_empty_generics() +{ + use syn::{ punctuated::Punctuated, GenericParam, token::Comma, parse_quote }; + use macro_tools::phantom::tuple; + + let input : Punctuated< GenericParam, Comma > = Punctuated::new(); + let result = tuple( &input ); + + let exp : syn::Type = parse_quote! { core::marker::PhantomData<()> }; + let got = result; + + assert_eq!( format!( "{:?}", exp ), format!( "{:?}", got ), "Expected empty PhantomData, got: {:?}", got ); +} + +// + +#[ test ] +fn phantom_tuple_only_type_parameters() +{ + use syn::{ parse_quote, punctuated::Punctuated, GenericParam, token::Comma }; + use macro_tools::phantom::tuple; + + let input : Punctuated< GenericParam, Comma > = parse_quote! { T, U }; + let result = tuple( &input ); + + let exp : syn::Type = parse_quote! { core::marker::PhantomData<(T, U)> }; + let got = result; + + assert_eq!( format!( "{:?}", exp ), format!( "{:?}", got ), "Expected PhantomData with type parameters, got: {:?}", got ); +} + +// + +#[ test ] +fn phantom_tuple_mixed_generics() +{ + use syn::{ parse_quote, punctuated::Punctuated, GenericParam, token::Comma }; + use macro_tools::phantom::tuple; + + let input : Punctuated< GenericParam, Comma > = parse_quote! { T, 'a, const N: usize }; + let result = tuple( &input ); + + let exp : syn::Type = parse_quote! { core::marker::PhantomData<(T, &'a (), N)> }; + let got = result; + + assert_eq!( format!( "{:?}", exp ), format!( "{:?}", got ), "Expected PhantomData with mixed generics, got: {:?}", got ); +} From e06f84ca6c5e7828695162537a1b337f4525f292 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 21:13:28 +0300 Subject: [PATCH 190/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 40 +++++++++++--------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 6afd97dbf2..1baa492a3c 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1108,9 +1108,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { < Context, Formed > }; - let former_definition_generics_type = generic_params::merge( &generics, &extra.into() ); - let ( former_definition_generics_type_with_defaults, former_definition_generics_type_impl, former_definition_generics_type_ty, former_definition_generics_type_where ) - = generic_params::decompose( &former_definition_generics_type ); + let former_definition_type_generics = generic_params::merge( &generics, &extra.into() ); + let ( former_definition_type_generics_with_defaults, former_definition_type_generics_impl, former_definition_type_generics_ty, former_definition_type_generics_where ) + = generic_params::decompose( &former_definition_type_generics ); + + let former_definition_type_phantom = macro_tools::phantom::tuple( &former_definition_type_generics_impl ); /* parameters for definition */ let extra : macro_tools::GenericsWithWhere = parse_quote! @@ -1121,6 +1123,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( former_definition_generics_with_defaults, former_definition_generics_impl, former_definition_generics_ty, former_definition_generics_where ) = generic_params::decompose( &generics_of_definition ); + let former_definition_phantom = macro_tools::phantom::tuple( &former_definition_generics_impl ); + /* structure attribute */ let ( perform, perform_output, perform_generics ) = performer @@ -1224,18 +1228,19 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ derive( Debug ) ] // xxx : revert later - pub struct #former_definition_types < #former_definition_generics_type_impl > - // pub struct #former_definition_types < #former_definition_generics_type_with_defaults > + pub struct #former_definition_types < #former_definition_type_generics_impl > + // pub struct #former_definition_types < #former_definition_type_generics_with_defaults > where - #former_definition_generics_type_where + #former_definition_type_generics_where { - _phantom : core::marker::PhantomData< ( Context, Formed ) >, + // _phantom : core::marker::PhantomData< ( Context, Formed ) >, + _phantom : #former_definition_type_phantom, } - impl < #former_definition_generics_type_impl > Default - for #former_definition_types < #former_definition_generics_type_ty > + impl < #former_definition_type_generics_impl > Default + for #former_definition_types < #former_definition_type_generics_ty > where - #former_definition_generics_type_where + #former_definition_type_generics_where { fn default() -> Self { @@ -1246,8 +1251,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } - impl < #former_definition_generics_type_impl > former::FormerDefinitionTypes - for #former_definition_types < #former_definition_generics_type_ty > + impl < #former_definition_type_generics_impl > former::FormerDefinitionTypes + for #former_definition_types < #former_definition_type_generics_ty > { type Storage = #former_storage < #struct_generics_ty >; type Formed = Formed; @@ -1263,7 +1268,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where #former_definition_generics_where { - _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, + // _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, + _phantom : #former_definition_phantom, } impl < #former_definition_generics_impl > Default @@ -1283,17 +1289,17 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl < #former_definition_generics_impl > former::FormerDefinition for #former_definition < #former_definition_generics_ty > // xxx where - End : former::FormingEnd< #former_definition_types < #former_definition_generics_type_ty > >, + End : former::FormingEnd< #former_definition_types < #former_definition_type_generics_ty > >, #former_definition_generics_where { - type Types = #former_definition_types < #former_definition_generics_type_ty >; + type Types = #former_definition_types < #former_definition_type_generics_ty >; type End = End; } - pub type #former_with_closure < #former_definition_generics_type_ty > = + pub type #former_with_closure < #former_definition_type_generics_ty > = #former_definition < - #former_definition_generics_type_ty former::FormingEndClosure< #former_definition_types < #former_definition_generics_type_ty > > + #former_definition_type_generics_ty former::FormingEndClosure< #former_definition_types < #former_definition_type_generics_ty > > >; // = storage From d1249a60a591bd82539c50346043d25b116fbcb2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 21:15:29 +0300 Subject: [PATCH 191/533] former : evolve --- .../tests/inc/former_tests/string_slice.rs | 191 +----------------- module/core/former/tests/inc/mod.rs | 49 +++-- module/core/former_meta/src/derive/former.rs | 12 +- 3 files changed, 32 insertions(+), 220 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/string_slice.rs b/module/core/former/tests/inc/former_tests/string_slice.rs index 449e6c6289..43b36261ff 100644 --- a/module/core/former/tests/inc/former_tests/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/string_slice.rs @@ -1,8 +1,8 @@ use super::*; -// #[ derive( Debug, PartialEq, former::Former ) ] +#[ derive( Debug, PartialEq, former::Former ) ] // #[ derive( Debug, PartialEq, former::Former ) ] #[ debug ] -#[ derive( Debug, PartialEq ) ] +// #[ derive( Debug, PartialEq ) ] pub struct Struct1< 'a > { pub string_slice_1 : &'a str, @@ -10,191 +10,6 @@ pub struct Struct1< 'a > // === begin of generated - #[automatically_derived] impl < 'a, > Struct1 < 'a, > where - { - #[doc = r""] - #[doc = - r" Make former, variation of builder pattern to form structure defining values of fields step by step."] - #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < 'a, - Struct1FormerDefinition < 'a, (), Struct1 < 'a, >, former :: - ReturnPreformed > > - { - Struct1Former :: < 'a, Struct1FormerDefinition < 'a, (), Struct1 < 'a, - >, former :: ReturnPreformed > > :: new(former :: ReturnPreformed) - } - } - - #[derive(Debug)] pub struct Struct1FormerDefinitionTypes < 'a, Context, - Formed, > where - { _phantom : core :: marker :: PhantomData < (Context, Formed) >, } - - impl < 'a, - Context, Formed, > Default for Struct1FormerDefinitionTypes < 'a, Context, - Formed, > where - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } - - impl < 'a, Context, Formed, > former :: FormerDefinitionTypes for - Struct1FormerDefinitionTypes < 'a, Context, Formed, > - { - type Storage = Struct1FormerStorage < 'a, > ; type Formed = Formed ; type - Context = Context ; - } #[derive(Debug)] pub struct Struct1FormerDefinition < 'a, Context, Formed, - End, > where - { _phantom : core :: marker :: PhantomData < (Context, Formed, End) >, } impl - < 'a, Context, Formed, End, > Default for Struct1FormerDefinition < 'a, - Context, Formed, End, > where - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } impl < 'a, Context, Formed, End, > former :: FormerDefinition for - Struct1FormerDefinition < 'a, Context, Formed, End, > where End : former :: - FormingEnd < Struct1FormerDefinitionTypes < 'a, Context, Formed, > >, - { - type Types = Struct1FormerDefinitionTypes < 'a, Context, Formed, > ; type - End = End ; - } pub type Struct1FormerWithClosure < 'a, Context, Formed, > = - Struct1FormerDefinition < 'a, Context, Formed, former :: FormingEndClosure < - Struct1FormerDefinitionTypes < 'a, Context, Formed, > > > ; - #[doc = "Container of a corresponding former."] pub struct - Struct1FormerStorage < 'a, > where - { - #[doc = r" A field"] pub string_slice_1 : :: core :: option :: Option < & - 'a str >, - } impl < 'a, > :: core :: default :: Default for Struct1FormerStorage < 'a, > - where - { - #[inline(always)] fn default() -> Self - { Self { string_slice_1 : :: core :: option :: Option :: None, } } - } impl < 'a, > former :: Storage for Struct1FormerStorage < 'a, > where - { type Formed = Struct1 < 'a, > ; } impl < 'a, > former :: StoragePreform for - Struct1FormerStorage < 'a, > where - { - fn preform(mut self) -> < Self as former :: Storage > :: Formed - { - let string_slice_1 = if self.string_slice_1.is_some() - { self.string_slice_1.take().unwrap() } else - { - { - trait MaybeDefault < T > - { - fn maybe_default(self : & Self) -> T - { panic! ("Field 'string_slice_1' isn't initialized") } - } impl < T > MaybeDefault < T > for & :: core :: marker :: - PhantomData < T > {} impl < T > MaybeDefault < T > for :: core - :: marker :: PhantomData < T > where T : :: core :: default :: - Default, - { fn maybe_default(self : & Self) -> T { T :: default() } } - (& :: core :: marker :: PhantomData :: < & 'a str - >).maybe_default() - } - } ; let result = Struct1 :: < 'a, > { string_slice_1, } ; return - result ; - } - } - #[doc = - " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] - pub struct Struct1Former < 'a, Definition = Struct1FormerDefinition < 'a, (), - Struct1 < 'a, >, former :: ReturnPreformed >, > where Definition : former :: - FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < - Storage = Struct1FormerStorage < 'a, > >, - { - storage : < Definition :: Types as former :: FormerDefinitionTypes > :: - Storage, context : core :: option :: Option < < Definition :: Types as - former :: FormerDefinitionTypes > :: Context >, on_end : core :: option :: - Option < Definition :: End >, - } #[automatically_derived] impl < 'a, Definition, > Struct1Former < 'a, - Definition, > where Definition : former :: FormerDefinition, Definition :: - Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < 'a, - > >, - { - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] - #[doc = - r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = - r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { let result = self.form() ; return result ; } #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn - _new_precise(on_end : Definition :: End) -> Self - { Self :: begin(None, None, on_end) } #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new < IntoEnd > (end : IntoEnd) -> - Self where IntoEnd : Into < Definition :: End >, - { Self :: begin(None, None, end,) } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn - _begin_precise(mut storage : core :: option :: Option < < Definition :: - Types as former :: FormerDefinitionTypes > :: Storage >, context : core :: - option :: Option < < Definition :: Types as former :: - FormerDefinitionTypes > :: Context >, on_end : < Definition as former :: - FormerDefinition > :: End,) -> Self - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()) ; } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: Some(on_end), - } - } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn begin < IntoEnd > - (mut storage : core :: option :: Option < < Definition :: Types as former - :: FormerDefinitionTypes > :: Storage >, context : core :: option :: - Option < < Definition :: Types as former :: FormerDefinitionTypes > :: - Context >, on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert - :: Into < < Definition as former :: FormerDefinition > :: End >, - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()) ; } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: - Some(:: core :: convert :: Into :: into(on_end)), - } - } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types - as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { - let on_end = self.on_end.take().unwrap() ; let context = - self.context.take() ; former :: FormingEnd :: < Definition :: Types > - :: call(& on_end, self.storage, context) - } #[doc = "Setter for the 'string_slice_1' field."] #[inline] pub fn - string_slice_1 < Src > (mut self, src : Src) -> Self where Src : :: core - :: convert :: Into < & 'a str >, - { - debug_assert! (self.storage.string_slice_1.is_none()) ; - self.storage.string_slice_1 = :: core :: option :: Option :: - Some(:: core :: convert :: Into :: into(src)) ; self - } - } impl < 'a, Definition, > Struct1Former < 'a, Definition, > where Definition - : former :: FormerDefinition, Definition :: Types : former :: - FormerDefinitionTypes < Storage = Struct1FormerStorage < 'a, >, Formed = - Struct1 < 'a, > >, < Definition :: Types as former :: FormerDefinitionTypes > - :: Storage : former :: StoragePreform, < Definition :: Types as former :: - FormerDefinitionTypes > :: Storage : former :: Storage < Formed = Struct1 < - 'a, > >, - { - pub fn preform(self) -> < Definition :: Types as former :: - FormerDefinitionTypes > :: Formed - { former :: StoragePreform :: preform(self.storage) } - } - // === end of generated -// include!( "./only_test/string_slice.rs" ); -// xxx : uncomment +include!( "./only_test/string_slice.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index d0765ee383..5b96e1f135 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -13,36 +13,35 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod container_former_common; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod container_former_vec; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod container_former_hashset; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod container_former_hashmap; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_common; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_vec; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashset; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashmap; mod a_basic_manual; mod a_basic; -// mod a_primitives_manual; -// mod a_primitives; -// // mod a_containers_without_subformer; -// // xxx -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer_manual; -// // #[ cfg( not( feature = "no_std" ) ) ] -// // mod a_containers_with_subformer ; -// // xxx -// -// mod attribute_default_container; -// mod attribute_default_primitive; -// // mod attribute_perform; // xxx -// mod attribute_setter; -// mod attribute_alias; - + mod a_primitives_manual; + mod a_primitives; + // mod a_containers_without_subformer; + // xxx + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer_manual; + // #[ cfg( not( feature = "no_std" ) ) ] + // mod a_containers_with_subformer ; // xxx + + mod attribute_default_container; + mod attribute_default_primitive; + // mod attribute_perform; // xxx + mod attribute_setter; + mod attribute_alias; + mod string_slice_manual; - // mod string_slice; + mod string_slice; // mod unsigned_primitive_types; // mod default_user_type; // mod user_type_no_default; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 1baa492a3c..e81b6ae8dd 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1227,9 +1227,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = definition types #[ derive( Debug ) ] - // xxx : revert later - pub struct #former_definition_types < #former_definition_type_generics_impl > - // pub struct #former_definition_types < #former_definition_type_generics_with_defaults > + // pub struct #former_definition_types < #former_definition_type_generics_impl > + pub struct #former_definition_types < #former_definition_type_generics_with_defaults > where #former_definition_type_generics_where { @@ -1262,9 +1261,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = definition #[ derive( Debug ) ] - // xxx : revert later - // pub struct #former_definition < #former_definition_generics_with_defaults > - pub struct #former_definition < #former_definition_generics_impl > + // pub struct #former_definition < #former_definition_generics_impl > + pub struct #former_definition < #former_definition_generics_with_defaults > where #former_definition_generics_where { @@ -1287,7 +1285,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } impl < #former_definition_generics_impl > former::FormerDefinition - for #former_definition < #former_definition_generics_ty > // xxx + for #former_definition < #former_definition_generics_ty > where End : former::FormingEnd< #former_definition_types < #former_definition_type_generics_ty > >, #former_definition_generics_where From 81cbcae9a29c875e371c083e6004bf6b0ffd727d Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 21:36:25 +0300 Subject: [PATCH 192/533] former : evolve --- .../a_containers_without_subformer.rs | 2 +- .../only_test/containers_without_subformer.rs | 2 + module/core/former/tests/inc/mod.rs | 40 ++++++++----------- module/core/former_meta/src/derive/former.rs | 5 ++- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs index 7a64f958dc..941d235faa 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use std::collections::HashSet; #[ derive( Debug, PartialEq, the_module::Former ) ] -// #[ debug ] +// #[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] // #[ derive( Debug, PartialEq ) ] pub struct Struct1 { diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs index 72b86f7fe0..6d7763e697 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs @@ -150,10 +150,12 @@ tests_impls! tests_index! { + internals, test_vector, test_hashmap, test_hashset, test_underscored_form, test_complex, + } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 5b96e1f135..f67d0493c8 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -1,12 +1,6 @@ #[ allow( unused_imports ) ] use super::*; -// struct Struct1< 'a, const N : i32, T > -// where -// { -// _phantom : core::marker::PhantomData< ( &'a (), T, ) >, -// } - #[ cfg( feature = "derive_former" ) ] mod former_tests { @@ -26,13 +20,11 @@ mod former_tests mod a_basic; mod a_primitives_manual; mod a_primitives; - // mod a_containers_without_subformer; - // xxx + mod a_containers_without_subformer; #[ cfg( not( feature = "no_std" ) ) ] mod a_containers_with_subformer_manual; - // #[ cfg( not( feature = "no_std" ) ) ] - // mod a_containers_with_subformer ; - // xxx + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer ; mod attribute_default_container; mod attribute_default_primitive; @@ -42,19 +34,19 @@ mod former_tests mod string_slice_manual; mod string_slice; - // mod unsigned_primitive_types; - // mod default_user_type; - // mod user_type_no_default; - // mod user_type_no_debug; + mod unsigned_primitive_types; + mod default_user_type; + mod user_type_no_default; + mod user_type_no_debug; // xxx -// mod name_collision_former_hashmap_without_parameter; -// mod name_collision_former_vector_without_parameter; -// mod name_collisions; -// mod name_collision_context; -// mod name_collision_end; -// mod name_collision_on_end; -// + mod name_collision_former_hashmap_without_parameter; + mod name_collision_former_vector_without_parameter; + // mod name_collisions; + // mod name_collision_context; + // mod name_collision_end; + // mod name_collision_on_end; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod parametrized_struct_manual; // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] @@ -67,8 +59,8 @@ mod former_tests // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_shortcut; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_shortcut; // xxx : uncomment diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index e81b6ae8dd..431c18f4c8 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1106,7 +1106,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /* parameters for definition types */ let extra : macro_tools::GenericsWithWhere = parse_quote! { - < Context, Formed > + < Context = (), Formed = #struct_name < #struct_generics_ty > > }; let former_definition_type_generics = generic_params::merge( &generics, &extra.into() ); let ( former_definition_type_generics_with_defaults, former_definition_type_generics_impl, former_definition_type_generics_ty, former_definition_type_generics_where ) @@ -1117,7 +1117,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /* parameters for definition */ let extra : macro_tools::GenericsWithWhere = parse_quote! { - < Context, Formed, End > + < Context = (), Formed = #struct_name < #struct_generics_ty >, End = former::ReturnPreformed > }; let generics_of_definition = generic_params::merge( &generics, &extra.into() ); let ( former_definition_generics_with_defaults, former_definition_generics_impl, former_definition_generics_ty, former_definition_generics_where ) @@ -1211,6 +1211,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where #struct_generics_where { + /// /// Make former, variation of builder pattern to form structure defining values of fields step by step. /// From f62731ec0496e09307a5c2c82f4c02bddbb792b1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 19 Apr 2024 22:58:22 +0300 Subject: [PATCH 193/533] former : evolve --- .../former_tests/name_collision_context.rs | 1 + .../inc/former_tests/name_collision_end.rs | 7 ++++ .../only_test/parametrized_struct.rs | 6 ++-- .../former_tests/parametrized_struct_imm.rs | 8 +++-- module/core/former/tests/inc/mod.rs | 27 ++++++++-------- module/core/former_meta/src/derive/former.rs | 32 ++++++++++--------- .../macro_tools/tests/inc/generic_params.rs | 18 +++++++++++ 7 files changed, 65 insertions(+), 34 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/name_collision_context.rs b/module/core/former/tests/inc/former_tests/name_collision_context.rs index e9f7024853..8123626a1d 100644 --- a/module/core/former/tests/inc/former_tests/name_collision_context.rs +++ b/module/core/former/tests/inc/former_tests/name_collision_context.rs @@ -5,6 +5,7 @@ use super::*; pub trait CloneAny{} pub trait End{} +pub trait Formed{} pub trait OnEnd{} #[ derive( Clone, the_module::Former ) ] diff --git a/module/core/former/tests/inc/former_tests/name_collision_end.rs b/module/core/former/tests/inc/former_tests/name_collision_end.rs index f0200c1c34..5690ee583b 100644 --- a/module/core/former/tests/inc/former_tests/name_collision_end.rs +++ b/module/core/former/tests/inc/former_tests/name_collision_end.rs @@ -5,10 +5,17 @@ use super::*; pub trait CloneAny{} pub trait Context{} +pub trait Formed{} pub trait OnEnd{} #[ derive( Clone, the_module::Former ) ] +// #[ derive( Clone, the_module::Former ) ] #[ debug ] +// #[ derive( Clone ) ] pub struct End { inner : std::sync::Arc< core::cell::RefCell< dyn CloneAny > > } + +// = begin of generated + +// = end of generated \ No newline at end of file diff --git a/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs b/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs index 01c03c9800..78cc9ec2e4 100644 --- a/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs +++ b/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs @@ -49,9 +49,9 @@ fn command_properties() let got = Command::< &str >::former() .name( "a" ) .properties() - .insert( "property1", Property::< &str >::new( "property1", 13isize ) ) - .insert( "property2", Property::new( "property2", 13isize ) ) - .insert( "property2", Property::new( "property2", 113isize ) ) + .add( ( "property1", Property::< &str >::new( "property1", 13isize ) ) ) + .add( ( "property2", Property::new( "property2", 13isize ) ) ) + .add( ( "property2", Property::new( "property2", 113isize ) ) ) .end() .form(); let exp = Command::< &str > diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs index 40943ddd1f..2df2210fce 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs @@ -23,14 +23,18 @@ impl< Name > Property< Name > } #[ derive( Debug, PartialEq, the_module::Former ) ] +// #[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, PartialEq ) ] pub struct Command< K : core::hash::Hash + std::cmp::Eq > { pub name : String, - // #[ subformer( the_module::HashMapSubformer ) ] #[ subformer( former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } -// == +// == begin of generated + +// == end of generated include!( "./only_test/parametrized_struct.rs" ); +// xxx : uncomment diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index f67d0493c8..b25fa04463 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -39,25 +39,24 @@ mod former_tests mod user_type_no_default; mod user_type_no_debug; -// xxx mod name_collision_former_hashmap_without_parameter; mod name_collision_former_vector_without_parameter; - // mod name_collisions; - // mod name_collision_context; - // mod name_collision_end; - // mod name_collision_on_end; + mod name_collisions; + mod name_collision_context; + mod name_collision_end; + mod name_collision_on_end; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_manual; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_imm; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod parametrized_struct_manual; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_imm; // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod parametrized_struct_where; -// -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_basic_manual; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_basic; + + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod subformer_basic_manual; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod subformer_basic; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_shortcut; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 431c18f4c8..b9153e8027 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -854,7 +854,7 @@ fn fields_setter_callback_descriptor_map former_storage : &syn::Ident, former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - // former_definition : &syn::Ident, + struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, ) -> Result< TokenStream > @@ -893,7 +893,7 @@ Result< TokenStream > Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes < - Storage = #former_storage + Storage = #former_storage < #struct_generics_ty > >, { #[ inline( always ) ] @@ -1106,7 +1106,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /* parameters for definition types */ let extra : macro_tools::GenericsWithWhere = parse_quote! { - < Context = (), Formed = #struct_name < #struct_generics_ty > > + < __Context = (), __Formed = #struct_name < #struct_generics_ty > > }; let former_definition_type_generics = generic_params::merge( &generics, &extra.into() ); let ( former_definition_type_generics_with_defaults, former_definition_type_generics_impl, former_definition_type_generics_ty, former_definition_type_generics_where ) @@ -1117,7 +1117,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /* parameters for definition */ let extra : macro_tools::GenericsWithWhere = parse_quote! { - < Context = (), Formed = #struct_name < #struct_generics_ty >, End = former::ReturnPreformed > + < __Context = (), __Formed = #struct_name < #struct_generics_ty >, __End = former::ReturnPreformed > }; let generics_of_definition = generic_params::merge( &generics, &extra.into() ); let ( former_definition_generics_with_defaults, former_definition_generics_impl, former_definition_generics_ty, former_definition_generics_where ) @@ -1193,6 +1193,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > &former_storage, &former_generics_impl, &former_generics_ty, + &struct_generics_ty, ), )}).multiunzip(); @@ -1217,9 +1218,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// #[ inline( always ) ] - pub fn former() -> #former < #struct_generics_impl #former_definition< #former_definition_args > > + pub fn former() -> #former < #struct_generics_ty #former_definition< #former_definition_args > > { - #former :: < #struct_generics_impl #former_definition< #former_definition_args > > :: new( former::ReturnPreformed ) + #former :: < #struct_generics_ty #former_definition< #former_definition_args > > :: new( former::ReturnPreformed ) } @@ -1233,11 +1234,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where #former_definition_type_generics_where { - // _phantom : core::marker::PhantomData< ( Context, Formed ) >, + // _phantom : core::marker::PhantomData< ( __Context, __Formed ) >, _phantom : #former_definition_type_phantom, } - impl < #former_definition_type_generics_impl > Default + impl < #former_definition_type_generics_impl > ::core::default::Default for #former_definition_types < #former_definition_type_generics_ty > where #former_definition_type_generics_where @@ -1255,8 +1256,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > for #former_definition_types < #former_definition_type_generics_ty > { type Storage = #former_storage < #struct_generics_ty >; - type Formed = Formed; - type Context = Context; + type Formed = __Formed; + type Context = __Context; } // = definition @@ -1267,11 +1268,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where #former_definition_generics_where { - // _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, + // _phantom : core::marker::PhantomData< ( __Context, __Formed, __End ) >, _phantom : #former_definition_phantom, } - impl < #former_definition_generics_impl > Default + impl < #former_definition_generics_impl > ::core::default::Default for #former_definition < #former_definition_generics_ty > where #former_definition_generics_where @@ -1288,11 +1289,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl < #former_definition_generics_impl > former::FormerDefinition for #former_definition < #former_definition_generics_ty > where - End : former::FormingEnd< #former_definition_types < #former_definition_type_generics_ty > >, + __End : former::FormingEnd< #former_definition_types < #former_definition_type_generics_ty > >, #former_definition_generics_where { type Types = #former_definition_types < #former_definition_type_generics_ty >; - type End = End; + type End = __End; } pub type #former_with_closure < #former_definition_type_generics_ty > = @@ -1315,7 +1316,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > )* } - impl < #struct_generics_impl > ::core::default::Default for #former_storage < #struct_generics_ty > + impl < #struct_generics_impl > ::core::default::Default + for #former_storage < #struct_generics_ty > where #struct_generics_where { diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index d0bb3b0dbe..1988663f27 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -352,3 +352,21 @@ fn decompose_mixed_generics_types() } } + +// xxx +// #[ test ] +// fn decompose_bug_a() +// { +// use macro_tools::quote::ToTokens; +// let generics : the_module::GenericsWithWhere = syn::parse_quote! { < K : core::hash::Hash + std::cmp::Eq > }; +// let generics = generics.unwrap(); +// let ( impl_with_def, impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); +// +// let impl_with_def_exp : syn::Generics = syn::parse_quote! { < K : core::hash::Hash + std::cmp::Eq, > }; +// let impl_gen_exp : syn::Generics = syn::parse_quote! { < K, > }; +// let ty_gen_exp : syn::Generics = syn::parse_quote! { < K, > }; +// a_id!( impl_with_def, impl_with_def_exp.params ); +// a_id!( impl_gen, impl_gen_exp.params ); +// a_id!( ty_gen_exp, ty_gen.params ); +// +// } From 5613e1a209954db9924e2d6570f726ab8fadfc78 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 00:24:23 +0300 Subject: [PATCH 194/533] former : evolve --- .../former_tests/parametrized_struct_imm.rs | 1 - .../parametrized_struct_manual.rs | 318 +++++++++++++----- .../former_tests/parametrized_struct_where.rs | 7 +- module/core/former/tests/inc/mod.rs | 11 +- module/core/former_meta/src/derive/former.rs | 7 + 5 files changed, 242 insertions(+), 102 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs index 2df2210fce..afaf7c0fb2 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs @@ -37,4 +37,3 @@ pub struct Command< K : core::hash::Hash + std::cmp::Eq > // == end of generated include!( "./only_test/parametrized_struct.rs" ); -// xxx : uncomment diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index f599ddceb0..6450f4a8d7 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -22,182 +22,314 @@ impl< Name > Property< Name > } } +// #[ derive( Debug, PartialEq, the_module::Former ) ] +// #[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] #[ derive( Debug, PartialEq ) ] pub struct Command< K > where K : core::hash::Hash + std::cmp::Eq, { pub name : String, + // #[ subformer( former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } -// generated by former -impl< K > Command< K > -where - K : core::hash::Hash + std::cmp::Eq, +// == begin of generated + +#[ automatically_derived ] +impl< K, > Command< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, { + + #[ inline( always ) ] - pub fn former() -> CommandFormer< K > + pub fn former() -> CommandFormer< K, CommandFormerDefinition< K, (), Command< K, >, former :: ReturnPreformed > > { - CommandFormer::< K >::new() + CommandFormer :: < K, CommandFormerDefinition< K, (), Command< K, >, former :: ReturnPreformed > > :: new( former :: ReturnPreformed ) } +} +#[ derive( Debug ) ] +pub struct CommandFormerDefinitionTypes< K, __Context = (), __Formed = Command< K, >, > where K : core :: hash :: Hash + std :: cmp :: Eq, +{ + _phantom : core :: marker :: PhantomData< ( K, __Context, __Formed ) >, } -// generated by former -pub struct CommandFormerStorage< K > -where - K : core::hash::Hash + std::cmp::Eq, +impl< K, __Context, __Formed, > :: core :: default :: Default for CommandFormerDefinitionTypes< K, __Context, __Formed, > where K : core :: hash :: Hash + std :: cmp :: Eq, { - name : core::option::Option< String >, - properties : core::option::Option< collection_tools::HashMap< K, Property< K > > >, + fn default() -> Self + { + Self + { + _phantom : core :: marker :: PhantomData, + } + } } -impl< K > Default for CommandFormerStorage< K > -where - K : core::hash::Hash + std::cmp::Eq, +impl< K, __Context, __Formed, > former :: FormerDefinitionTypes for CommandFormerDefinitionTypes< K, __Context, __Formed, > where K : core :: hash :: Hash + std :: cmp :: Eq, { + type Storage = CommandFormerStorage< K, >; + type Formed = __Formed; + type Context = __Context; +} - #[ inline( always ) ] +#[ derive( Debug ) ] +pub struct CommandFormerDefinition< K, __Context = (), __Formed = Command< K, >, __End = former :: ReturnPreformed, > where K : core :: hash :: Hash + std :: cmp :: Eq, +{ + _phantom : core :: marker :: PhantomData< ( K, __Context, __Formed, __End ) >, +} + +impl< K, __Context, __Formed, __End, > :: core :: default :: Default for CommandFormerDefinition< K, __Context, __Formed, __End, > where K : core :: hash :: Hash + std :: cmp :: Eq, +{ fn default() -> Self { Self { - name : None, - properties : None, + _phantom : core :: marker :: PhantomData, } } - } -// generated by former -// #[ derive( Debug, Default ) ] -pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnPreformed > -where - K : core::hash::Hash + std::cmp::Eq, - End : the_module::FormingEnd< Command< K >, Context >, +impl< K, __Context, __Formed, __End, > former :: FormerDefinition for CommandFormerDefinition< K, __Context, __Formed, __End, > where __End : former :: FormingEnd< CommandFormerDefinitionTypes< K, __Context, __Formed, > >, K : core :: hash :: Hash + std :: cmp :: Eq, { - storage : CommandFormerStorage< K >, - context : core::option::Option< Context >, - on_end : core::option::Option< End >, + type Types = CommandFormerDefinitionTypes< K, __Context, __Formed, >; + type End = __End; } -// generated by former -impl< K, Context, End > -CommandFormer< K, Context, End > -where - K : core::hash::Hash + std::cmp::Eq, - End : the_module::FormingEnd< Command< K >, Context >, +pub type CommandFormerWithClosure< K, __Context, __Formed, > = CommandFormerDefinition< K, __Context, __Formed, former :: FormingEndClosure< CommandFormerDefinitionTypes< K, __Context, __Formed, > > >; + + +pub struct CommandFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, { + pub name : :: core :: option :: Option< String >, + + pub properties : :: core :: option :: Option< collection_tools :: HashMap< K, Property< K > > >, +} + +impl< K, > :: core :: default :: Default for CommandFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, +{ #[ inline( always ) ] - fn form( mut self ) -> Command< K > + fn default() -> Self { + Self + { + name : :: core :: option :: Option :: None, + properties : :: core :: option :: Option :: None, + } + } +} - let name = if self.storage.name.is_some() +impl< K, > former :: Storage for CommandFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, +{ + type Formed = Command< K, >; +} + +impl< K, > former :: StoragePreform for CommandFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, +{ + fn preform( mut self ) -> < Self as former :: Storage > :: Formed + { + let name = if self.name.is_some() { - self.storage.name.take().unwrap() + self.name.take().unwrap() } else { - let val = Default::default(); - val + { + trait MaybeDefault< T > + { + fn maybe_default( self : & Self ) -> T + { + panic!( "Field 'name' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for & :: core :: marker :: PhantomData< T > {} + impl< T > MaybeDefault< T > for :: core :: marker :: PhantomData< T > where T : :: core :: default :: Default, + { + fn maybe_default( self : & Self ) -> T { T :: default() } + } + ( & :: core :: marker :: PhantomData :: < String > ).maybe_default() + } }; - let properties = if self.storage.properties.is_some() + let properties = if self.properties.is_some() { - self.storage.properties.take().unwrap() + self.properties.take().unwrap() } else { - let val = Default::default(); - val + { + trait MaybeDefault< T > + { + fn maybe_default( self : & Self ) -> T + { + panic!( "Field 'properties' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for & :: core :: marker :: PhantomData< T > {} + impl< T > MaybeDefault< T > for :: core :: marker :: PhantomData< T > where T : :: core :: default :: Default, + { + fn maybe_default( self : & Self ) -> T { T :: default() } + } + ( & :: core :: marker :: PhantomData :: < collection_tools :: HashMap< K, Property< K > > > ).maybe_default() + } }; - Command - { - name, - properties, - } + let result = Command :: < K, > { name, properties, }; + return result; + } +} + + // xxx +pub struct CommandFormer< K, Definition = CommandFormerDefinition< K, (), Command< K, >, former::ReturnPreformed >, > +where + K : core::hash::Hash + std::cmp::Eq, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > > +{ + storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : core::option::Option< Definition::End >, +} + +#[ automatically_derived ] +impl< K, Definition, > CommandFormer< K, Definition, > +where + K : core::hash::Hash + std::cmp::Eq, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > > +{ + #[ inline( always ) ] + pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + let result = self.form(); + return result; } #[ inline( always ) ] - pub fn perform( self ) -> Command< K > + pub fn _new_precise( on_end : Definition::End ) -> Self { - self.form() + Self::begin( None, None, on_end ) } #[ inline( always ) ] - pub fn new() -> CommandFormer< K > + pub fn new< IntoEnd >( end : IntoEnd ) -> Self + where IntoEnd : Into< Definition::End > { - CommandFormer::< K >::begin - ( - None, - None, - the_module::ReturnPreformed, - ) + Self::begin( None, None, end ) } #[ inline( always ) ] - pub fn begin - ( - storage : core::option::Option< CommandFormerStorage< K > >, - context : core::option::Option< Context >, - on_end : End, - ) -> Self - { - // xxx : fix - debug_assert!( storage.is_none() ); + pub fn _begin_precise( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } Self { - storage : Default::default(), + storage : storage.unwrap(), context : context, - on_end : Some( on_end ), + on_end : ::core::option::Option::Some( on_end ), } } - /// Return former of your struct moving container there. Should be called after configuring the container. #[ inline( always ) ] - pub fn end( mut self ) -> Context + pub fn begin< IntoEnd >( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : IntoEnd, ) -> Self + where IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), + } + } + + #[ inline( always ) ] + pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + self.end() + } + + #[ inline( always ) ] + pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) + former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) } - #[ inline( always ) ] + #[ inline ] pub fn name< Src >( mut self, src : Src ) -> Self - where Src : core::convert::Into< String >, + where Src : ::core::convert::Into< String > { debug_assert!( self.storage.name.is_none() ); - self.storage.name = Some( src.into() ); + self.storage.name = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); self } #[ inline( always ) ] - pub fn properties( mut self ) -> the_module::HashMapSubformer - < - K, - Property< K >, - collection_tools::HashMap< K, Property< K > >, - CommandFormer< K, Context, End >, - impl the_module::FormingEnd< collection_tools::HashMap< K, Property< K > >, Self >, - > - { - let formed = self.storage.properties.take(); - let on_end = | formed : collection_tools::HashMap< K, Property< K > >, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - super_former.storage.properties = Some( formed ); - super_former - }; - the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) + pub fn properties_set< Former2 >( self ) -> Former2 + where Former2 : former::FormerBegin< former::HashMapDefinition< K, Property< K >, Self, Self, CommandFormerPropertiesEnd, > > + { + Former2::_begin( None, Some( self ), CommandFormerPropertiesEnd ) + } + + #[ inline( always ) ] + pub fn properties( self ) -> former::ContainerSubformer::< ( K, Property< K >, ), former::HashMapDefinition< K, Property< K >, Self, Self, CommandFormerPropertiesEnd > > + { + self.properties_set::< former::ContainerSubformer::< ( K, Property< K >, ), former::HashMapDefinition< K, Property< K >, Self, Self, CommandFormerPropertiesEnd > >>() + } +} + +// xxx + +impl< K, Definition, > CommandFormer< K, Definition, > +where + K : core::hash::Hash + std::cmp::Eq, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, >, Formed = Command< K, > >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Command< K, > > +{ + pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + former::StoragePreform::preform( self.storage ) } +} + +#[ allow( non_camel_case_types ) ] +pub struct CommandFormerPropertiesEnd; + +#[ automatically_derived ] +impl< K, Definition, > former::FormingEnd< former::HashMapDefinition< K, Property< K >, CommandFormer< K, Definition, >, CommandFormer< K, Definition, >, former::NoEnd >, > for CommandFormerPropertiesEnd +where + K : core::hash::Hash + std::cmp::Eq, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > > +{ + #[ inline( always ) ] + fn call( &self, storage : collection_tools::HashMap< K, Property< K > >, super_former : Option< CommandFormer< K, Definition, > >, ) -> CommandFormer< K, Definition, > + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.properties + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.properties = Some( storage ); + } + super_former + } } -// == +// == end of generated include!( "./only_test/parametrized_struct.rs" ); diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs index ba358b14f9..5cb3a0fc51 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs @@ -23,16 +23,19 @@ impl< Name > Property< Name > } #[ derive( Debug, PartialEq, the_module::Former ) ] +// #[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, PartialEq ) ] pub struct Command< K > where K : core::hash::Hash + std::cmp::Eq, { pub name : String, - // #[ subformer( the_module::HashMapSubformer ) ] #[ subformer( former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } -// == +// == begin of generated + +// == end of generated include!( "./only_test/parametrized_struct.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index b25fa04463..bc0b43d12a 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -46,23 +46,22 @@ mod former_tests mod name_collision_end; mod name_collision_on_end; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod parametrized_struct_manual; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_manual; #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod parametrized_struct_imm; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_where; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_where; // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic_manual; // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic; + // xxx : uncomment #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_shortcut; -// xxx : uncomment - } #[ cfg( feature = "derive_components" ) ] diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index b9153e8027..561597b625 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -854,6 +854,7 @@ fn fields_setter_callback_descriptor_map former_storage : &syn::Ident, former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, ) -> @@ -883,6 +884,7 @@ Result< TokenStream > /// Return original former after subformer for `vec_1` is done. #[ allow( non_camel_case_types ) ] pub struct #field_forming_end; + #[ automatically_derived ] impl< #former_generics_impl > former::FormingEnd < @@ -895,6 +897,7 @@ Result< TokenStream > < Storage = #former_storage < #struct_generics_ty > >, + #former_generics_where { #[ inline( always ) ] fn call @@ -1193,6 +1196,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > &former_storage, &former_generics_impl, &former_generics_ty, + &former_generics_where, &struct_generics_ty, ), )}).multiunzip(); @@ -1254,6 +1258,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl < #former_definition_type_generics_impl > former::FormerDefinitionTypes for #former_definition_types < #former_definition_type_generics_ty > + where + #former_definition_type_generics_where { type Storage = #former_storage < #struct_generics_ty >; type Formed = __Formed; @@ -1504,6 +1510,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #struct_generics_ty >, Formed = #struct_name < #struct_generics_ty > >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = #struct_name < #struct_generics_ty > >, + #former_generics_where { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed From 983ece969b9658bfb5e96ca1fe587ebd6f13ab6a Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 00:41:57 +0300 Subject: [PATCH 195/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 108 ++++++++++-------- module/core/former/tests/inc/mod.rs | 4 +- 2 files changed, 61 insertions(+), 51 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 6d45926eba..2a30a8ae7d 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -59,11 +59,12 @@ where } // manual -impl< K, Context, End > -CommandFormer< K, Context, End > +impl< K, Definition > CommandFormer< K, Definition > where K : core::hash::Hash + std::cmp::Eq, - End : the_module::FormingEnd< Command< K >, Context >, + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K > >, { /// Inserts a key-value pair into the map. Make a new container if it was not made so far. @@ -96,52 +97,61 @@ where // == aggregator -#[ derive( Debug, PartialEq, the_module::Former ) ] -pub struct Aggregator< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - pub parameter1 : String, - #[ subformer( the_module::HashMapSubformer ) ] - pub commands : collection_tools::HashMap< String, Command< K > >, -} - -// manual -impl< K, Context, End > -AggregatorFormer< K, Context, End > -where - K : core::hash::Hash + std::cmp::Eq, - End : the_module::FormingEnd< Aggregator< K >, Context >, -{ - - #[ inline( always ) ] - pub fn command< IntoName >( self, name : IntoName ) - -> CommandFormer< K, Self, impl the_module::FormingEnd< Command< K >, Self > > - where - K : core::hash::Hash + std::cmp::Eq, - IntoName : core::convert::Into< String >, - { - let on_end = | command : Command< K >, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut commands ) = super_former.storage.commands - { - commands.insert( command.name.clone(), command ); - } - else - { - let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - commands.insert( command.name.clone(), command ); - super_former.storage.commands = Some( commands ); - } - super_former - }; - let former = CommandFormer::begin( None, Some( self ), on_end ); - former.name( name ) - } - -} +// #[ derive( Debug, PartialEq, the_module::Former ) ] +// pub struct Aggregator< K > +// where +// K : core::hash::Hash + std::cmp::Eq, +// { +// pub parameter1 : String, +// // #[ subformer( the_module::HashMapSubformer ) ] +// #[ subformer( former::HashMapDefinition ) ] +// pub commands : collection_tools::HashMap< String, Command< K > >, +// } +// +// // manual +// // impl< K, Context, End > +// // AggregatorFormer< K, Context, End > +// // where +// // K : core::hash::Hash + std::cmp::Eq, +// // End : the_module::FormingEnd< Aggregator< K >, Context >, +// +// impl< K, Definition > AggregatorFormer< K, Definition > +// where +// K : core::hash::Hash + std::cmp::Eq, +// Definition : former::FormerDefinition, +// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +// Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, +// { +// +// #[ inline( always ) ] +// pub fn command< IntoName >( self, name : IntoName ) +// -> CommandFormer< K, Self, impl the_module::FormingEnd< Command< K >, Self > > +// where +// K : core::hash::Hash + std::cmp::Eq, +// IntoName : core::convert::Into< String >, +// { +// let on_end = | command : Command< K >, super_former : core::option::Option< Self > | -> Self +// { +// let mut super_former = super_former.unwrap(); +// if let Some( ref mut commands ) = super_former.storage.commands +// { +// commands.insert( command.name.clone(), command ); +// } +// else +// { +// let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); +// commands.insert( command.name.clone(), command ); +// super_former.storage.commands = Some( commands ); +// } +// super_former +// }; +// let former = CommandFormer::begin( None, Some( self ), on_end ); +// former.name( name ) +// } +// +// } // == -include!( "./only_test/subformer_basic.rs" ); +// include!( "./only_test/subformer_basic.rs" ); +// xxx : uncomment \ No newline at end of file diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index bc0b43d12a..457ebea3f3 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -55,8 +55,8 @@ mod former_tests // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic_manual; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod subformer_basic; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod subformer_basic; // xxx : uncomment #[ cfg( any( not( feature = "no_std" ) ) ) ] From 3ee7b213fb7332d976402a7be9c3d46cbf8ef985 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 11:13:54 +0300 Subject: [PATCH 196/533] former : evolve --- .../tests/inc/former_tests/a_basic_manual.rs | 1 - .../a_containers_with_subformer_manual.rs | 70 ++++--- .../tests/inc/former_tests/subformer_basic.rs | 172 +++++++++++++----- 3 files changed, 158 insertions(+), 85 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index de5b1e47c8..233293af3f 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -249,7 +249,6 @@ where Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Struct1 >, - { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index b3a9d0b152..ed011815bb 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -21,7 +21,7 @@ impl Struct1 } } -// = definition +// = definition types #[ derive( Debug ) ] pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > @@ -40,6 +40,16 @@ impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Forme } } +impl< Context, Formed > former::FormerDefinitionTypes +for Struct1FormerDefinitionTypes< Context, Formed > +{ + type Storage = Struct1FormerStorage; + type Formed = Formed; + type Context = Context; +} + +// = definition + #[ derive( Debug ) ] pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > { @@ -57,13 +67,6 @@ impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Forme } } -impl< Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed > -{ - type Storage = Struct1FormerStorage; - type Formed = Formed; - type Context = Context; -} - impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > where End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, @@ -76,16 +79,10 @@ pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< // = storage -#[ doc = "Container of a corresponding former." ] pub struct Struct1FormerStorage { - #[ doc = r" A field" ] pub vec_1 : ::core::option::Option< Vec< String > >, - - #[ doc = r" A field" ] pub hashmap_1 : ::core::option::Option< std::collections::HashMap< String, String > >, - - #[ doc = r" A field" ] pub hashset_1 : ::core::option::Option< std::collections::HashSet< String > >, } @@ -202,7 +199,6 @@ impl former::StoragePreform for Struct1FormerStorage // = former -#[ doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[ default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] pub struct Struct1Former< Definition = Struct1FormerDefinition > where Definition : former::FormerDefinition, @@ -221,12 +217,8 @@ where < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { - #[ doc = r"" ] - #[ doc = r" Finish setting options and call perform on formed entity." ] - #[ doc = r"" ] - #[ doc = r" If `perform` defined then associated method is called and its result returned instead of entity." ] - #[ doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str ) ]` returns `&str`." ] - #[ doc = r"" ] + + #[ inline( always ) ] pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { @@ -234,18 +226,18 @@ where return result; } - #[ doc = r"" ] - #[ doc = r" Construct new instance of former with default parameters." ] - #[ doc = r"" ] + + + #[ inline( always ) ] pub fn _new_precise( on_end : Definition::End ) -> Self { Self::begin( None, None, on_end ) } - #[ doc = r"" ] - #[ doc = r" Construct new instance of former with default parameters." ] - #[ doc = r"" ] + + + #[ inline( always ) ] pub fn new< IntoEnd >( end : IntoEnd ) -> Self where @@ -254,9 +246,9 @@ where Self::begin( None, None, end, ) } - #[ doc = r"" ] - #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] - #[ doc = r"" ] + + + #[ inline( always ) ] pub fn _begin_precise( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, @@ -276,9 +268,9 @@ where } } - #[ doc = r"" ] - #[ doc = r" Begin the process of forming. Expects context of forming to return it after forming." ] - #[ doc = r"" ] + + + #[ inline( always ) ] pub fn begin< IntoEnd >( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, @@ -300,18 +292,18 @@ where } } - #[ doc = r"" ] - #[ doc = r" End the process of forming returning original context of forming." ] - #[ doc = r"" ] + + + #[ inline( always ) ] pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { self.end() } - #[ doc = r"" ] - #[ doc = r" End the process of forming returning original context of forming." ] - #[ doc = r"" ] + + + #[ inline( always ) ] pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 2a30a8ae7d..86c9653dc0 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -97,24 +97,39 @@ where // == aggregator -// #[ derive( Debug, PartialEq, the_module::Former ) ] -// pub struct Aggregator< K > +#[ derive( Debug, PartialEq, the_module::Former ) ] +pub struct Aggregator< K > +where + K : core::hash::Hash + std::cmp::Eq, +{ + pub parameter1 : String, + // #[ subformer( the_module::HashMapSubformer ) ] + #[ subformer( former::HashMapDefinition ) ] + pub commands : collection_tools::HashMap< String, Command< K > >, +} + +// manual +// impl< K, Context, End > +// AggregatorFormer< K, Context, End > // where // K : core::hash::Hash + std::cmp::Eq, -// { -// pub parameter1 : String, -// // #[ subformer( the_module::HashMapSubformer ) ] -// #[ subformer( former::HashMapDefinition ) ] -// pub commands : collection_tools::HashMap< String, Command< K > >, -// } -// -// // manual -// // impl< K, Context, End > -// // AggregatorFormer< K, Context, End > -// // where -// // K : core::hash::Hash + std::cmp::Eq, -// // End : the_module::FormingEnd< Aggregator< K >, Context >, -// +// End : the_module::FormingEnd< Aggregator< K >, Context >, + +impl< K, Definition > AggregatorFormer +< + K, + Definition, +> +where + K : core::hash::Hash + std::cmp::Eq, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, + + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Aggregator< K > >, + +{ + // impl< K, Definition > AggregatorFormer< K, Definition > // where // K : core::hash::Hash + std::cmp::Eq, @@ -122,36 +137,103 @@ where // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, // Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, // { -// -// #[ inline( always ) ] -// pub fn command< IntoName >( self, name : IntoName ) -// -> CommandFormer< K, Self, impl the_module::FormingEnd< Command< K >, Self > > -// where -// K : core::hash::Hash + std::cmp::Eq, -// IntoName : core::convert::Into< String >, -// { -// let on_end = | command : Command< K >, super_former : core::option::Option< Self > | -> Self -// { -// let mut super_former = super_former.unwrap(); -// if let Some( ref mut commands ) = super_former.storage.commands -// { -// commands.insert( command.name.clone(), command ); -// } -// else -// { -// let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); -// commands.insert( command.name.clone(), command ); -// super_former.storage.commands = Some( commands ); -// } -// super_former -// }; -// let former = CommandFormer::begin( None, Some( self ), on_end ); -// former.name( name ) -// } -// -// } + + // #[ inline( always ) ] + // pub fn command< IntoName >( self, name : IntoName ) + // -> CommandFormer< K, Self, impl the_module::FormingEnd< Command< K >, Self > > + // where + // K : core::hash::Hash + std::cmp::Eq, + // IntoName : core::convert::Into< String >, + // { + // let on_end = | command : Command< K >, super_former : core::option::Option< Self > | -> Self + // { + // let mut super_former = super_former.unwrap(); + // if let Some( ref mut commands ) = super_former.storage.commands + // { + // commands.insert( command.name.clone(), command ); + // } + // else + // { + // let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); + // commands.insert( command.name.clone(), command ); + // super_former.storage.commands = Some( commands ); + // } + // super_former + // }; + // let former = CommandFormer::begin( None, Some( self ), on_end ); + // former.name( name ) + // } + + #[ inline( always ) ] + pub fn command< IntoName >( self, name : IntoName ) + // -> CommandFormer + // < + // K, + // CommandFormerDefinition + // < + // K, + // Self, + // Self, + // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, + // >, + // > + where + // K : core::hash::Hash + std::cmp::Eq, + IntoName : core::convert::Into< String >, + { + + let on_end = | command : CommandFormerStorage< K >, super_former : core::option::Option< Self > | -> Self + { + let command = former::StoragePreform::preform( command ); + let mut super_former = super_former.unwrap(); + if let Some( ref mut commands ) = super_former.storage.commands + { + former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); + } + else + { + let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); + former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); + super_former.storage.commands = Some( commands ); + } + super_former + }; + + let former + // : CommandFormer, AggregatorFormer, _>> + : CommandFormer + < + K, + CommandFormerDefinition + < + K, + AggregatorFormer< K, Definition >, + AggregatorFormer< K, Definition >, + former::FormingEndClosure< _ >, + // former::FormingEnd< CommandFormerDefinitionTypes< K, AggregatorFormer< K, Definition >, AggregatorFormer< K, Definition > > >, + > + > + = CommandFormer::begin( None, Some( self ), on_end ); + + // former.name( name ) + + } + + // pub fn hashset_1( self ) -> + // former::ContainerSubformer:: + // < + // String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End > + // > + // { + // self.hashset_1_set::< former::ContainerSubformer:: + // < + // String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End > + // >>() + // } + +} // == // include!( "./only_test/subformer_basic.rs" ); -// xxx : uncomment \ No newline at end of file +// xxx : uncomment From 359b4f09e6eae6cd28f41a53c001bd63da2f8d8e Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 11:17:05 +0300 Subject: [PATCH 197/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 86c9653dc0..46debf2f3f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -166,17 +166,18 @@ where #[ inline( always ) ] pub fn command< IntoName >( self, name : IntoName ) - // -> CommandFormer - // < - // K, - // CommandFormerDefinition - // < - // K, - // Self, - // Self, - // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, - // >, - // > + -> CommandFormer + < + K, + CommandFormerDefinition + < + K, + Self, + Self, + impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, AggregatorFormer< K, Definition >, AggregatorFormer< K, Definition > > >, + // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, + >, + > where // K : core::hash::Hash + std::cmp::Eq, IntoName : core::convert::Into< String >, @@ -210,12 +211,13 @@ where AggregatorFormer< K, Definition >, AggregatorFormer< K, Definition >, former::FormingEndClosure< _ >, + // former::FormingEndClosure< CommandFormerDefinitionTypes< K, AggregatorFormer< K, Definition >, AggregatorFormer< K, Definition > > >, // former::FormingEnd< CommandFormerDefinitionTypes< K, AggregatorFormer< K, Definition >, AggregatorFormer< K, Definition > > >, > > = CommandFormer::begin( None, Some( self ), on_end ); - // former.name( name ) + former.name( name ) } From 621ec3671e8648f2293d7bc344207327456147ba Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 11:37:30 +0300 Subject: [PATCH 198/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 46debf2f3f..db37c730d3 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -175,12 +175,35 @@ where Self, Self, impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, AggregatorFormer< K, Definition >, AggregatorFormer< K, Definition > > >, - // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, >, > where - // K : core::hash::Hash + std::cmp::Eq, IntoName : core::convert::Into< String >, +// { +// +// let on_end = | command : CommandFormerStorage< K >, super_former : core::option::Option< Self > | -> Self +// { +// let command = former::StoragePreform::preform( command ); +// let mut super_former = super_former.unwrap(); +// if let Some( ref mut commands ) = super_former.storage.commands +// { +// former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); +// } +// else +// { +// let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); +// former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); +// super_former.storage.commands = Some( commands ); +// } +// super_former +// }; +// +// self.commands_set::< former::ContainerSubformer:: +// < +// ( K, Command< K > ), former::HashMapDefinition< K, Command< K >, Self, Self, AggregatorFormerCommandsEnd > +// > >() +// } + { let on_end = | command : CommandFormerStorage< K >, super_former : core::option::Option< Self > | -> Self @@ -201,7 +224,6 @@ where }; let former - // : CommandFormer, AggregatorFormer, _>> : CommandFormer < K, From 676fcdc2847744c6e7c3424a0e4998be7acf66b8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 11:59:45 +0300 Subject: [PATCH 199/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 89 +++++++++---------- 1 file changed, 40 insertions(+), 49 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index db37c730d3..8c10497392 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -108,6 +108,19 @@ where pub commands : collection_tools::HashMap< String, Command< K > >, } +pub type CommandSubformer< K, Superformer > = CommandFormer +< + K, + CommandFormerDefinition + < + K, + Superformer, + Superformer, + former::FormingEndClosure< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, + // impl former::FormingEnd< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, + >, +>; + // manual // impl< K, Context, End > // AggregatorFormer< K, Context, End > @@ -166,44 +179,21 @@ where #[ inline( always ) ] pub fn command< IntoName >( self, name : IntoName ) - -> CommandFormer - < - K, - CommandFormerDefinition - < - K, - Self, - Self, - impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, AggregatorFormer< K, Definition >, AggregatorFormer< K, Definition > > >, - >, - > + -> + CommandSubformer< K, Self > + // CommandFormer + // < + // K, + // CommandFormerDefinition + // < + // K, + // Self, + // Self, + // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, + // >, + // > where IntoName : core::convert::Into< String >, -// { -// -// let on_end = | command : CommandFormerStorage< K >, super_former : core::option::Option< Self > | -> Self -// { -// let command = former::StoragePreform::preform( command ); -// let mut super_former = super_former.unwrap(); -// if let Some( ref mut commands ) = super_former.storage.commands -// { -// former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); -// } -// else -// { -// let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); -// former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); -// super_former.storage.commands = Some( commands ); -// } -// super_former -// }; -// -// self.commands_set::< former::ContainerSubformer:: -// < -// ( K, Command< K > ), former::HashMapDefinition< K, Command< K >, Self, Self, AggregatorFormerCommandsEnd > -// > >() -// } - { let on_end = | command : CommandFormerStorage< K >, super_former : core::option::Option< Self > | -> Self @@ -224,19 +214,20 @@ where }; let former - : CommandFormer - < - K, - CommandFormerDefinition - < - K, - AggregatorFormer< K, Definition >, - AggregatorFormer< K, Definition >, - former::FormingEndClosure< _ >, - // former::FormingEndClosure< CommandFormerDefinitionTypes< K, AggregatorFormer< K, Definition >, AggregatorFormer< K, Definition > > >, - // former::FormingEnd< CommandFormerDefinitionTypes< K, AggregatorFormer< K, Definition >, AggregatorFormer< K, Definition > > >, - > - > + : CommandSubformer< K, Self > + // : CommandFormer + // < + // K, + // CommandFormerDefinition + // < + // K, + // Self, + // Self, + // former::FormingEndClosure< _ >, + // // former::FormingEndClosure< CommandFormerDefinitionTypes< K, Self, Self > >, + // // former::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, + // > + // > = CommandFormer::begin( None, Some( self ), on_end ); former.name( name ) From b5b096a5b0f49a9eb27afb872578df77c20a14de Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 12:15:45 +0300 Subject: [PATCH 200/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 8c10497392..4b9f086b79 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -248,6 +248,40 @@ where } +#[ allow( non_camel_case_types ) ] +pub struct AggregatorFormerCommandEnd; +#[ automatically_derived ] +impl< K, Definition > former::FormingEnd +< + former::HashMapDefinition< String, Command< K >, AggregatorFormer< K, Definition >, AggregatorFormer< K, Definition >, former::NoEnd >, +> +for AggregatorFormerCommandEnd +where + K : core::hash::Hash + std::cmp::Eq, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = AggregatorFormerStorage< K > + >, +{ + #[ inline( always ) ] + fn call( &self, storage : std::collections::HashMap< String, Command< K > >, super_former : Option< AggregatorFormer< K, Definition > > ) + -> + AggregatorFormer< K, Definition > + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.commands + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.commands = Some( storage ); + } + super_former + } +} + // == // include!( "./only_test/subformer_basic.rs" ); From ca04d3a61876827339b8808481710edf24621b51 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 14:49:38 +0300 Subject: [PATCH 201/533] former : evolve --- .../a_containers_with_subformer_manual.rs | 9 +- .../tests/inc/former_tests/subformer_basic.rs | 143 ++++++++---------- 2 files changed, 70 insertions(+), 82 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index ed011815bb..60d0b05409 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -465,7 +465,14 @@ where >, { #[ inline( always ) ] - fn call( &self, storage : std::collections::HashMap< String, String >, super_former : Option< Struct1Former< Definition > > ) -> Struct1Former< Definition > + fn call + ( + &self, + storage : std::collections::HashMap< String, String >, + super_former : Option< Struct1Former< Definition > >, + ) + -> + Struct1Former< Definition > { let mut super_former = super_former.unwrap(); if let Some( ref mut field ) = super_former.storage.hashmap_1 diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 4b9f086b79..eef1a24bb4 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -143,55 +143,48 @@ where { -// impl< K, Definition > AggregatorFormer< K, Definition > -// where -// K : core::hash::Hash + std::cmp::Eq, -// Definition : former::FormerDefinition, -// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, -// Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, -// { + #[ inline( always ) ] + pub fn command_with_types< IntoName >( self, name : IntoName ) + -> + // CommandSubformer< K, Self > + CommandFormer + < + K, + CommandFormerDefinition + < + K, + Self, + Self, + impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, + >, + > + where + IntoName : core::convert::Into< String >, + { + + let former + // : CommandSubformer< K, Self > + // : CommandFormer + // < + // K, + // CommandFormerDefinition + // < + // K, + // Self, + // Self, + // AggregatorFormerCommandEnd2, + // > + // > + = CommandFormer::_begin_precise( None, Some( self ), AggregatorFormerCommandEnd2 ); - // #[ inline( always ) ] - // pub fn command< IntoName >( self, name : IntoName ) - // -> CommandFormer< K, Self, impl the_module::FormingEnd< Command< K >, Self > > - // where - // K : core::hash::Hash + std::cmp::Eq, - // IntoName : core::convert::Into< String >, - // { - // let on_end = | command : Command< K >, super_former : core::option::Option< Self > | -> Self - // { - // let mut super_former = super_former.unwrap(); - // if let Some( ref mut commands ) = super_former.storage.commands - // { - // commands.insert( command.name.clone(), command ); - // } - // else - // { - // let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - // commands.insert( command.name.clone(), command ); - // super_former.storage.commands = Some( commands ); - // } - // super_former - // }; - // let former = CommandFormer::begin( None, Some( self ), on_end ); - // former.name( name ) - // } + former.name( name ) + + } #[ inline( always ) ] - pub fn command< IntoName >( self, name : IntoName ) + pub fn command_with_closure< IntoName >( self, name : IntoName ) -> CommandSubformer< K, Self > - // CommandFormer - // < - // K, - // CommandFormerDefinition - // < - // K, - // Self, - // Self, - // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, - // >, - // > where IntoName : core::convert::Into< String >, { @@ -213,72 +206,60 @@ where super_former }; - let former - : CommandSubformer< K, Self > - // : CommandFormer - // < - // K, - // CommandFormerDefinition - // < - // K, - // Self, - // Self, - // former::FormingEndClosure< _ >, - // // former::FormingEndClosure< CommandFormerDefinitionTypes< K, Self, Self > >, - // // former::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, - // > - // > - = CommandFormer::begin( None, Some( self ), on_end ); - + let former = CommandFormer::begin( None, Some( self ), on_end ); former.name( name ) } - // pub fn hashset_1( self ) -> - // former::ContainerSubformer:: - // < - // String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End > - // > - // { - // self.hashset_1_set::< former::ContainerSubformer:: - // < - // String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End > - // >>() - // } - } #[ allow( non_camel_case_types ) ] -pub struct AggregatorFormerCommandEnd; +pub struct AggregatorFormerCommandEnd2; + #[ automatically_derived ] impl< K, Definition > former::FormingEnd < - former::HashMapDefinition< String, Command< K >, AggregatorFormer< K, Definition >, AggregatorFormer< K, Definition >, former::NoEnd >, + CommandFormerDefinitionTypes + < + K, + AggregatorFormer< K, Definition >, + AggregatorFormer< K, Definition >, + >, > -for AggregatorFormerCommandEnd +for AggregatorFormerCommandEnd2 where K : core::hash::Hash + std::cmp::Eq, Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes < - Storage = AggregatorFormerStorage< K > + Storage = AggregatorFormerStorage< K >, >, { #[ inline( always ) ] - fn call( &self, storage : std::collections::HashMap< String, Command< K > >, super_former : Option< AggregatorFormer< K, Definition > > ) + fn call + ( + &self, + command : CommandFormerStorage< K >, + super_former : Option< AggregatorFormer< K, Definition > >, + ) -> AggregatorFormer< K, Definition > { + + let command = former::StoragePreform::preform( command ); let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.commands + if let Some( ref mut commands ) = super_former.storage.commands { - former::ContainerAssign::assign( field, storage ); + former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); } else { - super_former.storage.commands = Some( storage ); + let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); + former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); + super_former.storage.commands = Some( commands ); } super_former + } } From 0d36e8fbece2143754080a5ea1452a1d65c17c5d Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 14:52:59 +0300 Subject: [PATCH 202/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index eef1a24bb4..a28f591bd7 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -263,6 +263,58 @@ where } } +// + +#[ allow( non_camel_case_types ) ] +pub struct ContainerAddElement; + +#[ automatically_derived ] +impl< K, Definition > former::FormingEnd +< + CommandFormerDefinitionTypes + < + K, + AggregatorFormer< K, Definition >, + AggregatorFormer< K, Definition >, + >, +> +for ContainerAddElement +where + K : core::hash::Hash + std::cmp::Eq, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = AggregatorFormerStorage< K >, + >, +{ + #[ inline( always ) ] + fn call + ( + &self, + command : CommandFormerStorage< K >, + super_former : Option< AggregatorFormer< K, Definition > >, + ) + -> + AggregatorFormer< K, Definition > + { + + let command = former::StoragePreform::preform( command ); + let mut super_former = super_former.unwrap(); + if let Some( ref mut commands ) = super_former.storage.commands + { + former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); + } + else + { + let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); + former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); + super_former.storage.commands = Some( commands ); + } + super_former + + } +} + // == // include!( "./only_test/subformer_basic.rs" ); From 7ebab8074c122d6b552711c7249f67a820da7253 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 15:25:02 +0300 Subject: [PATCH 203/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index a28f591bd7..2f00aa5820 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -265,6 +265,27 @@ where // +/// xxx : extend description +/// Convert an entity to an element which could be added to a container. +pub trait IntoElement< Target > +{ + /// Convert an entity to an element which could be added to a container. + fn into_element( self ) -> Target; +} + +impl< K > IntoElement< ( String, Command< K > ) > +for Command< K > +where + K : core::hash::Hash + std::cmp::Eq, +{ + fn into_element( self ) -> ( String, Command< K > ) + { + ( self.name.clone(), self ) + } +} + +// + #[ allow( non_camel_case_types ) ] pub struct ContainerAddElement; @@ -291,23 +312,34 @@ where fn call ( &self, - command : CommandFormerStorage< K >, + storage : CommandFormerStorage< K >, super_former : Option< AggregatorFormer< K, Definition > >, ) -> AggregatorFormer< K, Definition > { - let command = former::StoragePreform::preform( command ); + let storage = former::StoragePreform::preform( storage ); let mut super_former = super_former.unwrap(); if let Some( ref mut commands ) = super_former.storage.commands { - former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); + former::ContainerAdd::add + ( + commands, + IntoElement::< ( String, Command< K > ) >::into_element( storage ), + // ( storage.name.clone(), storage ), + ); + // former::ContainerAdd::add( commands, ( storage.name.clone(), storage ) ); } else { let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); + former::ContainerAdd::add + ( + &mut commands, + IntoElement::< ( String, Command< K > ) >::into_element( storage ), + // ( storage.name.clone(), storage ), + ); super_former.storage.commands = Some( commands ); } super_former From 382c8abdf99cd66a2b384df36357ffd5752f72f1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 15:28:10 +0300 Subject: [PATCH 204/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 2f00aa5820..6591a07d93 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -290,20 +290,20 @@ where pub struct ContainerAddElement; #[ automatically_derived ] -impl< K, Definition > former::FormingEnd +impl< K, SuperDefinition > former::FormingEnd < CommandFormerDefinitionTypes < K, - AggregatorFormer< K, Definition >, - AggregatorFormer< K, Definition >, + AggregatorFormer< K, SuperDefinition >, + AggregatorFormer< K, SuperDefinition >, >, > for ContainerAddElement where K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes + SuperDefinition : former::FormerDefinition, + SuperDefinition::Types : former::FormerDefinitionTypes < Storage = AggregatorFormerStorage< K >, >, @@ -313,10 +313,10 @@ where ( &self, storage : CommandFormerStorage< K >, - super_former : Option< AggregatorFormer< K, Definition > >, + super_former : Option< AggregatorFormer< K, SuperDefinition > >, ) -> - AggregatorFormer< K, Definition > + AggregatorFormer< K, SuperDefinition > { let storage = former::StoragePreform::preform( storage ); From 56f4af522e5d9bd645aac2b3a3aefbd3ae2ff965 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 15:28:49 +0300 Subject: [PATCH 205/533] former : evolve --- module/core/former/tests/inc/former_tests/subformer_basic.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 6591a07d93..b91199bd6a 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -329,7 +329,6 @@ where IntoElement::< ( String, Command< K > ) >::into_element( storage ), // ( storage.name.clone(), storage ), ); - // former::ContainerAdd::add( commands, ( storage.name.clone(), storage ) ); } else { From a2d745884dfc103552295db39cf3afc44a8ebdb9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 15:56:00 +0300 Subject: [PATCH 206/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 141 ++++++++++++------ 1 file changed, 95 insertions(+), 46 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index b91199bd6a..a0364455f4 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -286,66 +286,115 @@ where // -#[ allow( non_camel_case_types ) ] -pub struct ContainerAddElement; +/// xxx : extend description +/// get container for a field out of a storage +pub trait StorageContainer< Target > +{ + // fn container_get( &self ) -> &Target; + fn container_mut( &mut self ) -> &mut Target; +} -#[ automatically_derived ] -impl< K, SuperDefinition > former::FormingEnd -< - CommandFormerDefinitionTypes - < - K, - AggregatorFormer< K, SuperDefinition >, - AggregatorFormer< K, SuperDefinition >, - >, -> -for ContainerAddElement +impl< K > StorageContainer< collection_tools::HashMap< String, Command< K > > > +for AggregatorFormerStorage< K > where K : core::hash::Hash + std::cmp::Eq, - SuperDefinition : former::FormerDefinition, - SuperDefinition::Types : former::FormerDefinitionTypes - < - Storage = AggregatorFormerStorage< K >, - >, { - #[ inline( always ) ] - fn call - ( - &self, - storage : CommandFormerStorage< K >, - super_former : Option< AggregatorFormer< K, SuperDefinition > >, - ) - -> - AggregatorFormer< K, SuperDefinition > + // fn container_get( &self ) -> &collection_tools::HashMap< String, Command< K > > + // { + // &self.commands + // } + fn container_mut( &mut self ) -> &mut collection_tools::HashMap< String, Command< K > > { - - let storage = former::StoragePreform::preform( storage ); - let mut super_former = super_former.unwrap(); - if let Some( ref mut commands ) = super_former.storage.commands + if let Some( ref mut commands ) = self.commands { - former::ContainerAdd::add - ( - commands, - IntoElement::< ( String, Command< K > ) >::into_element( storage ), - // ( storage.name.clone(), storage ), - ); + commands } else { let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - former::ContainerAdd::add - ( - &mut commands, - IntoElement::< ( String, Command< K > ) >::into_element( storage ), - // ( storage.name.clone(), storage ), - ); - super_former.storage.commands = Some( commands ); + self.commands = Some( commands ); + self.commands.as_mut().unwrap() } - super_former - } } +// + +#[ allow( non_camel_case_types ) ] +pub struct ContainerAddElement; + +// #[ automatically_derived ] +// impl< /*K,*/ SuperDefinition, SuperFormer, SubDefinitionTypes > former::FormingEnd +// < +// SubDefinitionTypes, +// // CommandFormerDefinitionTypes +// // < +// // K, +// // AggregatorFormer< K, SuperDefinition >, +// // AggregatorFormer< K, SuperDefinition >, +// // >, +// +// > +// for ContainerAddElement +// where +// // K : core::hash::Hash + std::cmp::Eq, +// SuperDefinition : former::FormerDefinition, +// SuperDefinition::Types : former::FormerDefinitionTypes +// < +// // Storage = AggregatorFormerStorage< K >, +// // Storage = SubDefinitionTypes::Storage, +// >, +// SubDefinitionTypes : former::FormerDefinitionTypes +// < +// // Storage = Storate, +// Formed = SuperFormer, +// Context = SuperFormer, +// >, +// SubDefinitionTypes::Storage : former::Storage< Formed = SuperFormer >, +// SubDefinitionTypes::Storage : former::StoragePreform, +// { +// #[ inline( always ) ] +// fn call +// ( +// &self, +// // storage : CommandFormerStorage< K >, +// storage : SubDefinitionTypes::Storage, +// super_former : Option< SuperFormer >, +// // super_former : Option< AggregatorFormer< K, SuperDefinition > >, +// ) +// -> +// SuperFormer +// // AggregatorFormer< K, SuperDefinition > +// { +// +// let storage = former::StoragePreform::preform( storage ); +// let mut super_former = super_former.unwrap(); +// if let Some( ref mut container ) = super_former.storage.commands +// { +// former::ContainerAdd::add +// ( +// container, +// IntoElement::< ( String, Command< K > ) >::into_element( storage ), +// // ( storage.name.clone(), storage ), +// ); +// } +// else +// { +// // let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); +// let mut container = Default::default(); +// former::ContainerAdd::add +// ( +// &mut container, +// IntoElement::< ( String, Command< K > ) >::into_element( storage ), +// // ( storage.name.clone(), storage ), +// ); +// super_former.storage.commands = Some( container ); +// } +// super_former +// +// } +// } + // == // include!( "./only_test/subformer_basic.rs" ); From c7ec0c60781d3a14c4af799bb85b7b1c0e118190 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 16:15:32 +0300 Subject: [PATCH 207/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 97 ++++++++++++------- 1 file changed, 61 insertions(+), 36 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index a0364455f4..20d6ea4bdf 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -288,21 +288,16 @@ where /// xxx : extend description /// get container for a field out of a storage -pub trait StorageContainer< Target > +pub trait StorageExtractContainer< Target > { - // fn container_get( &self ) -> &Target; fn container_mut( &mut self ) -> &mut Target; } -impl< K > StorageContainer< collection_tools::HashMap< String, Command< K > > > +impl< K > StorageExtractContainer< collection_tools::HashMap< String, Command< K > > > for AggregatorFormerStorage< K > where K : core::hash::Hash + std::cmp::Eq, { - // fn container_get( &self ) -> &collection_tools::HashMap< String, Command< K > > - // { - // &self.commands - // } fn container_mut( &mut self ) -> &mut collection_tools::HashMap< String, Command< K > > { if let Some( ref mut commands ) = self.commands @@ -311,7 +306,7 @@ where } else { - let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); + let commands : collection_tools::HashMap< String, Command< K > > = Default::default(); self.commands = Some( commands ); self.commands.as_mut().unwrap() } @@ -320,11 +315,33 @@ where // -#[ allow( non_camel_case_types ) ] -pub struct ContainerAddElement; +/// xxx : extend description +/// extract storage from a former +pub trait FormerExtractStorage +{ + type Storage; + fn storage_mut( &mut self ) -> &mut Self::Storage; +} + +impl< K > FormerExtractStorage +for AggregatorFormer< K > +where + K : core::hash::Hash + std::cmp::Eq, +{ + type Storage = AggregatorFormerStorage< K >; + fn storage_mut( &mut self ) -> &mut Self::Storage + { + &mut self.storage + } +} + +// + +pub struct ContainerAddElement< SuperDefinition, SuperContainer, Element > +( core::marker::PhantomData< fn( SuperDefinition, SuperContainer, Element ) > ); -// #[ automatically_derived ] -// impl< /*K,*/ SuperDefinition, SuperFormer, SubDefinitionTypes > former::FormingEnd +// impl< SuperDefinition, SuperFormer, SuperContainer, Element, SubDefinitionTypes > +// former::FormingEnd // < // SubDefinitionTypes, // // CommandFormerDefinitionTypes @@ -333,9 +350,8 @@ pub struct ContainerAddElement; // // AggregatorFormer< K, SuperDefinition >, // // AggregatorFormer< K, SuperDefinition >, // // >, -// // > -// for ContainerAddElement +// for ContainerAddElement< SuperDefinition, > // where // // K : core::hash::Hash + std::cmp::Eq, // SuperDefinition : former::FormerDefinition, @@ -352,6 +368,7 @@ pub struct ContainerAddElement; // >, // SubDefinitionTypes::Storage : former::Storage< Formed = SuperFormer >, // SubDefinitionTypes::Storage : former::StoragePreform, +// SubDefinitionTypes::Formed : IntoElement< Element > // { // #[ inline( always ) ] // fn call @@ -369,29 +386,37 @@ pub struct ContainerAddElement; // // let storage = former::StoragePreform::preform( storage ); // let mut super_former = super_former.unwrap(); -// if let Some( ref mut container ) = super_former.storage.commands -// { -// former::ContainerAdd::add -// ( -// container, -// IntoElement::< ( String, Command< K > ) >::into_element( storage ), -// // ( storage.name.clone(), storage ), -// ); -// } -// else -// { -// // let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); -// let mut container = Default::default(); -// former::ContainerAdd::add -// ( -// &mut container, -// IntoElement::< ( String, Command< K > ) >::into_element( storage ), -// // ( storage.name.clone(), storage ), -// ); -// super_former.storage.commands = Some( container ); -// } -// super_former +// let container = StorageExtractContainer::< SuperContainer >::container_mut( FormerExtractStorage::storage_mut( super_former ) ); +// +// former::ContainerAdd::add +// ( +// container, +// IntoElement::< SubDefinitionTypes::Formed >::into_element( storage ), +// ); // +// // if let Some( ref mut container ) = super_former.storage.commands +// // { +// // former::ContainerAdd::add +// // ( +// // container, +// // IntoElement::< ( String, Command< K > ) >::into_element( storage ), +// // // ( storage.name.clone(), storage ), +// // ); +// // } +// // else +// // { +// // // let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); +// // let mut container = Default::default(); +// // former::ContainerAdd::add +// // ( +// // &mut container, +// // IntoElement::< ( String, Command< K > ) >::into_element( storage ), +// // // ( storage.name.clone(), storage ), +// // ); +// // super_former.storage.commands = Some( container ); +// // } +// +// super_former // } // } From 85b04e0371088e5eae904a8157785383b93511e7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 16:16:38 +0300 Subject: [PATCH 208/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 145 +++++++++--------- 1 file changed, 73 insertions(+), 72 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 20d6ea4bdf..f6dcae01cb 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -340,52 +340,53 @@ where pub struct ContainerAddElement< SuperDefinition, SuperContainer, Element > ( core::marker::PhantomData< fn( SuperDefinition, SuperContainer, Element ) > ); -// impl< SuperDefinition, SuperFormer, SuperContainer, Element, SubDefinitionTypes > -// former::FormingEnd -// < -// SubDefinitionTypes, -// // CommandFormerDefinitionTypes -// // < -// // K, -// // AggregatorFormer< K, SuperDefinition >, -// // AggregatorFormer< K, SuperDefinition >, -// // >, -// > -// for ContainerAddElement< SuperDefinition, > -// where -// // K : core::hash::Hash + std::cmp::Eq, -// SuperDefinition : former::FormerDefinition, -// SuperDefinition::Types : former::FormerDefinitionTypes -// < -// // Storage = AggregatorFormerStorage< K >, -// // Storage = SubDefinitionTypes::Storage, -// >, -// SubDefinitionTypes : former::FormerDefinitionTypes -// < -// // Storage = Storate, -// Formed = SuperFormer, -// Context = SuperFormer, -// >, -// SubDefinitionTypes::Storage : former::Storage< Formed = SuperFormer >, -// SubDefinitionTypes::Storage : former::StoragePreform, -// SubDefinitionTypes::Formed : IntoElement< Element > -// { -// #[ inline( always ) ] -// fn call -// ( -// &self, -// // storage : CommandFormerStorage< K >, -// storage : SubDefinitionTypes::Storage, -// super_former : Option< SuperFormer >, -// // super_former : Option< AggregatorFormer< K, SuperDefinition > >, -// ) -// -> -// SuperFormer -// // AggregatorFormer< K, SuperDefinition > -// { -// -// let storage = former::StoragePreform::preform( storage ); -// let mut super_former = super_former.unwrap(); +impl< SuperDefinition, SuperFormer, SuperContainer, Element, SubDefinitionTypes > +former::FormingEnd +< + SubDefinitionTypes, + // CommandFormerDefinitionTypes + // < + // K, + // AggregatorFormer< K, SuperDefinition >, + // AggregatorFormer< K, SuperDefinition >, + // >, +> +for ContainerAddElement< SuperDefinition, SuperContainer, Element > +where + // K : core::hash::Hash + std::cmp::Eq, + SuperDefinition : former::FormerDefinition, + SuperDefinition::Types : former::FormerDefinitionTypes + < + // Storage = AggregatorFormerStorage< K >, + // Storage = SubDefinitionTypes::Storage, + >, + SubDefinitionTypes : former::FormerDefinitionTypes + < + // Storage = Storate, + Formed = SuperFormer, + Context = SuperFormer, + >, + SubDefinitionTypes::Storage : former::Storage< Formed = SuperFormer >, + SubDefinitionTypes::Storage : former::StoragePreform, + SubDefinitionTypes::Formed : IntoElement< Element > +{ + #[ inline( always ) ] + fn call + ( + &self, + // storage : CommandFormerStorage< K >, + storage : SubDefinitionTypes::Storage, + super_former : Option< SuperFormer >, + // super_former : Option< AggregatorFormer< K, SuperDefinition > >, + ) + -> + SuperFormer + // AggregatorFormer< K, SuperDefinition > + { + + let storage = former::StoragePreform::preform( storage ); + let mut super_former = super_former.unwrap(); + // let container = StorageExtractContainer::< SuperContainer >::container_mut( FormerExtractStorage::storage_mut( super_former ) ); // // former::ContainerAdd::add @@ -393,32 +394,32 @@ pub struct ContainerAddElement< SuperDefinition, SuperContainer, Element > // container, // IntoElement::< SubDefinitionTypes::Formed >::into_element( storage ), // ); -// -// // if let Some( ref mut container ) = super_former.storage.commands -// // { -// // former::ContainerAdd::add -// // ( -// // container, -// // IntoElement::< ( String, Command< K > ) >::into_element( storage ), -// // // ( storage.name.clone(), storage ), -// // ); -// // } -// // else -// // { -// // // let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); -// // let mut container = Default::default(); -// // former::ContainerAdd::add -// // ( -// // &mut container, -// // IntoElement::< ( String, Command< K > ) >::into_element( storage ), -// // // ( storage.name.clone(), storage ), -// // ); -// // super_former.storage.commands = Some( container ); -// // } -// -// super_former -// } -// } + + // if let Some( ref mut container ) = super_former.storage.commands + // { + // former::ContainerAdd::add + // ( + // container, + // IntoElement::< ( String, Command< K > ) >::into_element( storage ), + // // ( storage.name.clone(), storage ), + // ); + // } + // else + // { + // // let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); + // let mut container = Default::default(); + // former::ContainerAdd::add + // ( + // &mut container, + // IntoElement::< ( String, Command< K > ) >::into_element( storage ), + // // ( storage.name.clone(), storage ), + // ); + // super_former.storage.commands = Some( container ); + // } + + super_former + } +} // == From 41fcccbcd2b29e948a51d39fb169ca4ec3f92574 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 16:19:08 +0300 Subject: [PATCH 209/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index f6dcae01cb..90cbd95c4b 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -360,6 +360,8 @@ where // Storage = AggregatorFormerStorage< K >, // Storage = SubDefinitionTypes::Storage, >, + SuperFormer : FormerExtractStorage, + < SuperFormer as FormerExtractStorage >::Storage : StorageExtractContainer< SuperContainer >, SubDefinitionTypes : former::FormerDefinitionTypes < // Storage = Storate, @@ -387,13 +389,15 @@ where let storage = former::StoragePreform::preform( storage ); let mut super_former = super_former.unwrap(); -// let container = StorageExtractContainer::< SuperContainer >::container_mut( FormerExtractStorage::storage_mut( super_former ) ); -// -// former::ContainerAdd::add -// ( -// container, -// IntoElement::< SubDefinitionTypes::Formed >::into_element( storage ), -// ); + let container = StorageExtractContainer + ::< SuperContainer > + ::container_mut( FormerExtractStorage::storage_mut( &mut super_former ) ); + + // former::ContainerAdd::add + // ( + // container, + // IntoElement::< SubDefinitionTypes::Formed >::into_element( storage ), + // ); // if let Some( ref mut container ) = super_former.storage.commands // { From 816ba048c61181fe1e9bf24a5731f5fdbc5d17d2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 17:10:56 +0300 Subject: [PATCH 210/533] former : evolve --- module/core/former/src/axiomatic.rs | 12 ++++-- module/core/former/src/hash_map.rs | 3 +- module/core/former/src/hash_set.rs | 4 +- module/core/former/src/vector.rs | 4 +- .../tests/inc/former_tests/a_basic_manual.rs | 5 ++- .../a_containers_with_subformer_manual.rs | 4 +- .../inc/former_tests/a_primitives_manual.rs | 4 +- .../parametrized_struct_manual.rs | 7 +++- .../inc/former_tests/string_slice_manual.rs | 7 +++- .../tests/inc/former_tests/subformer_basic.rs | 40 ++++++++++++------- module/core/former_meta/src/derive/former.rs | 6 ++- 11 files changed, 65 insertions(+), 31 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 34f191ded4..f9af1f3ecf 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -6,9 +6,15 @@ pub trait Storage : ::core::default::Default } /// zzz : write description -pub trait StoragePreform : Storage +// pub trait StoragePreform : Storage +// { +// fn preform( self ) -> Self::Formed; +// } + +pub trait StoragePreform { - fn preform( self ) -> Self::Formed; + type Preformed; + fn preform( self ) -> Self::Preformed; } /// zzz : write description @@ -75,7 +81,7 @@ pub struct ReturnPreformed; impl< Definition > FormingEnd< Definition > for ReturnPreformed where - Definition::Storage : StoragePreform< Formed = Definition::Formed >, + Definition::Storage : StoragePreform< Preformed = Definition::Formed >, Definition : FormerDefinitionTypes, { #[ inline( always ) ] diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 9e4ade2a37..b7230ba78b 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -61,8 +61,9 @@ for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { + type Preformed = HashMap< K, E >; // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed - fn preform( self ) -> Self::Formed + fn preform( self ) -> Self::Preformed { self } diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index bf65f0229c..b2cec7cb93 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -49,8 +49,10 @@ for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { + type Preformed = HashSet< K >; // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed - fn preform( self ) -> Self::Formed + // fn preform( self ) -> Self::Formed + fn preform( self ) -> Self::Preformed { self } diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 26b18c5704..4e8faf4463 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -34,7 +34,9 @@ for Vec< E > impl< E > StoragePreform for Vec< E > { - fn preform( self ) -> Self::Formed + type Preformed = Vec< E >; + // fn preform( self ) -> Self::Formed + fn preform( self ) -> Self::Preformed { self } diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 233293af3f..db42694c71 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -99,7 +99,8 @@ impl former::Storage for Struct1FormerStorage impl former::StoragePreform for Struct1FormerStorage { - fn preform( mut self ) -> < Self as former::Storage >::Formed + type Preformed = < Self as former::Storage >::Formed; + fn preform( mut self ) -> Self::Preformed { let int_1 = if self.int_1.is_some() { @@ -248,7 +249,7 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Struct1 >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Struct1 >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 60d0b05409..3f46c7cc8a 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -107,7 +107,9 @@ impl former::Storage for Struct1FormerStorage impl former::StoragePreform for Struct1FormerStorage { - fn preform( mut self ) -> < Self as former::Storage >::Formed + type Preformed = Struct1; + // fn preform( mut self ) -> < Self as former::Storage >::Formed + fn preform( mut self ) -> Self::Preformed { let vec_1 = if self.vec_1.is_some() { diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 3038918978..d65b619ffb 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -117,8 +117,10 @@ for Struct1FormerStorage impl former::StoragePreform for Struct1FormerStorage { + type Preformed = Struct1; - fn preform( mut self ) -> < Self as former::Storage >::Formed + // fn preform( mut self ) -> < Self as former::Storage >::Formed + fn preform( mut self ) -> Self::Preformed { let int_1 = if self.int_1.is_some() diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 6450f4a8d7..63ed1c712d 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -127,7 +127,10 @@ impl< K, > former :: Storage for CommandFormerStorage< K, > where K : core :: ha impl< K, > former :: StoragePreform for CommandFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, { - fn preform( mut self ) -> < Self as former :: Storage > :: Formed + type Preformed = Command< K, >; + + fn preform( mut self ) -> Self::Preformed + // fn preform( mut self ) -> < Self as former :: Storage > :: Formed { let name = if self.name.is_some() { @@ -295,7 +298,7 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, >, Formed = Command< K, > >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Command< K, > > + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Command< K, > > { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 19b47882ed..075c9e8723 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -100,7 +100,10 @@ impl< 'a > former::Storage for Struct1FormerStorage< 'a > impl< 'a > former::StoragePreform for Struct1FormerStorage< 'a > { - fn preform( mut self ) -> < Self as former::Storage >::Formed + type Preformed = Struct1< 'a >; + + fn preform( mut self ) -> Self::Preformed + // fn preform( mut self ) -> < Self as former::Storage >::Formed // fn preform( mut self ) -> Struct1< 'a > { let string_slice_1 = if self.string_slice_1.is_some() @@ -248,7 +251,7 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a > >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Struct1< 'a > >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Struct1< 'a > >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 90cbd95c4b..d8f32024d1 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -139,7 +139,7 @@ where Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = Aggregator< K > >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Aggregator< K > >, { @@ -246,7 +246,7 @@ where AggregatorFormer< K, Definition > { - let command = former::StoragePreform::preform( command ); + let command = former::StoragePreform::preform( command ); let mut super_former = super_former.unwrap(); if let Some( ref mut commands ) = super_former.storage.commands { @@ -337,10 +337,10 @@ where // -pub struct ContainerAddElement< SuperDefinition, SuperContainer, Element > -( core::marker::PhantomData< fn( SuperDefinition, SuperContainer, Element ) > ); +pub struct ContainerAddElement< SuperDefinition, SuperContainer, Element, SubFormed > +( core::marker::PhantomData< fn( SuperDefinition, SuperContainer, Element, SubFormed ) > ); -impl< SuperDefinition, SuperFormer, SuperContainer, Element, SubDefinitionTypes > +impl< SuperDefinition, SuperFormer, SuperContainer, Element, SubFormed, SubDefinitionTypes > former::FormingEnd < SubDefinitionTypes, @@ -351,26 +351,34 @@ former::FormingEnd // AggregatorFormer< K, SuperDefinition >, // >, > -for ContainerAddElement< SuperDefinition, SuperContainer, Element > +for ContainerAddElement< SuperDefinition, SuperContainer, Element, SubFormed > where + // K : core::hash::Hash + std::cmp::Eq, SuperDefinition : former::FormerDefinition, + < SuperDefinition::Types as former::FormerDefinitionTypes >::Storage : StorageExtractContainer< SuperContainer >, SuperDefinition::Types : former::FormerDefinitionTypes < // Storage = AggregatorFormerStorage< K >, // Storage = SubDefinitionTypes::Storage, >, - SuperFormer : FormerExtractStorage, + + SuperFormer : FormerExtractStorage< Storage = < SuperDefinition::Types as former::FormerDefinitionTypes >::Storage >, < SuperFormer as FormerExtractStorage >::Storage : StorageExtractContainer< SuperContainer >, + SuperContainer : former::ContainerAdd< Element = Element >, + SubDefinitionTypes : former::FormerDefinitionTypes < // Storage = Storate, Formed = SuperFormer, Context = SuperFormer, >, - SubDefinitionTypes::Storage : former::Storage< Formed = SuperFormer >, + // SubDefinitionTypes::Storage : former::StoragePreform< Preformed = SuperFormer >, + SubDefinitionTypes::Storage : former::StoragePreform< Preformed = SubFormed >, SubDefinitionTypes::Storage : former::StoragePreform, - SubDefinitionTypes::Formed : IntoElement< Element > + + SubFormed : IntoElement< Element >, + // SubDefinitionTypes::Formed : IntoElement< Element >, { #[ inline( always ) ] fn call @@ -386,18 +394,20 @@ where // AggregatorFormer< K, SuperDefinition > { - let storage = former::StoragePreform::preform( storage ); + let storage : SubFormed = former::StoragePreform::preform( storage ); let mut super_former = super_former.unwrap(); let container = StorageExtractContainer ::< SuperContainer > ::container_mut( FormerExtractStorage::storage_mut( &mut super_former ) ); - // former::ContainerAdd::add - // ( - // container, - // IntoElement::< SubDefinitionTypes::Formed >::into_element( storage ), - // ); + // let x = IntoElement::< Element >::into_element( storage ); + + former::ContainerAdd::add + ( + container, + IntoElement::< Element >::into_element( storage ), + ); // if let Some( ref mut container ) = super_former.storage.commands // { diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 561597b625..b68f521e40 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1352,8 +1352,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where #struct_generics_where { + type Preformed = #struct_name < #struct_generics_ty >; - fn preform( mut self ) -> < Self as former::Storage >::Formed + // fn preform( mut self ) -> < Self as former::Storage >::Formed + fn preform( mut self ) -> Self::Preformed { #( #fields_form )* // Rust does not support that, yet @@ -1509,7 +1511,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #struct_generics_ty >, Formed = #struct_name < #struct_generics_ty > >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::Storage< Formed = #struct_name < #struct_generics_ty > >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = #struct_name < #struct_generics_ty > >, #former_generics_where { From e76308d225214c7c2b16397bb1e411831c962d4d Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 17:18:40 +0300 Subject: [PATCH 211/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 113 +++++++++++++----- 1 file changed, 84 insertions(+), 29 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index d8f32024d1..f32c550d07 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -143,6 +143,36 @@ where { + #[ inline( always ) ] + pub fn command_with_closure< IntoName >( self, name : IntoName ) + -> + CommandSubformer< K, Self > + where + IntoName : core::convert::Into< String >, + { + + let on_end = | command : CommandFormerStorage< K >, super_former : core::option::Option< Self > | -> Self + { + let command = former::StoragePreform::preform( command ); + let mut super_former = super_former.unwrap(); + if let Some( ref mut commands ) = super_former.storage.commands + { + former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); + } + else + { + let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); + former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); + super_former.storage.commands = Some( commands ); + } + super_former + }; + + let former = CommandFormer::begin( None, Some( self ), on_end ); + former.name( name ) + + } + #[ inline( always ) ] pub fn command_with_types< IntoName >( self, name : IntoName ) -> @@ -181,35 +211,60 @@ where } - #[ inline( always ) ] - pub fn command_with_closure< IntoName >( self, name : IntoName ) - -> - CommandSubformer< K, Self > - where - IntoName : core::convert::Into< String >, - { - - let on_end = | command : CommandFormerStorage< K >, super_former : core::option::Option< Self > | -> Self - { - let command = former::StoragePreform::preform( command ); - let mut super_former = super_former.unwrap(); - if let Some( ref mut commands ) = super_former.storage.commands - { - former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); - } - else - { - let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); - super_former.storage.commands = Some( commands ); - } - super_former - }; - - let former = CommandFormer::begin( None, Some( self ), on_end ); - former.name( name ) - - } +// #[ inline( always ) ] +// pub fn command_with_helper< IntoName >( self, name : IntoName ) +// -> +// // CommandSubformer< K, Self > +// CommandFormer +// < +// K, +// CommandFormerDefinition +// < +// K, +// Self, +// Self, +// impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, +// >, +// > +// where +// IntoName : core::convert::Into< String >, +// { +// +// let former +// // : CommandSubformer< K, Self > +// // : CommandFormer +// // < +// // K, +// // CommandFormerDefinition +// // < +// // K, +// // Self, +// // Self, +// // AggregatorFormerCommandEnd2, +// // > +// // > +// = CommandFormer::_begin_precise +// ( +// None, +// Some( self ), +// ContainerAddElement:: +// < +// CommandFormerDefinition +// < +// K, +// Self, +// Self, +// impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, +// >, +// SuperContainer, +// Element, +// SubFormed +// >, +// ); +// +// former.name( name ) +// +// } } From 503517f5b454247bfe620c22a660dab94a987683 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 17:20:51 +0300 Subject: [PATCH 212/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index f32c550d07..7510db87ba 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -395,10 +395,10 @@ where pub struct ContainerAddElement< SuperDefinition, SuperContainer, Element, SubFormed > ( core::marker::PhantomData< fn( SuperDefinition, SuperContainer, Element, SubFormed ) > ); -impl< SuperDefinition, SuperFormer, SuperContainer, Element, SubFormed, SubDefinitionTypes > +impl< SuperDefinition, SuperFormer, SuperContainer, Element, SubFormed, SubDefinition > former::FormingEnd < - SubDefinitionTypes, + SubDefinition, // CommandFormerDefinitionTypes // < // K, @@ -410,37 +410,38 @@ for ContainerAddElement< SuperDefinition, SuperContainer, Element, SubFormed > where // K : core::hash::Hash + std::cmp::Eq, - SuperDefinition : former::FormerDefinition, - < SuperDefinition::Types as former::FormerDefinitionTypes >::Storage : StorageExtractContainer< SuperContainer >, - SuperDefinition::Types : former::FormerDefinitionTypes - < - // Storage = AggregatorFormerStorage< K >, - // Storage = SubDefinitionTypes::Storage, - >, + SuperDefinition : former::FormerDefinitionTypes, + SuperDefinition::Storage : StorageExtractContainer< SuperContainer >, + + // SuperDefinition::Types : former::FormerDefinitionTypes + // < + // // Storage = AggregatorFormerStorage< K >, + // // Storage = SubDefinition::Storage, + // >, - SuperFormer : FormerExtractStorage< Storage = < SuperDefinition::Types as former::FormerDefinitionTypes >::Storage >, + SuperFormer : FormerExtractStorage< Storage = SuperDefinition::Storage >, < SuperFormer as FormerExtractStorage >::Storage : StorageExtractContainer< SuperContainer >, SuperContainer : former::ContainerAdd< Element = Element >, - SubDefinitionTypes : former::FormerDefinitionTypes + SubDefinition : former::FormerDefinitionTypes < // Storage = Storate, Formed = SuperFormer, Context = SuperFormer, >, - // SubDefinitionTypes::Storage : former::StoragePreform< Preformed = SuperFormer >, - SubDefinitionTypes::Storage : former::StoragePreform< Preformed = SubFormed >, - SubDefinitionTypes::Storage : former::StoragePreform, + // SubDefinition::Storage : former::StoragePreform< Preformed = SuperFormer >, + SubDefinition::Storage : former::StoragePreform< Preformed = SubFormed >, + SubDefinition::Storage : former::StoragePreform, SubFormed : IntoElement< Element >, - // SubDefinitionTypes::Formed : IntoElement< Element >, + // SubDefinition::Formed : IntoElement< Element >, { #[ inline( always ) ] fn call ( &self, // storage : CommandFormerStorage< K >, - storage : SubDefinitionTypes::Storage, + storage : SubDefinition::Storage, super_former : Option< SuperFormer >, // super_former : Option< AggregatorFormer< K, SuperDefinition > >, ) From 5c97fe955fc57f920c328c8baa95b8ade1b9851c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 17:53:52 +0300 Subject: [PATCH 213/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 154 ++++++++++++------ 1 file changed, 102 insertions(+), 52 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 7510db87ba..9b848cf47c 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -211,60 +211,99 @@ where } -// #[ inline( always ) ] -// pub fn command_with_helper< IntoName >( self, name : IntoName ) -// -> -// // CommandSubformer< K, Self > -// CommandFormer -// < -// K, -// CommandFormerDefinition + #[ inline( always ) ] + pub fn command_with_helper< IntoName >( self, name : IntoName ) + -> + // () + // CommandSubformer< K, Self > + CommandFormer + < + K, + CommandFormerDefinition + < + K, + Self, + Self, + impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, + >, + > + where + IntoName : core::convert::Into< String >, + + ContainerAddElement + < + < Definition as former::FormerDefinition >::Types, + collection_tools::HashMap + < + String, + Command< K > + >, + ( + String, + Command< K >, + ), + Command< K > + > + : + former::FormingEnd + < + CommandFormerDefinitionTypes + < + K, + AggregatorFormer< K, Definition >, + AggregatorFormer< K, Definition > + > + > + { + + let former + // : CommandSubformer< K, Self > + : CommandFormer + < + K, + CommandFormerDefinition + < + K, + Self, + Self, + _, + > + > + = CommandFormer::_begin_precise + ( + None, + Some( self ), + ContainerAddElement:: + < + Definition::Types, + collection_tools::HashMap< String, Command< K > >, + ( String, Command< K > ), + Command< K >, + > + ::new(), + ); + +// let callback = ContainerAddElement +// :: // < -// K, -// Self, -// Self, -// impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, -// >, -// > -// where -// IntoName : core::convert::Into< String >, -// { +// Definition::Types, +// collection_tools::HashMap< String, Command< K > >, +// ( String, Command< K > ), +// Command< K >, +// > +// ::new(); // -// let former -// // : CommandSubformer< K, Self > -// // : CommandFormer -// // < -// // K, -// // CommandFormerDefinition -// // < -// // K, -// // Self, -// // Self, -// // AggregatorFormerCommandEnd2, -// // > -// // > -// = CommandFormer::_begin_precise -// ( -// None, -// Some( self ), -// ContainerAddElement:: -// < -// CommandFormerDefinition -// < -// K, -// Self, -// Self, -// impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, -// >, -// SuperContainer, -// Element, -// SubFormed -// >, -// ); +// let command : CommandFormerStorage< K > = Default::default(); +// // let super_former : core::option::Option< Self > = ; // -// former.name( name ) -// -// } +// // use former::FormingEnd; +// let got = former::FormingEnd +// ::< CommandFormerDefinitionTypes< K, Self, Self > > +// ::call( &callback, command, Some( self ) ); + + former.name( name ) + + } } @@ -395,6 +434,15 @@ where pub struct ContainerAddElement< SuperDefinition, SuperContainer, Element, SubFormed > ( core::marker::PhantomData< fn( SuperDefinition, SuperContainer, Element, SubFormed ) > ); +impl< SuperDefinition, SuperContainer, Element, SubFormed > +ContainerAddElement< SuperDefinition, SuperContainer, Element, SubFormed > +{ + pub fn new() -> Self + { + Self( core::marker::PhantomData ) + } +} + impl< SuperDefinition, SuperFormer, SuperContainer, Element, SubFormed, SubDefinition > former::FormingEnd < @@ -431,11 +479,12 @@ where >, // SubDefinition::Storage : former::StoragePreform< Preformed = SuperFormer >, SubDefinition::Storage : former::StoragePreform< Preformed = SubFormed >, - SubDefinition::Storage : former::StoragePreform, + // SubDefinition::Storage : former::StoragePreform, SubFormed : IntoElement< Element >, // SubDefinition::Formed : IntoElement< Element >, { + #[ inline( always ) ] fn call ( @@ -489,6 +538,7 @@ where super_former } + } // == From 40d77943006d5a12dce1d3b417075b958c7fd9a7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 17:55:51 +0300 Subject: [PATCH 214/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 9b848cf47c..73e9ceffeb 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -457,46 +457,32 @@ former::FormingEnd for ContainerAddElement< SuperDefinition, SuperContainer, Element, SubFormed > where - // K : core::hash::Hash + std::cmp::Eq, SuperDefinition : former::FormerDefinitionTypes, SuperDefinition::Storage : StorageExtractContainer< SuperContainer >, - // SuperDefinition::Types : former::FormerDefinitionTypes - // < - // // Storage = AggregatorFormerStorage< K >, - // // Storage = SubDefinition::Storage, - // >, - SuperFormer : FormerExtractStorage< Storage = SuperDefinition::Storage >, < SuperFormer as FormerExtractStorage >::Storage : StorageExtractContainer< SuperContainer >, SuperContainer : former::ContainerAdd< Element = Element >, SubDefinition : former::FormerDefinitionTypes < - // Storage = Storate, Formed = SuperFormer, Context = SuperFormer, >, - // SubDefinition::Storage : former::StoragePreform< Preformed = SuperFormer >, SubDefinition::Storage : former::StoragePreform< Preformed = SubFormed >, - // SubDefinition::Storage : former::StoragePreform, SubFormed : IntoElement< Element >, - // SubDefinition::Formed : IntoElement< Element >, { #[ inline( always ) ] fn call ( &self, - // storage : CommandFormerStorage< K >, storage : SubDefinition::Storage, super_former : Option< SuperFormer >, - // super_former : Option< AggregatorFormer< K, SuperDefinition > >, ) -> SuperFormer - // AggregatorFormer< K, SuperDefinition > { let storage : SubFormed = former::StoragePreform::preform( storage ); @@ -506,36 +492,12 @@ where ::< SuperContainer > ::container_mut( FormerExtractStorage::storage_mut( &mut super_former ) ); - // let x = IntoElement::< Element >::into_element( storage ); - former::ContainerAdd::add ( container, IntoElement::< Element >::into_element( storage ), ); - // if let Some( ref mut container ) = super_former.storage.commands - // { - // former::ContainerAdd::add - // ( - // container, - // IntoElement::< ( String, Command< K > ) >::into_element( storage ), - // // ( storage.name.clone(), storage ), - // ); - // } - // else - // { - // // let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); - // let mut container = Default::default(); - // former::ContainerAdd::add - // ( - // &mut container, - // IntoElement::< ( String, Command< K > ) >::into_element( storage ), - // // ( storage.name.clone(), storage ), - // ); - // super_former.storage.commands = Some( container ); - // } - super_former } From 04d942007cd80c8ca3dcecde26046251da958b55 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 17:57:58 +0300 Subject: [PATCH 215/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 73e9ceffeb..7fb346d1df 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -434,8 +434,20 @@ where pub struct ContainerAddElement< SuperDefinition, SuperContainer, Element, SubFormed > ( core::marker::PhantomData< fn( SuperDefinition, SuperContainer, Element, SubFormed ) > ); -impl< SuperDefinition, SuperContainer, Element, SubFormed > -ContainerAddElement< SuperDefinition, SuperContainer, Element, SubFormed > +impl +< + SuperDefinition, + SuperContainer, + Element, + SubFormed, +> +ContainerAddElement +< + SuperDefinition, + SuperContainer, + Element, + SubFormed, +> { pub fn new() -> Self { @@ -443,7 +455,15 @@ ContainerAddElement< SuperDefinition, SuperContainer, Element, SubFormed > } } -impl< SuperDefinition, SuperFormer, SuperContainer, Element, SubFormed, SubDefinition > +impl +< + SuperDefinition, + SuperFormer, + SuperContainer, + Element, + SubFormed, + SubDefinition, +> former::FormingEnd < SubDefinition, From 333af2d275be79fdcf234283a4fb111366d9f554 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 18:02:05 +0300 Subject: [PATCH 216/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 7fb346d1df..e211b7c9ce 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -232,7 +232,7 @@ where ContainerAddElement < - < Definition as former::FormerDefinition >::Types, + // < Definition as former::FormerDefinition >::Types, collection_tools::HashMap < String, @@ -275,7 +275,7 @@ where Some( self ), ContainerAddElement:: < - Definition::Types, + // Definition::Types, collection_tools::HashMap< String, Command< K > >, ( String, Command< K > ), Command< K >, @@ -382,12 +382,12 @@ where /// xxx : extend description /// get container for a field out of a storage -pub trait StorageExtractContainer< Target > +pub trait FormerStorageExtractContainer< Target > { fn container_mut( &mut self ) -> &mut Target; } -impl< K > StorageExtractContainer< collection_tools::HashMap< String, Command< K > > > +impl< K > FormerStorageExtractContainer< collection_tools::HashMap< String, Command< K > > > for AggregatorFormerStorage< K > where K : core::hash::Hash + std::cmp::Eq, @@ -431,19 +431,19 @@ where // -pub struct ContainerAddElement< SuperDefinition, SuperContainer, Element, SubFormed > -( core::marker::PhantomData< fn( SuperDefinition, SuperContainer, Element, SubFormed ) > ); +pub struct ContainerAddElement< /*SuperDefinition,*/ SuperContainer, Element, SubFormed > +( core::marker::PhantomData< fn( /*SuperDefinition,*/ SuperContainer, Element, SubFormed ) > ); impl < - SuperDefinition, + // SuperDefinition, SuperContainer, Element, SubFormed, > ContainerAddElement < - SuperDefinition, + // SuperDefinition, SuperContainer, Element, SubFormed, @@ -457,7 +457,7 @@ ContainerAddElement impl < - SuperDefinition, + // SuperDefinition, SuperFormer, SuperContainer, Element, @@ -474,14 +474,21 @@ former::FormingEnd // AggregatorFormer< K, SuperDefinition >, // >, > -for ContainerAddElement< SuperDefinition, SuperContainer, Element, SubFormed > +for ContainerAddElement +< + // SuperDefinition, + SuperContainer, + Element, + SubFormed, +> where - SuperDefinition : former::FormerDefinitionTypes, - SuperDefinition::Storage : StorageExtractContainer< SuperContainer >, + // SuperDefinition : former::FormerDefinitionTypes, + // SuperDefinition::Storage : FormerStorageExtractContainer< SuperContainer >, - SuperFormer : FormerExtractStorage< Storage = SuperDefinition::Storage >, - < SuperFormer as FormerExtractStorage >::Storage : StorageExtractContainer< SuperContainer >, + // SuperFormer : FormerExtractStorage< Storage = SuperDefinition::Storage >, + SuperFormer : FormerExtractStorage<>, + < SuperFormer as FormerExtractStorage >::Storage : FormerStorageExtractContainer< SuperContainer >, SuperContainer : former::ContainerAdd< Element = Element >, SubDefinition : former::FormerDefinitionTypes @@ -508,7 +515,7 @@ where let storage : SubFormed = former::StoragePreform::preform( storage ); let mut super_former = super_former.unwrap(); - let container = StorageExtractContainer + let container = FormerStorageExtractContainer ::< SuperContainer > ::container_mut( FormerExtractStorage::storage_mut( &mut super_former ) ); From 28d6d42ac437e85252c6924eaf96f54e43833b48 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 18:09:44 +0300 Subject: [PATCH 217/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 40 +++++-------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index e211b7c9ce..1e7816193b 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -250,8 +250,8 @@ where CommandFormerDefinitionTypes < K, - AggregatorFormer< K, Definition >, - AggregatorFormer< K, Definition > + Self, + Self, > > { @@ -266,43 +266,23 @@ where K, Self, Self, - _, + ContainerAddElement:: + < + collection_tools::HashMap< String, Command< K > >, + ( String, Command< K > ), + Command< K >, + >, > > - = CommandFormer::_begin_precise + = CommandFormer::begin ( None, Some( self ), - ContainerAddElement:: - < - // Definition::Types, - collection_tools::HashMap< String, Command< K > >, - ( String, Command< K > ), - Command< K >, - > + ContainerAddElement ::new(), ); -// let callback = ContainerAddElement -// :: -// < -// Definition::Types, -// collection_tools::HashMap< String, Command< K > >, -// ( String, Command< K > ), -// Command< K >, -// > -// ::new(); -// -// let command : CommandFormerStorage< K > = Default::default(); -// // let super_former : core::option::Option< Self > = ; -// -// // use former::FormingEnd; -// let got = former::FormingEnd -// ::< CommandFormerDefinitionTypes< K, Self, Self > > -// ::call( &callback, command, Some( self ) ); - former.name( name ) - } } From c5cbde58c9db66471e5d9679246993d31bd6c506 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 18:12:03 +0300 Subject: [PATCH 218/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 1e7816193b..3406515f10 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -232,7 +232,6 @@ where ContainerAddElement < - // < Definition as former::FormerDefinition >::Types, collection_tools::HashMap < String, @@ -266,12 +265,14 @@ where K, Self, Self, - ContainerAddElement:: - < - collection_tools::HashMap< String, Command< K > >, - ( String, Command< K > ), - Command< K >, - >, + ContainerAddElement + ::< _, _, _ > + // :: + // < + // // collection_tools::HashMap< String, Command< K > >, + // // ( String, Command< K > ), + // // Command< K >, + // >, > > = CommandFormer::begin From a02b8135eee4ada5800f64a09d8ded1eb0ade6cf Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 18:41:44 +0300 Subject: [PATCH 219/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 3406515f10..e7cdeae77e 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -146,7 +146,18 @@ where #[ inline( always ) ] pub fn command_with_closure< IntoName >( self, name : IntoName ) -> - CommandSubformer< K, Self > + // CommandSubformer< K, Self > + CommandFormer + < + K, + CommandFormerDefinition + < + K, + Self, + Self, + impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, + >, + > where IntoName : core::convert::Into< String >, { @@ -168,7 +179,7 @@ where super_former }; - let former = CommandFormer::begin( None, Some( self ), on_end ); + let former : CommandSubformer< K, Self > = CommandFormer::begin( None, Some( self ), on_end ); former.name( name ) } From 16b04e09a02c30acde5294768a9b395f5f63719c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 18:55:25 +0300 Subject: [PATCH 220/533] former : evolve --- module/core/former/Readme.md | 6 ++-- module/core/former/src/container.rs | 8 ++--- module/core/former/src/hash_map.rs | 2 +- .../former/tests/inc/former_tests/a_basic.rs | 2 +- .../tests/inc/former_tests/a_basic_manual.rs | 8 ++--- .../a_containers_with_subformer_manual.rs | 6 ++-- .../a_containers_without_subformer.rs | 2 +- .../tests/inc/former_tests/a_primitives.rs | 2 +- .../inc/former_tests/a_primitives_manual.rs | 4 +-- .../former_tests/container_former_common.rs | 10 +++---- .../former_tests/container_former_hashmap.rs | 4 +-- .../former_tests/container_former_hashset.rs | 4 +-- .../inc/former_tests/container_former_vec.rs | 4 +-- .../inc/former_tests/name_collision_end.rs | 2 +- .../tests/inc/former_tests/only_test/basic.rs | 30 +++++++++---------- .../former_tests/parametrized_struct_imm.rs | 2 +- .../parametrized_struct_manual.rs | 8 ++--- .../former_tests/parametrized_struct_where.rs | 2 +- .../tests/inc/former_tests/string_slice.rs | 2 +- .../inc/former_tests/string_slice_manual.rs | 8 ++--- .../tests/inc/former_tests/subformer_basic.rs | 19 ++++++++++-- .../former_tests/subformer_basic_manual.rs | 14 ++++----- .../inc/former_tests/subformer_shortcut.rs | 2 +- module/core/former_meta/src/derive/former.rs | 10 +++---- module/core/former_meta/src/lib.rs | 4 +-- 25 files changed, 90 insertions(+), 75 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index ec0a4f16ec..1f5289de87 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -207,11 +207,11 @@ where #[ inline( always ) ] pub fn new() -> UserProfileFormer< UserProfile, former::ReturnFormed > { - UserProfileFormer::< UserProfile, former::ReturnFormed >::begin( None, former::ReturnFormed ) + UserProfileFormer::< UserProfile, former::ReturnFormed >::begin_coercing( None, former::ReturnFormed ) } #[ inline( always ) ] - pub fn begin + pub fn begin_coercing ( context : Option< Context >, on_end : End, @@ -566,7 +566,7 @@ fn main() } super_former }; - let former = CommandFormer::begin( None, Some( self ), on_end ); + let former = CommandFormer::begin_coercing( None, Some( self ), on_end ); former.name( name ) } } diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index e9ba9590e5..ec23cdaa20 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -246,7 +246,7 @@ where /// Begins the building process, optionally initializing with a context and storage. #[ inline( always ) ] - pub fn begin + pub fn begin_coercing ( mut storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, @@ -309,7 +309,7 @@ where #[ inline( always ) ] pub fn new( end : Definition::End ) -> Self { - Self::begin + Self::begin_coercing ( None, None, @@ -323,7 +323,7 @@ where where IntoEnd : Into< Definition::End >, { - Self::begin + Self::begin_coercing ( None, None, @@ -376,7 +376,7 @@ where ) -> Self { - Self::begin( storage, context, on_end ) + Self::begin_coercing( storage, context, on_end ) } } diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index b7230ba78b..c1bfeabb58 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -25,7 +25,7 @@ where // -> // HashMapSubformer< K, E, Definition, (), impl FormingEnd< Self, Self > > // { - // HashMapSubformer::begin( Some( self ), None, ReturnFormed ) + // HashMapSubformer::begin_coercing( Some( self ), None, ReturnFormed ) // } // xxx : uncomment and cover by tests diff --git a/module/core/former/tests/inc/former_tests/a_basic.rs b/module/core/former/tests/inc/former_tests/a_basic.rs index 31ec06d07d..331f2da430 100644 --- a/module/core/former/tests/inc/former_tests/a_basic.rs +++ b/module/core/former/tests/inc/former_tests/a_basic.rs @@ -9,7 +9,7 @@ pub struct Struct1 pub int_1 : i32, } -// = begin of generated +// = begin_coercing of generated // = end of generated diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index db42694c71..23808a5a65 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -7,7 +7,7 @@ pub struct Struct1 pub int_1 : i32, } -// === begin of generated +// === begin_coercing of generated // = formed @@ -164,14 +164,14 @@ where #[ inline( always ) ] pub fn _new_precise( on_end : Definition::End ) -> Self { - Self::begin( None, None, on_end ) + Self::begin_coercing( None, None, on_end ) } #[ inline( always ) ] pub fn new< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End >, { - Self::begin( None, None, end, ) + Self::begin_coercing( None, None, end, ) } #[ inline( always ) ] @@ -196,7 +196,7 @@ where } #[ inline( always ) ] - pub fn begin< IntoEnd > + pub fn begin_coercing< IntoEnd > ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 3f46c7cc8a..3377890be4 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -234,7 +234,7 @@ where #[ inline( always ) ] pub fn _new_precise( on_end : Definition::End ) -> Self { - Self::begin( None, None, on_end ) + Self::begin_coercing( None, None, on_end ) } @@ -245,7 +245,7 @@ where where IntoEnd : Into< Definition::End >, { - Self::begin( None, None, end, ) + Self::begin_coercing( None, None, end, ) } @@ -274,7 +274,7 @@ where #[ inline( always ) ] - pub fn begin< IntoEnd >( + pub fn begin_coercing< IntoEnd >( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : IntoEnd, diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs index 941d235faa..8494ec17ce 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs @@ -14,7 +14,7 @@ pub struct Struct1 hashset_1 : HashSet< String >, } -// = begin of generated +// = begin_coercing of generated // = end of generated diff --git a/module/core/former/tests/inc/former_tests/a_primitives.rs b/module/core/former/tests/inc/former_tests/a_primitives.rs index dc4963c069..bf53367676 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives.rs @@ -12,7 +12,7 @@ pub struct Struct1 string_optional_1 : Option< String >, } -// = begin of generated +// = begin_coercing of generated // = end of generated diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index d65b619ffb..424485178c 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -212,7 +212,7 @@ where where IntoEnd : Into< Definition::End >, { - Self::begin + Self::begin_coercing ( None, None, @@ -241,7 +241,7 @@ where } #[ inline( always ) ] - pub fn begin< IntoEnd > + pub fn begin_coercing< IntoEnd > ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index 228662f385..1edc6bb0cc 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -50,7 +50,7 @@ fn begin_and_custom_end() { 13.1 } - let got = the_module::VectorSubformer::begin( None, None, return_13 ) + let got = the_module::VectorSubformer::begin_coercing( None, None, return_13 ) .add( "a" ) .add( "b" ) .form(); @@ -77,7 +77,7 @@ fn begin_and_custom_end() 13.1 } } - let got = the_module::VectorSubformer::begin( None, Some( 10.0 ), context_plus_13 ) + let got = the_module::VectorSubformer::begin_coercing( None, Some( 10.0 ), context_plus_13 ) .add( "a" ) .add( "b" ) .form(); @@ -128,7 +128,7 @@ fn custom_definition() // - let got = the_module::ContainerSubformer::< String, Return13 >::begin( None, None, Return13 ) + let got = the_module::ContainerSubformer::< String, Return13 >::begin_coercing( None, None, Return13 ) .add( "a" ) .add( "b" ) .form(); @@ -195,7 +195,7 @@ fn custom_definition_parametrized() // - let got = the_module::ContainerSubformer::< String, Return13< String > >::begin( None, None, Return13::new() ) + let got = the_module::ContainerSubformer::< String, Return13< String > >::begin_coercing( None, None, Return13::new() ) .add( "a" ) .add( "b" ) .form(); @@ -213,7 +213,7 @@ fn custom_definition_parametrized() type MyContainer< E > = the_module::ContainerSubformer::< E, Return13< E > >; - let got = MyContainer::< String >::begin( None, None, Return13::new() ) + let got = MyContainer::< String >::begin_coercing( None, None, Return13::new() ) .add( "a" ) .add( "b" ) .form(); diff --git a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs index da24fc1ec1..ec017cf3a3 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs @@ -54,10 +54,10 @@ fn add() ]; a_id!( got, exp ); - // with begin + // with begin_coercing let got : HashMap< String, String > = the_module::HashMapSubformer - ::begin( Some( hmap![ "a".to_string() => "x".to_string() ] ), Some( () ), former::ReturnStorage ) + ::begin_coercing( Some( hmap![ "a".to_string() => "x".to_string() ] ), Some( () ), former::ReturnStorage ) .add( ( "b".into(), "y".into() ) ) .form(); let exp = hmap! diff --git a/module/core/former/tests/inc/former_tests/container_former_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs index a84a716f45..ca797c2cf6 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashset.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashset.rs @@ -54,10 +54,10 @@ fn add() ]; a_id!( got, exp ); - // with begin + // with begin_coercing let got : HashSet< String > = the_module::HashSetSubformer - ::begin( Some( hset![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) + ::begin_coercing( Some( hset![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) .add( "b" ) .form(); let exp = hset! 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 8d4aea60fe..f2bb876c74 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 @@ -53,10 +53,10 @@ fn add() ]; a_id!( got, exp ); - // with begin + // with begin_coercing let got : Vec< String > = the_module::VectorSubformer - ::begin( Some( vec![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) + ::begin_coercing( Some( vec![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) .add( "b" ) .form(); let exp = vec! diff --git a/module/core/former/tests/inc/former_tests/name_collision_end.rs b/module/core/former/tests/inc/former_tests/name_collision_end.rs index 5690ee583b..d53541675f 100644 --- a/module/core/former/tests/inc/former_tests/name_collision_end.rs +++ b/module/core/former/tests/inc/former_tests/name_collision_end.rs @@ -16,6 +16,6 @@ pub struct End inner : std::sync::Arc< core::cell::RefCell< dyn CloneAny > > } -// = begin of generated +// = begin_coercing of generated // = end of generated \ No newline at end of file diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index 18e20a953b..daeb2a763d 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -44,7 +44,7 @@ tests_impls! < Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::begin + ::begin_coercing ( None, Some( 3 ), @@ -60,7 +60,7 @@ tests_impls! < Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::begin + ::begin_coercing ( None, Some( 3 ), @@ -70,14 +70,14 @@ tests_impls! .form(); a_id!( got, 32 ); - // custom params begin + // custom params begin_coercing let got = Struct1Former :: < Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::begin + ::begin_coercing ( None, Some( 3 ), @@ -87,14 +87,14 @@ tests_impls! .form(); a_id!( got, 32 ); - // custom params begin with Struct1FormerWithClosure + // custom params begin_coercing with Struct1FormerWithClosure let got = Struct1Former :: < Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::begin + ::begin_coercing ( None, Some( 3 ), @@ -111,7 +111,7 @@ tests_impls! Struct1FormerDefinition< i32, i32, former::FormingEndClosure< _ > > > - ::begin + ::begin_coercing ( None, Some( 3 ), @@ -125,21 +125,21 @@ tests_impls! // - fn begin() + fn begin_coercing() { - // begin with none - let got = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::begin( None, None, the_module::ReturnPreformed ).int_1( 13 ).form(); + // begin_coercing with none + let got = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::begin_coercing( None, None, the_module::ReturnPreformed ).int_1( 13 ).form(); let exp = Struct1::former().int_1( 13 ).form(); a_id!( got, exp ); - // begin with storage + // begin_coercing with storage let mut storage = Struct1FormerStorage::default(); storage.int_1 = Some( 13 ); - let exp = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::begin( Some( storage ), None, the_module::ReturnPreformed ).form(); + let exp = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::begin_coercing( Some( storage ), None, the_module::ReturnPreformed ).form(); a_id!( got, exp ); - // begin with context + // begin_coercing with context let mut storage = Struct1FormerStorage::default(); storage.int_1 = Some( 13 ); let exp = Struct1Former @@ -147,7 +147,7 @@ tests_impls! < Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > - ::begin( Some( storage ), Some( () ), the_module::ReturnPreformed ) + ::begin_coercing( Some( storage ), Some( () ), the_module::ReturnPreformed ) .form(); a_id!( got, exp ); @@ -518,7 +518,7 @@ tests_index! { internals, custom_definition_params, - begin, + begin_coercing, _begin_precise, new, _new_precise, diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs index afaf7c0fb2..d30aa71c20 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs @@ -32,7 +32,7 @@ pub struct Command< K : core::hash::Hash + std::cmp::Eq > pub properties : collection_tools::HashMap< K, Property< K > >, } -// == begin of generated +// == begin_coercing of generated // == end of generated diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 63ed1c712d..0aadf0c81a 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -34,7 +34,7 @@ where pub properties : collection_tools::HashMap< K, Property< K > >, } -// == begin of generated +// == begin_coercing of generated #[ automatically_derived ] impl< K, > Command< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, @@ -212,14 +212,14 @@ where #[ inline( always ) ] pub fn _new_precise( on_end : Definition::End ) -> Self { - Self::begin( None, None, on_end ) + Self::begin_coercing( None, None, on_end ) } #[ inline( always ) ] pub fn new< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End > { - Self::begin( None, None, end ) + Self::begin_coercing( None, None, end ) } #[ inline( always ) ] @@ -238,7 +238,7 @@ where } #[ inline( always ) ] - pub fn begin< IntoEnd >( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : IntoEnd, ) -> Self + pub fn begin_coercing< IntoEnd >( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : IntoEnd, ) -> Self where IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > { if storage.is_none() diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs index 5cb3a0fc51..5da806be97 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs @@ -34,7 +34,7 @@ where pub properties : collection_tools::HashMap< K, Property< K > >, } -// == begin of generated +// == begin_coercing of generated // == end of generated diff --git a/module/core/former/tests/inc/former_tests/string_slice.rs b/module/core/former/tests/inc/former_tests/string_slice.rs index 43b36261ff..70466144db 100644 --- a/module/core/former/tests/inc/former_tests/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/string_slice.rs @@ -8,7 +8,7 @@ pub struct Struct1< 'a > pub string_slice_1 : &'a str, } -// === begin of generated +// === begin_coercing of generated // === end of generated diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 075c9e8723..ce03f9df61 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -7,7 +7,7 @@ pub struct Struct1< 'a > pub string_slice_1 : &'a str, } -// === begin of generated +// === begin_coercing of generated #[ automatically_derived ] impl< 'a > Struct1< 'a > @@ -171,14 +171,14 @@ where #[ inline( always ) ] pub fn _new_precise( on_end : Definition::End ) -> Self { - Self::begin( None, None, on_end ) + Self::begin_coercing( None, None, on_end ) } #[ inline( always ) ] pub fn new< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End >, { - Self::begin( None, None, end, ) + Self::begin_coercing( None, None, end, ) } #[ inline( always ) ] @@ -202,7 +202,7 @@ where } #[ inline( always ) ] - pub fn begin< IntoEnd > + pub fn begin_coercing< IntoEnd > ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index e7cdeae77e..23c2c30c59 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -179,7 +179,22 @@ where super_former }; - let former : CommandSubformer< K, Self > = CommandFormer::begin( None, Some( self ), on_end ); + let former + // : CommandSubformer< K, Self > + : CommandFormer< _, _ > + // : CommandFormer + // < + // K, + // CommandFormerDefinition + // < + // K, + // Self, + // Self, + // _, + // > + // > + = CommandFormer::_begin_precise( None, Some( self ), on_end ); + // = CommandFormer::begin_coercing( None, Some( self ), on_end ); former.name( name ) } @@ -286,7 +301,7 @@ where // >, > > - = CommandFormer::begin + = CommandFormer::begin_coercing ( None, Some( self ), diff --git a/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs b/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs index c336a55bcd..09bac144f9 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs @@ -162,7 +162,7 @@ where #[ inline( always ) ] pub fn new() -> CommandFormer< K > { - CommandFormer::< K >::begin + CommandFormer::< K >::begin_coercing ( None, None, @@ -171,7 +171,7 @@ where } #[ inline( always ) ] - pub fn begin + pub fn begin_coercing ( storage : core::option::Option< CommandFormerStorage< K > >, context : core::option::Option< Context >, @@ -233,7 +233,7 @@ where super_former.storage.properties = Some( formed ); super_former }; - the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) + the_module::HashMapSubformer::begin_coercing( formed, Some( self ), on_end ) } } @@ -360,7 +360,7 @@ where #[ inline( always ) ] pub fn new() -> AggregatorFormer< K > { - AggregatorFormer::< K >::begin + AggregatorFormer::< K >::begin_coercing ( None, the_module::ReturnPreformed, @@ -368,7 +368,7 @@ where } #[ inline( always ) ] - pub fn begin + pub fn begin_coercing ( context : core::option::Option< Context >, on_end : End, @@ -419,7 +419,7 @@ where super_former.commands = Some( formed ); super_former }; - the_module::HashMapSubformer::begin( formed, Some( self ), on_end ) + the_module::HashMapSubformer::begin_coercing( formed, Some( self ), on_end ) } } @@ -454,7 +454,7 @@ where } super_former }; - let former = CommandFormer::begin( None, Some( self ), on_end ); + let former = CommandFormer::begin_coercing( None, Some( self ), on_end ); former.name( name ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 50f92f771e..16a87e16a6 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -34,7 +34,7 @@ where ) -> Self { debug_assert!( storage.is_none() ); - Self::begin( None, context, on_end ) + Self::begin_coercing( None, context, on_end ) } } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index b68f521e40..2deee29487 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -634,7 +634,7 @@ fn field_setter /// former.hashmap_strings_1 = Some( formed ); /// former /// }; -/// former::HashMapSubformer::begin( formed, self, on_end ) +/// former::HashMapSubformer::begin_coercing( formed, self, on_end ) /// } /// ``` /// zzz : update example @@ -767,7 +767,7 @@ fn subformer_field_setter // former.storage.#setter_name = Some( formed ); // former // }; - // #subformer_type::begin( formed, Some( self ), on_end ) + // #subformer_type::begin_coercing( formed, Some( self ), on_end ) // } // } @@ -1408,7 +1408,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ inline( always ) ] pub fn _new_precise( on_end : Definition::End ) -> Self { - Self::begin( None, None, on_end ) + Self::begin_coercing( None, None, on_end ) } /// @@ -1420,7 +1420,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where IntoEnd : Into< Definition::End >, { - Self::begin + Self::begin_coercing ( None, None, @@ -1457,7 +1457,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// // zzz : improve description #[ inline( always ) ] - pub fn begin< IntoEnd > + pub fn begin_coercing< IntoEnd > ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index 3f0dab9097..3a1325956d 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -192,11 +192,11 @@ mod derive /// #[ inline( always ) ] /// pub fn new() -> UserProfileFormer< UserProfile, former::ReturnFormed > /// { -/// UserProfileFormer::< UserProfile, former::ReturnFormed >::begin( None, former::ReturnFormed ) +/// UserProfileFormer::< UserProfile, former::ReturnFormed >::begin_coercing( None, former::ReturnFormed ) /// } /// /// #[ inline( always ) ] -/// pub fn begin( context : Option< Context >, on_end : End ) -> Self +/// pub fn begin_coercing( context : Option< Context >, on_end : End ) -> Self /// { /// Self /// { From 9c19109ee1596eeaca73f81c76f4470ae3c6a4de Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 20:27:00 +0300 Subject: [PATCH 221/533] former : evolve --- .../tests/inc/former_tests/a_basic_manual.rs | 4 ++-- .../a_containers_with_subformer_manual.rs | 4 ++-- .../inc/former_tests/a_primitives_manual.rs | 4 ++-- .../tests/inc/former_tests/only_test/basic.rs | 18 ++++++++---------- .../only_test/containers_with_subformer.rs | 8 ++++---- .../only_test/containers_without_subformer.rs | 2 +- .../inc/former_tests/only_test/primitives.rs | 2 +- .../inc/former_tests/only_test/string_slice.rs | 2 +- .../former_tests/only_test/subformer_basic.rs | 2 +- .../inc/former_tests/string_slice_manual.rs | 10 ++-------- .../tests/inc/former_tests/subformer_basic.rs | 6 +++--- module/core/former_meta/src/derive/former.rs | 5 ++--- module/core/former_meta/src/lib.rs | 4 ++-- 13 files changed, 31 insertions(+), 40 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 23808a5a65..176bdf13a5 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -18,7 +18,7 @@ impl Struct1 #[ inline( always ) ] pub fn former() -> Struct1Former< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > { - Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new( former::ReturnPreformed ) + Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new_coercing( former::ReturnPreformed ) } } @@ -168,7 +168,7 @@ where } #[ inline( always ) ] - pub fn new< IntoEnd >( end : IntoEnd ) -> Self + pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End >, { Self::begin_coercing( None, None, end, ) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 3377890be4..25301f6972 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -17,7 +17,7 @@ impl Struct1 #[ inline( always ) ] pub fn former() -> Struct1Former< > { - Struct1Former::<>::new( the_module::ReturnPreformed ) + Struct1Former::<>::new_coercing( the_module::ReturnPreformed ) } } @@ -241,7 +241,7 @@ where #[ inline( always ) ] - pub fn new< IntoEnd >( end : IntoEnd ) -> Self + pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End >, { diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 424485178c..fee31705da 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -17,7 +17,7 @@ impl Struct1 { pub fn former() -> Struct1Former { - Struct1Former::new( the_module::ReturnPreformed ) + Struct1Former::new_coercing( the_module::ReturnPreformed ) } } @@ -208,7 +208,7 @@ where } #[ inline( always ) ] - pub fn new< IntoEnd >( end : IntoEnd ) -> Self + pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End >, { diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index daeb2a763d..44f5f0b1aa 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -15,9 +15,9 @@ tests_impls! a_id!( former.storage.int_1, None ); a_id!( former.context, None ); a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); - let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new_coercing( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); - // let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); + // let former2 = Struct1Former::< Struct1FormerDefinition >::new_coercing( former::ReturnPreformed ); // a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); // xxx : uncomment @@ -217,7 +217,7 @@ tests_impls! // default explicit params let got = Struct1Former ::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > - ::new( former::ReturnPreformed ) + ::new_coercing( former::ReturnPreformed ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -233,10 +233,9 @@ tests_impls! // ::< Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > :: < - Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > - ::new( end_wrapper ) + ::new_coercing( end_wrapper ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -250,7 +249,7 @@ tests_impls! Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > - ::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + ::new_coercing( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -264,7 +263,7 @@ tests_impls! Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > - ::new( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) + ::new_coercing( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -275,10 +274,9 @@ tests_impls! // ::< Struct1FormerWithClosure< (), Struct1 > > :: < - Struct1FormerWithClosure< (), Struct1 > > - ::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + ::new_coercing( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -292,7 +290,7 @@ tests_impls! Struct1FormerWithClosure< (), Struct1 > > - ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) + ::new_coercing( | storage, _context | { former::StoragePreform::preform( storage ) } ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index 1968c27eca..a6787e59f8 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -50,18 +50,18 @@ tests_impls_optional! // former with explicit definition let former = Struct1::former(); a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); - let former2 = Struct1Former::< Struct1FormerDefinition >::new( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition >::new_coercing( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); // default parameters let former = Struct1::former(); - let former2 : Struct1Former = Struct1Former::new( former::ReturnPreformed ); + let former2 : Struct1Former = Struct1Former::new_coercing( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); // closure without helper let got : Struct1 = Struct1Former ::< Struct1FormerDefinition< _, _, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > - ::new( | storage : Struct1FormerStorage, _context | { former::StoragePreform::preform( storage ) } ) + ::new_coercing( | storage : Struct1FormerStorage, _context | { former::StoragePreform::preform( storage ) } ) .vec_1().replace( vec![ "a".to_string(), "b".to_string() ] ).end() .form(); let exp : Struct1 = Struct1 @@ -75,7 +75,7 @@ tests_impls_optional! // closure with helper let got : Struct1 = Struct1Former ::< Struct1FormerWithClosure< (), Struct1 > > - ::new( | storage : Struct1FormerStorage, _context | { former::StoragePreform::preform( storage ) } ) + ::new_coercing( | storage : Struct1FormerStorage, _context | { former::StoragePreform::preform( storage ) } ) .vec_1().replace( vec![ "a".to_string(), "b".to_string() ] ).end() .form(); let exp : Struct1 = Struct1 diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs index 6d7763e697..c19e92eead 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_without_subformer.rs @@ -19,7 +19,7 @@ tests_impls! a_id!( former.storage.hashset_1, None ); a_id!( former.context, None ); a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); - let former2 = Struct1Former::< Struct1FormerDefinition >::new( the_module::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition >::new_coercing( the_module::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 45a9dc02cd..de15d3f897 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -40,7 +40,7 @@ tests_impls! // default explicit params with wrapper and closure let got = Struct1Former ::< Struct1FormerWithClosure< (), Struct1 > > - ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) + ::new_coercing( | storage, _context | { former::StoragePreform::preform( storage ) } ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); diff --git a/module/core/former/tests/inc/former_tests/only_test/string_slice.rs b/module/core/former/tests/inc/former_tests/only_test/string_slice.rs index 315d2c8942..8e5c210170 100644 --- a/module/core/former/tests/inc/former_tests/only_test/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/only_test/string_slice.rs @@ -34,7 +34,7 @@ tests_impls! // default explicit params with wrapper and closure let got = Struct1Former ::< Struct1FormerWithClosure< (), Struct1 > > - ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) + ::new_coercing( | storage, _context | { former::StoragePreform::preform( storage ) } ) .string_slice_1( "abc" ) .form(); let exp = Struct1::former().string_slice_1( "abc" ).form(); diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs index 6d8c236e49..6093719096 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs @@ -122,7 +122,7 @@ fn aggregator() // with helper let got = Aggregator::< &str >::former() .parameter1( "p1" ) - .commands().insert( "name1", CommandFormer::< &str >::new().name( "name1" ).subject( "s" ).end() ).end() + .commands().insert( "name1", CommandFormer::< &str >::new_coercing().name( "name1" ).subject( "s" ).end() ).end() .command( "command1".to_string() ) .subject( "b" ) .property( "property1", "simple property", 13isize ) diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index ce03f9df61..0641ce6dfa 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -13,16 +13,10 @@ pub struct Struct1< 'a > impl< 'a > Struct1< 'a > { - // #[ inline( always ) ] - // pub fn former() -> Struct1Former< 'a, (), Struct1< 'a >, former::ReturnPreformed > - // { - // Struct1Former::< 'a, _, _, _ >::new( former::ReturnPreformed ) - // } - #[ inline( always ) ] pub fn former() -> Struct1Former< 'a > { - Struct1Former::new( former::ReturnPreformed ) + Struct1Former::new_coercing( former::ReturnPreformed ) } } @@ -175,7 +169,7 @@ where } #[ inline( always ) ] - pub fn new< IntoEnd >( end : IntoEnd ) -> Self + pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End >, { Self::begin_coercing( None, None, end, ) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 23c2c30c59..c542807936 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -34,7 +34,7 @@ pub struct Property< Name > impl< Name > Property< Name > { #[ inline ] - pub fn new< Description, Code >( name : Name, description : Description, code : Code ) -> Self + pub fn new_coercing< Description, Code >( name : Name, description : Description, code : Code ) -> Self where Name : core::convert::Into< Name >, Description : core::convert::Into< String >, @@ -306,7 +306,7 @@ where None, Some( self ), ContainerAddElement - ::new(), + ::new_coercing(), ); former.name( name ) @@ -456,7 +456,7 @@ ContainerAddElement SubFormed, > { - pub fn new() -> Self + pub fn new_coercing() -> Self { Self( core::marker::PhantomData ) } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 2deee29487..ea6c824424 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1224,8 +1224,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ inline( always ) ] pub fn former() -> #former < #struct_generics_ty #former_definition< #former_definition_args > > { - #former :: < #struct_generics_ty #former_definition< #former_definition_args > > :: new( former::ReturnPreformed ) - + #former :: < #struct_generics_ty #former_definition< #former_definition_args > > :: new_coercing( former::ReturnPreformed ) } } @@ -1416,7 +1415,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// // zzz : improve description #[ inline( always ) ] - pub fn new< IntoEnd >( end : IntoEnd ) -> Self + pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End >, { diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index 3a1325956d..f585486925 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -121,7 +121,7 @@ mod derive /// #[ inline( always ) ] /// pub fn former() -> UserProfileFormer< UserProfile, former::ReturnFormed > /// { -/// UserProfileFormer::< UserProfile, former::ReturnFormed >::new() +/// UserProfileFormer::< UserProfile, former::ReturnFormed >::new_coercing() /// } /// } /// @@ -190,7 +190,7 @@ mod derive /// /// // qqq : zzz : outdated, update /// #[ inline( always ) ] -/// pub fn new() -> UserProfileFormer< UserProfile, former::ReturnFormed > +/// pub fn new_coercing() -> UserProfileFormer< UserProfile, former::ReturnFormed > /// { /// UserProfileFormer::< UserProfile, former::ReturnFormed >::begin_coercing( None, former::ReturnFormed ) /// } From 63bd1fb0a3e8c64bac2075e68160704b023932ce Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 20:28:08 +0300 Subject: [PATCH 222/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index c542807936..2fa645622f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -438,19 +438,17 @@ where // -pub struct ContainerAddElement< /*SuperDefinition,*/ SuperContainer, Element, SubFormed > -( core::marker::PhantomData< fn( /*SuperDefinition,*/ SuperContainer, Element, SubFormed ) > ); +pub struct ContainerAddElement< SuperContainer, Element, SubFormed > +( core::marker::PhantomData< fn( SuperContainer, Element, SubFormed ) > ); impl < - // SuperDefinition, SuperContainer, Element, SubFormed, > ContainerAddElement < - // SuperDefinition, SuperContainer, Element, SubFormed, @@ -464,7 +462,6 @@ ContainerAddElement impl < - // SuperDefinition, SuperFormer, SuperContainer, Element, @@ -483,17 +480,11 @@ former::FormingEnd > for ContainerAddElement < - // SuperDefinition, SuperContainer, Element, SubFormed, > where - - // SuperDefinition : former::FormerDefinitionTypes, - // SuperDefinition::Storage : FormerStorageExtractContainer< SuperContainer >, - - // SuperFormer : FormerExtractStorage< Storage = SuperDefinition::Storage >, SuperFormer : FormerExtractStorage<>, < SuperFormer as FormerExtractStorage >::Storage : FormerStorageExtractContainer< SuperContainer >, SuperContainer : former::ContainerAdd< Element = Element >, From 9f3be3dd44d6f0c1d3368753a977f04e77786349 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 20:45:59 +0300 Subject: [PATCH 223/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 97 ++++++++----------- 1 file changed, 43 insertions(+), 54 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 2fa645622f..40980e35b4 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -108,7 +108,7 @@ where pub commands : collection_tools::HashMap< String, Command< K > >, } -pub type CommandSubformer< K, Superformer > = CommandFormer +pub type CommandSubformerWithClosure< K, Superformer > = CommandFormer < K, CommandFormerDefinition @@ -121,6 +121,27 @@ pub type CommandSubformer< K, Superformer > = CommandFormer >, >; +pub trait CommandSubformerEnd< K, SuperFormer > +where + K : core::hash::Hash + std::cmp::Eq, + Self : the_module::FormingEnd + < + CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, + > +{ +} + +impl< K, SuperFormer, T > CommandSubformerEnd< K, SuperFormer > +for T +where + K : core::hash::Hash + std::cmp::Eq, + Self : the_module::FormingEnd + < + CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, + > +{ +} + // manual // impl< K, Context, End > // AggregatorFormer< K, Context, End > @@ -146,7 +167,6 @@ where #[ inline( always ) ] pub fn command_with_closure< IntoName >( self, name : IntoName ) -> - // CommandSubformer< K, Self > CommandFormer < K, @@ -155,7 +175,8 @@ where K, Self, Self, - impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, + impl CommandSubformerEnd< K, Self >, + // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, >, > where @@ -180,29 +201,16 @@ where }; let former - // : CommandSubformer< K, Self > : CommandFormer< _, _ > - // : CommandFormer - // < - // K, - // CommandFormerDefinition - // < - // K, - // Self, - // Self, - // _, - // > - // > = CommandFormer::_begin_precise( None, Some( self ), on_end ); - // = CommandFormer::begin_coercing( None, Some( self ), on_end ); - former.name( name ) + former.name( name ) } #[ inline( always ) ] pub fn command_with_types< IntoName >( self, name : IntoName ) -> - // CommandSubformer< K, Self > + // CommandSubformerWithClosure< K, Self > CommandFormer < K, @@ -211,7 +219,8 @@ where K, Self, Self, - impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, + impl CommandSubformerEnd< K, Self >, + // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, >, > where @@ -219,7 +228,7 @@ where { let former - // : CommandSubformer< K, Self > + // : CommandSubformerWithClosure< K, Self > // : CommandFormer // < // K, @@ -240,8 +249,6 @@ where #[ inline( always ) ] pub fn command_with_helper< IntoName >( self, name : IntoName ) -> - // () - // CommandSubformer< K, Self > CommandFormer < K, @@ -250,7 +257,8 @@ where K, Self, Self, - impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, + impl CommandSubformerEnd< K, Self >, + // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, >, > where @@ -270,43 +278,24 @@ where Command< K > > : - former::FormingEnd - < - CommandFormerDefinitionTypes - < - K, - Self, - Self, - > - > + CommandSubformerEnd< K, Self >, + // former::FormingEnd + // < + // CommandFormerDefinitionTypes + // < + // K, + // Self, + // Self, + // > + // > { let former - // : CommandSubformer< K, Self > - : CommandFormer - < - K, - CommandFormerDefinition - < - K, - Self, - Self, - ContainerAddElement - ::< _, _, _ > - // :: - // < - // // collection_tools::HashMap< String, Command< K > >, - // // ( String, Command< K > ), - // // Command< K >, - // >, - > - > - = CommandFormer::begin_coercing + = CommandFormer::_begin_precise ( None, Some( self ), - ContainerAddElement - ::new_coercing(), + ContainerAddElement::new_coercing(), ); former.name( name ) From ce28204e1f2911f6c502636e49384178ae1f4baf Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 20:49:41 +0300 Subject: [PATCH 224/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 40980e35b4..bd837d5a5b 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -34,7 +34,7 @@ pub struct Property< Name > impl< Name > Property< Name > { #[ inline ] - pub fn new_coercing< Description, Code >( name : Name, description : Description, code : Code ) -> Self + pub fn new< Description, Code >( name : Name, description : Description, code : Code ) -> Self where Name : core::convert::Into< Name >, Description : core::convert::Into< String >, @@ -295,7 +295,7 @@ where ( None, Some( self ), - ContainerAddElement::new_coercing(), + ContainerAddElement::default(), ); former.name( name ) @@ -427,23 +427,15 @@ where // +#[ derive( Debug ) ] pub struct ContainerAddElement< SuperContainer, Element, SubFormed > ( core::marker::PhantomData< fn( SuperContainer, Element, SubFormed ) > ); -impl -< - SuperContainer, - Element, - SubFormed, -> -ContainerAddElement -< - SuperContainer, - Element, - SubFormed, -> +impl< SuperContainer, Element, SubFormed > ::core::default::Default +for ContainerAddElement< SuperContainer, Element, SubFormed > { - pub fn new_coercing() -> Self + #[ inline( always ) ] + fn default() -> Self { Self( core::marker::PhantomData ) } From 547ae03d0e10eb27361f5744a3132d060bff1d49 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 21:13:34 +0300 Subject: [PATCH 225/533] former : evolve --- .../former_tests/only_test/subformer_basic.rs | 56 +- .../former_tests/only_test/subformer_extra.rs | 209 ++++++++ .../tests/inc/former_tests/subformer_basic.rs | 373 +------------ .../tests/inc/former_tests/subformer_extra.rs | 499 ++++++++++++++++++ module/core/former/tests/inc/mod.rs | 2 + 5 files changed, 719 insertions(+), 420 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs create mode 100644 module/core/former/tests/inc/former_tests/subformer_extra.rs diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs index 6093719096..8810cb6a7f 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs @@ -1,11 +1,11 @@ // let ca = wca::CommandsAggregator::former() -// .command( "echo" ) +// .command_with_closure( "echo" ) // .name( "prints all subjects and properties" ) // .subject( "Subject", wca::Type::String, true ) // .property( "property", "simple property", wca::Type::String, true ) // .routine( f1 ) // .perform() -// .command( "exit" ) +// .command_with_closure( "exit" ) // .name( "just exit" ) // .routine( || exit() ) // .perform() @@ -16,7 +16,7 @@ // qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] -fn command() +fn command_with_closure() { let got = Command::< &str >::former() @@ -91,9 +91,9 @@ fn command_properties() .name( "a" ) .subject( "b" ) .properties() - .insert( "property1", Property::new( "property1", "simple property", 13isize ) ) - .insert( "property2", Property::new( "property2", "simple property 2", 13isize ) ) - .insert( "property2", Property::new( "property2", "simple property 3", 113isize ) ) + .add( ( "property1", Property::new( "property1", "simple property", 13isize ) ) ) + .add( ( "property2", Property::new( "property2", "simple property 2", 13isize ) ) ) + .add( ( "property2", Property::new( "property2", "simple property 3", 113isize ) ) ) .end() .form(); let exp = Command::< &str > @@ -122,16 +122,7 @@ fn aggregator() // with helper let got = Aggregator::< &str >::former() .parameter1( "p1" ) - .commands().insert( "name1", CommandFormer::< &str >::new_coercing().name( "name1" ).subject( "s" ).end() ).end() - .command( "command1".to_string() ) - .subject( "b" ) - .property( "property1", "simple property", 13isize ) - .property( "property2", "simple property 3", 113isize ) - .end() - .command( "command2".to_string() ) - .subject( "c" ) - .property( "property3", "x", 113isize ) - .end() + .commands().add( ( "name1".to_string(), CommandFormer::< &str >::new_coercing( former::ReturnPreformed ).name( "name1" ).subject( "s" ).end() ) ).end() .form() ; @@ -141,29 +132,10 @@ fn aggregator() subject : "s".to_string(), properties : hmap!{}, }; - let command1 = Command::< &str > - { - name : "command1".to_string(), - subject : "b".to_string(), - properties : hmap! - { - "property1" => Property::new( "property1", "simple property", 13isize ), - "property2" => Property::new( "property2", "simple property 3", 113isize ), - }, - }; - let command2 = Command::< &str > - { - name : "command2".to_string(), - subject : "c".to_string(), - properties : hmap! - { - "property3" => Property::new( "property3", "x", 113isize ), - }, - }; let exp = Aggregator { parameter1 : "p1".to_string(), - commands : hmap!{ "name1" => name1, "command1" => command1, "command2" => command2 }, + commands : hmap!{ "name1" => name1 }, }; dbg!( &got ); dbg!( &exp ); @@ -179,29 +151,17 @@ fn aggregator_alternative_form() let exp = Aggregator::< &str >::former() .parameter1( "p1" ) - .command( "command1".to_string() ) - .subject( "b" ) - .property( "property2", "simple property 3", 113isize ) - .end() .form() ; let got = Aggregator::< &str >::former() .parameter1( "p1" ) - .command( "command1".to_string() ) - .subject( "b" ) - .property( "property2", "simple property 3", 113isize ) - .end() .perform() ; a_id!( got, exp ); let got = Aggregator::< &str >::former() .parameter1( "p1" ) - .command( "command1".to_string() ) - .subject( "b" ) - .property( "property2", "simple property 3", 113isize ) - .end() .end() ; a_id!( got, exp ); diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs new file mode 100644 index 0000000000..382b87f809 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs @@ -0,0 +1,209 @@ +// let ca = wca::CommandsAggregator::former() +// .command_with_closure( "echo" ) +// .name( "prints all subjects and properties" ) +// .subject( "Subject", wca::Type::String, true ) +// .property( "property", "simple property", wca::Type::String, true ) +// .routine( f1 ) +// .perform() +// .command_with_closure( "exit" ) +// .name( "just exit" ) +// .routine( || exit() ) +// .perform() +// .perform() +// ; +// ca.execute( input ).unwrap(); + +// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +#[ cfg( not( feature = "use_alloc" ) ) ] +#[ test ] +fn command_with_closure() +{ + + let got = Command::< &str >::former() + .name( "a" ) + .subject( "b" ) + .form(); + let exp = Command::< &str > + { + name : "a".to_string(), + subject : "b".to_string(), + properties : collection_tools::HashMap::< &str, Property< &str > >::new(), + }; + a_id!( got, exp ); + + let got = Command::< &str >::former() + .name( "a" ) + .subject( "b" ) + .perform(); + let exp = Command::< &str > + { + name : "a".to_string(), + subject : "b".to_string(), + properties : collection_tools::HashMap::< &str, Property< &str > >::new(), + }; + a_id!( got, exp ); + + let got = Command::< &str >::former() + .name( "a" ) + .subject( "b" ) + .end(); + let exp = Command::< &str > + { + name : "a".to_string(), + subject : "b".to_string(), + properties : collection_tools::HashMap::< &str, Property< &str > >::new(), + }; + a_id!( got, exp ); + +} + +// + +// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +#[ cfg( not( feature = "use_alloc" ) ) ] +#[ test ] +fn command_properties() +{ + + // with helper + let got = Command::< &str >::former() + .name( "a" ) + .subject( "b" ) + .property( "property1", "simple property", 13isize ) + .property( "property2", "simple property 2", 13isize ) + .property( "property2", "simple property 3", 113isize ) + .form(); + let exp = Command::< &str > + { + name : "a".to_string(), + subject : "b".to_string(), + properties : hmap! + { + "property1" => Property::new( "property1", "simple property", 13isize ), + "property2" => Property::new( "property2", "simple property 3", 113isize ), + }, + // properties : collection_tools::HashMap::< &str, Property< &str > >::new(), + }; + a_id!( got, exp ); + + // with HashMapSubformer + let got = Command::< &str >::former() + .name( "a" ) + .subject( "b" ) + .properties() + .add( ( "property1", Property::new( "property1", "simple property", 13isize ) ) ) + .add( ( "property2", Property::new( "property2", "simple property 2", 13isize ) ) ) + .add( ( "property2", Property::new( "property2", "simple property 3", 113isize ) ) ) + .end() + .form(); + let exp = Command::< &str > + { + name : "a".to_string(), + subject : "b".to_string(), + properties : hmap! + { + "property1" => Property::new( "property1", "simple property", 13isize ), + "property2" => Property::new( "property2", "simple property 3", 113isize ), + }, + // properties : collection_tools::HashMap::< &str, Property< &str > >::new(), + }; + a_id!( got, exp ); + +} + +// + +// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +#[ cfg( not( feature = "use_alloc" ) ) ] +#[ test ] +fn aggregator() +{ + + // with helper + let got = Aggregator::< &str >::former() + .parameter1( "p1" ) + .commands().add( ( "name1".to_string(), CommandFormer::< &str >::new_coercing( former::ReturnPreformed ).name( "name1" ).subject( "s" ).end() ) ).end() + .command_with_closure( "command1".to_string() ) + .subject( "b" ) + .property( "property1", "simple property", 13isize ) + .property( "property2", "simple property 3", 113isize ) + .end() + .command_with_closure( "command2".to_string() ) + .subject( "c" ) + .property( "property3", "x", 113isize ) + .end() + .form() + ; + + let name1 = Command::< &str > + { + name : "name1".to_string(), + subject : "s".to_string(), + properties : hmap!{}, + }; + let command1 = Command::< &str > + { + name : "command1".to_string(), + subject : "b".to_string(), + properties : hmap! + { + "property1" => Property::new( "property1", "simple property", 13isize ), + "property2" => Property::new( "property2", "simple property 3", 113isize ), + }, + }; + let command2 = Command::< &str > + { + name : "command2".to_string(), + subject : "c".to_string(), + properties : hmap! + { + "property3" => Property::new( "property3", "x", 113isize ), + }, + }; + let exp = Aggregator + { + parameter1 : "p1".to_string(), + commands : hmap!{ "name1" => name1, "command1" => command1, "command2" => command2 }, + }; + dbg!( &got ); + dbg!( &exp ); + a_id!( got, exp ); + +} + +// + +#[ test ] +fn aggregator_alternative_form() +{ + + let exp = Aggregator::< &str >::former() + .parameter1( "p1" ) + .command_with_closure( "command1".to_string() ) + .subject( "b" ) + .property( "property2", "simple property 3", 113isize ) + .end() + .form() + ; + + let got = Aggregator::< &str >::former() + .parameter1( "p1" ) + .command_with_closure( "command1".to_string() ) + .subject( "b" ) + .property( "property2", "simple property 3", 113isize ) + .end() + .perform() + ; + a_id!( got, exp ); + + let got = Aggregator::< &str >::former() + .parameter1( "p1" ) + .command_with_closure( "command1".to_string() ) + .subject( "b" ) + .property( "property2", "simple property 3", 113isize ) + .end() + .end() + ; + a_id!( got, exp ); + +} diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index bd837d5a5b..d86ea06af5 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -53,7 +53,6 @@ where { pub name : String, pub subject : String, - // #[ subformer( the_module::HashMapSubformer ) ] #[ subformer( former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } @@ -103,7 +102,6 @@ where K : core::hash::Hash + std::cmp::Eq, { pub parameter1 : String, - // #[ subformer( the_module::HashMapSubformer ) ] #[ subformer( former::HashMapDefinition ) ] pub commands : collection_tools::HashMap< String, Command< K > >, } @@ -117,7 +115,6 @@ pub type CommandSubformerWithClosure< K, Superformer > = CommandFormer Superformer, Superformer, former::FormingEndClosure< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, - // impl former::FormingEnd< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, >, >; @@ -142,374 +139,6 @@ where { } -// manual -// impl< K, Context, End > -// AggregatorFormer< K, Context, End > -// where -// K : core::hash::Hash + std::cmp::Eq, -// End : the_module::FormingEnd< Aggregator< K >, Context >, - -impl< K, Definition > AggregatorFormer -< - K, - Definition, -> -where - K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, - - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Aggregator< K > >, - -{ - - #[ inline( always ) ] - pub fn command_with_closure< IntoName >( self, name : IntoName ) - -> - CommandFormer - < - K, - CommandFormerDefinition - < - K, - Self, - Self, - impl CommandSubformerEnd< K, Self >, - // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, - >, - > - where - IntoName : core::convert::Into< String >, - { - - let on_end = | command : CommandFormerStorage< K >, super_former : core::option::Option< Self > | -> Self - { - let command = former::StoragePreform::preform( command ); - let mut super_former = super_former.unwrap(); - if let Some( ref mut commands ) = super_former.storage.commands - { - former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); - } - else - { - let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); - super_former.storage.commands = Some( commands ); - } - super_former - }; - - let former - : CommandFormer< _, _ > - = CommandFormer::_begin_precise( None, Some( self ), on_end ); - - former.name( name ) - } - - #[ inline( always ) ] - pub fn command_with_types< IntoName >( self, name : IntoName ) - -> - // CommandSubformerWithClosure< K, Self > - CommandFormer - < - K, - CommandFormerDefinition - < - K, - Self, - Self, - impl CommandSubformerEnd< K, Self >, - // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, - >, - > - where - IntoName : core::convert::Into< String >, - { - - let former - // : CommandSubformerWithClosure< K, Self > - // : CommandFormer - // < - // K, - // CommandFormerDefinition - // < - // K, - // Self, - // Self, - // AggregatorFormerCommandEnd2, - // > - // > - = CommandFormer::_begin_precise( None, Some( self ), AggregatorFormerCommandEnd2 ); - - former.name( name ) - - } - - #[ inline( always ) ] - pub fn command_with_helper< IntoName >( self, name : IntoName ) - -> - CommandFormer - < - K, - CommandFormerDefinition - < - K, - Self, - Self, - impl CommandSubformerEnd< K, Self >, - // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, - >, - > - where - IntoName : core::convert::Into< String >, - - ContainerAddElement - < - collection_tools::HashMap - < - String, - Command< K > - >, - ( - String, - Command< K >, - ), - Command< K > - > - : - CommandSubformerEnd< K, Self >, - // former::FormingEnd - // < - // CommandFormerDefinitionTypes - // < - // K, - // Self, - // Self, - // > - // > - { - - let former - = CommandFormer::_begin_precise - ( - None, - Some( self ), - ContainerAddElement::default(), - ); - - former.name( name ) - } - -} - -#[ allow( non_camel_case_types ) ] -pub struct AggregatorFormerCommandEnd2; - -#[ automatically_derived ] -impl< K, Definition > former::FormingEnd -< - CommandFormerDefinitionTypes - < - K, - AggregatorFormer< K, Definition >, - AggregatorFormer< K, Definition >, - >, -> -for AggregatorFormerCommandEnd2 -where - K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes - < - Storage = AggregatorFormerStorage< K >, - >, -{ - #[ inline( always ) ] - fn call - ( - &self, - command : CommandFormerStorage< K >, - super_former : Option< AggregatorFormer< K, Definition > >, - ) - -> - AggregatorFormer< K, Definition > - { - - let command = former::StoragePreform::preform( command ); - let mut super_former = super_former.unwrap(); - if let Some( ref mut commands ) = super_former.storage.commands - { - former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); - } - else - { - let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); - super_former.storage.commands = Some( commands ); - } - super_former - - } -} - -// - -/// xxx : extend description -/// Convert an entity to an element which could be added to a container. -pub trait IntoElement< Target > -{ - /// Convert an entity to an element which could be added to a container. - fn into_element( self ) -> Target; -} - -impl< K > IntoElement< ( String, Command< K > ) > -for Command< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - fn into_element( self ) -> ( String, Command< K > ) - { - ( self.name.clone(), self ) - } -} - -// - -/// xxx : extend description -/// get container for a field out of a storage -pub trait FormerStorageExtractContainer< Target > -{ - fn container_mut( &mut self ) -> &mut Target; -} - -impl< K > FormerStorageExtractContainer< collection_tools::HashMap< String, Command< K > > > -for AggregatorFormerStorage< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - fn container_mut( &mut self ) -> &mut collection_tools::HashMap< String, Command< K > > - { - if let Some( ref mut commands ) = self.commands - { - commands - } - else - { - let commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - self.commands = Some( commands ); - self.commands.as_mut().unwrap() - } - } -} - -// - -/// xxx : extend description -/// extract storage from a former -pub trait FormerExtractStorage -{ - type Storage; - fn storage_mut( &mut self ) -> &mut Self::Storage; -} - -impl< K > FormerExtractStorage -for AggregatorFormer< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - type Storage = AggregatorFormerStorage< K >; - fn storage_mut( &mut self ) -> &mut Self::Storage - { - &mut self.storage - } -} - -// - -#[ derive( Debug ) ] -pub struct ContainerAddElement< SuperContainer, Element, SubFormed > -( core::marker::PhantomData< fn( SuperContainer, Element, SubFormed ) > ); - -impl< SuperContainer, Element, SubFormed > ::core::default::Default -for ContainerAddElement< SuperContainer, Element, SubFormed > -{ - #[ inline( always ) ] - fn default() -> Self - { - Self( core::marker::PhantomData ) - } -} - -impl -< - SuperFormer, - SuperContainer, - Element, - SubFormed, - SubDefinition, -> -former::FormingEnd -< - SubDefinition, - // CommandFormerDefinitionTypes - // < - // K, - // AggregatorFormer< K, SuperDefinition >, - // AggregatorFormer< K, SuperDefinition >, - // >, -> -for ContainerAddElement -< - SuperContainer, - Element, - SubFormed, -> -where - SuperFormer : FormerExtractStorage<>, - < SuperFormer as FormerExtractStorage >::Storage : FormerStorageExtractContainer< SuperContainer >, - SuperContainer : former::ContainerAdd< Element = Element >, - - SubDefinition : former::FormerDefinitionTypes - < - Formed = SuperFormer, - Context = SuperFormer, - >, - SubDefinition::Storage : former::StoragePreform< Preformed = SubFormed >, - - SubFormed : IntoElement< Element >, -{ - - #[ inline( always ) ] - fn call - ( - &self, - storage : SubDefinition::Storage, - super_former : Option< SuperFormer >, - ) - -> - SuperFormer - { - - let storage : SubFormed = former::StoragePreform::preform( storage ); - let mut super_former = super_former.unwrap(); - - let container = FormerStorageExtractContainer - ::< SuperContainer > - ::container_mut( FormerExtractStorage::storage_mut( &mut super_former ) ); - - former::ContainerAdd::add - ( - container, - IntoElement::< Element >::into_element( storage ), - ); - - super_former - } - -} - // == -// include!( "./only_test/subformer_basic.rs" ); -// xxx : uncomment +include!( "./only_test/subformer_basic.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs new file mode 100644 index 0000000000..5df2b2e552 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -0,0 +1,499 @@ +#![ allow( dead_code ) ] +use super::*; + +// +// this should work +// +// let ca = Aggregator::former() +// .parameter1( "val" ) +// .command( "echo" ) +// .name( "prints all subjects and properties" ) +// .subject( "Subject", wca::Type::String, true ) +// .property( "property", "simple property", wca::Type::String, true ) +// .routine( f1 ) +// .end() +// .command( "exit" ) +// .name( "just exit" ) +// .routine( || exit() ) +// .end() +// .perform() +// ; +// ca.execute( input ).unwrap(); + +// == property + +#[ derive( Debug, PartialEq, Default ) ] +pub struct Property< Name > +{ + name : Name, + description : String, + code : isize, +} + +/// generated by new +impl< Name > Property< Name > +{ + #[ inline ] + pub fn new< Description, Code >( name : Name, description : Description, code : Code ) -> Self + where + Name : core::convert::Into< Name >, + Description : core::convert::Into< String >, + Code : core::convert::Into< isize >, + { + Self { name : name.into(), description : description.into(), code : code.into() } + } +} + +// == command + +#[ derive( Debug, PartialEq, the_module::Former ) ] +pub struct Command< K > +where + K : core::hash::Hash + std::cmp::Eq, +{ + pub name : String, + pub subject : String, + // #[ subformer( the_module::HashMapSubformer ) ] + #[ subformer( former::HashMapDefinition ) ] + pub properties : collection_tools::HashMap< K, Property< K > >, +} + +// manual +impl< K, Definition > CommandFormer< K, Definition > +where + K : core::hash::Hash + std::cmp::Eq, + Definition : former::FormerDefinition, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K > >, +{ + + /// Inserts a key-value pair into the map. Make a new container if it was not made so far. + #[ inline( always ) ] + pub fn property< Name, Description, Code > + ( mut self, name : Name, description : Description, code : Code ) -> Self + where + Name : core::convert::Into< K > + Clone, + Description : core::convert::Into< String >, + Code : core::convert::Into< isize >, + { + if self.storage.properties.is_none() + { + self.storage.properties = core::option::Option::Some( Default::default() ); + } + if let core::option::Option::Some( ref mut properties ) = self.storage.properties + { + let property = Property + { + name : name.clone().into(), + description : description.into(), + code : code.into(), + }; + properties.insert( name.into(), property ); + } + self + } + +} + +// == aggregator + +#[ derive( Debug, PartialEq, the_module::Former ) ] +pub struct Aggregator< K > +where + K : core::hash::Hash + std::cmp::Eq, +{ + pub parameter1 : String, + // #[ subformer( the_module::HashMapSubformer ) ] + #[ subformer( former::HashMapDefinition ) ] + pub commands : collection_tools::HashMap< String, Command< K > >, +} + +pub type CommandSubformerWithClosure< K, Superformer > = CommandFormer +< + K, + CommandFormerDefinition + < + K, + Superformer, + Superformer, + former::FormingEndClosure< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, + // impl former::FormingEnd< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, + >, +>; + +pub trait CommandSubformerEnd< K, SuperFormer > +where + K : core::hash::Hash + std::cmp::Eq, + Self : the_module::FormingEnd + < + CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, + > +{ +} + +impl< K, SuperFormer, T > CommandSubformerEnd< K, SuperFormer > +for T +where + K : core::hash::Hash + std::cmp::Eq, + Self : the_module::FormingEnd + < + CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, + > +{ +} + +// manual +// impl< K, Context, End > +// AggregatorFormer< K, Context, End > +// where +// K : core::hash::Hash + std::cmp::Eq, +// End : the_module::FormingEnd< Aggregator< K >, Context >, + +impl< K, Definition > AggregatorFormer +< + K, + Definition, +> +where + K : core::hash::Hash + std::cmp::Eq, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, + + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Aggregator< K > >, + +{ + + #[ inline( always ) ] + pub fn command_with_closure< IntoName >( self, name : IntoName ) + -> + CommandFormer + < + K, + CommandFormerDefinition + < + K, + Self, + Self, + impl CommandSubformerEnd< K, Self >, + // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, + >, + > + where + IntoName : core::convert::Into< String >, + { + + let on_end = | command : CommandFormerStorage< K >, super_former : core::option::Option< Self > | -> Self + { + let command = former::StoragePreform::preform( command ); + let mut super_former = super_former.unwrap(); + if let Some( ref mut commands ) = super_former.storage.commands + { + former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); + } + else + { + let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); + former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); + super_former.storage.commands = Some( commands ); + } + super_former + }; + + let former + : CommandFormer< _, _ > + = CommandFormer::_begin_precise( None, Some( self ), on_end ); + + former.name( name ) + } + + #[ inline( always ) ] + pub fn command_with_types< IntoName >( self, name : IntoName ) + -> + // CommandSubformerWithClosure< K, Self > + CommandFormer + < + K, + CommandFormerDefinition + < + K, + Self, + Self, + impl CommandSubformerEnd< K, Self >, + // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, + >, + > + where + IntoName : core::convert::Into< String >, + { + + let former + // : CommandSubformerWithClosure< K, Self > + // : CommandFormer + // < + // K, + // CommandFormerDefinition + // < + // K, + // Self, + // Self, + // AggregatorFormerCommandEnd2, + // > + // > + = CommandFormer::_begin_precise( None, Some( self ), AggregatorFormerCommandEnd2 ); + + former.name( name ) + + } + + #[ inline( always ) ] + pub fn command_with_helper< IntoName >( self, name : IntoName ) + -> + CommandFormer + < + K, + CommandFormerDefinition + < + K, + Self, + Self, + impl CommandSubformerEnd< K, Self >, + // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, + >, + > + where + IntoName : core::convert::Into< String >, + + ContainerAddElement + < + collection_tools::HashMap< String, Command< K > >, + ( String, Command< K >, ), + Command< K > + > + : + CommandSubformerEnd< K, Self >, + { + + let former + = CommandFormer::_begin_precise + ( + None, + Some( self ), + ContainerAddElement::default(), + ); + + former.name( name ) + } + +} + +#[ allow( non_camel_case_types ) ] +pub struct AggregatorFormerCommandEnd2; + +#[ automatically_derived ] +impl< K, Definition > former::FormingEnd +< + CommandFormerDefinitionTypes + < + K, + AggregatorFormer< K, Definition >, + AggregatorFormer< K, Definition >, + >, +> +for AggregatorFormerCommandEnd2 +where + K : core::hash::Hash + std::cmp::Eq, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = AggregatorFormerStorage< K >, + >, +{ + #[ inline( always ) ] + fn call + ( + &self, + command : CommandFormerStorage< K >, + super_former : Option< AggregatorFormer< K, Definition > >, + ) + -> + AggregatorFormer< K, Definition > + { + + let command = former::StoragePreform::preform( command ); + let mut super_former = super_former.unwrap(); + if let Some( ref mut commands ) = super_former.storage.commands + { + former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); + } + else + { + let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); + former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); + super_former.storage.commands = Some( commands ); + } + super_former + + } +} + +// + +/// xxx : extend description +/// Convert an entity to an element which could be added to a container. +pub trait IntoElement< Element > +{ + /// Convert an entity to an element which could be added to a container. + fn into_element( self ) -> Element; +} + +impl< K > IntoElement< ( String, Command< K > ) > +for Command< K > +where + K : core::hash::Hash + std::cmp::Eq, +{ + fn into_element( self ) -> ( String, Command< K > ) + { + ( self.name.clone(), self ) + } +} + +// + +/// xxx : extend description +/// get container for a field out of a storage +pub trait FormerStorageExtractContainer< Target > +{ + fn container_mut( &mut self ) -> &mut Target; +} + +impl< K > FormerStorageExtractContainer< collection_tools::HashMap< String, Command< K > > > +for AggregatorFormerStorage< K > +where + K : core::hash::Hash + std::cmp::Eq, +{ + fn container_mut( &mut self ) -> &mut collection_tools::HashMap< String, Command< K > > + { + if let Some( ref mut commands ) = self.commands + { + commands + } + else + { + let commands : collection_tools::HashMap< String, Command< K > > = Default::default(); + self.commands = Some( commands ); + self.commands.as_mut().unwrap() + } + } +} + +// + +/// xxx : extend description +/// extract storage from a former +pub trait FormerExtractStorage +{ + type Storage; + fn storage_mut( &mut self ) -> &mut Self::Storage; +} + +impl< K > FormerExtractStorage +for AggregatorFormer< K > +where + K : core::hash::Hash + std::cmp::Eq, +{ + type Storage = AggregatorFormerStorage< K >; + fn storage_mut( &mut self ) -> &mut Self::Storage + { + &mut self.storage + } +} + +// + +#[ derive( Debug ) ] +pub struct ContainerAddElement< SuperContainer, Element, SubFormed > +( core::marker::PhantomData< fn( SuperContainer, Element, SubFormed ) > ); + +impl< SuperContainer, Element, SubFormed > ::core::default::Default +for ContainerAddElement< SuperContainer, Element, SubFormed > +{ + #[ inline( always ) ] + fn default() -> Self + { + Self( core::marker::PhantomData ) + } +} + +impl +< + SuperFormer, + SuperContainer, + Element, + SubFormed, + SubDefinition, +> +former::FormingEnd +< + SubDefinition, + // CommandFormerDefinitionTypes + // < + // K, + // AggregatorFormer< K, SuperDefinition >, + // AggregatorFormer< K, SuperDefinition >, + // >, +> +for ContainerAddElement +< + SuperContainer, + Element, + SubFormed, +> +where + SuperFormer : FormerExtractStorage<>, + < SuperFormer as FormerExtractStorage >::Storage : FormerStorageExtractContainer< SuperContainer >, + SuperContainer : former::ContainerAdd< Element = Element >, + + SubDefinition : former::FormerDefinitionTypes + < + Formed = SuperFormer, + Context = SuperFormer, + >, + SubDefinition::Storage : former::StoragePreform< Preformed = SubFormed >, + + SubFormed : IntoElement< Element >, +{ + + #[ inline( always ) ] + fn call + ( + &self, + storage : SubDefinition::Storage, + super_former : Option< SuperFormer >, + ) + -> + SuperFormer + { + + let storage : SubFormed = former::StoragePreform::preform( storage ); + let mut super_former = super_former.unwrap(); + + let container = FormerStorageExtractContainer + ::< SuperContainer > + ::container_mut( FormerExtractStorage::storage_mut( &mut super_former ) ); + + former::ContainerAdd::add + ( + container, + IntoElement::< Element >::into_element( storage ), + ); + + super_former + } + +} + +// == + +include!( "./only_test/subformer_basic.rs" ); +// xxx : uncomment diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 457ebea3f3..92979966f6 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -58,6 +58,8 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod subformer_basic; // xxx : uncomment + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod subformer_extra; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_shortcut; From 8a38d837cb7d4654eafb19cd9e6d4023b6bb6c9b Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 21:23:34 +0300 Subject: [PATCH 226/533] former : evolve --- .../former_tests/only_test/subformer_extra.rs | 158 +++--- .../former_tests/subformer_basic_manual.rs | 465 ------------------ .../tests/inc/former_tests/subformer_extra.rs | 107 +--- module/core/former/tests/inc/mod.rs | 4 +- 4 files changed, 85 insertions(+), 649 deletions(-) delete mode 100644 module/core/former/tests/inc/former_tests/subformer_basic_manual.rs diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs index 382b87f809..fe62ad6926 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs @@ -1,22 +1,8 @@ -// let ca = wca::CommandsAggregator::former() -// .command_with_closure( "echo" ) -// .name( "prints all subjects and properties" ) -// .subject( "Subject", wca::Type::String, true ) -// .property( "property", "simple property", wca::Type::String, true ) -// .routine( f1 ) -// .perform() -// .command_with_closure( "exit" ) -// .name( "just exit" ) -// .routine( || exit() ) -// .perform() -// .perform() -// ; -// ca.execute( input ).unwrap(); // qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] -fn command_with_closure() +fn command_constructor() { let got = Command::< &str >::former() @@ -26,8 +12,7 @@ fn command_with_closure() let exp = Command::< &str > { name : "a".to_string(), - subject : "b".to_string(), - properties : collection_tools::HashMap::< &str, Property< &str > >::new(), + subject : "b", }; a_id!( got, exp ); @@ -38,8 +23,7 @@ fn command_with_closure() let exp = Command::< &str > { name : "a".to_string(), - subject : "b".to_string(), - properties : collection_tools::HashMap::< &str, Property< &str > >::new(), + subject : "b", }; a_id!( got, exp ); @@ -50,8 +34,7 @@ fn command_with_closure() let exp = Command::< &str > { name : "a".to_string(), - subject : "b".to_string(), - properties : collection_tools::HashMap::< &str, Property< &str > >::new(), + subject : "b", }; a_id!( got, exp ); @@ -69,20 +52,11 @@ fn command_properties() let got = Command::< &str >::former() .name( "a" ) .subject( "b" ) - .property( "property1", "simple property", 13isize ) - .property( "property2", "simple property 2", 13isize ) - .property( "property2", "simple property 3", 113isize ) .form(); let exp = Command::< &str > { name : "a".to_string(), - subject : "b".to_string(), - properties : hmap! - { - "property1" => Property::new( "property1", "simple property", 13isize ), - "property2" => Property::new( "property2", "simple property 3", 113isize ), - }, - // properties : collection_tools::HashMap::< &str, Property< &str > >::new(), + subject : "b", }; a_id!( got, exp ); @@ -90,22 +64,11 @@ fn command_properties() let got = Command::< &str >::former() .name( "a" ) .subject( "b" ) - .properties() - .add( ( "property1", Property::new( "property1", "simple property", 13isize ) ) ) - .add( ( "property2", Property::new( "property2", "simple property 2", 13isize ) ) ) - .add( ( "property2", Property::new( "property2", "simple property 3", 113isize ) ) ) - .end() .form(); let exp = Command::< &str > { name : "a".to_string(), - subject : "b".to_string(), - properties : hmap! - { - "property1" => Property::new( "property1", "simple property", 13isize ), - "property2" => Property::new( "property2", "simple property 3", 113isize ), - }, - // properties : collection_tools::HashMap::< &str, Property< &str > >::new(), + subject : "b", }; a_id!( got, exp ); @@ -113,10 +76,44 @@ fn command_properties() // +#[ test ] +fn aggregator_alternative_form() +{ + + let exp = Aggregator::< &str >::former() + .parameter1( "p1" ) + .command_with_closure( "command1".to_string() ) + .subject( "b" ) + .end() + .form() + ; + + let got = Aggregator::< &str >::former() + .parameter1( "p1" ) + .command_with_closure( "command1".to_string() ) + .subject( "b" ) + .end() + .perform() + ; + a_id!( got, exp ); + + let got = Aggregator::< &str >::former() + .parameter1( "p1" ) + .command_with_closure( "command1".to_string() ) + .subject( "b" ) + .end() + .end() + ; + a_id!( got, exp ); + +} + +// + // qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] -fn aggregator() +fn command_with_closure() { // with helper @@ -125,12 +122,9 @@ fn aggregator() .commands().add( ( "name1".to_string(), CommandFormer::< &str >::new_coercing( former::ReturnPreformed ).name( "name1" ).subject( "s" ).end() ) ).end() .command_with_closure( "command1".to_string() ) .subject( "b" ) - .property( "property1", "simple property", 13isize ) - .property( "property2", "simple property 3", 113isize ) .end() .command_with_closure( "command2".to_string() ) .subject( "c" ) - .property( "property3", "x", 113isize ) .end() .form() ; @@ -138,27 +132,17 @@ fn aggregator() let name1 = Command::< &str > { name : "name1".to_string(), - subject : "s".to_string(), - properties : hmap!{}, + subject : "s", }; let command1 = Command::< &str > { name : "command1".to_string(), - subject : "b".to_string(), - properties : hmap! - { - "property1" => Property::new( "property1", "simple property", 13isize ), - "property2" => Property::new( "property2", "simple property 3", 113isize ), - }, + subject : "b", }; let command2 = Command::< &str > { name : "command2".to_string(), - subject : "c".to_string(), - properties : hmap! - { - "property3" => Property::new( "property3", "x", 113isize ), - }, + subject : "c", }; let exp = Aggregator { @@ -173,37 +157,47 @@ fn aggregator() // +// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +#[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] -fn aggregator_alternative_form() +fn command_with_type() { - let exp = Aggregator::< &str >::former() - .parameter1( "p1" ) - .command_with_closure( "command1".to_string() ) - .subject( "b" ) - .property( "property2", "simple property 3", 113isize ) - .end() - .form() - ; - + // with helper let got = Aggregator::< &str >::former() .parameter1( "p1" ) - .command_with_closure( "command1".to_string() ) + .commands().add( ( "name1".to_string(), CommandFormer::< &str >::new_coercing( former::ReturnPreformed ).name( "name1" ).subject( "s" ).end() ) ).end() + .command_with_type( "command1".to_string() ) .subject( "b" ) - .property( "property2", "simple property 3", 113isize ) .end() - .perform() - ; - a_id!( got, exp ); - - let got = Aggregator::< &str >::former() - .parameter1( "p1" ) - .command_with_closure( "command1".to_string() ) - .subject( "b" ) - .property( "property2", "simple property 3", 113isize ) + .command_with_type( "command2".to_string() ) + .subject( "c" ) .end() - .end() + .form() ; + + let name1 = Command::< &str > + { + name : "name1".to_string(), + subject : "s", + }; + let command1 = Command::< &str > + { + name : "command1".to_string(), + subject : "b", + }; + let command2 = Command::< &str > + { + name : "command2".to_string(), + subject : "c", + }; + let exp = Aggregator + { + parameter1 : "p1".to_string(), + commands : hmap!{ "name1" => name1, "command1" => command1, "command2" => command2 }, + }; + dbg!( &got ); + dbg!( &exp ); a_id!( got, exp ); } diff --git a/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs b/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs deleted file mode 100644 index 09bac144f9..0000000000 --- a/module/core/former/tests/inc/former_tests/subformer_basic_manual.rs +++ /dev/null @@ -1,465 +0,0 @@ -#![ allow( dead_code ) ] -use super::*; - -// let ca = Aggregator::former() -// .parameter1( "val" ) -// .command( "echo" ) -// .name( "prints all subjects and properties" ) -// .subject( "Subject", wca::Type::String, true ) -// .property( "property", "simple property", wca::Type::String, true ) -// .routine( f1 ) -// .end() -// .command( "exit" ) -// .name( "just exit" ) -// .routine( || exit() ) -// .end() -// .perform() -// ; -// ca.execute( input ).unwrap(); - -#[ derive( Debug, PartialEq, Default ) ] -pub struct Property< Name > -{ - name : Name, - description : String, - code : isize, -} - -/// generated by new -impl< Name > Property< Name > -{ - #[ inline ] - pub fn new< Description, Code >( name : Name, description : Description, code : Code ) -> Self - where - Name : core::convert::Into< Name >, - Description : core::convert::Into< String >, - Code : core::convert::Into< isize >, - { - Self { name : name.into(), description : description.into(), code : code.into() } - } -} - -#[ derive( Debug, PartialEq ) ] -pub struct Command< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - pub name : String, - pub subject : String, - pub properties : collection_tools::HashMap< K, Property< K > >, -} - -// generated by former -impl< K > Command< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - - #[ inline( always ) ] - pub fn former() -> CommandFormer< K > - { - CommandFormer::< K >::new() - } - -} - -// generated by former -pub struct CommandFormerStorage< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - name : core::option::Option< String >, - subject : core::option::Option< String >, - properties : core::option::Option< collection_tools::HashMap< K, Property< K > > >, -} - -impl< K > Default for CommandFormerStorage< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - - #[ inline( always ) ] - fn default() -> Self - { - Self - { - name : None, - subject : None, - properties : None, - } - } - -} - -// generated by former -// #[ derive( Debug, Default ) ] -pub struct CommandFormer< K, Context = Command< K >, End = the_module::ReturnPreformed > -where - K : core::hash::Hash + std::cmp::Eq, - End : the_module::FormingEnd< Command< K >, Context >, -{ - storage : CommandFormerStorage< K >, - context : core::option::Option< Context >, - on_end : core::option::Option< End >, -} - -// generated by former -impl< K, Context, End > -CommandFormer< K, Context, End > -where - K : core::hash::Hash + std::cmp::Eq, - End : the_module::FormingEnd< Command< K >, Context >, -{ - - #[ inline( always ) ] - fn form( mut self ) -> Command< K > - { - - let name = if self.storage.name.is_some() - { - self.storage.name.take().unwrap() - } - else - { - let val = Default::default(); - val - }; - - let subject = if self.storage.subject.is_some() - { - self.storage.subject.take().unwrap() - } - else - { - let val = Default::default(); - val - }; - - let properties = if self.storage.properties.is_some() - { - self.storage.properties.take().unwrap() - } - else - { - let val = Default::default(); - val - }; - - Command - { - name, - subject, - properties, - } - } - - #[ inline( always ) ] - pub fn perform( self ) -> Command< K > - { - self.form() - } - - #[ inline( always ) ] - pub fn new() -> CommandFormer< K > - { - CommandFormer::< K >::begin_coercing - ( - None, - None, - the_module::ReturnPreformed, - ) - } - - #[ inline( always ) ] - pub fn begin_coercing - ( - storage : core::option::Option< CommandFormerStorage< K > >, - context : core::option::Option< Context >, - on_end : End, - ) -> Self - { - // qqq : fix - debug_assert!( storage.is_none() ); - Self - { - storage : Default::default(), - context : context, - on_end : Some( on_end ), - } - } - - /// Return former of your struct moving container there. Should be called after configuring the container. - #[ inline( always ) ] - pub fn end( mut self ) -> Context - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) - } - - #[ inline( always ) ] - pub fn name< Src >( mut self, src : Src ) -> Self - where Src : core::convert::Into< String >, - { - debug_assert!( self.storage.name.is_none() ); - self.storage.name = Some( src.into() ); - self - } - - #[ inline( always ) ] - pub fn subject< Src >( mut self, src : Src ) -> Self - where Src : core::convert::Into< String >, - { - debug_assert!( self.storage.subject.is_none() ); - self.storage.subject = Some( src.into() ); - self - } - - #[ inline( always ) ] - pub fn properties( mut self ) -> the_module::HashMapSubformer - < - K, - Property< K >, - collection_tools::HashMap< K, Property< K > >, - CommandFormer< K, Context, End >, - impl the_module::FormingEnd< collection_tools::HashMap< K, Property< K > >, Self >, - > - { - let formed = self.storage.properties.take(); - let on_end = | formed : collection_tools::HashMap< K, Property< K > >, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - super_former.storage.properties = Some( formed ); - super_former - }; - the_module::HashMapSubformer::begin_coercing( formed, Some( self ), on_end ) - } - -} - -// manual -impl< K, Context, End > -CommandFormer< K, Context, End > -where - K : core::hash::Hash + std::cmp::Eq, - End : the_module::FormingEnd< Command< K >, Context >, -{ - - /// Inserts a key-value pair into the map. Make a new container if it was not made so far. - #[ inline( always ) ] - pub fn property< Name, Description, Code > - ( mut self, name : Name, description : Description, code : Code ) -> Self - where - Name : core::convert::Into< K > + Clone, - Description : core::convert::Into< String >, - Code : core::convert::Into< isize >, - { - if self.storage.properties.is_none() - { - self.storage.properties = core::option::Option::Some( Default::default() ); - } - if let core::option::Option::Some( ref mut properties ) = self.storage.properties - { - let property = Property - { - name : name.clone().into(), - description : description.into(), - code : code.into(), - }; - properties.insert( name.into(), property ); - } - self - } - -} - -// == aggregator - -#[ derive( Debug, PartialEq ) ] -pub struct Aggregator< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - pub parameter1 : String, - pub commands : collection_tools::HashMap< String, Command< K > >, -} - -// generated by former -impl< K > Aggregator< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - - #[ inline( always ) ] - pub fn former() -> AggregatorFormer< K > - { - AggregatorFormer::< K >::new() - } - -} - -// generated by former -// #[ derive( Debug, Default ) ] -pub struct AggregatorFormer< K, Context = Aggregator< K >, End = the_module::ReturnPreformed > -where - K : core::hash::Hash + std::cmp::Eq, - End : the_module::FormingEnd< Aggregator< K >, Context >, -{ - parameter1 : core::option::Option< String >, - commands : core::option::Option< collection_tools::HashMap< String, Command< K > > >, - context : core::option::Option< Context >, - on_end : core::option::Option< End >, -} - -// generated by former -impl< K, Context, End > -AggregatorFormer< K, Context, End > -where - K : core::hash::Hash + std::cmp::Eq, - End : the_module::FormingEnd< Aggregator< K >, Context >, -{ - - #[ inline( always ) ] - fn form( mut self ) -> Aggregator< K > - { - - let parameter1 = if self.parameter1.is_some() - { - self.parameter1.take().unwrap() - } - else - { - let val = Default::default(); - val - }; - - let commands = if self.commands.is_some() - { - self.commands.take().unwrap() - } - else - { - let val = Default::default(); - val - }; - - Aggregator - { - parameter1, - commands, - } - } - - #[ inline( always ) ] - pub fn perform( self ) -> Aggregator< K > - { - self.form() - } - - #[ inline( always ) ] - pub fn new() -> AggregatorFormer< K > - { - AggregatorFormer::< K >::begin_coercing - ( - None, - the_module::ReturnPreformed, - ) - } - - #[ inline( always ) ] - pub fn begin_coercing - ( - context : core::option::Option< Context >, - on_end : End, - ) -> Self - { - Self - { - parameter1 : None, - commands : None, - context : context, - on_end : Some( on_end ), - } - } - - /// Return former of your struct moving container there. Should be called after configuring the container. - #[ inline( always ) ] - pub fn end( mut self ) -> Context - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) - } - - #[ inline( always ) ] - pub fn parameter1< Src >( mut self, src : Src ) -> Self - where Src : core::convert::Into< String >, - { - debug_assert!( self.parameter1.is_none() ); - self.parameter1 = Some( src.into() ); - self - } - - #[ inline( always ) ] - pub fn commands( mut self ) -> the_module::HashMapSubformer - < - String, - Command< K >, - collection_tools::HashMap< String, Command< K > >, - AggregatorFormer< K, Context, End >, - impl the_module::FormingEnd< collection_tools::HashMap< String, Command< K > >, Self >, - > - { - let formed = self.commands.take(); - let on_end = | formed : collection_tools::HashMap< String, Command< K > >, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - super_former.commands = Some( formed ); - super_former - }; - the_module::HashMapSubformer::begin_coercing( formed, Some( self ), on_end ) - } - -} - -// manual -impl< K, Context, End > -AggregatorFormer< K, Context, End > -where - K : core::hash::Hash + std::cmp::Eq, - End : the_module::FormingEnd< Aggregator< K >, Context >, -{ - - #[ inline( always ) ] - pub fn command< IntoName >( self, name : IntoName ) - -> CommandFormer< K, Self, impl the_module::FormingEnd< Command< K >, Self > > - where - K : core::hash::Hash + std::cmp::Eq, - IntoName : core::convert::Into< String >, - { - let on_end = | command : Command< K >, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut commands ) = super_former.commands - { - commands.insert( command.name.clone(), command ); - } - else - { - let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - commands.insert( command.name.clone(), command ); - super_former.commands = Some( commands ); - } - super_former - }; - let former = CommandFormer::begin_coercing( None, Some( self ), on_end ); - former.name( name ) - } - -} - -// == - -include!( "./only_test/subformer_basic.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs index 5df2b2e552..a843b05477 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -1,49 +1,6 @@ #![ allow( dead_code ) ] use super::*; -// -// this should work -// -// let ca = Aggregator::former() -// .parameter1( "val" ) -// .command( "echo" ) -// .name( "prints all subjects and properties" ) -// .subject( "Subject", wca::Type::String, true ) -// .property( "property", "simple property", wca::Type::String, true ) -// .routine( f1 ) -// .end() -// .command( "exit" ) -// .name( "just exit" ) -// .routine( || exit() ) -// .end() -// .perform() -// ; -// ca.execute( input ).unwrap(); - -// == property - -#[ derive( Debug, PartialEq, Default ) ] -pub struct Property< Name > -{ - name : Name, - description : String, - code : isize, -} - -/// generated by new -impl< Name > Property< Name > -{ - #[ inline ] - pub fn new< Description, Code >( name : Name, description : Description, code : Code ) -> Self - where - Name : core::convert::Into< Name >, - Description : core::convert::Into< String >, - Code : core::convert::Into< isize >, - { - Self { name : name.into(), description : description.into(), code : code.into() } - } -} - // == command #[ derive( Debug, PartialEq, the_module::Former ) ] @@ -52,47 +9,7 @@ where K : core::hash::Hash + std::cmp::Eq, { pub name : String, - pub subject : String, - // #[ subformer( the_module::HashMapSubformer ) ] - #[ subformer( former::HashMapDefinition ) ] - pub properties : collection_tools::HashMap< K, Property< K > >, -} - -// manual -impl< K, Definition > CommandFormer< K, Definition > -where - K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K > >, -{ - - /// Inserts a key-value pair into the map. Make a new container if it was not made so far. - #[ inline( always ) ] - pub fn property< Name, Description, Code > - ( mut self, name : Name, description : Description, code : Code ) -> Self - where - Name : core::convert::Into< K > + Clone, - Description : core::convert::Into< String >, - Code : core::convert::Into< isize >, - { - if self.storage.properties.is_none() - { - self.storage.properties = core::option::Option::Some( Default::default() ); - } - if let core::option::Option::Some( ref mut properties ) = self.storage.properties - { - let property = Property - { - name : name.clone().into(), - description : description.into(), - code : code.into(), - }; - properties.insert( name.into(), property ); - } - self - } - + pub subject : K, } // == aggregator @@ -103,7 +20,6 @@ where K : core::hash::Hash + std::cmp::Eq, { pub parameter1 : String, - // #[ subformer( the_module::HashMapSubformer ) ] #[ subformer( former::HashMapDefinition ) ] pub commands : collection_tools::HashMap< String, Command< K > >, } @@ -142,12 +58,7 @@ where { } -// manual -// impl< K, Context, End > -// AggregatorFormer< K, Context, End > -// where -// K : core::hash::Hash + std::cmp::Eq, -// End : the_module::FormingEnd< Aggregator< K >, Context >, +// impl< K, Definition > AggregatorFormer < @@ -158,10 +69,8 @@ where K : core::hash::Hash + std::cmp::Eq, Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Aggregator< K > >, - { #[ inline( always ) ] @@ -208,7 +117,7 @@ where } #[ inline( always ) ] - pub fn command_with_types< IntoName >( self, name : IntoName ) + pub fn command_with_type< IntoName >( self, name : IntoName ) -> // CommandSubformerWithClosure< K, Self > CommandFormer @@ -237,10 +146,10 @@ where // K, // Self, // Self, - // AggregatorFormerCommandEnd2, + // AggregatorFormerCommandEnd, // > // > - = CommandFormer::_begin_precise( None, Some( self ), AggregatorFormerCommandEnd2 ); + = CommandFormer::_begin_precise( None, Some( self ), AggregatorFormerCommandEnd ); former.name( name ) @@ -288,7 +197,7 @@ where } #[ allow( non_camel_case_types ) ] -pub struct AggregatorFormerCommandEnd2; +pub struct AggregatorFormerCommandEnd; #[ automatically_derived ] impl< K, Definition > former::FormingEnd @@ -300,7 +209,7 @@ impl< K, Definition > former::FormingEnd AggregatorFormer< K, Definition >, >, > -for AggregatorFormerCommandEnd2 +for AggregatorFormerCommandEnd where K : core::hash::Hash + std::cmp::Eq, Definition : former::FormerDefinition, @@ -495,5 +404,5 @@ where // == -include!( "./only_test/subformer_basic.rs" ); +include!( "./only_test/subformer_extra.rs" ); // xxx : uncomment diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 92979966f6..bec5b304e1 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -53,13 +53,11 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod parametrized_struct_where; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod subformer_basic_manual; #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod subformer_basic; - // xxx : uncomment #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod subformer_extra; + // xxx : uncomment #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_shortcut; From 1edb9e795fd1958de3ca9788132c2db0153ed720 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 21:30:30 +0300 Subject: [PATCH 227/533] former : evolve --- .../tests/inc/former_tests/subformer_extra.rs | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs index a843b05477..6d3b8a9678 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -248,22 +248,15 @@ where // -/// xxx : extend description -/// Convert an entity to an element which could be added to a container. -pub trait IntoElement< Element > -{ - /// Convert an entity to an element which could be added to a container. - fn into_element( self ) -> Element; -} - -impl< K > IntoElement< ( String, Command< K > ) > -for Command< K > +impl< K > From< Command< K > > +for ( String, Command< K > ) where K : core::hash::Hash + std::cmp::Eq, { - fn into_element( self ) -> ( String, Command< K > ) + #[ inline( always ) ] + fn from( src : Command< K > ) -> Self { - ( self.name.clone(), self ) + ( src.name.clone(), src ) } } @@ -370,7 +363,8 @@ where >, SubDefinition::Storage : former::StoragePreform< Preformed = SubFormed >, - SubFormed : IntoElement< Element >, + // SubFormed : IntoElement< Element >, + SubFormed : Into< Element >, { #[ inline( always ) ] @@ -394,7 +388,7 @@ where former::ContainerAdd::add ( container, - IntoElement::< Element >::into_element( storage ), + Into::< Element >::into( storage ), ); super_former From 556500536ee9b534388985a4ff1486c9845fc522 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 21:35:34 +0300 Subject: [PATCH 228/533] former : evolve --- module/core/former/tests/inc/former_tests/subformer_extra.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs index 6d3b8a9678..151d52a0d8 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -363,7 +363,6 @@ where >, SubDefinition::Storage : former::StoragePreform< Preformed = SubFormed >, - // SubFormed : IntoElement< Element >, SubFormed : Into< Element >, { From c593bed89bc595db88e5bf753a3354c9b1dfc745 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 21:37:53 +0300 Subject: [PATCH 229/533] former : evolve --- .../former_tests/only_test/subformer_extra.rs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs index fe62ad6926..bce9bd5328 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs @@ -201,3 +201,50 @@ fn command_with_type() a_id!( got, exp ); } + +// + +// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +#[ cfg( not( feature = "use_alloc" ) ) ] +#[ test ] +fn command_with_helper() +{ + + // with helper + let got = Aggregator::< &str >::former() + .parameter1( "p1" ) + .commands().add( ( "name1".to_string(), CommandFormer::< &str >::new_coercing( former::ReturnPreformed ).name( "name1" ).subject( "s" ).end() ) ).end() + .command_with_helper( "command1".to_string() ) + .subject( "b" ) + .end() + .command_with_helper( "command2".to_string() ) + .subject( "c" ) + .end() + .form() + ; + + let name1 = Command::< &str > + { + name : "name1".to_string(), + subject : "s", + }; + let command1 = Command::< &str > + { + name : "command1".to_string(), + subject : "b", + }; + let command2 = Command::< &str > + { + name : "command2".to_string(), + subject : "c", + }; + let exp = Aggregator + { + parameter1 : "p1".to_string(), + commands : hmap!{ "name1" => name1, "command1" => command1, "command2" => command2 }, + }; + dbg!( &got ); + dbg!( &exp ); + a_id!( got, exp ); + +} From 00deb47179d01f100c0a42bd7a425d99810a8d50 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 21:56:56 +0300 Subject: [PATCH 230/533] former : evolve --- .../tests/inc/former_tests/subformer_extra.rs | 96 ++++++++++++------- module/core/former/tests/inc/mod.rs | 2 - 2 files changed, 61 insertions(+), 37 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs index 151d52a0d8..e78c7ed197 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -24,6 +24,8 @@ where pub commands : collection_tools::HashMap< String, Command< K > >, } +// = + pub type CommandSubformerWithClosure< K, Superformer > = CommandFormer < K, @@ -37,6 +39,36 @@ pub type CommandSubformerWithClosure< K, Superformer > = CommandFormer >, >; +// = + +pub type CommandSubformer< K, Superformer, End > = CommandFormer +< + K, + CommandFormerDefinition + < + K, + Superformer, + Superformer, + End, + // impl former::FormingEnd< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, + >, +>; + +// CommandFormer +// < +// K, +// CommandFormerDefinition +// < +// K, +// Self, +// Self, +// impl CommandSubformerEnd< K, Self >, +// // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, +// >, +// > + +// = + pub trait CommandSubformerEnd< K, SuperFormer > where K : core::hash::Hash + std::cmp::Eq, @@ -58,7 +90,7 @@ where { } -// +// = impl< K, Definition > AggregatorFormer < @@ -119,40 +151,13 @@ where #[ inline( always ) ] pub fn command_with_type< IntoName >( self, name : IntoName ) -> - // CommandSubformerWithClosure< K, Self > - CommandFormer - < - K, - CommandFormerDefinition - < - K, - Self, - Self, - impl CommandSubformerEnd< K, Self >, - // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, - >, - > + CommandSubformer< K, Self, impl CommandSubformerEnd< K, Self > > where IntoName : core::convert::Into< String >, { - let former - // : CommandSubformerWithClosure< K, Self > - // : CommandFormer - // < - // K, - // CommandFormerDefinition - // < - // K, - // Self, - // Self, - // AggregatorFormerCommandEnd, - // > - // > = CommandFormer::_begin_precise( None, Some( self ), AggregatorFormerCommandEnd ); - former.name( name ) - } #[ inline( always ) ] @@ -200,7 +205,9 @@ where pub struct AggregatorFormerCommandEnd; #[ automatically_derived ] -impl< K, Definition > former::FormingEnd +impl< K, Definition > +// CommandSubformerEnd< K, AggregatorFormer< K, Definition > > +former::FormingEnd < CommandFormerDefinitionTypes < @@ -222,23 +229,23 @@ where fn call ( &self, - command : CommandFormerStorage< K >, + sub_storage : CommandFormerStorage< K >, super_former : Option< AggregatorFormer< K, Definition > >, ) -> AggregatorFormer< K, Definition > { - let command = former::StoragePreform::preform( command ); + let sub_formed = former::StoragePreform::preform( sub_storage ); let mut super_former = super_former.unwrap(); if let Some( ref mut commands ) = super_former.storage.commands { - former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); + former::ContainerAdd::add( commands, ( sub_formed.name.clone(), sub_formed ) ); } else { let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); + former::ContainerAdd::add( &mut commands, ( sub_formed.name.clone(), sub_formed ) ); super_former.storage.commands = Some( commands ); } super_former @@ -248,6 +255,26 @@ where // +// /// Convert an entity to an element which could be added to a container. +// pub trait IntoElement< Element > +// { +// /// Convert an entity to an element which could be added to a container. +// fn into_element( self ) -> Element; +// } +// +// impl< K > IntoElement< ( String, Command< K > ) > +// for Command< K > +// where +// K : core::hash::Hash + std::cmp::Eq, +// { +// fn into_element( self ) -> ( String, Command< K > ) +// { +// ( self.name.clone(), self ) +// } +// } + +// + impl< K > From< Command< K > > for ( String, Command< K > ) where @@ -398,4 +425,3 @@ where // == include!( "./only_test/subformer_extra.rs" ); -// xxx : uncomment diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index bec5b304e1..b643b5966b 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -57,8 +57,6 @@ mod former_tests mod subformer_basic; #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod subformer_extra; - // xxx : uncomment - #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_shortcut; From 96085b9c12cd7df116fbc1323184f27745f5d186 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 21:57:43 +0300 Subject: [PATCH 231/533] former : evolve --- .../former/tests/inc/former_tests/subformer_extra.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs index e78c7ed197..2b1143fe66 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -238,15 +238,15 @@ where let sub_formed = former::StoragePreform::preform( sub_storage ); let mut super_former = super_former.unwrap(); - if let Some( ref mut commands ) = super_former.storage.commands + if let Some( ref mut container ) = super_former.storage.commands { - former::ContainerAdd::add( commands, ( sub_formed.name.clone(), sub_formed ) ); + former::ContainerAdd::add( container, ( sub_formed.name.clone(), sub_formed ) ); } else { - let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - former::ContainerAdd::add( &mut commands, ( sub_formed.name.clone(), sub_formed ) ); - super_former.storage.commands = Some( commands ); + let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); + former::ContainerAdd::add( &mut container, ( sub_formed.name.clone(), sub_formed ) ); + super_former.storage.commands = Some( container ); } super_former From 1eac6c91e0a69c9b4c883f88ab8f5be82ed0ee2b Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 22:04:09 +0300 Subject: [PATCH 232/533] former : evolve --- .../tests/inc/former_tests/subformer_extra.rs | 28 ++----------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs index 2b1143fe66..7faecb7d68 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -101,25 +101,13 @@ where K : core::hash::Hash + std::cmp::Eq, Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Aggregator< K > >, { #[ inline( always ) ] pub fn command_with_closure< IntoName >( self, name : IntoName ) -> - CommandFormer - < - K, - CommandFormerDefinition - < - K, - Self, - Self, - impl CommandSubformerEnd< K, Self >, - // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, - >, - > + CommandSubformer< K, Self, impl CommandSubformerEnd< K, Self > > where IntoName : core::convert::Into< String >, { @@ -163,21 +151,9 @@ where #[ inline( always ) ] pub fn command_with_helper< IntoName >( self, name : IntoName ) -> - CommandFormer - < - K, - CommandFormerDefinition - < - K, - Self, - Self, - impl CommandSubformerEnd< K, Self >, - // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, - >, - > + CommandSubformer< K, Self, impl CommandSubformerEnd< K, Self > > where IntoName : core::convert::Into< String >, - ContainerAddElement < collection_tools::HashMap< String, Command< K > >, From c64ea27fe6c49bf94305112487065b88d57726b6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 22:05:39 +0300 Subject: [PATCH 233/533] former : evolve --- .../tests/inc/former_tests/subformer_extra.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs index 7faecb7d68..c1169d7625 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -112,19 +112,19 @@ where IntoName : core::convert::Into< String >, { - let on_end = | command : CommandFormerStorage< K >, super_former : core::option::Option< Self > | -> Self + let on_end = | storage : CommandFormerStorage< K >, super_former : core::option::Option< Self > | -> Self { - let command = former::StoragePreform::preform( command ); + let formed = former::StoragePreform::preform( storage ); let mut super_former = super_former.unwrap(); - if let Some( ref mut commands ) = super_former.storage.commands + if let Some( ref mut container ) = super_former.storage.commands { - former::ContainerAdd::add( commands, ( command.name.clone(), command ) ); + former::ContainerAdd::add( container, ( formed.name.clone(), formed ) ); } else { - let mut commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - former::ContainerAdd::add( &mut commands, ( command.name.clone(), command ) ); - super_former.storage.commands = Some( commands ); + let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); + former::ContainerAdd::add( &mut container, ( formed.name.clone(), formed ) ); + super_former.storage.commands = Some( container ); } super_former }; From 5e96866b35c0b08549822610a4404507fba2b012 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 22:06:09 +0300 Subject: [PATCH 234/533] former : evolve --- module/core/former/tests/inc/former_tests/subformer_extra.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs index c1169d7625..79a984c6a8 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -104,6 +104,7 @@ where < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Aggregator< K > >, { + // #[ inline( always ) ] pub fn command_with_closure< IntoName >( self, name : IntoName ) -> @@ -136,6 +137,7 @@ where former.name( name ) } + // #[ inline( always ) ] pub fn command_with_type< IntoName >( self, name : IntoName ) -> @@ -148,6 +150,7 @@ where former.name( name ) } + // #[ inline( always ) ] pub fn command_with_helper< IntoName >( self, name : IntoName ) -> @@ -163,7 +166,6 @@ where : CommandSubformerEnd< K, Self >, { - let former = CommandFormer::_begin_precise ( @@ -171,7 +173,6 @@ where Some( self ), ContainerAddElement::default(), ); - former.name( name ) } From 36c530209ef7a43715b17290525938dcab49ffde Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 22:13:47 +0300 Subject: [PATCH 235/533] former : evolve --- .../former/tests/inc/former_tests/subformer_extra.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs index 79a984c6a8..68e5ed2595 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -145,8 +145,7 @@ where where IntoName : core::convert::Into< String >, { - let former - = CommandFormer::_begin_precise( None, Some( self ), AggregatorFormerCommandEnd ); + let former = CommandFormer::_begin_precise( None, Some( self ), AggregatorFormerCommandEnd ); former.name( name ) } @@ -217,16 +216,19 @@ where let mut super_former = super_former.unwrap(); if let Some( ref mut container ) = super_former.storage.commands { - former::ContainerAdd::add( container, ( sub_formed.name.clone(), sub_formed ) ); + // former::ContainerAdd::add( container, ( sub_formed.name.clone(), sub_formed ) ); + former::ContainerAdd::add( container, Into::into( sub_formed ) ); } else { let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); - former::ContainerAdd::add( &mut container, ( sub_formed.name.clone(), sub_formed ) ); + // former::ContainerAdd::add( &mut container, ( sub_formed.name.clone(), sub_formed ) ); + // former::ContainerAdd::add( &mut container, Into::< Element >::into( sub_formed ) ); + former::ContainerAdd::add( &mut container, Into::into( sub_formed ) ); super_former.storage.commands = Some( container ); } - super_former + super_former } } From 1d47db647e8a774c3ff50f1f187d01e2256a4b75 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 22:25:49 +0300 Subject: [PATCH 236/533] former : evolve --- module/core/former/tests/inc/former_tests/subformer_extra.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs index 68e5ed2595..7b1ce68fca 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -177,12 +177,9 @@ where } -#[ allow( non_camel_case_types ) ] pub struct AggregatorFormerCommandEnd; -#[ automatically_derived ] impl< K, Definition > -// CommandSubformerEnd< K, AggregatorFormer< K, Definition > > former::FormingEnd < CommandFormerDefinitionTypes @@ -223,7 +220,6 @@ where { let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); // former::ContainerAdd::add( &mut container, ( sub_formed.name.clone(), sub_formed ) ); - // former::ContainerAdd::add( &mut container, Into::< Element >::into( sub_formed ) ); former::ContainerAdd::add( &mut container, Into::into( sub_formed ) ); super_former.storage.commands = Some( container ); } From cbeb0dc7e8e75bba08f050e7a3fef267f62c9989 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 22:28:03 +0300 Subject: [PATCH 237/533] former : evolve --- .../tests/inc/former_tests/subformer_extra.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs index 7b1ce68fca..48c49d9692 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -178,9 +178,7 @@ where } pub struct AggregatorFormerCommandEnd; - -impl< K, Definition > -former::FormingEnd +impl< K, Definition > former::FormingEnd < CommandFormerDefinitionTypes < @@ -209,18 +207,18 @@ where AggregatorFormer< K, Definition > { - let sub_formed = former::StoragePreform::preform( sub_storage ); + let preformed = former::StoragePreform::preform( sub_storage ); let mut super_former = super_former.unwrap(); if let Some( ref mut container ) = super_former.storage.commands { - // former::ContainerAdd::add( container, ( sub_formed.name.clone(), sub_formed ) ); - former::ContainerAdd::add( container, Into::into( sub_formed ) ); + // former::ContainerAdd::add( container, ( preformed.name.clone(), preformed ) ); + former::ContainerAdd::add( container, Into::into( preformed ) ); } else { let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); - // former::ContainerAdd::add( &mut container, ( sub_formed.name.clone(), sub_formed ) ); - former::ContainerAdd::add( &mut container, Into::into( sub_formed ) ); + // former::ContainerAdd::add( &mut container, ( preformed.name.clone(), preformed ) ); + former::ContainerAdd::add( &mut container, Into::into( preformed ) ); super_former.storage.commands = Some( container ); } From f2a1c74ad15c8664105f39b9deea9899e2430e89 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 22:31:20 +0300 Subject: [PATCH 238/533] former : evolve --- .../tests/inc/former_tests/subformer_extra.rs | 67 ++++++++----------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs index 48c49d9692..18e41a0632 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -12,34 +12,22 @@ where pub subject : K, } -// == aggregator - -#[ derive( Debug, PartialEq, the_module::Former ) ] -pub struct Aggregator< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - pub parameter1 : String, - #[ subformer( former::HashMapDefinition ) ] - pub commands : collection_tools::HashMap< String, Command< K > >, -} - -// = +// = command subformer with closure -pub type CommandSubformerWithClosure< K, Superformer > = CommandFormer -< - K, - CommandFormerDefinition - < - K, - Superformer, - Superformer, - former::FormingEndClosure< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, - // impl former::FormingEnd< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, - >, ->; +// pub type CommandSubformerWithClosure< K, Superformer > = CommandFormer +// < +// K, +// CommandFormerDefinition +// < +// K, +// Superformer, +// Superformer, +// former::FormingEndClosure< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, +// // impl former::FormingEnd< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, +// >, +// >; -// = +// = command subformer pub type CommandSubformer< K, Superformer, End > = CommandFormer < @@ -54,20 +42,7 @@ pub type CommandSubformer< K, Superformer, End > = CommandFormer >, >; -// CommandFormer -// < -// K, -// CommandFormerDefinition -// < -// K, -// Self, -// Self, -// impl CommandSubformerEnd< K, Self >, -// // impl the_module::FormingEnd< CommandFormerDefinitionTypes< K, Self, Self > >, -// >, -// > - -// = +// = command subformer end pub trait CommandSubformerEnd< K, SuperFormer > where @@ -90,6 +65,18 @@ where { } +// == aggregator + +#[ derive( Debug, PartialEq, the_module::Former ) ] +pub struct Aggregator< K > +where + K : core::hash::Hash + std::cmp::Eq, +{ + pub parameter1 : String, + #[ subformer( former::HashMapDefinition ) ] + pub commands : collection_tools::HashMap< String, Command< K > >, +} + // = impl< K, Definition > AggregatorFormer From 1b57bbb3b394bdf57eb0d0b6edb8311ef143c61d Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 23:18:35 +0300 Subject: [PATCH 239/533] former : evolve --- .../tests/inc/former_tests/subformer_basic.rs | 65 ++++++++--------- .../tests/inc/former_tests/subformer_extra.rs | 69 ++++++++----------- module/core/former_meta/src/derive/former.rs | 57 ++++++++++++++- 3 files changed, 114 insertions(+), 77 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index d86ea06af5..0d7637632b 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -106,38 +106,39 @@ where pub commands : collection_tools::HashMap< String, Command< K > >, } -pub type CommandSubformerWithClosure< K, Superformer > = CommandFormer -< - K, - CommandFormerDefinition - < - K, - Superformer, - Superformer, - former::FormingEndClosure< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, - >, ->; - -pub trait CommandSubformerEnd< K, SuperFormer > -where - K : core::hash::Hash + std::cmp::Eq, - Self : the_module::FormingEnd - < - CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, - > -{ -} - -impl< K, SuperFormer, T > CommandSubformerEnd< K, SuperFormer > -for T -where - K : core::hash::Hash + std::cmp::Eq, - Self : the_module::FormingEnd - < - CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, - > -{ -} +// xxx : remove +// pub type CommandSubformerWithClosure< K, Superformer > = CommandFormer +// < +// K, +// CommandFormerDefinition +// < +// K, +// Superformer, +// Superformer, +// former::FormingEndClosure< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, +// >, +// >; +// +// pub trait CommandSubformerEnd< K, SuperFormer > +// where +// K : core::hash::Hash + std::cmp::Eq, +// Self : the_module::FormingEnd +// < +// CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, +// > +// { +// } +// +// impl< K, SuperFormer, T > CommandSubformerEnd< K, SuperFormer > +// for T +// where +// K : core::hash::Hash + std::cmp::Eq, +// Self : the_module::FormingEnd +// < +// CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, +// > +// { +// } // == diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_extra.rs index 18e41a0632..28e66a215b 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_extra.rs @@ -12,9 +12,9 @@ where pub subject : K, } -// = command subformer with closure - -// pub type CommandSubformerWithClosure< K, Superformer > = CommandFormer +// // = command subformer - generated +// +// pub type CommandSubformer< K, Superformer, End > = CommandFormer // < // K, // CommandFormerDefinition @@ -22,48 +22,33 @@ where // K, // Superformer, // Superformer, -// former::FormingEndClosure< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, +// End, // // impl former::FormingEnd< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, // >, // >; - -// = command subformer - -pub type CommandSubformer< K, Superformer, End > = CommandFormer -< - K, - CommandFormerDefinition - < - K, - Superformer, - Superformer, - End, - // impl former::FormingEnd< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, - >, ->; - -// = command subformer end - -pub trait CommandSubformerEnd< K, SuperFormer > -where - K : core::hash::Hash + std::cmp::Eq, - Self : the_module::FormingEnd - < - CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, - > -{ -} - -impl< K, SuperFormer, T > CommandSubformerEnd< K, SuperFormer > -for T -where - K : core::hash::Hash + std::cmp::Eq, - Self : the_module::FormingEnd - < - CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, - > -{ -} +// +// // = command subformer end - generated +// +// pub trait CommandSubformerEnd< K, SuperFormer > +// where +// K : core::hash::Hash + std::cmp::Eq, +// Self : the_module::FormingEnd +// < +// CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, +// > +// { +// } +// +// impl< K, SuperFormer, T > CommandSubformerEnd< K, SuperFormer > +// for T +// where +// K : core::hash::Hash + std::cmp::Eq, +// Self : the_module::FormingEnd +// < +// CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, +// > +// { +// } // == aggregator diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index ea6c824424..54a5a169f3 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1077,16 +1077,20 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_definition_types_name = format!( "{}FormerDefinitionTypes", struct_name ); let former_definition_types = syn::Ident::new( &former_definition_types_name, struct_name.span() ); let former_with_closure_name = format!( "{}FormerWithClosure", struct_name ); - let former_with_closure = syn::Ident::new( &former_with_closure_name, struct_name.span() ); + let former_with_closure = syn::Ident::new( &former_with_closure_name, struct_name.span() ); // xxx : maybe remove + let subformer_name = format!( "{}Subformer", struct_name ); + let subformer = syn::Ident::new( &subformer_name, struct_name.span() ); + let subformer_end_name = format!( "{}SubformerEnd", struct_name ); + let subformer_end = syn::Ident::new( &subformer_end_name, struct_name.span() ); - /* generic parameters */ + /* parameters for structure */ let generics = &ast.generics; let ( struct_generics_with_defaults, struct_generics_impl, struct_generics_ty, struct_generics_where ) = generic_params::decompose( generics ); /* parameters for definition */ - /* parameters for definition */ + let extra : macro_tools::syn::AngleBracketedGenericArguments = parse_quote! { < (), #struct_name < #struct_generics_ty >, former::ReturnPreformed > @@ -1094,6 +1098,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_definition_args = generic_args::merge( &generics.into_generic_args(), &extra.into() ).args; /* parameters for former */ + let extra : macro_tools::GenericsWithWhere = parse_quote! { < Definition = #former_definition < #former_definition_args > > @@ -1107,6 +1112,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > = generic_params::decompose( &extra ); /* parameters for definition types */ + let extra : macro_tools::GenericsWithWhere = parse_quote! { < __Context = (), __Formed = #struct_name < #struct_generics_ty > > @@ -1118,6 +1124,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_definition_type_phantom = macro_tools::phantom::tuple( &former_definition_type_generics_impl ); /* parameters for definition */ + let extra : macro_tools::GenericsWithWhere = parse_quote! { < __Context = (), __Formed = #struct_name < #struct_generics_ty >, __End = former::ReturnPreformed > @@ -1521,6 +1528,50 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } + // = subformer + + // xxx + + /// Use as subformer of a field during process of forming of super structure. + pub type #subformer < #struct_generics_ty __Superformer, __End > = #former + < + #struct_generics_ty + #former_definition + < + #struct_generics_ty + __Superformer, + __Superformer, + __End, + // impl former::FormingEnd< CommandFormerDefinitionTypes< K, __Superformer, __Superformer > >, + >, + >; + + // = subformer end + + /// Use as subformer end of a field during process of forming of super structure. + pub trait #subformer_end < #struct_generics_impl SuperFormer > + where + #struct_generics_where + Self : former::FormingEnd + < + #former_definition_types < #struct_generics_ty SuperFormer, SuperFormer >, + >, + { + } + + impl< #struct_generics_impl SuperFormer, T > #subformer_end < #struct_generics_ty SuperFormer > + for T + where + #struct_generics_where + Self : former::FormingEnd + < + #former_definition_types < #struct_generics_ty SuperFormer, SuperFormer >, + >, + { + } + + // = setters + #( #fields_setter_callback_descriptor )* From 03c8378bc3ebcaff93f42a7ea5f85dd605e37e33 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 23:24:41 +0300 Subject: [PATCH 240/533] former : evolve --- ...subformer_extra.rs => subformer_custom.rs} | 47 ---- .../subformer_custom_experimental.rs | 47 ++++ ...subformer_extra.rs => subformer_custom.rs} | 161 +----------- .../subformer_custom_experimental.rs | 240 ++++++++++++++++++ module/core/former/tests/inc/mod.rs | 4 +- 5 files changed, 291 insertions(+), 208 deletions(-) rename module/core/former/tests/inc/former_tests/only_test/{subformer_extra.rs => subformer_custom.rs} (79%) create mode 100644 module/core/former/tests/inc/former_tests/only_test/subformer_custom_experimental.rs rename module/core/former/tests/inc/former_tests/{subformer_extra.rs => subformer_custom.rs} (60%) create mode 100644 module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_custom.rs similarity index 79% rename from module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs rename to module/core/former/tests/inc/former_tests/only_test/subformer_custom.rs index bce9bd5328..fe62ad6926 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_custom.rs @@ -201,50 +201,3 @@ fn command_with_type() a_id!( got, exp ); } - -// - -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] -#[ cfg( not( feature = "use_alloc" ) ) ] -#[ test ] -fn command_with_helper() -{ - - // with helper - let got = Aggregator::< &str >::former() - .parameter1( "p1" ) - .commands().add( ( "name1".to_string(), CommandFormer::< &str >::new_coercing( former::ReturnPreformed ).name( "name1" ).subject( "s" ).end() ) ).end() - .command_with_helper( "command1".to_string() ) - .subject( "b" ) - .end() - .command_with_helper( "command2".to_string() ) - .subject( "c" ) - .end() - .form() - ; - - let name1 = Command::< &str > - { - name : "name1".to_string(), - subject : "s", - }; - let command1 = Command::< &str > - { - name : "command1".to_string(), - subject : "b", - }; - let command2 = Command::< &str > - { - name : "command2".to_string(), - subject : "c", - }; - let exp = Aggregator - { - parameter1 : "p1".to_string(), - commands : hmap!{ "name1" => name1, "command1" => command1, "command2" => command2 }, - }; - dbg!( &got ); - dbg!( &exp ); - a_id!( got, exp ); - -} diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_custom_experimental.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_custom_experimental.rs new file mode 100644 index 0000000000..2bd1f4e924 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_custom_experimental.rs @@ -0,0 +1,47 @@ + +// + +// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +#[ cfg( not( feature = "use_alloc" ) ) ] +#[ test ] +fn command_with_helper() +{ + + // with helper + let got = Aggregator::< &str >::former() + .parameter1( "p1" ) + .commands().add( ( "name1".to_string(), CommandFormer::< &str >::new_coercing( former::ReturnPreformed ).name( "name1" ).subject( "s" ).end() ) ).end() + .command_with_helper( "command1".to_string() ) + .subject( "b" ) + .end() + .command_with_helper( "command2".to_string() ) + .subject( "c" ) + .end() + .form() + ; + + let name1 = Command::< &str > + { + name : "name1".to_string(), + subject : "s", + }; + let command1 = Command::< &str > + { + name : "command1".to_string(), + subject : "b", + }; + let command2 = Command::< &str > + { + name : "command2".to_string(), + subject : "c", + }; + let exp = Aggregator + { + parameter1 : "p1".to_string(), + commands : hmap!{ "name1" => name1, "command1" => command1, "command2" => command2 }, + }; + dbg!( &got ); + dbg!( &exp ); + a_id!( got, exp ); + +} diff --git a/module/core/former/tests/inc/former_tests/subformer_extra.rs b/module/core/former/tests/inc/former_tests/subformer_custom.rs similarity index 60% rename from module/core/former/tests/inc/former_tests/subformer_extra.rs rename to module/core/former/tests/inc/former_tests/subformer_custom.rs index 28e66a215b..6e066f7baf 100644 --- a/module/core/former/tests/inc/former_tests/subformer_extra.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom.rs @@ -121,32 +121,6 @@ where former.name( name ) } - // - #[ inline( always ) ] - pub fn command_with_helper< IntoName >( self, name : IntoName ) - -> - CommandSubformer< K, Self, impl CommandSubformerEnd< K, Self > > - where - IntoName : core::convert::Into< String >, - ContainerAddElement - < - collection_tools::HashMap< String, Command< K > >, - ( String, Command< K >, ), - Command< K > - > - : - CommandSubformerEnd< K, Self >, - { - let former - = CommandFormer::_begin_precise - ( - None, - Some( self ), - ContainerAddElement::default(), - ); - former.name( name ) - } - } pub struct AggregatorFormerCommandEnd; @@ -234,139 +208,6 @@ where // -/// xxx : extend description -/// get container for a field out of a storage -pub trait FormerStorageExtractContainer< Target > -{ - fn container_mut( &mut self ) -> &mut Target; -} - -impl< K > FormerStorageExtractContainer< collection_tools::HashMap< String, Command< K > > > -for AggregatorFormerStorage< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - fn container_mut( &mut self ) -> &mut collection_tools::HashMap< String, Command< K > > - { - if let Some( ref mut commands ) = self.commands - { - commands - } - else - { - let commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - self.commands = Some( commands ); - self.commands.as_mut().unwrap() - } - } -} - -// - -/// xxx : extend description -/// extract storage from a former -pub trait FormerExtractStorage -{ - type Storage; - fn storage_mut( &mut self ) -> &mut Self::Storage; -} - -impl< K > FormerExtractStorage -for AggregatorFormer< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - type Storage = AggregatorFormerStorage< K >; - fn storage_mut( &mut self ) -> &mut Self::Storage - { - &mut self.storage - } -} - -// - -#[ derive( Debug ) ] -pub struct ContainerAddElement< SuperContainer, Element, SubFormed > -( core::marker::PhantomData< fn( SuperContainer, Element, SubFormed ) > ); - -impl< SuperContainer, Element, SubFormed > ::core::default::Default -for ContainerAddElement< SuperContainer, Element, SubFormed > -{ - #[ inline( always ) ] - fn default() -> Self - { - Self( core::marker::PhantomData ) - } -} - -impl -< - SuperFormer, - SuperContainer, - Element, - SubFormed, - SubDefinition, -> -former::FormingEnd -< - SubDefinition, - // CommandFormerDefinitionTypes - // < - // K, - // AggregatorFormer< K, SuperDefinition >, - // AggregatorFormer< K, SuperDefinition >, - // >, -> -for ContainerAddElement -< - SuperContainer, - Element, - SubFormed, -> -where - SuperFormer : FormerExtractStorage<>, - < SuperFormer as FormerExtractStorage >::Storage : FormerStorageExtractContainer< SuperContainer >, - SuperContainer : former::ContainerAdd< Element = Element >, - - SubDefinition : former::FormerDefinitionTypes - < - Formed = SuperFormer, - Context = SuperFormer, - >, - SubDefinition::Storage : former::StoragePreform< Preformed = SubFormed >, - - SubFormed : Into< Element >, -{ - - #[ inline( always ) ] - fn call - ( - &self, - storage : SubDefinition::Storage, - super_former : Option< SuperFormer >, - ) - -> - SuperFormer - { - - let storage : SubFormed = former::StoragePreform::preform( storage ); - let mut super_former = super_former.unwrap(); - - let container = FormerStorageExtractContainer - ::< SuperContainer > - ::container_mut( FormerExtractStorage::storage_mut( &mut super_former ) ); - - former::ContainerAdd::add - ( - container, - Into::< Element >::into( storage ), - ); - - super_former - } - -} - // == -include!( "./only_test/subformer_extra.rs" ); +include!( "./only_test/subformer_custom.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs new file mode 100644 index 0000000000..3426a4a042 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs @@ -0,0 +1,240 @@ +#![ allow( dead_code ) ] +use super::*; + +// == command + +#[ derive( Debug, PartialEq, the_module::Former ) ] +pub struct Command< K > +where + K : core::hash::Hash + std::cmp::Eq, +{ + pub name : String, + pub subject : K, +} + +// == aggregator + +#[ derive( Debug, PartialEq, the_module::Former ) ] +pub struct Aggregator< K > +where + K : core::hash::Hash + std::cmp::Eq, +{ + pub parameter1 : String, + #[ subformer( former::HashMapDefinition ) ] + pub commands : collection_tools::HashMap< String, Command< K > >, +} + +// = + +impl< K, Definition > AggregatorFormer +< + K, + Definition, +> +where + K : core::hash::Hash + std::cmp::Eq, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Aggregator< K > >, +{ + + // + #[ inline( always ) ] + pub fn command_with_helper< IntoName >( self, name : IntoName ) + -> + CommandSubformer< K, Self, impl CommandSubformerEnd< K, Self > > + where + IntoName : core::convert::Into< String >, + ContainerAddElement + < + collection_tools::HashMap< String, Command< K > >, + ( String, Command< K >, ), + Command< K > + > + : + CommandSubformerEnd< K, Self >, + { + let former + = CommandFormer::_begin_precise + ( + None, + Some( self ), + ContainerAddElement::default(), + ); + former.name( name ) + } + +} + +// + +// /// Convert an entity to an element which could be added to a container. +// pub trait IntoElement< Element > +// { +// /// Convert an entity to an element which could be added to a container. +// fn into_element( self ) -> Element; +// } +// +// impl< K > IntoElement< ( String, Command< K > ) > +// for Command< K > +// where +// K : core::hash::Hash + std::cmp::Eq, +// { +// fn into_element( self ) -> ( String, Command< K > ) +// { +// ( self.name.clone(), self ) +// } +// } + +// + +impl< K > From< Command< K > > +for ( String, Command< K > ) +where + K : core::hash::Hash + std::cmp::Eq, +{ + #[ inline( always ) ] + fn from( src : Command< K > ) -> Self + { + ( src.name.clone(), src ) + } +} + +// + +/// xxx : extend description +/// get container for a field out of a storage +pub trait FormerStorageExtractContainer< Target > +{ + fn container_mut( &mut self ) -> &mut Target; +} + +impl< K > FormerStorageExtractContainer< collection_tools::HashMap< String, Command< K > > > +for AggregatorFormerStorage< K > +where + K : core::hash::Hash + std::cmp::Eq, +{ + fn container_mut( &mut self ) -> &mut collection_tools::HashMap< String, Command< K > > + { + if let Some( ref mut commands ) = self.commands + { + commands + } + else + { + let commands : collection_tools::HashMap< String, Command< K > > = Default::default(); + self.commands = Some( commands ); + self.commands.as_mut().unwrap() + } + } +} + +// + +/// xxx : extend description +/// extract storage from a former +pub trait FormerExtractStorage +{ + type Storage; + fn storage_mut( &mut self ) -> &mut Self::Storage; +} + +impl< K > FormerExtractStorage +for AggregatorFormer< K > +where + K : core::hash::Hash + std::cmp::Eq, +{ + type Storage = AggregatorFormerStorage< K >; + fn storage_mut( &mut self ) -> &mut Self::Storage + { + &mut self.storage + } +} + +// + +#[ derive( Debug ) ] +pub struct ContainerAddElement< SuperContainer, Element, SubFormed > +( core::marker::PhantomData< fn( SuperContainer, Element, SubFormed ) > ); + +impl< SuperContainer, Element, SubFormed > ::core::default::Default +for ContainerAddElement< SuperContainer, Element, SubFormed > +{ + #[ inline( always ) ] + fn default() -> Self + { + Self( core::marker::PhantomData ) + } +} + +impl +< + SuperFormer, + SuperContainer, + Element, + SubFormed, + SubDefinition, +> +former::FormingEnd +< + SubDefinition, + // CommandFormerDefinitionTypes + // < + // K, + // AggregatorFormer< K, SuperDefinition >, + // AggregatorFormer< K, SuperDefinition >, + // >, +> +for ContainerAddElement +< + SuperContainer, + Element, + SubFormed, +> +where + SuperFormer : FormerExtractStorage<>, + < SuperFormer as FormerExtractStorage >::Storage : FormerStorageExtractContainer< SuperContainer >, + SuperContainer : former::ContainerAdd< Element = Element >, + + SubDefinition : former::FormerDefinitionTypes + < + Formed = SuperFormer, + Context = SuperFormer, + >, + SubDefinition::Storage : former::StoragePreform< Preformed = SubFormed >, + + SubFormed : Into< Element >, +{ + + #[ inline( always ) ] + fn call + ( + &self, + storage : SubDefinition::Storage, + super_former : Option< SuperFormer >, + ) + -> + SuperFormer + { + + let storage : SubFormed = former::StoragePreform::preform( storage ); + let mut super_former = super_former.unwrap(); + + let container = FormerStorageExtractContainer + ::< SuperContainer > + ::container_mut( FormerExtractStorage::storage_mut( &mut super_former ) ); + + former::ContainerAdd::add + ( + container, + Into::< Element >::into( storage ), + ); + + super_former + } + +} + +// == + +include!( "./only_test/subformer_custom_experimental.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index b643b5966b..4677eacfe2 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -56,7 +56,9 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod subformer_basic; #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_extra; + mod subformer_custom; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod subformer_custom_experimental; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_shortcut; From 074bcdd6183edb0d120a21a41883b77be3eb7329 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 23:45:13 +0300 Subject: [PATCH 241/533] former : evolve --- .../inc/former_tests/attribute_perform.rs | 6 +++- module/core/former/tests/inc/mod.rs | 10 +++--- module/core/former_meta/src/derive/former.rs | 36 +++++++++++++++++-- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_perform.rs b/module/core/former/tests/inc/former_tests/attribute_perform.rs index b7e645bbfc..2eaaa75fa0 100644 --- a/module/core/former/tests/inc/former_tests/attribute_perform.rs +++ b/module/core/former/tests/inc/former_tests/attribute_perform.rs @@ -7,6 +7,8 @@ pub struct Struct0 pub int_1 : i32, } +// #[ derive( Debug, PartialEq ) ] +// #[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] #[ derive( Debug, PartialEq, the_module::Former ) ] #[ perform( fn perform1< 'a >() -> Option< &'a str > ) ] pub struct Struct1 @@ -14,7 +16,9 @@ pub struct Struct1 pub int_1 : i32, } -// +// == begin of generated + +// == end of generated impl Struct1 { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 4677eacfe2..c813d82bf7 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -28,7 +28,7 @@ mod former_tests mod attribute_default_container; mod attribute_default_primitive; - // mod attribute_perform; // xxx + mod attribute_perform; mod attribute_setter; mod attribute_alias; @@ -107,12 +107,12 @@ only_for_terminal_module! { println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); - // let t = test_tools::compiletime::TestCases::new(); + let t = test_tools::compiletime::TestCases::new(); // zzz : uncomment - // t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); - // t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); - // t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); + t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); + t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); + t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 54a5a169f3..97822f7e1f 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1111,6 +1111,28 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( former_generics_with_defaults, former_generics_impl, former_generics_ty, former_generics_where ) = generic_params::decompose( &extra ); + /* parameters for former perform */ + + let extra : macro_tools::GenericsWithWhere = parse_quote! + { + < Definition = #former_definition < #former_definition_args > > + where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = #former_storage < #struct_generics_ty >, + Formed = #struct_name < #struct_generics_ty > + >, + }; + let extra = generic_params::merge( &generics, &extra.into() ); + + let ( _former_perform_generics_with_defaults, former_perform_generics_impl, former_perform_generics_ty, former_perform_generics_where ) + = generic_params::decompose( &extra ); + +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<>, Formed = Struct1 >, + /* parameters for definition types */ let extra : macro_tools::GenericsWithWhere = parse_quote! @@ -1389,9 +1411,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } #[ automatically_derived ] - impl < #former_generics_impl > #former < #former_generics_ty > + impl < #former_perform_generics_impl > #former < #former_perform_generics_ty > where - #former_generics_where + #former_perform_generics_where { /// @@ -1407,6 +1429,14 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #perform } + } + + #[ automatically_derived ] + impl < #former_generics_impl > #former < #former_generics_ty > + where + #former_generics_where + { + /// /// Construct new instance of former with default parameters. /// @@ -1530,7 +1560,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = subformer - // xxx + // xxx : improve description /// Use as subformer of a field during process of forming of super structure. pub type #subformer < #struct_generics_ty __Superformer, __End > = #former From 28a750366abbdeb7ac5dc65bebcbe07cbdce8359 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 23:52:36 +0300 Subject: [PATCH 242/533] former : evolve --- module/core/former/src/hash_map.rs | 2 +- module/core/former/src/hash_set.rs | 2 +- ..._under_feature.rs => attribute_feature.rs} | 1 + .../former_tests/container_former_common.rs | 6 ++-- .../tests/inc/former_tests/only_test/basic.rs | 1 - .../parametrized_struct_manual.rs | 3 +- .../tests/inc/former_tests/subformer_basic.rs | 34 ------------------- .../subformer_custom_experimental.rs | 2 -- module/core/former/tests/inc/mod.rs | 1 + 9 files changed, 8 insertions(+), 44 deletions(-) rename module/core/former/tests/inc/former_tests/{only_test/with_field_under_feature.rs => attribute_feature.rs} (94%) diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index c1bfeabb58..6e3deb4a35 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -171,7 +171,7 @@ where // pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, End > >; -// xxx : update documentation +// zzz : update documentation // pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< K, HashMapDefinition< K, E, Context, End > >; pub type HashMapSubformer< K, E, Context, Formed, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, Formed, End > >; diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index b2cec7cb93..11a517fec0 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -120,7 +120,7 @@ where /// # } /// ``` -// xxx : update documentation +// zzz : update documentation // write: instead of writing long version with ContainerSubformer it's possible to be more concise with help of the type alias // pub type HashSetSubformer< K, Context, Formed, End > = diff --git a/module/core/former/tests/inc/former_tests/only_test/with_field_under_feature.rs b/module/core/former/tests/inc/former_tests/attribute_feature.rs similarity index 94% rename from module/core/former/tests/inc/former_tests/only_test/with_field_under_feature.rs rename to module/core/former/tests/inc/former_tests/attribute_feature.rs index 2623f7579b..39640fa86f 100644 --- a/module/core/former/tests/inc/former_tests/only_test/with_field_under_feature.rs +++ b/module/core/former/tests/inc/former_tests/attribute_feature.rs @@ -1,4 +1,5 @@ // xxx : need to fix + // #[ derive( Former ) ] // struct Foo // { diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index 1edc6bb0cc..beaaee388d 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -42,7 +42,7 @@ fn definitions() fn begin_and_custom_end() { - // xxx : make example with that + // zzz : make example with that // basic case @@ -94,7 +94,7 @@ fn begin_and_custom_end() fn custom_definition() { - // xxx : make example of that + // zzz : make example of that struct Return13; impl former::FormerDefinitionTypes for Return13 @@ -152,7 +152,7 @@ fn custom_definition() fn custom_definition_parametrized() { - // xxx : make example of that + // zzz : make example of that struct Return13< E >( ::core::marker::PhantomData< E > ); diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index 44f5f0b1aa..45bc6cb028 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -34,7 +34,6 @@ tests_impls! // -// xxx : uncomment fn custom_definition_params() { diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 0aadf0c81a..d8099a8525 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -183,7 +183,6 @@ impl< K, > former :: StoragePreform for CommandFormerStorage< K, > where K : cor } } - // xxx pub struct CommandFormer< K, Definition = CommandFormerDefinition< K, (), Command< K, >, former::ReturnPreformed >, > where K : core::hash::Hash + std::cmp::Eq, @@ -290,7 +289,7 @@ where } } -// xxx +// impl< K, Definition, > CommandFormer< K, Definition, > where diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 0d7637632b..0728a3df87 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -106,40 +106,6 @@ where pub commands : collection_tools::HashMap< String, Command< K > >, } -// xxx : remove -// pub type CommandSubformerWithClosure< K, Superformer > = CommandFormer -// < -// K, -// CommandFormerDefinition -// < -// K, -// Superformer, -// Superformer, -// former::FormingEndClosure< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, -// >, -// >; -// -// pub trait CommandSubformerEnd< K, SuperFormer > -// where -// K : core::hash::Hash + std::cmp::Eq, -// Self : the_module::FormingEnd -// < -// CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, -// > -// { -// } -// -// impl< K, SuperFormer, T > CommandSubformerEnd< K, SuperFormer > -// for T -// where -// K : core::hash::Hash + std::cmp::Eq, -// Self : the_module::FormingEnd -// < -// CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, -// > -// { -// } - // == include!( "./only_test/subformer_basic.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs index 3426a4a042..6fc085ecac 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs @@ -102,7 +102,6 @@ where // -/// xxx : extend description /// get container for a field out of a storage pub trait FormerStorageExtractContainer< Target > { @@ -131,7 +130,6 @@ where // -/// xxx : extend description /// extract storage from a former pub trait FormerExtractStorage { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index c813d82bf7..4182358976 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -31,6 +31,7 @@ mod former_tests mod attribute_perform; mod attribute_setter; mod attribute_alias; + // mod attribute_feature; // xxx : write test mod string_slice_manual; mod string_slice; From 727e5c15ec4804ebab1397df1f440e6da6c00ab9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 23:55:56 +0300 Subject: [PATCH 243/533] former : evolve --- .../inc/former_tests/subformer_shortcut.rs | 1 - module/core/macro_tools/src/generic_params.rs | 19 ------------------- .../macro_tools/tests/inc/generic_params.rs | 18 ------------------ 3 files changed, 38 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 16a87e16a6..dd22bdf686 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -105,7 +105,6 @@ where } -// xxx : uncomment #[ test ] fn basic() { diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index 3eec786c34..380e82e3ed 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -191,25 +191,6 @@ pub( crate ) mod private result } -// // add embedded generic parameters -// let mut extra_generics : syn::Generics = parse_quote! -// { -// < Definition = #former_definition < #generics_for_ty (), #struct_name, former::ReturnPreformed > > -// // Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, -// // xxx -// }; -// -// extra_generics.where_clause = parse_quote! -// { -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage #generics_for_ty >, -// // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, -// }; -// -// // zzz : write helper to fix bug with where -// let generics_of_former = generic_params::merge( &generics, &extra_generics ); - /// Extracts parameter names from the given `Generics`, /// dropping bounds, defaults, and the where clause. /// diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index 1988663f27..d0bb3b0dbe 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -352,21 +352,3 @@ fn decompose_mixed_generics_types() } } - -// xxx -// #[ test ] -// fn decompose_bug_a() -// { -// use macro_tools::quote::ToTokens; -// let generics : the_module::GenericsWithWhere = syn::parse_quote! { < K : core::hash::Hash + std::cmp::Eq > }; -// let generics = generics.unwrap(); -// let ( impl_with_def, impl_gen, ty_gen, where_gen ) = the_module::generic_params::decompose( &generics ); -// -// let impl_with_def_exp : syn::Generics = syn::parse_quote! { < K : core::hash::Hash + std::cmp::Eq, > }; -// let impl_gen_exp : syn::Generics = syn::parse_quote! { < K, > }; -// let ty_gen_exp : syn::Generics = syn::parse_quote! { < K, > }; -// a_id!( impl_with_def, impl_with_def_exp.params ); -// a_id!( impl_gen, impl_gen_exp.params ); -// a_id!( ty_gen_exp, ty_gen.params ); -// -// } From a4aedb0fa6e0bdb26ae9c42c62224cb2b0ad9b04 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 20 Apr 2024 23:57:36 +0300 Subject: [PATCH 244/533] former : evolve --- module/core/former_meta/src/derive/former.rs | 82 ++++++++++---------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 97822f7e1f..841a46f884 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -521,7 +521,7 @@ fn field_name_map( field : &FormerField< '_ > ) -> syn::Ident /// ``` #[ inline ] -fn field_setter_map( field : &FormerField< '_ >, struct_name : &syn::Ident ) -> Result< TokenStream > +fn field_setter_map( field : &FormerField< '_ >, stru : &syn::Ident ) -> Result< TokenStream > { let ident = &field.ident; @@ -538,7 +538,7 @@ fn field_setter_map( field : &FormerField< '_ >, struct_name : &syn::Ident ) -> let setter_tokens = if let Some( _subformer_ty ) = &field.attrs.subformer { // subformer_field_setter( ident, ident, non_optional_ty, &subformer_ty.expr ) - subformer_field_setter( field, struct_name ) + subformer_field_setter( field, stru ) } else { @@ -643,7 +643,7 @@ fn field_setter fn subformer_field_setter ( field : &FormerField< '_ >, - struct_name : &syn::Ident, + stru : &syn::Ident, // field_ident : &syn::Ident, // setter_name : &syn::Ident, // non_optional_type : &syn::Type, @@ -664,7 +664,7 @@ fn subformer_field_setter use convert_case::{ Case, Casing }; // let ident = field_ident; - let field_forming_end_name = format!( "{}Former{}End", struct_name, field_ident.to_string().to_case( Case::Pascal ) ); + let field_forming_end_name = format!( "{}Former{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let field_forming_end = syn::Ident::new( &field_forming_end_name, field_ident.span() ); let field_set_name = format!( "{}_set", field_ident ); let field_set = syn::Ident::new( &field_set_name, field_ident.span() ); @@ -849,7 +849,7 @@ fn subformer_field_setter fn fields_setter_callback_descriptor_map ( field : &FormerField< '_ >, - struct_name : &syn::Ident, + stru : &syn::Ident, former : &syn::Ident, former_storage : &syn::Ident, former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, @@ -871,7 +871,7 @@ Result< TokenStream > use convert_case::{ Case, Casing }; let ident = field.ident; - let field_forming_end_name = format!( "{}Former{}End", struct_name, field.ident.to_string().to_case( Case::Pascal ) ); + let field_forming_end_name = format!( "{}Former{}End", stru, field.ident.to_string().to_case( Case::Pascal ) ); let field_forming_end = syn::Ident::new( &field_forming_end_name, ident.span() ); let field_ty = field.non_optional_ty; @@ -931,14 +931,14 @@ Result< TokenStream > /// Generate documentation for the former. /// -fn doc_generate( struct_name : &syn::Ident ) -> ( String, String ) +fn doc_generate( stru : &syn::Ident ) -> ( String, String ) { let doc_former_mod = format! ( r#" Implementation of former for [{}]. "#, - struct_name + stru ); let doc_example1 = @@ -961,7 +961,7 @@ For specifying custom default value use attribute `default`. For example: {} ``` "#, - struct_name, doc_example1 + stru, doc_example1 ); ( doc_former_mod, doc_former_struct ) @@ -999,7 +999,7 @@ pub fn performer< 'a > { return result; }; - // let mut perform_output = qt!{ #struct_name #generics_ty_ }; + // let mut perform_output = qt!{ #stru #generics_ty_ }; let mut perform_output = qt!{ < Definition::Types as former::FormerDefinitionTypes >::Formed }; let mut perform_generics = qt!{}; @@ -1067,21 +1067,21 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /* names */ - let struct_name = &ast.ident; - let former_name = format!( "{}Former", struct_name ); - let former = syn::Ident::new( &former_name, struct_name.span() ); - let former_storage_name = format!( "{}FormerStorage", struct_name ); - let former_storage = syn::Ident::new( &former_storage_name, struct_name.span() ); - let former_definition_name = format!( "{}FormerDefinition", struct_name ); - let former_definition = syn::Ident::new( &former_definition_name, struct_name.span() ); - let former_definition_types_name = format!( "{}FormerDefinitionTypes", struct_name ); - let former_definition_types = syn::Ident::new( &former_definition_types_name, struct_name.span() ); - let former_with_closure_name = format!( "{}FormerWithClosure", struct_name ); - let former_with_closure = syn::Ident::new( &former_with_closure_name, struct_name.span() ); // xxx : maybe remove - let subformer_name = format!( "{}Subformer", struct_name ); - let subformer = syn::Ident::new( &subformer_name, struct_name.span() ); - let subformer_end_name = format!( "{}SubformerEnd", struct_name ); - let subformer_end = syn::Ident::new( &subformer_end_name, struct_name.span() ); + let stru = &ast.ident; + let former_name = format!( "{}Former", stru ); + let former = syn::Ident::new( &former_name, stru.span() ); + let former_storage_name = format!( "{}FormerStorage", stru ); + let former_storage = syn::Ident::new( &former_storage_name, stru.span() ); + let former_definition_name = format!( "{}FormerDefinition", stru ); + let former_definition = syn::Ident::new( &former_definition_name, stru.span() ); + let former_definition_types_name = format!( "{}FormerDefinitionTypes", stru ); + let former_definition_types = syn::Ident::new( &former_definition_types_name, stru.span() ); + let former_with_closure_name = format!( "{}FormerWithClosure", stru ); + let former_with_closure = syn::Ident::new( &former_with_closure_name, stru.span() ); // xxx : maybe remove + let subformer_name = format!( "{}Subformer", stru ); + let subformer = syn::Ident::new( &subformer_name, stru.span() ); + let subformer_end_name = format!( "{}SubformerEnd", stru ); + let subformer_end = syn::Ident::new( &subformer_end_name, stru.span() ); /* parameters for structure */ @@ -1093,7 +1093,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let extra : macro_tools::syn::AngleBracketedGenericArguments = parse_quote! { - < (), #struct_name < #struct_generics_ty >, former::ReturnPreformed > + < (), #stru < #struct_generics_ty >, former::ReturnPreformed > }; let former_definition_args = generic_args::merge( &generics.into_generic_args(), &extra.into() ).args; @@ -1121,7 +1121,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > Definition::Types : former::FormerDefinitionTypes < Storage = #former_storage < #struct_generics_ty >, - Formed = #struct_name < #struct_generics_ty > + Formed = #stru < #struct_generics_ty > >, }; let extra = generic_params::merge( &generics, &extra.into() ); @@ -1129,15 +1129,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( _former_perform_generics_with_defaults, former_perform_generics_impl, former_perform_generics_ty, former_perform_generics_where ) = generic_params::decompose( &extra ); -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<>, Formed = Struct1 >, - /* parameters for definition types */ let extra : macro_tools::GenericsWithWhere = parse_quote! { - < __Context = (), __Formed = #struct_name < #struct_generics_ty > > + < __Context = (), __Formed = #stru < #struct_generics_ty > > }; let former_definition_type_generics = generic_params::merge( &generics, &extra.into() ); let ( former_definition_type_generics_with_defaults, former_definition_type_generics_impl, former_definition_type_generics_ty, former_definition_type_generics_where ) @@ -1149,7 +1145,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let extra : macro_tools::GenericsWithWhere = parse_quote! { - < __Context = (), __Formed = #struct_name < #struct_generics_ty >, __End = former::ReturnPreformed > + < __Context = (), __Formed = #stru < #struct_generics_ty >, __End = former::ReturnPreformed > }; let generics_of_definition = generic_params::merge( &generics, &extra.into() ); let ( former_definition_generics_with_defaults, former_definition_generics_impl, former_definition_generics_ty, former_definition_generics_where ) @@ -1161,7 +1157,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( perform, perform_output, perform_generics ) = performer ( - &struct_name, + &stru, // &former_definition, // &struct_generics_ty, ast.attrs.iter(), @@ -1216,11 +1212,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field_optional_map( former_field ), field_form_map( former_field ), field_name_map( former_field ), - field_setter_map( former_field, &struct_name ), + field_setter_map( former_field, &stru ), fields_setter_callback_descriptor_map ( former_field, - &struct_name, + &stru, &former, &former_storage, &former_generics_impl, @@ -1230,7 +1226,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > ), )}).multiunzip(); - let ( _doc_former_mod, doc_former_struct ) = doc_generate( struct_name ); + let ( _doc_former_mod, doc_former_struct ) = doc_generate( stru ); let fields_setter : Vec< _ > = process_results( fields_setter, | iter | iter.collect() )?; let fields_form : Vec< _ > = process_results( fields_form, | iter | iter.collect() )?; let fields_setter_callback_descriptor : Vec< _ > = process_results( fields_setter_callback_descriptor, | iter | iter.collect() )?; @@ -1241,7 +1237,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = formed #[ automatically_derived ] - impl < #struct_generics_impl > #struct_name < #struct_generics_ty > + impl < #struct_generics_impl > #stru < #struct_generics_ty > where #struct_generics_where { @@ -1372,7 +1368,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where #struct_generics_where { - type Formed = #struct_name < #struct_generics_ty >; + type Formed = #stru < #struct_generics_ty >; } impl < #struct_generics_impl > former::StoragePreform @@ -1380,7 +1376,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where #struct_generics_where { - type Preformed = #struct_name < #struct_generics_ty >; + type Preformed = #stru < #struct_generics_ty >; // fn preform( mut self ) -> < Self as former::Storage >::Formed fn preform( mut self ) -> Self::Preformed @@ -1388,7 +1384,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #( #fields_form )* // Rust does not support that, yet // let result = < Definition::Types as former::FormerDefinitionTypes >::Formed - let result = #struct_name :: < #struct_generics_ty > + let result = #stru :: < #struct_generics_ty > { #( #fields_names, )* }; @@ -1545,9 +1541,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl< #former_generics_impl > #former< #former_generics_ty > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #struct_generics_ty >, Formed = #struct_name < #struct_generics_ty > >, + Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #struct_generics_ty >, Formed = #stru < #struct_generics_ty > >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = #struct_name < #struct_generics_ty > >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = #stru < #struct_generics_ty > >, #former_generics_where { From eab438d676adcab7b7f9dcae821fa467e0fe787c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 21 Apr 2024 00:09:23 +0300 Subject: [PATCH 245/533] former : evolve --- module/core/former/tests/inc/former_tests/a_basic_manual.rs | 3 ++- .../inc/former_tests/a_containers_with_subformer_manual.rs | 5 ----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 176bdf13a5..2281095f2e 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -201,7 +201,8 @@ where mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : IntoEnd, - ) -> Self + ) + -> Self where IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, { diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 25301f6972..69f3b0c0af 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -294,9 +294,6 @@ where } } - - - #[ inline( always ) ] pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { @@ -304,8 +301,6 @@ where } - - #[ inline( always ) ] pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { From bc4b2e505352c22db906190572844956843f5e76 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 21 Apr 2024 00:29:40 +0300 Subject: [PATCH 246/533] former : evolve --- .../inc/former_tests/subformer_shortcut.rs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index dd22bdf686..d3bc578378 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -90,7 +90,8 @@ where < Self, Self, - former::FormingEndClosure< TemplateParameterDescriptorFormerDefinitionTypes< Self, Self > > + impl TemplateParameterDescriptorSubformerEnd< Self >, + // former::FormingEndClosure< TemplateParameterDescriptorFormerDefinitionTypes< Self, Self > >, > > { @@ -103,6 +104,28 @@ where .name( name ) } + // pub fn descriptor2( self, name : &str ) -> + // TemplateParameterDescriptorFormer + // < + // TemplateParameterDescriptorFormerDefinition + // < + // Self, + // Self, + // impl TemplateParameterDescriptorSubformerEnd< K, Self > + // // former::FormingEndClosure< TemplateParameterDescriptorFormerDefinitionTypes< Self, Self > >, + // > + // > + // // former::ContainerSubformer:: + // // < + // // String, former::VectorDefinition< String, Self, Self, Struct1FormerVec1End > + // // > + // { + // self.descriptors_set::< former::ContainerSubformer:: + // < + // String, former::VectorDefinition< String, Self, Self, TemplateParametersFormerDescriptorsEnd > + // >>() + // } + } #[ test ] From 182f119da2295487d001367f19f2c7e01fc67dfe Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 00:37:38 +0300 Subject: [PATCH 247/533] former : experimenting --- .../a_containers_with_subformer.rs | 3 -- .../inc/former_tests/subformer_custom.rs | 6 +-- .../inc/former_tests/subformer_shortcut.rs | 45 +++++-------------- 3 files changed, 14 insertions(+), 40 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 0720ed37de..3f8f3c705e 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -17,9 +17,6 @@ pub struct Struct1 hashset_1 : std::collections::HashSet< String >, } -// = generated - - // = generated include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_custom.rs b/module/core/former/tests/inc/former_tests/subformer_custom.rs index 6e066f7baf..f4039b82dd 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom.rs @@ -77,6 +77,7 @@ where { // + #[ inline( always ) ] pub fn command_with_closure< IntoName >( self, name : IntoName ) -> @@ -110,6 +111,7 @@ where } // + #[ inline( always ) ] pub fn command_with_type< IntoName >( self, name : IntoName ) -> @@ -152,22 +154,18 @@ where -> AggregatorFormer< K, Definition > { - let preformed = former::StoragePreform::preform( sub_storage ); let mut super_former = super_former.unwrap(); if let Some( ref mut container ) = super_former.storage.commands { - // former::ContainerAdd::add( container, ( preformed.name.clone(), preformed ) ); former::ContainerAdd::add( container, Into::into( preformed ) ); } else { let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); - // former::ContainerAdd::add( &mut container, ( preformed.name.clone(), preformed ) ); former::ContainerAdd::add( &mut container, Into::into( preformed ) ); super_former.storage.commands = Some( container ); } - super_former } } diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index d3bc578378..40e3ca8691 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -55,8 +55,8 @@ where Formed = Self, Context = Self, >, - Definition2 : former::FormerDefinition< End = former::FormingEndClosure< Types2 >, Types = Types2 >, - Definition2 : former::FormerDefinition, + Definition2 : former::FormerDefinition< Types = Types2, End = former::FormingEndClosure< Types2 > >, + // Definition2 : former::FormerDefinition< Types = Types2 >, Definition2::End : former::FormingEnd< Definition2::Types >, Former2 : former::FormerBegin < @@ -78,52 +78,31 @@ where super_former }; Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + // Former2::_begin( None, Some( self ), on_end ) } // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help - #[ inline( always ) ] - pub fn descriptor( self, name : &str ) -> - TemplateParameterDescriptorFormer - < - TemplateParameterDescriptorFormerDefinition - < - Self, - Self, - impl TemplateParameterDescriptorSubformerEnd< Self >, - // former::FormingEndClosure< TemplateParameterDescriptorFormerDefinitionTypes< Self, Self > >, - > - > - { - self.descriptor3:: - < - TemplateParameterDescriptorFormer< _ >, - _, - _, - >() - .name( name ) - } - - // pub fn descriptor2( self, name : &str ) -> + // #[ inline( always ) ] + // pub fn descriptor( self, name : &str ) -> // TemplateParameterDescriptorFormer // < // TemplateParameterDescriptorFormerDefinition // < // Self, // Self, - // impl TemplateParameterDescriptorSubformerEnd< K, Self > + // impl TemplateParameterDescriptorSubformerEnd< Self >, // // former::FormingEndClosure< TemplateParameterDescriptorFormerDefinitionTypes< Self, Self > >, // > // > - // // former::ContainerSubformer:: - // // < - // // String, former::VectorDefinition< String, Self, Self, Struct1FormerVec1End > - // // > // { - // self.descriptors_set::< former::ContainerSubformer:: + // self.descriptor3:: // < - // String, former::VectorDefinition< String, Self, Self, TemplateParametersFormerDescriptorsEnd > - // >>() + // TemplateParameterDescriptorFormer< _ >, + // _, + // _, + // >() + // .name( name ) // } } From 52e69634b904d4285dc872e4ae1c38ab4cacbd73 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 00:38:48 +0300 Subject: [PATCH 248/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 40e3ca8691..84427be4d6 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -63,7 +63,6 @@ where Definition2, >, { - let on_end = | descriptor : TemplateParameterDescriptorFormerStorage, super_former : core::option::Option< Self > | -> Self { let mut super_former = super_former.unwrap(); @@ -83,27 +82,27 @@ where // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help - // #[ inline( always ) ] - // pub fn descriptor( self, name : &str ) -> - // TemplateParameterDescriptorFormer - // < - // TemplateParameterDescriptorFormerDefinition - // < - // Self, - // Self, - // impl TemplateParameterDescriptorSubformerEnd< Self >, - // // former::FormingEndClosure< TemplateParameterDescriptorFormerDefinitionTypes< Self, Self > >, - // > - // > - // { - // self.descriptor3:: - // < - // TemplateParameterDescriptorFormer< _ >, - // _, - // _, - // >() - // .name( name ) - // } + #[ inline( always ) ] + pub fn descriptor( self, name : &str ) -> + TemplateParameterDescriptorFormer + < + TemplateParameterDescriptorFormerDefinition + < + Self, + Self, + impl TemplateParameterDescriptorSubformerEnd< Self >, + // former::FormingEndClosure< TemplateParameterDescriptorFormerDefinitionTypes< Self, Self > >, + > + > + { + self.descriptor3:: + < + TemplateParameterDescriptorFormer< _ >, + _, + _, + >() + .name( name ) + } } From 5a5a615f220cae60015210ad55c5efb082f19e83 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 09:54:24 +0300 Subject: [PATCH 249/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 125 +++++++++++++++--- 1 file changed, 103 insertions(+), 22 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 84427be4d6..185cfe0f00 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -45,6 +45,30 @@ where Definition::Types : former::FormerDefinitionTypes< Storage = TemplateParametersFormerStorage >, { + // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help + + #[ inline( always ) ] + pub fn descriptor( self, name : &str ) -> + TemplateParameterDescriptorFormer + < + TemplateParameterDescriptorFormerDefinition + < + Self, + Self, + impl TemplateParameterDescriptorSubformerEnd< Self >, + // former::FormingEndClosure< TemplateParameterDescriptorFormerDefinitionTypes< Self, Self > >, + > + > + { + self.descriptor3:: + < + TemplateParameterDescriptorFormer< _ >, + _, + _, + >() + .name( name ) + } + #[ inline( always ) ] pub fn descriptor3< Former2, Definition2, Types2 >( self ) -> Former2 @@ -63,7 +87,7 @@ where Definition2, >, { - let on_end = | descriptor : TemplateParameterDescriptorFormerStorage, super_former : core::option::Option< Self > | -> Self + let on_end = | substorage : TemplateParameterDescriptorFormerStorage, super_former : core::option::Option< Self > | -> Self { let mut super_former = super_former.unwrap(); if super_former.storage.descriptors.is_none() @@ -72,7 +96,7 @@ where } if let Some( ref mut descriptors ) = super_former.storage.descriptors { - former::ContainerAdd::add( descriptors, former::StoragePreform::preform( descriptor ) ); + former::ContainerAdd::add( descriptors, former::StoragePreform::preform( substorage ) ); } super_former }; @@ -80,32 +104,89 @@ where // Former2::_begin( None, Some( self ), on_end ) } - // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help +} +/// Handles the completion of the subformer for `TemplateParameterDescriptor`. +pub struct TemplateParameterDescriptorEnd< Definition, Former2, Definition2, Types2 > +{ + _phantom : core::marker::PhantomData< fn( Definition, Former2, Definition2, Types2 ) >, +} + +impl< Definition, Former2, Definition2, Types2 > Default +for TemplateParameterDescriptorEnd< Definition, Former2, Definition2, Types2 > +{ #[ inline( always ) ] - pub fn descriptor( self, name : &str ) -> - TemplateParameterDescriptorFormer - < - TemplateParameterDescriptorFormerDefinition - < - Self, - Self, - impl TemplateParameterDescriptorSubformerEnd< Self >, - // former::FormingEndClosure< TemplateParameterDescriptorFormerDefinitionTypes< Self, Self > >, - > - > + fn default() -> Self { - self.descriptor3:: - < - TemplateParameterDescriptorFormer< _ >, - _, - _, - >() - .name( name ) + Self + { + _phantom : core::marker::PhantomData, + } } - } +// impl< Definition, Former2, Definition2, Types2 > former::FormingEnd +// < +// Types2, +// > +// for TemplateParameterDescriptorEnd< Definition, Former2, Definition2, Types2 > +// where +// +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes +// < +// Storage = TemplateParametersFormerStorage +// >, +// +// // Self : former::FormerDefinition, +// // Self::Types : former::FormerDefinitionTypes< Storage = TemplateParametersFormerStorage, > +// Types2 : former::FormerDefinitionTypes +// < +// Storage = TemplateParameterDescriptorFormerStorage, +// Formed = Self, +// Context = Self, +// >, +// Definition2 : former::FormerDefinition< Types = Types2, End = former::FormingEndClosure< Types2 > >, +// // Definition2 : former::FormerDefinition< Types = Types2 >, +// Definition2::End : former::FormingEnd< Definition2::Types >, +// Former2 : former::FormerBegin +// < +// Definition2, +// >, +// +// { +// #[ inline( always ) ] +// fn call +// ( +// &self, +// substorage : TemplateParameterDescriptorFormerStorage, +// super_former : core::option::Option< Self >, +// // descriptor : TemplateParameterDescriptorFormerStorage, +// // super_former : Option< TemplateParametersFormer< Self > >, +// ) +// -> TemplateParametersFormer< Definition > +// { +// let mut super_former = super_former.unwrap(); +// if super_former.storage.descriptors.is_none() +// { +// super_former.storage.descriptors = Some( Default::default() ); +// } +// if let Some( ref mut descriptors ) = super_former.storage.descriptors +// { +// former::ContainerAdd::add( descriptors, former::StoragePreform::preform( substorage ) ); +// } +// super_former +// // let mut super_former = super_former.unwrap(); +// // if super_former.storage.descriptors.is_none() +// // { +// // super_former.storage.descriptors = Some( Vec::new() ); +// // } +// // let preformed_descriptor = former::StoragePreform::preform( substorage ); +// // super_former.storage.descriptors.as_mut().unwrap().push( preformed_descriptor ); +// // super_former +// } +// } + #[ test ] fn basic() { From 08d5e206065e7a89e656f75919f839e4edf1d8b0 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 09:56:18 +0300 Subject: [PATCH 250/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 122 +++++++++--------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 185cfe0f00..df03bc4998 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -125,67 +125,67 @@ for TemplateParameterDescriptorEnd< Definition, Former2, Definition2, Types2 > } } -// impl< Definition, Former2, Definition2, Types2 > former::FormingEnd -// < -// Types2, -// > -// for TemplateParameterDescriptorEnd< Definition, Former2, Definition2, Types2 > -// where -// -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes -// < -// Storage = TemplateParametersFormerStorage -// >, -// -// // Self : former::FormerDefinition, -// // Self::Types : former::FormerDefinitionTypes< Storage = TemplateParametersFormerStorage, > -// Types2 : former::FormerDefinitionTypes -// < -// Storage = TemplateParameterDescriptorFormerStorage, -// Formed = Self, -// Context = Self, -// >, -// Definition2 : former::FormerDefinition< Types = Types2, End = former::FormingEndClosure< Types2 > >, -// // Definition2 : former::FormerDefinition< Types = Types2 >, -// Definition2::End : former::FormingEnd< Definition2::Types >, -// Former2 : former::FormerBegin -// < -// Definition2, -// >, -// -// { -// #[ inline( always ) ] -// fn call -// ( -// &self, -// substorage : TemplateParameterDescriptorFormerStorage, -// super_former : core::option::Option< Self >, -// // descriptor : TemplateParameterDescriptorFormerStorage, -// // super_former : Option< TemplateParametersFormer< Self > >, -// ) -// -> TemplateParametersFormer< Definition > -// { -// let mut super_former = super_former.unwrap(); -// if super_former.storage.descriptors.is_none() -// { -// super_former.storage.descriptors = Some( Default::default() ); -// } -// if let Some( ref mut descriptors ) = super_former.storage.descriptors -// { -// former::ContainerAdd::add( descriptors, former::StoragePreform::preform( substorage ) ); -// } -// super_former -// // let mut super_former = super_former.unwrap(); -// // if super_former.storage.descriptors.is_none() -// // { -// // super_former.storage.descriptors = Some( Vec::new() ); -// // } -// // let preformed_descriptor = former::StoragePreform::preform( substorage ); -// // super_former.storage.descriptors.as_mut().unwrap().push( preformed_descriptor ); -// // super_former -// } -// } +impl< Definition, Former2, Definition2, Types2 > former::FormingEnd +< + Types2, +> +for TemplateParameterDescriptorEnd< Definition, Former2, Definition2, Types2 > +where + + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = TemplateParametersFormerStorage + >, + + // Self : former::FormerDefinition, + // Self::Types : former::FormerDefinitionTypes< Storage = TemplateParametersFormerStorage, > + Types2 : former::FormerDefinitionTypes + < + Storage = TemplateParameterDescriptorFormerStorage, + Formed = TemplateParametersFormer< Definition >, + Context = TemplateParametersFormer< Definition >, + >, + Definition2 : former::FormerDefinition< Types = Types2, End = former::FormingEndClosure< Types2 > >, + // Definition2 : former::FormerDefinition< Types = Types2 >, + Definition2::End : former::FormingEnd< Definition2::Types >, + Former2 : former::FormerBegin + < + Definition2, + >, + +{ + #[ inline( always ) ] + fn call + ( + &self, + substorage : TemplateParameterDescriptorFormerStorage, + super_former : core::option::Option< TemplateParametersFormer< Definition > >, + // descriptor : TemplateParameterDescriptorFormerStorage, + // super_former : Option< TemplateParametersFormer< Self > >, + ) + -> TemplateParametersFormer< Definition > + { + let mut super_former = super_former.unwrap(); + if super_former.storage.descriptors.is_none() + { + super_former.storage.descriptors = Some( Default::default() ); + } + if let Some( ref mut descriptors ) = super_former.storage.descriptors + { + former::ContainerAdd::add( descriptors, former::StoragePreform::preform( substorage ) ); + } + super_former + // let mut super_former = super_former.unwrap(); + // if super_former.storage.descriptors.is_none() + // { + // super_former.storage.descriptors = Some( Vec::new() ); + // } + // let preformed_descriptor = former::StoragePreform::preform( substorage ); + // super_former.storage.descriptors.as_mut().unwrap().push( preformed_descriptor ); + // super_former + } +} #[ test ] fn basic() From bc65b467b3999ad94d36d0dfe3bd799618c182f2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 10:06:32 +0300 Subject: [PATCH 251/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index df03bc4998..f0db5da546 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -125,10 +125,7 @@ for TemplateParameterDescriptorEnd< Definition, Former2, Definition2, Types2 > } } -impl< Definition, Former2, Definition2, Types2 > former::FormingEnd -< - Types2, -> +impl< Definition, Former2, Definition2, Types2 > former::FormingEnd< Types2, > for TemplateParameterDescriptorEnd< Definition, Former2, Definition2, Types2 > where @@ -138,21 +135,21 @@ where Storage = TemplateParametersFormerStorage >, - // Self : former::FormerDefinition, - // Self::Types : former::FormerDefinitionTypes< Storage = TemplateParametersFormerStorage, > + // // Self : former::FormerDefinition, + // // Self::Types : former::FormerDefinitionTypes< Storage = TemplateParametersFormerStorage, > Types2 : former::FormerDefinitionTypes < Storage = TemplateParameterDescriptorFormerStorage, Formed = TemplateParametersFormer< Definition >, Context = TemplateParametersFormer< Definition >, >, - Definition2 : former::FormerDefinition< Types = Types2, End = former::FormingEndClosure< Types2 > >, - // Definition2 : former::FormerDefinition< Types = Types2 >, - Definition2::End : former::FormingEnd< Definition2::Types >, - Former2 : former::FormerBegin - < - Definition2, - >, + // Definition2 : former::FormerDefinition< Types = Types2, End = former::FormingEndClosure< Types2 > >, + // // Definition2 : former::FormerDefinition< Types = Types2 >, + // Definition2::End : former::FormingEnd< Definition2::Types >, + // Former2 : former::FormerBegin + // < + // Definition2, + // >, { #[ inline( always ) ] From 02ca2734999d1d1f508ab7ccd3d39e9f1b1fe01e Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 11:01:51 +0300 Subject: [PATCH 252/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 59 ++++++++++++++++--- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index f0db5da546..030581644c 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -60,7 +60,7 @@ where > > { - self.descriptor3:: + self._descriptor_former:: < TemplateParameterDescriptorFormer< _ >, _, @@ -70,7 +70,7 @@ where } #[ inline( always ) ] - pub fn descriptor3< Former2, Definition2, Types2 >( self ) -> + pub fn _descriptor_former< Former2, Definition2, Types2 >( self ) -> Former2 where Types2 : former::FormerDefinitionTypes @@ -80,7 +80,6 @@ where Context = Self, >, Definition2 : former::FormerDefinition< Types = Types2, End = former::FormingEndClosure< Types2 > >, - // Definition2 : former::FormerDefinition< Types = Types2 >, Definition2::End : former::FormingEnd< Definition2::Types >, Former2 : former::FormerBegin < @@ -104,16 +103,36 @@ where // Former2::_begin( None, Some( self ), on_end ) } + #[ inline( always ) ] + pub fn _descriptor_former2< Former2, Definition2, Types2 >( self ) -> + Former2 + where + Types2 : former::FormerDefinitionTypes + < + Storage = TemplateParameterDescriptorFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParameterDescriptorEnd< Definition, Types2 > >, + Definition2::End : former::FormingEnd< Definition2::Types >, + Former2 : former::FormerBegin + < + Definition2, + >, + { + Former2::_begin( None, Some( self ), TemplateParameterDescriptorEnd::< Definition, Types2 >::default() ) + } + } /// Handles the completion of the subformer for `TemplateParameterDescriptor`. -pub struct TemplateParameterDescriptorEnd< Definition, Former2, Definition2, Types2 > +pub struct TemplateParameterDescriptorEnd< Definition, Types2 > { - _phantom : core::marker::PhantomData< fn( Definition, Former2, Definition2, Types2 ) >, + _phantom : core::marker::PhantomData< fn( Definition, Types2 ) >, } -impl< Definition, Former2, Definition2, Types2 > Default -for TemplateParameterDescriptorEnd< Definition, Former2, Definition2, Types2 > +impl< Definition, Types2 > Default +for TemplateParameterDescriptorEnd< Definition, Types2 > { #[ inline( always ) ] fn default() -> Self @@ -125,8 +144,8 @@ for TemplateParameterDescriptorEnd< Definition, Former2, Definition2, Types2 > } } -impl< Definition, Former2, Definition2, Types2 > former::FormingEnd< Types2, > -for TemplateParameterDescriptorEnd< Definition, Former2, Definition2, Types2 > +impl< Definition, Types2 > former::FormingEnd< Types2, > +for TemplateParameterDescriptorEnd< Definition, Types2 > where Definition : former::FormerDefinition, @@ -204,3 +223,25 @@ fn basic() a_id!( got, exp ); } + +#[ test ] +fn descriptor() +{ + + let got = TemplateParameters::former() + .descriptor( "a" ).end() + .descriptor( "b" ).end() + // .add( TemplateParameterDescriptor::former().name( "a" ).form() ) + // .add( TemplateParameterDescriptor::former().name( "b" ).form() ) + // .end() + .form(); + + let descriptors = vec! + [ + TemplateParameterDescriptor { name : "a".to_string(), is_mandatory : false }, + TemplateParameterDescriptor { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = TemplateParameters { descriptors }; + a_id!( got, exp ); + +} From 76fd8517f9900f640a3a05a1d81a325d9ffb7de2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 13:56:56 +0300 Subject: [PATCH 253/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 8 +- .../a_containers_with_subformer.rs | 6 +- .../a_containers_with_subformer_manual.rs | 328 ++++++++---------- .../inc/former_tests/a_primitives_manual.rs | 12 +- .../tests/inc/former_tests/only_test/basic.rs | 76 ++-- .../only_test/containers_with_subformer.rs | 45 ++- .../inc/former_tests/only_test/primitives.rs | 4 +- .../former_tests/only_test/string_slice.rs | 13 +- .../parametrized_struct_manual.rs | 7 +- .../inc/former_tests/string_slice_manual.rs | 8 +- .../inc/former_tests/subformer_custom.rs | 4 +- .../subformer_custom_experimental.rs | 2 +- .../inc/former_tests/subformer_shortcut.rs | 2 +- module/core/former_meta/src/derive/former.rs | 69 ++-- 14 files changed, 304 insertions(+), 280 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 2281095f2e..dcec2edb6d 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -72,8 +72,8 @@ where End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > type End = End; } -pub type Struct1FormerWithClosure< Context, Formed > = - Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; +// pub type Struct1FormerWithClosure< Context, Formed > = +// Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; // = storage @@ -162,7 +162,7 @@ where } #[ inline( always ) ] - pub fn _new_precise( on_end : Definition::End ) -> Self + pub fn new_precise( on_end : Definition::End ) -> Self { Self::begin_coercing( None, None, on_end ) } @@ -175,7 +175,7 @@ where } #[ inline( always ) ] - pub fn _begin_precise + pub fn begin_precise ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 3f8f3c705e..7dfec039e6 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -5,7 +5,7 @@ use super::*; // use std::collections::HashSet; #[ derive( Default, Debug, PartialEq, former::Former ) ] -// #[ debug ] +// #[ derive( Default, Debug, PartialEq, former::Former ) ] #[ debug ] // #[ derive( Default, Debug, PartialEq ) ] pub struct Struct1 { @@ -17,6 +17,8 @@ pub struct Struct1 hashset_1 : std::collections::HashSet< String >, } -// = generated +// == generated begin + +// == generated end include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 69f3b0c0af..c468742a0a 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -9,27 +9,30 @@ pub struct Struct1 hashset_1 : std::collections::HashSet< String >, } -// = generated +// == begin of generated #[ automatically_derived ] -impl Struct1 +impl< > Struct1< > +where { #[ inline( always ) ] - pub fn former() -> Struct1Former< > + pub fn former() -> Struct1Former< Struct1FormerDefinition< (), Struct1< >, former::ReturnPreformed > > { - Struct1Former::<>::new_coercing( the_module::ReturnPreformed ) + Struct1Former::< Struct1FormerDefinition< (), Struct1< >, former::ReturnPreformed > >::new_coercing( former::ReturnPreformed ) } } -// = definition types +// = types #[ derive( Debug ) ] -pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1 > +pub struct Struct1FormerDefinitionTypes< __Context = (), __Formed = Struct1< >, > +where { - _phantom : core::marker::PhantomData< ( Context, Formed ) >, + _phantom : core::marker::PhantomData< ( __Context, __Formed ) >, } -impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Formed > +impl< __Context, __Formed, > ::core::default::Default for Struct1FormerDefinitionTypes< __Context, __Formed, > +where { fn default() -> Self { @@ -40,23 +43,25 @@ impl< Context, Formed > Default for Struct1FormerDefinitionTypes< Context, Forme } } -impl< Context, Formed > former::FormerDefinitionTypes -for Struct1FormerDefinitionTypes< Context, Formed > +impl< __Context, __Formed, > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< __Context, __Formed, > +where { - type Storage = Struct1FormerStorage; - type Formed = Formed; - type Context = Context; + type Storage = Struct1FormerStorage< >; + type Formed = __Formed; + type Context = __Context; } // = definition #[ derive( Debug ) ] -pub struct Struct1FormerDefinition< Context = (), Formed = Struct1, End = former::ReturnPreformed > +pub struct Struct1FormerDefinition< __Context = (), __Formed = Struct1< >, __End = former::ReturnPreformed, > +where { - _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, + _phantom : core::marker::PhantomData< ( __Context, __Formed, __End ) >, } -impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Formed, End > +impl< __Context, __Formed, __End, > ::core::default::Default for Struct1FormerDefinition< __Context, __Formed, __End, > +where { fn default() -> Self { @@ -67,26 +72,29 @@ impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Forme } } -impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > +impl< __Context, __Formed, __End, > former::FormerDefinition for Struct1FormerDefinition< __Context, __Formed, __End, > where - End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, + __End : former::FormingEnd< Struct1FormerDefinitionTypes< __Context, __Formed, > >, { - type Types = Struct1FormerDefinitionTypes< Context, Formed >; - type End = End; + type Types = Struct1FormerDefinitionTypes< __Context, __Formed, >; + type End = __End; } -pub type Struct1FormerWithClosure< Context, Formed > = Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; - // = storage -pub struct Struct1FormerStorage +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 > >, } -impl ::core::default::Default for Struct1FormerStorage +impl< > ::core::default::Default for Struct1FormerStorage< > +where { #[ inline( always ) ] fn default() -> Self @@ -100,15 +108,17 @@ impl ::core::default::Default for Struct1FormerStorage } } -impl former::Storage for Struct1FormerStorage +impl< > former::Storage for Struct1FormerStorage< > +where { - type Formed = Struct1; + type Formed = Struct1< >; } -impl former::StoragePreform for Struct1FormerStorage +impl< > former::StoragePreform for Struct1FormerStorage< > +where { - type Preformed = Struct1; - // fn preform( mut self ) -> < Self as former::Storage >::Formed + type Preformed = Struct1< >; + fn preform( mut self ) -> Self::Preformed { let vec_1 = if self.vec_1.is_some() @@ -120,23 +130,29 @@ impl former::StoragePreform for Struct1FormerStorage { trait MaybeDefault< T > { - fn maybe_default( self : &Self ) -> T + fn maybe_default( self : & Self ) -> T { panic!( "Field 'vec_1' isn't initialized" ) } } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > + { + } + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > where T : ::core::default::Default, { - fn maybe_default( self : &Self ) -> T + fn maybe_default( self : & Self ) -> T { T::default() } } - ( &::core::marker::PhantomData::< Vec< String > > ).maybe_default() + + (&::core::marker::PhantomData::< Vec< String > >).maybe_default() } }; + let hashmap_1 = if self.hashmap_1.is_some() { self.hashmap_1.take().unwrap() @@ -146,23 +162,29 @@ impl former::StoragePreform for Struct1FormerStorage { trait MaybeDefault< T > { - fn maybe_default( self : &Self ) -> T + fn maybe_default( self : & Self ) -> T { panic!( "Field 'hashmap_1' isn't initialized" ) } } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > + { + } + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > where T : ::core::default::Default, { - fn maybe_default( self : &Self ) -> T + fn maybe_default( self : & Self ) -> T { T::default() } } - ( &::core::marker::PhantomData::< std::collections::HashMap< String, String > > ).maybe_default() + + (&::core::marker::PhantomData::< std::collections::HashMap< String, String > >).maybe_default() } }; + let hashset_1 = if self.hashset_1.is_some() { self.hashset_1.take().unwrap() @@ -172,40 +194,46 @@ impl former::StoragePreform for Struct1FormerStorage { trait MaybeDefault< T > { - fn maybe_default( self : &Self ) -> T + fn maybe_default( self : & Self ) -> T { panic!( "Field 'hashset_1' isn't initialized" ) } } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > + { + } + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > where T : ::core::default::Default, { - fn maybe_default( self : &Self ) -> T + fn maybe_default( self : & Self ) -> T { T::default() } } - ( &::core::marker::PhantomData::< std::collections::HashSet< String > > ).maybe_default() + + (&::core::marker::PhantomData::< std::collections::HashSet< String > >).maybe_default() } }; + let result = Struct1 { vec_1, hashmap_1, hashset_1, }; + return result; } } // = former -pub struct Struct1Former< Definition = Struct1FormerDefinition > +pub struct Struct1Former< Definition = Struct1FormerDefinition< (), Struct1< >, former::ReturnPreformed >, > where Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, { storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -213,46 +241,29 @@ where } #[ automatically_derived ] -impl< Definition > Struct1Former< Definition > +impl< Definition, > Struct1Former< Definition, > where Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, { - - #[ inline( always ) ] - pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - { - let result = self.form(); - return result; - } - - - - #[ inline( always ) ] - pub fn _new_precise( on_end : Definition::End ) -> Self + pub fn new_precise( on_end : Definition::End ) -> Self { Self::begin_coercing( None, None, on_end ) } - - - #[ inline( always ) ] pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End >, { - Self::begin_coercing( None, None, end, ) + Self::begin_coercing( None, None, end ) } - - - #[ inline( always ) ] - pub fn _begin_precise( + pub fn begin_precise + ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, @@ -270,9 +281,6 @@ where } } - - - #[ inline( always ) ] pub fn begin_coercing< IntoEnd >( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, @@ -300,7 +308,6 @@ where self.end() } - #[ inline( always ) ] pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { @@ -312,98 +319,57 @@ where #[ inline( always ) ] pub fn vec_1_set< Former2 >( self ) -> Former2 where - Former2 : former::FormerBegin - < - former::VectorDefinition - < - String, - Self, - Self, - Struct1FormerVec1End, - > - >, + Former2 : former::FormerBegin< former::VectorDefinition< String, Self, Self, Struct1FormerVec1End, > >, { Former2::_begin( None, Some( self ), Struct1FormerVec1End ) } - pub fn vec_1( self ) -> - former::ContainerSubformer:: - < - String, former::VectorDefinition< String, Self, Self, Struct1FormerVec1End > - > + #[ inline( always ) ] + pub fn vec_1( self ) -> former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1FormerVec1End > > { - self.vec_1_set::< former::ContainerSubformer:: - < - String, former::VectorDefinition< String, Self, Self, Struct1FormerVec1End > - >>() + self.vec_1_set::< former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1FormerVec1End > >>() } #[ inline( always ) ] pub fn hashmap_1_set< Former2 >( self ) -> Former2 where - Former2 : former::FormerBegin - < - former::HashMapDefinition - < - String, - String, - Self, - Self, - Struct1FormerHashmap1End, - > - >, + Former2 : former::FormerBegin< former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap1End, > >, { Former2::_begin( None, Some( self ), Struct1FormerHashmap1End ) } - pub fn hashmap_1( self ) -> - former::ContainerSubformer:: - < - ( String, String ), former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap1End > - > + + #[ inline( always ) ] + pub fn hashmap_1( self ) -> former::ContainerSubformer::< (String, String), former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap1End > > { - self.hashmap_1_set::< former::ContainerSubformer:: - < - ( String, String ), former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap1End > - > >() + self.hashmap_1_set::< former::ContainerSubformer::< (String, String), former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap1End > >>() } + #[ inline( always ) ] pub fn hashset_1_set< Former2 >( self ) -> Former2 where - Former2 : former::FormerBegin - < - former::HashSetDefinition - < - String, - Self, - Self, - Struct1FormerHashset1End, - > - >, + Former2 : former::FormerBegin< former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End, > >, { Former2::_begin( None, Some( self ), Struct1FormerHashset1End ) } - pub fn hashset_1( self ) -> - former::ContainerSubformer:: - < - String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End > - > + + #[ inline( always ) ] + pub fn hashset_1( self ) -> former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End > > { - self.hashset_1_set::< former::ContainerSubformer:: - < - String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End > - >>() + self.hashset_1_set::< former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End > >>() } - } -impl< Definition > Struct1Former< Definition > +// = former :: preform + +impl< Definition, > Struct1Former< Definition, > where Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< >, Formed = Struct1< > >, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Struct1< > >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { @@ -411,25 +377,58 @@ where } } -// zzz : description -/// Return original former after subformer for `vec_1` is done. +// = former :: perform + +#[ automatically_derived ] +impl< Definition, > Struct1Former< Definition, > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< >, Formed = Struct1< > >, +{ + + #[ inline( always ) ] + pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + let result = self.form(); + return result; + } +} + +// = subformer + +#[ allow( dead_code ) ] +pub type Struct1Subformer< __Superformer, __End > += Struct1Former< Struct1FormerDefinition< __Superformer, __Superformer, __End, >, >; + +// // xxx : remove maybe +// pub type Struct1FormerWithClosure< __Context, __Formed, > = Struct1FormerDefinition< __Context, __Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< __Context, __Formed, > > >; + +// = subformer end + +#[ allow( dead_code ) ] +pub trait Struct1SubformerEnd< SuperFormer > +where + Self : former::FormingEnd< Struct1FormerDefinitionTypes< SuperFormer, SuperFormer >, >, +{} + +impl< SuperFormer, T > Struct1SubformerEnd< SuperFormer > for T +where + Self : former::FormingEnd< Struct1FormerDefinitionTypes< SuperFormer, SuperFormer >, >, +{} + +// = end handlers + #[ allow( non_camel_case_types ) ] pub struct Struct1FormerVec1End; + #[ automatically_derived ] -impl< Definition > former::FormingEnd -< - former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, -> -for Struct1FormerVec1End +impl< Definition, > former::FormingEnd< former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, > for Struct1FormerVec1End where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes - < - Storage = Struct1FormerStorage - >, + 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 @@ -444,32 +443,17 @@ where } } -// zzz : description -/// Return original former after subformer for `hashmap_string_1` is done. #[ allow( non_camel_case_types ) ] pub struct Struct1FormerHashmap1End; + #[ automatically_derived ] -impl< Definition > former::FormingEnd -< - former::HashMapDefinition< String, String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, -> -for Struct1FormerHashmap1End +impl< Definition, > former::FormingEnd< former::HashMapDefinition< String, String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, > for Struct1FormerHashmap1End where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes - < - Storage = Struct1FormerStorage - >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, { #[ inline( always ) ] - fn call - ( - &self, - storage : std::collections::HashMap< String, String >, - super_former : Option< Struct1Former< Definition > >, - ) - -> - Struct1Former< Definition > + fn call( &self, storage : std::collections::HashMap< String, String >, super_former : Option< Struct1Former< Definition, > >, ) -> Struct1Former< Definition, > { let mut super_former = super_former.unwrap(); if let Some( ref mut field ) = super_former.storage.hashmap_1 @@ -484,25 +468,17 @@ where } } -// zzz : description -/// Return original former after subformer for `hashset_string_1` is done. #[ allow( non_camel_case_types ) ] pub struct Struct1FormerHashset1End; + #[ automatically_derived ] -impl< Definition > former::FormingEnd -< - former::HashSetDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, -> -for Struct1FormerHashset1End +impl< Definition, > former::FormingEnd< former::HashSetDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, > for Struct1FormerHashset1End where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes - < - Storage = Struct1FormerStorage - >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, { #[ inline( always ) ] - fn call( &self, storage : std::collections::HashSet< String >, super_former : Option< Struct1Former< Definition > > ) -> Struct1Former< Definition > + fn call( &self, storage : std::collections::HashSet< String >, super_former : Option< Struct1Former< Definition, > >, ) -> Struct1Former< Definition, > { let mut super_former = super_former.unwrap(); if let Some( ref mut field ) = super_former.storage.hashset_1 @@ -517,6 +493,6 @@ where } } -// = end of generated +// == end of generated include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index fee31705da..a65d526bcd 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -76,9 +76,9 @@ where type End = End; } -// zzz : documentation -pub type Struct1FormerWithClosure< Context, Formed > = -Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; +// // zzz : documentation +// pub type Struct1FormerWithClosure< Context, Formed > = +// Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; // = storage @@ -202,9 +202,9 @@ where // zzz : update description #[ inline( always ) ] - pub fn _new_precise( on_end : Definition::End ) -> Self + pub fn new_precise( on_end : Definition::End ) -> Self { - Self::_begin_precise( None, None, on_end ) + Self::begin_precise( None, None, on_end ) } #[ inline( always ) ] @@ -221,7 +221,7 @@ where } #[ inline( always ) ] - pub fn _begin_precise + pub fn begin_precise ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index 45bc6cb028..d2ffa9df6e 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -154,7 +154,7 @@ tests_impls! // - fn _begin_precise() + fn begin_precise() { // custom params @@ -165,7 +165,7 @@ tests_impls! Struct1FormerDefinition< i32, i32, _ > > - ::_begin_precise + ::begin_precise ( None, Some( 3 ), @@ -186,7 +186,7 @@ tests_impls! Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::_begin_precise + ::begin_precise ( None, Some( 3 ), @@ -207,7 +207,7 @@ tests_impls! // basic case let former = Struct1::former(); - let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::_new_precise( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new_precise( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let exp = former.form(); let got = former2.form(); @@ -268,43 +268,43 @@ tests_impls! let exp = Struct1::former().int_1( 13 ).form(); a_id!( got, exp ); - // default explicit params with wrapper and closure - let got = Struct1Former - // ::< Struct1FormerWithClosure< (), Struct1 > > - :: - < - Struct1FormerWithClosure< (), Struct1 > - > - ::new_coercing( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // default explicit params with wrapper and closure - let got = Struct1Former - // ::< Struct1FormerWithClosure< (), Struct1 > > - :: - < - - Struct1FormerWithClosure< (), Struct1 > - > - ::new_coercing( | storage, _context | { former::StoragePreform::preform( storage ) } ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); +// xxx : switch on or remove +// // default explicit params with wrapper and closure +// let got = Struct1Former +// // ::< Struct1FormerWithClosure< (), Struct1 > > +// :: +// < +// Struct1FormerDefinition< (), Struct1, _ > +// > +// ::new_coercing( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) +// .int_1( 13 ) +// .form(); +// let exp = Struct1::former().int_1( 13 ).form(); +// a_id!( got, exp ); +// +// // default explicit params with wrapper and closure +// let got = Struct1Former +// // ::< Struct1FormerWithClosure< (), Struct1 > > +// :: +// < +// Struct1FormerDefinition< (), Struct1, _ > +// > +// ::new_coercing( | storage, _context | { former::StoragePreform::preform( storage ) } ) +// .int_1( 13 ) +// .form(); +// let exp = Struct1::former().int_1( 13 ).form(); +// a_id!( got, exp ); } // - fn _new_precise() + fn new_precise() { // basic case let former = Struct1::former(); - let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::_new_precise( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new_precise( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let exp = former.form(); let got = former2.form(); @@ -318,7 +318,7 @@ tests_impls! Struct1FormerDefinition< (), Struct1, _ >, > - ::_new_precise( former::ReturnPreformed ) + ::new_precise( former::ReturnPreformed ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -337,7 +337,7 @@ tests_impls! Struct1FormerDefinition< (), Struct1, _ >, > - ::_new_precise( end_wrapper ) + ::new_precise( end_wrapper ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -351,7 +351,7 @@ tests_impls! Struct1FormerDefinition< (), Struct1, _ >, > - ::_new_precise( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + ::new_precise( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -365,7 +365,7 @@ tests_impls! Struct1FormerDefinition< _, _, _ >, > - ::_new_precise( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) + ::new_precise( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -516,9 +516,9 @@ tests_index! internals, custom_definition_params, begin_coercing, - _begin_precise, + begin_precise, new, - _new_precise, + new_precise, preform, definition, storage, diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index a6787e59f8..549232fa8a 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -3,7 +3,7 @@ use super::*; // -tests_impls_optional! +tests_impls! { // @@ -74,8 +74,36 @@ tests_impls_optional! // closure with helper let got : Struct1 = Struct1Former - ::< Struct1FormerWithClosure< (), Struct1 > > - ::new_coercing( | storage : Struct1FormerStorage, _context | { former::StoragePreform::preform( storage ) } ) + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::new_precise( | storage, _context | { former::StoragePreform::preform( storage ) } ) + .vec_1().replace( vec![ "a".to_string(), "b".to_string() ] ).end() + .form(); + let exp : Struct1 = Struct1 + { + vec_1 : vec![ "a".to_string(), "b".to_string() ], + hashmap_1 : hmap!{}, + hashset_1 : hset!{}, + }; + a_id!( got, exp ); + + // // closure with helper + // let got : Struct1 = Struct1Former + // ::< Struct1FormerWithClosure< (), Struct1 > > + // ::new_coercing( | storage : Struct1FormerStorage, _context | { former::StoragePreform::preform( storage ) } ) + // .vec_1().replace( vec![ "a".to_string(), "b".to_string() ] ).end() + // .form(); + // let exp : Struct1 = Struct1 + // { + // vec_1 : vec![ "a".to_string(), "b".to_string() ], + // hashmap_1 : hmap!{}, + // hashset_1 : hset!{}, + // }; + // a_id!( got, exp ); + + // closure with helper + let got : Struct1 = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::begin_precise( None, None, | storage, _context | { former::StoragePreform::preform( storage ) } ) .vec_1().replace( vec![ "a".to_string(), "b".to_string() ] ).end() .form(); let exp : Struct1 = Struct1 @@ -93,11 +121,20 @@ tests_impls_optional! fn field_forming_end() { - // use super::*; + // Container subformers are defined let _got = Struct1FormerVec1End; let _got = Struct1FormerHashmap1End; let _got = Struct1FormerHashset1End; + // SubformerEnd is defined + fn _f1< End : Struct1SubformerEnd< Struct1Former > > + ( + _end : End, + _subformer : Struct1Subformer< Struct1Former, impl Struct1SubformerEnd< Struct1Former > > + ) + { + } + } // diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index de15d3f897..3c87c071a4 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -39,8 +39,8 @@ tests_impls! // default explicit params with wrapper and closure let got = Struct1Former - ::< Struct1FormerWithClosure< (), Struct1 > > - ::new_coercing( | storage, _context | { former::StoragePreform::preform( storage ) } ) + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::new_precise( | storage, _context | { former::StoragePreform::preform( storage ) } ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); diff --git a/module/core/former/tests/inc/former_tests/only_test/string_slice.rs b/module/core/former/tests/inc/former_tests/only_test/string_slice.rs index 8e5c210170..88dd2ccf1f 100644 --- a/module/core/former/tests/inc/former_tests/only_test/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/only_test/string_slice.rs @@ -33,8 +33,17 @@ tests_impls! // default explicit params with wrapper and closure let got = Struct1Former - ::< Struct1FormerWithClosure< (), Struct1 > > - ::new_coercing( | storage, _context | { former::StoragePreform::preform( storage ) } ) + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::new_precise( | storage, _context | { former::StoragePreform::preform( storage ) } ) + .string_slice_1( "abc" ) + .form(); + let exp = Struct1::former().string_slice_1( "abc" ).form(); + a_id!( got, exp ); + + // closure with helper + let got : Struct1 = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::begin_precise( None, None, | storage, _context | { former::StoragePreform::preform( storage ) } ) .string_slice_1( "abc" ) .form(); let exp = Struct1::former().string_slice_1( "abc" ).form(); diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index d8099a8525..515f8c86bc 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -96,8 +96,7 @@ impl< K, __Context, __Formed, __End, > former :: FormerDefinition for CommandFor type End = __End; } -pub type CommandFormerWithClosure< K, __Context, __Formed, > = CommandFormerDefinition< K, __Context, __Formed, former :: FormingEndClosure< CommandFormerDefinitionTypes< K, __Context, __Formed, > > >; - +// pub type CommandFormerWithClosure< K, __Context, __Formed, > = CommandFormerDefinition< K, __Context, __Formed, former :: FormingEndClosure< CommandFormerDefinitionTypes< K, __Context, __Formed, > > >; pub struct CommandFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, { @@ -209,7 +208,7 @@ where } #[ inline( always ) ] - pub fn _new_precise( on_end : Definition::End ) -> Self + pub fn new_precise( on_end : Definition::End ) -> Self { Self::begin_coercing( None, None, on_end ) } @@ -222,7 +221,7 @@ where } #[ inline( always ) ] - pub fn _begin_precise( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self + pub fn begin_precise( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self { if storage.is_none() { diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 0641ce6dfa..9dd8fefeb7 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -68,8 +68,8 @@ where End : former::FormingEnd< Struct1FormerDefinitionTypes< 'a, Context, Forme type End = End; } -pub type Struct1FormerWithClosure< 'a, Context, Formed > = - Struct1FormerDefinition< 'a, Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< 'a, Context, Formed > > >; +// pub type Struct1FormerWithClosure< 'a, Context, Formed > = +// Struct1FormerDefinition< 'a, Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< 'a, Context, Formed > > >; // = storage @@ -163,7 +163,7 @@ where } #[ inline( always ) ] - pub fn _new_precise( on_end : Definition::End ) -> Self + pub fn new_precise( on_end : Definition::End ) -> Self { Self::begin_coercing( None, None, on_end ) } @@ -176,7 +176,7 @@ where } #[ inline( always ) ] - pub fn _begin_precise + pub fn begin_precise ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, diff --git a/module/core/former/tests/inc/former_tests/subformer_custom.rs b/module/core/former/tests/inc/former_tests/subformer_custom.rs index f4039b82dd..e953ad798c 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom.rs @@ -105,7 +105,7 @@ where let former : CommandFormer< _, _ > - = CommandFormer::_begin_precise( None, Some( self ), on_end ); + = CommandFormer::begin_precise( None, Some( self ), on_end ); former.name( name ) } @@ -119,7 +119,7 @@ where where IntoName : core::convert::Into< String >, { - let former = CommandFormer::_begin_precise( None, Some( self ), AggregatorFormerCommandEnd ); + let former = CommandFormer::begin_precise( None, Some( self ), AggregatorFormerCommandEnd ); former.name( name ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs index 6fc085ecac..cf9d198b21 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs @@ -55,7 +55,7 @@ where CommandSubformerEnd< K, Self >, { let former - = CommandFormer::_begin_precise + = CommandFormer::begin_precise ( None, Some( self ), diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 030581644c..3e62ed73ad 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -60,7 +60,7 @@ where > > { - self._descriptor_former:: + self._descriptor_former2:: < TemplateParameterDescriptorFormer< _ >, _, diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 841a46f884..0859e9a407 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1076,8 +1076,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_definition = syn::Ident::new( &former_definition_name, stru.span() ); let former_definition_types_name = format!( "{}FormerDefinitionTypes", stru ); let former_definition_types = syn::Ident::new( &former_definition_types_name, stru.span() ); - let former_with_closure_name = format!( "{}FormerWithClosure", stru ); - let former_with_closure = syn::Ident::new( &former_with_closure_name, stru.span() ); // xxx : maybe remove + // let former_with_closure_name = format!( "{}FormerWithClosure", stru ); + // let former_with_closure = syn::Ident::new( &former_with_closure_name, stru.span() ); // xxx : maybe remove let subformer_name = format!( "{}Subformer", stru ); let subformer = syn::Ident::new( &subformer_name, stru.span() ); let subformer_end_name = format!( "{}SubformerEnd", stru ); @@ -1326,12 +1326,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > type End = __End; } - pub type #former_with_closure < #former_definition_type_generics_ty > = - #former_definition - < - #former_definition_type_generics_ty former::FormingEndClosure< #former_definition_types < #former_definition_type_generics_ty > > - >; - // = storage #[ doc = "Container of a corresponding former." ] @@ -1406,27 +1400,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // zzz : should on_end be optional? } - #[ automatically_derived ] - impl < #former_perform_generics_impl > #former < #former_perform_generics_ty > - where - #former_perform_generics_where - { - - /// - /// Finish setting options and call perform on formed entity. - /// - /// If `perform` defined then associated method is called and its result returned instead of entity. - /// For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`. - /// - #[ inline( always ) ] - pub fn perform #perform_generics ( self ) -> #perform_output - { - let result = self.form(); - #perform - } - - } - #[ automatically_derived ] impl < #former_generics_impl > #former < #former_generics_ty > where @@ -1438,7 +1411,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// // zzz : improve description #[ inline( always ) ] - pub fn _new_precise( on_end : Definition::End ) -> Self + pub fn new_precise( on_end : Definition::End ) -> Self { Self::begin_coercing( None, None, on_end ) } @@ -1465,7 +1438,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// // zzz : improve description #[ inline( always ) ] - pub fn _begin_precise + pub fn begin_precise ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -1536,7 +1509,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } - // = preform with Storage::preform + // = former :: preform impl< #former_generics_impl > #former< #former_generics_ty > where @@ -1554,10 +1527,32 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } - // = subformer + // = former :: perform + + #[ automatically_derived ] + impl < #former_perform_generics_impl > #former < #former_perform_generics_ty > + where + #former_perform_generics_where + { + + /// + /// Finish setting options and call perform on formed entity. + /// + /// If `perform` defined then associated method is called and its result returned instead of entity. + /// For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`. + /// + #[ inline( always ) ] + pub fn perform #perform_generics ( self ) -> #perform_output + { + let result = self.form(); + #perform + } + + } - // xxx : improve description + // = subformer + // zzz : improve description /// Use as subformer of a field during process of forming of super structure. pub type #subformer < #struct_generics_ty __Superformer, __End > = #former < @@ -1572,6 +1567,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > >, >; + // pub type #former_with_closure < #former_definition_type_generics_ty > = + // #former_definition + // < + // #former_definition_type_generics_ty former::FormingEndClosure< #former_definition_types < #former_definition_type_generics_ty > > + // >; + // = subformer end /// Use as subformer end of a field during process of forming of super structure. From c5063098bbf212a5a4ced88f666294b481df29fc Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 14:05:07 +0300 Subject: [PATCH 254/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 1 - .../inc/former_tests/subformer_shortcut.rs | 61 +++++-------------- module/core/former_meta/src/derive/former.rs | 2 +- 3 files changed, 17 insertions(+), 47 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index c468742a0a..86df054885 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -400,7 +400,6 @@ where pub type Struct1Subformer< __Superformer, __End > = Struct1Former< Struct1FormerDefinition< __Superformer, __Superformer, __End, >, >; -// // xxx : remove maybe // pub type Struct1FormerWithClosure< __Context, __Formed, > = Struct1FormerDefinition< __Context, __Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< __Context, __Formed, > > >; // = subformer end diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 3e62ed73ad..57f305cd17 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -45,29 +45,6 @@ where Definition::Types : former::FormerDefinitionTypes< Storage = TemplateParametersFormerStorage >, { - // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help - - #[ inline( always ) ] - pub fn descriptor( self, name : &str ) -> - TemplateParameterDescriptorFormer - < - TemplateParameterDescriptorFormerDefinition - < - Self, - Self, - impl TemplateParameterDescriptorSubformerEnd< Self >, - // former::FormingEndClosure< TemplateParameterDescriptorFormerDefinitionTypes< Self, Self > >, - > - > - { - self._descriptor_former2:: - < - TemplateParameterDescriptorFormer< _ >, - _, - _, - >() - .name( name ) - } #[ inline( always ) ] pub fn _descriptor_former< Former2, Definition2, Types2 >( self ) -> @@ -123,6 +100,22 @@ where Former2::_begin( None, Some( self ), TemplateParameterDescriptorEnd::< Definition, Types2 >::default() ) } + // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help + + #[ inline( always ) ] + pub fn descriptor( self, name : &str ) -> + TemplateParameterDescriptorSubformer< Self, impl TemplateParameterDescriptorSubformerEnd< Self > > + { + self._descriptor_former2 + :: + < + TemplateParameterDescriptorFormer< _ >, + _, + _, + > + () + .name( name ) + } } /// Handles the completion of the subformer for `TemplateParameterDescriptor`. @@ -147,29 +140,17 @@ for TemplateParameterDescriptorEnd< Definition, Types2 > impl< Definition, Types2 > former::FormingEnd< Types2, > for TemplateParameterDescriptorEnd< Definition, Types2 > where - Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes < Storage = TemplateParametersFormerStorage >, - - // // Self : former::FormerDefinition, - // // Self::Types : former::FormerDefinitionTypes< Storage = TemplateParametersFormerStorage, > Types2 : former::FormerDefinitionTypes < Storage = TemplateParameterDescriptorFormerStorage, Formed = TemplateParametersFormer< Definition >, Context = TemplateParametersFormer< Definition >, >, - // Definition2 : former::FormerDefinition< Types = Types2, End = former::FormingEndClosure< Types2 > >, - // // Definition2 : former::FormerDefinition< Types = Types2 >, - // Definition2::End : former::FormingEnd< Definition2::Types >, - // Former2 : former::FormerBegin - // < - // Definition2, - // >, - { #[ inline( always ) ] fn call @@ -177,8 +158,6 @@ where &self, substorage : TemplateParameterDescriptorFormerStorage, super_former : core::option::Option< TemplateParametersFormer< Definition > >, - // descriptor : TemplateParameterDescriptorFormerStorage, - // super_former : Option< TemplateParametersFormer< Self > >, ) -> TemplateParametersFormer< Definition > { @@ -192,14 +171,6 @@ where former::ContainerAdd::add( descriptors, former::StoragePreform::preform( substorage ) ); } super_former - // let mut super_former = super_former.unwrap(); - // if super_former.storage.descriptors.is_none() - // { - // super_former.storage.descriptors = Some( Vec::new() ); - // } - // let preformed_descriptor = former::StoragePreform::preform( substorage ); - // super_former.storage.descriptors.as_mut().unwrap().push( preformed_descriptor ); - // super_former } } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 0859e9a407..82919623ec 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1077,7 +1077,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_definition_types_name = format!( "{}FormerDefinitionTypes", stru ); let former_definition_types = syn::Ident::new( &former_definition_types_name, stru.span() ); // let former_with_closure_name = format!( "{}FormerWithClosure", stru ); - // let former_with_closure = syn::Ident::new( &former_with_closure_name, stru.span() ); // xxx : maybe remove + // let former_with_closure = syn::Ident::new( &former_with_closure_name, stru.span() ); let subformer_name = format!( "{}Subformer", stru ); let subformer = syn::Ident::new( &subformer_name, stru.span() ); let subformer_end_name = format!( "{}SubformerEnd", stru ); From aa8d15c7c77158edf02d511e2ff11e9da3c154ac Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 14:07:40 +0300 Subject: [PATCH 255/533] former : experimenting --- .../former/tests/inc/former_tests/subformer_shortcut.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 57f305cd17..6f32e8f670 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -91,11 +91,7 @@ where Context = Self, >, Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParameterDescriptorEnd< Definition, Types2 > >, - Definition2::End : former::FormingEnd< Definition2::Types >, - Former2 : former::FormerBegin - < - Definition2, - >, + Former2 : former::FormerBegin< Definition2 >, { Former2::_begin( None, Some( self ), TemplateParameterDescriptorEnd::< Definition, Types2 >::default() ) } From 05d19ccddf8d6d433228e2f1e764f4705781fe6e Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 14:38:11 +0300 Subject: [PATCH 256/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 62 ++++++++++++++----- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 6f32e8f670..c1d67a0e6b 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -80,21 +80,21 @@ where // Former2::_begin( None, Some( self ), on_end ) } - #[ inline( always ) ] - pub fn _descriptor_former2< Former2, Definition2, Types2 >( self ) -> - Former2 - where - Types2 : former::FormerDefinitionTypes - < - Storage = TemplateParameterDescriptorFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParameterDescriptorEnd< Definition, Types2 > >, - Former2 : former::FormerBegin< Definition2 >, - { - Former2::_begin( None, Some( self ), TemplateParameterDescriptorEnd::< Definition, Types2 >::default() ) - } + // #[ inline( always ) ] + // pub fn _descriptor_former2< Former2, Definition2, Types2 >( self ) -> + // Former2 + // where + // Types2 : former::FormerDefinitionTypes + // < + // Storage = TemplateParameterDescriptorFormerStorage, + // Formed = Self, + // Context = Self, + // >, + // Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParameterDescriptorEnd< Definition, Types2 > >, + // Former2 : former::FormerBegin< Definition2 >, + // { + // Former2::_begin( None, Some( self ), TemplateParameterDescriptorEnd::default() ) + // } // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help @@ -102,7 +102,7 @@ where pub fn descriptor( self, name : &str ) -> TemplateParameterDescriptorSubformer< Self, impl TemplateParameterDescriptorSubformerEnd< Self > > { - self._descriptor_former2 + self._descriptor_former :: < TemplateParameterDescriptorFormer< _ >, @@ -114,6 +114,33 @@ where } } +trait SubFormerTrait< Definition, Definition2, Types2 > +where + Types2 : former::FormerDefinitionTypes + < + Storage = TemplateParameterDescriptorFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParameterDescriptorEnd< Definition, Types2 > >, + Self : former::FormerBegin< Definition2 >, +{ +} + +impl< T, Definition, Definition2, Types2 > SubFormerTrait< Definition, Definition2, Types2 > +for T +where + Types2 : former::FormerDefinitionTypes + < + Storage = TemplateParameterDescriptorFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParameterDescriptorEnd< Definition, Types2 > >, + Self : former::FormerBegin< Definition2 >, +{ +} + /// Handles the completion of the subformer for `TemplateParameterDescriptor`. pub struct TemplateParameterDescriptorEnd< Definition, Types2 > { @@ -139,7 +166,8 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes < - Storage = TemplateParametersFormerStorage + Storage = TemplateParametersFormerStorage, + // Storage = Storage, >, Types2 : former::FormerDefinitionTypes < From f11dfb2678e3d6cbe65fb21c5b67e0e8671c822d Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 21:11:40 +0300 Subject: [PATCH 257/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 92 +++++++++---------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index c1d67a0e6b..9b52c3351d 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -114,41 +114,41 @@ where } } -trait SubFormerTrait< Definition, Definition2, Types2 > -where - Types2 : former::FormerDefinitionTypes - < - Storage = TemplateParameterDescriptorFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParameterDescriptorEnd< Definition, Types2 > >, - Self : former::FormerBegin< Definition2 >, -{ -} - -impl< T, Definition, Definition2, Types2 > SubFormerTrait< Definition, Definition2, Types2 > -for T -where - Types2 : former::FormerDefinitionTypes - < - Storage = TemplateParameterDescriptorFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParameterDescriptorEnd< Definition, Types2 > >, - Self : former::FormerBegin< Definition2 >, -{ -} +// trait SubFormerTrait< Definition, Definition2, Types2 > +// where +// Types2 : former::FormerDefinitionTypes +// < +// Storage = TemplateParameterDescriptorFormerStorage, +// Formed = Self, +// Context = Self, +// >, +// Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParameterDescriptorEnd< Definition, Types2 > >, +// Self : former::FormerBegin< Definition2 >, +// { +// } +// +// impl< T, Definition, Definition2, Types2 > SubFormerTrait< Definition, Definition2, Types2 > +// for T +// where +// Types2 : former::FormerDefinitionTypes +// < +// Storage = TemplateParameterDescriptorFormerStorage, +// Formed = Self, +// Context = Self, +// >, +// Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParameterDescriptorEnd< Definition, Types2 > >, +// Self : former::FormerBegin< Definition2 >, +// { +// } /// Handles the completion of the subformer for `TemplateParameterDescriptor`. -pub struct TemplateParameterDescriptorEnd< Definition, Types2 > +pub struct TemplateParameterDescriptorEnd< X, Definition, Types2 > { - _phantom : core::marker::PhantomData< fn( Definition, Types2 ) >, + _phantom : core::marker::PhantomData< fn( X, Definition, Types2 ) >, } -impl< Definition, Types2 > Default -for TemplateParameterDescriptorEnd< Definition, Types2 > +impl< X, Definition, Types2 > Default +for TemplateParameterDescriptorEnd< X, Definition, Types2 > { #[ inline( always ) ] fn default() -> Self @@ -160,14 +160,14 @@ for TemplateParameterDescriptorEnd< Definition, Types2 > } } -impl< Definition, Types2 > former::FormingEnd< Types2, > -for TemplateParameterDescriptorEnd< Definition, Types2 > +impl< X, Definition, Types2 > former::FormingEnd< Types2, > +for TemplateParameterDescriptorEnd< X, Definition, Types2 > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes < Storage = TemplateParametersFormerStorage, - // Storage = Storage, + // Storage = X, >, Types2 : former::FormerDefinitionTypes < @@ -180,21 +180,21 @@ where fn call ( &self, - substorage : TemplateParameterDescriptorFormerStorage, - super_former : core::option::Option< TemplateParametersFormer< Definition > >, + substorage : Types2::Storage, + super_former : core::option::Option< Types2::Context >, ) - -> TemplateParametersFormer< Definition > + -> Types2::Formed { - let mut super_former = super_former.unwrap(); - if super_former.storage.descriptors.is_none() - { - super_former.storage.descriptors = Some( Default::default() ); - } - if let Some( ref mut descriptors ) = super_former.storage.descriptors - { - former::ContainerAdd::add( descriptors, former::StoragePreform::preform( substorage ) ); - } - super_former + let mut super_former = super_former.unwrap(); + if super_former.storage.descriptors.is_none() + { + super_former.storage.descriptors = Some( Default::default() ); + } + if let Some( ref mut descriptors ) = super_former.storage.descriptors + { + former::ContainerAdd::add( descriptors, former::StoragePreform::preform( substorage ) ); + } + super_former } } From 4bdf16fcbd93fa490575c1219c9145855433cce9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 21:44:27 +0300 Subject: [PATCH 258/533] former : experimenting --- .../tests/inc/former_tests/subformer_shortcut.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 9b52c3351d..b03bebb902 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -90,10 +90,10 @@ where // Formed = Self, // Context = Self, // >, - // Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParameterDescriptorEnd< Definition, Types2 > >, + // Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > >, // Former2 : former::FormerBegin< Definition2 >, // { - // Former2::_begin( None, Some( self ), TemplateParameterDescriptorEnd::default() ) + // Former2::_begin( None, Some( self ), TemplateParametersTemplateParameterDescriptorElementEnd::default() ) // } // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help @@ -122,7 +122,7 @@ where // Formed = Self, // Context = Self, // >, -// Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParameterDescriptorEnd< Definition, Types2 > >, +// Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > >, // Self : former::FormerBegin< Definition2 >, // { // } @@ -136,19 +136,19 @@ where // Formed = Self, // Context = Self, // >, -// Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParameterDescriptorEnd< Definition, Types2 > >, +// Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > >, // Self : former::FormerBegin< Definition2 >, // { // } /// Handles the completion of the subformer for `TemplateParameterDescriptor`. -pub struct TemplateParameterDescriptorEnd< X, Definition, Types2 > +pub struct TemplateParametersTemplateParameterDescriptorElementEnd< X, Definition, Types2 > { _phantom : core::marker::PhantomData< fn( X, Definition, Types2 ) >, } impl< X, Definition, Types2 > Default -for TemplateParameterDescriptorEnd< X, Definition, Types2 > +for TemplateParametersTemplateParameterDescriptorElementEnd< X, Definition, Types2 > { #[ inline( always ) ] fn default() -> Self @@ -161,7 +161,7 @@ for TemplateParameterDescriptorEnd< X, Definition, Types2 > } impl< X, Definition, Types2 > former::FormingEnd< Types2, > -for TemplateParameterDescriptorEnd< X, Definition, Types2 > +for TemplateParametersTemplateParameterDescriptorElementEnd< X, Definition, Types2 > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes @@ -175,6 +175,7 @@ where Formed = TemplateParametersFormer< Definition >, Context = TemplateParametersFormer< Definition >, >, + // Types2::Storage : former::StoragePreform, { #[ inline( always ) ] fn call From 5b4713447d3c575193e92b0a04ed5b26814ae95a Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 21:45:21 +0300 Subject: [PATCH 259/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index b03bebb902..b50e6a9971 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -80,21 +80,21 @@ where // Former2::_begin( None, Some( self ), on_end ) } - // #[ inline( always ) ] - // pub fn _descriptor_former2< Former2, Definition2, Types2 >( self ) -> - // Former2 - // where - // Types2 : former::FormerDefinitionTypes - // < - // Storage = TemplateParameterDescriptorFormerStorage, - // Formed = Self, - // Context = Self, - // >, - // Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > >, - // Former2 : former::FormerBegin< Definition2 >, - // { - // Former2::_begin( None, Some( self ), TemplateParametersTemplateParameterDescriptorElementEnd::default() ) - // } + #[ inline( always ) ] + pub fn _descriptor_former2< Former2, Definition2, Types2 >( self ) -> + Former2 + where + Types2 : former::FormerDefinitionTypes + < + Storage = TemplateParameterDescriptorFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > >, + Former2 : former::FormerBegin< Definition2 >, + { + Former2::_begin( None, Some( self ), TemplateParametersTemplateParameterDescriptorElementEnd::default() ) + } // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help From 7bff1f27edb4950a114eb30226deed1559131b05 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 21:46:20 +0300 Subject: [PATCH 260/533] former : experimenting --- .../tests/inc/former_tests/subformer_shortcut.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index b50e6a9971..cf304d06b1 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -47,7 +47,7 @@ where #[ inline( always ) ] - pub fn _descriptor_former< Former2, Definition2, Types2 >( self ) -> + pub fn _descriptor_former_with_closure< Former2, Definition2, Types2 >( self ) -> Former2 where Types2 : former::FormerDefinitionTypes @@ -81,7 +81,7 @@ where } #[ inline( always ) ] - pub fn _descriptor_former2< Former2, Definition2, Types2 >( self ) -> + pub fn _descriptor_former< Former2, Definition2, Types2 >( self ) -> Former2 where Types2 : former::FormerDefinitionTypes @@ -142,13 +142,13 @@ where // } /// Handles the completion of the subformer for `TemplateParameterDescriptor`. -pub struct TemplateParametersTemplateParameterDescriptorElementEnd< X, Definition, Types2 > +pub struct TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > { - _phantom : core::marker::PhantomData< fn( X, Definition, Types2 ) >, + _phantom : core::marker::PhantomData< fn( Definition, Types2 ) >, } -impl< X, Definition, Types2 > Default -for TemplateParametersTemplateParameterDescriptorElementEnd< X, Definition, Types2 > +impl< Definition, Types2 > Default +for TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > { #[ inline( always ) ] fn default() -> Self @@ -160,8 +160,8 @@ for TemplateParametersTemplateParameterDescriptorElementEnd< X, Definition, Type } } -impl< X, Definition, Types2 > former::FormingEnd< Types2, > -for TemplateParametersTemplateParameterDescriptorElementEnd< X, Definition, Types2 > +impl< Definition, Types2 > former::FormingEnd< Types2, > +for TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes From 2b12b757ef319091867207d9410eb8278a11a428 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 21:53:09 +0300 Subject: [PATCH 261/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index cf304d06b1..7d6816c27b 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -81,7 +81,7 @@ where } #[ inline( always ) ] - pub fn _descriptor_former< Former2, Definition2, Types2 >( self ) -> + pub fn _descriptor_former_set2< Former2, Definition2, Types2 >( self ) -> Former2 where Types2 : former::FormerDefinitionTypes @@ -90,10 +90,10 @@ where Formed = Self, Context = Self, >, - Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > >, + Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorAddElementOnEnd< Types2, Definition > >, Former2 : former::FormerBegin< Definition2 >, { - Former2::_begin( None, Some( self ), TemplateParametersTemplateParameterDescriptorElementEnd::default() ) + Former2::_begin( None, Some( self ), TemplateParametersTemplateParameterDescriptorAddElementOnEnd::default() ) } // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help @@ -102,7 +102,7 @@ where pub fn descriptor( self, name : &str ) -> TemplateParameterDescriptorSubformer< Self, impl TemplateParameterDescriptorSubformerEnd< Self > > { - self._descriptor_former + self._descriptor_former_set2 :: < TemplateParameterDescriptorFormer< _ >, @@ -122,7 +122,7 @@ where // Formed = Self, // Context = Self, // >, -// Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > >, +// Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorAddElementOnEnd< Definition, Types2 > >, // Self : former::FormerBegin< Definition2 >, // { // } @@ -136,19 +136,19 @@ where // Formed = Self, // Context = Self, // >, -// Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > >, +// Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorAddElementOnEnd< Definition, Types2 > >, // Self : former::FormerBegin< Definition2 >, // { // } /// Handles the completion of the subformer for `TemplateParameterDescriptor`. -pub struct TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > +pub struct TemplateParametersTemplateParameterDescriptorAddElementOnEnd< Definition, Types2 > { _phantom : core::marker::PhantomData< fn( Definition, Types2 ) >, } impl< Definition, Types2 > Default -for TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > +for TemplateParametersTemplateParameterDescriptorAddElementOnEnd< Definition, Types2 > { #[ inline( always ) ] fn default() -> Self @@ -160,8 +160,8 @@ for TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 } } -impl< Definition, Types2 > former::FormingEnd< Types2, > -for TemplateParametersTemplateParameterDescriptorElementEnd< Definition, Types2 > +impl< Types2, Definition > former::FormingEnd< Types2, > +for TemplateParametersTemplateParameterDescriptorAddElementOnEnd< Types2, Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes From 7f4a5bd0cca2df4bcad3ff077e349cb408061346 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 22:21:05 +0300 Subject: [PATCH 262/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 140 ++++++++++-------- 1 file changed, 79 insertions(+), 61 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 7d6816c27b..c873f2ec57 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -4,7 +4,7 @@ use super::*; /// Parameter description. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] -pub struct TemplateParameterDescriptor +pub struct Descriptor { name : String, is_mandatory : bool, @@ -12,17 +12,17 @@ pub struct TemplateParameterDescriptor /// Parameters required for the template. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] -pub struct TemplateParameters +pub struct Parameters { #[ subformer( former::VectorDefinition ) ] - descriptors : Vec< TemplateParameterDescriptor >, + descriptors : Vec< Descriptor >, } impl< Definition > former::FormerBegin< Definition > -for TemplateParameterDescriptorFormer< Definition > +for DescriptorFormer< Definition > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = TemplateParameterDescriptorFormerStorage >, + Definition::Types : former::FormerDefinitionTypes< Storage = DescriptorFormerStorage >, { #[ inline( always ) ] @@ -39,10 +39,10 @@ where } -impl< Definition > TemplateParametersFormer< Definition > +impl< Definition > ParametersFormer< Definition > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = TemplateParametersFormerStorage >, + Definition::Types : former::FormerDefinitionTypes< Storage = ParametersFormerStorage >, { @@ -52,7 +52,7 @@ where where Types2 : former::FormerDefinitionTypes < - Storage = TemplateParameterDescriptorFormerStorage, + Storage = DescriptorFormerStorage, Formed = Self, Context = Self, >, @@ -63,7 +63,7 @@ where Definition2, >, { - let on_end = | substorage : TemplateParameterDescriptorFormerStorage, super_former : core::option::Option< Self > | -> Self + let on_end = | substorage : DescriptorFormerStorage, super_former : core::option::Option< Self > | -> Self { let mut super_former = super_former.unwrap(); if super_former.storage.descriptors.is_none() @@ -86,69 +86,87 @@ where where Types2 : former::FormerDefinitionTypes < - Storage = TemplateParameterDescriptorFormerStorage, + Storage = DescriptorFormerStorage, Formed = Self, Context = Self, >, - Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorAddElementOnEnd< Types2, Definition > >, + Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, Former2 : former::FormerBegin< Definition2 >, { - Former2::_begin( None, Some( self ), TemplateParametersTemplateParameterDescriptorAddElementOnEnd::default() ) + Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) + } + + #[ inline( always ) ] + pub fn _descriptor_former_set3< Former2, Definition2, Types2 >( self ) -> + Former2 + where + Former2 : SubFormerTrait< Self, Definition, Definition2, Types2 >, + Types2 : former::FormerDefinitionTypes + < + Storage = DescriptorFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, + Former2 : former::FormerBegin< Definition2 >, + { + Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) } // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help #[ inline( always ) ] pub fn descriptor( self, name : &str ) -> - TemplateParameterDescriptorSubformer< Self, impl TemplateParameterDescriptorSubformerEnd< Self > > + DescriptorSubformer< Self, impl DescriptorSubformerEnd< Self > > { self._descriptor_former_set2 :: < - TemplateParameterDescriptorFormer< _ >, + DescriptorFormer< _ >, _, _, > () .name( name ) } + +} + +pub trait SubFormerTrait< Former, Definition, Definition2, Types2 > +where + Types2 : former::FormerDefinitionTypes + < + Storage = DescriptorFormerStorage, + Formed = Former, + Context = Former, + >, + Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, + Self : former::FormerBegin< Definition2 >, +{ +} + +impl< T, Former, Definition, Definition2, Types2 > SubFormerTrait< Former, Definition, Definition2, Types2 > +for T +where + Types2 : former::FormerDefinitionTypes + < + Storage = DescriptorFormerStorage, + Formed = Former, + Context = Former, + >, + Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, + Self : former::FormerBegin< Definition2 >, +{ } -// trait SubFormerTrait< Definition, Definition2, Types2 > -// where -// Types2 : former::FormerDefinitionTypes -// < -// Storage = TemplateParameterDescriptorFormerStorage, -// Formed = Self, -// Context = Self, -// >, -// Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorAddElementOnEnd< Definition, Types2 > >, -// Self : former::FormerBegin< Definition2 >, -// { -// } -// -// impl< T, Definition, Definition2, Types2 > SubFormerTrait< Definition, Definition2, Types2 > -// for T -// where -// Types2 : former::FormerDefinitionTypes -// < -// Storage = TemplateParameterDescriptorFormerStorage, -// Formed = Self, -// Context = Self, -// >, -// Definition2 : former::FormerDefinition< Types = Types2, End = TemplateParametersTemplateParameterDescriptorAddElementOnEnd< Definition, Types2 > >, -// Self : former::FormerBegin< Definition2 >, -// { -// } - -/// Handles the completion of the subformer for `TemplateParameterDescriptor`. -pub struct TemplateParametersTemplateParameterDescriptorAddElementOnEnd< Definition, Types2 > +/// Handles the completion of the subformer for `Descriptor`. +pub struct ParametersDescriptorAddElementOnEnd< Definition, Types2 > { _phantom : core::marker::PhantomData< fn( Definition, Types2 ) >, } impl< Definition, Types2 > Default -for TemplateParametersTemplateParameterDescriptorAddElementOnEnd< Definition, Types2 > +for ParametersDescriptorAddElementOnEnd< Definition, Types2 > { #[ inline( always ) ] fn default() -> Self @@ -161,19 +179,19 @@ for TemplateParametersTemplateParameterDescriptorAddElementOnEnd< Definition, Ty } impl< Types2, Definition > former::FormingEnd< Types2, > -for TemplateParametersTemplateParameterDescriptorAddElementOnEnd< Types2, Definition > +for ParametersDescriptorAddElementOnEnd< Types2, Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes < - Storage = TemplateParametersFormerStorage, + Storage = ParametersFormerStorage, // Storage = X, >, Types2 : former::FormerDefinitionTypes < - Storage = TemplateParameterDescriptorFormerStorage, - Formed = TemplateParametersFormer< Definition >, - Context = TemplateParametersFormer< Definition >, + Storage = DescriptorFormerStorage, + Formed = ParametersFormer< Definition >, + Context = ParametersFormer< Definition >, >, // Types2::Storage : former::StoragePreform, { @@ -203,19 +221,19 @@ where fn basic() { - let got = TemplateParameters::former() + let got = Parameters::former() .descriptors() - .add( TemplateParameterDescriptor::former().name( "a" ).form() ) - .add( TemplateParameterDescriptor::former().name( "b" ).form() ) + .add( Descriptor::former().name( "a" ).form() ) + .add( Descriptor::former().name( "b" ).form() ) .end() .form(); let descriptors = vec! [ - TemplateParameterDescriptor { name : "a".to_string(), is_mandatory : false }, - TemplateParameterDescriptor { name : "b".to_string(), is_mandatory : false }, + Descriptor { name : "a".to_string(), is_mandatory : false }, + Descriptor { name : "b".to_string(), is_mandatory : false }, ]; - let exp = TemplateParameters { descriptors }; + let exp = Parameters { descriptors }; a_id!( got, exp ); } @@ -224,20 +242,20 @@ fn basic() fn descriptor() { - let got = TemplateParameters::former() + let got = Parameters::former() .descriptor( "a" ).end() .descriptor( "b" ).end() - // .add( TemplateParameterDescriptor::former().name( "a" ).form() ) - // .add( TemplateParameterDescriptor::former().name( "b" ).form() ) + // .add( Descriptor::former().name( "a" ).form() ) + // .add( Descriptor::former().name( "b" ).form() ) // .end() .form(); let descriptors = vec! [ - TemplateParameterDescriptor { name : "a".to_string(), is_mandatory : false }, - TemplateParameterDescriptor { name : "b".to_string(), is_mandatory : false }, + Descriptor { name : "a".to_string(), is_mandatory : false }, + Descriptor { name : "b".to_string(), is_mandatory : false }, ]; - let exp = TemplateParameters { descriptors }; + let exp = Parameters { descriptors }; a_id!( got, exp ); } From b31831bc32dd9ca866e096daeab54ef7c4061724 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 22:22:45 +0300 Subject: [PATCH 263/533] former : experimenting --- .../core/former/tests/inc/former_tests/subformer_shortcut.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index c873f2ec57..03f5aac200 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -100,7 +100,6 @@ where pub fn _descriptor_former_set3< Former2, Definition2, Types2 >( self ) -> Former2 where - Former2 : SubFormerTrait< Self, Definition, Definition2, Types2 >, Types2 : former::FormerDefinitionTypes < Storage = DescriptorFormerStorage, @@ -108,7 +107,7 @@ where Context = Self, >, Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, - Former2 : former::FormerBegin< Definition2 >, + Former2 : SubFormerTrait< Self, Definition, Definition2, Types2 >, { Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) } From 8aa9eb4fb865b05d72d2a3e695d6a075f639b430 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 23:04:12 +0300 Subject: [PATCH 264/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 106 +++++++++++------- 1 file changed, 65 insertions(+), 41 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 03f5aac200..87f087698d 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -96,21 +96,22 @@ where Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) } - #[ inline( always ) ] - pub fn _descriptor_former_set3< Former2, Definition2, Types2 >( self ) -> - Former2 - where - Types2 : former::FormerDefinitionTypes - < - Storage = DescriptorFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, - Former2 : SubFormerTrait< Self, Definition, Definition2, Types2 >, - { - Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) - } + // #[ inline( always ) ] + // pub fn _descriptor_former_set3< Former2 >( self ) -> + // Former2 + // where + // Former2 : SubFormerTrait2< Definition = Definition, Former = Self >, + // // Types2 : former::FormerDefinitionTypes + // // < + // // Storage = DescriptorFormerStorage, + // // Formed = Self, + // // Context = Self, + // // >, + // // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, + // // Former2 : SubFormerTrait< Self, Definition, Definition2, Types2 >, + // { + // Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) + // } // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help @@ -131,32 +132,55 @@ where } -pub trait SubFormerTrait< Former, Definition, Definition2, Types2 > -where - Types2 : former::FormerDefinitionTypes - < - Storage = DescriptorFormerStorage, - Formed = Former, - Context = Former, - >, - Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, - Self : former::FormerBegin< Definition2 >, -{ -} - -impl< T, Former, Definition, Definition2, Types2 > SubFormerTrait< Former, Definition, Definition2, Types2 > -for T -where - Types2 : former::FormerDefinitionTypes - < - Storage = DescriptorFormerStorage, - Formed = Former, - Context = Former, - >, - Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, - Self : former::FormerBegin< Definition2 >, -{ -} +// pub trait SubFormerTrait2 +// where +// < Self::Definition2 as former::FormerDefinition >::Types : former::FormerDefinitionTypes +// < +// Storage = DescriptorFormerStorage, +// Formed = Self::Former, +// Context = Self::Former, +// >, +// Self : former::FormerBegin< Self::Definition2 >, +// { +// type Former; +// type Definition; +// type Definition2 : former::FormerDefinition +// < +// End = ParametersDescriptorAddElementOnEnd +// < +// < Self::Definition2 as former::FormerDefinition >::Types, +// Self::Definition, +// >, +// >; +// // type Types2; +// } +// +// pub trait SubFormerTrait< Former, Definition, Definition2, Types2 > +// where +// Types2 : former::FormerDefinitionTypes +// < +// Storage = DescriptorFormerStorage, +// Formed = Former, +// Context = Former, +// >, +// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, +// Self : former::FormerBegin< Definition2 >, +// { +// } +// +// impl< T, Former, Definition, Definition2, Types2 > SubFormerTrait< Former, Definition, Definition2, Types2 > +// for T +// where +// Types2 : former::FormerDefinitionTypes +// < +// Storage = DescriptorFormerStorage, +// Formed = Former, +// Context = Former, +// >, +// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, +// Self : former::FormerBegin< Definition2 >, +// { +// } /// Handles the completion of the subformer for `Descriptor`. pub struct ParametersDescriptorAddElementOnEnd< Definition, Types2 > From c92510be0cb5d6ff014c61e8c3761e9bde8da2a7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 23:05:24 +0300 Subject: [PATCH 265/533] former : experimenting --- .../former/tests/inc/former_tests/subformer_shortcut.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 87f087698d..9a911dcd4a 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -120,13 +120,7 @@ where DescriptorSubformer< Self, impl DescriptorSubformerEnd< Self > > { self._descriptor_former_set2 - :: - < - DescriptorFormer< _ >, - _, - _, - > - () + ::< DescriptorFormer< _ >, _, _, >() .name( name ) } From 5373bbeceb318da4cacd2e1473d49eb8081df7e7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 23:26:11 +0300 Subject: [PATCH 266/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 22 +++--- module/core/former_meta/src/derive/former.rs | 72 +++++++++++++++++++ 2 files changed, 82 insertions(+), 12 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 9a911dcd4a..b9865283e0 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -90,7 +90,7 @@ where Formed = Self, Context = Self, >, - Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, + Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Definition > >, Former2 : former::FormerBegin< Definition2 >, { Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) @@ -107,7 +107,7 @@ where // // Formed = Self, // // Context = Self, // // >, - // // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, + // // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Definition > >, // // Former2 : SubFormerTrait< Self, Definition, Definition2, Types2 >, // { // Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) @@ -157,7 +157,7 @@ where // Formed = Former, // Context = Former, // >, -// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, +// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Definition > >, // Self : former::FormerBegin< Definition2 >, // { // } @@ -171,19 +171,19 @@ where // Formed = Former, // Context = Former, // >, -// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, +// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Definition > >, // Self : former::FormerBegin< Definition2 >, // { // } -/// Handles the completion of the subformer for `Descriptor`. -pub struct ParametersDescriptorAddElementOnEnd< Definition, Types2 > +/// Handles the completion of and element of subformer's container. +pub struct ParametersDescriptorAddElementOnEnd< Definition > { - _phantom : core::marker::PhantomData< fn( Definition, Types2 ) >, + _phantom : core::marker::PhantomData< fn( Definition ) >, } -impl< Definition, Types2 > Default -for ParametersDescriptorAddElementOnEnd< Definition, Types2 > +impl< Definition > Default +for ParametersDescriptorAddElementOnEnd< Definition > { #[ inline( always ) ] fn default() -> Self @@ -196,13 +196,12 @@ for ParametersDescriptorAddElementOnEnd< Definition, Types2 > } impl< Types2, Definition > former::FormingEnd< Types2, > -for ParametersDescriptorAddElementOnEnd< Types2, Definition > +for ParametersDescriptorAddElementOnEnd< Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes < Storage = ParametersFormerStorage, - // Storage = X, >, Types2 : former::FormerDefinitionTypes < @@ -210,7 +209,6 @@ where Formed = ParametersFormer< Definition >, Context = ParametersFormer< Definition >, >, - // Types2::Storage : former::StoragePreform, { #[ inline( always ) ] fn call diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 82919623ec..a1be106ac4 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -921,6 +921,78 @@ Result< TokenStream > } } + // #[ inline( always ) ] + // pub fn _descriptor_former_set2< Former2, Definition2, Types2 >( self ) -> + // Former2 + // where + // Types2 : former::FormerDefinitionTypes + // < + // Storage = DescriptorFormerStorage, + // Formed = Self, + // Context = Self, + // >, + // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, + // Former2 : former::FormerBegin< Definition2 >, + // { + // Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) + // } + +// /// Handles the completion of and element of subformer's container. +// pub struct ParametersDescriptorAddElementOnEnd< Definition > +// { +// _phantom : core::marker::PhantomData< fn( Definition ) >, +// } +// +// impl< Definition > Default +// for ParametersDescriptorAddElementOnEnd< Definition > +// { +// #[ inline( always ) ] +// fn default() -> Self +// { +// Self +// { +// _phantom : core::marker::PhantomData, +// } +// } +// } +// +// impl< Types2, Definition > former::FormingEnd< Types2, > +// for ParametersDescriptorAddElementOnEnd< Definition > +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes +// < +// Storage = ParametersFormerStorage, +// >, +// Types2 : former::FormerDefinitionTypes +// < +// Storage = DescriptorFormerStorage, +// Formed = ParametersFormer< Definition >, +// Context = ParametersFormer< Definition >, +// >, +// { +// #[ inline( always ) ] +// fn call +// ( +// &self, +// substorage : Types2::Storage, +// super_former : core::option::Option< Types2::Context >, +// ) +// -> Types2::Formed +// { +// let mut super_former = super_former.unwrap(); +// if super_former.storage.descriptors.is_none() +// { +// super_former.storage.descriptors = Some( Default::default() ); +// } +// if let Some( ref mut descriptors ) = super_former.storage.descriptors +// { +// former::ContainerAdd::add( descriptors, former::StoragePreform::preform( substorage ) ); +// } +// super_former +// } +// } + }; // tree_print!( r.as_ref().unwrap() ); From 1f0d8dd1a80ea36039bc60701ee914f03f60e152 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 23:51:00 +0300 Subject: [PATCH 267/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index b9865283e0..a7e641c501 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -15,6 +15,7 @@ pub struct Descriptor pub struct Parameters { #[ subformer( former::VectorDefinition ) ] + // #[ element_subformer( Descriptor ) ] descriptors : Vec< Descriptor >, } @@ -126,6 +127,24 @@ where } +pub trait FormerDefinitionFull +{ + type Storage; + // type Formed; + // type Context; + // type Types; + // type Definition; +} + +impl FormerDefinitionFull for Descriptor +{ + type Storage = DescriptorFormerStorage; + // type Formed; + // type Context; + // type Types; + // type Definition; +} + // pub trait SubFormerTrait2 // where // < Self::Definition2 as former::FormerDefinition >::Types : former::FormerDefinitionTypes @@ -205,7 +224,10 @@ where >, Types2 : former::FormerDefinitionTypes < - Storage = DescriptorFormerStorage, + // Storage = DescriptorFormerStorage, + // Storage = < DescriptorFormerDefinitionTypes as former::FormerDefinitionTypes >::Storage, + Storage = < Descriptor as FormerDefinitionFull >::Storage, + // Storage = < former::VectorDefinition< Descriptor > as former::FormerDefinitionTypes >::Storage, Formed = ParametersFormer< Definition >, Context = ParametersFormer< Definition >, >, From 482df0147679c3919d47e3ec92c9a96d5e2c666e Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 23 Apr 2024 23:56:29 +0300 Subject: [PATCH 268/533] former : experimenting --- .../former/tests/inc/former_tests/subformer_shortcut.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index a7e641c501..c3c38ed7c2 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -127,18 +127,20 @@ where } -pub trait FormerDefinitionFull +pub trait EntityToFormer { type Storage; + type Former; // type Formed; // type Context; // type Types; // type Definition; } -impl FormerDefinitionFull for Descriptor +impl EntityToFormer for Descriptor { type Storage = DescriptorFormerStorage; + type Former = DescriptorFormer; // type Formed; // type Context; // type Types; @@ -226,8 +228,7 @@ where < // Storage = DescriptorFormerStorage, // Storage = < DescriptorFormerDefinitionTypes as former::FormerDefinitionTypes >::Storage, - Storage = < Descriptor as FormerDefinitionFull >::Storage, - // Storage = < former::VectorDefinition< Descriptor > as former::FormerDefinitionTypes >::Storage, + Storage = < Descriptor as EntityToFormer >::Storage, Formed = ParametersFormer< Definition >, Context = ParametersFormer< Definition >, >, From 7f1dc8eccbf69737173cf46acd836d2968b32225 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 24 Apr 2024 00:04:23 +0300 Subject: [PATCH 269/533] former : experimenting --- module/core/former/src/axiomatic.rs | 5 - .../tests/inc/former_tests/a_basic_manual.rs | 3 + module/core/former/tests/inc/mod.rs | 110 +++++++++--------- 3 files changed, 59 insertions(+), 59 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index f9af1f3ecf..cd8e43d686 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -20,14 +20,9 @@ pub trait StoragePreform /// zzz : write description pub trait FormerDefinitionTypes : Sized { - // type Storage : Storage< Definition = Self >; - // type Storage : Storage< Formed = Self::Formed >; type Storage : Default; type Formed; type Context; - - // fn preform( storage : Self::Storage, context : Self::Context ) -> Self::Formed; - } /// zzz : write description diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index dcec2edb6d..ed0f627c4d 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -69,6 +69,9 @@ impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinitio where End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > > { type Types = Struct1FormerDefinitionTypes< Context, Formed >; + // type Storage = Struct1FormerStorage; + // type Formed = Formed; + // type Context = Context; type End = End; } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 4182358976..441d91fe6e 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -7,61 +7,63 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_common; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_vec; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_hashset; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_hashmap; - +// xxx : uncomment +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_common; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_vec; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_hashset; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_hashmap; +// mod a_basic_manual; - mod a_basic; - mod a_primitives_manual; - mod a_primitives; - mod a_containers_without_subformer; - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer_manual; - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer ; - - mod attribute_default_container; - mod attribute_default_primitive; - mod attribute_perform; - mod attribute_setter; - mod attribute_alias; - // mod attribute_feature; // xxx : write test - - mod string_slice_manual; - mod string_slice; - mod unsigned_primitive_types; - mod default_user_type; - mod user_type_no_default; - mod user_type_no_debug; - - mod name_collision_former_hashmap_without_parameter; - mod name_collision_former_vector_without_parameter; - mod name_collisions; - mod name_collision_context; - mod name_collision_end; - mod name_collision_on_end; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_manual; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_imm; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_where; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_basic; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_custom; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_custom_experimental; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_shortcut; + // mod a_basic; +// mod a_primitives_manual; +// mod a_primitives; +// mod a_containers_without_subformer; +// #[ cfg( not( feature = "no_std" ) ) ] +// mod a_containers_with_subformer_manual; +// #[ cfg( not( feature = "no_std" ) ) ] +// mod a_containers_with_subformer ; +// +// mod attribute_default_container; +// mod attribute_default_primitive; +// mod attribute_perform; +// mod attribute_setter; +// mod attribute_alias; +// // mod attribute_feature; // xxx : write test +// +// mod string_slice_manual; +// mod string_slice; +// mod unsigned_primitive_types; +// mod default_user_type; +// mod user_type_no_default; +// mod user_type_no_debug; +// +// mod name_collision_former_hashmap_without_parameter; +// mod name_collision_former_vector_without_parameter; +// mod name_collisions; +// mod name_collision_context; +// mod name_collision_end; +// mod name_collision_on_end; +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_manual; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_imm; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_where; +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_basic; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_custom; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_custom_experimental; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_shortcut; + // xxx : uncomment } From afba488740132cbb4cc33736534037ef4f354cc9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 24 Apr 2024 14:53:27 +0300 Subject: [PATCH 270/533] former : experimenting --- module/core/former/src/axiomatic.rs | 9 +- module/core/former/src/hash_map.rs | 8 ++ module/core/former/src/hash_set.rs | 7 + module/core/former/src/vector.rs | 4 + .../tests/inc/former_tests/a_basic_manual.rs | 9 +- .../a_containers_with_subformer_manual.rs | 9 +- .../inc/former_tests/a_primitives_manual.rs | 3 + .../former_tests/container_former_common.rs | 9 ++ .../parametrized_struct_manual.rs | 34 ++++- .../inc/former_tests/string_slice_manual.rs | 9 +- .../inc/former_tests/subformer_shortcut.rs | 22 +++- module/core/former/tests/inc/mod.rs | 120 +++++++++--------- module/core/former_meta/src/derive/former.rs | 4 + 13 files changed, 166 insertions(+), 81 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index cd8e43d686..4e69f3e6b1 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -28,8 +28,11 @@ pub trait FormerDefinitionTypes : Sized /// zzz : write description pub trait FormerDefinition : Sized { - type Types : FormerDefinitionTypes; + type Types : FormerDefinitionTypes< Storage = Self::Storage, Formed = Self::Formed, Context = Self::Context >; type End : FormingEnd< Self::Types >; + type Storage : Default; + type Formed; + type Context; } /// Defines a handler for the end of a subforming process, enabling the return of the original context. @@ -228,8 +231,8 @@ pub trait FormerBegin< Definition : FormerDefinition > /// * `on_end` - A completion handler responsible for transforming the accumulated `Storage` into the final `Formed` structure. fn _begin ( - storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, + storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Definition::Context >, on_end : Definition::End, ) -> Self; diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 6e3deb4a35..c2e2c28c08 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -93,8 +93,16 @@ where K : ::core::cmp::Eq + ::core::hash::Hash, End : FormingEnd< HashMapDefinition< K, E, Context, Formed, NoEnd > >, { + // type Types = HashMapDefinition< K, E, Context, Formed, NoEnd >; + // type End = End; + + type Storage = HashMap< K, E >; + type Formed = Formed; + type Context = Context; + type Types = HashMapDefinition< K, E, Context, Formed, NoEnd >; type End = End; + } // #[ derive( Debug, Default ) ] diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 11a517fec0..d3c7ed7ffb 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -82,8 +82,15 @@ where K : ::core::cmp::Eq + ::core::hash::Hash, End : FormingEnd< HashSetDefinition< K, Context, Formed, NoEnd > >, { + type Storage = HashSet< K >; + type Formed = Formed; + type Context = Context; + type Types = HashSetDefinition< K, Context, Formed, NoEnd >; type End = End; + + // type Types = HashSetDefinition< K, Context, Formed, NoEnd >; + // type End = End; } // = subformer diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 4e8faf4463..ea16c631d0 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -65,6 +65,10 @@ for VectorDefinition< E, Context, Formed, End > where End : FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, { + type Storage = Vec< E >; + type Formed = Formed; + type Context = Context; + type Types = VectorDefinition< E, Context, Formed, NoEnd >; type End = End; } diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index ed0f627c4d..65c743e7ab 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -66,12 +66,13 @@ impl< Context, Formed, End > Default for Struct1FormerDefinition< Context, Forme } impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > -where End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > > +where + End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > > { + type Storage = Struct1FormerStorage; + type Formed = Formed; + type Context = Context; type Types = Struct1FormerDefinitionTypes< Context, Formed >; - // type Storage = Struct1FormerStorage; - // type Formed = Formed; - // type Context = Context; type End = End; } diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 86df054885..17b28c55c7 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -43,7 +43,8 @@ where } } -impl< __Context, __Formed, > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< __Context, __Formed, > +impl< __Context, __Formed, > former::FormerDefinitionTypes +for Struct1FormerDefinitionTypes< __Context, __Formed, > where { type Storage = Struct1FormerStorage< >; @@ -72,12 +73,16 @@ where } } -impl< __Context, __Formed, __End, > former::FormerDefinition for Struct1FormerDefinition< __Context, __Formed, __End, > +impl< __Context, __Formed, __End, > former::FormerDefinition +for Struct1FormerDefinition< __Context, __Formed, __End, > where __End : former::FormingEnd< Struct1FormerDefinitionTypes< __Context, __Formed, > >, { type Types = Struct1FormerDefinitionTypes< __Context, __Formed, >; type End = __End; + type Storage = Struct1FormerStorage< >; + type Formed = __Formed; + type Context = __Context; } // = storage diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index a65d526bcd..f7c6b93291 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -74,6 +74,9 @@ where { type Types = Struct1FormerDefinitionTypes< Context, Formed >; type End = End; + type Storage = Struct1FormerStorage; + type Formed = Formed; + type Context = Context; } // // zzz : documentation diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index beaaee388d..b0167aeb3c 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -108,6 +108,9 @@ fn custom_definition() { type Types = Return13; type End = Return13; + type Storage = Vec< String >; + type Formed = i32; + type Context = (); } // - @@ -175,6 +178,9 @@ fn custom_definition_parametrized() { type Types = Return13< E >; type End = Return13< E >; + type Storage = Vec< E >; + type Formed = i32; + type Context = (); } // - @@ -248,6 +254,9 @@ fn custom_definition_custom_end() { type Types = Return13; type End = former::FormingEndClosure< < Self as former::FormerDefinition >::Types >; + type Storage = Vec< String >; + type Formed = i32; + type Context = (); } fn return_13( _storage : Vec< String >, _context : Option< () > ) -> i32 diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 515f8c86bc..18a16fc490 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -45,7 +45,10 @@ impl< K, > Command< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, #[ inline( always ) ] pub fn former() -> CommandFormer< K, CommandFormerDefinition< K, (), Command< K, >, former :: ReturnPreformed > > { - CommandFormer :: < K, CommandFormerDefinition< K, (), Command< K, >, former :: ReturnPreformed > > :: new( former :: ReturnPreformed ) + CommandFormer + :: + < K, CommandFormerDefinition< K, (), Command< K, >, former :: ReturnPreformed > > + :: new( former :: ReturnPreformed ) } } @@ -55,7 +58,10 @@ pub struct CommandFormerDefinitionTypes< K, __Context = (), __Formed = Command< _phantom : core :: marker :: PhantomData< ( K, __Context, __Formed ) >, } -impl< K, __Context, __Formed, > :: core :: default :: Default for CommandFormerDefinitionTypes< K, __Context, __Formed, > where K : core :: hash :: Hash + std :: cmp :: Eq, +impl< K, __Context, __Formed, > :: core :: default :: Default +for CommandFormerDefinitionTypes< K, __Context, __Formed, > +where + K : core :: hash :: Hash + std :: cmp :: Eq, { fn default() -> Self { @@ -66,7 +72,10 @@ impl< K, __Context, __Formed, > :: core :: default :: Default for CommandFormerD } } -impl< K, __Context, __Formed, > former :: FormerDefinitionTypes for CommandFormerDefinitionTypes< K, __Context, __Formed, > where K : core :: hash :: Hash + std :: cmp :: Eq, +impl< K, __Context, __Formed, > former :: FormerDefinitionTypes +for CommandFormerDefinitionTypes< K, __Context, __Formed, > +where + K : core :: hash :: Hash + std :: cmp :: Eq, { type Storage = CommandFormerStorage< K, >; type Formed = __Formed; @@ -74,12 +83,18 @@ impl< K, __Context, __Formed, > former :: FormerDefinitionTypes for CommandForme } #[ derive( Debug ) ] -pub struct CommandFormerDefinition< K, __Context = (), __Formed = Command< K, >, __End = former :: ReturnPreformed, > where K : core :: hash :: Hash + std :: cmp :: Eq, +pub struct CommandFormerDefinition +< K, __Context = (), __Formed = Command< K, >, __End = former :: ReturnPreformed, > +where + K : core :: hash :: Hash + std :: cmp :: Eq, { _phantom : core :: marker :: PhantomData< ( K, __Context, __Formed, __End ) >, } -impl< K, __Context, __Formed, __End, > :: core :: default :: Default for CommandFormerDefinition< K, __Context, __Formed, __End, > where K : core :: hash :: Hash + std :: cmp :: Eq, +impl< K, __Context, __Formed, __End, > :: core :: default :: Default +for CommandFormerDefinition< K, __Context, __Formed, __End, > +where + K : core :: hash :: Hash + std :: cmp :: Eq, { fn default() -> Self { @@ -90,10 +105,17 @@ impl< K, __Context, __Formed, __End, > :: core :: default :: Default for Command } } -impl< K, __Context, __Formed, __End, > former :: FormerDefinition for CommandFormerDefinition< K, __Context, __Formed, __End, > where __End : former :: FormingEnd< CommandFormerDefinitionTypes< K, __Context, __Formed, > >, K : core :: hash :: Hash + std :: cmp :: Eq, +impl< K, __Context, __Formed, __End, > former :: FormerDefinition +for CommandFormerDefinition< K, __Context, __Formed, __End, > +where + __End : former :: FormingEnd< CommandFormerDefinitionTypes< K, __Context, __Formed, > >, + K : core :: hash :: Hash + std :: cmp :: Eq, { type Types = CommandFormerDefinitionTypes< K, __Context, __Formed, >; type End = __End; + type Storage = CommandFormerStorage< K, >; + type Formed = __Formed; + type Context = __Context; } // pub type CommandFormerWithClosure< K, __Context, __Formed, > = CommandFormerDefinition< K, __Context, __Formed, former :: FormingEndClosure< CommandFormerDefinitionTypes< K, __Context, __Formed, > > >; diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 9dd8fefeb7..92044c9b30 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -61,11 +61,16 @@ impl< 'a, Context, Formed, End > Default for Struct1FormerDefinition< 'a, Contex } } -impl< 'a, Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< 'a, Context, Formed, End > -where End : former::FormingEnd< Struct1FormerDefinitionTypes< 'a, Context, Formed > > +impl< 'a, Context, Formed, End > former::FormerDefinition +for Struct1FormerDefinition< 'a, Context, Formed, End > +where + End : former::FormingEnd< Struct1FormerDefinitionTypes< 'a, Context, Formed > > { type Types = Struct1FormerDefinitionTypes< 'a, Context, Formed >; type End = End; + type Storage = Struct1FormerStorage< 'a >; + type Formed = Formed; + type Context = Context; } // pub type Struct1FormerWithClosure< 'a, Context, Formed > = diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index c3c38ed7c2..45dc72d78a 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -22,8 +22,8 @@ pub struct Parameters impl< Definition > former::FormerBegin< Definition > for DescriptorFormer< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = DescriptorFormerStorage >, + Definition : former::FormerDefinition< Storage = DescriptorFormerStorage >, + // Definition::Types : former::FormerDefinitionTypes< Storage = DescriptorFormerStorage >, { #[ inline( always ) ] @@ -57,7 +57,14 @@ where Formed = Self, Context = Self, >, - Definition2 : former::FormerDefinition< Types = Types2, End = former::FormingEndClosure< Types2 > >, + Definition2 : former::FormerDefinition + < + Types = Types2, + End = former::FormingEndClosure< Types2 >, + Storage = DescriptorFormerStorage, + Formed = Self, + Context = Self, + >, Definition2::End : former::FormingEnd< Definition2::Types >, Former2 : former::FormerBegin < @@ -91,7 +98,14 @@ where Formed = Self, Context = Self, >, - Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Definition > >, + Definition2 : former::FormerDefinition + < + Types = Types2, + End = ParametersDescriptorAddElementOnEnd< Definition >, + Storage = DescriptorFormerStorage, + Formed = Self, + Context = Self, + >, Former2 : former::FormerBegin< Definition2 >, { Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 441d91fe6e..32b3d18294 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -8,61 +8,61 @@ mod former_tests use super::*; // xxx : uncomment -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_common; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_vec; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_hashset; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_hashmap; -// + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_common; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_vec; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashset; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashmap; + mod a_basic_manual; - // mod a_basic; -// mod a_primitives_manual; -// mod a_primitives; -// mod a_containers_without_subformer; -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer_manual; -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer ; -// -// mod attribute_default_container; -// mod attribute_default_primitive; -// mod attribute_perform; -// mod attribute_setter; -// mod attribute_alias; -// // mod attribute_feature; // xxx : write test -// -// mod string_slice_manual; -// mod string_slice; -// mod unsigned_primitive_types; -// mod default_user_type; -// mod user_type_no_default; -// mod user_type_no_debug; -// -// mod name_collision_former_hashmap_without_parameter; -// mod name_collision_former_vector_without_parameter; -// mod name_collisions; -// mod name_collision_context; -// mod name_collision_end; -// mod name_collision_on_end; -// -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_manual; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_imm; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_where; -// -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_basic; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_custom; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_custom_experimental; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_shortcut; + mod a_basic; + mod a_primitives_manual; + mod a_primitives; + mod a_containers_without_subformer; + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer_manual; + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer ; + + mod attribute_default_container; + mod attribute_default_primitive; + mod attribute_perform; + mod attribute_setter; + mod attribute_alias; + // mod attribute_feature; // xxx : write test + + mod string_slice_manual; + mod string_slice; + mod unsigned_primitive_types; + mod default_user_type; + mod user_type_no_default; + mod user_type_no_debug; + + mod name_collision_former_hashmap_without_parameter; + mod name_collision_former_vector_without_parameter; + mod name_collisions; + mod name_collision_context; + mod name_collision_end; + mod name_collision_on_end; + + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_manual; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_imm; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_where; + + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod subformer_basic; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod subformer_custom; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod subformer_custom_experimental; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_shortcut; // xxx : uncomment } @@ -109,13 +109,13 @@ only_for_terminal_module! fn former_trybuild() { - println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); - let t = test_tools::compiletime::TestCases::new(); - +// println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); +// let t = test_tools::compiletime::TestCases::new(); +// // zzz : uncomment - t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); - t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); - t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); + // t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); + // t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); + // t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index a1be106ac4..7ee8af10b9 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -937,6 +937,7 @@ Result< TokenStream > // Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) // } +// xxx : uncomment // /// Handles the completion of and element of subformer's container. // pub struct ParametersDescriptorAddElementOnEnd< Definition > // { @@ -1396,6 +1397,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { type Types = #former_definition_types < #former_definition_type_generics_ty >; type End = __End; + type Storage = #former_storage < #struct_generics_ty >; + type Formed = __Formed; + type Context = __Context; } // = storage From acfab7dd2267ae13bb72d7adfc71e89d5847d0ab Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 11:45:15 +0300 Subject: [PATCH 271/533] former : experimenting --- module/core/former/src/axiomatic.rs | 10 +++ .../inc/former_tests/subformer_shortcut.rs | 80 +++++++++---------- module/core/former/tests/inc/mod.rs | 4 +- module/core/former_meta/src/derive/former.rs | 16 ++-- 4 files changed, 57 insertions(+), 53 deletions(-) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 4e69f3e6b1..0e1f235ffa 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -17,6 +17,16 @@ pub trait StoragePreform fn preform( self ) -> Self::Preformed; } +pub trait EntityToFormer +{ + type Storage; + type Former; + // type Formed; + // type Context; + // type Types; + // type Definition; +} + /// zzz : write description pub trait FormerDefinitionTypes : Sized { diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 45dc72d78a..92311789f6 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -10,15 +10,32 @@ pub struct Descriptor is_mandatory : bool, } +impl former::EntityToFormer for Descriptor +where + Self : Sized, +{ + type Storage = DescriptorFormerStorage; + type Former = DescriptorFormer; +} + /// Parameters required for the template. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] pub struct Parameters { + // xxx : is definition as argument fine? #[ subformer( former::VectorDefinition ) ] // #[ element_subformer( Descriptor ) ] descriptors : Vec< Descriptor >, } +impl former::EntityToFormer for Parameters +where + Self : Sized, +{ + type Storage = ParametersFormerStorage; + type Former = ParametersFormer; +} + impl< Definition > former::FormerBegin< Definition > for DescriptorFormer< Definition > where @@ -43,10 +60,9 @@ where impl< Definition > ParametersFormer< Definition > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = ParametersFormerStorage >, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parameters as former::EntityToFormer >::Storage >, { - #[ inline( always ) ] pub fn _descriptor_former_with_closure< Former2, Definition2, Types2 >( self ) -> Former2 @@ -89,26 +105,25 @@ where } #[ inline( always ) ] - pub fn _descriptor_former_set2< Former2, Definition2, Types2 >( self ) -> + pub fn _descriptor_former_set2< Former2, Definition2 >( self ) -> Former2 where - Types2 : former::FormerDefinitionTypes + Definition2 : former::FormerDefinition < - Storage = DescriptorFormerStorage, + End = ParametersAddDescriptorOnEnd< Definition >, + Storage = < Descriptor as former::EntityToFormer >::Storage, Formed = Self, Context = Self, >, - Definition2 : former::FormerDefinition + Definition2::Types : former::FormerDefinitionTypes < - Types = Types2, - End = ParametersDescriptorAddElementOnEnd< Definition >, - Storage = DescriptorFormerStorage, + Storage = < Descriptor as former::EntityToFormer >::Storage, Formed = Self, Context = Self, >, Former2 : former::FormerBegin< Definition2 >, { - Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) + Former2::_begin( None, Some( self ), ParametersAddDescriptorOnEnd::default() ) } // #[ inline( always ) ] @@ -122,10 +137,10 @@ where // // Formed = Self, // // Context = Self, // // >, - // // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Definition > >, + // // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorOnEnd< Definition > >, // // Former2 : SubFormerTrait< Self, Definition, Definition2, Types2 >, // { - // Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) + // Former2::_begin( None, Some( self ), ParametersAddDescriptorOnEnd::default() ) // } // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help @@ -135,32 +150,12 @@ where DescriptorSubformer< Self, impl DescriptorSubformerEnd< Self > > { self._descriptor_former_set2 - ::< DescriptorFormer< _ >, _, _, >() + ::< DescriptorFormer< _ >, _, >() .name( name ) } } -pub trait EntityToFormer -{ - type Storage; - type Former; - // type Formed; - // type Context; - // type Types; - // type Definition; -} - -impl EntityToFormer for Descriptor -{ - type Storage = DescriptorFormerStorage; - type Former = DescriptorFormer; - // type Formed; - // type Context; - // type Types; - // type Definition; -} - // pub trait SubFormerTrait2 // where // < Self::Definition2 as former::FormerDefinition >::Types : former::FormerDefinitionTypes @@ -175,7 +170,7 @@ impl EntityToFormer for Descriptor // type Definition; // type Definition2 : former::FormerDefinition // < -// End = ParametersDescriptorAddElementOnEnd +// End = ParametersAddDescriptorOnEnd // < // < Self::Definition2 as former::FormerDefinition >::Types, // Self::Definition, @@ -192,7 +187,7 @@ impl EntityToFormer for Descriptor // Formed = Former, // Context = Former, // >, -// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Definition > >, +// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorOnEnd< Definition > >, // Self : former::FormerBegin< Definition2 >, // { // } @@ -206,19 +201,20 @@ impl EntityToFormer for Descriptor // Formed = Former, // Context = Former, // >, -// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Definition > >, +// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorOnEnd< Definition > >, // Self : former::FormerBegin< Definition2 >, // { // } +// zzz : improve description /// Handles the completion of and element of subformer's container. -pub struct ParametersDescriptorAddElementOnEnd< Definition > +pub struct ParametersAddDescriptorOnEnd< Definition > { _phantom : core::marker::PhantomData< fn( Definition ) >, } impl< Definition > Default -for ParametersDescriptorAddElementOnEnd< Definition > +for ParametersAddDescriptorOnEnd< Definition > { #[ inline( always ) ] fn default() -> Self @@ -231,18 +227,16 @@ for ParametersDescriptorAddElementOnEnd< Definition > } impl< Types2, Definition > former::FormingEnd< Types2, > -for ParametersDescriptorAddElementOnEnd< Definition > +for ParametersAddDescriptorOnEnd< Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes < - Storage = ParametersFormerStorage, + Storage = < Parameters as former::EntityToFormer >::Storage, >, Types2 : former::FormerDefinitionTypes < - // Storage = DescriptorFormerStorage, - // Storage = < DescriptorFormerDefinitionTypes as former::FormerDefinitionTypes >::Storage, - Storage = < Descriptor as EntityToFormer >::Storage, + Storage = < Descriptor as former::EntityToFormer >::Storage, Formed = ParametersFormer< Definition >, Context = ParametersFormer< Definition >, >, diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 32b3d18294..1b787a9734 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -7,7 +7,6 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; -// xxx : uncomment #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod container_former_common; #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] @@ -32,7 +31,7 @@ mod former_tests mod attribute_perform; mod attribute_setter; mod attribute_alias; - // mod attribute_feature; // xxx : write test + // mod attribute_feature; // zzz : write test mod string_slice_manual; mod string_slice; @@ -63,7 +62,6 @@ mod former_tests mod subformer_custom_experimental; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_shortcut; - // xxx : uncomment } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 7ee8af10b9..b919e37bdc 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -931,21 +931,23 @@ Result< TokenStream > // Formed = Self, // Context = Self, // >, - // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersDescriptorAddElementOnEnd< Types2, Definition > >, + // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorOnEnd< Types2, Definition > >, // Former2 : former::FormerBegin< Definition2 >, // { - // Former2::_begin( None, Some( self ), ParametersDescriptorAddElementOnEnd::default() ) + // Former2::_begin( None, Some( self ), ParametersAddDescriptorOnEnd::default() ) // } // xxx : uncomment + +// // zzz : improve description // /// Handles the completion of and element of subformer's container. -// pub struct ParametersDescriptorAddElementOnEnd< Definition > +// pub struct ParametersAddDescriptorOnEnd< Definition > // { // _phantom : core::marker::PhantomData< fn( Definition ) >, // } // // impl< Definition > Default -// for ParametersDescriptorAddElementOnEnd< Definition > +// for ParametersAddDescriptorOnEnd< Definition > // { // #[ inline( always ) ] // fn default() -> Self @@ -958,16 +960,16 @@ Result< TokenStream > // } // // impl< Types2, Definition > former::FormingEnd< Types2, > -// for ParametersDescriptorAddElementOnEnd< Definition > +// for ParametersAddDescriptorOnEnd< Definition > // where // Definition : former::FormerDefinition, // Definition::Types : former::FormerDefinitionTypes // < -// Storage = ParametersFormerStorage, +// Storage = < Parameters as former::EntityToFormer >::Storage, // >, // Types2 : former::FormerDefinitionTypes // < -// Storage = DescriptorFormerStorage, +// Storage = < Descriptor as former::EntityToFormer >::Storage, // Formed = ParametersFormer< Definition >, // Context = ParametersFormer< Definition >, // >, From 19811f235bcc94a23f33cfb9e38d51707e4849e9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 11:58:03 +0300 Subject: [PATCH 272/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 29 ++++++++++--------- module/core/former_meta/src/derive/former.rs | 11 +++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 92311789f6..521beeae62 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -10,13 +10,14 @@ pub struct Descriptor is_mandatory : bool, } -impl former::EntityToFormer for Descriptor -where - Self : Sized, -{ - type Storage = DescriptorFormerStorage; - type Former = DescriptorFormer; -} +// xxx : write test of to check that former::EntityToFormer is implemented for a struct +// impl former::EntityToFormer for Descriptor +// where +// Self : Sized, +// { +// type Storage = DescriptorFormerStorage; +// type Former = DescriptorFormer; +// } /// Parameters required for the template. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] @@ -28,13 +29,13 @@ pub struct Parameters descriptors : Vec< Descriptor >, } -impl former::EntityToFormer for Parameters -where - Self : Sized, -{ - type Storage = ParametersFormerStorage; - type Former = ParametersFormer; -} +// impl former::EntityToFormer for Parameters +// where +// Self : Sized, +// { +// type Storage = ParametersFormerStorage; +// type Former = ParametersFormer; +// } impl< Definition > former::FormerBegin< Definition > for DescriptorFormer< Definition > diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index b919e37bdc..5076d3dde0 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1329,6 +1329,17 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } + // = entity to former + + impl< #struct_generics_impl > former::EntityToFormer for #stru < #struct_generics_ty > + where + Self : Sized, + #struct_generics_where + { + type Storage = #former_storage < #struct_generics_ty >; + type Former = #former < #struct_generics_ty >; + } + // = definition types #[ derive( Debug ) ] From 84a850e1baf656db1c3d5a20c73a0d61b2e90927 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 12:09:37 +0300 Subject: [PATCH 273/533] former : experimenting --- module/core/former/src/axiomatic.rs | 4 ++++ .../tests/inc/former_tests/a_basic_manual.rs | 10 ++++++++++ .../tests/inc/former_tests/only_test/basic.rs | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index 0e1f235ffa..c1151fb6a1 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -17,9 +17,13 @@ pub trait StoragePreform fn preform( self ) -> Self::Preformed; } +// zzz : improve documentation +/// Map type of entity to storage and former. pub trait EntityToFormer { + /// Storage to store fields of entity during formign process. type Storage; + /// Former with default definition type Former; // type Formed; // type Context; diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 65c743e7ab..4a26e4ec01 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -23,6 +23,16 @@ impl Struct1 } +// = entity to former + +impl former::EntityToFormer for Struct1 +where + Self : Sized, +{ + type Storage = Struct1FormerStorage; + type Former = Struct1Former; +} + // = definition types #[ derive( Debug ) ] diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index d2ffa9df6e..c6e4afb456 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -34,6 +34,23 @@ tests_impls! // + fn entity_to_former() + { + + let got = < Struct1 as former::EntityToFormer >::Former::new_precise( former::ReturnPreformed ) + .int_1( 13 ) + .form(); + let exp = Struct1 { int_1 : 13 }; + a_id!( got, exp ); + + let got = < Struct1 as former::EntityToFormer >::Storage::default(); + let exp = < Struct1 as former::EntityToFormer >::Former::new_precise( former::ReturnPreformed ); + a_id!( got.int_1, exp.storage.int_1 ); + + } + + // + fn custom_definition_params() { @@ -514,6 +531,7 @@ tests_impls! tests_index! { internals, + entity_to_former, custom_definition_params, begin_coercing, begin_precise, From 76e0c67eec0816447431f5566cf9ea22b92892b7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 12:13:29 +0300 Subject: [PATCH 274/533] former : experimenting --- .../core/former/tests/inc/former_tests/subformer_shortcut.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 521beeae62..cbc18fbfa6 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -10,7 +10,6 @@ pub struct Descriptor is_mandatory : bool, } -// xxx : write test of to check that former::EntityToFormer is implemented for a struct // impl former::EntityToFormer for Descriptor // where // Self : Sized, @@ -53,7 +52,7 @@ where ) -> Self { debug_assert!( storage.is_none() ); - Self::begin_coercing( None, context, on_end ) + Self::begin_precise( None, context, on_end ) } } From 370846e16784cdf4b10b4b229e7cdfc3e5be78e9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 12:38:14 +0300 Subject: [PATCH 275/533] former : experimenting --- module/core/former/src/axiomatic.rs | 253 ------------------ module/core/former/src/container.rs | 2 +- module/core/former/src/definition.rs | 32 +++ module/core/former/src/forming.rs | 200 ++++++++++++++ module/core/former/src/lib.rs | 20 +- module/core/former/src/storage.rs | 18 ++ module/core/former/src/vector.rs | 2 +- .../a_containers_with_subformer_manual.rs | 6 +- .../parametrized_struct_manual.rs | 2 +- .../inc/former_tests/subformer_shortcut.rs | 8 +- module/core/former_meta/src/derive/former.rs | 2 +- 11 files changed, 279 insertions(+), 266 deletions(-) create mode 100644 module/core/former/src/definition.rs create mode 100644 module/core/former/src/forming.rs create mode 100644 module/core/former/src/storage.rs diff --git a/module/core/former/src/axiomatic.rs b/module/core/former/src/axiomatic.rs index c1151fb6a1..e69de29bb2 100644 --- a/module/core/former/src/axiomatic.rs +++ b/module/core/former/src/axiomatic.rs @@ -1,253 +0,0 @@ - -/// zzz : write description -pub trait Storage : ::core::default::Default -{ - type Formed; -} - -/// zzz : write description -// pub trait StoragePreform : Storage -// { -// fn preform( self ) -> Self::Formed; -// } - -pub trait StoragePreform -{ - type Preformed; - fn preform( self ) -> Self::Preformed; -} - -// zzz : improve documentation -/// Map type of entity to storage and former. -pub trait EntityToFormer -{ - /// Storage to store fields of entity during formign process. - type Storage; - /// Former with default definition - type Former; - // type Formed; - // type Context; - // type Types; - // type Definition; -} - -/// zzz : write description -pub trait FormerDefinitionTypes : Sized -{ - type Storage : Default; - type Formed; - type Context; -} - -/// zzz : write description -pub trait FormerDefinition : Sized -{ - type Types : FormerDefinitionTypes< Storage = Self::Storage, Formed = Self::Formed, Context = Self::Context >; - type End : FormingEnd< Self::Types >; - type Storage : Default; - type Formed; - type Context; -} - -/// Defines a handler for the end of a subforming process, enabling the return of the original context. -/// -/// This trait is designed to be flexible, allowing for various end-of-forming behaviors in builder patterns. -/// Implementors can define how to transform or pass through the context during the forming process's completion. -/// -/// # Parameters -/// - `Storage`: The type of the container being processed. -/// - `Context`: The type of the context that might be altered or returned upon completion. - -pub trait FormingEnd< Definition : FormerDefinitionTypes > -{ - /// Called at the end of the subforming process to return the modified or original context. - /// - /// # Parameters - /// - `container`: The container being processed. - /// - `context`: Optional context to be transformed or returned. - /// - /// # Returns - /// Returns the transformed or original context based on the implementation. - fn call( &self, storage : Definition::Storage, context : core::option::Option< Definition::Context > ) -> Definition::Formed; -} - -impl< Definition, F > FormingEnd< Definition > for F -where - F : Fn( Definition::Storage, core::option::Option< Definition::Context > ) -> Definition::Formed, - Definition : FormerDefinitionTypes, -{ - #[ inline( always ) ] - fn call( &self, storage : Definition::Storage, context : core::option::Option< Definition::Context > ) -> Definition::Formed - { - self( storage, context ) - } -} - -/// A `FormingEnd` implementation that returns the formed container itself instead of the context. -/// -/// This struct is useful when the forming process should result in the formed container being returned directly, -/// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. -#[ derive( Debug, Default ) ] -pub struct ReturnPreformed; - -impl< Definition > FormingEnd< Definition > -for ReturnPreformed -where - Definition::Storage : StoragePreform< Preformed = Definition::Formed >, - Definition : FormerDefinitionTypes, -{ - #[ inline( always ) ] - fn call( &self, storage : Definition::Storage, _context : core::option::Option< Definition::Context > ) -> Definition::Formed - { - storage.preform() - } -} - -/// zzz : update description -#[ derive( Debug, Default ) ] -pub struct ReturnStorage; - -impl< Definition, T > FormingEnd< Definition > -for ReturnStorage -where - Definition : FormerDefinitionTypes< Context = (), Storage = T, Formed = T >, - // Definition::End : FormingEnd< Definition >, - // Definition::End : Self, - // Definition::Storage : Default, -{ - #[ inline( always ) ] - fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed - { - storage - } -} - -// zzz : improve description -/// Use `NoEnd` to fill parameter FormingEnd in struct where parameter exists, but it is not needed. -/// It might be needed if the same struct is used as `FormerDefinitionTypes` and as `FormerDefinition`, because the first one does not have information aboud End function. -/// Similar logic which `std::marker::PhantomData` has behind. -#[ derive( Debug, Default ) ] -pub struct NoEnd; - -impl< Definition > FormingEnd< Definition > -for NoEnd -where - Definition : FormerDefinitionTypes, -{ - #[ inline( always ) ] - fn call( &self, _storage : Definition::Storage, _context : core::option::Option< Definition::Context > ) -> Definition::Formed - { - unreachable!(); - } -} - -/// A wrapper around a closure to be used as a `FormingEnd`. -/// -/// This struct allows for dynamic dispatch of a closure that matches the -/// `FormingEnd` trait's `call` method signature. It is useful for cases where -/// a closure needs to be stored or passed around as an object implementing -/// `FormingEnd`. -#[ cfg( not( feature = "no_std" ) ) ] -pub struct FormingEndClosure< Definition : FormerDefinitionTypes > -{ - closure : Box< dyn Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed >, - _marker : std::marker::PhantomData< Definition::Storage >, -} - -impl< T, Definition > From< T > for FormingEndClosure< Definition > -where - T : Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed + 'static, - Definition : FormerDefinitionTypes, -{ - #[ inline( always ) ] - fn from( closure : T ) -> Self - { - Self - { - closure : Box::new( closure ), - _marker : std::marker::PhantomData - } - } -} - -#[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinitionTypes > FormingEndClosure< Definition > -{ - /// Constructs a new `FormingEndClosure` with the provided closure. - /// - /// # Parameters - /// - /// * `closure` - A closure that matches the expected signature for transforming a container - /// and context into a new context. This closure is stored and called by the - /// `call` method of the `FormingEnd` trait implementation. - /// - /// # Returns - /// - /// Returns an instance of `FormingEndClosure` encapsulating the provided closure. - pub fn new( closure : impl Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed + 'static ) -> Self - { - Self - { - closure : Box::new( closure ), - _marker : std::marker::PhantomData - } - } -} - -#[ cfg( not( feature = "no_std" ) ) ] -use std::fmt; -#[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinitionTypes > fmt::Debug for FormingEndClosure< Definition > -{ - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result - { - f.debug_struct( "FormingEndClosure" ) - .field( "closure", &format_args!{ "- closure -" } ) - .field( "_marker", &self._marker ) - .finish() - } -} - -#[ cfg( not( feature = "no_std" ) ) ] -impl< Definition : FormerDefinitionTypes > FormingEnd< Definition > -for FormingEndClosure< Definition > -{ - fn call( &self, storage : Definition::Storage, context : Option< Definition::Context > ) -> Definition::Formed - { - ( self.closure )( storage, context ) - } -} - -// - -/// A trait for initiating a structured subforming process with contextual and intermediary storage linkage. -/// -/// This trait facilitates the creation of a subformer that carries through a builder pattern chain, -/// utilizing intermediary storage for accumulating state or data before finally transforming it into -/// a `Formed` structure. It is designed for scenarios where a multi-step construction or transformation -/// process benefits from maintaining both transient state (`Storage`) and contextual information (`Context`), -/// before concluding with the generation of a final product (`Formed`). -/// -/// The `FormerBegin` trait, by decoupling `Storage` from `Formed` and introducing a contextual layer, enables -/// sophisticated and flexible construction patterns conducive to complex data transformations or object creation -/// sequences within builder patterns. - -// zzz : update description -pub trait FormerBegin< Definition : FormerDefinition > -{ - - /// Launches the subforming process with an initial storage and context, setting up an `on_end` completion handler. - /// - /// # Parameters - /// - /// * `storage` - An optional initial state for the intermediary storage structure. - /// * `context` - An optional initial setting providing contextual information for the subforming process. - /// * `on_end` - A completion handler responsible for transforming the accumulated `Storage` into the final `Formed` structure. - fn _begin - ( - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Definition::Context >, - on_end : Definition::End, - ) -> Self; - -} diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index ec23cdaa20..3ead72aca0 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -368,7 +368,7 @@ where // type End = Definition::End; #[ inline( always ) ] - fn _begin + fn former_begin ( storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs new file mode 100644 index 0000000000..df31395922 --- /dev/null +++ b/module/core/former/src/definition.rs @@ -0,0 +1,32 @@ + +// zzz : improve documentation +/// Map type of entity to storage and former. +pub trait EntityToFormer +{ + /// Storage to store fields of entity during formign process. + type Storage; + /// Former with default definition + type Former; + // type Formed; + // type Context; + // type Types; + // type Definition; +} + +/// zzz : write description +pub trait FormerDefinitionTypes : Sized +{ + type Storage : Default; + type Formed; + type Context; +} + +/// zzz : write description +pub trait FormerDefinition : Sized +{ + type Types : crate::FormerDefinitionTypes< Storage = Self::Storage, Formed = Self::Formed, Context = Self::Context >; + type End : crate::FormingEnd< Self::Types >; + type Storage : Default; + type Formed; + type Context; +} diff --git a/module/core/former/src/forming.rs b/module/core/former/src/forming.rs new file mode 100644 index 0000000000..e94e059258 --- /dev/null +++ b/module/core/former/src/forming.rs @@ -0,0 +1,200 @@ + +/// Defines a handler for the end of a subforming process, enabling the return of the original context. +/// +/// This trait is designed to be flexible, allowing for various end-of-forming behaviors in builder patterns. +/// Implementors can define how to transform or pass through the context during the forming process's completion. +/// +/// # Parameters +/// - `Storage`: The type of the container being processed. +/// - `Context`: The type of the context that might be altered or returned upon completion. + +pub trait FormingEnd< Definition : crate::FormerDefinitionTypes > +{ + /// Called at the end of the subforming process to return the modified or original context. + /// + /// # Parameters + /// - `container`: The container being processed. + /// - `context`: Optional context to be transformed or returned. + /// + /// # Returns + /// Returns the transformed or original context based on the implementation. + fn call( &self, storage : Definition::Storage, context : core::option::Option< Definition::Context > ) -> Definition::Formed; +} + +impl< Definition, F > FormingEnd< Definition > for F +where + F : Fn( Definition::Storage, core::option::Option< Definition::Context > ) -> Definition::Formed, + Definition : crate::FormerDefinitionTypes, +{ + #[ inline( always ) ] + fn call( &self, storage : Definition::Storage, context : core::option::Option< Definition::Context > ) -> Definition::Formed + { + self( storage, context ) + } +} + +/// A `FormingEnd` implementation that returns the formed container itself instead of the context. +/// +/// This struct is useful when the forming process should result in the formed container being returned directly, +/// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. +#[ derive( Debug, Default ) ] +pub struct ReturnPreformed; + +impl< Definition > FormingEnd< Definition > +for ReturnPreformed +where + Definition::Storage : crate::StoragePreform< Preformed = Definition::Formed >, + Definition : crate::FormerDefinitionTypes, +{ + #[ inline( always ) ] + fn call( &self, storage : Definition::Storage, _context : core::option::Option< Definition::Context > ) -> Definition::Formed + { + crate::StoragePreform::preform( storage ) + } +} + +/// zzz : update description +#[ derive( Debug, Default ) ] +pub struct ReturnStorage; + +impl< Definition, T > FormingEnd< Definition > +for ReturnStorage +where + Definition : crate::FormerDefinitionTypes< Context = (), Storage = T, Formed = T >, +{ + #[ inline( always ) ] + fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed + { + storage + } +} + +// zzz : improve description +/// Use `NoEnd` to fill parameter FormingEnd in struct where parameter exists, but it is not needed. +/// It might be needed if the same struct is used as `FormerDefinitionTypes` and as `FormerDefinition`, because the first one does not have information aboud End function. +/// Similar logic which `std::marker::PhantomData` has behind. +#[ derive( Debug, Default ) ] +pub struct NoEnd; + +impl< Definition > FormingEnd< Definition > +for NoEnd +where + Definition : crate::FormerDefinitionTypes, +{ + #[ inline( always ) ] + fn call( &self, _storage : Definition::Storage, _context : core::option::Option< Definition::Context > ) -> Definition::Formed + { + unreachable!(); + } +} + +/// A wrapper around a closure to be used as a `FormingEnd`. +/// +/// This struct allows for dynamic dispatch of a closure that matches the +/// `FormingEnd` trait's `call` method signature. It is useful for cases where +/// a closure needs to be stored or passed around as an object implementing +/// `FormingEnd`. +#[ cfg( not( feature = "no_std" ) ) ] +pub struct FormingEndClosure< Definition : crate::FormerDefinitionTypes > +{ + closure : Box< dyn Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed >, + _marker : std::marker::PhantomData< Definition::Storage >, +} + +impl< T, Definition > From< T > for FormingEndClosure< Definition > +where + T : Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed + 'static, + Definition : crate::FormerDefinitionTypes, +{ + #[ inline( always ) ] + fn from( closure : T ) -> Self + { + Self + { + closure : Box::new( closure ), + _marker : std::marker::PhantomData + } + } +} + +#[ cfg( not( feature = "no_std" ) ) ] +impl< Definition : crate::FormerDefinitionTypes > FormingEndClosure< Definition > +{ + /// Constructs a new `FormingEndClosure` with the provided closure. + /// + /// # Parameters + /// + /// * `closure` - A closure that matches the expected signature for transforming a container + /// and context into a new context. This closure is stored and called by the + /// `call` method of the `FormingEnd` trait implementation. + /// + /// # Returns + /// + /// Returns an instance of `FormingEndClosure` encapsulating the provided closure. + pub fn new( closure : impl Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed + 'static ) -> Self + { + Self + { + closure : Box::new( closure ), + _marker : std::marker::PhantomData + } + } +} + +#[ cfg( not( feature = "no_std" ) ) ] +use std::fmt; +#[ cfg( not( feature = "no_std" ) ) ] +impl< Definition : crate::FormerDefinitionTypes > fmt::Debug for FormingEndClosure< Definition > +{ + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f.debug_struct( "FormingEndClosure" ) + .field( "closure", &format_args!{ "- closure -" } ) + .field( "_marker", &self._marker ) + .finish() + } +} + +#[ cfg( not( feature = "no_std" ) ) ] +impl< Definition : crate::FormerDefinitionTypes > FormingEnd< Definition > +for FormingEndClosure< Definition > +{ + fn call( &self, storage : Definition::Storage, context : Option< Definition::Context > ) -> Definition::Formed + { + ( self.closure )( storage, context ) + } +} + +// + +/// A trait for initiating a structured subforming process with contextual and intermediary storage linkage. +/// +/// This trait facilitates the creation of a subformer that carries through a builder pattern chain, +/// utilizing intermediary storage for accumulating state or data before finally transforming it into +/// a `Formed` structure. It is designed for scenarios where a multi-step construction or transformation +/// process benefits from maintaining both transient state (`Storage`) and contextual information (`Context`), +/// before concluding with the generation of a final product (`Formed`). +/// +/// The `FormerBegin` trait, by decoupling `Storage` from `Formed` and introducing a contextual layer, enables +/// sophisticated and flexible construction patterns conducive to complex data transformations or object creation +/// sequences within builder patterns. + +// zzz : update description +pub trait FormerBegin< Definition : crate::FormerDefinition > +{ + + /// Launches the subforming process with an initial storage and context, setting up an `on_end` completion handler. + /// + /// # Parameters + /// + /// * `storage` - An optional initial state for the intermediary storage structure. + /// * `context` - An optional initial setting providing contextual information for the subforming process. + /// * `on_end` - A completion handler responsible for transforming the accumulated `Storage` into the final `Formed` structure. + fn former_begin + ( + storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Definition::Context >, + on_end : Definition::End, + ) -> Self; + +} diff --git a/module/core/former/src/lib.rs b/module/core/former/src/lib.rs index 02106c368f..0e20de312b 100644 --- a/module/core/former/src/lib.rs +++ b/module/core/former/src/lib.rs @@ -14,6 +14,18 @@ #[ cfg( feature = "enabled" ) ] #[ cfg( feature = "derive_former" ) ] mod axiomatic; +/// Forming process. +#[ cfg( feature = "enabled" ) ] +#[ cfg( feature = "derive_former" ) ] +mod definition; +/// Forming process. +#[ cfg( feature = "enabled" ) ] +#[ cfg( feature = "derive_former" ) ] +mod forming; +/// Storage. +#[ cfg( feature = "enabled" ) ] +#[ cfg( feature = "derive_former" ) ] +mod storage; /// Interface for containers. #[ cfg( feature = "enabled" ) ] @@ -96,7 +108,13 @@ pub mod exposed #[ allow( unused_imports ) ] #[ cfg( feature = "enabled" ) ] #[ cfg( feature = "derive_former" ) ] - pub use super::axiomatic::*; + pub use super:: + { + axiomatic::*, + definition::*, + forming::*, + storage::*, + }; #[ doc( inline ) ] #[ allow( unused_imports ) ] diff --git a/module/core/former/src/storage.rs b/module/core/former/src/storage.rs new file mode 100644 index 0000000000..2a175dd7d7 --- /dev/null +++ b/module/core/former/src/storage.rs @@ -0,0 +1,18 @@ + +/// zzz : write description +pub trait Storage : ::core::default::Default +{ + type Formed; +} + +/// zzz : write description +// pub trait StoragePreform : Storage +// { +// fn preform( self ) -> Self::Formed; +// } + +pub trait StoragePreform +{ + type Preformed; + fn preform( self ) -> Self::Preformed; +} diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index ea16c631d0..a9f282efb9 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -1,5 +1,5 @@ use super::*; -use axiomatic::*; +// use axiomatic::*; #[ allow( unused ) ] use collection_tools::Vec; diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 17b28c55c7..136c6a4012 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -326,7 +326,7 @@ where where Former2 : former::FormerBegin< former::VectorDefinition< String, Self, Self, Struct1FormerVec1End, > >, { - Former2::_begin( None, Some( self ), Struct1FormerVec1End ) + Former2::former_begin( None, Some( self ), Struct1FormerVec1End ) } #[ inline( always ) ] @@ -340,7 +340,7 @@ where where Former2 : former::FormerBegin< former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap1End, > >, { - Former2::_begin( None, Some( self ), Struct1FormerHashmap1End ) + Former2::former_begin( None, Some( self ), Struct1FormerHashmap1End ) } @@ -356,7 +356,7 @@ where where Former2 : former::FormerBegin< former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End, > >, { - Former2::_begin( None, Some( self ), Struct1FormerHashset1End ) + Former2::former_begin( None, Some( self ), Struct1FormerHashset1End ) } diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 18a16fc490..407d747b4a 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -300,7 +300,7 @@ where pub fn properties_set< Former2 >( self ) -> Former2 where Former2 : former::FormerBegin< former::HashMapDefinition< K, Property< K >, Self, Self, CommandFormerPropertiesEnd, > > { - Former2::_begin( None, Some( self ), CommandFormerPropertiesEnd ) + Former2::former_begin( None, Some( self ), CommandFormerPropertiesEnd ) } #[ inline( always ) ] diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index cbc18fbfa6..955e4f4d6b 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -40,11 +40,10 @@ impl< Definition > former::FormerBegin< Definition > for DescriptorFormer< Definition > where Definition : former::FormerDefinition< Storage = DescriptorFormerStorage >, - // Definition::Types : former::FormerDefinitionTypes< Storage = DescriptorFormerStorage >, { #[ inline( always ) ] - fn _begin + fn former_begin ( storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -100,8 +99,7 @@ where } super_former }; - Former2::_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) - // Former2::_begin( None, Some( self ), on_end ) + Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) } #[ inline( always ) ] @@ -123,7 +121,7 @@ where >, Former2 : former::FormerBegin< Definition2 >, { - Former2::_begin( None, Some( self ), ParametersAddDescriptorOnEnd::default() ) + Former2::former_begin( None, Some( self ), ParametersAddDescriptorOnEnd::default() ) } // #[ inline( always ) ] diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 5076d3dde0..43d2eec02d 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -695,7 +695,7 @@ fn subformer_field_setter > >, { - Former2::_begin( None, Some( self ), #field_forming_end ) + Former2::former_begin( None, Some( self ), #field_forming_end ) } }; From b120001b8d0c98c2a5568abb75c76b94182da25c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 12:58:32 +0300 Subject: [PATCH 276/533] former : experimenting --- module/core/former/src/container.rs | 50 +------------------ module/core/former/src/hash_map.rs | 14 ++++++ module/core/former/src/hash_set.rs | 14 ++++++ module/core/former/src/vector.rs | 13 +++++ .../inc/former_tests/subformer_shortcut.rs | 20 ++++---- module/core/former_meta/src/derive/former.rs | 37 ++++++++------ 6 files changed, 73 insertions(+), 75 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 3ead72aca0..b4418ba154 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -87,47 +87,6 @@ pub trait ContainerAdd } -impl< T > ContainerAdd for collection_tools::Vec< T > -{ - type Element = T; - - #[ inline( always ) ] - fn add( &mut self, e : Self::Element ) -> bool - { - self.push( e ); - true - } - -} - -impl< E > ContainerAdd for collection_tools::HashSet< E > -where - E : core::cmp::Eq + core::hash::Hash, -{ - type Element = E; - - #[ inline( always ) ] - fn add( &mut self, e : Self::Element ) -> bool - { - self.insert( e ) - } - -} - -impl< K, V > ContainerAdd for collection_tools::HashMap< K, V > -where - K : core::cmp::Eq + core::hash::Hash, -{ - type Element = ( K, V ); - - #[ inline( always ) ] - fn add( &mut self, ( k, v ) : Self::Element ) -> bool - { - self.insert( k, v ).map_or_else( || true, | _ | false ) - } - -} - // qqq : implement for other containers /// A trait defining the capability to replface all elements. @@ -344,14 +303,7 @@ where pub fn add< IntoElement >( mut self, element : IntoElement ) -> Self where IntoElement : core::convert::Into< E >, { - // if self.storage.is_none() - // { - // self.storage = core::option::Option::Some( Default::default() ); - // } - // if let core::option::Option::Some( ref mut storage ) = self.storage - // { - ContainerAdd::add( &mut self.storage, element.into() ); - // } + ContainerAdd::add( &mut self.storage, element.into() ); self } diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index c2e2c28c08..1abd1b2b96 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -2,6 +2,20 @@ use super::*; use collection_tools::HashMap; +impl< K, V > ContainerAdd for collection_tools::HashMap< K, V > +where + K : core::cmp::Eq + core::hash::Hash, +{ + type Element = ( K, V ); + + #[ inline( always ) ] + fn add( &mut self, ( k, v ) : Self::Element ) -> bool + { + self.insert( k, v ).map_or_else( || true, | _ | false ) + } + +} + /// 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 diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index d3c7ed7ffb..bfe5c043e4 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -5,6 +5,20 @@ use super::*; use collection_tools::HashSet; +impl< E > ContainerAdd for collection_tools::HashSet< E > +where + E : core::cmp::Eq + core::hash::Hash, +{ + type Element = E; + + #[ inline( always ) ] + fn add( &mut self, e : Self::Element ) -> bool + { + self.insert( e ) + } + +} + /// A trait for containers behaving like a `HashSet`, allowing insertion operations. /// /// Implementing this trait enables the associated formed to be used with `HashSetSubformer`, diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index a9f282efb9..b5a23195f2 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -4,6 +4,19 @@ use super::*; #[ allow( unused ) ] use collection_tools::Vec; +impl< T > ContainerAdd for collection_tools::Vec< T > +{ + type Element = T; + + #[ inline( always ) ] + fn add( &mut self, e : Self::Element ) -> bool + { + self.push( e ); + true + } + +} + /// 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, diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 955e4f4d6b..b65042da30 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -108,7 +108,7 @@ where where Definition2 : former::FormerDefinition < - End = ParametersAddDescriptorOnEnd< Definition >, + End = ParametersAddDescriptorEnd< Definition >, Storage = < Descriptor as former::EntityToFormer >::Storage, Formed = Self, Context = Self, @@ -121,7 +121,7 @@ where >, Former2 : former::FormerBegin< Definition2 >, { - Former2::former_begin( None, Some( self ), ParametersAddDescriptorOnEnd::default() ) + Former2::former_begin( None, Some( self ), ParametersAddDescriptorEnd::default() ) } // #[ inline( always ) ] @@ -135,10 +135,10 @@ where // // Formed = Self, // // Context = Self, // // >, - // // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorOnEnd< Definition > >, + // // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorEnd< Definition > >, // // Former2 : SubFormerTrait< Self, Definition, Definition2, Types2 >, // { - // Former2::_begin( None, Some( self ), ParametersAddDescriptorOnEnd::default() ) + // Former2::_begin( None, Some( self ), ParametersAddDescriptorEnd::default() ) // } // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help @@ -168,7 +168,7 @@ where // type Definition; // type Definition2 : former::FormerDefinition // < -// End = ParametersAddDescriptorOnEnd +// End = ParametersAddDescriptorEnd // < // < Self::Definition2 as former::FormerDefinition >::Types, // Self::Definition, @@ -185,7 +185,7 @@ where // Formed = Former, // Context = Former, // >, -// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorOnEnd< Definition > >, +// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorEnd< Definition > >, // Self : former::FormerBegin< Definition2 >, // { // } @@ -199,20 +199,20 @@ where // Formed = Former, // Context = Former, // >, -// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorOnEnd< Definition > >, +// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorEnd< Definition > >, // Self : former::FormerBegin< Definition2 >, // { // } // zzz : improve description /// Handles the completion of and element of subformer's container. -pub struct ParametersAddDescriptorOnEnd< Definition > +pub struct ParametersAddDescriptorEnd< Definition > { _phantom : core::marker::PhantomData< fn( Definition ) >, } impl< Definition > Default -for ParametersAddDescriptorOnEnd< Definition > +for ParametersAddDescriptorEnd< Definition > { #[ inline( always ) ] fn default() -> Self @@ -225,7 +225,7 @@ for ParametersAddDescriptorOnEnd< Definition > } impl< Types2, Definition > former::FormingEnd< Types2, > -for ParametersAddDescriptorOnEnd< Definition > +for ParametersAddDescriptorEnd< Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 43d2eec02d..a1d517ce62 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -870,9 +870,13 @@ Result< TokenStream > // Expected: "former::VectorDefinition" use convert_case::{ Case, Casing }; - let ident = field.ident; - let field_forming_end_name = format!( "{}Former{}End", stru, field.ident.to_string().to_case( Case::Pascal ) ); - let field_forming_end = syn::Ident::new( &field_forming_end_name, ident.span() ); + let field_ident = field.ident; + let field_forming_end_name = format!( "{}Former{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let field_forming_end = syn::Ident::new( &field_forming_end_name, field_ident.span() ); + + let parent_add_element_end_name = format!( "{}Add{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); + // #parent_add_element_end let field_ty = field.non_optional_ty; let params = typ::type_parameters( &field.non_optional_ty, .. ); @@ -909,13 +913,13 @@ Result< TokenStream > -> #former< #former_generics_ty > { let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.#ident + if let Some( ref mut field ) = super_former.storage.#field_ident { former::ContainerAssign::assign( field, storage ); } else { - super_former.storage.#ident = Some( storage ); + super_former.storage.#field_ident = Some( storage ); } super_former } @@ -931,23 +935,23 @@ Result< TokenStream > // Formed = Self, // Context = Self, // >, - // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorOnEnd< Types2, Definition > >, + // Definition2 : former::FormerDefinition< Types = Types2, End = #parent_add_element_end< Types2, Definition > >, // Former2 : former::FormerBegin< Definition2 >, // { - // Former2::_begin( None, Some( self ), ParametersAddDescriptorOnEnd::default() ) + // Former2::_begin( None, Some( self ), #parent_add_element_end::default() ) // } // xxx : uncomment // // zzz : improve description -// /// Handles the completion of and element of subformer's container. -// pub struct ParametersAddDescriptorOnEnd< Definition > +// /// Handles the completion of an element of subformer's container. +// pub struct #parent_add_element_end< Definition > // { // _phantom : core::marker::PhantomData< fn( Definition ) >, // } // // impl< Definition > Default -// for ParametersAddDescriptorOnEnd< Definition > +// for #parent_add_element_end< Definition > // { // #[ inline( always ) ] // fn default() -> Self @@ -960,12 +964,13 @@ Result< TokenStream > // } // // impl< Types2, Definition > former::FormingEnd< Types2, > -// for ParametersAddDescriptorOnEnd< Definition > +// for #parent_add_element_end< Definition > // where // Definition : former::FormerDefinition, // Definition::Types : former::FormerDefinitionTypes // < -// Storage = < Parameters as former::EntityToFormer >::Storage, +// Storage = < #stru as former::EntityToFormer >::Storage, +// // xxx : add test with life time + param + containers // >, // Types2 : former::FormerDefinitionTypes // < @@ -984,13 +989,13 @@ Result< TokenStream > // -> Types2::Formed // { // let mut super_former = super_former.unwrap(); -// if super_former.storage.descriptors.is_none() +// if super_former.storage.#field_ident.is_none() // { -// super_former.storage.descriptors = Some( Default::default() ); +// super_former.storage.#field_ident = Some( Default::default() ); // } -// if let Some( ref mut descriptors ) = super_former.storage.descriptors +// if let Some( ref mut field ) = super_former.storage.#field_ident // { -// former::ContainerAdd::add( descriptors, former::StoragePreform::preform( substorage ) ); +// former::ContainerAdd::add( field, former::StoragePreform::preform( substorage ) ); // } // super_former // } From 5a656642115341fc8348c97fb9462889baed8217 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 13:15:40 +0300 Subject: [PATCH 277/533] former : experimenting --- module/core/former/tests/inc/former_tests/subformer_shortcut.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index b65042da30..4044e0c27e 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -235,6 +235,7 @@ where Types2 : former::FormerDefinitionTypes < Storage = < Descriptor as former::EntityToFormer >::Storage, + // Storage = < Vec< Descriptor > as former::ContainerAdd >::Element, Formed = ParametersFormer< Definition >, Context = ParametersFormer< Definition >, >, From 25477749e14ab5f6f3901da2a43af4dd878ec0d8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 16:43:29 +0300 Subject: [PATCH 278/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 44 +++++++++++-------- .../only_test/containers_with_subformer.rs | 6 +-- .../inc/former_tests/subformer_shortcut.rs | 11 +++-- module/core/former_meta/src/derive/former.rs | 20 ++++----- 4 files changed, 46 insertions(+), 35 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 136c6a4012..a026906011 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -324,46 +324,46 @@ where #[ inline( always ) ] pub fn vec_1_set< Former2 >( self ) -> Former2 where - Former2 : former::FormerBegin< former::VectorDefinition< String, Self, Self, Struct1FormerVec1End, > >, + Former2 : former::FormerBegin< former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End, > >, { - Former2::former_begin( None, Some( self ), Struct1FormerVec1End ) + Former2::former_begin( None, Some( self ), Struct1FormerAssignVec1End ) } #[ inline( always ) ] - pub fn vec_1( self ) -> former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1FormerVec1End > > + 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, Struct1FormerVec1End > >>() + self.vec_1_set::< former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End > >>() } #[ inline( always ) ] pub fn hashmap_1_set< Former2 >( self ) -> Former2 where - Former2 : former::FormerBegin< former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap1End, > >, + Former2 : former::FormerBegin< former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End, > >, { - Former2::former_begin( None, Some( self ), Struct1FormerHashmap1End ) + Former2::former_begin( None, Some( self ), Struct1FormerAssignHashmap1End ) } #[ inline( always ) ] - pub fn hashmap_1( self ) -> former::ContainerSubformer::< (String, String), former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap1End > > + pub fn hashmap_1( self ) -> former::ContainerSubformer::< (String, String), former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End > > { - self.hashmap_1_set::< former::ContainerSubformer::< (String, String), former::HashMapDefinition< String, String, Self, Self, Struct1FormerHashmap1End > >>() + self.hashmap_1_set::< former::ContainerSubformer::< (String, String), former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End > >>() } #[ inline( always ) ] pub fn hashset_1_set< Former2 >( self ) -> Former2 where - Former2 : former::FormerBegin< former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End, > >, + Former2 : former::FormerBegin< former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End, > >, { - Former2::former_begin( None, Some( self ), Struct1FormerHashset1End ) + Former2::former_begin( None, Some( self ), Struct1FormerAssignHashset1End ) } #[ inline( always ) ] - pub fn hashset_1( self ) -> former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End > > + pub fn hashset_1( self ) -> former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End > > { - self.hashset_1_set::< former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1FormerHashset1End > >>() + self.hashset_1_set::< former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End > >>() } } @@ -423,10 +423,10 @@ where // = end handlers #[ allow( non_camel_case_types ) ] -pub struct Struct1FormerVec1End; +pub struct Struct1FormerAssignVec1End; #[ automatically_derived ] -impl< Definition, > former::FormingEnd< former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, > for Struct1FormerVec1End +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< > >, @@ -448,10 +448,15 @@ where } #[ allow( non_camel_case_types ) ] -pub struct Struct1FormerHashmap1End; +pub struct Struct1FormerAssignHashmap1End; #[ automatically_derived ] -impl< Definition, > former::FormingEnd< former::HashMapDefinition< String, String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, > for Struct1FormerHashmap1End +impl< Definition, > +former::FormingEnd +< + former::HashMapDefinition< String, String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, +> +for Struct1FormerAssignHashmap1End where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, @@ -473,10 +478,13 @@ where } #[ allow( non_camel_case_types ) ] -pub struct Struct1FormerHashset1End; +pub struct Struct1FormerAssignHashset1End; #[ automatically_derived ] -impl< Definition, > former::FormingEnd< former::HashSetDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, > for Struct1FormerHashset1End +impl< Definition, > former::FormingEnd +< + former::HashSetDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, > +for Struct1FormerAssignHashset1End where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index 549232fa8a..e6ac891448 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -122,9 +122,9 @@ tests_impls! { // Container subformers are defined - let _got = Struct1FormerVec1End; - let _got = Struct1FormerHashmap1End; - let _got = Struct1FormerHashset1End; + let _got = Struct1FormerAssignVec1End; + let _got = Struct1FormerAssignHashmap1End; + let _got = Struct1FormerAssignHashset1End; // SubformerEnd is defined fn _f1< End : Struct1SubformerEnd< Struct1Former > > diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 4044e0c27e..7ca66f1fe5 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -234,11 +234,12 @@ where >, Types2 : former::FormerDefinitionTypes < - Storage = < Descriptor as former::EntityToFormer >::Storage, - // Storage = < Vec< Descriptor > as former::ContainerAdd >::Element, + // Storage = < Descriptor as former::EntityToFormer >::Storage, + Storage = < < Vec< Descriptor > as former::ContainerAdd >::Element as former::EntityToFormer >::Storage, Formed = ParametersFormer< Definition >, Context = ParametersFormer< Definition >, >, + // Types2::Storage : former::StoragePreform< Preformed = >, { #[ inline( always ) ] fn call @@ -254,9 +255,9 @@ where { super_former.storage.descriptors = Some( Default::default() ); } - if let Some( ref mut descriptors ) = super_former.storage.descriptors + if let Some( ref mut fields ) = super_former.storage.descriptors { - former::ContainerAdd::add( descriptors, former::StoragePreform::preform( substorage ) ); + former::ContainerAdd::add( fields, former::StoragePreform::preform( substorage ) ); } super_former } @@ -266,6 +267,8 @@ where fn basic() { + // let x : < Vec< Descriptor > as former::ContainerAdd >::Element; + let got = Parameters::former() .descriptors() .add( Descriptor::former().name( "a" ).form() ) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index a1d517ce62..93e3a6bae7 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -568,7 +568,7 @@ fn field_setter_map( field : &FormerField< '_ >, stru : &syn::Ident ) -> Result< /// /// Generate a single setter for the 'field_ident' with the 'setter_name' name. /// -/// Used as a helper function for field_setter_map(), which generates all alias setters +/// Used as a helper function for field_setter_map(), which generates alias setters /// /// # Example of generated code /// ```ignore @@ -664,16 +664,16 @@ fn subformer_field_setter use convert_case::{ Case, Casing }; // let ident = field_ident; - let field_forming_end_name = format!( "{}Former{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let field_forming_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let field_forming_end = syn::Ident::new( &field_forming_end_name, field_ident.span() ); - let field_set_name = format!( "{}_set", field_ident ); - let field_set = syn::Ident::new( &field_set_name, field_ident.span() ); + let field_assign_name = format!( "{}_assign", field_ident ); + let field_assign = syn::Ident::new( &field_assign_name, field_ident.span() ); let doc = format! ( "Subformer setter for the '{}' field. Method {} unlike method {} accept custom subformer.", field_ident, - field_set_name, + field_assign_name, field_ident, ); @@ -682,7 +682,7 @@ fn subformer_field_setter { #[ doc = #doc ] #[ inline( always ) ] - pub fn #field_set< Former2 >( self ) -> Former2 + pub fn #field_assign< Former2 >( self ) -> Former2 where Former2 : former::FormerBegin < @@ -712,7 +712,7 @@ fn subformer_field_setter ( #( #params, )* ), #subformer_definition< #( #params, )* Self, Self, #field_forming_end > > { - self.#field_set::< former::ContainerSubformer:: + self.#field_assign::< former::ContainerSubformer:: < ( #( #params, )* ), #subformer_definition< #( #params, )* Self, Self, #field_forming_end > >>() @@ -733,7 +733,7 @@ fn subformer_field_setter #( #params, )* #subformer_definition< #( #params, )* Self, Self, #field_forming_end > > { - self.#field_set::< former::ContainerSubformer:: + self.#field_assign::< former::ContainerSubformer:: < #( #params, )* #subformer_definition< #( #params, )* Self, Self, #field_forming_end > >>() @@ -871,10 +871,10 @@ Result< TokenStream > use convert_case::{ Case, Casing }; let field_ident = field.ident; - let field_forming_end_name = format!( "{}Former{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let field_forming_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let field_forming_end = syn::Ident::new( &field_forming_end_name, field_ident.span() ); - let parent_add_element_end_name = format!( "{}Add{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let parent_add_element_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); // #parent_add_element_end From 9fd1cff1e9c16d706bdfe97891a2beadeb4eb415 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 16:46:19 +0300 Subject: [PATCH 279/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 93e3a6bae7..fc44cbe814 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -866,17 +866,17 @@ Result< TokenStream > return Ok( qt!{ } ); } + // example : `former::VectorDefinition`` let subformer_definition = &field.attrs.subformer.as_ref().unwrap().expr; - // Expected: "former::VectorDefinition" use convert_case::{ Case, Casing }; let field_ident = field.ident; + // example : `ParametersFormerAssignDescriptorsEnd`` let field_forming_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let field_forming_end = syn::Ident::new( &field_forming_end_name, field_ident.span() ); - + // example : `ParametersFormerAddDescriptorsEnd`` let parent_add_element_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); - // #parent_add_element_end let field_ty = field.non_optional_ty; let params = typ::type_parameters( &field.non_optional_ty, .. ); From 761e1183ffbcfc65bfdd78c2d33cea54d8a695c8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 16:46:45 +0300 Subject: [PATCH 280/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 7ca66f1fe5..29d3f9bddb 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -108,7 +108,7 @@ where where Definition2 : former::FormerDefinition < - End = ParametersAddDescriptorEnd< Definition >, + End = ParametersFormerAddDescriptorsEnd< Definition >, Storage = < Descriptor as former::EntityToFormer >::Storage, Formed = Self, Context = Self, @@ -121,7 +121,7 @@ where >, Former2 : former::FormerBegin< Definition2 >, { - Former2::former_begin( None, Some( self ), ParametersAddDescriptorEnd::default() ) + Former2::former_begin( None, Some( self ), ParametersFormerAddDescriptorsEnd::default() ) } // #[ inline( always ) ] @@ -135,10 +135,10 @@ where // // Formed = Self, // // Context = Self, // // >, - // // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorEnd< Definition > >, + // // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersFormerAddDescriptorsEnd< Definition > >, // // Former2 : SubFormerTrait< Self, Definition, Definition2, Types2 >, // { - // Former2::_begin( None, Some( self ), ParametersAddDescriptorEnd::default() ) + // Former2::_begin( None, Some( self ), ParametersFormerAddDescriptorsEnd::default() ) // } // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help @@ -168,7 +168,7 @@ where // type Definition; // type Definition2 : former::FormerDefinition // < -// End = ParametersAddDescriptorEnd +// End = ParametersFormerAddDescriptorsEnd // < // < Self::Definition2 as former::FormerDefinition >::Types, // Self::Definition, @@ -185,7 +185,7 @@ where // Formed = Former, // Context = Former, // >, -// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorEnd< Definition > >, +// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersFormerAddDescriptorsEnd< Definition > >, // Self : former::FormerBegin< Definition2 >, // { // } @@ -199,20 +199,20 @@ where // Formed = Former, // Context = Former, // >, -// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersAddDescriptorEnd< Definition > >, +// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersFormerAddDescriptorsEnd< Definition > >, // Self : former::FormerBegin< Definition2 >, // { // } // zzz : improve description /// Handles the completion of and element of subformer's container. -pub struct ParametersAddDescriptorEnd< Definition > +pub struct ParametersFormerAddDescriptorsEnd< Definition > { _phantom : core::marker::PhantomData< fn( Definition ) >, } impl< Definition > Default -for ParametersAddDescriptorEnd< Definition > +for ParametersFormerAddDescriptorsEnd< Definition > { #[ inline( always ) ] fn default() -> Self @@ -225,7 +225,7 @@ for ParametersAddDescriptorEnd< Definition > } impl< Types2, Definition > former::FormingEnd< Types2, > -for ParametersAddDescriptorEnd< Definition > +for ParametersFormerAddDescriptorsEnd< Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes From 779bf87eced61bb61b16abf396736dedc5d30c69 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 17:00:59 +0300 Subject: [PATCH 281/533] former : experimenting --- module/core/former/src/definition.rs | 18 ++++++++++++++++++ .../inc/former_tests/subformer_shortcut.rs | 12 +++++++++++- module/core/former_meta/src/derive/former.rs | 3 ++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs index df31395922..c1c91cc7fd 100644 --- a/module/core/former/src/definition.rs +++ b/module/core/former/src/definition.rs @@ -13,6 +13,24 @@ pub trait EntityToFormer // type Definition; } +// zzz : improve documentation +/// Map type of entity to storage and former. +pub trait EntityToFormer2< Definition > +{ + /// Storage to store fields of entity during formign process. + type Storage; + /// Former with default definition + type Former; + // type Definition = Definition; + // type Formed; + // type Context; + // type Types; + // type Definition; + + fn f1( _ : &Definition ) {} + +} + /// zzz : write description pub trait FormerDefinitionTypes : Sized { diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 29d3f9bddb..d56d261a4d 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -36,6 +36,14 @@ pub struct Parameters // type Former = ParametersFormer; // } +// impl< Definition > former::EntityToFormer for Parameters< > +// where +// Self : Sized, +// { +// type Storage = ParametersFormerStorage; +// type Former = ParametersFormer; +// } + impl< Definition > former::FormerBegin< Definition > for DescriptorFormer< Definition > where @@ -235,9 +243,11 @@ where Types2 : former::FormerDefinitionTypes < // Storage = < Descriptor as former::EntityToFormer >::Storage, - Storage = < < Vec< Descriptor > as former::ContainerAdd >::Element as former::EntityToFormer >::Storage, Formed = ParametersFormer< Definition >, Context = ParametersFormer< Definition >, + Storage = < < Vec< Descriptor > as former::ContainerAdd >::Element as former::EntityToFormer >::Storage, + // Formed = < Parameters as former::EntityToFormer >::Former, + // Context = < Parameters as former::EntityToFormer >::Former, >, // Types2::Storage : former::StoragePreform< Preformed = >, { diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index fc44cbe814..362a112650 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -974,7 +974,8 @@ Result< TokenStream > // >, // Types2 : former::FormerDefinitionTypes // < -// Storage = < Descriptor as former::EntityToFormer >::Storage, +// // Storage = < Descriptor as former::EntityToFormer >::Storage, +// Storage = < < Vec< #stru as former::ContainerAdd >::Element as former::EntityToFormer >::Storage, // Formed = ParametersFormer< Definition >, // Context = ParametersFormer< Definition >, // >, From 72a36bb732794791bb575e348d39b8aaa8571c8c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 17:14:15 +0300 Subject: [PATCH 282/533] former : experimenting --- module/core/former/src/definition.rs | 24 +++++------ .../tests/inc/former_tests/a_basic_manual.rs | 2 +- .../tests/inc/former_tests/only_test/basic.rs | 6 +-- .../inc/former_tests/subformer_shortcut.rs | 40 ++++++++++++------- module/core/former_meta/src/derive/former.rs | 8 ++-- 5 files changed, 45 insertions(+), 35 deletions(-) diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs index c1c91cc7fd..5ff1b1015c 100644 --- a/module/core/former/src/definition.rs +++ b/module/core/former/src/definition.rs @@ -1,7 +1,7 @@ // zzz : improve documentation /// Map type of entity to storage and former. -pub trait EntityToFormer +pub trait EntityToFormer_ { /// Storage to store fields of entity during formign process. type Storage; @@ -14,21 +14,21 @@ pub trait EntityToFormer } // zzz : improve documentation -/// Map type of entity to storage and former. -pub trait EntityToFormer2< Definition > +/// Map type of entity to former. +pub trait EntityToFormer< Definition > +where + // Definition : FormerDefinition< Storage = Self::Storage >, + Definition : FormerDefinition, { - /// Storage to store fields of entity during formign process. - type Storage; - /// Former with default definition type Former; - // type Definition = Definition; - // type Formed; - // type Context; - // type Types; - // type Definition; - fn f1( _ : &Definition ) {} +} +// zzz : improve documentation +/// Map type of entity to storage. +pub trait EntityToStorage +{ + type Storage; } /// zzz : write description diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 4a26e4ec01..f79a604a02 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -25,7 +25,7 @@ impl Struct1 // = entity to former -impl former::EntityToFormer for Struct1 +impl former::EntityToFormer_ for Struct1 where Self : Sized, { diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index c6e4afb456..ebd1aadf52 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -37,14 +37,14 @@ tests_impls! fn entity_to_former() { - let got = < Struct1 as former::EntityToFormer >::Former::new_precise( former::ReturnPreformed ) + let got = < Struct1 as former::EntityToFormer_ >::Former::new_precise( former::ReturnPreformed ) .int_1( 13 ) .form(); let exp = Struct1 { int_1 : 13 }; a_id!( got, exp ); - let got = < Struct1 as former::EntityToFormer >::Storage::default(); - let exp = < Struct1 as former::EntityToFormer >::Former::new_precise( former::ReturnPreformed ); + let got = < Struct1 as former::EntityToFormer_ >::Storage::default(); + let exp = < Struct1 as former::EntityToFormer_ >::Former::new_precise( former::ReturnPreformed ); a_id!( got.int_1, exp.storage.int_1 ); } diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index d56d261a4d..81b3ed1cdd 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -10,7 +10,7 @@ pub struct Descriptor is_mandatory : bool, } -// impl former::EntityToFormer for Descriptor +// impl former::EntityToFormer_ for Descriptor // where // Self : Sized, // { @@ -28,7 +28,7 @@ pub struct Parameters descriptors : Vec< Descriptor >, } -// impl former::EntityToFormer for Parameters +// impl former::EntityToFormer_ for Parameters // where // Self : Sized, // { @@ -36,13 +36,23 @@ pub struct Parameters // type Former = ParametersFormer; // } -// impl< Definition > former::EntityToFormer for Parameters< > +impl< Definition > former::EntityToFormer< Definition > for Parameters +where + Self : Sized, + // Definition : former::FormerDefinition< Storage = Self::Storage >, + Definition : former::FormerDefinition< Storage = ParametersFormerStorage >, + // Definition : former::FormerDefinition, +{ + // type Storage = ParametersFormerStorage; + type Former = ParametersFormer< Definition >; +} + +impl former::EntityToStorage for Parameters // where // Self : Sized, -// { -// type Storage = ParametersFormerStorage; -// type Former = ParametersFormer; -// } +{ + type Storage = ParametersFormerStorage; +} impl< Definition > former::FormerBegin< Definition > for DescriptorFormer< Definition > @@ -67,7 +77,7 @@ where impl< Definition > ParametersFormer< Definition > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = < Parameters as former::EntityToFormer >::Storage >, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parameters as former::EntityToFormer_ >::Storage >, { #[ inline( always ) ] @@ -117,13 +127,13 @@ where Definition2 : former::FormerDefinition < End = ParametersFormerAddDescriptorsEnd< Definition >, - Storage = < Descriptor as former::EntityToFormer >::Storage, + Storage = < Descriptor as former::EntityToFormer_ >::Storage, Formed = Self, Context = Self, >, Definition2::Types : former::FormerDefinitionTypes < - Storage = < Descriptor as former::EntityToFormer >::Storage, + Storage = < Descriptor as former::EntityToFormer_ >::Storage, Formed = Self, Context = Self, >, @@ -238,16 +248,16 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes < - Storage = < Parameters as former::EntityToFormer >::Storage, + Storage = < Parameters as former::EntityToFormer_ >::Storage, >, Types2 : former::FormerDefinitionTypes < - // Storage = < Descriptor as former::EntityToFormer >::Storage, + // Storage = < Descriptor as former::EntityToFormer_ >::Storage, Formed = ParametersFormer< Definition >, Context = ParametersFormer< Definition >, - Storage = < < Vec< Descriptor > as former::ContainerAdd >::Element as former::EntityToFormer >::Storage, - // Formed = < Parameters as former::EntityToFormer >::Former, - // Context = < Parameters as former::EntityToFormer >::Former, + Storage = < < Vec< Descriptor > as former::ContainerAdd >::Element as former::EntityToFormer_ >::Storage, + // Formed = < Parameters as former::EntityToFormer_ >::Former, + // Context = < Parameters as former::EntityToFormer_ >::Former, >, // Types2::Storage : former::StoragePreform< Preformed = >, { diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 362a112650..06f0914697 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -969,13 +969,13 @@ Result< TokenStream > // Definition : former::FormerDefinition, // Definition::Types : former::FormerDefinitionTypes // < -// Storage = < #stru as former::EntityToFormer >::Storage, +// Storage = < #stru as former::EntityToFormer_ >::Storage, // // xxx : add test with life time + param + containers // >, // Types2 : former::FormerDefinitionTypes // < -// // Storage = < Descriptor as former::EntityToFormer >::Storage, -// Storage = < < Vec< #stru as former::ContainerAdd >::Element as former::EntityToFormer >::Storage, +// // Storage = < Descriptor as former::EntityToFormer_ >::Storage, +// Storage = < < Vec< #stru as former::ContainerAdd >::Element as former::EntityToFormer_ >::Storage, // Formed = ParametersFormer< Definition >, // Context = ParametersFormer< Definition >, // >, @@ -1337,7 +1337,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = entity to former - impl< #struct_generics_impl > former::EntityToFormer for #stru < #struct_generics_ty > + impl< #struct_generics_impl > former::EntityToFormer_ for #stru < #struct_generics_ty > where Self : Sized, #struct_generics_where From 0da5c62ceca550e2b2fb1b124e78c1fc5199623c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 17:25:34 +0300 Subject: [PATCH 283/533] former : experimenting --- module/core/former/src/definition.rs | 26 ++++++------ .../tests/inc/former_tests/a_basic_manual.rs | 18 ++++++-- .../tests/inc/former_tests/only_test/basic.rs | 6 +-- .../inc/former_tests/subformer_shortcut.rs | 42 ++++++++----------- module/core/former_meta/src/derive/former.rs | 30 ++++++++++--- 5 files changed, 73 insertions(+), 49 deletions(-) diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs index 5ff1b1015c..d3f2d309db 100644 --- a/module/core/former/src/definition.rs +++ b/module/core/former/src/definition.rs @@ -1,17 +1,17 @@ -// zzz : improve documentation -/// Map type of entity to storage and former. -pub trait EntityToFormer_ -{ - /// Storage to store fields of entity during formign process. - type Storage; - /// Former with default definition - type Former; - // type Formed; - // type Context; - // type Types; - // type Definition; -} +// // zzz : improve documentation +// /// Map type of entity to storage and former. +// pub trait EntityToFormer_ +// { +// /// Storage to store fields of entity during formign process. +// type Storage; +// /// Former with default definition +// type Former; +// // type Formed; +// // type Context; +// // type Types; +// // type Definition; +// } // zzz : improve documentation /// Map type of entity to former. diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index f79a604a02..77abf58447 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -25,12 +25,24 @@ impl Struct1 // = entity to former -impl former::EntityToFormer_ for Struct1 +// impl former::EntityToFormer_ for Struct1 +// where +// Self : Sized, +// { +// type Storage = Struct1FormerStorage; +// type Former = Struct1Former; +// } + +impl< Definition > former::EntityToFormer< Definition > for Struct1 where - Self : Sized, + Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, +{ + type Former = Struct1Former< Definition >; +} + +impl former::EntityToStorage for Struct1 { type Storage = Struct1FormerStorage; - type Former = Struct1Former; } // = definition types diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index ebd1aadf52..d477b82534 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -37,14 +37,14 @@ tests_impls! fn entity_to_former() { - let got = < Struct1 as former::EntityToFormer_ >::Former::new_precise( former::ReturnPreformed ) + let got = < Struct1 as former::EntityToFormer< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > >::Former::new_precise( former::ReturnPreformed ) .int_1( 13 ) .form(); let exp = Struct1 { int_1 : 13 }; a_id!( got, exp ); - let got = < Struct1 as former::EntityToFormer_ >::Storage::default(); - let exp = < Struct1 as former::EntityToFormer_ >::Former::new_precise( former::ReturnPreformed ); + let got = < Struct1 as former::EntityToStorage >::Storage::default(); + let exp = < Struct1 as former::EntityToFormer< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > >::Former::new_precise( former::ReturnPreformed ); a_id!( got.int_1, exp.storage.int_1 ); } diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 81b3ed1cdd..7d1d7294c2 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -36,23 +36,17 @@ pub struct Parameters // type Former = ParametersFormer; // } -impl< Definition > former::EntityToFormer< Definition > for Parameters -where - Self : Sized, - // Definition : former::FormerDefinition< Storage = Self::Storage >, - Definition : former::FormerDefinition< Storage = ParametersFormerStorage >, - // Definition : former::FormerDefinition, -{ - // type Storage = ParametersFormerStorage; - type Former = ParametersFormer< Definition >; -} - -impl former::EntityToStorage for Parameters +// impl< Definition > former::EntityToFormer< Definition > for Parameters // where -// Self : Sized, -{ - type Storage = ParametersFormerStorage; -} +// Definition : former::FormerDefinition< Storage = ParametersFormerStorage >, +// { +// type Former = ParametersFormer< Definition >; +// } +// +// impl former::EntityToStorage for Parameters +// { +// type Storage = ParametersFormerStorage; +// } impl< Definition > former::FormerBegin< Definition > for DescriptorFormer< Definition > @@ -77,7 +71,7 @@ where impl< Definition > ParametersFormer< Definition > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = < Parameters as former::EntityToFormer_ >::Storage >, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parameters as former::EntityToStorage >::Storage >, { #[ inline( always ) ] @@ -127,13 +121,13 @@ where Definition2 : former::FormerDefinition < End = ParametersFormerAddDescriptorsEnd< Definition >, - Storage = < Descriptor as former::EntityToFormer_ >::Storage, + Storage = < Descriptor as former::EntityToStorage >::Storage, Formed = Self, Context = Self, >, Definition2::Types : former::FormerDefinitionTypes < - Storage = < Descriptor as former::EntityToFormer_ >::Storage, + Storage = < Descriptor as former::EntityToStorage >::Storage, Formed = Self, Context = Self, >, @@ -248,16 +242,16 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes < - Storage = < Parameters as former::EntityToFormer_ >::Storage, + Storage = < Parameters as former::EntityToStorage >::Storage, >, Types2 : former::FormerDefinitionTypes < - // Storage = < Descriptor as former::EntityToFormer_ >::Storage, + // Storage = < Descriptor as former::EntityToStorage >::Storage, Formed = ParametersFormer< Definition >, Context = ParametersFormer< Definition >, - Storage = < < Vec< Descriptor > as former::ContainerAdd >::Element as former::EntityToFormer_ >::Storage, - // Formed = < Parameters as former::EntityToFormer_ >::Former, - // Context = < Parameters as former::EntityToFormer_ >::Former, + Storage = < < Vec< Descriptor > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + // Formed = < Parameters as former::EntityToFormer >::Former, + // Context = < Parameters as former::EntityToFormer >::Former, >, // Types2::Storage : former::StoragePreform< Preformed = >, { diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 06f0914697..e5913ed421 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -969,13 +969,13 @@ Result< TokenStream > // Definition : former::FormerDefinition, // Definition::Types : former::FormerDefinitionTypes // < -// Storage = < #stru as former::EntityToFormer_ >::Storage, +// Storage = < #stru as former::EntityToStorage >::Storage, // // xxx : add test with life time + param + containers // >, // Types2 : former::FormerDefinitionTypes // < -// // Storage = < Descriptor as former::EntityToFormer_ >::Storage, -// Storage = < < Vec< #stru as former::ContainerAdd >::Element as former::EntityToFormer_ >::Storage, +// // Storage = < Descriptor as former::EntityToStorage >::Storage, +// Storage = < < Vec< #stru as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, // Formed = ParametersFormer< Definition >, // Context = ParametersFormer< Definition >, // >, @@ -1337,13 +1337,31 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = entity to former - impl< #struct_generics_impl > former::EntityToFormer_ for #stru < #struct_generics_ty > + // impl< #struct_generics_impl > former::EntityToFormer_ + // for #stru < #struct_generics_ty > + // where + // Self : Sized, + // #struct_generics_where + // { + // type Storage = #former_storage < #struct_generics_ty >; + // type Former = #former < #struct_generics_ty >; + // } + + impl< #struct_generics_impl Definition > former::EntityToFormer< Definition > + for #stru < #struct_generics_ty > + where + Definition : former::FormerDefinition< Storage = #former_storage < #struct_generics_ty > >, + #struct_generics_where + { + type Former = #former < #struct_generics_ty Definition > ; + } + + impl< #struct_generics_impl > former::EntityToStorage + for #stru < #struct_generics_ty > where - Self : Sized, #struct_generics_where { type Storage = #former_storage < #struct_generics_ty >; - type Former = #former < #struct_generics_ty >; } // = definition types From ab99e6f058d9733a505522b353adac3b5d521c17 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 17:39:35 +0300 Subject: [PATCH 284/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 2 +- module/core/former_meta/src/derive/former.rs | 145 +++++++++--------- 2 files changed, 75 insertions(+), 72 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 7d1d7294c2..d2c36374cb 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -247,9 +247,9 @@ where Types2 : former::FormerDefinitionTypes < // Storage = < Descriptor as former::EntityToStorage >::Storage, + Storage = < < Vec< Descriptor > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, Formed = ParametersFormer< Definition >, Context = ParametersFormer< Definition >, - Storage = < < Vec< Descriptor > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, // Formed = < Parameters as former::EntityToFormer >::Former, // Context = < Parameters as former::EntityToFormer >::Former, >, diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index e5913ed421..3ed913b0ea 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -664,8 +664,8 @@ fn subformer_field_setter use convert_case::{ Case, Casing }; // let ident = field_ident; - let field_forming_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); - let field_forming_end = syn::Ident::new( &field_forming_end_name, field_ident.span() ); + let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); let field_assign_name = format!( "{}_assign", field_ident ); let field_assign = syn::Ident::new( &field_assign_name, field_ident.span() ); @@ -691,11 +691,11 @@ fn subformer_field_setter #( #params, )* Self, Self, - #field_forming_end, + #former_assign_end, > >, { - Former2::former_begin( None, Some( self ), #field_forming_end ) + Former2::former_begin( None, Some( self ), #former_assign_end ) } }; @@ -709,12 +709,12 @@ fn subformer_field_setter pub fn #field_ident( self ) -> former::ContainerSubformer:: < - ( #( #params, )* ), #subformer_definition< #( #params, )* Self, Self, #field_forming_end > + ( #( #params, )* ), #subformer_definition< #( #params, )* Self, Self, #former_assign_end > > { self.#field_assign::< former::ContainerSubformer:: < - ( #( #params, )* ), #subformer_definition< #( #params, )* Self, Self, #field_forming_end > + ( #( #params, )* ), #subformer_definition< #( #params, )* Self, Self, #former_assign_end > >>() } @@ -730,12 +730,12 @@ fn subformer_field_setter pub fn #field_ident( self ) -> former::ContainerSubformer:: < - #( #params, )* #subformer_definition< #( #params, )* Self, Self, #field_forming_end > + #( #params, )* #subformer_definition< #( #params, )* Self, Self, #former_assign_end > > { self.#field_assign::< former::ContainerSubformer:: < - #( #params, )* #subformer_definition< #( #params, )* Self, Self, #field_forming_end > + #( #params, )* #subformer_definition< #( #params, )* Self, Self, #former_assign_end > >>() } @@ -872,10 +872,10 @@ Result< TokenStream > use convert_case::{ Case, Casing }; let field_ident = field.ident; // example : `ParametersFormerAssignDescriptorsEnd`` - let field_forming_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); - let field_forming_end = syn::Ident::new( &field_forming_end_name, field_ident.span() ); + let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); // example : `ParametersFormerAddDescriptorsEnd`` - let parent_add_element_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let parent_add_element_end_name = format!( "{}FormerAdd{}End2", stru, field_ident.to_string().to_case( Case::Pascal ) ); let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); let field_ty = field.non_optional_ty; @@ -887,14 +887,14 @@ Result< TokenStream > // zzz : description /// Return original former after subformer for `vec_1` is done. #[ allow( non_camel_case_types ) ] - pub struct #field_forming_end; + pub struct #former_assign_end; #[ automatically_derived ] impl< #former_generics_impl > former::FormingEnd < #subformer_definition < #( #params, )* #former< #former_generics_ty >, #former< #former_generics_ty >, former::NoEnd >, > - for #field_forming_end + for #former_assign_end where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes @@ -943,64 +943,67 @@ Result< TokenStream > // xxx : uncomment -// // zzz : improve description -// /// Handles the completion of an element of subformer's container. -// pub struct #parent_add_element_end< Definition > -// { -// _phantom : core::marker::PhantomData< fn( Definition ) >, -// } -// -// impl< Definition > Default -// for #parent_add_element_end< Definition > -// { -// #[ inline( always ) ] -// fn default() -> Self -// { -// Self -// { -// _phantom : core::marker::PhantomData, -// } -// } -// } -// -// impl< Types2, Definition > former::FormingEnd< Types2, > -// for #parent_add_element_end< Definition > -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes -// < -// Storage = < #stru as former::EntityToStorage >::Storage, -// // xxx : add test with life time + param + containers -// >, -// Types2 : former::FormerDefinitionTypes -// < -// // Storage = < Descriptor as former::EntityToStorage >::Storage, -// Storage = < < Vec< #stru as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, -// Formed = ParametersFormer< Definition >, -// Context = ParametersFormer< Definition >, -// >, -// { -// #[ inline( always ) ] -// fn call -// ( -// &self, -// substorage : Types2::Storage, -// super_former : core::option::Option< Types2::Context >, -// ) -// -> Types2::Formed -// { -// let mut super_former = super_former.unwrap(); -// if super_former.storage.#field_ident.is_none() -// { -// super_former.storage.#field_ident = Some( Default::default() ); -// } -// if let Some( ref mut field ) = super_former.storage.#field_ident -// { -// former::ContainerAdd::add( field, former::StoragePreform::preform( substorage ) ); -// } -// super_former -// } -// } + // zzz : improve description + /// Handles the completion of an element of subformer's container. + pub struct #parent_add_element_end< Definition > + { + _phantom : core::marker::PhantomData< fn( Definition ) >, + } + + impl< Definition > Default + for #parent_add_element_end< Definition > + { + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + } + + // impl< Types2, Definition > former::FormingEnd< Types2, > + // for #parent_add_element_end< Definition > + // where + // Definition : former::FormerDefinition, + // Definition::Types : former::FormerDefinitionTypes + // < + // Storage = < #stru as former::EntityToStorage >::Storage, + // // xxx : add test with life time + param + containers + // >, + // Types2 : former::FormerDefinitionTypes + // < + // // Storage = < Descriptor as former::EntityToStorage >::Storage, + // // Formed = ParametersFormer< Definition >, + // // Context = ParametersFormer< Definition >, + // // Storage = < < Vec< #field > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + // Storage = < < Vec< #field > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + // Formed = #former< #former_generics_ty >, + // Context = #former< #former_generics_ty >, + // >, + // { + // #[ inline( always ) ] + // fn call + // ( + // &self, + // substorage : Types2::Storage, + // super_former : core::option::Option< Types2::Context >, + // ) + // -> Types2::Formed + // { + // let mut super_former = super_former.unwrap(); + // if super_former.storage.#field_ident.is_none() + // { + // super_former.storage.#field_ident = Some( Default::default() ); + // } + // if let Some( ref mut field ) = super_former.storage.#field_ident + // { + // former::ContainerAdd::add( field, former::StoragePreform::preform( substorage ) ); + // } + // super_former + // } + // } }; From 1cc00880f2fbf0fe3b8c7149a68f0b8f1f100d07 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 21:23:56 +0300 Subject: [PATCH 285/533] former : experimenting --- module/core/former/src/definition.rs | 6 + .../a_containers_with_subformer.rs | 442 ++++++++++++++++++ .../a_containers_with_subformer_manual.rs | 11 +- module/core/former/tests/inc/mod.rs | 73 +-- module/core/former_meta/src/derive/former.rs | 127 ++--- 5 files changed, 557 insertions(+), 102 deletions(-) diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs index d3f2d309db..ab0246fe85 100644 --- a/module/core/former/src/definition.rs +++ b/module/core/former/src/definition.rs @@ -31,6 +31,12 @@ pub trait EntityToStorage type Storage; } +// impl< T > EntityToStorage +// for T +// { +// type Storage = T; +// } + /// zzz : write description pub trait FormerDefinitionTypes : Sized { diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 7dfec039e6..5dc34147df 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -19,6 +19,448 @@ pub struct Struct1 // == generated begin +// #[automatically_derived] impl < > Struct1 < > where +// { +// #[doc = r""] +// #[doc = +// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] +// #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < +// Struct1FormerDefinition < (), Struct1 < > , former :: ReturnPreformed > > +// { +// Struct1Former :: < Struct1FormerDefinition < (), Struct1 < > , former +// :: ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) +// } +// } impl < Definition > former :: EntityToFormer < Definition > for Struct1 < > +// where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage +// < > > , { type Former = Struct1Former < Definition > ; } impl < > former :: +// EntityToStorage for Struct1 < > where +// { type Storage = Struct1FormerStorage < > ; } #[derive(Debug)] pub struct +// Struct1FormerDefinitionTypes < __Context = (), __Formed = Struct1 < > , > +// where { _phantom : core :: marker :: PhantomData < (__Context, __Formed) > , } +// impl < __Context, __Formed, > :: core :: default :: Default for +// Struct1FormerDefinitionTypes < __Context, __Formed, > where +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < __Context, __Formed, > former :: FormerDefinitionTypes for +// Struct1FormerDefinitionTypes < __Context, __Formed, > where +// { +// type Storage = Struct1FormerStorage < > ; type Formed = __Formed; type +// Context = __Context; +// } #[derive(Debug)] pub struct Struct1FormerDefinition < __Context = (), +// __Formed = Struct1 < > , __End = former :: ReturnPreformed, > where +// { +// _phantom : core :: marker :: PhantomData < (__Context, __Formed, __End) > +// , +// } impl < __Context, __Formed, __End, > :: core :: default :: Default for +// Struct1FormerDefinition < __Context, __Formed, __End, > where +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < __Context, __Formed, __End, > former :: FormerDefinition for +// Struct1FormerDefinition < __Context, __Formed, __End, > where __End : former +// :: FormingEnd < Struct1FormerDefinitionTypes < __Context, __Formed, > > , +// { +// type Types = Struct1FormerDefinitionTypes < __Context, __Formed, > ; type +// End = __End; type Storage = Struct1FormerStorage < > ; type Formed = +// __Formed; type Context = __Context; +// } #[doc = "Container of a corresponding former."] pub struct +// Struct1FormerStorage < > where +// { +// #[doc = r" A field"] pub vec_1 : :: core :: option :: Option < Vec < +// String > > , #[doc = r" A field"] pub hashmap_1 : :: core :: option :: +// Option < std :: collections :: HashMap < String, String > > , +// #[doc = r" A field"] pub hashset_1 : :: core :: option :: Option < std :: +// collections :: HashSet < String > > , +// } impl < > :: core :: default :: Default for Struct1FormerStorage < > where +// { +// #[inline(always)] fn default() -> Self +// { +// Self +// { +// vec_1 : :: core :: option :: Option :: None, hashmap_1 : :: core +// :: option :: Option :: None, hashset_1 : :: core :: option :: +// Option :: None, +// } +// } +// } impl < > former :: Storage for Struct1FormerStorage < > where +// { type Formed = Struct1 < > ; } impl < > former :: StoragePreform for +// Struct1FormerStorage < > where +// { +// type Preformed = Struct1 < > ; fn preform(mut self) -> Self :: Preformed +// { +// let vec_1 = if self.vec_1.is_some() { self.vec_1.take().unwrap() } +// else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'vec_1' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < Vec < String > +// >).maybe_default() +// } +// }; let hashmap_1 = if self.hashmap_1.is_some() +// { self.hashmap_1.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'hashmap_1' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < std :: collections :: +// HashMap < String, String > >).maybe_default() +// } +// }; let hashset_1 = if self.hashset_1.is_some() +// { self.hashset_1.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'hashset_1' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < std :: collections :: +// HashSet < String > >).maybe_default() +// } +// }; let result = Struct1 :: < > { vec_1, hashmap_1, hashset_1, }; +// return result; +// } +// } +// #[doc = +// " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +// pub struct Struct1Former < Definition = Struct1FormerDefinition < (), Struct1 +// < > , former :: ReturnPreformed > , > where Definition : former :: +// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = Struct1FormerStorage < > > , +// { +// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: +// Storage, context : core :: option :: Option < < Definition :: Types as +// former :: FormerDefinitionTypes > :: Context > , on_end : core :: option +// :: Option < Definition :: End > , +// } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > +// where Definition : former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , +// { +// #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn +// new_precise(on_end : Definition :: End) -> Self +// { Self :: begin_coercing(None, None, on_end) } #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > +// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , +// { Self :: begin_coercing(None, None, end,) } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn +// begin_precise(mut storage : core :: option :: Option < < Definition :: +// Types as former :: FormerDefinitionTypes > :: Storage > , context : core +// :: option :: Option < < Definition :: Types as former :: +// FormerDefinitionTypes > :: Context > , on_end : < Definition as former :: +// FormerDefinition > :: End,) -> Self +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: Some(on_end), +// } +// } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > +// (mut storage : core :: option :: Option < < Definition :: Types as former +// :: FormerDefinitionTypes > :: Storage > , context : core :: option :: +// Option < < Definition :: Types as former :: FormerDefinitionTypes > :: +// Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert +// :: Into < < Definition as former :: FormerDefinition > :: End > , +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: +// Some(:: core :: convert :: Into :: into(on_end)), +// } +// } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types +// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { +// let on_end = self.on_end.take().unwrap(); let context = +// self.context.take(); former :: FormingEnd :: < Definition :: Types > +// :: call(& on_end, self.storage, context) +// } +// #[doc = +// "Subformer setter for the 'vec_1' field. Method vec_1_assign unlike method vec_1 accept custom subformer."] +// #[inline(always)] pub fn vec_1_assign < Former2 > (self) -> Former2 where +// Former2 : former :: FormerBegin < former :: VectorDefinition < String, +// Self, Self, Struct1FormerAssignVec1End, > > , +// { Former2 :: former_begin(None, Some(self), Struct1FormerAssignVec1End) } +// #[doc = +// "Subformer setter for the 'vec_1' field. Method vec_1_assign unlike method vec_1 accept custom subformer."] +// #[inline(always)] pub fn vec_1(self) -> former :: ContainerSubformer :: < +// String, former :: VectorDefinition < String, Self, Self, +// Struct1FormerAssignVec1End > > +// { +// self.vec_1_assign :: < former :: ContainerSubformer :: < String, +// former :: VectorDefinition < String, Self, Self, +// Struct1FormerAssignVec1End > >> () +// } +// #[doc = +// "Subformer setter for the 'hashmap_1' field. Method hashmap_1_assign unlike method hashmap_1 accept custom subformer."] +// #[inline(always)] pub fn hashmap_1_assign < Former2 > (self) -> Former2 +// where Former2 : former :: FormerBegin < former :: HashMapDefinition < +// String, String, Self, Self, Struct1FormerAssignHashmap1End, > > , +// { +// Former2 :: +// former_begin(None, Some(self), Struct1FormerAssignHashmap1End) +// } +// #[doc = +// "Subformer setter for the 'hashmap_1' field. Method hashmap_1_assign unlike method hashmap_1 accept custom subformer."] +// #[inline(always)] pub fn hashmap_1(self) -> former :: ContainerSubformer +// :: < (String, String,), former :: HashMapDefinition < String, String, +// Self, Self, Struct1FormerAssignHashmap1End > > +// { +// self.hashmap_1_assign :: < former :: ContainerSubformer :: < +// (String, String,), former :: HashMapDefinition < String, String, Self, +// Self, Struct1FormerAssignHashmap1End > >> () +// } +// #[doc = +// "Subformer setter for the 'hashset_1' field. Method hashset_1_assign unlike method hashset_1 accept custom subformer."] +// #[inline(always)] pub fn hashset_1_assign < Former2 > (self) -> Former2 +// where Former2 : former :: FormerBegin < former :: HashSetDefinition < +// String, Self, Self, Struct1FormerAssignHashset1End, > > , +// { +// Former2 :: +// former_begin(None, Some(self), Struct1FormerAssignHashset1End) +// } +// #[doc = +// "Subformer setter for the 'hashset_1' field. Method hashset_1_assign unlike method hashset_1 accept custom subformer."] +// #[inline(always)] pub fn hashset_1(self) -> former :: ContainerSubformer +// :: < String, former :: HashSetDefinition < String, Self, Self, +// Struct1FormerAssignHashset1End > > +// { +// self.hashset_1_assign :: < former :: ContainerSubformer :: < String, +// former :: HashSetDefinition < String, Self, Self, +// Struct1FormerAssignHashset1End > >> () +// } +// } impl < Definition, > Struct1Former < Definition, > where Definition : former +// :: FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = Struct1FormerStorage < > , Formed = Struct1 < > > , < Definition :: +// Types as former :: FormerDefinitionTypes > :: Storage : former :: +// StoragePreform, < Definition :: Types as former :: FormerDefinitionTypes > :: +// Storage : former :: StoragePreform < Preformed = Struct1 < > > , Definition : +// former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , +// { +// pub fn preform(self) -> < Definition :: Types as former :: +// FormerDefinitionTypes > :: Formed +// { former :: StoragePreform :: preform(self.storage) } +// } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > +// where Definition : former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > , Formed = Struct1 +// < > > , +// { +// #[doc = r""] +// #[doc = r" Finish setting options and call perform on formed entity."] +// #[doc = r""] +// #[doc = +// r" If `perform` defined then associated method is called and its result returned instead of entity."] +// #[doc = +// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] +// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { let result = self.form(); return result; } +// } +// #[doc = +// r" Use as subformer of a field during process of forming of super structure."] +// pub type Struct1Subformer < __Superformer, __End > = Struct1Former < +// Struct1FormerDefinition < __Superformer, __Superformer, __End, > , > ; +// #[doc = +// r" Use as subformer end of a field during process of forming of super structure."] +// pub trait Struct1SubformerEnd < SuperFormer > where Self : former :: +// FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, SuperFormer > , > , +// {} impl < SuperFormer, T > Struct1SubformerEnd < SuperFormer > for T where +// Self : former :: FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, +// SuperFormer > , > , {} +// #[doc = r" Return original former after subformer for `vec_1` is done."] +// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignVec1End; +// #[automatically_derived] 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 < > > , Definition : +// former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , +// { +// #[inline(always)] 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 +// { former :: ContainerAssign :: assign(field, storage); } else +// { super_former.storage.vec_1 = Some(storage); } super_former +// } +// } #[doc = r" Handles the completion of an element of subformer's container."] +// pub struct Struct1FormerAddVec1End2 < Definition > +// { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < +// Definition > Default for Struct1FormerAddVec1End2 < Definition > +// { +// #[inline(always)] fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } +// +// impl < Types2, Definition > former :: FormingEnd < Types2, > +// for Struct1FormerAddVec1End2 < Definition > +// where +// Definition : former ::FormerDefinition, +// Definition :: Types : former :: FormerDefinitionTypes < Storage = < Struct1 < > as former :: EntityToStorage > :: Storage, > , +// Types2 : former :: FormerDefinitionTypes +// < +// Storage = < < Vec < String > as former :: ContainerAdd > :: Element as former :: EntityToStorage > :: Storage, +// Formed = Struct1Former < Definition, > , +// Context = Struct1Former < Definition, > , +// > , +// < Vec < String > as former :: ContainerAdd > :: Element : former::EntityToStorage, +// { +// #[inline(always)] fn +// call(& self, substorage : Types2 :: Storage, super_former : core :: option :: Option < Types2 :: Context > ,) +// -> Types2 :: Formed +// { +// let mut super_former = super_former.unwrap(); if +// super_former.storage.vec_1.is_none() +// { super_former.storage.vec_1 = Some(Default :: default()); } if let +// Some(ref mut field) = super_former.storage.vec_1 +// { +// former :: ContainerAdd :: +// add(field, former :: StoragePreform :: preform(substorage)); +// } super_former +// } +// } +// +// #[doc = r" Return original former after subformer for `vec_1` is done."] +// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashmap1End; +// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: +// HashMapDefinition < String, String, Struct1Former < Definition, > , +// Struct1Former < Definition, > , former :: NoEnd > , > for +// Struct1FormerAssignHashmap1End where Definition : former :: FormerDefinition, +// Definition :: Types : former :: FormerDefinitionTypes < Storage = +// Struct1FormerStorage < > > , Definition : former :: FormerDefinition, +// Definition :: Types : former :: FormerDefinitionTypes < Storage = +// Struct1FormerStorage < > > , +// { +// #[inline(always)] fn +// call(& self, storage : std :: collections :: HashMap < String, String > , +// super_former : Option < Struct1Former < Definition, > > ,) -> +// Struct1Former < Definition, > +// { +// let mut super_former = super_former.unwrap(); if let +// Some(ref mut field) = super_former.storage.hashmap_1 +// { former :: ContainerAssign :: assign(field, storage); } else +// { super_former.storage.hashmap_1 = Some(storage); } super_former +// } +// } #[doc = r" Handles the completion of an element of subformer's container."] +// pub struct Struct1FormerAddHashmap1End2 < Definition > +// { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < +// Definition > Default for Struct1FormerAddHashmap1End2 < Definition > +// { +// #[inline(always)] fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < Types2, Definition > former :: FormingEnd < Types2, > for +// Struct1FormerAddHashmap1End2 < Definition > where Definition : former :: +// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = < Struct1 < > as former :: EntityToStorage > :: Storage, > , Types2 +// : former :: FormerDefinitionTypes < Storage = < < std :: collections :: +// HashMap < String, String > as former :: ContainerAdd > :: Element as former :: +// EntityToStorage > :: Storage, Formed = Struct1Former < Definition, > , Context +// = Struct1Former < Definition, > , > , +// { +// #[inline(always)] fn +// call(& self, substorage : Types2 :: Storage, super_former : core :: option +// :: Option < Types2 :: Context > ,) -> Types2 :: Formed +// { +// let mut super_former = super_former.unwrap(); if +// super_former.storage.hashmap_1.is_none() +// { super_former.storage.hashmap_1 = Some(Default :: default()); } if +// let Some(ref mut field) = super_former.storage.hashmap_1 +// { +// former :: ContainerAdd :: +// add(field, former :: StoragePreform :: preform(substorage)); +// } super_former +// } +// } #[doc = r" Return original former after subformer for `vec_1` is done."] +// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashset1End; +// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: +// HashSetDefinition < String, Struct1Former < Definition, > , Struct1Former < +// Definition, > , former :: NoEnd > , > for Struct1FormerAssignHashset1End where +// Definition : former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , Definition : +// former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , +// { +// #[inline(always)] fn +// call(& self, storage : std :: collections :: HashSet < String > , +// super_former : Option < Struct1Former < Definition, > > ,) -> +// Struct1Former < Definition, > +// { +// let mut super_former = super_former.unwrap(); if let +// Some(ref mut field) = super_former.storage.hashset_1 +// { former :: ContainerAssign :: assign(field, storage); } else +// { super_former.storage.hashset_1 = Some(storage); } super_former +// } +// } #[doc = r" Handles the completion of an element of subformer's container."] +// pub struct Struct1FormerAddHashset1End2 < Definition > +// { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < +// Definition > Default for Struct1FormerAddHashset1End2 < Definition > +// { +// #[inline(always)] fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < Types2, Definition > former :: FormingEnd < Types2, > for +// Struct1FormerAddHashset1End2 < Definition > where Definition : former :: +// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = < Struct1 < > as former :: EntityToStorage > :: Storage, > , Types2 +// : former :: FormerDefinitionTypes < Storage = < < std :: collections :: +// HashSet < String > as former :: ContainerAdd > :: Element as former :: +// EntityToStorage > :: Storage, Formed = Struct1Former < Definition, > , Context +// = Struct1Former < Definition, > , > , +// { +// #[inline(always)] fn +// call(& self, substorage : Types2 :: Storage, super_former : core :: option +// :: Option < Types2 :: Context > ,) -> Types2 :: Formed +// { +// let mut super_former = super_former.unwrap(); if +// super_former.storage.hashset_1.is_none() +// { super_former.storage.hashset_1 = Some(Default :: default()); } if +// let Some(ref mut field) = super_former.storage.hashset_1 +// { +// former :: ContainerAdd :: +// add(field, former :: StoragePreform :: preform(substorage)); +// } super_former +// } +// } + // == generated end include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index a026906011..01125ccf65 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -199,7 +199,7 @@ where { trait MaybeDefault< T > { - fn maybe_default( self : & Self ) -> T + fn maybe_default( self : &Self ) -> T { panic!( "Field 'hashset_1' isn't initialized" ) } @@ -212,7 +212,7 @@ where impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > where T : ::core::default::Default, { - fn maybe_default( self : & Self ) -> T + fn maybe_default( self : &Self ) -> T { T::default() } @@ -390,7 +390,6 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< >, Formed = Struct1< > >, { - #[ inline( always ) ] pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { @@ -426,7 +425,8 @@ where pub struct Struct1FormerAssignVec1End; #[ automatically_derived ] -impl< Definition, > former::FormingEnd< former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, > for Struct1FormerAssignVec1End +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< > >, @@ -483,7 +483,8 @@ pub struct Struct1FormerAssignHashset1End; #[ automatically_derived ] impl< Definition, > former::FormingEnd < - former::HashSetDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, > + former::HashSetDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, +> for Struct1FormerAssignHashset1End where Definition : former::FormerDefinition, diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 1b787a9734..89385f7bfc 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -26,42 +26,43 @@ mod former_tests #[ cfg( not( feature = "no_std" ) ) ] mod a_containers_with_subformer ; - mod attribute_default_container; - mod attribute_default_primitive; - mod attribute_perform; - mod attribute_setter; - mod attribute_alias; - // mod attribute_feature; // zzz : write test - - mod string_slice_manual; - mod string_slice; - mod unsigned_primitive_types; - mod default_user_type; - mod user_type_no_default; - mod user_type_no_debug; - - mod name_collision_former_hashmap_without_parameter; - mod name_collision_former_vector_without_parameter; - mod name_collisions; - mod name_collision_context; - mod name_collision_end; - mod name_collision_on_end; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_manual; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_imm; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_where; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_basic; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_custom; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_custom_experimental; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_shortcut; +// mod attribute_default_container; +// mod attribute_default_primitive; +// mod attribute_perform; +// mod attribute_setter; +// mod attribute_alias; +// // mod attribute_feature; // zzz : write test +// +// mod string_slice_manual; +// mod string_slice; +// mod unsigned_primitive_types; +// mod default_user_type; +// mod user_type_no_default; +// mod user_type_no_debug; +// +// mod name_collision_former_hashmap_without_parameter; +// mod name_collision_former_vector_without_parameter; +// mod name_collisions; +// mod name_collision_context; +// mod name_collision_end; +// mod name_collision_on_end; +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_manual; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_imm; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_where; +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_basic; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_custom; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_custom_experimental; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_shortcut; +// xxx } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 3ed913b0ea..51c7c66af0 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -855,7 +855,9 @@ fn fields_setter_callback_descriptor_map former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, + struct_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + struct_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, ) -> Result< TokenStream > @@ -943,67 +945,68 @@ Result< TokenStream > // xxx : uncomment - // zzz : improve description - /// Handles the completion of an element of subformer's container. - pub struct #parent_add_element_end< Definition > - { - _phantom : core::marker::PhantomData< fn( Definition ) >, - } - - impl< Definition > Default - for #parent_add_element_end< Definition > - { - #[ inline( always ) ] - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } - } - - // impl< Types2, Definition > former::FormingEnd< Types2, > - // for #parent_add_element_end< Definition > - // where - // Definition : former::FormerDefinition, - // Definition::Types : former::FormerDefinitionTypes - // < - // Storage = < #stru as former::EntityToStorage >::Storage, - // // xxx : add test with life time + param + containers - // >, - // Types2 : former::FormerDefinitionTypes - // < - // // Storage = < Descriptor as former::EntityToStorage >::Storage, - // // Formed = ParametersFormer< Definition >, - // // Context = ParametersFormer< Definition >, - // // Storage = < < Vec< #field > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, - // Storage = < < Vec< #field > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, - // Formed = #former< #former_generics_ty >, - // Context = #former< #former_generics_ty >, - // >, - // { - // #[ inline( always ) ] - // fn call - // ( - // &self, - // substorage : Types2::Storage, - // super_former : core::option::Option< Types2::Context >, - // ) - // -> Types2::Formed - // { - // let mut super_former = super_former.unwrap(); - // if super_former.storage.#field_ident.is_none() - // { - // super_former.storage.#field_ident = Some( Default::default() ); - // } - // if let Some( ref mut field ) = super_former.storage.#field_ident - // { - // former::ContainerAdd::add( field, former::StoragePreform::preform( substorage ) ); - // } - // super_former - // } - // } +// // zzz : improve description +// /// Handles the completion of an element of subformer's container. +// pub struct #parent_add_element_end< Definition > +// { +// _phantom : core::marker::PhantomData< fn( Definition ) >, +// } +// +// impl< Definition > Default +// for #parent_add_element_end< Definition > +// { +// #[ inline( always ) ] +// fn default() -> Self +// { +// Self +// { +// _phantom : core::marker::PhantomData, +// } +// } +// } +// +// impl< #struct_generics_impl Types2, Definition > former::FormingEnd< Types2, > +// for #parent_add_element_end< Definition > +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes +// < +// Storage = < #stru < #struct_generics_ty > as former::EntityToStorage >::Storage, +// // xxx : add test with life time + param + containers +// >, +// Types2 : former::FormerDefinitionTypes +// < +// // Storage = < Descriptor as former::EntityToStorage >::Storage, +// // Formed = ParametersFormer< Definition >, +// // Context = ParametersFormer< Definition >, +// // Storage = < < Vec< #field_ident > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, +// Storage = < < #field_ty as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, +// Formed = #former< #former_generics_ty >, +// Context = #former< #former_generics_ty >, +// >, +// #struct_generics_where +// { +// #[ inline( always ) ] +// fn call +// ( +// &self, +// substorage : Types2::Storage, +// super_former : core::option::Option< Types2::Context >, +// ) +// -> Types2::Formed +// { +// let mut super_former = super_former.unwrap(); +// if super_former.storage.#field_ident.is_none() +// { +// super_former.storage.#field_ident = Some( Default::default() ); +// } +// if let Some( ref mut field ) = super_former.storage.#field_ident +// { +// former::ContainerAdd::add( field, former::StoragePreform::preform( substorage ) ); +// } +// super_former +// } +// } }; @@ -1306,7 +1309,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > &former_generics_impl, &former_generics_ty, &former_generics_where, + &struct_generics_impl, &struct_generics_ty, + &struct_generics_where, ), )}).multiunzip(); From 5be7d084800527ae6bdf5fd10896c185184d8910 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 21:58:57 +0300 Subject: [PATCH 286/533] former : experimenting --- module/core/former/Readme.md | 6 +- module/core/former/src/hash_map.rs | 2 +- module/core/former/src/hash_set.rs | 2 +- .../a_containers_with_subformer.rs | 448 +----------------- .../only_test/subformer_shortcut.rs | 45 ++ .../former_tests/parametrized_struct_imm.rs | 2 +- .../parametrized_struct_manual.rs | 2 +- .../former_tests/parametrized_struct_where.rs | 2 +- .../tests/inc/former_tests/subformer_basic.rs | 4 +- .../inc/former_tests/subformer_custom.rs | 2 +- .../subformer_custom_experimental.rs | 2 +- .../inc/former_tests/subformer_shortcut.rs | 219 +++------ module/core/former/tests/inc/mod.rs | 72 +-- module/core/former_meta/src/derive/former.rs | 297 ++++++++---- module/core/former_meta/src/lib.rs | 4 +- 15 files changed, 350 insertions(+), 759 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 1f5289de87..1c6003a399 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -434,7 +434,7 @@ The following example illustrates how to use a `VectorSubformer` to construct a #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithVec { - #[ subformer( former::VectorSubformer ) ] + #[ container( former::VectorSubformer ) ] vec : Vec< &'static str >, } @@ -463,7 +463,7 @@ use test_tools::exposed::*; #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithMap { - #[ subformer( former::HashMapSubformer ) ] + #[ container( former::HashMapSubformer ) ] map : std::collections::HashMap< &'static str, &'static str >, } @@ -492,7 +492,7 @@ use test_tools::exposed::*; #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithSet { - #[ subformer( former::HashSetSubformer ) ] + #[ container( former::HashSetSubformer ) ] set : std::collections::HashSet< &'static str >, } diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 1abd1b2b96..330544c9ad 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -175,7 +175,7 @@ where /// #[ derive( Debug, PartialEq, former::Former ) ] /// pub struct StructWithMap /// { -/// #[ subformer( former::HashMapSubformer ) ] +/// #[ container( former::HashMapSubformer ) ] /// map : std::collections::HashMap< &'static str, &'static str >, /// } /// diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index bfe5c043e4..876883a850 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -126,7 +126,7 @@ where /// #[ derive( Debug, PartialEq, former::Former ) ] /// pub struct StructWithSet /// { -/// #[ subformer( former::HashSetSubformer ) ] +/// #[ container( former::HashSetSubformer ) ] /// set : std::collections::HashSet< &'static str >, /// } /// diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 5dc34147df..9daf174695 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -9,458 +9,16 @@ use super::*; // #[ derive( Default, Debug, PartialEq ) ] pub struct Struct1 { - #[ subformer( former::VectorDefinition ) ] + #[ container( former::VectorDefinition ) ] vec_1 : Vec< String >, - #[ subformer( former::HashMapDefinition ) ] + #[ container( former::HashMapDefinition ) ] hashmap_1 : std::collections::HashMap< String, String >, - #[ subformer( former::HashSetDefinition ) ] + #[ container( former::HashSetDefinition ) ] hashset_1 : std::collections::HashSet< String >, } // == generated begin -// #[automatically_derived] impl < > Struct1 < > where -// { -// #[doc = r""] -// #[doc = -// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] -// #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < -// Struct1FormerDefinition < (), Struct1 < > , former :: ReturnPreformed > > -// { -// Struct1Former :: < Struct1FormerDefinition < (), Struct1 < > , former -// :: ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) -// } -// } impl < Definition > former :: EntityToFormer < Definition > for Struct1 < > -// where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage -// < > > , { type Former = Struct1Former < Definition > ; } impl < > former :: -// EntityToStorage for Struct1 < > where -// { type Storage = Struct1FormerStorage < > ; } #[derive(Debug)] pub struct -// Struct1FormerDefinitionTypes < __Context = (), __Formed = Struct1 < > , > -// where { _phantom : core :: marker :: PhantomData < (__Context, __Formed) > , } -// impl < __Context, __Formed, > :: core :: default :: Default for -// Struct1FormerDefinitionTypes < __Context, __Formed, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, > former :: FormerDefinitionTypes for -// Struct1FormerDefinitionTypes < __Context, __Formed, > where -// { -// type Storage = Struct1FormerStorage < > ; type Formed = __Formed; type -// Context = __Context; -// } #[derive(Debug)] pub struct Struct1FormerDefinition < __Context = (), -// __Formed = Struct1 < > , __End = former :: ReturnPreformed, > where -// { -// _phantom : core :: marker :: PhantomData < (__Context, __Formed, __End) > -// , -// } impl < __Context, __Formed, __End, > :: core :: default :: Default for -// Struct1FormerDefinition < __Context, __Formed, __End, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, __End, > former :: FormerDefinition for -// Struct1FormerDefinition < __Context, __Formed, __End, > where __End : former -// :: FormingEnd < Struct1FormerDefinitionTypes < __Context, __Formed, > > , -// { -// type Types = Struct1FormerDefinitionTypes < __Context, __Formed, > ; type -// End = __End; type Storage = Struct1FormerStorage < > ; type Formed = -// __Formed; type Context = __Context; -// } #[doc = "Container of a corresponding former."] pub struct -// Struct1FormerStorage < > where -// { -// #[doc = r" A field"] pub vec_1 : :: core :: option :: Option < Vec < -// String > > , #[doc = r" A field"] pub hashmap_1 : :: core :: option :: -// Option < std :: collections :: HashMap < String, String > > , -// #[doc = r" A field"] pub hashset_1 : :: core :: option :: Option < std :: -// collections :: HashSet < String > > , -// } impl < > :: core :: default :: Default for Struct1FormerStorage < > where -// { -// #[inline(always)] fn default() -> Self -// { -// Self -// { -// vec_1 : :: core :: option :: Option :: None, hashmap_1 : :: core -// :: option :: Option :: None, hashset_1 : :: core :: option :: -// Option :: None, -// } -// } -// } impl < > former :: Storage for Struct1FormerStorage < > where -// { type Formed = Struct1 < > ; } impl < > former :: StoragePreform for -// Struct1FormerStorage < > where -// { -// type Preformed = Struct1 < > ; fn preform(mut self) -> Self :: Preformed -// { -// let vec_1 = if self.vec_1.is_some() { self.vec_1.take().unwrap() } -// else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'vec_1' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < Vec < String > -// >).maybe_default() -// } -// }; let hashmap_1 = if self.hashmap_1.is_some() -// { self.hashmap_1.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'hashmap_1' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < std :: collections :: -// HashMap < String, String > >).maybe_default() -// } -// }; let hashset_1 = if self.hashset_1.is_some() -// { self.hashset_1.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'hashset_1' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < std :: collections :: -// HashSet < String > >).maybe_default() -// } -// }; let result = Struct1 :: < > { vec_1, hashmap_1, hashset_1, }; -// return result; -// } -// } -// #[doc = -// " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -// pub struct Struct1Former < Definition = Struct1FormerDefinition < (), Struct1 -// < > , former :: ReturnPreformed > , > where Definition : former :: -// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = Struct1FormerStorage < > > , -// { -// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: -// Storage, context : core :: option :: Option < < Definition :: Types as -// former :: FormerDefinitionTypes > :: Context > , on_end : core :: option -// :: Option < Definition :: End > , -// } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > -// where Definition : former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn -// new_precise(on_end : Definition :: End) -> Self -// { Self :: begin_coercing(None, None, on_end) } #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > -// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , -// { Self :: begin_coercing(None, None, end,) } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn -// begin_precise(mut storage : core :: option :: Option < < Definition :: -// Types as former :: FormerDefinitionTypes > :: Storage > , context : core -// :: option :: Option < < Definition :: Types as former :: -// FormerDefinitionTypes > :: Context > , on_end : < Definition as former :: -// FormerDefinition > :: End,) -> Self -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: Some(on_end), -// } -// } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > -// (mut storage : core :: option :: Option < < Definition :: Types as former -// :: FormerDefinitionTypes > :: Storage > , context : core :: option :: -// Option < < Definition :: Types as former :: FormerDefinitionTypes > :: -// Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert -// :: Into < < Definition as former :: FormerDefinition > :: End > , -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: -// Some(:: core :: convert :: Into :: into(on_end)), -// } -// } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types -// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { -// let on_end = self.on_end.take().unwrap(); let context = -// self.context.take(); former :: FormingEnd :: < Definition :: Types > -// :: call(& on_end, self.storage, context) -// } -// #[doc = -// "Subformer setter for the 'vec_1' field. Method vec_1_assign unlike method vec_1 accept custom subformer."] -// #[inline(always)] pub fn vec_1_assign < Former2 > (self) -> Former2 where -// Former2 : former :: FormerBegin < former :: VectorDefinition < String, -// Self, Self, Struct1FormerAssignVec1End, > > , -// { Former2 :: former_begin(None, Some(self), Struct1FormerAssignVec1End) } -// #[doc = -// "Subformer setter for the 'vec_1' field. Method vec_1_assign unlike method vec_1 accept custom subformer."] -// #[inline(always)] pub fn vec_1(self) -> former :: ContainerSubformer :: < -// String, former :: VectorDefinition < String, Self, Self, -// Struct1FormerAssignVec1End > > -// { -// self.vec_1_assign :: < former :: ContainerSubformer :: < String, -// former :: VectorDefinition < String, Self, Self, -// Struct1FormerAssignVec1End > >> () -// } -// #[doc = -// "Subformer setter for the 'hashmap_1' field. Method hashmap_1_assign unlike method hashmap_1 accept custom subformer."] -// #[inline(always)] pub fn hashmap_1_assign < Former2 > (self) -> Former2 -// where Former2 : former :: FormerBegin < former :: HashMapDefinition < -// String, String, Self, Self, Struct1FormerAssignHashmap1End, > > , -// { -// Former2 :: -// former_begin(None, Some(self), Struct1FormerAssignHashmap1End) -// } -// #[doc = -// "Subformer setter for the 'hashmap_1' field. Method hashmap_1_assign unlike method hashmap_1 accept custom subformer."] -// #[inline(always)] pub fn hashmap_1(self) -> former :: ContainerSubformer -// :: < (String, String,), former :: HashMapDefinition < String, String, -// Self, Self, Struct1FormerAssignHashmap1End > > -// { -// self.hashmap_1_assign :: < former :: ContainerSubformer :: < -// (String, String,), former :: HashMapDefinition < String, String, Self, -// Self, Struct1FormerAssignHashmap1End > >> () -// } -// #[doc = -// "Subformer setter for the 'hashset_1' field. Method hashset_1_assign unlike method hashset_1 accept custom subformer."] -// #[inline(always)] pub fn hashset_1_assign < Former2 > (self) -> Former2 -// where Former2 : former :: FormerBegin < former :: HashSetDefinition < -// String, Self, Self, Struct1FormerAssignHashset1End, > > , -// { -// Former2 :: -// former_begin(None, Some(self), Struct1FormerAssignHashset1End) -// } -// #[doc = -// "Subformer setter for the 'hashset_1' field. Method hashset_1_assign unlike method hashset_1 accept custom subformer."] -// #[inline(always)] pub fn hashset_1(self) -> former :: ContainerSubformer -// :: < String, former :: HashSetDefinition < String, Self, Self, -// Struct1FormerAssignHashset1End > > -// { -// self.hashset_1_assign :: < former :: ContainerSubformer :: < String, -// former :: HashSetDefinition < String, Self, Self, -// Struct1FormerAssignHashset1End > >> () -// } -// } impl < Definition, > Struct1Former < Definition, > where Definition : former -// :: FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = Struct1FormerStorage < > , Formed = Struct1 < > > , < Definition :: -// Types as former :: FormerDefinitionTypes > :: Storage : former :: -// StoragePreform, < Definition :: Types as former :: FormerDefinitionTypes > :: -// Storage : former :: StoragePreform < Preformed = Struct1 < > > , Definition : -// former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// pub fn preform(self) -> < Definition :: Types as former :: -// FormerDefinitionTypes > :: Formed -// { former :: StoragePreform :: preform(self.storage) } -// } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > -// where Definition : former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > , Formed = Struct1 -// < > > , -// { -// #[doc = r""] -// #[doc = r" Finish setting options and call perform on formed entity."] -// #[doc = r""] -// #[doc = -// r" If `perform` defined then associated method is called and its result returned instead of entity."] -// #[doc = -// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] -// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { let result = self.form(); return result; } -// } -// #[doc = -// r" Use as subformer of a field during process of forming of super structure."] -// pub type Struct1Subformer < __Superformer, __End > = Struct1Former < -// Struct1FormerDefinition < __Superformer, __Superformer, __End, > , > ; -// #[doc = -// r" Use as subformer end of a field during process of forming of super structure."] -// pub trait Struct1SubformerEnd < SuperFormer > where Self : former :: -// FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, SuperFormer > , > , -// {} impl < SuperFormer, T > Struct1SubformerEnd < SuperFormer > for T where -// Self : former :: FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, -// SuperFormer > , > , {} -// #[doc = r" Return original former after subformer for `vec_1` is done."] -// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignVec1End; -// #[automatically_derived] 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 < > > , Definition : -// former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// #[inline(always)] 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 -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.vec_1 = Some(storage); } super_former -// } -// } #[doc = r" Handles the completion of an element of subformer's container."] -// pub struct Struct1FormerAddVec1End2 < Definition > -// { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < -// Definition > Default for Struct1FormerAddVec1End2 < Definition > -// { -// #[inline(always)] fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } -// -// impl < Types2, Definition > former :: FormingEnd < Types2, > -// for Struct1FormerAddVec1End2 < Definition > -// where -// Definition : former ::FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = < Struct1 < > as former :: EntityToStorage > :: Storage, > , -// Types2 : former :: FormerDefinitionTypes -// < -// Storage = < < Vec < String > as former :: ContainerAdd > :: Element as former :: EntityToStorage > :: Storage, -// Formed = Struct1Former < Definition, > , -// Context = Struct1Former < Definition, > , -// > , -// < Vec < String > as former :: ContainerAdd > :: Element : former::EntityToStorage, -// { -// #[inline(always)] fn -// call(& self, substorage : Types2 :: Storage, super_former : core :: option :: Option < Types2 :: Context > ,) -// -> Types2 :: Formed -// { -// let mut super_former = super_former.unwrap(); if -// super_former.storage.vec_1.is_none() -// { super_former.storage.vec_1 = Some(Default :: default()); } if let -// Some(ref mut field) = super_former.storage.vec_1 -// { -// former :: ContainerAdd :: -// add(field, former :: StoragePreform :: preform(substorage)); -// } super_former -// } -// } -// -// #[doc = r" Return original former after subformer for `vec_1` is done."] -// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashmap1End; -// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: -// HashMapDefinition < String, String, Struct1Former < Definition, > , -// Struct1Former < Definition, > , former :: NoEnd > , > for -// Struct1FormerAssignHashmap1End where Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = -// Struct1FormerStorage < > > , Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = -// Struct1FormerStorage < > > , -// { -// #[inline(always)] fn -// call(& self, storage : std :: collections :: HashMap < String, String > , -// super_former : Option < Struct1Former < Definition, > > ,) -> -// Struct1Former < Definition, > -// { -// let mut super_former = super_former.unwrap(); if let -// Some(ref mut field) = super_former.storage.hashmap_1 -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.hashmap_1 = Some(storage); } super_former -// } -// } #[doc = r" Handles the completion of an element of subformer's container."] -// pub struct Struct1FormerAddHashmap1End2 < Definition > -// { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < -// Definition > Default for Struct1FormerAddHashmap1End2 < Definition > -// { -// #[inline(always)] fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < Types2, Definition > former :: FormingEnd < Types2, > for -// Struct1FormerAddHashmap1End2 < Definition > where Definition : former :: -// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = < Struct1 < > as former :: EntityToStorage > :: Storage, > , Types2 -// : former :: FormerDefinitionTypes < Storage = < < std :: collections :: -// HashMap < String, String > as former :: ContainerAdd > :: Element as former :: -// EntityToStorage > :: Storage, Formed = Struct1Former < Definition, > , Context -// = Struct1Former < Definition, > , > , -// { -// #[inline(always)] fn -// call(& self, substorage : Types2 :: Storage, super_former : core :: option -// :: Option < Types2 :: Context > ,) -> Types2 :: Formed -// { -// let mut super_former = super_former.unwrap(); if -// super_former.storage.hashmap_1.is_none() -// { super_former.storage.hashmap_1 = Some(Default :: default()); } if -// let Some(ref mut field) = super_former.storage.hashmap_1 -// { -// former :: ContainerAdd :: -// add(field, former :: StoragePreform :: preform(substorage)); -// } super_former -// } -// } #[doc = r" Return original former after subformer for `vec_1` is done."] -// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashset1End; -// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: -// HashSetDefinition < String, Struct1Former < Definition, > , Struct1Former < -// Definition, > , former :: NoEnd > , > for Struct1FormerAssignHashset1End where -// Definition : former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , Definition : -// former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// #[inline(always)] fn -// call(& self, storage : std :: collections :: HashSet < String > , -// super_former : Option < Struct1Former < Definition, > > ,) -> -// Struct1Former < Definition, > -// { -// let mut super_former = super_former.unwrap(); if let -// Some(ref mut field) = super_former.storage.hashset_1 -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.hashset_1 = Some(storage); } super_former -// } -// } #[doc = r" Handles the completion of an element of subformer's container."] -// pub struct Struct1FormerAddHashset1End2 < Definition > -// { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < -// Definition > Default for Struct1FormerAddHashset1End2 < Definition > -// { -// #[inline(always)] fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < Types2, Definition > former :: FormingEnd < Types2, > for -// Struct1FormerAddHashset1End2 < Definition > where Definition : former :: -// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = < Struct1 < > as former :: EntityToStorage > :: Storage, > , Types2 -// : former :: FormerDefinitionTypes < Storage = < < std :: collections :: -// HashSet < String > as former :: ContainerAdd > :: Element as former :: -// EntityToStorage > :: Storage, Formed = Struct1Former < Definition, > , Context -// = Struct1Former < Definition, > , > , -// { -// #[inline(always)] fn -// call(& self, substorage : Types2 :: Storage, super_former : core :: option -// :: Option < Types2 :: Context > ,) -> Types2 :: Formed -// { -// let mut super_former = super_former.unwrap(); if -// super_former.storage.hashset_1.is_none() -// { super_former.storage.hashset_1 = Some(Default :: default()); } if -// let Some(ref mut field) = super_former.storage.hashset_1 -// { -// former :: ContainerAdd :: -// add(field, former :: StoragePreform :: preform(substorage)); -// } super_former -// } -// } - // == generated end include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs new file mode 100644 index 0000000000..039fc8ed30 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs @@ -0,0 +1,45 @@ + +#[ test ] +fn basic() +{ + + // let x : < Vec< Descriptor > as former::ContainerAdd >::Element; + + let got = Parameters::former() + .descriptors() + .add( Descriptor::former().name( "a" ).form() ) + .add( Descriptor::former().name( "b" ).form() ) + .end() + .form(); + + let descriptors = vec! + [ + Descriptor { name : "a".to_string(), is_mandatory : false }, + Descriptor { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parameters { descriptors }; + a_id!( got, exp ); + +} + +#[ test ] +fn descriptor() +{ + + let got = Parameters::former() + .descriptor( "a" ).end() + .descriptor( "b" ).end() + // .add( Descriptor::former().name( "a" ).form() ) + // .add( Descriptor::former().name( "b" ).form() ) + // .end() + .form(); + + let descriptors = vec! + [ + Descriptor { name : "a".to_string(), is_mandatory : false }, + Descriptor { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parameters { descriptors }; + a_id!( got, exp ); + +} diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs index d30aa71c20..f0236afb4d 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs @@ -28,7 +28,7 @@ impl< Name > Property< Name > pub struct Command< K : core::hash::Hash + std::cmp::Eq > { pub name : String, - #[ subformer( former::HashMapDefinition ) ] + #[ container( former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 407d747b4a..78ca6b6ad2 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -30,7 +30,7 @@ where K : core::hash::Hash + std::cmp::Eq, { pub name : String, - // #[ subformer( former::HashMapDefinition ) ] + // #[ container( former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs index 5da806be97..c2515a69eb 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs @@ -30,7 +30,7 @@ where K : core::hash::Hash + std::cmp::Eq, { pub name : String, - #[ subformer( former::HashMapDefinition ) ] + #[ container( former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 0728a3df87..66b1ad7a0f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -53,7 +53,7 @@ where { pub name : String, pub subject : String, - #[ subformer( former::HashMapDefinition ) ] + #[ container( former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } @@ -102,7 +102,7 @@ where K : core::hash::Hash + std::cmp::Eq, { pub parameter1 : String, - #[ subformer( former::HashMapDefinition ) ] + #[ container( former::HashMapDefinition ) ] pub commands : collection_tools::HashMap< String, Command< K > >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_custom.rs b/module/core/former/tests/inc/former_tests/subformer_custom.rs index e953ad798c..49b8ab0a5e 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom.rs @@ -58,7 +58,7 @@ where K : core::hash::Hash + std::cmp::Eq, { pub parameter1 : String, - #[ subformer( former::HashMapDefinition ) ] + #[ container( former::HashMapDefinition ) ] pub commands : collection_tools::HashMap< String, Command< K > >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs index cf9d198b21..0d54af871f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs @@ -20,7 +20,7 @@ where K : core::hash::Hash + std::cmp::Eq, { pub parameter1 : String, - #[ subformer( former::HashMapDefinition ) ] + #[ container( former::HashMapDefinition ) ] pub commands : collection_tools::HashMap< String, Command< K > >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index d2c36374cb..46d337fb4a 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -2,6 +2,7 @@ use super::*; +// xxx : rename /// Parameter description. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] pub struct Descriptor @@ -23,8 +24,8 @@ pub struct Descriptor pub struct Parameters { // xxx : is definition as argument fine? - #[ subformer( former::VectorDefinition ) ] - // #[ element_subformer( Descriptor ) ] + #[ container( former::VectorDefinition ) ] + #[ subform ] descriptors : Vec< Descriptor >, } @@ -60,7 +61,8 @@ where storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : Definition::End, - ) -> Self + ) + -> Self { debug_assert!( storage.is_none() ); Self::begin_precise( None, context, on_end ) @@ -136,25 +138,6 @@ where Former2::former_begin( None, Some( self ), ParametersFormerAddDescriptorsEnd::default() ) } - // #[ inline( always ) ] - // pub fn _descriptor_former_set3< Former2 >( self ) -> - // Former2 - // where - // Former2 : SubFormerTrait2< Definition = Definition, Former = Self >, - // // Types2 : former::FormerDefinitionTypes - // // < - // // Storage = DescriptorFormerStorage, - // // Formed = Self, - // // Context = Self, - // // >, - // // Definition2 : former::FormerDefinition< Types = Types2, End = ParametersFormerAddDescriptorsEnd< Definition > >, - // // Former2 : SubFormerTrait< Self, Definition, Definition2, Types2 >, - // { - // Former2::_begin( None, Some( self ), ParametersFormerAddDescriptorsEnd::default() ) - // } - - // xxx2 : move to a trait and make easier to use subformer, trait with generic interface of a container should help - #[ inline( always ) ] pub fn descriptor( self, name : &str ) -> DescriptorSubformer< Self, impl DescriptorSubformerEnd< Self > > @@ -166,158 +149,68 @@ where } -// pub trait SubFormerTrait2 -// where -// < Self::Definition2 as former::FormerDefinition >::Types : former::FormerDefinitionTypes -// < -// Storage = DescriptorFormerStorage, -// Formed = Self::Former, -// Context = Self::Former, -// >, -// Self : former::FormerBegin< Self::Definition2 >, +// xxx : make manual version of the file +// // zzz : improve description +// /// Handles the completion of and element of subformer's container. +// pub struct ParametersFormerAddDescriptorsEnd< Definition > // { -// type Former; -// type Definition; -// type Definition2 : former::FormerDefinition -// < -// End = ParametersFormerAddDescriptorsEnd -// < -// < Self::Definition2 as former::FormerDefinition >::Types, -// Self::Definition, -// >, -// >; -// // type Types2; +// _phantom : core::marker::PhantomData< fn( Definition ) >, // } // -// pub trait SubFormerTrait< Former, Definition, Definition2, Types2 > -// where -// Types2 : former::FormerDefinitionTypes -// < -// Storage = DescriptorFormerStorage, -// Formed = Former, -// Context = Former, -// >, -// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersFormerAddDescriptorsEnd< Definition > >, -// Self : former::FormerBegin< Definition2 >, +// impl< Definition > Default +// for ParametersFormerAddDescriptorsEnd< Definition > // { +// #[ inline( always ) ] +// fn default() -> Self +// { +// Self +// { +// _phantom : core::marker::PhantomData, +// } +// } // } // -// impl< T, Former, Definition, Definition2, Types2 > SubFormerTrait< Former, Definition, Definition2, Types2 > -// for T +// impl< Types2, Definition > former::FormingEnd< Types2, > +// for ParametersFormerAddDescriptorsEnd< Definition > // where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes +// < +// Storage = < Parameters as former::EntityToStorage >::Storage, +// >, // Types2 : former::FormerDefinitionTypes // < -// Storage = DescriptorFormerStorage, -// Formed = Former, -// Context = Former, +// // Storage = < Descriptor as former::EntityToStorage >::Storage, +// Storage = < < Vec< Descriptor > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, +// Formed = ParametersFormer< Definition >, +// Context = ParametersFormer< Definition >, +// // Formed = < Parameters as former::EntityToFormer >::Former, +// // Context = < Parameters as former::EntityToFormer >::Former, // >, -// Definition2 : former::FormerDefinition< Types = Types2, End = ParametersFormerAddDescriptorsEnd< Definition > >, -// Self : former::FormerBegin< Definition2 >, +// // Types2::Storage : former::StoragePreform< Preformed = >, // { +// #[ inline( always ) ] +// fn call +// ( +// &self, +// substorage : Types2::Storage, +// super_former : core::option::Option< Types2::Context >, +// ) +// -> Types2::Formed +// { +// let mut super_former = super_former.unwrap(); +// if super_former.storage.descriptors.is_none() +// { +// super_former.storage.descriptors = Some( Default::default() ); +// } +// if let Some( ref mut fields ) = super_former.storage.descriptors +// { +// former::ContainerAdd::add( fields, former::StoragePreform::preform( substorage ) ); +// } +// super_former +// } // } -// zzz : improve description -/// Handles the completion of and element of subformer's container. -pub struct ParametersFormerAddDescriptorsEnd< Definition > -{ - _phantom : core::marker::PhantomData< fn( Definition ) >, -} - -impl< Definition > Default -for ParametersFormerAddDescriptorsEnd< Definition > -{ - #[ inline( always ) ] - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } -} - -impl< Types2, Definition > former::FormingEnd< Types2, > -for ParametersFormerAddDescriptorsEnd< Definition > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes - < - Storage = < Parameters as former::EntityToStorage >::Storage, - >, - Types2 : former::FormerDefinitionTypes - < - // Storage = < Descriptor as former::EntityToStorage >::Storage, - Storage = < < Vec< Descriptor > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, - Formed = ParametersFormer< Definition >, - Context = ParametersFormer< Definition >, - // Formed = < Parameters as former::EntityToFormer >::Former, - // Context = < Parameters as former::EntityToFormer >::Former, - >, - // Types2::Storage : former::StoragePreform< Preformed = >, -{ - #[ inline( always ) ] - fn call - ( - &self, - substorage : Types2::Storage, - super_former : core::option::Option< Types2::Context >, - ) - -> Types2::Formed - { - let mut super_former = super_former.unwrap(); - if super_former.storage.descriptors.is_none() - { - super_former.storage.descriptors = Some( Default::default() ); - } - if let Some( ref mut fields ) = super_former.storage.descriptors - { - former::ContainerAdd::add( fields, former::StoragePreform::preform( substorage ) ); - } - super_former - } -} - -#[ test ] -fn basic() -{ - - // let x : < Vec< Descriptor > as former::ContainerAdd >::Element; - - let got = Parameters::former() - .descriptors() - .add( Descriptor::former().name( "a" ).form() ) - .add( Descriptor::former().name( "b" ).form() ) - .end() - .form(); - - let descriptors = vec! - [ - Descriptor { name : "a".to_string(), is_mandatory : false }, - Descriptor { name : "b".to_string(), is_mandatory : false }, - ]; - let exp = Parameters { descriptors }; - a_id!( got, exp ); - -} - -#[ test ] -fn descriptor() -{ - - let got = Parameters::former() - .descriptor( "a" ).end() - .descriptor( "b" ).end() - // .add( Descriptor::former().name( "a" ).form() ) - // .add( Descriptor::former().name( "b" ).form() ) - // .end() - .form(); - - let descriptors = vec! - [ - Descriptor { name : "a".to_string(), is_mandatory : false }, - Descriptor { name : "b".to_string(), is_mandatory : false }, - ]; - let exp = Parameters { descriptors }; - a_id!( got, exp ); +// -} +include!( "./only_test/subformer_shortcut.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 89385f7bfc..7be372f041 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -26,42 +26,42 @@ mod former_tests #[ cfg( not( feature = "no_std" ) ) ] mod a_containers_with_subformer ; -// mod attribute_default_container; -// mod attribute_default_primitive; -// mod attribute_perform; -// mod attribute_setter; -// mod attribute_alias; -// // mod attribute_feature; // zzz : write test -// -// mod string_slice_manual; -// mod string_slice; -// mod unsigned_primitive_types; -// mod default_user_type; -// mod user_type_no_default; -// mod user_type_no_debug; -// -// mod name_collision_former_hashmap_without_parameter; -// mod name_collision_former_vector_without_parameter; -// mod name_collisions; -// mod name_collision_context; -// mod name_collision_end; -// mod name_collision_on_end; -// -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_manual; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_imm; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_where; -// -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_basic; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_custom; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_custom_experimental; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_shortcut; + mod attribute_default_container; + mod attribute_default_primitive; + mod attribute_perform; + mod attribute_setter; + mod attribute_alias; + // mod attribute_feature; // zzz : write test + + mod string_slice_manual; + mod string_slice; + mod unsigned_primitive_types; + mod default_user_type; + mod user_type_no_default; + mod user_type_no_debug; + + mod name_collision_former_hashmap_without_parameter; + mod name_collision_former_vector_without_parameter; + mod name_collisions; + mod name_collision_context; + mod name_collision_end; + mod name_collision_on_end; + + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_manual; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_imm; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_where; + + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod subformer_basic; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod subformer_custom; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod subformer_custom_experimental; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_shortcut; // xxx } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 51c7c66af0..a18410b675 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -29,7 +29,8 @@ struct Attributes { default : Option< AttributeDefault >, setter : Option< AttributeSetter >, - subformer : Option< AttributeFormer >, + container : Option< AttributeContainer >, + subform : Option< AttributeSubform >, alias : Option< AttributeAlias >, } @@ -39,7 +40,8 @@ impl Attributes { let mut default = None; let mut setter = None; - let mut subformer = None; + let mut container = None; + let mut subform = None; let mut alias = None; for attr in attributes { @@ -56,7 +58,7 @@ impl Attributes { default.replace( syn::parse2::< AttributeDefault >( meta_list.tokens.clone() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ), + _ => return_syn_err!( attr, "Expects an attribute of format #[ default( val ) ], but got:\n {}", qt!{ #attr } ), } } "setter" => @@ -67,23 +69,35 @@ impl Attributes { setter.replace( syn::parse2::< AttributeSetter >( meta_list.tokens.clone() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ), + _ => return_syn_err!( attr, "Expects an attribute of format #[ setter( val ) ], but got:\n {}", qt!{ #attr } ), } // let attr_setter = syn::parse2::< AttributeSetter >( attr.tokens.clone() )?; // setter.replace( attr_setter ); } - "subformer" => + "container" => { match attr.meta { syn::Meta::List( ref meta_list ) => { - subformer.replace( syn::parse2::< AttributeFormer >( meta_list.tokens.clone() )? ); + container.replace( syn::parse2::< AttributeContainer >( meta_list.tokens.clone() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ), + _ => return_syn_err!( attr, "Expects an attribute of format #[ container( val ) ], but got:\n {}", qt!{ #attr } ), + } + } + // xxx + "subform" => + { + match attr.meta + { + syn::Meta::Path( ref _path ) => + { + // code_print!( _path ); + // panic!( "xxx!" ); + subform.replace( syn::parse2::< AttributeSubform >( Default::default() )? ); + }, + _ => return_syn_err!( attr, "Expects an attribute of format #[ subform ], but got:\n {}", qt!{ #attr } ), } - // let attr_former = syn::parse2::< AttributeFormer >( attr.tokens.clone() )?; - // subformer.replace( attr_former ); } "alias" => { @@ -93,7 +107,7 @@ impl Attributes { alias.replace( syn::parse2::< AttributeAlias >( meta_list.tokens.clone() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ), + _ => return_syn_err!( attr, "Expects an attribute of format #[ alias( val ) ], but got:\n {}", qt!{ #attr } ), } // let attr_alias = syn::parse2::< AttributeAlias >( attr.tokens.clone() )?; // alias.replace( attr_alias ); @@ -108,7 +122,7 @@ impl Attributes } } - Ok( Attributes { default, setter, subformer, alias } ) + Ok( Attributes { default, setter, container, subform, alias } ) } } @@ -200,31 +214,45 @@ impl syn::parse::Parse for AttributeSetter /// Also known as subformers, used for aggregation relationship, when a struct holds another struct, which needs to be build by invoking multiple methods /// Typical example is a struct holding a `Vec` /// -/// `#[ subformer( former::VectorSubformer ) ]` +/// `#[ container( former::VectorSubformer ) ]` /// // qqq : update documentation #[ allow( dead_code ) ] -struct AttributeFormer +struct AttributeContainer { - // paren_token : syn::token::Paren, expr : syn::Type, } -impl syn::parse::Parse for AttributeFormer +impl syn::parse::Parse for AttributeContainer { fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > { - // let input2; Ok( Self { - // paren_token : syn::parenthesized!( input2 in input ), - // expr : input2.parse()?, expr : input.parse()?, }) } } +/// zzz : write description with example +#[ allow( dead_code ) ] +struct AttributeSubform +{ + // expr : syn::Type, +} + +impl syn::parse::Parse for AttributeSubform +{ + fn parse( _input : syn::parse::ParseStream< '_ > ) -> Result< Self > + { + Ok( Self + { + // expr : input.parse()?, + }) + } +} + /// /// Attribute to create alias. /// @@ -535,9 +563,8 @@ fn field_setter_map( field : &FormerField< '_ >, stru : &syn::Ident ) -> Result< let non_optional_ty = &field.non_optional_ty; // Either subformer or ordinary setter. - let setter_tokens = if let Some( _subformer_ty ) = &field.attrs.subformer + let setter_tokens = if let Some( _container_ty ) = &field.attrs.container { - // subformer_field_setter( ident, ident, non_optional_ty, &subformer_ty.expr ) subformer_field_setter( field, stru ) } else @@ -659,7 +686,7 @@ fn subformer_field_setter let params = typ::type_parameters( &non_optional_ty, .. ); // params.iter().for_each( | e | println!( "{}", qt!( #e ) ) ); - let subformer_definition = &field.attrs.subformer.as_ref().unwrap().expr; + let subformer_definition = &field.attrs.container.as_ref().unwrap().expr; // for example : former::VectorDefinition use convert_case::{ Case, Casing }; @@ -671,7 +698,7 @@ fn subformer_field_setter let doc = format! ( - "Subformer setter for the '{}' field. Method {} unlike method {} accept custom subformer.", + "Subformer setter for the '{}' field. Method {} unlike method {} accept custom container subformer.", field_ident, field_assign_name, field_ident, @@ -846,7 +873,7 @@ fn subformer_field_setter /// ``` #[ inline ] -fn fields_setter_callback_descriptor_map +fn field_former_assign_map ( field : &FormerField< '_ >, stru : &syn::Ident, @@ -855,39 +882,40 @@ fn fields_setter_callback_descriptor_map former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - struct_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + _struct_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - struct_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, + _struct_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, ) -> Result< TokenStream > { - if field.attrs.subformer.is_none() + if field.attrs.container.is_none() { return Ok( qt!{ } ); } // example : `former::VectorDefinition`` - let subformer_definition = &field.attrs.subformer.as_ref().unwrap().expr; + let subformer_definition = &field.attrs.container.as_ref().unwrap().expr; use convert_case::{ Case, Casing }; let field_ident = field.ident; + let field_ty = field.non_optional_ty; + let params = typ::type_parameters( &field.non_optional_ty, .. ); + // example : `ParametersFormerAssignDescriptorsEnd`` let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); - // example : `ParametersFormerAddDescriptorsEnd`` - let parent_add_element_end_name = format!( "{}FormerAdd{}End2", stru, field_ident.to_string().to_case( Case::Pascal ) ); - let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); - let field_ty = field.non_optional_ty; - let params = typ::type_parameters( &field.non_optional_ty, .. ); + // // example : `ParametersFormerAddDescriptorsEnd`` + // let parent_add_element_end_name = format!( "{}FormerAdd{}End2", stru, field_ident.to_string().to_case( Case::Pascal ) ); + // let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); let r = qt! { // zzz : description - /// Return original former after subformer for `vec_1` is done. + /// Return original former after container for `vec_1` is done. #[ allow( non_camel_case_types ) ] pub struct #former_assign_end; @@ -927,6 +955,52 @@ Result< TokenStream > } } + }; + + // tree_print!( r.as_ref().unwrap() ); + Ok( r ) +} + +/// xxx : write documentation + +#[ inline ] +fn field_former_add_map +( + field : &FormerField< '_ >, + stru : &syn::Ident, + former : &syn::Ident, + _former_storage : &syn::Ident, + _former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + _former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, + struct_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + struct_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, +) +-> +Result< TokenStream > +{ + + if field.attrs.subform.is_none() + { + return Ok( qt!{ } ); + } + + // example : `former::VectorDefinition`` + // let subformer_definition = &field.attrs.subform.as_ref().unwrap().expr; + + use convert_case::{ Case, Casing }; + let field_ident = field.ident; + let field_ty = field.non_optional_ty; + // let params = typ::type_parameters( &field.non_optional_ty, .. ); + + // example : `ParametersFormerAddDescriptorsEnd`` + let parent_add_element_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); + + let r = qt! + { + // #[ inline( always ) ] // pub fn _descriptor_former_set2< Former2, Definition2, Types2 >( self ) -> // Former2 @@ -945,68 +1019,68 @@ Result< TokenStream > // xxx : uncomment -// // zzz : improve description -// /// Handles the completion of an element of subformer's container. -// pub struct #parent_add_element_end< Definition > -// { -// _phantom : core::marker::PhantomData< fn( Definition ) >, -// } -// -// impl< Definition > Default -// for #parent_add_element_end< Definition > -// { -// #[ inline( always ) ] -// fn default() -> Self -// { -// Self -// { -// _phantom : core::marker::PhantomData, -// } -// } -// } -// -// impl< #struct_generics_impl Types2, Definition > former::FormingEnd< Types2, > -// for #parent_add_element_end< Definition > -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes -// < -// Storage = < #stru < #struct_generics_ty > as former::EntityToStorage >::Storage, -// // xxx : add test with life time + param + containers -// >, -// Types2 : former::FormerDefinitionTypes -// < -// // Storage = < Descriptor as former::EntityToStorage >::Storage, -// // Formed = ParametersFormer< Definition >, -// // Context = ParametersFormer< Definition >, -// // Storage = < < Vec< #field_ident > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, -// Storage = < < #field_ty as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, -// Formed = #former< #former_generics_ty >, -// Context = #former< #former_generics_ty >, -// >, -// #struct_generics_where -// { -// #[ inline( always ) ] -// fn call -// ( -// &self, -// substorage : Types2::Storage, -// super_former : core::option::Option< Types2::Context >, -// ) -// -> Types2::Formed -// { -// let mut super_former = super_former.unwrap(); -// if super_former.storage.#field_ident.is_none() -// { -// super_former.storage.#field_ident = Some( Default::default() ); -// } -// if let Some( ref mut field ) = super_former.storage.#field_ident -// { -// former::ContainerAdd::add( field, former::StoragePreform::preform( substorage ) ); -// } -// super_former -// } -// } + // zzz : improve description + /// Handles the completion of an element of subformer's container. + pub struct #parent_add_element_end< Definition > + { + _phantom : core::marker::PhantomData< fn( Definition ) >, + } + + impl< Definition > Default + for #parent_add_element_end< Definition > + { + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + } + + impl< #struct_generics_impl Types2, Definition > former::FormingEnd< Types2, > + for #parent_add_element_end< Definition > + where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = < #stru < #struct_generics_ty > as former::EntityToStorage >::Storage, + // xxx : add test with life time + param + containers + >, + Types2 : former::FormerDefinitionTypes + < + // Storage = < Descriptor as former::EntityToStorage >::Storage, + // Formed = ParametersFormer< Definition >, + // Context = ParametersFormer< Definition >, + // Storage = < < Vec< #field_ident > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + Storage = < < #field_ty as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + Formed = #former< #former_generics_ty >, + Context = #former< #former_generics_ty >, + >, + #struct_generics_where + { + #[ inline( always ) ] + fn call + ( + &self, + substorage : Types2::Storage, + super_former : core::option::Option< Types2::Context >, + ) + -> Types2::Formed + { + let mut super_former = super_former.unwrap(); + if super_former.storage.#field_ident.is_none() + { + super_former.storage.#field_ident = Some( Default::default() ); + } + if let Some( ref mut field ) = super_former.storage.#field_ident + { + former::ContainerAdd::add( field, former::StoragePreform::preform( substorage ) ); + } + super_former + } + } }; @@ -1289,10 +1363,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > fields_form, fields_names, fields_setter, - fields_setter_callback_descriptor, + fields_former_assign, + fields_former_add, ) : - ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) + ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) = former_fields.iter().map( | former_field | {( field_none_map( former_field ), @@ -1300,7 +1375,20 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field_form_map( former_field ), field_name_map( former_field ), field_setter_map( former_field, &stru ), - fields_setter_callback_descriptor_map + field_former_assign_map + ( + former_field, + &stru, + &former, + &former_storage, + &former_generics_impl, + &former_generics_ty, + &former_generics_where, + &struct_generics_impl, + &struct_generics_ty, + &struct_generics_where, + ), + field_former_add_map ( former_field, &stru, @@ -1318,7 +1406,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( _doc_former_mod, doc_former_struct ) = doc_generate( stru ); let fields_setter : Vec< _ > = process_results( fields_setter, | iter | iter.collect() )?; let fields_form : Vec< _ > = process_results( fields_form, | iter | iter.collect() )?; - let fields_setter_callback_descriptor : Vec< _ > = process_results( fields_setter_callback_descriptor, | iter | iter.collect() )?; + let fields_former_assign : Vec< _ > = process_results( fields_former_assign, | iter | iter.collect() )?; + let fields_former_add : Vec< _ > = process_results( fields_former_add, | iter | iter.collect() )?; let result = qt! { @@ -1718,10 +1807,16 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { } - // = setters + // = container assign callbacks + + #( + #fields_former_assign + )* + + // = container add callbacks #( - #fields_setter_callback_descriptor + #fields_former_add )* }; diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index f585486925..d4ee961f2d 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -27,10 +27,10 @@ mod derive } +// zzz : outdated /// /// Derive macro to generate former for a structure. Former is variation of Builder Pattern. /// - /// Derives a 'Former' for a struct, implementing a variation of the Builder Pattern. /// /// This macro simplifies the creation of builder patterns for structs by automatically @@ -272,7 +272,7 @@ mod derive #[ cfg( feature = "enabled" ) ] #[ cfg( feature = "derive_former" ) ] -#[ proc_macro_derive( Former, attributes( debug, perform, default, setter, subformer, alias, doc, embed ) ) ] +#[ proc_macro_derive( Former, attributes( debug, perform, default, setter, container, subform, alias, doc, embed ) ) ] pub fn former( input : proc_macro::TokenStream ) -> proc_macro::TokenStream { let result = derive::former::former( input ); From 9041bb0d172168f7c00964ca220ef6200895cb2d Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 22:10:01 +0300 Subject: [PATCH 287/533] former : experimenting --- .../only_test/subformer_shortcut.rs | 32 +-- .../inc/former_tests/subformer_shortcut.rs | 141 +++---------- .../former_tests/subformer_shortcut_manual.rs | 185 ++++++++++++++++++ module/core/former/tests/inc/mod.rs | 4 +- module/core/former_meta/src/derive/former.rs | 16 +- 5 files changed, 237 insertions(+), 141 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs index 039fc8ed30..824cda487d 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs @@ -3,21 +3,21 @@ fn basic() { - // let x : < Vec< Descriptor > as former::ContainerAdd >::Element; + // let x : < Vec< Child > as former::ContainerAdd >::Element; - let got = Parameters::former() - .descriptors() - .add( Descriptor::former().name( "a" ).form() ) - .add( Descriptor::former().name( "b" ).form() ) + let got = Parent::former() + .children() + .add( Child::former().name( "a" ).form() ) + .add( Child::former().name( "b" ).form() ) .end() .form(); - let descriptors = vec! + let children = vec! [ - Descriptor { name : "a".to_string(), is_mandatory : false }, - Descriptor { name : "b".to_string(), is_mandatory : false }, + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, ]; - let exp = Parameters { descriptors }; + let exp = Parent { children }; a_id!( got, exp ); } @@ -26,20 +26,20 @@ fn basic() fn descriptor() { - let got = Parameters::former() + let got = Parent::former() .descriptor( "a" ).end() .descriptor( "b" ).end() - // .add( Descriptor::former().name( "a" ).form() ) - // .add( Descriptor::former().name( "b" ).form() ) + // .add( Child::former().name( "a" ).form() ) + // .add( Child::former().name( "b" ).form() ) // .end() .form(); - let descriptors = vec! + let children = vec! [ - Descriptor { name : "a".to_string(), is_mandatory : false }, - Descriptor { name : "b".to_string(), is_mandatory : false }, + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, ]; - let exp = Parameters { descriptors }; + let exp = Parent { children }; a_id!( got, exp ); } diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 46d337fb4a..7772ffdd61 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -2,57 +2,28 @@ use super::*; -// xxx : rename -/// Parameter description. +/// Child #[ derive( Debug, Default, PartialEq, the_module::Former ) ] -pub struct Descriptor +pub struct Child { name : String, is_mandatory : bool, } -// impl former::EntityToFormer_ for Descriptor -// where -// Self : Sized, -// { -// type Storage = DescriptorFormerStorage; -// type Former = DescriptorFormer; -// } - -/// Parameters required for the template. +/// Parent #[ derive( Debug, Default, PartialEq, the_module::Former ) ] -pub struct Parameters +pub struct Parent { // xxx : is definition as argument fine? #[ container( former::VectorDefinition ) ] #[ subform ] - descriptors : Vec< Descriptor >, + children : Vec< Child >, } -// impl former::EntityToFormer_ for Parameters -// where -// Self : Sized, -// { -// type Storage = ParametersFormerStorage; -// type Former = ParametersFormer; -// } - -// impl< Definition > former::EntityToFormer< Definition > for Parameters -// where -// Definition : former::FormerDefinition< Storage = ParametersFormerStorage >, -// { -// type Former = ParametersFormer< Definition >; -// } -// -// impl former::EntityToStorage for Parameters -// { -// type Storage = ParametersFormerStorage; -// } - impl< Definition > former::FormerBegin< Definition > -for DescriptorFormer< Definition > +for ChildFormer< Definition > where - Definition : former::FormerDefinition< Storage = DescriptorFormerStorage >, + Definition : former::FormerDefinition< Storage = ChildFormerStorage >, { #[ inline( always ) ] @@ -70,19 +41,19 @@ where } -impl< Definition > ParametersFormer< Definition > +impl< Definition > ParentFormer< Definition > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = < Parameters as former::EntityToStorage >::Storage >, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, { #[ inline( always ) ] - pub fn _descriptor_former_with_closure< Former2, Definition2, Types2 >( self ) -> + pub fn _children_former_with_closure< Former2, Definition2, Types2 >( self ) -> Former2 where Types2 : former::FormerDefinitionTypes < - Storage = DescriptorFormerStorage, + Storage = ChildFormerStorage, Formed = Self, Context = Self, >, @@ -90,7 +61,7 @@ where < Types = Types2, End = former::FormingEndClosure< Types2 >, - Storage = DescriptorFormerStorage, + Storage = ChildFormerStorage, Formed = Self, Context = Self, >, @@ -100,16 +71,16 @@ where Definition2, >, { - let on_end = | substorage : DescriptorFormerStorage, super_former : core::option::Option< Self > | -> Self + let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self { let mut super_former = super_former.unwrap(); - if super_former.storage.descriptors.is_none() + if super_former.storage.children.is_none() { - super_former.storage.descriptors = Some( Default::default() ); + super_former.storage.children = Some( Default::default() ); } - if let Some( ref mut descriptors ) = super_former.storage.descriptors + if let Some( ref mut children ) = super_former.storage.children { - former::ContainerAdd::add( descriptors, former::StoragePreform::preform( substorage ) ); + former::ContainerAdd::add( children, former::StoragePreform::preform( substorage ) ); } super_former }; @@ -117,100 +88,38 @@ where } #[ inline( always ) ] - pub fn _descriptor_former_set2< Former2, Definition2 >( self ) -> + pub fn _children_former< Former2, Definition2 >( self ) -> Former2 where Definition2 : former::FormerDefinition < - End = ParametersFormerAddDescriptorsEnd< Definition >, - Storage = < Descriptor as former::EntityToStorage >::Storage, + End = ParentFormerAddChildrenEnd< Definition >, + Storage = < Child as former::EntityToStorage >::Storage, Formed = Self, Context = Self, >, Definition2::Types : former::FormerDefinitionTypes < - Storage = < Descriptor as former::EntityToStorage >::Storage, + Storage = < Child as former::EntityToStorage >::Storage, Formed = Self, Context = Self, >, Former2 : former::FormerBegin< Definition2 >, { - Former2::former_begin( None, Some( self ), ParametersFormerAddDescriptorsEnd::default() ) + Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) } #[ inline( always ) ] pub fn descriptor( self, name : &str ) -> - DescriptorSubformer< Self, impl DescriptorSubformerEnd< Self > > + ChildSubformer< Self, impl ChildSubformerEnd< Self > > { - self._descriptor_former_set2 - ::< DescriptorFormer< _ >, _, >() + self._children_former + ::< ChildFormer< _ >, _, >() .name( name ) } } -// xxx : make manual version of the file -// // zzz : improve description -// /// Handles the completion of and element of subformer's container. -// pub struct ParametersFormerAddDescriptorsEnd< Definition > -// { -// _phantom : core::marker::PhantomData< fn( Definition ) >, -// } -// -// impl< Definition > Default -// for ParametersFormerAddDescriptorsEnd< Definition > -// { -// #[ inline( always ) ] -// fn default() -> Self -// { -// Self -// { -// _phantom : core::marker::PhantomData, -// } -// } -// } -// -// impl< Types2, Definition > former::FormingEnd< Types2, > -// for ParametersFormerAddDescriptorsEnd< Definition > -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes -// < -// Storage = < Parameters as former::EntityToStorage >::Storage, -// >, -// Types2 : former::FormerDefinitionTypes -// < -// // Storage = < Descriptor as former::EntityToStorage >::Storage, -// Storage = < < Vec< Descriptor > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, -// Formed = ParametersFormer< Definition >, -// Context = ParametersFormer< Definition >, -// // Formed = < Parameters as former::EntityToFormer >::Former, -// // Context = < Parameters as former::EntityToFormer >::Former, -// >, -// // Types2::Storage : former::StoragePreform< Preformed = >, -// { -// #[ inline( always ) ] -// fn call -// ( -// &self, -// substorage : Types2::Storage, -// super_former : core::option::Option< Types2::Context >, -// ) -// -> Types2::Formed -// { -// let mut super_former = super_former.unwrap(); -// if super_former.storage.descriptors.is_none() -// { -// super_former.storage.descriptors = Some( Default::default() ); -// } -// if let Some( ref mut fields ) = super_former.storage.descriptors -// { -// former::ContainerAdd::add( fields, former::StoragePreform::preform( substorage ) ); -// } -// super_former -// } -// } - // include!( "./only_test/subformer_shortcut.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs new file mode 100644 index 0000000000..cad94cd7c0 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs @@ -0,0 +1,185 @@ +#![ allow( dead_code ) ] + +use super::*; + +// xxx : rename +/// Parameter description. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent required for the template. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Parent +{ + #[ container( former::VectorDefinition ) ] + // #[ subform ] + children : Vec< Child >, +} + +impl< Definition > former::FormerBegin< Definition > +for ChildFormer< Definition > +where + Definition : former::FormerDefinition< Storage = ChildFormerStorage >, +{ + + #[ inline( always ) ] + fn former_begin + ( + storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : Definition::End, + ) + -> Self + { + debug_assert!( storage.is_none() ); + Self::begin_precise( None, context, on_end ) + } + +} + +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn _children_former_with_closure< Former2, Definition2, Types2 >( self ) -> + Former2 + where + Types2 : former::FormerDefinitionTypes + < + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2 : former::FormerDefinition + < + Types = Types2, + End = former::FormingEndClosure< Types2 >, + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2::End : former::FormingEnd< Definition2::Types >, + Former2 : former::FormerBegin + < + Definition2, + >, + { + let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + if super_former.storage.children.is_none() + { + super_former.storage.children = Some( Default::default() ); + } + if let Some( ref mut children ) = super_former.storage.children + { + former::ContainerAdd::add( children, former::StoragePreform::preform( substorage ) ); + } + super_former + }; + Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + } + + #[ inline( always ) ] + pub fn _children_former< Former2, Definition2 >( self ) -> + Former2 + where + Definition2 : former::FormerDefinition + < + End = ParentFormerAddChildsEnd< Definition >, + Storage = < Child as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Definition2::Types : former::FormerDefinitionTypes + < + Storage = < Child as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Former2 : former::FormerBegin< Definition2 >, + { + Former2::former_begin( None, Some( self ), ParentFormerAddChildsEnd::default() ) + } + + #[ inline( always ) ] + pub fn descriptor( self, name : &str ) -> + ChildSubformer< Self, impl ChildSubformerEnd< Self > > + { + self._children_former + ::< ChildFormer< _ >, _, >() + .name( name ) + } + +} + +/// Handles the completion of and element of subformer's container. +pub struct ParentFormerAddChildsEnd< Definition > +{ + _phantom : core::marker::PhantomData< fn( Definition ) >, +} + +impl< Definition > Default +for ParentFormerAddChildsEnd< Definition > +{ + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} + +impl< Types2, Definition > former::FormingEnd< Types2, > +for ParentFormerAddChildsEnd< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = < Parent as former::EntityToStorage >::Storage, + >, + Types2 : former::FormerDefinitionTypes + < + // Storage = < Child as former::EntityToStorage >::Storage, + Storage = < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + Formed = ParentFormer< Definition >, + Context = ParentFormer< Definition >, + // Formed = < Parent as former::EntityToFormer >::Former, + // Context = < Parent as former::EntityToFormer >::Former, + >, + // Types2::Storage : former::StoragePreform< Preformed = >, +{ + #[ inline( always ) ] + fn call + ( + &self, + substorage : Types2::Storage, + super_former : core::option::Option< Types2::Context >, + ) + -> Types2::Formed + { + let mut super_former = super_former.unwrap(); + if super_former.storage.children.is_none() + { + super_former.storage.children = Some( Default::default() ); + } + if let Some( ref mut fields ) = super_former.storage.children + { + former::ContainerAdd::add( fields, former::StoragePreform::preform( substorage ) ); + } + super_former + } +} + +// + +include!( "./only_test/subformer_shortcut.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 7be372f041..d13e70be60 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -60,9 +60,11 @@ mod former_tests mod subformer_custom; #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod subformer_custom_experimental; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_shortcut_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_shortcut; -// xxx } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index a18410b675..3d133837ab 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -830,7 +830,7 @@ fn subformer_field_setter } // zzz : description and exmaple -/// Generate unit struct which is descriptor of callback which should be called after subforming process of a specific field. Descriptors are used insted of closures to inline code and let optimizer play with optimization. +/// Generate unit struct which is descriptor of callback which should be called after subforming process of a specific field. Childs are used insted of closures to inline code and let optimizer play with optimization. /// /// # Example of generated code /// @@ -903,11 +903,11 @@ Result< TokenStream > let field_ty = field.non_optional_ty; let params = typ::type_parameters( &field.non_optional_ty, .. ); - // example : `ParametersFormerAssignDescriptorsEnd`` + // example : `ParentFormerAssignChildsEnd`` let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); - // // example : `ParametersFormerAddDescriptorsEnd`` + // // example : `ParentFormerAddChildsEnd`` // let parent_add_element_end_name = format!( "{}FormerAdd{}End2", stru, field_ident.to_string().to_case( Case::Pascal ) ); // let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); @@ -994,7 +994,7 @@ Result< TokenStream > let field_ty = field.non_optional_ty; // let params = typ::type_parameters( &field.non_optional_ty, .. ); - // example : `ParametersFormerAddDescriptorsEnd`` + // example : `ParentFormerAddChildsEnd`` let parent_add_element_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); @@ -1007,7 +1007,7 @@ Result< TokenStream > // where // Types2 : former::FormerDefinitionTypes // < - // Storage = DescriptorFormerStorage, + // Storage = ChildFormerStorage, // Formed = Self, // Context = Self, // >, @@ -1050,9 +1050,9 @@ Result< TokenStream > >, Types2 : former::FormerDefinitionTypes < - // Storage = < Descriptor as former::EntityToStorage >::Storage, - // Formed = ParametersFormer< Definition >, - // Context = ParametersFormer< Definition >, + // Storage = < Child as former::EntityToStorage >::Storage, + // Formed = ParentFormer< Definition >, + // Context = ParentFormer< Definition >, // Storage = < < Vec< #field_ident > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, Storage = < < #field_ty as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, Formed = #former< #former_generics_ty >, From fe31218bd758030014aa4fe34ffac6c15187ffc6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 22:30:27 +0300 Subject: [PATCH 288/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 25 ++++++++++++++-- .../tests/inc/former_tests/only_test/basic.rs | 16 ++++++++++ .../inc/former_tests/subformer_shortcut.rs | 4 +-- module/core/former/tests/inc/mod.rs | 10 ++++--- module/core/former_meta/src/derive/former.rs | 29 +++++++++++++++++++ 5 files changed, 76 insertions(+), 8 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 77abf58447..f485824477 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -7,7 +7,7 @@ pub struct Struct1 pub int_1 : i32, } -// === begin_coercing of generated +// == begin of generated // = formed @@ -284,6 +284,27 @@ where } } -// === end of generated +impl< Definition > former::FormerBegin< Definition > +for Struct1Former< Definition > +where + Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, +{ + + #[ inline( always ) ] + fn former_begin + ( + storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Definition::Context >, + on_end : Definition::End, + ) + -> Self + { + debug_assert!( storage.is_none() ); + Self::begin_precise( None, context, on_end ) + } + +} + +// == end of generated include!( "./only_test/basic.rs" ); diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index d477b82534..a2d0b8bb22 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -51,6 +51,21 @@ tests_impls! // + fn former_begin() + { + + let former = < Struct1Former as former::FormerBegin< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > > + ::former_begin( None, None, former::ReturnPreformed ); + let got = former + .int_1( 13 ) + .form(); + let exp = Struct1 { int_1 : 13 }; + a_id!( got, exp ); + + } + + // + fn custom_definition_params() { @@ -532,6 +547,7 @@ tests_index! { internals, entity_to_former, + former_begin, custom_definition_params, begin_coercing, begin_precise, diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 7772ffdd61..c0d6bdff03 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -29,8 +29,8 @@ where #[ inline( always ) ] fn former_begin ( - storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Definition::Context >, on_end : Definition::End, ) -> Self diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index d13e70be60..0a8ac5ab38 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -16,6 +16,7 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod container_former_hashmap; + // xxx mod a_basic_manual; mod a_basic; mod a_primitives_manual; @@ -61,10 +62,11 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod subformer_custom_experimental; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_shortcut_manual; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_shortcut; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_shortcut_manual; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_shortcut; + // xxx } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 3d133837ab..ec3bf32c47 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1760,6 +1760,35 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } + // = former begin + + impl< #struct_generics_impl Definition > former::FormerBegin< Definition > + // for ChildFormer< Definition > + for #former + < + #struct_generics_ty + Definition, + > + where + Definition : former::FormerDefinition< Storage = #former_storage < #struct_generics_ty > >, + #struct_generics_where + { + + #[ inline( always ) ] + fn former_begin + ( + storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Definition::Context >, + on_end : Definition::End, + ) + -> Self + { + debug_assert!( storage.is_none() ); + Self::begin_precise( None, context, on_end ) + } + + } + // = subformer // zzz : improve description From e31d0bd40f257faa4279556485a07eb555c81fe7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 22:31:12 +0300 Subject: [PATCH 289/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 21 ---------- .../former_tests/subformer_shortcut_manual.rs | 40 +++++++++---------- module/core/former/tests/inc/mod.rs | 9 ++--- 3 files changed, 24 insertions(+), 46 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index c0d6bdff03..7b903d74d3 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -20,27 +20,6 @@ pub struct Parent children : Vec< Child >, } -impl< Definition > former::FormerBegin< Definition > -for ChildFormer< Definition > -where - Definition : former::FormerDefinition< Storage = ChildFormerStorage >, -{ - - #[ inline( always ) ] - fn former_begin - ( - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Definition::Context >, - on_end : Definition::End, - ) - -> Self - { - debug_assert!( storage.is_none() ); - Self::begin_precise( None, context, on_end ) - } - -} - impl< Definition > ParentFormer< Definition > where Definition : former::FormerDefinition, diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs index cad94cd7c0..c316b4c58d 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs @@ -20,26 +20,26 @@ pub struct Parent children : Vec< Child >, } -impl< Definition > former::FormerBegin< Definition > -for ChildFormer< Definition > -where - Definition : former::FormerDefinition< Storage = ChildFormerStorage >, -{ - - #[ inline( always ) ] - fn former_begin - ( - storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : Definition::End, - ) - -> Self - { - debug_assert!( storage.is_none() ); - Self::begin_precise( None, context, on_end ) - } - -} +// impl< Definition > former::FormerBegin< Definition > +// for ChildFormer< Definition > +// where +// Definition : former::FormerDefinition< Storage = ChildFormerStorage >, +// { +// +// #[ inline( always ) ] +// fn former_begin +// ( +// storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, +// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, +// on_end : Definition::End, +// ) +// -> Self +// { +// debug_assert!( storage.is_none() ); +// Self::begin_precise( None, context, on_end ) +// } +// +// } impl< Definition > ParentFormer< Definition > where diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 0a8ac5ab38..c0a6d9bba1 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -16,7 +16,6 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod container_former_hashmap; - // xxx mod a_basic_manual; mod a_basic; mod a_primitives_manual; @@ -62,10 +61,10 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod subformer_custom_experimental; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_shortcut_manual; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_shortcut; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_shortcut_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_shortcut; // xxx } From 3475e5300d113cf796e03e9e2af001697e817662 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 22:35:54 +0300 Subject: [PATCH 290/533] former : experimenting --- .../only_test/subformer_shortcut.rs | 30 +++++------ .../inc/former_tests/subformer_shortcut.rs | 52 ++----------------- .../former_tests/subformer_shortcut_manual.rs | 2 +- 3 files changed, 20 insertions(+), 64 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs index 824cda487d..7934ca0ad9 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs @@ -3,22 +3,20 @@ fn basic() { - // let x : < Vec< Child > as former::ContainerAdd >::Element; - - let got = Parent::former() - .children() - .add( Child::former().name( "a" ).form() ) - .add( Child::former().name( "b" ).form() ) - .end() - .form(); - - let children = vec! - [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, - ]; - let exp = Parent { children }; - a_id!( got, exp ); +// let got = Parent::former() +// .children() +// .add( Child::former().name( "a" ).form() ) +// .add( Child::former().name( "b" ).form() ) +// .end() +// .form(); +// +// let children = vec! +// [ +// Child { name : "a".to_string(), is_mandatory : false }, +// Child { name : "b".to_string(), is_mandatory : false }, +// ]; +// let exp = Parent { children }; +// a_id!( got, exp ); } diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 7b903d74d3..74298e1bd6 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -15,7 +15,8 @@ pub struct Child pub struct Parent { // xxx : is definition as argument fine? - #[ container( former::VectorDefinition ) ] + // xxx : add another test to make sure attributes container and subform are compatible + // #[ container( former::VectorDefinition ) ] #[ subform ] children : Vec< Child >, } @@ -27,48 +28,7 @@ where { #[ inline( always ) ] - pub fn _children_former_with_closure< Former2, Definition2, Types2 >( self ) -> - Former2 - where - Types2 : former::FormerDefinitionTypes - < - Storage = ChildFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2 : former::FormerDefinition - < - Types = Types2, - End = former::FormingEndClosure< Types2 >, - Storage = ChildFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2::End : former::FormingEnd< Definition2::Types >, - Former2 : former::FormerBegin - < - Definition2, - >, - { - let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if super_former.storage.children.is_none() - { - super_former.storage.children = Some( Default::default() ); - } - if let Some( ref mut children ) = super_former.storage.children - { - former::ContainerAdd::add( children, former::StoragePreform::preform( substorage ) ); - } - super_former - }; - Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) - } - - #[ inline( always ) ] - pub fn _children_former< Former2, Definition2 >( self ) -> - Former2 + pub fn _children_former< Former2, Definition2 >( self ) -> Former2 where Definition2 : former::FormerDefinition < @@ -89,11 +49,9 @@ where } #[ inline( always ) ] - pub fn descriptor( self, name : &str ) -> - ChildSubformer< Self, impl ChildSubformerEnd< Self > > + pub fn descriptor( self, name : &str ) -> ChildSubformer< Self, impl ChildSubformerEnd< Self > > { - self._children_former - ::< ChildFormer< _ >, _, >() + self._children_former::< ChildFormer< _ >, _, >() .name( name ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs index c316b4c58d..c764a2cc30 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs @@ -15,7 +15,7 @@ pub struct Child #[ derive( Debug, Default, PartialEq, the_module::Former ) ] pub struct Parent { - #[ container( former::VectorDefinition ) ] + // #[ container( former::VectorDefinition ) ] // #[ subform ] children : Vec< Child >, } From a2767446271e191af6da1eed693abbc84be0f207 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 22:36:38 +0300 Subject: [PATCH 291/533] former : experimenting --- .../tests/inc/former_tests/only_test/subformer_shortcut.rs | 6 +++--- .../former/tests/inc/former_tests/subformer_shortcut.rs | 2 +- .../tests/inc/former_tests/subformer_shortcut_manual.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs index 7934ca0ad9..22d24e69ac 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs @@ -21,12 +21,12 @@ fn basic() } #[ test ] -fn descriptor() +fn child() { let got = Parent::former() - .descriptor( "a" ).end() - .descriptor( "b" ).end() + .child( "a" ).end() + .child( "b" ).end() // .add( Child::former().name( "a" ).form() ) // .add( Child::former().name( "b" ).form() ) // .end() diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 74298e1bd6..9d336701a7 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -49,7 +49,7 @@ where } #[ inline( always ) ] - pub fn descriptor( self, name : &str ) -> ChildSubformer< Self, impl ChildSubformerEnd< Self > > + pub fn child( self, name : &str ) -> ChildSubformer< Self, impl ChildSubformerEnd< Self > > { self._children_former::< ChildFormer< _ >, _, >() .name( name ) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs index c764a2cc30..0920e82cb1 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs @@ -110,7 +110,7 @@ where } #[ inline( always ) ] - pub fn descriptor( self, name : &str ) -> + pub fn child( self, name : &str ) -> ChildSubformer< Self, impl ChildSubformerEnd< Self > > { self._children_former From f491ccc3f69c51adc55f8da17c65fb05943a4753 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 22:52:32 +0300 Subject: [PATCH 292/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 40 ++++---- module/core/former_meta/src/derive/former.rs | 99 ++++++++++++++----- 2 files changed, 95 insertions(+), 44 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 9d336701a7..60f1e3251f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -27,26 +27,26 @@ where Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, { - #[ inline( always ) ] - pub fn _children_former< Former2, Definition2 >( self ) -> Former2 - where - Definition2 : former::FormerDefinition - < - End = ParentFormerAddChildrenEnd< Definition >, - Storage = < Child as former::EntityToStorage >::Storage, - Formed = Self, - Context = Self, - >, - Definition2::Types : former::FormerDefinitionTypes - < - Storage = < Child as former::EntityToStorage >::Storage, - Formed = Self, - Context = Self, - >, - Former2 : former::FormerBegin< Definition2 >, - { - Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) - } + // #[ inline( always ) ] + // pub fn _children_former< Former2, Definition2 >( self ) -> Former2 + // where + // Definition2 : former::FormerDefinition + // < + // End = ParentFormerAddChildrenEnd< Definition >, + // Storage = < Child as former::EntityToStorage >::Storage, + // Formed = Self, + // Context = Self, + // >, + // Definition2::Types : former::FormerDefinitionTypes + // < + // Storage = < Child as former::EntityToStorage >::Storage, + // Formed = Self, + // Context = Self, + // >, + // Former2 : former::FormerBegin< Definition2 >, + // { + // Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) + // } #[ inline( always ) ] pub fn child( self, name : &str ) -> ChildSubformer< Self, impl ChildSubformerEnd< Self > > diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index ec3bf32c47..9f9bda4e02 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -575,22 +575,92 @@ fn field_setter_map( field : &FormerField< '_ >, stru : &syn::Ident ) -> Result< let r = if let Some( alias_attr ) = &field.attrs.alias { let alias_tokens = field_setter( ident, &alias_attr.alias, non_optional_ty ); - let token = qt! + qt! { #setter_tokens #alias_tokens - }; - Ok( token ) + } } else { - Ok( setter_tokens ) + setter_tokens + }; + + let r = if field.attrs.subform.is_some() + { + let subformer = field_subformer_map( field, stru )?; + qt! + { + #r + #subformer + } + } + else + { + r }; // tree_print!( r.as_ref().unwrap() ); - r + Ok( r ) } +/// xxx : write documentation + +#[ inline ] +fn field_subformer_map +( + field : &FormerField< '_ >, + stru : &syn::Ident +) -> Result< TokenStream > +{ + + if field.attrs.subform.is_none() + { + return Ok( qt!{ } ); + } + + use convert_case::{ Case, Casing }; + let field_ident = field.ident; + // let field_ty = field.non_optional_ty; + // let params = typ::type_parameters( &field.non_optional_ty, .. ); + + // example : `ParentFormerAddChildsEnd`` + let parent_add_element_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); + + // example : `_children_former` + let child_former_name = format!( "_{}_former", field_ident ); + let child_former = syn::Ident::new( &child_former_name, field_ident.span() ); + + let r = qt! + { + + #[ inline( always ) ] + pub fn #child_former< Former2, Definition2 >( self ) -> Former2 + where + Definition2 : former::FormerDefinition + < + End = #parent_add_element_end< Definition >, + Storage = < Child as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Definition2::Types : former::FormerDefinitionTypes + < + Storage = < Child as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Former2 : former::FormerBegin< Definition2 >, + { + Former2::former_begin( None, Some( self ), #parent_add_element_end::default() ) + } + + }; + + // tree_print!( r.as_ref().unwrap() ); + Ok( r ) +} /// /// Generate a single setter for the 'field_ident' with the 'setter_name' name. @@ -986,9 +1056,6 @@ Result< TokenStream > return Ok( qt!{ } ); } - // example : `former::VectorDefinition`` - // let subformer_definition = &field.attrs.subform.as_ref().unwrap().expr; - use convert_case::{ Case, Casing }; let field_ident = field.ident; let field_ty = field.non_optional_ty; @@ -1001,22 +1068,6 @@ Result< TokenStream > let r = qt! { - // #[ inline( always ) ] - // pub fn _descriptor_former_set2< Former2, Definition2, Types2 >( self ) -> - // Former2 - // where - // Types2 : former::FormerDefinitionTypes - // < - // Storage = ChildFormerStorage, - // Formed = Self, - // Context = Self, - // >, - // Definition2 : former::FormerDefinition< Types = Types2, End = #parent_add_element_end< Types2, Definition > >, - // Former2 : former::FormerBegin< Definition2 >, - // { - // Former2::_begin( None, Some( self ), #parent_add_element_end::default() ) - // } - // xxx : uncomment // zzz : improve description From 4c71480233f292b7d8a6f473953ccf8a9dc3cabb Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 23:05:06 +0300 Subject: [PATCH 293/533] former : experimenting --- .../inc/former_tests/subformer_shortcut.rs | 23 +------- .../former_tests/subformer_shortcut_manual.rs | 6 +-- module/core/former_meta/src/derive/former.rs | 53 +++++-------------- 3 files changed, 18 insertions(+), 64 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs index 60f1e3251f..9021529890 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut.rs @@ -27,31 +27,10 @@ where Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, { - // #[ inline( always ) ] - // pub fn _children_former< Former2, Definition2 >( self ) -> Former2 - // where - // Definition2 : former::FormerDefinition - // < - // End = ParentFormerAddChildrenEnd< Definition >, - // Storage = < Child as former::EntityToStorage >::Storage, - // Formed = Self, - // Context = Self, - // >, - // Definition2::Types : former::FormerDefinitionTypes - // < - // Storage = < Child as former::EntityToStorage >::Storage, - // Formed = Self, - // Context = Self, - // >, - // Former2 : former::FormerBegin< Definition2 >, - // { - // Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) - // } - #[ inline( always ) ] pub fn child( self, name : &str ) -> ChildSubformer< Self, impl ChildSubformerEnd< Self > > { - self._children_former::< ChildFormer< _ >, _, >() + self._children_element_subformer::< ChildFormer< _ >, _, >() .name( name ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs b/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs index 0920e82cb1..1fd12a4d31 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs @@ -48,7 +48,7 @@ where { #[ inline( always ) ] - pub fn _children_former_with_closure< Former2, Definition2, Types2 >( self ) -> + pub fn _children_element_subformer_with_closure< Former2, Definition2, Types2 >( self ) -> Former2 where Types2 : former::FormerDefinitionTypes @@ -88,7 +88,7 @@ where } #[ inline( always ) ] - pub fn _children_former< Former2, Definition2 >( self ) -> + pub fn _children_element_subformer< Former2, Definition2 >( self ) -> Former2 where Definition2 : former::FormerDefinition @@ -113,7 +113,7 @@ where pub fn child( self, name : &str ) -> ChildSubformer< Self, impl ChildSubformerEnd< Self > > { - self._children_former + self._children_element_subformer ::< ChildFormer< _ >, _, >() .name( name ) } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 9f9bda4e02..87e3cec152 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -85,7 +85,6 @@ impl Attributes _ => return_syn_err!( attr, "Expects an attribute of format #[ container( val ) ], but got:\n {}", qt!{ #attr } ), } } - // xxx "subform" => { match attr.meta @@ -93,7 +92,6 @@ impl Attributes syn::Meta::Path( ref _path ) => { // code_print!( _path ); - // panic!( "xxx!" ); subform.replace( syn::parse2::< AttributeSubform >( Default::default() )? ); }, _ => return_syn_err!( attr, "Expects an attribute of format #[ subform ], but got:\n {}", qt!{ #attr } ), @@ -563,9 +561,9 @@ fn field_setter_map( field : &FormerField< '_ >, stru : &syn::Ident ) -> Result< let non_optional_ty = &field.non_optional_ty; // Either subformer or ordinary setter. - let setter_tokens = if let Some( _container_ty ) = &field.attrs.container + let r = if let Some( _container_ty ) = &field.attrs.container { - subformer_field_setter( field, stru ) + container_setter( field, stru ) } else { @@ -577,13 +575,13 @@ fn field_setter_map( field : &FormerField< '_ >, stru : &syn::Ident ) -> Result< let alias_tokens = field_setter( ident, &alias_attr.alias, non_optional_ty ); qt! { - #setter_tokens + #r #alias_tokens } } else { - setter_tokens + r }; let r = if field.attrs.subform.is_some() @@ -604,7 +602,7 @@ fn field_setter_map( field : &FormerField< '_ >, stru : &syn::Ident ) -> Result< Ok( r ) } -/// xxx : write documentation +/// zzz : write documentation #[ inline ] fn field_subformer_map @@ -629,14 +627,16 @@ fn field_subformer_map let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); // example : `_children_former` - let child_former_name = format!( "_{}_former", field_ident ); - let child_former = syn::Ident::new( &child_former_name, field_ident.span() ); + let element_subformer_name = format!( "_{}_element_subformer", field_ident ); + let element_subformer = syn::Ident::new( &element_subformer_name, field_ident.span() ); let r = qt! { + // zzz : improve documentation + /// Custom setter which produce container element subformer. #[ inline( always ) ] - pub fn #child_former< Former2, Definition2 >( self ) -> Former2 + pub fn #element_subformer< Former2, Definition2 >( self ) -> Former2 where Definition2 : former::FormerDefinition < @@ -737,7 +737,7 @@ fn field_setter /// zzz : update example #[ inline ] -fn subformer_field_setter +fn container_setter ( field : &FormerField< '_ >, stru : &syn::Ident, @@ -845,31 +845,8 @@ fn subformer_field_setter #setter2 } - // qt! - // { - // #[ doc = #doc ] - // #[ inline ] - // pub fn #setter_name( mut self ) -> #subformer_type - // < - // #( #params, )* - // #non_optional_type, - // Self, - // impl Fn( #non_optional_type, core::option::Option< Self > ) -> Self, - // > - // { - // let formed = self.storage.#setter_name.take(); - // let on_end = | formed : #non_optional_type, former : core::option::Option< Self > | -> Self - // { - // let mut former = former.unwrap(); - // former.storage.#setter_name = Some( formed ); - // former - // }; - // #subformer_type::begin_coercing( formed, Some( self ), on_end ) - // } - // } - // #[ inline( always ) ] -// pub fn vec_1_set< Former2 >( self ) -> Former2 +// pub fn vec_1_assign< Former2 >( self ) -> Former2 // where // Former2 : former::FormerBegin // < @@ -891,7 +868,7 @@ fn subformer_field_setter // String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > // > // { -// self.vec_1_set::< former::ContainerSubformer:: +// self.vec_1_assign::< former::ContainerSubformer:: // < // String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > // >>() @@ -1031,7 +1008,7 @@ Result< TokenStream > Ok( r ) } -/// xxx : write documentation +/// zzz : write documentation #[ inline ] fn field_former_add_map @@ -1068,8 +1045,6 @@ Result< TokenStream > let r = qt! { -// xxx : uncomment - // zzz : improve description /// Handles the completion of an element of subformer's container. pub struct #parent_add_element_end< Definition > From 19f741a22a1cddd91452fc0d0c356d5ba01e775c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 23:11:03 +0300 Subject: [PATCH 294/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 87e3cec152..6d018df0fb 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -741,29 +741,20 @@ fn container_setter ( field : &FormerField< '_ >, stru : &syn::Ident, - // field_ident : &syn::Ident, - // setter_name : &syn::Ident, - // non_optional_type : &syn::Type, - // subformer_type : &syn::Type, ) -> TokenStream { let field_ident = &field.ident; let non_optional_ty = &field.non_optional_ty; - - // tree_print!( non_optional_type ); - // code_print!( non_optional_type ); let params = typ::type_parameters( &non_optional_ty, .. ); - // params.iter().for_each( | e | println!( "{}", qt!( #e ) ) ); + // example : `former::VectorDefinition` let subformer_definition = &field.attrs.container.as_ref().unwrap().expr; - // for example : former::VectorDefinition use convert_case::{ Case, Casing }; - // let ident = field_ident; let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); - let field_assign_name = format!( "{}_assign", field_ident ); + let field_assign_name = format!( "_{}_assign", field_ident ); let field_assign = syn::Ident::new( &field_assign_name, field_ident.span() ); let doc = format! From c482d19cdbc0dff77e231f2aef5a6008ccbf425b Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 23:40:17 +0300 Subject: [PATCH 295/533] former : experimenting --- module/core/former/src/container.rs | 48 ------------------- module/core/former/src/hash_map.rs | 16 +++++++ module/core/former/src/hash_set.rs | 16 +++++++ module/core/former/src/vector.rs | 16 +++++++ .../a_containers_with_subformer_manual.rs | 12 ++--- 5 files changed, 54 insertions(+), 54 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index b4418ba154..682e326137 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -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. diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 330544c9ad..e484b43490 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -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 diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 876883a850..383cad33be 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -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`, diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index b5a23195f2..237147041c 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -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, diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 01125ccf65..96b2d0197d 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -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 > >, } @@ -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 > >>() } @@ -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 From ec769135f1f8e141eed02f97db482b22b11f3896 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 27 Apr 2024 23:48:23 +0300 Subject: [PATCH 296/533] former : experimenting --- module/core/former/src/definition.rs | 20 -------------------- module/core/former/src/vector.rs | 8 ++++++++ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs index ab0246fe85..67961c64f4 100644 --- a/module/core/former/src/definition.rs +++ b/module/core/former/src/definition.rs @@ -1,18 +1,4 @@ -// // zzz : improve documentation -// /// Map type of entity to storage and former. -// pub trait EntityToFormer_ -// { -// /// Storage to store fields of entity during formign process. -// type Storage; -// /// Former with default definition -// type Former; -// // type Formed; -// // type Context; -// // type Types; -// // type Definition; -// } - // zzz : improve documentation /// Map type of entity to former. pub trait EntityToFormer< Definition > @@ -31,12 +17,6 @@ pub trait EntityToStorage type Storage; } -// impl< T > EntityToStorage -// for T -// { -// type Storage = T; -// } - /// zzz : write description pub trait FormerDefinitionTypes : Sized { diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 237147041c..ddc683ebdf 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -102,6 +102,14 @@ where type End = End; } +impl< E, Definition > EntityToFormer< Definition > for Vec< E > +where + Definition : FormerDefinition< Storage = Vec< E >, Formed = () >, + < Definition as definition::FormerDefinition>::End : Fn( Vec< E >, Option< Definition::Context > ), +{ + type Former = VectorSubformer< E, Definition::Context, Definition::Formed, Definition::End >; +} + // = subformer /// A builder for constructing `VectorLike` containers, facilitating a fluent and flexible interface. From d3cb287bfa3fefc56880b137999d82130c571e28 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 28 Apr 2024 00:22:54 +0300 Subject: [PATCH 297/533] former : experimenting --- module/core/former/src/definition.rs | 7 ++++++ module/core/former/src/vector.rs | 11 ++++++++++ .../a_containers_with_subformer_implicit.rs | 22 +++++++++++++++++++ module/core/former/tests/inc/mod.rs | 5 ++++- module/core/former_meta/src/derive/former.rs | 10 ++++++--- 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs index 67961c64f4..97926ec02e 100644 --- a/module/core/former/src/definition.rs +++ b/module/core/former/src/definition.rs @@ -1,4 +1,11 @@ +// zzz : improve documentation +/// Map type of entity to former. +pub trait EntityToDefinition< Context, Formed, End > +{ + type Definition : FormerDefinition; +} + // zzz : improve documentation /// Map type of entity to former. pub trait EntityToFormer< Definition > diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index ddc683ebdf..2989033fc7 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -102,6 +102,8 @@ where type End = End; } +// xxx : implement for hashset / hashmap +// xxx : cover by tests impl< E, Definition > EntityToFormer< Definition > for Vec< E > where Definition : FormerDefinition< Storage = Vec< E >, Formed = () >, @@ -110,6 +112,15 @@ where type Former = VectorSubformer< E, Definition::Context, Definition::Formed, Definition::End >; } +impl< E, Context, Formed, End > EntityToDefinition< Context, Formed, End > +for Vec< E > +where + // End : std::ops::Fn< ( collection_tools::Vec< E >, std::option::Option< Context > ), Output = Formed >, + End : Fn(collection_tools::Vec< E >, std::option::Option< Context >) -> Formed, +{ + type Definition = VectorDefinition< E, Context, Formed, End >; +} + // = subformer /// A builder for constructing `VectorLike` containers, facilitating a fluent and flexible interface. diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs new file mode 100644 index 0000000000..82d7635aa3 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs @@ -0,0 +1,22 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ derive( Default, Debug, PartialEq, former::Former ) ] +// #[ derive( Default, Debug, PartialEq, former::Former ) ] #[ debug ] +// #[ derive( Default, Debug, PartialEq ) ] +pub struct Struct1 +{ + #[ container( former::VectorDefinition ) ] + // #[ container ] + vec_1 : Vec< String >, + #[ container( former::HashMapDefinition ) ] + hashmap_1 : std::collections::HashMap< String, String >, + #[ container( former::HashSetDefinition ) ] + hashset_1 : std::collections::HashSet< String >, +} + +// == generated begin + +// == generated end + +include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index c0a6d9bba1..12bdc75f01 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -20,11 +20,14 @@ mod former_tests mod a_basic; mod a_primitives_manual; mod a_primitives; + mod a_containers_without_subformer; #[ cfg( not( feature = "no_std" ) ) ] mod a_containers_with_subformer_manual; #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer ; + mod a_containers_with_subformer; + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer_implicit; mod attribute_default_container; mod attribute_default_primitive; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 6d018df0fb..3697f37542 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -82,7 +82,11 @@ impl Attributes { container.replace( syn::parse2::< AttributeContainer >( meta_list.tokens.clone() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ container( val ) ], but got:\n {}", qt!{ #attr } ), + syn::Meta::Path( ref _path ) => + { + container.replace( syn::parse2::< AttributeContainer >( Default::default() )? ); + }, + _ => return_syn_err!( attr, "Expects an attribute of format #[ container( former::VectorDefinition ) ] or #[ container ] if you want to use default container defition, but got:\n {}", qt!{ #attr } ), } } "subform" => @@ -219,7 +223,7 @@ impl syn::parse::Parse for AttributeSetter #[ allow( dead_code ) ] struct AttributeContainer { - expr : syn::Type, + expr : Option< syn::Type >, } impl syn::parse::Parse for AttributeContainer @@ -228,7 +232,7 @@ impl syn::parse::Parse for AttributeContainer { Ok( Self { - expr : input.parse()?, + expr : Some( input.parse()? ), }) } } From 490960e0e201f66f7a48c105ebddd527f8b942ee Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 28 Apr 2024 00:24:47 +0300 Subject: [PATCH 298/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 3697f37542..0bea9285e0 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -230,9 +230,10 @@ impl syn::parse::Parse for AttributeContainer { fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > { + let expr : Option< syn::Type > = input.parse().ok(); Ok( Self { - expr : Some( input.parse()? ), + expr, }) } } From affb65eb98a6833cf792d6ad8b61da00c98ce811 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 28 Apr 2024 00:31:17 +0300 Subject: [PATCH 299/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 0bea9285e0..c8dabb5680 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -754,7 +754,18 @@ fn container_setter let params = typ::type_parameters( &non_optional_ty, .. ); // example : `former::VectorDefinition` - let subformer_definition = &field.attrs.container.as_ref().unwrap().expr; + let mut subformer_definition = &field.attrs.container.as_ref().unwrap().expr; + + // xxx + // if subformer_definition.is_none() + // { + // let extra : syn::Type = parse_quote! + // // let code = qt! + // { + // + // } + // subformer_definition = Some( code ); + // } use convert_case::{ Case, Casing }; let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); From d4d4b64c440853671cae0b430259eae90bf2c2cd Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 28 Apr 2024 00:38:54 +0300 Subject: [PATCH 300/533] former : experimenting --- module/core/former/src/vector.rs | 5 +++-- .../inc/former_tests/a_containers_with_subformer_manual.rs | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 2989033fc7..908811646b 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -115,8 +115,9 @@ where impl< E, Context, Formed, End > EntityToDefinition< Context, Formed, End > for Vec< E > where - // End : std::ops::Fn< ( collection_tools::Vec< E >, std::option::Option< Context > ), Output = Formed >, - End : Fn(collection_tools::Vec< E >, std::option::Option< Context >) -> Formed, + // End : std::ops::Fn< ( Vec< E >, std::option::Option< Context > ), Output = Formed >, + // End : Fn( Vec< E >, std::option::Option< Context > ) -> Formed, + End : crate::FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, { type Definition = VectorDefinition< E, Context, Formed, End >; } diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 96b2d0197d..323af95ab0 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -322,6 +322,7 @@ where pub fn vec_1_set< Former2 >( self ) -> Former2 where Former2 : former::FormerBegin< former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End, > >, + // Former2 : former::FormerBegin< < Vec< String > as former::EntityToDefinition< Self, Self, Struct1FormerAssignVec1End > >::Definition >, { Former2::former_begin( None, Some( self ), Struct1FormerAssignVec1End ) } From ec837ae592b1dc38b7240d27dd2760b26accd107 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 28 Apr 2024 00:46:41 +0300 Subject: [PATCH 301/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 4 +- module/core/former_meta/src/derive/former.rs | 55 +++++++++++-------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 323af95ab0..6966aa8d71 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -321,8 +321,8 @@ where #[ inline( always ) ] pub fn vec_1_set< Former2 >( self ) -> Former2 where - Former2 : former::FormerBegin< former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End, > >, - // Former2 : former::FormerBegin< < Vec< String > as former::EntityToDefinition< Self, Self, Struct1FormerAssignVec1End > >::Definition >, + // Former2 : former::FormerBegin< former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End, > >, + Former2 : former::FormerBegin< < Vec< String > as former::EntityToDefinition< Self, Self, Struct1FormerAssignVec1End > >::Definition >, { Former2::former_begin( None, Some( self ), Struct1FormerAssignVec1End ) } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index c8dabb5680..001a3d13c9 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -753,26 +753,39 @@ fn container_setter let non_optional_ty = &field.non_optional_ty; let params = typ::type_parameters( &non_optional_ty, .. ); - // example : `former::VectorDefinition` - let mut subformer_definition = &field.attrs.container.as_ref().unwrap().expr; - - // xxx - // if subformer_definition.is_none() - // { - // let extra : syn::Type = parse_quote! - // // let code = qt! - // { - // - // } - // subformer_definition = Some( code ); - // } - use convert_case::{ Case, Casing }; let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); let field_assign_name = format!( "_{}_assign", field_ident ); let field_assign = syn::Ident::new( &field_assign_name, field_ident.span() ); + // example : `former::VectorDefinition` + let subformer_definition = &field.attrs.container.as_ref().unwrap().expr; + + // xxx + let subformer_definition = if subformer_definition.is_some() + { + qt! + { + #subformer_definition + < + #( #params, )* + Self, + Self, + #former_assign_end, + > + } + // former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End, > + } + else + { + qt! + { + < #non_optional_ty as former::EntityToDefinition< Self, Self, #former_assign_end > >::Definition + } + // < Vec< String > as former::EntityToDefinition< Self, Self, Struct1FormerAssignVec1End > >::Definition + }; + let doc = format! ( "Subformer setter for the '{}' field. Method {} unlike method {} accept custom container subformer.", @@ -791,12 +804,6 @@ fn container_setter Former2 : former::FormerBegin < #subformer_definition - < - #( #params, )* - Self, - Self, - #former_assign_end, - > >, { Former2::former_begin( None, Some( self ), #former_assign_end ) @@ -813,12 +820,12 @@ fn container_setter pub fn #field_ident( self ) -> former::ContainerSubformer:: < - ( #( #params, )* ), #subformer_definition< #( #params, )* Self, Self, #former_assign_end > + ( #( #params, )* ), #subformer_definition > { self.#field_assign::< former::ContainerSubformer:: < - ( #( #params, )* ), #subformer_definition< #( #params, )* Self, Self, #former_assign_end > + ( #( #params, )* ), #subformer_definition >>() } @@ -834,12 +841,12 @@ fn container_setter pub fn #field_ident( self ) -> former::ContainerSubformer:: < - #( #params, )* #subformer_definition< #( #params, )* Self, Self, #former_assign_end > + #( #params, )* #subformer_definition > { self.#field_assign::< former::ContainerSubformer:: < - #( #params, )* #subformer_definition< #( #params, )* Self, Self, #former_assign_end > + #( #params, )* #subformer_definition >>() } From 663fe7468eb25e7bb4be0815254390c99dfe36e6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 28 Apr 2024 00:51:49 +0300 Subject: [PATCH 302/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 30 ++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 001a3d13c9..e481029cc6 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -956,21 +956,34 @@ Result< TokenStream > return Ok( qt!{ } ); } - // example : `former::VectorDefinition`` - let subformer_definition = &field.attrs.container.as_ref().unwrap().expr; - use convert_case::{ Case, Casing }; let field_ident = field.ident; let field_ty = field.non_optional_ty; - let params = typ::type_parameters( &field.non_optional_ty, .. ); + let params = typ::type_parameters( field_ty, .. ); // example : `ParentFormerAssignChildsEnd`` let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); - // // example : `ParentFormerAddChildsEnd`` - // let parent_add_element_end_name = format!( "{}FormerAdd{}End2", stru, field_ident.to_string().to_case( Case::Pascal ) ); - // let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); + // example : `former::VectorDefinition`` + let subformer_definition = &field.attrs.container.as_ref().unwrap().expr; + + let subformer_definition = if subformer_definition.is_some() + { + qt! + { + #subformer_definition < #( #params, )* #former< #former_generics_ty >, #former< #former_generics_ty >, former::NoEnd > + } + // former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd > + } + else + { + qt! + { + < #field_ty as former::EntityToDefinition< #former< #former_generics_ty >, #former< #former_generics_ty >, former::NoEnd > >::Definition + } + // < Vec< String > as former::EntityToDefinition< Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd > >::Definition + }; let r = qt! { @@ -983,7 +996,8 @@ Result< TokenStream > #[ automatically_derived ] impl< #former_generics_impl > former::FormingEnd < - #subformer_definition < #( #params, )* #former< #former_generics_ty >, #former< #former_generics_ty >, former::NoEnd >, + // #subformer_definition < #( #params, )* #former< #former_generics_ty >, #former< #former_generics_ty >, former::NoEnd >, + #subformer_definition, > for #former_assign_end where From 4ae9a15341fa13e965eb1671b9822e82bd269ec0 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 28 Apr 2024 01:08:59 +0300 Subject: [PATCH 303/533] former : experimenting --- .../a_containers_with_subformer_implicit.rs | 368 ++++++++++++++++++ 1 file changed, 368 insertions(+) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs index 82d7635aa3..3078918980 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs @@ -17,6 +17,374 @@ pub struct Struct1 // == generated begin +// #[automatically_derived] impl < > Struct1 < > where +// { +// #[doc = r""] +// #[doc = +// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] +// #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < +// Struct1FormerDefinition < (), Struct1 < > , former :: ReturnPreformed > > +// { +// Struct1Former :: < Struct1FormerDefinition < (), Struct1 < > , former +// :: ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) +// } +// } impl < Definition > former :: EntityToFormer < Definition > for Struct1 < > +// where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage +// < > > , { type Former = Struct1Former < Definition > ; } impl < > former :: +// EntityToStorage for Struct1 < > where +// { type Storage = Struct1FormerStorage < > ; } #[derive(Debug)] pub struct +// Struct1FormerDefinitionTypes < __Context = (), __Formed = Struct1 < > , > +// where { _phantom : core :: marker :: PhantomData < (__Context, __Formed) > , } +// impl < __Context, __Formed, > :: core :: default :: Default for +// Struct1FormerDefinitionTypes < __Context, __Formed, > where +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < __Context, __Formed, > former :: FormerDefinitionTypes for +// Struct1FormerDefinitionTypes < __Context, __Formed, > where +// { +// type Storage = Struct1FormerStorage < > ; type Formed = __Formed; type +// Context = __Context; +// } #[derive(Debug)] pub struct Struct1FormerDefinition < __Context = (), +// __Formed = Struct1 < > , __End = former :: ReturnPreformed, > where +// { +// _phantom : core :: marker :: PhantomData < (__Context, __Formed, __End) > +// , +// } impl < __Context, __Formed, __End, > :: core :: default :: Default for +// Struct1FormerDefinition < __Context, __Formed, __End, > where +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < __Context, __Formed, __End, > former :: FormerDefinition for +// Struct1FormerDefinition < __Context, __Formed, __End, > where __End : former +// :: FormingEnd < Struct1FormerDefinitionTypes < __Context, __Formed, > > , +// { +// type Types = Struct1FormerDefinitionTypes < __Context, __Formed, > ; type +// End = __End; type Storage = Struct1FormerStorage < > ; type Formed = +// __Formed; type Context = __Context; +// } #[doc = "Container of a corresponding former."] pub struct +// Struct1FormerStorage < > where +// { +// #[doc = r" A field"] pub vec_1 : :: core :: option :: Option < Vec < +// String > > , #[doc = r" A field"] pub hashmap_1 : :: core :: option :: +// Option < std :: collections :: HashMap < String, String > > , +// #[doc = r" A field"] pub hashset_1 : :: core :: option :: Option < std :: +// collections :: HashSet < String > > , +// } impl < > :: core :: default :: Default for Struct1FormerStorage < > where +// { +// #[inline(always)] fn default() -> Self +// { +// Self +// { +// vec_1 : :: core :: option :: Option :: None, hashmap_1 : :: core +// :: option :: Option :: None, hashset_1 : :: core :: option :: +// Option :: None, +// } +// } +// } impl < > former :: Storage for Struct1FormerStorage < > where +// { type Formed = Struct1 < > ; } impl < > former :: StoragePreform for +// Struct1FormerStorage < > where +// { +// type Preformed = Struct1 < > ; fn preform(mut self) -> Self :: Preformed +// { +// let vec_1 = if self.vec_1.is_some() { self.vec_1.take().unwrap() } +// else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'vec_1' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < Vec < String > +// >).maybe_default() +// } +// }; let hashmap_1 = if self.hashmap_1.is_some() +// { self.hashmap_1.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'hashmap_1' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < std :: collections :: +// HashMap < String, String > >).maybe_default() +// } +// }; let hashset_1 = if self.hashset_1.is_some() +// { self.hashset_1.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'hashset_1' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < std :: collections :: +// HashSet < String > >).maybe_default() +// } +// }; let result = Struct1 :: < > { vec_1, hashmap_1, hashset_1, }; +// return result; +// } +// } +// #[doc = +// " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +// pub struct Struct1Former < Definition = Struct1FormerDefinition < (), Struct1 +// < > , former :: ReturnPreformed > , > where Definition : former :: +// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = Struct1FormerStorage < > > , +// { +// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: +// Storage, context : core :: option :: Option < < Definition :: Types as +// former :: FormerDefinitionTypes > :: Context > , on_end : core :: option +// :: Option < Definition :: End > , +// } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > +// where Definition : former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , +// { +// #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn +// new_precise(on_end : Definition :: End) -> Self +// { Self :: begin_coercing(None, None, on_end) } #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > +// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , +// { Self :: begin_coercing(None, None, end,) } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn +// begin_precise(mut storage : core :: option :: Option < < Definition :: +// Types as former :: FormerDefinitionTypes > :: Storage > , context : core +// :: option :: Option < < Definition :: Types as former :: +// FormerDefinitionTypes > :: Context > , on_end : < Definition as former :: +// FormerDefinition > :: End,) -> Self +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: Some(on_end), +// } +// } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > +// (mut storage : core :: option :: Option < < Definition :: Types as former +// :: FormerDefinitionTypes > :: Storage > , context : core :: option :: +// Option < < Definition :: Types as former :: FormerDefinitionTypes > :: +// Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert +// :: Into < < Definition as former :: FormerDefinition > :: End > , +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: +// Some(:: core :: convert :: Into :: into(on_end)), +// } +// } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types +// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { +// let on_end = self.on_end.take().unwrap(); let context = +// self.context.take(); former :: FormingEnd :: < Definition :: Types > +// :: call(& on_end, self.storage, context) +// } +// #[doc = +// "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] +// #[inline(always)] pub fn _vec_1_assign < Former2 > (self) -> Former2 where +// Former2 : former :: FormerBegin < < Vec < String > as former :: +// EntityToDefinition < Self, Self, Struct1FormerAssignVec1End > > :: +// Definition > , +// { Former2 :: former_begin(None, Some(self), Struct1FormerAssignVec1End) } +// #[doc = +// "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] +// #[inline(always)] pub fn vec_1(self) -> former :: ContainerSubformer :: < +// String, < Vec < String > as former :: EntityToDefinition < Self, Self, +// Struct1FormerAssignVec1End > > :: Definition > +// { +// self._vec_1_assign :: < former :: ContainerSubformer :: < String, < +// Vec < String > as former :: EntityToDefinition < Self, Self, +// Struct1FormerAssignVec1End > > :: Definition >> () +// } +// #[doc = +// "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] +// #[inline(always)] pub fn _hashmap_1_assign < Former2 > (self) -> Former2 +// where Former2 : former :: FormerBegin < former :: HashMapDefinition < +// String, String, Self, Self, Struct1FormerAssignHashmap1End, > > , +// { +// Former2 :: +// former_begin(None, Some(self), Struct1FormerAssignHashmap1End) +// } +// #[doc = +// "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] +// #[inline(always)] pub fn hashmap_1(self) -> former :: ContainerSubformer +// :: < (String, String,), former :: HashMapDefinition < String, String, +// Self, Self, Struct1FormerAssignHashmap1End, > > +// { +// self._hashmap_1_assign :: < former :: ContainerSubformer :: < +// (String, String,), former :: HashMapDefinition < String, String, Self, +// Self, Struct1FormerAssignHashmap1End, > >> () +// } +// #[doc = +// "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] +// #[inline(always)] pub fn _hashset_1_assign < Former2 > (self) -> Former2 +// where Former2 : former :: FormerBegin < former :: HashSetDefinition < +// String, Self, Self, Struct1FormerAssignHashset1End, > > , +// { +// Former2 :: +// former_begin(None, Some(self), Struct1FormerAssignHashset1End) +// } +// #[doc = +// "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] +// #[inline(always)] pub fn hashset_1(self) -> former :: ContainerSubformer +// :: < String, former :: HashSetDefinition < String, Self, Self, +// Struct1FormerAssignHashset1End, > > +// { +// self._hashset_1_assign :: < former :: ContainerSubformer :: < String, +// former :: HashSetDefinition < String, Self, Self, +// Struct1FormerAssignHashset1End, > >> () +// } +// } impl < Definition, > Struct1Former < Definition, > where Definition : former +// :: FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = Struct1FormerStorage < > , Formed = Struct1 < > > , < Definition :: +// Types as former :: FormerDefinitionTypes > :: Storage : former :: +// StoragePreform, < Definition :: Types as former :: FormerDefinitionTypes > :: +// Storage : former :: StoragePreform < Preformed = Struct1 < > > , Definition : +// former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , +// { +// pub fn preform(self) -> < Definition :: Types as former :: +// FormerDefinitionTypes > :: Formed +// { former :: StoragePreform :: preform(self.storage) } +// } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > +// where Definition : former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > , Formed = Struct1 +// < > > , +// { +// #[doc = r""] +// #[doc = r" Finish setting options and call perform on formed entity."] +// #[doc = r""] +// #[doc = +// r" If `perform` defined then associated method is called and its result returned instead of entity."] +// #[doc = +// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] +// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { let result = self.form(); return result; } +// } impl < Definition > former :: FormerBegin < Definition > for Struct1Former < +// Definition, > where Definition : former :: FormerDefinition < Storage = +// Struct1FormerStorage < > > , +// { +// #[inline(always)] fn +// former_begin(storage : core :: option :: Option < Definition :: Storage > +// , context : core :: option :: Option < Definition :: Context > , on_end : +// Definition :: End,) -> Self +// { +// debug_assert! (storage.is_none()); Self :: +// begin_precise(None, context, on_end) +// } +// } +// #[doc = +// r" Use as subformer of a field during process of forming of super structure."] +// pub type Struct1Subformer < __Superformer, __End > = Struct1Former < +// Struct1FormerDefinition < __Superformer, __Superformer, __End, > , > ; +// #[doc = +// r" Use as subformer end of a field during process of forming of super structure."] +// pub trait Struct1SubformerEnd < SuperFormer > where Self : former :: +// FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, SuperFormer > , > , +// {} impl < SuperFormer, T > Struct1SubformerEnd < SuperFormer > for T where +// Self : former :: FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, +// SuperFormer > , > , {} +// #[doc = r" Return original former after container for `vec_1` is done."] +// +// #[allow(non_camel_case_types)] +// pub struct Struct1FormerAssignVec1End; +// +// #[automatically_derived] +// impl < Definition, > former :: FormingEnd +// < +// < Vec < String > as former :: EntityToDefinition < Struct1Former < Definition, > , Struct1Former < Definition, > , former :: NoEnd > > :: Definition, +// > +// for Struct1FormerAssignVec1End +// where +// Definition : former :: FormerDefinition, +// Definition :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , Definition : former :: FormerDefinition, +// Definition :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , +// { +// #[inline(always)] 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 +// { former :: ContainerAssign :: assign(field, storage); } else +// { super_former.storage.vec_1 = Some(storage); } super_former +// } +// } +// +// #[doc = r" Return original former after container for `vec_1` is done."] +// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashmap1End; +// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: +// HashMapDefinition < String, String, Struct1Former < Definition, > , +// Struct1Former < Definition, > , former :: NoEnd > , > for +// Struct1FormerAssignHashmap1End where Definition : former :: FormerDefinition, +// Definition :: Types : former :: FormerDefinitionTypes < Storage = +// Struct1FormerStorage < > > , Definition : former :: FormerDefinition, +// Definition :: Types : former :: FormerDefinitionTypes < Storage = +// Struct1FormerStorage < > > , +// { +// #[inline(always)] fn +// call(& self, storage : std :: collections :: HashMap < String, String > , +// super_former : Option < Struct1Former < Definition, > > ,) -> +// Struct1Former < Definition, > +// { +// let mut super_former = super_former.unwrap(); if let +// Some(ref mut field) = super_former.storage.hashmap_1 +// { former :: ContainerAssign :: assign(field, storage); } else +// { super_former.storage.hashmap_1 = Some(storage); } super_former +// } +// } #[doc = r" Return original former after container for `vec_1` is done."] +// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashset1End; +// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: +// HashSetDefinition < String, Struct1Former < Definition, > , Struct1Former < +// Definition, > , former :: NoEnd > , > for Struct1FormerAssignHashset1End where +// Definition : former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , Definition : +// former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , +// { +// #[inline(always)] fn +// call(& self, storage : std :: collections :: HashSet < String > , +// super_former : Option < Struct1Former < Definition, > > ,) -> +// Struct1Former < Definition, > +// { +// let mut super_former = super_former.unwrap(); if let +// Some(ref mut field) = super_former.storage.hashset_1 +// { former :: ContainerAssign :: assign(field, storage); } else +// { super_former.storage.hashset_1 = Some(storage); } super_former +// } +// } + // == generated end include!( "./only_test/containers_with_subformer.rs" ); From dea173a8146ca8a7ab79141ac2e57fd3cfcbaa2c Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 29 Apr 2024 17:31:22 +0300 Subject: [PATCH 304/533] former : experimenting --- .../a_containers_with_subformer_implicit.rs | 732 +++++++++--------- .../only_test/subformer_container.rs | 21 + .../only_test/subformer_shortcut.rs | 43 - .../only_test/subformer_subform.rs | 22 + ...ormer_shortcut.rs => subformer_subform.rs} | 2 +- .../subformer_subform_implicit_container.rs | 571 ++++++++++++++ ..._manual.rs => subformer_subform_manual.rs} | 5 +- module/core/former/tests/inc/mod.rs | 9 +- 8 files changed, 992 insertions(+), 413 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/only_test/subformer_container.rs delete mode 100644 module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs create mode 100644 module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs rename module/core/former/tests/inc/former_tests/{subformer_shortcut.rs => subformer_subform.rs} (94%) create mode 100644 module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs rename module/core/former/tests/inc/former_tests/{subformer_shortcut_manual.rs => subformer_subform_manual.rs} (98%) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs index 3078918980..71e71d6bc6 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs @@ -17,373 +17,377 @@ pub struct Struct1 // == generated begin -// #[automatically_derived] impl < > Struct1 < > where -// { -// #[doc = r""] -// #[doc = -// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] -// #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < -// Struct1FormerDefinition < (), Struct1 < > , former :: ReturnPreformed > > -// { -// Struct1Former :: < Struct1FormerDefinition < (), Struct1 < > , former -// :: ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) -// } -// } impl < Definition > former :: EntityToFormer < Definition > for Struct1 < > -// where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage -// < > > , { type Former = Struct1Former < Definition > ; } impl < > former :: -// EntityToStorage for Struct1 < > where -// { type Storage = Struct1FormerStorage < > ; } #[derive(Debug)] pub struct -// Struct1FormerDefinitionTypes < __Context = (), __Formed = Struct1 < > , > -// where { _phantom : core :: marker :: PhantomData < (__Context, __Formed) > , } -// impl < __Context, __Formed, > :: core :: default :: Default for -// Struct1FormerDefinitionTypes < __Context, __Formed, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, > former :: FormerDefinitionTypes for -// Struct1FormerDefinitionTypes < __Context, __Formed, > where -// { -// type Storage = Struct1FormerStorage < > ; type Formed = __Formed; type -// Context = __Context; -// } #[derive(Debug)] pub struct Struct1FormerDefinition < __Context = (), -// __Formed = Struct1 < > , __End = former :: ReturnPreformed, > where -// { -// _phantom : core :: marker :: PhantomData < (__Context, __Formed, __End) > -// , -// } impl < __Context, __Formed, __End, > :: core :: default :: Default for -// Struct1FormerDefinition < __Context, __Formed, __End, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, __End, > former :: FormerDefinition for -// Struct1FormerDefinition < __Context, __Formed, __End, > where __End : former -// :: FormingEnd < Struct1FormerDefinitionTypes < __Context, __Formed, > > , -// { -// type Types = Struct1FormerDefinitionTypes < __Context, __Formed, > ; type -// End = __End; type Storage = Struct1FormerStorage < > ; type Formed = -// __Formed; type Context = __Context; -// } #[doc = "Container of a corresponding former."] pub struct -// Struct1FormerStorage < > where -// { -// #[doc = r" A field"] pub vec_1 : :: core :: option :: Option < Vec < -// String > > , #[doc = r" A field"] pub hashmap_1 : :: core :: option :: -// Option < std :: collections :: HashMap < String, String > > , -// #[doc = r" A field"] pub hashset_1 : :: core :: option :: Option < std :: -// collections :: HashSet < String > > , -// } impl < > :: core :: default :: Default for Struct1FormerStorage < > where -// { -// #[inline(always)] fn default() -> Self -// { -// Self -// { -// vec_1 : :: core :: option :: Option :: None, hashmap_1 : :: core -// :: option :: Option :: None, hashset_1 : :: core :: option :: -// Option :: None, -// } -// } -// } impl < > former :: Storage for Struct1FormerStorage < > where -// { type Formed = Struct1 < > ; } impl < > former :: StoragePreform for -// Struct1FormerStorage < > where -// { -// type Preformed = Struct1 < > ; fn preform(mut self) -> Self :: Preformed -// { -// let vec_1 = if self.vec_1.is_some() { self.vec_1.take().unwrap() } -// else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'vec_1' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < Vec < String > -// >).maybe_default() -// } -// }; let hashmap_1 = if self.hashmap_1.is_some() -// { self.hashmap_1.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'hashmap_1' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < std :: collections :: -// HashMap < String, String > >).maybe_default() -// } -// }; let hashset_1 = if self.hashset_1.is_some() -// { self.hashset_1.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'hashset_1' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < std :: collections :: -// HashSet < String > >).maybe_default() -// } -// }; let result = Struct1 :: < > { vec_1, hashmap_1, hashset_1, }; -// return result; -// } -// } -// #[doc = -// " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -// pub struct Struct1Former < Definition = Struct1FormerDefinition < (), Struct1 -// < > , former :: ReturnPreformed > , > where Definition : former :: -// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = Struct1FormerStorage < > > , -// { -// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: -// Storage, context : core :: option :: Option < < Definition :: Types as -// former :: FormerDefinitionTypes > :: Context > , on_end : core :: option -// :: Option < Definition :: End > , -// } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > -// where Definition : former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn -// new_precise(on_end : Definition :: End) -> Self -// { Self :: begin_coercing(None, None, on_end) } #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > -// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , -// { Self :: begin_coercing(None, None, end,) } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn -// begin_precise(mut storage : core :: option :: Option < < Definition :: -// Types as former :: FormerDefinitionTypes > :: Storage > , context : core -// :: option :: Option < < Definition :: Types as former :: -// FormerDefinitionTypes > :: Context > , on_end : < Definition as former :: -// FormerDefinition > :: End,) -> Self -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: Some(on_end), -// } -// } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > -// (mut storage : core :: option :: Option < < Definition :: Types as former -// :: FormerDefinitionTypes > :: Storage > , context : core :: option :: -// Option < < Definition :: Types as former :: FormerDefinitionTypes > :: -// Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert -// :: Into < < Definition as former :: FormerDefinition > :: End > , -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: -// Some(:: core :: convert :: Into :: into(on_end)), -// } -// } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types -// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { -// let on_end = self.on_end.take().unwrap(); let context = -// self.context.take(); former :: FormingEnd :: < Definition :: Types > -// :: call(& on_end, self.storage, context) -// } -// #[doc = -// "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] -// #[inline(always)] pub fn _vec_1_assign < Former2 > (self) -> Former2 where -// Former2 : former :: FormerBegin < < Vec < String > as former :: -// EntityToDefinition < Self, Self, Struct1FormerAssignVec1End > > :: -// Definition > , -// { Former2 :: former_begin(None, Some(self), Struct1FormerAssignVec1End) } -// #[doc = -// "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] -// #[inline(always)] pub fn vec_1(self) -> former :: ContainerSubformer :: < -// String, < Vec < String > as former :: EntityToDefinition < Self, Self, -// Struct1FormerAssignVec1End > > :: Definition > -// { -// self._vec_1_assign :: < former :: ContainerSubformer :: < String, < -// Vec < String > as former :: EntityToDefinition < Self, Self, -// Struct1FormerAssignVec1End > > :: Definition >> () -// } -// #[doc = -// "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] -// #[inline(always)] pub fn _hashmap_1_assign < Former2 > (self) -> Former2 -// where Former2 : former :: FormerBegin < former :: HashMapDefinition < -// String, String, Self, Self, Struct1FormerAssignHashmap1End, > > , -// { -// Former2 :: -// former_begin(None, Some(self), Struct1FormerAssignHashmap1End) -// } -// #[doc = -// "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] -// #[inline(always)] pub fn hashmap_1(self) -> former :: ContainerSubformer -// :: < (String, String,), former :: HashMapDefinition < String, String, -// Self, Self, Struct1FormerAssignHashmap1End, > > -// { -// self._hashmap_1_assign :: < former :: ContainerSubformer :: < -// (String, String,), former :: HashMapDefinition < String, String, Self, -// Self, Struct1FormerAssignHashmap1End, > >> () -// } -// #[doc = -// "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] -// #[inline(always)] pub fn _hashset_1_assign < Former2 > (self) -> Former2 -// where Former2 : former :: FormerBegin < former :: HashSetDefinition < -// String, Self, Self, Struct1FormerAssignHashset1End, > > , -// { -// Former2 :: -// former_begin(None, Some(self), Struct1FormerAssignHashset1End) -// } -// #[doc = -// "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] -// #[inline(always)] pub fn hashset_1(self) -> former :: ContainerSubformer -// :: < String, former :: HashSetDefinition < String, Self, Self, -// Struct1FormerAssignHashset1End, > > -// { -// self._hashset_1_assign :: < former :: ContainerSubformer :: < String, -// former :: HashSetDefinition < String, Self, Self, -// Struct1FormerAssignHashset1End, > >> () -// } -// } impl < Definition, > Struct1Former < Definition, > where Definition : former -// :: FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = Struct1FormerStorage < > , Formed = Struct1 < > > , < Definition :: -// Types as former :: FormerDefinitionTypes > :: Storage : former :: -// StoragePreform, < Definition :: Types as former :: FormerDefinitionTypes > :: -// Storage : former :: StoragePreform < Preformed = Struct1 < > > , Definition : -// former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// pub fn preform(self) -> < Definition :: Types as former :: -// FormerDefinitionTypes > :: Formed -// { former :: StoragePreform :: preform(self.storage) } -// } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > -// where Definition : former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > , Formed = Struct1 -// < > > , -// { -// #[doc = r""] -// #[doc = r" Finish setting options and call perform on formed entity."] -// #[doc = r""] -// #[doc = -// r" If `perform` defined then associated method is called and its result returned instead of entity."] -// #[doc = -// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] -// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { let result = self.form(); return result; } -// } impl < Definition > former :: FormerBegin < Definition > for Struct1Former < -// Definition, > where Definition : former :: FormerDefinition < Storage = -// Struct1FormerStorage < > > , -// { -// #[inline(always)] fn -// former_begin(storage : core :: option :: Option < Definition :: Storage > -// , context : core :: option :: Option < Definition :: Context > , on_end : -// Definition :: End,) -> Self -// { -// debug_assert! (storage.is_none()); Self :: -// begin_precise(None, context, on_end) -// } -// } -// #[doc = -// r" Use as subformer of a field during process of forming of super structure."] -// pub type Struct1Subformer < __Superformer, __End > = Struct1Former < -// Struct1FormerDefinition < __Superformer, __Superformer, __End, > , > ; -// #[doc = -// r" Use as subformer end of a field during process of forming of super structure."] -// pub trait Struct1SubformerEnd < SuperFormer > where Self : former :: -// FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, SuperFormer > , > , -// {} impl < SuperFormer, T > Struct1SubformerEnd < SuperFormer > for T where -// Self : former :: FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, -// SuperFormer > , > , {} -// #[doc = r" Return original former after container for `vec_1` is done."] +// #[automatically_derived] +// impl < > Struct1 < > where +// { +// #[doc = r""] +// #[doc = +// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] +// #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < +// Struct1FormerDefinition < (), Struct1 < > , former :: ReturnPreformed > > +// { +// Struct1Former :: < Struct1FormerDefinition < (), Struct1 < > , former +// :: ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) +// } +// } impl < Definition > former :: EntityToFormer < Definition > for Struct1 < > +// where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage +// < > > , { type Former = Struct1Former < Definition > ; } impl < > former :: +// EntityToStorage for Struct1 < > where +// { type Storage = Struct1FormerStorage < > ; } #[derive(Debug)] pub struct +// Struct1FormerDefinitionTypes < __Context = (), __Formed = Struct1 < > , > +// where { _phantom : core :: marker :: PhantomData < (__Context, __Formed) > , } +// impl < __Context, __Formed, > :: core :: default :: Default for +// Struct1FormerDefinitionTypes < __Context, __Formed, > where +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < __Context, __Formed, > former :: FormerDefinitionTypes for +// Struct1FormerDefinitionTypes < __Context, __Formed, > where +// { +// type Storage = Struct1FormerStorage < > ; type Formed = __Formed; type +// Context = __Context; +// } #[derive(Debug)] pub struct Struct1FormerDefinition < __Context = (), +// __Formed = Struct1 < > , __End = former :: ReturnPreformed, > where +// { +// _phantom : core :: marker :: PhantomData < (__Context, __Formed, __End) > +// , +// } impl < __Context, __Formed, __End, > :: core :: default :: Default for +// Struct1FormerDefinition < __Context, __Formed, __End, > where +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < __Context, __Formed, __End, > former :: FormerDefinition for +// Struct1FormerDefinition < __Context, __Formed, __End, > where __End : former +// :: FormingEnd < Struct1FormerDefinitionTypes < __Context, __Formed, > > , +// { +// type Types = Struct1FormerDefinitionTypes < __Context, __Formed, > ; type +// End = __End; type Storage = Struct1FormerStorage < > ; type Formed = +// __Formed; type Context = __Context; +// } #[doc = "Container of a corresponding former."] pub struct +// Struct1FormerStorage < > where +// { +// #[doc = r" A field"] pub vec_1 : :: core :: option :: Option < Vec < +// String > > , #[doc = r" A field"] pub hashmap_1 : :: core :: option :: +// Option < std :: collections :: HashMap < String, String > > , +// #[doc = r" A field"] pub hashset_1 : :: core :: option :: Option < std :: +// collections :: HashSet < String > > , +// } impl < > :: core :: default :: Default for Struct1FormerStorage < > where +// { +// #[inline(always)] fn default() -> Self +// { +// Self +// { +// vec_1 : :: core :: option :: Option :: None, hashmap_1 : :: core +// :: option :: Option :: None, hashset_1 : :: core :: option :: +// Option :: None, +// } +// } +// } impl < > former :: Storage for Struct1FormerStorage < > where +// { type Formed = Struct1 < > ; } impl < > former :: StoragePreform for +// Struct1FormerStorage < > where +// { +// type Preformed = Struct1 < > ; fn preform(mut self) -> Self :: Preformed +// { +// let vec_1 = if self.vec_1.is_some() { self.vec_1.take().unwrap() } +// else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'vec_1' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < Vec < String > +// >).maybe_default() +// } +// }; let hashmap_1 = if self.hashmap_1.is_some() +// { self.hashmap_1.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'hashmap_1' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < std :: collections :: +// HashMap < String, String > >).maybe_default() +// } +// }; let hashset_1 = if self.hashset_1.is_some() +// { self.hashset_1.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'hashset_1' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < std :: collections :: +// HashSet < String > >).maybe_default() +// } +// }; let result = Struct1 :: < > { vec_1, hashmap_1, hashset_1, }; +// return result; +// } +// } +// #[doc = +// " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +// pub struct Struct1Former < Definition = Struct1FormerDefinition < (), Struct1 +// < > , former :: ReturnPreformed > , > where Definition : former :: +// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = Struct1FormerStorage < > > , +// { +// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: +// Storage, context : core :: option :: Option < < Definition :: Types as +// former :: FormerDefinitionTypes > :: Context > , on_end : core :: option +// :: Option < Definition :: End > , +// } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > +// where Definition : former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , +// { +// #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn +// new_precise(on_end : Definition :: End) -> Self +// { Self :: begin_coercing(None, None, on_end) } #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > +// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , +// { Self :: begin_coercing(None, None, end,) } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn +// begin_precise(mut storage : core :: option :: Option < < Definition :: +// Types as former :: FormerDefinitionTypes > :: Storage > , context : core +// :: option :: Option < < Definition :: Types as former :: +// FormerDefinitionTypes > :: Context > , on_end : < Definition as former :: +// FormerDefinition > :: End,) -> Self +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: Some(on_end), +// } +// } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > +// (mut storage : core :: option :: Option < < Definition :: Types as former +// :: FormerDefinitionTypes > :: Storage > , context : core :: option :: +// Option < < Definition :: Types as former :: FormerDefinitionTypes > :: +// Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert +// :: Into < < Definition as former :: FormerDefinition > :: End > , +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: +// Some(:: core :: convert :: Into :: into(on_end)), +// } +// } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types +// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { +// let on_end = self.on_end.take().unwrap(); let context = +// self.context.take(); former :: FormingEnd :: < Definition :: Types > +// :: call(& on_end, self.storage, context) +// } +// #[doc = +// "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] +// #[inline(always)] pub fn _vec_1_assign < Former2 > (self) -> Former2 where +// Former2 : former :: FormerBegin < < Vec < String > as former :: +// EntityToDefinition < Self, Self, Struct1FormerAssignVec1End > > :: +// Definition > , +// { Former2 :: former_begin(None, Some(self), Struct1FormerAssignVec1End) } +// #[doc = +// "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] +// #[inline(always)] pub fn vec_1(self) -> former :: ContainerSubformer :: < +// String, < Vec < String > as former :: EntityToDefinition < Self, Self, +// Struct1FormerAssignVec1End > > :: Definition > +// { +// self._vec_1_assign :: < former :: ContainerSubformer :: < String, < +// Vec < String > as former :: EntityToDefinition < Self, Self, +// Struct1FormerAssignVec1End > > :: Definition >> () +// } +// #[doc = +// "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] +// #[inline(always)] pub fn _hashmap_1_assign < Former2 > (self) -> Former2 +// where Former2 : former :: FormerBegin < former :: HashMapDefinition < +// String, String, Self, Self, Struct1FormerAssignHashmap1End, > > , +// { +// Former2 :: +// former_begin(None, Some(self), Struct1FormerAssignHashmap1End) +// } +// #[doc = +// "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] +// #[inline(always)] pub fn hashmap_1(self) -> former :: ContainerSubformer +// :: < (String, String,), former :: HashMapDefinition < String, String, +// Self, Self, Struct1FormerAssignHashmap1End, > > +// { +// self._hashmap_1_assign :: < former :: ContainerSubformer :: < +// (String, String,), former :: HashMapDefinition < String, String, Self, +// Self, Struct1FormerAssignHashmap1End, > >> () +// } +// #[doc = +// "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] +// #[inline(always)] pub fn _hashset_1_assign < Former2 > (self) -> Former2 +// where Former2 : former :: FormerBegin < former :: HashSetDefinition < +// String, Self, Self, Struct1FormerAssignHashset1End, > > , +// { +// Former2 :: +// former_begin(None, Some(self), Struct1FormerAssignHashset1End) +// } +// #[doc = +// "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] +// #[inline(always)] pub fn hashset_1(self) -> former :: ContainerSubformer +// :: < String, former :: HashSetDefinition < String, Self, Self, +// Struct1FormerAssignHashset1End, > > +// { +// self._hashset_1_assign :: < former :: ContainerSubformer :: < String, +// former :: HashSetDefinition < String, Self, Self, +// Struct1FormerAssignHashset1End, > >> () +// } +// } impl < Definition, > Struct1Former < Definition, > where Definition : former +// :: FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = Struct1FormerStorage < > , Formed = Struct1 < > > , < Definition :: +// Types as former :: FormerDefinitionTypes > :: Storage : former :: +// StoragePreform, < Definition :: Types as former :: FormerDefinitionTypes > :: +// Storage : former :: StoragePreform < Preformed = Struct1 < > > , Definition : +// former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , +// { +// pub fn preform(self) -> < Definition :: Types as former :: +// FormerDefinitionTypes > :: Formed +// { former :: StoragePreform :: preform(self.storage) } +// } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > +// where Definition : former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > , Formed = Struct1 +// < > > , +// { +// #[doc = r""] +// #[doc = r" Finish setting options and call perform on formed entity."] +// #[doc = r""] +// #[doc = +// r" If `perform` defined then associated method is called and its result returned instead of entity."] +// #[doc = +// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] +// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { let result = self.form(); return result; } +// } impl < Definition > former :: FormerBegin < Definition > for Struct1Former < +// Definition, > where Definition : former :: FormerDefinition < Storage = +// Struct1FormerStorage < > > , +// { +// #[inline(always)] fn +// former_begin(storage : core :: option :: Option < Definition :: Storage > +// , context : core :: option :: Option < Definition :: Context > , on_end : +// Definition :: End,) -> Self +// { +// debug_assert! (storage.is_none()); Self :: +// begin_precise(None, context, on_end) +// } +// } +// #[doc = +// r" Use as subformer of a field during process of forming of super structure."] +// pub type Struct1Subformer < __Superformer, __End > = Struct1Former < +// Struct1FormerDefinition < __Superformer, __Superformer, __End, > , > ; +// #[doc = +// r" Use as subformer end of a field during process of forming of super structure."] +// pub trait Struct1SubformerEnd < SuperFormer > where Self : former :: +// FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, SuperFormer > , > , +// {} impl < SuperFormer, T > Struct1SubformerEnd < SuperFormer > for T where +// Self : former :: FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, +// SuperFormer > , > , {} +// #[doc = r" Return original former after container for `vec_1` is done."] +// #[allow(non_camel_case_types)] // -// #[allow(non_camel_case_types)] -// pub struct Struct1FormerAssignVec1End; -// -// #[automatically_derived] -// impl < Definition, > former :: FormingEnd +// pub struct Struct1FormerAssignVec1End; +// #[automatically_derived] +// impl < Definition, > former :: FormingEnd +// < +// < Vec < String > as former :: EntityToDefinition // < -// < Vec < String > as former :: EntityToDefinition < Struct1Former < Definition, > , Struct1Former < Definition, > , former :: NoEnd > > :: Definition, -// > -// for Struct1FormerAssignVec1End -// where -// Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// #[inline(always)] 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 -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.vec_1 = Some(storage); } super_former -// } -// } +// Struct1Former < Definition, > , Struct1Former < Definition, > , former :: NoEnd > +// > :: Definition, +// > +// for Struct1FormerAssignVec1End +// where +// Definition : former :: FormerDefinition, +// Definition :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , +// Definition : former :: FormerDefinition, +// Definition :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , +// { +// #[inline(always)] 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 +// { former :: ContainerAssign :: assign(field, storage); } else +// { super_former.storage.vec_1 = Some(storage); } super_former +// } +// } // -// #[doc = r" Return original former after container for `vec_1` is done."] -// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashmap1End; -// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: -// HashMapDefinition < String, String, Struct1Former < Definition, > , -// Struct1Former < Definition, > , former :: NoEnd > , > for -// Struct1FormerAssignHashmap1End where Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = -// Struct1FormerStorage < > > , Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = -// Struct1FormerStorage < > > , -// { -// #[inline(always)] fn -// call(& self, storage : std :: collections :: HashMap < String, String > , -// super_former : Option < Struct1Former < Definition, > > ,) -> -// Struct1Former < Definition, > -// { -// let mut super_former = super_former.unwrap(); if let -// Some(ref mut field) = super_former.storage.hashmap_1 -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.hashmap_1 = Some(storage); } super_former -// } -// } #[doc = r" Return original former after container for `vec_1` is done."] -// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashset1End; -// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: -// HashSetDefinition < String, Struct1Former < Definition, > , Struct1Former < -// Definition, > , former :: NoEnd > , > for Struct1FormerAssignHashset1End where -// Definition : former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , Definition : -// former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// #[inline(always)] fn -// call(& self, storage : std :: collections :: HashSet < String > , -// super_former : Option < Struct1Former < Definition, > > ,) -> -// Struct1Former < Definition, > -// { -// let mut super_former = super_former.unwrap(); if let -// Some(ref mut field) = super_former.storage.hashset_1 -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.hashset_1 = Some(storage); } super_former -// } -// } +// #[doc = r" Return original former after container for `vec_1` is done."] +// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashmap1End; +// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: +// HashMapDefinition < String, String, Struct1Former < Definition, > , +// Struct1Former < Definition, > , former :: NoEnd > , > for +// Struct1FormerAssignHashmap1End where Definition : former :: FormerDefinition, +// Definition :: Types : former :: FormerDefinitionTypes < Storage = +// Struct1FormerStorage < > > , Definition : former :: FormerDefinition, +// Definition :: Types : former :: FormerDefinitionTypes < Storage = +// Struct1FormerStorage < > > , +// { +// #[inline(always)] fn +// call(& self, storage : std :: collections :: HashMap < String, String > , +// super_former : Option < Struct1Former < Definition, > > ,) -> +// Struct1Former < Definition, > +// { +// let mut super_former = super_former.unwrap(); if let +// Some(ref mut field) = super_former.storage.hashmap_1 +// { former :: ContainerAssign :: assign(field, storage); } else +// { super_former.storage.hashmap_1 = Some(storage); } super_former +// } +// } #[doc = r" Return original former after container for `vec_1` is done."] +// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashset1End; +// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: +// HashSetDefinition < String, Struct1Former < Definition, > , Struct1Former < +// Definition, > , former :: NoEnd > , > for Struct1FormerAssignHashset1End where +// Definition : former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , Definition : +// former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , +// { +// #[inline(always)] fn +// call(& self, storage : std :: collections :: HashSet < String > , +// super_former : Option < Struct1Former < Definition, > > ,) -> +// Struct1Former < Definition, > +// { +// let mut super_former = super_former.unwrap(); if let +// Some(ref mut field) = super_former.storage.hashset_1 +// { former :: ContainerAssign :: assign(field, storage); } else +// { super_former.storage.hashset_1 = Some(storage); } super_former +// } +// } // == generated end diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_container.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_container.rs new file mode 100644 index 0000000000..522ece211b --- /dev/null +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_container.rs @@ -0,0 +1,21 @@ + +#[ test ] +fn basic() +{ + + let got = Parent::former() + .children() + .add( Child::former().name( "a" ).form() ) + .add( Child::former().name( "b" ).form() ) + .end() + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs deleted file mode 100644 index 22d24e69ac..0000000000 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_shortcut.rs +++ /dev/null @@ -1,43 +0,0 @@ - -#[ test ] -fn basic() -{ - -// let got = Parent::former() -// .children() -// .add( Child::former().name( "a" ).form() ) -// .add( Child::former().name( "b" ).form() ) -// .end() -// .form(); -// -// let children = vec! -// [ -// Child { name : "a".to_string(), is_mandatory : false }, -// Child { name : "b".to_string(), is_mandatory : false }, -// ]; -// let exp = Parent { children }; -// a_id!( got, exp ); - -} - -#[ test ] -fn child() -{ - - let got = Parent::former() - .child( "a" ).end() - .child( "b" ).end() - // .add( Child::former().name( "a" ).form() ) - // .add( Child::former().name( "b" ).form() ) - // .end() - .form(); - - let children = vec! - [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, - ]; - let exp = Parent { children }; - a_id!( got, exp ); - -} diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs new file mode 100644 index 0000000000..58bd50f517 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs @@ -0,0 +1,22 @@ + +#[ test ] +fn child() +{ + + let got = Parent::former() + .child( "a" ).end() + .child( "b" ).end() + // .add( Child::former().name( "a" ).form() ) + // .add( Child::former().name( "b" ).form() ) + // .end() + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs b/module/core/former/tests/inc/former_tests/subformer_subform.rs similarity index 94% rename from module/core/former/tests/inc/former_tests/subformer_shortcut.rs rename to module/core/former/tests/inc/former_tests/subformer_subform.rs index 9021529890..fe3ec1ffe9 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform.rs @@ -38,4 +38,4 @@ where // -include!( "./only_test/subformer_shortcut.rs" ); +include!( "./only_test/subformer_subform.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs new file mode 100644 index 0000000000..e86212bf01 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs @@ -0,0 +1,571 @@ +#![ allow( dead_code ) ] + +use super::*; + +// xxx : rename +/// Parameter description. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent required for the template. +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +#[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + // #[ container( former::VectorDefinition ) ] + // #[ subform ] + children : Vec< Child >, +} + +// = begin of generated for Parent in context of attribute subform + +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn _children_element_subformer_with_closure< Former2, Definition2, Types2 >( self ) -> + Former2 + where + Types2 : former::FormerDefinitionTypes + < + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2 : former::FormerDefinition + < + Types = Types2, + End = former::FormingEndClosure< Types2 >, + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2::End : former::FormingEnd< Definition2::Types >, + Former2 : former::FormerBegin + < + Definition2, + >, + { + let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + if super_former.storage.children.is_none() + { + super_former.storage.children = Some( Default::default() ); + } + if let Some( ref mut children ) = super_former.storage.children + { + former::ContainerAdd::add( children, former::StoragePreform::preform( substorage ) ); + } + super_former + }; + Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + } + + #[ inline( always ) ] + pub fn _children_element_subformer< Former2, Definition2 >( self ) -> + Former2 + where + Definition2 : former::FormerDefinition + < + End = ParentFormerAddChildsEnd< Definition >, + Storage = < Child as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Definition2::Types : former::FormerDefinitionTypes + < + Storage = < Child as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Former2 : former::FormerBegin< Definition2 >, + { + Former2::former_begin( None, Some( self ), ParentFormerAddChildsEnd::default() ) + } + + #[ inline( always ) ] + pub fn child( self, name : &str ) -> + ChildSubformer< Self, impl ChildSubformerEnd< Self > > + { + self._children_element_subformer + ::< ChildFormer< _ >, _, >() + .name( name ) + } + +} + +/// Handles the completion of and element of subformer's container. +pub struct ParentFormerAddChildsEnd< Definition > +{ + _phantom : core::marker::PhantomData< fn( Definition ) >, +} + +impl< Definition > Default +for ParentFormerAddChildsEnd< Definition > +{ + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} + +impl< Types2, Definition > former::FormingEnd< Types2, > +for ParentFormerAddChildsEnd< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = < Parent as former::EntityToStorage >::Storage, + >, + Types2 : former::FormerDefinitionTypes + < + // Storage = < Child as former::EntityToStorage >::Storage, + Storage = < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + Formed = ParentFormer< Definition >, + Context = ParentFormer< Definition >, + >, + // Types2::Storage : former::StoragePreform< Preformed = >, +{ + #[ inline( always ) ] + fn call + ( + &self, + substorage : Types2::Storage, + super_former : core::option::Option< Types2::Context >, + ) + -> Types2::Formed + { + let mut super_former = super_former.unwrap(); + if super_former.storage.children.is_none() + { + super_former.storage.children = Some( Default::default() ); + } + if let Some( ref mut fields ) = super_former.storage.children + { + former::ContainerAdd::add( fields, former::StoragePreform::preform( substorage ) ); + } + super_former + } +} + +// = end of generated for Parent in context of attribute subform + +// = begin of generated for Parent in context of attribute container( former::VectorDefinition ) ] + +#[ automatically_derived ] +impl< > Parent< > +where +{ + #[ doc = r"" ] + #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] + #[ doc = r"" ] #[ inline( always ) ] + pub fn former() -> ParentFormer< ParentFormerDefinition< (), Parent< >, former::ReturnPreformed > > + { + ParentFormer::< ParentFormerDefinition< (), Parent< >, former::ReturnPreformed > >::new_coercing( former::ReturnPreformed ) + } +} + +impl< Definition > former::EntityToFormer< Definition > for Parent< > +where + Definition : former::FormerDefinition< Storage = ParentFormerStorage< > >, +{ + type Former = ParentFormer< Definition >; +} + +impl< > former::EntityToStorage for Parent< > +where +{ + type Storage = ParentFormerStorage< >; +} + +#[ derive( Debug ) ] +pub struct ParentFormerDefinitionTypes< __Context = (), __Formed = Parent< >, > +where +{ + _phantom : core::marker::PhantomData< ( __Context, __Formed ) >, +} + +impl< __Context, __Formed, > ::core::default::Default for ParentFormerDefinitionTypes< __Context, __Formed, > +where +{ + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} + +impl< __Context, __Formed, > former::FormerDefinitionTypes for ParentFormerDefinitionTypes< __Context, __Formed, > +where +{ + type Storage = ParentFormerStorage< >; + type Formed = __Formed; + type Context = __Context; +} + +#[ derive( Debug ) ] +pub struct ParentFormerDefinition< __Context = (), __Formed = Parent< >, __End = former::ReturnPreformed, > +where +{ + _phantom : core::marker::PhantomData< ( __Context, __Formed, __End ) >, +} + +impl< __Context, __Formed, __End, > ::core::default::Default for ParentFormerDefinition< __Context, __Formed, __End, > +where +{ + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} + +impl< __Context, __Formed, __End, > former::FormerDefinition for ParentFormerDefinition< __Context, __Formed, __End, > +where + __End : former::FormingEnd< ParentFormerDefinitionTypes< __Context, __Formed, > >, +{ + type Types = ParentFormerDefinitionTypes< __Context, __Formed, >; + type End = __End; + type Storage = ParentFormerStorage< >; + type Formed = __Formed; + type Context = __Context; +} + +#[ doc = "Container of a corresponding former." ] +pub struct ParentFormerStorage< > +where +{ + #[ doc = r" A field" ] + pub children : ::core::option::Option< Vec< Child > >, +} + +impl< > ::core::default::Default for ParentFormerStorage< > +where +{ + #[ inline( always ) ] + fn default() -> Self + { + Self + { + children : ::core::option::Option::None, + } + } +} + +impl< > former::Storage for ParentFormerStorage< > +where +{ + type Formed = Parent< >; +} + +impl< > former::StoragePreform for ParentFormerStorage< > +where +{ + type Preformed = Parent< >; + + fn preform( mut self ) -> Self::Preformed + { + let children = if self.children.is_some() + { + self.children.take().unwrap() + } + else + { + trait MaybeDefault< T > + { + fn maybe_default( self : &Self ) -> T + { + panic!( "Field 'children' isn't initialized" ) + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where + T : ::core::default::Default, + { + fn maybe_default( self : &Self ) -> T { T::default() } + } + ( &::core::marker::PhantomData::< Vec< Child > > ).maybe_default() + }; + let result = Parent::< > { children, }; + return result; + } +} + +#[ doc = +" Object to form [Parent]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] +pub struct ParentFormer< Definition = ParentFormerDefinition< (), Parent< >, former::ReturnPreformed >, > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, +{ + storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : core::option::Option< Definition::End >, +} + +#[ automatically_derived ] +impl< Definition, > ParentFormer< Definition, > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, +{ + #[ doc = r"" ] + #[ doc = r" Construct new instance of former with default parameters." ] + #[ doc = r"" ] #[ inline( always ) ] + pub fn new_precise( on_end : Definition::End ) -> Self + { + Self::begin_coercing( None, None, on_end ) + } + #[ doc = r"" ] + #[ doc = r" Construct new instance of former with default parameters." ] + #[ doc = r"" ] #[ inline( always ) ] + pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self + where + IntoEnd : Into< Definition::End >, + { + Self::begin_coercing( None, None, end, ) + } + #[ doc = r"" ] + #[ doc = + r" Begin the process of forming. Expects context of forming to return it after forming." ] + #[ doc = r"" ] #[ inline( always ) ] + pub fn begin_precise( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : < Definition as former::FormerDefinition >::End, + ) -> Self + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some( on_end ), + } + } + #[ doc = r"" ] + #[ doc = + r" Begin the process of forming. Expects context of forming to return it after forming." ] + #[ doc = r"" ] #[ inline( always ) ] + pub fn begin_coercing< IntoEnd >( + mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + on_end : IntoEnd, + ) -> Self + where + IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, + { + if storage.is_none() + { + storage = Some( ::core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), + } + } + #[ doc = r"" ] + #[ doc = + r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] #[ inline( always ) ] + pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { self.end() } + #[ doc = r"" ] + #[ doc = + r" End the process of forming returning original context of forming." ] + #[ doc = r"" ] #[ inline( always ) ] + pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) + } + #[ doc = + "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer." ] + #[ inline( always ) ] + pub fn _children_assign< Former2 >( self ) -> Former2 + where + Former2 : former::FormerBegin< former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd, > >, + { + Former2::former_begin( None, Some( self ), ParentFormerAssignChildrenEnd ) + } + #[ doc = + "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer." ] + #[ inline( always ) ] + pub fn children( self ) -> former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd, > > + { + self._children_assign::< former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd, > > >() + } + +} + +impl< Definition, > ParentFormer< Definition, > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< >, Formed = Parent< > >, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Parent< > >, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, +{ + pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + former::StoragePreform::preform( self.storage ) + } +} + +#[ automatically_derived ] +impl< Definition, > ParentFormer< Definition, > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< >, Formed = Parent< > >, +{ + #[ doc = r"" ] + #[ doc = r" Finish setting options and call perform on formed entity." ] + #[ doc = r"" ] + #[ doc = + r" If `perform` defined then associated method is called and its result returned instead of entity." ] + #[ doc = + r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`." ] + #[ doc = r"" ] #[ inline( always ) ] + pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + { + let result = self.form(); + return result; + } +} + +impl< Definition > former::FormerBegin< Definition > for ParentFormer< Definition, > +where + Definition : former::FormerDefinition< Storage = ParentFormerStorage< > >, +{ + #[ inline( always ) ] + fn former_begin( + storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Definition::Context >, + on_end : Definition::End, + ) -> Self + { + debug_assert!( storage.is_none() ); + Self::begin_precise( None, context, on_end ) + } +} + +#[ doc = +r" Use as subformer of a field during process of forming of super structure." ] +pub type ParentSubformer< __Superformer, __End > = ParentFormer< ParentFormerDefinition< __Superformer, __Superformer, __End, >, >; + +#[ doc = +r" Use as subformer end of a field during process of forming of super structure." ] +pub trait ParentSubformerEnd< SuperFormer > +where + Self : former::FormingEnd< ParentFormerDefinitionTypes< SuperFormer, SuperFormer >, >, +{} + +impl< SuperFormer, T > ParentSubformerEnd< SuperFormer > for T +where + Self : former::FormingEnd< ParentFormerDefinitionTypes< SuperFormer, SuperFormer >, >, +{} + +#[ doc = r" Return original former after container for `vec_1` is done." ] +#[ allow( non_camel_case_types ) ] +pub struct ParentFormerAssignChildrenEnd; + +#[ automatically_derived ] +impl< Definition, > former::FormingEnd< former::VectorDefinition< Child, ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd >, > for ParentFormerAssignChildrenEnd +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, +{ + #[ inline( always ) ] + fn call( + &self, + storage : Vec< Child >, + super_former : Option< ParentFormer< Definition, > >, + ) -> ParentFormer< Definition, > + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.children + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.children = Some( storage ); + } + super_former + } +} + +#[ doc = r" Handles the completion of an element of subformer's container." ] +pub struct ParentFormerAddChildrenEnd< Definition > +{ + _phantom : core::marker::PhantomData< fn( Definition ) >, +} + +impl< Definition > Default for ParentFormerAddChildrenEnd< Definition > +{ + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} + +impl< Types2, Definition > former::FormingEnd< Types2, > for ParentFormerAddChildrenEnd< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parent< > as former::EntityToStorage >::Storage, >, + Types2 : former::FormerDefinitionTypes< Storage = < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, Formed = ParentFormer< Definition, >, Context = ParentFormer< Definition, >, >, +{ + #[ inline( always ) ] + fn call( + &self, + substorage : Types2::Storage, + super_former : core::option::Option< Types2::Context >, + ) -> Types2::Formed + { + let mut super_former = super_former.unwrap(); + if super_former.storage.children.is_none() + { + super_former.storage.children = Some( Default::default() ); + } + if let Some( ref mut field ) = super_former.storage.children + { + former::ContainerAdd::add( field, former::StoragePreform::preform( substorage ) ); + } + super_former + } +} + +// = end of generated for Parent in context of attribute container( former::VectorDefinition ) ] + +include!( "./only_test/subformer_subform.rs" ); +include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs similarity index 98% rename from module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs rename to module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 1fd12a4d31..e824e7c3e4 100644 --- a/module/core/former/tests/inc/former_tests/subformer_shortcut_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -13,6 +13,7 @@ pub struct Child /// Parent required for the template. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { // #[ container( former::VectorDefinition ) ] @@ -180,6 +181,4 @@ where } } -// - -include!( "./only_test/subformer_shortcut.rs" ); +include!( "./only_test/subformer_subform.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 12bdc75f01..cb00c05876 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -65,9 +65,14 @@ mod former_tests mod subformer_custom_experimental; #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_shortcut_manual; + mod subformer_subform; #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_shortcut; + mod subformer_subform_manual; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_implicit_container; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_subform_implicit_container_manutal; // xxx } From b3b9c57517f7b06b7f85b770a0db9f06b89e8655 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 29 Apr 2024 17:34:52 +0300 Subject: [PATCH 305/533] former : experimenting --- .../subformer_subform_implicit_container.rs | 56 +++---------------- .../former_tests/subformer_subform_manual.rs | 10 ++-- module/core/former_meta/src/derive/former.rs | 4 +- 3 files changed, 14 insertions(+), 56 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs index e86212bf01..f4528dc659 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs @@ -76,7 +76,7 @@ where where Definition2 : former::FormerDefinition < - End = ParentFormerAddChildsEnd< Definition >, + End = ParentFormerAddChildrenEnd< Definition >, Storage = < Child as former::EntityToStorage >::Storage, Formed = Self, Context = Self, @@ -89,7 +89,7 @@ where >, Former2 : former::FormerBegin< Definition2 >, { - Former2::former_begin( None, Some( self ), ParentFormerAddChildsEnd::default() ) + Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) } #[ inline( always ) ] @@ -104,13 +104,13 @@ where } /// Handles the completion of and element of subformer's container. -pub struct ParentFormerAddChildsEnd< Definition > +pub struct ParentFormerAddChildrenEnd< Definition > { _phantom : core::marker::PhantomData< fn( Definition ) >, } impl< Definition > Default -for ParentFormerAddChildsEnd< Definition > +for ParentFormerAddChildrenEnd< Definition > { #[ inline( always ) ] fn default() -> Self @@ -123,7 +123,7 @@ for ParentFormerAddChildsEnd< Definition > } impl< Types2, Definition > former::FormingEnd< Types2, > -for ParentFormerAddChildsEnd< Definition > +for ParentFormerAddChildrenEnd< Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes @@ -489,6 +489,8 @@ where Self : former::FormingEnd< ParentFormerDefinitionTypes< SuperFormer, SuperFormer >, >, {} +// = assign + #[ doc = r" Return original former after container for `vec_1` is done." ] #[ allow( non_camel_case_types ) ] pub struct ParentFormerAssignChildrenEnd; @@ -521,50 +523,6 @@ where } } -#[ doc = r" Handles the completion of an element of subformer's container." ] -pub struct ParentFormerAddChildrenEnd< Definition > -{ - _phantom : core::marker::PhantomData< fn( Definition ) >, -} - -impl< Definition > Default for ParentFormerAddChildrenEnd< Definition > -{ - #[ inline( always ) ] - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } -} - -impl< Types2, Definition > former::FormingEnd< Types2, > for ParentFormerAddChildrenEnd< Definition > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = < Parent< > as former::EntityToStorage >::Storage, >, - Types2 : former::FormerDefinitionTypes< Storage = < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, Formed = ParentFormer< Definition, >, Context = ParentFormer< Definition, >, >, -{ - #[ inline( always ) ] - fn call( - &self, - substorage : Types2::Storage, - super_former : core::option::Option< Types2::Context >, - ) -> Types2::Formed - { - let mut super_former = super_former.unwrap(); - if super_former.storage.children.is_none() - { - super_former.storage.children = Some( Default::default() ); - } - if let Some( ref mut field ) = super_former.storage.children - { - former::ContainerAdd::add( field, former::StoragePreform::preform( substorage ) ); - } - super_former - } -} - // = end of generated for Parent in context of attribute container( former::VectorDefinition ) ] include!( "./only_test/subformer_subform.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index e824e7c3e4..40409c8542 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -94,7 +94,7 @@ where where Definition2 : former::FormerDefinition < - End = ParentFormerAddChildsEnd< Definition >, + End = ParentFormerAddChildrenEnd< Definition >, Storage = < Child as former::EntityToStorage >::Storage, Formed = Self, Context = Self, @@ -107,7 +107,7 @@ where >, Former2 : former::FormerBegin< Definition2 >, { - Former2::former_begin( None, Some( self ), ParentFormerAddChildsEnd::default() ) + Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) } #[ inline( always ) ] @@ -122,13 +122,13 @@ where } /// Handles the completion of and element of subformer's container. -pub struct ParentFormerAddChildsEnd< Definition > +pub struct ParentFormerAddChildrenEnd< Definition > { _phantom : core::marker::PhantomData< fn( Definition ) >, } impl< Definition > Default -for ParentFormerAddChildsEnd< Definition > +for ParentFormerAddChildrenEnd< Definition > { #[ inline( always ) ] fn default() -> Self @@ -141,7 +141,7 @@ for ParentFormerAddChildsEnd< Definition > } impl< Types2, Definition > former::FormingEnd< Types2, > -for ParentFormerAddChildsEnd< Definition > +for ParentFormerAddChildrenEnd< Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index e481029cc6..3a517c4955 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -627,7 +627,7 @@ fn field_subformer_map // let field_ty = field.non_optional_ty; // let params = typ::type_parameters( &field.non_optional_ty, .. ); - // example : `ParentFormerAddChildsEnd`` + // example : `ParentFormerAddChildrenEnd`` let parent_add_element_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); @@ -1066,7 +1066,7 @@ Result< TokenStream > let field_ty = field.non_optional_ty; // let params = typ::type_parameters( &field.non_optional_ty, .. ); - // example : `ParentFormerAddChildsEnd`` + // example : `ParentFormerAddChildrenEnd`` let parent_add_element_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); From c1b8311c4eaeb606174913a22f0367b8037756b1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 29 Apr 2024 17:56:29 +0300 Subject: [PATCH 306/533] former : experimenting --- .../subformer_subform_implicit_container.rs | 609 +++++++++--------- module/core/former_meta/src/derive/former.rs | 1 - 2 files changed, 308 insertions(+), 302 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs index f4528dc659..46be22930b 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs @@ -12,13 +12,14 @@ pub struct Child } /// Parent required for the template. -// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] // #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] -#[ derive( Debug, Default, PartialEq ) ] +// #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { // #[ container( former::VectorDefinition ) ] // #[ subform ] + #[ setter( false ) ] children : Vec< Child >, } @@ -165,161 +166,161 @@ where // = begin of generated for Parent in context of attribute container( former::VectorDefinition ) ] -#[ automatically_derived ] -impl< > Parent< > -where -{ - #[ doc = r"" ] - #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] - #[ doc = r"" ] #[ inline( always ) ] - pub fn former() -> ParentFormer< ParentFormerDefinition< (), Parent< >, former::ReturnPreformed > > - { - ParentFormer::< ParentFormerDefinition< (), Parent< >, former::ReturnPreformed > >::new_coercing( former::ReturnPreformed ) - } -} - -impl< Definition > former::EntityToFormer< Definition > for Parent< > -where - Definition : former::FormerDefinition< Storage = ParentFormerStorage< > >, -{ - type Former = ParentFormer< Definition >; -} - -impl< > former::EntityToStorage for Parent< > -where -{ - type Storage = ParentFormerStorage< >; -} - -#[ derive( Debug ) ] -pub struct ParentFormerDefinitionTypes< __Context = (), __Formed = Parent< >, > -where -{ - _phantom : core::marker::PhantomData< ( __Context, __Formed ) >, -} - -impl< __Context, __Formed, > ::core::default::Default for ParentFormerDefinitionTypes< __Context, __Formed, > -where -{ - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } -} - -impl< __Context, __Formed, > former::FormerDefinitionTypes for ParentFormerDefinitionTypes< __Context, __Formed, > -where -{ - type Storage = ParentFormerStorage< >; - type Formed = __Formed; - type Context = __Context; -} - -#[ derive( Debug ) ] -pub struct ParentFormerDefinition< __Context = (), __Formed = Parent< >, __End = former::ReturnPreformed, > -where -{ - _phantom : core::marker::PhantomData< ( __Context, __Formed, __End ) >, -} - -impl< __Context, __Formed, __End, > ::core::default::Default for ParentFormerDefinition< __Context, __Formed, __End, > -where -{ - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } -} - -impl< __Context, __Formed, __End, > former::FormerDefinition for ParentFormerDefinition< __Context, __Formed, __End, > -where - __End : former::FormingEnd< ParentFormerDefinitionTypes< __Context, __Formed, > >, -{ - type Types = ParentFormerDefinitionTypes< __Context, __Formed, >; - type End = __End; - type Storage = ParentFormerStorage< >; - type Formed = __Formed; - type Context = __Context; -} - -#[ doc = "Container of a corresponding former." ] -pub struct ParentFormerStorage< > -where -{ - #[ doc = r" A field" ] - pub children : ::core::option::Option< Vec< Child > >, -} - -impl< > ::core::default::Default for ParentFormerStorage< > -where -{ - #[ inline( always ) ] - fn default() -> Self - { - Self - { - children : ::core::option::Option::None, - } - } -} - -impl< > former::Storage for ParentFormerStorage< > -where -{ - type Formed = Parent< >; -} - -impl< > former::StoragePreform for ParentFormerStorage< > -where -{ - type Preformed = Parent< >; - - fn preform( mut self ) -> Self::Preformed - { - let children = if self.children.is_some() - { - self.children.take().unwrap() - } - else - { - trait MaybeDefault< T > - { - fn maybe_default( self : &Self ) -> T - { - panic!( "Field 'children' isn't initialized" ) - } - } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where - T : ::core::default::Default, - { - fn maybe_default( self : &Self ) -> T { T::default() } - } - ( &::core::marker::PhantomData::< Vec< Child > > ).maybe_default() - }; - let result = Parent::< > { children, }; - return result; - } -} - -#[ doc = -" Object to form [Parent]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] -pub struct ParentFormer< Definition = ParentFormerDefinition< (), Parent< >, former::ReturnPreformed >, > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, -{ - storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : core::option::Option< Definition::End >, -} +// #[ automatically_derived ] +// impl< > Parent< > +// where +// { +// #[ doc = r"" ] +// #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] +// #[ doc = r"" ] #[ inline( always ) ] +// pub fn former() -> ParentFormer< ParentFormerDefinition< (), Parent< >, former::ReturnPreformed > > +// { +// ParentFormer::< ParentFormerDefinition< (), Parent< >, former::ReturnPreformed > >::new_coercing( former::ReturnPreformed ) +// } +// } +// +// impl< Definition > former::EntityToFormer< Definition > for Parent< > +// where +// Definition : former::FormerDefinition< Storage = ParentFormerStorage< > >, +// { +// type Former = ParentFormer< Definition >; +// } +// +// impl< > former::EntityToStorage for Parent< > +// where +// { +// type Storage = ParentFormerStorage< >; +// } +// +// #[ derive( Debug ) ] +// pub struct ParentFormerDefinitionTypes< __Context = (), __Formed = Parent< >, > +// where +// { +// _phantom : core::marker::PhantomData< ( __Context, __Formed ) >, +// } +// +// impl< __Context, __Formed, > ::core::default::Default for ParentFormerDefinitionTypes< __Context, __Formed, > +// where +// { +// fn default() -> Self +// { +// Self +// { +// _phantom : core::marker::PhantomData, +// } +// } +// } +// +// impl< __Context, __Formed, > former::FormerDefinitionTypes for ParentFormerDefinitionTypes< __Context, __Formed, > +// where +// { +// type Storage = ParentFormerStorage< >; +// type Formed = __Formed; +// type Context = __Context; +// } +// +// #[ derive( Debug ) ] +// pub struct ParentFormerDefinition< __Context = (), __Formed = Parent< >, __End = former::ReturnPreformed, > +// where +// { +// _phantom : core::marker::PhantomData< ( __Context, __Formed, __End ) >, +// } +// +// impl< __Context, __Formed, __End, > ::core::default::Default for ParentFormerDefinition< __Context, __Formed, __End, > +// where +// { +// fn default() -> Self +// { +// Self +// { +// _phantom : core::marker::PhantomData, +// } +// } +// } +// +// impl< __Context, __Formed, __End, > former::FormerDefinition for ParentFormerDefinition< __Context, __Formed, __End, > +// where +// __End : former::FormingEnd< ParentFormerDefinitionTypes< __Context, __Formed, > >, +// { +// type Types = ParentFormerDefinitionTypes< __Context, __Formed, >; +// type End = __End; +// type Storage = ParentFormerStorage< >; +// type Formed = __Formed; +// type Context = __Context; +// } +// +// #[ doc = "Container of a corresponding former." ] +// pub struct ParentFormerStorage< > +// where +// { +// #[ doc = r" A field" ] +// pub children : ::core::option::Option< Vec< Child > >, +// } +// +// impl< > ::core::default::Default for ParentFormerStorage< > +// where +// { +// #[ inline( always ) ] +// fn default() -> Self +// { +// Self +// { +// children : ::core::option::Option::None, +// } +// } +// } +// +// impl< > former::Storage for ParentFormerStorage< > +// where +// { +// type Formed = Parent< >; +// } +// +// impl< > former::StoragePreform for ParentFormerStorage< > +// where +// { +// type Preformed = Parent< >; +// +// fn preform( mut self ) -> Self::Preformed +// { +// let children = if self.children.is_some() +// { +// self.children.take().unwrap() +// } +// else +// { +// trait MaybeDefault< T > +// { +// fn maybe_default( self : &Self ) -> T +// { +// panic!( "Field 'children' isn't initialized" ) +// } +// } +// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} +// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > +// where +// T : ::core::default::Default, +// { +// fn maybe_default( self : &Self ) -> T { T::default() } +// } +// ( &::core::marker::PhantomData::< Vec< Child > > ).maybe_default() +// }; +// let result = Parent::< > { children, }; +// return result; +// } +// } +// +// #[ doc = +// " Object to form [Parent]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] +// pub struct ParentFormer< Definition = ParentFormerDefinition< (), Parent< >, former::ReturnPreformed >, > +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, +// { +// storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, +// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, +// on_end : core::option::Option< Definition::End >, +// } #[ automatically_derived ] impl< Definition, > ParentFormer< Definition, > @@ -327,83 +328,84 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, { - #[ doc = r"" ] - #[ doc = r" Construct new instance of former with default parameters." ] - #[ doc = r"" ] #[ inline( always ) ] - pub fn new_precise( on_end : Definition::End ) -> Self - { - Self::begin_coercing( None, None, on_end ) - } - #[ doc = r"" ] - #[ doc = r" Construct new instance of former with default parameters." ] - #[ doc = r"" ] #[ inline( always ) ] - pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self - where - IntoEnd : Into< Definition::End >, - { - Self::begin_coercing( None, None, end, ) - } - #[ doc = r"" ] - #[ doc = - r" Begin the process of forming. Expects context of forming to return it after forming." ] - #[ doc = r"" ] #[ inline( always ) ] - pub fn begin_precise( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : < Definition as former::FormerDefinition >::End, - ) -> Self - { - if storage.is_none() - { - storage = Some( ::core::default::Default::default() ); - } - Self - { - storage : storage.unwrap(), - context : context, - on_end : ::core::option::Option::Some( on_end ), - } - } - #[ doc = r"" ] - #[ doc = - r" Begin the process of forming. Expects context of forming to return it after forming." ] - #[ doc = r"" ] #[ inline( always ) ] - pub fn begin_coercing< IntoEnd >( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : IntoEnd, - ) -> Self - where - IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, - { - if storage.is_none() - { - storage = Some( ::core::default::Default::default() ); - } - Self - { - storage : storage.unwrap(), - context : context, - on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), - } - } - #[ doc = r"" ] - #[ doc = - r" End the process of forming returning original context of forming." ] - #[ doc = r"" ] #[ inline( always ) ] - pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { self.end() } - #[ doc = r"" ] - #[ doc = - r" End the process of forming returning original context of forming." ] - #[ doc = r"" ] #[ inline( always ) ] - pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) - } - #[ doc = - "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer." ] +// #[ doc = r"" ] +// #[ doc = r" Construct new instance of former with default parameters." ] +// #[ doc = r"" ] #[ inline( always ) ] +// pub fn new_precise( on_end : Definition::End ) -> Self +// { +// Self::begin_coercing( None, None, on_end ) +// } +// #[ doc = r"" ] +// #[ doc = r" Construct new instance of former with default parameters." ] +// #[ doc = r"" ] #[ inline( always ) ] +// pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self +// where +// IntoEnd : Into< Definition::End >, +// { +// Self::begin_coercing( None, None, end, ) +// } +// #[ doc = r"" ] +// #[ doc = +// r" Begin the process of forming. Expects context of forming to return it after forming." ] +// #[ doc = r"" ] #[ inline( always ) ] +// pub fn begin_precise( +// mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, +// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, +// on_end : < Definition as former::FormerDefinition >::End, +// ) -> Self +// { +// if storage.is_none() +// { +// storage = Some( ::core::default::Default::default() ); +// } +// Self +// { +// storage : storage.unwrap(), +// context : context, +// on_end : ::core::option::Option::Some( on_end ), +// } +// } +// #[ doc = r"" ] +// #[ doc = +// r" Begin the process of forming. Expects context of forming to return it after forming." ] +// #[ doc = r"" ] #[ inline( always ) ] +// pub fn begin_coercing< IntoEnd >( +// mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, +// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, +// on_end : IntoEnd, +// ) -> Self +// where +// IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, +// { +// if storage.is_none() +// { +// storage = Some( ::core::default::Default::default() ); +// } +// Self +// { +// storage : storage.unwrap(), +// context : context, +// on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), +// } +// } +// #[ doc = r"" ] +// #[ doc = +// r" End the process of forming returning original context of forming." ] +// #[ doc = r"" ] #[ inline( always ) ] +// pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { self.end() } +// #[ doc = r"" ] +// #[ doc = +// r" End the process of forming returning original context of forming." ] +// #[ doc = r"" ] #[ inline( always ) ] +// pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed +// { +// let on_end = self.on_end.take().unwrap(); +// let context = self.context.take(); +// former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) +// } +// #[ doc = +// "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer." ] + #[ inline( always ) ] pub fn _children_assign< Former2 >( self ) -> Former2 where @@ -421,73 +423,78 @@ where } -impl< Definition, > ParentFormer< Definition, > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< >, Formed = Parent< > >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Parent< > >, - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, -{ - pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - { - former::StoragePreform::preform( self.storage ) - } -} - -#[ automatically_derived ] -impl< Definition, > ParentFormer< Definition, > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< >, Formed = Parent< > >, -{ - #[ doc = r"" ] - #[ doc = r" Finish setting options and call perform on formed entity." ] - #[ doc = r"" ] - #[ doc = - r" If `perform` defined then associated method is called and its result returned instead of entity." ] - #[ doc = - r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`." ] - #[ doc = r"" ] #[ inline( always ) ] - pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed - { - let result = self.form(); - return result; - } -} - -impl< Definition > former::FormerBegin< Definition > for ParentFormer< Definition, > -where - Definition : former::FormerDefinition< Storage = ParentFormerStorage< > >, -{ - #[ inline( always ) ] - fn former_begin( - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Definition::Context >, - on_end : Definition::End, - ) -> Self - { - debug_assert!( storage.is_none() ); - Self::begin_precise( None, context, on_end ) - } -} - -#[ doc = -r" Use as subformer of a field during process of forming of super structure." ] -pub type ParentSubformer< __Superformer, __End > = ParentFormer< ParentFormerDefinition< __Superformer, __Superformer, __End, >, >; - -#[ doc = -r" Use as subformer end of a field during process of forming of super structure." ] -pub trait ParentSubformerEnd< SuperFormer > -where - Self : former::FormingEnd< ParentFormerDefinitionTypes< SuperFormer, SuperFormer >, >, -{} - -impl< SuperFormer, T > ParentSubformerEnd< SuperFormer > for T -where - Self : former::FormingEnd< ParentFormerDefinitionTypes< SuperFormer, SuperFormer >, >, -{} +// = xxx + +// impl< Definition, > ParentFormer< Definition, > +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< >, Formed = Parent< > >, +// // xxx +// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Parent< > >, +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, +// { +// pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed +// { +// former::StoragePreform::preform( self.storage ) +// } +// } + +// = xxx + +// #[ automatically_derived ] +// impl< Definition, > ParentFormer< Definition, > +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< >, Formed = Parent< > >, +// { +// #[ doc = r"" ] +// #[ doc = r" Finish setting options and call perform on formed entity." ] +// #[ doc = r"" ] +// #[ doc = +// r" If `perform` defined then associated method is called and its result returned instead of entity." ] +// #[ doc = +// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`." ] +// #[ doc = r"" ] #[ inline( always ) ] +// pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed +// { +// let result = self.form(); +// return result; +// } +// } +// +// impl< Definition > former::FormerBegin< Definition > for ParentFormer< Definition, > +// where +// Definition : former::FormerDefinition< Storage = ParentFormerStorage< > >, +// { +// #[ inline( always ) ] +// fn former_begin( +// storage : core::option::Option< Definition::Storage >, +// context : core::option::Option< Definition::Context >, +// on_end : Definition::End, +// ) -> Self +// { +// debug_assert!( storage.is_none() ); +// Self::begin_precise( None, context, on_end ) +// } +// } +// +// #[ doc = +// r" Use as subformer of a field during process of forming of super structure." ] +// pub type ParentSubformer< __Superformer, __End > = ParentFormer< ParentFormerDefinition< __Superformer, __Superformer, __End, >, >; +// +// #[ doc = +// r" Use as subformer end of a field during process of forming of super structure." ] +// pub trait ParentSubformerEnd< SuperFormer > +// where +// Self : former::FormingEnd< ParentFormerDefinitionTypes< SuperFormer, SuperFormer >, >, +// {} +// +// impl< SuperFormer, T > ParentSubformerEnd< SuperFormer > for T +// where +// Self : former::FormingEnd< ParentFormerDefinitionTypes< SuperFormer, SuperFormer >, >, +// {} // = assign diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 3a517c4955..4506066225 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1779,7 +1779,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #struct_generics_ty >, Formed = #stru < #struct_generics_ty > >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = #stru < #struct_generics_ty > >, #former_generics_where { From e8a32208d6eccbb4ccb1580c5ec20d25a5c2233f Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 29 Apr 2024 18:15:44 +0300 Subject: [PATCH 307/533] former : experimenting --- .../subformer_subform_implicit_container.rs | 11 +++++----- module/core/former_meta/src/derive/former.rs | 21 +++++++------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs index 46be22930b..b8921f3d93 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs @@ -429,8 +429,7 @@ where // where // Definition : former::FormerDefinition, // Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< >, Formed = Parent< > >, -// // xxx -// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, +// x < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Parent< > >, // Definition : former::FormerDefinition, // Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, @@ -496,19 +495,19 @@ where // Self : former::FormingEnd< ParentFormerDefinitionTypes< SuperFormer, SuperFormer >, >, // {} -// = assign +// #[ doc = r" Return original former after container for `vec_1` is done." ] #[ allow( non_camel_case_types ) ] pub struct ParentFormerAssignChildrenEnd; #[ automatically_derived ] -impl< Definition, > former::FormingEnd< former::VectorDefinition< Child, ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd >, > for ParentFormerAssignChildrenEnd +impl< Definition, > former::FormingEnd +< former::VectorDefinition< Child, ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd >, > +for ParentFormerAssignChildrenEnd where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, { #[ inline( always ) ] fn call( diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 4506066225..33e7958299 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -939,12 +939,12 @@ fn field_former_assign_map field : &FormerField< '_ >, stru : &syn::Ident, former : &syn::Ident, - former_storage : &syn::Ident, + _former_storage : &syn::Ident, former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, _struct_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + _struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, _struct_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, ) -> @@ -1001,11 +1001,11 @@ Result< TokenStream > > for #former_assign_end where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes - < - Storage = #former_storage < #struct_generics_ty > - >, + // Definition : former::FormerDefinition, + // Definition::Types : former::FormerDefinitionTypes + // < + // Storage = #former_storage < #struct_generics_ty > + // >, #former_generics_where { #[ inline( always ) ] @@ -1104,10 +1104,6 @@ Result< TokenStream > >, Types2 : former::FormerDefinitionTypes < - // Storage = < Child as former::EntityToStorage >::Storage, - // Formed = ParentFormer< Definition >, - // Context = ParentFormer< Definition >, - // Storage = < < Vec< #field_ident > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, Storage = < < #field_ty as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, Formed = #former< #former_generics_ty >, Context = #former< #former_generics_ty >, @@ -1777,9 +1773,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl< #former_generics_impl > #former< #former_generics_ty > where - Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #struct_generics_ty >, Formed = #stru < #struct_generics_ty > >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = #stru < #struct_generics_ty > >, + // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = #stru < #struct_generics_ty > >, #former_generics_where { From 345f3720838d52b610be93fdc93226c9a62c2cdf Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 29 Apr 2024 18:20:48 +0300 Subject: [PATCH 308/533] former : experimenting --- .../subformer_subform_implicit_container.rs | 307 ------------------ 1 file changed, 307 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs index b8921f3d93..b1038ed64e 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs @@ -133,12 +133,10 @@ where >, Types2 : former::FormerDefinitionTypes < - // Storage = < Child as former::EntityToStorage >::Storage, Storage = < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, Formed = ParentFormer< Definition >, Context = ParentFormer< Definition >, >, - // Types2::Storage : former::StoragePreform< Preformed = >, { #[ inline( always ) ] fn call @@ -166,245 +164,12 @@ where // = begin of generated for Parent in context of attribute container( former::VectorDefinition ) ] -// #[ automatically_derived ] -// impl< > Parent< > -// where -// { -// #[ doc = r"" ] -// #[ doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step." ] -// #[ doc = r"" ] #[ inline( always ) ] -// pub fn former() -> ParentFormer< ParentFormerDefinition< (), Parent< >, former::ReturnPreformed > > -// { -// ParentFormer::< ParentFormerDefinition< (), Parent< >, former::ReturnPreformed > >::new_coercing( former::ReturnPreformed ) -// } -// } -// -// impl< Definition > former::EntityToFormer< Definition > for Parent< > -// where -// Definition : former::FormerDefinition< Storage = ParentFormerStorage< > >, -// { -// type Former = ParentFormer< Definition >; -// } -// -// impl< > former::EntityToStorage for Parent< > -// where -// { -// type Storage = ParentFormerStorage< >; -// } -// -// #[ derive( Debug ) ] -// pub struct ParentFormerDefinitionTypes< __Context = (), __Formed = Parent< >, > -// where -// { -// _phantom : core::marker::PhantomData< ( __Context, __Formed ) >, -// } -// -// impl< __Context, __Formed, > ::core::default::Default for ParentFormerDefinitionTypes< __Context, __Formed, > -// where -// { -// fn default() -> Self -// { -// Self -// { -// _phantom : core::marker::PhantomData, -// } -// } -// } -// -// impl< __Context, __Formed, > former::FormerDefinitionTypes for ParentFormerDefinitionTypes< __Context, __Formed, > -// where -// { -// type Storage = ParentFormerStorage< >; -// type Formed = __Formed; -// type Context = __Context; -// } -// -// #[ derive( Debug ) ] -// pub struct ParentFormerDefinition< __Context = (), __Formed = Parent< >, __End = former::ReturnPreformed, > -// where -// { -// _phantom : core::marker::PhantomData< ( __Context, __Formed, __End ) >, -// } -// -// impl< __Context, __Formed, __End, > ::core::default::Default for ParentFormerDefinition< __Context, __Formed, __End, > -// where -// { -// fn default() -> Self -// { -// Self -// { -// _phantom : core::marker::PhantomData, -// } -// } -// } -// -// impl< __Context, __Formed, __End, > former::FormerDefinition for ParentFormerDefinition< __Context, __Formed, __End, > -// where -// __End : former::FormingEnd< ParentFormerDefinitionTypes< __Context, __Formed, > >, -// { -// type Types = ParentFormerDefinitionTypes< __Context, __Formed, >; -// type End = __End; -// type Storage = ParentFormerStorage< >; -// type Formed = __Formed; -// type Context = __Context; -// } -// -// #[ doc = "Container of a corresponding former." ] -// pub struct ParentFormerStorage< > -// where -// { -// #[ doc = r" A field" ] -// pub children : ::core::option::Option< Vec< Child > >, -// } -// -// impl< > ::core::default::Default for ParentFormerStorage< > -// where -// { -// #[ inline( always ) ] -// fn default() -> Self -// { -// Self -// { -// children : ::core::option::Option::None, -// } -// } -// } -// -// impl< > former::Storage for ParentFormerStorage< > -// where -// { -// type Formed = Parent< >; -// } -// -// impl< > former::StoragePreform for ParentFormerStorage< > -// where -// { -// type Preformed = Parent< >; -// -// fn preform( mut self ) -> Self::Preformed -// { -// let children = if self.children.is_some() -// { -// self.children.take().unwrap() -// } -// else -// { -// trait MaybeDefault< T > -// { -// fn maybe_default( self : &Self ) -> T -// { -// panic!( "Field 'children' isn't initialized" ) -// } -// } -// impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > {} -// impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > -// where -// T : ::core::default::Default, -// { -// fn maybe_default( self : &Self ) -> T { T::default() } -// } -// ( &::core::marker::PhantomData::< Vec< Child > > ).maybe_default() -// }; -// let result = Parent::< > { children, }; -// return result; -// } -// } -// -// #[ doc = -// " Object to form [Parent]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n" ] -// pub struct ParentFormer< Definition = ParentFormerDefinition< (), Parent< >, former::ReturnPreformed >, > -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, -// { -// storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, -// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, -// on_end : core::option::Option< Definition::End >, -// } - #[ automatically_derived ] impl< Definition, > ParentFormer< Definition, > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, { -// #[ doc = r"" ] -// #[ doc = r" Construct new instance of former with default parameters." ] -// #[ doc = r"" ] #[ inline( always ) ] -// pub fn new_precise( on_end : Definition::End ) -> Self -// { -// Self::begin_coercing( None, None, on_end ) -// } -// #[ doc = r"" ] -// #[ doc = r" Construct new instance of former with default parameters." ] -// #[ doc = r"" ] #[ inline( always ) ] -// pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self -// where -// IntoEnd : Into< Definition::End >, -// { -// Self::begin_coercing( None, None, end, ) -// } -// #[ doc = r"" ] -// #[ doc = -// r" Begin the process of forming. Expects context of forming to return it after forming." ] -// #[ doc = r"" ] #[ inline( always ) ] -// pub fn begin_precise( -// mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, -// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, -// on_end : < Definition as former::FormerDefinition >::End, -// ) -> Self -// { -// if storage.is_none() -// { -// storage = Some( ::core::default::Default::default() ); -// } -// Self -// { -// storage : storage.unwrap(), -// context : context, -// on_end : ::core::option::Option::Some( on_end ), -// } -// } -// #[ doc = r"" ] -// #[ doc = -// r" Begin the process of forming. Expects context of forming to return it after forming." ] -// #[ doc = r"" ] #[ inline( always ) ] -// pub fn begin_coercing< IntoEnd >( -// mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, -// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, -// on_end : IntoEnd, -// ) -> Self -// where -// IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, -// { -// if storage.is_none() -// { -// storage = Some( ::core::default::Default::default() ); -// } -// Self -// { -// storage : storage.unwrap(), -// context : context, -// on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), -// } -// } -// #[ doc = r"" ] -// #[ doc = -// r" End the process of forming returning original context of forming." ] -// #[ doc = r"" ] #[ inline( always ) ] -// pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { self.end() } -// #[ doc = r"" ] -// #[ doc = -// r" End the process of forming returning original context of forming." ] -// #[ doc = r"" ] #[ inline( always ) ] -// pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed -// { -// let on_end = self.on_end.take().unwrap(); -// let context = self.context.take(); -// former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) -// } -// #[ doc = -// "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer." ] #[ inline( always ) ] pub fn _children_assign< Former2 >( self ) -> Former2 @@ -423,78 +188,6 @@ where } -// = xxx - -// impl< Definition, > ParentFormer< Definition, > -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< >, Formed = Parent< > >, -// x < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, -// < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Parent< > >, -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, -// { -// pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed -// { -// former::StoragePreform::preform( self.storage ) -// } -// } - -// = xxx - -// #[ automatically_derived ] -// impl< Definition, > ParentFormer< Definition, > -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< >, Formed = Parent< > >, -// { -// #[ doc = r"" ] -// #[ doc = r" Finish setting options and call perform on formed entity." ] -// #[ doc = r"" ] -// #[ doc = -// r" If `perform` defined then associated method is called and its result returned instead of entity." ] -// #[ doc = -// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`." ] -// #[ doc = r"" ] #[ inline( always ) ] -// pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed -// { -// let result = self.form(); -// return result; -// } -// } -// -// impl< Definition > former::FormerBegin< Definition > for ParentFormer< Definition, > -// where -// Definition : former::FormerDefinition< Storage = ParentFormerStorage< > >, -// { -// #[ inline( always ) ] -// fn former_begin( -// storage : core::option::Option< Definition::Storage >, -// context : core::option::Option< Definition::Context >, -// on_end : Definition::End, -// ) -> Self -// { -// debug_assert!( storage.is_none() ); -// Self::begin_precise( None, context, on_end ) -// } -// } -// -// #[ doc = -// r" Use as subformer of a field during process of forming of super structure." ] -// pub type ParentSubformer< __Superformer, __End > = ParentFormer< ParentFormerDefinition< __Superformer, __Superformer, __End, >, >; -// -// #[ doc = -// r" Use as subformer end of a field during process of forming of super structure." ] -// pub trait ParentSubformerEnd< SuperFormer > -// where -// Self : former::FormingEnd< ParentFormerDefinitionTypes< SuperFormer, SuperFormer >, >, -// {} -// -// impl< SuperFormer, T > ParentSubformerEnd< SuperFormer > for T -// where -// Self : former::FormingEnd< ParentFormerDefinitionTypes< SuperFormer, SuperFormer >, >, -// {} - // #[ doc = r" Return original former after container for `vec_1` is done." ] From e93def3693c92cc0ed53c5badad66544b47817a0 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 29 Apr 2024 18:31:50 +0300 Subject: [PATCH 309/533] former : experimenting --- .../subformer_subform_implicit_container.rs | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs index b1038ed64e..01ce1dce95 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs @@ -174,16 +174,16 @@ where #[ inline( always ) ] pub fn _children_assign< Former2 >( self ) -> Former2 where - Former2 : former::FormerBegin< former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd, > >, + Former2 : former::FormerBegin< former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > >, { - Former2::former_begin( None, Some( self ), ParentFormerAssignChildrenEnd ) + Former2::former_begin( None, Some( self ), ParentFormerAssignChildrenEnd::< Definition >::default() ) } #[ doc = "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer." ] #[ inline( always ) ] - pub fn children( self ) -> former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd, > > + pub fn children( self ) -> former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > { - self._children_assign::< former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd, > > >() + self._children_assign::< former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > >() } } @@ -192,12 +192,32 @@ where #[ doc = r" Return original former after container for `vec_1` is done." ] #[ allow( non_camel_case_types ) ] -pub struct ParentFormerAssignChildrenEnd; +pub struct ParentFormerAssignChildrenEnd< Definition > +{ + _phantom : core::marker::PhantomData< ( Definition, ) >, +} + +impl< Definition > Default for ParentFormerAssignChildrenEnd< Definition > +{ + + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + +} #[ automatically_derived ] impl< Definition, > former::FormingEnd < former::VectorDefinition< Child, ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd >, > -for ParentFormerAssignChildrenEnd +// < +// < Vec< Child > as former::EntityToDefinition< Parent, Parent, former::NoEnd > >::Definition +// > +for ParentFormerAssignChildrenEnd< Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, From 1040577c1c4f8e9f4bc8ab181f057d4dc1c60864 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 29 Apr 2024 18:34:14 +0300 Subject: [PATCH 310/533] former : experimenting --- .../subformer_subform_implicit_container.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs index 01ce1dce95..6b60b43f84 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs @@ -213,21 +213,23 @@ impl< Definition > Default for ParentFormerAssignChildrenEnd< Definition > #[ automatically_derived ] impl< Definition, > former::FormingEnd -< former::VectorDefinition< Child, ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd >, > -// < -// < Vec< Child > as former::EntityToDefinition< Parent, Parent, former::NoEnd > >::Definition -// > +// < former::VectorDefinition< Child, ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd >, > +< + < Vec< Child > as former::EntityToDefinition< ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd > >::Definition +> for ParentFormerAssignChildrenEnd< Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, { #[ inline( always ) ] - fn call( + fn call + ( &self, storage : Vec< Child >, super_former : Option< ParentFormer< Definition, > >, - ) -> ParentFormer< Definition, > + ) + -> ParentFormer< Definition, > { let mut super_former = super_former.unwrap(); if let Some( ref mut field ) = super_former.storage.children From cbcdf7ff034b2f253999803bc97bfba79b67c744 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 10:23:19 +0300 Subject: [PATCH 311/533] former : experimenting --- .../subformer_subform_implicit_container.rs | 3 +- module/core/former_meta/src/derive/former.rs | 32 ++++++++----------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs index 6b60b43f84..55d8004e18 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs @@ -190,8 +190,7 @@ where // -#[ doc = r" Return original former after container for `vec_1` is done." ] -#[ allow( non_camel_case_types ) ] +#[ doc = r"Callback to return original former after forming of container for `vec_1` is done. Callback replace content of container assigning new content from subformer's storage." ] pub struct ParentFormerAssignChildrenEnd< Definition > { _phantom : core::marker::PhantomData< ( Definition, ) >, diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 33e7958299..37b7c56249 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -896,7 +896,6 @@ fn container_setter /// # Example of generated code /// /// ```rust, ignore -/// #[ allow( non_camel_case_types ) ] /// pub struct Struct1FormerVec_1End; /// #[ automatically_derived ] /// impl< Definition > former::FormingEnd @@ -968,6 +967,14 @@ Result< TokenStream > // example : `former::VectorDefinition`` let subformer_definition = &field.attrs.container.as_ref().unwrap().expr; + // zzz : improve description + let former_assign_end_doc = format! + ( +r#"Callback to return original former after forming of container for `${stru}` is done.# + +Callback replace content of container assigning new content from subformer's storage."# + ); + let subformer_definition = if subformer_definition.is_some() { qt! @@ -989,23 +996,16 @@ Result< TokenStream > { // zzz : description - /// Return original former after container for `vec_1` is done. - #[ allow( non_camel_case_types ) ] + #[ doc = #former_assign_end_doc ] pub struct #former_assign_end; #[ automatically_derived ] impl< #former_generics_impl > former::FormingEnd < - // #subformer_definition < #( #params, )* #former< #former_generics_ty >, #former< #former_generics_ty >, former::NoEnd >, #subformer_definition, > for #former_assign_end where - // Definition : former::FormerDefinition, - // Definition::Types : former::FormerDefinitionTypes - // < - // Storage = #former_storage < #struct_generics_ty > - // >, #former_generics_where { #[ inline( always ) ] @@ -1287,13 +1287,14 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_definition = syn::Ident::new( &former_definition_name, stru.span() ); let former_definition_types_name = format!( "{}FormerDefinitionTypes", stru ); let former_definition_types = syn::Ident::new( &former_definition_types_name, stru.span() ); - // let former_with_closure_name = format!( "{}FormerWithClosure", stru ); - // let former_with_closure = syn::Ident::new( &former_with_closure_name, stru.span() ); let subformer_name = format!( "{}Subformer", stru ); let subformer = syn::Ident::new( &subformer_name, stru.span() ); let subformer_end_name = format!( "{}SubformerEnd", stru ); let subformer_end = syn::Ident::new( &subformer_end_name, stru.span() ); + // zzz : improve + let subformer_end_doc = format!( "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure." ); + /* parameters for structure */ let generics = &ast.generics; @@ -1854,15 +1855,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > >, >; - // pub type #former_with_closure < #former_definition_type_generics_ty > = - // #former_definition - // < - // #former_definition_type_generics_ty former::FormingEndClosure< #former_definition_types < #former_definition_type_generics_ty > > - // >; - // = subformer end - /// Use as subformer end of a field during process of forming of super structure. + // zzz : imporove documentation + #[ doc = #subformer_end_doc ] pub trait #subformer_end < #struct_generics_impl SuperFormer > where #struct_generics_where From d83a1db64bc36029d6581bdc0f2c83589576cae1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 11:44:04 +0300 Subject: [PATCH 312/533] former : experimenting --- .../a_containers_with_subformer_implicit.rs | 394 -------------- .../a_containers_with_subformer_manual.rs | 512 ++++++++++-------- .../only_test/containers_with_subformer.rs | 12 +- .../only_test/subformer_subform.rs | 3 - .../inc/former_tests/subformer_custom.rs | 10 +- .../subformer_custom_experimental.rs | 4 +- .../subformer_implicit_container.rs | 29 + ...=> subformer_implicit_container_manual.rs} | 3 +- .../inc/former_tests/subformer_subform.rs | 2 +- .../former_tests/subformer_subform_manual.rs | 2 +- module/core/former/tests/inc/mod.rs | 9 +- module/core/former_meta/src/derive/former.rs | 129 ++++- 12 files changed, 446 insertions(+), 663 deletions(-) delete mode 100644 module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs create mode 100644 module/core/former/tests/inc/former_tests/subformer_implicit_container.rs rename module/core/former/tests/inc/former_tests/{subformer_subform_implicit_container.rs => subformer_implicit_container_manual.rs} (98%) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs deleted file mode 100644 index 71e71d6bc6..0000000000 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_implicit.rs +++ /dev/null @@ -1,394 +0,0 @@ -#[ allow( unused_imports ) ] -use super::*; - -#[ derive( Default, Debug, PartialEq, former::Former ) ] -// #[ derive( Default, Debug, PartialEq, former::Former ) ] #[ debug ] -// #[ derive( Default, Debug, PartialEq ) ] -pub struct Struct1 -{ - #[ container( former::VectorDefinition ) ] - // #[ container ] - vec_1 : Vec< String >, - #[ container( former::HashMapDefinition ) ] - hashmap_1 : std::collections::HashMap< String, String >, - #[ container( former::HashSetDefinition ) ] - hashset_1 : std::collections::HashSet< String >, -} - -// == generated begin - -// #[automatically_derived] -// impl < > Struct1 < > where -// { -// #[doc = r""] -// #[doc = -// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] -// #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < -// Struct1FormerDefinition < (), Struct1 < > , former :: ReturnPreformed > > -// { -// Struct1Former :: < Struct1FormerDefinition < (), Struct1 < > , former -// :: ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) -// } -// } impl < Definition > former :: EntityToFormer < Definition > for Struct1 < > -// where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage -// < > > , { type Former = Struct1Former < Definition > ; } impl < > former :: -// EntityToStorage for Struct1 < > where -// { type Storage = Struct1FormerStorage < > ; } #[derive(Debug)] pub struct -// Struct1FormerDefinitionTypes < __Context = (), __Formed = Struct1 < > , > -// where { _phantom : core :: marker :: PhantomData < (__Context, __Formed) > , } -// impl < __Context, __Formed, > :: core :: default :: Default for -// Struct1FormerDefinitionTypes < __Context, __Formed, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, > former :: FormerDefinitionTypes for -// Struct1FormerDefinitionTypes < __Context, __Formed, > where -// { -// type Storage = Struct1FormerStorage < > ; type Formed = __Formed; type -// Context = __Context; -// } #[derive(Debug)] pub struct Struct1FormerDefinition < __Context = (), -// __Formed = Struct1 < > , __End = former :: ReturnPreformed, > where -// { -// _phantom : core :: marker :: PhantomData < (__Context, __Formed, __End) > -// , -// } impl < __Context, __Formed, __End, > :: core :: default :: Default for -// Struct1FormerDefinition < __Context, __Formed, __End, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, __End, > former :: FormerDefinition for -// Struct1FormerDefinition < __Context, __Formed, __End, > where __End : former -// :: FormingEnd < Struct1FormerDefinitionTypes < __Context, __Formed, > > , -// { -// type Types = Struct1FormerDefinitionTypes < __Context, __Formed, > ; type -// End = __End; type Storage = Struct1FormerStorage < > ; type Formed = -// __Formed; type Context = __Context; -// } #[doc = "Container of a corresponding former."] pub struct -// Struct1FormerStorage < > where -// { -// #[doc = r" A field"] pub vec_1 : :: core :: option :: Option < Vec < -// String > > , #[doc = r" A field"] pub hashmap_1 : :: core :: option :: -// Option < std :: collections :: HashMap < String, String > > , -// #[doc = r" A field"] pub hashset_1 : :: core :: option :: Option < std :: -// collections :: HashSet < String > > , -// } impl < > :: core :: default :: Default for Struct1FormerStorage < > where -// { -// #[inline(always)] fn default() -> Self -// { -// Self -// { -// vec_1 : :: core :: option :: Option :: None, hashmap_1 : :: core -// :: option :: Option :: None, hashset_1 : :: core :: option :: -// Option :: None, -// } -// } -// } impl < > former :: Storage for Struct1FormerStorage < > where -// { type Formed = Struct1 < > ; } impl < > former :: StoragePreform for -// Struct1FormerStorage < > where -// { -// type Preformed = Struct1 < > ; fn preform(mut self) -> Self :: Preformed -// { -// let vec_1 = if self.vec_1.is_some() { self.vec_1.take().unwrap() } -// else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'vec_1' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < Vec < String > -// >).maybe_default() -// } -// }; let hashmap_1 = if self.hashmap_1.is_some() -// { self.hashmap_1.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'hashmap_1' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < std :: collections :: -// HashMap < String, String > >).maybe_default() -// } -// }; let hashset_1 = if self.hashset_1.is_some() -// { self.hashset_1.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'hashset_1' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < std :: collections :: -// HashSet < String > >).maybe_default() -// } -// }; let result = Struct1 :: < > { vec_1, hashmap_1, hashset_1, }; -// return result; -// } -// } -// #[doc = -// " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -// pub struct Struct1Former < Definition = Struct1FormerDefinition < (), Struct1 -// < > , former :: ReturnPreformed > , > where Definition : former :: -// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = Struct1FormerStorage < > > , -// { -// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: -// Storage, context : core :: option :: Option < < Definition :: Types as -// former :: FormerDefinitionTypes > :: Context > , on_end : core :: option -// :: Option < Definition :: End > , -// } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > -// where Definition : former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn -// new_precise(on_end : Definition :: End) -> Self -// { Self :: begin_coercing(None, None, on_end) } #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > -// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , -// { Self :: begin_coercing(None, None, end,) } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn -// begin_precise(mut storage : core :: option :: Option < < Definition :: -// Types as former :: FormerDefinitionTypes > :: Storage > , context : core -// :: option :: Option < < Definition :: Types as former :: -// FormerDefinitionTypes > :: Context > , on_end : < Definition as former :: -// FormerDefinition > :: End,) -> Self -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: Some(on_end), -// } -// } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > -// (mut storage : core :: option :: Option < < Definition :: Types as former -// :: FormerDefinitionTypes > :: Storage > , context : core :: option :: -// Option < < Definition :: Types as former :: FormerDefinitionTypes > :: -// Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert -// :: Into < < Definition as former :: FormerDefinition > :: End > , -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: -// Some(:: core :: convert :: Into :: into(on_end)), -// } -// } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types -// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { -// let on_end = self.on_end.take().unwrap(); let context = -// self.context.take(); former :: FormingEnd :: < Definition :: Types > -// :: call(& on_end, self.storage, context) -// } -// #[doc = -// "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] -// #[inline(always)] pub fn _vec_1_assign < Former2 > (self) -> Former2 where -// Former2 : former :: FormerBegin < < Vec < String > as former :: -// EntityToDefinition < Self, Self, Struct1FormerAssignVec1End > > :: -// Definition > , -// { Former2 :: former_begin(None, Some(self), Struct1FormerAssignVec1End) } -// #[doc = -// "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] -// #[inline(always)] pub fn vec_1(self) -> former :: ContainerSubformer :: < -// String, < Vec < String > as former :: EntityToDefinition < Self, Self, -// Struct1FormerAssignVec1End > > :: Definition > -// { -// self._vec_1_assign :: < former :: ContainerSubformer :: < String, < -// Vec < String > as former :: EntityToDefinition < Self, Self, -// Struct1FormerAssignVec1End > > :: Definition >> () -// } -// #[doc = -// "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] -// #[inline(always)] pub fn _hashmap_1_assign < Former2 > (self) -> Former2 -// where Former2 : former :: FormerBegin < former :: HashMapDefinition < -// String, String, Self, Self, Struct1FormerAssignHashmap1End, > > , -// { -// Former2 :: -// former_begin(None, Some(self), Struct1FormerAssignHashmap1End) -// } -// #[doc = -// "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] -// #[inline(always)] pub fn hashmap_1(self) -> former :: ContainerSubformer -// :: < (String, String,), former :: HashMapDefinition < String, String, -// Self, Self, Struct1FormerAssignHashmap1End, > > -// { -// self._hashmap_1_assign :: < former :: ContainerSubformer :: < -// (String, String,), former :: HashMapDefinition < String, String, Self, -// Self, Struct1FormerAssignHashmap1End, > >> () -// } -// #[doc = -// "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] -// #[inline(always)] pub fn _hashset_1_assign < Former2 > (self) -> Former2 -// where Former2 : former :: FormerBegin < former :: HashSetDefinition < -// String, Self, Self, Struct1FormerAssignHashset1End, > > , -// { -// Former2 :: -// former_begin(None, Some(self), Struct1FormerAssignHashset1End) -// } -// #[doc = -// "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] -// #[inline(always)] pub fn hashset_1(self) -> former :: ContainerSubformer -// :: < String, former :: HashSetDefinition < String, Self, Self, -// Struct1FormerAssignHashset1End, > > -// { -// self._hashset_1_assign :: < former :: ContainerSubformer :: < String, -// former :: HashSetDefinition < String, Self, Self, -// Struct1FormerAssignHashset1End, > >> () -// } -// } impl < Definition, > Struct1Former < Definition, > where Definition : former -// :: FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = Struct1FormerStorage < > , Formed = Struct1 < > > , < Definition :: -// Types as former :: FormerDefinitionTypes > :: Storage : former :: -// StoragePreform, < Definition :: Types as former :: FormerDefinitionTypes > :: -// Storage : former :: StoragePreform < Preformed = Struct1 < > > , Definition : -// former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// pub fn preform(self) -> < Definition :: Types as former :: -// FormerDefinitionTypes > :: Formed -// { former :: StoragePreform :: preform(self.storage) } -// } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > -// where Definition : former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > , Formed = Struct1 -// < > > , -// { -// #[doc = r""] -// #[doc = r" Finish setting options and call perform on formed entity."] -// #[doc = r""] -// #[doc = -// r" If `perform` defined then associated method is called and its result returned instead of entity."] -// #[doc = -// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] -// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { let result = self.form(); return result; } -// } impl < Definition > former :: FormerBegin < Definition > for Struct1Former < -// Definition, > where Definition : former :: FormerDefinition < Storage = -// Struct1FormerStorage < > > , -// { -// #[inline(always)] fn -// former_begin(storage : core :: option :: Option < Definition :: Storage > -// , context : core :: option :: Option < Definition :: Context > , on_end : -// Definition :: End,) -> Self -// { -// debug_assert! (storage.is_none()); Self :: -// begin_precise(None, context, on_end) -// } -// } -// #[doc = -// r" Use as subformer of a field during process of forming of super structure."] -// pub type Struct1Subformer < __Superformer, __End > = Struct1Former < -// Struct1FormerDefinition < __Superformer, __Superformer, __End, > , > ; -// #[doc = -// r" Use as subformer end of a field during process of forming of super structure."] -// pub trait Struct1SubformerEnd < SuperFormer > where Self : former :: -// FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, SuperFormer > , > , -// {} impl < SuperFormer, T > Struct1SubformerEnd < SuperFormer > for T where -// Self : former :: FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, -// SuperFormer > , > , {} -// #[doc = r" Return original former after container for `vec_1` is done."] -// #[allow(non_camel_case_types)] -// -// pub struct Struct1FormerAssignVec1End; -// #[automatically_derived] -// impl < Definition, > former :: FormingEnd -// < -// < Vec < String > as former :: EntityToDefinition -// < -// Struct1Former < Definition, > , Struct1Former < Definition, > , former :: NoEnd > -// > :: Definition, -// > -// for Struct1FormerAssignVec1End -// where -// Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// #[inline(always)] 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 -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.vec_1 = Some(storage); } super_former -// } -// } -// -// #[doc = r" Return original former after container for `vec_1` is done."] -// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashmap1End; -// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: -// HashMapDefinition < String, String, Struct1Former < Definition, > , -// Struct1Former < Definition, > , former :: NoEnd > , > for -// Struct1FormerAssignHashmap1End where Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = -// Struct1FormerStorage < > > , Definition : former :: FormerDefinition, -// Definition :: Types : former :: FormerDefinitionTypes < Storage = -// Struct1FormerStorage < > > , -// { -// #[inline(always)] fn -// call(& self, storage : std :: collections :: HashMap < String, String > , -// super_former : Option < Struct1Former < Definition, > > ,) -> -// Struct1Former < Definition, > -// { -// let mut super_former = super_former.unwrap(); if let -// Some(ref mut field) = super_former.storage.hashmap_1 -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.hashmap_1 = Some(storage); } super_former -// } -// } #[doc = r" Return original former after container for `vec_1` is done."] -// #[allow(non_camel_case_types)] pub struct Struct1FormerAssignHashset1End; -// #[automatically_derived] impl < Definition, > former :: FormingEnd < former :: -// HashSetDefinition < String, Struct1Former < Definition, > , Struct1Former < -// Definition, > , former :: NoEnd > , > for Struct1FormerAssignHashset1End where -// Definition : former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , Definition : -// former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , -// { -// #[inline(always)] fn -// call(& self, storage : std :: collections :: HashSet < String > , -// super_former : Option < Struct1Former < Definition, > > ,) -> -// Struct1Former < Definition, > -// { -// let mut super_former = super_former.unwrap(); if let -// Some(ref mut field) = super_former.storage.hashset_1 -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.hashset_1 = Some(storage); } super_former -// } -// } - -// == generated end - -include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 6966aa8d71..2a4e07e94a 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -11,27 +11,43 @@ pub struct Struct1 // == begin of generated -#[ automatically_derived ] +#[automatically_derived] impl< > Struct1< > where { - #[ inline( always ) ] - pub fn former() -> Struct1Former< Struct1FormerDefinition< (), Struct1< >, former::ReturnPreformed > > + #[doc = r""] + #[doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step."] + #[doc = r""] + #[inline(always)] + pub fn former() -> Struct1Former< + Struct1FormerDefinition<(), Struct1<>, former::ReturnPreformed> + > { - Struct1Former::< Struct1FormerDefinition< (), Struct1< >, former::ReturnPreformed > >::new_coercing( former::ReturnPreformed ) + Struct1Former::, former::ReturnPreformed>>::new_coercing(former::ReturnPreformed) } } -// = types +impl< Definition > former::EntityToFormer< Definition > for Struct1< > +where + Definition : former::FormerDefinition< Storage = Struct1FormerStorage<> >, +{ + type Former = Struct1Former< Definition >; +} -#[ derive( Debug ) ] -pub struct Struct1FormerDefinitionTypes< __Context = (), __Formed = Struct1< >, > +impl< > former::EntityToStorage for Struct1< > where { - _phantom : core::marker::PhantomData< ( __Context, __Formed ) >, + type Storage = Struct1FormerStorage<>; } -impl< __Context, __Formed, > ::core::default::Default for Struct1FormerDefinitionTypes< __Context, __Formed, > +#[derive(Debug)] +pub struct Struct1FormerDefinitionTypes< Context = (), Formed = Struct1<>, > +where +{ + _phantom : core::marker::PhantomData<(Context, Formed)>, +} + +impl< Context, Formed, > core::default::Default for Struct1FormerDefinitionTypes< Context, Formed, > where { fn default() -> Self @@ -43,25 +59,22 @@ where } } -impl< __Context, __Formed, > former::FormerDefinitionTypes -for Struct1FormerDefinitionTypes< __Context, __Formed, > +impl< Context, Formed, > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed, > where { - type Storage = Struct1FormerStorage< >; - type Formed = __Formed; - type Context = __Context; + type Storage = Struct1FormerStorage<>; + type Formed = Formed; + type Context = Context; } -// = definition - -#[ derive( Debug ) ] -pub struct Struct1FormerDefinition< __Context = (), __Formed = Struct1< >, __End = former::ReturnPreformed, > +#[derive(Debug)] +pub struct Struct1FormerDefinition< Context = (), Formed = Struct1<>, End = former::ReturnPreformed, > where { - _phantom : core::marker::PhantomData< ( __Context, __Formed, __End ) >, + _phantom : core::marker::PhantomData<(Context, Formed, End)>, } -impl< __Context, __Formed, __End, > ::core::default::Default for Struct1FormerDefinition< __Context, __Formed, __End, > +impl< Context, Formed, End, > core::default::Default for Struct1FormerDefinition< Context, Formed, End, > where { fn default() -> Self @@ -73,55 +86,56 @@ where } } -impl< __Context, __Formed, __End, > former::FormerDefinition -for Struct1FormerDefinition< __Context, __Formed, __End, > +impl< Context, Formed, End, > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End, > where - __End : former::FormingEnd< Struct1FormerDefinitionTypes< __Context, __Formed, > >, + End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed, > >, { - type Types = Struct1FormerDefinitionTypes< __Context, __Formed, >; - type End = __End; - type Storage = Struct1FormerStorage< >; - type Formed = __Formed; - type Context = __Context; + type Types = Struct1FormerDefinitionTypes< Context, Formed, >; + type End = End; + type Storage = Struct1FormerStorage<>; + type Formed = Formed; + type Context = Context; } -// = storage - -pub struct Struct1FormerStorage< > +#[doc = "Container of a corresponding former."] +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 > >, + #[doc = r" A field"] + pub vec_1 : core::option::Option>, + #[doc = r" A field"] + pub hashmap_1 : core::option::Option>, + #[doc = r" A field"] + pub hashset_1 : core::option::Option>, } -impl< > ::core::default::Default for Struct1FormerStorage< > +impl< > core::default::Default for Struct1FormerStorage<> where { - #[ inline( always ) ] + #[inline(always)] fn default() -> Self { Self { - vec_1 : ::core::option::Option::None, - hashmap_1 : ::core::option::Option::None, - hashset_1 : ::core::option::Option::None, + vec_1 : core::option::Option::None, + hashmap_1 : core::option::Option::None, + hashset_1 : core::option::Option::None, } } } -impl< > former::Storage for Struct1FormerStorage< > +impl< > former::Storage for Struct1FormerStorage<> where { - type Formed = Struct1< >; + type Formed = Struct1<>; } -impl< > former::StoragePreform for Struct1FormerStorage< > +impl< > former::StoragePreform for Struct1FormerStorage<> where { - type Preformed = Struct1< >; + type Preformed = Struct1<>; - fn preform( mut self ) -> Self::Preformed + fn preform(mut self) -> Self::Preformed { let vec_1 = if self.vec_1.is_some() { @@ -130,28 +144,27 @@ where else { { - trait MaybeDefault< T > + trait MaybeDefault { - fn maybe_default( self : & Self ) -> T + fn maybe_default(self: &Self) -> T { - panic!( "Field 'vec_1' isn't initialized" ) + panic!("Field 'vec_1' isn't initialized") } } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > - { - } + impl MaybeDefault for &core::marker::PhantomData {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where T : ::core::default::Default, + impl MaybeDefault for core::marker::PhantomData + where + T : core::default::Default, { - fn maybe_default( self : & Self ) -> T + fn maybe_default(self: &Self) -> T { T::default() } } - (&::core::marker::PhantomData::< Vec< String > >).maybe_default() + (&core::marker::PhantomData::>).maybe_default() } }; @@ -162,28 +175,27 @@ where else { { - trait MaybeDefault< T > + trait MaybeDefault { - fn maybe_default( self : & Self ) -> T + fn maybe_default(self: &Self) -> T { - panic!( "Field 'hashmap_1' isn't initialized" ) + panic!("Field 'hashmap_1' isn't initialized") } } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > - { - } + impl MaybeDefault for &core::marker::PhantomData {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where T : ::core::default::Default, + impl MaybeDefault for core::marker::PhantomData + where + T : core::default::Default, { - fn maybe_default( self : & Self ) -> T + fn maybe_default(self: &Self) -> T { T::default() } } - (&::core::marker::PhantomData::< std::collections::HashMap< String, String > >).maybe_default() + (&core::marker::PhantomData::>).maybe_default() } }; @@ -194,314 +206,378 @@ where else { { - trait MaybeDefault< T > + trait MaybeDefault { - fn maybe_default( self : &Self ) -> T + fn maybe_default(self: &Self) -> T { - panic!( "Field 'hashset_1' isn't initialized" ) + panic!("Field 'hashset_1' isn't initialized") } } - impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > - { - } + impl MaybeDefault for &core::marker::PhantomData {} - impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > - where T : ::core::default::Default, + impl MaybeDefault for core::marker::PhantomData + where + T : core::default::Default, { - fn maybe_default( self : &Self ) -> T + fn maybe_default(self: &Self) -> T { T::default() } } - (&::core::marker::PhantomData::< std::collections::HashSet< String > >).maybe_default() + (&core::marker::PhantomData::>).maybe_default() } }; - let result = Struct1 + let result = Struct1::<> { - vec_1, - hashmap_1, - hashset_1, + vec_1, hashmap_1, hashset_1, }; return result; } } -// = former - -pub struct Struct1Former< Definition = Struct1FormerDefinition< (), Struct1< >, former::ReturnPreformed >, > +#[doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +pub struct Struct1Former< Definition = Struct1FormerDefinition<(), Struct1<>, former::ReturnPreformed>, > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { - storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : core::option::Option< Definition::End >, + storage : ::Storage, + context : core::option::Option<::Context>, + on_end : core::option::Option, } -#[ automatically_derived ] +#[automatically_derived] impl< Definition, > Struct1Former< Definition, > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { - - #[ inline( always ) ] - pub fn new_precise( on_end : Definition::End ) -> Self + #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] + #[inline(always)] + pub fn new_precise(on_end: Definition::End) -> Self { - Self::begin_coercing( None, None, on_end ) + Self::begin_coercing(None, None, on_end) } - #[ inline( always ) ] - pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self + #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] + #[inline(always)] + pub fn new_coercing(end: IntoEnd) -> Self where - IntoEnd : Into< Definition::End >, + IntoEnd : Into, { - Self::begin_coercing( None, None, end ) + Self::begin_coercing(None, None, end,) } - #[ inline( always ) ] - pub fn begin_precise - ( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : < Definition as former::FormerDefinition >::End, - ) -> Self + #[doc = r""] + #[doc = r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] + #[inline(always)] + pub fn begin_precise(mut storage: core::option::Option<::Storage>, context: core::option::Option<::Context>, on_end: ::End,) -> Self { if storage.is_none() { - storage = Some( ::core::default::Default::default() ); + storage = Some(core::default::Default::default()); } Self { - storage : storage.unwrap(), - context : context, - on_end : ::core::option::Option::Some( on_end ), + storage: storage.unwrap(), + context: context, + on_end: core::option::Option::Some(on_end), } } - #[ inline( always ) ] - pub fn begin_coercing< IntoEnd >( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, - on_end : IntoEnd, - ) -> Self + #[doc = r""] + #[doc = r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] + #[inline(always)] + pub fn begin_coercing(mut storage: core::option::Option<::Storage>, context: core::option::Option<::Context>, on_end: IntoEnd,) -> Self where - IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, + IntoEnd : core::convert::Into<::End>, { if storage.is_none() { - storage = Some( ::core::default::Default::default() ); + storage = Some(core::default::Default::default()); } Self { - storage : storage.unwrap(), - context : context, - on_end : ::core::option::Option::Some( ::core::convert::Into::into( on_end ) ), + storage: storage.unwrap(), + context: context, + on_end: core::option::Option::Some(core::convert::Into::into(on_end)), } } - #[ inline( always ) ] - pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + #[doc = r""] + #[doc = r" End the process of forming returning original context of forming."] + #[doc = r""] + #[inline(always)] + pub fn form(self) -> ::Formed { self.end() } - #[ inline( always ) ] - pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + #[doc = r""] + #[doc = r" End the process of forming returning original context of forming."] + #[doc = r""] + #[inline(always)] + pub fn end(mut self) -> ::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) + former::FormingEnd::::call(&on_end, self.storage, context) } - #[ inline( always ) ] - pub fn vec_1_set< Former2 >( self ) -> Former2 + #[doc = "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] + #[inline(always)] + pub fn _vec_1_assign(self) -> Former2 where - // Former2 : former::FormerBegin< former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End, > >, - Former2 : former::FormerBegin< < Vec< String > as former::EntityToDefinition< Self, Self, Struct1FormerAssignVec1End > >::Definition >, + Former2 : former::FormerBegin,>>, { - Former2::former_begin( None, Some( self ), Struct1FormerAssignVec1End ) + Former2::former_begin(None, Some(self), Struct1FormerAssignVec1End::::default()) } - #[ inline( always ) ] - pub fn vec_1( self ) -> - former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End > > + #[doc = "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] + #[inline(always)] + pub fn vec_1(self) -> former::ContainerSubformer::< + String, + former::VectorDefinition,> + > { - self.vec_1_set::< former::ContainerSubformer::< String, former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End > >>() + self._vec_1_assign::,>>> () } - #[ inline( always ) ] - pub fn hashmap_1_set< Former2 >( self ) -> Former2 + #[doc = "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] + #[inline(always)] + pub fn _hashmap_1_assign(self) -> Former2 where - Former2 : former::FormerBegin< former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End, > >, + Former2 : former::FormerBegin,>>, { - Former2::former_begin( None, Some( self ), Struct1FormerAssignHashmap1End ) + Former2::former_begin(None, Some(self), Struct1FormerAssignHashmap1End::::default()) } - - #[ inline( always ) ] - pub fn hashmap_1( self ) -> former::ContainerSubformer::< (String, String), former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End > > + #[doc = "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] + #[inline(always)] + pub fn hashmap_1(self) -> former::ContainerSubformer::< + (String, String,), + former::HashMapDefinition,> + > { - self.hashmap_1_set::< former::ContainerSubformer::< (String, String), former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End > >>() + self._hashmap_1_assign::,> + >> () } - - #[ inline( always ) ] - pub fn hashset_1_set< Former2 >( self ) -> Former2 + #[doc = "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] + #[inline(always)] + pub fn _hashset_1_assign(self) -> Former2 where - Former2 : former::FormerBegin< former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End, > >, + Former2 : former::FormerBegin,>>, { - Former2::former_begin( None, Some( self ), Struct1FormerAssignHashset1End ) + Former2::former_begin(None, Some(self), Struct1FormerAssignHashset1End::::default()) } - - #[ inline( always ) ] - pub fn hashset_1( self ) -> former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End > > + #[doc = "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] + #[inline(always)] + pub fn hashset_1(self) -> former::ContainerSubformer::< + String, + former::HashSetDefinition,> + > { - self.hashset_1_set::< former::ContainerSubformer::< String, former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End > >>() + self._hashset_1_assign::,> + >> () } } -// = former :: preform - impl< Definition, > Struct1Former< Definition, > where + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<>, Formed = Struct1<> >, Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< >, Formed = Struct1< > >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Struct1< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { - pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + pub fn preform(self) -> ::Formed { - former::StoragePreform::preform( self.storage ) + former::StoragePreform::preform(self.storage) } } -// = former :: perform - -#[ automatically_derived ] +#[automatically_derived] impl< Definition, > Struct1Former< Definition, > where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< >, Formed = Struct1< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<>, Formed = Struct1<> >, { - #[ inline( always ) ] - pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed + #[doc = r""] + #[doc = r" Finish setting options and call perform on formed entity."] + #[doc = r""] + #[doc = + r" If `perform` defined then associated method is called and its result returned instead of entity."] + #[doc = + r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] + #[doc = r""] + #[inline(always)] + pub fn perform(self) -> ::Formed { let result = self.form(); return result; } } -// = subformer - -#[ allow( dead_code ) ] -pub type Struct1Subformer< __Superformer, __End > -= Struct1Former< Struct1FormerDefinition< __Superformer, __Superformer, __End, >, >; - -// pub type Struct1FormerWithClosure< __Context, __Formed, > = Struct1FormerDefinition< __Context, __Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< __Context, __Formed, > > >; +impl< Definition > former::FormerBegin< Definition > for Struct1Former< Definition, > +where + Definition : former::FormerDefinition< Storage = Struct1FormerStorage<> >, +{ + #[inline(always)] + fn former_begin(storage: core::option::Option, context: core::option::Option, on_end: Definition::End,) -> Self + { + debug_assert!(storage.is_none()); + Self::begin_precise(None, context, on_end) + } +} -// = subformer end +#[doc = +r" Use as subformer of a field during process of forming of super structure."] +pub type Struct1AsSubformer = Struct1Former< + Struct1FormerDefinition, +>; -#[ allow( dead_code ) ] -pub trait Struct1SubformerEnd< SuperFormer > -where - Self : former::FormingEnd< Struct1FormerDefinitionTypes< SuperFormer, SuperFormer >, >, +#[doc = +"Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] +pub trait Struct1AsSubformerEnd where Self : former::FormingEnd< Struct1FormerDefinitionTypes, > {} -impl< SuperFormer, T > Struct1SubformerEnd< SuperFormer > for T +impl Struct1AsSubformerEnd for T where - Self : former::FormingEnd< Struct1FormerDefinitionTypes< SuperFormer, SuperFormer >, >, + Self : former::FormingEnd< Struct1FormerDefinitionTypes, >, {} -// = end handlers +#[doc = +"Callback to return original former after forming of container for `$Struct1` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] +pub struct Struct1FormerAssignVec1End +{ + _phantom : core::marker::PhantomData<(Definition,)>, +} -#[ allow( non_camel_case_types ) ] -pub struct Struct1FormerAssignVec1End; +impl Default for Struct1FormerAssignVec1End +{ + #[inline(always)] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} -#[ automatically_derived ] -impl< Definition, > former::FormingEnd -< former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, > -for Struct1FormerAssignVec1End +#[automatically_derived] +impl former::FormingEnd< former::VectorDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignVec1End where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { - #[ inline( always ) ] - fn call( &self, storage : Vec< String >, super_former : Option< Struct1Former< Definition, > >, ) -> - Struct1Former< Definition, > + #[inline(always)] + fn call(&self, storage: Vec, super_former: Option>,) -> Struct1Former { let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.vec_1 + if let Some(ref mut field) = super_former.storage.vec_1 { - former::ContainerAssign::assign( field, storage ); + former::ContainerAssign::assign(field, storage); } else { - super_former.storage.vec_1 = Some( storage ); + super_former.storage.vec_1 = Some(storage); } super_former } } -#[ allow( non_camel_case_types ) ] -pub struct Struct1FormerAssignHashmap1End; +#[doc = +"Callback to return original former after forming of container for `$Struct1` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] +pub struct Struct1FormerAssignHashmap1End +{ + _phantom : core::marker::PhantomData<(Definition,)>, +} + +impl Default for Struct1FormerAssignHashmap1End +{ + #[inline(always)] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} -#[ automatically_derived ] -impl< Definition, > -former::FormingEnd -< - former::HashMapDefinition< String, String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, -> -for Struct1FormerAssignHashmap1End +#[automatically_derived] +impl former::FormingEnd< former::HashMapDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignHashmap1End where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { - #[ inline( always ) ] - fn call( &self, storage : std::collections::HashMap< String, String >, super_former : Option< Struct1Former< Definition, > >, ) -> Struct1Former< Definition, > + #[inline(always)] + fn call(&self, storage: std::collections::HashMap, super_former: Option>,) -> Struct1Former { let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.hashmap_1 + if let Some(ref mut field) = super_former.storage.hashmap_1 { - former::ContainerAssign::assign( field, storage ); + former::ContainerAssign::assign(field, storage); } else { - super_former.storage.hashmap_1 = Some( storage ); + super_former.storage.hashmap_1 = Some(storage); } super_former } } -#[ allow( non_camel_case_types ) ] -pub struct Struct1FormerAssignHashset1End; +#[doc = +"Callback to return original former after forming of container for `$Struct1` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] +pub struct Struct1FormerAssignHashset1End +{ + _phantom : core::marker::PhantomData<(Definition,)>, +} + +impl Default for Struct1FormerAssignHashset1End +{ + #[inline(always)] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} -#[ automatically_derived ] -impl< Definition, > former::FormingEnd -< - former::HashSetDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd >, -> -for Struct1FormerAssignHashset1End +#[automatically_derived] +impl former::FormingEnd< former::HashSetDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignHashset1End where Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { - #[ inline( always ) ] - fn call( &self, storage : std::collections::HashSet< String >, super_former : Option< Struct1Former< Definition, > >, ) -> Struct1Former< Definition, > + #[inline(always)] + fn call(&self, storage: std::collections::HashSet, super_former: Option>,) -> Struct1Former { let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.hashset_1 + if let Some(ref mut field) = super_former.storage.hashset_1 { - former::ContainerAssign::assign( field, storage ); + former::ContainerAssign::assign(field, storage); } else { - super_former.storage.hashset_1 = Some( storage ); + super_former.storage.hashset_1 = Some(storage); } super_former } diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index e6ac891448..78ac8522c3 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -122,15 +122,15 @@ tests_impls! { // Container subformers are defined - let _got = Struct1FormerAssignVec1End; - let _got = Struct1FormerAssignHashmap1End; - let _got = Struct1FormerAssignHashset1End; + let _got = Struct1FormerAssignVec1End::< Struct1FormerDefinition >::default(); + let _got = Struct1FormerAssignHashmap1End::< Struct1FormerDefinition >::default(); + let _got = Struct1FormerAssignHashset1End::< Struct1FormerDefinition >::default(); - // SubformerEnd is defined - fn _f1< End : Struct1SubformerEnd< Struct1Former > > + // AsSubformerEnd is defined + fn _f1< End : Struct1AsSubformerEnd< Struct1Former > > ( _end : End, - _subformer : Struct1Subformer< Struct1Former, impl Struct1SubformerEnd< Struct1Former > > + _subformer : Struct1AsSubformer< Struct1Former, impl Struct1AsSubformerEnd< Struct1Former > > ) { } diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs index 58bd50f517..e62dd67566 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs @@ -6,9 +6,6 @@ fn child() let got = Parent::former() .child( "a" ).end() .child( "b" ).end() - // .add( Child::former().name( "a" ).form() ) - // .add( Child::former().name( "b" ).form() ) - // .end() .form(); let children = vec! diff --git a/module/core/former/tests/inc/former_tests/subformer_custom.rs b/module/core/former/tests/inc/former_tests/subformer_custom.rs index 49b8ab0a5e..5bf0331956 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom.rs @@ -14,7 +14,7 @@ where // // = command subformer - generated // -// pub type CommandSubformer< K, Superformer, End > = CommandFormer +// pub type CommandAsSubformer< K, Superformer, End > = CommandFormer // < // K, // CommandFormerDefinition @@ -29,7 +29,7 @@ where // // // = command subformer end - generated // -// pub trait CommandSubformerEnd< K, SuperFormer > +// pub trait CommandAsSubformerEnd< K, SuperFormer > // where // K : core::hash::Hash + std::cmp::Eq, // Self : the_module::FormingEnd @@ -39,7 +39,7 @@ where // { // } // -// impl< K, SuperFormer, T > CommandSubformerEnd< K, SuperFormer > +// impl< K, SuperFormer, T > CommandAsSubformerEnd< K, SuperFormer > // for T // where // K : core::hash::Hash + std::cmp::Eq, @@ -81,7 +81,7 @@ where #[ inline( always ) ] pub fn command_with_closure< IntoName >( self, name : IntoName ) -> - CommandSubformer< K, Self, impl CommandSubformerEnd< K, Self > > + CommandAsSubformer< K, Self, impl CommandAsSubformerEnd< K, Self > > where IntoName : core::convert::Into< String >, { @@ -115,7 +115,7 @@ where #[ inline( always ) ] pub fn command_with_type< IntoName >( self, name : IntoName ) -> - CommandSubformer< K, Self, impl CommandSubformerEnd< K, Self > > + CommandAsSubformer< K, Self, impl CommandAsSubformerEnd< K, Self > > where IntoName : core::convert::Into< String >, { diff --git a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs index 0d54af871f..4d22cbf714 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs @@ -42,7 +42,7 @@ where #[ inline( always ) ] pub fn command_with_helper< IntoName >( self, name : IntoName ) -> - CommandSubformer< K, Self, impl CommandSubformerEnd< K, Self > > + CommandAsSubformer< K, Self, impl CommandAsSubformerEnd< K, Self > > where IntoName : core::convert::Into< String >, ContainerAddElement @@ -52,7 +52,7 @@ where Command< K > > : - CommandSubformerEnd< K, Self >, + CommandAsSubformerEnd< K, Self >, { let former = CommandFormer::begin_precise diff --git a/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs new file mode 100644 index 0000000000..df0d6dac08 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs @@ -0,0 +1,29 @@ +#![ allow( dead_code ) ] + +use super::*; + +/// Parameter description. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent required for the template. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + #[ container( former::VectorDefinition ) ] + #[ subform( name : child ) ] + // #[ setter( false ) ] + children : Vec< Child >, +} + +// + +// xxx +// include!( "./only_test/subformer_subform.rs" ); +include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs similarity index 98% rename from module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs rename to module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs index 55d8004e18..3a5f2e592a 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_implicit_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs @@ -2,7 +2,6 @@ use super::*; -// xxx : rename /// Parameter description. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] pub struct Child @@ -95,7 +94,7 @@ where #[ inline( always ) ] pub fn child( self, name : &str ) -> - ChildSubformer< Self, impl ChildSubformerEnd< Self > > + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { self._children_element_subformer ::< ChildFormer< _ >, _, >() diff --git a/module/core/former/tests/inc/former_tests/subformer_subform.rs b/module/core/former/tests/inc/former_tests/subformer_subform.rs index fe3ec1ffe9..a3325cbae2 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform.rs @@ -28,7 +28,7 @@ where { #[ inline( always ) ] - pub fn child( self, name : &str ) -> ChildSubformer< Self, impl ChildSubformerEnd< Self > > + pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { self._children_element_subformer::< ChildFormer< _ >, _, >() .name( name ) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 40409c8542..7295556e41 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -112,7 +112,7 @@ where #[ inline( always ) ] pub fn child( self, name : &str ) -> - ChildSubformer< Self, impl ChildSubformerEnd< Self > > + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { self._children_element_subformer ::< ChildFormer< _ >, _, >() diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index cb00c05876..2c7fd9548a 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -26,8 +26,6 @@ mod former_tests mod a_containers_with_subformer_manual; #[ cfg( not( feature = "no_std" ) ) ] mod a_containers_with_subformer; - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer_implicit; mod attribute_default_container; mod attribute_default_primitive; @@ -70,10 +68,9 @@ mod former_tests mod subformer_subform_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_implicit_container; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_subform_implicit_container_manutal; - // xxx + mod subformer_implicit_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_implicit_container_manual; } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 37b7c56249..9b2bf54339 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -93,12 +93,15 @@ impl Attributes { match attr.meta { + syn::Meta::List( ref meta_list ) => + { + subform.replace( syn::parse2::< AttributeSubform >( meta_list.tokens.clone() )? ); + }, syn::Meta::Path( ref _path ) => { - // code_print!( _path ); subform.replace( syn::parse2::< AttributeSubform >( Default::default() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ subform ], but got:\n {}", qt!{ #attr } ), + _ => return_syn_err!( attr, "Expects an attribute of format #[ subform ] or #[ subform( name : child ) ], but got:\n {}", qt!{ #attr } ), } } "alias" => @@ -238,21 +241,79 @@ impl syn::parse::Parse for AttributeContainer } } -/// zzz : write description with example -#[ allow( dead_code ) ] +// /// zzz : write description with example +// #[ allow( dead_code ) ] +// struct AttributeSubform +// { +// // name : Option< syn::Ident >, +// // public : bolean, +// } +// +// impl syn::parse::Parse for AttributeSubform +// { +// fn parse( _input : syn::parse::ParseStream< '_ > ) -> Result< Self > +// { +// Ok( Self +// { +// // expr : input.parse()?, +// }) +// } +// } + struct AttributeSubform { - // expr : syn::Type, + name : Option< syn::Ident >, + public : bool, } impl syn::parse::Parse for AttributeSubform { - fn parse( _input : syn::parse::ParseStream< '_ > ) -> Result< Self > + fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > { - Ok( Self + let mut name : Option< syn::Ident > = None; + let mut public : bool = true; + + while !input.is_empty() { - // expr : input.parse()?, - }) + let lookahead = input.lookahead1(); + if lookahead.peek( syn::Ident ) + { + let ident : syn::Ident = input.parse()?; + if ident == "name" + { + input.parse::< syn::Token![:] >()?; // Expecting a colon + name = Some( input.parse()? ); // Parse the identifier + } + else if ident == "public" + { + input.parse::< syn::Token![:] >()?; // Expecting a colon + // Parse the boolean by checking next Ident if it's "true" or "false" + let value : syn::Ident = input.parse()?; + match value.to_string().as_str() + { + "true" => public = true, + "false" => public = false, + _ => return Err( syn::Error::new( value.span(), "expected `true` or `false`" ) ), + } + } + else + { + return Err( lookahead.error() ); + } + } + else + { + return Err( lookahead.error() ); + } + + // Optional comma handling + if input.peek( syn::Token![,] ) + { + input.parse::< syn::Token![,] >()?; + } + } + + Ok( Self { name, public } ) } } @@ -772,7 +833,7 @@ fn container_setter #( #params, )* Self, Self, - #former_assign_end, + #former_assign_end< Definition >, > } // former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End, > @@ -781,7 +842,7 @@ fn container_setter { qt! { - < #non_optional_ty as former::EntityToDefinition< Self, Self, #former_assign_end > >::Definition + < #non_optional_ty as former::EntityToDefinition< Self, Self, #former_assign_end< Definition > > >::Definition } // < Vec< String > as former::EntityToDefinition< Self, Self, Struct1FormerAssignVec1End > >::Definition }; @@ -806,7 +867,7 @@ fn container_setter #subformer_definition >, { - Former2::former_begin( None, Some( self ), #former_assign_end ) + Former2::former_begin( None, Some( self ), #former_assign_end::< Definition >::default() ) } }; @@ -995,16 +1056,34 @@ Callback replace content of container assigning new content from subformer's sto let r = qt! { - // zzz : description + // zzz : improve description #[ doc = #former_assign_end_doc ] - pub struct #former_assign_end; + pub struct #former_assign_end< Definition > + { + _phantom : core::marker::PhantomData< ( Definition, ) >, + } + + impl< Definition > Default + for #former_assign_end< Definition > + { + + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + + } #[ automatically_derived ] impl< #former_generics_impl > former::FormingEnd < #subformer_definition, > - for #former_assign_end + for #former_assign_end< Definition > where #former_generics_where { @@ -1287,13 +1366,13 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_definition = syn::Ident::new( &former_definition_name, stru.span() ); let former_definition_types_name = format!( "{}FormerDefinitionTypes", stru ); let former_definition_types = syn::Ident::new( &former_definition_types_name, stru.span() ); - let subformer_name = format!( "{}Subformer", stru ); - let subformer = syn::Ident::new( &subformer_name, stru.span() ); - let subformer_end_name = format!( "{}SubformerEnd", stru ); - let subformer_end = syn::Ident::new( &subformer_end_name, stru.span() ); + let as_subformer_name = format!( "{}AsSubformer", stru ); + let as_subformer = syn::Ident::new( &as_subformer_name, stru.span() ); + let as_subformer_end_name = format!( "{}AsSubformerEnd", stru ); + let as_subformer_end = syn::Ident::new( &as_subformer_end_name, stru.span() ); // zzz : improve - let subformer_end_doc = format!( "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure." ); + let as_subformer_end_doc = format!( "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure." ); /* parameters for structure */ @@ -1842,7 +1921,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // zzz : improve description /// Use as subformer of a field during process of forming of super structure. - pub type #subformer < #struct_generics_ty __Superformer, __End > = #former + pub type #as_subformer < #struct_generics_ty __Superformer, __End > = #former < #struct_generics_ty #former_definition @@ -1855,11 +1934,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > >, >; - // = subformer end + // = as subformer end // zzz : imporove documentation - #[ doc = #subformer_end_doc ] - pub trait #subformer_end < #struct_generics_impl SuperFormer > + #[ doc = #as_subformer_end_doc ] + pub trait #as_subformer_end < #struct_generics_impl SuperFormer > where #struct_generics_where Self : former::FormingEnd @@ -1869,7 +1948,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { } - impl< #struct_generics_impl SuperFormer, T > #subformer_end < #struct_generics_ty SuperFormer > + impl< #struct_generics_impl SuperFormer, T > #as_subformer_end < #struct_generics_ty SuperFormer > for T where #struct_generics_where From 2a85e337f77d82452eafefdd2e8d53561a0709c6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 12:38:30 +0300 Subject: [PATCH 313/533] former : experimenting --- .../former/tests/inc/former_tests/a_basic.rs | 2 +- .../a_containers_with_subformer_manual.rs | 9 +- .../a_containers_without_subformer.rs | 2 +- .../tests/inc/former_tests/a_primitives.rs | 2 +- .../inc/former_tests/name_collision_end.rs | 2 +- .../subformer_implicit_container.rs | 315 +++++++++++++++++- .../subformer_implicit_container_manual.rs | 34 +- .../inc/former_tests/subformer_subform.rs | 2 +- .../former_tests/subformer_subform_manual.rs | 6 +- module/core/former_meta/src/derive/former.rs | 201 +++++++---- 10 files changed, 478 insertions(+), 97 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic.rs b/module/core/former/tests/inc/former_tests/a_basic.rs index 331f2da430..8bbe8dd77f 100644 --- a/module/core/former/tests/inc/former_tests/a_basic.rs +++ b/module/core/former/tests/inc/former_tests/a_basic.rs @@ -11,6 +11,6 @@ pub struct Struct1 // = begin_coercing of generated -// = end of generated +// == end of generated include!( "./only_test/basic.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 2a4e07e94a..db4c84006c 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -27,7 +27,8 @@ where } } -impl< Definition > former::EntityToFormer< Definition > for Struct1< > +impl< Definition > former::EntityToFormer< Definition > +for Struct1< > where Definition : former::FormerDefinition< Storage = Struct1FormerStorage<> >, { @@ -444,14 +445,12 @@ where } } -#[doc = -r" Use as subformer of a field during process of forming of super structure."] +#[ allow( dead_code ) ] pub type Struct1AsSubformer = Struct1Former< Struct1FormerDefinition, >; -#[doc = -"Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] +#[ allow( dead_code ) ] pub trait Struct1AsSubformerEnd where Self : former::FormingEnd< Struct1FormerDefinitionTypes, > {} diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs index 8494ec17ce..b87ae9a9e1 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs @@ -16,6 +16,6 @@ pub struct Struct1 // = begin_coercing of generated -// = end of generated +// == end of generated include!( "./only_test/containers_without_subformer.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_primitives.rs b/module/core/former/tests/inc/former_tests/a_primitives.rs index bf53367676..446b7c98d8 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives.rs @@ -14,6 +14,6 @@ pub struct Struct1 // = begin_coercing of generated -// = end of generated +// == end of generated include!( "./only_test/primitives.rs" ); diff --git a/module/core/former/tests/inc/former_tests/name_collision_end.rs b/module/core/former/tests/inc/former_tests/name_collision_end.rs index d53541675f..99f736019d 100644 --- a/module/core/former/tests/inc/former_tests/name_collision_end.rs +++ b/module/core/former/tests/inc/former_tests/name_collision_end.rs @@ -18,4 +18,4 @@ pub struct End // = begin_coercing of generated -// = end of generated \ No newline at end of file +// == end of generated \ No newline at end of file diff --git a/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs index df0d6dac08..bd63db1041 100644 --- a/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs @@ -16,14 +16,325 @@ pub struct Child // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { + #[ subform ] + // #[ subform( name = child ) ] #[ container( former::VectorDefinition ) ] - #[ subform( name : child ) ] // #[ setter( false ) ] children : Vec< Child >, } +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn child( self, name : &str ) -> + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._children_add_subformer + ::< ChildFormer< _ >, _, >() + .name( name ) + } + +} + +// == begin of generated + +// #[automatically_derived] impl < > Parent < > where +// { +// #[doc = r""] +// #[doc = +// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] +// #[doc = r""] #[inline(always)] pub fn former() -> ParentFormer < +// ParentFormerDefinition < (), Parent < > , former :: ReturnPreformed > > +// { +// ParentFormer :: < ParentFormerDefinition < (), Parent < > , former :: +// ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) +// } +// } impl < Definition > former :: EntityToFormer < Definition > for Parent < > +// where Definition : former :: FormerDefinition < Storage = ParentFormerStorage +// < > > , { type Former = ParentFormer < Definition > ; } impl < > former :: +// EntityToStorage for Parent < > where +// { type Storage = ParentFormerStorage < > ; } #[derive(Debug)] pub struct +// ParentFormerDefinitionTypes < __Context = (), __Formed = Parent < > , > where +// { _phantom : core :: marker :: PhantomData < (__Context, __Formed) > , } impl +// < __Context, __Formed, > :: core :: default :: Default for +// ParentFormerDefinitionTypes < __Context, __Formed, > where +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < __Context, __Formed, > former :: FormerDefinitionTypes for +// ParentFormerDefinitionTypes < __Context, __Formed, > where +// { +// type Storage = ParentFormerStorage < > ; type Formed = __Formed; type +// Context = __Context; +// } #[derive(Debug)] pub struct ParentFormerDefinition < __Context = (), +// __Formed = Parent < > , __End = former :: ReturnPreformed, > where +// { +// _phantom : core :: marker :: PhantomData < (__Context, __Formed, __End) > +// , +// } impl < __Context, __Formed, __End, > :: core :: default :: Default for +// ParentFormerDefinition < __Context, __Formed, __End, > where +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < __Context, __Formed, __End, > former :: FormerDefinition for +// ParentFormerDefinition < __Context, __Formed, __End, > where __End : former :: +// FormingEnd < ParentFormerDefinitionTypes < __Context, __Formed, > > , +// { +// type Types = ParentFormerDefinitionTypes < __Context, __Formed, > ; type +// End = __End; type Storage = ParentFormerStorage < > ; type Formed = +// __Formed; type Context = __Context; +// } #[doc = "Container of a corresponding former."] pub struct +// ParentFormerStorage < > where +// { +// #[doc = r" A field"] pub children : :: core :: option :: Option < Vec < +// Child > > , +// } impl < > :: core :: default :: Default for ParentFormerStorage < > where +// { +// #[inline(always)] fn default() -> Self +// { Self { children : :: core :: option :: Option :: None, } } +// } impl < > former :: Storage for ParentFormerStorage < > where +// { type Formed = Parent < > ; } impl < > former :: StoragePreform for +// ParentFormerStorage < > where +// { +// type Preformed = Parent < > ; fn preform(mut self) -> Self :: Preformed +// { +// let children = if self.children.is_some() +// { self.children.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'children' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < Vec < Child > +// >).maybe_default() +// } +// }; let result = Parent :: < > { children, }; return result; +// } +// } +// #[doc = +// " Object to form [Parent]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +// pub struct ParentFormer < Definition = ParentFormerDefinition < (), Parent < > +// , former :: ReturnPreformed > , > where Definition : former :: +// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = ParentFormerStorage < > > , +// { +// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: +// Storage, context : core :: option :: Option < < Definition :: Types as +// former :: FormerDefinitionTypes > :: Context > , on_end : core :: option +// :: Option < Definition :: End > , +// } #[automatically_derived] impl < Definition, > ParentFormer < Definition, > +// where Definition : former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = ParentFormerStorage < > > , +// { +// #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn +// new_precise(on_end : Definition :: End) -> Self +// { Self :: begin_coercing(None, None, on_end) } #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > +// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , +// { Self :: begin_coercing(None, None, end,) } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn +// begin_precise(mut storage : core :: option :: Option < < Definition :: +// Types as former :: FormerDefinitionTypes > :: Storage > , context : core +// :: option :: Option < < Definition :: Types as former :: +// FormerDefinitionTypes > :: Context > , on_end : < Definition as former :: +// FormerDefinition > :: End,) -> Self +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: Some(on_end), +// } +// } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > +// (mut storage : core :: option :: Option < < Definition :: Types as former +// :: FormerDefinitionTypes > :: Storage > , context : core :: option :: +// Option < < Definition :: Types as former :: FormerDefinitionTypes > :: +// Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert +// :: Into < < Definition as former :: FormerDefinition > :: End > , +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: +// Some(:: core :: convert :: Into :: into(on_end)), +// } +// } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types +// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { +// let on_end = self.on_end.take().unwrap(); let context = +// self.context.take(); former :: FormingEnd :: < Definition :: Types > +// :: call(& on_end, self.storage, context) +// } +// #[doc = +// "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer."] +// #[inline(always)] pub fn _children_assign < Former2 > (self) -> Former2 +// where Former2 : former :: FormerBegin < former :: VectorDefinition < +// Child, Self, Self, ParentFormerAssignChildrenEnd < Definition > , > > , +// { +// Former2 :: +// former_begin(None, Some(self), ParentFormerAssignChildrenEnd :: < +// Definition > :: default()) +// } +// #[doc = +// "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer."] +// #[inline(always)] pub fn children(self) -> former :: ContainerSubformer :: +// < Child, former :: VectorDefinition < Child, Self, Self, +// ParentFormerAssignChildrenEnd < Definition > , > > +// { +// self._children_assign :: < former :: ContainerSubformer :: < Child, +// former :: VectorDefinition < Child, Self, Self, +// ParentFormerAssignChildrenEnd < Definition > , > >> () +// } #[doc = r" Custom setter which produce container element subformer."] +// #[inline(always)] pub fn _children_add_subformer < Former2, Definition2 > +// (self) -> Former2 where Definition2 : former :: FormerDefinition < End = +// ParentFormerAddChildrenEnd < Definition > , Storage = < Child as former :: +// EntityToStorage > :: Storage, Formed = Self, Context = Self, > , +// Definition2 :: Types : former :: FormerDefinitionTypes < Storage = < Child +// as former :: EntityToStorage > :: Storage, Formed = Self, Context = Self, +// > , Former2 : former :: FormerBegin < Definition2 > , +// { +// Former2 :: +// former_begin(None, Some(self), ParentFormerAddChildrenEnd :: +// default()) +// } // +// #[inline(always)] +// pub fn child(self) -> ParentAsSubformer < Self, impl ParentAsSubformerEnd < Self > > +// { +// self._children_add_subformer :: < < Vec < Child > as former :: +// EntityToFormer < _ > > :: Former, _, > () +// } +// } +// +// impl < Definition, > ParentFormer < Definition, > where Definition :: Types +// : former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > , Formed +// = Parent < > > , Definition : former :: FormerDefinition, Definition :: Types +// : former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , +// { +// pub fn preform(self) -> < Definition :: Types as former :: +// FormerDefinitionTypes > :: Formed +// { former :: StoragePreform :: preform(self.storage) } +// } #[automatically_derived] impl < Definition, > ParentFormer < Definition, > +// where Definition : former :: FormerDefinition, Definition :: Types : former :: +// FormerDefinitionTypes < Storage = ParentFormerStorage < > , Formed = Parent < +// > > , +// { +// #[doc = r""] +// #[doc = r" Finish setting options and call perform on formed entity."] +// #[doc = r""] +// #[doc = +// r" If `perform` defined then associated method is called and its result returned instead of entity."] +// #[doc = +// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] +// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { let result = self.form(); return result; } +// } impl < Definition > former :: FormerBegin < Definition > for ParentFormer < +// Definition, > where Definition : former :: FormerDefinition < Storage = +// ParentFormerStorage < > > , +// { +// #[inline(always)] fn +// former_begin(storage : core :: option :: Option < Definition :: Storage > +// , context : core :: option :: Option < Definition :: Context > , on_end : +// Definition :: End,) -> Self +// { +// debug_assert! (storage.is_none()); Self :: +// begin_precise(None, context, on_end) +// } +// } +// #[doc = +// r" Use as subformer of a field during process of forming of super structure."] +// pub type ParentAsSubformer < __Superformer, __End > = ParentFormer < +// ParentFormerDefinition < __Superformer, __Superformer, __End, > , > ; +// #[doc = +// "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] +// pub trait ParentAsSubformerEnd < SuperFormer > where Self : former :: +// FormingEnd < ParentFormerDefinitionTypes < SuperFormer, SuperFormer > , > , {} +// impl < SuperFormer, T > ParentAsSubformerEnd < SuperFormer > for T where Self +// : former :: FormingEnd < ParentFormerDefinitionTypes < SuperFormer, +// SuperFormer > , > , {} +// #[doc = +// "Callback to return original former after forming of container for `$Parent` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] +// pub struct ParentFormerAssignChildrenEnd < Definition > +// { _phantom : core :: marker :: PhantomData < (Definition,) > , } impl < +// Definition > Default for ParentFormerAssignChildrenEnd < Definition > +// { +// #[inline(always)] fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } #[automatically_derived] impl < Definition, > former :: FormingEnd < former +// :: VectorDefinition < Child, ParentFormer < Definition, > , ParentFormer < +// Definition, > , former :: NoEnd > , > for ParentFormerAssignChildrenEnd < +// Definition > where Definition : former :: FormerDefinition, Definition :: +// Types : former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > +// , +// { +// #[inline(always)] fn +// call(& self, storage : Vec < Child > , super_former : Option < +// ParentFormer < Definition, > > ,) -> ParentFormer < Definition, > +// { +// let mut super_former = super_former.unwrap(); if let +// Some(ref mut field) = super_former.storage.children +// { former :: ContainerAssign :: assign(field, storage); } else +// { super_former.storage.children = Some(storage); } super_former +// } +// } #[doc = r" Handles the completion of an element of subformer's container."] +// pub struct ParentFormerAddChildrenEnd < Definition > +// { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < +// Definition > Default for ParentFormerAddChildrenEnd < Definition > +// { +// #[inline(always)] fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < Types2, Definition > former :: FormingEnd < Types2, > for +// ParentFormerAddChildrenEnd < Definition > where Definition : former :: +// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = < Parent < > as former :: EntityToStorage > :: Storage, > , Types2 : +// former :: FormerDefinitionTypes < Storage = < < Vec < Child > as former :: +// ContainerAdd > :: Element as former :: EntityToStorage > :: Storage, Formed = +// ParentFormer < Definition, > , Context = ParentFormer < Definition, > , > , +// { +// #[inline(always)] fn +// call(& self, substorage : Types2 :: Storage, super_former : core :: option +// :: Option < Types2 :: Context > ,) -> Types2 :: Formed +// { +// let mut super_former = super_former.unwrap(); if +// super_former.storage.children.is_none() +// { super_former.storage.children = Some(Default :: default()); } if let +// Some(ref mut field) = super_former.storage.children +// { +// former :: ContainerAdd :: +// add(field, former :: StoragePreform :: preform(substorage)); +// } super_former +// } +// } + +// == end of generated // xxx -// include!( "./only_test/subformer_subform.rs" ); +include!( "./only_test/subformer_subform.rs" ); include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs index 3a5f2e592a..ee39ac235e 100644 --- a/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs @@ -22,7 +22,7 @@ pub struct Parent children : Vec< Child >, } -// = begin of generated for Parent in context of attribute subform +// == begin of generated for Parent in context of attribute subform impl< Definition > ParentFormer< Definition > where @@ -31,7 +31,7 @@ where { #[ inline( always ) ] - pub fn _children_element_subformer_with_closure< Former2, Definition2, Types2 >( self ) -> + pub fn _children_add_subformer_with_closure< Former2, Definition2, Types2 >( self ) -> Former2 where Types2 : former::FormerDefinitionTypes @@ -71,7 +71,7 @@ where } #[ inline( always ) ] - pub fn _children_element_subformer< Former2, Definition2 >( self ) -> + pub fn _children_add_subformer< Former2, Definition2 >( self ) -> Former2 where Definition2 : former::FormerDefinition @@ -92,12 +92,30 @@ where Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) } + // #[ inline( always ) ] + // pub fn child( self, name : &str ) -> + // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + // { + // self._children_add_subformer + // ::< ChildFormer< _ >, _, >() + // .name( name ) + // } + + // #[ inline( always ) ] + // pub fn child( self, name : &str ) -> + // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + // { + // self._children_add_subformer + // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + // .name( name ) + // } + #[ inline( always ) ] pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { - self._children_element_subformer - ::< ChildFormer< _ >, _, >() + self._children_add_subformer + ::< < Child as former::EntityToFormer< _ > >::Former, _, >() .name( name ) } @@ -159,9 +177,9 @@ where } } -// = end of generated for Parent in context of attribute subform +// == end of generated for Parent in context of attribute subform -// = begin of generated for Parent in context of attribute container( former::VectorDefinition ) ] +// == begin of generated for Parent in context of attribute container( former::VectorDefinition ) ] #[ automatically_derived ] impl< Definition, > ParentFormer< Definition, > @@ -242,7 +260,7 @@ where } } -// = end of generated for Parent in context of attribute container( former::VectorDefinition ) ] +// == end of generated for Parent in context of attribute container( former::VectorDefinition ) ] include!( "./only_test/subformer_subform.rs" ); include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform.rs b/module/core/former/tests/inc/former_tests/subformer_subform.rs index a3325cbae2..bca588df3a 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform.rs @@ -30,7 +30,7 @@ where #[ inline( always ) ] pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { - self._children_element_subformer::< ChildFormer< _ >, _, >() + self._children_add_subformer::< ChildFormer< _ >, _, >() .name( name ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 7295556e41..6983cb98c9 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -49,7 +49,7 @@ where { #[ inline( always ) ] - pub fn _children_element_subformer_with_closure< Former2, Definition2, Types2 >( self ) -> + pub fn _children_add_subformer_with_closure< Former2, Definition2, Types2 >( self ) -> Former2 where Types2 : former::FormerDefinitionTypes @@ -89,7 +89,7 @@ where } #[ inline( always ) ] - pub fn _children_element_subformer< Former2, Definition2 >( self ) -> + pub fn _children_add_subformer< Former2, Definition2 >( self ) -> Former2 where Definition2 : former::FormerDefinition @@ -114,7 +114,7 @@ where pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { - self._children_element_subformer + self._children_add_subformer ::< ChildFormer< _ >, _, >() .name( name ) } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 9b2bf54339..d530e48d5c 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -241,28 +241,28 @@ impl syn::parse::Parse for AttributeContainer } } -// /// zzz : write description with example -// #[ allow( dead_code ) ] -// struct AttributeSubform -// { -// // name : Option< syn::Ident >, -// // public : bolean, -// } -// -// impl syn::parse::Parse for AttributeSubform -// { -// fn parse( _input : syn::parse::ParseStream< '_ > ) -> Result< Self > -// { -// Ok( Self -// { -// // expr : input.parse()?, -// }) -// } -// } +/// Represents a subform attribute with optional name flag. +/// Used to specify extra options for using one former as subformer of another one. +/// For example name of setter could be customized. +/// +/// ## Example Input +/// +/// A typical input to parse might look like the following: +/// ``` +/// name = field_name, public = true +/// ``` +/// or simply: +/// ``` +/// mame = field_name +/// ``` struct AttributeSubform { + /// - `name` : An optional identifier that names the subform. It is parsed from inputs + /// like `name = my_field`. name : Option< syn::Ident >, + /// - `pubc` : An option for debug purpose. + #[ allow( dead_code ) ] public : bool, } @@ -281,12 +281,12 @@ impl syn::parse::Parse for AttributeSubform let ident : syn::Ident = input.parse()?; if ident == "name" { - input.parse::< syn::Token![:] >()?; // Expecting a colon - name = Some( input.parse()? ); // Parse the identifier + input.parse::< syn::Token![ = ] >()?; + name = Some( input.parse()? ); } else if ident == "public" { - input.parse::< syn::Token![:] >()?; // Expecting a colon + input.parse::< syn::Token![ = ] >()?; // Parse the boolean by checking next Ident if it's "true" or "false" let value : syn::Ident = input.parse()?; match value.to_string().as_str() @@ -613,7 +613,14 @@ fn field_name_map( field : &FormerField< '_ > ) -> syn::Ident /// ``` #[ inline ] -fn field_setter_map( field : &FormerField< '_ >, stru : &syn::Ident ) -> Result< TokenStream > +fn field_setter_map +( + field : &FormerField< '_ >, + stru : &syn::Ident, + as_subformer : &syn::Ident, + as_subformer_end : &syn::Ident, +) +-> Result< TokenStream > { let ident = &field.ident; @@ -652,7 +659,7 @@ fn field_setter_map( field : &FormerField< '_ >, stru : &syn::Ident ) -> Result< let r = if field.attrs.subform.is_some() { - let subformer = field_subformer_map( field, stru )?; + let subformer = field_subformer_map( field, stru, as_subformer, as_subformer_end )?; qt! { #r @@ -674,8 +681,11 @@ fn field_setter_map( field : &FormerField< '_ >, stru : &syn::Ident ) -> Result< fn field_subformer_map ( field : &FormerField< '_ >, - stru : &syn::Ident -) -> Result< TokenStream > + stru : &syn::Ident, + as_subformer : &syn::Ident, + as_subformer_end : &syn::Ident, +) +-> Result< TokenStream > { if field.attrs.subform.is_none() @@ -685,15 +695,27 @@ fn field_subformer_map use convert_case::{ Case, Casing }; let field_ident = field.ident; - // let field_ty = field.non_optional_ty; + let field_ty = field.non_optional_ty; // let params = typ::type_parameters( &field.non_optional_ty, .. ); + // example : `child` + let mut explicit_name = false; + let setter_name = if let Some( ref _name ) = field.attrs.subform.as_ref().unwrap().name + { + explicit_name = true; + _name + } + else + { + field_ident + }; + // example : `ParentFormerAddChildrenEnd`` let parent_add_element_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); // example : `_children_former` - let element_subformer_name = format!( "_{}_element_subformer", field_ident ); + let element_subformer_name = format!( "_{}_add_subformer", field_ident ); let element_subformer = syn::Ident::new( &element_subformer_name, field_ident.span() ); let r = qt! @@ -724,56 +746,39 @@ fn field_subformer_map }; - // tree_print!( r.as_ref().unwrap() ); - Ok( r ) -} - -/// -/// Generate a single setter for the 'field_ident' with the 'setter_name' name. -/// -/// Used as a helper function for field_setter_map(), which generates alias setters -/// -/// # Example of generated code -/// ```ignore -/// #[ doc = "Setter for the 'int_1' field." ] -/// #[ inline ] -/// pub fn int_1< Src >( mut self, src : Src ) -> Self -/// where -/// Src : ::core::convert::Into< i32 >, -/// { -/// debug_assert!( self.int_1.is_none() ); -/// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); -/// self -/// } -/// ``` - -#[ inline ] -fn field_setter -( - field_ident : &syn::Ident, - setter_name : &syn::Ident, - non_optional_type : &syn::Type, -) --> TokenStream -{ - let doc = format! - ( - "Setter for the '{}' field.", - field_ident, - ); - - qt! + // xxx : it should be printed by hint also + let r = if explicit_name { - #[ doc = #doc ] - #[ inline ] - pub fn #setter_name< Src >( mut self, src : Src ) -> Self - where Src : ::core::convert::Into< #non_optional_type >, + qt! { - debug_assert!( self.storage.#field_ident.is_none() ); - self.storage.#field_ident = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); - self + #r + + #[ inline( always ) ] + pub fn #setter_name( self ) -> + #as_subformer< Self, impl #as_subformer_end< Self > > + { + self.#element_subformer + ::< < #field_ty as former::EntityToFormer< _ > >::Former, _, >() + // ::< #former< _ >, _, >() + } } + + // #[ inline( always ) ] + // pub fn child( self ) -> + // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + // { + // self._children_add_subformer + // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + // } + } + else + { + r + }; + + // tree_print!( r.as_ref().unwrap() ); + Ok( r ) } /// @@ -951,6 +956,54 @@ fn container_setter } +/// +/// Generate a single setter for the 'field_ident' with the 'setter_name' name. +/// +/// Used as a helper function for field_setter_map(), which generates alias setters +/// +/// # Example of generated code +/// ```ignore +/// #[ doc = "Setter for the 'int_1' field." ] +/// #[ inline ] +/// pub fn int_1< Src >( mut self, src : Src ) -> Self +/// where +/// Src : ::core::convert::Into< i32 >, +/// { +/// debug_assert!( self.int_1.is_none() ); +/// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); +/// self +/// } +/// ``` + +#[ inline ] +fn field_setter +( + field_ident : &syn::Ident, + setter_name : &syn::Ident, + non_optional_type : &syn::Type, +) +-> TokenStream +{ + let doc = format! + ( + "Setter for the '{}' field.", + field_ident, + ); + + qt! + { + #[ doc = #doc ] + #[ inline ] + pub fn #setter_name< Src >( mut self, src : Src ) -> Self + where Src : ::core::convert::Into< #non_optional_type >, + { + debug_assert!( self.storage.#field_ident.is_none() ); + self.storage.#field_ident = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + self + } + } +} + // zzz : description and exmaple /// Generate unit struct which is descriptor of callback which should be called after subforming process of a specific field. Childs are used insted of closures to inline code and let optimizer play with optimization. /// @@ -1504,7 +1557,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field_optional_map( former_field ), field_form_map( former_field ), field_name_map( former_field ), - field_setter_map( former_field, &stru ), + field_setter_map( former_field, &stru, &as_subformer, &as_subformer_end ), field_former_assign_map ( former_field, From 71636466fdbd1360d4d898332190cd7e46bd6e53 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 14:45:51 +0300 Subject: [PATCH 314/533] former : experimenting --- .../a_containers_with_subformer_manual.rs | 5 ++- .../subformer_implicit_container_manual.rs | 38 +++++++++---------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index db4c84006c..7eab803186 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -446,8 +446,9 @@ where } #[ allow( dead_code ) ] -pub type Struct1AsSubformer = Struct1Former< - Struct1FormerDefinition, +pub type Struct1AsSubformer< Superformer, End > = Struct1Former +< + Struct1FormerDefinition< Superformer, Superformer, End, >, >; #[ allow( dead_code ) ] diff --git a/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs index ee39ac235e..da5aec5735 100644 --- a/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs @@ -92,33 +92,33 @@ where Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) } - // #[ inline( always ) ] - // pub fn child( self, name : &str ) -> - // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - // { - // self._children_add_subformer - // ::< ChildFormer< _ >, _, >() - // .name( name ) - // } - - // #[ inline( always ) ] - // pub fn child( self, name : &str ) -> - // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - // { - // self._children_add_subformer - // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() - // .name( name ) - // } - #[ inline( always ) ] pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { self._children_add_subformer - ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + ::< ChildFormer< _ >, _, >() .name( name ) } + #[ inline( always ) ] + pub fn _child( self ) -> + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._children_add_subformer + ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + } + + // #[ inline( always ) ] + // pub fn _child( self ) -> + // < Child as former::EntityToFormer< ChildFormerDefinition< Self, Self, impl ChildAsSubformerEnd< Self > > > >::Former + // // ChildFormer< ChildFormerDefinition< Self, Self, impl ChildAsSubformerEnd< Self > > > + // // ChildFormer< ChildFormerDefinition< Self, Self, impl ChildAsSubformerEnd< Self > > > + // { + // self._children_add_subformer + // ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() + // } + } /// Handles the completion of and element of subformer's container. From 4d538202fbdaf976152c85dfba208a1d1ce46635 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 15:09:49 +0300 Subject: [PATCH 315/533] former : experimenting --- .../only_test/subformer_subform.rs | 19 +++++++++++++++ .../subformer_implicit_container.rs | 8 +++++++ .../subformer_implicit_container_manual.rs | 24 +++++++++---------- module/core/former/tests/inc/mod.rs | 8 +++---- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs index e62dd67566..1b42589eeb 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs @@ -17,3 +17,22 @@ fn child() a_id!( got, exp ); } + +#[ test ] +fn _child() +{ + + let got = Parent::former() + ._child().name( "a" ).end() + ._child().name( "b" ).end() + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} diff --git a/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs index bd63db1041..7205ba5efe 100644 --- a/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs @@ -38,6 +38,14 @@ where .name( name ) } + #[ inline( always ) ] + pub fn _child( self ) -> + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._children_add_subformer + ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + } + } // == begin of generated diff --git a/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs index da5aec5735..e8549a7c8a 100644 --- a/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs @@ -101,24 +101,24 @@ where .name( name ) } - #[ inline( always ) ] - pub fn _child( self ) -> - ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - { - self._children_add_subformer - ::< < Child as former::EntityToFormer< _ > >::Former, _, >() - } - // #[ inline( always ) ] // pub fn _child( self ) -> - // < Child as former::EntityToFormer< ChildFormerDefinition< Self, Self, impl ChildAsSubformerEnd< Self > > > >::Former - // // ChildFormer< ChildFormerDefinition< Self, Self, impl ChildAsSubformerEnd< Self > > > - // // ChildFormer< ChildFormerDefinition< Self, Self, impl ChildAsSubformerEnd< Self > > > + // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > // { // self._children_add_subformer - // ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() + // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() // } + #[ inline( always ) ] + pub fn _child( self ) -> + < Child as former::EntityToFormer< ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > > >::Former + // ChildFormer< ChildFormerDefinition< Self, Self, impl ChildAsSubformerEnd< Self > > > + // ChildFormer< ChildFormerDefinition< Self, Self, impl ChildAsSubformerEnd< Self > > > + { + self._children_add_subformer + ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() + } + } /// Handles the completion of and element of subformer's container. diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 2c7fd9548a..81e711c0dd 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -62,10 +62,10 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod subformer_custom_experimental; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_manual; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_subform; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_subform_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_implicit_container; From 810a1ded816e10190f33020a1d192e5a1fbd6a2a Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 15:10:53 +0300 Subject: [PATCH 316/533] former : experimenting --- .../former/tests/inc/former_tests/subformer_subform.rs | 8 ++++++++ .../tests/inc/former_tests/subformer_subform_manual.rs | 8 ++++++++ module/core/former/tests/inc/mod.rs | 8 ++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform.rs b/module/core/former/tests/inc/former_tests/subformer_subform.rs index bca588df3a..bdc2d5f5bf 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform.rs @@ -34,6 +34,14 @@ where .name( name ) } + #[ inline( always ) ] + pub fn _child( self ) -> + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._children_add_subformer + ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + } + } // diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 6983cb98c9..45b5e64bfa 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -119,6 +119,14 @@ where .name( name ) } + #[ inline( always ) ] + pub fn _child( self ) -> + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._children_add_subformer + ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + } + } /// Handles the completion of and element of subformer's container. diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 81e711c0dd..2c7fd9548a 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -62,10 +62,10 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod subformer_custom_experimental; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_subform; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_subform_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_implicit_container; From dffbd69b8015ef548b09166890c9c7e1d7398ce4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 16:09:13 +0300 Subject: [PATCH 317/533] former : experimenting --- module/core/former/src/vector.rs | 11 ++++++++--- .../subformer_implicit_container_manual.rs | 18 +++++++++++++++--- module/core/former_meta/src/derive/former.rs | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 908811646b..b6f3d1b252 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -112,11 +112,16 @@ where type Former = VectorSubformer< E, Definition::Context, Definition::Formed, Definition::End >; } -impl< E, Context, Formed, End > EntityToDefinition< Context, Formed, End > +impl< E > crate::EntityToStorage +for Vec< E > +{ + type Storage = Vec< E >; +} + +// xxx : implement for other containers +impl< E, Context, Formed, End > crate::EntityToDefinition< Context, Formed, End > for Vec< E > where - // End : std::ops::Fn< ( Vec< E >, std::option::Option< Context > ), Output = Formed >, - // End : Fn( Vec< E >, std::option::Option< Context > ) -> Formed, End : crate::FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, { type Definition = VectorDefinition< E, Context, Formed, End >; diff --git a/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs index e8549a7c8a..f7bd766834 100644 --- a/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs @@ -10,6 +10,14 @@ pub struct Child is_mandatory : bool, } +// impl< Context, Formed, End > former::EntityToDefinition< Context, Formed, End > +// for Child +// where +// End : former::FormingEnd< ChildFormerDefinitionTypes< Context, Formed > >, +// { +// type Definition = ChildFormerDefinition< Context, Formed, End >; +// } + /// Parent required for the template. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] // #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] @@ -111,9 +119,13 @@ where #[ inline( always ) ] pub fn _child( self ) -> - < Child as former::EntityToFormer< ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > > >::Former - // ChildFormer< ChildFormerDefinition< Self, Self, impl ChildAsSubformerEnd< Self > > > - // ChildFormer< ChildFormerDefinition< Self, Self, impl ChildAsSubformerEnd< Self > > > + < Child as former::EntityToFormer + < + // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, + < Child as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > >::Definition, + // < Vec< Child > as former::EntityToDefinition< ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd > >::Definition + > + >::Former { self._children_add_subformer ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index d530e48d5c..a641708589 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1644,6 +1644,24 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > type Storage = #former_storage < #struct_generics_ty >; } + impl< #struct_generics_impl __Context, __Formed, __End > former::EntityToDefinition< __Context, __Formed, __End > + for #stru < #struct_generics_ty > + where + __End : former::FormingEnd< #former_definition_types < #struct_generics_ty __Context, __Formed > >, + #struct_generics_where + { + type Definition = #former_definition < #struct_generics_ty __Context, __Formed, __End >; + } + + // // xxx : implement for other containers + // impl< E, Context, Formed, End > former::EntityToDefinition< Context, Formed, End > + // for Vec< E > + // where + // End : crate::FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, + // { + // type Definition = VectorDefinition< E, Context, Formed, End >; + // } + // = definition types #[ derive( Debug ) ] From 977f9a6b5b4cc56af3353870f3ac94fae52a4a05 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 16:22:46 +0300 Subject: [PATCH 318/533] former : experimenting --- module/core/former/src/vector.rs | 1 - .../tests/inc/former_tests/a_basic_manual.rs | 8 ++++++++ .../tests/inc/former_tests/only_test/basic.rs | 18 +++++++++++++++++- module/core/former_meta/src/derive/former.rs | 19 ------------------- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index b6f3d1b252..e25cefe89f 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -118,7 +118,6 @@ for Vec< E > type Storage = Vec< E >; } -// xxx : implement for other containers impl< E, Context, Formed, End > crate::EntityToDefinition< Context, Formed, End > for Vec< E > where diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index f485824477..d2475ae738 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -45,6 +45,14 @@ impl former::EntityToStorage for Struct1 type Storage = Struct1FormerStorage; } +impl< Context, Formed, End > former::EntityToDefinition< Context, Formed, End > +for Struct1 +where + End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, +{ + type Definition = Struct1FormerDefinition< Context, Formed, End >; +} + // = definition types #[ derive( Debug ) ] diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index a2d0b8bb22..65487f5558 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -44,7 +44,23 @@ tests_impls! a_id!( got, exp ); let got = < Struct1 as former::EntityToStorage >::Storage::default(); - let exp = < Struct1 as former::EntityToFormer< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > >::Former::new_precise( former::ReturnPreformed ); + let exp = + < + Struct1 as former::EntityToFormer + < + Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > + > + >::Former::new_precise( former::ReturnPreformed ); + a_id!( got.int_1, exp.storage.int_1 ); + + let got = < Struct1 as former::EntityToStorage >::Storage::default(); + let exp = + < + Struct1 as former::EntityToFormer + < + < Struct1 as former::EntityToDefinition< (), Struct1, former::ReturnPreformed > >::Definition + > + >::Former::new_precise( former::ReturnPreformed ); a_id!( got.int_1, exp.storage.int_1 ); } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index a641708589..40df6ef59b 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1617,16 +1617,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = entity to former - // impl< #struct_generics_impl > former::EntityToFormer_ - // for #stru < #struct_generics_ty > - // where - // Self : Sized, - // #struct_generics_where - // { - // type Storage = #former_storage < #struct_generics_ty >; - // type Former = #former < #struct_generics_ty >; - // } - impl< #struct_generics_impl Definition > former::EntityToFormer< Definition > for #stru < #struct_generics_ty > where @@ -1653,15 +1643,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > type Definition = #former_definition < #struct_generics_ty __Context, __Formed, __End >; } - // // xxx : implement for other containers - // impl< E, Context, Formed, End > former::EntityToDefinition< Context, Formed, End > - // for Vec< E > - // where - // End : crate::FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, - // { - // type Definition = VectorDefinition< E, Context, Formed, End >; - // } - // = definition types #[ derive( Debug ) ] From 417d3ff880f5e3d58d2b5b2a4b00d31eaf36b228 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 16:44:05 +0300 Subject: [PATCH 319/533] former : experimenting --- module/core/former/src/container.rs | 55 +++++++++++-------- module/core/former/src/hash_map.rs | 2 +- module/core/former/src/hash_set.rs | 2 +- module/core/former/src/vector.rs | 2 +- .../former_tests/container_former_common.rs | 18 +++--- .../former_tests/container_former_hashmap.rs | 26 +++++++-- .../former_tests/container_former_hashset.rs | 10 ++-- .../inc/former_tests/container_former_vec.rs | 10 ++-- 8 files changed, 74 insertions(+), 51 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 682e326137..a1460c73fd 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -139,30 +139,15 @@ where < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, { - // /// Form current former into target structure. - // #[ inline( always ) ] - // pub fn storage( mut self ) -> < Definition::Types as FormerDefinitionTypes >::Storage - // { - // let storage = if self.storage.is_some() - // { - // self.storage.take().unwrap() - // } - // else - // { - // let val = Default::default(); - // val - // }; - // storage - // } - /// Begins the building process, optionally initializing with a context and storage. #[ inline( always ) ] - pub fn begin_coercing + pub fn begin_precise ( mut storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, on_end : Definition::End, - ) -> Self + ) + -> Self { if storage.is_none() { @@ -176,6 +161,30 @@ where } } + /// zzz : update description + #[ inline( always ) ] + pub fn begin_coercing< IntoEnd > + ( + mut storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, + context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, + on_end : IntoEnd, + ) + -> Self + where + IntoEnd : Into< Definition::End >, + { + if storage.is_none() + { + storage = Some( core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context, + on_end : Some( on_end.into() ), + } + } + /// Finalizes the building process, returning the formed or a context incorporating it. #[ inline( always ) ] pub fn end( mut self ) -> < Definition::Types as FormerDefinitionTypes >::Formed @@ -218,9 +227,9 @@ where /// // zzz : update description #[ inline( always ) ] - pub fn new( end : Definition::End ) -> Self + pub fn new_precise( end : Definition::End ) -> Self { - Self::begin_coercing + Self::begin_precise ( None, None, @@ -230,11 +239,11 @@ where // zzz : update description #[ inline( always ) ] - pub fn new_with< IntoEnd >( end : IntoEnd ) -> Self + pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End >, { - Self::begin_coercing + Self::begin_precise ( None, None, @@ -280,7 +289,7 @@ where ) -> Self { - Self::begin_coercing( storage, context, on_end ) + Self::begin_precise( storage, context, on_end ) } } diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index e484b43490..6ed9713964 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -229,7 +229,7 @@ where { fn former() -> HashMapSubformer< K, E, (), HashMap< K, E >, ReturnStorage > { - HashMapSubformer::< K, E, (), HashMap< K, E >, ReturnStorage >::new( ReturnStorage::default() ) + HashMapSubformer::< K, E, (), HashMap< K, E >, ReturnStorage >::new_precise( ReturnStorage::default() ) } } diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 383cad33be..a4951a7e7b 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -178,7 +178,7 @@ where { fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage > { - HashSetSubformer::< K, (), HashSet< K >, ReturnStorage >::new( ReturnStorage::default() ) + HashSetSubformer::< K, (), HashSet< K >, ReturnStorage >::new_precise( ReturnStorage::default() ) } } diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index e25cefe89f..fb6cfc1d29 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -149,7 +149,7 @@ impl< E > VecExt< E > for Vec< E > { fn former() -> VectorSubformer< E, (), Vec< E >, ReturnStorage > { - VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new( ReturnStorage::default() ) + VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new_precise( ReturnStorage::default() ) } } diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index b0167aeb3c..3ad2cdf80f 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -50,14 +50,14 @@ fn begin_and_custom_end() { 13.1 } - let got = the_module::VectorSubformer::begin_coercing( None, None, return_13 ) + let got = the_module::VectorSubformer::begin_precise( None, None, return_13 ) .add( "a" ) .add( "b" ) .form(); let exp = 13.1; a_id!( got, exp ); - let got = the_module::VectorSubformer::new( return_13 ) + let got = the_module::VectorSubformer::new_precise( return_13 ) .add( "a" ) .add( "b" ) .form(); @@ -77,7 +77,7 @@ fn begin_and_custom_end() 13.1 } } - let got = the_module::VectorSubformer::begin_coercing( None, Some( 10.0 ), context_plus_13 ) + let got = the_module::VectorSubformer::begin_precise( None, Some( 10.0 ), context_plus_13 ) .add( "a" ) .add( "b" ) .form(); @@ -138,7 +138,7 @@ fn custom_definition() let exp = 13; a_id!( got, exp ); - let got = the_module::ContainerSubformer::< String, Return13 >::new( Return13 ) + let got = the_module::ContainerSubformer::< String, Return13 >::new_precise( Return13 ) .add( "a" ) .add( "b" ) .form(); @@ -208,7 +208,7 @@ fn custom_definition_parametrized() let exp = 13; a_id!( got, exp ); - let got = the_module::ContainerSubformer::< String, Return13< String > >::new( Return13::new() ) + let got = the_module::ContainerSubformer::< String, Return13< String > >::new_coercing( Return13::new() ) .add( "a" ) .add( "b" ) .form(); @@ -226,7 +226,7 @@ fn custom_definition_parametrized() let exp = 13; a_id!( got, exp ); - let got = MyContainer::< String >::new( Return13::new() ) + let got = MyContainer::< String >::new_coercing( Return13::new() ) .add( "a" ) .add( "b" ) .form(); @@ -265,21 +265,21 @@ fn custom_definition_custom_end() } let end_wrapper : the_module::FormingEndClosure< Return13 > = the_module::FormingEndClosure::new( return_13 ); - let got = the_module::ContainerSubformer::< String, Return13 >::new( end_wrapper ) + let got = the_module::ContainerSubformer::< String, Return13 >::new_precise( end_wrapper ) .add( "a" ) .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); - let got = the_module::ContainerSubformer::< String, Return13 >::new( return_13.into() ) + let got = the_module::ContainerSubformer::< String, Return13 >::new_precise( return_13.into() ) .add( "a" ) .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); - let got = the_module::ContainerSubformer::< String, Return13 >::new_with( return_13 ) + let got = the_module::ContainerSubformer::< String, Return13 >::new_coercing( return_13 ) .add( "a" ) .add( "b" ) .form(); diff --git a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs index ec017cf3a3..0cf7183b27 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs @@ -16,7 +16,7 @@ fn add() let got : HashMap< String, String > = the_module ::ContainerSubformer ::< ( String, String ), former::HashMapDefinition< String, String, (), HashMap< String, String >, the_module::ReturnStorage > > - ::new( former::ReturnStorage ) + ::new_precise( former::ReturnStorage ) .add( ( "a".into(), "x".into() ) ) .add( ( "b".into(), "y".into() ) ) .form(); @@ -30,7 +30,7 @@ fn add() // expliccit with HashMapSubformer let got : HashMap< String, String > = the_module::HashMapSubformer::< String, String, (), HashMap< String, String >, the_module::ReturnStorage > - ::new( former::ReturnStorage ) + ::new_precise( former::ReturnStorage ) .add( ( "a".into(), "x".into() ) ) .add( ( "b".into(), "y".into() ) ) .form(); @@ -43,7 +43,7 @@ fn add() // compact with HashMapSubformer - let got : HashMap< String, String > = the_module::HashMapSubformer::new( former::ReturnStorage ) + let got : HashMap< String, String > = the_module::HashMapSubformer::new_precise( former::ReturnStorage ) .add( ( "a".into(), "x".into() ) ) .add( ( "b".into(), "y".into() ) ) .form(); @@ -54,10 +54,10 @@ fn add() ]; a_id!( got, exp ); - // with begin_coercing + // with begin_precise let got : HashMap< String, String > = the_module::HashMapSubformer - ::begin_coercing( Some( hmap![ "a".to_string() => "x".to_string() ] ), Some( () ), former::ReturnStorage ) + ::begin_precise( Some( hmap![ "a".to_string() => "x".to_string() ] ), Some( () ), former::ReturnStorage ) .add( ( "b".into(), "y".into() ) ) .form(); let exp = hmap! @@ -91,7 +91,7 @@ fn add() fn replace() { - let got : HashMap< String, String > = the_module::HashMapSubformer::new( former::ReturnStorage ) + let got : HashMap< String, String > = the_module::HashMapSubformer::new_precise( former::ReturnStorage ) .add( ( "x".to_string(), "y".to_string() ) ) .replace( hmap![ "a".to_string() => "x".to_string(), "b".to_string() => "y".to_string(), ] ) .form(); @@ -103,3 +103,17 @@ fn replace() a_id!( got, exp ); } + +// xxx +// #[ test ] +// fn entity_to() +// { +// +// let got = < Vec< i32 > as former::EntityToFormer< former::VectorDefinition< i32, (), Vec< i32 >, former::ReturnPreformed > > > +// ::Former::new_precise( former::ReturnPreformed ) +// .add( 13 ) +// .form(); +// let exp = vec![ 13 ]; +// a_id!( got, exp ); +// +// } diff --git a/module/core/former/tests/inc/former_tests/container_former_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs index ca797c2cf6..c175305de1 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashset.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashset.rs @@ -16,7 +16,7 @@ fn add() let got : HashSet< String > = the_module ::ContainerSubformer ::< String, former::HashSetDefinition< String, (), HashSet< String >, the_module::ReturnStorage > > - ::new( former::ReturnStorage ) + ::new_precise( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -30,7 +30,7 @@ fn add() // expliccit with HashSetSubformer let got : HashSet< String > = the_module::HashSetSubformer::< String, (), HashSet< String >, the_module::ReturnStorage > - ::new( former::ReturnStorage ) + ::new_precise( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -43,7 +43,7 @@ fn add() // compact with HashSetSubformer - let got : HashSet< String > = the_module::HashSetSubformer::new( former::ReturnStorage ) + let got : HashSet< String > = the_module::HashSetSubformer::new_precise( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -57,7 +57,7 @@ fn add() // with begin_coercing let got : HashSet< String > = the_module::HashSetSubformer - ::begin_coercing( Some( hset![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) + ::begin_precise( Some( hset![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) .add( "b" ) .form(); let exp = hset! @@ -91,7 +91,7 @@ fn add() fn replace() { - let got : HashSet< String > = the_module::HashSetSubformer::new( former::ReturnStorage ) + let got : HashSet< String > = the_module::HashSetSubformer::new_precise( former::ReturnStorage ) .add( "x" ) .replace( hset![ "a".to_string(), "b".to_string() ] ) .form(); 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 f2bb876c74..1d8e4faa21 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 @@ -15,7 +15,7 @@ fn add() let got : Vec< String > = the_module ::ContainerSubformer ::< String, former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > > - ::new( former::ReturnStorage ) + ::new_precise( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -29,7 +29,7 @@ fn add() // expliccit with VectorSubformer let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage > - ::new( former::ReturnStorage ) + ::new_precise( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -42,7 +42,7 @@ fn add() // compact with VectorSubformer - let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) + let got : Vec< String > = the_module::VectorSubformer::new_precise( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -56,7 +56,7 @@ fn add() // with begin_coercing let got : Vec< String > = the_module::VectorSubformer - ::begin_coercing( Some( vec![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) + ::begin_precise( Some( vec![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) .add( "b" ) .form(); let exp = vec! @@ -90,7 +90,7 @@ fn add() fn replace() { - let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) + let got : Vec< String > = the_module::VectorSubformer::new_precise( former::ReturnStorage ) .add( "x" ) .replace( vec![ "a".to_string(), "b".to_string() ] ) .form(); From 0fbc7e6e38facea492fc7dc4b180a24a16105c19 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 16:54:37 +0300 Subject: [PATCH 320/533] former : experimenting --- module/core/former/src/hash_set.rs | 35 +++++++++++++++++++++++++----- module/core/former/src/vector.rs | 2 ++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index a4951a7e7b..2fcf83bb8a 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -5,11 +5,11 @@ use super::*; use collection_tools::HashSet; -impl< E > ContainerAdd for collection_tools::HashSet< E > +impl ContainerAdd for collection_tools::HashSet< K > where - E : core::cmp::Eq + core::hash::Hash, + K : core::cmp::Eq + core::hash::Hash, { - type Element = E; + type Element = K; #[ inline( always ) ] fn add( &mut self, e : Self::Element ) -> bool @@ -118,9 +118,34 @@ where type Types = HashSetDefinition< K, Context, Formed, NoEnd >; type End = End; +} + +// = Entity To + +impl< K, Definition > EntityToFormer< Definition > for HashSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + Definition : FormerDefinition< Storage = HashSet< K >, Formed = () >, + < Definition as definition::FormerDefinition>::End : Fn( HashSet< K >, Option< Definition::Context > ), +{ + type Former = HashSetSubformer< K, Definition::Context, Definition::Formed, Definition::End >; +} - // type Types = HashSetDefinition< K, Context, Formed, NoEnd >; - // type End = End; +impl< K > crate::EntityToStorage +for HashSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Storage = HashSet< K >; +} + +impl< K, Context, Formed, End > crate::EntityToDefinition< Context, Formed, End > +for HashSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + End : crate::FormingEnd< HashSetDefinition< K, Context, Formed, NoEnd > >, +{ + type Definition = HashSetDefinition< K, Context, Formed, End >; } // = subformer diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index fb6cfc1d29..e381329a09 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -102,6 +102,8 @@ where type End = End; } +// = Entity To + // xxx : implement for hashset / hashmap // xxx : cover by tests impl< E, Definition > EntityToFormer< Definition > for Vec< E > From 79626caf09da38cb46923d88c0d41d4714c64978 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 17:01:37 +0300 Subject: [PATCH 321/533] former : experimenting --- module/core/former/src/hash_map.rs | 58 +++++++++---------- .../inc/former_tests/container_former_vec.rs | 32 ++++++++++ .../tests/inc/former_tests/only_test/basic.rs | 4 +- 3 files changed, 61 insertions(+), 33 deletions(-) diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 6ed9713964..6ebc355f90 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -135,37 +135,33 @@ where } -// #[ derive( Debug, Default ) ] -// pub struct HashMapDefinition< K, E, Context = (), Formed = HashMap< K, E >, End = ReturnStorage > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// _phantom : ::core::marker::PhantomData< ( K, E, Context, End ) >, -// } -// -// impl< K, E, Context, End > FormerDefinitionTypes -// for HashMapDefinition< K, E, Context, End > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// End : FormingEnd< Self >, -// { -// type Storage = HashMap< K, E >; -// type Formed = HashMap< K, E >; -// type Context = Context; -// type End = End; -// } -// -// impl< K, E, Context, End > FormerDefinitionTypes -// for HashMapDefinition< K, E, Context, End > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// End : FormingEnd< Self >, -// { -// type Storage = HashMap< K, E >; -// type Formed = HashMap< K, E >; -// type Context = Context; -// type End = End; -// } +// = Entity To + +impl< K, E, Definition > EntityToFormer< Definition > for HashMap< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + Definition : FormerDefinition< Storage = HashMap< K, E >, Formed = () >, + < Definition as definition::FormerDefinition>::End : Fn( HashMap< K, E >, Option< Definition::Context > ), +{ + type Former = HashMapSubformer< K, E, Definition::Context, Definition::Formed, Definition::End >; +} + +impl< K, E > crate::EntityToStorage +for HashMap< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Storage = HashMap< K, E >; +} + +impl< K, E, Context, Formed, End > crate::EntityToDefinition< Context, Formed, End > +for HashMap< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + End : crate::FormingEnd< HashMapDefinition< K, E, Context, Formed, NoEnd > >, +{ + type Definition = HashMapDefinition< K, E, Context, Formed, End >; +} // = subformer 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 1d8e4faa21..7dd7400632 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 @@ -104,3 +104,35 @@ fn replace() } // + +#[ test ] +fn entity_to() +{ + + // let got = < Vec< i32 > as former::EntityToFormer< former::VectorDefinition< (), Vec< i32 >, former::ReturnPreformed > > >::Former::new_precise( former::ReturnPreformed ) + // .add( 13 ) + // .form(); + // let exp = vec![ 13 ]; + // a_id!( got, exp ); + +// let got = < Vec< i32 > as former::EntityToStorage >::Storage::default(); +// let exp = +// < +// Vec< i32 > as former::EntityToFormer +// < +// Vec< i32 >FormerDefinition< (), Vec< i32 >, former::ReturnPreformed > +// > +// >::Former::new_precise( former::ReturnPreformed ); +// a_id!( got.int_1, exp.storage.int_1 ); +// +// let got = < Vec< i32 > as former::EntityToStorage >::Storage::default(); +// let exp = +// < +// Vec< i32 > as former::EntityToFormer +// < +// < Vec< i32 > as former::EntityToDefinition< (), Vec< i32 >, former::ReturnPreformed > >::Definition +// > +// >::Former::new_precise( former::ReturnPreformed ); +// a_id!( got.int_1, exp.storage.int_1 ); + +} diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index 65487f5558..0808b22625 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -34,7 +34,7 @@ tests_impls! // - fn entity_to_former() + fn entity_to() { let got = < Struct1 as former::EntityToFormer< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > >::Former::new_precise( former::ReturnPreformed ) @@ -562,7 +562,7 @@ tests_impls! tests_index! { internals, - entity_to_former, + entity_to, former_begin, custom_definition_params, begin_coercing, From 64d672b72106cd573e4df6b69dd0ac08788b53b4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 18:46:56 +0300 Subject: [PATCH 322/533] former : experimenting --- module/core/former/src/definition.rs | 2 +- module/core/former/src/vector.rs | 15 +++++++++------ .../inc/former_tests/container_former_vec.rs | 5 ++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs index 97926ec02e..3b52346534 100644 --- a/module/core/former/src/definition.rs +++ b/module/core/former/src/definition.rs @@ -14,7 +14,7 @@ where Definition : FormerDefinition, { type Former; - fn f1( _ : &Definition ) {} + fn __f( _ : &Definition ) {} } // zzz : improve documentation diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index e381329a09..1e2e7d17ee 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -75,8 +75,8 @@ for Vec< E > #[ derive( Debug, Default ) ] pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > -// where -// End : FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, +where + End : FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, { _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, } @@ -104,12 +104,15 @@ where // = Entity To -// xxx : implement for hashset / hashmap -// xxx : cover by tests +// zzz : qqq : implement for hashset / hashmap +// zzz : qqq : cover by tests +// zzz : qqq : rid off bound `Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed`` impl< E, Definition > EntityToFormer< Definition > for Vec< E > where - Definition : FormerDefinition< Storage = Vec< E >, Formed = () >, - < Definition as definition::FormerDefinition>::End : Fn( Vec< E >, Option< Definition::Context > ), + Definition : FormerDefinition< Storage = Vec< E > >, + Definition::Types : FormerDefinitionTypes< Storage = Vec< E >, Formed = Definition::Formed, Context = Definition::Context >, + Definition::End : crate::FormingEnd< Definition::Types >, + Definition::End : Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed, { type Former = VectorSubformer< E, Definition::Context, Definition::Formed, Definition::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 7dd7400632..10773220b4 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 @@ -109,12 +109,15 @@ fn replace() fn entity_to() { - // let got = < Vec< i32 > as former::EntityToFormer< former::VectorDefinition< (), Vec< i32 >, former::ReturnPreformed > > >::Former::new_precise( former::ReturnPreformed ) + // qqq : uncomment and make it working + // let got = < Vec< i32 > as former::EntityToFormer< former::VectorDefinition< i32, (), Vec< i32 >, former::ReturnPreformed > > > + // ::Former::new_precise( former::ReturnPreformed ) // .add( 13 ) // .form(); // let exp = vec![ 13 ]; // a_id!( got, exp ); +// qqq : uncomment and make it working // let got = < Vec< i32 > as former::EntityToStorage >::Storage::default(); // let exp = // < From 5ae55461d45e9b87a2145a7fa0596e78cd26572e Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 19:14:30 +0300 Subject: [PATCH 323/533] former : experimenting --- module/core/former/src/vector.rs | 2 +- .../former_tests/subformer_and_container.rs | 57 ++++ .../subformer_and_container_manual.rs | 271 +++++++++++++++ .../subformer_implicit_container.rs | 312 +----------------- .../subformer_implicit_container_manual.rs | 91 +---- .../former_tests/subformer_subform_manual.rs | 88 ++--- module/core/former/tests/inc/mod.rs | 5 + module/core/former_meta/src/derive/former.rs | 15 +- 8 files changed, 405 insertions(+), 436 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/subformer_and_container.rs create mode 100644 module/core/former/tests/inc/former_tests/subformer_and_container_manual.rs diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 1e2e7d17ee..13f7762a27 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -106,7 +106,7 @@ where // zzz : qqq : implement for hashset / hashmap // zzz : qqq : cover by tests -// zzz : qqq : rid off bound `Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed`` +// zzz : qqq : rid off bound `Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed` for all containers impl< E, Definition > EntityToFormer< Definition > for Vec< E > where Definition : FormerDefinition< Storage = Vec< E > >, diff --git a/module/core/former/tests/inc/former_tests/subformer_and_container.rs b/module/core/former/tests/inc/former_tests/subformer_and_container.rs new file mode 100644 index 0000000000..4c628069c1 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_and_container.rs @@ -0,0 +1,57 @@ +#![ allow( dead_code ) ] + +use super::*; + +/// Parameter description. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent required for the template. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + // #[ subform ] + #[ subform( name = _child ) ] + #[ container( former::VectorDefinition ) ] + // #[ setter( false ) ] + children : Vec< Child >, +} + +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn child( self, name : &str ) -> + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._children_add_subformer + ::< ChildFormer< _ >, _, >() + .name( name ) + } + + // #[ inline( always ) ] + // pub fn _child( self ) -> + // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + // { + // self._children_add_subformer + // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + // } + +} + +// == begin of generated + +// == end of generated + +// xxx +include!( "./only_test/subformer_subform.rs" ); +include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_and_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_and_container_manual.rs new file mode 100644 index 0000000000..30705da33c --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_and_container_manual.rs @@ -0,0 +1,271 @@ +#![ allow( dead_code ) ] + +use super::*; + +/// Parameter description. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent required for the template. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + // #[ container( former::VectorDefinition ) ] + // #[ subform ] + #[ setter( false ) ] + children : Vec< Child >, +} + +// == begin of generated for Parent in context of attribute subform + +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn _children_add_subformer_with_closure< Former2, Definition2, Types2 >( self ) -> + Former2 + where + Types2 : former::FormerDefinitionTypes + < + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2 : former::FormerDefinition + < + Types = Types2, + End = former::FormingEndClosure< Types2 >, + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2::End : former::FormingEnd< Definition2::Types >, + Former2 : former::FormerBegin + < + Definition2, + >, + { + let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + if super_former.storage.children.is_none() + { + super_former.storage.children = Some( Default::default() ); + } + if let Some( ref mut children ) = super_former.storage.children + { + former::ContainerAdd::add( children, former::StoragePreform::preform( substorage ) ); + } + super_former + }; + Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + } + + #[ inline( always ) ] + pub fn _children_add_subformer< Former2, Definition2 >( self ) -> + Former2 + where + Definition2 : former::FormerDefinition + < + End = ParentFormerAddChildrenEnd< Definition >, + Storage = < Child as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Definition2::Types : former::FormerDefinitionTypes + < + Storage = < Child as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Former2 : former::FormerBegin< Definition2 >, + { + Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) + } + + #[ inline( always ) ] + pub fn child( self, name : &str ) -> + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._children_add_subformer + ::< ChildFormer< _ >, _, >() + .name( name ) + } + + // #[ inline( always ) ] + // pub fn _child( self ) -> + // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + // { + // self._children_add_subformer + // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + // } + + #[ inline( always ) ] + pub fn _child( self ) -> + < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer + < + // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, + < + < Vec< Child > as former::ContainerAdd >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > + >::Definition, + > + >::Former + { + self._children_add_subformer + ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() + } + +} + +/// Handles the completion of and element of subformer's container. +pub struct ParentFormerAddChildrenEnd< Definition > +{ + _phantom : core::marker::PhantomData< fn( Definition ) >, +} + +impl< Definition > Default +for ParentFormerAddChildrenEnd< Definition > +{ + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} + +impl< Types2, Definition > former::FormingEnd< Types2, > +for ParentFormerAddChildrenEnd< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = < Parent as former::EntityToStorage >::Storage, + >, + Types2 : former::FormerDefinitionTypes + < + Storage = < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + Formed = ParentFormer< Definition >, + Context = ParentFormer< Definition >, + >, +{ + #[ inline( always ) ] + fn call + ( + &self, + substorage : Types2::Storage, + super_former : core::option::Option< Types2::Context >, + ) + -> Types2::Formed + { + let mut super_former = super_former.unwrap(); + if super_former.storage.children.is_none() + { + super_former.storage.children = Some( Default::default() ); + } + if let Some( ref mut fields ) = super_former.storage.children + { + former::ContainerAdd::add( fields, former::StoragePreform::preform( substorage ) ); + } + super_former + } +} + +// == end of generated for Parent in context of attribute subform + +// == begin of generated for Parent in context of attribute container( former::VectorDefinition ) ] + +#[ automatically_derived ] +impl< Definition, > ParentFormer< Definition, > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, +{ + + #[ inline( always ) ] + pub fn _children_assign< Former2 >( self ) -> Former2 + where + Former2 : former::FormerBegin< former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > >, + { + Former2::former_begin( None, Some( self ), ParentFormerAssignChildrenEnd::< Definition >::default() ) + } + #[ doc = + "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer." ] + #[ inline( always ) ] + pub fn children( self ) -> former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > + { + self._children_assign::< former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > >() + } + +} + +// + +#[ doc = r"Callback to return original former after forming of container for `vec_1` is done. Callback replace content of container assigning new content from subformer's storage." ] +pub struct ParentFormerAssignChildrenEnd< Definition > +{ + _phantom : core::marker::PhantomData< ( Definition, ) >, +} + +impl< Definition > Default for ParentFormerAssignChildrenEnd< Definition > +{ + + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + +} + +#[ automatically_derived ] +impl< Definition, > former::FormingEnd +// < former::VectorDefinition< Child, ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd >, > +< + < Vec< Child > as former::EntityToDefinition< ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd > >::Definition +> +for ParentFormerAssignChildrenEnd< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, +{ + #[ inline( always ) ] + fn call + ( + &self, + storage : Vec< Child >, + super_former : Option< ParentFormer< Definition, > >, + ) + -> ParentFormer< Definition, > + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.children + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.children = Some( storage ); + } + super_former + } +} + +// == end of generated for Parent in context of attribute container( former::VectorDefinition ) ] + +include!( "./only_test/subformer_subform.rs" ); +include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs index 7205ba5efe..56f41aa3e0 100644 --- a/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs @@ -16,9 +16,8 @@ pub struct Child // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { - #[ subform ] - // #[ subform( name = child ) ] - #[ container( former::VectorDefinition ) ] + // #[ subform ] + #[ subform( name = _child ) ] // #[ setter( false ) ] children : Vec< Child >, } @@ -38,311 +37,18 @@ where .name( name ) } - #[ inline( always ) ] - pub fn _child( self ) -> - ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - { - self._children_add_subformer - ::< < Child as former::EntityToFormer< _ > >::Former, _, >() - } + // #[ inline( always ) ] + // pub fn _child( self ) -> + // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + // { + // self._children_add_subformer + // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + // } } // == begin of generated -// #[automatically_derived] impl < > Parent < > where -// { -// #[doc = r""] -// #[doc = -// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] -// #[doc = r""] #[inline(always)] pub fn former() -> ParentFormer < -// ParentFormerDefinition < (), Parent < > , former :: ReturnPreformed > > -// { -// ParentFormer :: < ParentFormerDefinition < (), Parent < > , former :: -// ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) -// } -// } impl < Definition > former :: EntityToFormer < Definition > for Parent < > -// where Definition : former :: FormerDefinition < Storage = ParentFormerStorage -// < > > , { type Former = ParentFormer < Definition > ; } impl < > former :: -// EntityToStorage for Parent < > where -// { type Storage = ParentFormerStorage < > ; } #[derive(Debug)] pub struct -// ParentFormerDefinitionTypes < __Context = (), __Formed = Parent < > , > where -// { _phantom : core :: marker :: PhantomData < (__Context, __Formed) > , } impl -// < __Context, __Formed, > :: core :: default :: Default for -// ParentFormerDefinitionTypes < __Context, __Formed, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, > former :: FormerDefinitionTypes for -// ParentFormerDefinitionTypes < __Context, __Formed, > where -// { -// type Storage = ParentFormerStorage < > ; type Formed = __Formed; type -// Context = __Context; -// } #[derive(Debug)] pub struct ParentFormerDefinition < __Context = (), -// __Formed = Parent < > , __End = former :: ReturnPreformed, > where -// { -// _phantom : core :: marker :: PhantomData < (__Context, __Formed, __End) > -// , -// } impl < __Context, __Formed, __End, > :: core :: default :: Default for -// ParentFormerDefinition < __Context, __Formed, __End, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, __End, > former :: FormerDefinition for -// ParentFormerDefinition < __Context, __Formed, __End, > where __End : former :: -// FormingEnd < ParentFormerDefinitionTypes < __Context, __Formed, > > , -// { -// type Types = ParentFormerDefinitionTypes < __Context, __Formed, > ; type -// End = __End; type Storage = ParentFormerStorage < > ; type Formed = -// __Formed; type Context = __Context; -// } #[doc = "Container of a corresponding former."] pub struct -// ParentFormerStorage < > where -// { -// #[doc = r" A field"] pub children : :: core :: option :: Option < Vec < -// Child > > , -// } impl < > :: core :: default :: Default for ParentFormerStorage < > where -// { -// #[inline(always)] fn default() -> Self -// { Self { children : :: core :: option :: Option :: None, } } -// } impl < > former :: Storage for ParentFormerStorage < > where -// { type Formed = Parent < > ; } impl < > former :: StoragePreform for -// ParentFormerStorage < > where -// { -// type Preformed = Parent < > ; fn preform(mut self) -> Self :: Preformed -// { -// let children = if self.children.is_some() -// { self.children.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'children' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < Vec < Child > -// >).maybe_default() -// } -// }; let result = Parent :: < > { children, }; return result; -// } -// } -// #[doc = -// " Object to form [Parent]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -// pub struct ParentFormer < Definition = ParentFormerDefinition < (), Parent < > -// , former :: ReturnPreformed > , > where Definition : former :: -// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = ParentFormerStorage < > > , -// { -// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: -// Storage, context : core :: option :: Option < < Definition :: Types as -// former :: FormerDefinitionTypes > :: Context > , on_end : core :: option -// :: Option < Definition :: End > , -// } #[automatically_derived] impl < Definition, > ParentFormer < Definition, > -// where Definition : former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = ParentFormerStorage < > > , -// { -// #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn -// new_precise(on_end : Definition :: End) -> Self -// { Self :: begin_coercing(None, None, on_end) } #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > -// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , -// { Self :: begin_coercing(None, None, end,) } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn -// begin_precise(mut storage : core :: option :: Option < < Definition :: -// Types as former :: FormerDefinitionTypes > :: Storage > , context : core -// :: option :: Option < < Definition :: Types as former :: -// FormerDefinitionTypes > :: Context > , on_end : < Definition as former :: -// FormerDefinition > :: End,) -> Self -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: Some(on_end), -// } -// } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > -// (mut storage : core :: option :: Option < < Definition :: Types as former -// :: FormerDefinitionTypes > :: Storage > , context : core :: option :: -// Option < < Definition :: Types as former :: FormerDefinitionTypes > :: -// Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert -// :: Into < < Definition as former :: FormerDefinition > :: End > , -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: -// Some(:: core :: convert :: Into :: into(on_end)), -// } -// } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types -// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { -// let on_end = self.on_end.take().unwrap(); let context = -// self.context.take(); former :: FormingEnd :: < Definition :: Types > -// :: call(& on_end, self.storage, context) -// } -// #[doc = -// "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer."] -// #[inline(always)] pub fn _children_assign < Former2 > (self) -> Former2 -// where Former2 : former :: FormerBegin < former :: VectorDefinition < -// Child, Self, Self, ParentFormerAssignChildrenEnd < Definition > , > > , -// { -// Former2 :: -// former_begin(None, Some(self), ParentFormerAssignChildrenEnd :: < -// Definition > :: default()) -// } -// #[doc = -// "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer."] -// #[inline(always)] pub fn children(self) -> former :: ContainerSubformer :: -// < Child, former :: VectorDefinition < Child, Self, Self, -// ParentFormerAssignChildrenEnd < Definition > , > > -// { -// self._children_assign :: < former :: ContainerSubformer :: < Child, -// former :: VectorDefinition < Child, Self, Self, -// ParentFormerAssignChildrenEnd < Definition > , > >> () -// } #[doc = r" Custom setter which produce container element subformer."] -// #[inline(always)] pub fn _children_add_subformer < Former2, Definition2 > -// (self) -> Former2 where Definition2 : former :: FormerDefinition < End = -// ParentFormerAddChildrenEnd < Definition > , Storage = < Child as former :: -// EntityToStorage > :: Storage, Formed = Self, Context = Self, > , -// Definition2 :: Types : former :: FormerDefinitionTypes < Storage = < Child -// as former :: EntityToStorage > :: Storage, Formed = Self, Context = Self, -// > , Former2 : former :: FormerBegin < Definition2 > , -// { -// Former2 :: -// former_begin(None, Some(self), ParentFormerAddChildrenEnd :: -// default()) -// } -// -// #[inline(always)] -// pub fn child(self) -> ParentAsSubformer < Self, impl ParentAsSubformerEnd < Self > > -// { -// self._children_add_subformer :: < < Vec < Child > as former :: -// EntityToFormer < _ > > :: Former, _, > () -// } -// } -// -// impl < Definition, > ParentFormer < Definition, > where Definition :: Types -// : former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > , Formed -// = Parent < > > , Definition : former :: FormerDefinition, Definition :: Types -// : former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , -// { -// pub fn preform(self) -> < Definition :: Types as former :: -// FormerDefinitionTypes > :: Formed -// { former :: StoragePreform :: preform(self.storage) } -// } #[automatically_derived] impl < Definition, > ParentFormer < Definition, > -// where Definition : former :: FormerDefinition, Definition :: Types : former :: -// FormerDefinitionTypes < Storage = ParentFormerStorage < > , Formed = Parent < -// > > , -// { -// #[doc = r""] -// #[doc = r" Finish setting options and call perform on formed entity."] -// #[doc = r""] -// #[doc = -// r" If `perform` defined then associated method is called and its result returned instead of entity."] -// #[doc = -// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] -// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { let result = self.form(); return result; } -// } impl < Definition > former :: FormerBegin < Definition > for ParentFormer < -// Definition, > where Definition : former :: FormerDefinition < Storage = -// ParentFormerStorage < > > , -// { -// #[inline(always)] fn -// former_begin(storage : core :: option :: Option < Definition :: Storage > -// , context : core :: option :: Option < Definition :: Context > , on_end : -// Definition :: End,) -> Self -// { -// debug_assert! (storage.is_none()); Self :: -// begin_precise(None, context, on_end) -// } -// } -// #[doc = -// r" Use as subformer of a field during process of forming of super structure."] -// pub type ParentAsSubformer < __Superformer, __End > = ParentFormer < -// ParentFormerDefinition < __Superformer, __Superformer, __End, > , > ; -// #[doc = -// "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] -// pub trait ParentAsSubformerEnd < SuperFormer > where Self : former :: -// FormingEnd < ParentFormerDefinitionTypes < SuperFormer, SuperFormer > , > , {} -// impl < SuperFormer, T > ParentAsSubformerEnd < SuperFormer > for T where Self -// : former :: FormingEnd < ParentFormerDefinitionTypes < SuperFormer, -// SuperFormer > , > , {} -// #[doc = -// "Callback to return original former after forming of container for `$Parent` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] -// pub struct ParentFormerAssignChildrenEnd < Definition > -// { _phantom : core :: marker :: PhantomData < (Definition,) > , } impl < -// Definition > Default for ParentFormerAssignChildrenEnd < Definition > -// { -// #[inline(always)] fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } #[automatically_derived] impl < Definition, > former :: FormingEnd < former -// :: VectorDefinition < Child, ParentFormer < Definition, > , ParentFormer < -// Definition, > , former :: NoEnd > , > for ParentFormerAssignChildrenEnd < -// Definition > where Definition : former :: FormerDefinition, Definition :: -// Types : former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > -// , -// { -// #[inline(always)] fn -// call(& self, storage : Vec < Child > , super_former : Option < -// ParentFormer < Definition, > > ,) -> ParentFormer < Definition, > -// { -// let mut super_former = super_former.unwrap(); if let -// Some(ref mut field) = super_former.storage.children -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.children = Some(storage); } super_former -// } -// } #[doc = r" Handles the completion of an element of subformer's container."] -// pub struct ParentFormerAddChildrenEnd < Definition > -// { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < -// Definition > Default for ParentFormerAddChildrenEnd < Definition > -// { -// #[inline(always)] fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < Types2, Definition > former :: FormingEnd < Types2, > for -// ParentFormerAddChildrenEnd < Definition > where Definition : former :: -// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = < Parent < > as former :: EntityToStorage > :: Storage, > , Types2 : -// former :: FormerDefinitionTypes < Storage = < < Vec < Child > as former :: -// ContainerAdd > :: Element as former :: EntityToStorage > :: Storage, Formed = -// ParentFormer < Definition, > , Context = ParentFormer < Definition, > , > , -// { -// #[inline(always)] fn -// call(& self, substorage : Types2 :: Storage, super_former : core :: option -// :: Option < Types2 :: Context > ,) -> Types2 :: Formed -// { -// let mut super_former = super_former.unwrap(); if -// super_former.storage.children.is_none() -// { super_former.storage.children = Some(Default :: default()); } if let -// Some(ref mut field) = super_former.storage.children -// { -// former :: ContainerAdd :: -// add(field, former :: StoragePreform :: preform(substorage)); -// } super_former -// } -// } - // == end of generated -// xxx include!( "./only_test/subformer_subform.rs" ); -include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs index f7bd766834..9b1524dbf5 100644 --- a/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs @@ -119,11 +119,12 @@ where #[ inline( always ) ] pub fn _child( self ) -> - < Child as former::EntityToFormer + < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer < // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, - < Child as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > >::Definition, - // < Vec< Child > as former::EntityToDefinition< ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd > >::Definition + < + < Vec< Child > as former::ContainerAdd >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > + >::Definition, > >::Former { @@ -191,88 +192,4 @@ where // == end of generated for Parent in context of attribute subform -// == begin of generated for Parent in context of attribute container( former::VectorDefinition ) ] - -#[ automatically_derived ] -impl< Definition, > ParentFormer< Definition, > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, -{ - - #[ inline( always ) ] - pub fn _children_assign< Former2 >( self ) -> Former2 - where - Former2 : former::FormerBegin< former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > >, - { - Former2::former_begin( None, Some( self ), ParentFormerAssignChildrenEnd::< Definition >::default() ) - } - #[ doc = - "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer." ] - #[ inline( always ) ] - pub fn children( self ) -> former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > - { - self._children_assign::< former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > >() - } - -} - -// - -#[ doc = r"Callback to return original former after forming of container for `vec_1` is done. Callback replace content of container assigning new content from subformer's storage." ] -pub struct ParentFormerAssignChildrenEnd< Definition > -{ - _phantom : core::marker::PhantomData< ( Definition, ) >, -} - -impl< Definition > Default for ParentFormerAssignChildrenEnd< Definition > -{ - - #[ inline( always ) ] - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } - -} - -#[ automatically_derived ] -impl< Definition, > former::FormingEnd -// < former::VectorDefinition< Child, ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd >, > -< - < Vec< Child > as former::EntityToDefinition< ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd > >::Definition -> -for ParentFormerAssignChildrenEnd< Definition > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, -{ - #[ inline( always ) ] - fn call - ( - &self, - storage : Vec< Child >, - super_former : Option< ParentFormer< Definition, > >, - ) - -> ParentFormer< Definition, > - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.children - { - former::ContainerAssign::assign( field, storage ); - } - else - { - super_former.storage.children = Some( storage ); - } - super_former - } -} - -// == end of generated for Parent in context of attribute container( former::VectorDefinition ) ] - include!( "./only_test/subformer_subform.rs" ); -include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 45b5e64bfa..554e8f288a 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -18,29 +18,12 @@ pub struct Parent { // #[ container( former::VectorDefinition ) ] // #[ subform ] + #[ setter( false ) ] children : Vec< Child >, } -// impl< Definition > former::FormerBegin< Definition > -// for ChildFormer< Definition > -// where -// Definition : former::FormerDefinition< Storage = ChildFormerStorage >, -// { -// -// #[ inline( always ) ] -// fn former_begin -// ( -// storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, -// context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, -// on_end : Definition::End, -// ) -// -> Self -// { -// debug_assert!( storage.is_none() ); -// Self::begin_precise( None, context, on_end ) -// } -// -// } +// xxx + impl< Definition > ParentFormer< Definition > where @@ -88,6 +71,48 @@ where Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) } + #[ inline( always ) ] + pub fn child( self, name : &str ) -> + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._children_add_subformer + ::< ChildFormer< _ >, _, >() + .name( name ) + } + + // #[ inline( always ) ] + // pub fn _child( self ) -> + // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + // { + // self._children_add_subformer + // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + // } + + #[ inline( always ) ] + pub fn _child( self ) -> + < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer + < + // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, + < + < Vec< Child > as former::ContainerAdd >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > + >::Definition, + > + >::Former + { + self._children_add_subformer + ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() + } + +} + +// == begin of generated for Parent in context of attribute subform + +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + #[ inline( always ) ] pub fn _children_add_subformer< Former2, Definition2 >( self ) -> Former2 @@ -110,23 +135,6 @@ where Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) } - #[ inline( always ) ] - pub fn child( self, name : &str ) -> - ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - { - self._children_add_subformer - ::< ChildFormer< _ >, _, >() - .name( name ) - } - - #[ inline( always ) ] - pub fn _child( self ) -> - ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - { - self._children_add_subformer - ::< < Child as former::EntityToFormer< _ > >::Former, _, >() - } - } /// Handles the completion of and element of subformer's container. @@ -158,14 +166,10 @@ where >, Types2 : former::FormerDefinitionTypes < - // Storage = < Child as former::EntityToStorage >::Storage, Storage = < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, Formed = ParentFormer< Definition >, Context = ParentFormer< Definition >, - // Formed = < Parent as former::EntityToFormer >::Former, - // Context = < Parent as former::EntityToFormer >::Former, >, - // Types2::Storage : former::StoragePreform< Preformed = >, { #[ inline( always ) ] fn call @@ -189,4 +193,6 @@ where } } +// == end of generated for Parent in context of attribute subform + include!( "./only_test/subformer_subform.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 2c7fd9548a..bdbbd03433 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -72,6 +72,11 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_implicit_container_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_and_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_and_container_manual; + } #[ cfg( feature = "derive_components" ) ] diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 40df6ef59b..a58a36007c 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -682,8 +682,8 @@ fn field_subformer_map ( field : &FormerField< '_ >, stru : &syn::Ident, - as_subformer : &syn::Ident, - as_subformer_end : &syn::Ident, + _as_subformer : &syn::Ident, + _as_subformer_end : &syn::Ident, ) -> Result< TokenStream > { @@ -755,10 +755,17 @@ fn field_subformer_map #[ inline( always ) ] pub fn #setter_name( self ) -> - #as_subformer< Self, impl #as_subformer_end< Self > > + < < #field_ty as former::ContainerAdd >::Element as former::EntityToFormer + < + < + < #field_ty as former::ContainerAdd >::Element as former::EntityToDefinition< Self, Self, #parent_add_element_end < Definition > > + >::Definition, + > + >::Former + // #as_subformer< Self, impl #as_subformer_end< Self > > { self.#element_subformer - ::< < #field_ty as former::EntityToFormer< _ > >::Former, _, >() + ::< < < #field_ty as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() // ::< #former< _ >, _, >() } } From 96249d4a78ee656d335c02968e57677478f378c4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 19:17:09 +0300 Subject: [PATCH 324/533] former : experimenting --- .../inc/former_tests/subformer_container.rs | 28 ++ .../subformer_container_manual.rs | 271 ++++++++++++++++++ .../former_tests/subformer_subform_manual.rs | 3 +- module/core/former/tests/inc/mod.rs | 4 + 4 files changed, 304 insertions(+), 2 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/subformer_container.rs create mode 100644 module/core/former/tests/inc/former_tests/subformer_container_manual.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_container.rs b/module/core/former/tests/inc/former_tests/subformer_container.rs new file mode 100644 index 0000000000..98e04e4ffb --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_container.rs @@ -0,0 +1,28 @@ +#![ allow( dead_code ) ] + +use super::*; + +/// Parameter description. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent required for the template. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + #[ container( former::VectorDefinition ) ] + // #[ setter( false ) ] + children : Vec< Child >, +} + +// == begin of generated + +// == end of generated + +include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs new file mode 100644 index 0000000000..30705da33c --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs @@ -0,0 +1,271 @@ +#![ allow( dead_code ) ] + +use super::*; + +/// Parameter description. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent required for the template. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + // #[ container( former::VectorDefinition ) ] + // #[ subform ] + #[ setter( false ) ] + children : Vec< Child >, +} + +// == begin of generated for Parent in context of attribute subform + +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn _children_add_subformer_with_closure< Former2, Definition2, Types2 >( self ) -> + Former2 + where + Types2 : former::FormerDefinitionTypes + < + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2 : former::FormerDefinition + < + Types = Types2, + End = former::FormingEndClosure< Types2 >, + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2::End : former::FormingEnd< Definition2::Types >, + Former2 : former::FormerBegin + < + Definition2, + >, + { + let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + if super_former.storage.children.is_none() + { + super_former.storage.children = Some( Default::default() ); + } + if let Some( ref mut children ) = super_former.storage.children + { + former::ContainerAdd::add( children, former::StoragePreform::preform( substorage ) ); + } + super_former + }; + Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + } + + #[ inline( always ) ] + pub fn _children_add_subformer< Former2, Definition2 >( self ) -> + Former2 + where + Definition2 : former::FormerDefinition + < + End = ParentFormerAddChildrenEnd< Definition >, + Storage = < Child as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Definition2::Types : former::FormerDefinitionTypes + < + Storage = < Child as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Former2 : former::FormerBegin< Definition2 >, + { + Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) + } + + #[ inline( always ) ] + pub fn child( self, name : &str ) -> + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._children_add_subformer + ::< ChildFormer< _ >, _, >() + .name( name ) + } + + // #[ inline( always ) ] + // pub fn _child( self ) -> + // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + // { + // self._children_add_subformer + // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + // } + + #[ inline( always ) ] + pub fn _child( self ) -> + < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer + < + // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, + < + < Vec< Child > as former::ContainerAdd >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > + >::Definition, + > + >::Former + { + self._children_add_subformer + ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() + } + +} + +/// Handles the completion of and element of subformer's container. +pub struct ParentFormerAddChildrenEnd< Definition > +{ + _phantom : core::marker::PhantomData< fn( Definition ) >, +} + +impl< Definition > Default +for ParentFormerAddChildrenEnd< Definition > +{ + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } +} + +impl< Types2, Definition > former::FormingEnd< Types2, > +for ParentFormerAddChildrenEnd< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes + < + Storage = < Parent as former::EntityToStorage >::Storage, + >, + Types2 : former::FormerDefinitionTypes + < + Storage = < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + Formed = ParentFormer< Definition >, + Context = ParentFormer< Definition >, + >, +{ + #[ inline( always ) ] + fn call + ( + &self, + substorage : Types2::Storage, + super_former : core::option::Option< Types2::Context >, + ) + -> Types2::Formed + { + let mut super_former = super_former.unwrap(); + if super_former.storage.children.is_none() + { + super_former.storage.children = Some( Default::default() ); + } + if let Some( ref mut fields ) = super_former.storage.children + { + former::ContainerAdd::add( fields, former::StoragePreform::preform( substorage ) ); + } + super_former + } +} + +// == end of generated for Parent in context of attribute subform + +// == begin of generated for Parent in context of attribute container( former::VectorDefinition ) ] + +#[ automatically_derived ] +impl< Definition, > ParentFormer< Definition, > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, +{ + + #[ inline( always ) ] + pub fn _children_assign< Former2 >( self ) -> Former2 + where + Former2 : former::FormerBegin< former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > >, + { + Former2::former_begin( None, Some( self ), ParentFormerAssignChildrenEnd::< Definition >::default() ) + } + #[ doc = + "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer." ] + #[ inline( always ) ] + pub fn children( self ) -> former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > + { + self._children_assign::< former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > >() + } + +} + +// + +#[ doc = r"Callback to return original former after forming of container for `vec_1` is done. Callback replace content of container assigning new content from subformer's storage." ] +pub struct ParentFormerAssignChildrenEnd< Definition > +{ + _phantom : core::marker::PhantomData< ( Definition, ) >, +} + +impl< Definition > Default for ParentFormerAssignChildrenEnd< Definition > +{ + + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + +} + +#[ automatically_derived ] +impl< Definition, > former::FormingEnd +// < former::VectorDefinition< Child, ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd >, > +< + < Vec< Child > as former::EntityToDefinition< ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd > >::Definition +> +for ParentFormerAssignChildrenEnd< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, +{ + #[ inline( always ) ] + fn call + ( + &self, + storage : Vec< Child >, + super_former : Option< ParentFormer< Definition, > >, + ) + -> ParentFormer< Definition, > + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.children + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.children = Some( storage ); + } + super_former + } +} + +// == end of generated for Parent in context of attribute container( former::VectorDefinition ) ] + +include!( "./only_test/subformer_subform.rs" ); +include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 554e8f288a..f12d4f78d2 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -22,8 +22,7 @@ pub struct Parent children : Vec< Child >, } -// xxx - +// = custom impl< Definition > ParentFormer< Definition > where diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index bdbbd03433..5429413205 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -66,6 +66,10 @@ mod former_tests mod subformer_subform; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_implicit_container; From 105f448fa30c21589f87350b5cee4aff0be8a811 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 19:19:13 +0300 Subject: [PATCH 325/533] former : experimenting --- .../subformer_and_container_manual.rs | 271 ------------------ .../subformer_container_manual.rs | 164 ----------- ....rs => subformer_subform_and_container.rs} | 9 - module/core/former/tests/inc/mod.rs | 4 +- 4 files changed, 1 insertion(+), 447 deletions(-) delete mode 100644 module/core/former/tests/inc/former_tests/subformer_and_container_manual.rs rename module/core/former/tests/inc/former_tests/{subformer_and_container.rs => subformer_subform_and_container.rs} (82%) diff --git a/module/core/former/tests/inc/former_tests/subformer_and_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_and_container_manual.rs deleted file mode 100644 index 30705da33c..0000000000 --- a/module/core/former/tests/inc/former_tests/subformer_and_container_manual.rs +++ /dev/null @@ -1,271 +0,0 @@ -#![ allow( dead_code ) ] - -use super::*; - -/// Parameter description. -#[ derive( Debug, Default, PartialEq, the_module::Former ) ] -pub struct Child -{ - name : String, - is_mandatory : bool, -} - -/// Parent required for the template. -#[ derive( Debug, Default, PartialEq, the_module::Former ) ] -// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] -// #[ derive( Debug, Default, PartialEq ) ] -pub struct Parent -{ - // #[ container( former::VectorDefinition ) ] - // #[ subform ] - #[ setter( false ) ] - children : Vec< Child >, -} - -// == begin of generated for Parent in context of attribute subform - -impl< Definition > ParentFormer< Definition > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, -{ - - #[ inline( always ) ] - pub fn _children_add_subformer_with_closure< Former2, Definition2, Types2 >( self ) -> - Former2 - where - Types2 : former::FormerDefinitionTypes - < - Storage = ChildFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2 : former::FormerDefinition - < - Types = Types2, - End = former::FormingEndClosure< Types2 >, - Storage = ChildFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2::End : former::FormingEnd< Definition2::Types >, - Former2 : former::FormerBegin - < - Definition2, - >, - { - let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if super_former.storage.children.is_none() - { - super_former.storage.children = Some( Default::default() ); - } - if let Some( ref mut children ) = super_former.storage.children - { - former::ContainerAdd::add( children, former::StoragePreform::preform( substorage ) ); - } - super_former - }; - Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) - } - - #[ inline( always ) ] - pub fn _children_add_subformer< Former2, Definition2 >( self ) -> - Former2 - where - Definition2 : former::FormerDefinition - < - End = ParentFormerAddChildrenEnd< Definition >, - Storage = < Child as former::EntityToStorage >::Storage, - Formed = Self, - Context = Self, - >, - Definition2::Types : former::FormerDefinitionTypes - < - Storage = < Child as former::EntityToStorage >::Storage, - Formed = Self, - Context = Self, - >, - Former2 : former::FormerBegin< Definition2 >, - { - Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) - } - - #[ inline( always ) ] - pub fn child( self, name : &str ) -> - ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - { - self._children_add_subformer - ::< ChildFormer< _ >, _, >() - .name( name ) - } - - // #[ inline( always ) ] - // pub fn _child( self ) -> - // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - // { - // self._children_add_subformer - // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() - // } - - #[ inline( always ) ] - pub fn _child( self ) -> - < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer - < - // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, - < - < Vec< Child > as former::ContainerAdd >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > - >::Definition, - > - >::Former - { - self._children_add_subformer - ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() - } - -} - -/// Handles the completion of and element of subformer's container. -pub struct ParentFormerAddChildrenEnd< Definition > -{ - _phantom : core::marker::PhantomData< fn( Definition ) >, -} - -impl< Definition > Default -for ParentFormerAddChildrenEnd< Definition > -{ - #[ inline( always ) ] - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } -} - -impl< Types2, Definition > former::FormingEnd< Types2, > -for ParentFormerAddChildrenEnd< Definition > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes - < - Storage = < Parent as former::EntityToStorage >::Storage, - >, - Types2 : former::FormerDefinitionTypes - < - Storage = < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, - Formed = ParentFormer< Definition >, - Context = ParentFormer< Definition >, - >, -{ - #[ inline( always ) ] - fn call - ( - &self, - substorage : Types2::Storage, - super_former : core::option::Option< Types2::Context >, - ) - -> Types2::Formed - { - let mut super_former = super_former.unwrap(); - if super_former.storage.children.is_none() - { - super_former.storage.children = Some( Default::default() ); - } - if let Some( ref mut fields ) = super_former.storage.children - { - former::ContainerAdd::add( fields, former::StoragePreform::preform( substorage ) ); - } - super_former - } -} - -// == end of generated for Parent in context of attribute subform - -// == begin of generated for Parent in context of attribute container( former::VectorDefinition ) ] - -#[ automatically_derived ] -impl< Definition, > ParentFormer< Definition, > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, -{ - - #[ inline( always ) ] - pub fn _children_assign< Former2 >( self ) -> Former2 - where - Former2 : former::FormerBegin< former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > >, - { - Former2::former_begin( None, Some( self ), ParentFormerAssignChildrenEnd::< Definition >::default() ) - } - #[ doc = - "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer." ] - #[ inline( always ) ] - pub fn children( self ) -> former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > - { - self._children_assign::< former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > >() - } - -} - -// - -#[ doc = r"Callback to return original former after forming of container for `vec_1` is done. Callback replace content of container assigning new content from subformer's storage." ] -pub struct ParentFormerAssignChildrenEnd< Definition > -{ - _phantom : core::marker::PhantomData< ( Definition, ) >, -} - -impl< Definition > Default for ParentFormerAssignChildrenEnd< Definition > -{ - - #[ inline( always ) ] - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } - -} - -#[ automatically_derived ] -impl< Definition, > former::FormingEnd -// < former::VectorDefinition< Child, ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd >, > -< - < Vec< Child > as former::EntityToDefinition< ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd > >::Definition -> -for ParentFormerAssignChildrenEnd< Definition > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, -{ - #[ inline( always ) ] - fn call - ( - &self, - storage : Vec< Child >, - super_former : Option< ParentFormer< Definition, > >, - ) - -> ParentFormer< Definition, > - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.children - { - former::ContainerAssign::assign( field, storage ); - } - else - { - super_former.storage.children = Some( storage ); - } - super_former - } -} - -// == end of generated for Parent in context of attribute container( former::VectorDefinition ) ] - -include!( "./only_test/subformer_subform.rs" ); -include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs index 30705da33c..08530df747 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs @@ -17,173 +17,10 @@ pub struct Child pub struct Parent { // #[ container( former::VectorDefinition ) ] - // #[ subform ] #[ setter( false ) ] children : Vec< Child >, } -// == begin of generated for Parent in context of attribute subform - -impl< Definition > ParentFormer< Definition > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, -{ - - #[ inline( always ) ] - pub fn _children_add_subformer_with_closure< Former2, Definition2, Types2 >( self ) -> - Former2 - where - Types2 : former::FormerDefinitionTypes - < - Storage = ChildFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2 : former::FormerDefinition - < - Types = Types2, - End = former::FormingEndClosure< Types2 >, - Storage = ChildFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2::End : former::FormingEnd< Definition2::Types >, - Former2 : former::FormerBegin - < - Definition2, - >, - { - let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if super_former.storage.children.is_none() - { - super_former.storage.children = Some( Default::default() ); - } - if let Some( ref mut children ) = super_former.storage.children - { - former::ContainerAdd::add( children, former::StoragePreform::preform( substorage ) ); - } - super_former - }; - Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) - } - - #[ inline( always ) ] - pub fn _children_add_subformer< Former2, Definition2 >( self ) -> - Former2 - where - Definition2 : former::FormerDefinition - < - End = ParentFormerAddChildrenEnd< Definition >, - Storage = < Child as former::EntityToStorage >::Storage, - Formed = Self, - Context = Self, - >, - Definition2::Types : former::FormerDefinitionTypes - < - Storage = < Child as former::EntityToStorage >::Storage, - Formed = Self, - Context = Self, - >, - Former2 : former::FormerBegin< Definition2 >, - { - Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) - } - - #[ inline( always ) ] - pub fn child( self, name : &str ) -> - ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - { - self._children_add_subformer - ::< ChildFormer< _ >, _, >() - .name( name ) - } - - // #[ inline( always ) ] - // pub fn _child( self ) -> - // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - // { - // self._children_add_subformer - // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() - // } - - #[ inline( always ) ] - pub fn _child( self ) -> - < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer - < - // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, - < - < Vec< Child > as former::ContainerAdd >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > - >::Definition, - > - >::Former - { - self._children_add_subformer - ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() - } - -} - -/// Handles the completion of and element of subformer's container. -pub struct ParentFormerAddChildrenEnd< Definition > -{ - _phantom : core::marker::PhantomData< fn( Definition ) >, -} - -impl< Definition > Default -for ParentFormerAddChildrenEnd< Definition > -{ - #[ inline( always ) ] - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } -} - -impl< Types2, Definition > former::FormingEnd< Types2, > -for ParentFormerAddChildrenEnd< Definition > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes - < - Storage = < Parent as former::EntityToStorage >::Storage, - >, - Types2 : former::FormerDefinitionTypes - < - Storage = < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, - Formed = ParentFormer< Definition >, - Context = ParentFormer< Definition >, - >, -{ - #[ inline( always ) ] - fn call - ( - &self, - substorage : Types2::Storage, - super_former : core::option::Option< Types2::Context >, - ) - -> Types2::Formed - { - let mut super_former = super_former.unwrap(); - if super_former.storage.children.is_none() - { - super_former.storage.children = Some( Default::default() ); - } - if let Some( ref mut fields ) = super_former.storage.children - { - former::ContainerAdd::add( fields, former::StoragePreform::preform( substorage ) ); - } - super_former - } -} - -// == end of generated for Parent in context of attribute subform - // == begin of generated for Parent in context of attribute container( former::VectorDefinition ) ] #[ automatically_derived ] @@ -267,5 +104,4 @@ where // == end of generated for Parent in context of attribute container( former::VectorDefinition ) ] -include!( "./only_test/subformer_subform.rs" ); include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_and_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs similarity index 82% rename from module/core/former/tests/inc/former_tests/subformer_and_container.rs rename to module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs index 4c628069c1..fdbba4aedc 100644 --- a/module/core/former/tests/inc/former_tests/subformer_and_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs @@ -38,20 +38,11 @@ where .name( name ) } - // #[ inline( always ) ] - // pub fn _child( self ) -> - // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - // { - // self._children_add_subformer - // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() - // } - } // == begin of generated // == end of generated -// xxx include!( "./only_test/subformer_subform.rs" ); include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 5429413205..f4b2b46153 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -77,9 +77,7 @@ mod former_tests mod subformer_implicit_container_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_and_container; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_and_container_manual; + mod subformer_subform_and_container; } From e69efe1db17ff33361431562d38e3bc6d9874eba Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 19:30:26 +0300 Subject: [PATCH 326/533] former : experimenting --- .../subformer_container_implicit.rs | 28 +++ .../subformer_implicit_container_manual.rs | 195 ------------------ ...ontainer.rs => subformer_subform_named.rs} | 0 .../subformer_subform_named_manual.rs | 80 +++++++ module/core/former/tests/inc/mod.rs | 14 +- 5 files changed, 116 insertions(+), 201 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/subformer_container_implicit.rs delete mode 100644 module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs rename module/core/former/tests/inc/former_tests/{subformer_implicit_container.rs => subformer_subform_named.rs} (100%) create mode 100644 module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs new file mode 100644 index 0000000000..24c1126ee9 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs @@ -0,0 +1,28 @@ +#![ allow( dead_code ) ] + +use super::*; + +/// Parameter description. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent required for the template. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + #[ container ] + // #[ setter( false ) ] + children : Vec< Child >, +} + +// == begin of generated + +// == end of generated + +include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs deleted file mode 100644 index 9b1524dbf5..0000000000 --- a/module/core/former/tests/inc/former_tests/subformer_implicit_container_manual.rs +++ /dev/null @@ -1,195 +0,0 @@ -#![ allow( dead_code ) ] - -use super::*; - -/// Parameter description. -#[ derive( Debug, Default, PartialEq, the_module::Former ) ] -pub struct Child -{ - name : String, - is_mandatory : bool, -} - -// impl< Context, Formed, End > former::EntityToDefinition< Context, Formed, End > -// for Child -// where -// End : former::FormingEnd< ChildFormerDefinitionTypes< Context, Formed > >, -// { -// type Definition = ChildFormerDefinition< Context, Formed, End >; -// } - -/// Parent required for the template. -#[ derive( Debug, Default, PartialEq, the_module::Former ) ] -// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] -// #[ derive( Debug, Default, PartialEq ) ] -pub struct Parent -{ - // #[ container( former::VectorDefinition ) ] - // #[ subform ] - #[ setter( false ) ] - children : Vec< Child >, -} - -// == begin of generated for Parent in context of attribute subform - -impl< Definition > ParentFormer< Definition > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, -{ - - #[ inline( always ) ] - pub fn _children_add_subformer_with_closure< Former2, Definition2, Types2 >( self ) -> - Former2 - where - Types2 : former::FormerDefinitionTypes - < - Storage = ChildFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2 : former::FormerDefinition - < - Types = Types2, - End = former::FormingEndClosure< Types2 >, - Storage = ChildFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2::End : former::FormingEnd< Definition2::Types >, - Former2 : former::FormerBegin - < - Definition2, - >, - { - let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if super_former.storage.children.is_none() - { - super_former.storage.children = Some( Default::default() ); - } - if let Some( ref mut children ) = super_former.storage.children - { - former::ContainerAdd::add( children, former::StoragePreform::preform( substorage ) ); - } - super_former - }; - Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) - } - - #[ inline( always ) ] - pub fn _children_add_subformer< Former2, Definition2 >( self ) -> - Former2 - where - Definition2 : former::FormerDefinition - < - End = ParentFormerAddChildrenEnd< Definition >, - Storage = < Child as former::EntityToStorage >::Storage, - Formed = Self, - Context = Self, - >, - Definition2::Types : former::FormerDefinitionTypes - < - Storage = < Child as former::EntityToStorage >::Storage, - Formed = Self, - Context = Self, - >, - Former2 : former::FormerBegin< Definition2 >, - { - Former2::former_begin( None, Some( self ), ParentFormerAddChildrenEnd::default() ) - } - - #[ inline( always ) ] - pub fn child( self, name : &str ) -> - ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - { - self._children_add_subformer - ::< ChildFormer< _ >, _, >() - .name( name ) - } - - // #[ inline( always ) ] - // pub fn _child( self ) -> - // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - // { - // self._children_add_subformer - // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() - // } - - #[ inline( always ) ] - pub fn _child( self ) -> - < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer - < - // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, - < - < Vec< Child > as former::ContainerAdd >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > - >::Definition, - > - >::Former - { - self._children_add_subformer - ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() - } - -} - -/// Handles the completion of and element of subformer's container. -pub struct ParentFormerAddChildrenEnd< Definition > -{ - _phantom : core::marker::PhantomData< fn( Definition ) >, -} - -impl< Definition > Default -for ParentFormerAddChildrenEnd< Definition > -{ - #[ inline( always ) ] - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } -} - -impl< Types2, Definition > former::FormingEnd< Types2, > -for ParentFormerAddChildrenEnd< Definition > -where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes - < - Storage = < Parent as former::EntityToStorage >::Storage, - >, - Types2 : former::FormerDefinitionTypes - < - Storage = < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, - Formed = ParentFormer< Definition >, - Context = ParentFormer< Definition >, - >, -{ - #[ inline( always ) ] - fn call - ( - &self, - substorage : Types2::Storage, - super_former : core::option::Option< Types2::Context >, - ) - -> Types2::Formed - { - let mut super_former = super_former.unwrap(); - if super_former.storage.children.is_none() - { - super_former.storage.children = Some( Default::default() ); - } - if let Some( ref mut fields ) = super_former.storage.children - { - former::ContainerAdd::add( fields, former::StoragePreform::preform( substorage ) ); - } - super_former - } -} - -// == end of generated for Parent in context of attribute subform - -include!( "./only_test/subformer_subform.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_implicit_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs similarity index 100% rename from module/core/former/tests/inc/former_tests/subformer_implicit_container.rs rename to module/core/former/tests/inc/former_tests/subformer_subform_named.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs new file mode 100644 index 0000000000..9d19953c89 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs @@ -0,0 +1,80 @@ +#![ allow( dead_code ) ] + +use super::*; + +/// Parameter description. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +// impl< Context, Formed, End > former::EntityToDefinition< Context, Formed, End > +// for Child +// where +// End : former::FormingEnd< ChildFormerDefinitionTypes< Context, Formed > >, +// { +// type Definition = ChildFormerDefinition< Context, Formed, End >; +// } + +/// Parent required for the template. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + #[ subform ] + // #[ setter( false ) ] + children : Vec< Child >, +} + +// == begin of custom + +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition, + Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn child( self, name : &str ) -> + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._children_add_subformer + ::< ChildFormer< _ >, _, >() + .name( name ) + } + + // #[ inline( always ) ] + // pub fn _child( self ) -> + // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + // { + // self._children_add_subformer + // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + // } + + #[ inline( always ) ] + pub fn _child( self ) -> + < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer + < + // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, + < + < Vec< Child > as former::ContainerAdd >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > + >::Definition, + > + >::Former + { + self._children_add_subformer + ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() + } + +} + +// == end of custom + +// == begin of generated for Parent in context of attribute subform + +// == end of generated for Parent in context of attribute subform + +include!( "./only_test/subformer_subform.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index f4b2b46153..5cb99865fd 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -62,19 +62,21 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod subformer_custom_experimental; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_container; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_container_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_implicit; #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_implicit_container; + mod subformer_subform; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_named; #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_implicit_container_manual; + mod subformer_subform_named_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_and_container; From 1d353a2bd6c9176c3382f2b33d4776cb81241cb9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 23:01:37 +0300 Subject: [PATCH 327/533] former : experimenting --- .../tests/inc/former_tests/subformer_container_implicit.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs index 24c1126ee9..3775f5be1a 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs @@ -16,6 +16,7 @@ pub struct Child // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { + #[ container( former::VectorDefinition ) ] #[ container ] // #[ setter( false ) ] children : Vec< Child >, From ab8e78bd32659676f50f69de4bf7e787d5c24fee Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 23:01:54 +0300 Subject: [PATCH 328/533] former : experimenting --- .../tests/inc/former_tests/subformer_container_implicit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs index 3775f5be1a..2af5c2b50f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs @@ -16,7 +16,7 @@ pub struct Child // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { - #[ container( former::VectorDefinition ) ] + // #[ container( former::VectorDefinition ) ] #[ container ] // #[ setter( false ) ] children : Vec< Child >, From 1cb44dc21c00ac2c3dcf90bd9f5bda859907ce28 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 23:24:13 +0300 Subject: [PATCH 329/533] former : experimenting --- .../inc/former_tests/attribute_feature.rs | 17 ++++++----- .../tests/inc/former_tests/visibility.rs | 28 +++++++++++++++++++ module/core/former/tests/inc/mod.rs | 3 +- 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/visibility.rs diff --git a/module/core/former/tests/inc/former_tests/attribute_feature.rs b/module/core/former/tests/inc/former_tests/attribute_feature.rs index 39640fa86f..1747cb0fd8 100644 --- a/module/core/former/tests/inc/former_tests/attribute_feature.rs +++ b/module/core/former/tests/inc/former_tests/attribute_feature.rs @@ -1,10 +1,13 @@ +#[ allow( unused_imports ) ] +use super::*; + // xxx : need to fix -// #[ derive( Former ) ] -// struct Foo -// { -// #[ cfg( feature = "baz" ) ] -// bar : i32, -// } +#[ derive( former::Former ) ] +struct Foo +{ + // #[ cfg( feature = "baz" ) ] + bar : i32, +} -// error => Unknown attribute #[cfg(feature = "baz")] \ No newline at end of file +// error => Unknown attribute #[cfg(feature = "baz")] diff --git a/module/core/former/tests/inc/former_tests/visibility.rs b/module/core/former/tests/inc/former_tests/visibility.rs new file mode 100644 index 0000000000..8908c3ee08 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/visibility.rs @@ -0,0 +1,28 @@ +//! Structure must be public. +//! Otherwise public trait can't have it as type. + +#[ allow( unused_imports ) ] +use super::*; + +// xxx : need to fix + +#[ derive( Debug, PartialEq, former::Former ) ] +// #[ debug ] +// #[ derive( Debug, PartialEq ) ] +pub struct Foo +{ + bar : i32, +} + + +// == begin of generated + +// == end of generated + +#[ test ] +fn basic() +{ + let got = Foo::former().bar( 13 ).form(); + let exp = Foo { bar : 13 }; + a_id!( got, exp ); +} \ No newline at end of file diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 5cb99865fd..836fc15bde 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -32,7 +32,7 @@ mod former_tests mod attribute_perform; mod attribute_setter; mod attribute_alias; - // mod attribute_feature; // zzz : write test + // mod attribute_feature; // xxx : write test mod string_slice_manual; mod string_slice; @@ -40,6 +40,7 @@ mod former_tests mod default_user_type; mod user_type_no_default; mod user_type_no_debug; + mod visibility; // xxx : write test mod name_collision_former_hashmap_without_parameter; mod name_collision_former_vector_without_parameter; From f36d9047b88e4eb61e8dae5e07dd96a0f1699739 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 23:54:11 +0300 Subject: [PATCH 330/533] macro_tools : attr::is_standard --- .../inc/former_tests/attribute_feature.rs | 42 ++++++- .../tests/inc/former_tests/visibility.rs | 3 - module/core/former/tests/inc/mod.rs | 4 +- module/core/macro_tools/src/attr.rs | 103 ++++++++++++++++++ module/core/macro_tools/tests/inc/attr.rs | 31 +++++- 5 files changed, 172 insertions(+), 11 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_feature.rs b/module/core/former/tests/inc/former_tests/attribute_feature.rs index 1747cb0fd8..3ed046a626 100644 --- a/module/core/former/tests/inc/former_tests/attribute_feature.rs +++ b/module/core/former/tests/inc/former_tests/attribute_feature.rs @@ -3,11 +3,43 @@ use super::*; // xxx : need to fix -#[ derive( former::Former ) ] -struct Foo +#[ derive( Debug, PartialEq ) ] +pub struct BaseCase { - // #[ cfg( feature = "baz" ) ] - bar : i32, + #[ cfg( feature = "enabled" ) ] + enabled : i32, + #[ cfg( feature = "disabled" ) ] + disabled : i32, } -// error => Unknown attribute #[cfg(feature = "baz")] +#[ derive( Debug, PartialEq, former::Former ) ] +// #[ debug ] +// #[ derive( Debug, PartialEq ) ] +pub struct Foo +{ + // #[ cfg( feature = "enabled" ) ] + #[ allow( dead_code ) ] + enabled : i32, + #[ cfg( feature = "disabled" ) ] + disabled : i32, +} + +// == begin of generated + +// == end of generated + +#[ test ] +fn basecase() +{ + let got = BaseCase { enabled : 13 }; + let exp = BaseCase { enabled : 13 }; + a_id!( got, exp ); +} + +// #[ test ] +// fn basic() +// { +// let got = Foo::former().enabled( 13 ).form(); +// let exp = Foo { enabled : 13 }; +// a_id!( got, exp ); +// } diff --git a/module/core/former/tests/inc/former_tests/visibility.rs b/module/core/former/tests/inc/former_tests/visibility.rs index 8908c3ee08..7df53933ac 100644 --- a/module/core/former/tests/inc/former_tests/visibility.rs +++ b/module/core/former/tests/inc/former_tests/visibility.rs @@ -4,8 +4,6 @@ #[ allow( unused_imports ) ] use super::*; -// xxx : need to fix - #[ derive( Debug, PartialEq, former::Former ) ] // #[ debug ] // #[ derive( Debug, PartialEq ) ] @@ -14,7 +12,6 @@ pub struct Foo bar : i32, } - // == begin of generated // == end of generated diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 836fc15bde..3a0e1be899 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -32,7 +32,7 @@ mod former_tests mod attribute_perform; mod attribute_setter; mod attribute_alias; - // mod attribute_feature; // xxx : write test + mod attribute_feature; // xxx : write test mod string_slice_manual; mod string_slice; @@ -40,7 +40,7 @@ mod former_tests mod default_user_type; mod user_type_no_default; mod user_type_no_debug; - mod visibility; // xxx : write test + mod visibility; mod name_collision_former_hashmap_without_parameter; mod name_collision_former_vector_without_parameter; diff --git a/module/core/macro_tools/src/attr.rs b/module/core/macro_tools/src/attr.rs index 8a9d37cb81..c3a3cc2707 100644 --- a/module/core/macro_tools/src/attr.rs +++ b/module/core/macro_tools/src/attr.rs @@ -97,6 +97,108 @@ pub( crate ) mod private return Ok( false ) } + /// Checks if the given attribute name is a standard Rust attribute. + /// + /// Standard Rust attributes are those which are recognized and processed + /// directly by the Rust compiler. They influence various aspects of compilation, + /// including but not limited to conditional compilation, optimization hints, + /// code visibility, and procedural macro behavior. + /// + /// This function is useful when developing tools that need to interact with or + /// understand the significance of specific attributes in Rust source code, such + /// as linters, code analyzers, or procedural macros. + /// + /// This function does not cover all possible attributes but includes many of the + /// common ones that are relevant to most Rust projects. Developers are encouraged + /// to update this function as needed to suit more specialized needs, especially + /// when dealing with nightly-only compiler attributes or deprecated ones. + /// + /// # Parameters + /// - `attr_name`: A string slice that holds the name of the attribute to check. + /// + /// # Returns + /// Returns `true` if `attr_name` is a recognized standard Rust attribute. Otherwise, + /// returns `false`. + /// + /// # Examples + /// + /// Standard attributes: + /// + /// ``` + /// assert_eq!( macro_tools::attr::is_standard( "cfg" ), true ); + /// assert_eq!( macro_tools::attr::is_standard( "inline" ), true ); + /// assert_eq!( macro_tools::attr::is_standard( "derive" ), true ); + /// ``` + /// + /// Non-standard or custom attributes: + /// + /// ``` + /// assert_eq!( macro_tools::attr::is_standard( "custom_attr" ), false ); + /// assert_eq!( macro_tools::attr::is_standard( "my_attribute" ), false ); + /// ``` + /// + + pub fn is_standard<'a>( attr_name : &'a str ) -> bool + { + match attr_name + { + // Conditional compilation + "cfg" | "cfg_attr" => true, + + // Compiler instructions and optimizations + "inline" | "repr" | "derive" | "allow" | "warn" | "deny" | "forbid" => true, + + // Testing attributes + "test" | "bench" => true, + + // Documentation attributes + "doc" => true, + + // Visibility and accessibility + "pub" => true, // This would typically need context to be accurate + + // Safety and ABI + "unsafe" | "no_mangle" | "extern" => true, + + // Module and Crate configuration + "path" | "macro_use" | "crate_type" | "crate_name" => true, + + // Linking + "link" | "link_name" | "link_section" => true, + + // Usage warnings + "must_use" => true, + + // Other attributes + "cold" | "export_name" | "global_allocator" => true, + + // Module handling + "used" | "unused" => true, + + // Procedural macros and hygiene + "proc_macro" | "proc_macro_derive" | "proc_macro_attribute" => true, + + // Stability attributes + "stable" | "unstable" | "rustc_const_unstable" | "rustc_const_stable" | + "rustc_diagnostic_item" | "rustc_deprecated" | "rustc_legacy_const_generics" => true, + + // Special compiler attributes + "feature" | "non_exhaustive" => true, + + // Future compatibility + "rustc_paren_sugar" | "rustc_insignificant_dtor" => true, + + // Type system extensions + "opaque" => true, + + // Miscellaneous + "track_caller" => true, + + // Default case + _ => false, + } + } + /// /// Attribute which is inner. /// @@ -316,6 +418,7 @@ pub mod exposed { equation, has_debug, + is_standard, AttributesInner, AttributesOuter, AttributedIdent, diff --git a/module/core/macro_tools/tests/inc/attr.rs b/module/core/macro_tools/tests/inc/attr.rs index 942289e7b3..6bba6e98fc 100644 --- a/module/core/macro_tools/tests/inc/attr.rs +++ b/module/core/macro_tools/tests/inc/attr.rs @@ -4,7 +4,7 @@ use super::*; // #[ test ] -fn basic() +fn parse() { let attr : syn::Attribute = syn::parse_quote!( #[ default( 31 ) ] ); @@ -22,3 +22,32 @@ fn basic() a_id!( code_to_str!( got.right ), "31".to_string() ); } + +#[ test ] +fn is_standard_standard() +{ + // Test a selection of attributes known to be standard + assert!( is_standard( "cfg" ), "Expected 'cfg' to be a standard attribute." ); + assert!( is_standard( "derive" ), "Expected 'derive' to be a standard attribute." ); + assert!( is_standard( "inline" ), "Expected 'inline' to be a standard attribute." ); + assert!( is_standard( "test" ), "Expected 'test' to be a standard attribute." ); + assert!( is_standard( "doc" ), "Expected 'doc' to be a standard attribute." ); +} + +#[ test ] +fn is_standard_non_standard() +{ + // Test some made-up attributes that should not be standard + assert!( !is_standard( "custom_attr" ), "Expected 'custom_attr' to not be a standard attribute." ); + assert!( !is_standard( "my_attribute" ), "Expected 'my_attribute' to not be a standard attribute." ); + assert!( !is_standard( "special_feature" ), "Expected 'special_feature' to not be a standard attribute." ); +} + +#[ test ] +fn is_standard_edge_cases() +{ + // Test edge cases like empty strings or unusual input + assert!( !is_standard( "" ), "Expected empty string to not be a standard attribute." ); + assert!( !is_standard( " " ), "Expected a single space to not be a standard attribute." ); + assert!( !is_standard( "cfg_attr_extra" ), "Expected 'cfg_attr_extra' to not be a standard attribute." ); +} From 59700445bda3aa04d1dc46b836b784deee2c5eb5 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 23:56:42 +0300 Subject: [PATCH 331/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index a58a36007c..9416c41c9b 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -48,6 +48,12 @@ impl Attributes let key_ident = attr.path().get_ident() .ok_or_else( || syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ) )?; let key_str = format!( "{}", key_ident ); + + if attr::is_standard( &key_str ) + { + continue; + } + match key_str.as_ref() { "default" => @@ -117,9 +123,6 @@ impl Attributes // let attr_alias = syn::parse2::< AttributeAlias >( attr.tokens.clone() )?; // alias.replace( attr_alias ); } - "doc" => - { - } _ => { return Err( syn_err!( attr, "Unknown attribute {}", qt!{ #attr } ) ); From 240757365a42b80639b723c59a2a7bbf9d05a25d Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 30 Apr 2024 23:57:16 +0300 Subject: [PATCH 332/533] former : experimenting --- .../tests/inc/former_tests/attribute_feature.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_feature.rs b/module/core/former/tests/inc/former_tests/attribute_feature.rs index 3ed046a626..7acf8c06a9 100644 --- a/module/core/former/tests/inc/former_tests/attribute_feature.rs +++ b/module/core/former/tests/inc/former_tests/attribute_feature.rs @@ -17,7 +17,7 @@ pub struct BaseCase // #[ derive( Debug, PartialEq ) ] pub struct Foo { - // #[ cfg( feature = "enabled" ) ] + #[ cfg( feature = "enabled" ) ] #[ allow( dead_code ) ] enabled : i32, #[ cfg( feature = "disabled" ) ] @@ -36,10 +36,10 @@ fn basecase() a_id!( got, exp ); } -// #[ test ] -// fn basic() -// { -// let got = Foo::former().enabled( 13 ).form(); -// let exp = Foo { enabled : 13 }; -// a_id!( got, exp ); -// } +#[ test ] +fn basic() +{ + let got = Foo::former().enabled( 13 ).form(); + let exp = Foo { enabled : 13 }; + a_id!( got, exp ); +} From 7456208146ca8ffe01c411685d152a1b296bd6eb Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 00:04:42 +0300 Subject: [PATCH 333/533] former : experimenting --- .../inc/former_tests/attribute_feature.rs | 2 - .../former_tests/container_former_hashmap.rs | 14 ----- .../inc/former_tests/container_former_vec.rs | 1 + .../tests/inc/former_tests/only_test/basic.rs | 56 +++++++++---------- .../inc/former_tests/subformer_subform.rs | 3 - .../former_tests/subformer_subform_manual.rs | 1 - module/core/former/tests/inc/mod.rs | 2 +- 7 files changed, 29 insertions(+), 50 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_feature.rs b/module/core/former/tests/inc/former_tests/attribute_feature.rs index 7acf8c06a9..20dea37cf8 100644 --- a/module/core/former/tests/inc/former_tests/attribute_feature.rs +++ b/module/core/former/tests/inc/former_tests/attribute_feature.rs @@ -1,8 +1,6 @@ #[ allow( unused_imports ) ] use super::*; -// xxx : need to fix - #[ derive( Debug, PartialEq ) ] pub struct BaseCase { diff --git a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs index 0cf7183b27..4f5a0f7d82 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs @@ -103,17 +103,3 @@ fn replace() a_id!( got, exp ); } - -// xxx -// #[ test ] -// fn entity_to() -// { -// -// let got = < Vec< i32 > as former::EntityToFormer< former::VectorDefinition< i32, (), Vec< i32 >, former::ReturnPreformed > > > -// ::Former::new_precise( former::ReturnPreformed ) -// .add( 13 ) -// .form(); -// let exp = vec![ 13 ]; -// a_id!( got, exp ); -// -// } 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 10773220b4..e25a889e30 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 @@ -105,6 +105,7 @@ fn replace() // +// qqq : make similar test for all containers #[ test ] fn entity_to() { diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index 0808b22625..1bdeefd8ad 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -17,9 +17,8 @@ tests_impls! a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new_coercing( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); - // let former2 = Struct1Former::< Struct1FormerDefinition >::new_coercing( former::ReturnPreformed ); - // a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); - // xxx : uncomment + let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new_precise( former::ReturnPreformed ); + a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); a_id!( command.int_1, 0 ); @@ -307,7 +306,6 @@ tests_impls! // ::< Struct1FormerDefinition< _, _, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > :: < - Struct1FormerDefinition< (), Struct1, former::FormingEndClosure< Struct1FormerDefinitionTypes< (), Struct1 > > > > ::new_coercing( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) @@ -317,31 +315,31 @@ tests_impls! a_id!( got, exp ); // xxx : switch on or remove -// // default explicit params with wrapper and closure -// let got = Struct1Former -// // ::< Struct1FormerWithClosure< (), Struct1 > > -// :: -// < -// Struct1FormerDefinition< (), Struct1, _ > -// > -// ::new_coercing( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) -// .int_1( 13 ) -// .form(); -// let exp = Struct1::former().int_1( 13 ).form(); -// a_id!( got, exp ); -// -// // default explicit params with wrapper and closure -// let got = Struct1Former -// // ::< Struct1FormerWithClosure< (), Struct1 > > -// :: -// < -// Struct1FormerDefinition< (), Struct1, _ > -// > -// ::new_coercing( | storage, _context | { former::StoragePreform::preform( storage ) } ) -// .int_1( 13 ) -// .form(); -// let exp = Struct1::former().int_1( 13 ).form(); -// a_id!( got, exp ); + // default explicit params with wrapper and closure + let got = Struct1Former + // ::< Struct1FormerWithClosure< (), Struct1 > > + :: + < + Struct1FormerDefinition< (), Struct1, _ > + > + ::new_precise( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + + // default explicit params with wrapper and closure + let got = Struct1Former + // ::< Struct1FormerWithClosure< (), Struct1 > > + :: + < + Struct1FormerDefinition< (), Struct1, _ > + > + ::new_precise( | storage, _context | { former::StoragePreform::preform( storage ) } ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform.rs b/module/core/former/tests/inc/former_tests/subformer_subform.rs index bdc2d5f5bf..29746e2b39 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform.rs @@ -14,9 +14,6 @@ pub struct Child #[ derive( Debug, Default, PartialEq, the_module::Former ) ] pub struct Parent { - // xxx : is definition as argument fine? - // xxx : add another test to make sure attributes container and subform are compatible - // #[ container( former::VectorDefinition ) ] #[ subform ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index f12d4f78d2..5c7f4ee7f5 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -2,7 +2,6 @@ use super::*; -// xxx : rename /// Parameter description. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] pub struct Child diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 3a0e1be899..a26fc515b6 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -32,7 +32,7 @@ mod former_tests mod attribute_perform; mod attribute_setter; mod attribute_alias; - mod attribute_feature; // xxx : write test + mod attribute_feature; mod string_slice_manual; mod string_slice; From be26b7404e0d64d36d3e707da44373bbdb70f88a Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 00:08:42 +0300 Subject: [PATCH 334/533] former : experimenting --- module/core/former/src/container.rs | 2 +- module/core/former/src/hash_map.rs | 2 +- module/core/former/src/hash_set.rs | 2 +- module/core/former/src/vector.rs | 2 +- .../tests/inc/former_tests/a_basic_manual.rs | 2 +- .../a_containers_with_subformer_manual.rs | 2 +- .../inc/former_tests/a_primitives_manual.rs | 2 +- .../former_tests/container_former_common.rs | 8 +- .../former_tests/container_former_hashmap.rs | 8 +- .../former_tests/container_former_hashset.rs | 8 +- .../inc/former_tests/container_former_vec.rs | 14 ++-- .../tests/inc/former_tests/only_test/basic.rs | 73 ++++++++----------- .../only_test/containers_with_subformer.rs | 2 +- .../inc/former_tests/only_test/primitives.rs | 2 +- .../former_tests/only_test/string_slice.rs | 2 +- .../parametrized_struct_manual.rs | 4 +- .../inc/former_tests/string_slice_manual.rs | 2 +- module/core/former_meta/src/derive/former.rs | 2 +- 18 files changed, 63 insertions(+), 76 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index a1460c73fd..9960356f09 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -227,7 +227,7 @@ where /// // zzz : update description #[ inline( always ) ] - pub fn new_precise( end : Definition::End ) -> Self + pub fn new( end : Definition::End ) -> Self { Self::begin_precise ( diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 6ebc355f90..6e337ad1ac 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -225,7 +225,7 @@ where { fn former() -> HashMapSubformer< K, E, (), HashMap< K, E >, ReturnStorage > { - HashMapSubformer::< K, E, (), HashMap< K, E >, ReturnStorage >::new_precise( ReturnStorage::default() ) + HashMapSubformer::< K, E, (), HashMap< K, E >, ReturnStorage >::new( ReturnStorage::default() ) } } diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 2fcf83bb8a..65366617e7 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -203,7 +203,7 @@ where { fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage > { - HashSetSubformer::< K, (), HashSet< K >, ReturnStorage >::new_precise( ReturnStorage::default() ) + HashSetSubformer::< K, (), HashSet< K >, ReturnStorage >::new( ReturnStorage::default() ) } } diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 13f7762a27..6d874a001e 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -154,7 +154,7 @@ impl< E > VecExt< E > for Vec< E > { fn former() -> VectorSubformer< E, (), Vec< E >, ReturnStorage > { - VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new_precise( ReturnStorage::default() ) + VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new( ReturnStorage::default() ) } } diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index d2475ae738..9055ac809e 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -196,7 +196,7 @@ where } #[ inline( always ) ] - pub fn new_precise( on_end : Definition::End ) -> Self + pub fn new( on_end : Definition::End ) -> Self { Self::begin_coercing( None, None, on_end ) } diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 7eab803186..8c59d8e506 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -261,7 +261,7 @@ where #[doc = r" Construct new instance of former with default parameters."] #[doc = r""] #[inline(always)] - pub fn new_precise(on_end: Definition::End) -> Self + pub fn new(on_end: Definition::End) -> Self { Self::begin_coercing(None, None, on_end) } diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index f7c6b93291..655d810c25 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -205,7 +205,7 @@ where // zzz : update description #[ inline( always ) ] - pub fn new_precise( on_end : Definition::End ) -> Self + pub fn new( on_end : Definition::End ) -> Self { Self::begin_precise( None, None, on_end ) } diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index 3ad2cdf80f..2cd4f4bb18 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -57,7 +57,7 @@ fn begin_and_custom_end() let exp = 13.1; a_id!( got, exp ); - let got = the_module::VectorSubformer::new_precise( return_13 ) + let got = the_module::VectorSubformer::new( return_13 ) .add( "a" ) .add( "b" ) .form(); @@ -138,7 +138,7 @@ fn custom_definition() let exp = 13; a_id!( got, exp ); - let got = the_module::ContainerSubformer::< String, Return13 >::new_precise( Return13 ) + let got = the_module::ContainerSubformer::< String, Return13 >::new( Return13 ) .add( "a" ) .add( "b" ) .form(); @@ -265,14 +265,14 @@ fn custom_definition_custom_end() } let end_wrapper : the_module::FormingEndClosure< Return13 > = the_module::FormingEndClosure::new( return_13 ); - let got = the_module::ContainerSubformer::< String, Return13 >::new_precise( end_wrapper ) + let got = the_module::ContainerSubformer::< String, Return13 >::new( end_wrapper ) .add( "a" ) .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); - let got = the_module::ContainerSubformer::< String, Return13 >::new_precise( return_13.into() ) + let got = the_module::ContainerSubformer::< String, Return13 >::new( return_13.into() ) .add( "a" ) .add( "b" ) .form(); diff --git a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs index 4f5a0f7d82..0ef87ce578 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs @@ -16,7 +16,7 @@ fn add() let got : HashMap< String, String > = the_module ::ContainerSubformer ::< ( String, String ), former::HashMapDefinition< String, String, (), HashMap< String, String >, the_module::ReturnStorage > > - ::new_precise( former::ReturnStorage ) + ::new( former::ReturnStorage ) .add( ( "a".into(), "x".into() ) ) .add( ( "b".into(), "y".into() ) ) .form(); @@ -30,7 +30,7 @@ fn add() // expliccit with HashMapSubformer let got : HashMap< String, String > = the_module::HashMapSubformer::< String, String, (), HashMap< String, String >, the_module::ReturnStorage > - ::new_precise( former::ReturnStorage ) + ::new( former::ReturnStorage ) .add( ( "a".into(), "x".into() ) ) .add( ( "b".into(), "y".into() ) ) .form(); @@ -43,7 +43,7 @@ fn add() // compact with HashMapSubformer - let got : HashMap< String, String > = the_module::HashMapSubformer::new_precise( former::ReturnStorage ) + let got : HashMap< String, String > = the_module::HashMapSubformer::new( former::ReturnStorage ) .add( ( "a".into(), "x".into() ) ) .add( ( "b".into(), "y".into() ) ) .form(); @@ -91,7 +91,7 @@ fn add() fn replace() { - let got : HashMap< String, String > = the_module::HashMapSubformer::new_precise( former::ReturnStorage ) + let got : HashMap< String, String > = the_module::HashMapSubformer::new( former::ReturnStorage ) .add( ( "x".to_string(), "y".to_string() ) ) .replace( hmap![ "a".to_string() => "x".to_string(), "b".to_string() => "y".to_string(), ] ) .form(); diff --git a/module/core/former/tests/inc/former_tests/container_former_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs index c175305de1..dcd035a4fc 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashset.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashset.rs @@ -16,7 +16,7 @@ fn add() let got : HashSet< String > = the_module ::ContainerSubformer ::< String, former::HashSetDefinition< String, (), HashSet< String >, the_module::ReturnStorage > > - ::new_precise( former::ReturnStorage ) + ::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -30,7 +30,7 @@ fn add() // expliccit with HashSetSubformer let got : HashSet< String > = the_module::HashSetSubformer::< String, (), HashSet< String >, the_module::ReturnStorage > - ::new_precise( former::ReturnStorage ) + ::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -43,7 +43,7 @@ fn add() // compact with HashSetSubformer - let got : HashSet< String > = the_module::HashSetSubformer::new_precise( former::ReturnStorage ) + let got : HashSet< String > = the_module::HashSetSubformer::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -91,7 +91,7 @@ fn add() fn replace() { - let got : HashSet< String > = the_module::HashSetSubformer::new_precise( former::ReturnStorage ) + let got : HashSet< String > = the_module::HashSetSubformer::new( former::ReturnStorage ) .add( "x" ) .replace( hset![ "a".to_string(), "b".to_string() ] ) .form(); 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 e25a889e30..606b62fcb6 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 @@ -15,7 +15,7 @@ fn add() let got : Vec< String > = the_module ::ContainerSubformer ::< String, former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > > - ::new_precise( former::ReturnStorage ) + ::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -29,7 +29,7 @@ fn add() // expliccit with VectorSubformer let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage > - ::new_precise( former::ReturnStorage ) + ::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -42,7 +42,7 @@ fn add() // compact with VectorSubformer - let got : Vec< String > = the_module::VectorSubformer::new_precise( former::ReturnStorage ) + let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -90,7 +90,7 @@ fn add() fn replace() { - let got : Vec< String > = the_module::VectorSubformer::new_precise( former::ReturnStorage ) + let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) .add( "x" ) .replace( vec![ "a".to_string(), "b".to_string() ] ) .form(); @@ -112,7 +112,7 @@ fn entity_to() // qqq : uncomment and make it working // let got = < Vec< i32 > as former::EntityToFormer< former::VectorDefinition< i32, (), Vec< i32 >, former::ReturnPreformed > > > - // ::Former::new_precise( former::ReturnPreformed ) + // ::Former::new( former::ReturnPreformed ) // .add( 13 ) // .form(); // let exp = vec![ 13 ]; @@ -126,7 +126,7 @@ fn entity_to() // < // Vec< i32 >FormerDefinition< (), Vec< i32 >, former::ReturnPreformed > // > -// >::Former::new_precise( former::ReturnPreformed ); +// >::Former::new( former::ReturnPreformed ); // a_id!( got.int_1, exp.storage.int_1 ); // // let got = < Vec< i32 > as former::EntityToStorage >::Storage::default(); @@ -136,7 +136,7 @@ fn entity_to() // < // < Vec< i32 > as former::EntityToDefinition< (), Vec< i32 >, former::ReturnPreformed > >::Definition // > -// >::Former::new_precise( former::ReturnPreformed ); +// >::Former::new( former::ReturnPreformed ); // a_id!( got.int_1, exp.storage.int_1 ); } diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index 1bdeefd8ad..37f2c2695b 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -17,7 +17,7 @@ tests_impls! a_id!( print!( "{:?}", former.on_end ), print!( "{:?}", Some( the_module::ReturnPreformed ) ) ); let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new_coercing( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); - let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new_precise( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let command = Struct1::former().form(); @@ -36,7 +36,7 @@ tests_impls! fn entity_to() { - let got = < Struct1 as former::EntityToFormer< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > >::Former::new_precise( former::ReturnPreformed ) + let got = < Struct1 as former::EntityToFormer< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > >::Former::new( former::ReturnPreformed ) .int_1( 13 ) .form(); let exp = Struct1 { int_1 : 13 }; @@ -49,7 +49,7 @@ tests_impls! < Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > - >::Former::new_precise( former::ReturnPreformed ); + >::Former::new( former::ReturnPreformed ); a_id!( got.int_1, exp.storage.int_1 ); let got = < Struct1 as former::EntityToStorage >::Storage::default(); @@ -59,7 +59,7 @@ tests_impls! < < Struct1 as former::EntityToDefinition< (), Struct1, former::ReturnPreformed > >::Definition > - >::Former::new_precise( former::ReturnPreformed ); + >::Former::new( former::ReturnPreformed ); a_id!( got.int_1, exp.storage.int_1 ); } @@ -249,12 +249,12 @@ tests_impls! // - fn new() + fn new_coercing() { // basic case let former = Struct1::former(); - let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new_precise( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let exp = former.form(); let got = former2.form(); @@ -314,43 +314,16 @@ tests_impls! let exp = Struct1::former().int_1( 13 ).form(); a_id!( got, exp ); -// xxx : switch on or remove - // default explicit params with wrapper and closure - let got = Struct1Former - // ::< Struct1FormerWithClosure< (), Struct1 > > - :: - < - Struct1FormerDefinition< (), Struct1, _ > - > - ::new_precise( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - - // default explicit params with wrapper and closure - let got = Struct1Former - // ::< Struct1FormerWithClosure< (), Struct1 > > - :: - < - Struct1FormerDefinition< (), Struct1, _ > - > - ::new_precise( | storage, _context | { former::StoragePreform::preform( storage ) } ) - .int_1( 13 ) - .form(); - let exp = Struct1::former().int_1( 13 ).form(); - a_id!( got, exp ); - } // - fn new_precise() + fn new() { // basic case let former = Struct1::former(); - let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new_precise( former::ReturnPreformed ); + let former2 = Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new( former::ReturnPreformed ); a_id!( std::mem::size_of_val( &former ), std::mem::size_of_val( &former2 ) ); let exp = former.form(); let got = former2.form(); @@ -364,7 +337,7 @@ tests_impls! Struct1FormerDefinition< (), Struct1, _ >, > - ::new_precise( former::ReturnPreformed ) + ::new( former::ReturnPreformed ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -380,24 +353,39 @@ tests_impls! // ::< Struct1FormerDefinition< (), Struct1, _ > > :: < - Struct1FormerDefinition< (), Struct1, _ >, > - ::new_precise( end_wrapper ) + ::new( end_wrapper ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); a_id!( got, exp ); + // + // default explicit params with wrapper and closure let got = Struct1Former - // ::< Struct1FormerDefinition< (), Struct1, _ > > + // ::< Struct1FormerWithClosure< (), Struct1 > > :: < + Struct1FormerDefinition< (), Struct1, _ > + > + ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) + .int_1( 13 ) + .form(); + let exp = Struct1::former().int_1( 13 ).form(); + a_id!( got, exp ); + // + + // default explicit params with wrapper and closure + let got = Struct1Former + // ::< Struct1FormerDefinition< (), Struct1, _ > > + :: + < Struct1FormerDefinition< (), Struct1, _ >, > - ::new_precise( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) + ::new( former::FormingEndClosure::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -408,10 +396,9 @@ tests_impls! // ::< Struct1FormerDefinition< _, _, _ > > :: < - Struct1FormerDefinition< _, _, _ >, > - ::new_precise( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) + ::new( former::FormingEndClosure::new( | storage, _context : Option< () > | { former::StoragePreform::preform( storage ) } ) ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); @@ -565,8 +552,8 @@ tests_index! custom_definition_params, begin_coercing, begin_precise, + new_coercing, new, - new_precise, preform, definition, storage, diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index 78ac8522c3..ccdc331e91 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -75,7 +75,7 @@ tests_impls! // closure with helper let got : Struct1 = Struct1Former ::< Struct1FormerDefinition< (), Struct1, _ > > - ::new_precise( | storage, _context | { former::StoragePreform::preform( storage ) } ) + ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) .vec_1().replace( vec![ "a".to_string(), "b".to_string() ] ).end() .form(); let exp : Struct1 = Struct1 diff --git a/module/core/former/tests/inc/former_tests/only_test/primitives.rs b/module/core/former/tests/inc/former_tests/only_test/primitives.rs index 3c87c071a4..c38fea9bf8 100644 --- a/module/core/former/tests/inc/former_tests/only_test/primitives.rs +++ b/module/core/former/tests/inc/former_tests/only_test/primitives.rs @@ -40,7 +40,7 @@ tests_impls! // default explicit params with wrapper and closure let got = Struct1Former ::< Struct1FormerDefinition< (), Struct1, _ > > - ::new_precise( | storage, _context | { former::StoragePreform::preform( storage ) } ) + ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) .int_1( 13 ) .form(); let exp = Struct1::former().int_1( 13 ).form(); diff --git a/module/core/former/tests/inc/former_tests/only_test/string_slice.rs b/module/core/former/tests/inc/former_tests/only_test/string_slice.rs index 88dd2ccf1f..1d7650ea6f 100644 --- a/module/core/former/tests/inc/former_tests/only_test/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/only_test/string_slice.rs @@ -34,7 +34,7 @@ tests_impls! // default explicit params with wrapper and closure let got = Struct1Former ::< Struct1FormerDefinition< (), Struct1, _ > > - ::new_precise( | storage, _context | { former::StoragePreform::preform( storage ) } ) + ::new( | storage, _context | { former::StoragePreform::preform( storage ) } ) .string_slice_1( "abc" ) .form(); let exp = Struct1::former().string_slice_1( "abc" ).form(); diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 78ca6b6ad2..667c8c1bd3 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -230,13 +230,13 @@ where } #[ inline( always ) ] - pub fn new_precise( on_end : Definition::End ) -> Self + pub fn new( on_end : Definition::End ) -> Self { Self::begin_coercing( None, None, on_end ) } #[ inline( always ) ] - pub fn new< IntoEnd >( end : IntoEnd ) -> Self + pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End > { Self::begin_coercing( None, None, end ) diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 92044c9b30..6d47410651 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -168,7 +168,7 @@ where } #[ inline( always ) ] - pub fn new_precise( on_end : Definition::End ) -> Self + pub fn new( on_end : Definition::End ) -> Self { Self::begin_coercing( None, None, on_end ) } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 9416c41c9b..de6d32e9bf 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1813,7 +1813,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// // zzz : improve description #[ inline( always ) ] - pub fn new_precise( on_end : Definition::End ) -> Self + pub fn new( on_end : Definition::End ) -> Self { Self::begin_coercing( None, None, on_end ) } From e2869844b774b66cdcea61283093fe7cb7e34d7f Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 00:10:29 +0300 Subject: [PATCH 335/533] former : experimenting --- module/core/former/src/container.rs | 8 ++++---- .../core/former/tests/inc/former_tests/a_basic_manual.rs | 4 ++-- .../former_tests/a_containers_with_subformer_manual.rs | 4 ++-- .../former/tests/inc/former_tests/a_primitives_manual.rs | 4 ++-- .../tests/inc/former_tests/container_former_common.rs | 4 ++-- .../tests/inc/former_tests/container_former_hashmap.rs | 4 ++-- .../tests/inc/former_tests/container_former_hashset.rs | 2 +- .../former/tests/inc/former_tests/container_former_vec.rs | 2 +- .../core/former/tests/inc/former_tests/only_test/basic.rs | 8 ++++---- .../former_tests/only_test/containers_with_subformer.rs | 2 +- .../tests/inc/former_tests/only_test/string_slice.rs | 2 +- .../tests/inc/former_tests/parametrized_struct_manual.rs | 2 +- .../former/tests/inc/former_tests/string_slice_manual.rs | 2 +- .../former/tests/inc/former_tests/subformer_custom.rs | 4 ++-- .../inc/former_tests/subformer_custom_experimental.rs | 2 +- module/core/former_meta/src/derive/former.rs | 4 ++-- 16 files changed, 29 insertions(+), 29 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 9960356f09..122e47610a 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -141,7 +141,7 @@ where /// Begins the building process, optionally initializing with a context and storage. #[ inline( always ) ] - pub fn begin_precise + pub fn begin ( mut storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, @@ -229,7 +229,7 @@ where #[ inline( always ) ] pub fn new( end : Definition::End ) -> Self { - Self::begin_precise + Self::begin ( None, None, @@ -243,7 +243,7 @@ where where IntoEnd : Into< Definition::End >, { - Self::begin_precise + Self::begin ( None, None, @@ -289,7 +289,7 @@ where ) -> Self { - Self::begin_precise( storage, context, on_end ) + Self::begin( storage, context, on_end ) } } diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 9055ac809e..2b8aeefd92 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -209,7 +209,7 @@ where } #[ inline( always ) ] - pub fn begin_precise + pub fn begin ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -308,7 +308,7 @@ where -> Self { debug_assert!( storage.is_none() ); - Self::begin_precise( None, context, on_end ) + Self::begin( None, context, on_end ) } } diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 8c59d8e506..07ab4afe6e 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -281,7 +281,7 @@ where #[doc = r" Begin the process of forming. Expects context of forming to return it after forming."] #[doc = r""] #[inline(always)] - pub fn begin_precise(mut storage: core::option::Option<::Storage>, context: core::option::Option<::Context>, on_end: ::End,) -> Self + pub fn begin(mut storage: core::option::Option<::Storage>, context: core::option::Option<::Context>, on_end: ::End,) -> Self { if storage.is_none() { @@ -441,7 +441,7 @@ where fn former_begin(storage: core::option::Option, context: core::option::Option, on_end: Definition::End,) -> Self { debug_assert!(storage.is_none()); - Self::begin_precise(None, context, on_end) + Self::begin(None, context, on_end) } } diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 655d810c25..a82e9cf202 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -207,7 +207,7 @@ where #[ inline( always ) ] pub fn new( on_end : Definition::End ) -> Self { - Self::begin_precise( None, None, on_end ) + Self::begin( None, None, on_end ) } #[ inline( always ) ] @@ -224,7 +224,7 @@ where } #[ inline( always ) ] - pub fn begin_precise + pub fn begin ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index 2cd4f4bb18..2781556450 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -50,7 +50,7 @@ fn begin_and_custom_end() { 13.1 } - let got = the_module::VectorSubformer::begin_precise( None, None, return_13 ) + let got = the_module::VectorSubformer::begin( None, None, return_13 ) .add( "a" ) .add( "b" ) .form(); @@ -77,7 +77,7 @@ fn begin_and_custom_end() 13.1 } } - let got = the_module::VectorSubformer::begin_precise( None, Some( 10.0 ), context_plus_13 ) + let got = the_module::VectorSubformer::begin( None, Some( 10.0 ), context_plus_13 ) .add( "a" ) .add( "b" ) .form(); diff --git a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs index 0ef87ce578..da24fc1ec1 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs @@ -54,10 +54,10 @@ fn add() ]; a_id!( got, exp ); - // with begin_precise + // with begin let got : HashMap< String, String > = the_module::HashMapSubformer - ::begin_precise( Some( hmap![ "a".to_string() => "x".to_string() ] ), Some( () ), former::ReturnStorage ) + ::begin( Some( hmap![ "a".to_string() => "x".to_string() ] ), Some( () ), former::ReturnStorage ) .add( ( "b".into(), "y".into() ) ) .form(); let exp = hmap! diff --git a/module/core/former/tests/inc/former_tests/container_former_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs index dcd035a4fc..697d73e76c 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashset.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashset.rs @@ -57,7 +57,7 @@ fn add() // with begin_coercing let got : HashSet< String > = the_module::HashSetSubformer - ::begin_precise( Some( hset![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) + ::begin( Some( hset![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) .add( "b" ) .form(); let exp = hset! 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 606b62fcb6..f358ee727b 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 @@ -56,7 +56,7 @@ fn add() // with begin_coercing let got : Vec< String > = the_module::VectorSubformer - ::begin_precise( Some( vec![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) + ::begin( Some( vec![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) .add( "b" ) .form(); let exp = vec! diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index 37f2c2695b..9a07de6bde 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -201,7 +201,7 @@ tests_impls! // - fn begin_precise() + fn begin() { // custom params @@ -212,7 +212,7 @@ tests_impls! Struct1FormerDefinition< i32, i32, _ > > - ::begin_precise + ::begin ( None, Some( 3 ), @@ -233,7 +233,7 @@ tests_impls! Struct1FormerDefinition< i32, i32, former::FormingEndClosure< Struct1FormerDefinitionTypes< i32, i32 > > > > - ::begin_precise + ::begin ( None, Some( 3 ), @@ -551,7 +551,7 @@ tests_index! former_begin, custom_definition_params, begin_coercing, - begin_precise, + begin, new_coercing, new, preform, diff --git a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs index ccdc331e91..042d36e538 100644 --- a/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/only_test/containers_with_subformer.rs @@ -103,7 +103,7 @@ tests_impls! // closure with helper let got : Struct1 = Struct1Former ::< Struct1FormerDefinition< (), Struct1, _ > > - ::begin_precise( None, None, | storage, _context | { former::StoragePreform::preform( storage ) } ) + ::begin( None, None, | storage, _context | { former::StoragePreform::preform( storage ) } ) .vec_1().replace( vec![ "a".to_string(), "b".to_string() ] ).end() .form(); let exp : Struct1 = Struct1 diff --git a/module/core/former/tests/inc/former_tests/only_test/string_slice.rs b/module/core/former/tests/inc/former_tests/only_test/string_slice.rs index 1d7650ea6f..2ed7eb90c5 100644 --- a/module/core/former/tests/inc/former_tests/only_test/string_slice.rs +++ b/module/core/former/tests/inc/former_tests/only_test/string_slice.rs @@ -43,7 +43,7 @@ tests_impls! // closure with helper let got : Struct1 = Struct1Former ::< Struct1FormerDefinition< (), Struct1, _ > > - ::begin_precise( None, None, | storage, _context | { former::StoragePreform::preform( storage ) } ) + ::begin( None, None, | storage, _context | { former::StoragePreform::preform( storage ) } ) .string_slice_1( "abc" ) .form(); let exp = Struct1::former().string_slice_1( "abc" ).form(); diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 667c8c1bd3..0ddad4fd47 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -243,7 +243,7 @@ where } #[ inline( always ) ] - pub fn begin_precise( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self + pub fn begin( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self { if storage.is_none() { diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 6d47410651..5c540d1aac 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -181,7 +181,7 @@ where } #[ inline( always ) ] - pub fn begin_precise + pub fn begin ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, diff --git a/module/core/former/tests/inc/former_tests/subformer_custom.rs b/module/core/former/tests/inc/former_tests/subformer_custom.rs index 5bf0331956..eb4cb2d579 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom.rs @@ -105,7 +105,7 @@ where let former : CommandFormer< _, _ > - = CommandFormer::begin_precise( None, Some( self ), on_end ); + = CommandFormer::begin( None, Some( self ), on_end ); former.name( name ) } @@ -119,7 +119,7 @@ where where IntoName : core::convert::Into< String >, { - let former = CommandFormer::begin_precise( None, Some( self ), AggregatorFormerCommandEnd ); + let former = CommandFormer::begin( None, Some( self ), AggregatorFormerCommandEnd ); former.name( name ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs index 4d22cbf714..4fcdec6101 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs @@ -55,7 +55,7 @@ where CommandAsSubformerEnd< K, Self >, { let former - = CommandFormer::begin_precise + = CommandFormer::begin ( None, Some( self ), diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index de6d32e9bf..d5f561173c 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1840,7 +1840,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// // zzz : improve description #[ inline( always ) ] - pub fn begin_precise + pub fn begin ( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, @@ -1974,7 +1974,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > -> Self { debug_assert!( storage.is_none() ); - Self::begin_precise( None, context, on_end ) + Self::begin( None, context, on_end ) } } From 999034d1bb0596dbbc916cb0c10ccd7d008e2b84 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 00:18:10 +0300 Subject: [PATCH 336/533] former : experimenting --- ...rmer_subform_and_container_parametrized.rs | 51 +++++++++++++++++++ module/core/former/tests/inc/mod.rs | 2 + module/core/former_meta/src/derive/former.rs | 4 +- 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs new file mode 100644 index 0000000000..ac7f440a0f --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs @@ -0,0 +1,51 @@ +#![ allow( dead_code ) ] + +use super::*; + +// xxx : make it working + +/// Parameter description. +// #[ derive( Debug, PartialEq, the_module::Former ) ] +#[ derive( Debug, PartialEq ) ] +pub struct Child< 'child, T > +{ + name : String, + is_mandatory : &'child T, +} + +// /// Parent required for the template. +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// // #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +// // #[ derive( Debug, Default, PartialEq ) ] +// pub struct Parent +// { +// // #[ subform ] +// #[ subform( name = _child ) ] +// #[ container( former::VectorDefinition ) ] +// // #[ setter( false ) ] +// children : Vec< Child >, +// } +// +// impl< Definition > ParentFormer< Definition > +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, +// { +// +// #[ inline( always ) ] +// pub fn child( self, name : &str ) -> +// ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > +// { +// self._children_add_subformer +// ::< ChildFormer< _ >, _, >() +// .name( name ) +// } +// +// } + +// == begin of generated + +// == end of generated + +// include!( "./only_test/subformer_subform.rs" ); +// include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index a26fc515b6..a9cc304c3a 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -81,6 +81,8 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_and_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_and_container_parametrized; } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index d5f561173c..2e90db775f 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -837,8 +837,6 @@ fn container_setter // example : `former::VectorDefinition` let subformer_definition = &field.attrs.container.as_ref().unwrap().expr; - - // xxx let subformer_definition = if subformer_definition.is_some() { qt! @@ -1242,7 +1240,7 @@ Result< TokenStream > Definition::Types : former::FormerDefinitionTypes < Storage = < #stru < #struct_generics_ty > as former::EntityToStorage >::Storage, - // xxx : add test with life time + param + containers + // xxx : add test with life time + param + subform >, Types2 : former::FormerDefinitionTypes < From 1923acd9946bfb6c4c4c6339e10fdae061860628 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 00:37:12 +0300 Subject: [PATCH 337/533] former : experimenting --- .../inc/former_tests/parametrized_field.rs | 31 +++++++++++++++++++ ...rmer_subform_and_container_parametrized.rs | 2 +- module/core/former/tests/inc/mod.rs | 1 + module/core/former_meta/src/derive/former.rs | 14 ++++----- 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/parametrized_field.rs diff --git a/module/core/former/tests/inc/former_tests/parametrized_field.rs b/module/core/former/tests/inc/former_tests/parametrized_field.rs new file mode 100644 index 0000000000..c975cb8da6 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/parametrized_field.rs @@ -0,0 +1,31 @@ +#![ allow( dead_code ) ] +#[ allow( unused_imports ) ] +use super::*; + +// xxx : make it working + +/// Parameter description. +#[ allow( explicit_outlives_requirements ) ] +// #[ derive( Debug, PartialEq, the_module::Former ) ] +// #[ debug ] +#[ derive( Debug, PartialEq ) ] +pub struct Child< 'child, T > +where + T : 'child, +{ + name : String, + arg : &'child T, +} + +// == begin of generated + +// == end of generated + +// xxx : uncomment +// #[ test ] +// fn basic() +// { +// let got = Child::< 'static, str >::former().name( "abc" ).arg( "arg1" ).end(); +// let exp = Child::< 'static, str >{ name : "abc".into(), arg : "arg1" }; +// a_id!( got, exp ); +// } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs index ac7f440a0f..2cd5c5f09c 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs @@ -1,5 +1,5 @@ #![ allow( dead_code ) ] - +#[ allow( unused_imports ) ] use super::*; // xxx : make it working diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index a9cc304c3a..dc4e5a1842 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -55,6 +55,7 @@ mod former_tests mod parametrized_struct_imm; #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod parametrized_struct_where; + mod parametrized_field; #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod subformer_basic; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 2e90db775f..54bf71541e 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -620,8 +620,8 @@ fn field_setter_map ( field : &FormerField< '_ >, stru : &syn::Ident, - as_subformer : &syn::Ident, - as_subformer_end : &syn::Ident, + // as_subformer : &syn::Ident, + // as_subformer_end : &syn::Ident, ) -> Result< TokenStream > { @@ -662,7 +662,7 @@ fn field_setter_map let r = if field.attrs.subform.is_some() { - let subformer = field_subformer_map( field, stru, as_subformer, as_subformer_end )?; + let subformer = field_subformer_map( field, stru )?; qt! { #r @@ -685,8 +685,6 @@ fn field_subformer_map ( field : &FormerField< '_ >, stru : &syn::Ident, - _as_subformer : &syn::Ident, - _as_subformer_end : &syn::Ident, ) -> Result< TokenStream > { @@ -1565,7 +1563,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field_optional_map( former_field ), field_form_map( former_field ), field_name_map( former_field ), - field_setter_map( former_field, &stru, &as_subformer, &as_subformer_end ), + field_setter_map( former_field, &stru ), field_former_assign_map ( former_field, @@ -2008,8 +2006,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { } - impl< #struct_generics_impl SuperFormer, T > #as_subformer_end < #struct_generics_ty SuperFormer > - for T + impl< #struct_generics_impl SuperFormer, __T > #as_subformer_end < #struct_generics_ty SuperFormer > + for __T where #struct_generics_where Self : former::FormingEnd From 781ed873b55bb256b173efed8fb9e3ef659f3ccf Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 00:48:10 +0300 Subject: [PATCH 338/533] former : experimenting --- .../inc/former_tests/parametrized_field.rs | 283 +++++++++++++++++- 1 file changed, 275 insertions(+), 8 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/parametrized_field.rs b/module/core/former/tests/inc/former_tests/parametrized_field.rs index c975cb8da6..410ce11346 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_field.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_field.rs @@ -11,7 +11,7 @@ use super::*; #[ derive( Debug, PartialEq ) ] pub struct Child< 'child, T > where - T : 'child, + T : 'child + ?Sized, { name : String, arg : &'child T, @@ -19,13 +19,280 @@ where // == begin of generated +// #[automatically_derived] +// impl < 'child, T, > Child < 'child, T, > +// where +// T : 'child, +// { +// #[doc = r""] +// #[doc = +// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] +// #[doc = r""] #[inline(always)] pub fn former() -> ChildFormer < 'child, T, +// ChildFormerDefinition < 'child, T, (), Child < 'child, T, > , former :: +// ReturnPreformed > > +// { +// ChildFormer :: < 'child, T, ChildFormerDefinition < 'child, T, (), +// Child < 'child, T, > , former :: ReturnPreformed > > :: +// new_coercing(former :: ReturnPreformed) +// } +// } +// +// impl < 'child, T, Definition > former :: EntityToFormer < Definition > for +// Child < 'child, T, > where Definition : former :: FormerDefinition < Storage = +// ChildFormerStorage < 'child, T, > > , T : 'child, +// { type Former = ChildFormer < 'child, T, Definition > ; } impl < 'child, T, > +// former :: EntityToStorage for Child < 'child, T, > where T : 'child, +// { type Storage = ChildFormerStorage < 'child, T, > ; } impl < 'child, T, +// __Context, __Formed, __End > former :: EntityToDefinition < __Context, +// __Formed, __End > for Child < 'child, T, > where __End : former :: FormingEnd +// < ChildFormerDefinitionTypes < 'child, T, __Context, __Formed > > , T : +// 'child, +// { +// type Definition = ChildFormerDefinition < 'child, T, __Context, __Formed, +// __End > ; +// } #[derive(Debug)] pub struct ChildFormerDefinitionTypes < 'child, T, +// __Context = (), __Formed = Child < 'child, T, > , > where T : 'child, +// { +// _phantom : core :: marker :: PhantomData < +// (& 'child (), T, __Context, __Formed) > , +// } impl < 'child, T, __Context, __Formed, > :: core :: default :: Default for +// ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > where T : +// 'child, +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < 'child, T, __Context, __Formed, > former :: FormerDefinitionTypes for +// ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > where T : +// 'child, +// { +// type Storage = ChildFormerStorage < 'child, T, > ; type Formed = __Formed; +// type Context = __Context; +// } #[derive(Debug)] pub struct ChildFormerDefinition < 'child, T, __Context = +// (), __Formed = Child < 'child, T, > , __End = former :: ReturnPreformed, > +// where T : 'child, +// { +// _phantom : core :: marker :: PhantomData < +// (& 'child (), T, __Context, __Formed, __End) > , +// } impl < 'child, T, __Context, __Formed, __End, > :: core :: default :: +// Default for ChildFormerDefinition < 'child, T, __Context, __Formed, __End, > +// where T : 'child, +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < 'child, T, __Context, __Formed, __End, > former :: FormerDefinition +// for ChildFormerDefinition < 'child, T, __Context, __Formed, __End, > where +// __End : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, +// __Context, __Formed, > > , T : 'child, +// { +// type Types = ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, +// > ; type End = __End; type Storage = ChildFormerStorage < 'child, T, > ; +// type Formed = __Formed; type Context = __Context; +// } +// +// #[doc = "Container of a corresponding former."] +// #[ allow( explicit_outlives_requirements ) ] +// pub struct +// ChildFormerStorage < 'child, T, > where T : 'child, +// { +// #[doc = r" A field"] pub name : :: core :: option :: Option < String > , +// #[doc = r" A field"] pub arg : :: core :: option :: Option < & 'child T > +// , +// } impl < 'child, T, > :: core :: default :: Default for ChildFormerStorage < +// 'child, T, > where T : 'child, +// { +// #[inline(always)] fn default() -> Self +// { +// Self +// { +// name : :: core :: option :: Option :: None, arg : :: core :: +// option :: Option :: None, +// } +// } +// } impl < 'child, T, > former :: Storage for ChildFormerStorage < 'child, T, > +// where T : 'child, { type Formed = Child < 'child, T, > ; } impl < 'child, T, > +// former :: StoragePreform for ChildFormerStorage < 'child, T, > where T : +// 'child, +// { +// type Preformed = Child < 'child, T, > ; fn preform(mut self) -> Self :: +// Preformed +// { +// let name = if self.name.is_some() { self.name.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'name' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < String +// >).maybe_default() +// } +// }; let arg = if self.arg.is_some() { self.arg.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'arg' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < & 'child T +// >).maybe_default() +// } +// }; let result = Child :: < 'child, T, > { name, arg, }; return result; +// } +// } +// #[doc = +// " Object to form [Child]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +// pub struct ChildFormer < 'child, T, Definition = ChildFormerDefinition < +// 'child, T, (), Child < 'child, T, > , former :: ReturnPreformed > , > where T +// : 'child, Definition : former :: FormerDefinition, Definition :: Types : +// former :: FormerDefinitionTypes < Storage = ChildFormerStorage < 'child, T, > +// > , +// { +// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: +// Storage, context : core :: option :: Option < < Definition :: Types as +// former :: FormerDefinitionTypes > :: Context > , on_end : core :: option +// :: Option < Definition :: End > , +// } #[automatically_derived] impl < 'child, T, Definition, > ChildFormer < +// 'child, T, Definition, > where T : 'child, Definition : former :: +// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = ChildFormerStorage < 'child, T, > > , +// { +// #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> +// Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > +// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , +// { Self :: begin_coercing(None, None, end,) } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn +// begin(mut storage : core :: option :: Option < < Definition :: Types as +// former :: FormerDefinitionTypes > :: Storage > , context : core :: option +// :: Option < < Definition :: Types as former :: FormerDefinitionTypes > :: +// Context > , on_end : < Definition as former :: FormerDefinition > :: End,) +// -> Self +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: Some(on_end), +// } +// } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > +// (mut storage : core :: option :: Option < < Definition :: Types as former +// :: FormerDefinitionTypes > :: Storage > , context : core :: option :: +// Option < < Definition :: Types as former :: FormerDefinitionTypes > :: +// Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert +// :: Into < < Definition as former :: FormerDefinition > :: End > , +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: +// Some(:: core :: convert :: Into :: into(on_end)), +// } +// } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types +// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { +// let on_end = self.on_end.take().unwrap(); let context = +// self.context.take(); former :: FormingEnd :: < Definition :: Types > +// :: call(& on_end, self.storage, context) +// } #[doc = "Setter for the 'name' field."] #[inline] pub fn name < Src > +// (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < +// String > , +// { +// debug_assert! (self.storage.name.is_none()); self.storage.name = :: +// core :: option :: Option :: +// Some(:: core :: convert :: Into :: into(src)); self +// } #[doc = "Setter for the 'arg' field."] #[inline] pub fn arg < Src > +// (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < & +// 'child T > , +// { +// debug_assert! (self.storage.arg.is_none()); self.storage.arg = :: core +// :: option :: Option :: Some(:: core :: convert :: Into :: into(src)); +// self +// } +// } impl < 'child, T, Definition, > ChildFormer < 'child, T, Definition, > where +// Definition :: Types : former :: FormerDefinitionTypes < Storage = +// ChildFormerStorage < 'child, T, > , Formed = Child < 'child, T, > > , T : +// 'child, Definition : former :: FormerDefinition, Definition :: Types : former +// :: FormerDefinitionTypes < Storage = ChildFormerStorage < 'child, T, > > , +// { +// pub fn preform(self) -> < Definition :: Types as former :: +// FormerDefinitionTypes > :: Formed +// { former :: StoragePreform :: preform(self.storage) } +// } #[automatically_derived] impl < 'child, T, Definition, > ChildFormer < +// 'child, T, Definition, > where T : 'child, Definition : former :: +// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = ChildFormerStorage < 'child, T, > , Formed = Child < 'child, T, > > +// , +// { +// #[doc = r""] +// #[doc = r" Finish setting options and call perform on formed entity."] +// #[doc = r""] +// #[doc = +// r" If `perform` defined then associated method is called and its result returned instead of entity."] +// #[doc = +// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] +// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { let result = self.form(); return result; } +// } impl < 'child, T, Definition > former :: FormerBegin < Definition > for +// ChildFormer < 'child, T, Definition, > where Definition : former :: +// FormerDefinition < Storage = ChildFormerStorage < 'child, T, > > , T : 'child, +// { +// #[inline(always)] fn +// former_begin(storage : core :: option :: Option < Definition :: Storage > +// , context : core :: option :: Option < Definition :: Context > , on_end : +// Definition :: End,) -> Self +// { +// debug_assert! (storage.is_none()); Self :: +// begin(None, context, on_end) +// } +// } +// #[doc = +// r" Use as subformer of a field during process of forming of super structure."] +// pub type ChildAsSubformer < 'child, T, __Superformer, __End > = ChildFormer < +// 'child, T, ChildFormerDefinition < 'child, T, __Superformer, __Superformer, +// __End, > , > ; +// #[doc = +// "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] +// pub trait ChildAsSubformerEnd < 'child, T, SuperFormer > where T : 'child, +// Self : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, +// SuperFormer, SuperFormer > , > , {} impl < 'child, T, SuperFormer, __T > +// ChildAsSubformerEnd < 'child, T, SuperFormer > for __T where T : 'child, Self +// : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, SuperFormer, +// SuperFormer > , > , {} + // == end of generated // xxx : uncomment -// #[ test ] -// fn basic() -// { -// let got = Child::< 'static, str >::former().name( "abc" ).arg( "arg1" ).end(); -// let exp = Child::< 'static, str >{ name : "abc".into(), arg : "arg1" }; -// a_id!( got, exp ); -// } +#[ test ] +fn basic() +{ + // let got = Child::< 'static, str >::former().name( "abc" ).arg( "arg1" ).end(); + let exp = Child::< 'static, str >{ name : "abc".into(), arg : "arg1" }; + // a_id!( got, exp ); +} From 63e6afc0da75c350e55eccbc0aceaf2093c86162 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 08:20:33 +0300 Subject: [PATCH 339/533] macro_tools : better phantom generation --- .../inc/former_tests/parametrized_field.rs | 567 +++++++++--------- module/core/macro_tools/src/phantom.rs | 15 +- module/core/macro_tools/tests/inc/phantom.rs | 12 +- 3 files changed, 308 insertions(+), 286 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/parametrized_field.rs b/module/core/former/tests/inc/former_tests/parametrized_field.rs index 410ce11346..5c358f00ae 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_field.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_field.rs @@ -19,280 +19,301 @@ where // == begin of generated -// #[automatically_derived] -// impl < 'child, T, > Child < 'child, T, > -// where -// T : 'child, -// { -// #[doc = r""] -// #[doc = -// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] -// #[doc = r""] #[inline(always)] pub fn former() -> ChildFormer < 'child, T, -// ChildFormerDefinition < 'child, T, (), Child < 'child, T, > , former :: -// ReturnPreformed > > -// { -// ChildFormer :: < 'child, T, ChildFormerDefinition < 'child, T, (), -// Child < 'child, T, > , former :: ReturnPreformed > > :: -// new_coercing(former :: ReturnPreformed) -// } -// } -// -// impl < 'child, T, Definition > former :: EntityToFormer < Definition > for -// Child < 'child, T, > where Definition : former :: FormerDefinition < Storage = -// ChildFormerStorage < 'child, T, > > , T : 'child, -// { type Former = ChildFormer < 'child, T, Definition > ; } impl < 'child, T, > -// former :: EntityToStorage for Child < 'child, T, > where T : 'child, -// { type Storage = ChildFormerStorage < 'child, T, > ; } impl < 'child, T, -// __Context, __Formed, __End > former :: EntityToDefinition < __Context, -// __Formed, __End > for Child < 'child, T, > where __End : former :: FormingEnd -// < ChildFormerDefinitionTypes < 'child, T, __Context, __Formed > > , T : -// 'child, -// { -// type Definition = ChildFormerDefinition < 'child, T, __Context, __Formed, -// __End > ; -// } #[derive(Debug)] pub struct ChildFormerDefinitionTypes < 'child, T, -// __Context = (), __Formed = Child < 'child, T, > , > where T : 'child, -// { -// _phantom : core :: marker :: PhantomData < -// (& 'child (), T, __Context, __Formed) > , -// } impl < 'child, T, __Context, __Formed, > :: core :: default :: Default for -// ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > where T : -// 'child, -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < 'child, T, __Context, __Formed, > former :: FormerDefinitionTypes for -// ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > where T : -// 'child, -// { -// type Storage = ChildFormerStorage < 'child, T, > ; type Formed = __Formed; -// type Context = __Context; -// } #[derive(Debug)] pub struct ChildFormerDefinition < 'child, T, __Context = -// (), __Formed = Child < 'child, T, > , __End = former :: ReturnPreformed, > -// where T : 'child, -// { -// _phantom : core :: marker :: PhantomData < -// (& 'child (), T, __Context, __Formed, __End) > , -// } impl < 'child, T, __Context, __Formed, __End, > :: core :: default :: -// Default for ChildFormerDefinition < 'child, T, __Context, __Formed, __End, > -// where T : 'child, -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < 'child, T, __Context, __Formed, __End, > former :: FormerDefinition -// for ChildFormerDefinition < 'child, T, __Context, __Formed, __End, > where -// __End : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, -// __Context, __Formed, > > , T : 'child, -// { -// type Types = ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, -// > ; type End = __End; type Storage = ChildFormerStorage < 'child, T, > ; -// type Formed = __Formed; type Context = __Context; -// } -// -// #[doc = "Container of a corresponding former."] -// #[ allow( explicit_outlives_requirements ) ] -// pub struct -// ChildFormerStorage < 'child, T, > where T : 'child, -// { -// #[doc = r" A field"] pub name : :: core :: option :: Option < String > , -// #[doc = r" A field"] pub arg : :: core :: option :: Option < & 'child T > -// , -// } impl < 'child, T, > :: core :: default :: Default for ChildFormerStorage < -// 'child, T, > where T : 'child, -// { -// #[inline(always)] fn default() -> Self -// { -// Self -// { -// name : :: core :: option :: Option :: None, arg : :: core :: -// option :: Option :: None, -// } -// } -// } impl < 'child, T, > former :: Storage for ChildFormerStorage < 'child, T, > -// where T : 'child, { type Formed = Child < 'child, T, > ; } impl < 'child, T, > -// former :: StoragePreform for ChildFormerStorage < 'child, T, > where T : -// 'child, -// { -// type Preformed = Child < 'child, T, > ; fn preform(mut self) -> Self :: -// Preformed -// { -// let name = if self.name.is_some() { self.name.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'name' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < String -// >).maybe_default() -// } -// }; let arg = if self.arg.is_some() { self.arg.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'arg' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < & 'child T -// >).maybe_default() -// } -// }; let result = Child :: < 'child, T, > { name, arg, }; return result; -// } -// } -// #[doc = -// " Object to form [Child]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -// pub struct ChildFormer < 'child, T, Definition = ChildFormerDefinition < -// 'child, T, (), Child < 'child, T, > , former :: ReturnPreformed > , > where T -// : 'child, Definition : former :: FormerDefinition, Definition :: Types : -// former :: FormerDefinitionTypes < Storage = ChildFormerStorage < 'child, T, > -// > , -// { -// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: -// Storage, context : core :: option :: Option < < Definition :: Types as -// former :: FormerDefinitionTypes > :: Context > , on_end : core :: option -// :: Option < Definition :: End > , -// } #[automatically_derived] impl < 'child, T, Definition, > ChildFormer < -// 'child, T, Definition, > where T : 'child, Definition : former :: -// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = ChildFormerStorage < 'child, T, > > , -// { -// #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> -// Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > -// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , -// { Self :: begin_coercing(None, None, end,) } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn -// begin(mut storage : core :: option :: Option < < Definition :: Types as -// former :: FormerDefinitionTypes > :: Storage > , context : core :: option -// :: Option < < Definition :: Types as former :: FormerDefinitionTypes > :: -// Context > , on_end : < Definition as former :: FormerDefinition > :: End,) -// -> Self -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: Some(on_end), -// } -// } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > -// (mut storage : core :: option :: Option < < Definition :: Types as former -// :: FormerDefinitionTypes > :: Storage > , context : core :: option :: -// Option < < Definition :: Types as former :: FormerDefinitionTypes > :: -// Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert -// :: Into < < Definition as former :: FormerDefinition > :: End > , -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: -// Some(:: core :: convert :: Into :: into(on_end)), -// } -// } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types -// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { -// let on_end = self.on_end.take().unwrap(); let context = -// self.context.take(); former :: FormingEnd :: < Definition :: Types > -// :: call(& on_end, self.storage, context) -// } #[doc = "Setter for the 'name' field."] #[inline] pub fn name < Src > -// (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < -// String > , -// { -// debug_assert! (self.storage.name.is_none()); self.storage.name = :: -// core :: option :: Option :: -// Some(:: core :: convert :: Into :: into(src)); self -// } #[doc = "Setter for the 'arg' field."] #[inline] pub fn arg < Src > -// (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < & -// 'child T > , -// { -// debug_assert! (self.storage.arg.is_none()); self.storage.arg = :: core -// :: option :: Option :: Some(:: core :: convert :: Into :: into(src)); -// self -// } -// } impl < 'child, T, Definition, > ChildFormer < 'child, T, Definition, > where -// Definition :: Types : former :: FormerDefinitionTypes < Storage = -// ChildFormerStorage < 'child, T, > , Formed = Child < 'child, T, > > , T : -// 'child, Definition : former :: FormerDefinition, Definition :: Types : former -// :: FormerDefinitionTypes < Storage = ChildFormerStorage < 'child, T, > > , -// { -// pub fn preform(self) -> < Definition :: Types as former :: -// FormerDefinitionTypes > :: Formed -// { former :: StoragePreform :: preform(self.storage) } -// } #[automatically_derived] impl < 'child, T, Definition, > ChildFormer < -// 'child, T, Definition, > where T : 'child, Definition : former :: -// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = ChildFormerStorage < 'child, T, > , Formed = Child < 'child, T, > > -// , -// { -// #[doc = r""] -// #[doc = r" Finish setting options and call perform on formed entity."] -// #[doc = r""] -// #[doc = -// r" If `perform` defined then associated method is called and its result returned instead of entity."] -// #[doc = -// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] -// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { let result = self.form(); return result; } -// } impl < 'child, T, Definition > former :: FormerBegin < Definition > for -// ChildFormer < 'child, T, Definition, > where Definition : former :: -// FormerDefinition < Storage = ChildFormerStorage < 'child, T, > > , T : 'child, -// { -// #[inline(always)] fn -// former_begin(storage : core :: option :: Option < Definition :: Storage > -// , context : core :: option :: Option < Definition :: Context > , on_end : -// Definition :: End,) -> Self -// { -// debug_assert! (storage.is_none()); Self :: -// begin(None, context, on_end) -// } -// } -// #[doc = -// r" Use as subformer of a field during process of forming of super structure."] -// pub type ChildAsSubformer < 'child, T, __Superformer, __End > = ChildFormer < -// 'child, T, ChildFormerDefinition < 'child, T, __Superformer, __Superformer, -// __End, > , > ; -// #[doc = -// "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] -// pub trait ChildAsSubformerEnd < 'child, T, SuperFormer > where T : 'child, -// Self : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, -// SuperFormer, SuperFormer > , > , {} impl < 'child, T, SuperFormer, __T > -// ChildAsSubformerEnd < 'child, T, SuperFormer > for __T where T : 'child, Self -// : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, SuperFormer, -// SuperFormer > , > , {} + #[automatically_derived] impl < 'child, T, > Child < 'child, T, > where T : + 'child + ? Sized, + { + #[doc = r""] + #[doc = + r" Make former, variation of builder pattern to form structure defining values of fields step by step."] + #[doc = r""] #[inline(always)] pub fn former() -> ChildFormer < 'child, T, + ChildFormerDefinition < 'child, T, (), Child < 'child, T, > , former :: + ReturnPreformed > > + { + ChildFormer :: < 'child, T, ChildFormerDefinition < 'child, T, (), + Child < 'child, T, > , former :: ReturnPreformed > > :: + new_coercing(former :: ReturnPreformed) + } + } impl < 'child, T, Definition > former :: EntityToFormer < Definition > for + Child < 'child, T, > where Definition : former :: FormerDefinition < Storage = + ChildFormerStorage < 'child, T, > > , T : 'child + ? Sized, + { type Former = ChildFormer < 'child, T, Definition > ; } impl < 'child, T, > + former :: EntityToStorage for Child < 'child, T, > where T : 'child + ? Sized, + { type Storage = ChildFormerStorage < 'child, T, > ; } impl < 'child, T, + __Context, __Formed, __End > former :: EntityToDefinition < __Context, + __Formed, __End > for Child < 'child, T, > where __End : former :: FormingEnd + < ChildFormerDefinitionTypes < 'child, T, __Context, __Formed > > , T : 'child + + ? Sized, + { + type Definition = ChildFormerDefinition < 'child, T, __Context, __Formed, + __End > ; + } + + #[derive(Debug)] + pub struct ChildFormerDefinitionTypes < 'child, T, __Context = (), __Formed = Child < 'child, T, > , > + where + T : 'child + ?Sized, + { + _phantom : core :: marker :: PhantomData < + (& 'child (), *const T, __Context, __Formed) > , + } + + impl < 'child, T, __Context, __Formed, > :: core :: default :: Default for + ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > where T : + 'child + ? Sized, + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } + + impl < 'child, T, __Context, __Formed, > former :: FormerDefinitionTypes for + ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > where T : + 'child + ? Sized, + { + type Storage = ChildFormerStorage < 'child, T, > ; + type Formed = __Formed; + type Context = __Context; + } + + #[derive(Debug)] pub struct ChildFormerDefinition + < 'child, T, __Context = (), __Formed = Child < 'child, T, > , __End = former :: ReturnPreformed, > + where + T : 'child + ? Sized, + { + _phantom : core :: marker :: PhantomData < (& 'child (), *const T, __Context, __Formed, __End) > , + } + + impl < 'child, T, __Context, __Formed, __End, > :: core :: default :: + Default for ChildFormerDefinition < 'child, T, __Context, __Formed, __End, > + where T : 'child + ? Sized, + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } + + impl < 'child, T, __Context, __Formed, __End, > former :: FormerDefinition + for ChildFormerDefinition < 'child, T, __Context, __Formed, __End, > + where + __End : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, + __Context, __Formed, > > , T : 'child + ? Sized, + { + type Types = ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > ; + type End = __End; + type Storage = ChildFormerStorage < 'child, T, > ; + type Formed = __Formed; + type Context = __Context; + } + + #[doc = "Container of a corresponding former."] + #[ allow( explicit_outlives_requirements ) ] + pub struct ChildFormerStorage < 'child, T, > + where + T : 'child + ? Sized, + { + #[doc = r" A field"] + pub name : :: core :: option :: Option < String > , + #[doc = r" A field"] + pub arg : :: core :: option :: Option < & 'child T > + , + } + + impl < 'child, T, > :: core :: default :: Default for ChildFormerStorage < + 'child, T, > where T : 'child + ? Sized, + { + #[inline(always)] fn default() -> Self + { + Self + { + name : :: core :: option :: Option :: None, arg : :: core :: + option :: Option :: None, + } + } + } impl < 'child, T, > former :: Storage for ChildFormerStorage < 'child, T, > + where T : 'child + ? Sized, { type Formed = Child < 'child, T, > ; } impl < + 'child, T, > former :: StoragePreform for ChildFormerStorage < 'child, T, > + where T : 'child + ? Sized, + { + type Preformed = Child < 'child, T, > ; fn preform(mut self) -> Self :: + Preformed + { + let name = if self.name.is_some() { self.name.take().unwrap() } else + { + { + trait MaybeDefault < T > + { + fn maybe_default(self : & Self) -> T + { panic! ("Field 'name' isn't initialized") } + } impl < T > MaybeDefault < T > for & :: core :: marker :: + PhantomData < T > {} impl < T > MaybeDefault < T > for :: core + :: marker :: PhantomData < T > where T : :: core :: default :: + Default, + { fn maybe_default(self : & Self) -> T { T :: default() } } + (& :: core :: marker :: PhantomData :: < String + >).maybe_default() + } + }; let arg = if self.arg.is_some() { self.arg.take().unwrap() } else + { + { + trait MaybeDefault < T > + { + fn maybe_default(self : & Self) -> T + { panic! ("Field 'arg' isn't initialized") } + } impl < T > MaybeDefault < T > for & :: core :: marker :: + PhantomData < T > {} impl < T > MaybeDefault < T > for :: core + :: marker :: PhantomData < T > where T : :: core :: default :: + Default, + { fn maybe_default(self : & Self) -> T { T :: default() } } + (& :: core :: marker :: PhantomData :: < & 'child T + >).maybe_default() + } + }; let result = Child :: < 'child, T, > { name, arg, }; return result; + } + } + #[doc = + " Object to form [Child]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] + pub struct ChildFormer < 'child, T, Definition = ChildFormerDefinition < + 'child, T, (), Child < 'child, T, > , former :: ReturnPreformed > , > where T + : 'child + ? Sized, Definition : former :: FormerDefinition, Definition :: + Types : former :: FormerDefinitionTypes < Storage = ChildFormerStorage < + 'child, T, > > , + { + storage : < Definition :: Types as former :: FormerDefinitionTypes > :: + Storage, context : core :: option :: Option < < Definition :: Types as + former :: FormerDefinitionTypes > :: Context > , on_end : core :: option + :: Option < Definition :: End > , + } #[automatically_derived] impl < 'child, T, Definition, > ChildFormer < + 'child, T, Definition, > where T : 'child + ? Sized, Definition : former :: + FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < + Storage = ChildFormerStorage < 'child, T, > > , + { + #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> + Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > + (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , + { Self :: begin_coercing(None, None, end,) } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn + begin(mut storage : core :: option :: Option < < Definition :: Types as + former :: FormerDefinitionTypes > :: Storage > , context : core :: option + :: Option < < Definition :: Types as former :: FormerDefinitionTypes > :: + Context > , on_end : < Definition as former :: FormerDefinition > :: End,) + -> Self + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: Some(on_end), + } + } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > + (mut storage : core :: option :: Option < < Definition :: Types as former + :: FormerDefinitionTypes > :: Storage > , context : core :: option :: + Option < < Definition :: Types as former :: FormerDefinitionTypes > :: + Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert + :: Into < < Definition as former :: FormerDefinition > :: End > , + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: + Some(:: core :: convert :: Into :: into(on_end)), + } + } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types + as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { + let on_end = self.on_end.take().unwrap(); let context = + self.context.take(); former :: FormingEnd :: < Definition :: Types > + :: call(& on_end, self.storage, context) + } #[doc = "Setter for the 'name' field."] #[inline] pub fn name < Src > + (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < + String > , + { + debug_assert! (self.storage.name.is_none()); self.storage.name = :: + core :: option :: Option :: + Some(:: core :: convert :: Into :: into(src)); self + } #[doc = "Setter for the 'arg' field."] #[inline] pub fn arg < Src > + (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < & + 'child T > , + { + debug_assert! (self.storage.arg.is_none()); self.storage.arg = :: core + :: option :: Option :: Some(:: core :: convert :: Into :: into(src)); + self + } + } impl < 'child, T, Definition, > ChildFormer < 'child, T, Definition, > where + Definition :: Types : former :: FormerDefinitionTypes < Storage = + ChildFormerStorage < 'child, T, > , Formed = Child < 'child, T, > > , T : + 'child + ? Sized, Definition : former :: FormerDefinition, Definition :: Types + : former :: FormerDefinitionTypes < Storage = ChildFormerStorage < 'child, T, + > > , + { + pub fn preform(self) -> < Definition :: Types as former :: + FormerDefinitionTypes > :: Formed + { former :: StoragePreform :: preform(self.storage) } + } #[automatically_derived] impl < 'child, T, Definition, > ChildFormer < + 'child, T, Definition, > where T : 'child + ? Sized, Definition : former :: + FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < + Storage = ChildFormerStorage < 'child, T, > , Formed = Child < 'child, T, > > + , + { + #[doc = r""] + #[doc = r" Finish setting options and call perform on formed entity."] + #[doc = r""] + #[doc = + r" If `perform` defined then associated method is called and its result returned instead of entity."] + #[doc = + r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] + #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { let result = self.form(); return result; } + } impl < 'child, T, Definition > former :: FormerBegin < Definition > for + ChildFormer < 'child, T, Definition, > where Definition : former :: + FormerDefinition < Storage = ChildFormerStorage < 'child, T, > > , T : 'child + + ? Sized, + { + #[inline(always)] fn + former_begin(storage : core :: option :: Option < Definition :: Storage > + , context : core :: option :: Option < Definition :: Context > , on_end : + Definition :: End,) -> Self + { + debug_assert! (storage.is_none()); Self :: + begin(None, context, on_end) + } + } + #[doc = + r" Use as subformer of a field during process of forming of super structure."] + pub type ChildAsSubformer < 'child, T, __Superformer, __End > = ChildFormer < + 'child, T, ChildFormerDefinition < 'child, T, __Superformer, __Superformer, + __End, > , > ; + #[doc = + "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] + pub trait ChildAsSubformerEnd < 'child, T, SuperFormer > where T : 'child + ? + Sized, Self : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, + SuperFormer, SuperFormer > , > , {} impl < 'child, T, SuperFormer, __T > + ChildAsSubformerEnd < 'child, T, SuperFormer > for __T where T : 'child + ? + Sized, Self : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, + SuperFormer, SuperFormer > , > , {} // == end of generated // xxx : uncomment -#[ test ] -fn basic() -{ - // let got = Child::< 'static, str >::former().name( "abc" ).arg( "arg1" ).end(); - let exp = Child::< 'static, str >{ name : "abc".into(), arg : "arg1" }; - // a_id!( got, exp ); -} +// #[ test ] +// fn basic() +// { +// let got = Child::< 'static, str >::former().name( "abc" ).arg( "arg1" ).end(); +// let exp = Child::< 'static, str >{ name : "abc".into(), arg : "arg1" }; +// // a_id!( got, exp ); +// } diff --git a/module/core/macro_tools/src/phantom.rs b/module/core/macro_tools/src/phantom.rs index 8a34b35ad0..7c9e3bbbda 100644 --- a/module/core/macro_tools/src/phantom.rs +++ b/module/core/macro_tools/src/phantom.rs @@ -113,10 +113,10 @@ pub( crate ) mod private /// use syn::{parse_quote, punctuated::Punctuated, GenericParam, token::Comma}; /// use macro_tools::phantom::tuple; /// - /// let generics: Punctuated< GenericParam, Comma > = parse_quote! { T, 'a, const N : usize }; + /// let generics: Punctuated< GenericParam, Comma > = parse_quote! { 'a, T, const N : usize }; /// let phantom_type = tuple( &generics ); /// println!( "{}", quote::quote! { #phantom_type } ); - /// // Output: core::marker::PhantomData< ( T, &'a (), N ) > + /// // Output: core::marker::PhantomData< ( &'a (), *const T, N ) > /// ``` /// pub fn tuple( input : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma > ) -> syn::Type @@ -131,11 +131,12 @@ pub( crate ) mod private { match param { - GenericParam::Type( type_param ) => Type::Path( syn::TypePath + GenericParam::Type( type_param ) => { - qself : None, - path : type_param.ident.clone().into(), - }), + let path = &type_param.ident; + let path2 : syn::Type = parse_quote!{ *const #path }; + path2 + }, GenericParam::Lifetime( lifetime_param ) => Type::Reference( syn::TypeReference { and_token : Default::default(), @@ -153,7 +154,7 @@ pub( crate ) mod private path : const_param.ident.clone().into(), }), } - }).collect::>(); + }).collect::< syn::punctuated::Punctuated< _, syn::token::Comma > >(); Type::Tuple( syn::TypeTuple { diff --git a/module/core/macro_tools/tests/inc/phantom.rs b/module/core/macro_tools/tests/inc/phantom.rs index e0e4754035..990a63d2e7 100644 --- a/module/core/macro_tools/tests/inc/phantom.rs +++ b/module/core/macro_tools/tests/inc/phantom.rs @@ -18,7 +18,7 @@ fn phantom_add_basic() pub struct Struct1< 'a, Context, Formed > { f1 : int32, - _phantom : core::marker::PhantomData< ( &'a(), Context, Formed ) >, + _phantom : core::marker::PhantomData< ( &'a(), *const Context, *const Formed ) >, } }; @@ -64,7 +64,7 @@ fn phantom_add_type_generics() { struct TestStruct< T, U > { - _phantom : core::marker::PhantomData< ( T, U ) >, + _phantom : core::marker::PhantomData< ( *const T, *const U ) >, } }; @@ -130,7 +130,7 @@ fn phantom_add_mixed_generics() { struct TestStruct< T, 'a, const N : usize > { - _phantom : core::marker::PhantomData< ( T, &'a (), N ) >, + _phantom : core::marker::PhantomData< ( *const T, &'a (), N ) >, } }; @@ -191,7 +191,7 @@ fn phantom_add_unnamed_fields_with_generics() struct TestStruct< T, U > ( T, U, - core::marker::PhantomData< ( T, U ) >, + core::marker::PhantomData< ( *const T, *const U ) >, ); }; @@ -274,7 +274,7 @@ fn phantom_tuple_only_type_parameters() let input : Punctuated< GenericParam, Comma > = parse_quote! { T, U }; let result = tuple( &input ); - let exp : syn::Type = parse_quote! { core::marker::PhantomData<(T, U)> }; + let exp : syn::Type = parse_quote! { core::marker::PhantomData< ( *const T, *const U ) > }; let got = result; assert_eq!( format!( "{:?}", exp ), format!( "{:?}", got ), "Expected PhantomData with type parameters, got: {:?}", got ); @@ -291,7 +291,7 @@ fn phantom_tuple_mixed_generics() let input : Punctuated< GenericParam, Comma > = parse_quote! { T, 'a, const N: usize }; let result = tuple( &input ); - let exp : syn::Type = parse_quote! { core::marker::PhantomData<(T, &'a (), N)> }; + let exp : syn::Type = parse_quote! { core::marker::PhantomData< ( *const T, &'a (), N ) > }; let got = result; assert_eq!( format!( "{:?}", exp ), format!( "{:?}", got ), "Expected PhantomData with mixed generics, got: {:?}", got ); From f07bec15e9aa385acbb251832e215a83a613d5c0 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 08:22:49 +0300 Subject: [PATCH 340/533] former : experimenting --- .../inc/former_tests/parametrized_field.rs | 592 +++++++++--------- module/core/former_meta/src/derive/former.rs | 1 + 2 files changed, 297 insertions(+), 296 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/parametrized_field.rs b/module/core/former/tests/inc/former_tests/parametrized_field.rs index 5c358f00ae..088efc67d7 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_field.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_field.rs @@ -6,9 +6,9 @@ use super::*; /// Parameter description. #[ allow( explicit_outlives_requirements ) ] -// #[ derive( Debug, PartialEq, the_module::Former ) ] +#[ derive( Debug, PartialEq, the_module::Former ) ] // #[ debug ] -#[ derive( Debug, PartialEq ) ] +// #[ derive( Debug, PartialEq ) ] pub struct Child< 'child, T > where T : 'child + ?Sized, @@ -19,301 +19,301 @@ where // == begin of generated - #[automatically_derived] impl < 'child, T, > Child < 'child, T, > where T : - 'child + ? Sized, - { - #[doc = r""] - #[doc = - r" Make former, variation of builder pattern to form structure defining values of fields step by step."] - #[doc = r""] #[inline(always)] pub fn former() -> ChildFormer < 'child, T, - ChildFormerDefinition < 'child, T, (), Child < 'child, T, > , former :: - ReturnPreformed > > - { - ChildFormer :: < 'child, T, ChildFormerDefinition < 'child, T, (), - Child < 'child, T, > , former :: ReturnPreformed > > :: - new_coercing(former :: ReturnPreformed) - } - } impl < 'child, T, Definition > former :: EntityToFormer < Definition > for - Child < 'child, T, > where Definition : former :: FormerDefinition < Storage = - ChildFormerStorage < 'child, T, > > , T : 'child + ? Sized, - { type Former = ChildFormer < 'child, T, Definition > ; } impl < 'child, T, > - former :: EntityToStorage for Child < 'child, T, > where T : 'child + ? Sized, - { type Storage = ChildFormerStorage < 'child, T, > ; } impl < 'child, T, - __Context, __Formed, __End > former :: EntityToDefinition < __Context, - __Formed, __End > for Child < 'child, T, > where __End : former :: FormingEnd - < ChildFormerDefinitionTypes < 'child, T, __Context, __Formed > > , T : 'child - + ? Sized, - { - type Definition = ChildFormerDefinition < 'child, T, __Context, __Formed, - __End > ; - } - - #[derive(Debug)] - pub struct ChildFormerDefinitionTypes < 'child, T, __Context = (), __Formed = Child < 'child, T, > , > - where - T : 'child + ?Sized, - { - _phantom : core :: marker :: PhantomData < - (& 'child (), *const T, __Context, __Formed) > , - } - - impl < 'child, T, __Context, __Formed, > :: core :: default :: Default for - ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > where T : - 'child + ? Sized, - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } - - impl < 'child, T, __Context, __Formed, > former :: FormerDefinitionTypes for - ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > where T : - 'child + ? Sized, - { - type Storage = ChildFormerStorage < 'child, T, > ; - type Formed = __Formed; - type Context = __Context; - } - - #[derive(Debug)] pub struct ChildFormerDefinition - < 'child, T, __Context = (), __Formed = Child < 'child, T, > , __End = former :: ReturnPreformed, > - where - T : 'child + ? Sized, - { - _phantom : core :: marker :: PhantomData < (& 'child (), *const T, __Context, __Formed, __End) > , - } - - impl < 'child, T, __Context, __Formed, __End, > :: core :: default :: - Default for ChildFormerDefinition < 'child, T, __Context, __Formed, __End, > - where T : 'child + ? Sized, - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } - - impl < 'child, T, __Context, __Formed, __End, > former :: FormerDefinition - for ChildFormerDefinition < 'child, T, __Context, __Formed, __End, > - where - __End : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, - __Context, __Formed, > > , T : 'child + ? Sized, - { - type Types = ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > ; - type End = __End; - type Storage = ChildFormerStorage < 'child, T, > ; - type Formed = __Formed; - type Context = __Context; - } - - #[doc = "Container of a corresponding former."] - #[ allow( explicit_outlives_requirements ) ] - pub struct ChildFormerStorage < 'child, T, > - where - T : 'child + ? Sized, - { - #[doc = r" A field"] - pub name : :: core :: option :: Option < String > , - #[doc = r" A field"] - pub arg : :: core :: option :: Option < & 'child T > - , - } - - impl < 'child, T, > :: core :: default :: Default for ChildFormerStorage < - 'child, T, > where T : 'child + ? Sized, - { - #[inline(always)] fn default() -> Self - { - Self - { - name : :: core :: option :: Option :: None, arg : :: core :: - option :: Option :: None, - } - } - } impl < 'child, T, > former :: Storage for ChildFormerStorage < 'child, T, > - where T : 'child + ? Sized, { type Formed = Child < 'child, T, > ; } impl < - 'child, T, > former :: StoragePreform for ChildFormerStorage < 'child, T, > - where T : 'child + ? Sized, - { - type Preformed = Child < 'child, T, > ; fn preform(mut self) -> Self :: - Preformed - { - let name = if self.name.is_some() { self.name.take().unwrap() } else - { - { - trait MaybeDefault < T > - { - fn maybe_default(self : & Self) -> T - { panic! ("Field 'name' isn't initialized") } - } impl < T > MaybeDefault < T > for & :: core :: marker :: - PhantomData < T > {} impl < T > MaybeDefault < T > for :: core - :: marker :: PhantomData < T > where T : :: core :: default :: - Default, - { fn maybe_default(self : & Self) -> T { T :: default() } } - (& :: core :: marker :: PhantomData :: < String - >).maybe_default() - } - }; let arg = if self.arg.is_some() { self.arg.take().unwrap() } else - { - { - trait MaybeDefault < T > - { - fn maybe_default(self : & Self) -> T - { panic! ("Field 'arg' isn't initialized") } - } impl < T > MaybeDefault < T > for & :: core :: marker :: - PhantomData < T > {} impl < T > MaybeDefault < T > for :: core - :: marker :: PhantomData < T > where T : :: core :: default :: - Default, - { fn maybe_default(self : & Self) -> T { T :: default() } } - (& :: core :: marker :: PhantomData :: < & 'child T - >).maybe_default() - } - }; let result = Child :: < 'child, T, > { name, arg, }; return result; - } - } - #[doc = - " Object to form [Child]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] - pub struct ChildFormer < 'child, T, Definition = ChildFormerDefinition < - 'child, T, (), Child < 'child, T, > , former :: ReturnPreformed > , > where T - : 'child + ? Sized, Definition : former :: FormerDefinition, Definition :: - Types : former :: FormerDefinitionTypes < Storage = ChildFormerStorage < - 'child, T, > > , - { - storage : < Definition :: Types as former :: FormerDefinitionTypes > :: - Storage, context : core :: option :: Option < < Definition :: Types as - former :: FormerDefinitionTypes > :: Context > , on_end : core :: option - :: Option < Definition :: End > , - } #[automatically_derived] impl < 'child, T, Definition, > ChildFormer < - 'child, T, Definition, > where T : 'child + ? Sized, Definition : former :: - FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < - Storage = ChildFormerStorage < 'child, T, > > , - { - #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> - Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > - (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , - { Self :: begin_coercing(None, None, end,) } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn - begin(mut storage : core :: option :: Option < < Definition :: Types as - former :: FormerDefinitionTypes > :: Storage > , context : core :: option - :: Option < < Definition :: Types as former :: FormerDefinitionTypes > :: - Context > , on_end : < Definition as former :: FormerDefinition > :: End,) - -> Self - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: Some(on_end), - } - } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > - (mut storage : core :: option :: Option < < Definition :: Types as former - :: FormerDefinitionTypes > :: Storage > , context : core :: option :: - Option < < Definition :: Types as former :: FormerDefinitionTypes > :: - Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert - :: Into < < Definition as former :: FormerDefinition > :: End > , - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: - Some(:: core :: convert :: Into :: into(on_end)), - } - } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types - as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { - let on_end = self.on_end.take().unwrap(); let context = - self.context.take(); former :: FormingEnd :: < Definition :: Types > - :: call(& on_end, self.storage, context) - } #[doc = "Setter for the 'name' field."] #[inline] pub fn name < Src > - (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < - String > , - { - debug_assert! (self.storage.name.is_none()); self.storage.name = :: - core :: option :: Option :: - Some(:: core :: convert :: Into :: into(src)); self - } #[doc = "Setter for the 'arg' field."] #[inline] pub fn arg < Src > - (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < & - 'child T > , - { - debug_assert! (self.storage.arg.is_none()); self.storage.arg = :: core - :: option :: Option :: Some(:: core :: convert :: Into :: into(src)); - self - } - } impl < 'child, T, Definition, > ChildFormer < 'child, T, Definition, > where - Definition :: Types : former :: FormerDefinitionTypes < Storage = - ChildFormerStorage < 'child, T, > , Formed = Child < 'child, T, > > , T : - 'child + ? Sized, Definition : former :: FormerDefinition, Definition :: Types - : former :: FormerDefinitionTypes < Storage = ChildFormerStorage < 'child, T, - > > , - { - pub fn preform(self) -> < Definition :: Types as former :: - FormerDefinitionTypes > :: Formed - { former :: StoragePreform :: preform(self.storage) } - } #[automatically_derived] impl < 'child, T, Definition, > ChildFormer < - 'child, T, Definition, > where T : 'child + ? Sized, Definition : former :: - FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < - Storage = ChildFormerStorage < 'child, T, > , Formed = Child < 'child, T, > > - , - { - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] - #[doc = - r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = - r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { let result = self.form(); return result; } - } impl < 'child, T, Definition > former :: FormerBegin < Definition > for - ChildFormer < 'child, T, Definition, > where Definition : former :: - FormerDefinition < Storage = ChildFormerStorage < 'child, T, > > , T : 'child - + ? Sized, - { - #[inline(always)] fn - former_begin(storage : core :: option :: Option < Definition :: Storage > - , context : core :: option :: Option < Definition :: Context > , on_end : - Definition :: End,) -> Self - { - debug_assert! (storage.is_none()); Self :: - begin(None, context, on_end) - } - } - #[doc = - r" Use as subformer of a field during process of forming of super structure."] - pub type ChildAsSubformer < 'child, T, __Superformer, __End > = ChildFormer < - 'child, T, ChildFormerDefinition < 'child, T, __Superformer, __Superformer, - __End, > , > ; - #[doc = - "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] - pub trait ChildAsSubformerEnd < 'child, T, SuperFormer > where T : 'child + ? - Sized, Self : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, - SuperFormer, SuperFormer > , > , {} impl < 'child, T, SuperFormer, __T > - ChildAsSubformerEnd < 'child, T, SuperFormer > for __T where T : 'child + ? - Sized, Self : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, - SuperFormer, SuperFormer > , > , {} +// #[automatically_derived] impl < 'child, T, > Child < 'child, T, > where T : +// 'child + ? Sized, +// { +// #[doc = r""] +// #[doc = +// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] +// #[doc = r""] #[inline(always)] pub fn former() -> ChildFormer < 'child, T, +// ChildFormerDefinition < 'child, T, (), Child < 'child, T, > , former :: +// ReturnPreformed > > +// { +// ChildFormer :: < 'child, T, ChildFormerDefinition < 'child, T, (), +// Child < 'child, T, > , former :: ReturnPreformed > > :: +// new_coercing(former :: ReturnPreformed) +// } +// } impl < 'child, T, Definition > former :: EntityToFormer < Definition > for +// Child < 'child, T, > where Definition : former :: FormerDefinition < Storage = +// ChildFormerStorage < 'child, T, > > , T : 'child + ? Sized, +// { type Former = ChildFormer < 'child, T, Definition > ; } impl < 'child, T, > +// former :: EntityToStorage for Child < 'child, T, > where T : 'child + ? Sized, +// { type Storage = ChildFormerStorage < 'child, T, > ; } impl < 'child, T, +// __Context, __Formed, __End > former :: EntityToDefinition < __Context, +// __Formed, __End > for Child < 'child, T, > where __End : former :: FormingEnd +// < ChildFormerDefinitionTypes < 'child, T, __Context, __Formed > > , T : 'child +// + ? Sized, +// { +// type Definition = ChildFormerDefinition < 'child, T, __Context, __Formed, +// __End > ; +// } +// +// #[derive(Debug)] +// pub struct ChildFormerDefinitionTypes < 'child, T, __Context = (), __Formed = Child < 'child, T, > , > +// where +// T : 'child + ?Sized, +// { +// _phantom : core :: marker :: PhantomData < +// (& 'child (), *const T, __Context, __Formed) > , +// } +// +// impl < 'child, T, __Context, __Formed, > :: core :: default :: Default for +// ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > where T : +// 'child + ? Sized, +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } +// +// impl < 'child, T, __Context, __Formed, > former :: FormerDefinitionTypes for +// ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > where T : +// 'child + ? Sized, +// { +// type Storage = ChildFormerStorage < 'child, T, > ; +// type Formed = __Formed; +// type Context = __Context; +// } +// +// #[derive(Debug)] pub struct ChildFormerDefinition +// < 'child, T, __Context = (), __Formed = Child < 'child, T, > , __End = former :: ReturnPreformed, > +// where +// T : 'child + ? Sized, +// { +// _phantom : core :: marker :: PhantomData < (& 'child (), *const T, __Context, __Formed, __End) > , +// } +// +// impl < 'child, T, __Context, __Formed, __End, > :: core :: default :: +// Default for ChildFormerDefinition < 'child, T, __Context, __Formed, __End, > +// where T : 'child + ? Sized, +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } +// +// impl < 'child, T, __Context, __Formed, __End, > former :: FormerDefinition +// for ChildFormerDefinition < 'child, T, __Context, __Formed, __End, > +// where +// __End : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, +// __Context, __Formed, > > , T : 'child + ? Sized, +// { +// type Types = ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > ; +// type End = __End; +// type Storage = ChildFormerStorage < 'child, T, > ; +// type Formed = __Formed; +// type Context = __Context; +// } +// +// #[doc = "Container of a corresponding former."] +// #[ allow( explicit_outlives_requirements ) ] +// pub struct ChildFormerStorage < 'child, T, > +// where +// T : 'child + ? Sized, +// { +// #[doc = r" A field"] +// pub name : :: core :: option :: Option < String > , +// #[doc = r" A field"] +// pub arg : :: core :: option :: Option < & 'child T > +// , +// } +// +// impl < 'child, T, > :: core :: default :: Default for ChildFormerStorage < +// 'child, T, > where T : 'child + ? Sized, +// { +// #[inline(always)] fn default() -> Self +// { +// Self +// { +// name : :: core :: option :: Option :: None, arg : :: core :: +// option :: Option :: None, +// } +// } +// } impl < 'child, T, > former :: Storage for ChildFormerStorage < 'child, T, > +// where T : 'child + ? Sized, { type Formed = Child < 'child, T, > ; } impl < +// 'child, T, > former :: StoragePreform for ChildFormerStorage < 'child, T, > +// where T : 'child + ? Sized, +// { +// type Preformed = Child < 'child, T, > ; fn preform(mut self) -> Self :: +// Preformed +// { +// let name = if self.name.is_some() { self.name.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'name' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < String +// >).maybe_default() +// } +// }; let arg = if self.arg.is_some() { self.arg.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'arg' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < & 'child T +// >).maybe_default() +// } +// }; let result = Child :: < 'child, T, > { name, arg, }; return result; +// } +// } +// #[doc = +// " Object to form [Child]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +// pub struct ChildFormer < 'child, T, Definition = ChildFormerDefinition < +// 'child, T, (), Child < 'child, T, > , former :: ReturnPreformed > , > where T +// : 'child + ? Sized, Definition : former :: FormerDefinition, Definition :: +// Types : former :: FormerDefinitionTypes < Storage = ChildFormerStorage < +// 'child, T, > > , +// { +// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: +// Storage, context : core :: option :: Option < < Definition :: Types as +// former :: FormerDefinitionTypes > :: Context > , on_end : core :: option +// :: Option < Definition :: End > , +// } #[automatically_derived] impl < 'child, T, Definition, > ChildFormer < +// 'child, T, Definition, > where T : 'child + ? Sized, Definition : former :: +// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = ChildFormerStorage < 'child, T, > > , +// { +// #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> +// Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > +// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , +// { Self :: begin_coercing(None, None, end,) } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn +// begin(mut storage : core :: option :: Option < < Definition :: Types as +// former :: FormerDefinitionTypes > :: Storage > , context : core :: option +// :: Option < < Definition :: Types as former :: FormerDefinitionTypes > :: +// Context > , on_end : < Definition as former :: FormerDefinition > :: End,) +// -> Self +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: Some(on_end), +// } +// } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > +// (mut storage : core :: option :: Option < < Definition :: Types as former +// :: FormerDefinitionTypes > :: Storage > , context : core :: option :: +// Option < < Definition :: Types as former :: FormerDefinitionTypes > :: +// Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert +// :: Into < < Definition as former :: FormerDefinition > :: End > , +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: +// Some(:: core :: convert :: Into :: into(on_end)), +// } +// } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types +// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { +// let on_end = self.on_end.take().unwrap(); let context = +// self.context.take(); former :: FormingEnd :: < Definition :: Types > +// :: call(& on_end, self.storage, context) +// } #[doc = "Setter for the 'name' field."] #[inline] pub fn name < Src > +// (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < +// String > , +// { +// debug_assert! (self.storage.name.is_none()); self.storage.name = :: +// core :: option :: Option :: +// Some(:: core :: convert :: Into :: into(src)); self +// } #[doc = "Setter for the 'arg' field."] #[inline] pub fn arg < Src > +// (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < & +// 'child T > , +// { +// debug_assert! (self.storage.arg.is_none()); self.storage.arg = :: core +// :: option :: Option :: Some(:: core :: convert :: Into :: into(src)); +// self +// } +// } impl < 'child, T, Definition, > ChildFormer < 'child, T, Definition, > where +// Definition :: Types : former :: FormerDefinitionTypes < Storage = +// ChildFormerStorage < 'child, T, > , Formed = Child < 'child, T, > > , T : +// 'child + ? Sized, Definition : former :: FormerDefinition, Definition :: Types +// : former :: FormerDefinitionTypes < Storage = ChildFormerStorage < 'child, T, +// > > , +// { +// pub fn preform(self) -> < Definition :: Types as former :: +// FormerDefinitionTypes > :: Formed +// { former :: StoragePreform :: preform(self.storage) } +// } #[automatically_derived] impl < 'child, T, Definition, > ChildFormer < +// 'child, T, Definition, > where T : 'child + ? Sized, Definition : former :: +// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < +// Storage = ChildFormerStorage < 'child, T, > , Formed = Child < 'child, T, > > +// , +// { +// #[doc = r""] +// #[doc = r" Finish setting options and call perform on formed entity."] +// #[doc = r""] +// #[doc = +// r" If `perform` defined then associated method is called and its result returned instead of entity."] +// #[doc = +// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] +// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { let result = self.form(); return result; } +// } impl < 'child, T, Definition > former :: FormerBegin < Definition > for +// ChildFormer < 'child, T, Definition, > where Definition : former :: +// FormerDefinition < Storage = ChildFormerStorage < 'child, T, > > , T : 'child +// + ? Sized, +// { +// #[inline(always)] fn +// former_begin(storage : core :: option :: Option < Definition :: Storage > +// , context : core :: option :: Option < Definition :: Context > , on_end : +// Definition :: End,) -> Self +// { +// debug_assert! (storage.is_none()); Self :: +// begin(None, context, on_end) +// } +// } +// #[doc = +// r" Use as subformer of a field during process of forming of super structure."] +// pub type ChildAsSubformer < 'child, T, __Superformer, __End > = ChildFormer < +// 'child, T, ChildFormerDefinition < 'child, T, __Superformer, __Superformer, +// __End, > , > ; +// #[doc = +// "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] +// pub trait ChildAsSubformerEnd < 'child, T, SuperFormer > where T : 'child + ? +// Sized, Self : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, +// SuperFormer, SuperFormer > , > , {} impl < 'child, T, SuperFormer, __T > +// ChildAsSubformerEnd < 'child, T, SuperFormer > for __T where T : 'child + ? +// Sized, Self : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, +// SuperFormer, SuperFormer > , > , {} // == end of generated // xxx : uncomment -// #[ test ] -// fn basic() -// { -// let got = Child::< 'static, str >::former().name( "abc" ).arg( "arg1" ).end(); -// let exp = Child::< 'static, str >{ name : "abc".into(), arg : "arg1" }; -// // a_id!( got, exp ); -// } +#[ test ] +fn basic() +{ + let got = Child::< 'static, str >::former().name( "abc" ).arg( "arg1" ).end(); + let exp = Child::< 'static, str >{ name : "abc".into(), arg : "arg1" }; + a_id!( got, exp ); +} diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 54bf71541e..9e6aa5108f 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1727,6 +1727,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = storage #[ doc = "Container of a corresponding former." ] + #[ allow( explicit_outlives_requirements ) ] // pub struct #former_storage < #struct_generics_ty > pub struct #former_storage < #struct_generics_with_defaults > where From 201245a9621552770d50e9ac41d839c024ec6e54 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 09:08:35 +0300 Subject: [PATCH 341/533] former : experimenting --- .../only_test/parametrized_field.rs | 8 + .../inc/former_tests/parametrized_field.rs | 303 +----------------- .../former_tests/parametrized_field_where.rs | 22 ++ module/core/former/tests/inc/mod.rs | 1 + 4 files changed, 33 insertions(+), 301 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/only_test/parametrized_field.rs create mode 100644 module/core/former/tests/inc/former_tests/parametrized_field_where.rs diff --git a/module/core/former/tests/inc/former_tests/only_test/parametrized_field.rs b/module/core/former/tests/inc/former_tests/only_test/parametrized_field.rs new file mode 100644 index 0000000000..7449ec7129 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/only_test/parametrized_field.rs @@ -0,0 +1,8 @@ + +#[ test ] +fn basic() +{ + let got = Child::< 'static, str >::former().name( "abc" ).arg( "arg1" ).end(); + let exp = Child::< 'static, str >{ name : "abc".into(), arg : "arg1" }; + a_id!( got, exp ); +} diff --git a/module/core/former/tests/inc/former_tests/parametrized_field.rs b/module/core/former/tests/inc/former_tests/parametrized_field.rs index 088efc67d7..fce1a22818 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_field.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_field.rs @@ -2,16 +2,12 @@ #[ allow( unused_imports ) ] use super::*; -// xxx : make it working - /// Parameter description. #[ allow( explicit_outlives_requirements ) ] #[ derive( Debug, PartialEq, the_module::Former ) ] // #[ debug ] // #[ derive( Debug, PartialEq ) ] -pub struct Child< 'child, T > -where - T : 'child + ?Sized, +pub struct Child< 'child, T : ?Sized + 'child > { name : String, arg : &'child T, @@ -19,301 +15,6 @@ where // == begin of generated -// #[automatically_derived] impl < 'child, T, > Child < 'child, T, > where T : -// 'child + ? Sized, -// { -// #[doc = r""] -// #[doc = -// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] -// #[doc = r""] #[inline(always)] pub fn former() -> ChildFormer < 'child, T, -// ChildFormerDefinition < 'child, T, (), Child < 'child, T, > , former :: -// ReturnPreformed > > -// { -// ChildFormer :: < 'child, T, ChildFormerDefinition < 'child, T, (), -// Child < 'child, T, > , former :: ReturnPreformed > > :: -// new_coercing(former :: ReturnPreformed) -// } -// } impl < 'child, T, Definition > former :: EntityToFormer < Definition > for -// Child < 'child, T, > where Definition : former :: FormerDefinition < Storage = -// ChildFormerStorage < 'child, T, > > , T : 'child + ? Sized, -// { type Former = ChildFormer < 'child, T, Definition > ; } impl < 'child, T, > -// former :: EntityToStorage for Child < 'child, T, > where T : 'child + ? Sized, -// { type Storage = ChildFormerStorage < 'child, T, > ; } impl < 'child, T, -// __Context, __Formed, __End > former :: EntityToDefinition < __Context, -// __Formed, __End > for Child < 'child, T, > where __End : former :: FormingEnd -// < ChildFormerDefinitionTypes < 'child, T, __Context, __Formed > > , T : 'child -// + ? Sized, -// { -// type Definition = ChildFormerDefinition < 'child, T, __Context, __Formed, -// __End > ; -// } -// -// #[derive(Debug)] -// pub struct ChildFormerDefinitionTypes < 'child, T, __Context = (), __Formed = Child < 'child, T, > , > -// where -// T : 'child + ?Sized, -// { -// _phantom : core :: marker :: PhantomData < -// (& 'child (), *const T, __Context, __Formed) > , -// } -// -// impl < 'child, T, __Context, __Formed, > :: core :: default :: Default for -// ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > where T : -// 'child + ? Sized, -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } -// -// impl < 'child, T, __Context, __Formed, > former :: FormerDefinitionTypes for -// ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > where T : -// 'child + ? Sized, -// { -// type Storage = ChildFormerStorage < 'child, T, > ; -// type Formed = __Formed; -// type Context = __Context; -// } -// -// #[derive(Debug)] pub struct ChildFormerDefinition -// < 'child, T, __Context = (), __Formed = Child < 'child, T, > , __End = former :: ReturnPreformed, > -// where -// T : 'child + ? Sized, -// { -// _phantom : core :: marker :: PhantomData < (& 'child (), *const T, __Context, __Formed, __End) > , -// } -// -// impl < 'child, T, __Context, __Formed, __End, > :: core :: default :: -// Default for ChildFormerDefinition < 'child, T, __Context, __Formed, __End, > -// where T : 'child + ? Sized, -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } -// -// impl < 'child, T, __Context, __Formed, __End, > former :: FormerDefinition -// for ChildFormerDefinition < 'child, T, __Context, __Formed, __End, > -// where -// __End : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, -// __Context, __Formed, > > , T : 'child + ? Sized, -// { -// type Types = ChildFormerDefinitionTypes < 'child, T, __Context, __Formed, > ; -// type End = __End; -// type Storage = ChildFormerStorage < 'child, T, > ; -// type Formed = __Formed; -// type Context = __Context; -// } -// -// #[doc = "Container of a corresponding former."] -// #[ allow( explicit_outlives_requirements ) ] -// pub struct ChildFormerStorage < 'child, T, > -// where -// T : 'child + ? Sized, -// { -// #[doc = r" A field"] -// pub name : :: core :: option :: Option < String > , -// #[doc = r" A field"] -// pub arg : :: core :: option :: Option < & 'child T > -// , -// } -// -// impl < 'child, T, > :: core :: default :: Default for ChildFormerStorage < -// 'child, T, > where T : 'child + ? Sized, -// { -// #[inline(always)] fn default() -> Self -// { -// Self -// { -// name : :: core :: option :: Option :: None, arg : :: core :: -// option :: Option :: None, -// } -// } -// } impl < 'child, T, > former :: Storage for ChildFormerStorage < 'child, T, > -// where T : 'child + ? Sized, { type Formed = Child < 'child, T, > ; } impl < -// 'child, T, > former :: StoragePreform for ChildFormerStorage < 'child, T, > -// where T : 'child + ? Sized, -// { -// type Preformed = Child < 'child, T, > ; fn preform(mut self) -> Self :: -// Preformed -// { -// let name = if self.name.is_some() { self.name.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'name' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < String -// >).maybe_default() -// } -// }; let arg = if self.arg.is_some() { self.arg.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'arg' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < & 'child T -// >).maybe_default() -// } -// }; let result = Child :: < 'child, T, > { name, arg, }; return result; -// } -// } -// #[doc = -// " Object to form [Child]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -// pub struct ChildFormer < 'child, T, Definition = ChildFormerDefinition < -// 'child, T, (), Child < 'child, T, > , former :: ReturnPreformed > , > where T -// : 'child + ? Sized, Definition : former :: FormerDefinition, Definition :: -// Types : former :: FormerDefinitionTypes < Storage = ChildFormerStorage < -// 'child, T, > > , -// { -// storage : < Definition :: Types as former :: FormerDefinitionTypes > :: -// Storage, context : core :: option :: Option < < Definition :: Types as -// former :: FormerDefinitionTypes > :: Context > , on_end : core :: option -// :: Option < Definition :: End > , -// } #[automatically_derived] impl < 'child, T, Definition, > ChildFormer < -// 'child, T, Definition, > where T : 'child + ? Sized, Definition : former :: -// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = ChildFormerStorage < 'child, T, > > , -// { -// #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> -// Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > -// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , -// { Self :: begin_coercing(None, None, end,) } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn -// begin(mut storage : core :: option :: Option < < Definition :: Types as -// former :: FormerDefinitionTypes > :: Storage > , context : core :: option -// :: Option < < Definition :: Types as former :: FormerDefinitionTypes > :: -// Context > , on_end : < Definition as former :: FormerDefinition > :: End,) -// -> Self -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: Some(on_end), -// } -// } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > -// (mut storage : core :: option :: Option < < Definition :: Types as former -// :: FormerDefinitionTypes > :: Storage > , context : core :: option :: -// Option < < Definition :: Types as former :: FormerDefinitionTypes > :: -// Context > , on_end : IntoEnd,) -> Self where IntoEnd : :: core :: convert -// :: Into < < Definition as former :: FormerDefinition > :: End > , -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: -// Some(:: core :: convert :: Into :: into(on_end)), -// } -// } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types -// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { -// let on_end = self.on_end.take().unwrap(); let context = -// self.context.take(); former :: FormingEnd :: < Definition :: Types > -// :: call(& on_end, self.storage, context) -// } #[doc = "Setter for the 'name' field."] #[inline] pub fn name < Src > -// (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < -// String > , -// { -// debug_assert! (self.storage.name.is_none()); self.storage.name = :: -// core :: option :: Option :: -// Some(:: core :: convert :: Into :: into(src)); self -// } #[doc = "Setter for the 'arg' field."] #[inline] pub fn arg < Src > -// (mut self, src : Src) -> Self where Src : :: core :: convert :: Into < & -// 'child T > , -// { -// debug_assert! (self.storage.arg.is_none()); self.storage.arg = :: core -// :: option :: Option :: Some(:: core :: convert :: Into :: into(src)); -// self -// } -// } impl < 'child, T, Definition, > ChildFormer < 'child, T, Definition, > where -// Definition :: Types : former :: FormerDefinitionTypes < Storage = -// ChildFormerStorage < 'child, T, > , Formed = Child < 'child, T, > > , T : -// 'child + ? Sized, Definition : former :: FormerDefinition, Definition :: Types -// : former :: FormerDefinitionTypes < Storage = ChildFormerStorage < 'child, T, -// > > , -// { -// pub fn preform(self) -> < Definition :: Types as former :: -// FormerDefinitionTypes > :: Formed -// { former :: StoragePreform :: preform(self.storage) } -// } #[automatically_derived] impl < 'child, T, Definition, > ChildFormer < -// 'child, T, Definition, > where T : 'child + ? Sized, Definition : former :: -// FormerDefinition, Definition :: Types : former :: FormerDefinitionTypes < -// Storage = ChildFormerStorage < 'child, T, > , Formed = Child < 'child, T, > > -// , -// { -// #[doc = r""] -// #[doc = r" Finish setting options and call perform on formed entity."] -// #[doc = r""] -// #[doc = -// r" If `perform` defined then associated method is called and its result returned instead of entity."] -// #[doc = -// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] -// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { let result = self.form(); return result; } -// } impl < 'child, T, Definition > former :: FormerBegin < Definition > for -// ChildFormer < 'child, T, Definition, > where Definition : former :: -// FormerDefinition < Storage = ChildFormerStorage < 'child, T, > > , T : 'child -// + ? Sized, -// { -// #[inline(always)] fn -// former_begin(storage : core :: option :: Option < Definition :: Storage > -// , context : core :: option :: Option < Definition :: Context > , on_end : -// Definition :: End,) -> Self -// { -// debug_assert! (storage.is_none()); Self :: -// begin(None, context, on_end) -// } -// } -// #[doc = -// r" Use as subformer of a field during process of forming of super structure."] -// pub type ChildAsSubformer < 'child, T, __Superformer, __End > = ChildFormer < -// 'child, T, ChildFormerDefinition < 'child, T, __Superformer, __Superformer, -// __End, > , > ; -// #[doc = -// "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] -// pub trait ChildAsSubformerEnd < 'child, T, SuperFormer > where T : 'child + ? -// Sized, Self : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, -// SuperFormer, SuperFormer > , > , {} impl < 'child, T, SuperFormer, __T > -// ChildAsSubformerEnd < 'child, T, SuperFormer > for __T where T : 'child + ? -// Sized, Self : former :: FormingEnd < ChildFormerDefinitionTypes < 'child, T, -// SuperFormer, SuperFormer > , > , {} - // == end of generated -// xxx : uncomment -#[ test ] -fn basic() -{ - let got = Child::< 'static, str >::former().name( "abc" ).arg( "arg1" ).end(); - let exp = Child::< 'static, str >{ name : "abc".into(), arg : "arg1" }; - a_id!( got, exp ); -} +include!( "./only_test/parametrized_field.rs" ); diff --git a/module/core/former/tests/inc/former_tests/parametrized_field_where.rs b/module/core/former/tests/inc/former_tests/parametrized_field_where.rs new file mode 100644 index 0000000000..baaaed538f --- /dev/null +++ b/module/core/former/tests/inc/former_tests/parametrized_field_where.rs @@ -0,0 +1,22 @@ +#![ allow( dead_code ) ] +#[ allow( unused_imports ) ] +use super::*; + +/// Parameter description. +#[ allow( explicit_outlives_requirements ) ] +#[ derive( Debug, PartialEq, the_module::Former ) ] +// #[ debug ] +// #[ derive( Debug, PartialEq ) ] +pub struct Child< 'child, T > +where + T : ?Sized + 'child, +{ + name : String, + arg : &'child T, +} + +// == begin of generated + +// == end of generated + +include!( "./only_test/parametrized_field.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index dc4e5a1842..9c7b8e82dd 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -56,6 +56,7 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod parametrized_struct_where; mod parametrized_field; + mod parametrized_field_where; #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod subformer_basic; From a6c2c980cd41b82b717854d913f007b5031feedc Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 11:19:14 +0300 Subject: [PATCH 342/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 9e6aa5108f..7b60e081e9 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1238,7 +1238,6 @@ Result< TokenStream > Definition::Types : former::FormerDefinitionTypes < Storage = < #stru < #struct_generics_ty > as former::EntityToStorage >::Storage, - // xxx : add test with life time + param + subform >, Types2 : former::FormerDefinitionTypes < From bf79584bbb8d4a82ce8201126e95c3e136f3423d Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 13:31:28 +0300 Subject: [PATCH 343/533] former : experimenting --- .../former/examples/former_component_from.rs | 40 +++ .../former/examples/former_custom_default.rs | 53 ++++ .../former/examples/former_custom_setter.rs | 45 ++++ .../former_custom_setter_overriden.rs | 39 +++ .../examples/former_custom_subformer.rs | 82 ++++++ module/core/former/examples/former_debug.rs | 39 +++ .../former/examples/former_many_fields.rs | 70 ++++++ .../examples/former_subformer_hashmap.rs | 29 +++ .../examples/former_subformer_hashset.rs | 30 +++ .../examples/former_subformer_vector.rs | 29 +++ module/core/former/examples/former_trivial.rs | 49 ++++ .../former/examples/former_trivial_expaned.rs | 234 ++++++++++++++++++ .../inc/former_tests/subformer_custom.rs | 3 +- module/core/former/tests/inc/mod.rs | 12 +- 14 files changed, 747 insertions(+), 7 deletions(-) create mode 100644 module/core/former/examples/former_component_from.rs create mode 100644 module/core/former/examples/former_custom_default.rs create mode 100644 module/core/former/examples/former_custom_setter.rs create mode 100644 module/core/former/examples/former_custom_setter_overriden.rs create mode 100644 module/core/former/examples/former_custom_subformer.rs create mode 100644 module/core/former/examples/former_debug.rs create mode 100644 module/core/former/examples/former_many_fields.rs create mode 100644 module/core/former/examples/former_subformer_hashmap.rs create mode 100644 module/core/former/examples/former_subformer_hashset.rs create mode 100644 module/core/former/examples/former_subformer_vector.rs create mode 100644 module/core/former/examples/former_trivial.rs create mode 100644 module/core/former/examples/former_trivial_expaned.rs diff --git a/module/core/former/examples/former_component_from.rs b/module/core/former/examples/former_component_from.rs new file mode 100644 index 0000000000..e7cadbb335 --- /dev/null +++ b/module/core/former/examples/former_component_from.rs @@ -0,0 +1,40 @@ +//! +//! Macro to implement `From` for each component (field) of a structure. +//! This macro simplifies the creation of `From` trait implementations for struct fields, +//! enabling easy conversion from a struct reference to its field types. +//! +//! # Features +//! +//! - Requires the `derive_component_from` feature to be enabled for use. +//! - The `ComponentFrom` derive macro can be applied to structs to automatically generate +//! `From` implementations for each field. +//! +//! # Attributes +//! +//! - `debug` : Optional attribute to enable debug-level output during the macro expansion process. +//! + +#[ cfg( not( feature = "derive_component_from" ) ) ] +fn main() {} + +#[ cfg( feature = "derive_component_from" ) ] +fn main() +{ + + #[ derive( former::ComponentFrom ) ] + struct MyStruct + { + pub field1 : i32, + pub field2 : String, + } + + // Generated implementations allow for the following conversions : + let my_struct = MyStruct { field1 : 10, field2 : "Hello".into() }; + let field1 : i32 = From::from( &my_struct ); + let field2 : String = From::from( &my_struct ); + dbg!( field1 ); + dbg!( field2 ); + // > field1 = 10 + // > field2 = "Hello" + +} diff --git a/module/core/former/examples/former_custom_default.rs b/module/core/former/examples/former_custom_default.rs new file mode 100644 index 0000000000..2cc73f3fc0 --- /dev/null +++ b/module/core/former/examples/former_custom_default.rs @@ -0,0 +1,53 @@ +//! The `Former` crate enhances struct initialization in Rust by allowing the specification of custom default values for fields through the `default` attribute. +//! +//! This feature not only provides a way to set initial values for struct fields without relying on the `Default` trait but also adds flexibility in handling cases where a field's type does not implement `Default`, or a non-standard default value is desired. +//! The above code snippet showcases the `Former` crate's ability to initialize struct fields with custom default values: +//! - The `number` field is initialized to `5`. +//! - The `greeting` field defaults to a greeting message, "Hello, Former!". +//! - The `numbers` field starts with a vector containing the integers `10`, `20`, and `30`. +//! +//! This approach significantly simplifies struct construction, particularly for complex types or where defaults beyond the `Default` trait's capability are required. By utilizing the `default` attribute, developers can ensure their structs are initialized safely and predictably, enhancing code clarity and maintainability. +//! + +#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +fn main() {} + +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + use former::Former; + + /// Structure with default attributes. + #[ derive( Debug, PartialEq, Former ) ] + pub struct ExampleStruct + { + #[ default( 5 ) ] + number : i32, + #[ default( "Hello, Former!".to_string() ) ] + greeting : String, + #[ default( vec![ 10, 20, 30 ] ) ] + numbers : Vec< i32 >, + } + + // + + let instance = ExampleStruct::former().form(); + let expected = ExampleStruct + { + number : 5, + greeting : "Hello, Former!".to_string(), + numbers : vec![ 10, 20, 30 ], + }; + assert_eq!( instance, expected ); + dbg!( &instance ); + // > &instance = ExampleStruct { + // > number: 5, + // > greeting: "Hello, Former!", + // > numbers: [ + // > 10, + // > 20, + // > 30, + // > ], + // > } + +} diff --git a/module/core/former/examples/former_custom_setter.rs b/module/core/former/examples/former_custom_setter.rs new file mode 100644 index 0000000000..10c592f913 --- /dev/null +++ b/module/core/former/examples/former_custom_setter.rs @@ -0,0 +1,45 @@ +//! With help of `Former`, it is possible to define multiple versions of a setter for a single field, providing the flexibility to include custom logic within the setter methods. +//! +//! This feature is particularly useful when you need to preprocess data or enforce specific constraints before assigning values to fields. Custom setters should have unique names to differentiate them from the default setters generated by `Former`, allowing for specialized behavior while maintaining clarity in your code. +//! In the example showcases a custom alternative setter, `word_exclaimed`, which appends an exclamation mark to the input string before storing it. This approach allows for additional processing or validation of the input data without compromising the simplicity of the builder pattern. +//! + +#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +fn main() {} + +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + use former::Former; + + /// Structure with a custom setter. + #[ derive( Debug, Former ) ] + pub struct StructWithCustomSetters + { + word : String, + } + + impl StructWithCustomSettersFormer + { + + // Custom alternative setter for `word` + pub fn word_exclaimed( mut self, value : impl Into< String > ) -> Self + { + debug_assert!( self.storage.word.is_none() ); + self.storage.word = Some( format!( "{}!", value.into() ) ); + self + } + + } + + let example = StructWithCustomSetters::former() + .word( "Hello" ) + .form(); + assert_eq!( example.word, "Hello".to_string() ); + + let example = StructWithCustomSetters::former() + .word_exclaimed( "Hello" ) + .form(); + assert_eq!( example.word, "Hello!".to_string() ); + +} diff --git a/module/core/former/examples/former_custom_setter_overriden.rs b/module/core/former/examples/former_custom_setter_overriden.rs new file mode 100644 index 0000000000..c817ab6872 --- /dev/null +++ b/module/core/former/examples/former_custom_setter_overriden.rs @@ -0,0 +1,39 @@ +//! It's also possible to completely override setter and write its own from scratch. +//! +//! For that use attribe `[ setter( false ) ]` to disable setter. In the example, the default setter for `word` is disabled, and a custom setter is defined to automatically append an exclamation mark to the string. This method allows for complete control over the data assignment process, enabling the inclusion of any necessary logic or validation steps. +//! + +#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +fn main() {} + +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + use former::Former; + + /// Structure with a custom setter. + #[ derive( Debug, Former ) ] + pub struct StructWithCustomSetters + { + #[ setter( false ) ] + word : String, + } + + impl StructWithCustomSettersFormer + { + + // Custom alternative setter for `word` + pub fn word( mut self, value : impl Into< String > ) -> Self + { + debug_assert!( self.storage.word.is_none() ); + self.storage.word = Some( format!( "{}!", value.into() ) ); + self + } + + } + + let example = StructWithCustomSetters::former() + .word( "Hello" ) + .form(); + assert_eq!( example.word, "Hello!".to_string() ); +} diff --git a/module/core/former/examples/former_custom_subformer.rs b/module/core/former/examples/former_custom_subformer.rs new file mode 100644 index 0000000000..d5726a43d1 --- /dev/null +++ b/module/core/former/examples/former_custom_subformer.rs @@ -0,0 +1,82 @@ +//! example of how to use former of another structure as subformer of former of current one +//! function `command` integrate `CommandFormer` into `AggregatorFormer`. + +#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +fn main() {} + +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + use std::collections::HashMap; + use former::Former; + + // Command struct with Former derived for builder pattern support + #[ derive( Debug, PartialEq, Former ) ] + pub struct Command + { + name : String, + description : String, + } + + // Aggregator struct to hold commands + #[ derive( Debug, PartialEq, Former ) ] + pub struct Aggregator + { + #[ setter( false ) ] + command : HashMap< String, Command >, + } + + // Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. + impl< Definition > AggregatorFormer< Definition > + where + End : former::FormingEnd< Aggregator, Context >, + { + #[ inline( always ) ] + pub fn command< IntoName >( self, name : IntoName ) -> CommandFormer< Self, impl former::FormingEnd< Command, Self > > + where + IntoName : core::convert::Into< String >, + { + let on_end = | command : Command, super_former : core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut commands ) = super_former.storage.command + { + commands.insert( command.name.clone(), command ); + } + else + { + let mut commands: HashMap< String, Command > = Default::default(); + commands.insert( command.name.clone(), command ); + super_former.storage.command = Some( commands ); + } + super_former + }; + let former = CommandFormer::begin( None, Some( self ), on_end ); + former.name( name ) + } + // xxx : review + } + + let ca = Aggregator::former() + .command( "echo" ) + .description( "prints all subjects and properties" ) // sets additional properties using custom subformer + .end() + .command( "exit" ) + .description( "just exit" ) // Sets additional properties using using custom subformer + .end() + .form(); + + dbg!( &ca ); + // > &ca = Aggregator { + // > command: { + // > "echo": Command { + // > name: "echo", + // > description: "prints all subjects and properties", + // > }, + // > "exit": Command { + // > name: "exit", + // > description: "just exit", + // > }, + // > }, + // > } +} diff --git a/module/core/former/examples/former_debug.rs b/module/core/former/examples/former_debug.rs new file mode 100644 index 0000000000..0a849f684a --- /dev/null +++ b/module/core/former/examples/former_debug.rs @@ -0,0 +1,39 @@ +//! +//! This is a demonstration of attribute debug. +//! The attribute `#[ debug ]` outputs generated code into the console during compilation. +//! + +#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +fn main() {} + +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + use former::Former; + + + #[ derive( Debug, PartialEq, Former ) ] + // #[ debug ] + // Uncomment to see what derive expand into + pub struct UserProfile + { + age : i32, + username : String, + bio_optional : Option< String >, // Fields could be optional + } + + let profile = UserProfile::former() + .age( 30 ) + .username( "JohnDoe".to_string() ) + .bio_optional( "Software Developer".to_string() ) // Optionally provide a bio + .form(); + + dbg!( &profile ); + // Expected output: + // &profile = UserProfile { + // age: 30, + // username: "JohnDoe", + // bio_optional: Some("Software Developer"), + // } + +} diff --git a/module/core/former/examples/former_many_fields.rs b/module/core/former/examples/former_many_fields.rs new file mode 100644 index 0000000000..b8f506e9d3 --- /dev/null +++ b/module/core/former/examples/former_many_fields.rs @@ -0,0 +1,70 @@ +//! +//! Utilizing the Former Crate for Struct Initialization +//! +//! This example demonstrates the capability of the `Former` crate to simplify struct initialization through the builder pattern, particularly for structs with a mix of required and optional fields, as well as collections like vectors and hash maps. +//! +//! The `Structure1` struct is defined with various field types to showcase the flexibility of `Former`: +//! - `int_1`: A required integer field. +//! - `string_1`: A required string field. +//! - `vec_1`: A vector of unsigned integers, showcasing collection handling. +//! - `hashmap_1`: A hash map storing key-value pairs, both strings, illustrating how `Former` can manage more complex data structures. +//! - `int_optional_1`: An optional integer field, demonstrating `Former`'s capability to handle optional fields seamlessly. +//! - `string_optional_1`: An optional string field, further exemplifying optional field handling. +//! +//! A hash map is first created and populated with two key-value pairs. The `Structure1` struct is then instantiated using the fluent builder pattern methods provided by `Former`. Each method corresponds to one of `Structure1`'s fields, allowing for intuitive and clear field assignment. The `.form()` method completes the construction of the `Structure1` instance. +//! +//! The builder pattern methods significantly streamline the process of struct initialization, especially for structs with complex or optional fields. By leveraging `Former`, developers can write more readable and maintainable initialization code, avoiding the verbosity and complexity often associated with manual struct instantiation. +//! +//! The `dbg!` macro is utilized to print the constructed `Structure1` instance, confirming that all fields are correctly assigned, including the handling of optional fields and collections. This example underscores the power and convenience of using `Former` for struct initialization in Rust projects. + +#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +fn main() {} + +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + use former::Former; + + #[ derive( Debug, PartialEq, Eq, Former ) ] + pub struct Structure1 + { + int_1 : i32, + string_1 : String, + vec_1 : Vec< u32 >, + hashmap_1 : std::collections::HashMap< String, String >, + int_optional_1 : core::option::Option< i32 >, + string_optional_1 : Option< String >, + } + let hashmap = std::collections::HashMap::from + ([ + ( "k1".to_string(), "v1".to_string() ), + ( "k2".to_string(), "v2".to_string() ), + ]); + + let struct1 = Structure1::former() + .int_1( 13 ) + .string_1( "Abcd".to_string() ) + .vec_1( vec![ 1, 3 ] ) + .hashmap_1( hashmap ) + .string_optional_1( "dir1" ) + .form(); + dbg!( &struct1 ); + +// < &struct1 = Structure1 { +// < int_1: 13, +// < string_1: "Abcd", +// < vec_1: [ +// < 1, +// < 3, +// < ], +// < hashmap_1: { +// < "k1": "v1", +// < "k2": "v2", +// < }, +// < int_optional_1: None, +// < string_optional_1: Some( +// < "dir1", +// < ), +// < } + +} diff --git a/module/core/former/examples/former_subformer_hashmap.rs b/module/core/former/examples/former_subformer_hashmap.rs new file mode 100644 index 0000000000..121b10a29a --- /dev/null +++ b/module/core/former/examples/former_subformer_hashmap.rs @@ -0,0 +1,29 @@ +//! # Example Usage +//! +//! Demonstrates how to use `HashMapSubformer` with the `HashMapLike` trait to build a `std::collections::HashMap`: +//! + +#[ cfg( not( all( feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +fn main() {} + +#[ cfg( all( feature = "derive_former", not( feature = "no_std" ) ) ) ] +fn main() +{ + use test_tools::exposed::*; + + #[ derive( Debug, PartialEq, former::Former ) ] + pub struct StructWithMap + { + #[ container( former::HashMapSubformer ) ] + map : std::collections::HashMap< &'static str, &'static str >, + } + + let struct1 = StructWithMap::former() + .map() + .insert( "a", "b" ) + .insert( "c", "d" ) + .end() + .form() + ; + assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); +} diff --git a/module/core/former/examples/former_subformer_hashset.rs b/module/core/former/examples/former_subformer_hashset.rs new file mode 100644 index 0000000000..badb7ddb68 --- /dev/null +++ b/module/core/former/examples/former_subformer_hashset.rs @@ -0,0 +1,30 @@ +//! # Example Usage +//! +//! Demonstrates how to use `HashMapSubformer` with the `HashMapLike` trait to build a `std::collections::HashMap`: +//! + +#[ cfg( not( all( feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +fn main() {} + +#[ cfg( all( feature = "derive_former", not( feature = "no_std" ) ) ) ] +fn main() +{ + use test_tools::exposed::*; + + #[ derive( Debug, PartialEq, former::Former ) ] + pub struct StructWithSet + { + #[ container( former::HashSetSubformer ) ] + set : std::collections::HashSet< &'static str >, + } + + let instance = StructWithSet::former() + .set() + .insert("apple") + .insert("banana") + .end() + .form(); + + assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] }); + +} diff --git a/module/core/former/examples/former_subformer_vector.rs b/module/core/former/examples/former_subformer_vector.rs new file mode 100644 index 0000000000..2be17c7868 --- /dev/null +++ b/module/core/former/examples/former_subformer_vector.rs @@ -0,0 +1,29 @@ +//! # Example Usage +//! +//! Demonstrates how to use `HashMapSubformer` with the `HashMapLike` trait to build a `std::collections::HashMap`: +//! + +#[ cfg( not( all( feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +fn main() {} + +#[ cfg( all( feature = "derive_former", not( feature = "no_std" ) ) ) ] +fn main() +{ + + #[ derive( Debug, PartialEq, former::Former ) ] + pub struct StructWithVec + { + #[ container( former::VectorSubformer ) ] + vec : Vec< &'static str >, + } + + let instance = StructWithVec::former() + .vec() + .push( "apple" ) + .push( "banana" ) + .end() + .form(); + + assert_eq!( instance, StructWithVec { vec: vec![ "apple", "banana" ] } ); + +} diff --git a/module/core/former/examples/former_trivial.rs b/module/core/former/examples/former_trivial.rs new file mode 100644 index 0000000000..78331e5577 --- /dev/null +++ b/module/core/former/examples/former_trivial.rs @@ -0,0 +1,49 @@ +//! # Builder Pattern Implementation with Former +//! +//! This module demonstrates the use of the `Former` trait to apply the builder pattern for Rust structs. +//! The `Former` trait simplifies the instantiation of structs by enabling a fluent, method-chaining approach +//! to set fields before finalizing the instance with `.form()`. It is particularly useful for structs with optional fields +//! or when a clear and concise way to instantiate complex data structures is needed. +//! +//! ## How Former Works +//! +//! - **Trait Derivation** : By deriving `Former` on a struct, you automatically generate builder methods for each field. +//! - **Fluent Interface** : Each field's builder method allows for setting the value of that field and returns a mutable reference to the builder, +//! enabling method chaining. +//! - **Optional Fields** : Optional fields can be easily handled without needing to explicitly set them to `None`. +//! - **Finalization** : The `.form()` method finalizes the building process and returns the constructed struct instance. +//! +//! This approach abstracts away the need for manually implementing a builder for each struct, making code more readable and maintainable. +//! + +#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +fn main() {} + +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + use former::Former; + + #[ derive( Debug, PartialEq, Former ) ] + pub struct UserProfile + { + age : i32, + username : String, + bio_optional : Option< String >, // Fields could be optional + } + + let profile = UserProfile::former() + .age( 30 ) + .username( "JohnDoe".to_string() ) + .bio_optional( "Software Developer".to_string() ) // Optionally provide a bio + .form(); + + dbg!( &profile ); + // Expected output: + // &profile = UserProfile { + // age: 30, + // username: "JohnDoe", + // bio_optional: Some("Software Developer"), + // } + +} diff --git a/module/core/former/examples/former_trivial_expaned.rs b/module/core/former/examples/former_trivial_expaned.rs new file mode 100644 index 0000000000..ecfdb4f474 --- /dev/null +++ b/module/core/former/examples/former_trivial_expaned.rs @@ -0,0 +1,234 @@ +//! # Builder Pattern Implementation with Former +//! +//! This module demonstrates the use of the `Former` trait to apply the builder pattern for Rust structs. +//! The `Former` trait simplifies the instantiation of structs by enabling a fluent, method-chaining approach +//! to set fields before finalizing the instance with `.form()`. It is particularly useful for structs with optional fields +//! or when a clear and concise way to instantiate complex data structures is needed. +//! +//! ## How Former Works +//! +//! - **Trait Derivation** : By deriving `Former` on a struct, you automatically generate builder methods for each field. +//! - **Fluent Interface** : Each field's builder method allows for setting the value of that field and returns a mutable reference to the builder, +//! enabling method chaining. +//! - **Optional Fields** : Optional fields can be easily handled without needing to explicitly set them to `None`. +//! - **Finalization** : The `.form()` method finalizes the building process and returns the constructed struct instance. +//! +//! This approach abstracts away the need for manually implementing a builder for each struct, making code more readable and maintainable. +//! + +// xxx : regenerate + +// #![ allow( dead_code ) ] +// +// #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +// fn main(){} +// +// #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +// fn main() +// { +// +// #[ derive( Debug, PartialEq ) ] +// pub struct UserProfile +// { +// age : i32, +// username : String, +// bio_optional : Option< String >, // Fields could be optional +// } +// +// impl UserProfile +// { +// #[ inline( always ) ] +// pub fn former() -> UserProfileFormer< UserProfile, former::ReturnFormed > +// { +// UserProfileFormer::< UserProfile, former::ReturnFormed >::new() +// } +// } +// +// #[ derive( Debug, Default ) ] +// pub struct UserProfileFormerStorage +// { +// age : Option< i32 >, +// username : Option< String >, +// bio_optional : Option< String >, +// } +// +// pub struct UserProfileFormer +// < +// Context = UserProfile, +// End = former::ReturnFormed, +// > +// where +// End : former::FormingEnd< UserProfile, Context >, +// { +// storage : UserProfileFormerStorage, +// context : Option< Context >, +// on_end : Option< End >, +// } +// +// impl< Context, End > UserProfileFormer< Context, End > +// where +// End : former::FormingEnd< UserProfile, Context >, +// { +// #[ inline( always ) ] +// pub fn form( mut self ) -> UserProfile +// { +// let age = if self.storage.age.is_some() +// { +// self.storage.age.take().unwrap() +// } +// else +// { +// let val : i32 = +// { +// trait NotDefault< T > +// { +// fn maybe_default( self : &Self ) -> T { panic!( "Field 'age' isn't initialized" ) } +// } +// trait WithDefault< T > +// { +// fn maybe_default( self : &Self ) -> T; +// } +// impl< T > NotDefault< T > for &::core::marker::PhantomData< T > {} +// impl< T > WithDefault< T > for ::core::marker::PhantomData< T > +// where +// T : ::core::default::Default, +// { +// fn maybe_default( self : &Self ) -> T +// { +// T::default() +// } +// } +// ( &::core::marker::PhantomData::< i32 > ).maybe_default() +// }; +// val +// }; +// let username = if self.storage.username.is_some() +// { +// self.storage.username.take().unwrap() +// } +// else +// { +// let val : String = +// { +// trait NotDefault< T > +// { +// fn maybe_default( self : &Self ) -> T { panic!( "Field 'username' isn't initialized" ) } +// } +// trait WithDefault< T > +// { +// fn maybe_default( self : &Self ) -> T; +// } +// impl< T > NotDefault< T > for &::core::marker::PhantomData< T > {} +// impl< T > WithDefault< T > for ::core::marker::PhantomData< T > +// where +// T : ::core::default::Default, +// { +// fn maybe_default( self : &Self ) -> T +// { +// T::default() +// } +// } +// ( &::core::marker::PhantomData::< String > ).maybe_default() +// }; +// val +// }; +// let bio_optional = if self.storage.bio_optional.is_some() +// { +// Option::Some( self.storage.bio_optional.take().unwrap() ) +// } +// else +// { +// Option::None +// }; +// let result = UserProfile +// { +// age, +// username, +// bio_optional, +// }; +// return result; +// } +// +// #[ inline( always ) ] +// pub fn perform( self ) -> UserProfile +// { +// let result = self.form(); +// return result; +// } +// +// #[ inline( always ) ] +// pub fn new() -> UserProfileFormer< UserProfile, former::ReturnFormed > +// { +// UserProfileFormer::< UserProfile, former::ReturnFormed >::begin( None, former::ReturnFormed ) +// } +// +// #[ inline( always ) ] +// pub fn begin +// ( +// context : Option< Context >, +// on_end : End, +// ) -> Self +// { +// Self +// { +// storage : core::default::Default::default(), +// context : context, +// on_end : Option::Some( on_end ), +// } +// } +// +// #[ inline( always ) ] +// pub fn end( mut self ) -> Context +// { +// let on_end = self.on_end.take().unwrap(); +// let context = self.context.take(); +// let formed = self.form(); +// on_end.call( formed, context ) +// } +// +// #[ inline ] +// pub fn age< Src >( mut self, src : Src ) -> Self +// where +// Src : Into< i32 >, +// { +// debug_assert!( self.storage.age.is_none() ); +// self.storage.age = Option::Some( src.into() ); +// self +// } +// +// #[ inline ] +// pub fn username< Src >( mut self, src : Src ) -> Self +// where +// Src : Into< String >, +// { +// debug_assert!( self.storage.username.is_none() ); +// self.storage.username = Option::Some( src.into() ); +// self +// } +// +// #[ inline ] +// pub fn bio_optional< Src >( mut self, src : Src ) -> Self +// where +// Src : Into< String >, +// { +// debug_assert!( self.storage.bio_optional.is_none() ); +// self.storage.bio_optional = Option::Some( src.into() ); +// self +// } +// } +// +// let profile = UserProfile::former() +// .age( 30 ) +// .username( "JohnDoe".to_string() ) +// .bio_optional( "Software Developer".to_string() ) +// .form(); +// +// dbg!( &profile ); +// // Expected output: +// // &profile = UserProfile { +// // age: 30, +// // username: "JohnDoe", +// // bio_optional: Some("Software Developer"), +// // } +// +// } diff --git a/module/core/former/tests/inc/former_tests/subformer_custom.rs b/module/core/former/tests/inc/former_tests/subformer_custom.rs index eb4cb2d579..7602eb2521 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom.rs @@ -73,7 +73,8 @@ where K : core::hash::Hash + std::cmp::Eq, Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Aggregator< K > >, + Definition::Storage : former::StoragePreform< Preformed = Aggregator< K > >, + // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Aggregator< K > >, { // diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 9c7b8e82dd..937d37ed6f 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -130,13 +130,13 @@ only_for_terminal_module! fn former_trybuild() { -// println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); -// let t = test_tools::compiletime::TestCases::new(); -// + println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); + let t = test_tools::compiletime::TestCases::new(); + // zzz : uncomment - // t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); - // t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); - // t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); + t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); + t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); + t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); } From 7b80653cb8171a8dcdd31a15a69924ab7dd6dac1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 15:14:33 +0300 Subject: [PATCH 344/533] former : experimenting --- module/core/former/tests/inc/mod.rs | 154 +++++++++---------- module/core/former_meta/src/derive/former.rs | 24 +-- 2 files changed, 92 insertions(+), 86 deletions(-) diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 937d37ed6f..ce1ea7f4c5 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -7,84 +7,84 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_common; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_vec; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_hashset; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_hashmap; - - mod a_basic_manual; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_common; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_vec; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_hashset; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_hashmap; +// +// mod a_basic_manual; mod a_basic; - mod a_primitives_manual; - mod a_primitives; - - mod a_containers_without_subformer; - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer_manual; - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer; - - mod attribute_default_container; - mod attribute_default_primitive; - mod attribute_perform; - mod attribute_setter; - mod attribute_alias; - mod attribute_feature; - - mod string_slice_manual; - mod string_slice; - mod unsigned_primitive_types; - mod default_user_type; - mod user_type_no_default; - mod user_type_no_debug; - mod visibility; - - mod name_collision_former_hashmap_without_parameter; - mod name_collision_former_vector_without_parameter; - mod name_collisions; - mod name_collision_context; - mod name_collision_end; - mod name_collision_on_end; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_manual; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_imm; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_where; - mod parametrized_field; - mod parametrized_field_where; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_basic; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_custom; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_custom_experimental; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_manual; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_implicit; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_manual; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_named; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_named_manual; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_and_container; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_and_container_parametrized; +// mod a_primitives_manual; +// mod a_primitives; +// +// mod a_containers_without_subformer; +// #[ cfg( not( feature = "no_std" ) ) ] +// mod a_containers_with_subformer_manual; +// #[ cfg( not( feature = "no_std" ) ) ] +// mod a_containers_with_subformer; +// +// mod attribute_default_container; +// mod attribute_default_primitive; +// mod attribute_perform; +// mod attribute_setter; +// mod attribute_alias; +// mod attribute_feature; +// +// mod string_slice_manual; +// mod string_slice; +// mod unsigned_primitive_types; +// mod default_user_type; +// mod user_type_no_default; +// mod user_type_no_debug; +// mod visibility; +// +// mod name_collision_former_hashmap_without_parameter; +// mod name_collision_former_vector_without_parameter; +// mod name_collisions; +// mod name_collision_context; +// mod name_collision_end; +// mod name_collision_on_end; +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_manual; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_imm; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_where; +// mod parametrized_field; +// mod parametrized_field_where; +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_basic; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_custom; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_custom_experimental; +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container_manual; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container_implicit; +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_manual; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_named; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_named_manual; +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_and_container; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_and_container_parametrized; } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 7b60e081e9..236364b444 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1452,7 +1452,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { < Definition = #former_definition < #former_definition_args > > where - Definition : former::FormerDefinition, + Definition : former::FormerDefinition< Storage = #former_storage < #struct_generics_ty > >, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #struct_generics_ty > >, }; let extra = generic_params::merge( &generics, &extra.into() ); @@ -1466,11 +1466,15 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { < Definition = #former_definition < #former_definition_args > > where - Definition : former::FormerDefinition, + Definition : former::FormerDefinition + < + Storage = #former_storage < #struct_generics_ty >, + Formed = #stru < #struct_generics_ty >, + >, Definition::Types : former::FormerDefinitionTypes < Storage = #former_storage < #struct_generics_ty >, - Formed = #stru < #struct_generics_ty > + Formed = #stru < #struct_generics_ty >, >, }; let extra = generic_params::merge( &generics, &extra.into() ); @@ -1792,7 +1796,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where #former_generics_where { - storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + // storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, // xxx + storage : Definition::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : core::option::Option< Definition::End >, // zzz : should on_end be optional? @@ -1838,10 +1843,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ inline( always ) ] pub fn begin ( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + mut storage : core::option::Option< Definition::Storage >, + context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, // xxx on_end : < Definition as former::FormerDefinition >::End, - ) -> Self + ) + -> Self { if storage.is_none() { @@ -1862,7 +1868,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #[ inline( always ) ] pub fn begin_coercing< IntoEnd > ( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : IntoEnd, ) -> Self @@ -1911,8 +1917,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl< #former_generics_impl > #former< #former_generics_ty > where + Definition : former::FormerDefinition< Storage = #former_storage < #struct_generics_ty >, Formed = #stru < #struct_generics_ty > >, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #struct_generics_ty >, Formed = #stru < #struct_generics_ty > >, - // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = #stru < #struct_generics_ty > >, #former_generics_where { From b63dbf5cc558811cb49ed04d39f86f9530eee419 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 15:18:31 +0300 Subject: [PATCH 345/533] former : experimenting --- .../former/tests/inc/former_tests/a_basic_manual.rs | 10 +++++----- .../tests/inc/former_tests/a_primitives_manual.rs | 8 ++++---- .../inc/former_tests/parametrized_struct_manual.rs | 10 +++++----- .../tests/inc/former_tests/string_slice_manual.rs | 10 +++++----- .../former/tests/inc/former_tests/subformer_basic.rs | 2 +- .../former/tests/inc/former_tests/subformer_custom.rs | 2 +- .../inc/former_tests/subformer_custom_experimental.rs | 2 +- module/core/former_meta/src/derive/former.rs | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 2b8aeefd92..226159c95c 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -176,7 +176,7 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { - storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + storage : Definition::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : core::option::Option< Definition::End >, } @@ -211,7 +211,7 @@ where #[ inline( always ) ] pub fn begin ( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, ) @@ -232,7 +232,7 @@ where #[ inline( always ) ] pub fn begin_coercing< IntoEnd > ( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : IntoEnd, ) @@ -283,8 +283,8 @@ impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Struct1 >, + Definition::Storage : former::StoragePreform, + Definition::Storage : former::StoragePreform< Preformed = Struct1 >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index a82e9cf202..f5b1ac69ba 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -185,7 +185,7 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { - storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + storage : Definition::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : core::option::Option< Definition::End >, } @@ -226,7 +226,7 @@ where #[ inline( always ) ] pub fn begin ( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self @@ -246,7 +246,7 @@ where #[ inline( always ) ] pub fn begin_coercing< IntoEnd > ( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : IntoEnd, ) -> Self @@ -308,7 +308,7 @@ where impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + Definition::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, { diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 0ddad4fd47..81a6d1031b 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -210,7 +210,7 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > > { - storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + storage : Definition::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : core::option::Option< Definition::End >, } @@ -243,7 +243,7 @@ where } #[ inline( always ) ] - pub fn begin( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self + pub fn begin( mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self { if storage.is_none() { @@ -258,7 +258,7 @@ where } #[ inline( always ) ] - pub fn begin_coercing< IntoEnd >( mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : IntoEnd, ) -> Self + pub fn begin_coercing< IntoEnd >( mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : IntoEnd, ) -> Self where IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > { if storage.is_none() @@ -317,8 +317,8 @@ where K : core::hash::Hash + std::cmp::Eq, Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, >, Formed = Command< K, > >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Command< K, > > + Definition::Storage : former::StoragePreform, + Definition::Storage : former::StoragePreform< Preformed = Command< K, > > { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 5c540d1aac..5b8ab1f2dd 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -145,7 +145,7 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a > >, { - storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, + storage : Definition::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : core::option::Option< Definition::End >, } @@ -183,7 +183,7 @@ where #[ inline( always ) ] pub fn begin ( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self @@ -203,7 +203,7 @@ where #[ inline( always ) ] pub fn begin_coercing< IntoEnd > ( - mut storage : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Storage >, + mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : IntoEnd, ) -> Self @@ -249,8 +249,8 @@ impl< 'a, Definition > Struct1Former< 'a, Definition > where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a > >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Struct1< 'a > >, + Definition::Storage : former::StoragePreform, + Definition::Storage : former::StoragePreform< Preformed = Struct1< 'a > >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 66b1ad7a0f..62825d7d19 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -62,7 +62,7 @@ impl< K, Definition > CommandFormer< K, Definition > where K : core::hash::Hash + std::cmp::Eq, Definition : former::FormerDefinition, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform, + Definition::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K > >, { diff --git a/module/core/former/tests/inc/former_tests/subformer_custom.rs b/module/core/former/tests/inc/former_tests/subformer_custom.rs index 7602eb2521..9d23d9f24e 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom.rs @@ -74,7 +74,7 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, Definition::Storage : former::StoragePreform< Preformed = Aggregator< K > >, - // < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Aggregator< K > >, + // Definition::Storage : former::StoragePreform< Preformed = Aggregator< K > >, { // diff --git a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs index 4fcdec6101..b939740ef3 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs @@ -35,7 +35,7 @@ where K : core::hash::Hash + std::cmp::Eq, Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, - < Definition::Types as former::FormerDefinitionTypes >::Storage : former::StoragePreform< Preformed = Aggregator< K > >, + Definition::Storage : former::StoragePreform< Preformed = Aggregator< K > >, { // diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 236364b444..fe20e05c9a 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1796,7 +1796,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where #former_generics_where { - // storage : < Definition::Types as former::FormerDefinitionTypes >::Storage, // xxx + // storage : Definition::Storage, // xxx storage : Definition::Storage, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : core::option::Option< Definition::End >, From f50b54b8137d2d367f8a91e915acddbe078988c9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 15:19:38 +0300 Subject: [PATCH 346/533] former : experimenting --- .../core/former/tests/inc/former_tests/a_basic_manual.rs | 6 +++--- .../former/tests/inc/former_tests/a_primitives_manual.rs | 6 +++--- .../tests/inc/former_tests/parametrized_struct_manual.rs | 6 +++--- .../former/tests/inc/former_tests/string_slice_manual.rs | 6 +++--- module/core/former_meta/src/derive/former.rs | 7 +++---- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 226159c95c..0b7b9e5b05 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -177,7 +177,7 @@ where Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { storage : Definition::Storage, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + context : core::option::Option< Definition::Context >, on_end : core::option::Option< Definition::End >, } @@ -212,7 +212,7 @@ where pub fn begin ( mut storage : core::option::Option< Definition::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + context : core::option::Option< Definition::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self @@ -233,7 +233,7 @@ where pub fn begin_coercing< IntoEnd > ( mut storage : core::option::Option< Definition::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + context : core::option::Option< Definition::Context >, on_end : IntoEnd, ) -> Self diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index f5b1ac69ba..26f12a1cf2 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -186,7 +186,7 @@ where Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { storage : Definition::Storage, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + context : core::option::Option< Definition::Context >, on_end : core::option::Option< Definition::End >, } @@ -227,7 +227,7 @@ where pub fn begin ( mut storage : core::option::Option< Definition::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + context : core::option::Option< Definition::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self { @@ -247,7 +247,7 @@ where pub fn begin_coercing< IntoEnd > ( mut storage : core::option::Option< Definition::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + context : core::option::Option< Definition::Context >, on_end : IntoEnd, ) -> Self where diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 81a6d1031b..28a7ded170 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -211,7 +211,7 @@ where Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > > { storage : Definition::Storage, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + context : core::option::Option< Definition::Context >, on_end : core::option::Option< Definition::End >, } @@ -243,7 +243,7 @@ where } #[ inline( always ) ] - pub fn begin( mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self + pub fn begin( mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self { if storage.is_none() { @@ -258,7 +258,7 @@ where } #[ inline( always ) ] - pub fn begin_coercing< IntoEnd >( mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, on_end : IntoEnd, ) -> Self + pub fn begin_coercing< IntoEnd >( mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, on_end : IntoEnd, ) -> Self where IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > { if storage.is_none() diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 5b8ab1f2dd..73af4f49b4 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -146,7 +146,7 @@ where Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a > >, { storage : Definition::Storage, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + context : core::option::Option< Definition::Context >, on_end : core::option::Option< Definition::End >, } @@ -184,7 +184,7 @@ where pub fn begin ( mut storage : core::option::Option< Definition::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + context : core::option::Option< Definition::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self { @@ -204,7 +204,7 @@ where pub fn begin_coercing< IntoEnd > ( mut storage : core::option::Option< Definition::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + context : core::option::Option< Definition::Context >, on_end : IntoEnd, ) -> Self where IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End >, diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index fe20e05c9a..8f7a9d8913 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1796,9 +1796,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where #former_generics_where { - // storage : Definition::Storage, // xxx storage : Definition::Storage, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + context : core::option::Option< Definition::Context >, on_end : core::option::Option< Definition::End >, // zzz : should on_end be optional? } @@ -1844,7 +1843,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > pub fn begin ( mut storage : core::option::Option< Definition::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, // xxx + context : core::option::Option< Definition::Context >, // xxx on_end : < Definition as former::FormerDefinition >::End, ) -> Self @@ -1869,7 +1868,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > pub fn begin_coercing< IntoEnd > ( mut storage : core::option::Option< Definition::Storage >, - context : core::option::Option< < Definition::Types as former::FormerDefinitionTypes >::Context >, + context : core::option::Option< Definition::Context >, on_end : IntoEnd, ) -> Self where From b3aa51674d349d5869b41dba41315a3d383715c4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 15:27:49 +0300 Subject: [PATCH 347/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 14 +++-- .../inc/former_tests/a_primitives_manual.rs | 10 ++-- .../inc/former_tests/subformer_custom.rs | 3 +- module/core/former/tests/inc/mod.rs | 52 +++++++++---------- module/core/former_meta/src/derive/former.rs | 2 +- 5 files changed, 39 insertions(+), 42 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 0b7b9e5b05..69a2a92d08 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -118,7 +118,6 @@ pub struct Struct1FormerStorage impl ::core::default::Default for Struct1FormerStorage { - #[ inline( always ) ] fn default() -> Self { @@ -173,8 +172,8 @@ pub struct Struct1Former Definition = Struct1FormerDefinition< (), Struct1, former::ReturnPreformed >, > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { storage : Definition::Storage, context : core::option::Option< Definition::Context >, @@ -184,8 +183,8 @@ where #[ automatically_derived ] impl< Definition > Struct1Former< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { #[ inline( always ) ] @@ -281,9 +280,8 @@ where impl< Definition > Struct1Former< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, - Definition::Storage : former::StoragePreform, + Definition : former::FormerDefinition< Storage = Struct1FormerStorage, Formed = Struct1 >, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, Definition::Storage : former::StoragePreform< Preformed = Struct1 >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 26f12a1cf2..5c0b14ea3f 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -182,8 +182,8 @@ for Struct1FormerStorage pub struct Struct1Former< Definition = Struct1FormerDefinition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { storage : Definition::Storage, context : core::option::Option< Definition::Context >, @@ -192,8 +192,8 @@ where impl< Definition > Struct1Former< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { #[ inline( always ) ] @@ -307,7 +307,7 @@ where impl< Definition > Struct1Former< Definition > where - Definition : former::FormerDefinition, + Definition : former::FormerDefinition< Storage = Struct1FormerStorage, Formed = Struct1 >, Definition::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, { diff --git a/module/core/former/tests/inc/former_tests/subformer_custom.rs b/module/core/former/tests/inc/former_tests/subformer_custom.rs index 9d23d9f24e..1e18a63f42 100644 --- a/module/core/former/tests/inc/former_tests/subformer_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_custom.rs @@ -72,9 +72,8 @@ impl< K, Definition > AggregatorFormer where K : core::hash::Hash + std::cmp::Eq, Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, Definition::Storage : former::StoragePreform< Preformed = Aggregator< K > >, - // Definition::Storage : former::StoragePreform< Preformed = Aggregator< K > >, + Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, // xxx { // diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index ce1ea7f4c5..44516ef66a 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -7,33 +7,33 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_common; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_vec; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_hashset; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_hashmap; -// -// mod a_basic_manual; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_common; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_vec; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashset; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashmap; + + mod a_basic_manual; mod a_basic; -// mod a_primitives_manual; -// mod a_primitives; -// -// mod a_containers_without_subformer; -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer_manual; -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer; -// -// mod attribute_default_container; -// mod attribute_default_primitive; -// mod attribute_perform; -// mod attribute_setter; -// mod attribute_alias; -// mod attribute_feature; -// + mod a_primitives_manual; + mod a_primitives; + + mod a_containers_without_subformer; + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer_manual; + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer; + + mod attribute_default_container; + mod attribute_default_primitive; + mod attribute_perform; + mod attribute_setter; + mod attribute_alias; + mod attribute_feature; + // mod string_slice_manual; // mod string_slice; // mod unsigned_primitive_types; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 8f7a9d8913..29dc646165 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1843,7 +1843,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > pub fn begin ( mut storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Definition::Context >, // xxx + context : core::option::Option< Definition::Context >, on_end : < Definition as former::FormerDefinition >::End, ) -> Self From 123b9f7b975d0c0da2df9c2b96381b6f07c61d81 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 15:32:16 +0300 Subject: [PATCH 348/533] former : experimenting --- .../inc/former_tests/attribute_setter.rs | 4 +-- .../inc/former_tests/string_slice_manual.rs | 12 +++----- module/core/former/tests/inc/mod.rs | 30 +++++++++---------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_setter.rs b/module/core/former/tests/inc/former_tests/attribute_setter.rs index c3111256cc..1d0efb1bf5 100644 --- a/module/core/former/tests/inc/former_tests/attribute_setter.rs +++ b/module/core/former/tests/inc/former_tests/attribute_setter.rs @@ -16,8 +16,8 @@ pub struct StructWithCustomSetters impl< Definition > StructWithCustomSettersFormer< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = StructWithCustomSettersFormerStorage >, + Definition : former::FormerDefinition< Storage = StructWithCustomSettersFormerStorage >, + // Definition::Types : former::FormerDefinitionTypes< Storage = StructWithCustomSettersFormerStorage >, { /// Custom alternative setter of ordinary field. diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 73af4f49b4..c47e60e2ba 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -153,11 +153,8 @@ where #[ automatically_derived ] impl< 'a, Definition > Struct1Former< 'a, Definition > where - // End : former::FormingEnd::< Definition::Types >, - // Definition : former::FormerDefinition< End = End >, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Formed, Context = Context >, - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a > >, + Definition : former::FormerDefinition< Storage = Struct1FormerStorage< 'a > >, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a > >, { #[ inline( always ) ] @@ -247,9 +244,8 @@ where impl< 'a, Definition > Struct1Former< 'a, Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a > >, - Definition::Storage : former::StoragePreform, + Definition : former::FormerDefinition< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a > >, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< 'a >, Formed = Struct1< 'a > >, Definition::Storage : former::StoragePreform< Preformed = Struct1< 'a > >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 44516ef66a..ba34448b33 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -34,21 +34,21 @@ mod former_tests mod attribute_alias; mod attribute_feature; -// mod string_slice_manual; -// mod string_slice; -// mod unsigned_primitive_types; -// mod default_user_type; -// mod user_type_no_default; -// mod user_type_no_debug; -// mod visibility; -// -// mod name_collision_former_hashmap_without_parameter; -// mod name_collision_former_vector_without_parameter; -// mod name_collisions; -// mod name_collision_context; -// mod name_collision_end; -// mod name_collision_on_end; -// + mod string_slice_manual; + mod string_slice; + mod unsigned_primitive_types; + mod default_user_type; + mod user_type_no_default; + mod user_type_no_debug; + mod visibility; + + mod name_collision_former_hashmap_without_parameter; + mod name_collision_former_vector_without_parameter; + mod name_collisions; + mod name_collision_context; + mod name_collision_end; + mod name_collision_on_end; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod parametrized_struct_manual; // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] From a03fb09f358c9e7cc4a02ded3f36d2221da8c238 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 15:35:01 +0300 Subject: [PATCH 349/533] former : experimenting --- .../parametrized_struct_manual.rs | 27 +++++++++++-------- module/core/former/tests/inc/mod.rs | 18 ++++++------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 28a7ded170..d6501b2107 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -207,8 +207,8 @@ impl< K, > former :: StoragePreform for CommandFormerStorage< K, > where K : cor pub struct CommandFormer< K, Definition = CommandFormerDefinition< K, (), Command< K, >, former::ReturnPreformed >, > where K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > > + Definition : former::FormerDefinition< Storage = CommandFormerStorage< K, > >, + // Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > > { storage : Definition::Storage, context : core::option::Option< Definition::Context >, @@ -219,9 +219,10 @@ where impl< K, Definition, > CommandFormer< K, Definition, > where K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > > + Definition : former::FormerDefinition< Storage = CommandFormerStorage< K, > > + // Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > >, { + #[ inline( always ) ] pub fn perform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { @@ -258,8 +259,13 @@ where } #[ inline( always ) ] - pub fn begin_coercing< IntoEnd >( mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, on_end : IntoEnd, ) -> Self - where IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > + pub fn begin_coercing< IntoEnd > + ( + mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, on_end : IntoEnd, + ) + -> Self + where + IntoEnd : ::core::convert::Into< < Definition as former::FormerDefinition >::End > { if storage.is_none() { @@ -315,9 +321,8 @@ where impl< K, Definition, > CommandFormer< K, Definition, > where K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, >, Formed = Command< K, > >, - Definition::Storage : former::StoragePreform, + Definition : former::FormerDefinition< Storage = CommandFormerStorage< K, >, Formed = Command< K, > >, + // Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, >, Formed = Command< K, > >, Definition::Storage : former::StoragePreform< Preformed = Command< K, > > { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed @@ -334,8 +339,8 @@ pub struct CommandFormerPropertiesEnd; impl< K, Definition, > former::FormingEnd< former::HashMapDefinition< K, Property< K >, CommandFormer< K, Definition, >, CommandFormer< K, Definition, >, former::NoEnd >, > for CommandFormerPropertiesEnd where K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > > + Definition : former::FormerDefinition< Storage = CommandFormerStorage< K, > >, + // Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > >, { #[ inline( always ) ] fn call( &self, storage : collection_tools::HashMap< K, Property< K > >, super_former : Option< CommandFormer< K, Definition, > >, ) -> CommandFormer< K, Definition, > diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index ba34448b33..06a486e826 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -49,15 +49,15 @@ mod former_tests mod name_collision_end; mod name_collision_on_end; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_manual; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_imm; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_where; -// mod parametrized_field; -// mod parametrized_field_where; -// + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_manual; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_imm; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_where; + mod parametrized_field; + mod parametrized_field_where; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic; // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] From ba20fbf08e0485680d28d34b03b79bf7704922f6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 17:01:55 +0300 Subject: [PATCH 350/533] former : experimenting --- .../only_test/subformer_custom.rs | 203 --------------- .../subformer_custom_experimental.rs | 47 ---- .../tests/inc/former_tests/subformer_basic.rs | 3 +- .../subformer_container_manual.rs | 8 +- .../inc/former_tests/subformer_custom.rs | 211 ---------------- .../subformer_custom_experimental.rs | 238 ------------------ .../inc/former_tests/subformer_subform.rs | 11 +- .../former_tests/subformer_subform_manual.rs | 4 +- module/core/former/tests/inc/mod.rs | 32 ++- module/core/former_meta/src/derive/former.rs | 3 +- 10 files changed, 30 insertions(+), 730 deletions(-) delete mode 100644 module/core/former/tests/inc/former_tests/only_test/subformer_custom.rs delete mode 100644 module/core/former/tests/inc/former_tests/only_test/subformer_custom_experimental.rs delete mode 100644 module/core/former/tests/inc/former_tests/subformer_custom.rs delete mode 100644 module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_custom.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_custom.rs deleted file mode 100644 index fe62ad6926..0000000000 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_custom.rs +++ /dev/null @@ -1,203 +0,0 @@ - -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] -#[ cfg( not( feature = "use_alloc" ) ) ] -#[ test ] -fn command_constructor() -{ - - let got = Command::< &str >::former() - .name( "a" ) - .subject( "b" ) - .form(); - let exp = Command::< &str > - { - name : "a".to_string(), - subject : "b", - }; - a_id!( got, exp ); - - let got = Command::< &str >::former() - .name( "a" ) - .subject( "b" ) - .perform(); - let exp = Command::< &str > - { - name : "a".to_string(), - subject : "b", - }; - a_id!( got, exp ); - - let got = Command::< &str >::former() - .name( "a" ) - .subject( "b" ) - .end(); - let exp = Command::< &str > - { - name : "a".to_string(), - subject : "b", - }; - a_id!( got, exp ); - -} - -// - -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] -#[ cfg( not( feature = "use_alloc" ) ) ] -#[ test ] -fn command_properties() -{ - - // with helper - let got = Command::< &str >::former() - .name( "a" ) - .subject( "b" ) - .form(); - let exp = Command::< &str > - { - name : "a".to_string(), - subject : "b", - }; - a_id!( got, exp ); - - // with HashMapSubformer - let got = Command::< &str >::former() - .name( "a" ) - .subject( "b" ) - .form(); - let exp = Command::< &str > - { - name : "a".to_string(), - subject : "b", - }; - a_id!( got, exp ); - -} - -// - -#[ test ] -fn aggregator_alternative_form() -{ - - let exp = Aggregator::< &str >::former() - .parameter1( "p1" ) - .command_with_closure( "command1".to_string() ) - .subject( "b" ) - .end() - .form() - ; - - let got = Aggregator::< &str >::former() - .parameter1( "p1" ) - .command_with_closure( "command1".to_string() ) - .subject( "b" ) - .end() - .perform() - ; - a_id!( got, exp ); - - let got = Aggregator::< &str >::former() - .parameter1( "p1" ) - .command_with_closure( "command1".to_string() ) - .subject( "b" ) - .end() - .end() - ; - a_id!( got, exp ); - -} - -// - -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] -#[ cfg( not( feature = "use_alloc" ) ) ] -#[ test ] -fn command_with_closure() -{ - - // with helper - let got = Aggregator::< &str >::former() - .parameter1( "p1" ) - .commands().add( ( "name1".to_string(), CommandFormer::< &str >::new_coercing( former::ReturnPreformed ).name( "name1" ).subject( "s" ).end() ) ).end() - .command_with_closure( "command1".to_string() ) - .subject( "b" ) - .end() - .command_with_closure( "command2".to_string() ) - .subject( "c" ) - .end() - .form() - ; - - let name1 = Command::< &str > - { - name : "name1".to_string(), - subject : "s", - }; - let command1 = Command::< &str > - { - name : "command1".to_string(), - subject : "b", - }; - let command2 = Command::< &str > - { - name : "command2".to_string(), - subject : "c", - }; - let exp = Aggregator - { - parameter1 : "p1".to_string(), - commands : hmap!{ "name1" => name1, "command1" => command1, "command2" => command2 }, - }; - dbg!( &got ); - dbg!( &exp ); - a_id!( got, exp ); - -} - -// - -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] -#[ cfg( not( feature = "use_alloc" ) ) ] -#[ test ] -fn command_with_type() -{ - - // with helper - let got = Aggregator::< &str >::former() - .parameter1( "p1" ) - .commands().add( ( "name1".to_string(), CommandFormer::< &str >::new_coercing( former::ReturnPreformed ).name( "name1" ).subject( "s" ).end() ) ).end() - .command_with_type( "command1".to_string() ) - .subject( "b" ) - .end() - .command_with_type( "command2".to_string() ) - .subject( "c" ) - .end() - .form() - ; - - let name1 = Command::< &str > - { - name : "name1".to_string(), - subject : "s", - }; - let command1 = Command::< &str > - { - name : "command1".to_string(), - subject : "b", - }; - let command2 = Command::< &str > - { - name : "command2".to_string(), - subject : "c", - }; - let exp = Aggregator - { - parameter1 : "p1".to_string(), - commands : hmap!{ "name1" => name1, "command1" => command1, "command2" => command2 }, - }; - dbg!( &got ); - dbg!( &exp ); - a_id!( got, exp ); - -} diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_custom_experimental.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_custom_experimental.rs deleted file mode 100644 index 2bd1f4e924..0000000000 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_custom_experimental.rs +++ /dev/null @@ -1,47 +0,0 @@ - -// - -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] -#[ cfg( not( feature = "use_alloc" ) ) ] -#[ test ] -fn command_with_helper() -{ - - // with helper - let got = Aggregator::< &str >::former() - .parameter1( "p1" ) - .commands().add( ( "name1".to_string(), CommandFormer::< &str >::new_coercing( former::ReturnPreformed ).name( "name1" ).subject( "s" ).end() ) ).end() - .command_with_helper( "command1".to_string() ) - .subject( "b" ) - .end() - .command_with_helper( "command2".to_string() ) - .subject( "c" ) - .end() - .form() - ; - - let name1 = Command::< &str > - { - name : "name1".to_string(), - subject : "s", - }; - let command1 = Command::< &str > - { - name : "command1".to_string(), - subject : "b", - }; - let command2 = Command::< &str > - { - name : "command2".to_string(), - subject : "c", - }; - let exp = Aggregator - { - parameter1 : "p1".to_string(), - commands : hmap!{ "name1" => name1, "command1" => command1, "command2" => command2 }, - }; - dbg!( &got ); - dbg!( &exp ); - a_id!( got, exp ); - -} diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 62825d7d19..9744776af3 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -61,9 +61,8 @@ where impl< K, Definition > CommandFormer< K, Definition > where K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition, + Definition : former::FormerDefinition< Storage = CommandFormerStorage< K > >, Definition::Storage : former::StoragePreform, - Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K > >, { /// Inserts a key-value pair into the map. Make a new container if it was not made so far. diff --git a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs index 08530df747..608bd68c75 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs @@ -26,8 +26,8 @@ pub struct Parent #[ automatically_derived ] impl< Definition, > ParentFormer< Definition, > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, + Definition : former::FormerDefinition< Storage = ParentFormerStorage< > >, + // Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, { #[ inline( always ) ] @@ -77,8 +77,8 @@ impl< Definition, > former::FormingEnd > for ParentFormerAssignChildrenEnd< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, + Definition : former::FormerDefinition< Storage = ParentFormerStorage< > >, + // Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, { #[ inline( always ) ] fn call diff --git a/module/core/former/tests/inc/former_tests/subformer_custom.rs b/module/core/former/tests/inc/former_tests/subformer_custom.rs deleted file mode 100644 index 1e18a63f42..0000000000 --- a/module/core/former/tests/inc/former_tests/subformer_custom.rs +++ /dev/null @@ -1,211 +0,0 @@ -#![ allow( dead_code ) ] -use super::*; - -// == command - -#[ derive( Debug, PartialEq, the_module::Former ) ] -pub struct Command< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - pub name : String, - pub subject : K, -} - -// // = command subformer - generated -// -// pub type CommandAsSubformer< K, Superformer, End > = CommandFormer -// < -// K, -// CommandFormerDefinition -// < -// K, -// Superformer, -// Superformer, -// End, -// // impl former::FormingEnd< CommandFormerDefinitionTypes< K, Superformer, Superformer > >, -// >, -// >; -// -// // = command subformer end - generated -// -// pub trait CommandAsSubformerEnd< K, SuperFormer > -// where -// K : core::hash::Hash + std::cmp::Eq, -// Self : the_module::FormingEnd -// < -// CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, -// > -// { -// } -// -// impl< K, SuperFormer, T > CommandAsSubformerEnd< K, SuperFormer > -// for T -// where -// K : core::hash::Hash + std::cmp::Eq, -// Self : the_module::FormingEnd -// < -// CommandFormerDefinitionTypes< K, SuperFormer, SuperFormer >, -// > -// { -// } - -// == aggregator - -#[ derive( Debug, PartialEq, the_module::Former ) ] -pub struct Aggregator< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - pub parameter1 : String, - #[ container( former::HashMapDefinition ) ] - pub commands : collection_tools::HashMap< String, Command< K > >, -} - -// = - -impl< K, Definition > AggregatorFormer -< - K, - Definition, -> -where - K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition, - Definition::Storage : former::StoragePreform< Preformed = Aggregator< K > >, - Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, // xxx -{ - - // - - #[ inline( always ) ] - pub fn command_with_closure< IntoName >( self, name : IntoName ) - -> - CommandAsSubformer< K, Self, impl CommandAsSubformerEnd< K, Self > > - where - IntoName : core::convert::Into< String >, - { - - let on_end = | storage : CommandFormerStorage< K >, super_former : core::option::Option< Self > | -> Self - { - let formed = former::StoragePreform::preform( storage ); - let mut super_former = super_former.unwrap(); - if let Some( ref mut container ) = super_former.storage.commands - { - former::ContainerAdd::add( container, ( formed.name.clone(), formed ) ); - } - else - { - let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); - former::ContainerAdd::add( &mut container, ( formed.name.clone(), formed ) ); - super_former.storage.commands = Some( container ); - } - super_former - }; - - let former - : CommandFormer< _, _ > - = CommandFormer::begin( None, Some( self ), on_end ); - - former.name( name ) - } - - // - - #[ inline( always ) ] - pub fn command_with_type< IntoName >( self, name : IntoName ) - -> - CommandAsSubformer< K, Self, impl CommandAsSubformerEnd< K, Self > > - where - IntoName : core::convert::Into< String >, - { - let former = CommandFormer::begin( None, Some( self ), AggregatorFormerCommandEnd ); - former.name( name ) - } - -} - -pub struct AggregatorFormerCommandEnd; -impl< K, Definition > former::FormingEnd -< - CommandFormerDefinitionTypes - < - K, - AggregatorFormer< K, Definition >, - AggregatorFormer< K, Definition >, - >, -> -for AggregatorFormerCommandEnd -where - K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes - < - Storage = AggregatorFormerStorage< K >, - >, -{ - #[ inline( always ) ] - fn call - ( - &self, - sub_storage : CommandFormerStorage< K >, - super_former : Option< AggregatorFormer< K, Definition > >, - ) - -> - AggregatorFormer< K, Definition > - { - let preformed = former::StoragePreform::preform( sub_storage ); - let mut super_former = super_former.unwrap(); - if let Some( ref mut container ) = super_former.storage.commands - { - former::ContainerAdd::add( container, Into::into( preformed ) ); - } - else - { - let mut container : collection_tools::HashMap< String, Command< K > > = Default::default(); - former::ContainerAdd::add( &mut container, Into::into( preformed ) ); - super_former.storage.commands = Some( container ); - } - super_former - } -} - -// - -// /// Convert an entity to an element which could be added to a container. -// pub trait IntoElement< Element > -// { -// /// Convert an entity to an element which could be added to a container. -// fn into_element( self ) -> Element; -// } -// -// impl< K > IntoElement< ( String, Command< K > ) > -// for Command< K > -// where -// K : core::hash::Hash + std::cmp::Eq, -// { -// fn into_element( self ) -> ( String, Command< K > ) -// { -// ( self.name.clone(), self ) -// } -// } - -// - -impl< K > From< Command< K > > -for ( String, Command< K > ) -where - K : core::hash::Hash + std::cmp::Eq, -{ - #[ inline( always ) ] - fn from( src : Command< K > ) -> Self - { - ( src.name.clone(), src ) - } -} - -// - -// == - -include!( "./only_test/subformer_custom.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs b/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs deleted file mode 100644 index b939740ef3..0000000000 --- a/module/core/former/tests/inc/former_tests/subformer_custom_experimental.rs +++ /dev/null @@ -1,238 +0,0 @@ -#![ allow( dead_code ) ] -use super::*; - -// == command - -#[ derive( Debug, PartialEq, the_module::Former ) ] -pub struct Command< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - pub name : String, - pub subject : K, -} - -// == aggregator - -#[ derive( Debug, PartialEq, the_module::Former ) ] -pub struct Aggregator< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - pub parameter1 : String, - #[ container( former::HashMapDefinition ) ] - pub commands : collection_tools::HashMap< String, Command< K > >, -} - -// = - -impl< K, Definition > AggregatorFormer -< - K, - Definition, -> -where - K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = AggregatorFormerStorage< K > >, - Definition::Storage : former::StoragePreform< Preformed = Aggregator< K > >, -{ - - // - #[ inline( always ) ] - pub fn command_with_helper< IntoName >( self, name : IntoName ) - -> - CommandAsSubformer< K, Self, impl CommandAsSubformerEnd< K, Self > > - where - IntoName : core::convert::Into< String >, - ContainerAddElement - < - collection_tools::HashMap< String, Command< K > >, - ( String, Command< K >, ), - Command< K > - > - : - CommandAsSubformerEnd< K, Self >, - { - let former - = CommandFormer::begin - ( - None, - Some( self ), - ContainerAddElement::default(), - ); - former.name( name ) - } - -} - -// - -// /// Convert an entity to an element which could be added to a container. -// pub trait IntoElement< Element > -// { -// /// Convert an entity to an element which could be added to a container. -// fn into_element( self ) -> Element; -// } -// -// impl< K > IntoElement< ( String, Command< K > ) > -// for Command< K > -// where -// K : core::hash::Hash + std::cmp::Eq, -// { -// fn into_element( self ) -> ( String, Command< K > ) -// { -// ( self.name.clone(), self ) -// } -// } - -// - -impl< K > From< Command< K > > -for ( String, Command< K > ) -where - K : core::hash::Hash + std::cmp::Eq, -{ - #[ inline( always ) ] - fn from( src : Command< K > ) -> Self - { - ( src.name.clone(), src ) - } -} - -// - -/// get container for a field out of a storage -pub trait FormerStorageExtractContainer< Target > -{ - fn container_mut( &mut self ) -> &mut Target; -} - -impl< K > FormerStorageExtractContainer< collection_tools::HashMap< String, Command< K > > > -for AggregatorFormerStorage< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - fn container_mut( &mut self ) -> &mut collection_tools::HashMap< String, Command< K > > - { - if let Some( ref mut commands ) = self.commands - { - commands - } - else - { - let commands : collection_tools::HashMap< String, Command< K > > = Default::default(); - self.commands = Some( commands ); - self.commands.as_mut().unwrap() - } - } -} - -// - -/// extract storage from a former -pub trait FormerExtractStorage -{ - type Storage; - fn storage_mut( &mut self ) -> &mut Self::Storage; -} - -impl< K > FormerExtractStorage -for AggregatorFormer< K > -where - K : core::hash::Hash + std::cmp::Eq, -{ - type Storage = AggregatorFormerStorage< K >; - fn storage_mut( &mut self ) -> &mut Self::Storage - { - &mut self.storage - } -} - -// - -#[ derive( Debug ) ] -pub struct ContainerAddElement< SuperContainer, Element, SubFormed > -( core::marker::PhantomData< fn( SuperContainer, Element, SubFormed ) > ); - -impl< SuperContainer, Element, SubFormed > ::core::default::Default -for ContainerAddElement< SuperContainer, Element, SubFormed > -{ - #[ inline( always ) ] - fn default() -> Self - { - Self( core::marker::PhantomData ) - } -} - -impl -< - SuperFormer, - SuperContainer, - Element, - SubFormed, - SubDefinition, -> -former::FormingEnd -< - SubDefinition, - // CommandFormerDefinitionTypes - // < - // K, - // AggregatorFormer< K, SuperDefinition >, - // AggregatorFormer< K, SuperDefinition >, - // >, -> -for ContainerAddElement -< - SuperContainer, - Element, - SubFormed, -> -where - SuperFormer : FormerExtractStorage<>, - < SuperFormer as FormerExtractStorage >::Storage : FormerStorageExtractContainer< SuperContainer >, - SuperContainer : former::ContainerAdd< Element = Element >, - - SubDefinition : former::FormerDefinitionTypes - < - Formed = SuperFormer, - Context = SuperFormer, - >, - SubDefinition::Storage : former::StoragePreform< Preformed = SubFormed >, - - SubFormed : Into< Element >, -{ - - #[ inline( always ) ] - fn call - ( - &self, - storage : SubDefinition::Storage, - super_former : Option< SuperFormer >, - ) - -> - SuperFormer - { - - let storage : SubFormed = former::StoragePreform::preform( storage ); - let mut super_former = super_former.unwrap(); - - let container = FormerStorageExtractContainer - ::< SuperContainer > - ::container_mut( FormerExtractStorage::storage_mut( &mut super_former ) ); - - former::ContainerAdd::add - ( - container, - Into::< Element >::into( storage ), - ); - - super_former - } - -} - -// == - -include!( "./only_test/subformer_custom_experimental.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform.rs b/module/core/former/tests/inc/former_tests/subformer_subform.rs index 29746e2b39..dee0b0b37a 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform.rs @@ -11,7 +11,10 @@ pub struct Child } /// Parent + #[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { #[ subform ] @@ -20,8 +23,8 @@ pub struct Parent impl< Definition > ParentFormer< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, + // Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, { #[ inline( always ) ] @@ -41,6 +44,8 @@ where } -// +// == begin of generated + +// == end of generated include!( "./only_test/subformer_subform.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 5c7f4ee7f5..6750c98a89 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -107,8 +107,8 @@ where impl< Definition > ParentFormer< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, + // Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, { #[ inline( always ) ] diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 06a486e826..c4771d9bf2 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -58,24 +58,20 @@ mod former_tests mod parametrized_field; mod parametrized_field_where; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_basic; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_custom; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_custom_experimental; -// -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container_manual; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container_implicit; -// -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_manual; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod subformer_basic; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_implicit; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_subform_manual; // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_subform_named; // #[ cfg( any( not( feature = "no_std" ) ) ) ] diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 29dc646165..708452baf5 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -1234,8 +1234,7 @@ Result< TokenStream > impl< #struct_generics_impl Types2, Definition > former::FormingEnd< Types2, > for #parent_add_element_end< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes + Definition : former::FormerDefinition < Storage = < #stru < #struct_generics_ty > as former::EntityToStorage >::Storage, >, From 10aa80451c96515b9abe49a2935bffcc66bb0fbe Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 17:04:23 +0300 Subject: [PATCH 351/533] former : experimenting --- .../tests/inc/former_tests/subformer_subform_manual.rs | 7 +++---- .../tests/inc/former_tests/subformer_subform_named.rs | 4 ++-- module/core/former/tests/inc/mod.rs | 8 ++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 6750c98a89..057a209121 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -25,8 +25,8 @@ pub struct Parent impl< Definition > ParentFormer< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, + // Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, { #[ inline( always ) ] @@ -157,8 +157,7 @@ for ParentFormerAddChildrenEnd< Definition > impl< Types2, Definition > former::FormingEnd< Types2, > for ParentFormerAddChildrenEnd< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes + Definition : former::FormerDefinition < Storage = < Parent as former::EntityToStorage >::Storage, >, diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs index 56f41aa3e0..101fdb79bf 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs @@ -24,8 +24,8 @@ pub struct Parent impl< Definition > ParentFormer< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, + // Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, { #[ inline( always ) ] diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index c4771d9bf2..419baf4daa 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -70,10 +70,10 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_subform_manual; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_named; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_named; // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_subform_named_manual; // From 0f5200023f5b7781125104c5f922b9c7d17b0f0b Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 17:05:28 +0300 Subject: [PATCH 352/533] former : experimenting --- .../inc/former_tests/subformer_subform_named_manual.rs | 4 ++-- module/core/former/tests/inc/mod.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs index 9d19953c89..c9853de175 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs @@ -33,8 +33,8 @@ pub struct Parent impl< Definition > ParentFormer< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, + // Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, { #[ inline( always ) ] diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 419baf4daa..c28fc404a0 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -74,9 +74,9 @@ mod former_tests mod subformer_subform_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_named; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_named_manual; -// + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_named_manual; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_subform_and_container; // #[ cfg( any( not( feature = "no_std" ) ) ) ] From 0ab214e9034c8d626cd2411618be4361a2a6a94f Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 17:06:56 +0300 Subject: [PATCH 353/533] former : experimenting --- .../inc/former_tests/subformer_subform_and_container.rs | 4 ++-- module/core/former/tests/inc/mod.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs index fdbba4aedc..bdcf997739 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs @@ -25,8 +25,8 @@ pub struct Parent impl< Definition > ParentFormer< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, + // Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, { #[ inline( always ) ] diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index c28fc404a0..937aac7f27 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -77,10 +77,10 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_named_manual; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_and_container; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_and_container_parametrized; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_and_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_and_container_parametrized; } From c5ed2dd669db7acc609e7e2da9617d5ef374ffd5 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 17:10:44 +0300 Subject: [PATCH 354/533] former : experimenting --- .../examples/former_custom_subformer.rs | 62 ++++++++++++------- .../inc/former_tests/subformer_subform.rs | 1 - 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/module/core/former/examples/former_custom_subformer.rs b/module/core/former/examples/former_custom_subformer.rs index d5726a43d1..4065cbe8bf 100644 --- a/module/core/former/examples/former_custom_subformer.rs +++ b/module/core/former/examples/former_custom_subformer.rs @@ -22,41 +22,57 @@ fn main() #[ derive( Debug, PartialEq, Former ) ] pub struct Aggregator { + #[ subform ] #[ setter( false ) ] command : HashMap< String, Command >, } // Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. - impl< Definition > AggregatorFormer< Definition > + impl< Definition > ParentFormer< Definition > where - End : former::FormingEnd< Aggregator, Context >, + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, { + #[ inline( always ) ] - pub fn command< IntoName >( self, name : IntoName ) -> CommandFormer< Self, impl former::FormingEnd< Command, Self > > - where - IntoName : core::convert::Into< String >, + pub fn command( self, name : &str ) -> CommandAsSubformer< Self, impl CommandAsSubformerEnd< Self > > { - let on_end = | command : Command, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut commands ) = super_former.storage.command - { - commands.insert( command.name.clone(), command ); - } - else - { - let mut commands: HashMap< String, Command > = Default::default(); - commands.insert( command.name.clone(), command ); - super_former.storage.command = Some( commands ); - } - super_former - }; - let former = CommandFormer::begin( None, Some( self ), on_end ); - former.name( name ) + self._command_add_subformer::< CommandFormer< _ >, _, >() + .name( name ) } - // xxx : review + } + // // Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. + // impl< Definition > AggregatorFormer< Definition > + // where + // End : former::FormingEnd< Aggregator, Context >, + // { + // #[ inline( always ) ] + // pub fn command< IntoName >( self, name : IntoName ) -> CommandFormer< Self, impl former::FormingEnd< Command, Self > > + // where + // IntoName : core::convert::Into< String >, + // { + // let on_end = | command : Command, super_former : core::option::Option< Self > | -> Self + // { + // let mut super_former = super_former.unwrap(); + // if let Some( ref mut commands ) = super_former.storage.command + // { + // commands.insert( command.name.clone(), command ); + // } + // else + // { + // let mut commands: HashMap< String, Command > = Default::default(); + // commands.insert( command.name.clone(), command ); + // super_former.storage.command = Some( commands ); + // } + // super_former + // }; + // let former = CommandFormer::begin( None, Some( self ), on_end ); + // former.name( name ) + // } + // // xxx : review + // } + let ca = Aggregator::former() .command( "echo" ) .description( "prints all subjects and properties" ) // sets additional properties using custom subformer diff --git a/module/core/former/tests/inc/former_tests/subformer_subform.rs b/module/core/former/tests/inc/former_tests/subformer_subform.rs index dee0b0b37a..89b54bc044 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform.rs @@ -24,7 +24,6 @@ pub struct Parent impl< Definition > ParentFormer< Definition > where Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, - // Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, { #[ inline( always ) ] From 38a3374075eb16cf44e522e55df6829d499c2783 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 17:22:38 +0300 Subject: [PATCH 355/533] former : experimenting --- .../examples/former_custom_subformer.rs | 6 +- .../former_tests/subformer_subform_hashmap.rs | 89 +++++++++++++++++++ module/core/former/tests/inc/mod.rs | 2 + module/core/former_meta/src/derive/former.rs | 4 +- 4 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs diff --git a/module/core/former/examples/former_custom_subformer.rs b/module/core/former/examples/former_custom_subformer.rs index 4065cbe8bf..0e1967fdd7 100644 --- a/module/core/former/examples/former_custom_subformer.rs +++ b/module/core/former/examples/former_custom_subformer.rs @@ -23,14 +23,14 @@ fn main() pub struct Aggregator { #[ subform ] - #[ setter( false ) ] + // #[ setter( false ) ] command : HashMap< String, Command >, } // Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. - impl< Definition > ParentFormer< Definition > + impl< Definition > AggregatorFormer< Definition > where - Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, + Definition : former::FormerDefinition< Storage = < Aggregator as former::EntityToStorage >::Storage >, { #[ inline( always ) ] diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs new file mode 100644 index 0000000000..ff20693c8e --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -0,0 +1,89 @@ +#![ allow( dead_code ) ] + +#[ allow( unused_imports ) ] +use super::*; +#[ allow( unused_imports ) ] +use collection_tools::HashMap; + +// Command struct with Former derived for builder pattern support +#[ derive( Debug, PartialEq, former::Former ) ] +pub struct Command +{ + name : String, + description : String, +} + +// Aggregator struct to hold commands +#[ derive( Debug, PartialEq, former::Former ) ] +pub struct Aggregator +{ + #[ subform ] + // #[ setter( false ) ] + command : HashMap< String, Command >, +} + +// // Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. +// impl< Definition > AggregatorFormer< Definition > +// where +// Definition : former::FormerDefinition< Storage = < Aggregator as former::EntityToStorage >::Storage >, +// { +// +// #[ inline( always ) ] +// pub fn command( self, name : &str ) -> CommandAsSubformer< Self, impl CommandAsSubformerEnd< Self > > +// { +// self._command_add_subformer::< CommandFormer< _ >, _, >() +// .name( name ) +// } +// +// } + +// // Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. +// impl< Definition > AggregatorFormer< Definition > +// where +// End : former::FormingEnd< Aggregator, Context >, +// { +// #[ inline( always ) ] +// pub fn command< IntoName >( self, name : IntoName ) -> CommandFormer< Self, impl former::FormingEnd< Command, Self > > +// where +// IntoName : core::convert::Into< String >, +// { +// let on_end = | command : Command, super_former : core::option::Option< Self > | -> Self +// { +// let mut super_former = super_former.unwrap(); +// if let Some( ref mut commands ) = super_former.storage.command +// { +// commands.insert( command.name.clone(), command ); +// } +// else +// { +// let mut commands: HashMap< String, Command > = Default::default(); +// commands.insert( command.name.clone(), command ); +// super_former.storage.command = Some( commands ); +// } +// super_former +// }; +// let former = CommandFormer::begin( None, Some( self ), on_end ); +// former.name( name ) +// } +// // xxx : review +// } + +// == begin of generated + +// == end of generated + +// #[ test ] +// fn basic() +// { +// +// let ca = Aggregator::former() +// .command( "echo" ) +// .description( "prints all subjects and properties" ) // sets additional properties using custom subformer +// .end() +// .command( "exit" ) +// .description( "just exit" ) // Sets additional properties using using custom subformer +// .end() +// .form(); +// +// } +// xxx \ No newline at end of file diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 937aac7f27..4aa70adac1 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -76,6 +76,8 @@ mod former_tests mod subformer_subform_named; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_named_manual; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_subform_hashmap; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_and_container; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 708452baf5..dcb0501b9c 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -730,13 +730,13 @@ fn field_subformer_map Definition2 : former::FormerDefinition < End = #parent_add_element_end< Definition >, - Storage = < Child as former::EntityToStorage >::Storage, + Storage = < < #field_ty as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, Formed = Self, Context = Self, >, Definition2::Types : former::FormerDefinitionTypes < - Storage = < Child as former::EntityToStorage >::Storage, + Storage = < < #field_ty as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, Formed = Self, Context = Self, >, From bc73632601bf89dd8fa04d05431ba96b01302cbe Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 17:36:13 +0300 Subject: [PATCH 356/533] former : experimenting --- module/core/former/src/container.rs | 4 +- module/core/former/src/hash_map.rs | 1 + module/core/former/src/hash_set.rs | 1 + module/core/former/src/vector.rs | 9 +- .../former_tests/subformer_subform_hashmap.rs | 276 +++++++++++++++++- 5 files changed, 284 insertions(+), 7 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 122e47610a..18414db710 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -22,8 +22,10 @@ use crate::*; /// pub trait ContainerAdd { - /// The type of elements to be added to the container. + /// The type of elements to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. type Element; + /// The type of value to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. + type Val; /// Adds an element to the container. /// diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 6e337ad1ac..a22766ad56 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -7,6 +7,7 @@ where K : core::cmp::Eq + core::hash::Hash, { type Element = ( K, V ); + type Val = V; #[ inline( always ) ] fn add( &mut self, ( k, v ) : Self::Element ) -> bool diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 65366617e7..3502a1c097 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -10,6 +10,7 @@ where K : core::cmp::Eq + core::hash::Hash, { type Element = K; + type Val = K; #[ inline( always ) ] fn add( &mut self, e : Self::Element ) -> bool diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 6d874a001e..9ab8a7fd7c 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -4,9 +4,10 @@ use super::*; #[ allow( unused ) ] use collection_tools::Vec; -impl< T > ContainerAdd for collection_tools::Vec< T > +impl< E > ContainerAdd for collection_tools::Vec< E > { - type Element = T; + type Element = E; + type Val = E; #[ inline( always ) ] fn add( &mut self, e : Self::Element ) -> bool @@ -17,9 +18,9 @@ impl< T > ContainerAdd for collection_tools::Vec< T > } -impl< T > ContainerAssign for collection_tools::Vec< T > +impl< E > ContainerAssign for collection_tools::Vec< E > { - type Element = T; + type Element = E; #[ inline( always ) ] fn assign< Elements >( &mut self, elements : Elements ) -> usize diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index ff20693c8e..295fa30ed0 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -14,10 +14,12 @@ pub struct Command } // Aggregator struct to hold commands -#[ derive( Debug, PartialEq, former::Former ) ] +// #[ derive( Debug, PartialEq, former::Former ) ] +// #[ debug ] +#[ derive( Debug, PartialEq ) ] pub struct Aggregator { - #[ subform ] + // #[ subform ] // #[ setter( false ) ] command : HashMap< String, Command >, } @@ -70,6 +72,276 @@ pub struct Aggregator // == begin of generated + + #[automatically_derived] impl < > Aggregator < > where + { + #[doc = r""] + #[doc = + r" Make former, variation of builder pattern to form structure defining values of fields step by step."] + #[doc = r""] #[inline(always)] pub fn former() -> AggregatorFormer < + AggregatorFormerDefinition < (), Aggregator < > , former :: + ReturnPreformed > > + { + AggregatorFormer :: < AggregatorFormerDefinition < (), Aggregator < > + , former :: ReturnPreformed > > :: + new_coercing(former :: ReturnPreformed) + } + } impl < Definition > former :: EntityToFormer < Definition > for Aggregator < + > where Definition : former :: FormerDefinition < Storage = + AggregatorFormerStorage < > > , + { type Former = AggregatorFormer < Definition > ; } impl < > former :: + EntityToStorage for Aggregator < > where + { type Storage = AggregatorFormerStorage < > ; } impl < __Context, __Formed, + __End > former :: EntityToDefinition < __Context, __Formed, __End > for + Aggregator < > where __End : former :: FormingEnd < + AggregatorFormerDefinitionTypes < __Context, __Formed > > , + { + type Definition = AggregatorFormerDefinition < __Context, __Formed, __End + > ; + } #[derive(Debug)] pub struct AggregatorFormerDefinitionTypes < __Context = + (), __Formed = Aggregator < > , > where + { + _phantom : core :: marker :: PhantomData < + (* const __Context, * const __Formed) > , + } impl < __Context, __Formed, > :: core :: default :: Default for + AggregatorFormerDefinitionTypes < __Context, __Formed, > where + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } impl < __Context, __Formed, > former :: FormerDefinitionTypes for + AggregatorFormerDefinitionTypes < __Context, __Formed, > where + { + type Storage = AggregatorFormerStorage < > ; type Formed = __Formed; type + Context = __Context; + } #[derive(Debug)] pub struct AggregatorFormerDefinition < __Context = (), + __Formed = Aggregator < > , __End = former :: ReturnPreformed, > where + { + _phantom : core :: marker :: PhantomData < + (* const __Context, * const __Formed, * const __End) > , + } impl < __Context, __Formed, __End, > :: core :: default :: Default for + AggregatorFormerDefinition < __Context, __Formed, __End, > where + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } impl < __Context, __Formed, __End, > former :: FormerDefinition for + AggregatorFormerDefinition < __Context, __Formed, __End, > where __End : + former :: FormingEnd < AggregatorFormerDefinitionTypes < __Context, __Formed, + > > , + { + type Types = AggregatorFormerDefinitionTypes < __Context, __Formed, > ; + type End = __End; type Storage = AggregatorFormerStorage < > ; type Formed + = __Formed; type Context = __Context; + } #[doc = "Container of a corresponding former."] + #[allow(explicit_outlives_requirements)] pub struct AggregatorFormerStorage < + > where + { + #[doc = r" A field"] pub command : :: core :: option :: Option < HashMap < + String, Command > > , + } impl < > :: core :: default :: Default for AggregatorFormerStorage < > where + { + #[inline(always)] fn default() -> Self + { Self { command : :: core :: option :: Option :: None, } } + } impl < > former :: Storage for AggregatorFormerStorage < > where + { type Formed = Aggregator < > ; } impl < > former :: StoragePreform for + AggregatorFormerStorage < > where + { + type Preformed = Aggregator < > ; fn preform(mut self) -> Self :: + Preformed + { + let command = if self.command.is_some() + { self.command.take().unwrap() } else + { + { + trait MaybeDefault < T > + { + fn maybe_default(self : & Self) -> T + { panic! ("Field 'command' isn't initialized") } + } impl < T > MaybeDefault < T > for & :: core :: marker :: + PhantomData < T > {} impl < T > MaybeDefault < T > for :: core + :: marker :: PhantomData < T > where T : :: core :: default :: + Default, + { fn maybe_default(self : & Self) -> T { T :: default() } } + (& :: core :: marker :: PhantomData :: < HashMap < String, + Command > >).maybe_default() + } + }; let result = Aggregator :: < > { command, }; return result; + } + } + #[doc = + " Object to form [Aggregator]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] + pub struct AggregatorFormer < Definition = AggregatorFormerDefinition < (), + Aggregator < > , former :: ReturnPreformed > , > where Definition : former :: + FormerDefinition < Storage = AggregatorFormerStorage < > > , Definition :: + Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < + > > , + { + storage : Definition :: Storage, context : core :: option :: Option < + Definition :: Context > , on_end : core :: option :: Option < Definition + :: End > , + } #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, + > where Definition : former :: FormerDefinition < Storage = + AggregatorFormerStorage < > > , Definition :: Types : former :: + FormerDefinitionTypes < Storage = AggregatorFormerStorage < > > , + { + #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> + Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > + (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , + { Self :: begin_coercing(None, None, end,) } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn + begin(mut storage : core :: option :: Option < Definition :: Storage > , + context : core :: option :: Option < Definition :: Context > , on_end : < + Definition as former :: FormerDefinition > :: End,) -> Self + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: Some(on_end), + } + } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > + (mut storage : core :: option :: Option < Definition :: Storage > , + context : core :: option :: Option < Definition :: Context > , on_end : + IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < + Definition as former :: FormerDefinition > :: End > , + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: + Some(:: core :: convert :: Into :: into(on_end)), + } + } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types + as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { + let on_end = self.on_end.take().unwrap(); let context = + self.context.take(); former :: FormingEnd :: < Definition :: Types > + :: call(& on_end, self.storage, context) + } #[doc = "Setter for the 'command' field."] #[inline] pub fn command < + Src > (mut self, src : Src) -> Self where Src : :: core :: convert :: Into + < HashMap < String, Command > > , + { + debug_assert! (self.storage.command.is_none()); self.storage.command = + :: core :: option :: Option :: + Some(:: core :: convert :: Into :: into(src)); self + } #[doc = r" Custom setter which produce container element subformer."] + #[inline(always)] pub fn _command_add_subformer < Former2, Definition2 > + (self) -> Former2 where Definition2 : former :: FormerDefinition < End = + AggregatorFormerAddCommandEnd < Definition > , Storage = < < HashMap < + String, Command > as former :: ContainerAdd > :: Element as former :: + EntityToStorage > :: Storage, Formed = Self, Context = Self, > , + Definition2 :: Types : former :: FormerDefinitionTypes < Storage = < < + HashMap < String, Command > as former :: ContainerAdd > :: Element as + former :: EntityToStorage > :: Storage, Formed = Self, Context = Self, > , + Former2 : former :: FormerBegin < Definition2 > , + { + Former2 :: + former_begin(None, Some(self), AggregatorFormerAddCommandEnd :: + default()) + } + } impl < Definition, > AggregatorFormer < Definition, > where Definition : + former :: FormerDefinition < Storage = AggregatorFormerStorage < > , Formed = + Aggregator < > > , Definition :: Types : former :: FormerDefinitionTypes < + Storage = AggregatorFormerStorage < > , Formed = Aggregator < > > , Definition + : former :: FormerDefinition < Storage = AggregatorFormerStorage < > > , + Definition :: Types : former :: FormerDefinitionTypes < Storage = + AggregatorFormerStorage < > > , + { + pub fn preform(self) -> < Definition :: Types as former :: + FormerDefinitionTypes > :: Formed + { former :: StoragePreform :: preform(self.storage) } + } #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, + > where Definition : former :: FormerDefinition < Storage = + AggregatorFormerStorage < > , Formed = Aggregator < > , > , Definition :: + Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < + > , Formed = Aggregator < > , > , + { + #[doc = r""] + #[doc = r" Finish setting options and call perform on formed entity."] + #[doc = r""] + #[doc = + r" If `perform` defined then associated method is called and its result returned instead of entity."] + #[doc = + r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] + #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { let result = self.form(); return result; } + } impl < Definition > former :: FormerBegin < Definition > for + AggregatorFormer < Definition, > where Definition : former :: FormerDefinition + < Storage = AggregatorFormerStorage < > > , + { + #[inline(always)] fn + former_begin(storage : core :: option :: Option < Definition :: Storage > + , context : core :: option :: Option < Definition :: Context > , on_end : + Definition :: End,) -> Self + { + debug_assert! (storage.is_none()); Self :: + begin(None, context, on_end) + } + } + #[doc = + r" Use as subformer of a field during process of forming of super structure."] + pub type AggregatorAsSubformer < __Superformer, __End > = AggregatorFormer < + AggregatorFormerDefinition < __Superformer, __Superformer, __End, > , > ; + #[doc = + "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] + pub trait AggregatorAsSubformerEnd < SuperFormer > where Self : former :: + FormingEnd < AggregatorFormerDefinitionTypes < SuperFormer, SuperFormer > , > + , {} impl < SuperFormer, __T > AggregatorAsSubformerEnd < SuperFormer > for + __T where Self : former :: FormingEnd < AggregatorFormerDefinitionTypes < + SuperFormer, SuperFormer > , > , {} + #[doc = r" Handles the completion of an element of subformer's container."] + pub struct AggregatorFormerAddCommandEnd < Definition > + { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < + Definition > Default for AggregatorFormerAddCommandEnd < Definition > + { + #[inline(always)] fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } + + impl < Types2, Definition > former :: FormingEnd < Types2, > for + AggregatorFormerAddCommandEnd < Definition > + where + Definition : former :: FormerDefinition < Storage = < Aggregator < > as former :: EntityToStorage > + :: Storage, > , + Types2 : former :: FormerDefinitionTypes + < + Storage = < < HashMap < String, Command > as former :: ContainerAdd > :: Element as former :: EntityToStorage > :: Storage, + Formed = AggregatorFormer < Definition, > , + Context = AggregatorFormer < Definition, > , + > , + { + #[inline(always)] fn + call(& self, substorage : Types2 :: Storage, super_former : core :: option + :: Option < Types2 :: Context > ,) -> Types2 :: Formed + { + let mut super_former = super_former.unwrap(); if + super_former.storage.command.is_none() + { super_former.storage.command = Some(Default :: default()); } if let + Some(ref mut field) = super_former.storage.command + { + former :: ContainerAdd :: + add(field, former :: StoragePreform :: preform(substorage)); + } super_former + } + } + // == end of generated // #[ test ] From 889935f344fd27e75bf583e14c9d9a5459bc557d Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 17:37:11 +0300 Subject: [PATCH 357/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index dcb0501b9c..49682c6a05 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -730,13 +730,13 @@ fn field_subformer_map Definition2 : former::FormerDefinition < End = #parent_add_element_end< Definition >, - Storage = < < #field_ty as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + Storage = < < #field_ty as former::ContainerAdd >::Val as former::EntityToStorage >::Storage, Formed = Self, Context = Self, >, Definition2::Types : former::FormerDefinitionTypes < - Storage = < < #field_ty as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + Storage = < < #field_ty as former::ContainerAdd >::Val as former::EntityToStorage >::Storage, Formed = Self, Context = Self, >, @@ -756,17 +756,17 @@ fn field_subformer_map #[ inline( always ) ] pub fn #setter_name( self ) -> - < < #field_ty as former::ContainerAdd >::Element as former::EntityToFormer + < < #field_ty as former::ContainerAdd >::Val as former::EntityToFormer < < - < #field_ty as former::ContainerAdd >::Element as former::EntityToDefinition< Self, Self, #parent_add_element_end < Definition > > + < #field_ty as former::ContainerAdd >::Val as former::EntityToDefinition< Self, Self, #parent_add_element_end < Definition > > >::Definition, > >::Former // #as_subformer< Self, impl #as_subformer_end< Self > > { self.#element_subformer - ::< < < #field_ty as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() + ::< < < #field_ty as former::ContainerAdd >::Val as former::EntityToFormer< _ > >::Former, _, >() // ::< #former< _ >, _, >() } } @@ -1240,7 +1240,7 @@ Result< TokenStream > >, Types2 : former::FormerDefinitionTypes < - Storage = < < #field_ty as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + Storage = < < #field_ty as former::ContainerAdd >::Val as former::EntityToStorage >::Storage, Formed = #former< #former_generics_ty >, Context = #former< #former_generics_ty >, >, From 09051e5cb6862a4e3f36d023dca23f81f8971825 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 17:50:02 +0300 Subject: [PATCH 358/533] former : experimenting --- module/core/former/src/container.rs | 15 ++++++++++- .../former_tests/subformer_subform_hashmap.rs | 27 +++++++++---------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 18414db710..689893810d 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -2,6 +2,19 @@ use crate::*; +/// xxx : write description +pub trait Container +{ + /// The type of elements to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. + type Element; + /// The type of value to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. + type Val; + + // pub fn element_to_val( Element ) -> Val; + // pub fn val_to_element( Val ) -> Element; + +} + /// A trait defining the capability to add elements to a container. /// /// This trait should be implemented by container types that require a generic interface @@ -138,7 +151,7 @@ where impl< E, Definition > ContainerSubformer< E, Definition > where Definition : FormerDefinition, - < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, + < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, // xxx { /// Begins the building process, optionally initializing with a context and storage. diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index 295fa30ed0..db7e832218 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -72,7 +72,6 @@ pub struct Aggregator // == begin of generated - #[automatically_derived] impl < > Aggregator < > where { #[doc = r""] @@ -244,11 +243,11 @@ pub struct Aggregator #[inline(always)] pub fn _command_add_subformer < Former2, Definition2 > (self) -> Former2 where Definition2 : former :: FormerDefinition < End = AggregatorFormerAddCommandEnd < Definition > , Storage = < < HashMap < - String, Command > as former :: ContainerAdd > :: Element as former :: + String, Command > as former :: ContainerAdd > :: Val as former :: EntityToStorage > :: Storage, Formed = Self, Context = Self, > , Definition2 :: Types : former :: FormerDefinitionTypes < Storage = < < - HashMap < String, Command > as former :: ContainerAdd > :: Element as - former :: EntityToStorage > :: Storage, Formed = Self, Context = Self, > , + HashMap < String, Command > as former :: ContainerAdd > :: Val as former + :: EntityToStorage > :: Storage, Formed = Self, Context = Self, > , Former2 : former :: FormerBegin < Definition2 > , { Former2 :: @@ -315,17 +314,16 @@ pub struct Aggregator { Self { _phantom : core :: marker :: PhantomData, } } } - impl < Types2, Definition > former :: FormingEnd < Types2, > for + impl < Types2, Definition > former :: FormingEnd < Types2, > + for AggregatorFormerAddCommandEnd < Definition > where - Definition : former :: FormerDefinition < Storage = < Aggregator < > as former :: EntityToStorage > - :: Storage, > , - Types2 : former :: FormerDefinitionTypes - < - Storage = < < HashMap < String, Command > as former :: ContainerAdd > :: Element as former :: EntityToStorage > :: Storage, - Formed = AggregatorFormer < Definition, > , - Context = AggregatorFormer < Definition, > , - > , + Definition : former :: + FormerDefinition < Storage = < Aggregator < > as former :: EntityToStorage > + :: Storage, > , Types2 : former :: FormerDefinitionTypes < Storage = < < + HashMap < String, Command > as former :: ContainerAdd > :: Val as former :: + EntityToStorage > :: Storage, Formed = AggregatorFormer < Definition, > , + Context = AggregatorFormer < Definition, > , > , { #[inline(always)] fn call(& self, substorage : Types2 :: Storage, super_former : core :: option @@ -336,8 +334,7 @@ pub struct Aggregator { super_former.storage.command = Some(Default :: default()); } if let Some(ref mut field) = super_former.storage.command { - former :: ContainerAdd :: - add(field, former :: StoragePreform :: preform(substorage)); + former :: ContainerAdd :: add(field, former :: StoragePreform :: preform(substorage)); } super_former } } From 2cdddc4f4970713f7f57ec50290d6881d7aac2c5 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 17:56:01 +0300 Subject: [PATCH 359/533] former : experimenting --- module/core/former/src/container.rs | 14 +++++++++++--- module/core/former/src/hash_map.rs | 15 +++++++++++++++ module/core/former/src/hash_set.rs | 17 ++++++++++++++++- module/core/former/src/vector.rs | 13 +++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 689893810d..ed4e268a86 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -2,7 +2,9 @@ use crate::*; -/// xxx : write description +/// xxx : improve description +/// Descriptor of a container, specifically it define type of element and type of value. +/// As well as function to convert element to value. Reversal conversion could be not possible, so value to element conversion is in a separate trait. pub trait Container { /// The type of elements to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. @@ -10,8 +12,14 @@ pub trait Container /// The type of value to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. type Val; - // pub fn element_to_val( Element ) -> Val; - // pub fn val_to_element( Val ) -> Element; + fn element_to_val( e : Self::Element ) -> Self::Val; + +} + +pub trait ValToElement : Container +{ + + fn val_to_element( val : Self::Val ) -> Self::Element; } diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index a22766ad56..5ba20cb134 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -2,6 +2,21 @@ use super::*; use collection_tools::HashMap; +impl< K, V > Container for collection_tools::HashMap< K, V > +where + K : core::cmp::Eq + core::hash::Hash, +{ + type Element = ( K, V ); + type Val = V; + + #[ inline( always ) ] + fn element_to_val( e : Self::Element ) -> Self::Val + { + e.1 + } + +} + impl< K, V > ContainerAdd for collection_tools::HashMap< K, V > where K : core::cmp::Eq + core::hash::Hash, diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 3502a1c097..f973ab6838 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -5,7 +5,22 @@ use super::*; use collection_tools::HashSet; -impl ContainerAdd for collection_tools::HashSet< K > +impl< K > Container for collection_tools::HashSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + type Element = K; + type Val = K; + + #[ inline( always ) ] + fn element_to_val( e : Self::Element ) -> Self::Val + { + e + } + +} + +impl< K > ContainerAdd for collection_tools::HashSet< K > where K : core::cmp::Eq + core::hash::Hash, { diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 9ab8a7fd7c..336e5a8968 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -4,6 +4,19 @@ use super::*; #[ allow( unused ) ] use collection_tools::Vec; +impl< E > Container for collection_tools::Vec< E > +{ + type Element = E; + type Val = E; + + #[ inline( always ) ] + fn element_to_val( e : Self::Element ) -> Self::Val + { + e + } + +} + impl< E > ContainerAdd for collection_tools::Vec< E > { type Element = E; From 41f8a041f5579f762b4d15031039ba268d490654 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 17:58:31 +0300 Subject: [PATCH 360/533] former : experimenting --- module/core/former/src/container.rs | 11 ++++++----- module/core/former/src/hash_map.rs | 4 ++-- module/core/former/src/hash_set.rs | 4 ++-- module/core/former/src/vector.rs | 4 ++-- .../inc/former_tests/subformer_subform_manual.rs | 8 ++++---- .../former_tests/subformer_subform_named_manual.rs | 6 +++--- module/core/former_meta/src/derive/former.rs | 12 ++++++------ 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index ed4e268a86..15bc817bd0 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -41,12 +41,13 @@ pub trait ValToElement : Container /// defined by the implementer of the trait, allowing for flexibility in the kinds of /// elements different containers can accept. /// -pub trait ContainerAdd + +pub trait ContainerAdd : Container { - /// The type of elements to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. - type Element; - /// The type of value to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. - type Val; + // /// The type of elements to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. + // type Element; + // /// The type of value to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. + // type Val; /// Adds an element to the container. /// diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 5ba20cb134..f655467d37 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -21,8 +21,8 @@ impl< K, V > ContainerAdd for collection_tools::HashMap< K, V > where K : core::cmp::Eq + core::hash::Hash, { - type Element = ( K, V ); - type Val = V; + // type Element = ( K, V ); + // type Val = V; #[ inline( always ) ] fn add( &mut self, ( k, v ) : Self::Element ) -> bool diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index f973ab6838..b0871d3d66 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -24,8 +24,8 @@ impl< K > ContainerAdd for collection_tools::HashSet< K > where K : core::cmp::Eq + core::hash::Hash, { - type Element = K; - type Val = K; + // type Element = K; + // type Val = K; #[ inline( always ) ] fn add( &mut self, e : Self::Element ) -> bool diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 336e5a8968..3a1d327688 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -19,8 +19,8 @@ impl< E > Container for collection_tools::Vec< E > impl< E > ContainerAdd for collection_tools::Vec< E > { - type Element = E; - type Val = E; + // type Element = E; + // type Val = E; #[ inline( always ) ] fn add( &mut self, e : Self::Element ) -> bool diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 057a209121..97d030cdf7 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -88,17 +88,17 @@ where #[ inline( always ) ] pub fn _child( self ) -> - < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer + < < Vec< Child > as former::Container >::Element as former::EntityToFormer < // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, < - < Vec< Child > as former::ContainerAdd >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > + < Vec< Child > as former::Container >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > >::Definition, > >::Former { self._children_add_subformer - ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() + ::< < < Vec< Child > as former::Container >::Element as former::EntityToFormer< _ > >::Former, _, >() } } @@ -163,7 +163,7 @@ where >, Types2 : former::FormerDefinitionTypes < - Storage = < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToStorage >::Storage, + Storage = < < Vec< Child > as former::Container >::Element as former::EntityToStorage >::Storage, Formed = ParentFormer< Definition >, Context = ParentFormer< Definition >, >, diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs index c9853de175..f5103ab80d 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs @@ -56,17 +56,17 @@ where #[ inline( always ) ] pub fn _child( self ) -> - < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer + < < Vec< Child > as former::Container >::Element as former::EntityToFormer < // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, < - < Vec< Child > as former::ContainerAdd >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > + < Vec< Child > as former::Container >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > >::Definition, > >::Former { self._children_add_subformer - ::< < < Vec< Child > as former::ContainerAdd >::Element as former::EntityToFormer< _ > >::Former, _, >() + ::< < < Vec< Child > as former::Container >::Element as former::EntityToFormer< _ > >::Former, _, >() } } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 49682c6a05..094da29c45 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -730,13 +730,13 @@ fn field_subformer_map Definition2 : former::FormerDefinition < End = #parent_add_element_end< Definition >, - Storage = < < #field_ty as former::ContainerAdd >::Val as former::EntityToStorage >::Storage, + Storage = < < #field_ty as former::Container >::Val as former::EntityToStorage >::Storage, Formed = Self, Context = Self, >, Definition2::Types : former::FormerDefinitionTypes < - Storage = < < #field_ty as former::ContainerAdd >::Val as former::EntityToStorage >::Storage, + Storage = < < #field_ty as former::Container >::Val as former::EntityToStorage >::Storage, Formed = Self, Context = Self, >, @@ -756,17 +756,17 @@ fn field_subformer_map #[ inline( always ) ] pub fn #setter_name( self ) -> - < < #field_ty as former::ContainerAdd >::Val as former::EntityToFormer + < < #field_ty as former::Container >::Val as former::EntityToFormer < < - < #field_ty as former::ContainerAdd >::Val as former::EntityToDefinition< Self, Self, #parent_add_element_end < Definition > > + < #field_ty as former::Container >::Val as former::EntityToDefinition< Self, Self, #parent_add_element_end < Definition > > >::Definition, > >::Former // #as_subformer< Self, impl #as_subformer_end< Self > > { self.#element_subformer - ::< < < #field_ty as former::ContainerAdd >::Val as former::EntityToFormer< _ > >::Former, _, >() + ::< < < #field_ty as former::Container >::Val as former::EntityToFormer< _ > >::Former, _, >() // ::< #former< _ >, _, >() } } @@ -1240,7 +1240,7 @@ Result< TokenStream > >, Types2 : former::FormerDefinitionTypes < - Storage = < < #field_ty as former::ContainerAdd >::Val as former::EntityToStorage >::Storage, + Storage = < < #field_ty as former::Container >::Val as former::EntityToStorage >::Storage, Formed = #former< #former_generics_ty >, Context = #former< #former_generics_ty >, >, From 287c7b9c37d336591d37f1ee223cd48e559bef18 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 18:00:03 +0300 Subject: [PATCH 361/533] former : experimenting --- module/core/former/src/container.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 15bc817bd0..19170e765f 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -12,13 +12,18 @@ pub trait Container /// The type of value to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. type Val; + /// Convert element to val. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. fn element_to_val( e : Self::Element ) -> Self::Val; } +/// xxx : improve description +/// Extensation of container interface to convert value ot element. +/// As well as function to convert element to value. Reversal conversion could be not possible, so value to element conversion is in a separate trait. pub trait ValToElement : Container { + /// Convert val to element. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. fn val_to_element( val : Self::Val ) -> Self::Element; } From 4dfa9170891b2561fe77655cd7d61a8ab32bba5d Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 18:01:14 +0300 Subject: [PATCH 362/533] former : experimenting --- module/core/former/src/container.rs | 11 ++++------- module/core/former/src/hash_map.rs | 2 +- module/core/former/src/hash_set.rs | 2 +- module/core/former/src/vector.rs | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 19170e765f..318bd28dac 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -47,12 +47,9 @@ pub trait ValToElement : Container /// elements different containers can accept. /// +// zzz : update description pub trait ContainerAdd : Container { - // /// The type of elements to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. - // type Element; - // /// The type of value to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. - // type Val; /// Adds an element to the container. /// @@ -119,10 +116,10 @@ pub trait ContainerAdd : Container // qqq : implement for other containers /// A trait defining the capability to replface all elements. -pub trait ContainerAssign +pub trait ContainerAssign : Container { - /// The type of elements to be added to the container. - type Element; + // /// The type of elements to be added to the container. + // type Element; /// Agging elements to the container. fn assign< Elements >( &mut self, elements : Elements ) -> usize diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index f655467d37..ec4950d8de 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -36,7 +36,7 @@ impl< K, V > ContainerAssign for collection_tools::HashMap< K, V > where K : core::cmp::Eq + core::hash::Hash, { - type Element = ( K, V ); + // type Element = ( K, V ); fn assign< Elements >( &mut self, elements : Elements ) -> usize where diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index b0871d3d66..c20f5b0f64 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -39,7 +39,7 @@ impl< T > ContainerAssign for collection_tools::HashSet< T > where T : core::cmp::Eq + core::hash::Hash, { - type Element = T; + // type Element = T; fn assign< Elements >( &mut self, elements : Elements ) -> usize where diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 3a1d327688..7afdf664d4 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -33,7 +33,7 @@ impl< E > ContainerAdd for collection_tools::Vec< E > impl< E > ContainerAssign for collection_tools::Vec< E > { - type Element = E; + // type Element = E; #[ inline( always ) ] fn assign< Elements >( &mut self, elements : Elements ) -> usize From e10f1332e1a017fc98f9bdcfa520b5648159f3ad Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 18:04:23 +0300 Subject: [PATCH 363/533] former : experimenting --- module/core/former/src/container.rs | 3 +- .../former_tests/subformer_subform_hashmap.rs | 532 +++++++++--------- module/core/former/tests/inc/mod.rs | 4 +- 3 files changed, 270 insertions(+), 269 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 318bd28dac..9d8695c472 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -115,11 +115,10 @@ pub trait ContainerAdd : Container // qqq : implement for other containers +// xxx : extend documentation /// A trait defining the capability to replface all elements. pub trait ContainerAssign : Container { - // /// The type of elements to be added to the container. - // type Element; /// Agging elements to the container. fn assign< Elements >( &mut self, elements : Elements ) -> usize diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index db7e832218..fdcecb5585 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -72,272 +72,274 @@ pub struct Aggregator // == begin of generated - #[automatically_derived] impl < > Aggregator < > where - { - #[doc = r""] - #[doc = - r" Make former, variation of builder pattern to form structure defining values of fields step by step."] - #[doc = r""] #[inline(always)] pub fn former() -> AggregatorFormer < - AggregatorFormerDefinition < (), Aggregator < > , former :: - ReturnPreformed > > - { - AggregatorFormer :: < AggregatorFormerDefinition < (), Aggregator < > - , former :: ReturnPreformed > > :: - new_coercing(former :: ReturnPreformed) - } - } impl < Definition > former :: EntityToFormer < Definition > for Aggregator < - > where Definition : former :: FormerDefinition < Storage = - AggregatorFormerStorage < > > , - { type Former = AggregatorFormer < Definition > ; } impl < > former :: - EntityToStorage for Aggregator < > where - { type Storage = AggregatorFormerStorage < > ; } impl < __Context, __Formed, - __End > former :: EntityToDefinition < __Context, __Formed, __End > for - Aggregator < > where __End : former :: FormingEnd < - AggregatorFormerDefinitionTypes < __Context, __Formed > > , - { - type Definition = AggregatorFormerDefinition < __Context, __Formed, __End - > ; - } #[derive(Debug)] pub struct AggregatorFormerDefinitionTypes < __Context = - (), __Formed = Aggregator < > , > where - { - _phantom : core :: marker :: PhantomData < - (* const __Context, * const __Formed) > , - } impl < __Context, __Formed, > :: core :: default :: Default for - AggregatorFormerDefinitionTypes < __Context, __Formed, > where - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } impl < __Context, __Formed, > former :: FormerDefinitionTypes for - AggregatorFormerDefinitionTypes < __Context, __Formed, > where - { - type Storage = AggregatorFormerStorage < > ; type Formed = __Formed; type - Context = __Context; - } #[derive(Debug)] pub struct AggregatorFormerDefinition < __Context = (), - __Formed = Aggregator < > , __End = former :: ReturnPreformed, > where - { - _phantom : core :: marker :: PhantomData < - (* const __Context, * const __Formed, * const __End) > , - } impl < __Context, __Formed, __End, > :: core :: default :: Default for - AggregatorFormerDefinition < __Context, __Formed, __End, > where - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } impl < __Context, __Formed, __End, > former :: FormerDefinition for - AggregatorFormerDefinition < __Context, __Formed, __End, > where __End : - former :: FormingEnd < AggregatorFormerDefinitionTypes < __Context, __Formed, - > > , - { - type Types = AggregatorFormerDefinitionTypes < __Context, __Formed, > ; - type End = __End; type Storage = AggregatorFormerStorage < > ; type Formed - = __Formed; type Context = __Context; - } #[doc = "Container of a corresponding former."] - #[allow(explicit_outlives_requirements)] pub struct AggregatorFormerStorage < - > where - { - #[doc = r" A field"] pub command : :: core :: option :: Option < HashMap < - String, Command > > , - } impl < > :: core :: default :: Default for AggregatorFormerStorage < > where - { - #[inline(always)] fn default() -> Self - { Self { command : :: core :: option :: Option :: None, } } - } impl < > former :: Storage for AggregatorFormerStorage < > where - { type Formed = Aggregator < > ; } impl < > former :: StoragePreform for - AggregatorFormerStorage < > where - { - type Preformed = Aggregator < > ; fn preform(mut self) -> Self :: - Preformed - { - let command = if self.command.is_some() - { self.command.take().unwrap() } else - { - { - trait MaybeDefault < T > - { - fn maybe_default(self : & Self) -> T - { panic! ("Field 'command' isn't initialized") } - } impl < T > MaybeDefault < T > for & :: core :: marker :: - PhantomData < T > {} impl < T > MaybeDefault < T > for :: core - :: marker :: PhantomData < T > where T : :: core :: default :: - Default, - { fn maybe_default(self : & Self) -> T { T :: default() } } - (& :: core :: marker :: PhantomData :: < HashMap < String, - Command > >).maybe_default() - } - }; let result = Aggregator :: < > { command, }; return result; - } - } - #[doc = - " Object to form [Aggregator]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] - pub struct AggregatorFormer < Definition = AggregatorFormerDefinition < (), - Aggregator < > , former :: ReturnPreformed > , > where Definition : former :: - FormerDefinition < Storage = AggregatorFormerStorage < > > , Definition :: - Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < - > > , - { - storage : Definition :: Storage, context : core :: option :: Option < - Definition :: Context > , on_end : core :: option :: Option < Definition - :: End > , - } #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, - > where Definition : former :: FormerDefinition < Storage = - AggregatorFormerStorage < > > , Definition :: Types : former :: - FormerDefinitionTypes < Storage = AggregatorFormerStorage < > > , - { - #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> - Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > - (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , - { Self :: begin_coercing(None, None, end,) } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn - begin(mut storage : core :: option :: Option < Definition :: Storage > , - context : core :: option :: Option < Definition :: Context > , on_end : < - Definition as former :: FormerDefinition > :: End,) -> Self - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: Some(on_end), - } - } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > - (mut storage : core :: option :: Option < Definition :: Storage > , - context : core :: option :: Option < Definition :: Context > , on_end : - IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < - Definition as former :: FormerDefinition > :: End > , - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: - Some(:: core :: convert :: Into :: into(on_end)), - } - } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types - as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { - let on_end = self.on_end.take().unwrap(); let context = - self.context.take(); former :: FormingEnd :: < Definition :: Types > - :: call(& on_end, self.storage, context) - } #[doc = "Setter for the 'command' field."] #[inline] pub fn command < - Src > (mut self, src : Src) -> Self where Src : :: core :: convert :: Into - < HashMap < String, Command > > , - { - debug_assert! (self.storage.command.is_none()); self.storage.command = - :: core :: option :: Option :: - Some(:: core :: convert :: Into :: into(src)); self - } #[doc = r" Custom setter which produce container element subformer."] - #[inline(always)] pub fn _command_add_subformer < Former2, Definition2 > - (self) -> Former2 where Definition2 : former :: FormerDefinition < End = - AggregatorFormerAddCommandEnd < Definition > , Storage = < < HashMap < - String, Command > as former :: ContainerAdd > :: Val as former :: - EntityToStorage > :: Storage, Formed = Self, Context = Self, > , - Definition2 :: Types : former :: FormerDefinitionTypes < Storage = < < - HashMap < String, Command > as former :: ContainerAdd > :: Val as former - :: EntityToStorage > :: Storage, Formed = Self, Context = Self, > , - Former2 : former :: FormerBegin < Definition2 > , - { - Former2 :: - former_begin(None, Some(self), AggregatorFormerAddCommandEnd :: - default()) - } - } impl < Definition, > AggregatorFormer < Definition, > where Definition : - former :: FormerDefinition < Storage = AggregatorFormerStorage < > , Formed = - Aggregator < > > , Definition :: Types : former :: FormerDefinitionTypes < - Storage = AggregatorFormerStorage < > , Formed = Aggregator < > > , Definition - : former :: FormerDefinition < Storage = AggregatorFormerStorage < > > , - Definition :: Types : former :: FormerDefinitionTypes < Storage = - AggregatorFormerStorage < > > , - { - pub fn preform(self) -> < Definition :: Types as former :: - FormerDefinitionTypes > :: Formed - { former :: StoragePreform :: preform(self.storage) } - } #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, - > where Definition : former :: FormerDefinition < Storage = - AggregatorFormerStorage < > , Formed = Aggregator < > , > , Definition :: - Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < - > , Formed = Aggregator < > , > , - { - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] - #[doc = - r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = - r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { let result = self.form(); return result; } - } impl < Definition > former :: FormerBegin < Definition > for - AggregatorFormer < Definition, > where Definition : former :: FormerDefinition - < Storage = AggregatorFormerStorage < > > , - { - #[inline(always)] fn - former_begin(storage : core :: option :: Option < Definition :: Storage > - , context : core :: option :: Option < Definition :: Context > , on_end : - Definition :: End,) -> Self - { - debug_assert! (storage.is_none()); Self :: - begin(None, context, on_end) - } - } - #[doc = - r" Use as subformer of a field during process of forming of super structure."] - pub type AggregatorAsSubformer < __Superformer, __End > = AggregatorFormer < - AggregatorFormerDefinition < __Superformer, __Superformer, __End, > , > ; - #[doc = - "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] - pub trait AggregatorAsSubformerEnd < SuperFormer > where Self : former :: - FormingEnd < AggregatorFormerDefinitionTypes < SuperFormer, SuperFormer > , > - , {} impl < SuperFormer, __T > AggregatorAsSubformerEnd < SuperFormer > for - __T where Self : former :: FormingEnd < AggregatorFormerDefinitionTypes < - SuperFormer, SuperFormer > , > , {} - #[doc = r" Handles the completion of an element of subformer's container."] - pub struct AggregatorFormerAddCommandEnd < Definition > - { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < - Definition > Default for AggregatorFormerAddCommandEnd < Definition > - { - #[inline(always)] fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } +#[automatically_derived] impl < > Aggregator < > where +{ + #[doc = r""] + #[doc = + r" Make former, variation of builder pattern to form structure defining values of fields step by step."] + #[doc = r""] #[inline(always)] pub fn former() -> AggregatorFormer < + AggregatorFormerDefinition < (), Aggregator < > , former :: + ReturnPreformed > > + { + AggregatorFormer :: < AggregatorFormerDefinition < (), Aggregator < > + , former :: ReturnPreformed > > :: + new_coercing(former :: ReturnPreformed) + } +} + +impl < Definition > former :: EntityToFormer < Definition > +for Aggregator < +> +where Definition : former :: FormerDefinition < Storage = +AggregatorFormerStorage < > > , +{ type Former = AggregatorFormer < Definition > ; } impl < > former :: +EntityToStorage for Aggregator < > where +{ type Storage = AggregatorFormerStorage < > ; } impl < __Context, __Formed, +__End > former :: EntityToDefinition < __Context, __Formed, __End > for +Aggregator < > where __End : former :: FormingEnd < +AggregatorFormerDefinitionTypes < __Context, __Formed > > , +{ + type Definition = AggregatorFormerDefinition < __Context, __Formed, __End + > ; +} #[derive(Debug)] pub struct AggregatorFormerDefinitionTypes < __Context = +(), __Formed = Aggregator < > , > where +{ + _phantom : core :: marker :: PhantomData < + (* const __Context, * const __Formed) > , +} impl < __Context, __Formed, > :: core :: default :: Default for +AggregatorFormerDefinitionTypes < __Context, __Formed, > where +{ + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } +} impl < __Context, __Formed, > former :: FormerDefinitionTypes for +AggregatorFormerDefinitionTypes < __Context, __Formed, > where +{ + type Storage = AggregatorFormerStorage < > ; type Formed = __Formed; type + Context = __Context; +} #[derive(Debug)] pub struct AggregatorFormerDefinition < __Context = (), +__Formed = Aggregator < > , __End = former :: ReturnPreformed, > where +{ + _phantom : core :: marker :: PhantomData < + (* const __Context, * const __Formed, * const __End) > , +} impl < __Context, __Formed, __End, > :: core :: default :: Default for +AggregatorFormerDefinition < __Context, __Formed, __End, > where +{ + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } +} impl < __Context, __Formed, __End, > former :: FormerDefinition for +AggregatorFormerDefinition < __Context, __Formed, __End, > where __End : +former :: FormingEnd < AggregatorFormerDefinitionTypes < __Context, __Formed, +> > , +{ + type Types = AggregatorFormerDefinitionTypes < __Context, __Formed, > ; + type End = __End; type Storage = AggregatorFormerStorage < > ; type Formed + = __Formed; type Context = __Context; +} #[doc = "Container of a corresponding former."] +#[allow(explicit_outlives_requirements)] pub struct AggregatorFormerStorage < +> where +{ + #[doc = r" A field"] pub command : :: core :: option :: Option < HashMap < + String, Command > > , +} impl < > :: core :: default :: Default for AggregatorFormerStorage < > where +{ + #[inline(always)] fn default() -> Self + { Self { command : :: core :: option :: Option :: None, } } +} impl < > former :: Storage for AggregatorFormerStorage < > where +{ type Formed = Aggregator < > ; } impl < > former :: StoragePreform for +AggregatorFormerStorage < > where +{ + type Preformed = Aggregator < > ; fn preform(mut self) -> Self :: + Preformed + { + let command = if self.command.is_some() + { self.command.take().unwrap() } else + { + { + trait MaybeDefault < T > + { + fn maybe_default(self : & Self) -> T + { panic! ("Field 'command' isn't initialized") } + } impl < T > MaybeDefault < T > for & :: core :: marker :: + PhantomData < T > {} impl < T > MaybeDefault < T > for :: core + :: marker :: PhantomData < T > where T : :: core :: default :: + Default, + { fn maybe_default(self : & Self) -> T { T :: default() } } + (& :: core :: marker :: PhantomData :: < HashMap < String, + Command > >).maybe_default() + } + }; let result = Aggregator :: < > { command, }; return result; + } +} +#[doc = +" Object to form [Aggregator]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +pub struct AggregatorFormer < Definition = AggregatorFormerDefinition < (), +Aggregator < > , former :: ReturnPreformed > , > where Definition : former :: +FormerDefinition < Storage = AggregatorFormerStorage < > > , Definition :: +Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < +> > , +{ + storage : Definition :: Storage, context : core :: option :: Option < + Definition :: Context > , on_end : core :: option :: Option < Definition + :: End > , +} #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, +> where Definition : former :: FormerDefinition < Storage = +AggregatorFormerStorage < > > , Definition :: Types : former :: +FormerDefinitionTypes < Storage = AggregatorFormerStorage < > > , +{ + #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> + Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > + (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , + { Self :: begin_coercing(None, None, end,) } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn + begin(mut storage : core :: option :: Option < Definition :: Storage > , + context : core :: option :: Option < Definition :: Context > , on_end : < + Definition as former :: FormerDefinition > :: End,) -> Self + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: Some(on_end), + } + } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > + (mut storage : core :: option :: Option < Definition :: Storage > , + context : core :: option :: Option < Definition :: Context > , on_end : + IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < + Definition as former :: FormerDefinition > :: End > , + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: + Some(:: core :: convert :: Into :: into(on_end)), + } + } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types + as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { + let on_end = self.on_end.take().unwrap(); let context = + self.context.take(); former :: FormingEnd :: < Definition :: Types > + :: call(& on_end, self.storage, context) + } #[doc = "Setter for the 'command' field."] #[inline] pub fn command < + Src > (mut self, src : Src) -> Self where Src : :: core :: convert :: Into + < HashMap < String, Command > > , + { + debug_assert! (self.storage.command.is_none()); self.storage.command = + :: core :: option :: Option :: + Some(:: core :: convert :: Into :: into(src)); self + } #[doc = r" Custom setter which produce container element subformer."] + #[inline(always)] pub fn _command_add_subformer < Former2, Definition2 > + (self) -> Former2 where Definition2 : former :: FormerDefinition < End = + AggregatorFormerAddCommandEnd < Definition > , Storage = < < HashMap < + String, Command > as former :: Container > :: Val as former :: + EntityToStorage > :: Storage, Formed = Self, Context = Self, > , + Definition2 :: Types : former :: FormerDefinitionTypes < Storage = < < + HashMap < String, Command > as former :: Container > :: Val as former :: + EntityToStorage > :: Storage, Formed = Self, Context = Self, > , Former2 : + former :: FormerBegin < Definition2 > , + { + Former2 :: + former_begin(None, Some(self), AggregatorFormerAddCommandEnd :: + default()) + } +} impl < Definition, > AggregatorFormer < Definition, > where Definition : +former :: FormerDefinition < Storage = AggregatorFormerStorage < > , Formed = +Aggregator < > > , Definition :: Types : former :: FormerDefinitionTypes < +Storage = AggregatorFormerStorage < > , Formed = Aggregator < > > , Definition +: former :: FormerDefinition < Storage = AggregatorFormerStorage < > > , +Definition :: Types : former :: FormerDefinitionTypes < Storage = +AggregatorFormerStorage < > > , +{ + pub fn preform(self) -> < Definition :: Types as former :: + FormerDefinitionTypes > :: Formed + { former :: StoragePreform :: preform(self.storage) } +} #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, +> where Definition : former :: FormerDefinition < Storage = +AggregatorFormerStorage < > , Formed = Aggregator < > , > , Definition :: +Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < +> , Formed = Aggregator < > , > , +{ + #[doc = r""] + #[doc = r" Finish setting options and call perform on formed entity."] + #[doc = r""] + #[doc = + r" If `perform` defined then associated method is called and its result returned instead of entity."] + #[doc = + r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] + #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { let result = self.form(); return result; } +} impl < Definition > former :: FormerBegin < Definition > for +AggregatorFormer < Definition, > where Definition : former :: FormerDefinition +< Storage = AggregatorFormerStorage < > > , +{ + #[inline(always)] fn + former_begin(storage : core :: option :: Option < Definition :: Storage > + , context : core :: option :: Option < Definition :: Context > , on_end : + Definition :: End,) -> Self + { + debug_assert! (storage.is_none()); Self :: + begin(None, context, on_end) + } +} +#[doc = +r" Use as subformer of a field during process of forming of super structure."] +pub type AggregatorAsSubformer < __Superformer, __End > = AggregatorFormer < +AggregatorFormerDefinition < __Superformer, __Superformer, __End, > , > ; +#[doc = +"Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] +pub trait AggregatorAsSubformerEnd < SuperFormer > where Self : former :: +FormingEnd < AggregatorFormerDefinitionTypes < SuperFormer, SuperFormer > , > +, {} impl < SuperFormer, __T > AggregatorAsSubformerEnd < SuperFormer > for +__T where Self : former :: FormingEnd < AggregatorFormerDefinitionTypes < +SuperFormer, SuperFormer > , > , {} +#[doc = r" Handles the completion of an element of subformer's container."] +pub struct AggregatorFormerAddCommandEnd < Definition > +{ _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < +Definition > Default for AggregatorFormerAddCommandEnd < Definition > +{ + #[inline(always)] fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } +} - impl < Types2, Definition > former :: FormingEnd < Types2, > - for - AggregatorFormerAddCommandEnd < Definition > - where - Definition : former :: - FormerDefinition < Storage = < Aggregator < > as former :: EntityToStorage > - :: Storage, > , Types2 : former :: FormerDefinitionTypes < Storage = < < - HashMap < String, Command > as former :: ContainerAdd > :: Val as former :: - EntityToStorage > :: Storage, Formed = AggregatorFormer < Definition, > , - Context = AggregatorFormer < Definition, > , > , - { - #[inline(always)] fn - call(& self, substorage : Types2 :: Storage, super_former : core :: option - :: Option < Types2 :: Context > ,) -> Types2 :: Formed - { - let mut super_former = super_former.unwrap(); if - super_former.storage.command.is_none() - { super_former.storage.command = Some(Default :: default()); } if let - Some(ref mut field) = super_former.storage.command - { - former :: ContainerAdd :: add(field, former :: StoragePreform :: preform(substorage)); - } super_former - } - } +impl < Types2, Definition > former :: FormingEnd < Types2, > for +AggregatorFormerAddCommandEnd < Definition > where Definition : former :: +FormerDefinition < Storage = < Aggregator < > as former :: EntityToStorage > +:: Storage, > , Types2 : former :: FormerDefinitionTypes < Storage = < < +HashMap < String, Command > as former :: Container > :: Val as former :: +EntityToStorage > :: Storage, Formed = AggregatorFormer < Definition, > , +Context = AggregatorFormer < Definition, > , > , +{ + #[inline(always)] fn + call(& self, substorage : Types2 :: Storage, super_former : core :: option + :: Option < Types2 :: Context > ,) -> Types2 :: Formed + { + let mut super_former = super_former.unwrap(); if + super_former.storage.command.is_none() + { super_former.storage.command = Some(Default :: default()); } if let + Some(ref mut field) = super_former.storage.command + { + former :: ContainerAdd :: + add(field, former :: StoragePreform :: preform(substorage)); + } super_former + } +} // == end of generated diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 4aa70adac1..cc2adf6498 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -76,8 +76,8 @@ mod former_tests mod subformer_subform_named; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_named_manual; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_subform_hashmap; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_hashmap; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_and_container; From 35dbef40847f4ce4ccab6d68cd3c37d214a52e9f Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 18:19:44 +0300 Subject: [PATCH 364/533] former : experimenting --- module/core/former/src/container.rs | 18 ++++- .../former_tests/subformer_subform_hashmap.rs | 71 ++++++++++++++----- 2 files changed, 68 insertions(+), 21 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 9d8695c472..60fa7ebfcb 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -17,14 +17,26 @@ pub trait Container } +// /// xxx : improve description +// /// Extensation of container interface to convert value ot element. +// /// As well as function to convert element to value. Reversal conversion could be not possible, so value to element conversion is in a separate trait. +// pub trait ContainerValToElement : Container +// { +// +// /// Convert val to element. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. +// fn val_to_element( val : Self::Val ) -> Self::Element; +// +// } + /// xxx : improve description -/// Extensation of container interface to convert value ot element. +/// Implement function to convert value of an element of a container. /// As well as function to convert element to value. Reversal conversion could be not possible, so value to element conversion is in a separate trait. -pub trait ValToElement : Container +pub trait ValToElement { + type Element; /// Convert val to element. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. - fn val_to_element( val : Self::Val ) -> Self::Element; + fn val_to_element( self ) -> Self::Element; } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index fdcecb5585..4a51b0240c 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -318,29 +318,64 @@ Definition > Default for AggregatorFormerAddCommandEnd < Definition > { Self { _phantom : core :: marker :: PhantomData, } } } -impl < Types2, Definition > former :: FormingEnd < Types2, > for -AggregatorFormerAddCommandEnd < Definition > where Definition : former :: -FormerDefinition < Storage = < Aggregator < > as former :: EntityToStorage > -:: Storage, > , Types2 : former :: FormerDefinitionTypes < Storage = < < -HashMap < String, Command > as former :: Container > :: Val as former :: -EntityToStorage > :: Storage, Formed = AggregatorFormer < Definition, > , -Context = AggregatorFormer < Definition, > , > , +impl< Types2, Definition > former::FormingEnd< Types2, > +for AggregatorFormerAddCommandEnd< Definition > +where + Definition : former::FormerDefinition< Storage = < Aggregator< > as former::EntityToStorage >::Storage, >, + Types2 :former::FormerDefinitionTypes + < + Storage = < < HashMap< String, Command > as former::Container >::Val as former::EntityToStorage >::Storage, + Formed = AggregatorFormer< Definition, >, + Context = AggregatorFormer< Definition, >, + >, { - #[inline(always)] fn - call(& self, substorage : Types2 :: Storage, super_former : core :: option - :: Option < Types2 :: Context > ,) -> Types2 :: Formed + #[ inline( always ) ] + fn call( &self, substorage : Types2::Storage, super_former : core::option::Option< Types2::Context > ) -> Types2::Formed + { + let mut super_former = super_former.unwrap(); + if super_former.storage.command.is_none() { - let mut super_former = super_former.unwrap(); if - super_former.storage.command.is_none() - { super_former.storage.command = Some(Default :: default()); } if let - Some(ref mut field) = super_former.storage.command - { - former :: ContainerAdd :: - add(field, former :: StoragePreform :: preform(substorage)); - } super_former + super_former.storage.command = Some( Default::default() ); } + if let Some( ref mut field ) = super_former.storage.command + { + former::ContainerAdd::add + ( + field, + < Command as former::ValToElement >::val_to_element( former::StoragePreform::preform( substorage ) ), + ); + } + super_former + } } +// impl former::ContainerValToElement for collection_tools::HashMap< String, Command > +// { +// fn val_to_element( val : Self::Val ) -> Self::Element +// { +// ( val.name.clone(), val ) +// } +// } + +impl former::ValToElement for Command +{ + type Element = ( String, Command ); + #[ inline ] + fn val_to_element( self ) -> Self::Element + { + ( self.name.clone(), self ) + } +} + +// pub trait ValToElement +// { +// type Element; +// +// /// Convert val to element. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. +// fn val_to_element( self ) -> Self::Element; +// +// } + // == end of generated // #[ test ] From 62b13e23c540c21c4f1008041dc3178e06c2aa3e Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 1 May 2024 18:50:23 +0300 Subject: [PATCH 365/533] former : experimenting --- module/core/former/src/container.rs | 2 +- .../tests/inc/former_tests/subformer_subform_hashmap.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 60fa7ebfcb..3eab983a93 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -31,7 +31,7 @@ pub trait Container /// xxx : improve description /// Implement function to convert value of an element of a container. /// As well as function to convert element to value. Reversal conversion could be not possible, so value to element conversion is in a separate trait. -pub trait ValToElement +pub trait ValToElement< Container > { type Element; diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index 4a51b0240c..d5308b97f8 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -342,7 +342,8 @@ where former::ContainerAdd::add ( field, - < Command as former::ValToElement >::val_to_element( former::StoragePreform::preform( substorage ) ), + < Command as former::ValToElement< HashMap< String, Command > > > + ::val_to_element( former::StoragePreform::preform( substorage ) ), ); } super_former @@ -357,7 +358,7 @@ where // } // } -impl former::ValToElement for Command +impl former::ValToElement< HashMap< String, Command > > for Command { type Element = ( String, Command ); #[ inline ] From db62ac54dc6ffbc69cca8a299732aebc3f05d257 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 08:47:06 +0300 Subject: [PATCH 366/533] former : experimenting --- module/core/former/src/hash_set.rs | 18 +++++++++++++++--- module/core/former/src/vector.rs | 10 ++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index c20f5b0f64..2b35fe7092 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -35,11 +35,11 @@ where } -impl< T > ContainerAssign for collection_tools::HashSet< T > +impl< K > ContainerAssign for collection_tools::HashSet< K > where - T : core::cmp::Eq + core::hash::Hash, + K : core::cmp::Eq + core::hash::Hash, { - // type Element = T; + // type Element = K; fn assign< Elements >( &mut self, elements : Elements ) -> usize where @@ -51,6 +51,18 @@ where } } +impl< K > ValToElement< HashSet< K > > for K +where + K : core::cmp::Eq + core::hash::Hash, +{ + type Element = K; + #[ inline ] + fn val_to_element( self ) -> Self::Element + { + self + } +} + /// A trait for containers behaving like a `HashSet`, allowing insertion operations. /// /// Implementing this trait enables the associated formed to be used with `HashSetSubformer`, diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 7afdf664d4..c966ba4734 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -47,6 +47,16 @@ impl< E > ContainerAssign for collection_tools::Vec< E > } +impl< E > ValToElement< collection_tools::Vec< E > > for E +{ + type Element = E; + #[ inline ] + fn val_to_element( self ) -> Self::Element + { + 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, From 569eb0de4dbe754567a3e0b390ae11c74da0160c Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 09:09:49 +0300 Subject: [PATCH 367/533] former : experimenting --- module/core/former/src/hash_set.rs | 2 +- module/core/former/src/vector.rs | 2 +- .../former_tests/subformer_subform_hashmap.rs | 645 ++++++++---------- module/core/former_meta/src/derive/former.rs | 28 +- 4 files changed, 314 insertions(+), 363 deletions(-) diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 2b35fe7092..d0150b85d6 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -56,7 +56,7 @@ where K : core::cmp::Eq + core::hash::Hash, { type Element = K; - #[ inline ] + #[ inline( always ) ] fn val_to_element( self ) -> Self::Element { self diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index c966ba4734..3ef46dbbc7 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -50,7 +50,7 @@ impl< E > ContainerAssign for collection_tools::Vec< E > impl< E > ValToElement< collection_tools::Vec< E > > for E { type Element = E; - #[ inline ] + #[ inline( always ) ] fn val_to_element( self ) -> Self::Element { self diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index d5308b97f8..b3a76738f6 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -24,373 +24,318 @@ pub struct Aggregator command : HashMap< String, Command >, } -// // Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. -// impl< Definition > AggregatorFormer< Definition > -// where -// Definition : former::FormerDefinition< Storage = < Aggregator as former::EntityToStorage >::Storage >, -// { -// -// #[ inline( always ) ] -// pub fn command( self, name : &str ) -> CommandAsSubformer< Self, impl CommandAsSubformerEnd< Self > > -// { -// self._command_add_subformer::< CommandFormer< _ >, _, >() -// .name( name ) -// } -// -// } - -// // Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. -// impl< Definition > AggregatorFormer< Definition > -// where -// End : former::FormingEnd< Aggregator, Context >, -// { -// #[ inline( always ) ] -// pub fn command< IntoName >( self, name : IntoName ) -> CommandFormer< Self, impl former::FormingEnd< Command, Self > > -// where -// IntoName : core::convert::Into< String >, -// { -// let on_end = | command : Command, super_former : core::option::Option< Self > | -> Self -// { -// let mut super_former = super_former.unwrap(); -// if let Some( ref mut commands ) = super_former.storage.command -// { -// commands.insert( command.name.clone(), command ); -// } -// else -// { -// let mut commands: HashMap< String, Command > = Default::default(); -// commands.insert( command.name.clone(), command ); -// super_former.storage.command = Some( commands ); -// } -// super_former -// }; -// let former = CommandFormer::begin( None, Some( self ), on_end ); -// former.name( name ) -// } -// // xxx : review -// } - -// == begin of generated - -#[automatically_derived] impl < > Aggregator < > where -{ - #[doc = r""] - #[doc = - r" Make former, variation of builder pattern to form structure defining values of fields step by step."] - #[doc = r""] #[inline(always)] pub fn former() -> AggregatorFormer < - AggregatorFormerDefinition < (), Aggregator < > , former :: - ReturnPreformed > > - { - AggregatorFormer :: < AggregatorFormerDefinition < (), Aggregator < > - , former :: ReturnPreformed > > :: - new_coercing(former :: ReturnPreformed) - } -} - -impl < Definition > former :: EntityToFormer < Definition > -for Aggregator < -> -where Definition : former :: FormerDefinition < Storage = -AggregatorFormerStorage < > > , -{ type Former = AggregatorFormer < Definition > ; } impl < > former :: -EntityToStorage for Aggregator < > where -{ type Storage = AggregatorFormerStorage < > ; } impl < __Context, __Formed, -__End > former :: EntityToDefinition < __Context, __Formed, __End > for -Aggregator < > where __End : former :: FormingEnd < -AggregatorFormerDefinitionTypes < __Context, __Formed > > , -{ - type Definition = AggregatorFormerDefinition < __Context, __Formed, __End - > ; -} #[derive(Debug)] pub struct AggregatorFormerDefinitionTypes < __Context = -(), __Formed = Aggregator < > , > where -{ - _phantom : core :: marker :: PhantomData < - (* const __Context, * const __Formed) > , -} impl < __Context, __Formed, > :: core :: default :: Default for -AggregatorFormerDefinitionTypes < __Context, __Formed, > where -{ - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } -} impl < __Context, __Formed, > former :: FormerDefinitionTypes for -AggregatorFormerDefinitionTypes < __Context, __Formed, > where -{ - type Storage = AggregatorFormerStorage < > ; type Formed = __Formed; type - Context = __Context; -} #[derive(Debug)] pub struct AggregatorFormerDefinition < __Context = (), -__Formed = Aggregator < > , __End = former :: ReturnPreformed, > where -{ - _phantom : core :: marker :: PhantomData < - (* const __Context, * const __Formed, * const __End) > , -} impl < __Context, __Formed, __End, > :: core :: default :: Default for -AggregatorFormerDefinition < __Context, __Formed, __End, > where -{ - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } -} impl < __Context, __Formed, __End, > former :: FormerDefinition for -AggregatorFormerDefinition < __Context, __Formed, __End, > where __End : -former :: FormingEnd < AggregatorFormerDefinitionTypes < __Context, __Formed, -> > , -{ - type Types = AggregatorFormerDefinitionTypes < __Context, __Formed, > ; - type End = __End; type Storage = AggregatorFormerStorage < > ; type Formed - = __Formed; type Context = __Context; -} #[doc = "Container of a corresponding former."] -#[allow(explicit_outlives_requirements)] pub struct AggregatorFormerStorage < -> where -{ - #[doc = r" A field"] pub command : :: core :: option :: Option < HashMap < - String, Command > > , -} impl < > :: core :: default :: Default for AggregatorFormerStorage < > where -{ - #[inline(always)] fn default() -> Self - { Self { command : :: core :: option :: Option :: None, } } -} impl < > former :: Storage for AggregatorFormerStorage < > where -{ type Formed = Aggregator < > ; } impl < > former :: StoragePreform for -AggregatorFormerStorage < > where -{ - type Preformed = Aggregator < > ; fn preform(mut self) -> Self :: - Preformed - { - let command = if self.command.is_some() - { self.command.take().unwrap() } else - { - { - trait MaybeDefault < T > - { - fn maybe_default(self : & Self) -> T - { panic! ("Field 'command' isn't initialized") } - } impl < T > MaybeDefault < T > for & :: core :: marker :: - PhantomData < T > {} impl < T > MaybeDefault < T > for :: core - :: marker :: PhantomData < T > where T : :: core :: default :: - Default, - { fn maybe_default(self : & Self) -> T { T :: default() } } - (& :: core :: marker :: PhantomData :: < HashMap < String, - Command > >).maybe_default() - } - }; let result = Aggregator :: < > { command, }; return result; - } -} -#[doc = -" Object to form [Aggregator]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -pub struct AggregatorFormer < Definition = AggregatorFormerDefinition < (), -Aggregator < > , former :: ReturnPreformed > , > where Definition : former :: -FormerDefinition < Storage = AggregatorFormerStorage < > > , Definition :: -Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < -> > , -{ - storage : Definition :: Storage, context : core :: option :: Option < - Definition :: Context > , on_end : core :: option :: Option < Definition - :: End > , -} #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, -> where Definition : former :: FormerDefinition < Storage = -AggregatorFormerStorage < > > , Definition :: Types : former :: -FormerDefinitionTypes < Storage = AggregatorFormerStorage < > > , -{ - #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> - Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > - (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , - { Self :: begin_coercing(None, None, end,) } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn - begin(mut storage : core :: option :: Option < Definition :: Storage > , - context : core :: option :: Option < Definition :: Context > , on_end : < - Definition as former :: FormerDefinition > :: End,) -> Self - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: Some(on_end), - } - } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > - (mut storage : core :: option :: Option < Definition :: Storage > , - context : core :: option :: Option < Definition :: Context > , on_end : - IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < - Definition as former :: FormerDefinition > :: End > , - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: - Some(:: core :: convert :: Into :: into(on_end)), - } - } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types - as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { - let on_end = self.on_end.take().unwrap(); let context = - self.context.take(); former :: FormingEnd :: < Definition :: Types > - :: call(& on_end, self.storage, context) - } #[doc = "Setter for the 'command' field."] #[inline] pub fn command < - Src > (mut self, src : Src) -> Self where Src : :: core :: convert :: Into - < HashMap < String, Command > > , - { - debug_assert! (self.storage.command.is_none()); self.storage.command = - :: core :: option :: Option :: - Some(:: core :: convert :: Into :: into(src)); self - } #[doc = r" Custom setter which produce container element subformer."] - #[inline(always)] pub fn _command_add_subformer < Former2, Definition2 > - (self) -> Former2 where Definition2 : former :: FormerDefinition < End = - AggregatorFormerAddCommandEnd < Definition > , Storage = < < HashMap < - String, Command > as former :: Container > :: Val as former :: - EntityToStorage > :: Storage, Formed = Self, Context = Self, > , - Definition2 :: Types : former :: FormerDefinitionTypes < Storage = < < - HashMap < String, Command > as former :: Container > :: Val as former :: - EntityToStorage > :: Storage, Formed = Self, Context = Self, > , Former2 : - former :: FormerBegin < Definition2 > , - { - Former2 :: - former_begin(None, Some(self), AggregatorFormerAddCommandEnd :: - default()) - } -} impl < Definition, > AggregatorFormer < Definition, > where Definition : -former :: FormerDefinition < Storage = AggregatorFormerStorage < > , Formed = -Aggregator < > > , Definition :: Types : former :: FormerDefinitionTypes < -Storage = AggregatorFormerStorage < > , Formed = Aggregator < > > , Definition -: former :: FormerDefinition < Storage = AggregatorFormerStorage < > > , -Definition :: Types : former :: FormerDefinitionTypes < Storage = -AggregatorFormerStorage < > > , -{ - pub fn preform(self) -> < Definition :: Types as former :: - FormerDefinitionTypes > :: Formed - { former :: StoragePreform :: preform(self.storage) } -} #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, -> where Definition : former :: FormerDefinition < Storage = -AggregatorFormerStorage < > , Formed = Aggregator < > , > , Definition :: -Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < -> , Formed = Aggregator < > , > , -{ - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] - #[doc = - r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = - r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { let result = self.form(); return result; } -} impl < Definition > former :: FormerBegin < Definition > for -AggregatorFormer < Definition, > where Definition : former :: FormerDefinition -< Storage = AggregatorFormerStorage < > > , -{ - #[inline(always)] fn - former_begin(storage : core :: option :: Option < Definition :: Storage > - , context : core :: option :: Option < Definition :: Context > , on_end : - Definition :: End,) -> Self - { - debug_assert! (storage.is_none()); Self :: - begin(None, context, on_end) - } -} -#[doc = -r" Use as subformer of a field during process of forming of super structure."] -pub type AggregatorAsSubformer < __Superformer, __End > = AggregatorFormer < -AggregatorFormerDefinition < __Superformer, __Superformer, __End, > , > ; -#[doc = -"Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] -pub trait AggregatorAsSubformerEnd < SuperFormer > where Self : former :: -FormingEnd < AggregatorFormerDefinitionTypes < SuperFormer, SuperFormer > , > -, {} impl < SuperFormer, __T > AggregatorAsSubformerEnd < SuperFormer > for -__T where Self : former :: FormingEnd < AggregatorFormerDefinitionTypes < -SuperFormer, SuperFormer > , > , {} -#[doc = r" Handles the completion of an element of subformer's container."] -pub struct AggregatorFormerAddCommandEnd < Definition > -{ _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < -Definition > Default for AggregatorFormerAddCommandEnd < Definition > -{ - #[inline(always)] fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } -} - -impl< Types2, Definition > former::FormingEnd< Types2, > -for AggregatorFormerAddCommandEnd< Definition > +// Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. +impl< Definition > AggregatorFormer< Definition > where - Definition : former::FormerDefinition< Storage = < Aggregator< > as former::EntityToStorage >::Storage, >, - Types2 :former::FormerDefinitionTypes - < - Storage = < < HashMap< String, Command > as former::Container >::Val as former::EntityToStorage >::Storage, - Formed = AggregatorFormer< Definition, >, - Context = AggregatorFormer< Definition, >, - >, + Definition : former::FormerDefinition< Storage = < Aggregator as former::EntityToStorage >::Storage >, { + #[ inline( always ) ] - fn call( &self, substorage : Types2::Storage, super_former : core::option::Option< Types2::Context > ) -> Types2::Formed + pub fn command2( self, name : &str ) -> CommandAsSubformer< Self, impl CommandAsSubformerEnd< Self > > { - let mut super_former = super_former.unwrap(); - if super_former.storage.command.is_none() - { - super_former.storage.command = Some( Default::default() ); - } - if let Some( ref mut field ) = super_former.storage.command - { - former::ContainerAdd::add - ( - field, - < Command as former::ValToElement< HashMap< String, Command > > > - ::val_to_element( former::StoragePreform::preform( substorage ) ), - ); - } - super_former + self._command_add_subformer::< CommandFormer< _ >, _, >() + .name( name ) } -} -// impl former::ContainerValToElement for collection_tools::HashMap< String, Command > -// { -// fn val_to_element( val : Self::Val ) -> Self::Element -// { -// ( val.name.clone(), val ) -// } -// } +} impl former::ValToElement< HashMap< String, Command > > for Command { type Element = ( String, Command ); - #[ inline ] + #[ inline( always ) ] fn val_to_element( self ) -> Self::Element { ( self.name.clone(), self ) } } -// pub trait ValToElement -// { -// type Element; -// -// /// Convert val to element. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. -// fn val_to_element( self ) -> Self::Element; -// -// } +// == begin of generated + + #[automatically_derived] impl < > Aggregator < > where + { + #[doc = r""] + #[doc = + r" Make former, variation of builder pattern to form structure defining values of fields step by step."] + #[doc = r""] #[inline(always)] pub fn former() -> AggregatorFormer < + AggregatorFormerDefinition < (), Aggregator < > , former :: + ReturnPreformed > > + { + AggregatorFormer :: < AggregatorFormerDefinition < (), Aggregator < > + , former :: ReturnPreformed > > :: + new_coercing(former :: ReturnPreformed) + } + } impl < Definition > former :: EntityToFormer < Definition > for Aggregator < + > where Definition : former :: FormerDefinition < Storage = + AggregatorFormerStorage < > > , + { type Former = AggregatorFormer < Definition > ; } impl < > former :: + EntityToStorage for Aggregator < > where + { type Storage = AggregatorFormerStorage < > ; } impl < __Context, __Formed, + __End > former :: EntityToDefinition < __Context, __Formed, __End > for + Aggregator < > where __End : former :: FormingEnd < + AggregatorFormerDefinitionTypes < __Context, __Formed > > , + { + type Definition = AggregatorFormerDefinition < __Context, __Formed, __End + > ; + } #[derive(Debug)] pub struct AggregatorFormerDefinitionTypes < __Context = + (), __Formed = Aggregator < > , > where + { + _phantom : core :: marker :: PhantomData < + (* const __Context, * const __Formed) > , + } impl < __Context, __Formed, > :: core :: default :: Default for + AggregatorFormerDefinitionTypes < __Context, __Formed, > where + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } impl < __Context, __Formed, > former :: FormerDefinitionTypes for + AggregatorFormerDefinitionTypes < __Context, __Formed, > where + { + type Storage = AggregatorFormerStorage < > ; type Formed = __Formed; type + Context = __Context; + } #[derive(Debug)] pub struct AggregatorFormerDefinition < __Context = (), + __Formed = Aggregator < > , __End = former :: ReturnPreformed, > where + { + _phantom : core :: marker :: PhantomData < + (* const __Context, * const __Formed, * const __End) > , + } impl < __Context, __Formed, __End, > :: core :: default :: Default for + AggregatorFormerDefinition < __Context, __Formed, __End, > where + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } impl < __Context, __Formed, __End, > former :: FormerDefinition for + AggregatorFormerDefinition < __Context, __Formed, __End, > where __End : + former :: FormingEnd < AggregatorFormerDefinitionTypes < __Context, __Formed, + > > , + { + type Types = AggregatorFormerDefinitionTypes < __Context, __Formed, > ; + type End = __End; type Storage = AggregatorFormerStorage < > ; type Formed + = __Formed; type Context = __Context; + } #[doc = "Container of a corresponding former."] + #[allow(explicit_outlives_requirements)] pub struct AggregatorFormerStorage < + > where + { + #[doc = r" A field"] pub command : :: core :: option :: Option < HashMap < + String, Command > > , + } impl < > :: core :: default :: Default for AggregatorFormerStorage < > where + { + #[inline(always)] fn default() -> Self + { Self { command : :: core :: option :: Option :: None, } } + } impl < > former :: Storage for AggregatorFormerStorage < > where + { type Formed = Aggregator < > ; } impl < > former :: StoragePreform for + AggregatorFormerStorage < > where + { + type Preformed = Aggregator < > ; fn preform(mut self) -> Self :: + Preformed + { + let command = if self.command.is_some() + { self.command.take().unwrap() } else + { + { + trait MaybeDefault < T > + { + fn maybe_default(self : & Self) -> T + { panic! ("Field 'command' isn't initialized") } + } impl < T > MaybeDefault < T > for & :: core :: marker :: + PhantomData < T > {} impl < T > MaybeDefault < T > for :: core + :: marker :: PhantomData < T > where T : :: core :: default :: + Default, + { fn maybe_default(self : & Self) -> T { T :: default() } } + (& :: core :: marker :: PhantomData :: < HashMap < String, + Command > >).maybe_default() + } + }; let result = Aggregator :: < > { command, }; return result; + } + } + #[doc = + " Object to form [Aggregator]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] + pub struct AggregatorFormer < Definition = AggregatorFormerDefinition < (), + Aggregator < > , former :: ReturnPreformed > , > where Definition : former :: + FormerDefinition < Storage = AggregatorFormerStorage < > > , Definition :: + Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < + > > , + { + storage : Definition :: Storage, context : core :: option :: Option < + Definition :: Context > , on_end : core :: option :: Option < Definition + :: End > , + } #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, + > where Definition : former :: FormerDefinition < Storage = + AggregatorFormerStorage < > > , Definition :: Types : former :: + FormerDefinitionTypes < Storage = AggregatorFormerStorage < > > , + { + #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> + Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > + (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , + { Self :: begin_coercing(None, None, end,) } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn + begin(mut storage : core :: option :: Option < Definition :: Storage > , + context : core :: option :: Option < Definition :: Context > , on_end : < + Definition as former :: FormerDefinition > :: End,) -> Self + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: Some(on_end), + } + } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > + (mut storage : core :: option :: Option < Definition :: Storage > , + context : core :: option :: Option < Definition :: Context > , on_end : + IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < + Definition as former :: FormerDefinition > :: End > , + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: + Some(:: core :: convert :: Into :: into(on_end)), + } + } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types + as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { + let on_end = self.on_end.take().unwrap(); let context = + self.context.take(); former :: FormingEnd :: < Definition :: Types > + :: call(& on_end, self.storage, context) + } #[doc = "Setter for the 'command' field."] + + + #[inline] pub fn command < + Src > (mut self, src : Src) -> Self where Src : :: core :: convert :: Into + < HashMap < String, Command > > , + { + debug_assert! (self.storage.command.is_none()); self.storage.command = + :: core :: option :: Option :: + Some(:: core :: convert :: Into :: into(src)); self + } + + #[doc = r" Custom setter which produce container element subformer."] + #[inline(always)] pub fn _command_add_subformer < Former2, Definition2 > + (self) -> Former2 where Definition2 : former :: FormerDefinition < End = + AggregatorFormerAddCommandEnd < Definition > , Storage = < < HashMap < + String, Command > as former :: Container > :: Val as former :: + EntityToStorage > :: Storage, Formed = Self, Context = Self, > , + Definition2 :: Types : former :: FormerDefinitionTypes < Storage = < < + HashMap < String, Command > as former :: Container > :: Val as former :: + EntityToStorage > :: Storage, Formed = Self, Context = Self, > , Former2 : + former :: FormerBegin < Definition2 > , + { + Former2 :: + former_begin(None, Some(self), AggregatorFormerAddCommandEnd :: + default()) + } + } impl < Definition, > AggregatorFormer < Definition, > where Definition : + former :: FormerDefinition < Storage = AggregatorFormerStorage < > , Formed = + Aggregator < > > , Definition :: Types : former :: FormerDefinitionTypes < + Storage = AggregatorFormerStorage < > , Formed = Aggregator < > > , Definition + : former :: FormerDefinition < Storage = AggregatorFormerStorage < > > , + Definition :: Types : former :: FormerDefinitionTypes < Storage = + AggregatorFormerStorage < > > , + { + pub fn preform(self) -> < Definition :: Types as former :: + FormerDefinitionTypes > :: Formed + { former :: StoragePreform :: preform(self.storage) } + } #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, + > where Definition : former :: FormerDefinition < Storage = + AggregatorFormerStorage < > , Formed = Aggregator < > , > , Definition :: + Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < + > , Formed = Aggregator < > , > , + { + #[doc = r""] + #[doc = r" Finish setting options and call perform on formed entity."] + #[doc = r""] + #[doc = + r" If `perform` defined then associated method is called and its result returned instead of entity."] + #[doc = + r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] + #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { let result = self.form(); return result; } + } impl < Definition > former :: FormerBegin < Definition > for + AggregatorFormer < Definition, > where Definition : former :: FormerDefinition + < Storage = AggregatorFormerStorage < > > , + { + #[inline(always)] fn + former_begin(storage : core :: option :: Option < Definition :: Storage > + , context : core :: option :: Option < Definition :: Context > , on_end : + Definition :: End,) -> Self + { + debug_assert! (storage.is_none()); Self :: + begin(None, context, on_end) + } + } + #[doc = + r" Use as subformer of a field during process of forming of super structure."] + pub type AggregatorAsSubformer < __Superformer, __End > = AggregatorFormer < + AggregatorFormerDefinition < __Superformer, __Superformer, __End, > , > ; + #[doc = + "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] + pub trait AggregatorAsSubformerEnd < SuperFormer > where Self : former :: + FormingEnd < AggregatorFormerDefinitionTypes < SuperFormer, SuperFormer > , > + , {} impl < SuperFormer, __T > AggregatorAsSubformerEnd < SuperFormer > for + __T where Self : former :: FormingEnd < AggregatorFormerDefinitionTypes < + SuperFormer, SuperFormer > , > , {} + #[doc = r" Handles the completion of an element of subformer's container."] + pub struct AggregatorFormerAddCommandEnd < Definition > + { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < + Definition > Default for AggregatorFormerAddCommandEnd < Definition > + { + #[inline(always)] fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } impl < Types2, Definition > former :: FormingEnd < Types2, > for + AggregatorFormerAddCommandEnd < Definition > where Definition : former :: + FormerDefinition < Storage = < Aggregator < > as former :: EntityToStorage > + :: Storage, > , Types2 : former :: FormerDefinitionTypes < Storage = < < + HashMap < String, Command > as former :: Container > :: Val as former :: + EntityToStorage > :: Storage, Formed = AggregatorFormer < Definition, > , + Context = AggregatorFormer < Definition, > , > , + { + #[inline(always)] fn + call(& self, substorage : Types2 :: Storage, super_former : core :: option + :: Option < Types2 :: Context > ,) -> Types2 :: Formed + { + let mut super_former = super_former.unwrap(); if + super_former.storage.command.is_none() + { super_former.storage.command = Some(Default :: default()); } if let + Some(ref mut field) = super_former.storage.command + { + former :: ContainerAdd :: + add(field, < < HashMap < String, Command > as former :: Container + > :: Val as former :: ValToElement < HashMap < String, Command > > + > :: + val_to_element(former :: StoragePreform :: preform(substorage)),); + } super_former + } + } // == end of generated -// #[ test ] -// fn basic() -// { -// -// let ca = Aggregator::former() -// .command( "echo" ) -// .description( "prints all subjects and properties" ) // sets additional properties using custom subformer -// .end() -// .command( "exit" ) -// .description( "just exit" ) // Sets additional properties using using custom subformer -// .end() -// .form(); -// -// } +#[ test ] +fn basic() +{ + + let ca = Aggregator::former() + .command2( "echo" ) + .description( "prints all subjects and properties" ) // sets additional properties using custom subformer + .end() + .command2( "exit" ) + .description( "just exit" ) // Sets additional properties using using custom subformer + .end() + .form(); + +} // xxx \ No newline at end of file diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 094da29c45..ac1f26ed6d 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -712,8 +712,8 @@ fn field_subformer_map }; // example : `ParentFormerAddChildrenEnd`` - let parent_add_element_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); - let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); + let former_add_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let former_add_end = syn::Ident::new( &former_add_end_name, field_ident.span() ); // example : `_children_former` let element_subformer_name = format!( "_{}_add_subformer", field_ident ); @@ -729,7 +729,7 @@ fn field_subformer_map where Definition2 : former::FormerDefinition < - End = #parent_add_element_end< Definition >, + End = #former_add_end< Definition >, Storage = < < #field_ty as former::Container >::Val as former::EntityToStorage >::Storage, Formed = Self, Context = Self, @@ -742,7 +742,7 @@ fn field_subformer_map >, Former2 : former::FormerBegin< Definition2 >, { - Former2::former_begin( None, Some( self ), #parent_add_element_end::default() ) + Former2::former_begin( None, Some( self ), #former_add_end::default() ) } }; @@ -759,7 +759,7 @@ fn field_subformer_map < < #field_ty as former::Container >::Val as former::EntityToFormer < < - < #field_ty as former::Container >::Val as former::EntityToDefinition< Self, Self, #parent_add_element_end < Definition > > + < #field_ty as former::Container >::Val as former::EntityToDefinition< Self, Self, #former_add_end < Definition > > >::Definition, > >::Former @@ -1205,21 +1205,21 @@ Result< TokenStream > // let params = typ::type_parameters( &field.non_optional_ty, .. ); // example : `ParentFormerAddChildrenEnd`` - let parent_add_element_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); - let parent_add_element_end = syn::Ident::new( &parent_add_element_end_name, field_ident.span() ); + let former_add_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let former_add_end = syn::Ident::new( &former_add_end_name, field_ident.span() ); let r = qt! { // zzz : improve description /// Handles the completion of an element of subformer's container. - pub struct #parent_add_element_end< Definition > + pub struct #former_add_end< Definition > { _phantom : core::marker::PhantomData< fn( Definition ) >, } impl< Definition > Default - for #parent_add_element_end< Definition > + for #former_add_end< Definition > { #[ inline( always ) ] fn default() -> Self @@ -1232,7 +1232,7 @@ Result< TokenStream > } impl< #struct_generics_impl Types2, Definition > former::FormingEnd< Types2, > - for #parent_add_element_end< Definition > + for #former_add_end< Definition > where Definition : former::FormerDefinition < @@ -1262,7 +1262,13 @@ Result< TokenStream > } if let Some( ref mut field ) = super_former.storage.#field_ident { - former::ContainerAdd::add( field, former::StoragePreform::preform( substorage ) ); + former::ContainerAdd::add + ( + field, + < < #field_ty as former::Container >::Val as former::ValToElement< #field_ty > > + ::val_to_element( former::StoragePreform::preform( substorage ) ), + ); + // former::ContainerAdd::add( field, former::StoragePreform::preform( substorage ) ); } super_former } From 8036aadcd6f3cf05cd841e0fdafce1e884879cc6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 10:45:35 +0300 Subject: [PATCH 368/533] former : experimenting --- .../former_tests/subformer_subform_hashmap.rs | 554 +++++++++--------- module/core/former_meta/src/derive/former.rs | 68 ++- 2 files changed, 317 insertions(+), 305 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index b3a76738f6..4f69037b26 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -14,13 +14,13 @@ pub struct Command } // Aggregator struct to hold commands -// #[ derive( Debug, PartialEq, former::Former ) ] +#[ derive( Debug, PartialEq, former::Former ) ] // #[ debug ] -#[ derive( Debug, PartialEq ) ] +// #[ derive( Debug, PartialEq ) ] pub struct Aggregator { - // #[ subform ] - // #[ setter( false ) ] + #[ subform ] + #[ setter( false ) ] command : HashMap< String, Command >, } @@ -31,7 +31,7 @@ where { #[ inline( always ) ] - pub fn command2( self, name : &str ) -> CommandAsSubformer< Self, impl CommandAsSubformerEnd< Self > > + pub fn command( self, name : &str ) -> CommandAsSubformer< Self, impl CommandAsSubformerEnd< Self > > { self._command_add_subformer::< CommandFormer< _ >, _, >() .name( name ) @@ -51,276 +51,276 @@ impl former::ValToElement< HashMap< String, Command > > for Command // == begin of generated - #[automatically_derived] impl < > Aggregator < > where - { - #[doc = r""] - #[doc = - r" Make former, variation of builder pattern to form structure defining values of fields step by step."] - #[doc = r""] #[inline(always)] pub fn former() -> AggregatorFormer < - AggregatorFormerDefinition < (), Aggregator < > , former :: - ReturnPreformed > > - { - AggregatorFormer :: < AggregatorFormerDefinition < (), Aggregator < > - , former :: ReturnPreformed > > :: - new_coercing(former :: ReturnPreformed) - } - } impl < Definition > former :: EntityToFormer < Definition > for Aggregator < - > where Definition : former :: FormerDefinition < Storage = - AggregatorFormerStorage < > > , - { type Former = AggregatorFormer < Definition > ; } impl < > former :: - EntityToStorage for Aggregator < > where - { type Storage = AggregatorFormerStorage < > ; } impl < __Context, __Formed, - __End > former :: EntityToDefinition < __Context, __Formed, __End > for - Aggregator < > where __End : former :: FormingEnd < - AggregatorFormerDefinitionTypes < __Context, __Formed > > , - { - type Definition = AggregatorFormerDefinition < __Context, __Formed, __End - > ; - } #[derive(Debug)] pub struct AggregatorFormerDefinitionTypes < __Context = - (), __Formed = Aggregator < > , > where - { - _phantom : core :: marker :: PhantomData < - (* const __Context, * const __Formed) > , - } impl < __Context, __Formed, > :: core :: default :: Default for - AggregatorFormerDefinitionTypes < __Context, __Formed, > where - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } impl < __Context, __Formed, > former :: FormerDefinitionTypes for - AggregatorFormerDefinitionTypes < __Context, __Formed, > where - { - type Storage = AggregatorFormerStorage < > ; type Formed = __Formed; type - Context = __Context; - } #[derive(Debug)] pub struct AggregatorFormerDefinition < __Context = (), - __Formed = Aggregator < > , __End = former :: ReturnPreformed, > where - { - _phantom : core :: marker :: PhantomData < - (* const __Context, * const __Formed, * const __End) > , - } impl < __Context, __Formed, __End, > :: core :: default :: Default for - AggregatorFormerDefinition < __Context, __Formed, __End, > where - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } impl < __Context, __Formed, __End, > former :: FormerDefinition for - AggregatorFormerDefinition < __Context, __Formed, __End, > where __End : - former :: FormingEnd < AggregatorFormerDefinitionTypes < __Context, __Formed, - > > , - { - type Types = AggregatorFormerDefinitionTypes < __Context, __Formed, > ; - type End = __End; type Storage = AggregatorFormerStorage < > ; type Formed - = __Formed; type Context = __Context; - } #[doc = "Container of a corresponding former."] - #[allow(explicit_outlives_requirements)] pub struct AggregatorFormerStorage < - > where - { - #[doc = r" A field"] pub command : :: core :: option :: Option < HashMap < - String, Command > > , - } impl < > :: core :: default :: Default for AggregatorFormerStorage < > where - { - #[inline(always)] fn default() -> Self - { Self { command : :: core :: option :: Option :: None, } } - } impl < > former :: Storage for AggregatorFormerStorage < > where - { type Formed = Aggregator < > ; } impl < > former :: StoragePreform for - AggregatorFormerStorage < > where - { - type Preformed = Aggregator < > ; fn preform(mut self) -> Self :: - Preformed - { - let command = if self.command.is_some() - { self.command.take().unwrap() } else - { - { - trait MaybeDefault < T > - { - fn maybe_default(self : & Self) -> T - { panic! ("Field 'command' isn't initialized") } - } impl < T > MaybeDefault < T > for & :: core :: marker :: - PhantomData < T > {} impl < T > MaybeDefault < T > for :: core - :: marker :: PhantomData < T > where T : :: core :: default :: - Default, - { fn maybe_default(self : & Self) -> T { T :: default() } } - (& :: core :: marker :: PhantomData :: < HashMap < String, - Command > >).maybe_default() - } - }; let result = Aggregator :: < > { command, }; return result; - } - } - #[doc = - " Object to form [Aggregator]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] - pub struct AggregatorFormer < Definition = AggregatorFormerDefinition < (), - Aggregator < > , former :: ReturnPreformed > , > where Definition : former :: - FormerDefinition < Storage = AggregatorFormerStorage < > > , Definition :: - Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < - > > , - { - storage : Definition :: Storage, context : core :: option :: Option < - Definition :: Context > , on_end : core :: option :: Option < Definition - :: End > , - } #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, - > where Definition : former :: FormerDefinition < Storage = - AggregatorFormerStorage < > > , Definition :: Types : former :: - FormerDefinitionTypes < Storage = AggregatorFormerStorage < > > , - { - #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> - Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > - (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , - { Self :: begin_coercing(None, None, end,) } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn - begin(mut storage : core :: option :: Option < Definition :: Storage > , - context : core :: option :: Option < Definition :: Context > , on_end : < - Definition as former :: FormerDefinition > :: End,) -> Self - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: Some(on_end), - } - } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > - (mut storage : core :: option :: Option < Definition :: Storage > , - context : core :: option :: Option < Definition :: Context > , on_end : - IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < - Definition as former :: FormerDefinition > :: End > , - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: - Some(:: core :: convert :: Into :: into(on_end)), - } - } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types - as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { - let on_end = self.on_end.take().unwrap(); let context = - self.context.take(); former :: FormingEnd :: < Definition :: Types > - :: call(& on_end, self.storage, context) - } #[doc = "Setter for the 'command' field."] - - - #[inline] pub fn command < - Src > (mut self, src : Src) -> Self where Src : :: core :: convert :: Into - < HashMap < String, Command > > , - { - debug_assert! (self.storage.command.is_none()); self.storage.command = - :: core :: option :: Option :: - Some(:: core :: convert :: Into :: into(src)); self - } - - #[doc = r" Custom setter which produce container element subformer."] - #[inline(always)] pub fn _command_add_subformer < Former2, Definition2 > - (self) -> Former2 where Definition2 : former :: FormerDefinition < End = - AggregatorFormerAddCommandEnd < Definition > , Storage = < < HashMap < - String, Command > as former :: Container > :: Val as former :: - EntityToStorage > :: Storage, Formed = Self, Context = Self, > , - Definition2 :: Types : former :: FormerDefinitionTypes < Storage = < < - HashMap < String, Command > as former :: Container > :: Val as former :: - EntityToStorage > :: Storage, Formed = Self, Context = Self, > , Former2 : - former :: FormerBegin < Definition2 > , - { - Former2 :: - former_begin(None, Some(self), AggregatorFormerAddCommandEnd :: - default()) - } - } impl < Definition, > AggregatorFormer < Definition, > where Definition : - former :: FormerDefinition < Storage = AggregatorFormerStorage < > , Formed = - Aggregator < > > , Definition :: Types : former :: FormerDefinitionTypes < - Storage = AggregatorFormerStorage < > , Formed = Aggregator < > > , Definition - : former :: FormerDefinition < Storage = AggregatorFormerStorage < > > , - Definition :: Types : former :: FormerDefinitionTypes < Storage = - AggregatorFormerStorage < > > , - { - pub fn preform(self) -> < Definition :: Types as former :: - FormerDefinitionTypes > :: Formed - { former :: StoragePreform :: preform(self.storage) } - } #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, - > where Definition : former :: FormerDefinition < Storage = - AggregatorFormerStorage < > , Formed = Aggregator < > , > , Definition :: - Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < - > , Formed = Aggregator < > , > , - { - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] - #[doc = - r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = - r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { let result = self.form(); return result; } - } impl < Definition > former :: FormerBegin < Definition > for - AggregatorFormer < Definition, > where Definition : former :: FormerDefinition - < Storage = AggregatorFormerStorage < > > , - { - #[inline(always)] fn - former_begin(storage : core :: option :: Option < Definition :: Storage > - , context : core :: option :: Option < Definition :: Context > , on_end : - Definition :: End,) -> Self - { - debug_assert! (storage.is_none()); Self :: - begin(None, context, on_end) - } - } - #[doc = - r" Use as subformer of a field during process of forming of super structure."] - pub type AggregatorAsSubformer < __Superformer, __End > = AggregatorFormer < - AggregatorFormerDefinition < __Superformer, __Superformer, __End, > , > ; - #[doc = - "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] - pub trait AggregatorAsSubformerEnd < SuperFormer > where Self : former :: - FormingEnd < AggregatorFormerDefinitionTypes < SuperFormer, SuperFormer > , > - , {} impl < SuperFormer, __T > AggregatorAsSubformerEnd < SuperFormer > for - __T where Self : former :: FormingEnd < AggregatorFormerDefinitionTypes < - SuperFormer, SuperFormer > , > , {} - #[doc = r" Handles the completion of an element of subformer's container."] - pub struct AggregatorFormerAddCommandEnd < Definition > - { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < - Definition > Default for AggregatorFormerAddCommandEnd < Definition > - { - #[inline(always)] fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } impl < Types2, Definition > former :: FormingEnd < Types2, > for - AggregatorFormerAddCommandEnd < Definition > where Definition : former :: - FormerDefinition < Storage = < Aggregator < > as former :: EntityToStorage > - :: Storage, > , Types2 : former :: FormerDefinitionTypes < Storage = < < - HashMap < String, Command > as former :: Container > :: Val as former :: - EntityToStorage > :: Storage, Formed = AggregatorFormer < Definition, > , - Context = AggregatorFormer < Definition, > , > , - { - #[inline(always)] fn - call(& self, substorage : Types2 :: Storage, super_former : core :: option - :: Option < Types2 :: Context > ,) -> Types2 :: Formed - { - let mut super_former = super_former.unwrap(); if - super_former.storage.command.is_none() - { super_former.storage.command = Some(Default :: default()); } if let - Some(ref mut field) = super_former.storage.command - { - former :: ContainerAdd :: - add(field, < < HashMap < String, Command > as former :: Container - > :: Val as former :: ValToElement < HashMap < String, Command > > - > :: - val_to_element(former :: StoragePreform :: preform(substorage)),); - } super_former - } - } +// #[automatically_derived] impl < > Aggregator < > where +// { +// #[doc = r""] +// #[doc = +// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] +// #[doc = r""] #[inline(always)] pub fn former() -> AggregatorFormer < +// AggregatorFormerDefinition < (), Aggregator < > , former :: +// ReturnPreformed > > +// { +// AggregatorFormer :: < AggregatorFormerDefinition < (), Aggregator < > +// , former :: ReturnPreformed > > :: +// new_coercing(former :: ReturnPreformed) +// } +// } impl < Definition > former :: EntityToFormer < Definition > for Aggregator < +// > where Definition : former :: FormerDefinition < Storage = +// AggregatorFormerStorage < > > , +// { type Former = AggregatorFormer < Definition > ; } impl < > former :: +// EntityToStorage for Aggregator < > where +// { type Storage = AggregatorFormerStorage < > ; } impl < __Context, __Formed, +// __End > former :: EntityToDefinition < __Context, __Formed, __End > for +// Aggregator < > where __End : former :: FormingEnd < +// AggregatorFormerDefinitionTypes < __Context, __Formed > > , +// { +// type Definition = AggregatorFormerDefinition < __Context, __Formed, __End +// > ; +// } #[derive(Debug)] pub struct AggregatorFormerDefinitionTypes < __Context = +// (), __Formed = Aggregator < > , > where +// { +// _phantom : core :: marker :: PhantomData < +// (* const __Context, * const __Formed) > , +// } impl < __Context, __Formed, > :: core :: default :: Default for +// AggregatorFormerDefinitionTypes < __Context, __Formed, > where +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < __Context, __Formed, > former :: FormerDefinitionTypes for +// AggregatorFormerDefinitionTypes < __Context, __Formed, > where +// { +// type Storage = AggregatorFormerStorage < > ; type Formed = __Formed; type +// Context = __Context; +// } #[derive(Debug)] pub struct AggregatorFormerDefinition < __Context = (), +// __Formed = Aggregator < > , __End = former :: ReturnPreformed, > where +// { +// _phantom : core :: marker :: PhantomData < +// (* const __Context, * const __Formed, * const __End) > , +// } impl < __Context, __Formed, __End, > :: core :: default :: Default for +// AggregatorFormerDefinition < __Context, __Formed, __End, > where +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < __Context, __Formed, __End, > former :: FormerDefinition for +// AggregatorFormerDefinition < __Context, __Formed, __End, > where __End : +// former :: FormingEnd < AggregatorFormerDefinitionTypes < __Context, __Formed, +// > > , +// { +// type Types = AggregatorFormerDefinitionTypes < __Context, __Formed, > ; +// type End = __End; type Storage = AggregatorFormerStorage < > ; type Formed +// = __Formed; type Context = __Context; +// } #[doc = "Container of a corresponding former."] +// #[allow(explicit_outlives_requirements)] pub struct AggregatorFormerStorage < +// > where +// { +// #[doc = r" A field"] pub command : :: core :: option :: Option < HashMap < +// String, Command > > , +// } impl < > :: core :: default :: Default for AggregatorFormerStorage < > where +// { +// #[inline(always)] fn default() -> Self +// { Self { command : :: core :: option :: Option :: None, } } +// } impl < > former :: Storage for AggregatorFormerStorage < > where +// { type Formed = Aggregator < > ; } impl < > former :: StoragePreform for +// AggregatorFormerStorage < > where +// { +// type Preformed = Aggregator < > ; fn preform(mut self) -> Self :: +// Preformed +// { +// let command = if self.command.is_some() +// { self.command.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'command' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < HashMap < String, +// Command > >).maybe_default() +// } +// }; let result = Aggregator :: < > { command, }; return result; +// } +// } +// #[doc = +// " Object to form [Aggregator]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +// pub struct AggregatorFormer < Definition = AggregatorFormerDefinition < (), +// Aggregator < > , former :: ReturnPreformed > , > where Definition : former :: +// FormerDefinition < Storage = AggregatorFormerStorage < > > , Definition :: +// Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < +// > > , +// { +// storage : Definition :: Storage, context : core :: option :: Option < +// Definition :: Context > , on_end : core :: option :: Option < Definition +// :: End > , +// } #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, +// > where Definition : former :: FormerDefinition < Storage = +// AggregatorFormerStorage < > > , Definition :: Types : former :: +// FormerDefinitionTypes < Storage = AggregatorFormerStorage < > > , +// { +// #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> +// Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > +// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , +// { Self :: begin_coercing(None, None, end,) } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn +// begin(mut storage : core :: option :: Option < Definition :: Storage > , +// context : core :: option :: Option < Definition :: Context > , on_end : < +// Definition as former :: FormerDefinition > :: End,) -> Self +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: Some(on_end), +// } +// } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > +// (mut storage : core :: option :: Option < Definition :: Storage > , +// context : core :: option :: Option < Definition :: Context > , on_end : +// IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < +// Definition as former :: FormerDefinition > :: End > , +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: +// Some(:: core :: convert :: Into :: into(on_end)), +// } +// } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types +// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { +// let on_end = self.on_end.take().unwrap(); let context = +// self.context.take(); former :: FormingEnd :: < Definition :: Types > +// :: call(& on_end, self.storage, context) +// } #[doc = "Setter for the 'command' field."] +// +// +// #[inline] pub fn command < +// Src > (mut self, src : Src) -> Self where Src : :: core :: convert :: Into +// < HashMap < String, Command > > , +// { +// debug_assert! (self.storage.command.is_none()); self.storage.command = +// :: core :: option :: Option :: +// Some(:: core :: convert :: Into :: into(src)); self +// } +// +// #[doc = r" Custom setter which produce container element subformer."] +// #[inline(always)] pub fn _command_add_subformer < Former2, Definition2 > +// (self) -> Former2 where Definition2 : former :: FormerDefinition < End = +// AggregatorFormerAddCommandEnd < Definition > , Storage = < < HashMap < +// String, Command > as former :: Container > :: Val as former :: +// EntityToStorage > :: Storage, Formed = Self, Context = Self, > , +// Definition2 :: Types : former :: FormerDefinitionTypes < Storage = < < +// HashMap < String, Command > as former :: Container > :: Val as former :: +// EntityToStorage > :: Storage, Formed = Self, Context = Self, > , Former2 : +// former :: FormerBegin < Definition2 > , +// { +// Former2 :: +// former_begin(None, Some(self), AggregatorFormerAddCommandEnd :: +// default()) +// } +// } impl < Definition, > AggregatorFormer < Definition, > where Definition : +// former :: FormerDefinition < Storage = AggregatorFormerStorage < > , Formed = +// Aggregator < > > , Definition :: Types : former :: FormerDefinitionTypes < +// Storage = AggregatorFormerStorage < > , Formed = Aggregator < > > , Definition +// : former :: FormerDefinition < Storage = AggregatorFormerStorage < > > , +// Definition :: Types : former :: FormerDefinitionTypes < Storage = +// AggregatorFormerStorage < > > , +// { +// pub fn preform(self) -> < Definition :: Types as former :: +// FormerDefinitionTypes > :: Formed +// { former :: StoragePreform :: preform(self.storage) } +// } #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, +// > where Definition : former :: FormerDefinition < Storage = +// AggregatorFormerStorage < > , Formed = Aggregator < > , > , Definition :: +// Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < +// > , Formed = Aggregator < > , > , +// { +// #[doc = r""] +// #[doc = r" Finish setting options and call perform on formed entity."] +// #[doc = r""] +// #[doc = +// r" If `perform` defined then associated method is called and its result returned instead of entity."] +// #[doc = +// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] +// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { let result = self.form(); return result; } +// } impl < Definition > former :: FormerBegin < Definition > for +// AggregatorFormer < Definition, > where Definition : former :: FormerDefinition +// < Storage = AggregatorFormerStorage < > > , +// { +// #[inline(always)] fn +// former_begin(storage : core :: option :: Option < Definition :: Storage > +// , context : core :: option :: Option < Definition :: Context > , on_end : +// Definition :: End,) -> Self +// { +// debug_assert! (storage.is_none()); Self :: +// begin(None, context, on_end) +// } +// } +// #[doc = +// r" Use as subformer of a field during process of forming of super structure."] +// pub type AggregatorAsSubformer < __Superformer, __End > = AggregatorFormer < +// AggregatorFormerDefinition < __Superformer, __Superformer, __End, > , > ; +// #[doc = +// "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] +// pub trait AggregatorAsSubformerEnd < SuperFormer > where Self : former :: +// FormingEnd < AggregatorFormerDefinitionTypes < SuperFormer, SuperFormer > , > +// , {} impl < SuperFormer, __T > AggregatorAsSubformerEnd < SuperFormer > for +// __T where Self : former :: FormingEnd < AggregatorFormerDefinitionTypes < +// SuperFormer, SuperFormer > , > , {} +// #[doc = r" Handles the completion of an element of subformer's container."] +// pub struct AggregatorFormerAddCommandEnd < Definition > +// { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < +// Definition > Default for AggregatorFormerAddCommandEnd < Definition > +// { +// #[inline(always)] fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < Types2, Definition > former :: FormingEnd < Types2, > for +// AggregatorFormerAddCommandEnd < Definition > where Definition : former :: +// FormerDefinition < Storage = < Aggregator < > as former :: EntityToStorage > +// :: Storage, > , Types2 : former :: FormerDefinitionTypes < Storage = < < +// HashMap < String, Command > as former :: Container > :: Val as former :: +// EntityToStorage > :: Storage, Formed = AggregatorFormer < Definition, > , +// Context = AggregatorFormer < Definition, > , > , +// { +// #[inline(always)] fn +// call(& self, substorage : Types2 :: Storage, super_former : core :: option +// :: Option < Types2 :: Context > ,) -> Types2 :: Formed +// { +// let mut super_former = super_former.unwrap(); if +// super_former.storage.command.is_none() +// { super_former.storage.command = Some(Default :: default()); } if let +// Some(ref mut field) = super_former.storage.command +// { +// former :: ContainerAdd :: +// add(field, < < HashMap < String, Command > as former :: Container +// > :: Val as former :: ValToElement < HashMap < String, Command > > +// > :: +// val_to_element(former :: StoragePreform :: preform(substorage)),); +// } super_former +// } +// } // == end of generated @@ -329,10 +329,10 @@ fn basic() { let ca = Aggregator::former() - .command2( "echo" ) + .command( "echo" ) .description( "prints all subjects and properties" ) // sets additional properties using custom subformer .end() - .command2( "exit" ) + .command( "exit" ) .description( "just exit" ) // Sets additional properties using using custom subformer .end() .form(); diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index ac1f26ed6d..233ed148e2 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -620,30 +620,51 @@ fn field_setter_map ( field : &FormerField< '_ >, stru : &syn::Ident, - // as_subformer : &syn::Ident, - // as_subformer_end : &syn::Ident, ) -> Result< TokenStream > { let ident = &field.ident; - if let Some( setter_attr ) = &field.attrs.setter - { - if !setter_attr.condition.value() - { - return Ok( qt!{ } ); - } - } + // if let Some( setter_attr ) = &field.attrs.setter + // { + // if !setter_attr.condition.value() + // { + // return Ok( qt!{ } ); + // } + // } + // xxx : write test for interoperability of 3 attributes let non_optional_ty = &field.non_optional_ty; // Either subformer or ordinary setter. let r = if let Some( _container_ty ) = &field.attrs.container { - container_setter( field, stru ) + field_container_setter( field, stru ) } else { - field_setter( ident, ident, non_optional_ty ) + let setter_enabled = if let Some( setter_attr ) = &field.attrs.setter + { + if !setter_attr.condition.value() + { + false + } + else + { + true + } + } + else + { + true + }; + if setter_enabled + { + field_setter( ident, ident, non_optional_ty ) + } + else + { + qt!{ } + } }; let r = if let Some( alias_attr ) = &field.attrs.alias @@ -662,7 +683,7 @@ fn field_setter_map let r = if field.attrs.subform.is_some() { - let subformer = field_subformer_map( field, stru )?; + let subformer = field_subform_add_setter_map( field, stru )?; qt! { #r @@ -679,9 +700,8 @@ fn field_setter_map } /// zzz : write documentation - #[ inline ] -fn field_subformer_map +fn field_subform_add_setter_map ( field : &FormerField< '_ >, stru : &syn::Ident, @@ -716,7 +736,7 @@ fn field_subformer_map let former_add_end = syn::Ident::new( &former_add_end_name, field_ident.span() ); // example : `_children_former` - let element_subformer_name = format!( "_{}_add_subformer", field_ident ); + let element_subformer_name = format!( "_{}_add_subformer", field_ident ); // xxx : rename let element_subformer = syn::Ident::new( &element_subformer_name, field_ident.span() ); let r = qt! @@ -816,7 +836,7 @@ fn field_subformer_map /// zzz : update example #[ inline ] -fn container_setter +fn field_container_setter ( field : &FormerField< '_ >, stru : &syn::Ident, @@ -1053,18 +1073,14 @@ fn field_setter /// ``` #[ inline ] -fn field_former_assign_map +fn field_former_assign_end_map ( field : &FormerField< '_ >, stru : &syn::Ident, former : &syn::Ident, - _former_storage : &syn::Ident, former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - _struct_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - _struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - _struct_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, ) -> Result< TokenStream > @@ -1177,7 +1193,7 @@ Callback replace content of container assigning new content from subformer's sto /// zzz : write documentation #[ inline ] -fn field_former_add_map +fn field_former_add_end_map ( field : &FormerField< '_ >, stru : &syn::Ident, @@ -1572,20 +1588,16 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field_form_map( former_field ), field_name_map( former_field ), field_setter_map( former_field, &stru ), - field_former_assign_map + field_former_assign_end_map ( former_field, &stru, &former, - &former_storage, &former_generics_impl, &former_generics_ty, &former_generics_where, - &struct_generics_impl, - &struct_generics_ty, - &struct_generics_where, ), - field_former_add_map + field_former_add_end_map ( former_field, &stru, From 05bdcd1604f3b2b5998053c093a0e3195c64803f Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 10:46:02 +0300 Subject: [PATCH 369/533] former : experimenting --- module/core/former/examples/former_custom_subformer.rs | 2 +- .../former/tests/inc/former_tests/subformer_subform.rs | 4 ++-- .../former_tests/subformer_subform_and_container.rs | 2 +- .../subformer_subform_and_container_parametrized.rs | 2 +- .../inc/former_tests/subformer_subform_hashmap.rs | 4 ++-- .../tests/inc/former_tests/subformer_subform_manual.rs | 10 +++++----- .../tests/inc/former_tests/subformer_subform_named.rs | 4 ++-- .../inc/former_tests/subformer_subform_named_manual.rs | 6 +++--- module/core/former_meta/src/derive/former.rs | 4 ++-- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/module/core/former/examples/former_custom_subformer.rs b/module/core/former/examples/former_custom_subformer.rs index 0e1967fdd7..e80dbbdeaf 100644 --- a/module/core/former/examples/former_custom_subformer.rs +++ b/module/core/former/examples/former_custom_subformer.rs @@ -36,7 +36,7 @@ fn main() #[ inline( always ) ] pub fn command( self, name : &str ) -> CommandAsSubformer< Self, impl CommandAsSubformerEnd< Self > > { - self._command_add_subformer::< CommandFormer< _ >, _, >() + self._command_add::< CommandFormer< _ >, _, >() .name( name ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform.rs b/module/core/former/tests/inc/former_tests/subformer_subform.rs index 89b54bc044..ebacea4844 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform.rs @@ -29,7 +29,7 @@ where #[ inline( always ) ] pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { - self._children_add_subformer::< ChildFormer< _ >, _, >() + self._children_add::< ChildFormer< _ >, _, >() .name( name ) } @@ -37,7 +37,7 @@ where pub fn _child( self ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { - self._children_add_subformer + self._children_add ::< < Child as former::EntityToFormer< _ > >::Former, _, >() } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs index bdcf997739..86216319d4 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs @@ -33,7 +33,7 @@ where pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { - self._children_add_subformer + self._children_add ::< ChildFormer< _ >, _, >() .name( name ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs index 2cd5c5f09c..f2bc008b94 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs @@ -36,7 +36,7 @@ pub struct Child< 'child, T > // pub fn child( self, name : &str ) -> // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > // { -// self._children_add_subformer +// self._children_add // ::< ChildFormer< _ >, _, >() // .name( name ) // } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index 4f69037b26..a3ea713767 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -33,7 +33,7 @@ where #[ inline( always ) ] pub fn command( self, name : &str ) -> CommandAsSubformer< Self, impl CommandAsSubformerEnd< Self > > { - self._command_add_subformer::< CommandFormer< _ >, _, >() + self._command_add::< CommandFormer< _ >, _, >() .name( name ) } @@ -224,7 +224,7 @@ impl former::ValToElement< HashMap< String, Command > > for Command // } // // #[doc = r" Custom setter which produce container element subformer."] -// #[inline(always)] pub fn _command_add_subformer < Former2, Definition2 > +// #[inline(always)] pub fn _command_add < Former2, Definition2 > // (self) -> Former2 where Definition2 : former :: FormerDefinition < End = // AggregatorFormerAddCommandEnd < Definition > , Storage = < < HashMap < // String, Command > as former :: Container > :: Val as former :: diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 97d030cdf7..0ec1324a7d 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -30,7 +30,7 @@ where { #[ inline( always ) ] - pub fn _children_add_subformer_with_closure< Former2, Definition2, Types2 >( self ) -> + pub fn _children_add_with_closure< Former2, Definition2, Types2 >( self ) -> Former2 where Types2 : former::FormerDefinitionTypes @@ -73,7 +73,7 @@ where pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { - self._children_add_subformer + self._children_add ::< ChildFormer< _ >, _, >() .name( name ) } @@ -82,7 +82,7 @@ where // pub fn _child( self ) -> // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > // { - // self._children_add_subformer + // self._children_add // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() // } @@ -97,7 +97,7 @@ where > >::Former { - self._children_add_subformer + self._children_add ::< < < Vec< Child > as former::Container >::Element as former::EntityToFormer< _ > >::Former, _, >() } @@ -112,7 +112,7 @@ where { #[ inline( always ) ] - pub fn _children_add_subformer< Former2, Definition2 >( self ) -> + pub fn _children_add< Former2, Definition2 >( self ) -> Former2 where Definition2 : former::FormerDefinition diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs index 101fdb79bf..f422c0af6a 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs @@ -32,7 +32,7 @@ where pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { - self._children_add_subformer + self._children_add ::< ChildFormer< _ >, _, >() .name( name ) } @@ -41,7 +41,7 @@ where // pub fn _child( self ) -> // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > // { - // self._children_add_subformer + // self._children_add // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() // } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs index f5103ab80d..fe327af72f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs @@ -41,7 +41,7 @@ where pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { - self._children_add_subformer + self._children_add ::< ChildFormer< _ >, _, >() .name( name ) } @@ -50,7 +50,7 @@ where // pub fn _child( self ) -> // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > // { - // self._children_add_subformer + // self._children_add // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() // } @@ -65,7 +65,7 @@ where > >::Former { - self._children_add_subformer + self._children_add ::< < < Vec< Child > as former::Container >::Element as former::EntityToFormer< _ > >::Former, _, >() } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 233ed148e2..870c39929a 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -736,7 +736,7 @@ fn field_subform_add_setter_map let former_add_end = syn::Ident::new( &former_add_end_name, field_ident.span() ); // example : `_children_former` - let element_subformer_name = format!( "_{}_add_subformer", field_ident ); // xxx : rename + let element_subformer_name = format!( "_{}_add", field_ident ); // xxx : rename let element_subformer = syn::Ident::new( &element_subformer_name, field_ident.span() ); let r = qt! @@ -795,7 +795,7 @@ fn field_subform_add_setter_map // pub fn child( self ) -> // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > // { - // self._children_add_subformer + // self._children_add // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() // } From 92b0412b244a66b23f184d4d14b38c8aa6a94ad0 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 10:48:25 +0300 Subject: [PATCH 370/533] former : experimenting --- .../former_tests/subformer_subform_hashmap.rs | 275 +----------------- 1 file changed, 3 insertions(+), 272 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index a3ea713767..2c433a1242 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -51,284 +51,13 @@ impl former::ValToElement< HashMap< String, Command > > for Command // == begin of generated -// #[automatically_derived] impl < > Aggregator < > where -// { -// #[doc = r""] -// #[doc = -// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] -// #[doc = r""] #[inline(always)] pub fn former() -> AggregatorFormer < -// AggregatorFormerDefinition < (), Aggregator < > , former :: -// ReturnPreformed > > -// { -// AggregatorFormer :: < AggregatorFormerDefinition < (), Aggregator < > -// , former :: ReturnPreformed > > :: -// new_coercing(former :: ReturnPreformed) -// } -// } impl < Definition > former :: EntityToFormer < Definition > for Aggregator < -// > where Definition : former :: FormerDefinition < Storage = -// AggregatorFormerStorage < > > , -// { type Former = AggregatorFormer < Definition > ; } impl < > former :: -// EntityToStorage for Aggregator < > where -// { type Storage = AggregatorFormerStorage < > ; } impl < __Context, __Formed, -// __End > former :: EntityToDefinition < __Context, __Formed, __End > for -// Aggregator < > where __End : former :: FormingEnd < -// AggregatorFormerDefinitionTypes < __Context, __Formed > > , -// { -// type Definition = AggregatorFormerDefinition < __Context, __Formed, __End -// > ; -// } #[derive(Debug)] pub struct AggregatorFormerDefinitionTypes < __Context = -// (), __Formed = Aggregator < > , > where -// { -// _phantom : core :: marker :: PhantomData < -// (* const __Context, * const __Formed) > , -// } impl < __Context, __Formed, > :: core :: default :: Default for -// AggregatorFormerDefinitionTypes < __Context, __Formed, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, > former :: FormerDefinitionTypes for -// AggregatorFormerDefinitionTypes < __Context, __Formed, > where -// { -// type Storage = AggregatorFormerStorage < > ; type Formed = __Formed; type -// Context = __Context; -// } #[derive(Debug)] pub struct AggregatorFormerDefinition < __Context = (), -// __Formed = Aggregator < > , __End = former :: ReturnPreformed, > where -// { -// _phantom : core :: marker :: PhantomData < -// (* const __Context, * const __Formed, * const __End) > , -// } impl < __Context, __Formed, __End, > :: core :: default :: Default for -// AggregatorFormerDefinition < __Context, __Formed, __End, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, __End, > former :: FormerDefinition for -// AggregatorFormerDefinition < __Context, __Formed, __End, > where __End : -// former :: FormingEnd < AggregatorFormerDefinitionTypes < __Context, __Formed, -// > > , -// { -// type Types = AggregatorFormerDefinitionTypes < __Context, __Formed, > ; -// type End = __End; type Storage = AggregatorFormerStorage < > ; type Formed -// = __Formed; type Context = __Context; -// } #[doc = "Container of a corresponding former."] -// #[allow(explicit_outlives_requirements)] pub struct AggregatorFormerStorage < -// > where -// { -// #[doc = r" A field"] pub command : :: core :: option :: Option < HashMap < -// String, Command > > , -// } impl < > :: core :: default :: Default for AggregatorFormerStorage < > where -// { -// #[inline(always)] fn default() -> Self -// { Self { command : :: core :: option :: Option :: None, } } -// } impl < > former :: Storage for AggregatorFormerStorage < > where -// { type Formed = Aggregator < > ; } impl < > former :: StoragePreform for -// AggregatorFormerStorage < > where -// { -// type Preformed = Aggregator < > ; fn preform(mut self) -> Self :: -// Preformed -// { -// let command = if self.command.is_some() -// { self.command.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'command' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < HashMap < String, -// Command > >).maybe_default() -// } -// }; let result = Aggregator :: < > { command, }; return result; -// } -// } -// #[doc = -// " Object to form [Aggregator]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -// pub struct AggregatorFormer < Definition = AggregatorFormerDefinition < (), -// Aggregator < > , former :: ReturnPreformed > , > where Definition : former :: -// FormerDefinition < Storage = AggregatorFormerStorage < > > , Definition :: -// Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < -// > > , -// { -// storage : Definition :: Storage, context : core :: option :: Option < -// Definition :: Context > , on_end : core :: option :: Option < Definition -// :: End > , -// } #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, -// > where Definition : former :: FormerDefinition < Storage = -// AggregatorFormerStorage < > > , Definition :: Types : former :: -// FormerDefinitionTypes < Storage = AggregatorFormerStorage < > > , -// { -// #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> -// Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > -// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , -// { Self :: begin_coercing(None, None, end,) } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn -// begin(mut storage : core :: option :: Option < Definition :: Storage > , -// context : core :: option :: Option < Definition :: Context > , on_end : < -// Definition as former :: FormerDefinition > :: End,) -> Self -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: Some(on_end), -// } -// } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > -// (mut storage : core :: option :: Option < Definition :: Storage > , -// context : core :: option :: Option < Definition :: Context > , on_end : -// IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < -// Definition as former :: FormerDefinition > :: End > , -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: -// Some(:: core :: convert :: Into :: into(on_end)), -// } -// } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types -// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { -// let on_end = self.on_end.take().unwrap(); let context = -// self.context.take(); former :: FormingEnd :: < Definition :: Types > -// :: call(& on_end, self.storage, context) -// } #[doc = "Setter for the 'command' field."] -// -// -// #[inline] pub fn command < -// Src > (mut self, src : Src) -> Self where Src : :: core :: convert :: Into -// < HashMap < String, Command > > , -// { -// debug_assert! (self.storage.command.is_none()); self.storage.command = -// :: core :: option :: Option :: -// Some(:: core :: convert :: Into :: into(src)); self -// } -// -// #[doc = r" Custom setter which produce container element subformer."] -// #[inline(always)] pub fn _command_add < Former2, Definition2 > -// (self) -> Former2 where Definition2 : former :: FormerDefinition < End = -// AggregatorFormerAddCommandEnd < Definition > , Storage = < < HashMap < -// String, Command > as former :: Container > :: Val as former :: -// EntityToStorage > :: Storage, Formed = Self, Context = Self, > , -// Definition2 :: Types : former :: FormerDefinitionTypes < Storage = < < -// HashMap < String, Command > as former :: Container > :: Val as former :: -// EntityToStorage > :: Storage, Formed = Self, Context = Self, > , Former2 : -// former :: FormerBegin < Definition2 > , -// { -// Former2 :: -// former_begin(None, Some(self), AggregatorFormerAddCommandEnd :: -// default()) -// } -// } impl < Definition, > AggregatorFormer < Definition, > where Definition : -// former :: FormerDefinition < Storage = AggregatorFormerStorage < > , Formed = -// Aggregator < > > , Definition :: Types : former :: FormerDefinitionTypes < -// Storage = AggregatorFormerStorage < > , Formed = Aggregator < > > , Definition -// : former :: FormerDefinition < Storage = AggregatorFormerStorage < > > , -// Definition :: Types : former :: FormerDefinitionTypes < Storage = -// AggregatorFormerStorage < > > , -// { -// pub fn preform(self) -> < Definition :: Types as former :: -// FormerDefinitionTypes > :: Formed -// { former :: StoragePreform :: preform(self.storage) } -// } #[automatically_derived] impl < Definition, > AggregatorFormer < Definition, -// > where Definition : former :: FormerDefinition < Storage = -// AggregatorFormerStorage < > , Formed = Aggregator < > , > , Definition :: -// Types : former :: FormerDefinitionTypes < Storage = AggregatorFormerStorage < -// > , Formed = Aggregator < > , > , -// { -// #[doc = r""] -// #[doc = r" Finish setting options and call perform on formed entity."] -// #[doc = r""] -// #[doc = -// r" If `perform` defined then associated method is called and its result returned instead of entity."] -// #[doc = -// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] -// #[doc = r""] #[inline(always)] pub fn perform(self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { let result = self.form(); return result; } -// } impl < Definition > former :: FormerBegin < Definition > for -// AggregatorFormer < Definition, > where Definition : former :: FormerDefinition -// < Storage = AggregatorFormerStorage < > > , -// { -// #[inline(always)] fn -// former_begin(storage : core :: option :: Option < Definition :: Storage > -// , context : core :: option :: Option < Definition :: Context > , on_end : -// Definition :: End,) -> Self -// { -// debug_assert! (storage.is_none()); Self :: -// begin(None, context, on_end) -// } -// } -// #[doc = -// r" Use as subformer of a field during process of forming of super structure."] -// pub type AggregatorAsSubformer < __Superformer, __End > = AggregatorFormer < -// AggregatorFormerDefinition < __Superformer, __Superformer, __End, > , > ; -// #[doc = -// "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] -// pub trait AggregatorAsSubformerEnd < SuperFormer > where Self : former :: -// FormingEnd < AggregatorFormerDefinitionTypes < SuperFormer, SuperFormer > , > -// , {} impl < SuperFormer, __T > AggregatorAsSubformerEnd < SuperFormer > for -// __T where Self : former :: FormingEnd < AggregatorFormerDefinitionTypes < -// SuperFormer, SuperFormer > , > , {} -// #[doc = r" Handles the completion of an element of subformer's container."] -// pub struct AggregatorFormerAddCommandEnd < Definition > -// { _phantom : core :: marker :: PhantomData < fn(Definition) > , } impl < -// Definition > Default for AggregatorFormerAddCommandEnd < Definition > -// { -// #[inline(always)] fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < Types2, Definition > former :: FormingEnd < Types2, > for -// AggregatorFormerAddCommandEnd < Definition > where Definition : former :: -// FormerDefinition < Storage = < Aggregator < > as former :: EntityToStorage > -// :: Storage, > , Types2 : former :: FormerDefinitionTypes < Storage = < < -// HashMap < String, Command > as former :: Container > :: Val as former :: -// EntityToStorage > :: Storage, Formed = AggregatorFormer < Definition, > , -// Context = AggregatorFormer < Definition, > , > , -// { -// #[inline(always)] fn -// call(& self, substorage : Types2 :: Storage, super_former : core :: option -// :: Option < Types2 :: Context > ,) -> Types2 :: Formed -// { -// let mut super_former = super_former.unwrap(); if -// super_former.storage.command.is_none() -// { super_former.storage.command = Some(Default :: default()); } if let -// Some(ref mut field) = super_former.storage.command -// { -// former :: ContainerAdd :: -// add(field, < < HashMap < String, Command > as former :: Container -// > :: Val as former :: ValToElement < HashMap < String, Command > > -// > :: -// val_to_element(former :: StoragePreform :: preform(substorage)),); -// } super_former -// } -// } - // == end of generated #[ test ] fn basic() { - let ca = Aggregator::former() + let got = Aggregator::former() .command( "echo" ) .description( "prints all subjects and properties" ) // sets additional properties using custom subformer .end() @@ -337,5 +66,7 @@ fn basic() .end() .form(); + a_id!( got.command.len(), 2 ); + } // xxx \ No newline at end of file From f171301a629443818ff5305d82ee427c0956c1cb Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 12:13:13 +0300 Subject: [PATCH 371/533] former : experimenting --- .../former_tests/subformer_subform_hashmap.rs | 21 +-- .../subformer_subform_hashmap_explicit.rs | 72 +++++++++ module/core/former/tests/inc/mod.rs | 3 + module/core/former_meta/src/derive/former.rs | 140 ++++++++++++------ 4 files changed, 176 insertions(+), 60 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index 2c433a1242..197c69580f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -24,21 +24,6 @@ pub struct Aggregator command : HashMap< String, Command >, } -// Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. -impl< Definition > AggregatorFormer< Definition > -where - Definition : former::FormerDefinition< Storage = < Aggregator as former::EntityToStorage >::Storage >, -{ - - #[ inline( always ) ] - pub fn command( self, name : &str ) -> CommandAsSubformer< Self, impl CommandAsSubformerEnd< Self > > - { - self._command_add::< CommandFormer< _ >, _, >() - .name( name ) - } - -} - impl former::ValToElement< HashMap< String, Command > > for Command { type Element = ( String, Command ); @@ -58,10 +43,12 @@ fn basic() { let got = Aggregator::former() - .command( "echo" ) + .command() + .name( "echo" ) .description( "prints all subjects and properties" ) // sets additional properties using custom subformer .end() - .command( "exit" ) + .command() + .name( "exit" ) .description( "just exit" ) // Sets additional properties using using custom subformer .end() .form(); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs new file mode 100644 index 0000000000..f31fa885c4 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs @@ -0,0 +1,72 @@ +#![ allow( dead_code ) ] + +#[ allow( unused_imports ) ] +use super::*; +#[ allow( unused_imports ) ] +use collection_tools::HashMap; + +// Command struct with Former derived for builder pattern support +#[ derive( Debug, PartialEq, former::Former ) ] +pub struct Command +{ + name : String, + description : String, +} + +// Aggregator struct to hold commands +#[ derive( Debug, PartialEq, former::Former ) ] +// #[ debug ] +// #[ derive( Debug, PartialEq ) ] +pub struct Aggregator +{ + #[ subform( setter = false ) ] + #[ setter( false ) ] + command : HashMap< String, Command >, +} + +// Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. +impl< Definition > AggregatorFormer< Definition > +where + Definition : former::FormerDefinition< Storage = < Aggregator as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn command( self, name : &str ) -> CommandAsSubformer< Self, impl CommandAsSubformerEnd< Self > > + { + self._command_add::< CommandFormer< _ >, _, >() + .name( name ) + } + +} + +impl former::ValToElement< HashMap< String, Command > > for Command +{ + type Element = ( String, Command ); + #[ inline( always ) ] + fn val_to_element( self ) -> Self::Element + { + ( self.name.clone(), self ) + } +} + +// == begin of generated + +// == end of generated + +#[ test ] +fn basic() +{ + + let got = Aggregator::former() + .command( "echo" ) + .description( "prints all subjects and properties" ) // sets additional properties using custom subformer + .end() + .command( "exit" ) + .description( "just exit" ) // Sets additional properties using using custom subformer + .end() + .form(); + + a_id!( got.command.len(), 2 ); + +} +// xxx \ No newline at end of file diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index cc2adf6498..37819397ee 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -76,8 +76,11 @@ mod former_tests mod subformer_subform_named; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_named_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_hashmap; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_hashmap_explicit; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_and_container; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 870c39929a..c1030c8afd 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -21,6 +21,58 @@ struct FormerField< 'a > pub of_type : container_kind::ContainerKind, } +// xxx +impl< 'a > FormerField< 'a > +{ + + /// Get name of setter for subform. + pub fn subform_setter_name( &self ) -> Option< &syn::Ident > + { + + if let Some( ref attr ) = self.attrs.subform + { + if attr.setter + { + if let Some( ref name ) = attr.name + { + return Some( &name ) + } + else + { + return Some( &self.ident ) + } + } + } + + return None; + } + + /// Is trivial setter required. + pub fn trivial_setter_enabled( &self ) -> bool + { + + if let Some( ref attr ) = self.attrs.setter + { + if attr.condition.value() == false + { + return false + } + } + + let subform_name = self.subform_setter_name(); + if let Some( name ) = subform_name + { + if self.ident == name + { + return false; + } + } + + return true; + } + +} + /// /// Attributes of the field. /// @@ -264,9 +316,9 @@ struct AttributeSubform /// - `name` : An optional identifier that names the subform. It is parsed from inputs /// like `name = my_field`. name : Option< syn::Ident >, - /// - `pubc` : An option for debug purpose. - #[ allow( dead_code ) ] - public : bool, + /// - `setter` : Disable generation of setter. + /// It still generate `_field_add` method, so it could be used to make a setter with custom arguments. + setter : bool, } impl syn::parse::Parse for AttributeSubform @@ -274,7 +326,7 @@ impl syn::parse::Parse for AttributeSubform fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > { let mut name : Option< syn::Ident > = None; - let mut public : bool = true; + let mut setter : bool = true; while !input.is_empty() { @@ -287,17 +339,13 @@ impl syn::parse::Parse for AttributeSubform input.parse::< syn::Token![ = ] >()?; name = Some( input.parse()? ); } - else if ident == "public" + else if ident == "setter" { input.parse::< syn::Token![ = ] >()?; // Parse the boolean by checking next Ident if it's "true" or "false" - let value : syn::Ident = input.parse()?; - match value.to_string().as_str() - { - "true" => public = true, - "false" => public = false, - _ => return Err( syn::Error::new( value.span(), "expected `true` or `false`" ) ), - } + // let value : syn::Ident = input.parse()?; + let value : syn::LitBool = input.parse()?; + setter = value.value(); } else { @@ -316,7 +364,7 @@ impl syn::parse::Parse for AttributeSubform } } - Ok( Self { name, public } ) + Ok( Self { name, setter } ) } } @@ -642,24 +690,24 @@ fn field_setter_map } else { - let setter_enabled = if let Some( setter_attr ) = &field.attrs.setter - { - if !setter_attr.condition.value() - { - false - } - else - { - true - } - } - else - { - true - }; - if setter_enabled + // let setter_enabled = if let Some( setter_attr ) = &field.attrs.setter + // { + // if !setter_attr.condition.value() + // { + // false + // } + // else + // { + // true + // } + // } + // else + // { + // true + // }; + if field.trivial_setter_enabled() { - field_setter( ident, ident, non_optional_ty ) + field_trivial_setter( ident, ident, non_optional_ty ) } else { @@ -669,7 +717,7 @@ fn field_setter_map let r = if let Some( alias_attr ) = &field.attrs.alias { - let alias_tokens = field_setter( ident, &alias_attr.alias, non_optional_ty ); + let alias_tokens = field_trivial_setter( ident, &alias_attr.alias, non_optional_ty ); qt! { #r @@ -717,19 +765,24 @@ fn field_subform_add_setter_map use convert_case::{ Case, Casing }; let field_ident = field.ident; let field_ty = field.non_optional_ty; + let attr = field.attrs.subform.as_ref().unwrap(); // let params = typ::type_parameters( &field.non_optional_ty, .. ); + // xxx + // example : `child` - let mut explicit_name = false; - let setter_name = if let Some( ref _name ) = field.attrs.subform.as_ref().unwrap().name - { - explicit_name = true; - _name - } - else - { - field_ident - }; + // let mut explicit_name = false; + let setter_name = field.subform_setter_name(); + + // let setter_name = if let Some( ref name ) = attr.name + // { + // explicit_name = true; + // name + // } + // else + // { + // field_ident + // }; // example : `ParentFormerAddChildrenEnd`` let former_add_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); @@ -768,7 +821,8 @@ fn field_subform_add_setter_map }; // xxx : it should be printed by hint also - let r = if explicit_name + // let r = if explicit_name || attr.setter + let r = if attr.setter { qt! { @@ -1002,7 +1056,7 @@ fn field_container_setter /// ``` #[ inline ] -fn field_setter +fn field_trivial_setter ( field_ident : &syn::Ident, setter_name : &syn::Ident, From 75b290631863e4eccbb408b7f50682d3d6835733 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 12:23:03 +0300 Subject: [PATCH 372/533] former : experimenting --- .../former_tests/subformer_subform_hashmap.rs | 1 - .../subformer_subform_hashmap_explicit.rs | 1 - module/core/former_meta/src/derive/former.rs | 39 +++++++++++++------ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index 197c69580f..6c91c2cbf9 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -56,4 +56,3 @@ fn basic() a_id!( got.command.len(), 2 ); } -// xxx \ No newline at end of file diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs index f31fa885c4..c3d04a1387 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs @@ -69,4 +69,3 @@ fn basic() a_id!( got.command.len(), 2 ); } -// xxx \ No newline at end of file diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index c1030c8afd..d50f920c8e 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -59,6 +59,11 @@ impl< 'a > FormerField< 'a > } } + if let Some( ref _attr ) = self.attrs.container + { + return false; + } + let subform_name = self.subform_setter_name(); if let Some( name ) = subform_name { @@ -684,12 +689,17 @@ fn field_setter_map let non_optional_ty = &field.non_optional_ty; // Either subformer or ordinary setter. - let r = if let Some( _container_ty ) = &field.attrs.container + let r = if let Some( _ ) = &field.attrs.container { field_container_setter( field, stru ) } else { + qt!{} + }; + + // else + // { // let setter_enabled = if let Some( setter_attr ) = &field.attrs.setter // { // if !setter_attr.condition.value() @@ -705,23 +715,30 @@ fn field_setter_map // { // true // }; - if field.trivial_setter_enabled() - { - field_trivial_setter( ident, ident, non_optional_ty ) - } - else + + let r = if field.trivial_setter_enabled() + { + let r2 = field_trivial_setter( ident, ident, non_optional_ty ); + qt! { - qt!{ } + #r + #r2 } + } + else + { + r }; + // }; + let r = if let Some( alias_attr ) = &field.attrs.alias { - let alias_tokens = field_trivial_setter( ident, &alias_attr.alias, non_optional_ty ); + let r2 = field_trivial_setter( ident, &alias_attr.alias, non_optional_ty ); qt! { #r - #alias_tokens + #r2 } } else @@ -731,11 +748,11 @@ fn field_setter_map let r = if field.attrs.subform.is_some() { - let subformer = field_subform_add_setter_map( field, stru )?; + let r2 = field_subform_add_setter_map( field, stru )?; qt! { #r - #subformer + #r2 } } else From afa15abcec3ccfdce6108a60e88a5c2d2ec0de77 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 12:38:27 +0300 Subject: [PATCH 373/533] former : experimenting --- module/core/former/Readme.md | 4 +- .../former_custom_setter_overriden.rs | 2 +- .../examples/former_custom_subformer.rs | 2 +- .../inc/former_tests/attribute_setter.rs | 2 +- .../inc/former_tests/subformer_container.rs | 2 +- .../subformer_container_implicit.rs | 2 +- .../subformer_container_manual.rs | 2 +- .../subformer_subform_and_container.rs | 2 +- ...rmer_subform_and_container_parametrized.rs | 2 +- .../former_tests/subformer_subform_hashmap.rs | 2 +- .../subformer_subform_hashmap_explicit.rs | 2 +- .../former_tests/subformer_subform_manual.rs | 2 +- .../former_tests/subformer_subform_named.rs | 2 +- .../subformer_subform_named_manual.rs | 2 +- module/core/former_meta/src/derive/former.rs | 114 +++++++----------- module/core/former_meta/src/lib.rs | 2 +- 16 files changed, 57 insertions(+), 89 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 9cb3d60f41..d29570f6a5 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -341,7 +341,7 @@ use former::Former; #[ derive( Debug, Former ) ] pub struct StructWithCustomSetters { - #[ setter( false ) ] + #[ scalar_setter( false ) ] word : String, } @@ -537,7 +537,7 @@ fn main() #[ derive( Debug, PartialEq, Former ) ] pub struct Aggregator { - #[ setter( false ) ] + #[ scalar_setter( false ) ] command : HashMap< String, Command >, } diff --git a/module/core/former/examples/former_custom_setter_overriden.rs b/module/core/former/examples/former_custom_setter_overriden.rs index c817ab6872..4a4f8ead8b 100644 --- a/module/core/former/examples/former_custom_setter_overriden.rs +++ b/module/core/former/examples/former_custom_setter_overriden.rs @@ -15,7 +15,7 @@ fn main() #[ derive( Debug, Former ) ] pub struct StructWithCustomSetters { - #[ setter( false ) ] + #[ scalar_setter( false ) ] word : String, } diff --git a/module/core/former/examples/former_custom_subformer.rs b/module/core/former/examples/former_custom_subformer.rs index e80dbbdeaf..426e61253d 100644 --- a/module/core/former/examples/former_custom_subformer.rs +++ b/module/core/former/examples/former_custom_subformer.rs @@ -23,7 +23,7 @@ fn main() pub struct Aggregator { #[ subform ] - // #[ setter( false ) ] + // #[ scalar_setter( false ) ] command : HashMap< String, Command >, } diff --git a/module/core/former/tests/inc/former_tests/attribute_setter.rs b/module/core/former/tests/inc/former_tests/attribute_setter.rs index 1d0efb1bf5..a526437c2e 100644 --- a/module/core/former/tests/inc/former_tests/attribute_setter.rs +++ b/module/core/former/tests/inc/former_tests/attribute_setter.rs @@ -5,7 +5,7 @@ use super::*; pub struct StructWithCustomSetters { ordinary : String, - #[ setter( false ) ] + #[ scalar_setter( false ) ] magic : String, } diff --git a/module/core/former/tests/inc/former_tests/subformer_container.rs b/module/core/former/tests/inc/former_tests/subformer_container.rs index 98e04e4ffb..1c2a91cf20 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container.rs @@ -17,7 +17,7 @@ pub struct Child pub struct Parent { #[ container( former::VectorDefinition ) ] - // #[ setter( false ) ] + // #[ scalar_setter( false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs index 2af5c2b50f..44b0b83e37 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs @@ -18,7 +18,7 @@ pub struct Parent { // #[ container( former::VectorDefinition ) ] #[ container ] - // #[ setter( false ) ] + // #[ scalar_setter( false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs index 608bd68c75..c680267e6e 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs @@ -17,7 +17,7 @@ pub struct Child pub struct Parent { // #[ container( former::VectorDefinition ) ] - #[ setter( false ) ] + #[ scalar_setter( false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs index 86216319d4..a43809dff4 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs @@ -19,7 +19,7 @@ pub struct Parent // #[ subform ] #[ subform( name = _child ) ] #[ container( former::VectorDefinition ) ] - // #[ setter( false ) ] + // #[ scalar_setter( false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs index f2bc008b94..1631921866 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs @@ -22,7 +22,7 @@ pub struct Child< 'child, T > // // #[ subform ] // #[ subform( name = _child ) ] // #[ container( former::VectorDefinition ) ] -// // #[ setter( false ) ] +// // #[ scalar_setter( false ) ] // children : Vec< Child >, // } // diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index 6c91c2cbf9..d46ccbadfa 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -20,7 +20,7 @@ pub struct Command pub struct Aggregator { #[ subform ] - #[ setter( false ) ] + #[ scalar_setter( false ) ] command : HashMap< String, Command >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs index c3d04a1387..05772d4e78 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs @@ -20,7 +20,7 @@ pub struct Command pub struct Aggregator { #[ subform( setter = false ) ] - #[ setter( false ) ] + #[ scalar_setter( false ) ] // xxx : should not be required in this case command : HashMap< String, Command >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 0ec1324a7d..a9fd5299f8 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -17,7 +17,7 @@ pub struct Parent { // #[ container( former::VectorDefinition ) ] // #[ subform ] - #[ setter( false ) ] + #[ scalar_setter( false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs index f422c0af6a..db036526a5 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs @@ -18,7 +18,7 @@ pub struct Parent { // #[ subform ] #[ subform( name = _child ) ] - // #[ setter( false ) ] + // #[ scalar_setter( false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs index fe327af72f..4c04066614 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs @@ -25,7 +25,7 @@ pub struct Child pub struct Parent { #[ subform ] - // #[ setter( false ) ] + // #[ scalar_setter( false ) ] children : Vec< Child >, } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index d50f920c8e..674ba5dabd 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -47,11 +47,11 @@ impl< 'a > FormerField< 'a > return None; } - /// Is trivial setter required. - pub fn trivial_setter_enabled( &self ) -> bool + /// Is scalar setter required. + pub fn scalar_setter_enabled( &self ) -> bool { - if let Some( ref attr ) = self.attrs.setter + if let Some( ref attr ) = self.attrs.scalar_setter { if attr.condition.value() == false { @@ -85,7 +85,7 @@ impl< 'a > FormerField< 'a > struct Attributes { default : Option< AttributeDefault >, - setter : Option< AttributeSetter >, + scalar_setter : Option< AttributeTrivialSetter >, container : Option< AttributeContainer >, subform : Option< AttributeSubform >, alias : Option< AttributeAlias >, @@ -96,7 +96,7 @@ impl Attributes fn parse( attributes : & Vec< syn::Attribute > ) -> Result< Self > { let mut default = None; - let mut setter = None; + let mut scalar_setter = None; let mut container = None; let mut subform = None; let mut alias = None; @@ -124,18 +124,16 @@ impl Attributes _ => return_syn_err!( attr, "Expects an attribute of format #[ default( val ) ], but got:\n {}", qt!{ #attr } ), } } - "setter" => + "scalar_setter" => { match attr.meta { syn::Meta::List( ref meta_list ) => { - setter.replace( syn::parse2::< AttributeSetter >( meta_list.tokens.clone() )? ); + scalar_setter.replace( syn::parse2::< AttributeTrivialSetter >( meta_list.tokens.clone() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ setter( val ) ], but got:\n {}", qt!{ #attr } ), + _ => return_syn_err!( attr, "Expects an attribute of format #[ scalar_setter( val ) ], but got:\n {}", qt!{ #attr } ), } - // let attr_setter = syn::parse2::< AttributeSetter >( attr.tokens.clone() )?; - // setter.replace( attr_setter ); } "container" => { @@ -187,7 +185,7 @@ impl Attributes } } - Ok( Attributes { default, setter, container, subform, alias } ) + Ok( Attributes { default, scalar_setter, container, subform, alias } ) } } @@ -248,19 +246,19 @@ impl syn::parse::Parse for AttributeDefault } /// -/// Attribute to enable/disable setter generation. +/// Attribute to enable/disable scalar setter generation. /// -/// `#[ setter( false ) ]` +/// `#[ scalar_setter( false ) ]` /// #[ allow( dead_code ) ] -struct AttributeSetter +struct AttributeTrivialSetter { // paren_token : syn::token::Paren, condition : syn::LitBool, } -impl syn::parse::Parse for AttributeSetter +impl syn::parse::Parse for AttributeTrivialSetter { fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > { @@ -677,48 +675,30 @@ fn field_setter_map -> Result< TokenStream > { let ident = &field.ident; + let non_optional_ty = &field.non_optional_ty; + let r = qt!{}; - // if let Some( setter_attr ) = &field.attrs.setter - // { - // if !setter_attr.condition.value() - // { - // return Ok( qt!{ } ); - // } - // } - // xxx : write test for interoperability of 3 attributes + // xxx : write test for interoperability of 3 attributes: scalar_setter, subform, container - let non_optional_ty = &field.non_optional_ty; - // Either subformer or ordinary setter. - let r = if let Some( _ ) = &field.attrs.container + // scalar setter + let r = if field.scalar_setter_enabled() { - field_container_setter( field, stru ) + let r2 = field_scalar_setter( ident, ident, non_optional_ty ); + qt! + { + #r + #r2 + } } else { - qt!{} + r }; - // else - // { - // let setter_enabled = if let Some( setter_attr ) = &field.attrs.setter - // { - // if !setter_attr.condition.value() - // { - // false - // } - // else - // { - // true - // } - // } - // else - // { - // true - // }; - - let r = if field.trivial_setter_enabled() + // alias trival setter + let r = if let Some( alias_attr ) = &field.attrs.alias { - let r2 = field_trivial_setter( ident, ident, non_optional_ty ); + let r2 = field_scalar_setter( ident, &alias_attr.alias, non_optional_ty ); qt! { #r @@ -730,11 +710,10 @@ fn field_setter_map r }; - // }; - - let r = if let Some( alias_attr ) = &field.attrs.alias + // container setter + let r = if let Some( _ ) = &field.attrs.container { - let r2 = field_trivial_setter( ident, &alias_attr.alias, non_optional_ty ); + let r2 = field_container_setter( field, stru ); qt! { #r @@ -746,6 +725,7 @@ fn field_setter_map r }; + // subform setter let r = if field.attrs.subform.is_some() { let r2 = field_subform_add_setter_map( field, stru )?; @@ -788,34 +768,23 @@ fn field_subform_add_setter_map // xxx // example : `child` - // let mut explicit_name = false; let setter_name = field.subform_setter_name(); - // let setter_name = if let Some( ref name ) = attr.name - // { - // explicit_name = true; - // name - // } - // else - // { - // field_ident - // }; - // example : `ParentFormerAddChildrenEnd`` let former_add_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let former_add_end = syn::Ident::new( &former_add_end_name, field_ident.span() ); // example : `_children_former` - let element_subformer_name = format!( "_{}_add", field_ident ); // xxx : rename - let element_subformer = syn::Ident::new( &element_subformer_name, field_ident.span() ); + let field_add_name = format!( "_{}_add", field_ident ); + let field_add = syn::Ident::new( &field_add_name, field_ident.span() ); let r = qt! { // zzz : improve documentation - /// Custom setter which produce container element subformer. + /// Setter returning former of element of container of the field as subformer. #[ inline( always ) ] - pub fn #element_subformer< Former2, Definition2 >( self ) -> Former2 + pub fn #field_add< Former2, Definition2 >( self ) -> Former2 where Definition2 : former::FormerDefinition < @@ -838,7 +807,6 @@ fn field_subform_add_setter_map }; // xxx : it should be printed by hint also - // let r = if explicit_name || attr.setter let r = if attr.setter { qt! @@ -856,7 +824,7 @@ fn field_subform_add_setter_map >::Former // #as_subformer< Self, impl #as_subformer_end< Self > > { - self.#element_subformer + self.#field_add ::< < < #field_ty as former::Container >::Val as former::EntityToFormer< _ > >::Former, _, >() // ::< #former< _ >, _, >() } @@ -881,7 +849,7 @@ fn field_subform_add_setter_map } /// -/// Generate a sub-former setter for the 'field_ident' with the 'setter_name' name. +/// Generate a container setter for the 'field_ident' with the 'setter_name' name. /// /// # Example of generated code /// @@ -951,7 +919,7 @@ fn field_container_setter let doc = format! ( - "Subformer setter for the '{}' field. Method {} unlike method {} accept custom container subformer.", + "Container setter for the '{}' field. Method {} unlike method {} accept custom container subformer.", field_ident, field_assign_name, field_ident, @@ -1054,7 +1022,7 @@ fn field_container_setter } /// -/// Generate a single setter for the 'field_ident' with the 'setter_name' name. +/// Generate a single scalar setter for the 'field_ident' with the 'setter_name' name. /// /// Used as a helper function for field_setter_map(), which generates alias setters /// @@ -1073,7 +1041,7 @@ fn field_container_setter /// ``` #[ inline ] -fn field_trivial_setter +fn field_scalar_setter ( field_ident : &syn::Ident, setter_name : &syn::Ident, diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index d4ee961f2d..5d738a4e4b 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -272,7 +272,7 @@ mod derive #[ cfg( feature = "enabled" ) ] #[ cfg( feature = "derive_former" ) ] -#[ proc_macro_derive( Former, attributes( debug, perform, default, setter, container, subform, alias, doc, embed ) ) ] +#[ proc_macro_derive( Former, attributes( debug, perform, default, scalar_setter, container, subform, alias, doc, embed ) ) ] pub fn former( input : proc_macro::TokenStream ) -> proc_macro::TokenStream { let result = derive::former::former( input ); From d27d417e4703006a72bf46a7eec64c3cc583d8b5 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 12:41:34 +0300 Subject: [PATCH 374/533] former : experimenting --- .../only_test/parametrized_struct.rs | 16 ++-- .../former_tests/only_test/subformer_basic.rs | 36 ++++---- .../former_tests/parametrized_struct_imm.rs | 2 +- .../parametrized_struct_manual.rs | 86 +++++++++---------- .../former_tests/parametrized_struct_where.rs | 2 +- .../tests/inc/former_tests/subformer_basic.rs | 12 +-- .../former_tests/subformer_subform_hashmap.rs | 17 ++-- .../subformer_subform_hashmap_explicit.rs | 26 +++--- 8 files changed, 98 insertions(+), 99 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs b/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs index 78cc9ec2e4..b9826fe542 100644 --- a/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs +++ b/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs @@ -3,10 +3,10 @@ fn command_form() { // form - let got = Command::< &str >::former() + let got = Child::< &str >::former() .name( "a" ) .form(); - let exp = Command::< &str > + let exp = Child::< &str > { name : "a".to_string(), properties : collection_tools::HashMap::< &str, Property< &str > >::new(), @@ -14,10 +14,10 @@ fn command_form() a_id!( got, exp ); // perform - let got = Command::< &str >::former() + let got = Child::< &str >::former() .name( "a" ) .perform(); - let exp = Command::< &str > + let exp = Child::< &str > { name : "a".to_string(), properties : collection_tools::HashMap::< &str, Property< &str > >::new(), @@ -25,10 +25,10 @@ fn command_form() a_id!( got, exp ); // end - let got = Command::< &str >::former() + let got = Child::< &str >::former() .name( "a" ) .end(); - let exp = Command::< &str > + let exp = Child::< &str > { name : "a".to_string(), properties : collection_tools::HashMap::< &str, Property< &str > >::new(), @@ -46,7 +46,7 @@ fn command_properties() { // with HashMapSubformer - let got = Command::< &str >::former() + let got = Child::< &str >::former() .name( "a" ) .properties() .add( ( "property1", Property::< &str >::new( "property1", 13isize ) ) ) @@ -54,7 +54,7 @@ fn command_properties() .add( ( "property2", Property::new( "property2", 113isize ) ) ) .end() .form(); - let exp = Command::< &str > + let exp = Child::< &str > { name : "a".to_string(), properties : hmap! diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs index 8810cb6a7f..323bfb4d8b 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs @@ -1,4 +1,4 @@ -// let ca = wca::CommandsAggregator::former() +// let ca = wca::ChildsParent::former() // .command_with_closure( "echo" ) // .name( "prints all subjects and properties" ) // .subject( "Subject", wca::Type::String, true ) @@ -19,11 +19,11 @@ fn command_with_closure() { - let got = Command::< &str >::former() + let got = Child::< &str >::former() .name( "a" ) .subject( "b" ) .form(); - let exp = Command::< &str > + let exp = Child::< &str > { name : "a".to_string(), subject : "b".to_string(), @@ -31,11 +31,11 @@ fn command_with_closure() }; a_id!( got, exp ); - let got = Command::< &str >::former() + let got = Child::< &str >::former() .name( "a" ) .subject( "b" ) .perform(); - let exp = Command::< &str > + let exp = Child::< &str > { name : "a".to_string(), subject : "b".to_string(), @@ -43,11 +43,11 @@ fn command_with_closure() }; a_id!( got, exp ); - let got = Command::< &str >::former() + let got = Child::< &str >::former() .name( "a" ) .subject( "b" ) .end(); - let exp = Command::< &str > + let exp = Child::< &str > { name : "a".to_string(), subject : "b".to_string(), @@ -66,14 +66,14 @@ fn command_properties() { // with helper - let got = Command::< &str >::former() + let got = Child::< &str >::former() .name( "a" ) .subject( "b" ) .property( "property1", "simple property", 13isize ) .property( "property2", "simple property 2", 13isize ) .property( "property2", "simple property 3", 113isize ) .form(); - let exp = Command::< &str > + let exp = Child::< &str > { name : "a".to_string(), subject : "b".to_string(), @@ -87,7 +87,7 @@ fn command_properties() a_id!( got, exp ); // with HashMapSubformer - let got = Command::< &str >::former() + let got = Child::< &str >::former() .name( "a" ) .subject( "b" ) .properties() @@ -96,7 +96,7 @@ fn command_properties() .add( ( "property2", Property::new( "property2", "simple property 3", 113isize ) ) ) .end() .form(); - let exp = Command::< &str > + let exp = Child::< &str > { name : "a".to_string(), subject : "b".to_string(), @@ -120,19 +120,19 @@ fn aggregator() { // with helper - let got = Aggregator::< &str >::former() + let got = Parent::< &str >::former() .parameter1( "p1" ) - .commands().add( ( "name1".to_string(), CommandFormer::< &str >::new_coercing( former::ReturnPreformed ).name( "name1" ).subject( "s" ).end() ) ).end() + .commands().add( ( "name1".to_string(), ChildFormer::< &str >::new_coercing( former::ReturnPreformed ).name( "name1" ).subject( "s" ).end() ) ).end() .form() ; - let name1 = Command::< &str > + let name1 = Child::< &str > { name : "name1".to_string(), subject : "s".to_string(), properties : hmap!{}, }; - let exp = Aggregator + let exp = Parent { parameter1 : "p1".to_string(), commands : hmap!{ "name1" => name1 }, @@ -149,18 +149,18 @@ fn aggregator() fn aggregator_alternative_form() { - let exp = Aggregator::< &str >::former() + let exp = Parent::< &str >::former() .parameter1( "p1" ) .form() ; - let got = Aggregator::< &str >::former() + let got = Parent::< &str >::former() .parameter1( "p1" ) .perform() ; a_id!( got, exp ); - let got = Aggregator::< &str >::former() + let got = Parent::< &str >::former() .parameter1( "p1" ) .end() ; diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs index f0236afb4d..8f4ba1f7af 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs @@ -25,7 +25,7 @@ impl< Name > Property< Name > #[ derive( Debug, PartialEq, the_module::Former ) ] // #[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] // #[ derive( Debug, PartialEq ) ] -pub struct Command< K : core::hash::Hash + std::cmp::Eq > +pub struct Child< K : core::hash::Hash + std::cmp::Eq > { pub name : String, #[ container( former::HashMapDefinition ) ] diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index d6501b2107..e306d4ef07 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -25,7 +25,7 @@ impl< Name > Property< Name > // #[ derive( Debug, PartialEq, the_module::Former ) ] // #[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] #[ derive( Debug, PartialEq ) ] -pub struct Command< K > +pub struct Child< K > where K : core::hash::Hash + std::cmp::Eq, { @@ -37,29 +37,29 @@ where // == begin_coercing of generated #[ automatically_derived ] -impl< K, > Command< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, +impl< K, > Child< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, { #[ inline( always ) ] - pub fn former() -> CommandFormer< K, CommandFormerDefinition< K, (), Command< K, >, former :: ReturnPreformed > > + pub fn former() -> ChildFormer< K, ChildFormerDefinition< K, (), Child< K, >, former :: ReturnPreformed > > { - CommandFormer + ChildFormer :: - < K, CommandFormerDefinition< K, (), Command< K, >, former :: ReturnPreformed > > + < K, ChildFormerDefinition< K, (), Child< K, >, former :: ReturnPreformed > > :: new( former :: ReturnPreformed ) } } #[ derive( Debug ) ] -pub struct CommandFormerDefinitionTypes< K, __Context = (), __Formed = Command< K, >, > where K : core :: hash :: Hash + std :: cmp :: Eq, +pub struct ChildFormerDefinitionTypes< K, __Context = (), __Formed = Child< K, >, > where K : core :: hash :: Hash + std :: cmp :: Eq, { _phantom : core :: marker :: PhantomData< ( K, __Context, __Formed ) >, } impl< K, __Context, __Formed, > :: core :: default :: Default -for CommandFormerDefinitionTypes< K, __Context, __Formed, > +for ChildFormerDefinitionTypes< K, __Context, __Formed, > where K : core :: hash :: Hash + std :: cmp :: Eq, { @@ -73,18 +73,18 @@ where } impl< K, __Context, __Formed, > former :: FormerDefinitionTypes -for CommandFormerDefinitionTypes< K, __Context, __Formed, > +for ChildFormerDefinitionTypes< K, __Context, __Formed, > where K : core :: hash :: Hash + std :: cmp :: Eq, { - type Storage = CommandFormerStorage< K, >; + type Storage = ChildFormerStorage< K, >; type Formed = __Formed; type Context = __Context; } #[ derive( Debug ) ] -pub struct CommandFormerDefinition -< K, __Context = (), __Formed = Command< K, >, __End = former :: ReturnPreformed, > +pub struct ChildFormerDefinition +< K, __Context = (), __Formed = Child< K, >, __End = former :: ReturnPreformed, > where K : core :: hash :: Hash + std :: cmp :: Eq, { @@ -92,7 +92,7 @@ where } impl< K, __Context, __Formed, __End, > :: core :: default :: Default -for CommandFormerDefinition< K, __Context, __Formed, __End, > +for ChildFormerDefinition< K, __Context, __Formed, __End, > where K : core :: hash :: Hash + std :: cmp :: Eq, { @@ -106,21 +106,21 @@ where } impl< K, __Context, __Formed, __End, > former :: FormerDefinition -for CommandFormerDefinition< K, __Context, __Formed, __End, > +for ChildFormerDefinition< K, __Context, __Formed, __End, > where - __End : former :: FormingEnd< CommandFormerDefinitionTypes< K, __Context, __Formed, > >, + __End : former :: FormingEnd< ChildFormerDefinitionTypes< K, __Context, __Formed, > >, K : core :: hash :: Hash + std :: cmp :: Eq, { - type Types = CommandFormerDefinitionTypes< K, __Context, __Formed, >; + type Types = ChildFormerDefinitionTypes< K, __Context, __Formed, >; type End = __End; - type Storage = CommandFormerStorage< K, >; + type Storage = ChildFormerStorage< K, >; type Formed = __Formed; type Context = __Context; } -// pub type CommandFormerWithClosure< K, __Context, __Formed, > = CommandFormerDefinition< K, __Context, __Formed, former :: FormingEndClosure< CommandFormerDefinitionTypes< K, __Context, __Formed, > > >; +// pub type ChildFormerWithClosure< K, __Context, __Formed, > = ChildFormerDefinition< K, __Context, __Formed, former :: FormingEndClosure< ChildFormerDefinitionTypes< K, __Context, __Formed, > > >; -pub struct CommandFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, +pub struct ChildFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, { pub name : :: core :: option :: Option< String >, @@ -128,7 +128,7 @@ pub struct CommandFormerStorage< K, > where K : core :: hash :: Hash + std :: cm pub properties : :: core :: option :: Option< collection_tools :: HashMap< K, Property< K > > >, } -impl< K, > :: core :: default :: Default for CommandFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, +impl< K, > :: core :: default :: Default for ChildFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, { #[ inline( always ) ] fn default() -> Self @@ -141,14 +141,14 @@ impl< K, > :: core :: default :: Default for CommandFormerStorage< K, > where K } } -impl< K, > former :: Storage for CommandFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, +impl< K, > former :: Storage for ChildFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, { - type Formed = Command< K, >; + type Formed = Child< K, >; } -impl< K, > former :: StoragePreform for CommandFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, +impl< K, > former :: StoragePreform for ChildFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, { - type Preformed = Command< K, >; + type Preformed = Child< K, >; fn preform( mut self ) -> Self::Preformed // fn preform( mut self ) -> < Self as former :: Storage > :: Formed @@ -199,16 +199,16 @@ impl< K, > former :: StoragePreform for CommandFormerStorage< K, > where K : cor } }; - let result = Command :: < K, > { name, properties, }; + let result = Child :: < K, > { name, properties, }; return result; } } -pub struct CommandFormer< K, Definition = CommandFormerDefinition< K, (), Command< K, >, former::ReturnPreformed >, > +pub struct ChildFormer< K, Definition = ChildFormerDefinition< K, (), Child< K, >, former::ReturnPreformed >, > where K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition< Storage = CommandFormerStorage< K, > >, - // Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > > + Definition : former::FormerDefinition< Storage = ChildFormerStorage< K, > >, + // Definition::Types : former::FormerDefinitionTypes< Storage = ChildFormerStorage< K, > > { storage : Definition::Storage, context : core::option::Option< Definition::Context >, @@ -216,11 +216,11 @@ where } #[ automatically_derived ] -impl< K, Definition, > CommandFormer< K, Definition, > +impl< K, Definition, > ChildFormer< K, Definition, > where K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition< Storage = CommandFormerStorage< K, > > - // Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > >, + Definition : former::FormerDefinition< Storage = ChildFormerStorage< K, > > + // Definition::Types : former::FormerDefinitionTypes< Storage = ChildFormerStorage< K, > >, { #[ inline( always ) ] @@ -304,26 +304,26 @@ where #[ inline( always ) ] pub fn properties_set< Former2 >( self ) -> Former2 - where Former2 : former::FormerBegin< former::HashMapDefinition< K, Property< K >, Self, Self, CommandFormerPropertiesEnd, > > + where Former2 : former::FormerBegin< former::HashMapDefinition< K, Property< K >, Self, Self, ChildFormerPropertiesEnd, > > { - Former2::former_begin( None, Some( self ), CommandFormerPropertiesEnd ) + Former2::former_begin( None, Some( self ), ChildFormerPropertiesEnd ) } #[ inline( always ) ] - pub fn properties( self ) -> former::ContainerSubformer::< ( K, Property< K >, ), former::HashMapDefinition< K, Property< K >, Self, Self, CommandFormerPropertiesEnd > > + pub fn properties( self ) -> former::ContainerSubformer::< ( K, Property< K >, ), former::HashMapDefinition< K, Property< K >, Self, Self, ChildFormerPropertiesEnd > > { - self.properties_set::< former::ContainerSubformer::< ( K, Property< K >, ), former::HashMapDefinition< K, Property< K >, Self, Self, CommandFormerPropertiesEnd > >>() + self.properties_set::< former::ContainerSubformer::< ( K, Property< K >, ), former::HashMapDefinition< K, Property< K >, Self, Self, ChildFormerPropertiesEnd > >>() } } // -impl< K, Definition, > CommandFormer< K, Definition, > +impl< K, Definition, > ChildFormer< K, Definition, > where K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition< Storage = CommandFormerStorage< K, >, Formed = Command< K, > >, - // Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, >, Formed = Command< K, > >, - Definition::Storage : former::StoragePreform< Preformed = Command< K, > > + Definition : former::FormerDefinition< Storage = ChildFormerStorage< K, >, Formed = Child< K, > >, + // Definition::Types : former::FormerDefinitionTypes< Storage = ChildFormerStorage< K, >, Formed = Child< K, > >, + Definition::Storage : former::StoragePreform< Preformed = Child< K, > > { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { @@ -333,17 +333,17 @@ where #[ allow( non_camel_case_types ) ] -pub struct CommandFormerPropertiesEnd; +pub struct ChildFormerPropertiesEnd; #[ automatically_derived ] -impl< K, Definition, > former::FormingEnd< former::HashMapDefinition< K, Property< K >, CommandFormer< K, Definition, >, CommandFormer< K, Definition, >, former::NoEnd >, > for CommandFormerPropertiesEnd +impl< K, Definition, > former::FormingEnd< former::HashMapDefinition< K, Property< K >, ChildFormer< K, Definition, >, ChildFormer< K, Definition, >, former::NoEnd >, > for ChildFormerPropertiesEnd where K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition< Storage = CommandFormerStorage< K, > >, - // Definition::Types : former::FormerDefinitionTypes< Storage = CommandFormerStorage< K, > >, + Definition : former::FormerDefinition< Storage = ChildFormerStorage< K, > >, + // Definition::Types : former::FormerDefinitionTypes< Storage = ChildFormerStorage< K, > >, { #[ inline( always ) ] - fn call( &self, storage : collection_tools::HashMap< K, Property< K > >, super_former : Option< CommandFormer< K, Definition, > >, ) -> CommandFormer< K, Definition, > + fn call( &self, storage : collection_tools::HashMap< K, Property< K > >, super_former : Option< ChildFormer< K, Definition, > >, ) -> ChildFormer< K, Definition, > { let mut super_former = super_former.unwrap(); if let Some( ref mut field ) = super_former.storage.properties diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs index c2515a69eb..e0f2e2b962 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs @@ -25,7 +25,7 @@ impl< Name > Property< Name > #[ derive( Debug, PartialEq, the_module::Former ) ] // #[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] // #[ derive( Debug, PartialEq ) ] -pub struct Command< K > +pub struct Child< K > where K : core::hash::Hash + std::cmp::Eq, { diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 9744776af3..838e64b6e5 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -4,7 +4,7 @@ use super::*; // // this should work // -// let ca = Aggregator::former() +// let ca = Parent::former() // .parameter1( "val" ) // .command( "echo" ) // .name( "prints all subjects and properties" ) @@ -47,7 +47,7 @@ impl< Name > Property< Name > // == command #[ derive( Debug, PartialEq, the_module::Former ) ] -pub struct Command< K > +pub struct Child< K > where K : core::hash::Hash + std::cmp::Eq, { @@ -58,10 +58,10 @@ where } // manual -impl< K, Definition > CommandFormer< K, Definition > +impl< K, Definition > ChildFormer< K, Definition > where K : core::hash::Hash + std::cmp::Eq, - Definition : former::FormerDefinition< Storage = CommandFormerStorage< K > >, + Definition : former::FormerDefinition< Storage = ChildFormerStorage< K > >, Definition::Storage : former::StoragePreform, { @@ -96,13 +96,13 @@ where // == aggregator #[ derive( Debug, PartialEq, the_module::Former ) ] -pub struct Aggregator< K > +pub struct Parent< K > where K : core::hash::Hash + std::cmp::Eq, { pub parameter1 : String, #[ container( former::HashMapDefinition ) ] - pub commands : collection_tools::HashMap< String, Command< K > >, + pub commands : collection_tools::HashMap< String, Child< K > >, } // == diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index d46ccbadfa..a6d3afe3c9 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -5,28 +5,27 @@ use super::*; #[ allow( unused_imports ) ] use collection_tools::HashMap; -// Command struct with Former derived for builder pattern support +// Child struct with Former derived for builder pattern support #[ derive( Debug, PartialEq, former::Former ) ] -pub struct Command +pub struct Child { name : String, description : String, } -// Aggregator struct to hold commands +// Parent struct to hold commands #[ derive( Debug, PartialEq, former::Former ) ] // #[ debug ] // #[ derive( Debug, PartialEq ) ] -pub struct Aggregator +pub struct Parent { #[ subform ] - #[ scalar_setter( false ) ] - command : HashMap< String, Command >, + command : HashMap< String, Child >, } -impl former::ValToElement< HashMap< String, Command > > for Command +impl former::ValToElement< HashMap< String, Child > > for Child { - type Element = ( String, Command ); + type Element = ( String, Child ); #[ inline( always ) ] fn val_to_element( self ) -> Self::Element { @@ -42,7 +41,7 @@ impl former::ValToElement< HashMap< String, Command > > for Command fn basic() { - let got = Aggregator::former() + let got = Parent::former() .command() .name( "echo" ) .description( "prints all subjects and properties" ) // sets additional properties using custom subformer diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs index 05772d4e78..618ca13fa3 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs @@ -5,43 +5,43 @@ use super::*; #[ allow( unused_imports ) ] use collection_tools::HashMap; -// Command struct with Former derived for builder pattern support +// Child struct with Former derived for builder pattern support #[ derive( Debug, PartialEq, former::Former ) ] -pub struct Command +pub struct Child { name : String, description : String, } -// Aggregator struct to hold commands +// Parent struct to hold commands #[ derive( Debug, PartialEq, former::Former ) ] // #[ debug ] // #[ derive( Debug, PartialEq ) ] -pub struct Aggregator +pub struct Parent { #[ subform( setter = false ) ] #[ scalar_setter( false ) ] // xxx : should not be required in this case - command : HashMap< String, Command >, + command : HashMap< String, Child >, } -// Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. -impl< Definition > AggregatorFormer< Definition > +// Use ChildFormer as custom subformer for ParentFormer to add commands by name. +impl< Definition > ParentFormer< Definition > where - Definition : former::FormerDefinition< Storage = < Aggregator as former::EntityToStorage >::Storage >, + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, { #[ inline( always ) ] - pub fn command( self, name : &str ) -> CommandAsSubformer< Self, impl CommandAsSubformerEnd< Self > > + pub fn command( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { - self._command_add::< CommandFormer< _ >, _, >() + self._command_add::< ChildFormer< _ >, _, >() .name( name ) } } -impl former::ValToElement< HashMap< String, Command > > for Command +impl former::ValToElement< HashMap< String, Child > > for Child { - type Element = ( String, Command ); + type Element = ( String, Child ); #[ inline( always ) ] fn val_to_element( self ) -> Self::Element { @@ -57,7 +57,7 @@ impl former::ValToElement< HashMap< String, Command > > for Command fn basic() { - let got = Aggregator::former() + let got = Parent::former() .command( "echo" ) .description( "prints all subjects and properties" ) // sets additional properties using custom subformer .end() From 754823fc91be0f2f4197bb230406c8e8562fad01 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 13:18:20 +0300 Subject: [PATCH 375/533] former : experimenting --- .../subformer_setter_off_container.rs | 40 ++++++++++++++++++ .../subformer_setter_off_subform.rs | 41 +++++++++++++++++++ .../inc/former_tests/subformer_subform.rs | 5 +-- module/core/former/tests/inc/mod.rs | 5 +++ module/core/former_meta/src/derive/former.rs | 35 +++++++++++----- 5 files changed, 113 insertions(+), 13 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/subformer_setter_off_container.rs create mode 100644 module/core/former/tests/inc/former_tests/subformer_setter_off_subform.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_setter_off_container.rs b/module/core/former/tests/inc/former_tests/subformer_setter_off_container.rs new file mode 100644 index 0000000000..bb3fa60b98 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_setter_off_container.rs @@ -0,0 +1,40 @@ +#![ allow( dead_code ) ] + +use super::*; + +/// Child +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent + +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + #[ container( setter = false ) ] + // #[ scalar_setter( false ) ] + children : Vec< Child >, +} + +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + // xxx + #[ inline( always ) ] + pub fn children( self ) -> &'static str + { + r#" + Scalar setter `children` should not be generated by default if subform is used. + It can only be generated if req + "# + } + +} diff --git a/module/core/former/tests/inc/former_tests/subformer_setter_off_subform.rs b/module/core/former/tests/inc/former_tests/subformer_setter_off_subform.rs new file mode 100644 index 0000000000..2fe96eeb44 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_setter_off_subform.rs @@ -0,0 +1,41 @@ +#![ allow( dead_code ) ] + +use super::*; + +/// Child +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent + +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + #[ subform( setter = false ) ] + // #[ scalar_setter( false ) ] + // xxx : should be #[ scalar_setter = false ] + children : Vec< Child >, +} + +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + // xxx + #[ inline( always ) ] + pub fn children( self ) -> &'static str + { + r#" + Scalar setter `children` should not be generated by default if subform is used. + It can only be generated if req + "# + } + +} diff --git a/module/core/former/tests/inc/former_tests/subformer_subform.rs b/module/core/former/tests/inc/former_tests/subformer_subform.rs index ebacea4844..7781e87b37 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform.rs @@ -17,7 +17,7 @@ pub struct Child // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { - #[ subform ] + #[ subform( setter = false ) ] children : Vec< Child >, } @@ -34,8 +34,7 @@ where } #[ inline( always ) ] - pub fn _child( self ) -> - ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + pub fn _child( self ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { self._children_add ::< < Child as former::EntityToFormer< _ > >::Former, _, >() diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 37819397ee..52a5469e5a 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -82,6 +82,11 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_hashmap_explicit; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_setter_off_subform; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_setter_off_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_and_container; #[ cfg( any( not( feature = "no_std" ) ) ) ] diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 674ba5dabd..0d2ba744a1 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -51,28 +51,43 @@ impl< 'a > FormerField< 'a > pub fn scalar_setter_enabled( &self ) -> bool { + let mut explicit = false; if let Some( ref attr ) = self.attrs.scalar_setter { if attr.condition.value() == false { return false } + explicit = true; } + // xxx : container setter also could have custom name if let Some( ref _attr ) = self.attrs.container { return false; } - let subform_name = self.subform_setter_name(); - if let Some( name ) = subform_name + if self.attrs.subform.is_some() && !explicit { - if self.ident == name - { - return false; - } + return false; } + // let subform_name = self.subform_setter_name(); + // if let Some( name ) = subform_name + // { + // if self.ident == name + // { + // return false; + // } + // else + // { + // if !explicit + // { + // return false; + // } + // } + // } + return true; } @@ -85,7 +100,7 @@ impl< 'a > FormerField< 'a > struct Attributes { default : Option< AttributeDefault >, - scalar_setter : Option< AttributeTrivialSetter >, + scalar_setter : Option< AttributeScalarSetter >, container : Option< AttributeContainer >, subform : Option< AttributeSubform >, alias : Option< AttributeAlias >, @@ -130,7 +145,7 @@ impl Attributes { syn::Meta::List( ref meta_list ) => { - scalar_setter.replace( syn::parse2::< AttributeTrivialSetter >( meta_list.tokens.clone() )? ); + scalar_setter.replace( syn::parse2::< AttributeScalarSetter >( meta_list.tokens.clone() )? ); }, _ => return_syn_err!( attr, "Expects an attribute of format #[ scalar_setter( val ) ], but got:\n {}", qt!{ #attr } ), } @@ -252,13 +267,13 @@ impl syn::parse::Parse for AttributeDefault /// #[ allow( dead_code ) ] -struct AttributeTrivialSetter +struct AttributeScalarSetter { // paren_token : syn::token::Paren, condition : syn::LitBool, } -impl syn::parse::Parse for AttributeTrivialSetter +impl syn::parse::Parse for AttributeScalarSetter { fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > { From 02fd5d16e2c16865c9b4dd7f9c655b23e038cbc5 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 16:27:57 +0300 Subject: [PATCH 376/533] former : experimenting --- .../subformer_container_manual.rs | 16 +- ...r.rs => subformer_container_setter_off.rs} | 31 +++ ...orm.rs => subformer_subform_setter_off.rs} | 29 +++ module/core/former/tests/inc/mod.rs | 232 +++++++++--------- module/core/former_meta/src/derive/former.rs | 209 +++++++++++----- 5 files changed, 331 insertions(+), 186 deletions(-) rename module/core/former/tests/inc/former_tests/{subformer_setter_off_container.rs => subformer_container_setter_off.rs} (55%) rename module/core/former/tests/inc/former_tests/{subformer_setter_off_subform.rs => subformer_subform_setter_off.rs} (60%) diff --git a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs index c680267e6e..85faa40942 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs @@ -27,7 +27,6 @@ pub struct Parent impl< Definition, > ParentFormer< Definition, > where Definition : former::FormerDefinition< Storage = ParentFormerStorage< > >, - // Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, { #[ inline( always ) ] @@ -37,10 +36,13 @@ where { Former2::former_begin( None, Some( self ), ParentFormerAssignChildrenEnd::< Definition >::default() ) } - #[ doc = - "Subformer setter for the 'children' field. Method _children_assign unlike method children accept custom container subformer." ] + #[ inline( always ) ] - pub fn children( self ) -> former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > + pub fn children( self ) -> former::ContainerSubformer:: + < + Child, + former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > + > { self._children_assign::< former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > >() } @@ -71,14 +73,14 @@ impl< Definition > Default for ParentFormerAssignChildrenEnd< Definition > #[ automatically_derived ] impl< Definition, > former::FormingEnd -// < former::VectorDefinition< Child, ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd >, > < - < Vec< Child > as former::EntityToDefinition< ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd > >::Definition + < + Vec< Child > as former::EntityToDefinition< ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd > + >::Definition > for ParentFormerAssignChildrenEnd< Definition > where Definition : former::FormerDefinition< Storage = ParentFormerStorage< > >, - // Definition::Types : former::FormerDefinitionTypes< Storage = ParentFormerStorage< > >, { #[ inline( always ) ] fn call diff --git a/module/core/former/tests/inc/former_tests/subformer_setter_off_container.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs similarity index 55% rename from module/core/former/tests/inc/former_tests/subformer_setter_off_container.rs rename to module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs index bb3fa60b98..b763e6a464 100644 --- a/module/core/former/tests/inc/former_tests/subformer_setter_off_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs @@ -37,4 +37,35 @@ where "# } + #[ inline( always ) ] + pub fn children2( self ) -> former::ContainerSubformer:: + < + Child, + former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > + > + { + self._children_assign::< _ >() + } + +} + +#[ test ] +fn basic() +{ + + let got = Parent::former() + .children2() + .add( Child::former().name( "a" ).form() ) + .add( Child::former().name( "b" ).form() ) + .end() + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + } diff --git a/module/core/former/tests/inc/former_tests/subformer_setter_off_subform.rs b/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs similarity index 60% rename from module/core/former/tests/inc/former_tests/subformer_setter_off_subform.rs rename to module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs index 2fe96eeb44..48f086e668 100644 --- a/module/core/former/tests/inc/former_tests/subformer_setter_off_subform.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs @@ -1,4 +1,5 @@ #![ allow( dead_code ) ] +// xxx : rename use super::*; @@ -38,4 +39,32 @@ where "# } + #[ inline( always ) ] + pub fn children2( self, name : &str ) -> + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._children_add + ::< ChildFormer< _ >, _, >() + .name( name ) + } + +} + +#[ test ] +fn children() +{ + + let got = Parent::former() + .children2( "a" ).end() + .children2( "b" ).end() + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 52a5469e5a..77187d580d 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -7,91 +7,90 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_common; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_vec; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_hashset; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod container_former_hashmap; - - mod a_basic_manual; - mod a_basic; - mod a_primitives_manual; - mod a_primitives; - - mod a_containers_without_subformer; - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer_manual; - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer; - - mod attribute_default_container; - mod attribute_default_primitive; - mod attribute_perform; - mod attribute_setter; - mod attribute_alias; - mod attribute_feature; - - mod string_slice_manual; - mod string_slice; - mod unsigned_primitive_types; - mod default_user_type; - mod user_type_no_default; - mod user_type_no_debug; - mod visibility; - - mod name_collision_former_hashmap_without_parameter; - mod name_collision_former_vector_without_parameter; - mod name_collisions; - mod name_collision_context; - mod name_collision_end; - mod name_collision_on_end; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_manual; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_imm; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_where; - mod parametrized_field; - mod parametrized_field_where; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_basic; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_manual; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_implicit; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_manual; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_named; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_named_manual; - +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_common; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_vec; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_hashset; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod container_former_hashmap; +// +// mod a_basic_manual; +// mod a_basic; +// mod a_primitives_manual; +// mod a_primitives; +// +// mod a_containers_without_subformer; +// #[ cfg( not( feature = "no_std" ) ) ] +// mod a_containers_with_subformer_manual; +// #[ cfg( not( feature = "no_std" ) ) ] +// mod a_containers_with_subformer; +// +// mod attribute_default_container; +// mod attribute_default_primitive; +// mod attribute_perform; +// mod attribute_setter; +// mod attribute_alias; +// mod attribute_feature; +// +// mod string_slice_manual; +// mod string_slice; +// mod unsigned_primitive_types; +// mod default_user_type; +// mod user_type_no_default; +// mod user_type_no_debug; +// mod visibility; +// +// mod name_collision_former_hashmap_without_parameter; +// mod name_collision_former_vector_without_parameter; +// mod name_collisions; +// mod name_collision_context; +// mod name_collision_end; +// mod name_collision_on_end; +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_manual; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_imm; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_where; +// mod parametrized_field; +// mod parametrized_field_where; +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_basic; +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container_manual; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container_implicit; #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_hashmap; + mod subformer_container_setter_off; + +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_manual; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_named; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_named_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_hashmap_explicit; + mod subformer_subform_setter_off; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_setter_off_subform; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_hashmap; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_hashmap_explicit; // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_setter_off_container; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_and_container; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_and_container_parametrized; + // mod subformer_subform_and_container; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_subform_and_container_parametrized; + // xxx } #[ cfg( feature = "derive_components" ) ] @@ -126,39 +125,40 @@ mod components_tests } -only_for_terminal_module! -{ - - // stable have different information about error - // that's why these tests are active only for nightly - #[ test_tools::nightly ] - #[ test ] - fn former_trybuild() - { - - println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); - let t = test_tools::compiletime::TestCases::new(); - - // zzz : uncomment - t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); - t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); - t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); - - } - - // stable have different information about error - // that's why these tests are active only for nightly - #[ test_tools::nightly ] - #[ test ] - fn components_trybuild() - { - - println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); - let _t = test_tools::compiletime::TestCases::new(); - - // zzz : make it working test - //t.run( "tests/inc/compiletime/components_component_from_debug.rs" ); - - } - -} +// only_for_terminal_module! +// { +// +// // stable have different information about error +// // that's why these tests are active only for nightly +// #[ test_tools::nightly ] +// #[ test ] +// fn former_trybuild() +// { +// +// println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); +// let t = test_tools::compiletime::TestCases::new(); +// +// // zzz : uncomment +// t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); +// t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); +// t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); +// +// } +// +// // stable have different information about error +// // that's why these tests are active only for nightly +// #[ test_tools::nightly ] +// #[ test ] +// fn components_trybuild() +// { +// +// println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); +// let _t = test_tools::compiletime::TestCases::new(); +// +// // zzz : make it working test +// //t.run( "tests/inc/compiletime/components_component_from_debug.rs" ); +// +// } +// +// } +// xxx \ No newline at end of file diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 0d2ba744a1..00e4445807 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -8,7 +8,7 @@ use proc_macro2::TokenStream; /// Definition of a field. /// -#[ allow( dead_code ) ] + struct FormerField< 'a > { pub attrs : Attributes, @@ -25,7 +25,29 @@ struct FormerField< 'a > impl< 'a > FormerField< 'a > { - /// Get name of setter for subform. + /// Get name of setter for container if such setter should be generated. + pub fn container_setter_name( &self ) -> Option< &syn::Ident > + { + + if let Some( ref attr ) = self.attrs.container + { + if attr.setter.is_none() || attr.setter.unwrap() + { + if let Some( ref name ) = attr.name + { + return Some( &name ) + } + else + { + return Some( &self.ident ) + } + } + } + + return None; + } + + /// Get name of setter for subform if such setter should be generated. pub fn subform_setter_name( &self ) -> Option< &syn::Ident > { @@ -61,8 +83,7 @@ impl< 'a > FormerField< 'a > explicit = true; } - // xxx : container setter also could have custom name - if let Some( ref _attr ) = self.attrs.container + if self.attrs.container.is_some() && !explicit { return false; } @@ -72,22 +93,6 @@ impl< 'a > FormerField< 'a > return false; } - // let subform_name = self.subform_setter_name(); - // if let Some( name ) = subform_name - // { - // if self.ident == name - // { - // return false; - // } - // else - // { - // if !explicit - // { - // return false; - // } - // } - // } - return true; } @@ -162,7 +167,7 @@ impl Attributes { container.replace( syn::parse2::< AttributeContainer >( Default::default() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ container( former::VectorDefinition ) ] or #[ container ] if you want to use default container defition, but got:\n {}", qt!{ #attr } ), + _ => return_syn_err!( attr, "Expects an attribute of format #[ container ] or #[ container( definition = former::VectorDefinition ) ] if you want to use default container defition, but got:\n {}", qt!{ #attr } ), } } "subform" => @@ -210,7 +215,7 @@ impl Attributes /// `#[ perform( fn after1< 'a >() -> Option< &'a str > ) ]` /// -#[ allow( dead_code ) ] + struct AttributeFormAfter { // paren_token : syn::token::Paren, @@ -237,7 +242,7 @@ impl syn::parse::Parse for AttributeFormAfter /// `#[ default( 13 ) ]` /// -#[ allow( dead_code ) ] + struct AttributeDefault { // eq_token : syn::Token!{ = }, @@ -266,7 +271,7 @@ impl syn::parse::Parse for AttributeDefault /// `#[ scalar_setter( false ) ]` /// -#[ allow( dead_code ) ] + struct AttributeScalarSetter { // paren_token : syn::token::Paren, @@ -288,7 +293,8 @@ impl syn::parse::Parse for AttributeScalarSetter } /// -/// Attribute to enable/disable former generation. +/// Attribute to enable/disable/customize container setter generation. +/// /// Also known as subformers, used for aggregation relationship, when a struct holds another struct, which needs to be build by invoking multiple methods /// Typical example is a struct holding a `Vec` /// @@ -296,24 +302,93 @@ impl syn::parse::Parse for AttributeScalarSetter /// // qqq : update documentation -#[ allow( dead_code ) ] struct AttributeContainer { + /// Optional identifier for naming the setter. + name : Option< syn::Ident >, + /// Controls the generation of a setter method. If false, a setter method is not generated. + setter : Option< bool >, + /// Definition of the container former to use, e.g., `former::VectorSubformer`. expr : Option< syn::Type >, } impl syn::parse::Parse for AttributeContainer { - fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > + fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > { - let expr : Option< syn::Type > = input.parse().ok(); - Ok( Self + let mut name : Option< syn::Ident > = None; + let mut setter : Option< bool > = None; // Default is to generate a setter + let mut expr : Option< syn::Type > = None; + + while !input.is_empty() { - expr, - }) + let lookahead = input.lookahead1(); + if lookahead.peek( syn::Ident ) + { + let ident : syn::Ident = input.parse()?; + if ident == "name" + { + input.parse::< syn::Token![ = ] >()?; + name = Some( input.parse()? ); + } + else if ident == "setter" + { + input.parse::< syn::Token![ = ] >()?; + let value : syn::LitBool = input.parse()?; + setter = Some( value.value ); + } + else if ident == "definition" + { + input.parse::< syn::Token![ = ] >()?; + expr = Some( input.parse()? ); + } + else + { + return Err( lookahead.error() ); + } + } + else + { + return Err( lookahead.error() ); + } + + // Optional comma handling + if input.peek( syn::Token![ , ] ) + { + input.parse::< syn::Token![ , ] >()?; + } + } + + Ok( Self { name, setter, expr } ) } } +// +// struct AttributeContainer +// { +// // /// An optional identifier that names the setter. It is parsed from inputs +// // /// like `name = my_field`. +// // name : Option< syn::Ident >, +// // /// Disable generation of setter. +// // /// It still generate `_field_add` method, so it could be used to make a setter with custom arguments. +// // setter : bool, +// /// Definition of container former to use. +// /// Look [`former::ContainerSubformer`] and [`former::VectorDefinition`]. +// expr : Option< syn::Type >, // xxx : rename +// } +// +// impl syn::parse::Parse for AttributeContainer +// { +// fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > +// { +// let expr : Option< syn::Type > = input.parse().ok(); +// Ok( Self +// { +// expr, +// }) +// } +// } + /// Represents a subform attribute with optional name flag. /// Used to specify extra options for using one former as subformer of another one. /// For example name of setter could be customized. @@ -331,10 +406,10 @@ impl syn::parse::Parse for AttributeContainer struct AttributeSubform { - /// - `name` : An optional identifier that names the subform. It is parsed from inputs - /// like `name = my_field`. + /// An optional identifier that names the setter. It is parsed from inputs + /// like `name = my_field`. name : Option< syn::Ident >, - /// - `setter` : Disable generation of setter. + /// Disable generation of setter. /// It still generate `_field_add` method, so it could be used to make a setter with custom arguments. setter : bool, } @@ -392,7 +467,7 @@ impl syn::parse::Parse for AttributeSubform /// `#[ alias( name ) ]` /// -#[ allow( dead_code ) ] + struct AttributeAlias { // paren_token : syn::token::Paren, @@ -956,47 +1031,55 @@ fn field_container_setter } }; - let setter2 = if params.len() > 1 + let setter_name = field.container_setter_name(); + let setter2 = if let Some( setter_name ) = setter_name { - qt! + if params.len() > 1 { - - #[ doc = #doc ] - #[ inline( always ) ] - pub fn #field_ident( self ) -> - former::ContainerSubformer:: - < - ( #( #params, )* ), #subformer_definition - > + qt! { - self.#field_assign::< former::ContainerSubformer:: + + #[ doc = #doc ] + #[ inline( always ) ] + pub fn #setter_name( self ) -> + former::ContainerSubformer:: < ( #( #params, )* ), #subformer_definition - >>() - } + > + { + self.#field_assign::< former::ContainerSubformer:: + < + ( #( #params, )* ), #subformer_definition + > >() + } + } } - } - else - { - qt! + else { - - #[ doc = #doc ] - #[ inline( always ) ] - pub fn #field_ident( self ) -> - former::ContainerSubformer:: - < - #( #params, )* #subformer_definition - > + qt! { - self.#field_assign::< former::ContainerSubformer:: + + #[ doc = #doc ] + #[ inline( always ) ] + pub fn #setter_name( self ) -> + former::ContainerSubformer:: < #( #params, )* #subformer_definition - >>() - } + > + { + self.#field_assign::< former::ContainerSubformer:: + < + #( #params, )* #subformer_definition + > >() + } + } } + } + else + { + qt!{} }; qt! From 1f00d0ce1b1e6d85012553c91c833d6029f1ff1f Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 16:35:54 +0300 Subject: [PATCH 377/533] former : experimenting --- .../subformer_container_setter_off.rs | 2 +- .../subformer_container_setter_on.rs | 86 +++++++++++++++++++ .../subformer_subform_setter_off.rs | 3 +- .../subformer_subform_setter_on.rs | 83 ++++++++++++++++++ module/core/former/tests/inc/mod.rs | 6 +- module/core/former_meta/src/derive/former.rs | 2 +- 6 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs create mode 100644 module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs index b763e6a464..b20fe7e374 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs @@ -50,7 +50,7 @@ where } #[ test ] -fn basic() +fn container() { let got = Parent::former() diff --git a/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs new file mode 100644 index 0000000000..f8d963a732 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs @@ -0,0 +1,86 @@ +#![ allow( dead_code ) ] + +use super::*; + +/// Child +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent + +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + // Such parameters switch off generation of front-end container setter and switch on scalar setter. + // Without explicit scalar_setter( true ) scalar setter is not generated. + #[ subform( setter = false ) ] + #[ scalar_setter( true ) ] + children : Vec< Child >, +} + +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn children2( self ) -> former::ContainerSubformer:: + < + Child, + former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > + > + { + self._children_assign::< _ >() + } + +} + +#[ test ] +fn scalar() +{ + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let got = Parent::former() + .children( children ) + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} + +#[ test ] +fn container() +{ + + let got = Parent::former() + .children2() + .add( Child::former().name( "a" ).form() ) + .add( Child::former().name( "b" ).form() ) + .end() + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs b/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs index 48f086e668..a467fd2bea 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs @@ -29,7 +29,6 @@ where Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, { - // xxx #[ inline( always ) ] pub fn children( self ) -> &'static str { @@ -51,7 +50,7 @@ where } #[ test ] -fn children() +fn subform() { let got = Parent::former() diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs b/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs new file mode 100644 index 0000000000..2630abc97b --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs @@ -0,0 +1,83 @@ +#![ allow( dead_code ) ] + +use super::*; + +/// Child +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent + +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + // Such parameters switch off generation of front-end subform setter and switch on scalar setter. + // Without explicit scalar_setter( true ) scalar setter is not generated. + #[ subform( setter = false ) ] + #[ scalar_setter( true ) ] + children : Vec< Child >, +} + +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn children2( self, name : &str ) -> + ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._children_add + ::< ChildFormer< _ >, _, >() + .name( name ) + } + +} + +#[ test ] +fn scalar() +{ + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let got = Parent::former() + .children( children ) + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} + +#[ test ] +fn subform() +{ + + let got = Parent::former() + .children2( "a" ).end() + .children2( "b" ).end() + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 77187d580d..8a4cf017f1 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -65,8 +65,8 @@ mod former_tests // mod subformer_container; // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_container_manual; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container_implicit; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_implicit; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_container_setter_off; @@ -80,6 +80,8 @@ mod former_tests // mod subformer_subform_named_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_setter_off; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_setter_on; // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_subform_hashmap; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 00e4445807..37be332632 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -8,7 +8,7 @@ use proc_macro2::TokenStream; /// Definition of a field. /// - +#[ allow( dead_code ) ] struct FormerField< 'a > { pub attrs : Attributes, From 9c25ce7b02a705f4ef354ce85e053d74991c65b9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 18:24:49 +0300 Subject: [PATCH 378/533] former : experimenting --- .../examples/former_custom_subformer.rs | 3 + .../subformer_container_children2.rs | 21 +++++++ .../only_test/subformer_scalar_children.rs | 23 ++++++++ ..._subform.rs => subformer_subform_child.rs} | 0 .../only_test/subformer_subform_children2.rs | 19 ++++++ .../subformer_container_setter_off.rs | 21 +------ .../subformer_container_setter_on.rs | 45 +------------- .../inc/former_tests/subformer_subform.rs | 2 +- .../subformer_subform_and_container.rs | 4 +- ...rmer_subform_and_container_parametrized.rs | 2 +- .../former_tests/subformer_subform_hashmap.rs | 2 + .../former_tests/subformer_subform_manual.rs | 2 +- .../former_tests/subformer_subform_named.rs | 2 +- .../subformer_subform_named_manual.rs | 2 +- .../subformer_subform_setter_off.rs | 19 +----- .../subformer_subform_setter_on.rs | 43 +------------- module/core/former/tests/inc/mod.rs | 12 ++-- module/core/former_meta/src/derive/former.rs | 59 +++++++------------ 18 files changed, 107 insertions(+), 174 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/only_test/subformer_container_children2.rs create mode 100644 module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children.rs rename module/core/former/tests/inc/former_tests/only_test/{subformer_subform.rs => subformer_subform_child.rs} (100%) create mode 100644 module/core/former/tests/inc/former_tests/only_test/subformer_subform_children2.rs diff --git a/module/core/former/examples/former_custom_subformer.rs b/module/core/former/examples/former_custom_subformer.rs index 426e61253d..9240a7f85d 100644 --- a/module/core/former/examples/former_custom_subformer.rs +++ b/module/core/former/examples/former_custom_subformer.rs @@ -96,3 +96,6 @@ fn main() // > }, // > } } + +// xxx2 : finish example former_custom_subformer + diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_container_children2.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_container_children2.rs new file mode 100644 index 0000000000..44aac2d08f --- /dev/null +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_container_children2.rs @@ -0,0 +1,21 @@ + +#[ test ] +fn container() +{ + + let got = Parent::former() + .children2() + .add( Child::former().name( "a" ).form() ) + .add( Child::former().name( "b" ).form() ) + .end() + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children.rs new file mode 100644 index 0000000000..18a16fc71c --- /dev/null +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children.rs @@ -0,0 +1,23 @@ + +#[ test ] +fn scalar() +{ + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let got = Parent::former() + .children( children ) + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_subform_child.rs similarity index 100% rename from module/core/former/tests/inc/former_tests/only_test/subformer_subform.rs rename to module/core/former/tests/inc/former_tests/only_test/subformer_subform_child.rs diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_subform_children2.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_subform_children2.rs new file mode 100644 index 0000000000..0fac0895c5 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_subform_children2.rs @@ -0,0 +1,19 @@ + +#[ test ] +fn subform() +{ + + let got = Parent::former() + .children2( "a" ).end() + .children2( "b" ).end() + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} diff --git a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs index b20fe7e374..d30ddb2743 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs @@ -49,23 +49,4 @@ where } -#[ test ] -fn container() -{ - - let got = Parent::former() - .children2() - .add( Child::former().name( "a" ).form() ) - .add( Child::former().name( "b" ).form() ) - .end() - .form(); - - let children = vec! - [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, - ]; - let exp = Parent { children }; - a_id!( got, exp ); - -} +include!( "./only_test/subformer_container_children2.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs index f8d963a732..b4bd686094 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs @@ -41,46 +41,5 @@ where } -#[ test ] -fn scalar() -{ - - let children = vec! - [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, - ]; - let got = Parent::former() - .children( children ) - .form(); - - let children = vec! - [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, - ]; - let exp = Parent { children }; - a_id!( got, exp ); - -} - -#[ test ] -fn container() -{ - - let got = Parent::former() - .children2() - .add( Child::former().name( "a" ).form() ) - .add( Child::former().name( "b" ).form() ) - .end() - .form(); - - let children = vec! - [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, - ]; - let exp = Parent { children }; - a_id!( got, exp ); - -} +include!( "./only_test/subformer_scalar_children.rs" ); +include!( "./only_test/subformer_container_children2.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform.rs b/module/core/former/tests/inc/former_tests/subformer_subform.rs index 7781e87b37..9d9112f406 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform.rs @@ -46,4 +46,4 @@ where // == end of generated -include!( "./only_test/subformer_subform.rs" ); +include!( "./only_test/subformer_subform_child.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs index a43809dff4..c3599a76c3 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs @@ -18,7 +18,7 @@ pub struct Parent { // #[ subform ] #[ subform( name = _child ) ] - #[ container( former::VectorDefinition ) ] + #[ container( definition = former::VectorDefinition ) ] // #[ scalar_setter( false ) ] children : Vec< Child >, } @@ -44,5 +44,5 @@ where // == end of generated -include!( "./only_test/subformer_subform.rs" ); +include!( "./only_test/subformer_subform_child.rs" ); include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs index 1631921866..1771eedcc4 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs @@ -47,5 +47,5 @@ pub struct Child< 'child, T > // == end of generated -// include!( "./only_test/subformer_subform.rs" ); +// include!( "./only_test/subformer_subform_child.rs" ); // include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index a6d3afe3c9..4f9c0e50f1 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -55,3 +55,5 @@ fn basic() a_id!( got.command.len(), 2 ); } + +// xxx2 : finish example former_custom_subformer diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index a9fd5299f8..c26a4cf083 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -192,4 +192,4 @@ where // == end of generated for Parent in context of attribute subform -include!( "./only_test/subformer_subform.rs" ); +include!( "./only_test/subformer_subform_child.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs index db036526a5..4e56df7523 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs @@ -51,4 +51,4 @@ where // == end of generated -include!( "./only_test/subformer_subform.rs" ); +include!( "./only_test/subformer_subform_child.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs index 4c04066614..91745540ba 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs @@ -77,4 +77,4 @@ where // == end of generated for Parent in context of attribute subform -include!( "./only_test/subformer_subform.rs" ); +include!( "./only_test/subformer_subform_child.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs b/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs index a467fd2bea..95dabce287 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs @@ -49,21 +49,4 @@ where } -#[ test ] -fn subform() -{ - - let got = Parent::former() - .children2( "a" ).end() - .children2( "b" ).end() - .form(); - - let children = vec! - [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, - ]; - let exp = Parent { children }; - a_id!( got, exp ); - -} +include!( "./only_test/subformer_subform_children2.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs b/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs index 2630abc97b..1c8883f544 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs @@ -40,44 +40,5 @@ where } -#[ test ] -fn scalar() -{ - - let children = vec! - [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, - ]; - let got = Parent::former() - .children( children ) - .form(); - - let children = vec! - [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, - ]; - let exp = Parent { children }; - a_id!( got, exp ); - -} - -#[ test ] -fn subform() -{ - - let got = Parent::former() - .children2( "a" ).end() - .children2( "b" ).end() - .form(); - - let children = vec! - [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, - ]; - let exp = Parent { children }; - a_id!( got, exp ); - -} +include!( "./only_test/subformer_scalar_children.rs" ); +include!( "./only_test/subformer_subform_children2.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 8a4cf017f1..00ce81a4f4 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -83,12 +83,12 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_setter_on; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_hashmap; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_hashmap_explicit; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_subform_and_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_hashmap; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_hashmap_explicit; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_and_container; // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_subform_and_container_parametrized; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 37be332632..7eaee92404 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -292,15 +292,19 @@ impl syn::parse::Parse for AttributeScalarSetter } } +/// Represents an attribute for configuring setter generation in container-like structures. /// -/// Attribute to enable/disable/customize container setter generation. +/// This struct is part of a meta-programming approach to enable detailed configuration of nested structs or collections such as `Vec< E >, HashMap< K, E >` and so on. +/// It allows the customization of setter methods and the specification of the container's behavior through meta attributes. /// -/// Also known as subformers, used for aggregation relationship, when a struct holds another struct, which needs to be build by invoking multiple methods -/// Typical example is a struct holding a `Vec` +/// ## Example Input /// -/// `#[ container( former::VectorSubformer ) ]` +/// The following is an example of a token stream that this struct can parse: +/// ```ignore +/// container( name = "custom_setter", setter = true, definition = former::VectorDefinition ) +/// ``` +/// This example configures a struct to use a custom setter named `custom_setter` and enables setter generation using `former::VectorDefinition` as definition of the container former. /// -// qqq : update documentation struct AttributeContainer { @@ -309,7 +313,7 @@ struct AttributeContainer /// Controls the generation of a setter method. If false, a setter method is not generated. setter : Option< bool >, /// Definition of the container former to use, e.g., `former::VectorSubformer`. - expr : Option< syn::Type >, + definition : Option< syn::Type >, } impl syn::parse::Parse for AttributeContainer @@ -318,7 +322,7 @@ impl syn::parse::Parse for AttributeContainer { let mut name : Option< syn::Ident > = None; let mut setter : Option< bool > = None; // Default is to generate a setter - let mut expr : Option< syn::Type > = None; + let mut definition : Option< syn::Type > = None; while !input.is_empty() { @@ -340,16 +344,19 @@ impl syn::parse::Parse for AttributeContainer else if ident == "definition" { input.parse::< syn::Token![ = ] >()?; - expr = Some( input.parse()? ); + definition = Some( input.parse()? ); } else { - return Err( lookahead.error() ); + return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'name', 'setter', or 'definition'. For example: name = myName, setter = true, definition = MyContainerType", ident ) ) ); + // return Err( lookahead.error() ); } } else { - return Err( lookahead.error() ); + // return Err( lookahead.error() ); + // return Err( lookahead.error_with( "Expected 'name', 'setter', or 'definition' identifier " ) ); + return Err( syn::Error::new( input.span(), "Expected 'name', 'setter', or 'definition' identifier" ) ); } // Optional comma handling @@ -359,36 +366,10 @@ impl syn::parse::Parse for AttributeContainer } } - Ok( Self { name, setter, expr } ) + Ok( Self { name, setter, definition } ) } } -// -// struct AttributeContainer -// { -// // /// An optional identifier that names the setter. It is parsed from inputs -// // /// like `name = my_field`. -// // name : Option< syn::Ident >, -// // /// Disable generation of setter. -// // /// It still generate `_field_add` method, so it could be used to make a setter with custom arguments. -// // setter : bool, -// /// Definition of container former to use. -// /// Look [`former::ContainerSubformer`] and [`former::VectorDefinition`]. -// expr : Option< syn::Type >, // xxx : rename -// } -// -// impl syn::parse::Parse for AttributeContainer -// { -// fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > -// { -// let expr : Option< syn::Type > = input.parse().ok(); -// Ok( Self -// { -// expr, -// }) -// } -// } - /// Represents a subform attribute with optional name flag. /// Used to specify extra options for using one former as subformer of another one. /// For example name of setter could be customized. @@ -983,7 +964,7 @@ fn field_container_setter let field_assign = syn::Ident::new( &field_assign_name, field_ident.span() ); // example : `former::VectorDefinition` - let subformer_definition = &field.attrs.container.as_ref().unwrap().expr; + let subformer_definition = &field.attrs.container.as_ref().unwrap().definition; let subformer_definition = if subformer_definition.is_some() { qt! @@ -1238,7 +1219,7 @@ Result< TokenStream > let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); // example : `former::VectorDefinition`` - let subformer_definition = &field.attrs.container.as_ref().unwrap().expr; + let subformer_definition = &field.attrs.container.as_ref().unwrap().definition; // zzz : improve description let former_assign_end_doc = format! From a5a6e50dea4f9c9e1a7e2540ff7f8009aacce95b Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 18:28:38 +0300 Subject: [PATCH 379/533] former : experimenting --- module/core/former/Readme.md | 6 +- .../examples/former_subformer_hashmap.rs | 2 +- .../examples/former_subformer_hashset.rs | 2 +- .../examples/former_subformer_vector.rs | 2 +- module/core/former/src/hash_map.rs | 2 +- module/core/former/src/hash_set.rs | 2 +- .../a_containers_with_subformer.rs | 6 +- .../former_tests/parametrized_struct_imm.rs | 2 +- .../parametrized_struct_manual.rs | 2 +- .../former_tests/parametrized_struct_where.rs | 2 +- .../tests/inc/former_tests/subformer_basic.rs | 4 +- .../inc/former_tests/subformer_container.rs | 2 +- .../subformer_container_implicit.rs | 2 +- .../subformer_container_manual.rs | 2 +- ...rmer_subform_and_container_parametrized.rs | 2 +- .../former_tests/subformer_subform_manual.rs | 2 +- module/core/former/tests/inc/mod.rs | 136 +++++++++--------- module/core/former_meta/src/derive/former.rs | 21 ++- 18 files changed, 103 insertions(+), 96 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index d29570f6a5..a43fd57c67 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -433,7 +433,7 @@ The following example illustrates how to use a `VectorSubformer` to construct a #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithVec { - #[ container( former::VectorSubformer ) ] + #[ container( definition = former::VectorSubformer ) ] vec : Vec< &'static str >, } @@ -462,7 +462,7 @@ use test_tools::exposed::*; #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithMap { - #[ container( former::HashMapSubformer ) ] + #[ container( definition = former::HashMapSubformer ) ] map : std::collections::HashMap< &'static str, &'static str >, } @@ -491,7 +491,7 @@ use test_tools::exposed::*; #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithSet { - #[ container( former::HashSetSubformer ) ] + #[ container( definition = former::HashSetSubformer ) ] set : std::collections::HashSet< &'static str >, } diff --git a/module/core/former/examples/former_subformer_hashmap.rs b/module/core/former/examples/former_subformer_hashmap.rs index 121b10a29a..d6d49e9652 100644 --- a/module/core/former/examples/former_subformer_hashmap.rs +++ b/module/core/former/examples/former_subformer_hashmap.rs @@ -14,7 +14,7 @@ fn main() #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithMap { - #[ container( former::HashMapSubformer ) ] + #[ container( definition = former::HashMapSubformer ) ] map : std::collections::HashMap< &'static str, &'static str >, } diff --git a/module/core/former/examples/former_subformer_hashset.rs b/module/core/former/examples/former_subformer_hashset.rs index badb7ddb68..5920d6d71d 100644 --- a/module/core/former/examples/former_subformer_hashset.rs +++ b/module/core/former/examples/former_subformer_hashset.rs @@ -14,7 +14,7 @@ fn main() #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithSet { - #[ container( former::HashSetSubformer ) ] + #[ container( definition = former::HashSetSubformer ) ] set : std::collections::HashSet< &'static str >, } diff --git a/module/core/former/examples/former_subformer_vector.rs b/module/core/former/examples/former_subformer_vector.rs index 2be17c7868..55588a881b 100644 --- a/module/core/former/examples/former_subformer_vector.rs +++ b/module/core/former/examples/former_subformer_vector.rs @@ -13,7 +13,7 @@ fn main() #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithVec { - #[ container( former::VectorSubformer ) ] + #[ container( definition = former::VectorSubformer ) ] vec : Vec< &'static str >, } diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index ec4950d8de..e1dae85b22 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -203,7 +203,7 @@ where /// #[ derive( Debug, PartialEq, former::Former ) ] /// pub struct StructWithMap /// { -/// #[ container( former::HashMapSubformer ) ] +/// #[ container( definition = former::HashMapSubformer ) ] /// map : std::collections::HashMap< &'static str, &'static str >, /// } /// diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index d0150b85d6..307bd7490b 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -195,7 +195,7 @@ where /// #[ derive( Debug, PartialEq, former::Former ) ] /// pub struct StructWithSet /// { -/// #[ container( former::HashSetSubformer ) ] +/// #[ container( definition = former::HashSetSubformer ) ] /// set : std::collections::HashSet< &'static str >, /// } /// diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index 9daf174695..a9eaa315fa 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -9,11 +9,11 @@ use super::*; // #[ derive( Default, Debug, PartialEq ) ] pub struct Struct1 { - #[ container( former::VectorDefinition ) ] + #[ container( definition = former::VectorDefinition ) ] vec_1 : Vec< String >, - #[ container( former::HashMapDefinition ) ] + #[ container( definition = former::HashMapDefinition ) ] hashmap_1 : std::collections::HashMap< String, String >, - #[ container( former::HashSetDefinition ) ] + #[ container( definition = former::HashSetDefinition ) ] hashset_1 : std::collections::HashSet< String >, } diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs index 8f4ba1f7af..d216575504 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_imm.rs @@ -28,7 +28,7 @@ impl< Name > Property< Name > pub struct Child< K : core::hash::Hash + std::cmp::Eq > { pub name : String, - #[ container( former::HashMapDefinition ) ] + #[ container( definition = former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index e306d4ef07..d745a59167 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -30,7 +30,7 @@ where K : core::hash::Hash + std::cmp::Eq, { pub name : String, - // #[ container( former::HashMapDefinition ) ] + // #[ container( definition = former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs index e0f2e2b962..063e58be1c 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_where.rs @@ -30,7 +30,7 @@ where K : core::hash::Hash + std::cmp::Eq, { pub name : String, - #[ container( former::HashMapDefinition ) ] + #[ container( definition = former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index 838e64b6e5..f81bbda527 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -53,7 +53,7 @@ where { pub name : String, pub subject : String, - #[ container( former::HashMapDefinition ) ] + #[ container( definition = former::HashMapDefinition ) ] pub properties : collection_tools::HashMap< K, Property< K > >, } @@ -101,7 +101,7 @@ where K : core::hash::Hash + std::cmp::Eq, { pub parameter1 : String, - #[ container( former::HashMapDefinition ) ] + #[ container( definition = former::HashMapDefinition ) ] pub commands : collection_tools::HashMap< String, Child< K > >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_container.rs b/module/core/former/tests/inc/former_tests/subformer_container.rs index 1c2a91cf20..ecfa2a75f1 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container.rs @@ -16,7 +16,7 @@ pub struct Child // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { - #[ container( former::VectorDefinition ) ] + #[ container( definition = former::VectorDefinition ) ] // #[ scalar_setter( false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs index 44b0b83e37..87db7fa1f9 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs @@ -16,7 +16,7 @@ pub struct Child // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { - // #[ container( former::VectorDefinition ) ] + // #[ container( definition = former::VectorDefinition ) ] #[ container ] // #[ scalar_setter( false ) ] children : Vec< Child >, diff --git a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs index 85faa40942..abd938776e 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs @@ -16,7 +16,7 @@ pub struct Child // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { - // #[ container( former::VectorDefinition ) ] + // #[ container( definition = former::VectorDefinition ) ] #[ scalar_setter( false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs index 1771eedcc4..bc51827afd 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs @@ -21,7 +21,7 @@ pub struct Child< 'child, T > // { // // #[ subform ] // #[ subform( name = _child ) ] -// #[ container( former::VectorDefinition ) ] +// #[ container( definition = former::VectorDefinition ) ] // // #[ scalar_setter( false ) ] // children : Vec< Child >, // } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index c26a4cf083..39d61d1df0 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -15,7 +15,7 @@ pub struct Child // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { - // #[ container( former::VectorDefinition ) ] + // #[ container( definition = former::VectorDefinition ) ] // #[ subform ] #[ scalar_setter( false ) ] children : Vec< Child >, diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 00ce81a4f4..592c9d514f 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -7,77 +7,77 @@ mod former_tests #[ allow( unused_imports ) ] use super::*; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_common; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_vec; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_hashset; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod container_former_hashmap; -// -// mod a_basic_manual; -// mod a_basic; -// mod a_primitives_manual; -// mod a_primitives; -// -// mod a_containers_without_subformer; -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer_manual; -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer; -// -// mod attribute_default_container; -// mod attribute_default_primitive; -// mod attribute_perform; -// mod attribute_setter; -// mod attribute_alias; -// mod attribute_feature; -// -// mod string_slice_manual; -// mod string_slice; -// mod unsigned_primitive_types; -// mod default_user_type; -// mod user_type_no_default; -// mod user_type_no_debug; -// mod visibility; -// -// mod name_collision_former_hashmap_without_parameter; -// mod name_collision_former_vector_without_parameter; -// mod name_collisions; -// mod name_collision_context; -// mod name_collision_end; -// mod name_collision_on_end; -// -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_manual; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_imm; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_where; -// mod parametrized_field; -// mod parametrized_field_where; -// -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_basic; -// -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container_manual; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_common; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_vec; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashset; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod container_former_hashmap; + + mod a_basic_manual; + mod a_basic; + mod a_primitives_manual; + mod a_primitives; + + mod a_containers_without_subformer; + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer_manual; + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer; + + mod attribute_default_container; + mod attribute_default_primitive; + mod attribute_perform; + mod attribute_setter; + mod attribute_alias; + mod attribute_feature; + + mod string_slice_manual; + mod string_slice; + mod unsigned_primitive_types; + mod default_user_type; + mod user_type_no_default; + mod user_type_no_debug; + mod visibility; + + mod name_collision_former_hashmap_without_parameter; + mod name_collision_former_vector_without_parameter; + mod name_collisions; + mod name_collision_context; + mod name_collision_end; + mod name_collision_on_end; + + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_manual; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_imm; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_where; + mod parametrized_field; + mod parametrized_field_where; + + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod subformer_basic; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_container_implicit; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_container_setter_off; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_manual; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_named; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_named_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_named; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_named_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_setter_off; #[ cfg( any( not( feature = "no_std" ) ) ) ] @@ -89,8 +89,8 @@ mod former_tests mod subformer_subform_hashmap_explicit; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_and_container; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_subform_and_container_parametrized; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_and_container_parametrized; // xxx } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 7eaee92404..20813f8cfc 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -348,15 +348,12 @@ impl syn::parse::Parse for AttributeContainer } else { - return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'name', 'setter', or 'definition'. For example: name = myName, setter = true, definition = MyContainerType", ident ) ) ); - // return Err( lookahead.error() ); + return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'name', 'setter', or 'definition'. For example: `container( name = myName, setter = true, definition = MyDefinition )`", ident ) ) ); } } else { - // return Err( lookahead.error() ); - // return Err( lookahead.error_with( "Expected 'name', 'setter', or 'definition' identifier " ) ); - return Err( syn::Error::new( input.span(), "Expected 'name', 'setter', or 'definition' identifier" ) ); + return Err( syn::Error::new( input.span(), "Expected 'name', 'setter', or 'definition' identifier. For example: `container( name = myName, setter = true, definition = MyDefinition )`" ) ); } // Optional comma handling @@ -423,14 +420,24 @@ impl syn::parse::Parse for AttributeSubform } else { - return Err( lookahead.error() ); + return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'name', 'setter', or 'definition'. For example: `subform( name = myName, setter = true )`", ident ) ) ); } } else { - return Err( lookahead.error() ); + return Err( syn::Error::new( input.span(), "Expected 'name', 'setter', or 'definition' identifier. For example: `subform( name = myName, setter = true )`" ) ); } + // else + // { + // return Err( lookahead.error() ); + // } + // } + // else + // { + // return Err( lookahead.error() ); + // } + // Optional comma handling if input.peek( syn::Token![,] ) { From ace2366a9b892765425fafd7f421731c82eb3d1d Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 18:29:48 +0300 Subject: [PATCH 380/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 20813f8cfc..c89e97cd61 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -301,9 +301,8 @@ impl syn::parse::Parse for AttributeScalarSetter /// /// The following is an example of a token stream that this struct can parse: /// ```ignore -/// container( name = "custom_setter", setter = true, definition = former::VectorDefinition ) +/// name = "custom_setter", setter = true, definition = former::VectorDefinition /// ``` -/// This example configures a struct to use a custom setter named `custom_setter` and enables setter generation using `former::VectorDefinition` as definition of the container former. /// struct AttributeContainer @@ -413,8 +412,6 @@ impl syn::parse::Parse for AttributeSubform else if ident == "setter" { input.parse::< syn::Token![ = ] >()?; - // Parse the boolean by checking next Ident if it's "true" or "false" - // let value : syn::Ident = input.parse()?; let value : syn::LitBool = input.parse()?; setter = value.value(); } @@ -428,16 +425,6 @@ impl syn::parse::Parse for AttributeSubform return Err( syn::Error::new( input.span(), "Expected 'name', 'setter', or 'definition' identifier. For example: `subform( name = myName, setter = true )`" ) ); } - // else - // { - // return Err( lookahead.error() ); - // } - // } - // else - // { - // return Err( lookahead.error() ); - // } - // Optional comma handling if input.peek( syn::Token![,] ) { @@ -843,8 +830,6 @@ fn field_subform_add_setter_map let attr = field.attrs.subform.as_ref().unwrap(); // let params = typ::type_parameters( &field.non_optional_ty, .. ); - // xxx - // example : `child` let setter_name = field.subform_setter_name(); From c2a61c9f3b41e48a52cf9eb43ee326ec64d44809 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 18:46:21 +0300 Subject: [PATCH 381/533] former : experimenting --- .../former_tests/subformer_container_named.rs | 43 +++++++++++++++++++ .../subformer_container_setter_off.rs | 3 +- .../former_tests/subformer_subform_named.rs | 11 ++++- module/core/former/tests/inc/mod.rs | 2 + 4 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/subformer_container_named.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_container_named.rs b/module/core/former/tests/inc/former_tests/subformer_container_named.rs new file mode 100644 index 0000000000..a34969011f --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_container_named.rs @@ -0,0 +1,43 @@ +#![ allow( dead_code ) ] + +use super::*; + +/// Parameter description. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Child +{ + name : String, + is_mandatory : bool, +} + +/// Parent required for the template. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + #[ container( name = children2 ) ] + children : Vec< Child >, +} + +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn children( self ) -> &'static str + { + r#" + Scalar setter `children` should not be generated by default if container is used. + It can only be generated if req + "# + } + +} + +// == begin of generated + +// == end of generated + +include!( "./only_test/subformer_container_children2.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs index d30ddb2743..a94b59ea05 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs @@ -27,12 +27,11 @@ where Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, { - // xxx #[ inline( always ) ] pub fn children( self ) -> &'static str { r#" - Scalar setter `children` should not be generated by default if subform is used. + Scalar setter `children` should not be generated by default if container is used. It can only be generated if req "# } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs index 4e56df7523..14071581a9 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs @@ -16,9 +16,7 @@ pub struct Child // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { - // #[ subform ] #[ subform( name = _child ) ] - // #[ scalar_setter( false ) ] children : Vec< Child >, } @@ -28,6 +26,15 @@ where // Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, { + #[ inline( always ) ] + pub fn children( self ) -> &'static str + { + r#" + Scalar setter `children` should not be generated by default if subform is used. + It can only be generated if req + "# + } + #[ inline( always ) ] pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 592c9d514f..695bc1ba02 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -69,6 +69,8 @@ mod former_tests mod subformer_container_implicit; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_container_setter_off; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_named; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform; From 2ed2cd6d9a382be1d4562062cce25eec76fbd5cd Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 18:49:37 +0300 Subject: [PATCH 382/533] former : experimenting --- .../subformer_subform_and_container.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs index c3599a76c3..b57fb0988c 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs @@ -16,17 +16,14 @@ pub struct Child // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { - // #[ subform ] #[ subform( name = _child ) ] - #[ container( definition = former::VectorDefinition ) ] - // #[ scalar_setter( false ) ] + #[ container( definition = former::VectorDefinition, name = children2 ) ] children : Vec< Child >, } impl< Definition > ParentFormer< Definition > where Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, - // Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, { #[ inline( always ) ] @@ -38,6 +35,15 @@ where .name( name ) } + #[ inline( always ) ] + pub fn children( self ) -> &'static str + { + r#" + Scalar setter `children` should not be generated by default if subform is used. + It can only be generated if req + "# + } + } // == begin of generated @@ -45,4 +51,4 @@ where // == end of generated include!( "./only_test/subformer_subform_child.rs" ); -include!( "./only_test/subformer_container.rs" ); +include!( "./only_test/subformer_container_children2.rs" ); From 267bf2f20640e9acb93c12674e5c963e4ec32fc1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 19:06:23 +0300 Subject: [PATCH 383/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 180 ++++++++++++++----- module/core/former_meta/src/lib.rs | 2 +- 2 files changed, 136 insertions(+), 46 deletions(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index c89e97cd61..fd2887308d 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -53,7 +53,7 @@ impl< 'a > FormerField< 'a > if let Some( ref attr ) = self.attrs.subform { - if attr.setter + if attr.setter.is_none() || attr.setter.unwrap() == true { if let Some( ref name ) = attr.name { @@ -74,13 +74,16 @@ impl< 'a > FormerField< 'a > { let mut explicit = false; - if let Some( ref attr ) = self.attrs.scalar_setter + if let Some( ref attr ) = self.attrs.scalar { - if attr.condition.value() == false + if let Some( setter ) = attr.setter { - return false + if setter == false + { + return false + } + explicit = true; } - explicit = true; } if self.attrs.container.is_some() && !explicit @@ -105,10 +108,10 @@ impl< 'a > FormerField< 'a > struct Attributes { default : Option< AttributeDefault >, - scalar_setter : Option< AttributeScalarSetter >, - container : Option< AttributeContainer >, - subform : Option< AttributeSubform >, - alias : Option< AttributeAlias >, + scalar : Option< AttributeScalarSetter >, + container : Option< AttributeContainerSetter >, + subform : Option< AttributeSubformSetter >, + alias : Option< AttributeAlias >, // xxx : remove } impl Attributes @@ -116,7 +119,7 @@ impl Attributes fn parse( attributes : & Vec< syn::Attribute > ) -> Result< Self > { let mut default = None; - let mut scalar_setter = None; + let mut scalar = None; let mut container = None; let mut subform = None; let mut alias = None; @@ -144,15 +147,19 @@ impl Attributes _ => return_syn_err!( attr, "Expects an attribute of format #[ default( val ) ], but got:\n {}", qt!{ #attr } ), } } - "scalar_setter" => + "scalar" => { match attr.meta { syn::Meta::List( ref meta_list ) => { - scalar_setter.replace( syn::parse2::< AttributeScalarSetter >( meta_list.tokens.clone() )? ); + scalar.replace( syn::parse2::< AttributeScalarSetter >( meta_list.tokens.clone() )? ); + }, + syn::Meta::Path( ref _path ) => + { + scalar.replace( syn::parse2::< AttributeScalarSetter >( Default::default() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ scalar_setter( val ) ], but got:\n {}", qt!{ #attr } ), + _ => return_syn_err!( attr, "Expects an attribute of format `#[ scalar( setter = false ) ]` or `#[ scalar( setter = false, name = my_name ) ]`. \nGot: {}", qt!{ #attr } ), } } "container" => @@ -161,13 +168,13 @@ impl Attributes { syn::Meta::List( ref meta_list ) => { - container.replace( syn::parse2::< AttributeContainer >( meta_list.tokens.clone() )? ); + container.replace( syn::parse2::< AttributeContainerSetter >( meta_list.tokens.clone() )? ); }, syn::Meta::Path( ref _path ) => { - container.replace( syn::parse2::< AttributeContainer >( Default::default() )? ); + container.replace( syn::parse2::< AttributeContainerSetter >( Default::default() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ container ] or #[ container( definition = former::VectorDefinition ) ] if you want to use default container defition, but got:\n {}", qt!{ #attr } ), + _ => return_syn_err!( attr, "Expects an attribute of format `#[ container ]` or `#[ container( definition = former::VectorDefinition ) ]` if you want to use default container defition. \nGot: {}", qt!{ #attr } ), } } "subform" => @@ -176,13 +183,13 @@ impl Attributes { syn::Meta::List( ref meta_list ) => { - subform.replace( syn::parse2::< AttributeSubform >( meta_list.tokens.clone() )? ); + subform.replace( syn::parse2::< AttributeSubformSetter >( meta_list.tokens.clone() )? ); }, syn::Meta::Path( ref _path ) => { - subform.replace( syn::parse2::< AttributeSubform >( Default::default() )? ); + subform.replace( syn::parse2::< AttributeSubformSetter >( Default::default() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ subform ] or #[ subform( name : child ) ], but got:\n {}", qt!{ #attr } ), + _ => return_syn_err!( attr, "Expects an attribute of format `#[ subform ]` or `#[ subform( name : child )` ], \nGot: {}", qt!{ #attr } ), } } "alias" => @@ -193,7 +200,7 @@ impl Attributes { alias.replace( syn::parse2::< AttributeAlias >( meta_list.tokens.clone() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ alias( val ) ], but got:\n {}", qt!{ #attr } ), + _ => return_syn_err!( attr, "Expects an attribute of format `#[ alias( val ) ]`. \nGot: {}", qt!{ #attr } ), } // let attr_alias = syn::parse2::< AttributeAlias >( attr.tokens.clone() )?; // alias.replace( attr_alias ); @@ -205,7 +212,7 @@ impl Attributes } } - Ok( Attributes { default, scalar_setter, container, subform, alias } ) + Ok( Attributes { default, scalar, container, subform, alias } ) } } @@ -268,31 +275,89 @@ impl syn::parse::Parse for AttributeDefault /// /// Attribute to enable/disable scalar setter generation. /// -/// `#[ scalar_setter( false ) ]` +/// `#[ scalar( false ) ]` /// +/// Represents an attribute for configuring setter generation in container-like structures. +/// +/// Used to specify extra options for primitive scalar setter generation. +/// For example name of setter could be customized. +/// +/// ## Example Input +/// +/// A typical input to parse might look like the following: +/// +/// ```ignore +/// name = field_name, setter = true +/// ``` +/// + struct AttributeScalarSetter { - // paren_token : syn::token::Paren, - condition : syn::LitBool, + /// Optional identifier for naming the setter. + name : Option< syn::Ident >, + /// Controls the generation of a setter method. If false, a setter method is not generated. + setter : Option< bool >, +} + +impl AttributeScalarSetter +{ + + /// Should setter be generated or not? + pub fn setter( &self ) -> bool + { + self.setter.is_none() || self.setter.unwrap() + } + } impl syn::parse::Parse for AttributeScalarSetter { - fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > + fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > { - // let input2; - Ok( Self + let mut name : Option< syn::Ident > = None; + let mut setter : Option< bool > = None; + + while !input.is_empty() { - // paren_token : syn::parenthesized!( input2 in input ), - // condition : input2.parse()?, - condition : input.parse()?, - }) + let lookahead = input.lookahead1(); + if lookahead.peek( syn::Ident ) + { + let ident : syn::Ident = input.parse()?; + if ident == "name" + { + input.parse::< syn::Token![ = ] >()?; + name = Some( input.parse()? ); + } + else if ident == "setter" + { + input.parse::< syn::Token![ = ] >()?; + let value : syn::LitBool = input.parse()?; + setter = Some( value.value() ); + } + else + { + return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'name', 'setter', or 'definition'. For example: `scalar( name = myName, setter = true )`", ident ) ) ); + } + } + else + { + return Err( syn::Error::new( input.span(), "Expected 'name', 'setter', or 'definition' identifier. For example: `scalar( name = myName, setter = true )`" ) ); + } + + // Optional comma handling + if input.peek( syn::Token![,] ) + { + input.parse::< syn::Token![,] >()?; + } + } + + Ok( Self { name, setter } ) } } -/// Represents an attribute for configuring setter generation in container-like structures. +/// Represents an attribute for configuring container setter generation. /// /// This struct is part of a meta-programming approach to enable detailed configuration of nested structs or collections such as `Vec< E >, HashMap< K, E >` and so on. /// It allows the customization of setter methods and the specification of the container's behavior through meta attributes. @@ -305,7 +370,7 @@ impl syn::parse::Parse for AttributeScalarSetter /// ``` /// -struct AttributeContainer +struct AttributeContainerSetter { /// Optional identifier for naming the setter. name : Option< syn::Ident >, @@ -315,7 +380,18 @@ struct AttributeContainer definition : Option< syn::Type >, } -impl syn::parse::Parse for AttributeContainer +impl AttributeContainerSetter +{ + + /// Should setter be generated or not? + pub fn setter( &self ) -> bool + { + self.setter.is_none() || self.setter.unwrap() + } + +} + +impl syn::parse::Parse for AttributeContainerSetter { fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > { @@ -366,37 +442,51 @@ impl syn::parse::Parse for AttributeContainer } } -/// Represents a subform attribute with optional name flag. +/// Represents a subform attribute to control subform setter generation. /// Used to specify extra options for using one former as subformer of another one. /// For example name of setter could be customized. /// /// ## Example Input /// /// A typical input to parse might look like the following: +/// +/// ```ignore +/// name = field_name, setter = true /// ``` -/// name = field_name, public = true -/// ``` +/// /// or simply: -/// ``` +/// +/// ```ignore /// mame = field_name /// ``` -struct AttributeSubform +struct AttributeSubformSetter { /// An optional identifier that names the setter. It is parsed from inputs /// like `name = my_field`. name : Option< syn::Ident >, /// Disable generation of setter. /// It still generate `_field_add` method, so it could be used to make a setter with custom arguments. - setter : bool, + setter : Option< bool >, +} + +impl AttributeSubformSetter +{ + + /// Should setter be generated or not? + pub fn setter( &self ) -> bool + { + self.setter.is_none() || self.setter.unwrap() + } + } -impl syn::parse::Parse for AttributeSubform +impl syn::parse::Parse for AttributeSubformSetter { fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > { let mut name : Option< syn::Ident > = None; - let mut setter : bool = true; + let mut setter : Option< bool > = None; while !input.is_empty() { @@ -413,7 +503,7 @@ impl syn::parse::Parse for AttributeSubform { input.parse::< syn::Token![ = ] >()?; let value : syn::LitBool = input.parse()?; - setter = value.value(); + setter = Some( value.value() ); } else { @@ -743,7 +833,7 @@ fn field_setter_map let non_optional_ty = &field.non_optional_ty; let r = qt!{}; - // xxx : write test for interoperability of 3 attributes: scalar_setter, subform, container + // xxx : write test for interoperability of 3 attributes: scalar, subform, container // scalar setter let r = if field.scalar_setter_enabled() @@ -870,7 +960,7 @@ fn field_subform_add_setter_map }; // xxx : it should be printed by hint also - let r = if attr.setter + let r = if attr.setter() { qt! { diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index 5d738a4e4b..813489b96f 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -272,7 +272,7 @@ mod derive #[ cfg( feature = "enabled" ) ] #[ cfg( feature = "derive_former" ) ] -#[ proc_macro_derive( Former, attributes( debug, perform, default, scalar_setter, container, subform, alias, doc, embed ) ) ] +#[ proc_macro_derive( Former, attributes( debug, perform, default, scalar, container, subform, alias, doc, embed ) ) ] pub fn former( input : proc_macro::TokenStream ) -> proc_macro::TokenStream { let result = derive::former::former( input ); From a52a11c64e001c584a103d4972e68ea100fec8c3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 19:08:53 +0300 Subject: [PATCH 384/533] former : experimenting --- module/core/former/Readme.md | 4 ++-- module/core/former/examples/former_custom_setter_overriden.rs | 2 +- module/core/former/examples/former_custom_subformer.rs | 2 +- module/core/former/tests/inc/former_tests/attribute_setter.rs | 2 +- .../core/former/tests/inc/former_tests/subformer_container.rs | 2 +- .../tests/inc/former_tests/subformer_container_implicit.rs | 2 +- .../tests/inc/former_tests/subformer_container_manual.rs | 2 +- .../tests/inc/former_tests/subformer_container_setter_off.rs | 2 +- .../tests/inc/former_tests/subformer_container_setter_on.rs | 2 +- .../subformer_subform_and_container_parametrized.rs | 2 +- .../inc/former_tests/subformer_subform_hashmap_explicit.rs | 2 +- .../former/tests/inc/former_tests/subformer_subform_manual.rs | 2 +- .../tests/inc/former_tests/subformer_subform_named_manual.rs | 2 +- .../tests/inc/former_tests/subformer_subform_setter_off.rs | 2 +- .../tests/inc/former_tests/subformer_subform_setter_on.rs | 2 +- module/core/former_meta/src/derive/former.rs | 4 ++-- 16 files changed, 18 insertions(+), 18 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index a43fd57c67..8f1b1b6b5f 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -341,7 +341,7 @@ use former::Former; #[ derive( Debug, Former ) ] pub struct StructWithCustomSetters { - #[ scalar_setter( false ) ] + #[ scalar( setter = false ) ] word : String, } @@ -537,7 +537,7 @@ fn main() #[ derive( Debug, PartialEq, Former ) ] pub struct Aggregator { - #[ scalar_setter( false ) ] + #[ scalar( setter = false ) ] command : HashMap< String, Command >, } diff --git a/module/core/former/examples/former_custom_setter_overriden.rs b/module/core/former/examples/former_custom_setter_overriden.rs index 4a4f8ead8b..4723ab16e2 100644 --- a/module/core/former/examples/former_custom_setter_overriden.rs +++ b/module/core/former/examples/former_custom_setter_overriden.rs @@ -15,7 +15,7 @@ fn main() #[ derive( Debug, Former ) ] pub struct StructWithCustomSetters { - #[ scalar_setter( false ) ] + #[ scalar( setter = false ) ] word : String, } diff --git a/module/core/former/examples/former_custom_subformer.rs b/module/core/former/examples/former_custom_subformer.rs index 9240a7f85d..b45bb089c4 100644 --- a/module/core/former/examples/former_custom_subformer.rs +++ b/module/core/former/examples/former_custom_subformer.rs @@ -23,7 +23,7 @@ fn main() pub struct Aggregator { #[ subform ] - // #[ scalar_setter( false ) ] + // #[ scalar( setter = false ) ] command : HashMap< String, Command >, } diff --git a/module/core/former/tests/inc/former_tests/attribute_setter.rs b/module/core/former/tests/inc/former_tests/attribute_setter.rs index a526437c2e..d1674b7a83 100644 --- a/module/core/former/tests/inc/former_tests/attribute_setter.rs +++ b/module/core/former/tests/inc/former_tests/attribute_setter.rs @@ -5,7 +5,7 @@ use super::*; pub struct StructWithCustomSetters { ordinary : String, - #[ scalar_setter( false ) ] + #[ scalar( setter = false ) ] magic : String, } diff --git a/module/core/former/tests/inc/former_tests/subformer_container.rs b/module/core/former/tests/inc/former_tests/subformer_container.rs index ecfa2a75f1..e39b9d47ac 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container.rs @@ -17,7 +17,7 @@ pub struct Child pub struct Parent { #[ container( definition = former::VectorDefinition ) ] - // #[ scalar_setter( false ) ] + // #[ scalar( setter = false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs index 87db7fa1f9..58e4408f92 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs @@ -18,7 +18,7 @@ pub struct Parent { // #[ container( definition = former::VectorDefinition ) ] #[ container ] - // #[ scalar_setter( false ) ] + // #[ scalar( setter = false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs index abd938776e..91caa85c5e 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs @@ -17,7 +17,7 @@ pub struct Child pub struct Parent { // #[ container( definition = former::VectorDefinition ) ] - #[ scalar_setter( false ) ] + #[ scalar( setter = false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs index a94b59ea05..c0b7f8f536 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs @@ -18,7 +18,7 @@ pub struct Child pub struct Parent { #[ container( setter = false ) ] - // #[ scalar_setter( false ) ] + // #[ scalar( setter = false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs index b4bd686094..bbe4399746 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs @@ -20,7 +20,7 @@ pub struct Parent // Such parameters switch off generation of front-end container setter and switch on scalar setter. // Without explicit scalar_setter( true ) scalar setter is not generated. #[ subform( setter = false ) ] - #[ scalar_setter( true ) ] + #[ scalar( setter = true ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs index bc51827afd..2481026875 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs @@ -22,7 +22,7 @@ pub struct Child< 'child, T > // // #[ subform ] // #[ subform( name = _child ) ] // #[ container( definition = former::VectorDefinition ) ] -// // #[ scalar_setter( false ) ] +// // #[ scalar( setter = false ) ] // children : Vec< Child >, // } // diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs index 618ca13fa3..0d134e0263 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs @@ -20,7 +20,7 @@ pub struct Child pub struct Parent { #[ subform( setter = false ) ] - #[ scalar_setter( false ) ] // xxx : should not be required in this case + #[ scalar( setter = false ) ] // xxx : should not be required in this case command : HashMap< String, Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 39d61d1df0..9fec62425b 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -17,7 +17,7 @@ pub struct Parent { // #[ container( definition = former::VectorDefinition ) ] // #[ subform ] - #[ scalar_setter( false ) ] + #[ scalar( setter = false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs index 91745540ba..d02fbf87b3 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs @@ -25,7 +25,7 @@ pub struct Child pub struct Parent { #[ subform ] - // #[ scalar_setter( false ) ] + // #[ scalar( setter = false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs b/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs index 95dabce287..e24ab961a4 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs @@ -19,7 +19,7 @@ pub struct Child pub struct Parent { #[ subform( setter = false ) ] - // #[ scalar_setter( false ) ] + // #[ scalar( setter = false ) ] // xxx : should be #[ scalar_setter = false ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs b/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs index 1c8883f544..7b59e9f9cb 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs @@ -20,7 +20,7 @@ pub struct Parent // Such parameters switch off generation of front-end subform setter and switch on scalar setter. // Without explicit scalar_setter( true ) scalar setter is not generated. #[ subform( setter = false ) ] - #[ scalar_setter( true ) ] + #[ scalar( setter = true ) ] children : Vec< Child >, } diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index fd2887308d..cd0390e972 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -31,7 +31,7 @@ impl< 'a > FormerField< 'a > if let Some( ref attr ) = self.attrs.container { - if attr.setter.is_none() || attr.setter.unwrap() + if attr.setter() { if let Some( ref name ) = attr.name { @@ -53,7 +53,7 @@ impl< 'a > FormerField< 'a > if let Some( ref attr ) = self.attrs.subform { - if attr.setter.is_none() || attr.setter.unwrap() == true + if attr.setter() { if let Some( ref name ) = attr.name { From ba0f2f8ce9106b414de3947ea4f8f7ea1b4a8854 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 19:22:46 +0300 Subject: [PATCH 385/533] former : experimenting --- .../tests/inc/former_tests/attribute_alias.rs | 7 +- module/core/former_meta/src/derive/former.rs | 160 ++++++++++-------- module/core/former_meta/src/lib.rs | 3 +- 3 files changed, 99 insertions(+), 71 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_alias.rs b/module/core/former/tests/inc/former_tests/attribute_alias.rs index 1d5206bf94..f295c439ce 100644 --- a/module/core/former/tests/inc/former_tests/attribute_alias.rs +++ b/module/core/former/tests/inc/former_tests/attribute_alias.rs @@ -12,16 +12,17 @@ tests_impls! #[ derive( Debug, PartialEq, the_module::Former ) ] pub struct AliasTestStruct { - #[ alias( first_field ) ] + #[ scalar( name = first_field ) ] string_field : String, - #[ alias( second_field ) ] + #[ scalar( name = second_field ) ] i32_field : i32, i8_field : i8, } let test_struct = AliasTestStruct::former() .first_field( "first_field" ) - .i32_field( 2 ) + .second_field( 2 ) + // .i32_field( 2 ) .i8_field( 1 ) .form(); diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index cd0390e972..fe076fcd8a 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -21,10 +21,23 @@ struct FormerField< 'a > pub of_type : container_kind::ContainerKind, } -// xxx impl< 'a > FormerField< 'a > { + /// Get name of scalar setter. + pub fn scalar_setter_name( &self ) -> &syn::Ident + { + if let Some( ref attr ) = self.attrs.scalar + { + if let Some( ref name ) = attr.name + { + return name + } + } + return &self.ident; + } + + // xxx : maybe without Option? /// Get name of setter for container if such setter should be generated. pub fn container_setter_name( &self ) -> Option< &syn::Ident > { @@ -69,8 +82,8 @@ impl< 'a > FormerField< 'a > return None; } - /// Is scalar setter required. - pub fn scalar_setter_enabled( &self ) -> bool + /// Is scalar setter required. Does not if container of subformer setter requested. + pub fn scalar_setter_required( &self ) -> bool { let mut explicit = false; @@ -111,7 +124,7 @@ struct Attributes scalar : Option< AttributeScalarSetter >, container : Option< AttributeContainerSetter >, subform : Option< AttributeSubformSetter >, - alias : Option< AttributeAlias >, // xxx : remove + // alias : Option< AttributeAlias >, // xxx : remove } impl Attributes @@ -122,7 +135,7 @@ impl Attributes let mut scalar = None; let mut container = None; let mut subform = None; - let mut alias = None; + // let mut alias = None; for attr in attributes { let key_ident = attr.path().get_ident() @@ -192,19 +205,19 @@ impl Attributes _ => return_syn_err!( attr, "Expects an attribute of format `#[ subform ]` or `#[ subform( name : child )` ], \nGot: {}", qt!{ #attr } ), } } - "alias" => - { - match attr.meta - { - syn::Meta::List( ref meta_list ) => - { - alias.replace( syn::parse2::< AttributeAlias >( meta_list.tokens.clone() )? ); - }, - _ => return_syn_err!( attr, "Expects an attribute of format `#[ alias( val ) ]`. \nGot: {}", qt!{ #attr } ), - } - // let attr_alias = syn::parse2::< AttributeAlias >( attr.tokens.clone() )?; - // alias.replace( attr_alias ); - } + // "alias" => + // { + // match attr.meta + // { + // syn::Meta::List( ref meta_list ) => + // { + // alias.replace( syn::parse2::< AttributeAlias >( meta_list.tokens.clone() )? ); + // }, + // _ => return_syn_err!( attr, "Expects an attribute of format `#[ alias( val ) ]`. \nGot: {}", qt!{ #attr } ), + // } + // // let attr_alias = syn::parse2::< AttributeAlias >( attr.tokens.clone() )?; + // // alias.replace( attr_alias ); + // } _ => { return Err( syn_err!( attr, "Unknown attribute {}", qt!{ #attr } ) ); @@ -212,7 +225,7 @@ impl Attributes } } - Ok( Attributes { default, scalar, container, subform, alias } ) + Ok( Attributes { default, scalar, container, subform } ) } } @@ -526,32 +539,32 @@ impl syn::parse::Parse for AttributeSubformSetter } } -/// -/// Attribute to create alias. -/// -/// `#[ alias( name ) ]` -/// - - -struct AttributeAlias -{ - // paren_token : syn::token::Paren, - alias : syn::Ident, -} - -impl syn::parse::Parse for AttributeAlias -{ - fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > - { - // let input2; - Ok( Self - { - // paren_token : syn::parenthesized!( input2 in input ), - // alias : input2.parse()?, - alias : input.parse()?, - }) - } -} +// /// +// /// Attribute to create alias. +// /// +// /// `#[ alias( name ) ]` +// /// +// +// +// struct AttributeAlias +// { +// // paren_token : syn::token::Paren, +// alias : syn::Ident, +// } +// +// impl syn::parse::Parse for AttributeAlias +// { +// fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > +// { +// // let input2; +// Ok( Self +// { +// // paren_token : syn::parenthesized!( input2 in input ), +// // alias : input2.parse()?, +// alias : input.parse()?, +// }) +// } +// } /// /// Is type under Option. @@ -829,16 +842,16 @@ fn field_setter_map ) -> Result< TokenStream > { - let ident = &field.ident; - let non_optional_ty = &field.non_optional_ty; + // let ident = &field.ident; + // let typ = &field.non_optional_ty; let r = qt!{}; // xxx : write test for interoperability of 3 attributes: scalar, subform, container // scalar setter - let r = if field.scalar_setter_enabled() + let r = if field.scalar_setter_required() { - let r2 = field_scalar_setter( ident, ident, non_optional_ty ); + let r2 = field_scalar_setter( field ); qt! { #r @@ -850,20 +863,28 @@ fn field_setter_map r }; - // alias trival setter - let r = if let Some( alias_attr ) = &field.attrs.alias - { - let r2 = field_scalar_setter( ident, &alias_attr.alias, non_optional_ty ); - qt! - { - #r - #r2 - } - } - else - { - r - }; + // xxx : clean + // // alias trival setter + // let r = if let Some( attr ) = &field.attrs.scalar + // { + // if let Some( ref alias ) = attr.name + // { + // let r2 = field_scalar_setter( ident, alias, typ ); + // qt! + // { + // #r + // #r2 + // } + // } + // else + // { + // r + // } + // } + // else + // { + // r + // }; // container setter let r = if let Some( _ ) = &field.attrs.container @@ -1204,12 +1225,17 @@ fn field_container_setter #[ inline ] fn field_scalar_setter ( - field_ident : &syn::Ident, - setter_name : &syn::Ident, - non_optional_type : &syn::Type, + field : &FormerField< '_ >, + // field_ident : &syn::Ident, + // setter_name : &syn::Ident, + // non_optional_type : &syn::Type, ) -> TokenStream { + let field_ident = &field.ident; + let typ = &field.non_optional_ty; + let setter_name = field.scalar_setter_name(); + let doc = format! ( "Setter for the '{}' field.", @@ -1221,7 +1247,7 @@ fn field_scalar_setter #[ doc = #doc ] #[ inline ] pub fn #setter_name< Src >( mut self, src : Src ) -> Self - where Src : ::core::convert::Into< #non_optional_type >, + where Src : ::core::convert::Into< #typ >, { debug_assert!( self.storage.#field_ident.is_none() ); self.storage.#field_ident = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index 813489b96f..1ade4d0fe4 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -272,7 +272,8 @@ mod derive #[ cfg( feature = "enabled" ) ] #[ cfg( feature = "derive_former" ) ] -#[ proc_macro_derive( Former, attributes( debug, perform, default, scalar, container, subform, alias, doc, embed ) ) ] +// xxx : rename default +#[ proc_macro_derive( Former, attributes( debug, perform, default, scalar, container, subform ) ) ] pub fn former( input : proc_macro::TokenStream ) -> proc_macro::TokenStream { let result = derive::former::former( input ); From 1dd73e2f1d1526efe8ab87493cd1665a85a4d6a2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 19:23:24 +0300 Subject: [PATCH 386/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index fe076fcd8a..d0a122061a 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -4,6 +4,8 @@ use iter_tools::{ Itertools, process_results }; use macro_tools::{ attr, diag, generic_params, generic_args, container_kind, typ, Result }; use proc_macro2::TokenStream; +// zzz : feature to have storage fields + /// /// Definition of a field. /// From 6f8a74925bbaa6544bc81dc0a902c0015cf16373 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 19:37:27 +0300 Subject: [PATCH 387/533] former : experimenting --- .../only_test/subformer_scalar_children3.rs | 23 ++++++ .../subformer_subform_and_container.rs | 4 +- module/core/former_meta/src/derive/former.rs | 78 ++----------------- 3 files changed, 31 insertions(+), 74 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children3.rs diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children3.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children3.rs new file mode 100644 index 0000000000..379d2bfe82 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children3.rs @@ -0,0 +1,23 @@ + +#[ test ] +fn scalar() +{ + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let got = Parent::former() + .children3( children ) + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : false }, + Child { name : "b".to_string(), is_mandatory : false }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs index b57fb0988c..b14c901f6a 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs @@ -16,8 +16,9 @@ pub struct Child // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { + #[ scalar( name = children3 ) ] #[ subform( name = _child ) ] - #[ container( definition = former::VectorDefinition, name = children2 ) ] + #[ container( name = children2 ) ] children : Vec< Child >, } @@ -50,5 +51,6 @@ where // == end of generated +include!( "./only_test/subformer_scalar_children3.rs" ); include!( "./only_test/subformer_subform_child.rs" ); include!( "./only_test/subformer_container_children2.rs" ); diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index d0a122061a..1197efcd40 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -39,7 +39,6 @@ impl< 'a > FormerField< 'a > return &self.ident; } - // xxx : maybe without Option? /// Get name of setter for container if such setter should be generated. pub fn container_setter_name( &self ) -> Option< &syn::Ident > { @@ -99,6 +98,10 @@ impl< 'a > FormerField< 'a > } explicit = true; } + if let Some( ref _name ) = attr.name + { + explicit = true; + } } if self.attrs.container.is_some() && !explicit @@ -126,7 +129,6 @@ struct Attributes scalar : Option< AttributeScalarSetter >, container : Option< AttributeContainerSetter >, subform : Option< AttributeSubformSetter >, - // alias : Option< AttributeAlias >, // xxx : remove } impl Attributes @@ -137,7 +139,6 @@ impl Attributes let mut scalar = None; let mut container = None; let mut subform = None; - // let mut alias = None; for attr in attributes { let key_ident = attr.path().get_ident() @@ -207,19 +208,6 @@ impl Attributes _ => return_syn_err!( attr, "Expects an attribute of format `#[ subform ]` or `#[ subform( name : child )` ], \nGot: {}", qt!{ #attr } ), } } - // "alias" => - // { - // match attr.meta - // { - // syn::Meta::List( ref meta_list ) => - // { - // alias.replace( syn::parse2::< AttributeAlias >( meta_list.tokens.clone() )? ); - // }, - // _ => return_syn_err!( attr, "Expects an attribute of format `#[ alias( val ) ]`. \nGot: {}", qt!{ #attr } ), - // } - // // let attr_alias = syn::parse2::< AttributeAlias >( attr.tokens.clone() )?; - // // alias.replace( attr_alias ); - // } _ => { return Err( syn_err!( attr, "Unknown attribute {}", qt!{ #attr } ) ); @@ -541,33 +529,6 @@ impl syn::parse::Parse for AttributeSubformSetter } } -// /// -// /// Attribute to create alias. -// /// -// /// `#[ alias( name ) ]` -// /// -// -// -// struct AttributeAlias -// { -// // paren_token : syn::token::Paren, -// alias : syn::Ident, -// } -// -// impl syn::parse::Parse for AttributeAlias -// { -// fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > -// { -// // let input2; -// Ok( Self -// { -// // paren_token : syn::parenthesized!( input2 in input ), -// // alias : input2.parse()?, -// alias : input.parse()?, -// }) -// } -// } - /// /// Is type under Option. /// @@ -805,6 +766,7 @@ fn field_name_map( field : &FormerField< '_ > ) -> syn::Ident field.ident.clone() } +// zzz : outdated, please update documentation /// /// Generate a former setter for the field. /// @@ -844,12 +806,8 @@ fn field_setter_map ) -> Result< TokenStream > { - // let ident = &field.ident; - // let typ = &field.non_optional_ty; let r = qt!{}; - // xxx : write test for interoperability of 3 attributes: scalar, subform, container - // scalar setter let r = if field.scalar_setter_required() { @@ -865,29 +823,6 @@ fn field_setter_map r }; - // xxx : clean - // // alias trival setter - // let r = if let Some( attr ) = &field.attrs.scalar - // { - // if let Some( ref alias ) = attr.name - // { - // let r2 = field_scalar_setter( ident, alias, typ ); - // qt! - // { - // #r - // #r2 - // } - // } - // else - // { - // r - // } - // } - // else - // { - // r - // }; - // container setter let r = if let Some( _ ) = &field.attrs.container { @@ -1228,9 +1163,6 @@ fn field_container_setter fn field_scalar_setter ( field : &FormerField< '_ >, - // field_ident : &syn::Ident, - // setter_name : &syn::Ident, - // non_optional_type : &syn::Type, ) -> TokenStream { From 53bf8479b2804d1dac323bde9034f52bcba091f6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Thu, 2 May 2024 19:38:04 +0300 Subject: [PATCH 388/533] former : experimenting --- module/core/former_meta/src/derive/former.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 1197efcd40..2b0eb1460e 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -4,6 +4,7 @@ use iter_tools::{ Itertools, process_results }; use macro_tools::{ attr, diag, generic_params, generic_args, container_kind, typ, Result }; use proc_macro2::TokenStream; +// zzz : explain concept of Storage // zzz : feature to have storage fields /// @@ -2242,4 +2243,3 @@ where Ok( result ) } -// zzz : explain concept of Storage From 18523ebce0fe386f21860aace6db3b8a3f6e8438 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 09:31:22 +0300 Subject: [PATCH 389/533] former : experimenting --- module/core/former/src/container.rs | 64 +++++++++++++------ .../former_tests/container_former_hashmap.rs | 35 ++++++++++ .../former_tests/container_former_hashset.rs | 16 +++++ .../inc/former_tests/container_former_vec.rs | 16 +++++ 4 files changed, 111 insertions(+), 20 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 3eab983a93..7cd335c48f 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -2,7 +2,7 @@ use crate::*; -/// xxx : improve description +/// zzz : improve description /// Descriptor of a container, specifically it define type of element and type of value. /// As well as function to convert element to value. Reversal conversion could be not possible, so value to element conversion is in a separate trait. pub trait Container @@ -17,7 +17,7 @@ pub trait Container } -// /// xxx : improve description +// /// zzz : improve description // /// Extensation of container interface to convert value ot element. // /// As well as function to convert element to value. Reversal conversion could be not possible, so value to element conversion is in a separate trait. // pub trait ContainerValToElement : Container @@ -31,11 +31,35 @@ pub trait Container /// xxx : improve description /// Implement function to convert value of an element of a container. /// As well as function to convert element to value. Reversal conversion could be not possible, so value to element conversion is in a separate trait. +pub trait ElementToVal< Container > +{ + type Val; + + /// Convert element to value. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. + fn element_to_val( self ) -> Self::Val; + +} + +impl< C, E > ElementToVal< C > +for E +where + C : Container< Element = E >, +{ + type Val = C::Val; + fn element_to_val( self ) -> Self::Val + { + C::element_to_val( self ) + } +} + +/// xxx : improve description +/// Implement function to convert value to an element of a container. +/// Value to an element conversion could be not possible, so value to element conversion is in a separate trait. pub trait ValToElement< Container > { type Element; - /// Convert val to element. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. + /// Convert value to element. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. fn val_to_element( self ) -> Self::Element; } @@ -146,10 +170,10 @@ pub trait ContainerAssign : Container pub struct ContainerSubformer< E, Definition > where Definition : FormerDefinition, - < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, + Definition::Storage : ContainerAdd< Element = E >, { - storage : < Definition::Types as FormerDefinitionTypes >::Storage, - context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, + storage : Definition::Storage, + context : core::option::Option< Definition::Context >, on_end : core::option::Option< Definition::End >, } @@ -158,7 +182,7 @@ use std::fmt; impl< E, Definition > fmt::Debug for ContainerSubformer< E, Definition > where Definition : FormerDefinition, - < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, + Definition::Storage : ContainerAdd< Element = E >, { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { @@ -173,15 +197,15 @@ where impl< E, Definition > ContainerSubformer< E, Definition > where Definition : FormerDefinition, - < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, // xxx + Definition::Storage : ContainerAdd< Element = E >, { /// Begins the building process, optionally initializing with a context and storage. #[ inline( always ) ] pub fn begin ( - mut storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, + mut storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Definition::Context >, on_end : Definition::End, ) -> Self @@ -202,8 +226,8 @@ where #[ inline( always ) ] pub fn begin_coercing< IntoEnd > ( - mut storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, + mut storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Definition::Context >, on_end : IntoEnd, ) -> Self @@ -224,7 +248,7 @@ where /// Finalizes the building process, returning the formed or a context incorporating it. #[ inline( always ) ] - pub fn end( mut self ) -> < Definition::Types as FormerDefinitionTypes >::Formed + pub fn end( mut self ) -> Definition::Formed { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); @@ -234,14 +258,14 @@ where /// Finalizes the building process, returning the formed or a context incorporating it. #[ inline( always ) ] - pub fn form( self ) -> < Definition::Types as FormerDefinitionTypes >::Formed + pub fn form( self ) -> Definition::Formed { self.end() } /// Replaces the current storage with a provided one, allowing for a reset or redirection of the building process. #[ inline( always ) ] - pub fn replace( mut self, vector : < Definition::Types as FormerDefinitionTypes >::Storage ) -> Self + pub fn replace( mut self, vector : Definition::Storage ) -> Self { self.storage = vector; self @@ -253,7 +277,7 @@ impl< E, Storage, Formed, Types, Definition > ContainerSubformer< E, Definition where Types : FormerDefinitionTypes< Context = (), Storage = Storage, Formed = Formed >, Definition : FormerDefinition< Types = Types >, - < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, + Definition::Storage : ContainerAdd< Element = E >, { /// Initializes a new `ContainerSubformer` instance, starting with an empty formed. @@ -293,7 +317,7 @@ where impl< E, Definition > ContainerSubformer< E, Definition > where Definition : FormerDefinition, - < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, + Definition::Storage : ContainerAdd< Element = E >, { /// Appends an element to the end of the storage, expanding the internal collection. @@ -313,15 +337,15 @@ impl< E, Definition > FormerBegin< Definition > for ContainerSubformer< E, Definition > where Definition : FormerDefinition, - < Definition::Types as FormerDefinitionTypes >::Storage : ContainerAdd< Element = E >, + Definition::Storage : ContainerAdd< Element = E >, { // type End = Definition::End; #[ inline( always ) ] fn former_begin ( - storage : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Storage >, - context : core::option::Option< < Definition::Types as FormerDefinitionTypes >::Context >, + storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Definition::Context >, on_end : Definition::End, ) -> Self diff --git a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs index da24fc1ec1..f0f8e0304c 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs @@ -103,3 +103,38 @@ fn replace() a_id!( got, exp ); } + +#[ test ] +fn element_to_val() +{ + let got = former::ElementToVal::< HashMap< u32, i32 > >::element_to_val( ( 1u32, 13i32 ) ); + let exp = 13i32; + a_id!( got, exp ) +} + +#[ test ] +fn val_to_element() +{ + + #[ derive( Clone, Copy, Debug, PartialEq ) ] + struct Val + { + key : u32, + data : i32, + } + + impl former::ValToElement< HashMap< u32, Val > > for Val + { + type Element = ( u32, Val ); + #[ inline( always ) ] + fn val_to_element( self ) -> Self::Element + { + ( self.key, self ) + } + } + + let got = former::ValToElement::< HashMap< u32, Val > >::val_to_element( Val { key : 1u32, data : 13i32 } ); + let exp = ( 1u32, Val { key : 1u32, data : 13i32 } ); + a_id!( got, exp ) + +} diff --git a/module/core/former/tests/inc/former_tests/container_former_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs index 697d73e76c..3859e9b544 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashset.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashset.rs @@ -103,3 +103,19 @@ fn replace() a_id!( got, exp ); } + +#[ test ] +fn element_to_val() +{ + let got = former::ElementToVal::< HashSet< i32 > >::element_to_val( 13i32 ); + let exp = 13i32; + a_id!( got, exp ) +} + +#[ test ] +fn val_to_element() +{ + let got = former::ValToElement::< HashSet< i32 > >::val_to_element( 13i32 ); + let exp = 13i32; + a_id!( got, exp ) +} 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 f358ee727b..4e4b49ce7e 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 @@ -140,3 +140,19 @@ fn entity_to() // a_id!( got.int_1, exp.storage.int_1 ); } + +#[ test ] +fn element_to_val() +{ + let got = former::ElementToVal::< Vec< i32 > >::element_to_val( 13i32 ); + let exp = 13i32; + a_id!( got, exp ) +} + +#[ test ] +fn val_to_element() +{ + let got = former::ValToElement::< Vec< i32 > >::val_to_element( 13i32 ); + let exp = 13i32; + a_id!( got, exp ) +} From b42bb387e5661e9b8ba78083bac0b1b5d1ce719f Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 09:48:39 +0300 Subject: [PATCH 390/533] former : experimenting --- module/core/former/src/container.rs | 19 +-- ...rs => subformer_subform_hashmap_custom.rs} | 0 .../subformer_subform_hashmap_custom2.rs | 116 ++++++++++++++++++ .../former_tests/subformer_subform_manual.rs | 11 +- module/core/former/tests/inc/mod.rs | 5 +- module/core/former_meta/src/derive/former.rs | 1 + 6 files changed, 134 insertions(+), 18 deletions(-) rename module/core/former/tests/inc/former_tests/{subformer_subform_hashmap_explicit.rs => subformer_subform_hashmap_custom.rs} (100%) create mode 100644 module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 7cd335c48f..96b11ff4e9 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -17,18 +17,7 @@ pub trait Container } -// /// zzz : improve description -// /// Extensation of container interface to convert value ot element. -// /// As well as function to convert element to value. Reversal conversion could be not possible, so value to element conversion is in a separate trait. -// pub trait ContainerValToElement : Container -// { -// -// /// Convert val to element. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. -// fn val_to_element( val : Self::Val ) -> Self::Element; -// -// } - -/// xxx : improve description +/// zzz : improve description /// Implement function to convert value of an element of a container. /// As well as function to convert element to value. Reversal conversion could be not possible, so value to element conversion is in a separate trait. pub trait ElementToVal< Container > @@ -52,7 +41,7 @@ where } } -/// xxx : improve description +/// zzz : improve description /// Implement function to convert value to an element of a container. /// Value to an element conversion could be not possible, so value to element conversion is in a separate trait. pub trait ValToElement< Container > @@ -149,9 +138,7 @@ pub trait ContainerAdd : Container } -// qqq : implement for other containers - -// xxx : extend documentation +// zzz : extend documentation /// A trait defining the capability to replface all elements. pub trait ContainerAssign : Container { diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs similarity index 100% rename from module/core/former/tests/inc/former_tests/subformer_subform_hashmap_explicit.rs rename to module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs new file mode 100644 index 0000000000..94883282a2 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs @@ -0,0 +1,116 @@ +#![ allow( dead_code ) ] + +#[ allow( unused_imports ) ] +use super::*; +#[ allow( unused_imports ) ] +use collection_tools::HashMap; + +// Child struct with Former derived for builder pattern support +#[ derive( Debug, PartialEq, former::Former ) ] +pub struct Child +{ + name : String, + description : String, +} + +// Parent struct to hold commands +#[ derive( Debug, PartialEq, former::Former ) ] +// #[ debug ] +// #[ derive( Debug, PartialEq ) ] +pub struct Parent +{ + #[ subform( setter = false ) ] + #[ scalar( setter = false ) ] // xxx : should not be required in this case + command : HashMap< String, Child >, +} + +// Use ChildFormer as custom subformer for ParentFormer to add commands by name. +impl< Definition > ParentFormer< Definition > +where + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn _children_add_with_closure< Former2, Definition2, Types2 >( self ) -> + Former2 + where + Types2 : former::FormerDefinitionTypes + < + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2 : former::FormerDefinition + < + Types = Types2, + End = former::FormingEndClosure< Types2 >, + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2::End : former::FormingEnd< Definition2::Types >, + Former2 : former::FormerBegin + < + Definition2, + >, + { + let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + if super_former.storage.command.is_none() + { + super_former.storage.command = Some( Default::default() ); + } + if let Some( ref mut children ) = super_former.storage.command + { + former::ContainerAdd::add + ( + children, + < < HashMap< String, Child > as former::Container >::Val as former::ValToElement< HashMap< String, Child > > > + ::val_to_element( former::StoragePreform::preform( substorage ) ) + ); + } + super_former + }; + Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + } + + #[ inline( always ) ] + pub fn command( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + self._command_add::< ChildFormer< _ >, _, >() + .name( name ) + } + +} + +impl former::ValToElement< HashMap< String, Child > > for Child +{ + type Element = ( String, Child ); + #[ inline( always ) ] + fn val_to_element( self ) -> Self::Element + { + ( self.name.clone(), self ) + } +} + +// == begin of generated + +// == end of generated + +#[ test ] +fn basic() +{ + + let got = Parent::former() + .command( "echo" ) + .description( "prints all subjects and properties" ) // sets additional properties using custom subformer + .end() + .command( "exit" ) + .description( "just exit" ) // Sets additional properties using using custom subformer + .end() + .form(); + + a_id!( got.command.len(), 2 ); + +} diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 9fec62425b..500f045455 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -62,13 +62,21 @@ where } if let Some( ref mut children ) = super_former.storage.children { - former::ContainerAdd::add( children, former::StoragePreform::preform( substorage ) ); + former::ContainerAdd::add + ( + children, + < < Vec< Child > as former::Container >::Val as former::ValToElement< Vec< Child > > > + ::val_to_element( former::StoragePreform::preform( substorage ) ) + ); } super_former }; Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) } + // < < #field_ty as former::Container >::Val as former::ValToElement< #field_ty > > + + // less generic, but more concise way to define custom subform setter #[ inline( always ) ] pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > @@ -86,6 +94,7 @@ where // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() // } + // it is generated #[ inline( always ) ] pub fn _child( self ) -> < < Vec< Child > as former::Container >::Element as former::EntityToFormer diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 695bc1ba02..d7b35cbc88 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -88,7 +88,10 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_hashmap; #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_hashmap_explicit; + mod subformer_subform_hashmap_custom; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_hashmap_custom2; + #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_and_container; #[ cfg( any( not( feature = "no_std" ) ) ) ] diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 2b0eb1460e..e68e624694 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -6,6 +6,7 @@ use proc_macro2::TokenStream; // zzz : explain concept of Storage // zzz : feature to have storage fields +// zzz : qqq : implement interfaces for other containers /// /// Definition of a field. From afd3bcf6390e0bf5d9a955a73b020201d10e28bc Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 10:14:39 +0300 Subject: [PATCH 391/533] former : experimenting --- .../core/collection_tools/src/constructors.rs | 8 +-- module/core/former/Cargo.toml | 2 +- .../subformer_subform_hashmap_custom2.rs | 68 ++++++++++++++++++- 3 files changed, 70 insertions(+), 8 deletions(-) diff --git a/module/core/collection_tools/src/constructors.rs b/module/core/collection_tools/src/constructors.rs index c96770bd06..1ea42a5e62 100644 --- a/module/core/collection_tools/src/constructors.rs +++ b/module/core/collection_tools/src/constructors.rs @@ -199,7 +199,7 @@ macro_rules! heap /// Creates a `HashMap` from a list of key-value pairs. /// /// The `hmap` macro allows for convenient creation of a `HashMap` with initial elements. -/// +/// /// # Origin /// /// This collection can be reexported from different crates: @@ -276,9 +276,9 @@ macro_rules! hmap /// Creates a `HashSet` from a list of elements. /// /// The `hset` macro allows for convenient creation of a `HashSet` with initial elements. -/// +/// /// # Origin -/// +/// /// This collection can be reexported from different crates: /// - from `std`, if `no_std` flag if off /// - from `hashbrown`, if `use_alloc` flag if on @@ -354,7 +354,7 @@ macro_rules! hset /// /// The `list` macro facilitates the creation of a `LinkedList` with initial elements. /// -/// +/// /// # Origin /// /// This collection is reexported from `alloc`. diff --git a/module/core/former/Cargo.toml b/module/core/former/Cargo.toml index cf6e7e15f5..f8a90a2d70 100644 --- a/module/core/former/Cargo.toml +++ b/module/core/former/Cargo.toml @@ -59,7 +59,7 @@ derive_from_components = [ "derive_components", "former_meta/derive_from_compone [dependencies] former_meta = { workspace = true } -collection_tools = { workspace = true, features = [ "collection_std" ] } +collection_tools = { workspace = true, features = [ "collection_std", "collection_constructors" ] } [dev-dependencies] diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs index 94883282a2..f696a5d042 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs @@ -6,7 +6,7 @@ use super::*; use collection_tools::HashMap; // Child struct with Former derived for builder pattern support -#[ derive( Debug, PartialEq, former::Former ) ] +#[ derive( Clone, Debug, PartialEq, former::Former ) ] pub struct Child { name : String, @@ -30,6 +30,7 @@ where Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, { + // more generic version #[ inline( always ) ] pub fn _children_add_with_closure< Former2, Definition2, Types2 >( self ) -> Former2 @@ -75,6 +76,7 @@ where Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) } + // reuse _command_add #[ inline( always ) ] pub fn command( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { @@ -82,6 +84,35 @@ where .name( name ) } + // that's how you should do custom subformer setters if you can't reuse _command_add + #[ inline( always ) ] + pub fn command2( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + let preformed = former::StoragePreform::preform( substorage ); + + if super_former.storage.command.is_none() + { + super_former.storage.command = Some( Default::default() ); + } + + // custom logic to add two instances to the container + super_former.storage.command.as_mut().unwrap() + .entry( format!( "{}_2", preformed.name ) ) + .or_insert( preformed.clone() ); + + super_former.storage.command.as_mut().unwrap() + .entry( preformed.name.clone() ) + .or_insert( preformed ); + + super_former + }; + let subformer = ChildAsSubformer::< Self, _ >::begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ); + subformer.name( name ) + } + } impl former::ValToElement< HashMap< String, Child > > for Child @@ -99,7 +130,7 @@ impl former::ValToElement< HashMap< String, Child > > for Child // == end of generated #[ test ] -fn basic() +fn standard() { let got = Parent::former() @@ -111,6 +142,37 @@ fn basic() .end() .form(); - a_id!( got.command.len(), 2 ); + let got = got.command.iter().map( | e | e.0 ).cloned().collect::< collection_tools::HashSet< String > >(); + let exp = collection_tools::hset! + [ + "echo".into(), + "exit".into(), + ]; + a_id!( got, exp ); + +} + +#[ test ] +fn custom() +{ + + let got = Parent::former() + .command2( "echo" ) + .description( "prints all subjects and properties" ) // sets additional properties using custom subformer + .end() + .command2( "exit" ) + .description( "just exit" ) // Sets additional properties using using custom subformer + .end() + .form(); + + let got = got.command.iter().map( | e | e.0 ).cloned().collect::< collection_tools::HashSet< String > >(); + let exp = collection_tools::hset! + [ + "echo".into(), + "echo_2".into(), + "exit".into(), + "exit_2".into(), + ]; + a_id!( got, exp ); } From 77ec17f6f7ffdb817fb6dacdbee8064a8606143d Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 10:15:16 +0300 Subject: [PATCH 392/533] former : experimenting --- .../former_tests/subformer_subform_hashmap_custom2.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs index f696a5d042..c7fdf0f006 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs @@ -98,14 +98,15 @@ where super_former.storage.command = Some( Default::default() ); } - // custom logic to add two instances to the container + // add instance to the container super_former.storage.command.as_mut().unwrap() - .entry( format!( "{}_2", preformed.name ) ) + .entry( preformed.name.clone() ) .or_insert( preformed.clone() ); + // custom logic to add two instances to the container super_former.storage.command.as_mut().unwrap() - .entry( preformed.name.clone() ) - .or_insert( preformed ); + .entry( format!( "{}_2", preformed.name ) ) + .or_insert( preformed.clone() ); super_former }; From 002077ddc333484749fceb71967b06ce862f5bdf Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 10:16:09 +0300 Subject: [PATCH 393/533] former : experimenting --- .../tests/inc/former_tests/subformer_subform_hashmap_custom.rs | 1 - .../tests/inc/former_tests/subformer_subform_hashmap_custom2.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs index 0d134e0263..24e3ce3712 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs @@ -20,7 +20,6 @@ pub struct Child pub struct Parent { #[ subform( setter = false ) ] - #[ scalar( setter = false ) ] // xxx : should not be required in this case command : HashMap< String, Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs index c7fdf0f006..e7f3053519 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs @@ -20,7 +20,6 @@ pub struct Child pub struct Parent { #[ subform( setter = false ) ] - #[ scalar( setter = false ) ] // xxx : should not be required in this case command : HashMap< String, Child >, } From 2010c652ad59ecc995b025a8a0a212da5d9d06d2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 10:17:07 +0300 Subject: [PATCH 394/533] former : experimenting --- .../subformer_subform_hashmap_custom.rs | 114 ++++++++++- .../subformer_subform_hashmap_custom2.rs | 178 ------------------ module/core/former/tests/inc/mod.rs | 2 - 3 files changed, 111 insertions(+), 183 deletions(-) delete mode 100644 module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs index 24e3ce3712..5f39444665 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs @@ -6,7 +6,7 @@ use super::*; use collection_tools::HashMap; // Child struct with Former derived for builder pattern support -#[ derive( Debug, PartialEq, former::Former ) ] +#[ derive( Clone, Debug, PartialEq, former::Former ) ] pub struct Child { name : String, @@ -29,6 +29,53 @@ where Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, { + // more generic version + #[ inline( always ) ] + pub fn _children_add_with_closure< Former2, Definition2, Types2 >( self ) -> + Former2 + where + Types2 : former::FormerDefinitionTypes + < + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2 : former::FormerDefinition + < + Types = Types2, + End = former::FormingEndClosure< Types2 >, + Storage = ChildFormerStorage, + Formed = Self, + Context = Self, + >, + Definition2::End : former::FormingEnd< Definition2::Types >, + Former2 : former::FormerBegin + < + Definition2, + >, + { + let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + if super_former.storage.command.is_none() + { + super_former.storage.command = Some( Default::default() ); + } + if let Some( ref mut children ) = super_former.storage.command + { + former::ContainerAdd::add + ( + children, + < < HashMap< String, Child > as former::Container >::Val as former::ValToElement< HashMap< String, Child > > > + ::val_to_element( former::StoragePreform::preform( substorage ) ) + ); + } + super_former + }; + Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) + } + + // reuse _command_add #[ inline( always ) ] pub fn command( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { @@ -36,6 +83,36 @@ where .name( name ) } + // that's how you should do custom subformer setters if you can't reuse _command_add + #[ inline( always ) ] + pub fn command2( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + let preformed = former::StoragePreform::preform( substorage ); + + if super_former.storage.command.is_none() + { + super_former.storage.command = Some( Default::default() ); + } + + // add instance to the container + super_former.storage.command.as_mut().unwrap() + .entry( preformed.name.clone() ) + .or_insert( preformed.clone() ); + + // custom logic to add two instances to the container + super_former.storage.command.as_mut().unwrap() + .entry( format!( "{}_2", preformed.name ) ) + .or_insert( preformed.clone() ); + + super_former + }; + let subformer = ChildAsSubformer::< Self, _ >::begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ); + subformer.name( name ) + } + } impl former::ValToElement< HashMap< String, Child > > for Child @@ -53,7 +130,7 @@ impl former::ValToElement< HashMap< String, Child > > for Child // == end of generated #[ test ] -fn basic() +fn custom1() { let got = Parent::former() @@ -65,6 +142,37 @@ fn basic() .end() .form(); - a_id!( got.command.len(), 2 ); + let got = got.command.iter().map( | e | e.0 ).cloned().collect::< collection_tools::HashSet< String > >(); + let exp = collection_tools::hset! + [ + "echo".into(), + "exit".into(), + ]; + a_id!( got, exp ); + +} + +#[ test ] +fn custom2() +{ + + let got = Parent::former() + .command2( "echo" ) + .description( "prints all subjects and properties" ) // sets additional properties using custom subformer + .end() + .command2( "exit" ) + .description( "just exit" ) // Sets additional properties using using custom subformer + .end() + .form(); + + let got = got.command.iter().map( | e | e.0 ).cloned().collect::< collection_tools::HashSet< String > >(); + let exp = collection_tools::hset! + [ + "echo".into(), + "echo_2".into(), + "exit".into(), + "exit_2".into(), + ]; + a_id!( got, exp ); } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs deleted file mode 100644 index e7f3053519..0000000000 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom2.rs +++ /dev/null @@ -1,178 +0,0 @@ -#![ allow( dead_code ) ] - -#[ allow( unused_imports ) ] -use super::*; -#[ allow( unused_imports ) ] -use collection_tools::HashMap; - -// Child struct with Former derived for builder pattern support -#[ derive( Clone, Debug, PartialEq, former::Former ) ] -pub struct Child -{ - name : String, - description : String, -} - -// Parent struct to hold commands -#[ derive( Debug, PartialEq, former::Former ) ] -// #[ debug ] -// #[ derive( Debug, PartialEq ) ] -pub struct Parent -{ - #[ subform( setter = false ) ] - command : HashMap< String, Child >, -} - -// Use ChildFormer as custom subformer for ParentFormer to add commands by name. -impl< Definition > ParentFormer< Definition > -where - Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, -{ - - // more generic version - #[ inline( always ) ] - pub fn _children_add_with_closure< Former2, Definition2, Types2 >( self ) -> - Former2 - where - Types2 : former::FormerDefinitionTypes - < - Storage = ChildFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2 : former::FormerDefinition - < - Types = Types2, - End = former::FormingEndClosure< Types2 >, - Storage = ChildFormerStorage, - Formed = Self, - Context = Self, - >, - Definition2::End : former::FormingEnd< Definition2::Types >, - Former2 : former::FormerBegin - < - Definition2, - >, - { - let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if super_former.storage.command.is_none() - { - super_former.storage.command = Some( Default::default() ); - } - if let Some( ref mut children ) = super_former.storage.command - { - former::ContainerAdd::add - ( - children, - < < HashMap< String, Child > as former::Container >::Val as former::ValToElement< HashMap< String, Child > > > - ::val_to_element( former::StoragePreform::preform( substorage ) ) - ); - } - super_former - }; - Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) - } - - // reuse _command_add - #[ inline( always ) ] - pub fn command( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - { - self._command_add::< ChildFormer< _ >, _, >() - .name( name ) - } - - // that's how you should do custom subformer setters if you can't reuse _command_add - #[ inline( always ) ] - pub fn command2( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - { - let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - let preformed = former::StoragePreform::preform( substorage ); - - if super_former.storage.command.is_none() - { - super_former.storage.command = Some( Default::default() ); - } - - // add instance to the container - super_former.storage.command.as_mut().unwrap() - .entry( preformed.name.clone() ) - .or_insert( preformed.clone() ); - - // custom logic to add two instances to the container - super_former.storage.command.as_mut().unwrap() - .entry( format!( "{}_2", preformed.name ) ) - .or_insert( preformed.clone() ); - - super_former - }; - let subformer = ChildAsSubformer::< Self, _ >::begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ); - subformer.name( name ) - } - -} - -impl former::ValToElement< HashMap< String, Child > > for Child -{ - type Element = ( String, Child ); - #[ inline( always ) ] - fn val_to_element( self ) -> Self::Element - { - ( self.name.clone(), self ) - } -} - -// == begin of generated - -// == end of generated - -#[ test ] -fn standard() -{ - - let got = Parent::former() - .command( "echo" ) - .description( "prints all subjects and properties" ) // sets additional properties using custom subformer - .end() - .command( "exit" ) - .description( "just exit" ) // Sets additional properties using using custom subformer - .end() - .form(); - - let got = got.command.iter().map( | e | e.0 ).cloned().collect::< collection_tools::HashSet< String > >(); - let exp = collection_tools::hset! - [ - "echo".into(), - "exit".into(), - ]; - a_id!( got, exp ); - -} - -#[ test ] -fn custom() -{ - - let got = Parent::former() - .command2( "echo" ) - .description( "prints all subjects and properties" ) // sets additional properties using custom subformer - .end() - .command2( "exit" ) - .description( "just exit" ) // Sets additional properties using using custom subformer - .end() - .form(); - - let got = got.command.iter().map( | e | e.0 ).cloned().collect::< collection_tools::HashSet< String > >(); - let exp = collection_tools::hset! - [ - "echo".into(), - "echo_2".into(), - "exit".into(), - "exit_2".into(), - ]; - a_id!( got, exp ); - -} diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index d7b35cbc88..9a4d60d0ea 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -89,8 +89,6 @@ mod former_tests mod subformer_subform_hashmap; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_hashmap_custom; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_hashmap_custom2; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_and_container; From 8aa305f7bfa8d958fefcf6d7392e3239b9fed120 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 10:22:03 +0300 Subject: [PATCH 395/533] former : experimenting --- .../examples/former_custom_subformer.rs | 81 +++++++------------ .../former_tests/subformer_subform_hashmap.rs | 2 - module/core/former_meta/src/derive/former.rs | 1 + 3 files changed, 32 insertions(+), 52 deletions(-) diff --git a/module/core/former/examples/former_custom_subformer.rs b/module/core/former/examples/former_custom_subformer.rs index b45bb089c4..7c5cbcbe77 100644 --- a/module/core/former/examples/former_custom_subformer.rs +++ b/module/core/former/examples/former_custom_subformer.rs @@ -1,5 +1,8 @@ //! example of how to use former of another structure as subformer of former of current one -//! function `command` integrate `CommandFormer` into `AggregatorFormer`. +//! function `child` integrate `ChildFormer` into `ParentFormer`. +// zzz : improve description + +// xxx : zzz : implement example former_custom_container #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] fn main() {} @@ -10,86 +13,64 @@ fn main() use std::collections::HashMap; use former::Former; - // Command struct with Former derived for builder pattern support + // Child struct with Former derived for builder pattern support #[ derive( Debug, PartialEq, Former ) ] - pub struct Command + pub struct Child { name : String, description : String, } - // Aggregator struct to hold commands + // Parent struct to hold children #[ derive( Debug, PartialEq, Former ) ] - pub struct Aggregator + pub struct Parent { - #[ subform ] - // #[ scalar( setter = false ) ] - command : HashMap< String, Command >, + #[ subform( setter = false ) ] + child : HashMap< String, Child >, } - // Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. - impl< Definition > AggregatorFormer< Definition > + // Use ChildFormer as custom subformer for ParentFormer to add children by name. + impl< Definition > ParentFormer< Definition > where - Definition : former::FormerDefinition< Storage = < Aggregator as former::EntityToStorage >::Storage >, + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, { #[ inline( always ) ] - pub fn command( self, name : &str ) -> CommandAsSubformer< Self, impl CommandAsSubformerEnd< Self > > + pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { - self._command_add::< CommandFormer< _ >, _, >() + self._child_add::< ChildFormer< _ >, _, >() .name( name ) } } - // // Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. - // impl< Definition > AggregatorFormer< Definition > - // where - // End : former::FormingEnd< Aggregator, Context >, - // { - // #[ inline( always ) ] - // pub fn command< IntoName >( self, name : IntoName ) -> CommandFormer< Self, impl former::FormingEnd< Command, Self > > - // where - // IntoName : core::convert::Into< String >, - // { - // let on_end = | command : Command, super_former : core::option::Option< Self > | -> Self - // { - // let mut super_former = super_former.unwrap(); - // if let Some( ref mut commands ) = super_former.storage.command - // { - // commands.insert( command.name.clone(), command ); - // } - // else - // { - // let mut commands: HashMap< String, Command > = Default::default(); - // commands.insert( command.name.clone(), command ); - // super_former.storage.command = Some( commands ); - // } - // super_former - // }; - // let former = CommandFormer::begin( None, Some( self ), on_end ); - // former.name( name ) - // } - // // xxx : review - // } + impl former::ValToElement< HashMap< String, Child > > for Child + { + type Element = ( String, Child ); + #[ inline( always ) ] + fn val_to_element( self ) -> Self::Element + { + ( self.name.clone(), self ) + } + } - let ca = Aggregator::former() - .command( "echo" ) + let ca = Parent::former() + .child( "echo" ) .description( "prints all subjects and properties" ) // sets additional properties using custom subformer .end() - .command( "exit" ) + .child( "exit" ) .description( "just exit" ) // Sets additional properties using using custom subformer .end() .form(); dbg!( &ca ); - // > &ca = Aggregator { - // > command: { - // > "echo": Command { + // > &ca = Parent { + // > child: { + // > "echo": Child { // > name: "echo", // > description: "prints all subjects and properties", // > }, - // > "exit": Command { + // > "exit": Child { // > name: "exit", // > description: "just exit", // > }, diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index 4f9c0e50f1..a6d3afe3c9 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -55,5 +55,3 @@ fn basic() a_id!( got.command.len(), 2 ); } - -// xxx2 : finish example former_custom_subformer diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index e68e624694..0ad6167318 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -306,6 +306,7 @@ struct AttributeScalarSetter setter : Option< bool >, } +#[ allow( dead_code ) ] impl AttributeScalarSetter { From 7955016e90c12cdd6201b6b7e4e4079029151ac8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 11:01:50 +0300 Subject: [PATCH 396/533] former : experimenting --- .../examples/former_custom_subformer.rs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/module/core/former/examples/former_custom_subformer.rs b/module/core/former/examples/former_custom_subformer.rs index 7c5cbcbe77..1daf9d0d32 100644 --- a/module/core/former/examples/former_custom_subformer.rs +++ b/module/core/former/examples/former_custom_subformer.rs @@ -1,12 +1,23 @@ -//! example of how to use former of another structure as subformer of former of current one -//! function `child` integrate `ChildFormer` into `ParentFormer`. -// zzz : improve description +// example former_custom_subformer.rs +//! This example demonstrates the use of the `Former` trait to implement nested builder patterns +//! in Rust using a parent-child relationship. The `Parent` struct uses `ChildFormer` as a custom +//! subformer to dynamically construct its `child` field, which is a `HashMap`. Each entry in the +//! `HashMap` represents a child with unique attributes managed through the `ChildFormer`. +//! +//! The `child` function in `ParentFormer` is particularly noteworthy as it leverages the +//! `ChildFormer` to add and configure children by their names directly within the builder pattern +//! of the `Parent`. This approach showcases the flexibility of the `former` crate in handling +//! complex nested data structures and providing a clear, fluent interface for object construction. + +// xxx2 : description is not good enough. it should be made stress that example show how to write custom subform setter. also dedicate a paragraph to explain difference between subform setter which returns former of element of container exposing interface to form an element and container setter which returns container former exposing interface to containet itself, not its element +// xxx2 : finish example former_custom_subformer // xxx : zzz : implement example former_custom_container #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] fn main() {} +// Ensure the example only compiles when the appropriate features are enabled. #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] fn main() { @@ -15,6 +26,7 @@ fn main() // Child struct with Former derived for builder pattern support #[ derive( Debug, PartialEq, Former ) ] + #[ debug ] pub struct Child { name : String, @@ -23,6 +35,7 @@ fn main() // Parent struct to hold children #[ derive( Debug, PartialEq, Former ) ] + #[ debug ] pub struct Parent { #[ subform( setter = false ) ] @@ -78,5 +91,3 @@ fn main() // > } } -// xxx2 : finish example former_custom_subformer - From e7329834a6088a265ba19fd91aec6ff9c282f440 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 11:33:59 +0300 Subject: [PATCH 397/533] former : experimenting --- .../former/examples/former_trivial_expaned.rs | 2 +- module/core/former/src/hash_map.rs | 10 --- ...rmer_subform_and_container_parametrized.rs | 33 +++++---- .../subformer_subform_setter_off.rs | 3 - module/core/former/tests/inc/mod.rs | 74 +++++++++---------- 5 files changed, 55 insertions(+), 67 deletions(-) diff --git a/module/core/former/examples/former_trivial_expaned.rs b/module/core/former/examples/former_trivial_expaned.rs index ecfdb4f474..0e4372585d 100644 --- a/module/core/former/examples/former_trivial_expaned.rs +++ b/module/core/former/examples/former_trivial_expaned.rs @@ -16,7 +16,7 @@ //! This approach abstracts away the need for manually implementing a builder for each struct, making code more readable and maintainable. //! -// xxx : regenerate +// zzz : regenerate // #![ allow( dead_code ) ] // diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index e1dae85b22..e6081f428c 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -65,16 +65,6 @@ where /// Inserts a key-value pair into the map. fn insert( &mut self, k : K, e : E ) -> Option< E >; - // /// Return former. - // #[ inline( always ) ] - // fn former< Definition : FormerDefinitionTypes >( self ) - // -> - // HashMapSubformer< K, E, Definition, (), impl FormingEnd< Self, Self > > - // { - // HashMapSubformer::begin_coercing( Some( self ), None, ReturnFormed ) - // } - // xxx : uncomment and cover by tests - } impl< K, E > HashMapLike< K, E > for HashMap< K, E > diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs index 2481026875..5a3fd6f974 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs @@ -5,27 +5,30 @@ use super::*; // xxx : make it working /// Parameter description. -// #[ derive( Debug, PartialEq, the_module::Former ) ] -#[ derive( Debug, PartialEq ) ] +#[ allow( explicit_outlives_requirements ) ] +#[ derive( Debug, PartialEq, the_module::Former ) ] +// #[ derive( Debug, PartialEq ) ] pub struct Child< 'child, T > +where + T : 'child + ?Sized, { name : String, is_mandatory : &'child T, } -// /// Parent required for the template. -// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] -// // #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] -// // #[ derive( Debug, Default, PartialEq ) ] -// pub struct Parent -// { -// // #[ subform ] -// #[ subform( name = _child ) ] -// #[ container( definition = former::VectorDefinition ) ] -// // #[ scalar( setter = false ) ] -// children : Vec< Child >, -// } -// +/// Parent required for the template. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent< 'child > +{ + // #[ subform ] + // #[ subform( name = _child ) ] + // #[ container() ] + // #[ scalar( setter = false ) ] + children : Vec< Child< 'child, str > >, +} + // impl< Definition > ParentFormer< Definition > // where // Definition : former::FormerDefinition, diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs b/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs index e24ab961a4..31a8d0c05f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs @@ -1,5 +1,4 @@ #![ allow( dead_code ) ] -// xxx : rename use super::*; @@ -19,8 +18,6 @@ pub struct Child pub struct Parent { #[ subform( setter = false ) ] - // #[ scalar( setter = false ) ] - // xxx : should be #[ scalar_setter = false ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 9a4d60d0ea..411bba3169 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -95,7 +95,6 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_and_container_parametrized; - // xxx } #[ cfg( feature = "derive_components" ) ] @@ -130,40 +129,39 @@ mod components_tests } -// only_for_terminal_module! -// { -// -// // stable have different information about error -// // that's why these tests are active only for nightly -// #[ test_tools::nightly ] -// #[ test ] -// fn former_trybuild() -// { -// -// println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); -// let t = test_tools::compiletime::TestCases::new(); -// -// // zzz : uncomment -// t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); -// t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); -// t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); -// -// } -// -// // stable have different information about error -// // that's why these tests are active only for nightly -// #[ test_tools::nightly ] -// #[ test ] -// fn components_trybuild() -// { -// -// println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); -// let _t = test_tools::compiletime::TestCases::new(); -// -// // zzz : make it working test -// //t.run( "tests/inc/compiletime/components_component_from_debug.rs" ); -// -// } -// -// } -// xxx \ No newline at end of file +only_for_terminal_module! +{ + + // stable have different information about error + // that's why these tests are active only for nightly + #[ test_tools::nightly ] + #[ test ] + fn former_trybuild() + { + + println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); + let t = test_tools::compiletime::TestCases::new(); + + // zzz : uncomment + t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); + t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); + t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); + + } + + // stable have different information about error + // that's why these tests are active only for nightly + #[ test_tools::nightly ] + #[ test ] + fn components_trybuild() + { + + println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); + let _t = test_tools::compiletime::TestCases::new(); + + // zzz : make it working test + //t.run( "tests/inc/compiletime/components_component_from_debug.rs" ); + + } + +} From 7344337cad5fa51a5f4d6839623e66016a2b2034 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 12:08:44 +0300 Subject: [PATCH 398/533] former : experimenting --- .../subformer_subform_and_container.rs | 2 +- ...rmer_subform_and_container_parametrized.rs | 38 +++++++++---------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs index b14c901f6a..cb88502e11 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs @@ -16,9 +16,9 @@ pub struct Child // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { - #[ scalar( name = children3 ) ] #[ subform( name = _child ) ] #[ container( name = children2 ) ] + #[ scalar( name = children3 ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs index 5a3fd6f974..4076a82542 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs @@ -22,29 +22,27 @@ where // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent< 'child > { - // #[ subform ] - // #[ subform( name = _child ) ] - // #[ container() ] - // #[ scalar( setter = false ) ] + #[ subform( name = _child ) ] + #[ container( name = children2 ) ] + #[ scalar( name = children3 ) ] children : Vec< Child< 'child, str > >, } -// impl< Definition > ParentFormer< Definition > -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, -// { -// -// #[ inline( always ) ] -// pub fn child( self, name : &str ) -> -// ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > -// { -// self._children_add -// ::< ChildFormer< _ >, _, >() -// .name( name ) -// } -// -// } +impl< 'child, Definition > ParentFormer< 'child, Definition > +where + Definition : former::FormerDefinition< Storage = < Parent< 'child > as former::EntityToStorage >::Storage >, +{ + + #[ inline( always ) ] + pub fn child( self, name : &str ) -> + ChildAsSubformer< 'child, str, Self, impl ChildAsSubformerEnd< 'child, str, Self > > + { + self._children_add + ::< ChildFormer< '_, _, _ >, _, >() + .name( name ) + } + +} // == begin of generated From 006ec641e07365dc1b56adb56c835c44364b9881 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 12:12:45 +0300 Subject: [PATCH 399/533] former : experimenting --- .../subformer_subform_and_container.rs | 2 +- ...rmer_subform_and_container_parametrized.rs | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs index cb88502e11..427b4511d3 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs @@ -51,6 +51,6 @@ where // == end of generated -include!( "./only_test/subformer_scalar_children3.rs" ); include!( "./only_test/subformer_subform_child.rs" ); include!( "./only_test/subformer_container_children2.rs" ); +include!( "./only_test/subformer_scalar_children3.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs index 4076a82542..e0106e3493 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs @@ -48,5 +48,48 @@ where // == end of generated + +#[ test ] +fn subform_child() +{ + + let got = Parent::former() + .child( "a" ).is_mandatory( "aa" ).end() + .child( "b" ).is_mandatory( "bb" ).end() + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : "aa" }, + Child { name : "b".to_string(), is_mandatory : "bb" }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} + +#[ test ] +fn subform_child_generated() +{ + + let got = Parent::former() + ._child().name( "a" ).is_mandatory( "aa" ).end() + ._child().name( "b" ).is_mandatory( "bb" ).end() + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), is_mandatory : "aa" }, + Child { name : "b".to_string(), is_mandatory : "bb" }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} + +// include!( "./only_test/subformer_subform_child.rs" ); +// include!( "./only_test/subformer_container_children2.rs" ); +// include!( "./only_test/subformer_scalar_children3.rs" ); + // include!( "./only_test/subformer_subform_child.rs" ); // include!( "./only_test/subformer_container.rs" ); From 2e3da44bcf54af9420c82616545ba0103fb62777 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 12:16:46 +0300 Subject: [PATCH 400/533] former : experimenting --- .../only_test/subformer_container.rs | 4 +- .../subformer_container_children2.rs | 4 +- .../only_test/subformer_scalar_children.rs | 8 +-- .../only_test/subformer_scalar_children3.rs | 8 +-- .../only_test/subformer_subform_child.rs | 8 +-- .../only_test/subformer_subform_children2.rs | 4 +- .../inc/former_tests/subformer_container.rs | 2 +- .../subformer_container_implicit.rs | 2 +- .../subformer_container_manual.rs | 2 +- .../former_tests/subformer_container_named.rs | 2 +- .../subformer_container_setter_off.rs | 2 +- .../subformer_container_setter_on.rs | 2 +- .../inc/former_tests/subformer_subform.rs | 2 +- .../subformer_subform_and_container.rs | 2 +- ...rmer_subform_and_container_parametrized.rs | 68 +++++++++++++++---- .../former_tests/subformer_subform_manual.rs | 2 +- .../former_tests/subformer_subform_named.rs | 2 +- .../subformer_subform_named_manual.rs | 2 +- .../subformer_subform_setter_off.rs | 2 +- .../subformer_subform_setter_on.rs | 2 +- 20 files changed, 85 insertions(+), 45 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_container.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_container.rs index 522ece211b..ce7f0f08dd 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_container.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_container.rs @@ -12,8 +12,8 @@ fn basic() let children = vec! [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, + Child { name : "a".to_string(), data : false }, + Child { name : "b".to_string(), data : false }, ]; let exp = Parent { children }; a_id!( got, exp ); diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_container_children2.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_container_children2.rs index 44aac2d08f..46fae25331 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_container_children2.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_container_children2.rs @@ -12,8 +12,8 @@ fn container() let children = vec! [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, + Child { name : "a".to_string(), data : false }, + Child { name : "b".to_string(), data : false }, ]; let exp = Parent { children }; a_id!( got, exp ); diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children.rs index 18a16fc71c..76fe8fa988 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children.rs @@ -5,8 +5,8 @@ fn scalar() let children = vec! [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, + Child { name : "a".to_string(), data : false }, + Child { name : "b".to_string(), data : false }, ]; let got = Parent::former() .children( children ) @@ -14,8 +14,8 @@ fn scalar() let children = vec! [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, + Child { name : "a".to_string(), data : false }, + Child { name : "b".to_string(), data : false }, ]; let exp = Parent { children }; a_id!( got, exp ); diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children3.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children3.rs index 379d2bfe82..ba2c97b459 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children3.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_scalar_children3.rs @@ -5,8 +5,8 @@ fn scalar() let children = vec! [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, + Child { name : "a".to_string(), data : false }, + Child { name : "b".to_string(), data : false }, ]; let got = Parent::former() .children3( children ) @@ -14,8 +14,8 @@ fn scalar() let children = vec! [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, + Child { name : "a".to_string(), data : false }, + Child { name : "b".to_string(), data : false }, ]; let exp = Parent { children }; a_id!( got, exp ); diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_subform_child.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_subform_child.rs index 1b42589eeb..f4167ee982 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_subform_child.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_subform_child.rs @@ -10,8 +10,8 @@ fn child() let children = vec! [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, + Child { name : "a".to_string(), data : false }, + Child { name : "b".to_string(), data : false }, ]; let exp = Parent { children }; a_id!( got, exp ); @@ -29,8 +29,8 @@ fn _child() let children = vec! [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, + Child { name : "a".to_string(), data : false }, + Child { name : "b".to_string(), data : false }, ]; let exp = Parent { children }; a_id!( got, exp ); diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_subform_children2.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_subform_children2.rs index 0fac0895c5..c869113680 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_subform_children2.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_subform_children2.rs @@ -10,8 +10,8 @@ fn subform() let children = vec! [ - Child { name : "a".to_string(), is_mandatory : false }, - Child { name : "b".to_string(), is_mandatory : false }, + Child { name : "a".to_string(), data : false }, + Child { name : "b".to_string(), data : false }, ]; let exp = Parent { children }; a_id!( got, exp ); diff --git a/module/core/former/tests/inc/former_tests/subformer_container.rs b/module/core/former/tests/inc/former_tests/subformer_container.rs index e39b9d47ac..10370499cf 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container.rs @@ -7,7 +7,7 @@ use super::*; pub struct Child { name : String, - is_mandatory : bool, + data : bool, } /// Parent required for the template. diff --git a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs index 58e4408f92..4852c502e2 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs @@ -7,7 +7,7 @@ use super::*; pub struct Child { name : String, - is_mandatory : bool, + data : bool, } /// Parent required for the template. diff --git a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs index 91caa85c5e..b73a4bd65f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs @@ -7,7 +7,7 @@ use super::*; pub struct Child { name : String, - is_mandatory : bool, + data : bool, } /// Parent required for the template. diff --git a/module/core/former/tests/inc/former_tests/subformer_container_named.rs b/module/core/former/tests/inc/former_tests/subformer_container_named.rs index a34969011f..75ce8845b6 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_named.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_named.rs @@ -7,7 +7,7 @@ use super::*; pub struct Child { name : String, - is_mandatory : bool, + data : bool, } /// Parent required for the template. diff --git a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs index c0b7f8f536..058875a48d 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs @@ -7,7 +7,7 @@ use super::*; pub struct Child { name : String, - is_mandatory : bool, + data : bool, } /// Parent diff --git a/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs index bbe4399746..0625c6fd94 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs @@ -7,7 +7,7 @@ use super::*; pub struct Child { name : String, - is_mandatory : bool, + data : bool, } /// Parent diff --git a/module/core/former/tests/inc/former_tests/subformer_subform.rs b/module/core/former/tests/inc/former_tests/subformer_subform.rs index 9d9112f406..e112d38ecd 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform.rs @@ -7,7 +7,7 @@ use super::*; pub struct Child { name : String, - is_mandatory : bool, + data : bool, } /// Parent diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs index 427b4511d3..6a3546113e 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container.rs @@ -7,7 +7,7 @@ use super::*; pub struct Child { name : String, - is_mandatory : bool, + data : bool, } /// Parent required for the template. diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs index e0106e3493..be521e5ad0 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs @@ -2,8 +2,6 @@ #[ allow( unused_imports ) ] use super::*; -// xxx : make it working - /// Parameter description. #[ allow( explicit_outlives_requirements ) ] #[ derive( Debug, PartialEq, the_module::Former ) ] @@ -13,7 +11,7 @@ where T : 'child + ?Sized, { name : String, - is_mandatory : &'child T, + data : &'child T, } /// Parent required for the template. @@ -54,14 +52,14 @@ fn subform_child() { let got = Parent::former() - .child( "a" ).is_mandatory( "aa" ).end() - .child( "b" ).is_mandatory( "bb" ).end() + .child( "a" ).data( "aa" ).end() + .child( "b" ).data( "bb" ).end() .form(); let children = vec! [ - Child { name : "a".to_string(), is_mandatory : "aa" }, - Child { name : "b".to_string(), is_mandatory : "bb" }, + Child { name : "a".to_string(), data : "aa" }, + Child { name : "b".to_string(), data : "bb" }, ]; let exp = Parent { children }; a_id!( got, exp ); @@ -73,14 +71,59 @@ fn subform_child_generated() { let got = Parent::former() - ._child().name( "a" ).is_mandatory( "aa" ).end() - ._child().name( "b" ).is_mandatory( "bb" ).end() + ._child().name( "a" ).data( "aa" ).end() + ._child().name( "b" ).data( "bb" ).end() + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), data : "aa" }, + Child { name : "b".to_string(), data : "bb" }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} + +#[ test ] +fn container() +{ + + let got = Parent::former() + .children2() + .add( Child::former().name( "a" ).data( "aa" ).form() ) + .add( Child::former().name( "b" ).data( "bb" ).form() ) + .end() .form(); let children = vec! [ - Child { name : "a".to_string(), is_mandatory : "aa" }, - Child { name : "b".to_string(), is_mandatory : "bb" }, + Child { name : "a".to_string(), data : "aa" }, + Child { name : "b".to_string(), data : "bb" }, + ]; + let exp = Parent { children }; + a_id!( got, exp ); + +} + + +#[ test ] +fn scalar() +{ + + let children = vec! + [ + Child { name : "a".to_string(), data : "aa" }, + Child { name : "b".to_string(), data : "bb" }, + ]; + let got = Parent::former() + .children3( children ) + .form(); + + let children = vec! + [ + Child { name : "a".to_string(), data : "aa" }, + Child { name : "b".to_string(), data : "bb" }, ]; let exp = Parent { children }; a_id!( got, exp ); @@ -90,6 +133,3 @@ fn subform_child_generated() // include!( "./only_test/subformer_subform_child.rs" ); // include!( "./only_test/subformer_container_children2.rs" ); // include!( "./only_test/subformer_scalar_children3.rs" ); - -// include!( "./only_test/subformer_subform_child.rs" ); -// include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 500f045455..4903c6e911 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -7,7 +7,7 @@ use super::*; pub struct Child { name : String, - is_mandatory : bool, + data : bool, } /// Parent required for the template. diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs index 14071581a9..89370b9881 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs @@ -7,7 +7,7 @@ use super::*; pub struct Child { name : String, - is_mandatory : bool, + data : bool, } /// Parent required for the template. diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs index d02fbf87b3..bbd8a76afa 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs @@ -7,7 +7,7 @@ use super::*; pub struct Child { name : String, - is_mandatory : bool, + data : bool, } // impl< Context, Formed, End > former::EntityToDefinition< Context, Formed, End > diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs b/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs index 31a8d0c05f..e5a2f9eb61 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_setter_off.rs @@ -7,7 +7,7 @@ use super::*; pub struct Child { name : String, - is_mandatory : bool, + data : bool, } /// Parent diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs b/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs index 7b59e9f9cb..29378ff208 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs @@ -7,7 +7,7 @@ use super::*; pub struct Child { name : String, - is_mandatory : bool, + data : bool, } /// Parent From 3a0c33ec90e6b3f112d0756353a55bdb888f080b Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 12:42:51 +0300 Subject: [PATCH 401/533] former : experimenting --- .../attribute_default_conflict.rs | 32 +++++ .../attribute_default_container.rs | 2 +- .../attribute_default_primitive.rs | 19 --- ...rmer_subform_and_container_parametrized.rs | 1 - module/core/former/tests/inc/mod.rs | 1 + module/core/former_meta/src/derive/former.rs | 111 ++++++++++++++---- module/core/former_meta/src/lib.rs | 6 +- 7 files changed, 123 insertions(+), 49 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/attribute_default_conflict.rs diff --git a/module/core/former/tests/inc/former_tests/attribute_default_conflict.rs b/module/core/former/tests/inc/former_tests/attribute_default_conflict.rs new file mode 100644 index 0000000000..eaf8c321fc --- /dev/null +++ b/module/core/former/tests/inc/former_tests/attribute_default_conflict.rs @@ -0,0 +1,32 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ derive( Debug, PartialEq, Default, the_module::Former ) ] +pub struct Struct1 +{ + #[ default( 31 ) ] + pub int_1 : i32, +} + +// + +tests_impls! +{ + fn test_complex() + { + let command = Struct1::former().form(); + + let expected = Struct1 + { + int_1 : 31, + }; + a_id!( command, expected ); + } +} + +// + +tests_index! +{ + test_complex, +} diff --git a/module/core/former/tests/inc/former_tests/attribute_default_container.rs b/module/core/former/tests/inc/former_tests/attribute_default_container.rs index fab0ba40cf..41fd0e968b 100644 --- a/module/core/former/tests/inc/former_tests/attribute_default_container.rs +++ b/module/core/former/tests/inc/former_tests/attribute_default_container.rs @@ -8,7 +8,7 @@ use std::collections::HashSet; pub struct Struct1 { - #[ default( vec![ 1, 2, 3 ] ) ] + #[ former( default = vec![ 1, 2, 3 ] ) ] vec_ints : Vec< i32 >, #[ default( hmap!{ 1 => 11 } ) ] hashmap_ints : HashMap< i32, i32 >, diff --git a/module/core/former/tests/inc/former_tests/attribute_default_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_default_primitive.rs index 21538d87c4..ec88212cfd 100644 --- a/module/core/former/tests/inc/former_tests/attribute_default_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_default_primitive.rs @@ -1,25 +1,6 @@ #[ allow( unused_imports ) ] use super::*; -// #[ allow( unused_imports ) ] -// use test_tools::exposed::*; -// -// only_for_aggregating_module! -// { -// #[ allow( unused_imports ) ] -// use wtools::meta::*; -// #[ allow( unused_imports ) ] -// use wtools::the_module::Former; -// } -// -// only_for_terminal_module! -// { -// #[ allow( unused_imports ) ] -// use meta_tools::*; -// #[ allow( unused_imports ) ] -// use the_module::Former; -// } - use std::collections::HashMap; use std::collections::HashSet; diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs index be521e5ad0..43347fc9ce 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_and_container_parametrized.rs @@ -46,7 +46,6 @@ where // == end of generated - #[ test ] fn subform_child() { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 411bba3169..4c372b934b 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -29,6 +29,7 @@ mod former_tests mod attribute_default_container; mod attribute_default_primitive; + mod attribute_default_conflict; mod attribute_perform; mod attribute_setter; mod attribute_alias; diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 0ad6167318..4a9386249c 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -5,7 +5,8 @@ use macro_tools::{ attr, diag, generic_params, generic_args, container_kind, typ use proc_macro2::TokenStream; // zzz : explain concept of Storage -// zzz : feature to have storage fields +// xxx : feature to have storage fields +// xxx : introduce namespaces // zzz : qqq : implement interfaces for other containers /// @@ -127,7 +128,7 @@ impl< 'a > FormerField< 'a > struct Attributes { - default : Option< AttributeDefault >, + config : Option< AttributeConfig >, scalar : Option< AttributeScalarSetter >, container : Option< AttributeContainerSetter >, subform : Option< AttributeSubformSetter >, @@ -137,7 +138,7 @@ impl Attributes { fn parse( attributes : & Vec< syn::Attribute > ) -> Result< Self > { - let mut default = None; + let mut config = None; let mut scalar = None; let mut container = None; let mut subform = None; @@ -154,15 +155,23 @@ impl Attributes match key_str.as_ref() { - "default" => + "former" => { match attr.meta { + // syn::Meta::List( ref meta_list ) => + // { + // config.replace( syn::parse2::< AttributeConfig >( meta_list.tokens.clone() )? ); + // }, syn::Meta::List( ref meta_list ) => { - default.replace( syn::parse2::< AttributeDefault >( meta_list.tokens.clone() )? ); + config.replace( syn::parse2::< AttributeConfig >( meta_list.tokens.clone() )? ); }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ default( val ) ], but got:\n {}", qt!{ #attr } ), + syn::Meta::Path( ref _path ) => + { + config.replace( syn::parse2::< AttributeConfig >( Default::default() )? ); + }, + _ => return_syn_err!( attr, "Expects an attribute of format #[ former( default = 13 ) ].\nGot: {}", qt!{ #attr } ), } } "scalar" => @@ -217,7 +226,7 @@ impl Attributes } } - Ok( Attributes { default, scalar, container, subform } ) + Ok( Attributes { config, scalar, container, subform } ) } } @@ -249,31 +258,85 @@ impl syn::parse::Parse for AttributeFormAfter } /// -/// Attribute to hold information about default value. +/// Attribute to hold configuration information about the field such as default value. /// /// `#[ default( 13 ) ]` /// -struct AttributeDefault +// struct AttributeConfig +// { +// // eq_token : syn::Token!{ = }, +// // paren_token : syn::token::Paren, +// expr : syn::Expr, +// } +// +// impl syn::parse::Parse for AttributeConfig +// { +// fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > +// { +// // let input2; +// Ok( Self +// { +// // paren_token : syn::parenthesized!( input2 in input ), +// // eq_token : input.parse()?, +// // expr : input2.parse()?, +// expr : input.parse()?, +// }) +// } +// } + +struct AttributeConfig { - // eq_token : syn::Token!{ = }, - // paren_token : syn::token::Paren, - expr : syn::Expr, + + // /// Optional identifier for naming the setter. + // name : Option< syn::Ident >, + // /// Controls the generation of a setter method. If false, a setter method is not generated. + // setter : Option< bool >, + + /// Default value to use for the field. + default : Option< syn::Expr >, } -impl syn::parse::Parse for AttributeDefault +impl AttributeConfig { - fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > +} + +impl syn::parse::Parse for AttributeConfig +{ + fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > { - // let input2; - Ok( Self + let mut default : Option< syn::Expr > = None; + + while !input.is_empty() { - // paren_token : syn::parenthesized!( input2 in input ), - // eq_token : input.parse()?, - // expr : input2.parse()?, - expr : input.parse()?, - }) + let lookahead = input.lookahead1(); + if lookahead.peek( syn::Ident ) + { + let ident : syn::Ident = input.parse()?; + if ident == "default" + { + input.parse::< syn::Token![ = ] >()?; + default = Some( input.parse()? ); + } + else + { + return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'default'. For example: `former( default = 13 )`", ident ) ) ); + } + } + else + { + return Err( syn::Error::new( input.span(), "Expected 'default'. For example: `former( default = 13 )`" ) ); + } + + // Optional comma handling + if input.peek( syn::Token![ , ] ) + { + input.parse::< syn::Token![ , ] >()?; + } + } + + Ok( Self { default } ) } } @@ -657,8 +720,8 @@ fn field_form_map( field : &FormerField< '_ > ) -> Result< TokenStream > { let ident = field.ident; let ty = field.ty; - let default = field.attrs.default.as_ref() - .map( | attr_default | &attr_default.expr ); + let default = field.attrs.config.as_ref() + .map( | attr | &attr.default ); let tokens = if field.is_optional { @@ -1546,8 +1609,6 @@ pub fn performer< 'a > { syn::Meta::List( ref meta_list ) => { - // default.replace( syn::parse2::< AttributeDefault >( meta_list.tokens.clone() )? ); - // let attr_perform = syn::parse2::< AttributeFormAfter >( attr.tokens.clone() )?; let attr_perform = syn::parse2::< AttributeFormAfter >( meta_list.tokens.clone() )?; let signature = &attr_perform.signature; let generics = &signature.generics; diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index 1ade4d0fe4..47e048bb45 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -55,7 +55,7 @@ mod derive /// #[ perform( fn greet_user() ) ] /// pub struct UserProfile /// { -/// #[default(1)] +/// #[ former( default = 1 ) ] /// age : i32, /// /// username : String, @@ -272,8 +272,7 @@ mod derive #[ cfg( feature = "enabled" ) ] #[ cfg( feature = "derive_former" ) ] -// xxx : rename default -#[ proc_macro_derive( Former, attributes( debug, perform, default, scalar, container, subform ) ) ] +#[ proc_macro_derive( Former, attributes( debug, perform, former, scalar, container, subform ) ) ] pub fn former( input : proc_macro::TokenStream ) -> proc_macro::TokenStream { let result = derive::former::former( input ); @@ -667,6 +666,7 @@ pub fn component_assign( input : proc_macro::TokenStream ) -> proc_macro::TokenS /// take_smaller_opts( &options2 ); /// ``` /// + #[ cfg( feature = "enabled" ) ] #[ cfg( all( feature = "derive_component_assign", feature = "derive_components_assign" ) ) ] #[ proc_macro_derive( ComponentsAssign, attributes( debug ) ) ] From 543146912ed65d9716bd26611173f5e8b4d2019d Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 12:43:52 +0300 Subject: [PATCH 402/533] former : experimenting --- module/core/former/Readme.md | 6 +++--- module/core/former/examples/former_custom_default.rs | 6 +++--- .../inc/former_tests/attribute_default_conflict.rs | 2 +- .../inc/former_tests/attribute_default_container.rs | 10 +++++----- .../inc/former_tests/attribute_default_primitive.rs | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 8f1b1b6b5f..249a65220e 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -381,11 +381,11 @@ use former::Former; #[ derive( Debug, PartialEq, Former ) ] pub struct ExampleStruct { - #[ default( 5 ) ] + #[ former( default = 5 ) ] number : i32, - #[ default( "Hello, Former!".to_string() ) ] + #[ former( default = "Hello, Former!".to_string() ) ] greeting : String, - #[ default( vec![ 10, 20, 30 ] ) ] + #[ former( default = vec![ 10, 20, 30 ] ) ] numbers : Vec< i32 >, } diff --git a/module/core/former/examples/former_custom_default.rs b/module/core/former/examples/former_custom_default.rs index 2cc73f3fc0..7ebb39e432 100644 --- a/module/core/former/examples/former_custom_default.rs +++ b/module/core/former/examples/former_custom_default.rs @@ -21,11 +21,11 @@ fn main() #[ derive( Debug, PartialEq, Former ) ] pub struct ExampleStruct { - #[ default( 5 ) ] + #[ former( default = 5 ) ] number : i32, - #[ default( "Hello, Former!".to_string() ) ] + #[ former( default = "Hello, Former!".to_string() ) ] greeting : String, - #[ default( vec![ 10, 20, 30 ] ) ] + #[ former( default = vec![ 10, 20, 30 ] ) ] numbers : Vec< i32 >, } diff --git a/module/core/former/tests/inc/former_tests/attribute_default_conflict.rs b/module/core/former/tests/inc/former_tests/attribute_default_conflict.rs index eaf8c321fc..6a930e1014 100644 --- a/module/core/former/tests/inc/former_tests/attribute_default_conflict.rs +++ b/module/core/former/tests/inc/former_tests/attribute_default_conflict.rs @@ -4,7 +4,7 @@ use super::*; #[ derive( Debug, PartialEq, Default, the_module::Former ) ] pub struct Struct1 { - #[ default( 31 ) ] + #[ former( default = 31 ) ] pub int_1 : i32, } diff --git a/module/core/former/tests/inc/former_tests/attribute_default_container.rs b/module/core/former/tests/inc/former_tests/attribute_default_container.rs index 41fd0e968b..a1e1e07132 100644 --- a/module/core/former/tests/inc/former_tests/attribute_default_container.rs +++ b/module/core/former/tests/inc/former_tests/attribute_default_container.rs @@ -10,16 +10,16 @@ pub struct Struct1 #[ former( default = vec![ 1, 2, 3 ] ) ] vec_ints : Vec< i32 >, - #[ default( hmap!{ 1 => 11 } ) ] + #[ former( default = hmap!{ 1 => 11 } ) ] hashmap_ints : HashMap< i32, i32 >, - #[ default( hset!{ 11 } ) ] + #[ former( default = hset!{ 11 } ) ] hashset_ints : HashSet< i32 >, - #[ default( vec![ "abc".to_string(), "def".to_string() ] ) ] + #[ former( default = vec![ "abc".to_string(), "def".to_string() ] ) ] vec_strings : Vec< String >, - #[ default( hmap!{ "k1".to_string() => "v1".to_string() } ) ] + #[ former( default = hmap!{ "k1".to_string() => "v1".to_string() } ) ] hashmap_strings : HashMap< String, String >, - #[ default( hset!{ "k1".to_string() } ) ] + #[ former( default = hset!{ "k1".to_string() } ) ] hashset_strings : HashSet< String >, } diff --git a/module/core/former/tests/inc/former_tests/attribute_default_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_default_primitive.rs index ec88212cfd..609915ad5a 100644 --- a/module/core/former/tests/inc/former_tests/attribute_default_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_default_primitive.rs @@ -7,13 +7,13 @@ use std::collections::HashSet; #[ derive( Debug, PartialEq, the_module::Former ) ] pub struct Struct1 { - #[ default( 31 ) ] + #[ former( default = 31 ) ] pub int_1 : i32, - #[ default( "abc" ) ] + #[ former( default = "abc" ) ] string_1 : String, - #[ default( 31 ) ] + #[ former( default = 31 ) ] int_optional_1 : Option< i32 >, - #[ default( "abc" ) ] + #[ former( default = "abc" ) ] string_optional_1 : Option< String >, vec_1 : Vec< String >, From dd8d5c5b49a688a1af9e57281cb3fc6e8e014076 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 12:45:32 +0300 Subject: [PATCH 403/533] former : experimenting --- module/core/former/tests/inc/compiletime/former_bad_attr.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/core/former/tests/inc/compiletime/former_bad_attr.stderr b/module/core/former/tests/inc/compiletime/former_bad_attr.stderr index bc5a44f0c1..085d07fc00 100644 --- a/module/core/former/tests/inc/compiletime/former_bad_attr.stderr +++ b/module/core/former/tests/inc/compiletime/former_bad_attr.stderr @@ -8,4 +8,4 @@ error: cannot find attribute `defaultx` in this scope --> tests/inc/compiletime/former_bad_attr.rs:6:6 | 6 | #[ defaultx( 31 ) ] - | ^^^^^^^^ help: a derive helper attribute with a similar name exists: `default` + | ^^^^^^^^ From a38c34a39fdf1992bce21291de6f8629e56a4cb9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 12:53:21 +0300 Subject: [PATCH 404/533] former : experimenting --- .../attribute_storage_primitive.rs | 35 +++++++++++++++++++ module/core/former/tests/inc/mod.rs | 1 + 2 files changed, 36 insertions(+) create mode 100644 module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs new file mode 100644 index 0000000000..c692d974c0 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -0,0 +1,35 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ derive( Debug, PartialEq, the_module::Former ) ] +pub struct Struct1 +{ + #[ former( default = 31 ) ] + pub int_1 : i32, + #[ former( default = "abc" ) ] + string_optional_1 : Option< String >, +} + +// + +tests_impls! +{ + fn test_complex() + { + let command = Struct1::former().form(); + + let expected = Struct1 + { + int_1 : 31, + string_optional_1 : Some( "abc".to_string() ), + }; + a_id!( command, expected ); + } +} + +// + +tests_index! +{ + test_complex, +} diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 4c372b934b..e8063254f1 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -30,6 +30,7 @@ mod former_tests mod attribute_default_container; mod attribute_default_primitive; mod attribute_default_conflict; + mod attribute_storage_primitive; mod attribute_perform; mod attribute_setter; mod attribute_alias; From b7089aa8c81cc84b25d7fb55ca77ed8e4176efec Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 16:16:42 +0300 Subject: [PATCH 405/533] former : experimenting --- .../attribute_storage_primitive.rs | 30 +-- module/core/former_meta/src/derive/former.rs | 172 +++++++++++------- module/core/former_meta/src/lib.rs | 12 +- 3 files changed, 131 insertions(+), 83 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs index c692d974c0..c38446603e 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -2,12 +2,15 @@ use super::*; #[ derive( Debug, PartialEq, the_module::Former ) ] +// #[ debug ] +// #[ derive( Debug, PartialEq ) ] + #[ storage_fields( a : i32, b : Option< String > ) ] pub struct Struct1 { - #[ former( default = 31 ) ] - pub int_1 : i32, - #[ former( default = "abc" ) ] - string_optional_1 : Option< String >, + // #[ former( only_storage = true ) ] + pub a : i32, + // #[ former( only_storage = true ) ] + b : Option< String >, } // @@ -16,18 +19,19 @@ tests_impls! { fn test_complex() { - let command = Struct1::former().form(); - - let expected = Struct1 - { - int_1 : 31, - string_optional_1 : Some( "abc".to_string() ), - }; - a_id!( command, expected ); + // let got = Struct1::former().a( 13 ).b( "abc" ).form(); + // let exp = Struct1 + // { + // a : 13, + // b : Some( "abc".to_string() ), + // }; + // a_id!( got, exp ); } } -// +// == begin of generated + +// == end of generated tests_index! { diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/derive/former.rs index 4a9386249c..a4eec6399b 100644 --- a/module/core/former_meta/src/derive/former.rs +++ b/module/core/former_meta/src/derive/former.rs @@ -16,7 +16,7 @@ use proc_macro2::TokenStream; #[ allow( dead_code ) ] struct FormerField< 'a > { - pub attrs : Attributes, + pub attrs : FieldAttributes, pub vis : &'a syn::Visibility, pub ident : &'a syn::Ident, pub colon_token : &'a Option< syn::token::Colon >, @@ -123,10 +123,85 @@ impl< 'a > FormerField< 'a > } /// -/// Attributes of the field. +/// Attributes of a struct. /// -struct Attributes +struct StructAttributes +{ + perform : Option< AttributePerform >, +} + +impl StructAttributes +{ + // fn from_attrs( attributes : & Vec< syn::Attribute > ) -> Result< Self > + fn from_attrs< 'a >( attrs : impl Iterator< Item = &'a syn::Attribute > ) -> Result< Self > + { + let mut perform = None; + for attr in attrs + { + let key_ident = attr.path().get_ident() + .ok_or_else( || syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ) )?; + let key_str = format!( "{}", key_ident ); + + if attr::is_standard( &key_str ) + { + continue; + } + + match key_str.as_ref() + { + "storage_fields" => + { + } + "perform" => + { + } + "debug" => + { + } + _ => + { + return Err( syn_err!( attr, "Known structure attirbutes are : `storage_fields`, `perform`, `debug`.\nUnknown structure attribute : {}", qt!{ #attr } ) ); + } + } + } + + Ok( StructAttributes { perform } ) + } +} + +/// +/// Attribute to hold information about method to call after form. +/// +/// `#[ perform( fn after1< 'a >() -> Option< &'a str > ) ]` +/// + +// xxx : move out +struct AttributePerform +{ + // paren_token : syn::token::Paren, + signature : syn::Signature, +} + +impl syn::parse::Parse for AttributePerform +{ + fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > + { + // let input2; + Ok( Self + { + // paren_token : syn::parenthesized!( input2 in input ), + // signature : input2.parse()?, + signature : input.parse()?, + }) + } +} + +/// +/// Attributes of a field. +/// + +struct FieldAttributes { config : Option< AttributeConfig >, scalar : Option< AttributeScalarSetter >, @@ -134,15 +209,16 @@ struct Attributes subform : Option< AttributeSubformSetter >, } -impl Attributes +impl FieldAttributes { - fn parse( attributes : & Vec< syn::Attribute > ) -> Result< Self > + // fn from_attrs( attributes : & Vec< syn::Attribute > ) -> Result< Self > + fn from_attrs< 'a >( attrs : impl Iterator< Item = &'a syn::Attribute > ) -> Result< Self > { let mut config = None; let mut scalar = None; let mut container = None; let mut subform = None; - for attr in attributes + for attr in attrs { let key_ident = attr.path().get_ident() .ok_or_else( || syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ) )?; @@ -221,39 +297,12 @@ impl Attributes } _ => { - return Err( syn_err!( attr, "Unknown attribute {}", qt!{ #attr } ) ); + return Err( syn_err!( attr, "Unknown field attribute {}", qt!{ #attr } ) ); } } } - Ok( Attributes { config, scalar, container, subform } ) - } -} - -/// -/// Attribute to hold information about method to call after form. -/// -/// `#[ perform( fn after1< 'a >() -> Option< &'a str > ) ]` -/// - - -struct AttributeFormAfter -{ - // paren_token : syn::token::Paren, - signature : syn::Signature, -} - -impl syn::parse::Parse for AttributeFormAfter -{ - fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > - { - // let input2; - Ok( Self - { - // paren_token : syn::parenthesized!( input2 in input ), - // signature : input2.parse()?, - signature : input.parse()?, - }) + Ok( FieldAttributes { config, scalar, container, subform } ) } } @@ -263,39 +312,15 @@ impl syn::parse::Parse for AttributeFormAfter /// `#[ default( 13 ) ]` /// - -// struct AttributeConfig -// { -// // eq_token : syn::Token!{ = }, -// // paren_token : syn::token::Paren, -// expr : syn::Expr, -// } -// -// impl syn::parse::Parse for AttributeConfig -// { -// fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > -// { -// // let input2; -// Ok( Self -// { -// // paren_token : syn::parenthesized!( input2 in input ), -// // eq_token : input.parse()?, -// // expr : input2.parse()?, -// expr : input.parse()?, -// }) -// } -// } - struct AttributeConfig { - // /// Optional identifier for naming the setter. - // name : Option< syn::Ident >, - // /// Controls the generation of a setter method. If false, a setter method is not generated. - // setter : Option< bool >, - /// Default value to use for the field. default : Option< syn::Expr >, + /// Such field should be present only in storage and should not be present in structure itself. + /// That might be useful for parametrization of forming process. + only_storage : Option< bool >, + } impl AttributeConfig @@ -307,6 +332,7 @@ impl syn::parse::Parse for AttributeConfig fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > { let mut default : Option< syn::Expr > = None; + let mut only_storage : Option< bool > = None; while !input.is_empty() { @@ -319,11 +345,18 @@ impl syn::parse::Parse for AttributeConfig input.parse::< syn::Token![ = ] >()?; default = Some( input.parse()? ); } + else if ident == "only_storage" + { + input.parse::< syn::Token![ = ] >()?; + let value : syn::LitBool = input.parse()?; + only_storage = Some( value.value() ); + } else { return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'default'. For example: `former( default = 13 )`", ident ) ) ); } } + else { return Err( syn::Error::new( input.span(), "Expected 'default'. For example: `former( default = 13 )`" ) ); @@ -336,7 +369,7 @@ impl syn::parse::Parse for AttributeConfig } } - Ok( Self { default } ) + Ok( Self { default, only_storage } ) } } @@ -720,8 +753,8 @@ fn field_form_map( field : &FormerField< '_ > ) -> Result< TokenStream > { let ident = field.ident; let ty = field.ty; - let default = field.attrs.config.as_ref() - .map( | attr | &attr.default ); + let default : Option< &syn::Expr > = field.attrs.config.as_ref() + .and_then( | attr | attr.default.as_ref() ); let tokens = if field.is_optional { @@ -1609,7 +1642,7 @@ pub fn performer< 'a > { syn::Meta::List( ref meta_list ) => { - let attr_perform = syn::parse2::< AttributeFormAfter >( meta_list.tokens.clone() )?; + let attr_perform = syn::parse2::< AttributePerform >( meta_list.tokens.clone() )?; let signature = &attr_perform.signature; let generics = &signature.generics; perform_generics = qt!{ #generics }; @@ -1656,6 +1689,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > Err( err ) => return Err( err ), }; let has_debug = attr::has_debug( ast.attrs.iter() )?; + let struct_attrs = StructAttributes::from_attrs( ast.attrs.iter() )?; + let example_of_custom_setter = false; /* names */ @@ -1778,7 +1813,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_fields : Vec< Result< FormerField< '_ > > > = fields.iter().map( | field | { - let attrs = Attributes::parse( &field.attrs )?; + let attrs = FieldAttributes::from_attrs( field.attrs.iter() )?; let vis = &field.vis; let ident = field.ident.as_ref() .ok_or_else( || syn_err!( field, "Expected that each field has key, but some does not:\n {}", qt!{ #field } ) )?; @@ -2305,4 +2340,3 @@ where Ok( result ) } - diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index 47e048bb45..2d1215861c 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -272,7 +272,17 @@ mod derive #[ cfg( feature = "enabled" ) ] #[ cfg( feature = "derive_former" ) ] -#[ proc_macro_derive( Former, attributes( debug, perform, former, scalar, container, subform ) ) ] +#[ + proc_macro_derive + ( + Former, + attributes + ( + debug, perform, storage_fields, // struct attributes + former, scalar, container, subform, // field attributes + ) + ) +] pub fn former( input : proc_macro::TokenStream ) -> proc_macro::TokenStream { let result = derive::former::former( input ); From 76bdee100577630e67ab1af1707122808c7e518b Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 16:18:24 +0300 Subject: [PATCH 406/533] former : experimenting --- .../src/{derive => component}/component_assign.rs | 0 .../src/{derive => component}/component_from.rs | 0 .../src/{derive => component}/components_assign.rs | 0 .../src/{derive => component}/from_components.rs | 0 module/core/former_meta/src/{derive => }/former.rs | 0 module/core/former_meta/src/lib.rs | 8 +++++--- 6 files changed, 5 insertions(+), 3 deletions(-) rename module/core/former_meta/src/{derive => component}/component_assign.rs (100%) rename module/core/former_meta/src/{derive => component}/component_from.rs (100%) rename module/core/former_meta/src/{derive => component}/components_assign.rs (100%) rename module/core/former_meta/src/{derive => component}/from_components.rs (100%) rename module/core/former_meta/src/{derive => }/former.rs (100%) diff --git a/module/core/former_meta/src/derive/component_assign.rs b/module/core/former_meta/src/component/component_assign.rs similarity index 100% rename from module/core/former_meta/src/derive/component_assign.rs rename to module/core/former_meta/src/component/component_assign.rs diff --git a/module/core/former_meta/src/derive/component_from.rs b/module/core/former_meta/src/component/component_from.rs similarity index 100% rename from module/core/former_meta/src/derive/component_from.rs rename to module/core/former_meta/src/component/component_from.rs diff --git a/module/core/former_meta/src/derive/components_assign.rs b/module/core/former_meta/src/component/components_assign.rs similarity index 100% rename from module/core/former_meta/src/derive/components_assign.rs rename to module/core/former_meta/src/component/components_assign.rs diff --git a/module/core/former_meta/src/derive/from_components.rs b/module/core/former_meta/src/component/from_components.rs similarity index 100% rename from module/core/former_meta/src/derive/from_components.rs rename to module/core/former_meta/src/component/from_components.rs diff --git a/module/core/former_meta/src/derive/former.rs b/module/core/former_meta/src/former.rs similarity index 100% rename from module/core/former_meta/src/derive/former.rs rename to module/core/former_meta/src/former.rs diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index 2d1215861c..b00af52800 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -4,7 +4,8 @@ #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] #[ cfg( feature = "enabled" ) ] -mod derive +#[ cfg( feature = "derive_component_from" ) ] +mod component { //! @@ -14,8 +15,6 @@ mod derive #[ allow( unused_imports ) ] use macro_tools::prelude::*; - #[ cfg( feature = "derive_former" ) ] - pub mod former; #[ cfg( feature = "derive_component_from" ) ] pub mod component_from; #[ cfg( feature = "derive_from_components" ) ] @@ -27,6 +26,9 @@ mod derive } +#[ cfg( feature = "derive_former" ) ] +pub mod former; + // zzz : outdated /// /// Derive macro to generate former for a structure. Former is variation of Builder Pattern. From 6378e7cda17c5a8ce3495767ce2cf3f11e53de16 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 16:23:01 +0300 Subject: [PATCH 407/533] former : experimenting --- .../src/{former.rs => derive_former.rs} | 0 module/core/former_meta/src/lib.rs | 14 ++++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) rename module/core/former_meta/src/{former.rs => derive_former.rs} (100%) diff --git a/module/core/former_meta/src/former.rs b/module/core/former_meta/src/derive_former.rs similarity index 100% rename from module/core/former_meta/src/former.rs rename to module/core/former_meta/src/derive_former.rs diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index b00af52800..4237eb7a08 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -26,8 +26,10 @@ mod component } +#[ allow( unused_imports ) ] +use macro_tools::prelude::*; #[ cfg( feature = "derive_former" ) ] -pub mod former; +mod derive_former; // zzz : outdated /// @@ -287,7 +289,7 @@ pub mod former; ] pub fn former( input : proc_macro::TokenStream ) -> proc_macro::TokenStream { - let result = derive::former::former( input ); + let result = derive_former::former( input ); match result { Ok( stream ) => stream.into(), @@ -340,7 +342,7 @@ pub fn former( input : proc_macro::TokenStream ) -> proc_macro::TokenStream #[ proc_macro_derive( ComponentFrom, attributes( debug ) ) ] pub fn component_from( input : proc_macro::TokenStream ) -> proc_macro::TokenStream { - let result = derive::component_from::component_from( input ); + let result = component::component_from::component_from( input ); match result { Ok( stream ) => stream.into(), @@ -431,7 +433,7 @@ pub fn component_from( input : proc_macro::TokenStream ) -> proc_macro::TokenStr #[ proc_macro_derive( ComponentAssign, attributes( debug ) ) ] pub fn component_assign( input : proc_macro::TokenStream ) -> proc_macro::TokenStream { - let result = derive::component_assign::component_assign( input ); + let result = component::component_assign::component_assign( input ); match result { Ok( stream ) => stream.into(), @@ -684,7 +686,7 @@ pub fn component_assign( input : proc_macro::TokenStream ) -> proc_macro::TokenS #[ proc_macro_derive( ComponentsAssign, attributes( debug ) ) ] pub fn components_assign( input : proc_macro::TokenStream ) -> proc_macro::TokenStream { - let result = derive::components_assign::components_assign( input ); + let result = component::components_assign::components_assign( input ); match result { Ok( stream ) => stream.into(), @@ -785,7 +787,7 @@ pub fn components_assign( input : proc_macro::TokenStream ) -> proc_macro::Token #[ proc_macro_derive( FromComponents, attributes( debug ) ) ] pub fn from_components( input : proc_macro::TokenStream ) -> proc_macro::TokenStream { - let result = derive::from_components::from_components( input ); + let result = component::from_components::from_components( input ); match result { Ok( stream ) => stream.into(), From 48e93c10ccd3f8a50292e341b7fb6dcd7c293530 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 16:29:32 +0300 Subject: [PATCH 408/533] former : experimenting --- module/core/former_meta/src/derive_former.rs | 624 +----------------- .../former_meta/src/derive_former/field.rs | 118 ++++ .../src/derive_former/field_attrs.rs | 427 ++++++++++++ .../src/derive_former/struct_attrs.rs | 84 +++ 4 files changed, 635 insertions(+), 618 deletions(-) create mode 100644 module/core/former_meta/src/derive_former/field.rs create mode 100644 module/core/former_meta/src/derive_former/field_attrs.rs create mode 100644 module/core/former_meta/src/derive_former/struct_attrs.rs diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index a4eec6399b..e754e898ac 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -9,624 +9,12 @@ use proc_macro2::TokenStream; // xxx : introduce namespaces // zzz : qqq : implement interfaces for other containers -/// -/// Definition of a field. -/// - -#[ allow( dead_code ) ] -struct FormerField< 'a > -{ - pub attrs : FieldAttributes, - pub vis : &'a syn::Visibility, - pub ident : &'a syn::Ident, - pub colon_token : &'a Option< syn::token::Colon >, - pub ty : &'a syn::Type, - pub non_optional_ty : &'a syn::Type, - pub is_optional : bool, - pub of_type : container_kind::ContainerKind, -} - -impl< 'a > FormerField< 'a > -{ - - /// Get name of scalar setter. - pub fn scalar_setter_name( &self ) -> &syn::Ident - { - if let Some( ref attr ) = self.attrs.scalar - { - if let Some( ref name ) = attr.name - { - return name - } - } - return &self.ident; - } - - /// Get name of setter for container if such setter should be generated. - pub fn container_setter_name( &self ) -> Option< &syn::Ident > - { - - if let Some( ref attr ) = self.attrs.container - { - if attr.setter() - { - if let Some( ref name ) = attr.name - { - return Some( &name ) - } - else - { - return Some( &self.ident ) - } - } - } - - return None; - } - - /// Get name of setter for subform if such setter should be generated. - pub fn subform_setter_name( &self ) -> Option< &syn::Ident > - { - - if let Some( ref attr ) = self.attrs.subform - { - if attr.setter() - { - if let Some( ref name ) = attr.name - { - return Some( &name ) - } - else - { - return Some( &self.ident ) - } - } - } - - return None; - } - - /// Is scalar setter required. Does not if container of subformer setter requested. - pub fn scalar_setter_required( &self ) -> bool - { - - let mut explicit = false; - if let Some( ref attr ) = self.attrs.scalar - { - if let Some( setter ) = attr.setter - { - if setter == false - { - return false - } - explicit = true; - } - if let Some( ref _name ) = attr.name - { - explicit = true; - } - } - - if self.attrs.container.is_some() && !explicit - { - return false; - } - - if self.attrs.subform.is_some() && !explicit - { - return false; - } - - return true; - } - -} - -/// -/// Attributes of a struct. -/// - -struct StructAttributes -{ - perform : Option< AttributePerform >, -} - -impl StructAttributes -{ - // fn from_attrs( attributes : & Vec< syn::Attribute > ) -> Result< Self > - fn from_attrs< 'a >( attrs : impl Iterator< Item = &'a syn::Attribute > ) -> Result< Self > - { - let mut perform = None; - for attr in attrs - { - let key_ident = attr.path().get_ident() - .ok_or_else( || syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ) )?; - let key_str = format!( "{}", key_ident ); - - if attr::is_standard( &key_str ) - { - continue; - } - - match key_str.as_ref() - { - "storage_fields" => - { - } - "perform" => - { - } - "debug" => - { - } - _ => - { - return Err( syn_err!( attr, "Known structure attirbutes are : `storage_fields`, `perform`, `debug`.\nUnknown structure attribute : {}", qt!{ #attr } ) ); - } - } - } - - Ok( StructAttributes { perform } ) - } -} - -/// -/// Attribute to hold information about method to call after form. -/// -/// `#[ perform( fn after1< 'a >() -> Option< &'a str > ) ]` -/// - -// xxx : move out -struct AttributePerform -{ - // paren_token : syn::token::Paren, - signature : syn::Signature, -} - -impl syn::parse::Parse for AttributePerform -{ - fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > - { - // let input2; - Ok( Self - { - // paren_token : syn::parenthesized!( input2 in input ), - // signature : input2.parse()?, - signature : input.parse()?, - }) - } -} - -/// -/// Attributes of a field. -/// - -struct FieldAttributes -{ - config : Option< AttributeConfig >, - scalar : Option< AttributeScalarSetter >, - container : Option< AttributeContainerSetter >, - subform : Option< AttributeSubformSetter >, -} - -impl FieldAttributes -{ - // fn from_attrs( attributes : & Vec< syn::Attribute > ) -> Result< Self > - fn from_attrs< 'a >( attrs : impl Iterator< Item = &'a syn::Attribute > ) -> Result< Self > - { - let mut config = None; - let mut scalar = None; - let mut container = None; - let mut subform = None; - for attr in attrs - { - let key_ident = attr.path().get_ident() - .ok_or_else( || syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ) )?; - let key_str = format!( "{}", key_ident ); - - if attr::is_standard( &key_str ) - { - continue; - } - - match key_str.as_ref() - { - "former" => - { - match attr.meta - { - // syn::Meta::List( ref meta_list ) => - // { - // config.replace( syn::parse2::< AttributeConfig >( meta_list.tokens.clone() )? ); - // }, - syn::Meta::List( ref meta_list ) => - { - config.replace( syn::parse2::< AttributeConfig >( meta_list.tokens.clone() )? ); - }, - syn::Meta::Path( ref _path ) => - { - config.replace( syn::parse2::< AttributeConfig >( Default::default() )? ); - }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ former( default = 13 ) ].\nGot: {}", qt!{ #attr } ), - } - } - "scalar" => - { - match attr.meta - { - syn::Meta::List( ref meta_list ) => - { - scalar.replace( syn::parse2::< AttributeScalarSetter >( meta_list.tokens.clone() )? ); - }, - syn::Meta::Path( ref _path ) => - { - scalar.replace( syn::parse2::< AttributeScalarSetter >( Default::default() )? ); - }, - _ => return_syn_err!( attr, "Expects an attribute of format `#[ scalar( setter = false ) ]` or `#[ scalar( setter = false, name = my_name ) ]`. \nGot: {}", qt!{ #attr } ), - } - } - "container" => - { - match attr.meta - { - syn::Meta::List( ref meta_list ) => - { - container.replace( syn::parse2::< AttributeContainerSetter >( meta_list.tokens.clone() )? ); - }, - syn::Meta::Path( ref _path ) => - { - container.replace( syn::parse2::< AttributeContainerSetter >( Default::default() )? ); - }, - _ => return_syn_err!( attr, "Expects an attribute of format `#[ container ]` or `#[ container( definition = former::VectorDefinition ) ]` if you want to use default container defition. \nGot: {}", qt!{ #attr } ), - } - } - "subform" => - { - match attr.meta - { - syn::Meta::List( ref meta_list ) => - { - subform.replace( syn::parse2::< AttributeSubformSetter >( meta_list.tokens.clone() )? ); - }, - syn::Meta::Path( ref _path ) => - { - subform.replace( syn::parse2::< AttributeSubformSetter >( Default::default() )? ); - }, - _ => return_syn_err!( attr, "Expects an attribute of format `#[ subform ]` or `#[ subform( name : child )` ], \nGot: {}", qt!{ #attr } ), - } - } - _ => - { - return Err( syn_err!( attr, "Unknown field attribute {}", qt!{ #attr } ) ); - } - } - } - - Ok( FieldAttributes { config, scalar, container, subform } ) - } -} - -/// -/// Attribute to hold configuration information about the field such as default value. -/// -/// `#[ default( 13 ) ]` -/// - -struct AttributeConfig -{ - - /// Default value to use for the field. - default : Option< syn::Expr >, - /// Such field should be present only in storage and should not be present in structure itself. - /// That might be useful for parametrization of forming process. - only_storage : Option< bool >, - -} - -impl AttributeConfig -{ -} - -impl syn::parse::Parse for AttributeConfig -{ - fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > - { - let mut default : Option< syn::Expr > = None; - let mut only_storage : Option< bool > = None; - - while !input.is_empty() - { - let lookahead = input.lookahead1(); - if lookahead.peek( syn::Ident ) - { - let ident : syn::Ident = input.parse()?; - if ident == "default" - { - input.parse::< syn::Token![ = ] >()?; - default = Some( input.parse()? ); - } - else if ident == "only_storage" - { - input.parse::< syn::Token![ = ] >()?; - let value : syn::LitBool = input.parse()?; - only_storage = Some( value.value() ); - } - else - { - return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'default'. For example: `former( default = 13 )`", ident ) ) ); - } - } - - else - { - return Err( syn::Error::new( input.span(), "Expected 'default'. For example: `former( default = 13 )`" ) ); - } - - // Optional comma handling - if input.peek( syn::Token![ , ] ) - { - input.parse::< syn::Token![ , ] >()?; - } - } - - Ok( Self { default, only_storage } ) - } -} - -/// -/// Attribute to enable/disable scalar setter generation. -/// -/// `#[ scalar( false ) ]` -/// - - -/// Represents an attribute for configuring setter generation in container-like structures. -/// -/// Used to specify extra options for primitive scalar setter generation. -/// For example name of setter could be customized. -/// -/// ## Example Input -/// -/// A typical input to parse might look like the following: -/// -/// ```ignore -/// name = field_name, setter = true -/// ``` -/// - -struct AttributeScalarSetter -{ - /// Optional identifier for naming the setter. - name : Option< syn::Ident >, - /// Controls the generation of a setter method. If false, a setter method is not generated. - setter : Option< bool >, -} - -#[ allow( dead_code ) ] -impl AttributeScalarSetter -{ - - /// Should setter be generated or not? - pub fn setter( &self ) -> bool - { - self.setter.is_none() || self.setter.unwrap() - } - -} - -impl syn::parse::Parse for AttributeScalarSetter -{ - fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > - { - let mut name : Option< syn::Ident > = None; - let mut setter : Option< bool > = None; - - while !input.is_empty() - { - let lookahead = input.lookahead1(); - if lookahead.peek( syn::Ident ) - { - let ident : syn::Ident = input.parse()?; - if ident == "name" - { - input.parse::< syn::Token![ = ] >()?; - name = Some( input.parse()? ); - } - else if ident == "setter" - { - input.parse::< syn::Token![ = ] >()?; - let value : syn::LitBool = input.parse()?; - setter = Some( value.value() ); - } - else - { - return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'name', 'setter', or 'definition'. For example: `scalar( name = myName, setter = true )`", ident ) ) ); - } - } - else - { - return Err( syn::Error::new( input.span(), "Expected 'name', 'setter', or 'definition' identifier. For example: `scalar( name = myName, setter = true )`" ) ); - } - - // Optional comma handling - if input.peek( syn::Token![,] ) - { - input.parse::< syn::Token![,] >()?; - } - } - - Ok( Self { name, setter } ) - } -} - -/// Represents an attribute for configuring container setter generation. -/// -/// This struct is part of a meta-programming approach to enable detailed configuration of nested structs or collections such as `Vec< E >, HashMap< K, E >` and so on. -/// It allows the customization of setter methods and the specification of the container's behavior through meta attributes. -/// -/// ## Example Input -/// -/// The following is an example of a token stream that this struct can parse: -/// ```ignore -/// name = "custom_setter", setter = true, definition = former::VectorDefinition -/// ``` -/// - -struct AttributeContainerSetter -{ - /// Optional identifier for naming the setter. - name : Option< syn::Ident >, - /// Controls the generation of a setter method. If false, a setter method is not generated. - setter : Option< bool >, - /// Definition of the container former to use, e.g., `former::VectorSubformer`. - definition : Option< syn::Type >, -} - -impl AttributeContainerSetter -{ - - /// Should setter be generated or not? - pub fn setter( &self ) -> bool - { - self.setter.is_none() || self.setter.unwrap() - } - -} - -impl syn::parse::Parse for AttributeContainerSetter -{ - fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > - { - let mut name : Option< syn::Ident > = None; - let mut setter : Option< bool > = None; // Default is to generate a setter - let mut definition : Option< syn::Type > = None; - - while !input.is_empty() - { - let lookahead = input.lookahead1(); - if lookahead.peek( syn::Ident ) - { - let ident : syn::Ident = input.parse()?; - if ident == "name" - { - input.parse::< syn::Token![ = ] >()?; - name = Some( input.parse()? ); - } - else if ident == "setter" - { - input.parse::< syn::Token![ = ] >()?; - let value : syn::LitBool = input.parse()?; - setter = Some( value.value ); - } - else if ident == "definition" - { - input.parse::< syn::Token![ = ] >()?; - definition = Some( input.parse()? ); - } - else - { - return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'name', 'setter', or 'definition'. For example: `container( name = myName, setter = true, definition = MyDefinition )`", ident ) ) ); - } - } - else - { - return Err( syn::Error::new( input.span(), "Expected 'name', 'setter', or 'definition' identifier. For example: `container( name = myName, setter = true, definition = MyDefinition )`" ) ); - } - - // Optional comma handling - if input.peek( syn::Token![ , ] ) - { - input.parse::< syn::Token![ , ] >()?; - } - } - - Ok( Self { name, setter, definition } ) - } -} - -/// Represents a subform attribute to control subform setter generation. -/// Used to specify extra options for using one former as subformer of another one. -/// For example name of setter could be customized. -/// -/// ## Example Input -/// -/// A typical input to parse might look like the following: -/// -/// ```ignore -/// name = field_name, setter = true -/// ``` -/// -/// or simply: -/// -/// ```ignore -/// mame = field_name -/// ``` - -struct AttributeSubformSetter -{ - /// An optional identifier that names the setter. It is parsed from inputs - /// like `name = my_field`. - name : Option< syn::Ident >, - /// Disable generation of setter. - /// It still generate `_field_add` method, so it could be used to make a setter with custom arguments. - setter : Option< bool >, -} - -impl AttributeSubformSetter -{ - - /// Should setter be generated or not? - pub fn setter( &self ) -> bool - { - self.setter.is_none() || self.setter.unwrap() - } - -} - -impl syn::parse::Parse for AttributeSubformSetter -{ - fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > - { - let mut name : Option< syn::Ident > = None; - let mut setter : Option< bool > = None; - - while !input.is_empty() - { - let lookahead = input.lookahead1(); - if lookahead.peek( syn::Ident ) - { - let ident : syn::Ident = input.parse()?; - if ident == "name" - { - input.parse::< syn::Token![ = ] >()?; - name = Some( input.parse()? ); - } - else if ident == "setter" - { - input.parse::< syn::Token![ = ] >()?; - let value : syn::LitBool = input.parse()?; - setter = Some( value.value() ); - } - else - { - return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'name', 'setter', or 'definition'. For example: `subform( name = myName, setter = true )`", ident ) ) ); - } - } - else - { - return Err( syn::Error::new( input.span(), "Expected 'name', 'setter', or 'definition' identifier. For example: `subform( name = myName, setter = true )`" ) ); - } - - // Optional comma handling - if input.peek( syn::Token![,] ) - { - input.parse::< syn::Token![,] >()?; - } - } - - Ok( Self { name, setter } ) - } -} +mod field; +use field::*; +mod field_attrs; +use field_attrs::*; +mod struct_attrs; +use struct_attrs::*; /// /// Is type under Option. diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs new file mode 100644 index 0000000000..ac32f7973b --- /dev/null +++ b/module/core/former_meta/src/derive_former/field.rs @@ -0,0 +1,118 @@ + +use super::*; +use iter_tools::{ Itertools, process_results }; +use macro_tools::{ attr, diag, generic_params, generic_args, container_kind, typ, Result }; +use proc_macro2::TokenStream; + +/// +/// Definition of a field. +/// + +#[ allow( dead_code ) ] +pub struct FormerField< 'a > +{ + pub attrs : FieldAttributes, + pub vis : &'a syn::Visibility, + pub ident : &'a syn::Ident, + pub colon_token : &'a Option< syn::token::Colon >, + pub ty : &'a syn::Type, + pub non_optional_ty : &'a syn::Type, + pub is_optional : bool, + pub of_type : container_kind::ContainerKind, +} + +impl< 'a > FormerField< 'a > +{ + + /// Get name of scalar setter. + pub fn scalar_setter_name( &self ) -> &syn::Ident + { + if let Some( ref attr ) = self.attrs.scalar + { + if let Some( ref name ) = attr.name + { + return name + } + } + return &self.ident; + } + + /// Get name of setter for container if such setter should be generated. + pub fn container_setter_name( &self ) -> Option< &syn::Ident > + { + + if let Some( ref attr ) = self.attrs.container + { + if attr.setter() + { + if let Some( ref name ) = attr.name + { + return Some( &name ) + } + else + { + return Some( &self.ident ) + } + } + } + + return None; + } + + /// Get name of setter for subform if such setter should be generated. + pub fn subform_setter_name( &self ) -> Option< &syn::Ident > + { + + if let Some( ref attr ) = self.attrs.subform + { + if attr.setter() + { + if let Some( ref name ) = attr.name + { + return Some( &name ) + } + else + { + return Some( &self.ident ) + } + } + } + + return None; + } + + /// Is scalar setter required. Does not if container of subformer setter requested. + pub fn scalar_setter_required( &self ) -> bool + { + + let mut explicit = false; + if let Some( ref attr ) = self.attrs.scalar + { + if let Some( setter ) = attr.setter + { + if setter == false + { + return false + } + explicit = true; + } + if let Some( ref _name ) = attr.name + { + explicit = true; + } + } + + if self.attrs.container.is_some() && !explicit + { + return false; + } + + if self.attrs.subform.is_some() && !explicit + { + return false; + } + + return true; + } + +} diff --git a/module/core/former_meta/src/derive_former/field_attrs.rs b/module/core/former_meta/src/derive_former/field_attrs.rs new file mode 100644 index 0000000000..25ae64eb86 --- /dev/null +++ b/module/core/former_meta/src/derive_former/field_attrs.rs @@ -0,0 +1,427 @@ + +use super::*; +use iter_tools::{ Itertools, process_results }; +use macro_tools::{ attr, diag, generic_params, generic_args, container_kind, typ, Result }; +use proc_macro2::TokenStream; + +/// +/// Attributes of a field. +/// + +pub struct FieldAttributes +{ + pub config : Option< AttributeConfig >, + pub scalar : Option< AttributeScalarSetter >, + pub container : Option< AttributeContainerSetter >, + pub subform : Option< AttributeSubformSetter >, +} + +impl FieldAttributes +{ + // fn from_attrs( attributes : & Vec< syn::Attribute > ) -> Result< Self > + pub fn from_attrs< 'a >( attrs : impl Iterator< Item = &'a syn::Attribute > ) -> Result< Self > + { + let mut config = None; + let mut scalar = None; + let mut container = None; + let mut subform = None; + for attr in attrs + { + let key_ident = attr.path().get_ident() + .ok_or_else( || syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ) )?; + let key_str = format!( "{}", key_ident ); + + if attr::is_standard( &key_str ) + { + continue; + } + + match key_str.as_ref() + { + "former" => + { + match attr.meta + { + // syn::Meta::List( ref meta_list ) => + // { + // config.replace( syn::parse2::< AttributeConfig >( meta_list.tokens.clone() )? ); + // }, + syn::Meta::List( ref meta_list ) => + { + config.replace( syn::parse2::< AttributeConfig >( meta_list.tokens.clone() )? ); + }, + syn::Meta::Path( ref _path ) => + { + config.replace( syn::parse2::< AttributeConfig >( Default::default() )? ); + }, + _ => return_syn_err!( attr, "Expects an attribute of format #[ former( default = 13 ) ].\nGot: {}", qt!{ #attr } ), + } + } + "scalar" => + { + match attr.meta + { + syn::Meta::List( ref meta_list ) => + { + scalar.replace( syn::parse2::< AttributeScalarSetter >( meta_list.tokens.clone() )? ); + }, + syn::Meta::Path( ref _path ) => + { + scalar.replace( syn::parse2::< AttributeScalarSetter >( Default::default() )? ); + }, + _ => return_syn_err!( attr, "Expects an attribute of format `#[ scalar( setter = false ) ]` or `#[ scalar( setter = false, name = my_name ) ]`. \nGot: {}", qt!{ #attr } ), + } + } + "container" => + { + match attr.meta + { + syn::Meta::List( ref meta_list ) => + { + container.replace( syn::parse2::< AttributeContainerSetter >( meta_list.tokens.clone() )? ); + }, + syn::Meta::Path( ref _path ) => + { + container.replace( syn::parse2::< AttributeContainerSetter >( Default::default() )? ); + }, + _ => return_syn_err!( attr, "Expects an attribute of format `#[ container ]` or `#[ container( definition = former::VectorDefinition ) ]` if you want to use default container defition. \nGot: {}", qt!{ #attr } ), + } + } + "subform" => + { + match attr.meta + { + syn::Meta::List( ref meta_list ) => + { + subform.replace( syn::parse2::< AttributeSubformSetter >( meta_list.tokens.clone() )? ); + }, + syn::Meta::Path( ref _path ) => + { + subform.replace( syn::parse2::< AttributeSubformSetter >( Default::default() )? ); + }, + _ => return_syn_err!( attr, "Expects an attribute of format `#[ subform ]` or `#[ subform( name : child )` ], \nGot: {}", qt!{ #attr } ), + } + } + _ => + { + return Err( syn_err!( attr, "Unknown field attribute {}", qt!{ #attr } ) ); + } + } + } + + Ok( FieldAttributes { config, scalar, container, subform } ) + } +} + +/// +/// Attribute to hold configuration information about the field such as default value. +/// +/// `#[ default( 13 ) ]` +/// + +pub struct AttributeConfig +{ + + /// Default value to use for the field. + pub default : Option< syn::Expr >, + /// Such field should be present only in storage and should not be present in structure itself. + /// That might be useful for parametrization of forming process. + pub only_storage : Option< bool >, + +} + +impl AttributeConfig +{ +} + +impl syn::parse::Parse for AttributeConfig +{ + fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > + { + let mut default : Option< syn::Expr > = None; + let mut only_storage : Option< bool > = None; + + while !input.is_empty() + { + let lookahead = input.lookahead1(); + if lookahead.peek( syn::Ident ) + { + let ident : syn::Ident = input.parse()?; + if ident == "default" + { + input.parse::< syn::Token![ = ] >()?; + default = Some( input.parse()? ); + } + else if ident == "only_storage" + { + input.parse::< syn::Token![ = ] >()?; + let value : syn::LitBool = input.parse()?; + only_storage = Some( value.value() ); + } + else + { + return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'default'. For example: `former( default = 13 )`", ident ) ) ); + } + } + + else + { + return Err( syn::Error::new( input.span(), "Expected 'default'. For example: `former( default = 13 )`" ) ); + } + + // Optional comma handling + if input.peek( syn::Token![ , ] ) + { + input.parse::< syn::Token![ , ] >()?; + } + } + + Ok( Self { default, only_storage } ) + } +} + +/// +/// Attribute to enable/disable scalar setter generation. +/// +/// ## Example Input +/// +/// A typical input to parse might look like the following: +/// +/// ```ignore +/// name = field_name, setter = true +/// ``` +/// + +pub struct AttributeScalarSetter +{ + /// Optional identifier for naming the setter. + pub name : Option< syn::Ident >, + /// Controls the generation of a setter method. If false, a setter method is not generated. + pub setter : Option< bool >, +} + +#[ allow( dead_code ) ] +impl AttributeScalarSetter +{ + + /// Should setter be generated or not? + pub fn setter( &self ) -> bool + { + self.setter.is_none() || self.setter.unwrap() + } + +} + +impl syn::parse::Parse for AttributeScalarSetter +{ + fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > + { + let mut name : Option< syn::Ident > = None; + let mut setter : Option< bool > = None; + + while !input.is_empty() + { + let lookahead = input.lookahead1(); + if lookahead.peek( syn::Ident ) + { + let ident : syn::Ident = input.parse()?; + if ident == "name" + { + input.parse::< syn::Token![ = ] >()?; + name = Some( input.parse()? ); + } + else if ident == "setter" + { + input.parse::< syn::Token![ = ] >()?; + let value : syn::LitBool = input.parse()?; + setter = Some( value.value() ); + } + else + { + return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'name', 'setter', or 'definition'. For example: `scalar( name = myName, setter = true )`", ident ) ) ); + } + } + else + { + return Err( syn::Error::new( input.span(), "Expected 'name', 'setter', or 'definition' identifier. For example: `scalar( name = myName, setter = true )`" ) ); + } + + // Optional comma handling + if input.peek( syn::Token![,] ) + { + input.parse::< syn::Token![,] >()?; + } + } + + Ok( Self { name, setter } ) + } +} + +/// Represents an attribute for configuring container setter generation. +/// +/// This struct is part of a meta-programming approach to enable detailed configuration of nested structs or collections such as `Vec< E >, HashMap< K, E >` and so on. +/// It allows the customization of setter methods and the specification of the container's behavior through meta attributes. +/// +/// ## Example Input +/// +/// The following is an example of a token stream that this struct can parse: +/// ```ignore +/// name = "custom_setter", setter = true, definition = former::VectorDefinition +/// ``` +/// + +pub struct AttributeContainerSetter +{ + /// Optional identifier for naming the setter. + pub name : Option< syn::Ident >, + /// Controls the generation of a setter method. If false, a setter method is not generated. + pub setter : Option< bool >, + /// Definition of the container former to use, e.g., `former::VectorSubformer`. + pub definition : Option< syn::Type >, +} + +impl AttributeContainerSetter +{ + + /// Should setter be generated or not? + pub fn setter( &self ) -> bool + { + self.setter.is_none() || self.setter.unwrap() + } + +} + +impl syn::parse::Parse for AttributeContainerSetter +{ + fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > + { + let mut name : Option< syn::Ident > = None; + let mut setter : Option< bool > = None; // Default is to generate a setter + let mut definition : Option< syn::Type > = None; + + while !input.is_empty() + { + let lookahead = input.lookahead1(); + if lookahead.peek( syn::Ident ) + { + let ident : syn::Ident = input.parse()?; + if ident == "name" + { + input.parse::< syn::Token![ = ] >()?; + name = Some( input.parse()? ); + } + else if ident == "setter" + { + input.parse::< syn::Token![ = ] >()?; + let value : syn::LitBool = input.parse()?; + setter = Some( value.value ); + } + else if ident == "definition" + { + input.parse::< syn::Token![ = ] >()?; + definition = Some( input.parse()? ); + } + else + { + return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'name', 'setter', or 'definition'. For example: `container( name = myName, setter = true, definition = MyDefinition )`", ident ) ) ); + } + } + else + { + return Err( syn::Error::new( input.span(), "Expected 'name', 'setter', or 'definition' identifier. For example: `container( name = myName, setter = true, definition = MyDefinition )`" ) ); + } + + // Optional comma handling + if input.peek( syn::Token![ , ] ) + { + input.parse::< syn::Token![ , ] >()?; + } + } + + Ok( Self { name, setter, definition } ) + } +} + +/// Represents a subform attribute to control subform setter generation. +/// Used to specify extra options for using one former as subformer of another one. +/// For example name of setter could be customized. +/// +/// ## Example Input +/// +/// A typical input to parse might look like the following: +/// +/// ```ignore +/// name = field_name, setter = true +/// ``` +/// +/// or simply: +/// +/// ```ignore +/// mame = field_name +/// ``` + +pub struct AttributeSubformSetter +{ + /// An optional identifier that names the setter. It is parsed from inputs + /// like `name = my_field`. + pub name : Option< syn::Ident >, + /// Disable generation of setter. + /// It still generate `_field_add` method, so it could be used to make a setter with custom arguments. + pub setter : Option< bool >, +} + +impl AttributeSubformSetter +{ + + /// Should setter be generated or not? + pub fn setter( &self ) -> bool + { + self.setter.is_none() || self.setter.unwrap() + } + +} + +impl syn::parse::Parse for AttributeSubformSetter +{ + fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > + { + let mut name : Option< syn::Ident > = None; + let mut setter : Option< bool > = None; + + while !input.is_empty() + { + let lookahead = input.lookahead1(); + if lookahead.peek( syn::Ident ) + { + let ident : syn::Ident = input.parse()?; + if ident == "name" + { + input.parse::< syn::Token![ = ] >()?; + name = Some( input.parse()? ); + } + else if ident == "setter" + { + input.parse::< syn::Token![ = ] >()?; + let value : syn::LitBool = input.parse()?; + setter = Some( value.value() ); + } + else + { + return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'name', 'setter', or 'definition'. For example: `subform( name = myName, setter = true )`", ident ) ) ); + } + } + else + { + return Err( syn::Error::new( input.span(), "Expected 'name', 'setter', or 'definition' identifier. For example: `subform( name = myName, setter = true )`" ) ); + } + + // Optional comma handling + if input.peek( syn::Token![,] ) + { + input.parse::< syn::Token![,] >()?; + } + } + + Ok( Self { name, setter } ) + } +} diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs new file mode 100644 index 0000000000..c8abf6aa96 --- /dev/null +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -0,0 +1,84 @@ + +use super::*; +use iter_tools::{ Itertools, process_results }; +use macro_tools::{ attr, diag, generic_params, generic_args, container_kind, typ, Result }; +use proc_macro2::TokenStream; + +/// +/// Definition of a field. +/// + +/// +/// Attributes of a struct. +/// + +pub struct StructAttributes +{ + perform : Option< AttributePerform >, +} + +impl StructAttributes +{ + // fn from_attrs( attributes : & Vec< syn::Attribute > ) -> Result< Self > + pub fn from_attrs< 'a >( attrs : impl Iterator< Item = &'a syn::Attribute > ) -> Result< Self > + { + let mut perform = None; + for attr in attrs + { + let key_ident = attr.path().get_ident() + .ok_or_else( || syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ) )?; + let key_str = format!( "{}", key_ident ); + + if attr::is_standard( &key_str ) + { + continue; + } + + match key_str.as_ref() + { + "storage_fields" => + { + } + "perform" => + { + } + "debug" => + { + } + _ => + { + return Err( syn_err!( attr, "Known structure attirbutes are : `storage_fields`, `perform`, `debug`.\nUnknown structure attribute : {}", qt!{ #attr } ) ); + } + } + } + + Ok( StructAttributes { perform } ) + } +} + +/// +/// Attribute to hold information about method to call after form. +/// +/// `#[ perform( fn after1< 'a >() -> Option< &'a str > ) ]` +/// + +// xxx : move out +pub struct AttributePerform +{ + // paren_token : syn::token::Paren, + pub signature : syn::Signature, +} + +impl syn::parse::Parse for AttributePerform +{ + fn parse( input : syn::parse::ParseStream< '_ > ) -> Result< Self > + { + // let input2; + Ok( Self + { + // paren_token : syn::parenthesized!( input2 in input ), + // signature : input2.parse()?, + signature : input.parse()?, + }) + } +} From b411d8f8025f190ef461c93970cb761919a800d0 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 16:41:44 +0300 Subject: [PATCH 409/533] former : experimenting --- .../tests/inc/compiletime/former_bad_attr.stderr | 11 ----------- .../compiletime/components_component_from_debug.rs | 0 .../compiletime/field_attr_bad.rs} | 0 .../former_tests/compiletime/field_attr_bad.stderr | 11 +++++++++++ .../compiletime/hashmap_without_parameter.rs} | 0 .../inc/former_tests/compiletime/struct_attr_bad.rs | 11 +++++++++++ .../former_tests/compiletime/struct_attr_bad.stderr | 12 ++++++++++++ .../compiletime/vector_without_parameter.rs} | 0 module/core/former/tests/inc/mod.rs | 9 +++++---- module/core/former_meta/src/derive_former.rs | 8 ++------ module/core/former_meta/src/derive_former/field.rs | 4 +--- .../former_meta/src/derive_former/field_attrs.rs | 4 +--- .../former_meta/src/derive_former/struct_attrs.rs | 4 +--- 13 files changed, 44 insertions(+), 30 deletions(-) delete mode 100644 module/core/former/tests/inc/compiletime/former_bad_attr.stderr rename module/core/former/tests/inc/{ => components_tests}/compiletime/components_component_from_debug.rs (100%) rename module/core/former/tests/inc/{compiletime/former_bad_attr.rs => former_tests/compiletime/field_attr_bad.rs} (100%) create mode 100644 module/core/former/tests/inc/former_tests/compiletime/field_attr_bad.stderr rename module/core/former/tests/inc/{compiletime/former_hashmap_without_parameter.rs => former_tests/compiletime/hashmap_without_parameter.rs} (100%) create mode 100644 module/core/former/tests/inc/former_tests/compiletime/struct_attr_bad.rs create mode 100644 module/core/former/tests/inc/former_tests/compiletime/struct_attr_bad.stderr rename module/core/former/tests/inc/{compiletime/former_vector_without_parameter.rs => former_tests/compiletime/vector_without_parameter.rs} (100%) diff --git a/module/core/former/tests/inc/compiletime/former_bad_attr.stderr b/module/core/former/tests/inc/compiletime/former_bad_attr.stderr deleted file mode 100644 index 085d07fc00..0000000000 --- a/module/core/former/tests/inc/compiletime/former_bad_attr.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: Unknown attribute #[defaultx(31)] - --> tests/inc/compiletime/former_bad_attr.rs:6:3 - | -6 | #[ defaultx( 31 ) ] - | ^^^^^^^^^^^^^^^^^^^ - -error: cannot find attribute `defaultx` in this scope - --> tests/inc/compiletime/former_bad_attr.rs:6:6 - | -6 | #[ defaultx( 31 ) ] - | ^^^^^^^^ diff --git a/module/core/former/tests/inc/compiletime/components_component_from_debug.rs b/module/core/former/tests/inc/components_tests/compiletime/components_component_from_debug.rs similarity index 100% rename from module/core/former/tests/inc/compiletime/components_component_from_debug.rs rename to module/core/former/tests/inc/components_tests/compiletime/components_component_from_debug.rs diff --git a/module/core/former/tests/inc/compiletime/former_bad_attr.rs b/module/core/former/tests/inc/former_tests/compiletime/field_attr_bad.rs similarity index 100% rename from module/core/former/tests/inc/compiletime/former_bad_attr.rs rename to module/core/former/tests/inc/former_tests/compiletime/field_attr_bad.rs diff --git a/module/core/former/tests/inc/former_tests/compiletime/field_attr_bad.stderr b/module/core/former/tests/inc/former_tests/compiletime/field_attr_bad.stderr new file mode 100644 index 0000000000..8162f72bf2 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/compiletime/field_attr_bad.stderr @@ -0,0 +1,11 @@ +error: Unknown field attribute #[defaultx(31)] + --> tests/inc/former_tests/compiletime/field_attr_bad.rs:6:3 + | +6 | #[ defaultx( 31 ) ] + | ^^^^^^^^^^^^^^^^^^^ + +error: cannot find attribute `defaultx` in this scope + --> tests/inc/former_tests/compiletime/field_attr_bad.rs:6:6 + | +6 | #[ defaultx( 31 ) ] + | ^^^^^^^^ diff --git a/module/core/former/tests/inc/compiletime/former_hashmap_without_parameter.rs b/module/core/former/tests/inc/former_tests/compiletime/hashmap_without_parameter.rs similarity index 100% rename from module/core/former/tests/inc/compiletime/former_hashmap_without_parameter.rs rename to module/core/former/tests/inc/former_tests/compiletime/hashmap_without_parameter.rs diff --git a/module/core/former/tests/inc/former_tests/compiletime/struct_attr_bad.rs b/module/core/former/tests/inc/former_tests/compiletime/struct_attr_bad.rs new file mode 100644 index 0000000000..a08670ab93 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/compiletime/struct_attr_bad.rs @@ -0,0 +1,11 @@ +use former::Former; + +#[ derive( Former ) ] +#[ defaultx ] +pub struct Struct1 +{ + int_1 : i32, +} + +fn main() +{} \ No newline at end of file diff --git a/module/core/former/tests/inc/former_tests/compiletime/struct_attr_bad.stderr b/module/core/former/tests/inc/former_tests/compiletime/struct_attr_bad.stderr new file mode 100644 index 0000000000..7425033f39 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/compiletime/struct_attr_bad.stderr @@ -0,0 +1,12 @@ +error: Known structure attirbutes are : `storage_fields`, `perform`, `debug`. + Unknown structure attribute : #[defaultx] + --> tests/inc/former_tests/compiletime/struct_attr_bad.rs:4:1 + | +4 | #[ defaultx ] + | ^^^^^^^^^^^^^ + +error: cannot find attribute `defaultx` in this scope + --> tests/inc/former_tests/compiletime/struct_attr_bad.rs:4:4 + | +4 | #[ defaultx ] + | ^^^^^^^^ diff --git a/module/core/former/tests/inc/compiletime/former_vector_without_parameter.rs b/module/core/former/tests/inc/former_tests/compiletime/vector_without_parameter.rs similarity index 100% rename from module/core/former/tests/inc/compiletime/former_vector_without_parameter.rs rename to module/core/former/tests/inc/former_tests/compiletime/vector_without_parameter.rs diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index e8063254f1..9d6113b348 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -145,9 +145,10 @@ only_for_terminal_module! let t = test_tools::compiletime::TestCases::new(); // zzz : uncomment - t.compile_fail( "tests/inc/compiletime/former_bad_attr.rs" ); - t.pass( "tests/inc/compiletime/former_hashmap_without_parameter.rs" ); - t.pass( "tests/inc/compiletime/former_vector_without_parameter.rs" ); + t.compile_fail( "tests/inc/former_tests/compiletime/field_attr_bad.rs" ); + t.compile_fail( "tests/inc/former_tests/compiletime/struct_attr_bad.rs" ); + t.pass( "tests/inc/former_tests/compiletime/hashmap_without_parameter.rs" ); + t.pass( "tests/inc/former_tests/compiletime/vector_without_parameter.rs" ); } @@ -162,7 +163,7 @@ only_for_terminal_module! let _t = test_tools::compiletime::TestCases::new(); // zzz : make it working test - //t.run( "tests/inc/compiletime/components_component_from_debug.rs" ); + //t.run( "tests/inc/components_tests/compiletime/components_component_from_debug.rs" ); } diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index e754e898ac..38edef4d19 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -20,6 +20,7 @@ use struct_attrs::*; /// Is type under Option. /// +// xxx : move fn is_optional( ty : &syn::Type ) -> bool { typ::type_rightmost( ty ) == Some( "Option".to_string() ) @@ -845,10 +846,7 @@ fn field_former_add_end_map field : &FormerField< '_ >, stru : &syn::Ident, former : &syn::Ident, - _former_storage : &syn::Ident, - _former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - _former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, struct_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, struct_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, @@ -1199,6 +1197,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > _ => return Err( syn_err!( ast, "Unknown format of data, expected syn::Data::Struct( ref data_struct )\n {}", qt!{ #ast } ) ), }; + // xxx : move let former_fields : Vec< Result< FormerField< '_ > > > = fields.iter().map( | field | { let attrs = FieldAttributes::from_attrs( field.attrs.iter() )?; @@ -1249,10 +1248,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > former_field, &stru, &former, - &former_storage, - &former_generics_impl, &former_generics_ty, - &former_generics_where, &struct_generics_impl, &struct_generics_ty, &struct_generics_where, diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index ac32f7973b..a28d2c1d5e 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -1,8 +1,6 @@ use super::*; -use iter_tools::{ Itertools, process_results }; -use macro_tools::{ attr, diag, generic_params, generic_args, container_kind, typ, Result }; -use proc_macro2::TokenStream; +use macro_tools::{ container_kind }; /// /// Definition of a field. diff --git a/module/core/former_meta/src/derive_former/field_attrs.rs b/module/core/former_meta/src/derive_former/field_attrs.rs index 25ae64eb86..cf3877d8ee 100644 --- a/module/core/former_meta/src/derive_former/field_attrs.rs +++ b/module/core/former_meta/src/derive_former/field_attrs.rs @@ -1,8 +1,6 @@ use super::*; -use iter_tools::{ Itertools, process_results }; -use macro_tools::{ attr, diag, generic_params, generic_args, container_kind, typ, Result }; -use proc_macro2::TokenStream; +use macro_tools::{ attr, Result }; /// /// Attributes of a field. diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs index c8abf6aa96..bc45563136 100644 --- a/module/core/former_meta/src/derive_former/struct_attrs.rs +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -1,8 +1,6 @@ use super::*; -use iter_tools::{ Itertools, process_results }; -use macro_tools::{ attr, diag, generic_params, generic_args, container_kind, typ, Result }; -use proc_macro2::TokenStream; +use macro_tools::{ attr, Result }; /// /// Definition of a field. From f6d022d661698c62436d95345eb078defce2aa44 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 22:53:58 +0300 Subject: [PATCH 410/533] former : experimenting --- .../former/tests/inc/former_tests/a_basic.rs | 2 +- .../attribute_storage_primitive.rs | 1 + module/core/former_meta/src/derive_former.rs | 925 +----------------- .../former_meta/src/derive_former/field.rs | 902 +++++++++++++++++ 4 files changed, 914 insertions(+), 916 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic.rs b/module/core/former/tests/inc/former_tests/a_basic.rs index 8bbe8dd77f..04ef5312c9 100644 --- a/module/core/former/tests/inc/former_tests/a_basic.rs +++ b/module/core/former/tests/inc/former_tests/a_basic.rs @@ -9,7 +9,7 @@ pub struct Struct1 pub int_1 : i32, } -// = begin_coercing of generated +// == begin of generated // == end of generated diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs index c38446603e..b28a34fd4e 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -1,5 +1,6 @@ #[ allow( unused_imports ) ] use super::*; +// xxx2 : implement #[ derive( Debug, PartialEq, the_module::Former ) ] // #[ debug ] diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 38edef4d19..047223fa60 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -38,909 +38,6 @@ fn parameter_internal_first( ty : &syn::Type ) -> Result< &syn::Type > .ok_or_else( || syn_err!( ty, "Expects at least one parameter here:\n {}", qt!{ #ty } ) ) } -/// -/// Generate fields for initializer of a struct setting each field to `None`. -/// -/// Used for initializing a Container, where on initialization all fields are None. User can alter them through builder pattern -/// -/// ### Basic use-case. of output -/// -/// ```ignore -/// int_1 : core::option::Option::None, -/// string_1 : core::option::Option::None, -/// int_optional_1 : core::option::Option::None, -/// ``` -/// - -#[ inline( always ) ] -fn field_none_map( field : &FormerField< '_ > ) -> TokenStream -{ - let ident = Some( field.ident.clone() ); - let tokens = qt! { ::core::option::Option::None }; - let ty2 : syn::Type = syn::parse2( tokens ).unwrap(); - - qt! - { - #ident : #ty2 - } -} - -/// -/// Generate field of the former for a field of the structure -/// -/// Used to generate a Container -/// -/// ### Basic use-case. of output -/// -/// ```ignore -/// pub int_1 : core::option::Option< i32 >, -/// pub string_1 : core::option::Option< String >, -/// pub int_optional_1 : core::option::Option< i32 >, -/// pub string_optional_1 : core::option::Option< String >, -/// ``` -/// - -#[ inline( always ) ] -fn field_optional_map( field : &FormerField< '_ > ) -> TokenStream -{ - let ident = Some( field.ident.clone() ); - let ty = field.ty.clone(); - - // let ty2 = if is_optional( &ty ) - let ty2 = if field.is_optional - { - qt! { #ty } - } - else - { - qt! { ::core::option::Option< #ty > } - }; - - qt! - { - pub #ident : #ty2 - } - -} - -/// -/// Generate code converting a field of the former to the field of the structure. -/// -/// In simple terms, used on `form()` call to unwrap contained values from the former's storage. -/// Will try to use default values if no values supplied by the former and the type implements `Default` trait. -/// -/// ### Generated code will look similar to this : -/// -/// ```ignore -/// let int_1 : i32 = if self.storage.int_1.is_some() -/// { -/// // if int_1 is optional -/// Some( self.storage.int_1.take().unwrap() ) -/// -/// // if int_1 isn't optional -/// self.storage.int_1.take().unwrap() -/// } -/// else -/// { -/// // if int_1 is optional and has default -/// Some( i32::default().into() ) -/// -/// // if int_1 is optional and doesn't have default -/// None -/// -/// // if int_1 isn't optional and has default -/// i32::default().into() -/// -/// // if int_1 isn't optional and hasn't default -/// panic!( "Field 'int_1' isn't initialized" ) -/// }; -/// ``` -/// - -#[ inline( always ) ] -fn field_form_map( field : &FormerField< '_ > ) -> Result< TokenStream > -{ - let ident = field.ident; - let ty = field.ty; - let default : Option< &syn::Expr > = field.attrs.config.as_ref() - .and_then( | attr | attr.default.as_ref() ); - - let tokens = if field.is_optional - { - - let _else = match default - { - None => - { - qt! - { - ::core::option::Option::None - } - } - - Some( default_val ) => - { - qt! - { - ::core::option::Option::Some( ::core::convert::Into::into( #default_val ) ) - } - } - }; - - qt! - { - let #ident = if self.#ident.is_some() - { - ::core::option::Option::Some( self.#ident.take().unwrap() ) - } - else - { - #_else - }; - } - - } - else - { - - let _else = match default - { - None => - { - let panic_msg = format!( "Field '{}' isn't initialized", ident ); - qt! - { - { - // By hardly utilizing deref coercion, we achieve conditional trait implementation - trait MaybeDefault< T > - { - fn maybe_default( self : &Self ) -> T { panic!( #panic_msg ) } - } - - // Panic on non-`Default` types - impl< T > MaybeDefault< T > - for &::core::marker::PhantomData< T > - {} - - // Return default value on `Default`` types - impl< T > MaybeDefault< T > - for ::core::marker::PhantomData< T > - where T : ::core::default::Default, - { - fn maybe_default( self : &Self ) -> T - { - T::default() - } - } - - // default if `impl Default`, otherwise - panic - ( &::core::marker::PhantomData::< #ty > ).maybe_default() - } - } - } - Some( default_val ) => - { - qt! - { - ::core::convert::Into::into( #default_val ) - } - } - }; - - qt! - { - let #ident = if self.#ident.is_some() - { - self.#ident.take().unwrap() - } - else - { - #_else - }; - } - - }; - - Ok( tokens ) -} - -/// -/// Extract name of a field out. -/// - -#[ inline( always ) ] -fn field_name_map( field : &FormerField< '_ > ) -> syn::Ident -{ - field.ident.clone() -} - -// zzz : outdated, please update documentation -/// -/// Generate a former setter for the field. -/// -/// If aliases provided, also generate aliases -/// -/// # Example of generated code -/// -/// ```ignore -/// #[ doc = "Setter for the 'int_1' field." ] -/// #[ inline ] -/// pub fn int_1< Src >( mut self, src : Src ) -> Self -/// where -/// Src : ::core::convert::Into< i32 >, -/// { -/// debug_assert!( self.int_1.is_none() ); -/// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); -/// self -/// } -/// -/// /// #[ doc = "Setter for the 'int_1' field." ] -/// #[ inline ] -/// pub fn int_1_alias< Src >( mut self, src : Src ) -> Self -/// where -/// Src : ::core::convert::Into< i32 >, -/// { -/// debug_assert!( self.int_1.is_none() ); -/// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); -/// self -/// } -/// ``` - -#[ inline ] -fn field_setter_map -( - field : &FormerField< '_ >, - stru : &syn::Ident, -) --> Result< TokenStream > -{ - let r = qt!{}; - - // scalar setter - let r = if field.scalar_setter_required() - { - let r2 = field_scalar_setter( field ); - qt! - { - #r - #r2 - } - } - else - { - r - }; - - // container setter - let r = if let Some( _ ) = &field.attrs.container - { - let r2 = field_container_setter( field, stru ); - qt! - { - #r - #r2 - } - } - else - { - r - }; - - // subform setter - let r = if field.attrs.subform.is_some() - { - let r2 = field_subform_add_setter_map( field, stru )?; - qt! - { - #r - #r2 - } - } - else - { - r - }; - - // tree_print!( r.as_ref().unwrap() ); - Ok( r ) -} - -/// zzz : write documentation -#[ inline ] -fn field_subform_add_setter_map -( - field : &FormerField< '_ >, - stru : &syn::Ident, -) --> Result< TokenStream > -{ - - if field.attrs.subform.is_none() - { - return Ok( qt!{ } ); - } - - use convert_case::{ Case, Casing }; - let field_ident = field.ident; - let field_ty = field.non_optional_ty; - let attr = field.attrs.subform.as_ref().unwrap(); - // let params = typ::type_parameters( &field.non_optional_ty, .. ); - - // example : `child` - let setter_name = field.subform_setter_name(); - - // example : `ParentFormerAddChildrenEnd`` - let former_add_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); - let former_add_end = syn::Ident::new( &former_add_end_name, field_ident.span() ); - - // example : `_children_former` - let field_add_name = format!( "_{}_add", field_ident ); - let field_add = syn::Ident::new( &field_add_name, field_ident.span() ); - - let r = qt! - { - - // zzz : improve documentation - /// Setter returning former of element of container of the field as subformer. - #[ inline( always ) ] - pub fn #field_add< Former2, Definition2 >( self ) -> Former2 - where - Definition2 : former::FormerDefinition - < - End = #former_add_end< Definition >, - Storage = < < #field_ty as former::Container >::Val as former::EntityToStorage >::Storage, - Formed = Self, - Context = Self, - >, - Definition2::Types : former::FormerDefinitionTypes - < - Storage = < < #field_ty as former::Container >::Val as former::EntityToStorage >::Storage, - Formed = Self, - Context = Self, - >, - Former2 : former::FormerBegin< Definition2 >, - { - Former2::former_begin( None, Some( self ), #former_add_end::default() ) - } - - }; - - // xxx : it should be printed by hint also - let r = if attr.setter() - { - qt! - { - #r - - #[ inline( always ) ] - pub fn #setter_name( self ) -> - < < #field_ty as former::Container >::Val as former::EntityToFormer - < - < - < #field_ty as former::Container >::Val as former::EntityToDefinition< Self, Self, #former_add_end < Definition > > - >::Definition, - > - >::Former - // #as_subformer< Self, impl #as_subformer_end< Self > > - { - self.#field_add - ::< < < #field_ty as former::Container >::Val as former::EntityToFormer< _ > >::Former, _, >() - // ::< #former< _ >, _, >() - } - } - - // #[ inline( always ) ] - // pub fn child( self ) -> - // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - // { - // self._children_add - // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() - // } - - } - else - { - r - }; - - // tree_print!( r.as_ref().unwrap() ); - Ok( r ) -} - -/// -/// Generate a container setter for the 'field_ident' with the 'setter_name' name. -/// -/// # Example of generated code -/// -/// ```ignore -/// pub fn hashmap_strings_1( mut self ) -> former::HashMapSubformer -/// < -/// String, -/// String, -/// std::collections::HashMap< String, String >, -/// Struct1Former, -/// impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self -/// > -/// { -/// let formed = self.hashmap_strings_1.take(); -/// let on_end = | formed : std::collections::HashMap< String, String >, mut former : core::option::Option< Self > | -> Self -/// { -/// former.hashmap_strings_1 = Some( formed ); -/// former -/// }; -/// former::HashMapSubformer::begin_coercing( formed, self, on_end ) -/// } -/// ``` -/// zzz : update example - -#[ inline ] -fn field_container_setter -( - field : &FormerField< '_ >, - stru : &syn::Ident, -) --> TokenStream -{ - let field_ident = &field.ident; - let non_optional_ty = &field.non_optional_ty; - let params = typ::type_parameters( &non_optional_ty, .. ); - - use convert_case::{ Case, Casing }; - let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); - let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); - let field_assign_name = format!( "_{}_assign", field_ident ); - let field_assign = syn::Ident::new( &field_assign_name, field_ident.span() ); - - // example : `former::VectorDefinition` - let subformer_definition = &field.attrs.container.as_ref().unwrap().definition; - let subformer_definition = if subformer_definition.is_some() - { - qt! - { - #subformer_definition - < - #( #params, )* - Self, - Self, - #former_assign_end< Definition >, - > - } - // former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End, > - } - else - { - qt! - { - < #non_optional_ty as former::EntityToDefinition< Self, Self, #former_assign_end< Definition > > >::Definition - } - // < Vec< String > as former::EntityToDefinition< Self, Self, Struct1FormerAssignVec1End > >::Definition - }; - - let doc = format! - ( - "Container setter for the '{}' field. Method {} unlike method {} accept custom container subformer.", - field_ident, - field_assign_name, - field_ident, - ); - - let setter1 = - qt! - { - #[ doc = #doc ] - #[ inline( always ) ] - pub fn #field_assign< Former2 >( self ) -> Former2 - where - Former2 : former::FormerBegin - < - #subformer_definition - >, - { - Former2::former_begin( None, Some( self ), #former_assign_end::< Definition >::default() ) - } - }; - - let setter_name = field.container_setter_name(); - let setter2 = if let Some( setter_name ) = setter_name - { - if params.len() > 1 - { - qt! - { - - #[ doc = #doc ] - #[ inline( always ) ] - pub fn #setter_name( self ) -> - former::ContainerSubformer:: - < - ( #( #params, )* ), #subformer_definition - > - { - self.#field_assign::< former::ContainerSubformer:: - < - ( #( #params, )* ), #subformer_definition - > >() - } - - } - } - else - { - qt! - { - - #[ doc = #doc ] - #[ inline( always ) ] - pub fn #setter_name( self ) -> - former::ContainerSubformer:: - < - #( #params, )* #subformer_definition - > - { - self.#field_assign::< former::ContainerSubformer:: - < - #( #params, )* #subformer_definition - > >() - } - - } - } - } - else - { - qt!{} - }; - - qt! - { - #setter1 - #setter2 - } - -// #[ inline( always ) ] -// pub fn vec_1_assign< Former2 >( self ) -> Former2 -// where -// Former2 : former::FormerBegin -// < -// former::VectorDefinition -// < -// String, -// Self, -// Self, -// Struct1FormerVec_1End, -// > -// >, -// { -// Former2::_begin( None, Some( self ), Struct1FormerVec_1End ) -// } -// -// pub fn vec_1( self ) -> -// former::ContainerSubformer:: -// < -// String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > -// > -// { -// self.vec_1_assign::< former::ContainerSubformer:: -// < -// String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > -// >>() -// } - -} - -/// -/// Generate a single scalar setter for the 'field_ident' with the 'setter_name' name. -/// -/// Used as a helper function for field_setter_map(), which generates alias setters -/// -/// # Example of generated code -/// ```ignore -/// #[ doc = "Setter for the 'int_1' field." ] -/// #[ inline ] -/// pub fn int_1< Src >( mut self, src : Src ) -> Self -/// where -/// Src : ::core::convert::Into< i32 >, -/// { -/// debug_assert!( self.int_1.is_none() ); -/// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); -/// self -/// } -/// ``` - -#[ inline ] -fn field_scalar_setter -( - field : &FormerField< '_ >, -) --> TokenStream -{ - let field_ident = &field.ident; - let typ = &field.non_optional_ty; - let setter_name = field.scalar_setter_name(); - - let doc = format! - ( - "Setter for the '{}' field.", - field_ident, - ); - - qt! - { - #[ doc = #doc ] - #[ inline ] - pub fn #setter_name< Src >( mut self, src : Src ) -> Self - where Src : ::core::convert::Into< #typ >, - { - debug_assert!( self.storage.#field_ident.is_none() ); - self.storage.#field_ident = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); - self - } - } -} - -// zzz : description and exmaple -/// Generate unit struct which is descriptor of callback which should be called after subforming process of a specific field. Childs are used insted of closures to inline code and let optimizer play with optimization. -/// -/// # Example of generated code -/// -/// ```rust, ignore -/// pub struct Struct1FormerVec_1End; -/// #[ automatically_derived ] -/// impl< Definition > former::FormingEnd -/// < -/// former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, -/// > -/// for Struct1FormerVec_1End -/// 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 > -/// { -/// let mut super_former = super_former.unwrap(); -/// if let Some( ref mut field ) = super_former.storage.vec_1 -/// { -/// former::ContainerAssign::assign( field, storage ); -/// } -/// else -/// { -/// super_former.storage.vec_1 = Some( storage ); -/// } -/// super_former -/// } -/// } -/// ``` - -#[ inline ] -fn field_former_assign_end_map -( - field : &FormerField< '_ >, - stru : &syn::Ident, - former : &syn::Ident, - former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, -) --> -Result< TokenStream > -{ - - if field.attrs.container.is_none() - { - return Ok( qt!{ } ); - } - - use convert_case::{ Case, Casing }; - let field_ident = field.ident; - let field_ty = field.non_optional_ty; - let params = typ::type_parameters( field_ty, .. ); - - // example : `ParentFormerAssignChildsEnd`` - let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); - let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); - - // example : `former::VectorDefinition`` - let subformer_definition = &field.attrs.container.as_ref().unwrap().definition; - - // zzz : improve description - let former_assign_end_doc = format! - ( -r#"Callback to return original former after forming of container for `${stru}` is done.# - -Callback replace content of container assigning new content from subformer's storage."# - ); - - let subformer_definition = if subformer_definition.is_some() - { - qt! - { - #subformer_definition < #( #params, )* #former< #former_generics_ty >, #former< #former_generics_ty >, former::NoEnd > - } - // former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd > - } - else - { - qt! - { - < #field_ty as former::EntityToDefinition< #former< #former_generics_ty >, #former< #former_generics_ty >, former::NoEnd > >::Definition - } - // < Vec< String > as former::EntityToDefinition< Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd > >::Definition - }; - - let r = qt! - { - - // zzz : improve description - #[ doc = #former_assign_end_doc ] - pub struct #former_assign_end< Definition > - { - _phantom : core::marker::PhantomData< ( Definition, ) >, - } - - impl< Definition > Default - for #former_assign_end< Definition > - { - - #[ inline( always ) ] - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } - - } - - #[ automatically_derived ] - impl< #former_generics_impl > former::FormingEnd - < - #subformer_definition, - > - for #former_assign_end< Definition > - where - #former_generics_where - { - #[ inline( always ) ] - fn call - ( - &self, - storage : #field_ty, - super_former : Option< #former< #former_generics_ty > >, - ) - -> #former< #former_generics_ty > - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut field ) = super_former.storage.#field_ident - { - former::ContainerAssign::assign( field, storage ); - } - else - { - super_former.storage.#field_ident = Some( storage ); - } - super_former - } - } - - }; - - // tree_print!( r.as_ref().unwrap() ); - Ok( r ) -} - -/// zzz : write documentation - -#[ inline ] -fn field_former_add_end_map -( - field : &FormerField< '_ >, - stru : &syn::Ident, - former : &syn::Ident, - former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - struct_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - struct_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, -) --> -Result< TokenStream > -{ - - if field.attrs.subform.is_none() - { - return Ok( qt!{ } ); - } - - use convert_case::{ Case, Casing }; - let field_ident = field.ident; - let field_ty = field.non_optional_ty; - // let params = typ::type_parameters( &field.non_optional_ty, .. ); - - // example : `ParentFormerAddChildrenEnd`` - let former_add_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); - let former_add_end = syn::Ident::new( &former_add_end_name, field_ident.span() ); - - let r = qt! - { - - // zzz : improve description - /// Handles the completion of an element of subformer's container. - pub struct #former_add_end< Definition > - { - _phantom : core::marker::PhantomData< fn( Definition ) >, - } - - impl< Definition > Default - for #former_add_end< Definition > - { - #[ inline( always ) ] - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } - } - - impl< #struct_generics_impl Types2, Definition > former::FormingEnd< Types2, > - for #former_add_end< Definition > - where - Definition : former::FormerDefinition - < - Storage = < #stru < #struct_generics_ty > as former::EntityToStorage >::Storage, - >, - Types2 : former::FormerDefinitionTypes - < - Storage = < < #field_ty as former::Container >::Val as former::EntityToStorage >::Storage, - Formed = #former< #former_generics_ty >, - Context = #former< #former_generics_ty >, - >, - #struct_generics_where - { - #[ inline( always ) ] - fn call - ( - &self, - substorage : Types2::Storage, - super_former : core::option::Option< Types2::Context >, - ) - -> Types2::Formed - { - let mut super_former = super_former.unwrap(); - if super_former.storage.#field_ident.is_none() - { - super_former.storage.#field_ident = Some( Default::default() ); - } - if let Some( ref mut field ) = super_former.storage.#field_ident - { - former::ContainerAdd::add - ( - field, - < < #field_ty as former::Container >::Val as former::ValToElement< #field_ty > > - ::val_to_element( former::StoragePreform::preform( substorage ) ), - ); - // former::ContainerAdd::add( field, former::StoragePreform::preform( substorage ) ); - } - super_former - } - } - - }; - - // tree_print!( r.as_ref().unwrap() ); - Ok( r ) -} - /// /// Generate documentation for the former. /// @@ -1209,8 +306,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let is_optional = is_optional( ty ); let of_type = container_kind::of_optional( ty ).0; let non_optional_ty : &syn::Type = if is_optional { parameter_internal_first( ty )? } else { ty }; - let former_field = FormerField { attrs, vis, ident, colon_token, ty, non_optional_ty, is_optional, of_type }; - Ok( former_field ) + let field = FormerField { attrs, vis, ident, colon_token, ty, non_optional_ty, is_optional, of_type }; + Ok( field ) }).collect(); let former_fields : Vec< _ > = process_results( former_fields, | iter | iter.collect() )?; @@ -1227,25 +324,23 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > ) : ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) - = former_fields.iter().map( | former_field | + = former_fields.iter().map( | field | {( - field_none_map( former_field ), - field_optional_map( former_field ), - field_form_map( former_field ), - field_name_map( former_field ), - field_setter_map( former_field, &stru ), - field_former_assign_end_map + field.field_none_map(), + field.field_optional_map(), + field.field_form_map(), + field.field_name_map(), + field.field_setter_map( &stru ), + field.field_former_assign_end_map ( - former_field, &stru, &former, &former_generics_impl, &former_generics_ty, &former_generics_where, ), - field_former_add_end_map + field.field_former_add_end_map ( - former_field, &stru, &former, &former_generics_ty, diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index a28d2c1d5e..e239e6546b 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -113,4 +113,906 @@ impl< 'a > FormerField< 'a > return true; } + /// + /// Generate fields for initializer of a struct setting each field to `None`. + /// + /// Used for initializing a Container, where on initialization all fields are None. User can alter them through builder pattern + /// + /// ### Basic use-case. of output + /// + /// ```ignore + /// int_1 : core::option::Option::None, + /// string_1 : core::option::Option::None, + /// int_optional_1 : core::option::Option::None, + /// ``` + /// + + #[ inline( always ) ] + pub fn field_none_map( &self ) -> TokenStream + { + let ident = Some( self.ident.clone() ); + let tokens = qt! { ::core::option::Option::None }; + let ty2 : syn::Type = syn::parse2( tokens ).unwrap(); + + qt! + { + #ident : #ty2 + } + } + + /// + /// Generate field of the former for a field of the structure + /// + /// Used to generate a Container + /// + /// ### Basic use-case. of output + /// + /// ```ignore + /// pub int_1 : core::option::Option< i32 >, + /// pub string_1 : core::option::Option< String >, + /// pub int_optional_1 : core::option::Option< i32 >, + /// pub string_optional_1 : core::option::Option< String >, + /// ``` + /// + + #[ inline( always ) ] + pub fn field_optional_map( &self ) -> TokenStream + { + let ident = Some( self.ident.clone() ); + let ty = self.ty.clone(); + + // let ty2 = if is_optional( &ty ) + let ty2 = if self.is_optional + { + qt! { #ty } + } + else + { + qt! { ::core::option::Option< #ty > } + }; + + qt! + { + pub #ident : #ty2 + } + + } + + /// + /// Generate code converting a field of the former to the field of the structure. + /// + /// In simple terms, used on `form()` call to unwrap contained values from the former's storage. + /// Will try to use default values if no values supplied by the former and the type implements `Default` trait. + /// + /// ### Generated code will look similar to this : + /// + /// ```ignore + /// let int_1 : i32 = if self.storage.int_1.is_some() + /// { + /// // if int_1 is optional + /// Some( self.storage.int_1.take().unwrap() ) + /// + /// // if int_1 isn't optional + /// self.storage.int_1.take().unwrap() + /// } + /// else + /// { + /// // if int_1 is optional and has default + /// Some( i32::default().into() ) + /// + /// // if int_1 is optional and doesn't have default + /// None + /// + /// // if int_1 isn't optional and has default + /// i32::default().into() + /// + /// // if int_1 isn't optional and hasn't default + /// panic!( "Field 'int_1' isn't initialized" ) + /// }; + /// ``` + /// + + #[ inline( always ) ] + pub fn field_form_map( &self ) -> Result< TokenStream > + { + let ident = self.ident; + let ty = self.ty; + let default : Option< &syn::Expr > = self.attrs.config.as_ref() + .and_then( | attr | attr.default.as_ref() ); + + let tokens = if self.is_optional + { + + let _else = match default + { + None => + { + qt! + { + ::core::option::Option::None + } + } + + Some( default_val ) => + { + qt! + { + ::core::option::Option::Some( ::core::convert::Into::into( #default_val ) ) + } + } + }; + + qt! + { + let #ident = if self.#ident.is_some() + { + ::core::option::Option::Some( self.#ident.take().unwrap() ) + } + else + { + #_else + }; + } + + } + else + { + + let _else = match default + { + None => + { + let panic_msg = format!( "Field '{}' isn't initialized", ident ); + qt! + { + { + // By hardly utilizing deref coercion, we achieve conditional trait implementation + trait MaybeDefault< T > + { + fn maybe_default( self : &Self ) -> T { panic!( #panic_msg ) } + } + + // Panic on non-`Default` types + impl< T > MaybeDefault< T > + for &::core::marker::PhantomData< T > + {} + + // Return default value on `Default`` types + impl< T > MaybeDefault< T > + for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default( self : &Self ) -> T + { + T::default() + } + } + + // default if `impl Default`, otherwise - panic + ( &::core::marker::PhantomData::< #ty > ).maybe_default() + } + } + } + Some( default_val ) => + { + qt! + { + ::core::convert::Into::into( #default_val ) + } + } + }; + + qt! + { + let #ident = if self.#ident.is_some() + { + self.#ident.take().unwrap() + } + else + { + #_else + }; + } + + }; + + Ok( tokens ) + } + + /// + /// Extract name of a field out. + /// + + #[ inline( always ) ] + pub fn field_name_map( &self ) -> syn::Ident + { + self.ident.clone() + } + + // zzz : outdated, please update documentation + /// + /// Generate a former setter for the field. + /// + /// If aliases provided, also generate aliases + /// + /// # Example of generated code + /// + /// ```ignore + /// #[ doc = "Setter for the 'int_1' field." ] + /// #[ inline ] + /// pub fn int_1< Src >( mut self, src : Src ) -> Self + /// where + /// Src : ::core::convert::Into< i32 >, + /// { + /// debug_assert!( self.int_1.is_none() ); + /// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + /// self + /// } + /// + /// /// #[ doc = "Setter for the 'int_1' field." ] + /// #[ inline ] + /// pub fn int_1_alias< Src >( mut self, src : Src ) -> Self + /// where + /// Src : ::core::convert::Into< i32 >, + /// { + /// debug_assert!( self.int_1.is_none() ); + /// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + /// self + /// } + /// ``` + + #[ inline ] + pub fn field_setter_map + ( + &self, + stru : &syn::Ident, + ) + -> Result< TokenStream > + { + let r = qt!{}; + + // scalar setter + let r = if self.scalar_setter_required() + { + let r2 = self.field_scalar_setter(); + qt! + { + #r + #r2 + } + } + else + { + r + }; + + // container setter + let r = if let Some( _ ) = &self.attrs.container + { + let r2 = self.field_container_setter( stru ); + qt! + { + #r + #r2 + } + } + else + { + r + }; + + // subform setter + let r = if self.attrs.subform.is_some() + { + let r2 = self.field_subform_add_setter_map( stru )?; + qt! + { + #r + #r2 + } + } + else + { + r + }; + + // tree_print!( r.as_ref().unwrap() ); + Ok( r ) + } + + /// zzz : write documentation + #[ inline ] + pub fn field_subform_add_setter_map + ( + &self, + stru : &syn::Ident, + ) + -> Result< TokenStream > + { + + if self.attrs.subform.is_none() + { + return Ok( qt!{ } ); + } + + use convert_case::{ Case, Casing }; + let field_ident = self.ident; + let field_ty = self.non_optional_ty; + let attr = self.attrs.subform.as_ref().unwrap(); + // let params = typ::type_parameters( &self.non_optional_ty, .. ); + + // example : `child` + let setter_name = self.subform_setter_name(); + + // example : `ParentFormerAddChildrenEnd`` + let former_add_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let former_add_end = syn::Ident::new( &former_add_end_name, field_ident.span() ); + + // example : `_children_former` + let field_add_name = format!( "_{}_add", field_ident ); + let field_add = syn::Ident::new( &field_add_name, field_ident.span() ); + + let r = qt! + { + + // zzz : improve documentation + /// Setter returning former of element of container of the field as subformer. + #[ inline( always ) ] + pub fn #field_add< Former2, Definition2 >( self ) -> Former2 + where + Definition2 : former::FormerDefinition + < + End = #former_add_end< Definition >, + Storage = < < #field_ty as former::Container >::Val as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Definition2::Types : former::FormerDefinitionTypes + < + Storage = < < #field_ty as former::Container >::Val as former::EntityToStorage >::Storage, + Formed = Self, + Context = Self, + >, + Former2 : former::FormerBegin< Definition2 >, + { + Former2::former_begin( None, Some( self ), #former_add_end::default() ) + } + + }; + + // xxx : it should be printed by hint also + let r = if attr.setter() + { + qt! + { + #r + + #[ inline( always ) ] + pub fn #setter_name( self ) -> + < < #field_ty as former::Container >::Val as former::EntityToFormer + < + < + < #field_ty as former::Container >::Val as former::EntityToDefinition< Self, Self, #former_add_end < Definition > > + >::Definition, + > + >::Former + // #as_subformer< Self, impl #as_subformer_end< Self > > + { + self.#field_add + ::< < < #field_ty as former::Container >::Val as former::EntityToFormer< _ > >::Former, _, >() + // ::< #former< _ >, _, >() + } + } + + // #[ inline( always ) ] + // pub fn child( self ) -> + // ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + // { + // self._children_add + // ::< < Child as former::EntityToFormer< _ > >::Former, _, >() + // } + + } + else + { + r + }; + + // tree_print!( r.as_ref().unwrap() ); + Ok( r ) + } + + /// + /// Generate a container setter for the 'field_ident' with the 'setter_name' name. + /// + /// # Example of generated code + /// + /// ```ignore + /// pub fn hashmap_strings_1( mut self ) -> former::HashMapSubformer + /// < + /// String, + /// String, + /// std::collections::HashMap< String, String >, + /// Struct1Former, + /// impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self + /// > + /// { + /// let formed = self.hashmap_strings_1.take(); + /// let on_end = | formed : std::collections::HashMap< String, String >, mut former : core::option::Option< Self > | -> Self + /// { + /// former.hashmap_strings_1 = Some( formed ); + /// former + /// }; + /// former::HashMapSubformer::begin_coercing( formed, self, on_end ) + /// } + /// ``` + /// zzz : update example + + #[ inline ] + pub fn field_container_setter + ( + &self, + stru : &syn::Ident, + ) + -> TokenStream + { + let field_ident = &self.ident; + let non_optional_ty = &self.non_optional_ty; + let params = typ::type_parameters( &non_optional_ty, .. ); + + use convert_case::{ Case, Casing }; + let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); + let field_assign_name = format!( "_{}_assign", field_ident ); + let field_assign = syn::Ident::new( &field_assign_name, field_ident.span() ); + + // example : `former::VectorDefinition` + let subformer_definition = &self.attrs.container.as_ref().unwrap().definition; + let subformer_definition = if subformer_definition.is_some() + { + qt! + { + #subformer_definition + < + #( #params, )* + Self, + Self, + #former_assign_end< Definition >, + > + } + // former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End, > + } + else + { + qt! + { + < #non_optional_ty as former::EntityToDefinition< Self, Self, #former_assign_end< Definition > > >::Definition + } + // < Vec< String > as former::EntityToDefinition< Self, Self, Struct1FormerAssignVec1End > >::Definition + }; + + let doc = format! + ( + "Container setter for the '{}' field. Method {} unlike method {} accept custom container subformer.", + field_ident, + field_assign_name, + field_ident, + ); + + let setter1 = + qt! + { + #[ doc = #doc ] + #[ inline( always ) ] + pub fn #field_assign< Former2 >( self ) -> Former2 + where + Former2 : former::FormerBegin + < + #subformer_definition + >, + { + Former2::former_begin( None, Some( self ), #former_assign_end::< Definition >::default() ) + } + }; + + let setter_name = self.container_setter_name(); + let setter2 = if let Some( setter_name ) = setter_name + { + if params.len() > 1 + { + qt! + { + + #[ doc = #doc ] + #[ inline( always ) ] + pub fn #setter_name( self ) -> + former::ContainerSubformer:: + < + ( #( #params, )* ), #subformer_definition + > + { + self.#field_assign::< former::ContainerSubformer:: + < + ( #( #params, )* ), #subformer_definition + > >() + } + + } + } + else + { + qt! + { + + #[ doc = #doc ] + #[ inline( always ) ] + pub fn #setter_name( self ) -> + former::ContainerSubformer:: + < + #( #params, )* #subformer_definition + > + { + self.#field_assign::< former::ContainerSubformer:: + < + #( #params, )* #subformer_definition + > >() + } + + } + } + } + else + { + qt!{} + }; + + qt! + { + #setter1 + #setter2 + } + + // #[ inline( always ) ] + // pub fn vec_1_assign< Former2 >( self ) -> Former2 + // where + // Former2 : former::FormerBegin + // < + // former::VectorDefinition + // < + // String, + // Self, + // Self, + // Struct1FormerVec_1End, + // > + // >, + // { + // Former2::_begin( None, Some( self ), Struct1FormerVec_1End ) + // } + // + // pub fn vec_1( self ) -> + // former::ContainerSubformer:: + // < + // String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > + // > + // { + // self.vec_1_assign::< former::ContainerSubformer:: + // < + // String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > + // >>() + // } + + } + + /// + /// Generate a single scalar setter for the 'field_ident' with the 'setter_name' name. + /// + /// Used as a helper function for field_setter_map(), which generates alias setters + /// + /// # Example of generated code + /// ```ignore + /// #[ doc = "Setter for the 'int_1' field." ] + /// #[ inline ] + /// pub fn int_1< Src >( mut self, src : Src ) -> Self + /// where + /// Src : ::core::convert::Into< i32 >, + /// { + /// debug_assert!( self.int_1.is_none() ); + /// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + /// self + /// } + /// ``` + + #[ inline ] + pub fn field_scalar_setter + ( + &self, + ) + -> TokenStream + { + let field_ident = &self.ident; + let typ = &self.non_optional_ty; + let setter_name = self.scalar_setter_name(); + + let doc = format! + ( + "Setter for the '{}' field.", + field_ident, + ); + + qt! + { + #[ doc = #doc ] + #[ inline ] + pub fn #setter_name< Src >( mut self, src : Src ) -> Self + where Src : ::core::convert::Into< #typ >, + { + debug_assert!( self.storage.#field_ident.is_none() ); + self.storage.#field_ident = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + self + } + } + } + + // zzz : description and exmaple + /// Generate unit struct which is descriptor of callback which should be called after subforming process of a specific field. Childs are used insted of closures to inline code and let optimizer play with optimization. + /// + /// # Example of generated code + /// + /// ```rust, ignore + /// pub struct Struct1FormerVec_1End; + /// #[ automatically_derived ] + /// impl< Definition > former::FormingEnd + /// < + /// former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, + /// > + /// for Struct1FormerVec_1End + /// where + /// Definition : former::FormerDefinition, + /// Definition::Types : former::FormerDefinitionTypes + /// < + /// Storage = Struct1FormerStorage + /// >, + /// { + /// #[ inline( always ) ] + /// pub 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 + /// { + /// former::ContainerAssign::assign( field, storage ); + /// } + /// else + /// { + /// super_former.storage.vec_1 = Some( storage ); + /// } + /// super_former + /// } + /// } + /// ``` + + #[ inline ] + pub fn field_former_assign_end_map + ( + &self, + stru : &syn::Ident, + former : &syn::Ident, + former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, + ) + -> + Result< TokenStream > + { + + if self.attrs.container.is_none() + { + return Ok( qt!{ } ); + } + + use convert_case::{ Case, Casing }; + let field_ident = self.ident; + let field_ty = self.non_optional_ty; + let params = typ::type_parameters( field_ty, .. ); + + // example : `ParentFormerAssignChildsEnd`` + let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); + + // example : `former::VectorDefinition`` + let subformer_definition = &self.attrs.container.as_ref().unwrap().definition; + + // zzz : improve description + let former_assign_end_doc = format! + ( + r#"Callback to return original former after forming of container for `${stru}` is done.# + + Callback replace content of container assigning new content from subformer's storage."# + ); + + let subformer_definition = if subformer_definition.is_some() + { + qt! + { + #subformer_definition < #( #params, )* #former< #former_generics_ty >, #former< #former_generics_ty >, former::NoEnd > + } + // former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd > + } + else + { + qt! + { + < #field_ty as former::EntityToDefinition< #former< #former_generics_ty >, #former< #former_generics_ty >, former::NoEnd > >::Definition + } + // < Vec< String > as former::EntityToDefinition< Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd > >::Definition + }; + + let r = qt! + { + + // zzz : improve description + #[ doc = #former_assign_end_doc ] + pub struct #former_assign_end< Definition > + { + _phantom : core::marker::PhantomData< ( Definition, ) >, + } + + impl< Definition > Default + for #former_assign_end< Definition > + { + + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + + } + + #[ automatically_derived ] + impl< #former_generics_impl > former::FormingEnd + < + #subformer_definition, + > + for #former_assign_end< Definition > + where + #former_generics_where + { + #[ inline( always ) ] + fn call + ( + &self, + storage : #field_ty, + super_former : Option< #former< #former_generics_ty > >, + ) + -> #former< #former_generics_ty > + { + let mut super_former = super_former.unwrap(); + if let Some( ref mut field ) = super_former.storage.#field_ident + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.#field_ident = Some( storage ); + } + super_former + } + } + + }; + + // tree_print!( r.as_ref().unwrap() ); + Ok( r ) + } + + /// zzz : write documentation + + #[ inline ] + pub fn field_former_add_end_map + ( + &self, + stru : &syn::Ident, + former : &syn::Ident, + former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + struct_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + struct_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, + ) + -> + Result< TokenStream > + { + + if self.attrs.subform.is_none() + { + return Ok( qt!{ } ); + } + + use convert_case::{ Case, Casing }; + let field_ident = self.ident; + let field_ty = self.non_optional_ty; + // let params = typ::type_parameters( &self.non_optional_ty, .. ); + + // example : `ParentFormerAddChildrenEnd`` + let former_add_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + let former_add_end = syn::Ident::new( &former_add_end_name, field_ident.span() ); + + let r = qt! + { + + // zzz : improve description + /// Handles the completion of an element of subformer's container. + pub struct #former_add_end< Definition > + { + _phantom : core::marker::PhantomData< fn( Definition ) >, + } + + impl< Definition > Default + for #former_add_end< Definition > + { + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + } + + impl< #struct_generics_impl Types2, Definition > former::FormingEnd< Types2, > + for #former_add_end< Definition > + where + Definition : former::FormerDefinition + < + Storage = < #stru < #struct_generics_ty > as former::EntityToStorage >::Storage, + >, + Types2 : former::FormerDefinitionTypes + < + Storage = < < #field_ty as former::Container >::Val as former::EntityToStorage >::Storage, + Formed = #former< #former_generics_ty >, + Context = #former< #former_generics_ty >, + >, + #struct_generics_where + { + #[ inline( always ) ] + fn call + ( + &self, + substorage : Types2::Storage, + super_former : core::option::Option< Types2::Context >, + ) + -> Types2::Formed + { + let mut super_former = super_former.unwrap(); + if super_former.storage.#field_ident.is_none() + { + super_former.storage.#field_ident = Some( Default::default() ); + } + if let Some( ref mut field ) = super_former.storage.#field_ident + { + former::ContainerAdd::add + ( + field, + < < #field_ty as former::Container >::Val as former::ValToElement< #field_ty > > + ::val_to_element( former::StoragePreform::preform( substorage ) ), + ); + } + super_former + } + } + + }; + + // tree_print!( r.as_ref().unwrap() ); + Ok( r ) + } + } From 1655be59f3ebb2d66d47573cad4d1359e857014d Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 23:31:23 +0300 Subject: [PATCH 411/533] former : experimenting --- module/core/former_meta/src/derive_former.rs | 20 +++----- .../former_meta/src/derive_former/field.rs | 48 +++++++++++++------ .../src/derive_former/field_attrs.rs | 26 +++++----- .../src/derive_former/struct_attrs.rs | 10 ++++ 4 files changed, 62 insertions(+), 42 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 047223fa60..89dc0ffc62 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -98,9 +98,6 @@ For specifying custom default value use attribute `default`. For example: pub fn performer< 'a > ( - _struct_name : &syn::Ident, - // _former_definition : &syn::Ident, - // _generics_ty : &syn::TypeGenerics< '_ >, attrs : impl Iterator< Item = &'a syn::Attribute >, ) -> Result< ( TokenStream, TokenStream, TokenStream ) > @@ -273,9 +270,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( perform, perform_output, perform_generics ) = performer ( - &stru, - // &former_definition, - // &struct_generics_ty, ast.attrs.iter(), )?; @@ -326,12 +320,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) = former_fields.iter().map( | field | {( - field.field_none_map(), - field.field_optional_map(), - field.field_form_map(), - field.field_name_map(), - field.field_setter_map( &stru ), - field.field_former_assign_end_map + field.none_map(), + field.optional_map(), + field.form_map(), + field.name_map(), + field.setter_map( &stru ), + field.former_assign_end_map ( &stru, &former, @@ -339,7 +333,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > &former_generics_ty, &former_generics_where, ), - field.field_former_add_end_map + field.former_add_end_map ( &stru, &former, diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index e239e6546b..e9fd288f61 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -22,6 +22,26 @@ pub struct FormerField< 'a > impl< 'a > FormerField< 'a > { +/* + +scalar_setter_name +container_setter_name +subform_setter_name +scalar_setter_required + +none_map +optional_map +form_map +name_map +setter_map +subform_add_setter_map +container_setter +scalar_setter +former_assign_end_map +former_add_end_map + +*/ + /// Get name of scalar setter. pub fn scalar_setter_name( &self ) -> &syn::Ident { @@ -128,7 +148,7 @@ impl< 'a > FormerField< 'a > /// #[ inline( always ) ] - pub fn field_none_map( &self ) -> TokenStream + pub fn none_map( &self ) -> TokenStream { let ident = Some( self.ident.clone() ); let tokens = qt! { ::core::option::Option::None }; @@ -156,7 +176,7 @@ impl< 'a > FormerField< 'a > /// #[ inline( always ) ] - pub fn field_optional_map( &self ) -> TokenStream + pub fn optional_map( &self ) -> TokenStream { let ident = Some( self.ident.clone() ); let ty = self.ty.clone(); @@ -213,7 +233,7 @@ impl< 'a > FormerField< 'a > /// #[ inline( always ) ] - pub fn field_form_map( &self ) -> Result< TokenStream > + pub fn form_map( &self ) -> Result< TokenStream > { let ident = self.ident; let ty = self.ty; @@ -324,7 +344,7 @@ impl< 'a > FormerField< 'a > /// #[ inline( always ) ] - pub fn field_name_map( &self ) -> syn::Ident + pub fn name_map( &self ) -> syn::Ident { self.ident.clone() } @@ -362,7 +382,7 @@ impl< 'a > FormerField< 'a > /// ``` #[ inline ] - pub fn field_setter_map + pub fn setter_map ( &self, stru : &syn::Ident, @@ -374,7 +394,7 @@ impl< 'a > FormerField< 'a > // scalar setter let r = if self.scalar_setter_required() { - let r2 = self.field_scalar_setter(); + let r2 = self.scalar_setter(); qt! { #r @@ -389,7 +409,7 @@ impl< 'a > FormerField< 'a > // container setter let r = if let Some( _ ) = &self.attrs.container { - let r2 = self.field_container_setter( stru ); + let r2 = self.container_setter( stru ); qt! { #r @@ -404,7 +424,7 @@ impl< 'a > FormerField< 'a > // subform setter let r = if self.attrs.subform.is_some() { - let r2 = self.field_subform_add_setter_map( stru )?; + let r2 = self.subform_add_setter_map( stru )?; qt! { #r @@ -422,7 +442,7 @@ impl< 'a > FormerField< 'a > /// zzz : write documentation #[ inline ] - pub fn field_subform_add_setter_map + pub fn subform_add_setter_map ( &self, stru : &syn::Ident, @@ -549,7 +569,7 @@ impl< 'a > FormerField< 'a > /// zzz : update example #[ inline ] - pub fn field_container_setter + pub fn container_setter ( &self, stru : &syn::Ident, @@ -706,7 +726,7 @@ impl< 'a > FormerField< 'a > /// /// Generate a single scalar setter for the 'field_ident' with the 'setter_name' name. /// - /// Used as a helper function for field_setter_map(), which generates alias setters + /// Used as a helper function for setter_map(), which generates alias setters /// /// # Example of generated code /// ```ignore @@ -723,7 +743,7 @@ impl< 'a > FormerField< 'a > /// ``` #[ inline ] - pub fn field_scalar_setter + pub fn scalar_setter ( &self, ) @@ -796,7 +816,7 @@ impl< 'a > FormerField< 'a > /// ``` #[ inline ] - pub fn field_former_assign_end_map + pub fn former_assign_end_map ( &self, stru : &syn::Ident, @@ -916,7 +936,7 @@ impl< 'a > FormerField< 'a > /// zzz : write documentation #[ inline ] - pub fn field_former_add_end_map + pub fn former_add_end_map ( &self, stru : &syn::Ident, diff --git a/module/core/former_meta/src/derive_former/field_attrs.rs b/module/core/former_meta/src/derive_former/field_attrs.rs index cf3877d8ee..f044103961 100644 --- a/module/core/former_meta/src/derive_former/field_attrs.rs +++ b/module/core/former_meta/src/derive_former/field_attrs.rs @@ -40,10 +40,6 @@ impl FieldAttributes { match attr.meta { - // syn::Meta::List( ref meta_list ) => - // { - // config.replace( syn::parse2::< AttributeConfig >( meta_list.tokens.clone() )? ); - // }, syn::Meta::List( ref meta_list ) => { config.replace( syn::parse2::< AttributeConfig >( meta_list.tokens.clone() )? ); @@ -122,9 +118,9 @@ pub struct AttributeConfig /// Default value to use for the field. pub default : Option< syn::Expr >, - /// Such field should be present only in storage and should not be present in structure itself. - /// That might be useful for parametrization of forming process. - pub only_storage : Option< bool >, + // /// Such field should be present only in storage and should not be present in structure itself. + // /// That might be useful for parametrization of forming process. + // pub only_storage : Option< bool >, } @@ -137,7 +133,7 @@ impl syn::parse::Parse for AttributeConfig fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > { let mut default : Option< syn::Expr > = None; - let mut only_storage : Option< bool > = None; + // let mut only_storage : Option< bool > = None; while !input.is_empty() { @@ -150,12 +146,12 @@ impl syn::parse::Parse for AttributeConfig input.parse::< syn::Token![ = ] >()?; default = Some( input.parse()? ); } - else if ident == "only_storage" - { - input.parse::< syn::Token![ = ] >()?; - let value : syn::LitBool = input.parse()?; - only_storage = Some( value.value() ); - } + // else if ident == "only_storage" + // { + // input.parse::< syn::Token![ = ] >()?; + // let value : syn::LitBool = input.parse()?; + // only_storage = Some( value.value() ); + // } else { return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'default'. For example: `former( default = 13 )`", ident ) ) ); @@ -174,7 +170,7 @@ impl syn::parse::Parse for AttributeConfig } } - Ok( Self { default, only_storage } ) + Ok( Self { default } ) } } diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs index bc45563136..6eb79ada56 100644 --- a/module/core/former_meta/src/derive_former/struct_attrs.rs +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -21,6 +21,7 @@ impl StructAttributes pub fn from_attrs< 'a >( attrs : impl Iterator< Item = &'a syn::Attribute > ) -> Result< Self > { let mut perform = None; + for attr in attrs { let key_ident = attr.path().get_ident() @@ -39,6 +40,15 @@ impl StructAttributes } "perform" => { + match attr.meta + { + syn::Meta::List( ref meta_list ) => + { + perform.replace( syn::parse2::< AttributePerform >( meta_list.tokens.clone() )? ); + }, + _ => return_syn_err!( attr, "Expects an attribute of format #[ perform( fn parse( mut self ) -> Request ) ] +.\nGot: {}", qt!{ #attr } ), + } } "debug" => { From e7163317382d44e4ea966738755872fe23f7bf01 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 23:47:31 +0300 Subject: [PATCH 412/533] former : experimenting --- module/core/former_meta/src/derive_former.rs | 89 ++++++++++++------- .../former_meta/src/derive_former/field.rs | 2 +- .../src/derive_former/struct_attrs.rs | 2 +- 3 files changed, 57 insertions(+), 36 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 89dc0ffc62..47ee160f64 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -98,7 +98,8 @@ For specifying custom default value use attribute `default`. For example: pub fn performer< 'a > ( - attrs : impl Iterator< Item = &'a syn::Attribute >, + attrs : &StructAttributes, + // attrs : impl Iterator< Item = &'a syn::Attribute >, ) -> Result< ( TokenStream, TokenStream, TokenStream ) > { @@ -109,44 +110,64 @@ pub fn performer< 'a > }; // let mut perform_output = qt!{ #stru #generics_ty_ }; let mut perform_output = qt!{ < Definition::Types as former::FormerDefinitionTypes >::Formed }; - let mut perform_generics = qt!{}; - for attr in attrs + + if let Some( ref attr ) = attrs.perform { - if let Some( ident ) = attr.path().get_ident() + + // let attr_perform = syn::parse2::< AttributePerform >( meta_list.tokens.clone() )?; + let signature = &attr.signature; + let generics = &signature.generics; + perform_generics = qt!{ #generics }; + let perform_ident = &signature.ident; + let output = &signature.output; + if let syn::ReturnType::Type( _, boxed_type ) = output { - let ident_string = format!( "{}", ident ); - if ident_string == "perform" - { - match attr.meta - { - syn::Meta::List( ref meta_list ) => - { - let attr_perform = syn::parse2::< AttributePerform >( meta_list.tokens.clone() )?; - let signature = &attr_perform.signature; - let generics = &signature.generics; - perform_generics = qt!{ #generics }; - let perform_ident = &signature.ident; - let output = &signature.output; - if let syn::ReturnType::Type( _, boxed_type ) = output - { - perform_output = qt!{ #boxed_type }; - } - perform = qt! - { - return result.#perform_ident(); - }; - }, - _ => return_syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ), - } - } + perform_output = qt!{ #boxed_type }; } - else + perform = qt! { - return_syn_err!( "Unknown structure attribute:\n{}", qt!{ attr } ); - } + return result.#perform_ident(); + }; + } + // for attr in attrs + // { + // if let Some( ident ) = attr.path().get_ident() + // { + // let ident_string = format!( "{}", ident ); + // if ident_string == "perform" + // { + // match attr.meta + // { + // syn::Meta::List( ref meta_list ) => + // { + // let attr_perform = syn::parse2::< AttributePerform >( meta_list.tokens.clone() )?; + // let signature = &attr_perform.signature; + // let generics = &signature.generics; + // perform_generics = qt!{ #generics }; + // let perform_ident = &signature.ident; + // let output = &signature.output; + // if let syn::ReturnType::Type( _, boxed_type ) = output + // { + // perform_output = qt!{ #boxed_type }; + // } + // perform = qt! + // { + // return result.#perform_ident(); + // }; + // }, + // _ => return_syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ), + // } + // } + // } + // else + // { + // return_syn_err!( "Unknown structure attribute:\n{}", qt!{ attr } ); + // } + // } + Ok( ( perform, perform_output, perform_generics ) ) } @@ -270,7 +291,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( perform, perform_output, perform_generics ) = performer ( - ast.attrs.iter(), + &struct_attrs + // ast.attrs.iter(), )?; /* */ @@ -523,7 +545,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { type Preformed = #stru < #struct_generics_ty >; - // fn preform( mut self ) -> < Self as former::Storage >::Formed fn preform( mut self ) -> Self::Preformed { #( #fields_form )* diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index e9fd288f61..e542cf0277 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -22,7 +22,7 @@ pub struct FormerField< 'a > impl< 'a > FormerField< 'a > { -/* +/** methods scalar_setter_name container_setter_name diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs index 6eb79ada56..42f975ea0c 100644 --- a/module/core/former_meta/src/derive_former/struct_attrs.rs +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -12,7 +12,7 @@ use macro_tools::{ attr, Result }; pub struct StructAttributes { - perform : Option< AttributePerform >, + pub perform : Option< AttributePerform >, } impl StructAttributes From 01411bba4ced606caf855809f5e4813ec11dc6f4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 3 May 2024 23:48:44 +0300 Subject: [PATCH 413/533] former : experimenting --- module/core/former_meta/src/derive_former.rs | 39 +------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 47ee160f64..0f7fb42305 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -108,8 +108,7 @@ pub fn performer< 'a > { return result; }; - // let mut perform_output = qt!{ #stru #generics_ty_ }; - let mut perform_output = qt!{ < Definition::Types as former::FormerDefinitionTypes >::Formed }; + let mut perform_output = qt!{ Definition::Formed }; let mut perform_generics = qt!{}; if let Some( ref attr ) = attrs.perform @@ -132,42 +131,6 @@ pub fn performer< 'a > } - // for attr in attrs - // { - // if let Some( ident ) = attr.path().get_ident() - // { - // let ident_string = format!( "{}", ident ); - // if ident_string == "perform" - // { - // match attr.meta - // { - // syn::Meta::List( ref meta_list ) => - // { - // let attr_perform = syn::parse2::< AttributePerform >( meta_list.tokens.clone() )?; - // let signature = &attr_perform.signature; - // let generics = &signature.generics; - // perform_generics = qt!{ #generics }; - // let perform_ident = &signature.ident; - // let output = &signature.output; - // if let syn::ReturnType::Type( _, boxed_type ) = output - // { - // perform_output = qt!{ #boxed_type }; - // } - // perform = qt! - // { - // return result.#perform_ident(); - // }; - // }, - // _ => return_syn_err!( attr, "Expects an attribute of format #[ attribute( val ) ], but got:\n {}", qt!{ #attr } ), - // } - // } - // } - // else - // { - // return_syn_err!( "Unknown structure attribute:\n{}", qt!{ attr } ); - // } - // } - Ok( ( perform, perform_output, perform_generics ) ) } From 27fea10cd65fd9632b7c6b62fd174b419c66d210 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 00:11:22 +0300 Subject: [PATCH 414/533] former : experimenting --- module/core/former_meta/src/derive_former.rs | 21 +++++++---------- module/core/macro_tools/src/typ.rs | 24 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 0f7fb42305..63fb699d22 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -30,7 +30,7 @@ fn is_optional( ty : &syn::Type ) -> bool /// Extract the first parameter of the type if such exist. /// -fn parameter_internal_first( ty : &syn::Type ) -> Result< &syn::Type > +fn parameter_first( ty : &syn::Type ) -> Result< &syn::Type > { typ::type_parameters( ty, 0 ..= 0 ) .first() @@ -250,14 +250,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_definition_phantom = macro_tools::phantom::tuple( &former_definition_generics_impl ); - /* structure attribute */ - - let ( perform, perform_output, perform_generics ) = performer - ( - &struct_attrs - // ast.attrs.iter(), - )?; - /* */ let fields = match ast.data @@ -284,7 +276,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ty = &field.ty; let is_optional = is_optional( ty ); let of_type = container_kind::of_optional( ty ).0; - let non_optional_ty : &syn::Type = if is_optional { parameter_internal_first( ty )? } else { ty }; + let non_optional_ty : &syn::Type = if is_optional { parameter_first( ty )? } else { ty }; let field = FormerField { attrs, vis, ident, colon_token, ty, non_optional_ty, is_optional, of_type }; Ok( field ) }).collect(); @@ -329,12 +321,17 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > ), )}).multiunzip(); - let ( _doc_former_mod, doc_former_struct ) = doc_generate( stru ); let fields_setter : Vec< _ > = process_results( fields_setter, | iter | iter.collect() )?; let fields_form : Vec< _ > = process_results( fields_form, | iter | iter.collect() )?; let fields_former_assign : Vec< _ > = process_results( fields_former_assign, | iter | iter.collect() )?; let fields_former_add : Vec< _ > = process_results( fields_former_add, | iter | iter.collect() )?; + let ( _doc_former_mod, doc_former_struct ) = doc_generate( stru ); + let ( perform, perform_output, perform_generics ) = performer + ( + &struct_attrs + )?; + let result = qt! { @@ -389,7 +386,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = definition types #[ derive( Debug ) ] - // pub struct #former_definition_types < #former_definition_type_generics_impl > pub struct #former_definition_types < #former_definition_type_generics_with_defaults > where #former_definition_type_generics_where @@ -425,7 +421,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = definition #[ derive( Debug ) ] - // pub struct #former_definition < #former_definition_generics_impl > pub struct #former_definition < #former_definition_generics_with_defaults > where #former_definition_generics_where diff --git a/module/core/macro_tools/src/typ.rs b/module/core/macro_tools/src/typ.rs index 10fe4047b1..48422a7665 100644 --- a/module/core/macro_tools/src/typ.rs +++ b/module/core/macro_tools/src/typ.rs @@ -108,6 +108,28 @@ pub( crate ) mod private // None // } + /// + /// Is type under Option. + /// + + // xxx : move + pub fn is_optional( ty : &syn::Type ) -> bool + { + typ::type_rightmost( ty ) == Some( "Option".to_string() ) + } + + /// + /// Extract the first parameter of the type if such exist. + /// + + pub fn parameter_first( ty : &syn::Type ) -> Result< &syn::Type > + { + typ::type_parameters( ty, 0 ..= 0 ) + .first() + .copied() + .ok_or_else( || syn_err!( ty, "Expects at least one parameter here:\n {}", qt!{ #ty } ) ) + } + } #[ doc( inline ) ] @@ -127,6 +149,8 @@ pub mod protected type_rightmost, type_parameters, // all_type_parameters, + is_optional, + parameter_first, }; } From ecc18dfe4b22da516efc18e3d527fe6048f1a7e9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 00:12:01 +0300 Subject: [PATCH 415/533] former : experimenting --- module/core/former_meta/src/derive_former.rs | 26 ++------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 63fb699d22..1e1913e190 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -16,28 +16,6 @@ use field_attrs::*; mod struct_attrs; use struct_attrs::*; -/// -/// Is type under Option. -/// - -// xxx : move -fn is_optional( ty : &syn::Type ) -> bool -{ - typ::type_rightmost( ty ) == Some( "Option".to_string() ) -} - -/// -/// Extract the first parameter of the type if such exist. -/// - -fn parameter_first( ty : &syn::Type ) -> Result< &syn::Type > -{ - typ::type_parameters( ty, 0 ..= 0 ) - .first() - .copied() - .ok_or_else( || syn_err!( ty, "Expects at least one parameter here:\n {}", qt!{ #ty } ) ) -} - /// /// Generate documentation for the former. /// @@ -274,9 +252,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > .ok_or_else( || syn_err!( field, "Expected that each field has key, but some does not:\n {}", qt!{ #field } ) )?; let colon_token = &field.colon_token; let ty = &field.ty; - let is_optional = is_optional( ty ); + let is_optional = typ::is_optional( ty ); let of_type = container_kind::of_optional( ty ).0; - let non_optional_ty : &syn::Type = if is_optional { parameter_first( ty )? } else { ty }; + let non_optional_ty : &syn::Type = if is_optional { typ::parameter_first( ty )? } else { ty }; let field = FormerField { attrs, vis, ident, colon_token, ty, non_optional_ty, is_optional, of_type }; Ok( field ) }).collect(); From 203160e2acecfddc50cc17719f6cc9cc666fa009 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 00:13:47 +0300 Subject: [PATCH 416/533] former : experimenting --- module/core/former_meta/src/derive_former.rs | 1 - module/core/macro_tools/src/typ.rs | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 1e1913e190..944be53ecd 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -243,7 +243,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > _ => return Err( syn_err!( ast, "Unknown format of data, expected syn::Data::Struct( ref data_struct )\n {}", qt!{ #ast } ) ), }; - // xxx : move let former_fields : Vec< Result< FormerField< '_ > > > = fields.iter().map( | field | { let attrs = FieldAttributes::from_attrs( field.attrs.iter() )?; diff --git a/module/core/macro_tools/src/typ.rs b/module/core/macro_tools/src/typ.rs index 48422a7665..faf9698356 100644 --- a/module/core/macro_tools/src/typ.rs +++ b/module/core/macro_tools/src/typ.rs @@ -112,7 +112,7 @@ pub( crate ) mod private /// Is type under Option. /// - // xxx : move + // qqq : cover by test pub fn is_optional( ty : &syn::Type ) -> bool { typ::type_rightmost( ty ) == Some( "Option".to_string() ) @@ -122,6 +122,7 @@ pub( crate ) mod private /// Extract the first parameter of the type if such exist. /// + // qqq : cover by test pub fn parameter_first( ty : &syn::Type ) -> Result< &syn::Type > { typ::type_parameters( ty, 0 ..= 0 ) From bbdef9306b2acb576fbb7e8e128f53d2bed6bb5d Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 00:37:09 +0300 Subject: [PATCH 417/533] former : experimenting --- module/core/former_meta/src/derive_former.rs | 30 ++++++++++-- .../src/derive_former/struct_attrs.rs | 46 +++++++++++++++++-- 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 944be53ecd..fe97d89394 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -74,10 +74,9 @@ For specifying custom default value use attribute `default`. For example: /// ## perform_generics : /// Vec< T > -pub fn performer< 'a > +pub fn performer ( attrs : &StructAttributes, - // attrs : impl Iterator< Item = &'a syn::Attribute >, ) -> Result< ( TokenStream, TokenStream, TokenStream ) > { @@ -112,7 +111,27 @@ pub fn performer< 'a > Ok( ( perform, perform_output, perform_generics ) ) } -// +/// xxx : write documentation. provide example of generated code + +pub fn storage_fields +( + attrs : &StructAttributes, +) +-> Result< TokenStream > +{ + + let mut result = qt! + { + }; + + if let Some( ref attr ) = attrs.storage_fields + { + let storage_fields = &attr.fields; + result = qt! { #storage_fields } + } + + Ok( result ) +} /// /// Generate the whole Former ecosystem @@ -309,6 +328,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > &struct_attrs )?; + let storage_fields = storage_fields + ( + &struct_attrs + )?; + let result = qt! { diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs index 42f975ea0c..c6fef76d0e 100644 --- a/module/core/former_meta/src/derive_former/struct_attrs.rs +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -13,6 +13,7 @@ use macro_tools::{ attr, Result }; pub struct StructAttributes { pub perform : Option< AttributePerform >, + pub storage_fields : Option< AttributeStorageFields >, } impl StructAttributes @@ -21,6 +22,7 @@ impl StructAttributes pub fn from_attrs< 'a >( attrs : impl Iterator< Item = &'a syn::Attribute > ) -> Result< Self > { let mut perform = None; + let mut storage_fields = None; for attr in attrs { @@ -37,6 +39,15 @@ impl StructAttributes { "storage_fields" => { + match attr.meta + { + syn::Meta::List( ref meta_list ) => + { + storage_fields.replace( syn::parse2::< AttributeStorageFields >( meta_list.tokens.clone() )? ); + }, + _ => return_syn_err!( attr, "Expects an attribute of format #[ storage_fields( a : i32, b : Option< String > ) ] +.\nGot: {}", qt!{ #attr } ), + } } "perform" => { @@ -60,7 +71,7 @@ impl StructAttributes } } - Ok( StructAttributes { perform } ) + Ok( StructAttributes { perform, storage_fields } ) } } @@ -70,10 +81,8 @@ impl StructAttributes /// `#[ perform( fn after1< 'a >() -> Option< &'a str > ) ]` /// -// xxx : move out pub struct AttributePerform { - // paren_token : syn::token::Paren, pub signature : syn::Signature, } @@ -90,3 +99,34 @@ impl syn::parse::Parse for AttributePerform }) } } + +/// +/// Attribute to hold storage-specific fields. +/// Useful if formed structure should not have such fields. +/// +/// `#[ storage_fields( a : i32, b : Option< String > ) ]` +/// + +pub struct AttributeStorageFields +{ + pub fields : syn::Fields, +} + +impl syn::parse::Parse for AttributeStorageFields +{ + fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > + { + + let fields : syn::punctuated::Punctuated< syn::Field, syn::Token![,] > = + input.parse_terminated( syn::Field::parse_named, Token![,] )?; + + Ok( Self + { + fields : syn::Fields::Named( syn::FieldsNamed + { + brace_token : Default::default(), + named : fields, + }), + }) + } +} From 6025e2ef721b294f8b4dcdfcd84f11270bd6cab3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 00:45:03 +0300 Subject: [PATCH 418/533] former : experimenting --- .../attribute_storage_primitive.rs | 18 ++++++++---------- module/core/former_meta/src/derive_former.rs | 1 + .../src/derive_former/struct_attrs.rs | 15 ++++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs index b28a34fd4e..bc6b1e3ea3 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -2,19 +2,21 @@ use super::*; // xxx2 : implement -#[ derive( Debug, PartialEq, the_module::Former ) ] +// #[ derive( Debug, PartialEq, the_module::Former ) ] // #[ debug ] -// #[ derive( Debug, PartialEq ) ] - #[ storage_fields( a : i32, b : Option< String > ) ] +#[ derive( Debug, PartialEq ) ] +// #[ storage_fields( a : i32, b : Option< String > ) ] pub struct Struct1 { // #[ former( only_storage = true ) ] - pub a : i32, + // pub a : i32, // #[ former( only_storage = true ) ] - b : Option< String >, + // b : Option< String >, } -// +// == begin of generated + +// == end of generated tests_impls! { @@ -30,10 +32,6 @@ tests_impls! } } -// == begin of generated - -// == end of generated - tests_index! { test_complex, diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index fe97d89394..0164e32a6c 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -470,6 +470,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// A field #fields_optional, )* + #storage_fields } impl < #struct_generics_impl > ::core::default::Default diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs index c6fef76d0e..ed9ba691ae 100644 --- a/module/core/former_meta/src/derive_former/struct_attrs.rs +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -109,7 +109,7 @@ impl syn::parse::Parse for AttributePerform pub struct AttributeStorageFields { - pub fields : syn::Fields, + pub fields : syn::punctuated::Punctuated< syn::Field, syn::token::Comma >, } impl syn::parse::Parse for AttributeStorageFields @@ -118,15 +118,16 @@ impl syn::parse::Parse for AttributeStorageFields { let fields : syn::punctuated::Punctuated< syn::Field, syn::Token![,] > = - input.parse_terminated( syn::Field::parse_named, Token![,] )?; + input.parse_terminated( syn::Field::parse_named, Token![,] )?; Ok( Self { - fields : syn::Fields::Named( syn::FieldsNamed - { - brace_token : Default::default(), - named : fields, - }), + fields, + // fields : syn::Fields::Named( syn::FieldsNamed + // { + // brace_token : Default::default(), + // named : fields, + // }), }) } } From e448edd4c6412ca8ba2380afb9214b53428d5379 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 09:55:15 +0300 Subject: [PATCH 419/533] former : experimenting --- .../attribute_storage_primitive.rs | 181 +++++++++++++++++- module/core/former_meta/src/derive_former.rs | 101 ++-------- .../src/derive_former/struct_attrs.rs | 78 ++++++++ module/core/macro_tools/src/derive.rs | 161 ++++++++++++++++ module/core/macro_tools/src/lib.rs | 4 + 5 files changed, 434 insertions(+), 91 deletions(-) create mode 100644 module/core/macro_tools/src/derive.rs diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs index bc6b1e3ea3..37f65193c8 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -3,9 +3,9 @@ use super::*; // xxx2 : implement // #[ derive( Debug, PartialEq, the_module::Former ) ] +// #[ storage_fields( a : i32, b : Option< String > ) ] // #[ debug ] #[ derive( Debug, PartialEq ) ] -// #[ storage_fields( a : i32, b : Option< String > ) ] pub struct Struct1 { // #[ former( only_storage = true ) ] @@ -16,6 +16,185 @@ pub struct Struct1 // == begin of generated + #[automatically_derived] impl < > Struct1 < > where + { + #[doc = r""] + #[doc = + r" Make former, variation of builder pattern to form structure defining values of fields step by step."] + #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < + Struct1FormerDefinition < (), Struct1 < > , former :: ReturnPreformed > > + { + Struct1Former :: < Struct1FormerDefinition < (), Struct1 < > , former + :: ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) + } + } impl < Definition > former :: EntityToFormer < Definition > for Struct1 < > + where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage + < > > , { type Former = Struct1Former < Definition > ; } impl < > former :: + EntityToStorage for Struct1 < > where + { type Storage = Struct1FormerStorage < > ; } impl < __Context, __Formed, + __End > former :: EntityToDefinition < __Context, __Formed, __End > for + Struct1 < > where __End : former :: FormingEnd < Struct1FormerDefinitionTypes + < __Context, __Formed > > , + { type Definition = Struct1FormerDefinition < __Context, __Formed, __End > ; } + #[derive(Debug)] pub struct Struct1FormerDefinitionTypes < __Context = (), + __Formed = Struct1 < > , > where + { + _phantom : core :: marker :: PhantomData < + (* const __Context, * const __Formed) > , + } impl < __Context, __Formed, > :: core :: default :: Default for + Struct1FormerDefinitionTypes < __Context, __Formed, > where + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } impl < __Context, __Formed, > former :: FormerDefinitionTypes for + Struct1FormerDefinitionTypes < __Context, __Formed, > where + { + type Storage = Struct1FormerStorage < > ; type Formed = __Formed; type + Context = __Context; + } #[derive(Debug)] pub struct Struct1FormerDefinition < __Context = (), + __Formed = Struct1 < > , __End = former :: ReturnPreformed, > where + { + _phantom : core :: marker :: PhantomData < + (* const __Context, * const __Formed, * const __End) > , + } impl < __Context, __Formed, __End, > :: core :: default :: Default for + Struct1FormerDefinition < __Context, __Formed, __End, > where + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } impl < __Context, __Formed, __End, > former :: FormerDefinition for + Struct1FormerDefinition < __Context, __Formed, __End, > where __End : former + :: FormingEnd < Struct1FormerDefinitionTypes < __Context, __Formed, > > , + { + type Types = Struct1FormerDefinitionTypes < __Context, __Formed, > ; type + End = __End; type Storage = Struct1FormerStorage < > ; type Formed = + __Formed; type Context = __Context; + } #[doc = "Container of a corresponding former."] + #[allow(explicit_outlives_requirements)] pub struct Struct1FormerStorage < > + where { a : i32, b : Option < String > } impl < > :: core :: default :: + Default for Struct1FormerStorage < > where + { #[inline(always)] fn default() -> Self { Self {} } } impl < > former :: + Storage for Struct1FormerStorage < > where { type Formed = Struct1 < > ; } + impl < > former :: StoragePreform for Struct1FormerStorage < > where + { + type Preformed = Struct1 < > ; fn preform(mut self) -> Self :: Preformed + { let result = Struct1 :: < > {}; return result; } + } + #[doc = + " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] + pub struct Struct1Former < Definition = Struct1FormerDefinition < (), Struct1 + < > , former :: ReturnPreformed > , > where Definition : former :: + FormerDefinition < Storage = Struct1FormerStorage < > > , Definition :: Types + : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , + { + storage : Definition :: Storage, context : core :: option :: Option < + Definition :: Context > , on_end : core :: option :: Option < Definition + :: End > , + } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > + where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage + < > > , Definition :: Types : former :: FormerDefinitionTypes < Storage = + Struct1FormerStorage < > > , + { + #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> + Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > + (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , + { Self :: begin_coercing(None, None, end,) } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn + begin(mut storage : core :: option :: Option < Definition :: Storage > , + context : core :: option :: Option < Definition :: Context > , on_end : < + Definition as former :: FormerDefinition > :: End,) -> Self + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: Some(on_end), + } + } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > + (mut storage : core :: option :: Option < Definition :: Storage > , + context : core :: option :: Option < Definition :: Context > , on_end : + IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < + Definition as former :: FormerDefinition > :: End > , + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: + Some(:: core :: convert :: Into :: into(on_end)), + } + } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types + as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { + let on_end = self.on_end.take().unwrap(); let context = + self.context.take(); former :: FormingEnd :: < Definition :: Types > + :: call(& on_end, self.storage, context) + } + } impl < Definition, > Struct1Former < Definition, > where Definition : former + :: FormerDefinition < Storage = Struct1FormerStorage < > , Formed = Struct1 < + > > , Definition :: Types : former :: FormerDefinitionTypes < Storage = + Struct1FormerStorage < > , Formed = Struct1 < > > , Definition : former :: + FormerDefinition < Storage = Struct1FormerStorage < > > , Definition :: Types + : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , + { + pub fn preform(self) -> < Definition :: Types as former :: + FormerDefinitionTypes > :: Formed + { former :: StoragePreform :: preform(self.storage) } + } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > + where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage + < > , Formed = Struct1 < > , > , Definition :: Types : former :: + FormerDefinitionTypes < Storage = Struct1FormerStorage < > , Formed = Struct1 + < > , > , + { + #[doc = r""] + #[doc = r" Finish setting options and call perform on formed entity."] + #[doc = r""] + #[doc = + r" If `perform` defined then associated method is called and its result returned instead of entity."] + #[doc = + r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] + #[doc = r""] #[inline(always)] pub fn perform(self) -> Definition :: + Formed { let result = self.form(); return result; } + } impl < Definition > former :: FormerBegin < Definition > for Struct1Former < + Definition, > where Definition : former :: FormerDefinition < Storage = + Struct1FormerStorage < > > , + { + #[inline(always)] fn + former_begin(storage : core :: option :: Option < Definition :: Storage > + , context : core :: option :: Option < Definition :: Context > , on_end : + Definition :: End,) -> Self + { + debug_assert! (storage.is_none()); Self :: + begin(None, context, on_end) + } + } + #[doc = + r" Use as subformer of a field during process of forming of super structure."] + pub type Struct1AsSubformer < __Superformer, __End > = Struct1Former < + Struct1FormerDefinition < __Superformer, __Superformer, __End, > , > ; + #[doc = + "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] + pub trait Struct1AsSubformerEnd < SuperFormer > where Self : former :: + FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, SuperFormer > , > , + {} impl < SuperFormer, __T > Struct1AsSubformerEnd < SuperFormer > for __T + where Self : former :: FormingEnd < Struct1FormerDefinitionTypes < + SuperFormer, SuperFormer > , > , {} + // == end of generated tests_impls! diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 0164e32a6c..af3cf8edad 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -1,7 +1,7 @@ use super::*; use iter_tools::{ Itertools, process_results }; -use macro_tools::{ attr, diag, generic_params, generic_args, container_kind, typ, Result }; +use macro_tools::{ attr, diag, generic_params, generic_args, container_kind, typ, derive, Result }; use proc_macro2::TokenStream; // zzz : explain concept of Storage @@ -56,83 +56,6 @@ For specifying custom default value use attribute `default`. For example: ( doc_former_mod, doc_former_struct ) } -// - -/// -/// Generate parts, used for generating `perform()`` method. -/// -/// Similar to `form()`, but will also invoke function from `perform` attribute, if specified. -/// -/// # Example of returned tokens : -/// -/// ## perform : -/// return result; -/// -/// ## perform_output : -/// < T : ::core::default::Default > -/// -/// ## perform_generics : -/// Vec< T > - -pub fn performer -( - attrs : &StructAttributes, -) --> Result< ( TokenStream, TokenStream, TokenStream ) > -{ - - let mut perform = qt! - { - return result; - }; - let mut perform_output = qt!{ Definition::Formed }; - let mut perform_generics = qt!{}; - - if let Some( ref attr ) = attrs.perform - { - - // let attr_perform = syn::parse2::< AttributePerform >( meta_list.tokens.clone() )?; - let signature = &attr.signature; - let generics = &signature.generics; - perform_generics = qt!{ #generics }; - let perform_ident = &signature.ident; - let output = &signature.output; - if let syn::ReturnType::Type( _, boxed_type ) = output - { - perform_output = qt!{ #boxed_type }; - } - perform = qt! - { - return result.#perform_ident(); - }; - - } - - Ok( ( perform, perform_output, perform_generics ) ) -} - -/// xxx : write documentation. provide example of generated code - -pub fn storage_fields -( - attrs : &StructAttributes, -) --> Result< TokenStream > -{ - - let mut result = qt! - { - }; - - if let Some( ref attr ) = attrs.storage_fields - { - let storage_fields = &attr.fields; - result = qt! { #storage_fields } - } - - Ok( result ) -} - /// /// Generate the whole Former ecosystem /// @@ -247,7 +170,15 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_definition_phantom = macro_tools::phantom::tuple( &former_definition_generics_impl ); - /* */ + /* struct attributes */ + + let ( _doc_former_mod, doc_former_struct ) = doc_generate( stru ); + let ( perform, perform_output, perform_generics ) = struct_attrs.performer()?; + let storage_fields = struct_attrs.storage_fields()?; + + /* fields */ + + let fields = derive::data_named_fields( &ast ); let fields = match ast.data { @@ -322,17 +253,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let fields_former_assign : Vec< _ > = process_results( fields_former_assign, | iter | iter.collect() )?; let fields_former_add : Vec< _ > = process_results( fields_former_add, | iter | iter.collect() )?; - let ( _doc_former_mod, doc_former_struct ) = doc_generate( stru ); - let ( perform, perform_output, perform_generics ) = performer - ( - &struct_attrs - )?; - - let storage_fields = storage_fields - ( - &struct_attrs - )?; - let result = qt! { @@ -479,6 +399,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > #struct_generics_where { + // xxx #[ inline( always ) ] fn default() -> Self { diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs index ed9ba691ae..c22c333eb9 100644 --- a/module/core/former_meta/src/derive_former/struct_attrs.rs +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -131,3 +131,81 @@ impl syn::parse::Parse for AttributeStorageFields }) } } + + +// + +/// +/// Generate parts, used for generating `perform()`` method. +/// +/// Similar to `form()`, but will also invoke function from `perform` attribute, if specified. +/// +/// # Example of returned tokens : +/// +/// ## perform : +/// return result; +/// +/// ## perform_output : +/// < T : ::core::default::Default > +/// +/// ## perform_generics : +/// Vec< T > +/// + +impl StructAttributes +{ + + pub fn performer( &self ) + -> Result< ( TokenStream, TokenStream, TokenStream ) > + { + + let mut perform = qt! + { + return result; + }; + let mut perform_output = qt!{ Definition::Formed }; + let mut perform_generics = qt!{}; + + if let Some( ref attr ) = self.perform + { + + // let attr_perform = syn::parse2::< AttributePerform >( meta_list.tokens.clone() )?; + let signature = &attr.signature; + let generics = &signature.generics; + perform_generics = qt!{ #generics }; + let perform_ident = &signature.ident; + let output = &signature.output; + if let syn::ReturnType::Type( _, boxed_type ) = output + { + perform_output = qt!{ #boxed_type }; + } + perform = qt! + { + return result.#perform_ident(); + }; + + } + + Ok( ( perform, perform_output, perform_generics ) ) + } + + /// xxx : write documentation. provide example of generated code + + pub fn storage_fields( &self ) + -> Result< TokenStream > + { + + let mut result = qt! + { + }; + + if let Some( ref attr ) = self.storage_fields + { + let storage_fields = &attr.fields; + result = qt! { #storage_fields } + } + + Ok( result ) + } + +} diff --git a/module/core/macro_tools/src/derive.rs b/module/core/macro_tools/src/derive.rs new file mode 100644 index 0000000000..1a1fb98bbb --- /dev/null +++ b/module/core/macro_tools/src/derive.rs @@ -0,0 +1,161 @@ +//! +//! Macro helpers around derive macro and structure [`syn::DeriveInput`]. +//! + +/// Internal namespace. +pub( crate ) mod private +{ + use super::super::*; + use syn::punctuated::Punctuated; + +// struct Wrap< T >( pub T ); +// // impl quote::ToTokens for Wrap< syn::Data > +// // { +// // fn to_tokens( &self, tokens : &mut proc_macro2::TokenStream ) +// // { +// // match self.0 +// // { +// // syn::Data::Struct( ref data_struct ) => +// // { +// // qt! { #data_struct }.to_tokens( tokens ); +// // }, +// // syn::Data::Enum( ref data_enum ) => +// // { +// // qt! { #data_enum }.to_tokens( tokens ); +// // }, +// // syn::Data::Union( ref data_union ) => +// // { +// // qt! { #data_union }.to_tokens( tokens ); +// // }, +// // } +// // } +// // } +// impl quote::ToTokens for Wrap { +// fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { +// match &self.0 { +// syn::Data::Struct(data_struct) => { +// // Manually construct the representation for structs +// let fields_tokens = data_struct.fields.iter().map(|field| { +// quote::quote!(#field) +// }); +// let ident = &data_struct.ident; +// tokens.extend(quote::quote! { +// struct #ident { +// #(#fields_tokens),* +// } +// }); +// }, +// syn::Data::Enum(data_enum) => { +// // Manually construct the representation for enums +// let variants_tokens = data_enum.variants.iter().map(|variant| { +// quote::quote!(#variant) +// }); +// tokens.extend(quote::quote! { +// enum #data_enum.ident { +// #(#variants_tokens),* +// } +// }); +// }, +// syn::Data::Union(data_union) => { +// // Manually construct the representation for unions +// let fields_tokens = data_union.fields.named.iter().map(|field| { +// quote::quote!(#field) +// }); +// tokens.extend(quote::quote! { +// union #data_union.ident { +// #(#fields_tokens),* +// } +// }); +// }, +// } +// } +// } + + /// # Example + /// + /// ```rust, ignore + /// let ast = match syn::parse::< syn::DeriveInput >( input ) + /// { + /// Ok( syntax_tree ) => syntax_tree, + /// Err( err ) => return Err( err ), + /// }; + /// let fields = derive.data_named_fields( &ast ); + /// ``` + + pub fn data_named_fields< 'a >( ast : &'a syn::DeriveInput ) -> crate::Result< &'a Punctuated< syn::Field, syn::token::Comma > > + { + + let fields = match ast.data + { + syn::Data::Struct( ref data_struct ) => match data_struct.fields + { + syn::Fields::Named( ref fields_named ) => + { + &fields_named.named + }, + _ => return Err( syn_err!( ast, "Unknown format of data, expected syn::Fields::Named( ref fields_named )\n {}", qt!{ #ast } ) ), + }, + _ => return Err( syn_err!( ast, "Unknown format of data, expected syn::Data::Struct( ref data_struct )\n {}", qt!{ #ast } ) ), + }; + + Ok( fields ) + } + +} + +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +pub mod protected +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + data_named_fields, + }; + +} + +/// Parented namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +pub mod exposed +{ + pub use super::protected as derive; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::prelude::*; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + }; + +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: + { + }; + +} diff --git a/module/core/macro_tools/src/lib.rs b/module/core/macro_tools/src/lib.rs index 2d1977760c..d447b4b67b 100644 --- a/module/core/macro_tools/src/lib.rs +++ b/module/core/macro_tools/src/lib.rs @@ -11,6 +11,7 @@ mod file use super::*; pub mod attr; pub mod container_kind; + pub mod derive; pub mod diag; pub mod generic_analyze; pub mod generic_args; @@ -59,6 +60,7 @@ pub mod protected { attr::orphan::*, container_kind::orphan::*, + derive::orphan::*, diag::orphan::*, generic_analyze::orphan::*, generic_args::orphan::*, @@ -107,6 +109,7 @@ pub mod exposed { attr::exposed::*, container_kind::exposed::*, + derive::orphan::*, diag::exposed::*, generic_analyze::exposed::*, generic_args::exposed::*, @@ -172,6 +175,7 @@ pub mod prelude { attr::prelude::*, container_kind::prelude::*, + derive::orphan::*, diag::prelude::*, generic_analyze::prelude::*, generic_args::prelude::*, From d5e377bd6069f4ea3cd242e2849771a35ee7c927 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 11:20:03 +0300 Subject: [PATCH 420/533] former : experimenting --- .../attribute_storage_primitive.rs | 179 --------------- module/core/former_meta/src/derive_former.rs | 39 +--- .../former_meta/src/derive_former/field.rs | 203 ++++++++++-------- module/core/macro_tools/src/derive.rs | 75 +------ module/core/macro_tools/src/typ.rs | 14 +- module/core/macro_tools/tests/inc/derive.rs | 72 +++++++ module/core/macro_tools/tests/inc/mod.rs | 2 + module/core/macro_tools/tests/inc/typ.rs | 64 ++++++ 8 files changed, 279 insertions(+), 369 deletions(-) create mode 100644 module/core/macro_tools/tests/inc/derive.rs create mode 100644 module/core/macro_tools/tests/inc/typ.rs diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs index 37f65193c8..8fed031576 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -16,185 +16,6 @@ pub struct Struct1 // == begin of generated - #[automatically_derived] impl < > Struct1 < > where - { - #[doc = r""] - #[doc = - r" Make former, variation of builder pattern to form structure defining values of fields step by step."] - #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < - Struct1FormerDefinition < (), Struct1 < > , former :: ReturnPreformed > > - { - Struct1Former :: < Struct1FormerDefinition < (), Struct1 < > , former - :: ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) - } - } impl < Definition > former :: EntityToFormer < Definition > for Struct1 < > - where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage - < > > , { type Former = Struct1Former < Definition > ; } impl < > former :: - EntityToStorage for Struct1 < > where - { type Storage = Struct1FormerStorage < > ; } impl < __Context, __Formed, - __End > former :: EntityToDefinition < __Context, __Formed, __End > for - Struct1 < > where __End : former :: FormingEnd < Struct1FormerDefinitionTypes - < __Context, __Formed > > , - { type Definition = Struct1FormerDefinition < __Context, __Formed, __End > ; } - #[derive(Debug)] pub struct Struct1FormerDefinitionTypes < __Context = (), - __Formed = Struct1 < > , > where - { - _phantom : core :: marker :: PhantomData < - (* const __Context, * const __Formed) > , - } impl < __Context, __Formed, > :: core :: default :: Default for - Struct1FormerDefinitionTypes < __Context, __Formed, > where - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } impl < __Context, __Formed, > former :: FormerDefinitionTypes for - Struct1FormerDefinitionTypes < __Context, __Formed, > where - { - type Storage = Struct1FormerStorage < > ; type Formed = __Formed; type - Context = __Context; - } #[derive(Debug)] pub struct Struct1FormerDefinition < __Context = (), - __Formed = Struct1 < > , __End = former :: ReturnPreformed, > where - { - _phantom : core :: marker :: PhantomData < - (* const __Context, * const __Formed, * const __End) > , - } impl < __Context, __Formed, __End, > :: core :: default :: Default for - Struct1FormerDefinition < __Context, __Formed, __End, > where - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } impl < __Context, __Formed, __End, > former :: FormerDefinition for - Struct1FormerDefinition < __Context, __Formed, __End, > where __End : former - :: FormingEnd < Struct1FormerDefinitionTypes < __Context, __Formed, > > , - { - type Types = Struct1FormerDefinitionTypes < __Context, __Formed, > ; type - End = __End; type Storage = Struct1FormerStorage < > ; type Formed = - __Formed; type Context = __Context; - } #[doc = "Container of a corresponding former."] - #[allow(explicit_outlives_requirements)] pub struct Struct1FormerStorage < > - where { a : i32, b : Option < String > } impl < > :: core :: default :: - Default for Struct1FormerStorage < > where - { #[inline(always)] fn default() -> Self { Self {} } } impl < > former :: - Storage for Struct1FormerStorage < > where { type Formed = Struct1 < > ; } - impl < > former :: StoragePreform for Struct1FormerStorage < > where - { - type Preformed = Struct1 < > ; fn preform(mut self) -> Self :: Preformed - { let result = Struct1 :: < > {}; return result; } - } - #[doc = - " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] - pub struct Struct1Former < Definition = Struct1FormerDefinition < (), Struct1 - < > , former :: ReturnPreformed > , > where Definition : former :: - FormerDefinition < Storage = Struct1FormerStorage < > > , Definition :: Types - : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , - { - storage : Definition :: Storage, context : core :: option :: Option < - Definition :: Context > , on_end : core :: option :: Option < Definition - :: End > , - } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > - where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage - < > > , Definition :: Types : former :: FormerDefinitionTypes < Storage = - Struct1FormerStorage < > > , - { - #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> - Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > - (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , - { Self :: begin_coercing(None, None, end,) } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn - begin(mut storage : core :: option :: Option < Definition :: Storage > , - context : core :: option :: Option < Definition :: Context > , on_end : < - Definition as former :: FormerDefinition > :: End,) -> Self - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: Some(on_end), - } - } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > - (mut storage : core :: option :: Option < Definition :: Storage > , - context : core :: option :: Option < Definition :: Context > , on_end : - IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < - Definition as former :: FormerDefinition > :: End > , - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: - Some(:: core :: convert :: Into :: into(on_end)), - } - } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types - as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { - let on_end = self.on_end.take().unwrap(); let context = - self.context.take(); former :: FormingEnd :: < Definition :: Types > - :: call(& on_end, self.storage, context) - } - } impl < Definition, > Struct1Former < Definition, > where Definition : former - :: FormerDefinition < Storage = Struct1FormerStorage < > , Formed = Struct1 < - > > , Definition :: Types : former :: FormerDefinitionTypes < Storage = - Struct1FormerStorage < > , Formed = Struct1 < > > , Definition : former :: - FormerDefinition < Storage = Struct1FormerStorage < > > , Definition :: Types - : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , - { - pub fn preform(self) -> < Definition :: Types as former :: - FormerDefinitionTypes > :: Formed - { former :: StoragePreform :: preform(self.storage) } - } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > - where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage - < > , Formed = Struct1 < > , > , Definition :: Types : former :: - FormerDefinitionTypes < Storage = Struct1FormerStorage < > , Formed = Struct1 - < > , > , - { - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] - #[doc = - r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = - r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] #[inline(always)] pub fn perform(self) -> Definition :: - Formed { let result = self.form(); return result; } - } impl < Definition > former :: FormerBegin < Definition > for Struct1Former < - Definition, > where Definition : former :: FormerDefinition < Storage = - Struct1FormerStorage < > > , - { - #[inline(always)] fn - former_begin(storage : core :: option :: Option < Definition :: Storage > - , context : core :: option :: Option < Definition :: Context > , on_end : - Definition :: End,) -> Self - { - debug_assert! (storage.is_none()); Self :: - begin(None, context, on_end) - } - } - #[doc = - r" Use as subformer of a field during process of forming of super structure."] - pub type Struct1AsSubformer < __Superformer, __End > = Struct1Former < - Struct1FormerDefinition < __Superformer, __Superformer, __End, > , > ; - #[doc = - "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] - pub trait Struct1AsSubformerEnd < SuperFormer > where Self : former :: - FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, SuperFormer > , > , - {} impl < SuperFormer, __T > Struct1AsSubformerEnd < SuperFormer > for __T - where Self : former :: FormingEnd < Struct1FormerDefinitionTypes < - SuperFormer, SuperFormer > , > , {} - // == end of generated tests_impls! diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index af3cf8edad..b00863b895 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -1,7 +1,7 @@ use super::*; use iter_tools::{ Itertools, process_results }; -use macro_tools::{ attr, diag, generic_params, generic_args, container_kind, typ, derive, Result }; +use macro_tools::{ attr, diag, generic_params, generic_args, typ, derive, Result }; use proc_macro2::TokenStream; // zzz : explain concept of Storage @@ -178,56 +178,33 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /* fields */ - let fields = derive::data_named_fields( &ast ); + let fields = derive::named_fields( &ast )?; - let fields = match ast.data + let formed_fields : Vec< Result< FormerField< '_ > > > = fields.into_iter().map( | field | { - syn::Data::Struct( ref data_struct ) => match data_struct.fields - { - syn::Fields::Named( ref fields_named ) => - { - &fields_named.named - }, - _ => return Err( syn_err!( ast, "Unknown format of data, expected syn::Fields::Named( ref fields_named )\n {}", qt!{ #ast } ) ), - }, - _ => return Err( syn_err!( ast, "Unknown format of data, expected syn::Data::Struct( ref data_struct )\n {}", qt!{ #ast } ) ), - }; - - let former_fields : Vec< Result< FormerField< '_ > > > = fields.iter().map( | field | - { - let attrs = FieldAttributes::from_attrs( field.attrs.iter() )?; - let vis = &field.vis; - let ident = field.ident.as_ref() - .ok_or_else( || syn_err!( field, "Expected that each field has key, but some does not:\n {}", qt!{ #field } ) )?; - let colon_token = &field.colon_token; - let ty = &field.ty; - let is_optional = typ::is_optional( ty ); - let of_type = container_kind::of_optional( ty ).0; - let non_optional_ty : &syn::Type = if is_optional { typ::parameter_first( ty )? } else { ty }; - let field = FormerField { attrs, vis, ident, colon_token, ty, non_optional_ty, is_optional, of_type }; - Ok( field ) + FormerField::from_syn( field ) }).collect(); - let former_fields : Vec< _ > = process_results( former_fields, | iter | iter.collect() )?; + let formed_fields : Vec< _ > = process_results( formed_fields, | iter | iter.collect() )?; let ( fields_none, fields_optional, - fields_form, fields_names, + fields_form, fields_setter, fields_former_assign, fields_former_add, ) : ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) - = former_fields.iter().map( | field | + = formed_fields.iter().map( | field | {( field.none_map(), field.optional_map(), - field.form_map(), field.name_map(), + field.form_map(), field.setter_map( &stru ), field.former_assign_end_map ( diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index e542cf0277..6f48300f90 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -24,10 +24,7 @@ impl< 'a > FormerField< 'a > /** methods -scalar_setter_name -container_setter_name -subform_setter_name -scalar_setter_required +from_syn none_map optional_map @@ -40,97 +37,27 @@ scalar_setter former_assign_end_map former_add_end_map -*/ +scalar_setter_name +container_setter_name +subform_setter_name +scalar_setter_required - /// Get name of scalar setter. - pub fn scalar_setter_name( &self ) -> &syn::Ident - { - if let Some( ref attr ) = self.attrs.scalar - { - if let Some( ref name ) = attr.name - { - return name - } - } - return &self.ident; - } +*/ - /// Get name of setter for container if such setter should be generated. - pub fn container_setter_name( &self ) -> Option< &syn::Ident > + /// Construct former field from [`syn::Field`] + pub fn from_syn( field : &'a syn::Field ) -> Result< Self > { - - if let Some( ref attr ) = self.attrs.container - { - if attr.setter() - { - if let Some( ref name ) = attr.name - { - return Some( &name ) - } - else - { - return Some( &self.ident ) - } - } - } - - return None; - } - - /// Get name of setter for subform if such setter should be generated. - pub fn subform_setter_name( &self ) -> Option< &syn::Ident > - { - - if let Some( ref attr ) = self.attrs.subform - { - if attr.setter() - { - if let Some( ref name ) = attr.name - { - return Some( &name ) - } - else - { - return Some( &self.ident ) - } - } - } - - return None; - } - - /// Is scalar setter required. Does not if container of subformer setter requested. - pub fn scalar_setter_required( &self ) -> bool - { - - let mut explicit = false; - if let Some( ref attr ) = self.attrs.scalar - { - if let Some( setter ) = attr.setter - { - if setter == false - { - return false - } - explicit = true; - } - if let Some( ref _name ) = attr.name - { - explicit = true; - } - } - - if self.attrs.container.is_some() && !explicit - { - return false; - } - - if self.attrs.subform.is_some() && !explicit - { - return false; - } - - return true; + let attrs = FieldAttributes::from_attrs( field.attrs.iter() )?; + let vis = &field.vis; + let ident = field.ident.as_ref() + .ok_or_else( || syn_err!( field, "Expected that each field has key, but some does not:\n {}", qt!{ #field } ) )?; + let colon_token = &field.colon_token; + let ty = &field.ty; + let is_optional = typ::is_optional( ty ); + let of_type = container_kind::of_optional( ty ).0; + let non_optional_ty : &syn::Type = if is_optional { typ::parameter_first( ty )? } else { ty }; + let field2 = Self { attrs, vis, ident, colon_token, ty, non_optional_ty, is_optional, of_type }; + Ok( field2 ) } /// @@ -1035,4 +962,96 @@ former_add_end_map Ok( r ) } + + /// Get name of scalar setter. + pub fn scalar_setter_name( &self ) -> &syn::Ident + { + if let Some( ref attr ) = self.attrs.scalar + { + if let Some( ref name ) = attr.name + { + return name + } + } + return &self.ident; + } + + /// Get name of setter for container if such setter should be generated. + pub fn container_setter_name( &self ) -> Option< &syn::Ident > + { + + if let Some( ref attr ) = self.attrs.container + { + if attr.setter() + { + if let Some( ref name ) = attr.name + { + return Some( &name ) + } + else + { + return Some( &self.ident ) + } + } + } + + return None; + } + + /// Get name of setter for subform if such setter should be generated. + pub fn subform_setter_name( &self ) -> Option< &syn::Ident > + { + + if let Some( ref attr ) = self.attrs.subform + { + if attr.setter() + { + if let Some( ref name ) = attr.name + { + return Some( &name ) + } + else + { + return Some( &self.ident ) + } + } + } + + return None; + } + + /// Is scalar setter required. Does not if container of subformer setter requested. + pub fn scalar_setter_required( &self ) -> bool + { + + let mut explicit = false; + if let Some( ref attr ) = self.attrs.scalar + { + if let Some( setter ) = attr.setter + { + if setter == false + { + return false + } + explicit = true; + } + if let Some( ref _name ) = attr.name + { + explicit = true; + } + } + + if self.attrs.container.is_some() && !explicit + { + return false; + } + + if self.attrs.subform.is_some() && !explicit + { + return false; + } + + return true; + } + } diff --git a/module/core/macro_tools/src/derive.rs b/module/core/macro_tools/src/derive.rs index 1a1fb98bbb..9f29444e48 100644 --- a/module/core/macro_tools/src/derive.rs +++ b/module/core/macro_tools/src/derive.rs @@ -8,69 +8,12 @@ pub( crate ) mod private use super::super::*; use syn::punctuated::Punctuated; -// struct Wrap< T >( pub T ); -// // impl quote::ToTokens for Wrap< syn::Data > -// // { -// // fn to_tokens( &self, tokens : &mut proc_macro2::TokenStream ) -// // { -// // match self.0 -// // { -// // syn::Data::Struct( ref data_struct ) => -// // { -// // qt! { #data_struct }.to_tokens( tokens ); -// // }, -// // syn::Data::Enum( ref data_enum ) => -// // { -// // qt! { #data_enum }.to_tokens( tokens ); -// // }, -// // syn::Data::Union( ref data_union ) => -// // { -// // qt! { #data_union }.to_tokens( tokens ); -// // }, -// // } -// // } -// // } -// impl quote::ToTokens for Wrap { -// fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { -// match &self.0 { -// syn::Data::Struct(data_struct) => { -// // Manually construct the representation for structs -// let fields_tokens = data_struct.fields.iter().map(|field| { -// quote::quote!(#field) -// }); -// let ident = &data_struct.ident; -// tokens.extend(quote::quote! { -// struct #ident { -// #(#fields_tokens),* -// } -// }); -// }, -// syn::Data::Enum(data_enum) => { -// // Manually construct the representation for enums -// let variants_tokens = data_enum.variants.iter().map(|variant| { -// quote::quote!(#variant) -// }); -// tokens.extend(quote::quote! { -// enum #data_enum.ident { -// #(#variants_tokens),* -// } -// }); -// }, -// syn::Data::Union(data_union) => { -// // Manually construct the representation for unions -// let fields_tokens = data_union.fields.named.iter().map(|field| { -// quote::quote!(#field) -// }); -// tokens.extend(quote::quote! { -// union #data_union.ident { -// #(#fields_tokens),* -// } -// }); -// }, -// } -// } -// } - + /// + /// Extracts the named fields from a struct defined in a `syn::DeriveInput`. + /// + /// This function specifically handles `syn::DeriveInput` that represent structs + /// with named fields. It will return an error if the provided AST does not conform to these expectations. + /// /// # Example /// /// ```rust, ignore @@ -79,10 +22,10 @@ pub( crate ) mod private /// Ok( syntax_tree ) => syntax_tree, /// Err( err ) => return Err( err ), /// }; - /// let fields = derive.data_named_fields( &ast ); + /// let fields = derive.named_fields( &ast ); /// ``` - pub fn data_named_fields< 'a >( ast : &'a syn::DeriveInput ) -> crate::Result< &'a Punctuated< syn::Field, syn::token::Comma > > + pub fn named_fields< 'a >( ast : &'a syn::DeriveInput ) -> crate::Result< &'a Punctuated< syn::Field, syn::token::Comma > > { let fields = match ast.data @@ -118,7 +61,7 @@ pub mod protected #[ allow( unused_imports ) ] pub use super::private:: { - data_named_fields, + named_fields, }; } diff --git a/module/core/macro_tools/src/typ.rs b/module/core/macro_tools/src/typ.rs index faf9698356..6132e1776b 100644 --- a/module/core/macro_tools/src/typ.rs +++ b/module/core/macro_tools/src/typ.rs @@ -108,8 +108,20 @@ pub( crate ) mod private // None // } + + /// Checks if a given [`syn::Type`] is an `Option` type. + /// + /// This function examines a type to determine if it represents an `Option`. + /// It is useful for scenarios where type-specific behavior needs to be conditional + /// on whether the type is optional or not. + /// + /// # Example /// - /// Is type under Option. + /// ```rust + /// let type_string = "Option< i32 >"; + /// let parsed_type : syn::Type = syn::parse_str( type_string ).expect( "Type should parse correctly" ); + /// assert!( macro_tools::typ::is_optional( &parsed_type ) ); + /// ``` /// // qqq : cover by test diff --git a/module/core/macro_tools/tests/inc/derive.rs b/module/core/macro_tools/tests/inc/derive.rs new file mode 100644 index 0000000000..b6983e34d5 --- /dev/null +++ b/module/core/macro_tools/tests/inc/derive.rs @@ -0,0 +1,72 @@ + +use super::*; + +// + +#[test] +fn named_fields_with_named_fields() +{ + use syn::{parse_quote, punctuated::Punctuated, Field, token::Comma}; + use the_module::derive; + + let ast: syn::DeriveInput = parse_quote! + { + struct Test + { + a : i32, + b : String, + } + }; + + let result = derive::named_fields( &ast ).expect( "Expected successful extraction of named fields" ); + + let mut expected_fields = Punctuated::new(); + let field_a : Field = parse_quote! { a: i32 }; + let field_b : Field = parse_quote! { b: String }; + expected_fields.push_value( field_a); + expected_fields.push_punct( Comma::default() ); + expected_fields.push_value( field_b ); + expected_fields.push_punct( Comma::default() ); + + a_id!( format!( "{:?}", result ), format!( "{:?}", expected_fields ), "Fields did not match expected output" ); +} + +// + +#[ test ] +fn named_fields_with_tuple_struct() +{ + use syn::{ parse_quote }; + use the_module::derive::named_fields; + + let ast : syn::DeriveInput = parse_quote! + { + struct Test( i32, String ); + }; + + let result = named_fields( &ast ); + + assert!( result.is_err(), "Expected an error for tuple struct, but extraction was successful" ); +} + +// + +#[ test ] +fn named_fields_with_enum() +{ + use syn::{ parse_quote }; + use the_module::derive::named_fields; + + let ast : syn::DeriveInput = parse_quote! + { + enum Test + { + Variant1, + Variant2, + } + }; + + let result = named_fields( &ast ); + + assert!( result.is_err(), "Expected an error for enum, but extraction was successful" ); +} diff --git a/module/core/macro_tools/tests/inc/mod.rs b/module/core/macro_tools/tests/inc/mod.rs index 2d0cb908c8..9bf5c92947 100644 --- a/module/core/macro_tools/tests/inc/mod.rs +++ b/module/core/macro_tools/tests/inc/mod.rs @@ -15,6 +15,7 @@ mod if_enabled mod attr; mod basic; + mod derive; mod generic_args; mod generic_params; mod item; @@ -22,5 +23,6 @@ mod if_enabled mod quantifier; mod syntax; mod tokens; + mod typ; } diff --git a/module/core/macro_tools/tests/inc/typ.rs b/module/core/macro_tools/tests/inc/typ.rs new file mode 100644 index 0000000000..400d6b4e46 --- /dev/null +++ b/module/core/macro_tools/tests/inc/typ.rs @@ -0,0 +1,64 @@ + +use super::*; + +// + +#[test] +fn test_is_optional_with_option_type() +{ + use syn::parse_str; + use macro_tools::typ::is_optional; + + let type_string = "Option"; + let parsed_type: syn::Type = parse_str(type_string).expect("Type should parse correctly"); + + assert!(is_optional(&parsed_type), "Expected type to be recognized as an Option"); +} + +#[test] +fn test_is_optional_with_non_option_type() +{ + use syn::parse_str; + use macro_tools::typ::is_optional; + + let type_string = "Vec"; + let parsed_type: syn::Type = parse_str(type_string).expect("Type should parse correctly"); + + assert!(!is_optional(&parsed_type), "Expected type not to be recognized as an Option"); +} + +#[test] +fn test_is_optional_with_nested_option_type() +{ + use syn::parse_str; + use macro_tools::typ::is_optional; + + let type_string = "Option>"; + let parsed_type: syn::Type = parse_str(type_string).expect("Type should parse correctly"); + + assert!(is_optional(&parsed_type), "Expected nested Option type to be recognized as an Option"); +} + +#[test] +fn test_is_optional_with_similar_name_type() +{ + use syn::parse_str; + use macro_tools::typ::is_optional; + + let type_string = "OptionalValue"; + let parsed_type: syn::Type = parse_str(type_string).expect("Type should parse correctly"); + + assert!(!is_optional(&parsed_type), "Expected type with similar name not to be recognized as an Option"); +} + +#[test] +fn test_is_optional_with_empty_input() +{ + use syn::{parse_str, Type}; + use macro_tools::typ::is_optional; + + let type_string = ""; + let parsed_type_result = parse_str::(type_string); + + assert!(parsed_type_result.is_err(), "Expected parsing to fail for empty input"); +} From 1c6cc4c20ede88da274b882743bd51ba38a19856 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 12:09:43 +0300 Subject: [PATCH 421/533] former : experimenting --- module/core/macro_tools/src/typ.rs | 15 +++- module/core/macro_tools/tests/inc/typ.rs | 106 ++++++++++++++++++----- 2 files changed, 97 insertions(+), 24 deletions(-) diff --git a/module/core/macro_tools/src/typ.rs b/module/core/macro_tools/src/typ.rs index 6132e1776b..34d45e32b3 100644 --- a/module/core/macro_tools/src/typ.rs +++ b/module/core/macro_tools/src/typ.rs @@ -124,17 +124,26 @@ pub( crate ) mod private /// ``` /// - // qqq : cover by test pub fn is_optional( ty : &syn::Type ) -> bool { typ::type_rightmost( ty ) == Some( "Option".to_string() ) } + /// Extracts the first generic parameter from a given `syn::Type` if any exists. /// - /// Extract the first parameter of the type if such exist. + /// This function is designed to analyze a type and retrieve its first generic parameter. + /// It is particularly useful when working with complex types in macro expansions and needs + /// to extract specific type information for further processing. /// +/// + /// # Example + /// ```rust + /// let type_string = "Result< Option< i32 >, Error >"; + /// let parsed_type : syn::Type = syn::parse_str( type_string ).expect( "Type should parse correctly" ); + /// let first_param = macro_tools::typ::parameter_first( &parsed_type ).expect( "Should have at least one parameter" ); + /// // Option< i32 > + /// ``` - // qqq : cover by test pub fn parameter_first( ty : &syn::Type ) -> Result< &syn::Type > { typ::type_parameters( ty, 0 ..= 0 ) diff --git a/module/core/macro_tools/tests/inc/typ.rs b/module/core/macro_tools/tests/inc/typ.rs index 400d6b4e46..75bd10096d 100644 --- a/module/core/macro_tools/tests/inc/typ.rs +++ b/module/core/macro_tools/tests/inc/typ.rs @@ -3,62 +3,126 @@ use super::*; // -#[test] -fn test_is_optional_with_option_type() +#[ test ] +fn is_optional_with_option_type() { use syn::parse_str; use macro_tools::typ::is_optional; let type_string = "Option"; - let parsed_type: syn::Type = parse_str(type_string).expect("Type should parse correctly"); + let parsed_type : syn::Type = parse_str( type_string ).expect( "Type should parse correctly" ); - assert!(is_optional(&parsed_type), "Expected type to be recognized as an Option"); + assert!( is_optional( &parsed_type ), "Expected type to be recognized as an Option" ); } -#[test] -fn test_is_optional_with_non_option_type() +#[ test ] +fn is_optional_with_non_option_type() { use syn::parse_str; use macro_tools::typ::is_optional; let type_string = "Vec"; - let parsed_type: syn::Type = parse_str(type_string).expect("Type should parse correctly"); + let parsed_type : syn::Type = parse_str( type_string ).expect( "Type should parse correctly" ); - assert!(!is_optional(&parsed_type), "Expected type not to be recognized as an Option"); + assert!( !is_optional( &parsed_type ), "Expected type not to be recognized as an Option" ); } -#[test] -fn test_is_optional_with_nested_option_type() +#[ test ] +fn is_optional_with_nested_option_type() { use syn::parse_str; use macro_tools::typ::is_optional; let type_string = "Option>"; - let parsed_type: syn::Type = parse_str(type_string).expect("Type should parse correctly"); + let parsed_type : syn::Type = parse_str( type_string ).expect( "Type should parse correctly" ); - assert!(is_optional(&parsed_type), "Expected nested Option type to be recognized as an Option"); + assert!( is_optional( &parsed_type ), "Expected nested Option type to be recognized as an Option" ); } -#[test] -fn test_is_optional_with_similar_name_type() +#[ test ] +fn is_optional_with_similar_name_type() { use syn::parse_str; use macro_tools::typ::is_optional; let type_string = "OptionalValue"; - let parsed_type: syn::Type = parse_str(type_string).expect("Type should parse correctly"); + let parsed_type : syn::Type = parse_str( type_string ).expect( "Type should parse correctly" ); - assert!(!is_optional(&parsed_type), "Expected type with similar name not to be recognized as an Option"); + assert!( !is_optional( &parsed_type ), "Expected type with similar name not to be recognized as an Option" ); } -#[test] -fn test_is_optional_with_empty_input() +#[ test ] +fn is_optional_with_empty_input() { - use syn::{parse_str, Type}; + use syn::{ parse_str, Type }; use macro_tools::typ::is_optional; let type_string = ""; - let parsed_type_result = parse_str::(type_string); + let parsed_type_result = parse_str::< Type >( type_string ); - assert!(parsed_type_result.is_err(), "Expected parsing to fail for empty input"); + assert!( parsed_type_result.is_err(), "Expected parsing to fail for empty input" ); +} + +// xxx + +#[ test ] +fn parameter_first_with_multiple_generics() +{ + use syn::{ parse_str, Type }; + use macro_tools::typ::parameter_first; + + let type_string = "Result, Error>"; + let parsed_type : Type = parse_str( type_string ).expect( "Type should parse correctly" ); + + let first_param = parameter_first( &parsed_type ).expect( "Expected to extract the first generic parameter" ); + + let expected_type : Type = parse_str( "Option" ).expect( "Expected type to parse correctly" ); + assert_eq!( format!( "{:?}", expected_type ), format!( "{:?}", first_param ), "Extracted type does not match expected" ); +} + +#[ test ] +fn parameter_first_with_no_generics() +{ + use syn::{ parse_str, Type }; + use macro_tools::typ::parameter_first; + + let type_string = "i32"; + let parsed_type : Type = parse_str( type_string ).expect( "Type should parse correctly" ); + let got = parameter_first( &parsed_type ).expect( "Type should parse correctly" ); + + // tree_print!( got.as_ref().unwrap() ); + + let expected_type : Type = parse_str( "i32" ).expect( "Expected type to parse correctly" ); + assert_eq!( format!( "{:?}", expected_type ), format!( "{:?}", got ), "Extracted type does not match expected" ); + +} + +#[ test ] +fn parameter_first_with_single_generic() +{ + use syn::{ parse_str, Type }; + use macro_tools::typ::parameter_first; + + let type_string = "Vec< i32 >"; + let parsed_type : Type = parse_str( type_string ).expect( "Type should parse correctly" ); + + let first_param = parameter_first( &parsed_type ).expect( "Expected to extract the first generic parameter" ); + + let expected_type : Type = parse_str( "i32" ).expect( "Expected type to parse correctly" ); + assert_eq!( format!( "{:?}", expected_type ), format!( "{:?}", first_param ), "Extracted type does not match expected" ); +} + +#[ test ] +fn parameter_first_with_deeply_nested_generics() +{ + use syn::{ parse_str, Type }; + use macro_tools::typ::parameter_first; + + let type_string = "Vec< HashMap< String, Option< i32 > > >"; + let parsed_type : Type = parse_str( type_string ).expect( "Type should parse correctly" ); + + let first_param = parameter_first( &parsed_type ).expect( "Expected to extract the first generic parameter" ); + + let expected_type : Type = parse_str( "HashMap< String, Option< i32 > >" ).expect( "Expected type to parse correctly" ); + assert_eq!( format!( "{:?}", expected_type ), format!( "{:?}", first_param ), "Extracted type does not match expected" ); } From 34303534c37423e5368546e3fa1a0844a080db17 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 14:12:46 +0300 Subject: [PATCH 422/533] former : experimenting --- module/core/former_meta/src/derive_former.rs | 64 ++++++++++++------- .../src/derive_former/struct_attrs.rs | 18 +++++- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index b00863b895..502354711c 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -174,32 +174,48 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( _doc_former_mod, doc_former_struct ) = doc_generate( stru ); let ( perform, perform_output, perform_generics ) = struct_attrs.performer()?; - let storage_fields = struct_attrs.storage_fields()?; + let storage_fields_code = struct_attrs.storage_fields_code()?; /* fields */ let fields = derive::named_fields( &ast )?; - let formed_fields : Vec< Result< FormerField< '_ > > > = fields.into_iter().map( | field | + let formed_fields : Vec< Result< FormerField< '_ > > > = fields + .into_iter() + .map( | field | { FormerField::from_syn( field ) - }).collect(); - + }) + .collect(); let formed_fields : Vec< _ > = process_results( formed_fields, | iter | iter.collect() )?; + // xxx + + let storage_fields : Vec< Result< FormerField< '_ > > > = fields + .into_iter() + .map( | field | + { + FormerField::from_syn( field ) + }) + .collect(); + let storage_fields : Vec< _ > = process_results( storage_fields, | iter | iter.collect() )?; + let ( - fields_none, - fields_optional, - fields_names, - fields_form, - fields_setter, - fields_former_assign, - fields_former_add, + storage_fields_none, + storage_fields_optional, + storage_fields_names, + storage_fields_preform, + former_fields_setter, + former_fields_former_assign, + former_fields_former_add, ) : ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) - = formed_fields.iter().map( | field | + = formed_fields + .iter() + // .chain( storage_fields.iter() ) + .map( | field | {( field.none_map(), field.optional_map(), @@ -225,10 +241,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > ), )}).multiunzip(); - let fields_setter : Vec< _ > = process_results( fields_setter, | iter | iter.collect() )?; - let fields_form : Vec< _ > = process_results( fields_form, | iter | iter.collect() )?; - let fields_former_assign : Vec< _ > = process_results( fields_former_assign, | iter | iter.collect() )?; - let fields_former_add : Vec< _ > = process_results( fields_former_add, | iter | iter.collect() )?; + let former_fields_setter : Vec< _ > = process_results( former_fields_setter, | iter | iter.collect() )?; + let storage_fields_preform : Vec< _ > = process_results( storage_fields_preform, | iter | iter.collect() )?; + let former_fields_former_assign : Vec< _ > = process_results( former_fields_former_assign, | iter | iter.collect() )?; + let former_fields_former_add : Vec< _ > = process_results( former_fields_former_add, | iter | iter.collect() )?; let result = qt! { @@ -365,9 +381,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { #( /// A field - #fields_optional, + #storage_fields_optional, )* - #storage_fields + #storage_fields_code } impl < #struct_generics_impl > ::core::default::Default @@ -382,7 +398,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { Self { - #( #fields_none, )* + #( #storage_fields_none, )* } } @@ -405,12 +421,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > fn preform( mut self ) -> Self::Preformed { - #( #fields_form )* + #( #storage_fields_preform )* // Rust does not support that, yet // let result = < Definition::Types as former::FormerDefinitionTypes >::Formed let result = #stru :: < #struct_generics_ty > { - #( #fields_names, )* + #( #storage_fields_names, )* }; return result; } @@ -535,7 +551,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } #( - #fields_setter + #former_fields_setter )* } @@ -653,13 +669,13 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = container assign callbacks #( - #fields_former_assign + #former_fields_former_assign )* // = container add callbacks #( - #fields_former_add + #former_fields_former_add )* }; diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs index c22c333eb9..13862a83d9 100644 --- a/module/core/former_meta/src/derive_former/struct_attrs.rs +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -189,9 +189,25 @@ impl StructAttributes Ok( ( perform, perform_output, perform_generics ) ) } + /// Returns an iterator over the fields defined in the `storage_fields` attribute. + /// + /// This function provides an iterator that yields `syn::Field` objects. If `storage_fields` is set, + /// it clones and iterates over its fields. If `storage_fields` is `None`, it returns an empty iterator. + /// + + pub fn storage_fields( &self ) -> impl Iterator< Item = syn::Field > + { + self.storage_fields + .as_ref() + .map_or_else( + || syn::punctuated::Punctuated::< syn::Field, syn::token::Comma >::new().into_iter(), + | attr | attr.fields.clone().into_iter() // Clone and create an iterator when storage_fields is Some + ) + } + /// xxx : write documentation. provide example of generated code - pub fn storage_fields( &self ) + pub fn storage_fields_code( &self ) -> Result< TokenStream > { From c272d3f74452255b74b252a2e55df9d7a2dd4cdb Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 14:35:46 +0300 Subject: [PATCH 423/533] former : experimenting --- module/core/former_meta/src/derive_former.rs | 7 ++-- .../src/derive_former/struct_attrs.rs | 35 +++++++++++++++---- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 502354711c..6df7c8a487 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -191,11 +191,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // xxx - let storage_fields : Vec< Result< FormerField< '_ > > > = fields - .into_iter() + let storage_fields : Vec< Result< FormerField< '_ > > > = struct_attrs + .storage_fields() + .iter() .map( | field | { - FormerField::from_syn( field ) + FormerField::from_syn( &field ) }) .collect(); let storage_fields : Vec< _ > = process_results( storage_fields, | iter | iter.collect() )?; diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs index 13862a83d9..2dab13e9ee 100644 --- a/module/core/former_meta/src/derive_former/struct_attrs.rs +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -195,17 +195,38 @@ impl StructAttributes /// it clones and iterates over its fields. If `storage_fields` is `None`, it returns an empty iterator. /// - pub fn storage_fields( &self ) -> impl Iterator< Item = syn::Field > + // pub fn storage_fields( &self ) -> impl Iterator< Item = syn::Field > + pub fn storage_fields( &self ) -> &syn::punctuated::Punctuated< syn::Field, syn::token::Comma > { - self.storage_fields - .as_ref() - .map_or_else( - || syn::punctuated::Punctuated::< syn::Field, syn::token::Comma >::new().into_iter(), - | attr | attr.fields.clone().into_iter() // Clone and create an iterator when storage_fields is Some + + self.storage_fields.as_ref().map_or_else( + || &*Box::leak(Box::new(syn::punctuated::Punctuated::new())), + |attr| &attr.fields ) + // xxx : investigate + + // self.storage_fields + // .as_ref() + // .map_or_else( + // || syn::punctuated::Punctuated::< syn::Field, syn::token::Comma >::new().into_iter(), + // | attr | attr.fields.clone().into_iter() + // // Clone and create an iterator when storage_fields is Some + // ) } - /// xxx : write documentation. provide example of generated code + /// Generates a `TokenStream` for the fields specified in `storage_fields`. + /// + /// This function constructs a token stream for code generation, incorporating fields from the + /// `storage_fields` attribute into the generated Rust code. If `storage_fields` is set, it includes + /// its fields in the output; otherwise, it returns an empty token stream. + /// + /// # Example of generated code + /// + /// ```rust, ignore + /// field1 : i32, + /// field2 : String, + /// ``` + /// pub fn storage_fields_code( &self ) -> Result< TokenStream > From 97c2ee58b7672a985a912afc13cc1cb81d15e1d9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 14:48:33 +0300 Subject: [PATCH 424/533] former : experimenting --- .../attribute_storage_primitive.rs | 4 +- module/core/former_meta/src/derive_former.rs | 16 +++---- .../former_meta/src/derive_former/field.rs | 44 ++++++++++++++++--- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs index 8fed031576..44ab706301 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -2,10 +2,10 @@ use super::*; // xxx2 : implement -// #[ derive( Debug, PartialEq, the_module::Former ) ] +#[ derive( Debug, PartialEq, the_module::Former ) ] // #[ storage_fields( a : i32, b : Option< String > ) ] // #[ debug ] -#[ derive( Debug, PartialEq ) ] +// #[ derive( Debug, PartialEq ) ] pub struct Struct1 { // #[ former( only_storage = true ) ] diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 6df7c8a487..930548355e 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -184,7 +184,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > .into_iter() .map( | field | { - FormerField::from_syn( field ) + FormerField::from_syn( field, true, true ) }) .collect(); let formed_fields : Vec< _ > = process_results( formed_fields, | iter | iter.collect() )?; @@ -196,7 +196,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > .iter() .map( | field | { - FormerField::from_syn( &field ) + FormerField::from_syn( &field, true, false ) }) .collect(); let storage_fields : Vec< _ > = process_results( storage_fields, | iter | iter.collect() )?; @@ -205,7 +205,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > ( storage_fields_none, storage_fields_optional, - storage_fields_names, + storage_field_name, storage_fields_preform, former_fields_setter, former_fields_former_assign, @@ -215,13 +215,13 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) = formed_fields .iter() - // .chain( storage_fields.iter() ) + .chain( storage_fields.iter() ) .map( | field | {( field.none_map(), field.optional_map(), - field.name_map(), - field.form_map(), + field.storage_field_name(), + field.preform_map(), field.setter_map( &stru ), field.former_assign_end_map ( @@ -384,7 +384,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// A field #storage_fields_optional, )* - #storage_fields_code + // #storage_fields_code } impl < #struct_generics_impl > ::core::default::Default @@ -427,7 +427,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // let result = < Definition::Types as former::FormerDefinitionTypes >::Formed let result = #stru :: < #struct_generics_ty > { - #( #storage_fields_names, )* + #( #storage_field_name, )* }; return result; } diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 6f48300f90..27234adfc8 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -17,6 +17,8 @@ pub struct FormerField< 'a > pub non_optional_ty : &'a syn::Type, pub is_optional : bool, pub of_type : container_kind::ContainerKind, + pub for_storage : bool, + pub for_formed : bool, } impl< 'a > FormerField< 'a > @@ -28,8 +30,8 @@ from_syn none_map optional_map -form_map -name_map +preform_map +storage_field_name setter_map subform_add_setter_map container_setter @@ -45,7 +47,7 @@ scalar_setter_required */ /// Construct former field from [`syn::Field`] - pub fn from_syn( field : &'a syn::Field ) -> Result< Self > + pub fn from_syn( field : &'a syn::Field, for_storage : bool, for_formed : bool ) -> Result< Self > { let attrs = FieldAttributes::from_attrs( field.attrs.iter() )?; let vis = &field.vis; @@ -56,7 +58,21 @@ scalar_setter_required let is_optional = typ::is_optional( ty ); let of_type = container_kind::of_optional( ty ).0; let non_optional_ty : &syn::Type = if is_optional { typ::parameter_first( ty )? } else { ty }; - let field2 = Self { attrs, vis, ident, colon_token, ty, non_optional_ty, is_optional, of_type }; + // let for_storage = true; + // let for_formed = true; + let field2 = Self + { + attrs, + vis, + ident, + colon_token, + ty, + non_optional_ty, + is_optional, + of_type, + for_storage, + for_formed, + }; Ok( field2 ) } @@ -160,8 +176,14 @@ scalar_setter_required /// #[ inline( always ) ] - pub fn form_map( &self ) -> Result< TokenStream > + pub fn preform_map( &self ) -> Result< TokenStream > { + + if !self.for_formed + { + return Ok( qt!{} ) + } + let ident = self.ident; let ty = self.ty; let default : Option< &syn::Expr > = self.attrs.config.as_ref() @@ -271,9 +293,17 @@ scalar_setter_required /// #[ inline( always ) ] - pub fn name_map( &self ) -> syn::Ident + pub fn storage_field_name( &self ) -> TokenStream { - self.ident.clone() + + if !self.for_formed + { + return qt!{} + } + + let ident = self.ident; + qt!{ #ident } + } // zzz : outdated, please update documentation From 5ea3c78d29d1cbdf5639dc9faae77e3ddbfca3fb Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 16:21:41 +0300 Subject: [PATCH 425/533] former : experimenting --- .../attribute_storage_primitive.rs | 16 +++---- module/core/former_meta/src/derive_former.rs | 47 ++++++++++--------- .../former_meta/src/derive_former/field.rs | 28 +++++------ 3 files changed, 46 insertions(+), 45 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs index 44ab706301..038853eeb0 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -3,7 +3,7 @@ use super::*; // xxx2 : implement #[ derive( Debug, PartialEq, the_module::Former ) ] -// #[ storage_fields( a : i32, b : Option< String > ) ] +#[ storage_fields( a : i32, b : Option< String > ) ] // #[ debug ] // #[ derive( Debug, PartialEq ) ] pub struct Struct1 @@ -22,13 +22,13 @@ tests_impls! { fn test_complex() { - // let got = Struct1::former().a( 13 ).b( "abc" ).form(); - // let exp = Struct1 - // { - // a : 13, - // b : Some( "abc".to_string() ), - // }; - // a_id!( got, exp ); + let got = Struct1::former().a( 13 ).b( "abc" ).form(); + let exp = Struct1 + { + // a : 13, + // b : Some( "abc".to_string() ), + }; + a_id!( got, exp ); } } diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 930548355e..e70284ec88 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -203,13 +203,13 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( - storage_fields_none, - storage_fields_optional, + storage_field_none, + storage_field_optional, storage_field_name, - storage_fields_preform, - former_fields_setter, - former_fields_former_assign, - former_fields_former_add, + storage_field_preform, + former_field_setter, + former_field_assign_end, + former_field_add_end, ) : ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) @@ -218,12 +218,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > .chain( storage_fields.iter() ) .map( | field | {( - field.none_map(), - field.optional_map(), + field.storage_fields_none(), + field.storage_field_optional(), field.storage_field_name(), - field.preform_map(), - field.setter_map( &stru ), - field.former_assign_end_map + field.storage_field_preform(), + field.former_field_setter( &stru ), + field.former_field_assign_end ( &stru, &former, @@ -231,7 +231,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > &former_generics_ty, &former_generics_where, ), - field.former_add_end_map + field.former_field_add_end ( &stru, &former, @@ -242,10 +242,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > ), )}).multiunzip(); - let former_fields_setter : Vec< _ > = process_results( former_fields_setter, | iter | iter.collect() )?; - let storage_fields_preform : Vec< _ > = process_results( storage_fields_preform, | iter | iter.collect() )?; - let former_fields_former_assign : Vec< _ > = process_results( former_fields_former_assign, | iter | iter.collect() )?; - let former_fields_former_add : Vec< _ > = process_results( former_fields_former_add, | iter | iter.collect() )?; + let former_field_setter : Vec< _ > = process_results( former_field_setter, | iter | iter.collect() )?; + let storage_field_preform : Vec< _ > = process_results( storage_field_preform, | iter | iter.collect() )?; + let former_field_assign_end : Vec< _ > = process_results( former_field_assign_end, | iter | iter.collect() )?; + let former_field_add_end : Vec< _ > = process_results( former_field_add_end, | iter | iter.collect() )?; let result = qt! { @@ -382,7 +382,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { #( /// A field - #storage_fields_optional, + #storage_field_optional, )* // #storage_fields_code } @@ -399,7 +399,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { Self { - #( #storage_fields_none, )* + #( #storage_field_none, )* } } @@ -422,12 +422,13 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > fn preform( mut self ) -> Self::Preformed { - #( #storage_fields_preform )* + #( #storage_field_preform )* // Rust does not support that, yet // let result = < Definition::Types as former::FormerDefinitionTypes >::Formed let result = #stru :: < #struct_generics_ty > { - #( #storage_field_name, )* + #( #storage_field_name )* + // #( #storage_field_name, )* }; return result; } @@ -552,7 +553,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } #( - #former_fields_setter + #former_field_setter )* } @@ -670,13 +671,13 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = container assign callbacks #( - #former_fields_former_assign + #former_field_assign_end )* // = container add callbacks #( - #former_fields_former_add + #former_field_add_end )* }; diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 27234adfc8..df7de1f601 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -28,16 +28,16 @@ impl< 'a > FormerField< 'a > from_syn -none_map -optional_map -preform_map +storage_fields_none +storage_field_optional +storage_field_preform storage_field_name -setter_map +former_field_setter subform_add_setter_map container_setter scalar_setter -former_assign_end_map -former_add_end_map +former_field_assign_end +former_field_add_end scalar_setter_name container_setter_name @@ -91,7 +91,7 @@ scalar_setter_required /// #[ inline( always ) ] - pub fn none_map( &self ) -> TokenStream + pub fn storage_fields_none( &self ) -> TokenStream { let ident = Some( self.ident.clone() ); let tokens = qt! { ::core::option::Option::None }; @@ -119,7 +119,7 @@ scalar_setter_required /// #[ inline( always ) ] - pub fn optional_map( &self ) -> TokenStream + pub fn storage_field_optional( &self ) -> TokenStream { let ident = Some( self.ident.clone() ); let ty = self.ty.clone(); @@ -176,7 +176,7 @@ scalar_setter_required /// #[ inline( always ) ] - pub fn preform_map( &self ) -> Result< TokenStream > + pub fn storage_field_preform( &self ) -> Result< TokenStream > { if !self.for_formed @@ -302,7 +302,7 @@ scalar_setter_required } let ident = self.ident; - qt!{ #ident } + qt!{ #ident, } } @@ -339,7 +339,7 @@ scalar_setter_required /// ``` #[ inline ] - pub fn setter_map + pub fn former_field_setter ( &self, stru : &syn::Ident, @@ -683,7 +683,7 @@ scalar_setter_required /// /// Generate a single scalar setter for the 'field_ident' with the 'setter_name' name. /// - /// Used as a helper function for setter_map(), which generates alias setters + /// Used as a helper function for former_field_setter(), which generates alias setters /// /// # Example of generated code /// ```ignore @@ -773,7 +773,7 @@ scalar_setter_required /// ``` #[ inline ] - pub fn former_assign_end_map + pub fn former_field_assign_end ( &self, stru : &syn::Ident, @@ -893,7 +893,7 @@ scalar_setter_required /// zzz : write documentation #[ inline ] - pub fn former_add_end_map + pub fn former_field_add_end ( &self, stru : &syn::Ident, From bd02ef715f1f802dfb7af932ae28a9896d3e8c2a Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 16:23:14 +0300 Subject: [PATCH 426/533] former : experimenting --- .../inc/former_tests/attribute_storage_primitive.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs index 038853eeb0..d04ca0c283 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -8,10 +8,7 @@ use super::*; // #[ derive( Debug, PartialEq ) ] pub struct Struct1 { - // #[ former( only_storage = true ) ] - // pub a : i32, - // #[ former( only_storage = true ) ] - // b : Option< String >, + c : String, } // == begin of generated @@ -22,11 +19,10 @@ tests_impls! { fn test_complex() { - let got = Struct1::former().a( 13 ).b( "abc" ).form(); + let got = Struct1::former().a( 13 ).b( "abc" ).c( "def" ).form(); let exp = Struct1 { - // a : 13, - // b : Some( "abc".to_string() ), + c : "def".to_string(), }; a_id!( got, exp ); } From 93f25b4659e3118909b18c6aa60995cbf2e136ce Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 16:36:01 +0300 Subject: [PATCH 427/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 1 - .../attribute_storage_primitive.rs | 55 +++++++++++++++++++ .../subformer_subform_named_manual.rs | 9 --- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 69a2a92d08..16cfd5609a 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -281,7 +281,6 @@ where impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition< Storage = Struct1FormerStorage, Formed = Struct1 >, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, Definition::Storage : former::StoragePreform< Preformed = Struct1 >, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs index d04ca0c283..7c691fc9e0 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -11,6 +11,61 @@ pub struct Struct1 c : String, } +pub struct Struct1CustomEnd< Definition > +{ + _phantom : core::marker::PhantomData< ( Definition, ) >, +} + +impl< Definition > Default for Struct1CustomEnd< Definition > +{ + + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + +} + +#[ automatically_derived ] +impl< Context, > former::FormingEnd +< + Struct1FormerDefinitionTypes< Context, Struct1 > +> +for Struct1CustomEnd< Struct1FormerDefinitionTypes< Context, Struct1 > > +{ + #[ inline( always ) ] + fn call + ( + &self, + storage : Struct1FormerStorage, + super_former : Option< Context >, + ) + -> Struct1 + { + let a = if let Some( a ) = storage.a + { + a + } + else + { + Default::default() + }; + let b = if let Some( b ) = storage.b + { + b + } + else + { + Default::default() + }; + Struct1 { c : format!( "{:?} - {:?}", a, b ) } + } +} + // == begin of generated // == end of generated diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs index bbd8a76afa..ad36ff96be 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs @@ -10,14 +10,6 @@ pub struct Child data : bool, } -// impl< Context, Formed, End > former::EntityToDefinition< Context, Formed, End > -// for Child -// where -// End : former::FormingEnd< ChildFormerDefinitionTypes< Context, Formed > >, -// { -// type Definition = ChildFormerDefinition< Context, Formed, End >; -// } - /// Parent required for the template. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] // #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] @@ -34,7 +26,6 @@ pub struct Parent impl< Definition > ParentFormer< Definition > where Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, - // Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >, { #[ inline( always ) ] From 6667c7fe988f65ed824b5bf8a15d24002462ab23 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 16:43:14 +0300 Subject: [PATCH 428/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 4 +++- .../attribute_storage_primitive.rs | 21 ++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 16cfd5609a..9fa9ba6b7a 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -18,7 +18,9 @@ impl Struct1 #[ inline( always ) ] pub fn former() -> Struct1Former< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > { - Struct1Former::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > >::new_coercing( former::ReturnPreformed ) + Struct1Former + ::< Struct1FormerDefinition< (), Struct1, former::ReturnPreformed > > + ::new( former::ReturnPreformed ) } } diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs index 7c691fc9e0..fb167feb74 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -11,12 +11,13 @@ pub struct Struct1 c : String, } -pub struct Struct1CustomEnd< Definition > +pub struct Struct1CustomEnd { - _phantom : core::marker::PhantomData< ( Definition, ) >, + _phantom : core::marker::PhantomData< ( (), ) >, } -impl< Definition > Default for Struct1CustomEnd< Definition > +// impl< Definition > Default for Struct1CustomEnd< Definition > +impl Default for Struct1CustomEnd { #[ inline( always ) ] @@ -35,7 +36,7 @@ impl< Context, > former::FormingEnd < Struct1FormerDefinitionTypes< Context, Struct1 > > -for Struct1CustomEnd< Struct1FormerDefinitionTypes< Context, Struct1 > > +for Struct1CustomEnd { #[ inline( always ) ] fn call @@ -62,7 +63,7 @@ for Struct1CustomEnd< Struct1FormerDefinitionTypes< Context, Struct1 > > { Default::default() }; - Struct1 { c : format!( "{:?} - {:?}", a, b ) } + Struct1 { c : format!( "{:?} - :?", a, b ) } } } @@ -72,12 +73,18 @@ for Struct1CustomEnd< Struct1FormerDefinitionTypes< Context, Struct1 > > tests_impls! { + fn test_complex() { - let got = Struct1::former().a( 13 ).b( "abc" ).c( "def" ).form(); + // let got = Struct1::former().a( 13 ).b( "abc" ).c( "def" ).form(); + let end = Struct1CustomEnd::default(); + let got = Struct1Former + ::< Struct1FormerDefinition< (), Struct1, _ > > + ::new( end ) + .a( 13 ).b( "abc" ).c( "def" ).form(); let exp = Struct1 { - c : "def".to_string(), + c : "13 - abc".to_string(), }; a_id!( got, exp ); } From c2764a282e3983b25567d0d939fb36adcdd8c393 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 16:43:54 +0300 Subject: [PATCH 429/533] former : experimenting --- .../attribute_storage_primitive.rs | 2 +- module/core/former_meta/src/derive_former.rs | 2 +- .../src/derive_former/struct_attrs.rs | 60 +++++++++---------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs index fb167feb74..bfd3604262 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -63,7 +63,7 @@ for Struct1CustomEnd { Default::default() }; - Struct1 { c : format!( "{:?} - :?", a, b ) } + Struct1 { c : format!( "{:?} - {}", a, b ) } } } diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index e70284ec88..c51e3de245 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -174,7 +174,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( _doc_former_mod, doc_former_struct ) = doc_generate( stru ); let ( perform, perform_output, perform_generics ) = struct_attrs.performer()?; - let storage_fields_code = struct_attrs.storage_fields_code()?; + // let storage_fields_code = struct_attrs.storage_fields_code()?; /* fields */ diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs index 2dab13e9ee..5498e50099 100644 --- a/module/core/former_meta/src/derive_former/struct_attrs.rs +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -214,35 +214,35 @@ impl StructAttributes // ) } - /// Generates a `TokenStream` for the fields specified in `storage_fields`. - /// - /// This function constructs a token stream for code generation, incorporating fields from the - /// `storage_fields` attribute into the generated Rust code. If `storage_fields` is set, it includes - /// its fields in the output; otherwise, it returns an empty token stream. - /// - /// # Example of generated code - /// - /// ```rust, ignore - /// field1 : i32, - /// field2 : String, - /// ``` - /// - - pub fn storage_fields_code( &self ) - -> Result< TokenStream > - { - - let mut result = qt! - { - }; - - if let Some( ref attr ) = self.storage_fields - { - let storage_fields = &attr.fields; - result = qt! { #storage_fields } - } - - Ok( result ) - } +// /// Generates a `TokenStream` for the fields specified in `storage_fields`. +// /// +// /// This function constructs a token stream for code generation, incorporating fields from the +// /// `storage_fields` attribute into the generated Rust code. If `storage_fields` is set, it includes +// /// its fields in the output; otherwise, it returns an empty token stream. +// /// +// /// # Example of generated code +// /// +// /// ```rust, ignore +// /// field1 : i32, +// /// field2 : String, +// /// ``` +// /// +// +// pub fn storage_fields_code( &self ) +// -> Result< TokenStream > +// { +// +// let mut result = qt! +// { +// }; +// +// if let Some( ref attr ) = self.storage_fields +// { +// let storage_fields = &attr.fields; +// result = qt! { #storage_fields } +// } +// +// Ok( result ) +// } } From 729b281eae8c747a9de9cfe2cc3a8791418fd7ec Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 17:08:45 +0300 Subject: [PATCH 430/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 29 +++++++++++++++---- .../attribute_storage_primitive.rs | 1 + 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 9fa9ba6b7a..b3266e1e8d 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -167,6 +167,26 @@ impl former::StoragePreform for Struct1FormerStorage } } +// = former before end + +pub trait FormerBeforeEnd +where + Self : former::FormerDefinitionTypes, +{ + fn before_end( _storage : &mut Self::Storage, _context : &mut ::core::option::Option< Self::Context > ) + { + } +} + +impl< Definition > FormerBeforeEnd +for Definition +where + Definition : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +{ +} + +// FormerBeforeEnd::< Self >::before_end( &mut self.storage, &mut context ); + // = former pub struct Struct1Former @@ -175,18 +195,16 @@ pub struct Struct1Former > where Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { storage : Definition::Storage, - context : core::option::Option< Definition::Context >, - on_end : core::option::Option< Definition::End >, + context : ::core::option::Option< Definition::Context >, + on_end : ::core::option::Option< Definition::End >, } #[ automatically_derived ] impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { #[ inline( always ) ] @@ -263,7 +281,8 @@ where pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); + let mut context = self.context.take(); + < Definition::Types as FormerBeforeEnd >::before_end( &mut self.storage, &mut context ); former::FormingEnd::< Definition::Types >::call( & on_end, self.storage, context ) } diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs index bfd3604262..b3621a3753 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -88,6 +88,7 @@ tests_impls! }; a_id!( got, exp ); } + } tests_index! From 0246edc8950203b7fdd2a1c6a174808467481662 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 17:27:45 +0300 Subject: [PATCH 431/533] former : experimenting --- module/core/former/src/forming.rs | 39 +++++++++++++++++++ .../tests/inc/former_tests/a_basic_manual.rs | 25 +++++------- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/module/core/former/src/forming.rs b/module/core/former/src/forming.rs index e94e059258..2b3bf054bb 100644 --- a/module/core/former/src/forming.rs +++ b/module/core/former/src/forming.rs @@ -1,4 +1,43 @@ + +/// Provides a mechanism for mutating the context and storage just before the forming process is completed. +/// +/// The `FormerMutator` trait allows for the implementation of custom mutation logic on the internal state +/// of an entity (context and storage) just before the final forming operation is completed. This mutation +/// occurs immediately before the `FormingEnd` callback is invoked. +/// +/// ## Differences from `FormingEnd` +/// +/// Unlike `FormingEnd`, which is responsible for integrating and finalizing the formation process of a field within +/// a parent former, `form_mutation` directly pertains to the entity itself. This method is designed to be independent +/// of whether the forming process is occurring within the context of a superformer or if the structure is a standalone +/// or nested field. This makes `form_mutation` suitable for entity-specific transformations that should not interfere +/// with the hierarchical forming logic managed by `FormingEnd`. +/// +/// ## Use Cases +/// +/// - Applying last-minute changes to the data being formed. +/// - Setting or modifying properties that depend on the final state of the storage or context. +/// - Storage-specific fields which are not present in formed structure. + +// xxx : add example +pub trait FormerMutator +where + Self : crate::FormerDefinitionTypes, +{ + /// Mutates the context and storage of the entity just before the formation process completes. + /// + /// This function is invoked immediately prior to the `FormingEnd` callback during the forming process. + /// It provides a hook for implementing custom logic that modifies the internal state (storage and context) + /// of the entity. `form_mutation` is particularly useful for adjustments or updates that need to reflect + /// in the entity just before it is finalized and returned. + /// + #[ inline ] + fn form_mutation( _storage : &mut Self::Storage, _context : &mut ::core::option::Option< Self::Context > ) + { + } +} + /// Defines a handler for the end of a subforming process, enabling the return of the original context. /// /// This trait is designed to be flexible, allowing for various end-of-forming behaviors in builder patterns. diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index b3266e1e8d..378b74f2c6 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -167,25 +167,16 @@ impl former::StoragePreform for Struct1FormerStorage } } -// = former before end +// = former mutator -pub trait FormerBeforeEnd -where - Self : former::FormerDefinitionTypes, -{ - fn before_end( _storage : &mut Self::Storage, _context : &mut ::core::option::Option< Self::Context > ) - { - } -} - -impl< Definition > FormerBeforeEnd -for Definition -where - Definition : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, +impl< Context, Formed > former::FormerMutator +for Struct1FormerDefinitionTypes< Context, Formed > +// where + // Struct1FormerDefinitionTypes : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { } -// FormerBeforeEnd::< Self >::before_end( &mut self.storage, &mut context ); +// FormerMutator::< Self >::form_mutation( &mut self.storage, &mut context ); // = former @@ -205,6 +196,7 @@ where impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, + < Definition as former::FormerDefinition >::Types : former::FormerMutator, { #[ inline( always ) ] @@ -282,7 +274,7 @@ where { let on_end = self.on_end.take().unwrap(); let mut context = self.context.take(); - < Definition::Types as FormerBeforeEnd >::before_end( &mut self.storage, &mut context ); + < Definition::Types as former::FormerMutator >::form_mutation( &mut self.storage, &mut context ); former::FormingEnd::< Definition::Types >::call( & on_end, self.storage, context ) } @@ -314,6 +306,7 @@ impl< Definition > former::FormerBegin< Definition > for Struct1Former< Definition > where Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, + < Definition as former::FormerDefinition >::Types : former::FormerMutator, { #[ inline( always ) ] From 9987e1a875aebd2425a19648dbd1dd29195f17aa Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 17:31:02 +0300 Subject: [PATCH 432/533] former : experimenting --- module/core/former/src/forming.rs | 7 +++++++ .../core/former/tests/inc/former_tests/a_basic_manual.rs | 4 ---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/module/core/former/src/forming.rs b/module/core/former/src/forming.rs index 2b3bf054bb..b16f631a57 100644 --- a/module/core/former/src/forming.rs +++ b/module/core/former/src/forming.rs @@ -38,6 +38,13 @@ where } } +// impl< Definition > crate::FormerMutator +// for Definition +// where +// Definition : crate::FormerDefinitionTypes, +// { +// } + /// Defines a handler for the end of a subforming process, enabling the return of the original context. /// /// This trait is designed to be flexible, allowing for various end-of-forming behaviors in builder patterns. diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 378b74f2c6..e9b9c86583 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -171,13 +171,9 @@ impl former::StoragePreform for Struct1FormerStorage impl< Context, Formed > former::FormerMutator for Struct1FormerDefinitionTypes< Context, Formed > -// where - // Struct1FormerDefinitionTypes : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { } -// FormerMutator::< Self >::form_mutation( &mut self.storage, &mut context ); - // = former pub struct Struct1Former From 4389cc19fa85e7cee32466e71eeb0848be9a2af3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 17:56:19 +0300 Subject: [PATCH 433/533] former : experimenting --- module/core/former/src/definition.rs | 4 +- module/core/former/src/hash_map.rs | 7 + module/core/former/src/hash_set.rs | 7 + module/core/former/src/vector.rs | 5 + .../former/tests/inc/former_tests/a_basic.rs | 1 - .../tests/inc/former_tests/a_basic_manual.rs | 1 + .../a_containers_with_subformer_manual.rs | 11 +- .../inc/former_tests/a_primitives_manual.rs | 5 + .../inc/former_tests/attribute_setter.rs | 6 - .../former_tests/container_former_common.rs | 14 ++ module/core/former/tests/inc/mod.rs | 199 +++++++++--------- module/core/former_meta/src/derive_former.rs | 43 ++-- 12 files changed, 180 insertions(+), 123 deletions(-) diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs index 3b52346534..1b820752be 100644 --- a/module/core/former/src/definition.rs +++ b/module/core/former/src/definition.rs @@ -35,7 +35,9 @@ pub trait FormerDefinitionTypes : Sized /// zzz : write description pub trait FormerDefinition : Sized { - type Types : crate::FormerDefinitionTypes< Storage = Self::Storage, Formed = Self::Formed, Context = Self::Context >; + type Types : + crate::FormerDefinitionTypes< Storage = Self::Storage, Formed = Self::Formed, Context = Self::Context > + + crate::FormerMutator; type End : crate::FormingEnd< Self::Types >; type Storage : Default; type Formed; diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index e6081f428c..c57ac1bf16 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -123,6 +123,13 @@ where type Context = Context; } +impl< K, E, Context, Formed > FormerMutator +for HashMapDefinition< K, E, Context, Formed, NoEnd > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ +} + impl< K, E, Context, Formed, End > FormerDefinition for HashMapDefinition< K, E, Context, Formed, End > where diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 307bd7490b..fb479e1d01 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -134,6 +134,13 @@ where type Context = Context; } +impl< K, Context, Formed > FormerMutator +for HashSetDefinition< K, Context, Formed, NoEnd > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ +} + impl< K, Context, Formed, End > FormerDefinition for HashSetDefinition< K, Context, Formed, End > where diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 3ef46dbbc7..7d2b6147e9 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -113,6 +113,11 @@ for VectorDefinition< E, Context, Formed, NoEnd > type Context = Context; } +impl< E, Context, Formed > FormerMutator +for VectorDefinition< E, Context, Formed, NoEnd > +{ +} + impl< E, Context, Formed, End > FormerDefinition for VectorDefinition< E, Context, Formed, End > where diff --git a/module/core/former/tests/inc/former_tests/a_basic.rs b/module/core/former/tests/inc/former_tests/a_basic.rs index 04ef5312c9..50d74672af 100644 --- a/module/core/former/tests/inc/former_tests/a_basic.rs +++ b/module/core/former/tests/inc/former_tests/a_basic.rs @@ -10,7 +10,6 @@ pub struct Struct1 } // == begin of generated - // == end of generated include!( "./only_test/basic.rs" ); diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index e9b9c86583..ad872c3afc 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -291,6 +291,7 @@ impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition< Storage = Struct1FormerStorage, Formed = Struct1 >, Definition::Storage : former::StoragePreform< Preformed = Struct1 >, + < Definition as former::FormerDefinition >::Types : former::FormerMutator, { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 07ab4afe6e..237150fdb0 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -48,7 +48,8 @@ where _phantom : core::marker::PhantomData<(Context, Formed)>, } -impl< Context, Formed, > core::default::Default for Struct1FormerDefinitionTypes< Context, Formed, > +impl< Context, Formed, > core::default::Default +for Struct1FormerDefinitionTypes< Context, Formed, > where { fn default() -> Self @@ -60,7 +61,8 @@ where } } -impl< Context, Formed, > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< Context, Formed, > +impl< Context, Formed, > former::FormerDefinitionTypes +for Struct1FormerDefinitionTypes< Context, Formed, > where { type Storage = Struct1FormerStorage<>; @@ -68,6 +70,11 @@ where type Context = Context; } +impl< Context, Formed > former::FormerMutator +for Struct1FormerDefinitionTypes< Context, Formed > +{ +} + #[derive(Debug)] pub struct Struct1FormerDefinition< Context = (), Formed = Struct1<>, End = former::ReturnPreformed, > where diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 5c0b14ea3f..35778dd7bf 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -67,6 +67,11 @@ for Struct1FormerDefinitionTypes< Context, Formed > type Context = Context; } +impl< Context, Formed > former::FormerMutator +for Struct1FormerDefinitionTypes< Context, Formed > +{ +} + impl< Context, Formed, End > former::FormerDefinition for Struct1FormerDefinition< Context, Formed, End > where diff --git a/module/core/former/tests/inc/former_tests/attribute_setter.rs b/module/core/former/tests/inc/former_tests/attribute_setter.rs index d1674b7a83..ee18f78657 100644 --- a/module/core/former/tests/inc/former_tests/attribute_setter.rs +++ b/module/core/former/tests/inc/former_tests/attribute_setter.rs @@ -9,15 +9,9 @@ pub struct StructWithCustomSetters magic : String, } -// impl< Context, End > StructWithCustomSettersFormer< Context, End > -// where -// End: the_module::FormingEnd< StructWithCustomSetters, Context >, -// { - impl< Definition > StructWithCustomSettersFormer< Definition > where Definition : former::FormerDefinition< Storage = StructWithCustomSettersFormerStorage >, - // Definition::Types : former::FormerDefinitionTypes< Storage = StructWithCustomSettersFormerStorage >, { /// Custom alternative setter of ordinary field. diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index 2781556450..6e0df08764 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -104,6 +104,11 @@ fn custom_definition() type Context = (); } + impl former::FormerMutator + for Return13 + { + } + impl former::FormerDefinition for Return13 { type Types = Return13; @@ -174,6 +179,11 @@ fn custom_definition_parametrized() type Context = (); } + impl< E > former::FormerMutator + for Return13< E > + { + } + impl< E > former::FormerDefinition for Return13< E > { type Types = Return13< E >; @@ -250,6 +260,10 @@ fn custom_definition_custom_end() type Formed = i32; type Context = (); } + impl former::FormerMutator + for Return13 + { + } impl former::FormerDefinition for Return13 { type Types = Return13; diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 9d6113b348..6ddfc9a7ac 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -32,70 +32,72 @@ mod former_tests mod attribute_default_conflict; mod attribute_storage_primitive; mod attribute_perform; - mod attribute_setter; + // mod attribute_setter; mod attribute_alias; mod attribute_feature; - mod string_slice_manual; - mod string_slice; - mod unsigned_primitive_types; - mod default_user_type; - mod user_type_no_default; - mod user_type_no_debug; - mod visibility; - - mod name_collision_former_hashmap_without_parameter; - mod name_collision_former_vector_without_parameter; - mod name_collisions; - mod name_collision_context; - mod name_collision_end; - mod name_collision_on_end; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_manual; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_imm; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_where; - mod parametrized_field; - mod parametrized_field_where; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_basic; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_manual; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_implicit; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_setter_off; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_named; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_manual; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_named; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_named_manual; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_setter_off; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_setter_on; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_hashmap; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_hashmap_custom; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_and_container; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_and_container_parametrized; +// mod string_slice_manual; +// mod string_slice; +// mod unsigned_primitive_types; +// mod default_user_type; +// mod user_type_no_default; +// mod user_type_no_debug; +// mod visibility; +// +// mod name_collision_former_hashmap_without_parameter; +// mod name_collision_former_vector_without_parameter; +// mod name_collisions; +// mod name_collision_context; +// mod name_collision_end; +// mod name_collision_on_end; + +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_manual; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_imm; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_where; +// mod parametrized_field; +// mod parametrized_field_where; +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_basic; +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container_manual; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container_implicit; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container_setter_off; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container_named; +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_manual; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_named; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_named_manual; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_setter_off; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_setter_on; +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_hashmap; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_hashmap_custom; +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_and_container; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_and_container_parametrized; + +// xxx } @@ -131,40 +133,41 @@ mod components_tests } -only_for_terminal_module! -{ - - // stable have different information about error - // that's why these tests are active only for nightly - #[ test_tools::nightly ] - #[ test ] - fn former_trybuild() - { - - println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); - let t = test_tools::compiletime::TestCases::new(); - - // zzz : uncomment - t.compile_fail( "tests/inc/former_tests/compiletime/field_attr_bad.rs" ); - t.compile_fail( "tests/inc/former_tests/compiletime/struct_attr_bad.rs" ); - t.pass( "tests/inc/former_tests/compiletime/hashmap_without_parameter.rs" ); - t.pass( "tests/inc/former_tests/compiletime/vector_without_parameter.rs" ); - - } - - // stable have different information about error - // that's why these tests are active only for nightly - #[ test_tools::nightly ] - #[ test ] - fn components_trybuild() - { - - println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); - let _t = test_tools::compiletime::TestCases::new(); - - // zzz : make it working test - //t.run( "tests/inc/components_tests/compiletime/components_component_from_debug.rs" ); - - } - -} +// xxx +// only_for_terminal_module! +// { +// +// // stable have different information about error +// // that's why these tests are active only for nightly +// #[ test_tools::nightly ] +// #[ test ] +// fn former_trybuild() +// { +// +// println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); +// let t = test_tools::compiletime::TestCases::new(); +// +// // zzz : uncomment +// t.compile_fail( "tests/inc/former_tests/compiletime/field_attr_bad.rs" ); +// t.compile_fail( "tests/inc/former_tests/compiletime/struct_attr_bad.rs" ); +// t.pass( "tests/inc/former_tests/compiletime/hashmap_without_parameter.rs" ); +// t.pass( "tests/inc/former_tests/compiletime/vector_without_parameter.rs" ); +// +// } +// +// // stable have different information about error +// // that's why these tests are active only for nightly +// #[ test_tools::nightly ] +// #[ test ] +// fn components_trybuild() +// { +// +// println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); +// let _t = test_tools::compiletime::TestCases::new(); +// +// // zzz : make it working test +// //t.run( "tests/inc/components_tests/compiletime/components_component_from_debug.rs" ); +// +// } +// +// } diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index c51e3de245..10cd43d50d 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -118,6 +118,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where Definition : former::FormerDefinition< Storage = #former_storage < #struct_generics_ty > >, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #struct_generics_ty > >, + < Definition as former::FormerDefinition >::Types : former::FormerMutator, }; let extra = generic_params::merge( &generics, &extra.into() ); @@ -140,6 +141,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > Storage = #former_storage < #struct_generics_ty >, Formed = #stru < #struct_generics_ty >, >, + < Definition as former::FormerDefinition >::Types : former::FormerMutator, }; let extra = generic_params::merge( &generics, &extra.into() ); @@ -152,11 +154,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { < __Context = (), __Formed = #stru < #struct_generics_ty > > }; - let former_definition_type_generics = generic_params::merge( &generics, &extra.into() ); - let ( former_definition_type_generics_with_defaults, former_definition_type_generics_impl, former_definition_type_generics_ty, former_definition_type_generics_where ) - = generic_params::decompose( &former_definition_type_generics ); + let former_definition_types_generics = generic_params::merge( &generics, &extra.into() ); + let ( former_definition_types_generics_with_defaults, former_definition_types_generics_impl, former_definition_types_generics_ty, former_definition_types_generics_where ) + = generic_params::decompose( &former_definition_types_generics ); - let former_definition_type_phantom = macro_tools::phantom::tuple( &former_definition_type_generics_impl ); + let former_definition_types_phantom = macro_tools::phantom::tuple( &former_definition_types_generics_impl ); /* parameters for definition */ @@ -276,6 +278,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > for #stru < #struct_generics_ty > where Definition : former::FormerDefinition< Storage = #former_storage < #struct_generics_ty > >, + < Definition as former::FormerDefinition >::Types : former::FormerMutator, #struct_generics_where { type Former = #former < #struct_generics_ty Definition > ; @@ -301,18 +304,18 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = definition types #[ derive( Debug ) ] - pub struct #former_definition_types < #former_definition_type_generics_with_defaults > + pub struct #former_definition_types < #former_definition_types_generics_with_defaults > where - #former_definition_type_generics_where + #former_definition_types_generics_where { // _phantom : core::marker::PhantomData< ( __Context, __Formed ) >, - _phantom : #former_definition_type_phantom, + _phantom : #former_definition_types_phantom, } - impl < #former_definition_type_generics_impl > ::core::default::Default - for #former_definition_types < #former_definition_type_generics_ty > + impl < #former_definition_types_generics_impl > ::core::default::Default + for #former_definition_types < #former_definition_types_generics_ty > where - #former_definition_type_generics_where + #former_definition_types_generics_where { fn default() -> Self { @@ -323,10 +326,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } } - impl < #former_definition_type_generics_impl > former::FormerDefinitionTypes - for #former_definition_types < #former_definition_type_generics_ty > + impl < #former_definition_types_generics_impl > former::FormerDefinitionTypes + for #former_definition_types < #former_definition_types_generics_ty > where - #former_definition_type_generics_where + #former_definition_types_generics_where { type Storage = #former_storage < #struct_generics_ty >; type Formed = __Formed; @@ -361,16 +364,23 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl < #former_definition_generics_impl > former::FormerDefinition for #former_definition < #former_definition_generics_ty > where - __End : former::FormingEnd< #former_definition_types < #former_definition_type_generics_ty > >, + __End : former::FormingEnd< #former_definition_types < #former_definition_types_generics_ty > >, #former_definition_generics_where { - type Types = #former_definition_types < #former_definition_type_generics_ty >; + type Types = #former_definition_types < #former_definition_types_generics_ty >; type End = __End; type Storage = #former_storage < #struct_generics_ty >; type Formed = __Formed; type Context = __Context; } + // = former mutator + + impl< #former_definition_types_generics_impl > former::FormerMutator + for #former_definition_types < #former_definition_types_generics_ty > + { + } + // = storage #[ doc = "Container of a corresponding former." ] @@ -549,6 +559,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); + // < Definition::Types as former::FormerMutator >::form_mutation( &mut self.storage, &mut context ); + // xxx former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) } @@ -608,6 +620,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > > where Definition : former::FormerDefinition< Storage = #former_storage < #struct_generics_ty > >, + < Definition as former::FormerDefinition >::Types : former::FormerMutator, #struct_generics_where { From b3e1d6929be34581b522ec340c912d7fa6ff1cc7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 17:57:17 +0300 Subject: [PATCH 434/533] former : experimenting --- module/core/former_meta/src/derive_former.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 10cd43d50d..5681001d0d 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -118,7 +118,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where Definition : former::FormerDefinition< Storage = #former_storage < #struct_generics_ty > >, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #struct_generics_ty > >, - < Definition as former::FormerDefinition >::Types : former::FormerMutator, + // < Definition as former::FormerDefinition >::Types : former::FormerMutator, }; let extra = generic_params::merge( &generics, &extra.into() ); @@ -141,7 +141,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > Storage = #former_storage < #struct_generics_ty >, Formed = #stru < #struct_generics_ty >, >, - < Definition as former::FormerDefinition >::Types : former::FormerMutator, + // < Definition as former::FormerDefinition >::Types : former::FormerMutator, }; let extra = generic_params::merge( &generics, &extra.into() ); @@ -278,7 +278,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > for #stru < #struct_generics_ty > where Definition : former::FormerDefinition< Storage = #former_storage < #struct_generics_ty > >, - < Definition as former::FormerDefinition >::Types : former::FormerMutator, + // < Definition as former::FormerDefinition >::Types : former::FormerMutator, #struct_generics_where { type Former = #former < #struct_generics_ty Definition > ; @@ -620,7 +620,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > > where Definition : former::FormerDefinition< Storage = #former_storage < #struct_generics_ty > >, - < Definition as former::FormerDefinition >::Types : former::FormerMutator, + // < Definition as former::FormerDefinition >::Types : former::FormerMutator, #struct_generics_where { From e0d09a471d8fcdc3795011ea85bb7c9402aa7f26 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 18:05:14 +0300 Subject: [PATCH 435/533] former : experimenting --- module/core/former/src/vector.rs | 1 + .../attribute_storage_primitive.rs | 3 +- .../parametrized_struct_manual.rs | 10 ++- .../inc/former_tests/string_slice_manual.rs | 10 ++- .../inc/former_tests/subformer_container.rs | 1 - module/core/former/tests/inc/mod.rs | 78 +++++++++---------- 6 files changed, 60 insertions(+), 43 deletions(-) diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 7d2b6147e9..a53b50082e 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -97,6 +97,7 @@ for Vec< E > // = definition +// xxx : split definition and definition types #[ derive( Debug, Default ) ] pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > where diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs index b3621a3753..21dbc7e52f 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs @@ -1,6 +1,7 @@ #[ allow( unused_imports ) ] use super::*; -// xxx2 : implement + +// xxx2 : finish #[ derive( Debug, PartialEq, the_module::Former ) ] #[ storage_fields( a : i32, b : Option< String > ) ] diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index d745a59167..b3669e4e04 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -53,7 +53,8 @@ impl< K, > Child< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, } #[ derive( Debug ) ] -pub struct ChildFormerDefinitionTypes< K, __Context = (), __Formed = Child< K, >, > where K : core :: hash :: Hash + std :: cmp :: Eq, +pub struct ChildFormerDefinitionTypes< K, __Context = (), __Formed = Child< K, >, > +where K : core :: hash :: Hash + std :: cmp :: Eq, { _phantom : core :: marker :: PhantomData< ( K, __Context, __Formed ) >, } @@ -82,6 +83,13 @@ where type Context = __Context; } +impl< K, Context, Formed > former::FormerMutator +for ChildFormerDefinitionTypes< K, Context, Formed > +where + K : core :: hash :: Hash + std :: cmp :: Eq, +{ +} + #[ derive( Debug ) ] pub struct ChildFormerDefinition < K, __Context = (), __Formed = Child< K, >, __End = former :: ReturnPreformed, > diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index c47e60e2ba..85d3dbc414 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -37,13 +37,21 @@ impl< 'a, Context, Formed > Default for Struct1FormerDefinitionTypes< 'a, Contex } } -impl< 'a, Context, Formed > former::FormerDefinitionTypes for Struct1FormerDefinitionTypes< 'a, Context, Formed > +impl< 'a, Context, Formed > former::FormerDefinitionTypes +for Struct1FormerDefinitionTypes< 'a, Context, Formed > { type Storage = Struct1FormerStorage< 'a >; type Formed = Formed; type Context = Context; } +// = former mutator + +impl< 'a, Context, Formed > former::FormerMutator +for Struct1FormerDefinitionTypes< 'a, Context, Formed > +{ +} + // = definition #[ derive( Debug ) ] diff --git a/module/core/former/tests/inc/former_tests/subformer_container.rs b/module/core/former/tests/inc/former_tests/subformer_container.rs index 10370499cf..c168f83e8b 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container.rs @@ -17,7 +17,6 @@ pub struct Child pub struct Parent { #[ container( definition = former::VectorDefinition ) ] - // #[ scalar( setter = false ) ] children : Vec< Child >, } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 6ddfc9a7ac..c3df5bcb3e 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -32,48 +32,48 @@ mod former_tests mod attribute_default_conflict; mod attribute_storage_primitive; mod attribute_perform; - // mod attribute_setter; + mod attribute_setter; mod attribute_alias; mod attribute_feature; -// mod string_slice_manual; -// mod string_slice; -// mod unsigned_primitive_types; -// mod default_user_type; -// mod user_type_no_default; -// mod user_type_no_debug; -// mod visibility; -// -// mod name_collision_former_hashmap_without_parameter; -// mod name_collision_former_vector_without_parameter; -// mod name_collisions; -// mod name_collision_context; -// mod name_collision_end; -// mod name_collision_on_end; - -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_manual; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_imm; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_where; -// mod parametrized_field; -// mod parametrized_field_where; -// -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_basic; -// -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container_manual; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container_implicit; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container_setter_off; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container_named; -// + mod string_slice_manual; + mod string_slice; + mod unsigned_primitive_types; + mod default_user_type; + mod user_type_no_default; + mod user_type_no_debug; + mod visibility; + + mod name_collision_former_hashmap_without_parameter; + mod name_collision_former_vector_without_parameter; + mod name_collisions; + mod name_collision_context; + mod name_collision_end; + mod name_collision_on_end; + + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_manual; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod parametrized_struct_imm; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod parametrized_struct_where; + // mod parametrized_field; + // mod parametrized_field_where; + + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod subformer_basic; + + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_container; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_container_manual; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_container_implicit; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_container_setter_off; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_container_named; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_subform; // #[ cfg( any( not( feature = "no_std" ) ) ) ] From 792021bfc5b5f5e685bc2da5feaae139259c5076 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 18:06:53 +0300 Subject: [PATCH 436/533] former : experimenting --- module/core/former/tests/inc/mod.rs | 86 ++++++++++---------- module/core/former_meta/src/derive_former.rs | 2 + 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index c3df5bcb3e..75eb65ae8f 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -53,51 +53,49 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod parametrized_struct_manual; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod parametrized_struct_imm; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod parametrized_struct_where; - // mod parametrized_field; - // mod parametrized_field_where; - - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod subformer_basic; - - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_container; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_container_manual; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_container_implicit; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_container_setter_off; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_container_named; - -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_manual; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_named; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_named_manual; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_setter_off; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_setter_on; -// -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_hashmap; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_hashmap_custom; -// -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_and_container; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_and_container_parametrized; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_imm; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_where; + mod parametrized_field; + mod parametrized_field_where; -// xxx + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod subformer_basic; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_implicit; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_setter_off; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_named; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_named; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_named_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_setter_off; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_setter_on; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_hashmap; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_hashmap_custom; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_and_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_and_container_parametrized; } diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 5681001d0d..d8f776c4f1 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -378,6 +378,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > impl< #former_definition_types_generics_impl > former::FormerMutator for #former_definition_types < #former_definition_types_generics_ty > + where + #former_definition_types_generics_where { } From c61cae315d7b8ed05df9a6ac3a8e2e79efdf47ff Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 18:48:06 +0300 Subject: [PATCH 437/533] former : experimenting --- module/core/former_meta/src/derive_former.rs | 42 ++- .../src/derive_former/field_attrs.rs | 9 - .../src/derive_former/struct_attrs.rs | 255 ++++++++++-------- 3 files changed, 184 insertions(+), 122 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index d8f776c4f1..0de07ea245 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -249,6 +249,41 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_field_assign_end : Vec< _ > = process_results( former_field_assign_end, | iter | iter.collect() )?; let former_field_add_end : Vec< _ > = process_results( former_field_add_end, | iter | iter.collect() )?; + let former_mutator_code = if struct_attrs.mutator.custom + { + qt!{} + } + else + { + qt! + { + impl< #former_definition_types_generics_impl > former::FormerMutator + for #former_definition_types < #former_definition_types_generics_ty > + where + #former_definition_types_generics_where + { + } + } + }; + + if struct_attrs.mutator.hint + { + let hint = format! + ( + r#" + = Example of custom mutator + +impl< {former_definition_types_generics_impl:?} > former::FormerMutator +for {former_definition_types} < {former_definition_types_generics_ty:?} > +where + {former_definition_types_generics_where:?} +{} + "#, + "{\n}" + ); + println!( "{hint}" ); + }; + let result = qt! { @@ -376,12 +411,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = former mutator - impl< #former_definition_types_generics_impl > former::FormerMutator - for #former_definition_types < #former_definition_types_generics_ty > - where - #former_definition_types_generics_where - { - } + #former_mutator_code // = storage diff --git a/module/core/former_meta/src/derive_former/field_attrs.rs b/module/core/former_meta/src/derive_former/field_attrs.rs index f044103961..ded145de80 100644 --- a/module/core/former_meta/src/derive_former/field_attrs.rs +++ b/module/core/former_meta/src/derive_former/field_attrs.rs @@ -118,9 +118,6 @@ pub struct AttributeConfig /// Default value to use for the field. pub default : Option< syn::Expr >, - // /// Such field should be present only in storage and should not be present in structure itself. - // /// That might be useful for parametrization of forming process. - // pub only_storage : Option< bool >, } @@ -146,12 +143,6 @@ impl syn::parse::Parse for AttributeConfig input.parse::< syn::Token![ = ] >()?; default = Some( input.parse()? ); } - // else if ident == "only_storage" - // { - // input.parse::< syn::Token![ = ] >()?; - // let value : syn::LitBool = input.parse()?; - // only_storage = Some( value.value() ); - // } else { return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'default'. For example: `former( default = 13 )`", ident ) ) ); diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs index 5498e50099..cfc8521573 100644 --- a/module/core/former_meta/src/derive_former/struct_attrs.rs +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -14,15 +14,17 @@ pub struct StructAttributes { pub perform : Option< AttributePerform >, pub storage_fields : Option< AttributeStorageFields >, + pub mutator : AttributeMutator, } impl StructAttributes { - // fn from_attrs( attributes : & Vec< syn::Attribute > ) -> Result< Self > + pub fn from_attrs< 'a >( attrs : impl Iterator< Item = &'a syn::Attribute > ) -> Result< Self > { let mut perform = None; let mut storage_fields = None; + let mut mutator = Default::default(); for attr in attrs { @@ -61,6 +63,21 @@ impl StructAttributes .\nGot: {}", qt!{ #attr } ), } } + "mutator" => + { + match attr.meta + { + syn::Meta::List( ref meta_list ) => + { + mutator = syn::parse2::< AttributeMutator >( meta_list.tokens.clone() )? + // container.replace( syn::parse2::< AttributeMutator >( meta_list.tokens.clone() )? ); + }, + syn::Meta::Path( ref _path ) => + { + }, + _ => return_syn_err!( attr, "Expects an attribute of format `#[ container ]` or `#[ container( definition = former::VectorDefinition ) ]` if you want to use default container defition. \nGot: {}", qt!{ #attr } ), + } + } "debug" => { } @@ -71,8 +88,86 @@ impl StructAttributes } } - Ok( StructAttributes { perform, storage_fields } ) + Ok( StructAttributes { perform, storage_fields, mutator } ) + } + + + /// + /// Generate parts, used for generating `perform()`` method. + /// + /// Similar to `form()`, but will also invoke function from `perform` attribute, if specified. + /// + /// # Example of returned tokens : + /// + /// ## perform : + /// return result; + /// + /// ## perform_output : + /// < T : ::core::default::Default > + /// + /// ## perform_generics : + /// Vec< T > + /// + + pub fn performer( &self ) + -> Result< ( TokenStream, TokenStream, TokenStream ) > + { + + let mut perform = qt! + { + return result; + }; + let mut perform_output = qt!{ Definition::Formed }; + let mut perform_generics = qt!{}; + + if let Some( ref attr ) = self.perform + { + + // let attr_perform = syn::parse2::< AttributePerform >( meta_list.tokens.clone() )?; + let signature = &attr.signature; + let generics = &signature.generics; + perform_generics = qt!{ #generics }; + let perform_ident = &signature.ident; + let output = &signature.output; + if let syn::ReturnType::Type( _, boxed_type ) = output + { + perform_output = qt!{ #boxed_type }; + } + perform = qt! + { + return result.#perform_ident(); + }; + + } + + Ok( ( perform, perform_output, perform_generics ) ) } + + /// Returns an iterator over the fields defined in the `storage_fields` attribute. + /// + /// This function provides an iterator that yields `syn::Field` objects. If `storage_fields` is set, + /// it clones and iterates over its fields. If `storage_fields` is `None`, it returns an empty iterator. + /// + + // pub fn storage_fields( &self ) -> impl Iterator< Item = syn::Field > + pub fn storage_fields( &self ) -> &syn::punctuated::Punctuated< syn::Field, syn::token::Comma > + { + + self.storage_fields.as_ref().map_or_else( + || &*Box::leak( Box::new( syn::punctuated::Punctuated::new() ) ), + | attr | &attr.fields + ) + // xxx : investigate + + // self.storage_fields + // .as_ref() + // .map_or_else( + // || syn::punctuated::Punctuated::< syn::Field, syn::token::Comma >::new().into_iter(), + // | attr | attr.fields.clone().into_iter() + // // Clone and create an iterator when storage_fields is Some + // ) + } + } /// @@ -132,117 +227,63 @@ impl syn::parse::Parse for AttributeStorageFields } } - -// - -/// -/// Generate parts, used for generating `perform()`` method. +/// xxx : update documentation /// -/// Similar to `form()`, but will also invoke function from `perform` attribute, if specified. +/// Customize mutator making possible to write custom mutator and get hint with sketch of mutator. /// -/// # Example of returned tokens : +/// The `FormerMutator` trait allows for the implementation of custom mutation logic on the internal state +/// of an entity (context and storage) just before the final forming operation is completed. This mutation +/// occurs immediately before the `FormingEnd` callback is invoked. /// -/// ## perform : -/// return result; +/// ## Differences from `FormingEnd` /// -/// ## perform_output : -/// < T : ::core::default::Default > +/// Unlike `FormingEnd`, which is responsible for integrating and finalizing the formation process of a field within +/// a parent former, `form_mutation` directly pertains to the entity itself. This method is designed to be independent +/// of whether the forming process is occurring within the context of a superformer or if the structure is a standalone +/// or nested field. This makes `form_mutation` suitable for entity-specific transformations that should not interfere +/// with the hierarchical forming logic managed by `FormingEnd`. /// -/// ## perform_generics : -/// Vec< T > -/// - -impl StructAttributes +#[ derive( Debug, Default ) ] +pub struct AttributeMutator { + /// Disable generation of mutator. Optional and `false` by default. + pub custom : bool, + /// Get hint with sketch of mutator. Optional and `false` by default. + pub hint : bool, +} - pub fn performer( &self ) - -> Result< ( TokenStream, TokenStream, TokenStream ) > - { - - let mut perform = qt! - { - return result; - }; - let mut perform_output = qt!{ Definition::Formed }; - let mut perform_generics = qt!{}; - - if let Some( ref attr ) = self.perform - { - - // let attr_perform = syn::parse2::< AttributePerform >( meta_list.tokens.clone() )?; - let signature = &attr.signature; - let generics = &signature.generics; - perform_generics = qt!{ #generics }; - let perform_ident = &signature.ident; - let output = &signature.output; - if let syn::ReturnType::Type( _, boxed_type ) = output - { - perform_output = qt!{ #boxed_type }; - } - perform = qt! - { - return result.#perform_ident(); - }; +impl syn::parse::Parse for AttributeMutator { + fn parse(input: syn::parse::ParseStream<'_>) -> syn::Result { + let mut custom = None; + let mut hint = None; + + while !input.is_empty() { + let lookahead = input.lookahead1(); + if lookahead.peek(syn::Ident) { + let ident: syn::Ident = input.parse()?; + input.parse::()?; + if ident == "custom" { + let value: syn::LitBool = input.parse()?; + custom = Some(value.value); + } else if ident == "hint" { + let value: syn::LitBool = input.parse()?; + hint = Some(value.value); + } else { + return Err(syn::Error::new_spanned(&ident, format!("Unexpected identifier '{}'. Expected 'custom' or 'hint'.", ident))); + } + } else { + return Err(lookahead.error()); + } + + // Optional comma handling + if input.peek(syn::Token![,]) { + input.parse::()?; + } + } + Ok(Self { + custom: custom.unwrap_or(false), + hint: hint.unwrap_or(false), + }) } - - Ok( ( perform, perform_output, perform_generics ) ) - } - - /// Returns an iterator over the fields defined in the `storage_fields` attribute. - /// - /// This function provides an iterator that yields `syn::Field` objects. If `storage_fields` is set, - /// it clones and iterates over its fields. If `storage_fields` is `None`, it returns an empty iterator. - /// - - // pub fn storage_fields( &self ) -> impl Iterator< Item = syn::Field > - pub fn storage_fields( &self ) -> &syn::punctuated::Punctuated< syn::Field, syn::token::Comma > - { - - self.storage_fields.as_ref().map_or_else( - || &*Box::leak(Box::new(syn::punctuated::Punctuated::new())), - |attr| &attr.fields - ) - // xxx : investigate - - // self.storage_fields - // .as_ref() - // .map_or_else( - // || syn::punctuated::Punctuated::< syn::Field, syn::token::Comma >::new().into_iter(), - // | attr | attr.fields.clone().into_iter() - // // Clone and create an iterator when storage_fields is Some - // ) - } - -// /// Generates a `TokenStream` for the fields specified in `storage_fields`. -// /// -// /// This function constructs a token stream for code generation, incorporating fields from the -// /// `storage_fields` attribute into the generated Rust code. If `storage_fields` is set, it includes -// /// its fields in the output; otherwise, it returns an empty token stream. -// /// -// /// # Example of generated code -// /// -// /// ```rust, ignore -// /// field1 : i32, -// /// field2 : String, -// /// ``` -// /// -// -// pub fn storage_fields_code( &self ) -// -> Result< TokenStream > -// { -// -// let mut result = qt! -// { -// }; -// -// if let Some( ref attr ) = self.storage_fields -// { -// let storage_fields = &attr.fields; -// result = qt! { #storage_fields } -// } -// -// Ok( result ) -// } - -} +} \ No newline at end of file From 8647239fb31afdf8ccd3fefc30b5f76868bc181d Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 18:50:44 +0300 Subject: [PATCH 438/533] former : experimenting --- .../src/derive_former/struct_attrs.rs | 80 +++++++++++-------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs index cfc8521573..6abe870ef3 100644 --- a/module/core/former_meta/src/derive_former/struct_attrs.rs +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -70,12 +70,11 @@ impl StructAttributes syn::Meta::List( ref meta_list ) => { mutator = syn::parse2::< AttributeMutator >( meta_list.tokens.clone() )? - // container.replace( syn::parse2::< AttributeMutator >( meta_list.tokens.clone() )? ); }, syn::Meta::Path( ref _path ) => { }, - _ => return_syn_err!( attr, "Expects an attribute of format `#[ container ]` or `#[ container( definition = former::VectorDefinition ) ]` if you want to use default container defition. \nGot: {}", qt!{ #attr } ), + _ => return_syn_err!( attr, "Expects an attribute of format `#[ mutator( custom = true, hint = true ) ]`. \nGot: {}", qt!{ #attr } ), } } "debug" => @@ -252,38 +251,51 @@ pub struct AttributeMutator pub hint : bool, } -impl syn::parse::Parse for AttributeMutator { - fn parse(input: syn::parse::ParseStream<'_>) -> syn::Result { - let mut custom = None; - let mut hint = None; - - while !input.is_empty() { - let lookahead = input.lookahead1(); - if lookahead.peek(syn::Ident) { - let ident: syn::Ident = input.parse()?; - input.parse::()?; - if ident == "custom" { - let value: syn::LitBool = input.parse()?; - custom = Some(value.value); - } else if ident == "hint" { - let value: syn::LitBool = input.parse()?; - hint = Some(value.value); - } else { - return Err(syn::Error::new_spanned(&ident, format!("Unexpected identifier '{}'. Expected 'custom' or 'hint'.", ident))); - } - } else { - return Err(lookahead.error()); - } - - // Optional comma handling - if input.peek(syn::Token![,]) { - input.parse::()?; - } +impl syn::parse::Parse for AttributeMutator +{ + fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > + { + let mut custom = false; + let mut hint = false; + + while !input.is_empty() + { + let lookahead = input.lookahead1(); + if lookahead.peek( syn::Ident ) + { + let ident : syn::Ident = input.parse()?; + input.parse::< syn::Token![=] >()?; + if ident == "custom" + { + let value : syn::LitBool = input.parse()?; + custom = value.value; + } + else if ident == "hint" + { + let value : syn::LitBool = input.parse()?; + hint = value.value; + } + else + { + return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'custom' or 'hint'.", ident ) ) ); } + } + else + { + return Err( lookahead.error() ); + } - Ok(Self { - custom: custom.unwrap_or(false), - hint: hint.unwrap_or(false), - }) + // Optional comma handling + if input.peek( syn::Token![,] ) + { + input.parse::< syn::Token![,] >()?; + } } -} \ No newline at end of file + + Ok( Self + { + custom, + hint, + }) + } +} From 7a29564291b18db64f2e2e59e8269582d1b901d6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 19:00:44 +0300 Subject: [PATCH 439/533] former : experimenting --- ...itive.rs => attribute_storage_with_end.rs} | 0 .../attribute_storage_with_mutator.rs | 106 ++++++++++++++++++ module/core/former/tests/inc/mod.rs | 3 +- module/core/former_meta/src/derive_former.rs | 10 +- module/core/former_meta/src/lib.rs | 2 +- 5 files changed, 116 insertions(+), 5 deletions(-) rename module/core/former/tests/inc/former_tests/{attribute_storage_primitive.rs => attribute_storage_with_end.rs} (100%) create mode 100644 module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs b/module/core/former/tests/inc/former_tests/attribute_storage_with_end.rs similarity index 100% rename from module/core/former/tests/inc/former_tests/attribute_storage_primitive.rs rename to module/core/former/tests/inc/former_tests/attribute_storage_with_end.rs diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs new file mode 100644 index 0000000000..61cd37cfa3 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs @@ -0,0 +1,106 @@ +#[ allow( unused_imports ) ] +use super::*; + +// xxx2 : finish + +#[ derive( Debug, PartialEq, the_module::Former ) ] +#[ storage_fields( a : i32, b : Option< String > ) ] +#[ mutator( custom = true, hint = true ) ] +// #[ debug ] +// #[ derive( Debug, PartialEq ) ] +pub struct Struct1 +{ + c : String, +} + +// = former mutator + +impl< Context, Formed > former::FormerMutator +for Struct1FormerDefinitionTypes< Context, Formed > +{ +} + +// pub struct Struct1CustomEnd +// { +// _phantom : core::marker::PhantomData< ( (), ) >, +// } +// +// // impl< Definition > Default for Struct1CustomEnd< Definition > +// impl Default for Struct1CustomEnd +// { +// +// #[ inline( always ) ] +// fn default() -> Self +// { +// Self +// { +// _phantom : core::marker::PhantomData, +// } +// } +// +// } +// +// #[ automatically_derived ] +// impl< Context, > former::FormingEnd +// < +// Struct1FormerDefinitionTypes< Context, Struct1 > +// > +// for Struct1CustomEnd +// { +// #[ inline( always ) ] +// fn call +// ( +// &self, +// storage : Struct1FormerStorage, +// super_former : Option< Context >, +// ) +// -> Struct1 +// { +// let a = if let Some( a ) = storage.a +// { +// a +// } +// else +// { +// Default::default() +// }; +// let b = if let Some( b ) = storage.b +// { +// b +// } +// else +// { +// Default::default() +// }; +// Struct1 { c : format!( "{:?} - {}", a, b ) } +// } +// } + +// == begin of generated + +// == end of generated + +tests_impls! +{ + + fn test_complex() + { + // // let got = Struct1::former().a( 13 ).b( "abc" ).c( "def" ).form(); + // let end = Struct1CustomEnd::default(); + // let got = Struct1Former + // ::< Struct1FormerDefinition< (), Struct1, _ > > + // ::new( end ) + // .a( 13 ).b( "abc" ).c( "def" ).form(); + // let exp = Struct1 + // { + // c : "13 - abc".to_string(), + // }; + // a_id!( got, exp ); + } + +} + +tests_index! +{ + test_complex, +} diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 75eb65ae8f..253648f435 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -30,7 +30,8 @@ mod former_tests mod attribute_default_container; mod attribute_default_primitive; mod attribute_default_conflict; - mod attribute_storage_primitive; + mod attribute_storage_with_end; + mod attribute_storage_with_mutator; mod attribute_perform; mod attribute_setter; mod attribute_alias; diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 0de07ea245..3895be314b 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -273,12 +273,16 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > r#" = Example of custom mutator -impl< {former_definition_types_generics_impl:?} > former::FormerMutator -for {former_definition_types} < {former_definition_types_generics_ty:?} > +impl< {} > former::FormerMutator +for {} < {} > where - {former_definition_types_generics_where:?} + {} {} "#, + format!( "{}", qt!{ #former_definition_types_generics_impl } ), + former_definition_types, + format!( "{}", qt!{ #former_definition_types_generics_ty } ), + format!( "{}", qt!{ #former_definition_types_generics_where } ), "{\n}" ); println!( "{hint}" ); diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index 4237eb7a08..eff1761cd9 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -282,7 +282,7 @@ mod derive_former; Former, attributes ( - debug, perform, storage_fields, // struct attributes + debug, perform, storage_fields, mutator, // struct attributes former, scalar, container, subform, // field attributes ) ) From 8e0f50eee2bcc4f337a93cf08c2ab631e89d218a Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 19:07:29 +0300 Subject: [PATCH 440/533] former : experimenting --- .../attribute_storage_with_mutator.rs | 5 ++++ module/core/former_meta/src/derive_former.rs | 21 +++++++++----- .../src/derive_former/struct_attrs.rs | 29 +++++++++---------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs index 61cd37cfa3..0bb36691c7 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs @@ -18,6 +18,11 @@ pub struct Struct1 impl< Context, Formed > former::FormerMutator for Struct1FormerDefinitionTypes< Context, Formed > { + /// Mutates the context and storage of the entity just before the formation process completes. + #[ inline ] + fn form_mutation( _storage : &mut Self::Storage, _context : &mut ::core::option::Option< Self::Context > ) + { + } } // pub struct Struct1CustomEnd diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 3895be314b..dc598c93a5 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -270,20 +270,25 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { let hint = format! ( - r#" + r#" = Example of custom mutator impl< {} > former::FormerMutator for {} < {} > where {} -{} - "#, - format!( "{}", qt!{ #former_definition_types_generics_impl } ), - former_definition_types, - format!( "{}", qt!{ #former_definition_types_generics_ty } ), - format!( "{}", qt!{ #former_definition_types_generics_where } ), - "{\n}" +{{ + /// Mutates the context and storage of the entity just before the formation process completes. + #[ inline ] + fn form_mutation( storage : &mut Self::Storage, context : &mut Option< Self::Context > ) + {{ + }} +}} + "#, + format!( "{}", qt!{ #former_definition_types_generics_impl } ), + former_definition_types, + format!( "{}", qt!{ #former_definition_types_generics_ty } ), + format!( "{}", qt!{ #former_definition_types_generics_where } ), ); println!( "{hint}" ); }; diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs index 6abe870ef3..6642088dfe 100644 --- a/module/core/former_meta/src/derive_former/struct_attrs.rs +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -226,28 +226,25 @@ impl syn::parse::Parse for AttributeStorageFields } } -/// xxx : update documentation +/// Represents attributes for customizing the mutation process in a forming operation. /// -/// Customize mutator making possible to write custom mutator and get hint with sketch of mutator. -/// -/// The `FormerMutator` trait allows for the implementation of custom mutation logic on the internal state -/// of an entity (context and storage) just before the final forming operation is completed. This mutation -/// occurs immediately before the `FormingEnd` callback is invoked. -/// -/// ## Differences from `FormingEnd` -/// -/// Unlike `FormingEnd`, which is responsible for integrating and finalizing the formation process of a field within -/// a parent former, `form_mutation` directly pertains to the entity itself. This method is designed to be independent -/// of whether the forming process is occurring within the context of a superformer or if the structure is a standalone -/// or nested field. This makes `form_mutation` suitable for entity-specific transformations that should not interfere -/// with the hierarchical forming logic managed by `FormingEnd`. +/// `AttributeMutator` allows specifying whether a custom mutator should be used or a sketch should be provided +/// as a hint for developing a custom mutator. This is crucial for advanced scenarios where the entity's state +/// might require conditional modifications which are not handled by the standard `FormingEnd`. /// +/// ## Example of code +/// ```ignore +/// custom = true, hint = true +/// ``` + #[ derive( Debug, Default ) ] pub struct AttributeMutator { - /// Disable generation of mutator. Optional and `false` by default. + /// Indicates whether a custom mutator should be generated. + /// Defaults to `false`, meaning no custom mutator is generated unless explicitly requested. pub custom : bool, - /// Get hint with sketch of mutator. Optional and `false` by default. + /// Specifies whether to provide a sketch of the mutator as a hint. + /// Defaults to `false`, which means no hint is provided unless explicitly requested. pub hint : bool, } From abefe482533d0977f231618d6391a85087b2adb3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 19:27:25 +0300 Subject: [PATCH 441/533] former : experimenting --- .../attribute_storage_with_mutator.rs | 22 +++++++++---------- module/core/former_meta/src/derive_former.rs | 5 ++--- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs index 0bb36691c7..a21f68c6a3 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs @@ -20,8 +20,11 @@ for Struct1FormerDefinitionTypes< Context, Formed > { /// Mutates the context and storage of the entity just before the formation process completes. #[ inline ] - fn form_mutation( _storage : &mut Self::Storage, _context : &mut ::core::option::Option< Self::Context > ) + fn form_mutation( storage : &mut Self::Storage, _context : &mut ::core::option::Option< Self::Context > ) { + storage.a.get_or_insert_with( Default::default ); + storage.b.get_or_insert_with( Default::default ); + storage.c = Some( format!( "{:?} - {}", storage.a.unwrap(), storage.b.as_ref().unwrap() ) ); } } @@ -90,17 +93,12 @@ tests_impls! fn test_complex() { - // // let got = Struct1::former().a( 13 ).b( "abc" ).c( "def" ).form(); - // let end = Struct1CustomEnd::default(); - // let got = Struct1Former - // ::< Struct1FormerDefinition< (), Struct1, _ > > - // ::new( end ) - // .a( 13 ).b( "abc" ).c( "def" ).form(); - // let exp = Struct1 - // { - // c : "13 - abc".to_string(), - // }; - // a_id!( got, exp ); + let got = Struct1::former().a( 13 ).b( "abc" ).c( "def" ).form(); + let exp = Struct1 + { + c : "13 - abc".to_string(), + }; + a_id!( got, exp ); } } diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index dc598c93a5..c3e49d4a04 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -599,9 +599,8 @@ where pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - // < Definition::Types as former::FormerMutator >::form_mutation( &mut self.storage, &mut context ); - // xxx + let mut context = self.context.take(); + < Definition::Types as former::FormerMutator >::form_mutation( &mut self.storage, &mut context ); former::FormingEnd::< Definition::Types >::call( &on_end, self.storage, context ) } From cb1ed9c323318ce2d930da25431086d46fdeb35c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 19:29:16 +0300 Subject: [PATCH 442/533] former : experimenting --- .../tests/inc/former_tests/a_basic_manual.rs | 8 --- .../attribute_storage_with_mutator.rs | 58 ------------------- 2 files changed, 66 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index ad872c3afc..4af5c24b5f 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -27,14 +27,6 @@ impl Struct1 // = entity to former -// impl former::EntityToFormer_ for Struct1 -// where -// Self : Sized, -// { -// type Storage = Struct1FormerStorage; -// type Former = Struct1Former; -// } - impl< Definition > former::EntityToFormer< Definition > for Struct1 where Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs index a21f68c6a3..6169f479ca 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs @@ -1,8 +1,6 @@ #[ allow( unused_imports ) ] use super::*; -// xxx2 : finish - #[ derive( Debug, PartialEq, the_module::Former ) ] #[ storage_fields( a : i32, b : Option< String > ) ] #[ mutator( custom = true, hint = true ) ] @@ -28,62 +26,6 @@ for Struct1FormerDefinitionTypes< Context, Formed > } } -// pub struct Struct1CustomEnd -// { -// _phantom : core::marker::PhantomData< ( (), ) >, -// } -// -// // impl< Definition > Default for Struct1CustomEnd< Definition > -// impl Default for Struct1CustomEnd -// { -// -// #[ inline( always ) ] -// fn default() -> Self -// { -// Self -// { -// _phantom : core::marker::PhantomData, -// } -// } -// -// } -// -// #[ automatically_derived ] -// impl< Context, > former::FormingEnd -// < -// Struct1FormerDefinitionTypes< Context, Struct1 > -// > -// for Struct1CustomEnd -// { -// #[ inline( always ) ] -// fn call -// ( -// &self, -// storage : Struct1FormerStorage, -// super_former : Option< Context >, -// ) -// -> Struct1 -// { -// let a = if let Some( a ) = storage.a -// { -// a -// } -// else -// { -// Default::default() -// }; -// let b = if let Some( b ) = storage.b -// { -// b -// } -// else -// { -// Default::default() -// }; -// Struct1 { c : format!( "{:?} - {}", a, b ) } -// } -// } - // == begin of generated // == end of generated From 489ed169975cd491e34cb1393de41bf165be8568 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 19:34:52 +0300 Subject: [PATCH 443/533] former : experimenting --- .../attribute_storage_with_mutator.rs | 2 +- module/core/former_meta/src/derive_former.rs | 27 ------------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs index 6169f479ca..57936294d3 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs @@ -3,7 +3,7 @@ use super::*; #[ derive( Debug, PartialEq, the_module::Former ) ] #[ storage_fields( a : i32, b : Option< String > ) ] -#[ mutator( custom = true, hint = true ) ] +#[ mutator( custom = true ) ] // #[ debug ] // #[ derive( Debug, PartialEq ) ] pub struct Struct1 diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index c3e49d4a04..b3e28bb8ba 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -118,7 +118,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where Definition : former::FormerDefinition< Storage = #former_storage < #struct_generics_ty > >, Definition::Types : former::FormerDefinitionTypes< Storage = #former_storage < #struct_generics_ty > >, - // < Definition as former::FormerDefinition >::Types : former::FormerMutator, }; let extra = generic_params::merge( &generics, &extra.into() ); @@ -141,7 +140,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > Storage = #former_storage < #struct_generics_ty >, Formed = #stru < #struct_generics_ty >, >, - // < Definition as former::FormerDefinition >::Types : former::FormerMutator, }; let extra = generic_params::merge( &generics, &extra.into() ); @@ -191,8 +189,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > .collect(); let formed_fields : Vec< _ > = process_results( formed_fields, | iter | iter.collect() )?; - // xxx - let storage_fields : Vec< Result< FormerField< '_ > > > = struct_attrs .storage_fields() .iter() @@ -322,7 +318,6 @@ where for #stru < #struct_generics_ty > where Definition : former::FormerDefinition< Storage = #former_storage < #struct_generics_ty > >, - // < Definition as former::FormerDefinition >::Types : former::FormerMutator, #struct_generics_where { type Former = #former < #struct_generics_ty Definition > ; @@ -660,7 +655,6 @@ where > where Definition : former::FormerDefinition< Storage = #former_storage < #struct_generics_ty > >, - // < Definition as former::FormerDefinition >::Types : former::FormerMutator, #struct_generics_where { @@ -740,26 +734,5 @@ where diag::debug_report_print( "derive : Former", original_input, &result ); } - // zzz : implement hints, rewrite - if example_of_custom_setter - { - let _example = -r#" -impl< Context, End > UserProfileFormer< Context, End > -where - End : former::FormingEnd< UserProfile, Context >, -{ - pub fn age< Src >( mut self, src : Src ) -> Self - where - Src : Into< i32 >, - { - debug_assert!( self.age.is_none() ); - self.storage.age = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); - self - } -} -"#; - } - Ok( result ) } From f6c59c2995bf260b5152c5d9fddc2561807ac904 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 19:50:19 +0300 Subject: [PATCH 444/533] former : experimenting --- ...mer.rs => former_custom_subform_setter.rs} | 7 ++-- .../attribute_storage_with_end.rs | 2 -- .../attribute_storage_with_mutator.rs | 2 ++ module/core/former_meta/src/derive_former.rs | 4 --- .../src/derive_former/field_attrs.rs | 36 +++++++++++++++++-- 5 files changed, 38 insertions(+), 13 deletions(-) rename module/core/former/examples/{former_custom_subformer.rs => former_custom_subform_setter.rs} (97%) diff --git a/module/core/former/examples/former_custom_subformer.rs b/module/core/former/examples/former_custom_subform_setter.rs similarity index 97% rename from module/core/former/examples/former_custom_subformer.rs rename to module/core/former/examples/former_custom_subform_setter.rs index 1daf9d0d32..676f3cd78b 100644 --- a/module/core/former/examples/former_custom_subformer.rs +++ b/module/core/former/examples/former_custom_subform_setter.rs @@ -26,7 +26,7 @@ fn main() // Child struct with Former derived for builder pattern support #[ derive( Debug, PartialEq, Former ) ] - #[ debug ] + // #[ debug ] pub struct Child { name : String, @@ -35,10 +35,10 @@ fn main() // Parent struct to hold children #[ derive( Debug, PartialEq, Former ) ] - #[ debug ] + // #[ debug ] pub struct Parent { - #[ subform( setter = false ) ] + #[ subform( setter = false, hint = false ) ] child : HashMap< String, Child >, } @@ -90,4 +90,3 @@ fn main() // > }, // > } } - diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_with_end.rs b/module/core/former/tests/inc/former_tests/attribute_storage_with_end.rs index 21dbc7e52f..57d5f5f7da 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_with_end.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_with_end.rs @@ -1,8 +1,6 @@ #[ allow( unused_imports ) ] use super::*; -// xxx2 : finish - #[ derive( Debug, PartialEq, the_module::Former ) ] #[ storage_fields( a : i32, b : Option< String > ) ] // #[ debug ] diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs index 57936294d3..bf16186849 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs @@ -1,6 +1,8 @@ #[ allow( unused_imports ) ] use super::*; +// xxx : write example + #[ derive( Debug, PartialEq, the_module::Former ) ] #[ storage_fields( a : i32, b : Option< String > ) ] #[ mutator( custom = true ) ] diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index b3e28bb8ba..b5b1e45d32 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -5,7 +5,6 @@ use macro_tools::{ attr, diag, generic_params, generic_args, typ, derive, Result use proc_macro2::TokenStream; // zzz : explain concept of Storage -// xxx : feature to have storage fields // xxx : introduce namespaces // zzz : qqq : implement interfaces for other containers @@ -75,8 +74,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let has_debug = attr::has_debug( ast.attrs.iter() )?; let struct_attrs = StructAttributes::from_attrs( ast.attrs.iter() )?; - let example_of_custom_setter = false; - /* names */ let stru = &ast.ident; @@ -439,7 +436,6 @@ where #struct_generics_where { - // xxx #[ inline( always ) ] fn default() -> Self { diff --git a/module/core/former_meta/src/derive_former/field_attrs.rs b/module/core/former_meta/src/derive_former/field_attrs.rs index ded145de80..a19a98a2f3 100644 --- a/module/core/former_meta/src/derive_former/field_attrs.rs +++ b/module/core/former_meta/src/derive_former/field_attrs.rs @@ -183,6 +183,9 @@ pub struct AttributeScalarSetter pub name : Option< syn::Ident >, /// Controls the generation of a setter method. If false, a setter method is not generated. pub setter : Option< bool >, + /// Specifies whether to provide a sketch of the subform setter as a hint. + /// Defaults to `false`, which means no hint is provided unless explicitly requested. + pub hint : bool, } #[ allow( dead_code ) ] @@ -203,6 +206,7 @@ impl syn::parse::Parse for AttributeScalarSetter { let mut name : Option< syn::Ident > = None; let mut setter : Option< bool > = None; + let mut hint = false; while !input.is_empty() { @@ -221,6 +225,12 @@ impl syn::parse::Parse for AttributeScalarSetter let value : syn::LitBool = input.parse()?; setter = Some( value.value() ); } + else if ident == "hint" + { + input.parse::< syn::Token![ = ] >()?; + let value : syn::LitBool = input.parse()?; + hint = value.value; + } else { return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'name', 'setter', or 'definition'. For example: `scalar( name = myName, setter = true )`", ident ) ) ); @@ -238,7 +248,7 @@ impl syn::parse::Parse for AttributeScalarSetter } } - Ok( Self { name, setter } ) + Ok( Self { name, setter, hint } ) } } @@ -263,6 +273,9 @@ pub struct AttributeContainerSetter pub setter : Option< bool >, /// Definition of the container former to use, e.g., `former::VectorSubformer`. pub definition : Option< syn::Type >, + /// Specifies whether to provide a sketch of the subform setter as a hint. + /// Defaults to `false`, which means no hint is provided unless explicitly requested. + pub hint : bool, } impl AttributeContainerSetter @@ -282,6 +295,7 @@ impl syn::parse::Parse for AttributeContainerSetter { let mut name : Option< syn::Ident > = None; let mut setter : Option< bool > = None; // Default is to generate a setter + let mut hint = false; let mut definition : Option< syn::Type > = None; while !input.is_empty() @@ -301,6 +315,12 @@ impl syn::parse::Parse for AttributeContainerSetter let value : syn::LitBool = input.parse()?; setter = Some( value.value ); } + else if ident == "hint" + { + input.parse::< syn::Token![ = ] >()?; + let value : syn::LitBool = input.parse()?; + hint = value.value; + } else if ident == "definition" { input.parse::< syn::Token![ = ] >()?; @@ -323,7 +343,7 @@ impl syn::parse::Parse for AttributeContainerSetter } } - Ok( Self { name, setter, definition } ) + Ok( Self { name, setter, hint, definition } ) } } @@ -353,6 +373,9 @@ pub struct AttributeSubformSetter /// Disable generation of setter. /// It still generate `_field_add` method, so it could be used to make a setter with custom arguments. pub setter : Option< bool >, + /// Specifies whether to provide a sketch of the subform setter as a hint. + /// Defaults to `false`, which means no hint is provided unless explicitly requested. + pub hint : bool, } impl AttributeSubformSetter @@ -372,6 +395,7 @@ impl syn::parse::Parse for AttributeSubformSetter { let mut name : Option< syn::Ident > = None; let mut setter : Option< bool > = None; + let mut hint = false; while !input.is_empty() { @@ -390,6 +414,12 @@ impl syn::parse::Parse for AttributeSubformSetter let value : syn::LitBool = input.parse()?; setter = Some( value.value() ); } + else if ident == "hint" + { + input.parse::< syn::Token![ = ] >()?; + let value : syn::LitBool = input.parse()?; + hint = value.value; + } else { return Err( syn::Error::new_spanned( &ident, format!( "Unexpected identifier '{}'. Expected 'name', 'setter', or 'definition'. For example: `subform( name = myName, setter = true )`", ident ) ) ); @@ -407,6 +437,6 @@ impl syn::parse::Parse for AttributeSubformSetter } } - Ok( Self { name, setter } ) + Ok( Self { name, setter, hint } ) } } From c254de7d39f4419dcc70325be1ecaf1965a5deb8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 20:14:58 +0300 Subject: [PATCH 445/533] former : experimenting --- .../examples/former_custom_subform_setter.rs | 8 ++- module/core/former_meta/src/derive_former.rs | 11 +++- .../former_meta/src/derive_former/field.rs | 53 ++++++++++++++++++- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/module/core/former/examples/former_custom_subform_setter.rs b/module/core/former/examples/former_custom_subform_setter.rs index 676f3cd78b..70dd19cfdd 100644 --- a/module/core/former/examples/former_custom_subform_setter.rs +++ b/module/core/former/examples/former_custom_subform_setter.rs @@ -38,11 +38,15 @@ fn main() // #[ debug ] pub struct Parent { - #[ subform( setter = false, hint = false ) ] + #[ subform( setter = false, hint = true ) ] child : HashMap< String, Child >, } - // Use ChildFormer as custom subformer for ParentFormer to add children by name. + /// Initializes and configures a subformer for adding named child entities. This method leverages an internal function + /// to create and return a configured subformer instance. It allows for the dynamic addition of children with specific names, + /// integrating them into the formation process of the parent entity. After creation, the name of the child is immediately set, + /// facilitating the customization and integration of child entities within the overall structure of the parent. + /// impl< Definition > ParentFormer< Definition > where Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index b5b1e45d32..ebcaf19c4a 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -217,7 +217,14 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field.storage_field_optional(), field.storage_field_name(), field.storage_field_preform(), - field.former_field_setter( &stru ), + field.former_field_setter + ( + &stru, + &former, + &former_storage, + // &as_subformer, + // &as_subformer_end, + ), field.former_field_assign_end ( &stru, @@ -263,7 +270,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { let hint = format! ( - r#" +r#" = Example of custom mutator impl< {} > former::FormerMutator diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index df7de1f601..6a9b4ac493 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -343,6 +343,10 @@ scalar_setter_required ( &self, stru : &syn::Ident, + former : &syn::Ident, + former_storage : &syn::Ident, + // as_subformer : &syn::Ident, + // as_subformer_end : &syn::Ident, ) -> Result< TokenStream > { @@ -381,7 +385,14 @@ scalar_setter_required // subform setter let r = if self.attrs.subform.is_some() { - let r2 = self.subform_add_setter_map( stru )?; + let r2 = self.subform_add_setter_map + ( + stru, + former, + former_storage, + // as_subformer, + // as_subformer_end, + )?; qt! { #r @@ -403,6 +414,10 @@ scalar_setter_required ( &self, stru : &syn::Ident, + former : &syn::Ident, + former_storage : &syn::Ident, + // as_subformer : &syn::Ident, + // as_subformer_end : &syn::Ident, ) -> Result< TokenStream > { @@ -457,6 +472,42 @@ scalar_setter_required }; + if true + { + let hint = format! + ( +r#" + +/// Initializes and configures a subformer for adding named child entities. This method leverages an internal function +/// to create and return a configured subformer instance. It allows for the dynamic addition of children with specific names, +/// integrating them into the formation process of the parent entity. After creation, the name of the child is immediately set, +/// facilitating the customization and integration of child entities within the overall structure of the parent. +/// + +impl< Definition > {}< Definition > +where + Definition : former::FormerDefinition< Storage = {} >, +{{ + + #[ inline( always ) ] + pub fn {}( self ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + {{ + self.{}::< ChildFormer< _ >, _, >() + }} + +}} + "#, + former, + former_storage, + field_ident, + // as_subformer, + // as_subformer_end, + field_add_name, + ); + println!( "{hint}" ); + } + + // xxx : it should be printed by hint also let r = if attr.setter() { From 8295c1ccf5df21fb0532d832bdf049d2db41302f Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 20:39:00 +0300 Subject: [PATCH 446/533] former : experimenting --- .../former_custom_container_setter.rs | 79 +++++++++ .../examples/former_custom_subform_setter.rs | 28 ++-- .../examples/former_custom_subform_setter2.rs | 153 ++++++++++++++++++ .../former_meta/src/derive_former/field.rs | 2 +- 4 files changed, 248 insertions(+), 14 deletions(-) create mode 100644 module/core/former/examples/former_custom_container_setter.rs create mode 100644 module/core/former/examples/former_custom_subform_setter2.rs diff --git a/module/core/former/examples/former_custom_container_setter.rs b/module/core/former/examples/former_custom_container_setter.rs new file mode 100644 index 0000000000..b320b22811 --- /dev/null +++ b/module/core/former/examples/former_custom_container_setter.rs @@ -0,0 +1,79 @@ +// Example former_custom_container_setter.rs + +//! +//! This example illustrates the implementation of nested builder patterns in Rust using the `Former` trait, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. +//! +//! #### Custom Subform Setter +//! +//! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. +//! +//! #### Subform Setter vs. Container Setter +//! +//! It's important to distinguish between a subform setter and a container setter: +//! - **Subform Setter**: This returns a former of an element within a container, providing an interface to individually form each element. In this example, `child` acts as a subform setter, allowing for the addition and configuration of individual `Child` entities within the `Parent`'s `HashMap`. +//! - **Container Setter**: Conversely, a container setter returns a former of the container itself, offering an interface to manage the container as a whole rather than its individual elements. It would be used if one needed to apply configurations or validations to the entire `HashMap` of children, rather than to individual children. +//! + +// xxx : improve description of this example. container setter unlike subform setter expose interface of container, not element itself + +// zzz : duplicate into readme + +#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +fn main() {} + +// Ensure the example only compiles when the appropriate features are enabled. +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + use std::collections::HashMap; + use former::Former; + + // Child struct with Former derived for builder pattern support + #[ derive( Debug, PartialEq, Former ) ] + // #[ debug ] + pub struct Child + { + name : String, + description : String, + } + + // Parent struct to hold children + #[ derive( Debug, PartialEq, Former ) ] + // #[ debug ] + pub struct Parent + { + #[ container( setter = true, hint = true ) ] + child : HashMap< String, Child >, + } + + // impl former::ValToElement< HashMap< String, Child > > for Child + // { + // type Element = ( String, Child ); + // #[ inline( always ) ] + // fn val_to_element( self ) -> Self::Element + // { + // ( self.name.clone(), self ) + // } + // } + + let ca = Parent::former() + .child() + .add( Child { name : "echo".to_string(), description : "prints all subjects and properties".to_string() } ) + .add( Child { name : "exit".to_string(), description : "just exit".to_string() } ) + .end() + .form(); + + dbg!( &ca ); + // > &ca = Parent { + // > child: { + // > "echo": Child { + // > name: "echo", + // > description: "prints all subjects and properties", + // > }, + // > "exit": Child { + // > name: "exit", + // > description: "just exit", + // > }, + // > }, + // > } +} diff --git a/module/core/former/examples/former_custom_subform_setter.rs b/module/core/former/examples/former_custom_subform_setter.rs index 70dd19cfdd..97aa708538 100644 --- a/module/core/former/examples/former_custom_subform_setter.rs +++ b/module/core/former/examples/former_custom_subform_setter.rs @@ -1,18 +1,20 @@ -// example former_custom_subformer.rs +// Example former_custom_subformer.rs -//! This example demonstrates the use of the `Former` trait to implement nested builder patterns -//! in Rust using a parent-child relationship. The `Parent` struct uses `ChildFormer` as a custom -//! subformer to dynamically construct its `child` field, which is a `HashMap`. Each entry in the -//! `HashMap` represents a child with unique attributes managed through the `ChildFormer`. //! -//! The `child` function in `ParentFormer` is particularly noteworthy as it leverages the -//! `ChildFormer` to add and configure children by their names directly within the builder pattern -//! of the `Parent`. This approach showcases the flexibility of the `former` crate in handling -//! complex nested data structures and providing a clear, fluent interface for object construction. +//! This example illustrates the implementation of nested builder patterns in Rust using the `Former` trait, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. +//! +//! #### Custom Subform Setter +//! +//! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. +//! +//! #### Subform Setter vs. Container Setter +//! +//! It's important to distinguish between a subform setter and a container setter: +//! - **Subform Setter**: This returns a former of an element within a container, providing an interface to individually form each element. In this example, `child` acts as a subform setter, allowing for the addition and configuration of individual `Child` entities within the `Parent`'s `HashMap`. +//! - **Container Setter**: Conversely, a container setter returns a former of the container itself, offering an interface to manage the container as a whole rather than its individual elements. It would be used if one needed to apply configurations or validations to the entire `HashMap` of children, rather than to individual children. +//! -// xxx2 : description is not good enough. it should be made stress that example show how to write custom subform setter. also dedicate a paragraph to explain difference between subform setter which returns former of element of container exposing interface to form an element and container setter which returns container former exposing interface to containet itself, not its element -// xxx2 : finish example former_custom_subformer -// xxx : zzz : implement example former_custom_container +// zzz : duplicate into readme #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] fn main() {} @@ -38,7 +40,7 @@ fn main() // #[ debug ] pub struct Parent { - #[ subform( setter = false, hint = true ) ] + #[ subform( setter = false, hint = false ) ] child : HashMap< String, Child >, } diff --git a/module/core/former/examples/former_custom_subform_setter2.rs b/module/core/former/examples/former_custom_subform_setter2.rs new file mode 100644 index 0000000000..6cb56b1f4e --- /dev/null +++ b/module/core/former/examples/former_custom_subform_setter2.rs @@ -0,0 +1,153 @@ +// Example former_custom_subformer2.rs + +//! +//! This example extends the demonstration of nested builder patterns using the `Former` trait, highlighting a parent-child relationship similar to the `former_custom_subformer.rs`. However, this variant, `former_custom_subformer2.rs`, showcases a more flexible but complex approach to managing the `child` field in the `Parent` struct—a `HashMap` of `Child` entities. Instead of relying on a predefined subformer setter (`_child_add`), this example constructs the subformer logic directly using closures. This method provides greater control over how children are added and managed within the `Parent`. +//! +//! #### Custom Subform Setter +//! +//! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. +//! +//! #### Subform Setter vs. Container Setter +//! +//! It's important to distinguish between a subform setter and a container setter: +//! - **Subform Setter**: This returns a former of an element within a container, providing an interface to individually form each element. In this example, `child` acts as a subform setter, allowing for the addition and configuration of individual `Child` entities within the `Parent`'s `HashMap`. +//! - **Container Setter**: Conversely, a container setter returns a former of the container itself, offering an interface to manage the container as a whole rather than its individual elements. It would be used if one needed to apply configurations or validations to the entire `HashMap` of children, rather than to individual children. +//! + +// zzz : duplicate into readme + +#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +fn main() {} + +// Ensure the example only compiles when the appropriate features are enabled. +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + use std::collections::HashMap; + use former::Former; + + // Child struct with Former derived for builder pattern support + #[ derive( Clone, Debug, PartialEq, Former ) ] + // #[ debug ] + pub struct Child + { + name : String, + description : String, + } + + // Parent struct to hold children + #[ derive( Debug, PartialEq, Former ) ] + // #[ debug ] + pub struct Parent + { + #[ subform( setter = false, hint = false ) ] + child : HashMap< String, Child >, + } + + // Use ChildFormer as custom subformer for ParentFormer to add children by name. + impl< Definition > ParentFormer< Definition > + where + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, + { + + /// Adds a named child entity to the `Parent`'s `child` field using a custom subformer setup. + /// This method simplifies the process of dynamically adding child entities with specified names, + /// providing a basic yet powerful example of custom subformer implementation. + /// + #[ inline( always ) ] + pub fn child1( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + let preformed = former::StoragePreform::preform( substorage ); + + if super_former.storage.child.is_none() + { + super_former.storage.child = Some( Default::default() ); + } + + // add instance to the container + super_former.storage.child.as_mut().unwrap() + .entry( preformed.name.clone() ) + .or_insert( preformed.clone() ); + + super_former + }; + let subformer = ChildAsSubformer::< Self, _ >::begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ); + subformer.name( name ) + } + + /// Dynamically adds named child entities to the `Parent` structure using a custom subformer. + /// Unlike traditional methods that might use predefined setters like `_child_add`, this function + /// explicitly constructs a subformer setup through a closure to provide greater flexibility and control. + /// + #[ inline( always ) ] + pub fn child2( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + { + let on_end = | substorage : ChildFormerStorage, super_former : core::option::Option< Self > | -> Self + { + let mut super_former = super_former.unwrap(); + let preformed = former::StoragePreform::preform( substorage ); + + if super_former.storage.child.is_none() + { + super_former.storage.child = Some( Default::default() ); + } + + // add instance to the container + super_former.storage.child.as_mut().unwrap() + .entry( preformed.name.clone() ) + .or_insert( preformed.clone() ); + + // custom logic to add two instances to the container + super_former.storage.child.as_mut().unwrap() + .entry( format!( "{}_2", preformed.name ) ) + .or_insert( preformed.clone() ); + + super_former + }; + let subformer = ChildAsSubformer::< Self, _ >::begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ); + subformer.name( name ) + } + + } + + impl former::ValToElement< HashMap< String, Child > > for Child + { + type Element = ( String, Child ); + #[ inline( always ) ] + fn val_to_element( self ) -> Self::Element + { + ( self.name.clone(), self ) + } + } + + let ca = Parent::former() + .child1( "echo" ) + .description( "prints all subjects and properties" ) // sets additional properties using custom subformer + .end() + .child2( "exit" ) + .description( "just exit" ) // Sets additional properties using using custom subformer + .end() + .form(); + + dbg!( &ca ); + // > &ca = Parent { + // > child: { + // > "echo": Child { + // > name: "echo", + // > description: "prints all subjects and properties", + // > }, + // > "exit": Child { + // > name: "exit", + // > description: "just exit", + // > }, + // > "exit_2": Child { + // > name: "exit", + // > description: "just exit", + // > }, + // > }, + // > } + +} diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 6a9b4ac493..0c2ed2243b 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -472,7 +472,7 @@ scalar_setter_required }; - if true + if attr.hint { let hint = format! ( From 7115b21a4bfe92423f5105cdf4fd71994221126b Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 21:07:25 +0300 Subject: [PATCH 447/533] former : experimenting --- .../former_custom_container_setter.rs | 39 ++++++++++++------- .../examples/former_custom_subform_setter.rs | 1 + .../examples/former_custom_subform_setter2.rs | 1 + 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/module/core/former/examples/former_custom_container_setter.rs b/module/core/former/examples/former_custom_container_setter.rs index b320b22811..11fb01e6b3 100644 --- a/module/core/former/examples/former_custom_container_setter.rs +++ b/module/core/former/examples/former_custom_container_setter.rs @@ -1,7 +1,7 @@ // Example former_custom_container_setter.rs //! -//! This example illustrates the implementation of nested builder patterns in Rust using the `Former` trait, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. +//! This example demonstrates the use of container setters to manage complex nested data structures with the `Former` trait, focusing on a parent-child relationship structured around a container `HashMap`. Unlike typical builder patterns that add individual elements using subform setters, this example uses a container setter to manage the entire collection of children. //! //! #### Custom Subform Setter //! @@ -42,24 +42,33 @@ fn main() // #[ debug ] pub struct Parent { - #[ container( setter = true, hint = true ) ] - child : HashMap< String, Child >, + #[ container( setter = false, hint = true ) ] + children : HashMap< String, Child >, } - // impl former::ValToElement< HashMap< String, Child > > for Child - // { - // type Element = ( String, Child ); - // #[ inline( always ) ] - // fn val_to_element( self ) -> Self::Element - // { - // ( self.name.clone(), self ) - // } - // } + impl< Definition, > ParentFormer< Definition, > + where + Definition : former::FormerDefinition< Storage = ParentFormerStorage >, + { + + #[ inline( always ) ] + pub fn children( self ) -> former::ContainerSubformer:: + < + ( String, Child ), + former::HashMapDefinition< String, Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > + > + { + self._children_assign() + } + + } + let echo = Child { name : "echo".to_string(), description : "prints all subjects and properties".to_string() }; + let exit = Child { name : "exit".to_string(), description : "just exit".to_string() }; let ca = Parent::former() - .child() - .add( Child { name : "echo".to_string(), description : "prints all subjects and properties".to_string() } ) - .add( Child { name : "exit".to_string(), description : "just exit".to_string() } ) + .children() + .add( ( echo.name.clone(), echo ) ) + .add( ( exit.name.clone(), exit ) ) .end() .form(); diff --git a/module/core/former/examples/former_custom_subform_setter.rs b/module/core/former/examples/former_custom_subform_setter.rs index 97aa708538..f43b15e1a0 100644 --- a/module/core/former/examples/former_custom_subform_setter.rs +++ b/module/core/former/examples/former_custom_subform_setter.rs @@ -63,6 +63,7 @@ fn main() } + // Requored to define how `value` is converted into pair `( key, value )` impl former::ValToElement< HashMap< String, Child > > for Child { type Element = ( String, Child ); diff --git a/module/core/former/examples/former_custom_subform_setter2.rs b/module/core/former/examples/former_custom_subform_setter2.rs index 6cb56b1f4e..f3e2bb3af3 100644 --- a/module/core/former/examples/former_custom_subform_setter2.rs +++ b/module/core/former/examples/former_custom_subform_setter2.rs @@ -113,6 +113,7 @@ fn main() } + // Requored to define how `value` is converted into pair `( key, value )` impl former::ValToElement< HashMap< String, Child > > for Child { type Element = ( String, Child ); From 05686e89db070fae54faae7ecb0d07d824575e72 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 21:26:40 +0300 Subject: [PATCH 448/533] former : experimenting --- .../former_custom_container_setter.rs | 5 +- .../subformer_container_manual.rs | 4 +- .../subformer_container_setter_off.rs | 2 +- .../subformer_container_setter_on.rs | 2 +- module/core/former_meta/src/derive_former.rs | 2 +- .../former_meta/src/derive_former/field.rs | 63 +++++++++++++++---- 6 files changed, 59 insertions(+), 19 deletions(-) diff --git a/module/core/former/examples/former_custom_container_setter.rs b/module/core/former/examples/former_custom_container_setter.rs index 11fb01e6b3..0537d0df02 100644 --- a/module/core/former/examples/former_custom_container_setter.rs +++ b/module/core/former/examples/former_custom_container_setter.rs @@ -14,8 +14,6 @@ //! - **Container Setter**: Conversely, a container setter returns a former of the container itself, offering an interface to manage the container as a whole rather than its individual elements. It would be used if one needed to apply configurations or validations to the entire `HashMap` of children, rather than to individual children. //! -// xxx : improve description of this example. container setter unlike subform setter expose interface of container, not element itself - // zzz : duplicate into readme #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] @@ -46,6 +44,7 @@ fn main() children : HashMap< String, Child >, } + /// The containr setter provides a container setter that returns a ContainerSubformer tailored for managing a collection of child entities. It employs a generic container definition to facilitate operations on the entire collection, such as adding or updating elements. impl< Definition, > ParentFormer< Definition, > where Definition : former::FormerDefinition< Storage = ParentFormerStorage >, @@ -58,7 +57,7 @@ fn main() former::HashMapDefinition< String, Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > { - self._children_assign() + self._children_container_former() } } diff --git a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs index b73a4bd65f..a198a485fc 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs @@ -30,7 +30,7 @@ where { #[ inline( always ) ] - pub fn _children_assign< Former2 >( self ) -> Former2 + pub fn _children_container_former< Former2 >( self ) -> Former2 where Former2 : former::FormerBegin< former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > >, { @@ -44,7 +44,7 @@ where former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > { - self._children_assign::< former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > >() + self._children_container_former::< former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > >() } } diff --git a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs index 058875a48d..216aaa0afb 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs @@ -43,7 +43,7 @@ where former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > { - self._children_assign::< _ >() + self._children_container_former::< _ >() } } diff --git a/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs index 0625c6fd94..3259e27d04 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs @@ -36,7 +36,7 @@ where former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > { - self._children_assign::< _ >() + self._children_container_former::< _ >() } } diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index ebcaf19c4a..d4bcfae89e 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -270,7 +270,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { let hint = format! ( -r#" + r#" = Example of custom mutator impl< {} > former::FormerMutator diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 0c2ed2243b..70b38f953b 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -33,7 +33,7 @@ storage_field_optional storage_field_preform storage_field_name former_field_setter -subform_add_setter_map +subform_setter container_setter scalar_setter former_field_assign_end @@ -370,7 +370,12 @@ scalar_setter_required // container setter let r = if let Some( _ ) = &self.attrs.container { - let r2 = self.container_setter( stru ); + let r2 = self.container_setter + ( + stru, + former, + former_storage, + ); qt! { #r @@ -385,13 +390,11 @@ scalar_setter_required // subform setter let r = if self.attrs.subform.is_some() { - let r2 = self.subform_add_setter_map + let r2 = self.subform_setter ( stru, former, former_storage, - // as_subformer, - // as_subformer_end, )?; qt! { @@ -410,7 +413,7 @@ scalar_setter_required /// zzz : write documentation #[ inline ] - pub fn subform_add_setter_map + pub fn subform_setter ( &self, stru : &syn::Ident, @@ -476,7 +479,7 @@ scalar_setter_required { let hint = format! ( -r#" + r#" /// Initializes and configures a subformer for adding named child entities. This method leverages an internal function /// to create and return a configured subformer instance. It allows for the dynamic addition of children with specific names, @@ -494,6 +497,7 @@ where {{ self.{}::< ChildFormer< _ >, _, >() }} + // Replace Child with name of type of element value. }} "#, @@ -507,8 +511,6 @@ where println!( "{hint}" ); } - - // xxx : it should be printed by hint also let r = if attr.setter() { qt! @@ -581,9 +583,12 @@ where ( &self, stru : &syn::Ident, + former : &syn::Ident, + former_storage : &syn::Ident, ) -> TokenStream { + let attr = self.attrs.container.as_ref().unwrap(); let field_ident = &self.ident; let non_optional_ty = &self.non_optional_ty; let params = typ::type_parameters( &non_optional_ty, .. ); @@ -591,11 +596,11 @@ where use convert_case::{ Case, Casing }; let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); - let field_assign_name = format!( "_{}_assign", field_ident ); + let field_assign_name = format!( "_{}_container_former", field_ident ); let field_assign = syn::Ident::new( &field_assign_name, field_ident.span() ); // example : `former::VectorDefinition` - let subformer_definition = &self.attrs.container.as_ref().unwrap().definition; + let subformer_definition = &attr.definition; let subformer_definition = if subformer_definition.is_some() { qt! @@ -694,6 +699,42 @@ where qt!{} }; + if attr.hint + { + let hint = format! + ( + r#" + +/// The containr setter provides a container setter that returns a ContainerSubformer tailored for managing a collection of child entities. It employs a generic container definition to facilitate operations on the entire collection, such as adding or updating elements. +impl< Definition, > {}< Definition, > +where + Definition : former::FormerDefinition< Storage = {} >, +{{ + + #[ inline( always ) ] + pub fn {}( self ) -> former::ContainerSubformer:: + < + ( {} ), + former::HashMapDefinition< {} Self, Self, {}< Definition >, > + // Replace `HashMapDefinition` with definition for your container + > + {{ + self._children_container_former() + }} + +}} + + "#, + former, + former_storage, + field_ident, + format!( "{}", qt!{ #( #params, )* } ), + format!( "{}", qt!{ #( #params, )* } ), + former_assign_end, + ); + println!( "{hint}" ); + } + qt! { #setter1 From 1719df95116dadeeffd943dfde2f893514825db8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 4 May 2024 22:45:40 +0300 Subject: [PATCH 449/533] former : experimenting --- .../former_custom_container_setter.rs | 1 + .../former_custom_setter_overriden.rs | 2 + .../former/tests/inc/former_tests/a_basic.rs | 1 + .../tests/inc/former_tests/attribute_alias.rs | 6 ++ module/core/former/tests/inc/mod.rs | 65 ++++++++++--------- module/core/former_meta/src/derive_former.rs | 31 +++++++-- 6 files changed, 69 insertions(+), 37 deletions(-) diff --git a/module/core/former/examples/former_custom_container_setter.rs b/module/core/former/examples/former_custom_container_setter.rs index 0537d0df02..04717b6304 100644 --- a/module/core/former/examples/former_custom_container_setter.rs +++ b/module/core/former/examples/former_custom_container_setter.rs @@ -7,6 +7,7 @@ //! //! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. //! +//! xxx : extend by information about Scalar Setter //! #### Subform Setter vs. Container Setter //! //! It's important to distinguish between a subform setter and a container setter: diff --git a/module/core/former/examples/former_custom_setter_overriden.rs b/module/core/former/examples/former_custom_setter_overriden.rs index 4723ab16e2..c9e7ae98b2 100644 --- a/module/core/former/examples/former_custom_setter_overriden.rs +++ b/module/core/former/examples/former_custom_setter_overriden.rs @@ -3,6 +3,8 @@ //! For that use attribe `[ setter( false ) ]` to disable setter. In the example, the default setter for `word` is disabled, and a custom setter is defined to automatically append an exclamation mark to the string. This method allows for complete control over the data assignment process, enabling the inclusion of any necessary logic or validation steps. //! +// xxx : outdated description + #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] fn main() {} diff --git a/module/core/former/tests/inc/former_tests/a_basic.rs b/module/core/former/tests/inc/former_tests/a_basic.rs index 50d74672af..04ef5312c9 100644 --- a/module/core/former/tests/inc/former_tests/a_basic.rs +++ b/module/core/former/tests/inc/former_tests/a_basic.rs @@ -10,6 +10,7 @@ pub struct Struct1 } // == begin of generated + // == end of generated include!( "./only_test/basic.rs" ); diff --git a/module/core/former/tests/inc/former_tests/attribute_alias.rs b/module/core/former/tests/inc/former_tests/attribute_alias.rs index f295c439ce..a173d57182 100644 --- a/module/core/former/tests/inc/former_tests/attribute_alias.rs +++ b/module/core/former/tests/inc/former_tests/attribute_alias.rs @@ -10,6 +10,8 @@ tests_impls! fn test_alias() { #[ derive( Debug, PartialEq, the_module::Former ) ] + // #[ derive( Debug, PartialEq, the_module::Former ) ] #[ debug ] + // #[ derive( Debug, PartialEq ) ] pub struct AliasTestStruct { #[ scalar( name = first_field ) ] @@ -19,6 +21,10 @@ tests_impls! i8_field : i8, } + // == begin of generated + + // == end of generated + let test_struct = AliasTestStruct::former() .first_field( "first_field" ) .second_field( 2 ) diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 253648f435..737ec7ead1 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -98,40 +98,43 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_and_container_parametrized; -} - -#[ cfg( feature = "derive_components" ) ] -mod components_tests -{ - use super::*; - - #[ cfg( feature = "derive_component_from" ) ] - mod component_from_manual; - #[ cfg( feature = "derive_component_from" ) ] - mod component_from; - - #[ cfg( feature = "derive_component_assign" ) ] - mod component_assign_manual; - #[ cfg( feature = "derive_component_assign" ) ] - mod component_assign; - - #[ cfg( all( feature = "derive_component_assign", feature = "derive_components_assign" ) ) ] - mod components_assign_manual; - #[ cfg( all( feature = "derive_component_assign", feature = "derive_components_assign" ) ) ] - mod components_assign; - - #[ cfg( all( feature = "derive_from_components" ) ) ] - mod from_components_manual; - #[ cfg( all( feature = "derive_from_components" ) ) ] - mod from_components; - - #[ cfg( all( feature = "derive_component_from", feature = "derive_component_assign", feature = "derive_components_assign", feature = "derive_from_components" ) ) ] - mod composite_manual; - #[ cfg( all( feature = "derive_component_from", feature = "derive_component_assign", feature = "derive_components_assign", feature = "derive_from_components" ) ) ] - mod composite; + // xxx } +// xxx +// #[ cfg( feature = "derive_components" ) ] +// mod components_tests +// { +// use super::*; +// +// #[ cfg( feature = "derive_component_from" ) ] +// mod component_from_manual; +// #[ cfg( feature = "derive_component_from" ) ] +// mod component_from; +// +// #[ cfg( feature = "derive_component_assign" ) ] +// mod component_assign_manual; +// #[ cfg( feature = "derive_component_assign" ) ] +// mod component_assign; +// +// #[ cfg( all( feature = "derive_component_assign", feature = "derive_components_assign" ) ) ] +// mod components_assign_manual; +// #[ cfg( all( feature = "derive_component_assign", feature = "derive_components_assign" ) ) ] +// mod components_assign; +// +// #[ cfg( all( feature = "derive_from_components" ) ) ] +// mod from_components_manual; +// #[ cfg( all( feature = "derive_from_components" ) ) ] +// mod from_components; +// +// #[ cfg( all( feature = "derive_component_from", feature = "derive_component_assign", feature = "derive_components_assign", feature = "derive_from_components" ) ) ] +// mod composite_manual; +// #[ cfg( all( feature = "derive_component_from", feature = "derive_component_assign", feature = "derive_components_assign", feature = "derive_from_components" ) ) ] +// mod composite; +// +// } + // xxx // only_for_terminal_module! // { diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index d4bcfae89e..66078083ee 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -42,9 +42,12 @@ pub struct Struct1 let doc_former_struct = format! ( -r#" Object to form [{}]. If field's values is not set then default value of the field is set. +r#" +Structure to form [{}]. Represents a forming entity designed to construct objects through a builder pattern. -For specifying custom default value use attribute `default`. For example: +This structure holds temporary storage and context during the formation process and +utilizes a defined end strategy to finalize the object creation. It facilitates the flexible +construction of complex objects by allowing step-by-step configuration. ``` {} ``` @@ -79,6 +82,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let stru = &ast.ident; let former_name = format!( "{}Former", stru ); let former = syn::Ident::new( &former_name, stru.span() ); + // let former_namespace_name = format!( "{}FormerSpace", stru ); + // let former_namespace = syn::Ident::new( &former_namespace_name, stru.span() ); let former_storage_name = format!( "{}FormerStorage", stru ); let former_storage = syn::Ident::new( &former_storage_name, stru.span() ); let former_definition_name = format!( "{}FormerDefinition", stru ); @@ -344,6 +349,12 @@ where type Definition = #former_definition < #struct_generics_ty __Context, __Formed, __End >; } + // #[ allow( non_snake_case ) ] + // pub mod #former_namespace + // { + // pub use super::#stru; + // use super::*; + // = definition types #[ derive( Debug ) ] @@ -491,10 +502,15 @@ where where #former_generics_where { - storage : Definition::Storage, - context : core::option::Option< Definition::Context >, - on_end : core::option::Option< Definition::End >, - // zzz : should on_end be optional? + /// Temporary storage for all fields during the formation process. It contains + /// partial data that progressively builds up to the final object. + pub storage : Definition::Storage, + /// An optional context providing additional data or state necessary for custom + /// formation logic or to facilitate this former's role as a subformer within another former. + pub context : core::option::Option< Definition::Context >, + /// An optional closure or handler that is invoked to transform the accumulated + /// temporary storage into the final object structure once formation is complete. + pub on_end : core::option::Option< Definition::End >, } #[ automatically_derived ] @@ -730,6 +746,9 @@ where #former_field_add_end )* + // } /* end of namespace */ + // pub use #former_namespace :: *; + }; if has_debug From c9b3367c51706fda6b92247353545be7d5570a14 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 00:14:48 +0300 Subject: [PATCH 450/533] former : cleaning --- module/core/former_meta/src/derive_former.rs | 3 +-- module/core/former_meta/src/derive_former/struct_attrs.rs | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 66078083ee..c5e486249b 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -5,8 +5,7 @@ use macro_tools::{ attr, diag, generic_params, generic_args, typ, derive, Result use proc_macro2::TokenStream; // zzz : explain concept of Storage -// xxx : introduce namespaces -// zzz : qqq : implement interfaces for other containers +// qqq : implement interfaces for other containers mod field; use field::*; diff --git a/module/core/former_meta/src/derive_former/struct_attrs.rs b/module/core/former_meta/src/derive_former/struct_attrs.rs index 6642088dfe..c2a15bb9cf 100644 --- a/module/core/former_meta/src/derive_former/struct_attrs.rs +++ b/module/core/former_meta/src/derive_former/struct_attrs.rs @@ -152,11 +152,12 @@ impl StructAttributes pub fn storage_fields( &self ) -> &syn::punctuated::Punctuated< syn::Field, syn::token::Comma > { - self.storage_fields.as_ref().map_or_else( + self.storage_fields.as_ref().map_or_else + ( || &*Box::leak( Box::new( syn::punctuated::Punctuated::new() ) ), | attr | &attr.fields ) - // xxx : investigate + // qqq : find better solutioin // self.storage_fields // .as_ref() From 008b4bf74187c166c5ae0036b1b23c08de1fda59 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 00:19:51 +0300 Subject: [PATCH 451/533] former : cleaning --- .../examples/former_custom_container_setter.rs | 15 ++++++++++----- .../examples/former_custom_subform_setter.rs | 14 ++++++++++---- .../examples/former_custom_subform_setter2.rs | 14 ++++++++++---- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/module/core/former/examples/former_custom_container_setter.rs b/module/core/former/examples/former_custom_container_setter.rs index 04717b6304..c4b313cc8c 100644 --- a/module/core/former/examples/former_custom_container_setter.rs +++ b/module/core/former/examples/former_custom_container_setter.rs @@ -7,12 +7,17 @@ //! //! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. //! -//! xxx : extend by information about Scalar Setter -//! #### Subform Setter vs. Container Setter +//! #### Types of Setters //! -//! It's important to distinguish between a subform setter and a container setter: -//! - **Subform Setter**: This returns a former of an element within a container, providing an interface to individually form each element. In this example, `child` acts as a subform setter, allowing for the addition and configuration of individual `Child` entities within the `Parent`'s `HashMap`. -//! - **Container Setter**: Conversely, a container setter returns a former of the container itself, offering an interface to manage the container as a whole rather than its individual elements. It would be used if one needed to apply configurations or validations to the entire `HashMap` of children, rather than to individual children. +//! It's crucial to understand the differences among subform setters, container setters, and scalar setters: +//! +//! - **Scalar Setter**: Directly sets scalar values or simple fields within the forming entity. Unlike subform or container setters that manage complex objects or collections, scalar setters handle basic data types or individual fields. These are typically straightforward setter methods that do not involve nested formers or additional structuring. +//! +//! - **Container Setter**: Returns a former of the container itself, offering an interface to manage the container as a whole rather than its individual elements. This type of setter is useful for applying configurations or validations to the entire collection, such as a `HashMap` of children. +//! +//! - **Subform Setter**: Returns a former of an element within a container, providing an interface to individually form each element. For example, the `child` method acts as a subform setter, allowing for the addition and configuration of individual `Child` entities within the `Parent`'s `HashMap`. +//! +//! Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required. //! // zzz : duplicate into readme diff --git a/module/core/former/examples/former_custom_subform_setter.rs b/module/core/former/examples/former_custom_subform_setter.rs index f43b15e1a0..434c56d86e 100644 --- a/module/core/former/examples/former_custom_subform_setter.rs +++ b/module/core/former/examples/former_custom_subform_setter.rs @@ -7,11 +7,17 @@ //! //! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. //! -//! #### Subform Setter vs. Container Setter +//! #### Types of Setters //! -//! It's important to distinguish between a subform setter and a container setter: -//! - **Subform Setter**: This returns a former of an element within a container, providing an interface to individually form each element. In this example, `child` acts as a subform setter, allowing for the addition and configuration of individual `Child` entities within the `Parent`'s `HashMap`. -//! - **Container Setter**: Conversely, a container setter returns a former of the container itself, offering an interface to manage the container as a whole rather than its individual elements. It would be used if one needed to apply configurations or validations to the entire `HashMap` of children, rather than to individual children. +//! It's crucial to understand the differences among subform setters, container setters, and scalar setters: +//! +//! - **Scalar Setter**: Directly sets scalar values or simple fields within the forming entity. Unlike subform or container setters that manage complex objects or collections, scalar setters handle basic data types or individual fields. These are typically straightforward setter methods that do not involve nested formers or additional structuring. +//! +//! - **Container Setter**: Returns a former of the container itself, offering an interface to manage the container as a whole rather than its individual elements. This type of setter is useful for applying configurations or validations to the entire collection, such as a `HashMap` of children. +//! +//! - **Subform Setter**: Returns a former of an element within a container, providing an interface to individually form each element. For example, the `child` method acts as a subform setter, allowing for the addition and configuration of individual `Child` entities within the `Parent`'s `HashMap`. +//! +//! Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required. //! // zzz : duplicate into readme diff --git a/module/core/former/examples/former_custom_subform_setter2.rs b/module/core/former/examples/former_custom_subform_setter2.rs index f3e2bb3af3..2cfd49e2fe 100644 --- a/module/core/former/examples/former_custom_subform_setter2.rs +++ b/module/core/former/examples/former_custom_subform_setter2.rs @@ -7,11 +7,17 @@ //! //! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. //! -//! #### Subform Setter vs. Container Setter +//! #### Types of Setters //! -//! It's important to distinguish between a subform setter and a container setter: -//! - **Subform Setter**: This returns a former of an element within a container, providing an interface to individually form each element. In this example, `child` acts as a subform setter, allowing for the addition and configuration of individual `Child` entities within the `Parent`'s `HashMap`. -//! - **Container Setter**: Conversely, a container setter returns a former of the container itself, offering an interface to manage the container as a whole rather than its individual elements. It would be used if one needed to apply configurations or validations to the entire `HashMap` of children, rather than to individual children. +//! It's crucial to understand the differences among subform setters, container setters, and scalar setters: +//! +//! - **Scalar Setter**: Directly sets scalar values or simple fields within the forming entity. Unlike subform or container setters that manage complex objects or collections, scalar setters handle basic data types or individual fields. These are typically straightforward setter methods that do not involve nested formers or additional structuring. +//! +//! - **Container Setter**: Returns a former of the container itself, offering an interface to manage the container as a whole rather than its individual elements. This type of setter is useful for applying configurations or validations to the entire collection, such as a `HashMap` of children. +//! +//! - **Subform Setter**: Returns a former of an element within a container, providing an interface to individually form each element. For example, the `child` method acts as a subform setter, allowing for the addition and configuration of individual `Child` entities within the `Parent`'s `HashMap`. +//! +//! Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required. //! // zzz : duplicate into readme From b6ffbdbcfd84a1ef53be4d1c871bcbbe26d280e0 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 00:57:32 +0300 Subject: [PATCH 452/533] former : cleaning --- module/core/former/Readme.md | 69 ++++++++------ .../former_custom_container_setter.rs | 3 +- .../examples/former_custom_scalar_setter.rs | 91 +++++++++++++++++++ .../examples/former_custom_subform_setter.rs | 1 + .../examples/former_custom_subform_setter2.rs | 1 + .../tests/inc/former_tests/a_basic_manual.rs | 6 +- 6 files changed, 139 insertions(+), 32 deletions(-) create mode 100644 module/core/former/examples/former_custom_scalar_setter.rs diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 249a65220e..f2c6c4e169 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -421,6 +421,19 @@ This approach significantly simplifies struct construction, particularly for com Subformers are specialized builders used within the `Former` framework to construct nested or collection-based data structures like vectors, hash maps, and hash sets. They simplify the process of adding elements to these structures by providing a fluent interface that can be seamlessly integrated into the overall builder pattern of a parent struct. This approach allows for clean and intuitive initialization of complex data structures, enhancing code readability and maintainability. +### Types of Setters + +It's crucial to understand the differences among subform setters, container setters, and scalar setters: + +- **Scalar Setter**: Directly sets scalar values or simple fields within the forming entity. Unlike subform or container setters that manage complex objects or collections, scalar setters handle basic data types or individual fields. These are typically straightforward setter methods that do not involve nested formers or additional structuring. + +- **Container Setter**: Returns a former of the container itself, offering an interface to manage the container as a whole rather than its individual elements. This type of setter is useful for applying configurations or validations to the entire collection, such as a `HashMap` of children. + +- **Subform Setter**: Returns a former of an element within a container, providing an interface to individually form each element. For example, the `child` method acts as a subform setter, allowing for the addition and configuration of individual `Child` entities within the `Parent`'s `HashMap`. + +Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required. + + ### Subformer example: Building a Vector The following example illustrates how to use a `VectorSubformer` to construct a `Vec` field within a struct. The subformer enables adding elements to the vector with a fluent interface, streamlining the process of populating collection fields within structs. @@ -514,7 +527,7 @@ The example below illustrates how to incorporate the builder pattern of one stru Example of how to use former of another structure as subformer of former of current one -function `command` integrate `CommandFormer` into `AggregatorFormer`. +function `child` integrate `ChildFormer` into `ParentFormer`. ```rust # #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] @@ -525,68 +538,68 @@ fn main() use std::collections::HashMap; use former::Former; - // Command struct with Former derived for builder pattern support + // Child struct with Former derived for builder pattern support #[ derive( Debug, PartialEq, Former ) ] - pub struct Command + pub struct Child { name : String, description : String, } - // Aggregator struct to hold commands + // Parent struct to hold children #[ derive( Debug, PartialEq, Former ) ] - pub struct Aggregator + pub struct Parent { #[ scalar( setter = false ) ] - command : HashMap< String, Command >, + child : HashMap< String, Child >, } - // Use CommandFormer as custom subformer for AggregatorFormer to add commands by name. - impl< Context, End > AggregatorFormer< Context, End > + // Use ChildFormer as custom subformer for ParentFormer to add children by name. + impl< Context, End > ParentFormer< Context, End > where - End : former::FormingEnd< Aggregator, Context >, + End : former::FormingEnd< Parent, Context >, { - pub fn command< IntoName >( self, name : IntoName ) -> CommandFormer< Self, impl former::FormingEnd< Command, Self > > + pub fn child< IntoName >( self, name : IntoName ) -> ChildFormer< Self, impl former::FormingEnd< Child, Self > > where IntoName: core::convert::Into< String >, { - let on_end = | command : Command, super_former : core::option::Option< Self > | -> Self + let on_end = | child : Child, super_former : core::option::Option< Self > | -> Self { let mut super_former = super_former.unwrap(); - if let Some( ref mut commands ) = super_former.storage.command + if let Some( ref mut children ) = super_former.storage.child { - commands.insert( command.name.clone(), command ); + children.insert( child.name.clone(), child ); } else { - let mut commands: HashMap< String, Command > = Default::default(); - commands.insert( command.name.clone(), command ); - super_former.storage.command = Some( commands ); + let mut children: HashMap< String, Child > = Default::default(); + children.insert( child.name.clone(), child ); + super_former.storage.child = Some( children ); } super_former }; - let former = CommandFormer::begin_coercing( None, Some( self ), on_end ); + let former = ChildFormer::begin_coercing( None, Some( self ), on_end ); former.name( name ) } } - let ca = Aggregator::former() - .command( "echo" ) + let ca = Parent::former() + .child( "echo" ) .description( "prints all subjects and properties" ) // sets additional properties using custom subformer .end() - .command( "exit" ) + .child( "exit" ) .description( "just exit" ) // Sets additional properties using using custom subformer .end() .form(); dbg!( &ca ); - // > &ca = Aggregator { - // > command: { - // > "echo": Command { + // > &ca = Parent { + // > child: { + // > "echo": Child { // > name: "echo", // > description: "prints all subjects and properties", // > }, - // > "exit": Command { + // > "exit": Child { // > name: "exit", // > description: "just exit", // > }, @@ -596,11 +609,11 @@ fn main() # } ``` -In this example, the `Aggregator` struct functions as a container for multiple `Command` structs, each identified by a unique command name. The `AggregatorFormer` implements a custom method `command`, which serves as a subformer for adding `Command` instances into the `Aggregator`. +In this example, the `Parent` struct functions as a container for multiple `Child` structs, each identified by a unique child name. The `ParentFormer` implements a custom method `child`, which serves as a subformer for adding `Child` instances into the `Parent`. -- **Command Definition**: Each `Command` consists of a `name` and a `description`, and we derive `Former` to enable easy setting of these properties using a builder pattern. -- **Aggregator Definition**: It holds a collection of `Command` objects in a `HashMap`. The `#[setter(false)]` attribute is used to disable the default setter, and a custom method `command` is defined to facilitate the addition of commands with specific attributes. -- **Custom Subformer Integration**: The `command` method in the `AggregatorFormer` initializes a `CommandFormer` with a closure that integrates the `Command` into the `Aggregator`'s `command` map upon completion. +- **Child Definition**: Each `Child` consists of a `name` and a `description`, and we derive `Former` to enable easy setting of these properties using a builder pattern. +- **Parent Definition**: It holds a collection of `Child` objects in a `HashMap`. The `#[setter(false)]` attribute is used to disable the default setter, and a custom method `child` is defined to facilitate the addition of children with specific attributes. +- **Custom Subformer Integration**: The `child` method in the `ParentFormer` initializes a `ChildFormer` with a closure that integrates the `Child` into the `Parent`'s `child` map upon completion. This pattern of using a structure's former as a subformer within another facilitates the creation of deeply nested or complex data structures through a coherent and fluent interface, showcasing the powerful capabilities of the `Former` framework for Rust applications. diff --git a/module/core/former/examples/former_custom_container_setter.rs b/module/core/former/examples/former_custom_container_setter.rs index c4b313cc8c..8443e47098 100644 --- a/module/core/former/examples/former_custom_container_setter.rs +++ b/module/core/former/examples/former_custom_container_setter.rs @@ -46,7 +46,8 @@ fn main() // #[ debug ] pub struct Parent { - #[ container( setter = false, hint = true ) ] + // Use `hint = true` to gennerate sketch of setter. + #[ container( setter = false, hint = false ) ] children : HashMap< String, Child >, } diff --git a/module/core/former/examples/former_custom_scalar_setter.rs b/module/core/former/examples/former_custom_scalar_setter.rs new file mode 100644 index 0000000000..f4996c961a --- /dev/null +++ b/module/core/former/examples/former_custom_scalar_setter.rs @@ -0,0 +1,91 @@ +// Example former_custom_scalar_setter.rs + +//! +//! This example demonstrates the use of container setters to manage complex nested data structures with the `Former` trait, focusing on a parent-child relationship structured around a container `HashMap`. Unlike typical builder patterns that add individual elements using subform setters, this example uses a container setter to manage the entire collection of children. +//! +//! #### Custom Subform Setter +//! +//! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. +//! +//! #### Types of Setters +//! +//! It's crucial to understand the differences among subform setters, container setters, and scalar setters: +//! +//! - **Scalar Setter**: Directly sets scalar values or simple fields within the forming entity. Unlike subform or container setters that manage complex objects or collections, scalar setters handle basic data types or individual fields. These are typically straightforward setter methods that do not involve nested formers or additional structuring. +//! +//! - **Container Setter**: Returns a former of the container itself, offering an interface to manage the container as a whole rather than its individual elements. This type of setter is useful for applying configurations or validations to the entire collection, such as a `HashMap` of children. +//! +//! - **Subform Setter**: Returns a former of an element within a container, providing an interface to individually form each element. For example, the `child` method acts as a subform setter, allowing for the addition and configuration of individual `Child` entities within the `Parent`'s `HashMap`. +//! +//! Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required. +//! + +// xxx : update documentation + +// zzz : duplicate into readme + +#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +fn main() {} + +// Ensure the example only compiles when the appropriate features are enabled. +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + use std::collections::HashMap; + use former::Former; + + // Child struct with Former derived for builder pattern support + #[ derive( Debug, PartialEq, Former ) ] + // #[ debug ] + pub struct Child + { + name : String, + description : String, + } + + // Parent struct to hold children + #[ derive( Debug, PartialEq, Former ) ] + // #[ debug ] + pub struct Parent + { + #[ scalar( setter = false, hint = true ) ] + children : HashMap< String, Child >, + } + + impl< Definition > ParentFormer< Definition > + where + Definition : former::FormerDefinition< Storage = ParentFormerStorage >, + { + #[ inline ] + pub fn children< Src >( mut self, src : Src ) -> Self + where Src : ::core::convert::Into< HashMap< String, Child > >, + { + debug_assert!( self.storage.children.is_none() ); + self.storage.children = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + self + } + } + + let echo = Child { name : "echo".to_string(), description : "prints all subjects and properties".to_string() }; + let exit = Child { name : "exit".to_string(), description : "just exit".to_string() }; + let mut children = HashMap::new(); + children.insert( echo.name.clone(), echo ); + children.insert( exit.name.clone(), exit ); + let ca = Parent::former() + .children( children ) + .form(); + + dbg!( &ca ); + // > &ca = Parent { + // > child: { + // > "echo": Child { + // > name: "echo", + // > description: "prints all subjects and properties", + // > }, + // > "exit": Child { + // > name: "exit", + // > description: "just exit", + // > }, + // > }, + // > } +} diff --git a/module/core/former/examples/former_custom_subform_setter.rs b/module/core/former/examples/former_custom_subform_setter.rs index 434c56d86e..b7074bdad7 100644 --- a/module/core/former/examples/former_custom_subform_setter.rs +++ b/module/core/former/examples/former_custom_subform_setter.rs @@ -46,6 +46,7 @@ fn main() // #[ debug ] pub struct Parent { + // Use `hint = true` to gennerate sketch of setter. #[ subform( setter = false, hint = false ) ] child : HashMap< String, Child >, } diff --git a/module/core/former/examples/former_custom_subform_setter2.rs b/module/core/former/examples/former_custom_subform_setter2.rs index 2cfd49e2fe..60e9344f81 100644 --- a/module/core/former/examples/former_custom_subform_setter2.rs +++ b/module/core/former/examples/former_custom_subform_setter2.rs @@ -46,6 +46,7 @@ fn main() // #[ debug ] pub struct Parent { + // Use `hint = true` to gennerate sketch of setter. #[ subform( setter = false, hint = false ) ] child : HashMap< String, Child >, } diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 4af5c24b5f..f7cd572173 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -184,7 +184,7 @@ where impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, - < Definition as former::FormerDefinition >::Types : former::FormerMutator, + { #[ inline( always ) ] @@ -283,7 +283,7 @@ impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition< Storage = Struct1FormerStorage, Formed = Struct1 >, Definition::Storage : former::StoragePreform< Preformed = Struct1 >, - < Definition as former::FormerDefinition >::Types : former::FormerMutator, + { pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { @@ -295,7 +295,7 @@ impl< Definition > former::FormerBegin< Definition > for Struct1Former< Definition > where Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, - < Definition as former::FormerDefinition >::Types : former::FormerMutator, + { #[ inline( always ) ] From 75ad8b3126e02d6f3eaec47e92e36bcf9e57edb9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 01:31:27 +0300 Subject: [PATCH 453/533] former : cleaning --- .../examples/former_custom_scalar_setter.rs | 10 +-- .../former_meta/src/derive_former/field.rs | 85 +++++++++++++++---- 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/module/core/former/examples/former_custom_scalar_setter.rs b/module/core/former/examples/former_custom_scalar_setter.rs index f4996c961a..9774a8fabe 100644 --- a/module/core/former/examples/former_custom_scalar_setter.rs +++ b/module/core/former/examples/former_custom_scalar_setter.rs @@ -1,7 +1,7 @@ // Example former_custom_scalar_setter.rs //! -//! This example demonstrates the use of container setters to manage complex nested data structures with the `Former` trait, focusing on a parent-child relationship structured around a container `HashMap`. Unlike typical builder patterns that add individual elements using subform setters, this example uses a container setter to manage the entire collection of children. +//! This example demonstrates the implementation of a scalar setter using the `Former` trait in Rust. Unlike the more complex subform and container setters shown in previous examples, this example focuses on a straightforward approach to directly set a scalar value within a parent entity. The `Parent` struct manages a `HashMap` of `Child` entities, and the scalar setter is used to set the entire `HashMap` directly. //! //! #### Custom Subform Setter //! @@ -20,8 +20,6 @@ //! Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required. //! -// xxx : update documentation - // zzz : duplicate into readme #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] @@ -48,7 +46,8 @@ fn main() // #[ debug ] pub struct Parent { - #[ scalar( setter = false, hint = true ) ] + // Use `hint = true` to gennerate sketch of setter. + #[ scalar( setter = false, hint = false ) ] children : HashMap< String, Child >, } @@ -58,7 +57,8 @@ fn main() { #[ inline ] pub fn children< Src >( mut self, src : Src ) -> Self - where Src : ::core::convert::Into< HashMap< String, Child > >, + where + Src : ::core::convert::Into< HashMap< String, Child > >, { debug_assert!( self.storage.children.is_none() ); self.storage.children = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 70b38f953b..8968829802 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -350,22 +350,26 @@ scalar_setter_required ) -> Result< TokenStream > { - let r = qt!{}; + let r = self.scalar_setter + ( + former, + former_storage, + ); - // scalar setter - let r = if self.scalar_setter_required() - { - let r2 = self.scalar_setter(); - qt! - { - #r - #r2 - } - } - else - { - r - }; + // // scalar setter + // let r = if self.scalar_setter_required() + // { + // let r2 = self.scalar_setter(); + // qt! + // { + // #r + // #r2 + // } + // } + // else + // { + // r + // }; // container setter let r = if let Some( _ ) = &self.attrs.container @@ -795,12 +799,56 @@ where pub fn scalar_setter ( &self, + former : &syn::Ident, + former_storage : &syn::Ident, ) -> TokenStream { - let field_ident = &self.ident; - let typ = &self.non_optional_ty; + let field_ident = self.ident; + let typ = self.non_optional_ty; let setter_name = self.scalar_setter_name(); + let attr = self.attrs.scalar.as_ref(); + + if attr.is_some() && attr.unwrap().hint + { + let hint = format! + ( + r#" + +impl< Definition > {}< Definition > +where + Definition : former::FormerDefinition< Storage = {} >, +{{ + #[ inline ] + pub fn {}< Src >( mut self, src : Src ) -> Self + where + Src : ::core::convert::Into< {} >, + {{ + debug_assert!( self.storage.{}.is_none() ); + self.storage.{} = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + self + }} +}} + + "#, + former, + former_storage, + field_ident, + format!( "{}", qt!{ #typ } ), + field_ident, + field_ident, + // field_ident, + // format!( "{}", qt!{ #( #params, )* } ), + // format!( "{}", qt!{ #( #params, )* } ), + // former_assign_end, + ); + println!( "{hint}" ); + } + + if !self.scalar_setter_required() + { + return qt! {}; + } let doc = format! ( @@ -813,7 +861,8 @@ where #[ doc = #doc ] #[ inline ] pub fn #setter_name< Src >( mut self, src : Src ) -> Self - where Src : ::core::convert::Into< #typ >, + where + Src : ::core::convert::Into< #typ >, { debug_assert!( self.storage.#field_ident.is_none() ); self.storage.#field_ident = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); From 3223cdadcebf224ded215df6effdc6e16963de98 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 01:40:54 +0300 Subject: [PATCH 454/533] former : cleaning --- module/core/former/examples/former_custom_default.rs | 2 +- module/core/former/examples/former_subformer_hashmap.rs | 6 +++--- module/core/former/examples/former_subformer_hashset.rs | 6 +++--- module/core/former/examples/former_subformer_vector.rs | 8 ++++---- module/core/former/examples/former_trivial.rs | 2 ++ 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/module/core/former/examples/former_custom_default.rs b/module/core/former/examples/former_custom_default.rs index 7ebb39e432..c80eb0e1be 100644 --- a/module/core/former/examples/former_custom_default.rs +++ b/module/core/former/examples/former_custom_default.rs @@ -1,7 +1,7 @@ //! The `Former` crate enhances struct initialization in Rust by allowing the specification of custom default values for fields through the `default` attribute. //! //! This feature not only provides a way to set initial values for struct fields without relying on the `Default` trait but also adds flexibility in handling cases where a field's type does not implement `Default`, or a non-standard default value is desired. -//! The above code snippet showcases the `Former` crate's ability to initialize struct fields with custom default values: +//! The example showcases the `Former` crate's ability to initialize struct fields with custom default values: //! - The `number` field is initialized to `5`. //! - The `greeting` field defaults to a greeting message, "Hello, Former!". //! - The `numbers` field starts with a vector containing the integers `10`, `20`, and `30`. diff --git a/module/core/former/examples/former_subformer_hashmap.rs b/module/core/former/examples/former_subformer_hashmap.rs index d6d49e9652..3e635c4044 100644 --- a/module/core/former/examples/former_subformer_hashmap.rs +++ b/module/core/former/examples/former_subformer_hashmap.rs @@ -14,14 +14,14 @@ fn main() #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithMap { - #[ container( definition = former::HashMapSubformer ) ] + #[ container ] map : std::collections::HashMap< &'static str, &'static str >, } let struct1 = StructWithMap::former() .map() - .insert( "a", "b" ) - .insert( "c", "d" ) + .add( ( "a", "b" ) ) + .add( ( "c", "d" ) ) .end() .form() ; diff --git a/module/core/former/examples/former_subformer_hashset.rs b/module/core/former/examples/former_subformer_hashset.rs index 5920d6d71d..3acd60f693 100644 --- a/module/core/former/examples/former_subformer_hashset.rs +++ b/module/core/former/examples/former_subformer_hashset.rs @@ -14,14 +14,14 @@ fn main() #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithSet { - #[ container( definition = former::HashSetSubformer ) ] + #[ container ] set : std::collections::HashSet< &'static str >, } let instance = StructWithSet::former() .set() - .insert("apple") - .insert("banana") + .add( "apple" ) + .add( "banana" ) .end() .form(); diff --git a/module/core/former/examples/former_subformer_vector.rs b/module/core/former/examples/former_subformer_vector.rs index 55588a881b..cebaa5c131 100644 --- a/module/core/former/examples/former_subformer_vector.rs +++ b/module/core/former/examples/former_subformer_vector.rs @@ -1,6 +1,6 @@ //! # Example Usage //! -//! Demonstrates how to use `HashMapSubformer` with the `HashMapLike` trait to build a `std::collections::HashMap`: +//! This example demonstrates how to employ the `Former` trait to configure a `Vec` using a container setter in a structured manner. //! #[ cfg( not( all( feature = "derive_former", not( feature = "no_std" ) ) ) ) ] @@ -13,14 +13,14 @@ fn main() #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithVec { - #[ container( definition = former::VectorSubformer ) ] + #[ container ] vec : Vec< &'static str >, } let instance = StructWithVec::former() .vec() - .push( "apple" ) - .push( "banana" ) + .add( "apple" ) + .add( "banana" ) .end() .form(); diff --git a/module/core/former/examples/former_trivial.rs b/module/core/former/examples/former_trivial.rs index 78331e5577..4a94d8d942 100644 --- a/module/core/former/examples/former_trivial.rs +++ b/module/core/former/examples/former_trivial.rs @@ -24,7 +24,9 @@ fn main() { use former::Former; + // Use attribute debug to print expanded code. #[ derive( Debug, PartialEq, Former ) ] + #[ debug ] pub struct UserProfile { age : i32, From 30bfc5743dbc60e60d2b08ccb7af89b81a454fb8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 01:52:10 +0300 Subject: [PATCH 455/533] former : cleaning --- .../examples/former_subformer_hashmap.rs | 3 +- .../examples/former_subformer_hashset.rs | 3 +- .../former/examples/former_trivial_expaned.rs | 597 +++++++++++------- 3 files changed, 383 insertions(+), 220 deletions(-) diff --git a/module/core/former/examples/former_subformer_hashmap.rs b/module/core/former/examples/former_subformer_hashmap.rs index 3e635c4044..a36cfbf06e 100644 --- a/module/core/former/examples/former_subformer_hashmap.rs +++ b/module/core/former/examples/former_subformer_hashmap.rs @@ -1,6 +1,5 @@ -//! # Example Usage //! -//! Demonstrates how to use `HashMapSubformer` with the `HashMapLike` trait to build a `std::collections::HashMap`: +//! This example demonstrates how to effectively employ the `Former` trait to configure a `HashMap` using a container setter. //! #[ cfg( not( all( feature = "derive_former", not( feature = "no_std" ) ) ) ) ] diff --git a/module/core/former/examples/former_subformer_hashset.rs b/module/core/former/examples/former_subformer_hashset.rs index 3acd60f693..cb496ea010 100644 --- a/module/core/former/examples/former_subformer_hashset.rs +++ b/module/core/former/examples/former_subformer_hashset.rs @@ -1,6 +1,5 @@ -//! # Example Usage //! -//! Demonstrates how to use `HashMapSubformer` with the `HashMapLike` trait to build a `std::collections::HashMap`: +//! This example demonstrates the use of the `Former` trait to build a `std::collections::HashSet` through subforming. //! #[ cfg( not( all( feature = "derive_former", not( feature = "no_std" ) ) ) ) ] diff --git a/module/core/former/examples/former_trivial_expaned.rs b/module/core/former/examples/former_trivial_expaned.rs index 0e4372585d..222d12a64c 100644 --- a/module/core/former/examples/former_trivial_expaned.rs +++ b/module/core/former/examples/former_trivial_expaned.rs @@ -1,3 +1,4 @@ +#![ allow( dead_code ) ] //! # Builder Pattern Implementation with Former //! //! This module demonstrates the use of the `Former` trait to apply the builder pattern for Rust structs. @@ -16,219 +17,383 @@ //! This approach abstracts away the need for manually implementing a builder for each struct, making code more readable and maintainable. //! -// zzz : regenerate - -// #![ allow( dead_code ) ] -// -// #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] -// fn main(){} -// -// #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -// fn main() -// { -// -// #[ derive( Debug, PartialEq ) ] -// pub struct UserProfile -// { -// age : i32, -// username : String, -// bio_optional : Option< String >, // Fields could be optional -// } -// -// impl UserProfile -// { -// #[ inline( always ) ] -// pub fn former() -> UserProfileFormer< UserProfile, former::ReturnFormed > -// { -// UserProfileFormer::< UserProfile, former::ReturnFormed >::new() -// } -// } -// -// #[ derive( Debug, Default ) ] -// pub struct UserProfileFormerStorage -// { -// age : Option< i32 >, -// username : Option< String >, -// bio_optional : Option< String >, -// } -// -// pub struct UserProfileFormer -// < -// Context = UserProfile, -// End = former::ReturnFormed, -// > -// where -// End : former::FormingEnd< UserProfile, Context >, -// { -// storage : UserProfileFormerStorage, -// context : Option< Context >, -// on_end : Option< End >, -// } -// -// impl< Context, End > UserProfileFormer< Context, End > -// where -// End : former::FormingEnd< UserProfile, Context >, -// { -// #[ inline( always ) ] -// pub fn form( mut self ) -> UserProfile -// { -// let age = if self.storage.age.is_some() -// { -// self.storage.age.take().unwrap() -// } -// else -// { -// let val : i32 = -// { -// trait NotDefault< T > -// { -// fn maybe_default( self : &Self ) -> T { panic!( "Field 'age' isn't initialized" ) } -// } -// trait WithDefault< T > -// { -// fn maybe_default( self : &Self ) -> T; -// } -// impl< T > NotDefault< T > for &::core::marker::PhantomData< T > {} -// impl< T > WithDefault< T > for ::core::marker::PhantomData< T > -// where -// T : ::core::default::Default, -// { -// fn maybe_default( self : &Self ) -> T -// { -// T::default() -// } -// } -// ( &::core::marker::PhantomData::< i32 > ).maybe_default() -// }; -// val -// }; -// let username = if self.storage.username.is_some() -// { -// self.storage.username.take().unwrap() -// } -// else -// { -// let val : String = -// { -// trait NotDefault< T > -// { -// fn maybe_default( self : &Self ) -> T { panic!( "Field 'username' isn't initialized" ) } -// } -// trait WithDefault< T > -// { -// fn maybe_default( self : &Self ) -> T; -// } -// impl< T > NotDefault< T > for &::core::marker::PhantomData< T > {} -// impl< T > WithDefault< T > for ::core::marker::PhantomData< T > -// where -// T : ::core::default::Default, -// { -// fn maybe_default( self : &Self ) -> T -// { -// T::default() -// } -// } -// ( &::core::marker::PhantomData::< String > ).maybe_default() -// }; -// val -// }; -// let bio_optional = if self.storage.bio_optional.is_some() -// { -// Option::Some( self.storage.bio_optional.take().unwrap() ) -// } -// else -// { -// Option::None -// }; -// let result = UserProfile -// { -// age, -// username, -// bio_optional, -// }; -// return result; -// } -// -// #[ inline( always ) ] -// pub fn perform( self ) -> UserProfile -// { -// let result = self.form(); -// return result; -// } -// -// #[ inline( always ) ] -// pub fn new() -> UserProfileFormer< UserProfile, former::ReturnFormed > -// { -// UserProfileFormer::< UserProfile, former::ReturnFormed >::begin( None, former::ReturnFormed ) -// } -// -// #[ inline( always ) ] -// pub fn begin -// ( -// context : Option< Context >, -// on_end : End, -// ) -> Self -// { -// Self -// { -// storage : core::default::Default::default(), -// context : context, -// on_end : Option::Some( on_end ), -// } -// } -// -// #[ inline( always ) ] -// pub fn end( mut self ) -> Context -// { -// let on_end = self.on_end.take().unwrap(); -// let context = self.context.take(); -// let formed = self.form(); -// on_end.call( formed, context ) -// } -// -// #[ inline ] -// pub fn age< Src >( mut self, src : Src ) -> Self -// where -// Src : Into< i32 >, -// { -// debug_assert!( self.storage.age.is_none() ); -// self.storage.age = Option::Some( src.into() ); -// self -// } -// -// #[ inline ] -// pub fn username< Src >( mut self, src : Src ) -> Self -// where -// Src : Into< String >, -// { -// debug_assert!( self.storage.username.is_none() ); -// self.storage.username = Option::Some( src.into() ); -// self -// } -// -// #[ inline ] -// pub fn bio_optional< Src >( mut self, src : Src ) -> Self -// where -// Src : Into< String >, -// { -// debug_assert!( self.storage.bio_optional.is_none() ); -// self.storage.bio_optional = Option::Some( src.into() ); -// self -// } -// } -// -// let profile = UserProfile::former() -// .age( 30 ) -// .username( "JohnDoe".to_string() ) -// .bio_optional( "Software Developer".to_string() ) -// .form(); -// -// dbg!( &profile ); -// // Expected output: -// // &profile = UserProfile { -// // age: 30, -// // username: "JohnDoe", -// // bio_optional: Some("Software Developer"), -// // } -// -// } +#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +fn main() {} +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + + // Use attribute debug to print expanded code. + #[ derive( Debug, PartialEq ) ] + pub struct UserProfile + { + age : i32, + username : String, + bio_optional : Option< String >, // Fields could be optional + } + + impl< > UserProfile< > + where + { + #[ inline( always ) ] + pub fn former() -> UserProfileFormer< + UserProfileFormerDefinition< (), UserProfile< >, former::ReturnPreformed > + > + { + UserProfileFormer::< UserProfileFormerDefinition< (), UserProfile< >, former::ReturnPreformed > >:: + new_coercing(former::ReturnPreformed) + } + } + + impl< Definition > former::EntityToFormer< Definition > for UserProfile< > + where + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, + { + type Former = UserProfileFormer< Definition >; + } + + impl< > former::EntityToStorage for UserProfile< > + where + { + type Storage = UserProfileFormerStorage< >; + } + + impl< Context, Formed, End > former::EntityToDefinition< Context, Formed, End > for UserProfile< > + where + End : former::FormingEnd< UserProfileFormerDefinitionTypes< Context, Formed > >, + { + type Definition = UserProfileFormerDefinition< Context, Formed, End >; + } + + #[derive(Debug)] + pub struct UserProfileFormerDefinitionTypes< Context = (), Formed = UserProfile< >, > + where + { + _phantom : core::marker::PhantomData< (*const Context, *const Formed) >, + } + + impl< Context, Formed, > ::core::default::Default for UserProfileFormerDefinitionTypes< Context, Formed, > + where + { + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + } + + impl< Context, Formed, > former::FormerDefinitionTypes for UserProfileFormerDefinitionTypes< Context, Formed, > + where + { + type Storage = UserProfileFormerStorage< >; + type Formed = Formed; + type Context = Context; + } + + #[derive(Debug)] + pub struct UserProfileFormerDefinition< Context = (), Formed = UserProfile< >, End = former::ReturnPreformed, > + where + { + _phantom : core::marker::PhantomData< (*const Context, *const Formed, *const End) >, + } + + impl< Context, Formed, End, > ::core::default::Default for UserProfileFormerDefinition< Context, Formed, End, > + where + { + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + } + + impl< Context, Formed, End, > former::FormerDefinition for UserProfileFormerDefinition< Context, Formed, End, > + where + End : former::FormingEnd< UserProfileFormerDefinitionTypes< Context, Formed, > >, + { + type Types = UserProfileFormerDefinitionTypes< Context, Formed, >; + type End = End; + type Storage = UserProfileFormerStorage< >; + type Formed = Formed; + type Context = Context; + } + + impl< Context, Formed, > former::FormerMutator for UserProfileFormerDefinitionTypes< Context, Formed, > + where + {} + + pub struct UserProfileFormerStorage< > + where + { + pub age : ::core::option::Option< i32 >, + pub username : ::core::option::Option< String >, + pub bio_optional : Option< String >, + } + + impl< > ::core::default::Default for UserProfileFormerStorage< > + where + { + #[ inline( always ) ] + fn default() -> Self + { + Self + { + age : ::core::option::Option::None, + username : ::core::option::Option::None, + bio_optional : ::core::option::Option::None, + } + } + } + + impl< > former::Storage for UserProfileFormerStorage< > + where + { + type Formed = UserProfile< >; + } + + impl< > former::StoragePreform for UserProfileFormerStorage< > + where + { + type Preformed = UserProfile< >; + fn preform(mut self) -> Self::Preformed + { + let age = if self.age.is_some() + { + self.age.take().unwrap() + } + else + { + { + trait MaybeDefault< T > + { + fn maybe_default(self : &Self) -> T + { + panic!("Field 'age' isn't initialized") + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > + {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default(self : &Self) -> T + { + T::default() + } + } + (&::core::marker::PhantomData::< i32 >).maybe_default() + } + }; + let username = if self.username.is_some() + { + self.username.take().unwrap() + } + else + { + { + trait MaybeDefault< T > + { + fn maybe_default(self : &Self) -> T + { + panic!("Field 'username' isn't initialized") + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > + {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default(self : &Self) -> T + { + T::default() + } + } + (&::core::marker::PhantomData::< String >).maybe_default() + } + }; + let bio_optional = if self.bio_optional.is_some() + { + ::core::option::Option::Some(self.bio_optional.take().unwrap()) + } + else + { + ::core::option::Option::None + }; + let result = UserProfile::<> + { + age, + username, + bio_optional, + }; + return result; + } + } + + pub struct UserProfileFormer< Definition = UserProfileFormerDefinition< (), UserProfile< >, former::ReturnPreformed >, > + where + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, + { + pub storage : Definition::Storage, + pub context : core::option::Option< Definition::Context >, + pub on_end : core::option::Option< Definition::End >, + } + + impl< Definition, > UserProfileFormer< Definition, > + where + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, Definition::Types : former::FormerDefinitionTypes< Storage = UserProfileFormerStorage< > >, + { + #[ inline( always ) ] + pub fn new(on_end : Definition::End) -> Self + { + Self::begin_coercing(None, None, on_end) + } + + #[ inline( always ) ] + pub fn new_coercing< IntoEnd >(end : IntoEnd) -> Self + where IntoEnd : Into< Definition::End >, + { + Self::begin_coercing(None, None, end,) + } + + #[ inline( always ) ] + pub fn begin(mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, on_end : ::End,) -> Self + { + if storage.is_none() + { + storage = Some(::core::default::Default::default()); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some(on_end), + } + } + + #[ inline( always ) ] + pub fn begin_coercing< IntoEnd >(mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, on_end : IntoEnd,) -> Self + where IntoEnd : ::core::convert::Into< ::End >, + { + if storage.is_none() + { + storage = Some(::core::default::Default::default()); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some(::core::convert::Into::into(on_end)), + } + } + + #[ inline( always ) ] + pub fn form(self) -> ::Formed + { + self.end() + } + + #[ inline( always ) ] + pub fn end(mut self) -> ::Formed + { + let on_end = self.on_end.take().unwrap(); + let mut context = self.context.take(); + ::form_mutation(&mut self.storage, &mut context); + former::FormingEnd::::call(&on_end, self.storage, context) + } + + #[ inline( always ) ] + pub fn age< Src >(mut self, src : Src) -> Self + where Src : ::core::convert::Into< i32 >, + { + debug_assert!(self.storage.age.is_none()); + self.storage.age = ::core::option::Option::Some(::core::convert::Into::into(src)); + self + } + + #[ inline( always ) ] + pub fn username< Src >(mut self, src : Src) -> Self + where Src : ::core::convert::Into< String >, + { + debug_assert!(self.storage.username.is_none()); + self.storage.username = ::core::option::Option::Some(::core::convert::Into::into(src)); + self + } + + #[ inline( always ) ] + pub fn bio_optional< Src >(mut self, src : Src) -> Self + where Src : ::core::convert::Into< String >, + { + debug_assert!(self.storage.bio_optional.is_none()); + self.storage.bio_optional = ::core::option::Option::Some(::core::convert::Into::into(src)); + self + } + } + + impl< Definition, > UserProfileFormer< Definition, > + where + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< >, Formed = UserProfile< > >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, + { + pub fn preform(self) -> ::Formed + { + former::StoragePreform::preform(self.storage) + } + } + + impl< Definition, > UserProfileFormer< Definition, > + where + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< >, Formed = UserProfile< >, >, + { + + #[ inline( always ) ] + pub fn perform(self) -> Definition::Formed + { + let result = self.form(); + return result; + } + } + + impl< Definition > former::FormerBegin< Definition > for UserProfileFormer< Definition, > + where + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, + { + #[ inline( always ) ] + fn former_begin(storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, on_end : Definition::End,) -> Self + { + debug_assert!(storage.is_none()); + Self::begin(None, context, on_end) + } + } + + pub type UserProfileAsSubformer< Superformer, End > = + UserProfileFormer< UserProfileFormerDefinition< Superformer, Superformer, End, >, >; + + pub trait UserProfileAsSubformerEnd< SuperFormer > + where + Self : former::FormingEnd< UserProfileFormerDefinitionTypes< SuperFormer, SuperFormer >, >, {} + + impl< SuperFormer, T > UserProfileAsSubformerEnd< SuperFormer > for T + where + Self : former::FormingEnd< UserProfileFormerDefinitionTypes< SuperFormer, SuperFormer >, >, + {} + + let profile = UserProfile::former() + .age( 30 ) + .username( "JohnDoe".to_string() ) + .bio_optional( "Software Developer".to_string() ) // Optionally provide a bio + .form(); + dbg!( &profile ); + + // Expected output: + // + // &profile = UserProfile { + // age: 30, + // username: "JohnDoe", + // bio_optional: Some("Software Developer"), + // } + +} From 827fd95eb4177ef5e77b47c168517ba8a0fd38e6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 01:53:29 +0300 Subject: [PATCH 456/533] former : cleaning --- module/core/former/examples/former_trivial.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/core/former/examples/former_trivial.rs b/module/core/former/examples/former_trivial.rs index 4a94d8d942..c644035cfc 100644 --- a/module/core/former/examples/former_trivial.rs +++ b/module/core/former/examples/former_trivial.rs @@ -26,7 +26,7 @@ fn main() // Use attribute debug to print expanded code. #[ derive( Debug, PartialEq, Former ) ] - #[ debug ] + // #[ debug ] pub struct UserProfile { age : i32, From f5e27c232529d8fba289aff38289dabd1030de43 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 02:21:16 +0300 Subject: [PATCH 457/533] former : cleaning --- module/core/former/Readme.md | 573 ++++++++++++------ .../former_custom_setter_overriden.rs | 2 - .../former/examples/former_trivial_expaned.rs | 12 +- .../former_meta/src/derive_former/field.rs | 4 - 4 files changed, 404 insertions(+), 187 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index f2c6c4e169..b77e16ea4c 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -29,34 +29,21 @@ fn main() { use former::Former; + // Use attribute debug to print expanded code. #[ derive( Debug, PartialEq, Former ) ] - #[ perform( fn greet_user() ) ] + // #[ debug ] pub struct UserProfile { - #[default(1)] age : i32, - username : String, - - #[alias(bio)] bio_optional : Option< String >, // Fields could be optional } - impl UserProfile - { - fn greet_user(self) -> Self - { - println!("Hello, {}", self.username); - self - } - } - let profile = UserProfile::former() .age( 30 ) .username( "JohnDoe".to_string() ) .bio_optional( "Software Developer".to_string() ) // Optionally provide a bio .form(); - // .perform(); // same as `form()` but will execute method passed to `perform` attribute dbg!( &profile ); // Expected output: @@ -73,216 +60,389 @@ fn main() The code above will be expanded to this ```rust - -#[ derive( Debug, PartialEq ) ] -pub struct UserProfile +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() { - age : i32, - username : String, - bio_optional : Option< String >, // Fields could be optional -} -impl UserProfile -{ - #[ inline( always ) ] - pub fn former() -> UserProfileFormer< UserProfile, former::ReturnFormed > + // Use attribute debug to print expanded code. + #[ derive( Debug, PartialEq ) ] + pub struct UserProfile { - UserProfileFormer::< UserProfile, former::ReturnFormed >::new() + age : i32, + username : String, + bio_optional : Option< String >, // Fields could be optional } -} -#[ derive( Debug, Default ) ] -pub struct UserProfileFormerStorage -{ - age : Option< i32 >, - username : Option< String >, - bio_optional : Option< String >, -} + impl< > UserProfile< > + where + { + #[ inline( always ) ] + pub fn former() -> UserProfileFormer< + UserProfileFormerDefinition< (), UserProfile< >, former::ReturnPreformed > + > + { + UserProfileFormer::< UserProfileFormerDefinition< (), UserProfile< >, former::ReturnPreformed > >:: + new_coercing(former::ReturnPreformed) + } + } -pub struct UserProfileFormer -< - Context = UserProfile, - End = former::ReturnFormed, -> -where - End : former::FormingEnd< UserProfile, Context >, -{ - storage : UserProfileFormerStorage, - context : Option< Context >, - on_end : Option< End >, -} + impl< Definition > former::EntityToFormer< Definition > for UserProfile< > + where + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, + { + type Former = UserProfileFormer< Definition >; + } -impl< Context, End > UserProfileFormer< Context, End > -where - End : former::FormingEnd< UserProfile, Context >, -{ - #[ inline( always ) ] - pub fn form( mut self ) -> UserProfile + impl< > former::EntityToStorage for UserProfile< > + where + { + type Storage = UserProfileFormerStorage< >; + } + + impl< Context, Formed, End > former::EntityToDefinition< Context, Formed, End > for UserProfile< > + where + End : former::FormingEnd< UserProfileFormerDefinitionTypes< Context, Formed > >, + { + type Definition = UserProfileFormerDefinition< Context, Formed, End >; + } + + #[derive(Debug)] + pub struct UserProfileFormerDefinitionTypes< Context = (), Formed = UserProfile< >, > + where + { + _phantom : core::marker::PhantomData< (*const Context, *const Formed) >, + } + + impl< Context, Formed, > ::core::default::Default for UserProfileFormerDefinitionTypes< Context, Formed, > + where { - let age = if self.storage.age.is_some() + fn default() -> Self { - self.storage.age.take().unwrap() + Self + { + _phantom : core::marker::PhantomData, + } } - else + } + + impl< Context, Formed, > former::FormerDefinitionTypes for UserProfileFormerDefinitionTypes< Context, Formed, > + where + { + type Storage = UserProfileFormerStorage< >; + type Formed = Formed; + type Context = Context; + } + + #[derive(Debug)] + pub struct UserProfileFormerDefinition< Context = (), Formed = UserProfile< >, End = former::ReturnPreformed, > + where + { + _phantom : core::marker::PhantomData< (*const Context, *const Formed, *const End) >, + } + + impl< Context, Formed, End, > ::core::default::Default for UserProfileFormerDefinition< Context, Formed, End, > + where + { + fn default() -> Self { - let val : i32 = + Self { - trait NotDefault< T > - { - fn maybe_default( self : &Self ) -> T { panic!( "Field 'age' isn't initialized" ) } - } - trait WithDefault< T > - { - fn maybe_default( self : &Self ) -> T; - } - impl< T > NotDefault< T > for &::core::marker::PhantomData< T > {} - impl< T > WithDefault< T > for ::core::marker::PhantomData< T > - where - T : ::core::default::Default, - { - fn maybe_default( self : &Self ) -> T - { - T::default() - } - } - ( &::core::marker::PhantomData::< i32 > ).maybe_default() - }; - val - }; - let username = if self.storage.username.is_some() + _phantom : core::marker::PhantomData, + } + } + } + + impl< Context, Formed, End, > former::FormerDefinition for UserProfileFormerDefinition< Context, Formed, End, > + where + End : former::FormingEnd< UserProfileFormerDefinitionTypes< Context, Formed, > >, + { + type Types = UserProfileFormerDefinitionTypes< Context, Formed, >; + type End = End; + type Storage = UserProfileFormerStorage< >; + type Formed = Formed; + type Context = Context; + } + + impl< Context, Formed, > former::FormerMutator for UserProfileFormerDefinitionTypes< Context, Formed, > + where + {} + + pub struct UserProfileFormerStorage< > + where + { + pub age : ::core::option::Option< i32 >, + pub username : ::core::option::Option< String >, + pub bio_optional : Option< String >, + } + + impl< > ::core::default::Default for UserProfileFormerStorage< > + where + { + #[ inline( always ) ] + fn default() -> Self { - self.storage.username.take().unwrap() + Self + { + age : ::core::option::Option::None, + username : ::core::option::Option::None, + bio_optional : ::core::option::Option::None, + } } - else + } + + impl< > former::Storage for UserProfileFormerStorage< > + where + { + type Formed = UserProfile< >; + } + + impl< > former::StoragePreform for UserProfileFormerStorage< > + where + { + type Preformed = UserProfile< >; + fn preform(mut self) -> Self::Preformed { - let val : String = + let age = if self.age.is_some() + { + self.age.take().unwrap() + } + else { - trait NotDefault< T > - { - fn maybe_default( self : &Self ) -> T { panic!( "Field 'username' isn't initialized" ) } - } - trait WithDefault< T > { - fn maybe_default( self : &Self ) -> T; + trait MaybeDefault< T > + { + fn maybe_default(self : &Self) -> T + { + panic!("Field 'age' isn't initialized") + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > + {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, + { + fn maybe_default(self : &Self) -> T + { + T::default() + } + } + (&::core::marker::PhantomData::< i32 >).maybe_default() } - impl< T > NotDefault< T > for &::core::marker::PhantomData< T > {} - impl< T > WithDefault< T > for ::core::marker::PhantomData< T > - where - T : ::core::default::Default, + }; + let username = if self.username.is_some() + { + self.username.take().unwrap() + } + else + { { - fn maybe_default( self : &Self ) -> T + trait MaybeDefault< T > + { + fn maybe_default(self : &Self) -> T + { + panic!("Field 'username' isn't initialized") + } + } + impl< T > MaybeDefault< T > for &::core::marker::PhantomData< T > + {} + impl< T > MaybeDefault< T > for ::core::marker::PhantomData< T > + where T : ::core::default::Default, { - T::default() + fn maybe_default(self : &Self) -> T + { + T::default() + } } + (&::core::marker::PhantomData::< String >).maybe_default() } - ( &::core::marker::PhantomData::< String > ).maybe_default() }; - val - }; - let bio_optional = if self.storage.bio_optional.is_some() - { - Option::Some( self.storage.bio_optional.take().unwrap() ) + let bio_optional = if self.bio_optional.is_some() + { + ::core::option::Option::Some(self.bio_optional.take().unwrap()) + } + else + { + ::core::option::Option::None + }; + let result = UserProfile::<> + { + age, + username, + bio_optional, + }; + return result; } - else - { - Option::None - }; - let result = UserProfile - { - age, - username, - bio_optional, - }; - return result; } - #[ inline( always ) ] - pub fn perform( self ) -> UserProfile + pub struct UserProfileFormer< Definition = UserProfileFormerDefinition< (), UserProfile< >, former::ReturnPreformed >, > + where + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, { - let result = self.form(); - return result; + pub storage : Definition::Storage, + pub context : core::option::Option< Definition::Context >, + pub on_end : core::option::Option< Definition::End >, } - #[ inline( always ) ] - pub fn new() -> UserProfileFormer< UserProfile, former::ReturnFormed > + impl< Definition, > UserProfileFormer< Definition, > + where + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, Definition::Types : former::FormerDefinitionTypes< Storage = UserProfileFormerStorage< > >, { - UserProfileFormer::< UserProfile, former::ReturnFormed >::begin_coercing( None, former::ReturnFormed ) - } + #[ inline( always ) ] + pub fn new(on_end : Definition::End) -> Self + { + Self::begin_coercing(None, None, on_end) + } - #[ inline( always ) ] - pub fn begin_coercing - ( - context : Option< Context >, - on_end : End, - ) -> Self - { - Self + #[ inline( always ) ] + pub fn new_coercing< IntoEnd >(end : IntoEnd) -> Self + where IntoEnd : Into< Definition::End >, { - storage : core::default::Default::default(), - context : context, - on_end : Option::Some( on_end ), + Self::begin_coercing(None, None, end,) } - } - #[ inline( always ) ] - pub fn end( mut self ) -> Context - { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - let formed = self.form(); - on_end.call( formed, context ) + #[ inline( always ) ] + pub fn begin(mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, on_end : ::End,) -> Self + { + if storage.is_none() + { + storage = Some(::core::default::Default::default()); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some(on_end), + } + } + + #[ inline( always ) ] + pub fn begin_coercing< IntoEnd >(mut storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, on_end : IntoEnd,) -> Self + where IntoEnd : ::core::convert::Into< ::End >, + { + if storage.is_none() + { + storage = Some(::core::default::Default::default()); + } + Self + { + storage : storage.unwrap(), + context : context, + on_end : ::core::option::Option::Some(::core::convert::Into::into(on_end)), + } + } + + #[ inline( always ) ] + pub fn form(self) -> ::Formed + { + self.end() + } + + #[ inline( always ) ] + pub fn end(mut self) -> ::Formed + { + let on_end = self.on_end.take().unwrap(); + let mut context = self.context.take(); + ::form_mutation(&mut self.storage, &mut context); + former::FormingEnd::::call(&on_end, self.storage, context) + } + + #[ inline( always ) ] + pub fn age< Src >(mut self, src : Src) -> Self + where Src : ::core::convert::Into< i32 >, + { + debug_assert!(self.storage.age.is_none()); + self.storage.age = ::core::option::Option::Some(::core::convert::Into::into(src)); + self + } + + #[ inline( always ) ] + pub fn username< Src >(mut self, src : Src) -> Self + where Src : ::core::convert::Into< String >, + { + debug_assert!(self.storage.username.is_none()); + self.storage.username = ::core::option::Option::Some(::core::convert::Into::into(src)); + self + } + + #[ inline( always ) ] + pub fn bio_optional< Src >(mut self, src : Src) -> Self + where Src : ::core::convert::Into< String >, + { + debug_assert!(self.storage.bio_optional.is_none()); + self.storage.bio_optional = ::core::option::Option::Some(::core::convert::Into::into(src)); + self + } } - #[ inline ] - pub fn age< Src >( mut self, src : Src ) -> Self + impl< Definition, > UserProfileFormer< Definition, > where - Src : Into< i32 >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< >, Formed = UserProfile< > >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, { - debug_assert!( self.storage.age.is_none() ); - self.storage.age = Option::Some( src.into() ); - self + pub fn preform(self) -> ::Formed + { + former::StoragePreform::preform(self.storage) + } } - #[ inline ] - pub fn username< Src >( mut self, src : Src ) -> Self + impl< Definition, > UserProfileFormer< Definition, > where - Src : Into< String >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< >, Formed = UserProfile< >, >, { - debug_assert!( self.storage.username.is_none() ); - self.storage.username = Option::Some( src.into() ); - self + + #[ inline( always ) ] + pub fn perform(self) -> Definition::Formed + { + let result = self.form(); + return result; + } } - #[ inline ] - pub fn bio_optional< Src >( mut self, src : Src ) -> Self + impl< Definition > former::FormerBegin< Definition > for UserProfileFormer< Definition, > where - Src : Into< String >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, { - debug_assert!( self.storage.bio_optional.is_none() ); - self.storage.bio_optional = Option::Some( src.into() ); - self + #[ inline( always ) ] + fn former_begin(storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, on_end : Definition::End,) -> Self + { + debug_assert!(storage.is_none()); + Self::begin(None, context, on_end) + } } -} -let profile = UserProfile::former() -.age( 30 ) -.username( "JohnDoe".to_string() ) -.bio_optional( "Software Developer".to_string() ) -.form(); + pub type UserProfileAsSubformer< Superformer, End > = + UserProfileFormer< UserProfileFormerDefinition< Superformer, Superformer, End, >, >; + + pub trait UserProfileAsSubformerEnd< SuperFormer > + where + Self : former::FormingEnd< UserProfileFormerDefinitionTypes< SuperFormer, SuperFormer >, >, {} -dbg!( &profile ); -// Expected output: -// &profile = UserProfile { -// age: 30, -// username: "JohnDoe", -// bio_optional: Some("Software Developer"), -// } + impl< SuperFormer, T > UserProfileAsSubformerEnd< SuperFormer > for T + where + Self : former::FormingEnd< UserProfileFormerDefinitionTypes< SuperFormer, SuperFormer >, >, + {} + + let profile = UserProfile::former() + .age( 30 ) + .username( "JohnDoe".to_string() ) + .bio_optional( "Software Developer".to_string() ) // Optionally provide a bio + .form(); + dbg!( &profile ); + + // Expected output: + // + // &profile = UserProfile { + // age: 30, + // username: "JohnDoe", + // bio_optional: Some("Software Developer"), + // } +} ``` -### Custom and Alternative Setters +## Custom and Alternative Setters With help of `Former`, it is possible to define multiple versions of a setter for a single field, providing the flexibility to include custom logic within the setter methods. This feature is particularly useful when you need to preprocess data or enforce specific constraints before assigning values to fields. Custom setters should have unique names to differentiate them from the default setters generated by `Former`, allowing for specialized behavior while maintaining clarity in your code. @@ -327,7 +487,7 @@ assert_eq!( example.word, "Hello!".to_string() ); In the example above showcases a custom alternative setter, `word_exclaimed`, which appends an exclamation mark to the input string before storing it. This approach allows for additional processing or validation of the input data without compromising the simplicity of the builder pattern. -### Custom Setter Overriding +## Custom Setter Overriding But it's also possible to completely override setter and write its own from scratch. For that use attribe `[ setter( false ) ]` to disable setter. @@ -417,11 +577,40 @@ The above code snippet showcases the `Former` crate's ability to initialize stru This approach significantly simplifies struct construction, particularly for complex types or where defaults beyond the `Default` trait's capability are required. By utilizing the `default` attribute, developers can ensure their structs are initialized safely and predictably, enhancing code clarity and maintainability. +## Concept of Storage and Former + +Storage is temporary storage structure holds the intermediate state of an object during its construction. + +Purpose of Storage: + +- **Intermediate State Holding**: Storage serves as a temporary repository for all the partially set properties and data of the object being formed. This functionality is essential in situations where the object's completion depends on multiple, potentially complex stages of configuration. +- **Decoupling Configuration from Instantiation**: Storage separates the accumulation of configuration states from the actual creation of the final object. This separation fosters cleaner, more maintainable code, allowing developers to apply configurations in any order and manage interim states more efficiently, without compromising the integrity of the final object. + +Storage is not just a passive container; it is an active part of a larger ecosystem that includes the former itself, a context, and a callback (often referred to as `FormingEnd`): + +- **Former as an Active Manager**: The former is responsible for managing the storage, utilizing it to keep track of the object's evolving configuration. It orchestrates the formation process by handling intermediate states and preparing the object for its final form. +- **Contextual Flexibility**: The context associated with the former adds an additional layer of flexibility, allowing the former to adjust its behavior based on the broader circumstances of the object's formation. This is particularly useful when the forming process involves conditions or states external to the object itself. +- **FormingEnd Callback**: The `FormingEnd` callback is a dynamic component that defines the final steps of the forming process. It can modify the storage based on final adjustments, validate the object's readiness, or integrate the object into a larger structure, such as embedding it as a subformer within another structure. + +These elements work in concert to ensure that the forming process is not only about building an object step-by-step but also about integrating it seamlessly into larger, more complex structures or systems. The `Former` framework, with its sophisticated management of storage, context, and callbacks, enables a highly flexible and reusable approach to object formation, making it ideal for scenarios where objects are part of nested or interdependent systems. + +## Comcept of Definitions + +Definitions are utilized to encapsulate and manage generic parameters efficiently and avoid passing each parameter individually. + +Two key definition Traits: + +1. **`FormerDefinitionTypes`**: + - This trait outlines the essential components involved in the formation process, including the types of storage, the form being created, and the context used. It focuses on the types involved rather than the termination of the formation process. +2. **`FormerDefinition`**: + - Building upon `FormerDefinitionTypes`, this trait incorporates the `FormingEnd` callback, linking the formation types with a definitive ending. It specifies how the formation process should conclude, which may involve validations, transformations, or integrations into larger structures. + - The inclusion of the `End` type parameter specifies the end conditions of the formation process, effectively connecting the temporary state held in storage to its ultimate form. + ## Concept of subformer Subformers are specialized builders used within the `Former` framework to construct nested or collection-based data structures like vectors, hash maps, and hash sets. They simplify the process of adding elements to these structures by providing a fluent interface that can be seamlessly integrated into the overall builder pattern of a parent struct. This approach allows for clean and intuitive initialization of complex data structures, enhancing code readability and maintainability. -### Types of Setters +## Types of Setters It's crucial to understand the differences among subform setters, container setters, and scalar setters: @@ -434,7 +623,7 @@ It's crucial to understand the differences among subform setters, container sett Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required. -### Subformer example: Building a Vector +## Subformer example: Building a Vector The following example illustrates how to use a `VectorSubformer` to construct a `Vec` field within a struct. The subformer enables adding elements to the vector with a fluent interface, streamlining the process of populating collection fields within structs. @@ -461,7 +650,7 @@ assert_eq!( instance, StructWithVec { vec: vec![ "apple", "banana" ] } ); # } ``` -### Subformer example: Building a Hashmap +## Subformer example: Building a Hashmap This example demonstrates the use of a `HashMapSubformer` to build a hash map within a struct. The subformer provides a concise way to insert key-value pairs into the map, making it easier to manage and construct hash map fields. @@ -490,7 +679,7 @@ assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); # } ``` -### Subformer example: Building a Hashset +## Subformer example: Building a Hashset In the following example, a `HashSetSubformer` is utilized to construct a hash set within a struct. This illustrates the convenience of adding elements to a set using the builder pattern facilitated by subformers. @@ -519,7 +708,7 @@ assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] }); # } ``` -### Custom Subformer +## Custom Subformer It is possible to use former of one structure to construct field of another one and integrate it into former of the last one. @@ -617,13 +806,39 @@ In this example, the `Parent` struct functions as a container for multiple `Chil This pattern of using a structure's former as a subformer within another facilitates the creation of deeply nested or complex data structures through a coherent and fluent interface, showcasing the powerful capabilities of the `Former` framework for Rust applications. -### To add to your project +## Concept of Mutator + +Provides a mechanism for mutating the context and storage just before the forming process is completed. + +The `FormerMutator` trait allows for the implementation of custom mutation logic on the internal state +of an entity (context and storage) just before the final forming operation is completed. This mutation +occurs immediately before the `FormingEnd` callback is invoked. + +Use cases of Mutator + +- Applying last-minute changes to the data being formed. +- Setting or modifying properties that depend on the final state of the storage or context. +- Storage-specific fields which are not present in formed structure. + +## Mutator vs `FormingEnd` + +Unlike `FormingEnd`, which is responsible for integrating and finalizing the formation process of a field within +a parent former, `form_mutation` directly pertains to the entity itself. This method is designed to be independent +of whether the forming process is occurring within the context of a superformer or if the structure is a standalone +or nested field. This makes `form_mutation` suitable for entity-specific transformations that should not interfere +with the hierarchical forming logic managed by `FormingEnd`. + +## Example: Mutator + + + +## To add to your project ```sh cargo add former ``` -### Try out from the repository +## Try out from the repository ```sh git clone https://github.com/Wandalen/wTools diff --git a/module/core/former/examples/former_custom_setter_overriden.rs b/module/core/former/examples/former_custom_setter_overriden.rs index c9e7ae98b2..4723ab16e2 100644 --- a/module/core/former/examples/former_custom_setter_overriden.rs +++ b/module/core/former/examples/former_custom_setter_overriden.rs @@ -3,8 +3,6 @@ //! For that use attribe `[ setter( false ) ]` to disable setter. In the example, the default setter for `word` is disabled, and a custom setter is defined to automatically append an exclamation mark to the string. This method allows for complete control over the data assignment process, enabling the inclusion of any necessary logic or validation steps. //! -// xxx : outdated description - #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] fn main() {} diff --git a/module/core/former/examples/former_trivial_expaned.rs b/module/core/former/examples/former_trivial_expaned.rs index 222d12a64c..984f8811cb 100644 --- a/module/core/former/examples/former_trivial_expaned.rs +++ b/module/core/former/examples/former_trivial_expaned.rs @@ -45,6 +45,8 @@ fn main() } } + // = entity to + impl< Definition > former::EntityToFormer< Definition > for UserProfile< > where Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, @@ -65,6 +67,8 @@ fn main() type Definition = UserProfileFormerDefinition< Context, Formed, End >; } + // = definition + #[derive(Debug)] pub struct UserProfileFormerDefinitionTypes< Context = (), Formed = UserProfile< >, > where @@ -126,6 +130,8 @@ fn main() where {} + // = storage + pub struct UserProfileFormerStorage< > where { @@ -336,7 +342,6 @@ fn main() impl< Definition, > UserProfileFormer< Definition, > where Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< >, Formed = UserProfile< > >, - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, { pub fn preform(self) -> ::Formed { @@ -348,7 +353,6 @@ fn main() where Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< >, Formed = UserProfile< >, >, { - #[ inline( always ) ] pub fn perform(self) -> Definition::Formed { @@ -369,6 +373,8 @@ fn main() } } + // = as subformer + pub type UserProfileAsSubformer< Superformer, End > = UserProfileFormer< UserProfileFormerDefinition< Superformer, Superformer, End, >, >; @@ -381,6 +387,8 @@ fn main() Self : former::FormingEnd< UserProfileFormerDefinitionTypes< SuperFormer, SuperFormer >, >, {} + // = end + let profile = UserProfile::former() .age( 30 ) .username( "JohnDoe".to_string() ) diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 8968829802..8655bed4b7 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -837,10 +837,6 @@ where format!( "{}", qt!{ #typ } ), field_ident, field_ident, - // field_ident, - // format!( "{}", qt!{ #( #params, )* } ), - // format!( "{}", qt!{ #( #params, )* } ), - // former_assign_end, ); println!( "{hint}" ); } From 924186fa7ffe020cbabc973582b7661bb810b11f Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 02:22:38 +0300 Subject: [PATCH 458/533] former : cleaning --- module/core/former/Readme.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index b77e16ea4c..a0eb9dec3f 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -86,6 +86,8 @@ fn main() } } + // = entity to + impl< Definition > former::EntityToFormer< Definition > for UserProfile< > where Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, @@ -106,6 +108,8 @@ fn main() type Definition = UserProfileFormerDefinition< Context, Formed, End >; } + // = definition + #[derive(Debug)] pub struct UserProfileFormerDefinitionTypes< Context = (), Formed = UserProfile< >, > where @@ -167,6 +171,8 @@ fn main() where {} + // = storage + pub struct UserProfileFormerStorage< > where { @@ -377,7 +383,6 @@ fn main() impl< Definition, > UserProfileFormer< Definition, > where Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< >, Formed = UserProfile< > >, - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, { pub fn preform(self) -> ::Formed { @@ -389,7 +394,6 @@ fn main() where Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< >, Formed = UserProfile< >, >, { - #[ inline( always ) ] pub fn perform(self) -> Definition::Formed { @@ -410,6 +414,8 @@ fn main() } } + // = as subformer + pub type UserProfileAsSubformer< Superformer, End > = UserProfileFormer< UserProfileFormerDefinition< Superformer, Superformer, End, >, >; @@ -422,6 +428,8 @@ fn main() Self : former::FormingEnd< UserProfileFormerDefinitionTypes< SuperFormer, SuperFormer >, >, {} + // = end + let profile = UserProfile::former() .age( 30 ) .username( "JohnDoe".to_string() ) From 141cfa454d9b01bfc273f720e25b13bd38b0133e Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 02:28:14 +0300 Subject: [PATCH 459/533] former : cleaning --- Cargo.toml | 4 ++-- module/core/former/Cargo.toml | 2 +- module/core/former_meta/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index baff3b3f0e..b7e12b0f02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -200,7 +200,7 @@ path = "module/core/for_each" default-features = false [workspace.dependencies.former] -version = "~0.16.0" +version = "~1.0.0" path = "module/core/former" default-features = false @@ -210,7 +210,7 @@ version = "=0.15.0" default-features = false [workspace.dependencies.former_meta] -version = "~0.14.0" +version = "~1.0.0" path = "module/core/former_meta" default-features = false diff --git a/module/core/former/Cargo.toml b/module/core/former/Cargo.toml index f8a90a2d70..09489d9b38 100644 --- a/module/core/former/Cargo.toml +++ b/module/core/former/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former" -version = "0.16.0" +version = "1.0.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/former_meta/Cargo.toml b/module/core/former_meta/Cargo.toml index 87f531a9f9..4bb60c3283 100644 --- a/module/core/former_meta/Cargo.toml +++ b/module/core/former_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former_meta" -version = "0.14.0" +version = "1.0.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From fc745e2bb96d341d3d693d3bc44f518829a6122e Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 08:33:38 +0300 Subject: [PATCH 460/533] former : examples and cleaning --- module/core/former/Readme.md | 400 +++++++++++++----- .../former_custom_container_setter.rs | 13 +- .../former/examples/former_custom_mutator.rs | 77 ++++ .../examples/former_custom_scalar_setter.rs | 10 +- .../examples/former_custom_subform_setter.rs | 15 +- .../examples/former_custom_subform_setter2.rs | 11 +- .../former/examples/former_many_fields.rs | 4 +- .../examples/former_subformer_hashmap.rs | 7 +- .../examples/former_subformer_hashset.rs | 9 +- .../examples/former_subformer_vector.rs | 5 +- module/core/former/src/forming.rs | 4 +- .../former_meta/src/derive_former/field.rs | 4 +- 12 files changed, 411 insertions(+), 148 deletions(-) create mode 100644 module/core/former/examples/former_custom_mutator.rs diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index a0eb9dec3f..f0c828e4d2 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -618,7 +618,7 @@ Two key definition Traits: Subformers are specialized builders used within the `Former` framework to construct nested or collection-based data structures like vectors, hash maps, and hash sets. They simplify the process of adding elements to these structures by providing a fluent interface that can be seamlessly integrated into the overall builder pattern of a parent struct. This approach allows for clean and intuitive initialization of complex data structures, enhancing code readability and maintainability. -## Types of Setters +## Types of Setters / Subformers It's crucial to understand the differences among subform setters, container setters, and scalar setters: @@ -630,32 +630,32 @@ It's crucial to understand the differences among subform setters, container sett Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required. - ## Subformer example: Building a Vector The following example illustrates how to use a `VectorSubformer` to construct a `Vec` field within a struct. The subformer enables adding elements to the vector with a fluent interface, streamlining the process of populating collection fields within structs. ```rust -# #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -# #[ cfg( not( feature = "no_std" ) ) ] -# { - -#[ derive( Debug, PartialEq, former::Former ) ] -pub struct StructWithVec +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +fn main() { - #[ container( definition = former::VectorSubformer ) ] - vec : Vec< &'static str >, -} -let instance = StructWithVec::former() -.vec() - .push( "apple" ) - .push( "banana" ) - .end() -.form(); + #[ derive( Debug, PartialEq, former::Former ) ] + pub struct StructWithVec + { + #[ container ] + vec : Vec< &'static str >, + } -assert_eq!( instance, StructWithVec { vec: vec![ "apple", "banana" ] } ); -# } + let instance = StructWithVec::former() + .vec() + .add( "apple" ) + .add( "banana" ) + .end() + .form(); + + assert_eq!( instance, StructWithVec { vec: vec![ "apple", "banana" ] } ); + +} ``` ## Subformer example: Building a Hashmap @@ -663,28 +663,27 @@ assert_eq!( instance, StructWithVec { vec: vec![ "apple", "banana" ] } ); This example demonstrates the use of a `HashMapSubformer` to build a hash map within a struct. The subformer provides a concise way to insert key-value pairs into the map, making it easier to manage and construct hash map fields. ```rust -# #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -# #[ cfg( not( feature = "no_std" ) ) ] -# { +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +fn main() +{ + use test_tools::exposed::*; -use test_tools::exposed::*; + #[ derive( Debug, PartialEq, former::Former ) ] + pub struct StructWithMap + { + #[ container ] + map : collection_tools::HashMap< &'static str, &'static str >, + } -#[ derive( Debug, PartialEq, former::Former ) ] -pub struct StructWithMap -{ - #[ container( definition = former::HashMapSubformer ) ] - map : std::collections::HashMap< &'static str, &'static str >, + let struct1 = StructWithMap::former() + .map() + .add( ( "a", "b" ) ) + .add( ( "c", "d" ) ) + .end() + .form() + ; + assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); } - -let struct1 = StructWithMap::former() -.map() - .insert( "a", "b" ) - .insert( "c", "d" ) - .end() -.form() -; -assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); -# } ``` ## Subformer example: Building a Hashset @@ -692,51 +691,201 @@ assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); In the following example, a `HashSetSubformer` is utilized to construct a hash set within a struct. This illustrates the convenience of adding elements to a set using the builder pattern facilitated by subformers. ```rust -# #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -# #[ cfg( not( feature = "no_std" ) ) ] -# { +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +fn main() +{ + use test_tools::exposed::*; -use test_tools::exposed::*; + #[ derive( Debug, PartialEq, former::Former ) ] + pub struct StructWithSet + { + #[ container ] + set : collection_tools::HashSet< &'static str >, + } + + let instance = StructWithSet::former() + .set() + .add( "apple" ) + .add( "banana" ) + .end() + .form(); + + assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] }); -#[ derive( Debug, PartialEq, former::Former ) ] -pub struct StructWithSet -{ - #[ container( definition = former::HashSetSubformer ) ] - set : std::collections::HashSet< &'static str >, } +``` -let instance = StructWithSet::former() -.set() - .insert("apple") - .insert("banana") - .end() -.form(); +## Custom Scalar Setter -assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] }); -# } +This example demonstrates the implementation of a scalar setter using the `Former` trait in Rust. Unlike the more complex subform and container setters shown in previous examples, this example focuses on a straightforward approach to directly set a scalar value within a parent entity. The `Parent` struct manages a `HashMap` of `Child` entities, and the scalar setter is used to set the entire `HashMap` directly. + +The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. + +```rust +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +fn main() +{ + use collection_tools::HashMap; + use former::Former; + + // Child struct with Former derived for builder pattern support + #[ derive( Debug, PartialEq, Former ) ] + // #[ debug ] + pub struct Child + { + name : String, + description : String, + } + + // Parent struct to hold children + #[ derive( Debug, PartialEq, Former ) ] + // #[ debug ] + pub struct Parent + { + // Use `hint = true` to gennerate sketch of setter. + #[ scalar( setter = false, hint = false ) ] + children : HashMap< String, Child >, + } + + impl< Definition > ParentFormer< Definition > + where + Definition : former::FormerDefinition< Storage = ParentFormerStorage >, + { + #[ inline ] + pub fn children< Src >( mut self, src : Src ) -> Self + where + Src : ::core::convert::Into< HashMap< String, Child > >, + { + debug_assert!( self.storage.children.is_none() ); + self.storage.children = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + self + } + } + + let echo = Child { name : "echo".to_string(), description : "prints all subjects and properties".to_string() }; + let exit = Child { name : "exit".to_string(), description : "just exit".to_string() }; + let mut children = HashMap::new(); + children.insert( echo.name.clone(), echo ); + children.insert( exit.name.clone(), exit ); + let ca = Parent::former() + .children( children ) + .form(); + + dbg!( &ca ); + // > &ca = Parent { + // > child: { + // > "echo": Child { + // > name: "echo", + // > description: "prints all subjects and properties", + // > }, + // > "exit": Child { + // > name: "exit", + // > description: "just exit", + // > }, + // > }, + // > } +} ``` -## Custom Subformer +In this example, the `Parent` struct functions as a container for multiple `Child` structs, each identified by a unique child name. The `ParentFormer` implements a custom method `child`, which serves as a subformer for adding `Child` instances into the `Parent`. -It is possible to use former of one structure to construct field of another one and integrate it into former of the last one. +- **Child Definition**: Each `Child` consists of a `name` and a `description`, and we derive `Former` to enable easy setting of these properties using a builder pattern. +- **Parent Definition**: It holds a collection of `Child` objects in a `HashMap`. The `#[setter(false)]` attribute is used to disable the default setter, and a custom method `child` is defined to facilitate the addition of children with specific attributes. +- **Custom Subformer Integration**: The `child` method in the `ParentFormer` initializes a `ChildFormer` with a closure that integrates the `Child` into the `Parent`'s `child` map upon completion. -The example below illustrates how to incorporate the builder pattern of one structure as a subformer in another, enabling nested struct initialization within a single fluent interface. +This pattern of using a structure's former as a subformer within another facilitates the creation of deeply nested or complex data structures through a coherent and fluent interface, showcasing the powerful capabilities of the `Former` framework for Rust applications. + +## Custom Container Setter +This example demonstrates the use of container setters to manage complex nested data structures with the `Former` trait, focusing on a parent-child relationship structured around a container `HashMap`. Unlike typical builder patterns that add individual elements using subform setters, this example uses a container setter to manage the entire collection of children. -Example of how to use former of another structure as subformer of former of current one -function `child` integrate `ChildFormer` into `ParentFormer`. +The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. ```rust -# #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -# { +// Ensure the example only compiles when the appropriate features are enabled. +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +fn main() +{ + use collection_tools::HashMap; + use former::Former; + + // Child struct with Former derived for builder pattern support + #[ derive( Debug, PartialEq, Former ) ] + // #[ debug ] + pub struct Child + { + name : String, + description : String, + } + + // Parent struct to hold children + #[ derive( Debug, PartialEq, Former ) ] + // #[ debug ] + pub struct Parent + { + // Use `hint = true` to gennerate sketch of setter. + #[ scalar( setter = false, hint = false ) ] + children : HashMap< String, Child >, + } + + impl< Definition > ParentFormer< Definition > + where + Definition : former::FormerDefinition< Storage = ParentFormerStorage >, + { + #[ inline ] + pub fn children< Src >( mut self, src : Src ) -> Self + where + Src : ::core::convert::Into< HashMap< String, Child > >, + { + debug_assert!( self.storage.children.is_none() ); + self.storage.children = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + self + } + } + + let echo = Child { name : "echo".to_string(), description : "prints all subjects and properties".to_string() }; + let exit = Child { name : "exit".to_string(), description : "just exit".to_string() }; + let mut children = HashMap::new(); + children.insert( echo.name.clone(), echo ); + children.insert( exit.name.clone(), exit ); + let ca = Parent::former() + .children( children ) + .form(); + dbg!( &ca ); + // > &ca = Parent { + // > child: { + // > "echo": Child { + // > name: "echo", + // > description: "prints all subjects and properties", + // > }, + // > "exit": Child { + // > name: "exit", + // > description: "just exit", + // > }, + // > }, + // > } +} +``` + +## Custom Subform Setter + +This example illustrates the implementation of nested builder patterns in Rust using the `Former` trait, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. + +The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. + +```rust + +// Ensure the example only compiles when the appropriate features are enabled. +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { - use std::collections::HashMap; + use collection_tools::HashMap; use former::Former; // Child struct with Former derived for builder pattern support #[ derive( Debug, PartialEq, Former ) ] + // #[ debug ] pub struct Child { name : String, @@ -745,38 +894,40 @@ fn main() // Parent struct to hold children #[ derive( Debug, PartialEq, Former ) ] + // #[ debug ] pub struct Parent { - #[ scalar( setter = false ) ] + // Use `hint = true` to gennerate sketch of setter. + #[ subform( setter = false, hint = false ) ] child : HashMap< String, Child >, } - // Use ChildFormer as custom subformer for ParentFormer to add children by name. - impl< Context, End > ParentFormer< Context, End > + /// Initializes and configures a subformer for adding named child entities. This method leverages an internal function + /// to create and return a configured subformer instance. It allows for the dynamic addition of children with specific names, + /// integrating them into the formation process of the parent entity. + /// + impl< Definition > ParentFormer< Definition > where - End : former::FormingEnd< Parent, Context >, + Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, { - pub fn child< IntoName >( self, name : IntoName ) -> ChildFormer< Self, impl former::FormingEnd< Child, Self > > - where - IntoName: core::convert::Into< String >, + + #[ inline( always ) ] + pub fn child( self, name : &str ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > { - let on_end = | child : Child, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - if let Some( ref mut children ) = super_former.storage.child - { - children.insert( child.name.clone(), child ); - } - else - { - let mut children: HashMap< String, Child > = Default::default(); - children.insert( child.name.clone(), child ); - super_former.storage.child = Some( children ); - } - super_former - }; - let former = ChildFormer::begin_coercing( None, Some( self ), on_end ); - former.name( name ) + self._child_add::< ChildFormer< _ >, _, >() + .name( name ) + } + + } + + // Required to define how `value` is converted into pair `( key, value )` + impl former::ValToElement< HashMap< String, Child > > for Child + { + type Element = ( String, Child ); + #[ inline( always ) ] + fn val_to_element( self ) -> Self::Element + { + ( self.name.clone(), self ) } } @@ -803,17 +954,8 @@ fn main() // > }, // > } } -# } ``` -In this example, the `Parent` struct functions as a container for multiple `Child` structs, each identified by a unique child name. The `ParentFormer` implements a custom method `child`, which serves as a subformer for adding `Child` instances into the `Parent`. - -- **Child Definition**: Each `Child` consists of a `name` and a `description`, and we derive `Former` to enable easy setting of these properties using a builder pattern. -- **Parent Definition**: It holds a collection of `Child` objects in a `HashMap`. The `#[setter(false)]` attribute is used to disable the default setter, and a custom method `child` is defined to facilitate the addition of children with specific attributes. -- **Custom Subformer Integration**: The `child` method in the `ParentFormer` initializes a `ChildFormer` with a closure that integrates the `Child` into the `Parent`'s `child` map upon completion. - -This pattern of using a structure's former as a subformer within another facilitates the creation of deeply nested or complex data structures through a coherent and fluent interface, showcasing the powerful capabilities of the `Former` framework for Rust applications. - ## Concept of Mutator Provides a mechanism for mutating the context and storage just before the forming process is completed. @@ -828,6 +970,21 @@ Use cases of Mutator - Setting or modifying properties that depend on the final state of the storage or context. - Storage-specific fields which are not present in formed structure. +## Storage-Specific Fields + +Storage-specific fields are intermediate fields that exist only in the storage structure during +the forming process. These fields are not present in the final formed structure but are instrumental +in complex forming operations, such as conditional mutations, temporary state tracking, or accumulations. + +These fields are used to manage intermediate data or state that aids in the construction +of the final object but does not necessarily have a direct representation in the object's schema. For +instance, counters, flags, or temporary computation results that determine the final state of the object. + +The `FormerMutator` trait facilitates the implementation of custom mutation logic. It acts on the internal +state (context and storage) just before the final forming operation is completed, right before the `FormingEnd` +callback is invoked. This trait is crucial for making last-minute adjustments or computations based on the +accumulated state in the storage. + ## Mutator vs `FormingEnd` Unlike `FormingEnd`, which is responsible for integrating and finalizing the formation process of a field within @@ -838,7 +995,56 @@ with the hierarchical forming logic managed by `FormingEnd`. ## Example: Mutator - +This example illustrates how to use the `FormerMutator` trait for implementing custom mutations +and demonstrates the concept of storage-specific fields in the forming process. + +In this example, the fields `a` and `b` are defined only within the storage and used +within the custom mutator to enrich or modify the field `c` of the formed entity. This approach +allows for a richer and more flexible formation logic that can adapt based on the intermediate state +held within the storage. + +```rust +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + use former::Former; + + #[ derive( Debug, PartialEq, Former ) ] + #[ storage_fields( a : i32, b : Option< String > ) ] + #[ mutator( custom = true ) ] + pub struct Struct1 + { + c : String, + } + + // = former mutator + + impl< Context, Formed > former::FormerMutator + for Struct1FormerDefinitionTypes< Context, Formed > + { + Mutates the context and storage of the entity just before the formation process completes. + #[ inline ] + fn form_mutation( storage : &mut Self::Storage, _context : &mut ::core::option::Option< Self::Context > ) + { + storage.a.get_or_insert_with( Default::default ); + storage.b.get_or_insert_with( Default::default ); + storage.c = Some( format!( "{:?} - {}", storage.a.unwrap(), storage.b.as_ref().unwrap() ) ); + } + } + + let got = Struct1::former().a( 13 ).b( "abc" ).c( "def" ).form(); + let exp = Struct1 + { + c : "13 - abc".to_string(), + }; + assert_eq!( got, exp ); + dbg!( got ); + // > got = Struct1 { + // > c: "13 - abc", + // > } + +} +``` ## To add to your project diff --git a/module/core/former/examples/former_custom_container_setter.rs b/module/core/former/examples/former_custom_container_setter.rs index 8443e47098..381b047377 100644 --- a/module/core/former/examples/former_custom_container_setter.rs +++ b/module/core/former/examples/former_custom_container_setter.rs @@ -3,8 +3,6 @@ //! //! This example demonstrates the use of container setters to manage complex nested data structures with the `Former` trait, focusing on a parent-child relationship structured around a container `HashMap`. Unlike typical builder patterns that add individual elements using subform setters, this example uses a container setter to manage the entire collection of children. //! -//! #### Custom Subform Setter -//! //! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. //! //! #### Types of Setters @@ -20,16 +18,13 @@ //! Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required. //! -// zzz : duplicate into readme - -#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] -fn main() {} - // Ensure the example only compiles when the appropriate features are enabled. -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +fn main() {} +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { - use std::collections::HashMap; + use collection_tools::HashMap; use former::Former; // Child struct with Former derived for builder pattern support diff --git a/module/core/former/examples/former_custom_mutator.rs b/module/core/former/examples/former_custom_mutator.rs new file mode 100644 index 0000000000..aba337b185 --- /dev/null +++ b/module/core/former/examples/former_custom_mutator.rs @@ -0,0 +1,77 @@ +// former_custom_mutator.rs + +//! This example illustrates how to use the `FormerMutator` trait for implementing custom mutations +//! and demonstrates the concept of storage-specific fields in the forming process. +//! +//! #### Storage-Specific Fields +//! +//! Storage-specific fields are intermediate fields that exist only in the storage structure during +//! the forming process. These fields are not present in the final formed structure but are instrumental +//! in complex forming operations, such as conditional mutations, temporary state tracking, or accumulations. +//! +//! These fields are used to manage intermediate data or state that aids in the construction +//! of the final object but does not necessarily have a direct representation in the object's schema. For +//! instance, counters, flags, or temporary computation results that determine the final state of the object. +//! +//! The `FormerMutator` trait facilitates the implementation of custom mutation logic. It acts on the internal +//! state (context and storage) just before the final forming operation is completed, right before the `FormingEnd` +//! callback is invoked. This trait is crucial for making last-minute adjustments or computations based on the +//! accumulated state in the storage. +//! +//! In this example, the fields `a` and `b` are defined only within the storage and used +//! within the custom mutator to enrich or modify the field `c` of the formed entity. This approach +//! allows for a richer and more flexible formation logic that can adapt based on the intermediate state +//! held within the storage. +//! +//! #### Differences from `FormingEnd` +//! +//! Unlike `FormingEnd`, which is primarily responsible for integrating and finalizing the formation process of a field +//! within a parent former, `form_mutation` directly pertains to the entity itself. This method is designed to be independent +//! of whether the forming process is occurring within the context of a superformer or if the structure is a standalone +//! or nested field. This makes `form_mutation` suitable for entity-specific transformations that should not interfere +//! with the hierarchical forming logic managed by `FormingEnd`. +//! + +#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +fn main() {} + +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + use former::Former; + + #[ derive( Debug, PartialEq, Former ) ] + #[ storage_fields( a : i32, b : Option< String > ) ] + #[ mutator( custom = true ) ] + pub struct Struct1 + { + c : String, + } + + // = former mutator + + impl< Context, Formed > former::FormerMutator + for Struct1FormerDefinitionTypes< Context, Formed > + { + //! Mutates the context and storage of the entity just before the formation process completes. + #[ inline ] + fn form_mutation( storage : &mut Self::Storage, _context : &mut ::core::option::Option< Self::Context > ) + { + storage.a.get_or_insert_with( Default::default ); + storage.b.get_or_insert_with( Default::default ); + storage.c = Some( format!( "{:?} - {}", storage.a.unwrap(), storage.b.as_ref().unwrap() ) ); + } + } + + let got = Struct1::former().a( 13 ).b( "abc" ).c( "def" ).form(); + let exp = Struct1 + { + c : "13 - abc".to_string(), + }; + assert_eq!( got, exp ); + dbg!( got ); + // > got = Struct1 { + // > c: "13 - abc", + // > } + +} diff --git a/module/core/former/examples/former_custom_scalar_setter.rs b/module/core/former/examples/former_custom_scalar_setter.rs index 9774a8fabe..d09f3a77d9 100644 --- a/module/core/former/examples/former_custom_scalar_setter.rs +++ b/module/core/former/examples/former_custom_scalar_setter.rs @@ -3,8 +3,6 @@ //! //! This example demonstrates the implementation of a scalar setter using the `Former` trait in Rust. Unlike the more complex subform and container setters shown in previous examples, this example focuses on a straightforward approach to directly set a scalar value within a parent entity. The `Parent` struct manages a `HashMap` of `Child` entities, and the scalar setter is used to set the entire `HashMap` directly. //! -//! #### Custom Subform Setter -//! //! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. //! //! #### Types of Setters @@ -20,16 +18,14 @@ //! Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required. //! -// zzz : duplicate into readme - -#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] fn main() {} // Ensure the example only compiles when the appropriate features are enabled. -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { - use std::collections::HashMap; + use collection_tools::HashMap; use former::Former; // Child struct with Former derived for builder pattern support diff --git a/module/core/former/examples/former_custom_subform_setter.rs b/module/core/former/examples/former_custom_subform_setter.rs index b7074bdad7..d7090a74cf 100644 --- a/module/core/former/examples/former_custom_subform_setter.rs +++ b/module/core/former/examples/former_custom_subform_setter.rs @@ -3,8 +3,6 @@ //! //! This example illustrates the implementation of nested builder patterns in Rust using the `Former` trait, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. //! -//! #### Custom Subform Setter -//! //! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. //! //! #### Types of Setters @@ -20,16 +18,14 @@ //! Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required. //! -// zzz : duplicate into readme - -#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] fn main() {} // Ensure the example only compiles when the appropriate features are enabled. -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { - use std::collections::HashMap; + use collection_tools::HashMap; use former::Former; // Child struct with Former derived for builder pattern support @@ -53,8 +49,7 @@ fn main() /// Initializes and configures a subformer for adding named child entities. This method leverages an internal function /// to create and return a configured subformer instance. It allows for the dynamic addition of children with specific names, - /// integrating them into the formation process of the parent entity. After creation, the name of the child is immediately set, - /// facilitating the customization and integration of child entities within the overall structure of the parent. + /// integrating them into the formation process of the parent entity. /// impl< Definition > ParentFormer< Definition > where @@ -70,7 +65,7 @@ fn main() } - // Requored to define how `value` is converted into pair `( key, value )` + // Required to define how `value` is converted into pair `( key, value )` impl former::ValToElement< HashMap< String, Child > > for Child { type Element = ( String, Child ); diff --git a/module/core/former/examples/former_custom_subform_setter2.rs b/module/core/former/examples/former_custom_subform_setter2.rs index 60e9344f81..55092a6a28 100644 --- a/module/core/former/examples/former_custom_subform_setter2.rs +++ b/module/core/former/examples/former_custom_subform_setter2.rs @@ -22,14 +22,13 @@ // zzz : duplicate into readme -#[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] -fn main() {} - // Ensure the example only compiles when the appropriate features are enabled. -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +fn main() {} +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { - use std::collections::HashMap; + use collection_tools::HashMap; use former::Former; // Child struct with Former derived for builder pattern support @@ -120,7 +119,7 @@ fn main() } - // Requored to define how `value` is converted into pair `( key, value )` + // Required to define how `value` is converted into pair `( key, value )` impl former::ValToElement< HashMap< String, Child > > for Child { type Element = ( String, Child ); diff --git a/module/core/former/examples/former_many_fields.rs b/module/core/former/examples/former_many_fields.rs index b8f506e9d3..e275d99897 100644 --- a/module/core/former/examples/former_many_fields.rs +++ b/module/core/former/examples/former_many_fields.rs @@ -31,11 +31,11 @@ fn main() int_1 : i32, string_1 : String, vec_1 : Vec< u32 >, - hashmap_1 : std::collections::HashMap< String, String >, + hashmap_1 : collection_tools::HashMap< String, String >, int_optional_1 : core::option::Option< i32 >, string_optional_1 : Option< String >, } - let hashmap = std::collections::HashMap::from + let hashmap = collection_tools::HashMap::from ([ ( "k1".to_string(), "v1".to_string() ), ( "k2".to_string(), "v2".to_string() ), diff --git a/module/core/former/examples/former_subformer_hashmap.rs b/module/core/former/examples/former_subformer_hashmap.rs index a36cfbf06e..7087b4c395 100644 --- a/module/core/former/examples/former_subformer_hashmap.rs +++ b/module/core/former/examples/former_subformer_hashmap.rs @@ -2,10 +2,9 @@ //! This example demonstrates how to effectively employ the `Former` trait to configure a `HashMap` using a container setter. //! -#[ cfg( not( all( feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] fn main() {} - -#[ cfg( all( feature = "derive_former", not( feature = "no_std" ) ) ) ] +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { use test_tools::exposed::*; @@ -14,7 +13,7 @@ fn main() pub struct StructWithMap { #[ container ] - map : std::collections::HashMap< &'static str, &'static str >, + map : collection_tools::HashMap< &'static str, &'static str >, } let struct1 = StructWithMap::former() diff --git a/module/core/former/examples/former_subformer_hashset.rs b/module/core/former/examples/former_subformer_hashset.rs index cb496ea010..f9a823a284 100644 --- a/module/core/former/examples/former_subformer_hashset.rs +++ b/module/core/former/examples/former_subformer_hashset.rs @@ -1,11 +1,10 @@ //! -//! This example demonstrates the use of the `Former` trait to build a `std::collections::HashSet` through subforming. +//! This example demonstrates the use of the `Former` trait to build a `collection_tools::HashSet` through subforming. //! -#[ cfg( not( all( feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] fn main() {} - -#[ cfg( all( feature = "derive_former", not( feature = "no_std" ) ) ) ] +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { use test_tools::exposed::*; @@ -14,7 +13,7 @@ fn main() pub struct StructWithSet { #[ container ] - set : std::collections::HashSet< &'static str >, + set : collection_tools::HashSet< &'static str >, } let instance = StructWithSet::former() diff --git a/module/core/former/examples/former_subformer_vector.rs b/module/core/former/examples/former_subformer_vector.rs index cebaa5c131..8719c1155c 100644 --- a/module/core/former/examples/former_subformer_vector.rs +++ b/module/core/former/examples/former_subformer_vector.rs @@ -3,10 +3,9 @@ //! This example demonstrates how to employ the `Former` trait to configure a `Vec` using a container setter in a structured manner. //! -#[ cfg( not( all( feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] fn main() {} - -#[ cfg( all( feature = "derive_former", not( feature = "no_std" ) ) ) ] +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { diff --git a/module/core/former/src/forming.rs b/module/core/former/src/forming.rs index b16f631a57..7875afdb95 100644 --- a/module/core/former/src/forming.rs +++ b/module/core/former/src/forming.rs @@ -6,7 +6,7 @@ /// of an entity (context and storage) just before the final forming operation is completed. This mutation /// occurs immediately before the `FormingEnd` callback is invoked. /// -/// ## Differences from `FormingEnd` +/// #### Differences from `FormingEnd` /// /// Unlike `FormingEnd`, which is responsible for integrating and finalizing the formation process of a field within /// a parent former, `form_mutation` directly pertains to the entity itself. This method is designed to be independent @@ -14,7 +14,7 @@ /// or nested field. This makes `form_mutation` suitable for entity-specific transformations that should not interfere /// with the hierarchical forming logic managed by `FormingEnd`. /// -/// ## Use Cases +/// #### Use Cases /// /// - Applying last-minute changes to the data being formed. /// - Setting or modifying properties that depend on the final state of the storage or context. diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 8655bed4b7..b7e2da73da 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -487,9 +487,7 @@ scalar_setter_required /// Initializes and configures a subformer for adding named child entities. This method leverages an internal function /// to create and return a configured subformer instance. It allows for the dynamic addition of children with specific names, -/// integrating them into the formation process of the parent entity. After creation, the name of the child is immediately set, -/// facilitating the customization and integration of child entities within the overall structure of the parent. -/// +/// integrating them into the formation process of the parent entity. impl< Definition > {}< Definition > where From bc1c8baf70ab77ffa0c62b65f9311f0d13fef8eb Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 08:39:08 +0300 Subject: [PATCH 461/533] former : examples and cleaning --- module/core/former/examples/former_custom_subform_setter2.rs | 2 -- module/core/former/src/storage.rs | 5 ----- 2 files changed, 7 deletions(-) diff --git a/module/core/former/examples/former_custom_subform_setter2.rs b/module/core/former/examples/former_custom_subform_setter2.rs index 55092a6a28..586d69eb9d 100644 --- a/module/core/former/examples/former_custom_subform_setter2.rs +++ b/module/core/former/examples/former_custom_subform_setter2.rs @@ -20,8 +20,6 @@ //! Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required. //! -// zzz : duplicate into readme - // Ensure the example only compiles when the appropriate features are enabled. #[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] fn main() {} diff --git a/module/core/former/src/storage.rs b/module/core/former/src/storage.rs index 2a175dd7d7..9c872811b9 100644 --- a/module/core/former/src/storage.rs +++ b/module/core/former/src/storage.rs @@ -6,11 +6,6 @@ pub trait Storage : ::core::default::Default } /// zzz : write description -// pub trait StoragePreform : Storage -// { -// fn preform( self ) -> Self::Formed; -// } - pub trait StoragePreform { type Preformed; From accb6e6bdfdce63d0c5a3fe466b2a45a55e98946 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 08:46:37 +0300 Subject: [PATCH 462/533] former : examples and cleaning --- module/core/former/src/storage.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/module/core/former/src/storage.rs b/module/core/former/src/storage.rs index 9c872811b9..e021f30d3f 100644 --- a/module/core/former/src/storage.rs +++ b/module/core/former/src/storage.rs @@ -1,13 +1,34 @@ -/// zzz : write description +/// Defines the storage interface for entities being constructed using a forming pattern. +/// +/// This trait is required for any storage type that temporarily holds data during the construction +/// of an entity. It mandates the implementation of `Default`, ensuring that storage can be initialized +/// to a default state at the start of the forming process. pub trait Storage : ::core::default::Default { + /// The type of the fully formed entity that results from the forming process. type Formed; } -/// zzz : write description +/// Provides a mechanism to finalize the forming process by converting storage into its final formed state. +/// +/// This trait is crucial for transitioning the mutable, intermediate storage state into the final, +/// immutable state of an entity. The transformation is typically performed once all configurations +/// and modifications are applied to the storage during the forming process. The type `Preformed` and `Formed` is +/// generally the structure for which the `Former` trait is derived, representing the fully formed +/// state of the entity. However, it can differ if a custom `FormingEnd` or a different `Formed` type +/// is defined to handle specific forming logic or requirements. +/// But even if `Formed` is custom `Preformed` is always that structure. pub trait StoragePreform { + /// The type of the entity as it should appear once fully formed. type Preformed; + + /// Transforms the storage into the final formed state of the entity. + /// + /// This function is called at the conclusion of the forming process to finalize the entity's state, + /// effectively turning the mutable storage state into the immutable, fully formed entity. This transition + /// reflects the culmination of the forming process where the temporary, modifiable attributes of the + /// storage are solidified into the permanent attributes of the formed entity. fn preform( self ) -> Self::Preformed; } From 33169aefb62fe21b87c42b4ac706d08cfc960b8e Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 08:55:02 +0300 Subject: [PATCH 463/533] former : documentation and cleaning --- module/core/former/Readme.md | 2 +- module/core/former/src/definition.rs | 62 +++++++++++++++++++++------- module/core/former/src/storage.rs | 1 + 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index f0c828e4d2..b141c5dc0b 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -602,7 +602,7 @@ Storage is not just a passive container; it is an active part of a larger ecosys These elements work in concert to ensure that the forming process is not only about building an object step-by-step but also about integrating it seamlessly into larger, more complex structures or systems. The `Former` framework, with its sophisticated management of storage, context, and callbacks, enables a highly flexible and reusable approach to object formation, making it ideal for scenarios where objects are part of nested or interdependent systems. -## Comcept of Definitions +## Concept of Definitions Definitions are utilized to encapsulate and manage generic parameters efficiently and avoid passing each parameter individually. diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs index 1b820752be..788a7ea16b 100644 --- a/module/core/former/src/definition.rs +++ b/module/core/former/src/definition.rs @@ -1,45 +1,75 @@ +// definition.rs -// zzz : improve documentation -/// Map type of entity to former. -pub trait EntityToDefinition< Context, Formed, End > +/// Maps a type of entity to its corresponding former definition. +/// This trait provides a linkage between the entity and its definition, +/// allowing the formation logic to understand what definition to apply +/// during the formation process. +pub trait EntityToDefinition { + /// The specific `FormerDefinition` associated with this entity. type Definition : FormerDefinition; } -// zzz : improve documentation -/// Map type of entity to former. -pub trait EntityToFormer< Definition > +/// Maps a type of entity to its corresponding former. +/// This trait binds an entity type to a specific former, facilitating the use +/// of custom formers in complex formation scenarios. +pub trait EntityToFormer where - // Definition : FormerDefinition< Storage = Self::Storage >, Definition : FormerDefinition, { + /// The type of the former used for building the entity. type Former; - fn __f( _ : &Definition ) {} + + /// A placeholder function to reference the definition without operational logic to calm compiler. + fn __f(_: &Definition) {} } -// zzz : improve documentation -/// Map type of entity to storage. +/// Maps a type of entity to its storage type. +/// This trait defines what storage structure is used to hold the interim state +/// of an entity during its formation. pub trait EntityToStorage { + /// The storage type used for forming the entity. type Storage; } -/// zzz : write description +/// Defines the fundamental components involved in the formation of an entity. +/// This trait specifies the types of storage, the formed entity, and the context +/// used during the formation process. pub trait FormerDefinitionTypes : Sized { + /// The type of storage used to maintain the state during formation. type Storage : Default; + + /// The type of the entity once fully formed. type Formed; + + /// The contextual information used during formation, if any. type Context; } -/// zzz : write description +/// Expands on `FormerDefinitionTypes` by incorporating an ending mechanism for the formation process. +/// This trait connects the formation types with a specific endpoint, defining +/// how the formation process concludes, including any necessary transformations +/// or validations. pub trait FormerDefinition : Sized { - type Types : - crate::FormerDefinitionTypes< Storage = Self::Storage, Formed = Self::Formed, Context = Self::Context > - + crate::FormerMutator; - type End : crate::FormingEnd< Self::Types >; + /// Encapsulates the types related to the formation process including any mutators. + type Types : crate::FormerDefinitionTypes< Storage = Self::Storage, Formed = Self::Formed, Context = Self::Context > + + crate::FormerMutator; + + /// Defines the ending condition or operation of the formation process. + type End: crate::FormingEnd< Self::Types >; + + /// The storage type used during the formation. type Storage : Default; + + /// The type of the entity being formed. It is + /// generally the structure for which the `Former` trait is derived, representing the fully formed + /// state of the entity. However, it can differ if a custom `FormingEnd` or a different `Formed` type + /// is defined to handle specific forming logic or requirements. type Formed; + + /// The context used during the formation process. type Context; } diff --git a/module/core/former/src/storage.rs b/module/core/former/src/storage.rs index e021f30d3f..8d7ac111e3 100644 --- a/module/core/former/src/storage.rs +++ b/module/core/former/src/storage.rs @@ -1,3 +1,4 @@ +// storage.rs /// Defines the storage interface for entities being constructed using a forming pattern. /// From c484126efee64c27e4ee876a125472587872831a Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 5 May 2024 09:17:15 +0300 Subject: [PATCH 464/533] former : documentation and cleaning --- module/core/former/Readme.md | 17 +++++++ module/core/former/src/definition.rs | 17 ++++++- module/core/former/src/forming.rs | 75 ++++++++++++++++++++-------- module/core/former/src/storage.rs | 14 +++++- module/core/former/src/vector.rs | 2 + 5 files changed, 101 insertions(+), 24 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index b141c5dc0b..7dd07d1287 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -614,6 +614,23 @@ Two key definition Traits: - Building upon `FormerDefinitionTypes`, this trait incorporates the `FormingEnd` callback, linking the formation types with a definitive ending. It specifies how the formation process should conclude, which may involve validations, transformations, or integrations into larger structures. - The inclusion of the `End` type parameter specifies the end conditions of the formation process, effectively connecting the temporary state held in storage to its ultimate form. +## Overview of Formation Traits + +The formation process in our framework utilizes several core traits, each serving a specific purpose in the lifecycle of entity creation. These traits ensure that entities are constructed methodically, adhering to a structured pattern that enhances maintainability and scalability. Below is a summary of these key traits: + +- `EntityToDefinition`: Links entities to their respective formation definitions which dictate their construction process. +- `EntityToFormer`: Connects entities with formers that are responsible for their step-by-step construction. +- `EntityToStorage`: Specifies the storage structures that temporarily hold the state of an entity during its formation. +- `FormerDefinition`, `FormerDefinitionTypes`: Define the essential properties and ending conditions of the formation process, ensuring entities are formed according to predetermined rules and logic. +- `Storage`: Establishes the fundamental interface for storage types used in the formation process, ensuring each can initialize to a default state. +- `StoragePreform`: Describes the transformation of storage from a mutable, intermediate state into the final, immutable state of the entity, crucial for accurately concluding the formation process. +- `FormerMutator`: Allows for custom mutation logic on the storage and context immediately before the formation process completes, ensuring last-minute adjustments are possible. +- `FormingEnd`: Specifies the closure action at the end of the formation process, which can transform or validate the final state of the entity. +- `FormingEndClosure`: Provides a flexible mechanism for dynamically handling the end of the formation process using closures, useful for complex scenarios. +- `FormerBegin`: Initiates a subforming process, managing how entities begin their formation in terms of storage and context setup. + +These traits collectively facilitate a robust and flexible builder pattern that supports complex object creation and configuration scenarios. + ## Concept of subformer Subformers are specialized builders used within the `Former` framework to construct nested or collection-based data structures like vectors, hash maps, and hash sets. They simplify the process of adding elements to these structures by providing a fluent interface that can be seamlessly integrated into the overall builder pattern of a parent struct. This approach allows for clean and intuitive initialization of complex data structures, enhancing code readability and maintainability. diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs index 788a7ea16b..1448bb6e04 100644 --- a/module/core/former/src/definition.rs +++ b/module/core/former/src/definition.rs @@ -1,4 +1,19 @@ -// definition.rs +//! Module `definition` +//! +//! Provides traits for defining the relationships between entities and their formation mechanisms. +//! These traits are central to the implementation of a flexible and extensible formation system, +//! enabling entities to be constructed using various configurations and complex logic. +//! +//! Key aspects of the module include: +//! - **Entity to Definition Mapping**: Linking entities to their specific formation definitions, +//! which detail how they are to be constructed. +//! - **Entity to Former Mapping**: Associating entities with formers that handle their construction +//! process. +//! - **Entity to Storage Mapping**: Defining the storage structures that maintain the state of an +//! entity during its formation. +//! - **Definition Traits**: Specifying the properties and ending conditions of the formation +//! process to ensure entities are formed according to specified rules and logic. +//! /// Maps a type of entity to its corresponding former definition. /// This trait provides a linkage between the entity and its definition, diff --git a/module/core/former/src/forming.rs b/module/core/former/src/forming.rs index 7875afdb95..47e0088244 100644 --- a/module/core/former/src/forming.rs +++ b/module/core/former/src/forming.rs @@ -1,4 +1,9 @@ - +//! Module `forming` +//! +//! This module defines a collection of traits that are crucial for implementing a structured and extensible builder pattern. +//! The traits provided manage the various stages of the forming process, handling the initiation, mutation, and completion +//! of constructing complex data structures. These traits facilitate the creation of flexible and maintainable formation +//! logic that can accommodate complex construction scenarios, including nested and conditional formations. /// Provides a mechanism for mutating the context and storage just before the forming process is completed. /// @@ -19,8 +24,9 @@ /// - Applying last-minute changes to the data being formed. /// - Setting or modifying properties that depend on the final state of the storage or context. /// - Storage-specific fields which are not present in formed structure. +/// +/// Look example `former_custom_mutator.rs` -// xxx : add example pub trait FormerMutator where Self : crate::FormerDefinitionTypes, @@ -79,10 +85,11 @@ where } } -/// A `FormingEnd` implementation that returns the formed container itself instead of the context. +/// A `FormingEnd` implementation that directly returns the formed container as the final product of the forming process. /// -/// This struct is useful when the forming process should result in the formed container being returned directly, -/// bypassing any additional context processing. It simplifies scenarios where the formed container is the final result. +/// This struct is particularly useful when the end result of the forming process is simply the formed container itself, +/// without needing to integrate or process additional contextual information. It's ideal for scenarios where the final +/// entity is directly derived from the storage state without further transformations or context-dependent adjustments. #[ derive( Debug, Default ) ] pub struct ReturnPreformed; @@ -92,6 +99,7 @@ where Definition::Storage : crate::StoragePreform< Preformed = Definition::Formed >, Definition : crate::FormerDefinitionTypes, { + /// Transforms the storage into its final formed state and returns it, bypassing context processing. #[ inline( always ) ] fn call( &self, storage : Definition::Storage, _context : core::option::Option< Definition::Context > ) -> Definition::Formed { @@ -99,7 +107,12 @@ where } } -/// zzz : update description +/// A `FormingEnd` implementation that returns the storage itself as the formed entity, disregarding any contextual data. +/// +/// This struct is suited for straightforward forming processes where the storage already represents the final state of the +/// entity, and no additional processing or transformation of the storage is required. It simplifies use cases where the +/// storage does not undergo a transformation into a different type at the end of the forming process. + #[ derive( Debug, Default ) ] pub struct ReturnStorage; @@ -108,6 +121,7 @@ for ReturnStorage where Definition : crate::FormerDefinitionTypes< Context = (), Storage = T, Formed = T >, { + /// Returns the storage as the final product of the forming process, ignoring any additional context. #[ inline( always ) ] fn call( &self, storage : Definition::Storage, _context : core::option::Option< () > ) -> Definition::Formed { @@ -115,10 +129,11 @@ where } } -// zzz : improve description -/// Use `NoEnd` to fill parameter FormingEnd in struct where parameter exists, but it is not needed. -/// It might be needed if the same struct is used as `FormerDefinitionTypes` and as `FormerDefinition`, because the first one does not have information aboud End function. -/// Similar logic which `std::marker::PhantomData` has behind. +/// A placeholder `FormingEnd` used when no end operation is required or applicable. +/// +/// This implementation is useful in generic or templated scenarios where a `FormingEnd` is required by the interface, +/// but no meaningful end operation is applicable. It serves a role similar to `std::marker::PhantomData` by filling +/// generic parameter slots without contributing operational logic. #[ derive( Debug, Default ) ] pub struct NoEnd; @@ -127,6 +142,7 @@ for NoEnd where Definition : crate::FormerDefinitionTypes, { + /// Intentionally causes a panic if called, as its use indicates a configuration error. #[ inline( always ) ] fn call( &self, _storage : Definition::Storage, _context : core::option::Option< Definition::Context > ) -> Definition::Formed { @@ -211,31 +227,46 @@ for FormingEndClosure< Definition > } } -// - /// A trait for initiating a structured subforming process with contextual and intermediary storage linkage. /// -/// This trait facilitates the creation of a subformer that carries through a builder pattern chain, -/// utilizing intermediary storage for accumulating state or data before finally transforming it into -/// a `Formed` structure. It is designed for scenarios where a multi-step construction or transformation -/// process benefits from maintaining both transient state (`Storage`) and contextual information (`Context`), -/// before concluding with the generation of a final product (`Formed`). +/// This trait is crucial for the `derive(Former)` macro implementation, where it facilitates the creation +/// of a subformer that integrates seamlessly within a builder pattern chain. It handles intermediary storage +/// to accumulate state or data before finally transforming it into the final `Formed` structure. +/// +/// `FormerBegin` is particularly important in scenarios where complex, hierarchical structures are formed, +/// allowing a former to be reused within another former. This reusability and the ability to maintain both transient +/// state (`Storage`) and contextual information (`Context`) are essential for multi-step construction or transformation +/// processes that culminate in the generation of a final product (`Formed`). +/// +/// During code generation via the `derive(Former)` macro, `FormerBegin` provides the necessary scaffolding to +/// initiate the subforming process. This setup is critical for ensuring that all elements involved in the formation +/// are aligned from the onset, particularly when one former is nested within another, facilitating the creation +/// of complex hierarchical data structures. /// -/// The `FormerBegin` trait, by decoupling `Storage` from `Formed` and introducing a contextual layer, enables -/// sophisticated and flexible construction patterns conducive to complex data transformations or object creation -/// sequences within builder patterns. -// zzz : update description pub trait FormerBegin< Definition : crate::FormerDefinition > { /// Launches the subforming process with an initial storage and context, setting up an `on_end` completion handler. /// + /// This method initializes the formation process by providing the foundational elements necessary for + /// building the entity. It allows for the configuration of initial states and contextual parameters, which + /// are critical for accurately reflecting the intended final state of the entity. + /// /// # Parameters /// - /// * `storage` - An optional initial state for the intermediary storage structure. + /// * `storage` - An optional initial state for the intermediary storage structure. This parameter allows + /// for the pre-configuration of storage, which can be crucial for entities requiring specific initial states. /// * `context` - An optional initial setting providing contextual information for the subforming process. + /// This context can influence how the formation process progresses, especially in complex forming scenarios. /// * `on_end` - A completion handler responsible for transforming the accumulated `Storage` into the final `Formed` structure. + /// This parameter is vital for ensuring that the transition from `Storage` to `Formed` is handled correctly, + /// incorporating any last-minute adjustments or validations necessary for the entity's integrity. + /// + /// # Returns + /// + /// Returns an instance of Former. + /// fn former_begin ( storage : core::option::Option< Definition::Storage >, diff --git a/module/core/former/src/storage.rs b/module/core/former/src/storage.rs index 8d7ac111e3..b4a65ef38a 100644 --- a/module/core/former/src/storage.rs +++ b/module/core/former/src/storage.rs @@ -1,4 +1,16 @@ -// storage.rs +//! Module `storage` +//! +//! Provides traits that define the storage mechanics used during the formation of entities in a builder pattern. +//! This module is critical for managing the state of entities as they are constructed, ensuring that all +//! interim data is handled appropriately before finalizing the entity's construction. +//! +//! Key components of the module include: +//! - **Storage Interface**: Defines the essential interface for any storage type used in the formation +//! process. It ensures that each storage type can be initialized to a default state. +//! - **Storage Preformation**: Outlines the method for transitioning storage from a mutable, intermediate +//! state to a finalized, immutable state of the entity. This is pivotal for concluding the formation process +//! with integrity and accuracy. +//! /// Defines the storage interface for entities being constructed using a forming pattern. /// diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index a53b50082e..eaec2aad1f 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -98,6 +98,8 @@ for Vec< E > // = definition // xxx : split definition and definition types +// xxx : imlement custom ContainerDefinition + #[ derive( Debug, Default ) ] pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > where From 53b5ea49f33ff21209d6d61dc25e0908435df86d Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 6 May 2024 08:39:44 +0300 Subject: [PATCH 465/533] former : documentation and cleaning --- module/core/former/src/container.rs | 70 ++++++++++++++++------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 96b11ff4e9..bc3d454dae 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -1,56 +1,72 @@ +// File container.rs + //! Interface for containers. use crate::*; -/// zzz : improve description -/// Descriptor of a container, specifically it define type of element and type of value. -/// As well as function to convert element to value. Reversal conversion could be not possible, so value to element conversion is in a separate trait. +/// Represents a container by defining the types of elements and values it handles. +/// +/// This trait abstracts the nature of containers in data structures, facilitating the handling of contained +/// elements and values, especially in scenarios where the structure of the container allows for complex relationships, +/// such as `HashMap`s. It not only identifies what constitutes an element and a value in the context of the container +/// but also provides utility for converting between these two, which is critical in operations involving element manipulation +/// and value retrieval. + pub trait Container { - /// The type of elements to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. + /// The type of elements that can be added to the container. This type can differ from `Val` in containers like `HashMap`, + /// where an element might represent a key-value pair, and `Val` could represent just the value or the key. type Element; - /// The type of value to be added to the container. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. + + /// The type of values stored in the container. This might be distinct from `Element` in complex containers. + /// For example, in a `HashMap`, while `Element` might be a (key, value) tuple, `Val` might only be the value part. type Val; - /// Convert element to val. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. + /// Converts an element to its corresponding value within the container. This function is essential for abstracting + /// the container's internal representation from the values it manipulates. fn element_to_val( e : Self::Element ) -> Self::Val; - } -/// zzz : improve description -/// Implement function to convert value of an element of a container. -/// As well as function to convert element to value. Reversal conversion could be not possible, so value to element conversion is in a separate trait. -pub trait ElementToVal< Container > +/// Facilitates the conversion of container elements to their corresponding value representations. +/// +/// This trait is utilized to transform an element of a container into a value, abstracting the operation of containers +/// like vectors or hash maps. It ensures that even in complex container structures, elements can be seamlessly managed +/// and manipulated as values. +pub trait ElementToVal { type Val; - /// Convert element to value. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. + /// Converts an element into a value representation specific to the type of container. This conversion is crucial + /// for handling operations on elements, especially when they need to be treated or accessed as individual values, + /// such as retrieving the value part from a key-value pair in a hash map. fn element_to_val( self ) -> Self::Val; - } -impl< C, E > ElementToVal< C > -for E +impl< C, E > ElementToVal< C > for E where C : Container< Element = E >, { type Val = C::Val; + fn element_to_val( self ) -> Self::Val { C::element_to_val( self ) } } -/// zzz : improve description -/// Implement function to convert value to an element of a container. -/// Value to an element conversion could be not possible, so value to element conversion is in a separate trait. +/// Provides a mechanism for converting values back to container-specific elements. +/// +/// This trait is crucial for operations that require the insertion or modification of elements based on values, +/// especially in complex data structures where the element's structure is more intricate than the value it represents, +/// such as inserting a new entry in a `HashMap` where the element consists of a key-value pair. pub trait ValToElement< Container > { type Element; - /// Convert value to element. For Vector `Val` and `Element` is the same type, but for `HashMap` `Element` is pair of key-value and `Val` is value itself. + /// Converts a value back into an element of the container. This function is essential for operations like insertion + /// or modification, where a value needs to be transformed into a container-compatible element, such as converting + /// a value into a (key, value) tuple for insertion into a `HashMap`. fn val_to_element( self ) -> Self::Element; - } /// A trait defining the capability to add elements to a container. @@ -60,17 +76,6 @@ pub trait ValToElement< Container > /// added to the container, providing a consistent API regardless of the underlying /// container's structure. /// -/// # Type Parameters -/// -/// - There are no explicit type parameters for the trait itself, but implementers will -/// specify their own types as needed. -/// -/// # Associated Types -/// -/// * `Element`: The type of elements that can be added to the container. This type is -/// defined by the implementer of the trait, allowing for flexibility in the kinds of -/// elements different containers can accept. -/// // zzz : update description pub trait ContainerAdd : Container @@ -173,7 +178,8 @@ where { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { - f.debug_struct( "ContainerSubformer" ) + f + .debug_struct( "ContainerSubformer" ) .field( "storage", &"Storage Present" ) .field( "context", &self.context.as_ref().map( |_| "Context Present" ) ) .field( "on_end", &self.on_end.as_ref().map( |_| "End Present" ) ) From b5c565d245ab33d82787e09713ae5dd42735fc02 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 6 May 2024 08:44:41 +0300 Subject: [PATCH 466/533] former : documentation and cleaning --- module/core/former/Readme.md | 6 +- .../examples/former_custom_subform_setter.rs | 6 +- .../examples/former_custom_subform_setter2.rs | 6 +- module/core/former/src/container.rs | 193 ++++++++++-------- module/core/former/src/hash_map.rs | 14 +- module/core/former/src/hash_set.rs | 18 +- module/core/former/src/vector.rs | 18 +- .../former_tests/container_former_hashmap.rs | 14 +- .../former_tests/container_former_hashset.rs | 8 +- .../inc/former_tests/container_former_vec.rs | 8 +- .../former_tests/subformer_subform_hashmap.rs | 6 +- .../subformer_subform_hashmap_custom.rs | 10 +- .../former_tests/subformer_subform_manual.rs | 14 +- .../subformer_subform_named_manual.rs | 6 +- .../former_meta/src/derive_former/field.rs | 4 +- 15 files changed, 177 insertions(+), 154 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 7dd07d1287..d1b8a47dfa 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -938,11 +938,11 @@ fn main() } // Required to define how `value` is converted into pair `( key, value )` - impl former::ValToElement< HashMap< String, Child > > for Child + impl former::ValToEntry< HashMap< String, Child > > for Child { - type Element = ( String, Child ); + type Entry = ( String, Child ); #[ inline( always ) ] - fn val_to_element( self ) -> Self::Element + fn val_to_entry( self ) -> Self::Entry { ( self.name.clone(), self ) } diff --git a/module/core/former/examples/former_custom_subform_setter.rs b/module/core/former/examples/former_custom_subform_setter.rs index d7090a74cf..6061c61718 100644 --- a/module/core/former/examples/former_custom_subform_setter.rs +++ b/module/core/former/examples/former_custom_subform_setter.rs @@ -66,11 +66,11 @@ fn main() } // Required to define how `value` is converted into pair `( key, value )` - impl former::ValToElement< HashMap< String, Child > > for Child + impl former::ValToEntry< HashMap< String, Child > > for Child { - type Element = ( String, Child ); + type Entry = ( String, Child ); #[ inline( always ) ] - fn val_to_element( self ) -> Self::Element + fn val_to_entry( self ) -> Self::Entry { ( self.name.clone(), self ) } diff --git a/module/core/former/examples/former_custom_subform_setter2.rs b/module/core/former/examples/former_custom_subform_setter2.rs index 586d69eb9d..08583a85b7 100644 --- a/module/core/former/examples/former_custom_subform_setter2.rs +++ b/module/core/former/examples/former_custom_subform_setter2.rs @@ -118,11 +118,11 @@ fn main() } // Required to define how `value` is converted into pair `( key, value )` - impl former::ValToElement< HashMap< String, Child > > for Child + impl former::ValToEntry< HashMap< String, Child > > for Child { - type Element = ( String, Child ); + type Entry = ( String, Child ); #[ inline( always ) ] - fn val_to_element( self ) -> Self::Element + fn val_to_entry( self ) -> Self::Entry { ( self.name.clone(), self ) } diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index bc3d454dae..6d1b3d3583 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -4,155 +4,178 @@ use crate::*; -/// Represents a container by defining the types of elements and values it handles. +/// Represents a container by defining the types of entries and values it handles. /// /// This trait abstracts the nature of containers in data structures, facilitating the handling of contained -/// elements and values, especially in scenarios where the structure of the container allows for complex relationships, -/// such as `HashMap`s. It not only identifies what constitutes an element and a value in the context of the container -/// but also provides utility for converting between these two, which is critical in operations involving element manipulation +/// entries and values, especially in scenarios where the structure of the container allows for complex relationships, +/// such as `HashMap`s. It not only identifies what constitutes an entry and a value in the context of the container +/// but also provides utility for converting between these two, which is critical in operations involving entry manipulation /// and value retrieval. pub trait Container { - /// The type of elements that can be added to the container. This type can differ from `Val` in containers like `HashMap`, - /// where an element might represent a key-value pair, and `Val` could represent just the value or the key. - type Element; + /// The type of entries that can be added to the container. This type can differ from `Val` in containers like `HashMap`, + /// where an entry might represent a key-value pair, and `Val` could represent just the value or the key. + type Entry; - /// The type of values stored in the container. This might be distinct from `Element` in complex containers. - /// For example, in a `HashMap`, while `Element` might be a (key, value) tuple, `Val` might only be the value part. + /// The type of values stored in the container. This might be distinct from `Entry` in complex containers. + /// For example, in a `HashMap`, while `Entry` might be a (key, value) tuple, `Val` might only be the value part. type Val; - /// Converts an element to its corresponding value within the container. This function is essential for abstracting + /// Converts an entry to its corresponding value within the container. This function is essential for abstracting /// the container's internal representation from the values it manipulates. - fn element_to_val( e : Self::Element ) -> Self::Val; + fn entry_to_val( e : Self::Entry ) -> Self::Val; } -/// Facilitates the conversion of container elements to their corresponding value representations. +/// Facilitates the conversion of container entries to their corresponding value representations. /// -/// This trait is utilized to transform an element of a container into a value, abstracting the operation of containers -/// like vectors or hash maps. It ensures that even in complex container structures, elements can be seamlessly managed +/// This trait is utilized to transform an entry of a container into a value, abstracting the operation of containers +/// like vectors or hash maps. It ensures that even in complex container structures, entries can be seamlessly managed /// and manipulated as values. -pub trait ElementToVal +pub trait EntryToVal { type Val; - /// Converts an element into a value representation specific to the type of container. This conversion is crucial - /// for handling operations on elements, especially when they need to be treated or accessed as individual values, + /// Converts an entry into a value representation specific to the type of container. This conversion is crucial + /// for handling operations on entries, especially when they need to be treated or accessed as individual values, /// such as retrieving the value part from a key-value pair in a hash map. - fn element_to_val( self ) -> Self::Val; + fn entry_to_val( self ) -> Self::Val; } -impl< C, E > ElementToVal< C > for E +impl< C, E > EntryToVal< C > for E where - C : Container< Element = E >, + C : Container< Entry = E >, { type Val = C::Val; - fn element_to_val( self ) -> Self::Val + fn entry_to_val( self ) -> Self::Val { - C::element_to_val( self ) + C::entry_to_val( self ) } } -/// Provides a mechanism for converting values back to container-specific elements. +/// Provides a mechanism for converting values back to container-specific entries. /// -/// This trait is crucial for operations that require the insertion or modification of elements based on values, -/// especially in complex data structures where the element's structure is more intricate than the value it represents, -/// such as inserting a new entry in a `HashMap` where the element consists of a key-value pair. -pub trait ValToElement< Container > +/// This trait is crucial for operations that require the insertion or modification of entries based on values, +/// especially in complex data structures where the entry's structure is more intricate than the value it represents, +/// such as inserting a new entry in a `HashMap` where the entry consists of a key-value pair. +pub trait ValToEntry< Container > { - type Element; + type Entry; - /// Converts a value back into an element of the container. This function is essential for operations like insertion - /// or modification, where a value needs to be transformed into a container-compatible element, such as converting + /// Converts a value back into an entry of the container. This function is essential for operations like insertion + /// or modification, where a value needs to be transformed into a container-compatible entry, such as converting /// a value into a (key, value) tuple for insertion into a `HashMap`. - fn val_to_element( self ) -> Self::Element; + fn val_to_entry( self ) -> Self::Entry; } - -/// A trait defining the capability to add elements to a container. -/// -/// This trait should be implemented by container types that require a generic interface -/// for adding new elements. It abstracts over the specific details of how elements are -/// added to the container, providing a consistent API regardless of the underlying -/// container's structure. +/// Provides functionality to add individual entries to a container. /// - -// zzz : update description +/// This trait extends the basic `Container` trait by introducing a method to add entries to a container. +/// It is designed to handle the container's specific requirements and rules for adding entries, such as +/// managing duplicates, maintaining order, or handling capacity constraints. pub trait ContainerAdd : Container { - - /// Adds an element to the container. + /// Adds an entry to the container and returns a boolean indicating the success of the operation. /// - /// Implementations of this function should add the provided element to the container, - /// respecting the container's specific semantics for element addition (e.g., handling - /// duplicates or maintaining order). The function returns a boolean indicating whether - /// the addition was successful. + /// Implementations should ensure that the entry is added according to the rules of the container, + /// which might involve checking for duplicates, ordering, or capacity limits. /// /// # Parameters /// - /// * `e`: The element to be added to the container. The type of the element is specified - /// by the associated `Element` type. + /// * `e`: The entry to be added to the container, where the type `Entry` is defined by the `Container` trait. /// /// # Returns /// - /// Returns `true` if the element was successfully added to the container, or `false` if - /// the addition failed. Failure conditions are defined by the implementer but may include - /// situations like the container being at capacity or the element already existing in a - /// set. + /// Returns `true` if the entry was successfully added, or `false` if not added due to reasons such as + /// the entry already existing in the container or the container reaching its capacity. /// /// # Examples /// /// Basic usage: /// - /// ``` + /// ```rust /// use former::ContainerAdd; /// /// struct MyContainer /// { - /// elements : Vec< i32 >, + /// entries : Vec< i32 >, /// } /// /// impl ContainerAdd for MyContainer /// { - /// type Element = i32; - /// - /// fn add( &mut self, e : Self::Element ) -> bool + /// fn add( &mut self, e : Self::Entry ) -> bool /// { - /// if self.elements.contains( &e ) + /// if self.entries.contains( &e ) /// { /// false /// } /// else /// { - /// self.elements.push( e ); + /// self.entries.push( e ); /// true /// } /// } /// } /// - /// let mut container = MyContainer { elements : vec![] }; - /// assert!( container.add( 10 ) ); // Returns true, element added - /// assert!( !container.add( 10 ) ); // Returns false, element already exists + /// let mut container = MyContainer { entries : vec![] }; + /// assert!( container.add( 10 ) ); // Returns true, entry added + /// assert!( !container.add( 10 ) ); // Returns false, entry already exists /// ``` - /// - /// This example demonstrates a simple container that does not allow duplicate elements. - /// The `add` method checks for the existence of the element before adding it, returning - /// `false` if the element is already present. - /// - fn add( &mut self, e : Self::Element ) -> bool; - + fn add( &mut self, e : Self::Entry ) -> bool; } -// zzz : extend documentation -/// A trait defining the capability to replface all elements. +/// Defines the capability to replace all entries in a container with a new set of entries. +/// +/// This trait extends the `Container` trait by providing a method to replace the existing entries in +/// the container with a new set. This can be useful for resetting the container's contents or bulk-updating +/// them based on external criteria or operations. pub trait ContainerAssign : Container { - - /// Agging elements to the container. - fn assign< Elements >( &mut self, elements : Elements ) -> usize + /// Replaces all entries in the container with the provided entries and returns the count of new entries added. + /// + /// This method clears the existing entries and populates the container with new ones provided by an iterator. + /// It is ideal for scenarios where the container needs to be refreshed or updated with a new batch of entries. + /// + /// # Parameters + /// + /// * `entries` : An iterator over the entries to be added to the container. The entries must conform to + /// the `Entry` type defined by the `Container` trait. + /// + /// # Returns + /// + /// Returns the number of entries successfully added to the container. This count may differ from the total + /// number of entries in the iterator if the container imposes restrictions such as capacity limits or duplicate + /// handling. + /// + /// # Examples + /// + /// ```rust + /// use former::ContainerAssign; + /// + /// struct MyContainer + /// { + /// entries : Vec< i32 >, + /// } + /// + /// impl ContainerAssign for MyContainer + /// { + /// fn assign< Entries >( &mut self, entries : Entries ) -> usize + /// where + /// Entries : IntoIterator< Item = Self::Entry >, + /// { + /// self.entries.clear(); + /// self.entries.extend( entries ); + /// self.entries.len() + /// } + /// } + /// + /// let mut container = MyContainer { entries : vec![ 1, 2, 3 ] }; + /// let new_elements = vec![ 4, 5, 6 ]; + /// assert_eq!( container.assign( new_elements ), 3 ); // Container now contains [ 4, 5, 6 ] + /// ``` + fn assign< Entries >( &mut self, entries : Entries ) -> usize where - Elements : IntoIterator< Item = Self::Element >; - + Entries : IntoIterator< Item = Self::Entry >; } // = @@ -162,7 +185,7 @@ pub trait ContainerAssign : Container pub struct ContainerSubformer< E, Definition > where Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, + Definition::Storage : ContainerAdd< Entry = E >, { storage : Definition::Storage, context : core::option::Option< Definition::Context >, @@ -174,7 +197,7 @@ use std::fmt; impl< E, Definition > fmt::Debug for ContainerSubformer< E, Definition > where Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, + Definition::Storage : ContainerAdd< Entry = E >, { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result { @@ -190,7 +213,7 @@ where impl< E, Definition > ContainerSubformer< E, Definition > where Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, + Definition::Storage : ContainerAdd< Entry = E >, { /// Begins the building process, optionally initializing with a context and storage. @@ -270,7 +293,7 @@ impl< E, Storage, Formed, Types, Definition > ContainerSubformer< E, Definition where Types : FormerDefinitionTypes< Context = (), Storage = Storage, Formed = Formed >, Definition : FormerDefinition< Types = Types >, - Definition::Storage : ContainerAdd< Element = E >, + Definition::Storage : ContainerAdd< Entry = E >, { /// Initializes a new `ContainerSubformer` instance, starting with an empty formed. @@ -310,15 +333,15 @@ where impl< E, Definition > ContainerSubformer< E, Definition > where Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, + Definition::Storage : ContainerAdd< Entry = E >, { - /// Appends an element to the end of the storage, expanding the internal collection. + /// Appends an entry to the end of the storage, expanding the internal collection. #[ inline( always ) ] - pub fn add< IntoElement >( mut self, element : IntoElement ) -> Self + pub fn add< IntoElement >( mut self, entry : IntoElement ) -> Self where IntoElement : core::convert::Into< E >, { - ContainerAdd::add( &mut self.storage, element.into() ); + ContainerAdd::add( &mut self.storage, entry.into() ); self } @@ -330,7 +353,7 @@ impl< E, Definition > FormerBegin< Definition > for ContainerSubformer< E, Definition > where Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Element = E >, + Definition::Storage : ContainerAdd< Entry = E >, { // type End = Definition::End; diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index c57ac1bf16..c986f54cf8 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -6,11 +6,11 @@ impl< K, V > Container for collection_tools::HashMap< K, V > where K : core::cmp::Eq + core::hash::Hash, { - type Element = ( K, V ); + type Entry = ( K, V ); type Val = V; #[ inline( always ) ] - fn element_to_val( e : Self::Element ) -> Self::Val + fn entry_to_val( e : Self::Entry ) -> Self::Val { e.1 } @@ -21,11 +21,11 @@ impl< K, V > ContainerAdd for collection_tools::HashMap< K, V > where K : core::cmp::Eq + core::hash::Hash, { - // type Element = ( K, V ); + // type Entry = ( K, V ); // type Val = V; #[ inline( always ) ] - fn add( &mut self, ( k, v ) : Self::Element ) -> bool + fn add( &mut self, ( k, v ) : Self::Entry ) -> bool { self.insert( k, v ).map_or_else( || true, | _ | false ) } @@ -36,11 +36,11 @@ impl< K, V > ContainerAssign for collection_tools::HashMap< K, V > where K : core::cmp::Eq + core::hash::Hash, { - // type Element = ( K, V ); + // type Entry = ( K, V ); fn assign< Elements >( &mut self, elements : Elements ) -> usize where - Elements : IntoIterator< Item = Self::Element > + Elements : IntoIterator< Item = Self::Entry > { let initial_len = self.len(); self.extend( elements ); @@ -186,7 +186,7 @@ where /// /// # Type Parameters /// - `K`: Key type, must implement `Eq` and `Hash`. -/// - `E`: Element (value) type. +/// - `E`: Entry (value) type. /// - `Formed`: The hash map-like formed being built. /// - `Context`: Type of the optional context used during the building process. /// - `End`: End-of-forming action to be executed upon completion. diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index fb479e1d01..7f0bc16c55 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -9,11 +9,11 @@ impl< K > Container for collection_tools::HashSet< K > where K : core::cmp::Eq + core::hash::Hash, { - type Element = K; + type Entry = K; type Val = K; #[ inline( always ) ] - fn element_to_val( e : Self::Element ) -> Self::Val + fn entry_to_val( e : Self::Entry ) -> Self::Val { e } @@ -24,11 +24,11 @@ impl< K > ContainerAdd for collection_tools::HashSet< K > where K : core::cmp::Eq + core::hash::Hash, { - // type Element = K; + // type Entry = K; // type Val = K; #[ inline( always ) ] - fn add( &mut self, e : Self::Element ) -> bool + fn add( &mut self, e : Self::Entry ) -> bool { self.insert( e ) } @@ -39,11 +39,11 @@ impl< K > ContainerAssign for collection_tools::HashSet< K > where K : core::cmp::Eq + core::hash::Hash, { - // type Element = K; + // type Entry = K; fn assign< Elements >( &mut self, elements : Elements ) -> usize where - Elements : IntoIterator< Item = Self::Element > + Elements : IntoIterator< Item = Self::Entry > { let initial_len = self.len(); self.extend( elements ); @@ -51,13 +51,13 @@ where } } -impl< K > ValToElement< HashSet< K > > for K +impl< K > ValToEntry< HashSet< K > > for K where K : core::cmp::Eq + core::hash::Hash, { - type Element = K; + type Entry = K; #[ inline( always ) ] - fn val_to_element( self ) -> Self::Element + fn val_to_entry( self ) -> Self::Entry { self } diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index eaec2aad1f..2642b5b425 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -6,11 +6,11 @@ use collection_tools::Vec; impl< E > Container for collection_tools::Vec< E > { - type Element = E; + type Entry = E; type Val = E; #[ inline( always ) ] - fn element_to_val( e : Self::Element ) -> Self::Val + fn entry_to_val( e : Self::Entry ) -> Self::Val { e } @@ -19,11 +19,11 @@ impl< E > Container for collection_tools::Vec< E > impl< E > ContainerAdd for collection_tools::Vec< E > { - // type Element = E; + // type Entry = E; // type Val = E; #[ inline( always ) ] - fn add( &mut self, e : Self::Element ) -> bool + fn add( &mut self, e : Self::Entry ) -> bool { self.push( e ); true @@ -33,12 +33,12 @@ impl< E > ContainerAdd for collection_tools::Vec< E > impl< E > ContainerAssign for collection_tools::Vec< E > { - // type Element = E; + // type Entry = E; #[ inline( always ) ] fn assign< Elements >( &mut self, elements : Elements ) -> usize where - Elements : IntoIterator< Item = Self::Element > + Elements : IntoIterator< Item = Self::Entry > { let initial_len = self.len(); self.extend( elements ); @@ -47,11 +47,11 @@ impl< E > ContainerAssign for collection_tools::Vec< E > } -impl< E > ValToElement< collection_tools::Vec< E > > for E +impl< E > ValToEntry< collection_tools::Vec< E > > for E { - type Element = E; + type Entry = E; #[ inline( always ) ] - fn val_to_element( self ) -> Self::Element + fn val_to_entry( self ) -> Self::Entry { self } diff --git a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs index f0f8e0304c..8d1f57b79e 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs @@ -105,15 +105,15 @@ fn replace() } #[ test ] -fn element_to_val() +fn entry_to_val() { - let got = former::ElementToVal::< HashMap< u32, i32 > >::element_to_val( ( 1u32, 13i32 ) ); + let got = former::EntryToVal::< HashMap< u32, i32 > >::entry_to_val( ( 1u32, 13i32 ) ); let exp = 13i32; a_id!( got, exp ) } #[ test ] -fn val_to_element() +fn val_to_entry() { #[ derive( Clone, Copy, Debug, PartialEq ) ] @@ -123,17 +123,17 @@ fn val_to_element() data : i32, } - impl former::ValToElement< HashMap< u32, Val > > for Val + impl former::ValToEntry< HashMap< u32, Val > > for Val { - type Element = ( u32, Val ); + type Entry = ( u32, Val ); #[ inline( always ) ] - fn val_to_element( self ) -> Self::Element + fn val_to_entry( self ) -> Self::Entry { ( self.key, self ) } } - let got = former::ValToElement::< HashMap< u32, Val > >::val_to_element( Val { key : 1u32, data : 13i32 } ); + let got = former::ValToEntry::< HashMap< u32, Val > >::val_to_entry( Val { key : 1u32, data : 13i32 } ); let exp = ( 1u32, Val { key : 1u32, data : 13i32 } ); a_id!( got, exp ) diff --git a/module/core/former/tests/inc/former_tests/container_former_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs index 3859e9b544..814d2c1095 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashset.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashset.rs @@ -105,17 +105,17 @@ fn replace() } #[ test ] -fn element_to_val() +fn entry_to_val() { - let got = former::ElementToVal::< HashSet< i32 > >::element_to_val( 13i32 ); + let got = former::EntryToVal::< HashSet< i32 > >::entry_to_val( 13i32 ); let exp = 13i32; a_id!( got, exp ) } #[ test ] -fn val_to_element() +fn val_to_entry() { - let got = former::ValToElement::< HashSet< i32 > >::val_to_element( 13i32 ); + let got = former::ValToEntry::< HashSet< i32 > >::val_to_entry( 13i32 ); let exp = 13i32; a_id!( got, exp ) } 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 4e4b49ce7e..a8951379ab 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 @@ -142,17 +142,17 @@ fn entity_to() } #[ test ] -fn element_to_val() +fn entry_to_val() { - let got = former::ElementToVal::< Vec< i32 > >::element_to_val( 13i32 ); + let got = former::EntryToVal::< Vec< i32 > >::entry_to_val( 13i32 ); let exp = 13i32; a_id!( got, exp ) } #[ test ] -fn val_to_element() +fn val_to_entry() { - let got = former::ValToElement::< Vec< i32 > >::val_to_element( 13i32 ); + let got = former::ValToEntry::< Vec< i32 > >::val_to_entry( 13i32 ); let exp = 13i32; a_id!( got, exp ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs index a6d3afe3c9..2c0ad7e8d7 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap.rs @@ -23,11 +23,11 @@ pub struct Parent command : HashMap< String, Child >, } -impl former::ValToElement< HashMap< String, Child > > for Child +impl former::ValToEntry< HashMap< String, Child > > for Child { - type Element = ( String, Child ); + type Entry = ( String, Child ); #[ inline( always ) ] - fn val_to_element( self ) -> Self::Element + fn val_to_entry( self ) -> Self::Entry { ( self.name.clone(), self ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs index 5f39444665..175197fab8 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_hashmap_custom.rs @@ -66,8 +66,8 @@ where former::ContainerAdd::add ( children, - < < HashMap< String, Child > as former::Container >::Val as former::ValToElement< HashMap< String, Child > > > - ::val_to_element( former::StoragePreform::preform( substorage ) ) + < < HashMap< String, Child > as former::Container >::Val as former::ValToEntry< HashMap< String, Child > > > + ::val_to_entry( former::StoragePreform::preform( substorage ) ) ); } super_former @@ -115,11 +115,11 @@ where } -impl former::ValToElement< HashMap< String, Child > > for Child +impl former::ValToEntry< HashMap< String, Child > > for Child { - type Element = ( String, Child ); + type Entry = ( String, Child ); #[ inline( always ) ] - fn val_to_element( self ) -> Self::Element + fn val_to_entry( self ) -> Self::Entry { ( self.name.clone(), self ) } diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs index 4903c6e911..dd75b254c0 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_manual.rs @@ -65,8 +65,8 @@ where former::ContainerAdd::add ( children, - < < Vec< Child > as former::Container >::Val as former::ValToElement< Vec< Child > > > - ::val_to_element( former::StoragePreform::preform( substorage ) ) + < < Vec< Child > as former::Container >::Val as former::ValToEntry< Vec< Child > > > + ::val_to_entry( former::StoragePreform::preform( substorage ) ) ); } super_former @@ -74,7 +74,7 @@ where Former2::former_begin( None, Some( self ), former::FormingEndClosure::new( on_end ) ) } - // < < #field_ty as former::Container >::Val as former::ValToElement< #field_ty > > + // < < #field_ty as former::Container >::Val as former::ValToEntry< #field_ty > > // less generic, but more concise way to define custom subform setter #[ inline( always ) ] @@ -97,17 +97,17 @@ where // it is generated #[ inline( always ) ] pub fn _child( self ) -> - < < Vec< Child > as former::Container >::Element as former::EntityToFormer + < < Vec< Child > as former::Container >::Entry as former::EntityToFormer < // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, < - < Vec< Child > as former::Container >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > + < Vec< Child > as former::Container >::Entry as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > >::Definition, > >::Former { self._children_add - ::< < < Vec< Child > as former::Container >::Element as former::EntityToFormer< _ > >::Former, _, >() + ::< < < Vec< Child > as former::Container >::Entry as former::EntityToFormer< _ > >::Former, _, >() } } @@ -172,7 +172,7 @@ where >, Types2 : former::FormerDefinitionTypes < - Storage = < < Vec< Child > as former::Container >::Element as former::EntityToStorage >::Storage, + Storage = < < Vec< Child > as former::Container >::Entry as former::EntityToStorage >::Storage, Formed = ParentFormer< Definition >, Context = ParentFormer< Definition >, >, diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs index ad36ff96be..fa6e91d223 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs @@ -47,17 +47,17 @@ where #[ inline( always ) ] pub fn _child( self ) -> - < < Vec< Child > as former::Container >::Element as former::EntityToFormer + < < Vec< Child > as former::Container >::Entry as former::EntityToFormer < // ChildFormerDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > >, < - < Vec< Child > as former::Container >::Element as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > + < Vec< Child > as former::Container >::Entry as former::EntityToDefinition< Self, Self, ParentFormerAddChildrenEnd< Definition > > >::Definition, > >::Former { self._children_add - ::< < < Vec< Child > as former::Container >::Element as former::EntityToFormer< _ > >::Former, _, >() + ::< < < Vec< Child > as former::Container >::Entry as former::EntityToFormer< _ > >::Former, _, >() } } diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index b7e2da73da..d0e0b9c443 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -1113,8 +1113,8 @@ where former::ContainerAdd::add ( field, - < < #field_ty as former::Container >::Val as former::ValToElement< #field_ty > > - ::val_to_element( former::StoragePreform::preform( substorage ) ), + < < #field_ty as former::Container >::Val as former::ValToEntry< #field_ty > > + ::val_to_entry( former::StoragePreform::preform( substorage ) ), ); } super_former From d5ff136a56d5487bf1a59769013a9eee16fbd093 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 6 May 2024 08:59:47 +0300 Subject: [PATCH 467/533] former : documentation and cleaning --- module/core/former/src/container.rs | 42 ++++++++++++----------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 6d1b3d3583..1386ad63fd 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -180,7 +180,7 @@ pub trait ContainerAssign : Container // = -/// A builder for constructing containers, facilitating a fluent and flexible interface. +/// A builder structure for constructing containers with a fluent and flexible interface. #[ derive( Default ) ] pub struct ContainerSubformer< E, Definition > where @@ -192,7 +192,6 @@ where on_end : core::option::Option< Definition::End >, } -// zzz : cover by test use std::fmt; impl< E, Definition > fmt::Debug for ContainerSubformer< E, Definition > where @@ -215,8 +214,8 @@ where Definition : FormerDefinition, Definition::Storage : ContainerAdd< Entry = E >, { - - /// Begins the building process, optionally initializing with a context and storage. + /// Begins the construction process of a container with optional initial storage and context, + /// setting up an `on_end` completion handler to finalize the container's construction. #[ inline( always ) ] pub fn begin ( @@ -238,7 +237,8 @@ where } } - /// zzz : update description + /// Provides a variation of the `begin` method allowing for coercion of the end handler, + /// facilitating ease of integration with different end conditions. #[ inline( always ) ] pub fn begin_coercing< IntoEnd > ( @@ -268,41 +268,34 @@ where { let on_end = self.on_end.take().unwrap(); let context = self.context.take(); - // let storage = self.storage(); on_end.call( self.storage, context ) } - /// Finalizes the building process, returning the formed or a context incorporating it. + /// Alias for the `end` method to align with typical builder pattern terminologies. #[ inline( always ) ] pub fn form( self ) -> Definition::Formed { self.end() } - /// Replaces the current storage with a provided one, allowing for a reset or redirection of the building process. + /// Replaces the current storage with a provided storage, allowing for resetting or + /// redirection of the building process. #[ inline( always ) ] - pub fn replace( mut self, vector : Definition::Storage ) -> Self + pub fn replace( mut self, storage : Definition::Storage ) -> Self { - self.storage = vector; + self.storage = storage; self } - } -impl< E, Storage, Formed, Types, Definition > ContainerSubformer< E, Definition > +impl< E, Storage, Formed, Definition > ContainerSubformer< E, Definition > where - Types : FormerDefinitionTypes< Context = (), Storage = Storage, Formed = Formed >, - Definition : FormerDefinition< Types = Types >, + Definition : FormerDefinition< Context = (), Storage = Storage, Formed = Formed >, Definition::Storage : ContainerAdd< Entry = E >, { - - /// Initializes a new `ContainerSubformer` instance, starting with an empty formed. - /// This function serves as the entry point for the builder pattern. - /// - /// # Returns - /// A new instance of `ContainerSubformer` with an empty internal formed. - /// - // zzz : update description + /// Constructs a new `ContainerSubformer` instance, starting with an empty storage. + /// This method serves as the entry point for the builder pattern, facilitating the + /// creation of a new container. #[ inline( always ) ] pub fn new( end : Definition::End ) -> Self { @@ -314,7 +307,8 @@ where ) } - // zzz : update description + /// Variant of the `new` method allowing for end condition coercion, providing flexibility + /// in specifying different types of end conditions dynamically. #[ inline( always ) ] pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self where @@ -327,7 +321,6 @@ where end.into(), ) } - } impl< E, Definition > ContainerSubformer< E, Definition > @@ -355,7 +348,6 @@ where Definition : FormerDefinition, Definition::Storage : ContainerAdd< Entry = E >, { - // type End = Definition::End; #[ inline( always ) ] fn former_begin From 02bbb4bfc2cd9b67c043edcc46d5e7a68db22ec4 Mon Sep 17 00:00:00 2001 From: Barsik Date: Mon, 6 May 2024 14:41:27 +0300 Subject: [PATCH 468/533] Using `former` in `strs_tools` has been updated --- module/core/strs_tools/src/string/isolate.rs | 12 ++++++------ .../core/strs_tools/src/string/parse_request.rs | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/module/core/strs_tools/src/string/isolate.rs b/module/core/strs_tools/src/string/isolate.rs index abe3ddc13b..78d23f6658 100644 --- a/module/core/strs_tools/src/string/isolate.rs +++ b/module/core/strs_tools/src/string/isolate.rs @@ -11,17 +11,17 @@ pub( crate ) mod private #[ perform( fn isolate( &self ) -> ( &'a str, Option<&'a str>, &'a str ) ) ] pub struct IsolateOptions<'a> { - #[ default( "" ) ] + #[ former( default = "" ) ] src : &'a str, - #[ default( " " ) ] + #[ former( default = " " ) ] delimeter : &'a str, - #[ default( true ) ] + #[ former( default = true ) ] quote : bool, - #[ default( true ) ] + #[ former( default = true ) ] left : bool, - #[ default( 1 ) ] + #[ former( default = 1 ) ] times : u8, /* rrr : Dmytro : former do not form u16, u32, u64, usize, replace after fix */ - #[ default( true ) ] + #[ former( default = true ) ] none : bool, } diff --git a/module/core/strs_tools/src/string/parse_request.rs b/module/core/strs_tools/src/string/parse_request.rs index f972a50852..e3c68de8f9 100644 --- a/module/core/strs_tools/src/string/parse_request.rs +++ b/module/core/strs_tools/src/string/parse_request.rs @@ -160,21 +160,21 @@ pub( crate ) mod private #[ perform( fn parse( mut self ) -> Request< 'a > ) ] pub struct ParseOptions< 'a > { - #[ default( "" ) ] + #[ former( default = "" ) ] src : &'a str, - #[ default( ":" ) ] + #[ former( default = ":" ) ] key_val_delimeter : &'a str, - #[ default( ";" ) ] + #[ former( default = ";" ) ] commands_delimeter : &'a str, - #[ default( true ) ] + #[ former( default = true ) ] quoting : bool, - #[ default( true ) ] + #[ former( default = true ) ] unquoting : bool, - #[ default( true ) ] + #[ former( default = true ) ] parsing_arrays : bool, - #[ default( false ) ] + #[ former( default = false ) ] several_values : bool, - #[ default( false ) ] + #[ former( default = false ) ] subject_win_paths_maybe : bool, } From d69f04293796f817f572db07a10d4a32eb6d598b Mon Sep 17 00:00:00 2001 From: Barsik Date: Mon, 6 May 2024 15:57:12 +0300 Subject: [PATCH 469/533] Using `former` in `wca` has been updated --- module/move/wca/src/ca/aggregator.rs | 32 ++++++++------- module/move/wca/src/ca/executor/executor.rs | 2 +- module/move/wca/src/ca/grammar/command.rs | 41 ++++++++++---------- module/move/wca/src/ca/grammar/dictionary.rs | 2 +- module/move/wca/src/ca/help.rs | 2 +- 5 files changed, 43 insertions(+), 36 deletions(-) diff --git a/module/move/wca/src/ca/aggregator.rs b/module/move/wca/src/ca/aggregator.rs index 9c287326a7..7712b5c3b5 100644 --- a/module/move/wca/src/ca/aggregator.rs +++ b/module/move/wca/src/ca/aggregator.rs @@ -5,13 +5,19 @@ pub( crate ) mod private { Verifier, Executor, - Command, - grammar::command::private::CommandFormer, + grammar::command::private:: + { + CommandFormer, + CommandAsSubformer, + CommandAsSubformerEnd, + CommandFormerStorage + }, help::{ HelpGeneratorFn, HelpGeneratorOptions, HelpVariants }, }; use std::collections::HashSet; use std::fmt; + use former::StoragePreform; use wtools::thiserror; use wtools::error:: { @@ -97,25 +103,25 @@ pub( crate ) mod private #[ perform( fn build() -> CommandsAggregator ) ] pub struct CommandsAggregator { - #[ default( Dictionary::default() ) ] + #[ former( default = Dictionary::default() ) ] dictionary : Dictionary, - #[ default( Parser ) ] + #[ former( default = Parser ) ] parser : Parser, - #[ setter( false ) ] - #[ default( Executor::former().form() ) ] + #[ scalar( setter = false, hint = false ) ] + #[ former( default = Executor::former().form() ) ] executor : Executor, help_generator : Option< HelpGeneratorFn >, - #[ default( HashSet::from([ HelpVariants::All ]) ) ] + #[ former( default = HashSet::from([ HelpVariants::All ]) ) ] help_variants : HashSet< HelpVariants >, // aaa : for Bohdan : should not have fields help_generator and help_variants // help_generator generateds VerifiedCommand(s) and stop to exist // aaa : Defaults after formation // #[ default( Verifier::former().form() ) ] - #[ default( Verifier ) ] + #[ former( default = Verifier ) ] verifier : Verifier, // #[ default( ExecutorConverter::former().form() ) ] @@ -124,25 +130,25 @@ pub( crate ) mod private callback_fn : Option< CommandsAggregatorCallback >, } - impl< Context, End > CommandsAggregatorFormer< Context, End > + impl< Definition > CommandsAggregatorFormer< Definition > where - End : former::FormingEnd< CommandsAggregator, Context >, + Definition : former::FormerDefinition< Storage = < CommandsAggregator as former::EntityToStorage >::Storage >, { /// Creates a command in the command chain. /// /// # Arguments /// /// * `name` - The name of the command. - pub fn command< IntoName >( self, name : IntoName ) -> CommandFormer< Self, impl former::FormingEnd< Command, Self > > + pub fn command< IntoName >( self, name : IntoName ) -> CommandAsSubformer< Self, impl CommandAsSubformerEnd< Self > > where IntoName : Into< String >, { - let on_end = | command : Command, super_former : Option< Self > | -> Self + let on_end = | command : CommandFormerStorage, super_former : Option< Self > | -> Self { let mut super_former = super_former.unwrap(); let mut dictionary = super_former.storage.dictionary.unwrap_or_default(); - dictionary.register( command ); + dictionary.register( command.preform() ); super_former.storage.dictionary = Some( dictionary ); diff --git a/module/move/wca/src/ca/executor/executor.rs b/module/move/wca/src/ca/executor/executor.rs index a48cc95bb7..1ba7ce66a4 100644 --- a/module/move/wca/src/ca/executor/executor.rs +++ b/module/move/wca/src/ca/executor/executor.rs @@ -16,7 +16,7 @@ pub( crate ) mod private pub struct Executor { /// The default context for the executor - #[ default( Context::default() ) ] + #[ former( default = Context::default() ) ] pub context : Context, } diff --git a/module/move/wca/src/ca/grammar/command.rs b/module/move/wca/src/ca/grammar/command.rs index 7d61e0ac38..0d1889bbb4 100644 --- a/module/move/wca/src/ca/grammar/command.rs +++ b/module/move/wca/src/ca/grammar/command.rs @@ -5,7 +5,7 @@ pub( crate ) mod private use { Handler, Routine, Type }; use std::collections::HashMap; - use former::Former; + use former::{ Former, StoragePreform }; /// A description of a Value in a command. Used to specify the expected type and provide a hint for the Value. /// @@ -27,7 +27,7 @@ pub( crate ) mod private /// expected type of a value pub kind : Type, /// subject optional parameter - #[ default( false ) ] + #[ former( default = false ) ] pub optional : bool, } @@ -42,16 +42,16 @@ pub( crate ) mod private /// expected type of a value kind : Type, /// subject optional parameter - #[ default( false ) ] + #[ former( default = false ) ] optional : bool, - #[ setter( false ) ] - #[ default( Vec::new() ) ] + #[ scalar( setter = false, hint = false ) ] + #[ former( default = Vec::new() ) ] properties_aliases : Vec< String >, } - impl< C, End > PropertyDescriptionFormer< C, End > + impl< Definition > PropertyDescriptionFormer< Definition > where - End : former::FormingEnd< PropertyDescription, C >, + Definition : former::FormerDefinition< Storage = < PropertyDescription as former::EntityToStorage >::Storage >, { pub fn alias< IntoName >( mut self, name : IntoName ) -> Self where @@ -89,10 +89,10 @@ pub( crate ) mod private pub struct Command { /// Command common hint. - #[ alias( h ) ] + // #[ alias( h ) ] // qqq: is it works? pub hint : String, /// Command full hint. - #[ alias( lh ) ] + // #[ alias( lh ) ] pub long_hint : String, /// Phrase descriptor for command. pub phrase : String, @@ -107,14 +107,14 @@ pub( crate ) mod private // aaa : here it is // qqq : make it usable and remove default(?) /// The type `Routine` represents the specific implementation of the routine. - #[ setter( false ) ] - #[ default( Routine::from( Handler::from( || { panic!( "No routine available: A handler function for the command is missing" ) } ) ) ) ] + #[ scalar( setter = false, hint = false ) ] + #[ former( default = Routine::from( Handler::from( || { panic!( "No routine available: A handler function for the command is missing" ) } ) ) ) ] pub routine : Routine, } - impl< Context, End > CommandFormer< Context, End > + impl< Definition > CommandFormer< Definition > where - End : former::FormingEnd< Command, Context >, + Definition : former::FormerDefinition< Storage = < Command as former::EntityToStorage >::Storage >, { /// Setter for separate properties aliases. pub fn property_alias< S : Into< String > >( mut self, key : S, alias : S ) -> Self @@ -169,21 +169,21 @@ pub( crate ) mod private } } - impl< Context, End > CommandFormer< Context, End > + impl< Definition > CommandFormer< Definition > where - End : former::FormingEnd< Command, Context >, + Definition : former::FormerDefinition< Storage = < Command as former::EntityToStorage >::Storage >, { /// Implements the `subject` method for a value. /// /// This method allows chaining, where `subject` is the current value and `ValueDescription` is the super-former. /// It returns a `ValueDescriptionFormer` which can be used to further build the super-former. - pub fn subject( self ) -> ValueDescriptionFormer< Self, impl former::FormingEnd< ValueDescription, Self > > + pub fn subject( self ) -> ValueDescriptionAsSubformer< Self, impl ValueDescriptionAsSubformerEnd< Self > > { - let on_end = | subject : ValueDescription, super_former : Option< Self > | -> Self + let on_end = | subject : ValueDescriptionFormerStorage, super_former : Option< Self > | -> Self { let mut super_former = super_former.unwrap(); let mut subjects = super_former.storage.subjects.unwrap_or_default(); - subjects.push( subject ); + subjects.push( subject.preform() ); super_former.storage.subjects = Some( subjects ); @@ -201,14 +201,15 @@ pub( crate ) mod private /// # Arguments /// /// * `name` - The name of the property. It should implement the `Into< String >` trait. - pub fn property< IntoName >( self, name : IntoName ) -> PropertyDescriptionFormer< Self, impl former::FormingEnd< PropertyDescription, Self > > + pub fn property< IntoName >( self, name : IntoName ) -> PropertyDescriptionAsSubformer< Self, impl PropertyDescriptionAsSubformerEnd< Self > > where IntoName : Into< String >, { - let on_end = | property : PropertyDescription, super_former : Option< Self > | -> Self + let on_end = | property : PropertyDescriptionFormerStorage, super_former : Option< Self > | -> Self { let mut super_former = super_former.unwrap(); let mut properties = super_former.storage.properties.unwrap_or_default(); + let property = property.preform(); let value = ValueDescription { hint : property.hint, diff --git a/module/move/wca/src/ca/grammar/dictionary.rs b/module/move/wca/src/ca/grammar/dictionary.rs index 21fc962efb..a9a79d198a 100644 --- a/module/move/wca/src/ca/grammar/dictionary.rs +++ b/module/move/wca/src/ca/grammar/dictionary.rs @@ -20,7 +20,7 @@ pub( crate ) mod private #[ derive( Debug, Default, Former, Clone ) ] pub struct Dictionary { - #[ setter( false ) ] + #[ scalar( setter = false, hint = false ) ] pub( crate ) commands : HashMap< String, Command >, } diff --git a/module/move/wca/src/ca/help.rs b/module/move/wca/src/ca/help.rs index 54d1485a12..028a79347e 100644 --- a/module/move/wca/src/ca/help.rs +++ b/module/move/wca/src/ca/help.rs @@ -29,7 +29,7 @@ pub( crate ) mod private pub struct HelpGeneratorOptions< 'a > { /// Prefix that will be shown before command name - #[ default( String::new() ) ] + #[ former( default = String::new() ) ] pub command_prefix : String, /// Show help for the specified commands pub for_commands : Vec< &'a Command >, From e61984bcbf874226e0cd3452a48b0ae8042242cc Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 6 May 2024 16:11:06 +0300 Subject: [PATCH 470/533] former : examples and cleaning --- module/core/former/Readme.md | 30 ++- .../examples/former_custom_container.rs | 68 ++++++ .../examples/former_subformer_hashmap.rs | 1 - .../examples/former_subformer_hashset.rs | 1 - module/core/former/src/container.rs | 9 +- .../a_containers_with_subformer_manual.rs | 5 +- .../subformer_container_custom.rs | 219 ++++++++++++++++++ module/core/former/tests/inc/mod.rs | 2 + 8 files changed, 326 insertions(+), 9 deletions(-) create mode 100644 module/core/former/examples/former_custom_container.rs create mode 100644 module/core/former/tests/inc/former_tests/subformer_container_custom.rs diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 2bb3bea73a..01f5ce0242 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -683,7 +683,6 @@ This example demonstrates the use of a `HashMapSubformer` to build a hash map wi #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { - use test_tools::exposed::*; #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithMap @@ -711,7 +710,6 @@ In the following example, a `HashSetSubformer` is utilized to construct a hash s #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { - use test_tools::exposed::*; #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithSet @@ -973,6 +971,34 @@ fn main() } ``` +## General Container Interface + +There are suite of traits designed to abstract and enhance the functionality of container data structures within the forming process. These traits are integral to managing the complexity of container operations, such as adding, modifying, and converting between different representations within containers like vectors, hash maps, etc. They are especially useful when used in conjunction with the `container` attribute in the `former` macro, which automates the implementation of these traits to create robust and flexible builder patterns for complex data structures. + +- [`Container`] - Defines basic functionalities for containers, managing entries and values, establishing the fundamental operations required for any custom container implementation in forming processes. +- [`EntryToVal`] - Facilitates the conversion of container entries to their value representations, crucial for operations that treat container elements more abstractly as values. +- [`ValToEntry`] - Provides the reverse functionality of `EntryToVal`, converting values back into entries, which is essential for operations that require adding or modifying entries in the container based on value data. +- [`ContainerAdd`] - Adds functionality for inserting entries into a container, considering container-specific rules such as duplication handling and order preservation, enhancing the usability of containers in forming scenarios. +- [`ContainerAssign`] - Extends the container functionality to replace all existing entries with new ones, enabling bulk updates or complete resets of container contents, which is particularly useful in dynamic data environments. + +## Custom Container Former + +Container interface is defined in the crate and implemented for containers like vectors, hash maps, etc, but if you want to use non-standard container you can implement container interface for the container. This example demonstrate how to do that. + +```rust + +// Ensure the example only compiles when the appropriate features are enabled. +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +fn main() +{ + use collection_tools::HashMap; + use former::Former; + + xxx : write + +} +``` + ## Concept of Mutator Provides a mechanism for mutating the context and storage just before the forming process is completed. diff --git a/module/core/former/examples/former_custom_container.rs b/module/core/former/examples/former_custom_container.rs new file mode 100644 index 0000000000..822be42bb3 --- /dev/null +++ b/module/core/former/examples/former_custom_container.rs @@ -0,0 +1,68 @@ +/// Example former_custom_container.rs +/// +/// Container interface is defined in the crate and implemented for containers like vectors, hash maps, etc, but if you want to use non-standard container you can implement container interface for the container. This example demonstrate how to do that. + + +#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +fn main() {} +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +fn main() +{ + use collection_tools::HashSet; + use std::fmt; + + // = define custom container + + // Custom container that logs additions + #[derive(Default)] + pub struct LoggingSet + { + set: HashSet, + } + +// // Implementing the container traits for LoggingSet +// impl former::Container for LoggingSet +// { +// type Entry = T; +// type Val = T; +// +// fn entry_to_val(e: Self::Entry) -> Self::Val +// { +// e // In this simple case, entry and value are the same. +// } +// } + + // This trait allows adding entries to the LoggingSet + impl former::ContainerAdd for LoggingSet + { + fn add(&mut self, e: Self::Entry) -> bool + { + let result = self.set.insert(e); + if result { + println!("{:?} was added to the set", e); + } + result + } + } + + // = use custom container + + // Define a struct to use with Former + #[derive(Debug, PartialEq, former::Former)] + pub struct CollectionContainer + { + #[container] + data: LoggingSet, + } + + // Using the builder pattern provided by Former to manipulate CollectionContainer + let mut container = CollectionContainer::former().data(); + + container.add(10); + container.add(20); + container.add(10); // This will not be added again, and "add" will log the attempt. + + let final_container = container.end().form(); + + println!("Final container: {:?}", final_container); +} \ No newline at end of file diff --git a/module/core/former/examples/former_subformer_hashmap.rs b/module/core/former/examples/former_subformer_hashmap.rs index 7087b4c395..78472c52ce 100644 --- a/module/core/former/examples/former_subformer_hashmap.rs +++ b/module/core/former/examples/former_subformer_hashmap.rs @@ -7,7 +7,6 @@ fn main() {} #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { - use test_tools::exposed::*; #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithMap diff --git a/module/core/former/examples/former_subformer_hashset.rs b/module/core/former/examples/former_subformer_hashset.rs index f9a823a284..3bf8a65d89 100644 --- a/module/core/former/examples/former_subformer_hashset.rs +++ b/module/core/former/examples/former_subformer_hashset.rs @@ -7,7 +7,6 @@ fn main() {} #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { - use test_tools::exposed::*; #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithSet diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 1386ad63fd..49a4332bba 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -1,6 +1,9 @@ -// File container.rs - -//! Interface for containers. +//! +//! This module defines traits and structures that facilitate the management and manipulation +//! of container data structures within a builder pattern context. It provides a comprehensive +//! interface for adding, managing, and converting elements within various types of containers, +//! such as vectors, hash maps, and custom container implementations. +//! use crate::*; diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 237150fdb0..1e712189ce 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -569,9 +569,10 @@ impl Default for Struct1FormerAssignHashset1End } #[automatically_derived] -impl former::FormingEnd< former::HashSetDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignHashset1End +impl former::FormingEnd< former::HashSetDefinition, Struct1Former, former::NoEnd>, > +for Struct1FormerAssignHashset1End where - Definition : former::FormerDefinition, + Definition : former::FormerDefinition< Storage = Struct1FormerStorage<> >, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { #[inline(always)] diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs new file mode 100644 index 0000000000..e0aaa9c941 --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -0,0 +1,219 @@ +// #![ allow( dead_code ) ] +// +// use super::*; +// use collection_tools::HashSet; +// use std::fmt; +// +// // == define custom containers +// +// // Custom container that logs additions +// #[derive(Default)] +// pub struct LoggingSet +// where +// K : core::cmp::Eq + core::hash::Hash, +// { +// set: HashSet, +// } +// +// impl< K > former::Container for LoggingSet< K > +// where +// K : core::cmp::Eq + core::hash::Hash, +// { +// type Entry = K; +// type Val = K; +// +// #[ inline( always ) ] +// fn entry_to_val( e : Self::Entry ) -> Self::Val +// { +// e +// } +// +// } +// +// impl< K > former::ContainerAdd for LoggingSet< K > +// where +// K : core::cmp::Eq + core::hash::Hash, +// { +// // type Entry = K; +// // type Val = K; +// +// #[ inline( always ) ] +// fn add( &mut self, e : Self::Entry ) -> bool +// { +// self.set.insert( e ) +// } +// +// } +// +// impl< K > former::ContainerAssign for LoggingSet< K > +// where +// K : core::cmp::Eq + core::hash::Hash, +// { +// // type Entry = K; +// +// fn assign< Elements >( &mut self, elements : Elements ) -> usize +// where +// Elements : IntoIterator< Item = Self::Entry > +// { +// let initial_len = self.len(); +// self.set.extend( elements ); +// self.set.len() - initial_len +// } +// } +// +// impl< K > former::ValToEntry< LoggingSet< K > > for K +// where +// K : core::cmp::Eq + core::hash::Hash, +// { +// type Entry = K; +// #[ inline( always ) ] +// fn val_to_entry( self ) -> Self::Entry +// { +// self +// } +// } +// +// // xxx : test with HashSetLike +// // +// // impl< K > HashSetLike< K > for LoggingSet< K > +// // where +// // K : core::cmp::Eq + core::hash::Hash, +// // { +// // fn insert( &mut self, element : K ) -> Option< K > +// // { +// // HashSet::replace( self, element ) +// // } +// // } +// +// // = storage +// +// impl< K > former::Storage +// for LoggingSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// type Formed = LoggingSet< K >; +// // xxx : rid off Formed maybe? +// } +// +// impl< K > former::StoragePreform +// for LoggingSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// type Preformed = LoggingSet< K >; +// fn preform( self ) -> Self::Preformed +// { +// self +// } +// } +// +// // = definition types +// +// #[ derive( Debug, Default ) ] +// pub struct HashSetDefinitionTypes< K, Context = (), Formed = LoggingSet< K > > +// { +// _phantom : core::marker::PhantomData< ( K, Context, Formed ) >, +// } +// +// impl< K, Context, Formed > FormerDefinitionTypes +// for HashSetDefinitionTypes< K, Context, Formed, NoEnd > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// type Storage = LoggingSet< K >; +// type Formed = Formed; +// type Context = Context; +// } +// +// // = definition +// +// #[ derive( Debug, Default ) ] +// pub struct HashSetDefinition< K, Context = (), Formed = LoggingSet< K >, End = ReturnStorage > +// { +// _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, +// } +// +// impl< K, Context, Formed, End > FormerDefinition +// for HashSetDefinition< K, Context, Formed, End > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// End : FormingEnd< HashSetDefinition< K, Context, Formed, NoEnd > >, +// { +// type Storage = LoggingSet< K >; +// type Formed = Formed; +// type Context = Context; +// +// type Types = HashSetDefinition< K, Context, Formed, NoEnd >; +// type End = End; +// } +// +// // = mutator +// +// impl< K, Context, Formed > FormerMutator +// for HashSetDefinition< K, Context, Formed, NoEnd > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// } +// +// // = Entity To +// +// impl< K, Definition > EntityToFormer< Definition > for LoggingSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// Definition : FormerDefinition< Storage = LoggingSet< K >, Formed = () >, +// < Definition as definition::FormerDefinition>::End : Fn( LoggingSet< K >, Option< Definition::Context > ), +// { +// type Former = HashSetSubformer< K, Definition::Context, Definition::Formed, Definition::End >; +// } +// +// impl< K > crate::EntityToStorage +// for LoggingSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// type Storage = LoggingSet< K >; +// } +// +// impl< K, Context, Formed, End > crate::EntityToDefinition< Context, Formed, End > +// for LoggingSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// End : crate::FormingEnd< HashSetDefinition< K, Context, Formed, NoEnd > >, +// { +// type Definition = HashSetDefinition< K, Context, Formed, End >; +// } +// +// // == use custom container +// +// /// Parent required for the template. +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// // #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +// // #[ derive( Debug, Default, PartialEq ) ] +// pub struct Parent +// { +// #[ container ] +// children: LoggingSet, +// } +// +// // == begin of generated +// +// // == end of generated +// +// #[ test ] +// fn basic() +// { +// +// // Using the builder pattern provided by Former to manipulate Parent +// let mut parent = Parent::former() +// .children() +// .add(10) +// .add(20) +// .add(10) +// .end() +// .form(); +// +// println!("Got: {:?}", parent); +// +// } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 737ec7ead1..e5467bb3c5 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -74,6 +74,8 @@ mod former_tests mod subformer_container_setter_off; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_container_named; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_custom; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform; From 8247b8d378de863e8a04032e12d662282e969e19 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 6 May 2024 16:11:35 +0300 Subject: [PATCH 471/533] former : examples and cleaning --- .../inc/former_tests/a_containers_with_subformer_manual.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 1e712189ce..237150fdb0 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -569,10 +569,9 @@ impl Default for Struct1FormerAssignHashset1End } #[automatically_derived] -impl former::FormingEnd< former::HashSetDefinition, Struct1Former, former::NoEnd>, > -for Struct1FormerAssignHashset1End +impl former::FormingEnd< former::HashSetDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignHashset1End where - Definition : former::FormerDefinition< Storage = Struct1FormerStorage<> >, + Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { #[inline(always)] From a80258c66104cbefe6e66f69743bcc3fe615d118 Mon Sep 17 00:00:00 2001 From: Barsik Date: Mon, 6 May 2024 16:22:55 +0300 Subject: [PATCH 472/533] Using `former` in `willbe` has been updated --- module/core/process_tools/src/process.rs | 2 +- module/move/willbe/src/action/test.rs | 16 +++++----- module/move/willbe/src/command/list.rs | 19 ++++++------ module/move/willbe/src/command/publish.rs | 7 +++-- .../move/willbe/src/command/publish_diff.rs | 3 +- module/move/willbe/src/command/test.rs | 29 ++++++++++--------- .../willbe/src/command/workspace_renew.rs | 3 +- module/move/willbe/src/entity/package.rs | 6 ++-- module/move/willbe/src/entity/test.rs | 6 ++-- module/move/willbe/src/tool/cargo.rs | 4 +-- module/move/willbe/src/tool/template.rs | 22 +++++++------- 11 files changed, 62 insertions(+), 55 deletions(-) diff --git a/module/core/process_tools/src/process.rs b/module/core/process_tools/src/process.rs index 3060f0d105..29af5a1a80 100644 --- a/module/core/process_tools/src/process.rs +++ b/module/core/process_tools/src/process.rs @@ -211,7 +211,7 @@ pub( crate ) mod private bin_path : PathBuf, current_path : PathBuf, args : Vec< OsString >, - #[ default( false ) ] + #[ former( default = false ) ] joining_streams : bool, env_variable : HashMap< String, String >, } diff --git a/module/move/willbe/src/action/test.rs b/module/move/willbe/src/action/test.rs index 3f9bd57009..72483c71d6 100644 --- a/module/move/willbe/src/action/test.rs +++ b/module/move/willbe/src/action/test.rs @@ -69,24 +69,24 @@ mod private { dir : AbsolutePath, channels : HashSet< channel::Channel >, - #[ default( 0u32 ) ] + #[ former( default = 0u32 ) ] concurrent : u32, - #[ default( 1u32 ) ] + #[ former( default = 1u32 ) ] power : u32, include_features : Vec< String >, - #[ default ( [ "full".to_string(), "default".to_string() ] ) ] + #[ former( default = [ "full".to_string(), "default".to_string() ] ) ] exclude_features : Vec< String >, - #[ default( true ) ] + #[ former( default = true ) ] temp : bool, enabled_features : Vec< String >, - #[ default( true ) ] + #[ former( default = true ) ] with_all_features : bool, - #[ default( true ) ] + #[ former( default = true ) ] with_none_features : bool, optimizations : HashSet< optimization::Optimization >, - #[ default( 1000u32 ) ] + #[ former( default = 1000u32 ) ] variants_cap : u32, - #[ default( false ) ] + #[ former( default = false ) ] with_progress : bool, } diff --git a/module/move/willbe/src/command/list.rs b/module/move/willbe/src/command/list.rs index 593f40193d..9c970783f9 100644 --- a/module/move/willbe/src/command/list.rs +++ b/module/move/willbe/src/command/list.rs @@ -19,27 +19,28 @@ mod private use action::{ list as l, list::{ ListFormat, ListOptions } }; use former::Former; + // qqq: `Former` forces the struct to be public #[ derive( Former ) ] - struct ListProperties + pub struct ListProperties { - #[ default( ListFormat::Tree ) ] + #[ former( default = ListFormat::Tree ) ] format : ListFormat, - #[ default( false ) ] + #[ former( default = false ) ] with_version : bool, - #[ default( false ) ] + #[ former( default = false ) ] with_path : bool, - #[ default( true ) ] + #[ former( default = true ) ] with_local : bool, - #[ default( false ) ] + #[ former( default = false ) ] with_remote : bool, - #[ default( true ) ] + #[ former( default = true ) ] with_primary : bool, - #[ default( false ) ] + #[ former( default = false ) ] with_dev : bool, - #[ default( false ) ] + #[ former( default = false ) ] with_build : bool, } diff --git a/module/move/willbe/src/command/publish.rs b/module/move/willbe/src/command/publish.rs index d591f56fe3..2724b33b78 100644 --- a/module/move/willbe/src/command/publish.rs +++ b/module/move/willbe/src/command/publish.rs @@ -9,12 +9,13 @@ mod private use former::Former; use std::fmt::Write; + // qqq: `Former` forces the struct to be public #[ derive( Former ) ] - struct PublishProperties + pub struct PublishProperties { - #[ default( true ) ] + #[ former( default = true ) ] dry : bool, - #[ default( true ) ] + #[ former( default = true ) ] temp : bool, } diff --git a/module/move/willbe/src/command/publish_diff.rs b/module/move/willbe/src/command/publish_diff.rs index 961ba818c4..cbb029393e 100644 --- a/module/move/willbe/src/command/publish_diff.rs +++ b/module/move/willbe/src/command/publish_diff.rs @@ -8,8 +8,9 @@ mod private use wtools::error::Result; use _path::AbsolutePath; + // qqq: `Former` forces the struct to be public #[ derive( former::Former ) ] - struct PublishDiffProperties + pub struct PublishDiffProperties { keep_archive : Option< PathBuf >, } diff --git a/module/move/willbe/src/command/test.rs b/module/move/willbe/src/command/test.rs index 5f72660220..e97ff16b5f 100644 --- a/module/move/willbe/src/command/test.rs +++ b/module/move/willbe/src/command/test.rs @@ -14,35 +14,36 @@ mod private use channel::Channel; use error_tools::for_app::bail; use optimization::Optimization; - + + // qqq: `Former` forces the struct to be public #[ derive( Former, Debug ) ] - struct TestsProperties + pub struct TestsProperties { - #[ default( true ) ] + #[ former( default = true ) ] dry : bool, - #[ default( true ) ] + #[ former( default = true ) ] with_stable : bool, - #[ default( false ) ] + #[ former( default = false ) ] with_nightly : bool, - #[ default( 0u32 ) ] + #[ former( default = 0u32 ) ] concurrent : u32, - #[ default( 1u32 ) ] + #[ former( default = 1u32 ) ] power : u32, include : Vec< String >, - #[ default ( [ "full".to_string(), "default".to_string() ] ) ] + #[ former( default = [ "full".to_string(), "default".to_string() ] ) ] exclude : Vec< String >, - #[ default( true ) ] + #[ former( default = true ) ] temp : bool, enabled_features : Vec< String >, - #[ default( true ) ] + #[ former( default = true ) ] with_all_features : bool, - #[ default( true ) ] + #[ former( default = true ) ] with_none_features : bool, - #[ default( true ) ] + #[ former( default = true ) ] with_debug : bool, - #[ default( false ) ] + #[ former( default = false ) ] with_release : bool, - #[ default( true ) ] + #[ former( default = true ) ] with_progress : bool, } diff --git a/module/move/willbe/src/command/workspace_renew.rs b/module/move/willbe/src/command/workspace_renew.rs index 26cc520bf4..4307e20045 100644 --- a/module/move/willbe/src/command/workspace_renew.rs +++ b/module/move/willbe/src/command/workspace_renew.rs @@ -7,8 +7,9 @@ mod private use wtools::error::{ anyhow::Context, Result }; use action::WorkspaceTemplate; + // qqq: `Former` forces the struct to be public #[ derive( Former ) ] - struct WorkspaceNewProperties + pub struct WorkspaceNewProperties { repository_url : String, branches : Vec< String >, diff --git a/module/move/willbe/src/entity/package.rs b/module/move/willbe/src/entity/package.rs index 97522326bf..68d17afd72 100644 --- a/module/move/willbe/src/entity/package.rs +++ b/module/move/willbe/src/entity/package.rs @@ -367,7 +367,7 @@ mod private workspace_dir : CrateDir, package : Package, base_temp_dir : Option< PathBuf >, - #[ default( true ) ] + #[ former( default = true ) ] dry : bool, } @@ -483,7 +483,7 @@ mod private /// `dry` - A boolean value indicating whether to do a dry run. If set to `true`, the application performs /// a simulated run without making any actual changes. If set to `false`, the operations are actually executed. /// This property is optional and defaults to `true`. - #[ default( true ) ] + #[ former( default = true ) ] pub dry : bool, /// Required for tree view only @@ -494,7 +494,7 @@ mod private /// how to build and where to publish the package amongst other instructions. The `#[setter( false )]` /// attribute indicates that there is no setter method for the `plans` variable and it can only be modified /// within the struct. - #[ setter( false ) ] + #[ scalar( setter = false, hint = false ) ] pub plans : Vec< PackagePublishInstruction >, } diff --git a/module/move/willbe/src/entity/test.rs b/module/move/willbe/src/entity/test.rs index f68f4cb56f..7735bc5af1 100644 --- a/module/move/willbe/src/entity/test.rs +++ b/module/move/willbe/src/entity/test.rs @@ -336,11 +336,11 @@ mod private optimization : Optimization, /// Determines whether to use default features in the test. /// Enabled by default. - #[ default( true ) ] + #[ former( default = true ) ] with_default_features : bool, /// Determines whether to use all available features in the test. /// Disabled by default. - #[ default( false ) ] + #[ former( default = false ) ] with_all_features : bool, /// Specifies a list of features to be enabled in the test. enable_features : BTreeSet< String >, @@ -349,7 +349,7 @@ mod private /// A boolean indicating whether to perform a dry run or not. dry : bool, /// RUST_BACKTRACE - #[ default( true ) ] + #[ former( default = true ) ] backtrace : bool, } diff --git a/module/move/willbe/src/tool/cargo.rs b/module/move/willbe/src/tool/cargo.rs index 6a078e0eab..259c828791 100644 --- a/module/move/willbe/src/tool/cargo.rs +++ b/module/move/willbe/src/tool/cargo.rs @@ -14,9 +14,9 @@ mod private pub struct PackOptions { pub( crate ) path : PathBuf, - #[ default( false ) ] + #[ former( default = false ) ] pub( crate ) allow_dirty : bool, - #[ default( false ) ] + #[ former( default = false ) ] pub( crate ) no_verify : bool, pub( crate ) temp_path : Option< PathBuf >, pub( crate ) dry : bool, diff --git a/module/move/willbe/src/tool/template.rs b/module/move/willbe/src/tool/template.rs index 9e00f793b3..afc9941dd1 100644 --- a/module/move/willbe/src/tool/template.rs +++ b/module/move/willbe/src/tool/template.rs @@ -4,7 +4,7 @@ mod private use std::fs; use error_tools::for_app::Context; use error_tools::Result; - use former::Former; + use former::{ Former, StoragePreform }; use wca::Props; use std::path::Path; use std::path::PathBuf; @@ -138,17 +138,18 @@ mod private is_mandatory : bool, } - impl< Context, End > TemplateParametersFormer< Context, End > + impl< Definition > TemplateParametersFormer< Definition > where - End : former::FormingEnd< TemplateParameters, Context >, + Definition : former::FormerDefinition< Storage = < TemplateParameters as former::EntityToStorage >::Storage >, { #[ inline( always ) ] pub fn parameter( self, name : &str ) -> - TemplateParameterDescriptorFormer< Self, impl former::FormingEnd< TemplateParameterDescriptor, Self > > + TemplateParameterDescriptorAsSubformer< Self, impl TemplateParameterDescriptorAsSubformerEnd< Self > > { - let on_end = | descriptor : TemplateParameterDescriptor, super_former : core::option::Option< Self > | -> Self + let on_end = | descriptor : TemplateParameterDescriptorFormerStorage, super_former : core::option::Option< Self > | -> Self { let mut super_former = super_former.unwrap(); + let descriptor = descriptor.preform(); if let Some( ref mut descriptors ) = super_former.storage.descriptors { descriptors.push( descriptor ); @@ -313,20 +314,21 @@ mod private pub struct TemplateFilesBuilder { /// Stores all file descriptors for current template. - #[ setter( false ) ] + #[ scalar( setter = false, hint = false ) ] pub files : Vec< TemplateFileDescriptor >, } - impl< Context, End > TemplateFilesBuilderFormer< Context, End > + impl< Description > TemplateFilesBuilderFormer< Description > where - End : former::FormingEnd< TemplateFilesBuilder, Context >, + Description : former::FormerDefinition< Storage = < TemplateFilesBuilder as former::EntityToStorage >::Storage >, { #[ inline( always ) ] - pub fn file( self ) -> TemplateFileDescriptorFormer< Self, impl former::FormingEnd< TemplateFileDescriptor, Self > > + pub fn file( self ) -> TemplateFileDescriptorAsSubformer< Self, impl TemplateFileDescriptorAsSubformerEnd< Self > > { - let on_end = | descriptor : TemplateFileDescriptor, super_former : core::option::Option< Self > | -> Self + let on_end = | descriptor : TemplateFileDescriptorFormerStorage, super_former : core::option::Option< Self > | -> Self { let mut super_former = super_former.unwrap(); + let descriptor = descriptor.preform(); if let Some( ref mut files ) = super_former.storage.files { files.push( descriptor ); From a9022196e87e100e9e65e27f9708a5b792e8884a Mon Sep 17 00:00:00 2001 From: Barsik Date: Mon, 6 May 2024 19:11:52 +0300 Subject: [PATCH 473/533] Subformer and mutator are used --- module/move/wca/src/ca/aggregator.rs | 64 ++++++++++------------- module/move/wca/src/ca/grammar/command.rs | 15 +----- module/move/willbe/src/tool/template.rs | 37 +++---------- 3 files changed, 36 insertions(+), 80 deletions(-) diff --git a/module/move/wca/src/ca/aggregator.rs b/module/move/wca/src/ca/aggregator.rs index 7712b5c3b5..197c1ff6e4 100644 --- a/module/move/wca/src/ca/aggregator.rs +++ b/module/move/wca/src/ca/aggregator.rs @@ -100,7 +100,8 @@ pub( crate ) mod private /// ``` #[ derive( Debug ) ] #[ derive( former::Former ) ] - #[ perform( fn build() -> CommandsAggregator ) ] + #[ storage_fields( help_generator : HelpGeneratorFn, help_variants : HashSet< HelpVariants > ) ] + #[ mutator( custom = true ) ] pub struct CommandsAggregator { #[ former( default = Dictionary::default() ) ] @@ -113,22 +114,35 @@ pub( crate ) mod private #[ former( default = Executor::former().form() ) ] executor : Executor, - help_generator : Option< HelpGeneratorFn >, - #[ former( default = HashSet::from([ HelpVariants::All ]) ) ] - help_variants : HashSet< HelpVariants >, - // aaa : for Bohdan : should not have fields help_generator and help_variants - // help_generator generateds VerifiedCommand(s) and stop to exist - // aaa : Defaults after formation - - // #[ default( Verifier::former().form() ) ] #[ former( default = Verifier ) ] verifier : Verifier, - // #[ default( ExecutorConverter::former().form() ) ] - // executor_converter : ExecutorConverter, - callback_fn : Option< CommandsAggregatorCallback >, } + + impl< Context, Formed > former::FormerMutator for CommandsAggregatorFormerDefinitionTypes< Context, Formed > + { + fn form_mutation( storage : &mut Self::Storage, _context : &mut Option< Self::Context > ) + { + let ca = storage; + let dictionary = ca.dictionary.get_or_insert_with( Dictionary::default ); + + let help_generator = std::mem::take( &mut ca.help_generator ).unwrap_or_default(); + let help_variants = std::mem::take( &mut ca.help_variants ).unwrap_or_else( || HashSet::from([ HelpVariants::All ]) ); + + if help_variants.contains( &HelpVariants::All ) + { + HelpVariants::All.generate( &help_generator, dictionary ); + } + else + { + for help in help_variants.iter().sorted() + { + help.generate( &help_generator, dictionary ); + } + } + } + } impl< Definition > CommandsAggregatorFormer< Definition > where @@ -205,7 +219,8 @@ pub( crate ) mod private self.storage.help_generator = Some( HelpGeneratorFn::new( func ) ); self } - // qqq : it is good access method, but formed structure should not have help_generator anymore + // aaa : it is good access method, but formed structure should not have help_generator anymore + // aaa : mutator used /// Set callback function that will be executed after validation state /// @@ -233,29 +248,6 @@ pub( crate ) mod private impl CommandsAggregator { - /// Construct CommandsAggregator - fn build( self ) -> CommandsAggregator - { - let mut ca = self; - - let help_generator = std::mem::take( &mut ca.help_generator ).unwrap_or_default(); - let help_variants = std::mem::take( &mut ca.help_variants ); - - if help_variants.contains( &HelpVariants::All ) - { - HelpVariants::All.generate( &help_generator, &mut ca.dictionary ); - } - else - { - for help in help_variants.iter().sorted() - { - help.generate( &help_generator, &mut ca.dictionary ); - } - } - - ca - } - /// Parse, converts and executes a program /// /// Takes a string with program and executes it diff --git a/module/move/wca/src/ca/grammar/command.rs b/module/move/wca/src/ca/grammar/command.rs index 0d1889bbb4..93648eda09 100644 --- a/module/move/wca/src/ca/grammar/command.rs +++ b/module/move/wca/src/ca/grammar/command.rs @@ -89,14 +89,13 @@ pub( crate ) mod private pub struct Command { /// Command common hint. - // #[ alias( h ) ] // qqq: is it works? pub hint : String, /// Command full hint. - // #[ alias( lh ) ] pub long_hint : String, /// Phrase descriptor for command. pub phrase : String, /// Command subjects hints and types. + #[ subform( setter = true ) ] pub subjects : Vec< ValueDescription >, /// Hints and types for command options. pub properties : HashMap< String, ValueDescription >, @@ -179,17 +178,7 @@ pub( crate ) mod private /// It returns a `ValueDescriptionFormer` which can be used to further build the super-former. pub fn subject( self ) -> ValueDescriptionAsSubformer< Self, impl ValueDescriptionAsSubformerEnd< Self > > { - let on_end = | subject : ValueDescriptionFormerStorage, super_former : Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - let mut subjects = super_former.storage.subjects.unwrap_or_default(); - subjects.push( subject.preform() ); - - super_former.storage.subjects = Some( subjects ); - - super_former - }; - ValueDescriptionFormer::begin( None, Some( self ), on_end ) + self._subjects_add() } /// Sets the name and other properties of the current property. diff --git a/module/move/willbe/src/tool/template.rs b/module/move/willbe/src/tool/template.rs index afc9941dd1..044f1157b9 100644 --- a/module/move/willbe/src/tool/template.rs +++ b/module/move/willbe/src/tool/template.rs @@ -4,7 +4,7 @@ mod private use std::fs; use error_tools::for_app::Context; use error_tools::Result; - use former::{ Former, StoragePreform }; + use former::Former; use wca::Props; use std::path::Path; use std::path::PathBuf; @@ -107,6 +107,7 @@ mod private #[ derive( Debug, Default, Former ) ] pub struct TemplateParameters { + #[ subform( setter = false ) ] descriptors : Vec< TemplateParameterDescriptor > } @@ -146,21 +147,8 @@ mod private pub fn parameter( self, name : &str ) -> TemplateParameterDescriptorAsSubformer< Self, impl TemplateParameterDescriptorAsSubformerEnd< Self > > { - let on_end = | descriptor : TemplateParameterDescriptorFormerStorage, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - let descriptor = descriptor.preform(); - if let Some( ref mut descriptors ) = super_former.storage.descriptors - { - descriptors.push( descriptor ); - } - else - { - super_former.storage.descriptors = Some( vec![ descriptor ] ); - } - super_former - }; - TemplateParameterDescriptorFormer::begin( None, Some( self ), on_end ).parameter( name ) + self._descriptors_add::< TemplateParameterDescriptorFormer< _ >, _ >() + .parameter( name ) } } @@ -314,6 +302,7 @@ mod private pub struct TemplateFilesBuilder { /// Stores all file descriptors for current template. + #[ subform( setter = true ) ] #[ scalar( setter = false, hint = false ) ] pub files : Vec< TemplateFileDescriptor >, } @@ -325,21 +314,7 @@ mod private #[ inline( always ) ] pub fn file( self ) -> TemplateFileDescriptorAsSubformer< Self, impl TemplateFileDescriptorAsSubformerEnd< Self > > { - let on_end = | descriptor : TemplateFileDescriptorFormerStorage, super_former : core::option::Option< Self > | -> Self - { - let mut super_former = super_former.unwrap(); - let descriptor = descriptor.preform(); - if let Some( ref mut files ) = super_former.storage.files - { - files.push( descriptor ); - } - else - { - super_former.storage.files = Some( vec![ descriptor ] ); - } - super_former - }; - TemplateFileDescriptorFormer::begin( None, Some( self ), on_end ) + self._files_add() } } From 31acf6a45f4d3995305e6ee706ae6e3fef7a661a Mon Sep 17 00:00:00 2001 From: Barsik Date: Mon, 6 May 2024 19:30:52 +0300 Subject: [PATCH 474/533] Fixed doc tests related to changes in former --- .../inc/former_tests/a_containers_with_subformer_manual.rs | 2 +- module/core/former_meta/src/derive_former.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 237150fdb0..02a68ccfbb 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -247,7 +247,7 @@ where } } -#[doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +#[doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[ former( default = 31 ) ]\n field1 : i32,\n}\n\n```\n"] pub struct Struct1Former< Definition = Struct1FormerDefinition<(), Struct1<>, former::ReturnPreformed>, > where Definition : former::FormerDefinition, diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index c5e486249b..65434df946 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -34,7 +34,7 @@ use former::Former; #[ derive( Former ) ] pub struct Struct1 { - #[default( 31 ) ] + #[ former( default = 31 ) ] field1 : i32, } "#; From e8e9bef8a8d2efdf7bbabb3f231e978eaa2e8bfa Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 12:20:37 +0300 Subject: [PATCH 475/533] former : solve problem with container interface --- module/core/former/src/container.rs | 1 + module/core/former/src/definition.rs | 12 +- module/core/former/src/forming.rs | 4 +- module/core/former/src/hash_map.rs | 47 ++- module/core/former/src/hash_set.rs | 48 ++- module/core/former/src/vector.rs | 43 ++- .../tests/inc/former_tests/a_basic_manual.rs | 7 + .../a_containers_with_subformer_manual.rs | 345 +++++++++++------- .../former_tests/container_former_common.rs | 4 +- module/core/former/tests/inc/mod.rs | 150 ++++---- module/core/former_meta/src/derive_former.rs | 32 +- .../former_meta/src/derive_former/field.rs | 233 ++++++++---- 12 files changed, 589 insertions(+), 337 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 49a4332bba..d59ae3518f 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -71,6 +71,7 @@ pub trait ValToEntry< Container > /// a value into a (key, value) tuple for insertion into a `HashMap`. fn val_to_entry( self ) -> Self::Entry; } + /// Provides functionality to add individual entries to a container. /// /// This trait extends the basic `Container` trait by introducing a method to add entries to a container. diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs index 1448bb6e04..c3a8619dc6 100644 --- a/module/core/former/src/definition.rs +++ b/module/core/former/src/definition.rs @@ -19,16 +19,24 @@ /// This trait provides a linkage between the entity and its definition, /// allowing the formation logic to understand what definition to apply /// during the formation process. -pub trait EntityToDefinition +pub trait EntityToDefinition< Context, Formed, End > { /// The specific `FormerDefinition` associated with this entity. type Definition : FormerDefinition; + type Types : FormerDefinitionTypes; +} + +/// xxx : update description +pub trait EntityToDefinitionTypes< Context, Formed > +{ + /// The specific `FormerDefinitionTypes` associated with this entity. + type Types : FormerDefinitionTypes; } /// Maps a type of entity to its corresponding former. /// This trait binds an entity type to a specific former, facilitating the use /// of custom formers in complex formation scenarios. -pub trait EntityToFormer +pub trait EntityToFormer< Definition > where Definition : FormerDefinition, { diff --git a/module/core/former/src/forming.rs b/module/core/former/src/forming.rs index 47e0088244..8bb8968418 100644 --- a/module/core/former/src/forming.rs +++ b/module/core/former/src/forming.rs @@ -244,7 +244,9 @@ for FormingEndClosure< Definition > /// of complex hierarchical data structures. /// -pub trait FormerBegin< Definition : crate::FormerDefinition > +pub trait FormerBegin< Definition : > +where + Definition : crate::FormerDefinition, { /// Launches the subforming process with an initial storage and context, setting up an `on_end` completion handler. diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index c986f54cf8..079ffb3bea 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -113,39 +113,47 @@ pub struct HashMapDefinition< K, E, Context = (), Formed = HashMap< K, E >, End _phantom : core::marker::PhantomData< ( K, E, Context, Formed, End ) >, } -impl< K, E, Context, Formed > FormerDefinitionTypes -for HashMapDefinition< K, E, Context, Formed, NoEnd > +impl< K, E, Context, Formed, End > FormerDefinition +for HashMapDefinition< K, E, Context, Formed, End > where K : ::core::cmp::Eq + ::core::hash::Hash, + End : FormingEnd< HashMapDefinitionTypes< K, E, Context, Formed > >, { + type Storage = HashMap< K, E >; type Formed = Formed; type Context = Context; + + type Types = HashMapDefinitionTypes< K, E, Context, Formed >; + type End = End; + } -impl< K, E, Context, Formed > FormerMutator -for HashMapDefinition< K, E, Context, Formed, NoEnd > -where - K : ::core::cmp::Eq + ::core::hash::Hash, +// = definition types + +#[ derive( Debug, Default ) ] +pub struct HashMapDefinitionTypes< K, E, Context = (), Formed = HashMap< K, E > > { + _phantom : core::marker::PhantomData< ( K, E, Context, Formed ) >, } -impl< K, E, Context, Formed, End > FormerDefinition -for HashMapDefinition< K, E, Context, Formed, End > +impl< K, E, Context, Formed > FormerDefinitionTypes +for HashMapDefinitionTypes< K, E, Context, Formed > where K : ::core::cmp::Eq + ::core::hash::Hash, - End : FormingEnd< HashMapDefinition< K, E, Context, Formed, NoEnd > >, { - // type Types = HashMapDefinition< K, E, Context, Formed, NoEnd >; - // type End = End; - type Storage = HashMap< K, E >; type Formed = Formed; type Context = Context; +} - type Types = HashMapDefinition< K, E, Context, Formed, NoEnd >; - type End = End; +// = mutator +impl< K, E, Context, Formed > FormerMutator +for HashMapDefinitionTypes< K, E, Context, Formed > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ } // = Entity To @@ -171,9 +179,18 @@ impl< K, E, Context, Formed, End > crate::EntityToDefinition< Context, Formed, E for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, - End : crate::FormingEnd< HashMapDefinition< K, E, Context, Formed, NoEnd > >, + End : crate::FormingEnd< HashMapDefinitionTypes< K, E, Context, Formed > >, { type Definition = HashMapDefinition< K, E, Context, Formed, End >; + type Types = HashMapDefinitionTypes< K, E, Context, Formed >; +} + +impl< K, E, Context, Formed > crate::EntityToDefinitionTypes< Context, Formed > +for HashMap< K, E > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Types = HashMapDefinitionTypes< K, E, Context, Formed >; } // = subformer diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 7f0bc16c55..a665b42224 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -98,7 +98,6 @@ for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - // type Types = HashSetDefinition< K >; type Formed = HashSet< K >; } @@ -108,24 +107,22 @@ where K : ::core::cmp::Eq + ::core::hash::Hash, { type Preformed = HashSet< K >; - // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed - // fn preform( self ) -> Self::Formed fn preform( self ) -> Self::Preformed { self } } -// = definition +// = definition types #[ derive( Debug, Default ) ] -pub struct HashSetDefinition< K, Context = (), Formed = HashSet< K >, End = ReturnStorage > +pub struct HashSetDefinitionTypes< K, Context = (), Formed = HashSet< K > > { - _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, + _phantom : core::marker::PhantomData< ( K, Context, Formed ) >, } impl< K, Context, Formed > FormerDefinitionTypes -for HashSetDefinition< K, Context, Formed, NoEnd > +for HashSetDefinitionTypes< K, Context, Formed > where K : ::core::cmp::Eq + ::core::hash::Hash, { @@ -134,33 +131,45 @@ where type Context = Context; } -impl< K, Context, Formed > FormerMutator -for HashSetDefinition< K, Context, Formed, NoEnd > -where - K : ::core::cmp::Eq + ::core::hash::Hash, +// = definition + +#[ derive( Debug, Default ) ] +pub struct HashSetDefinition< K, Context = (), Formed = HashSet< K >, End = ReturnStorage > { + _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, } impl< K, Context, Formed, End > FormerDefinition for HashSetDefinition< K, Context, Formed, End > where K : ::core::cmp::Eq + ::core::hash::Hash, - End : FormingEnd< HashSetDefinition< K, Context, Formed, NoEnd > >, + End : FormingEnd< HashSetDefinitionTypes< K, Context, Formed > >, { type Storage = HashSet< K >; type Formed = Formed; type Context = Context; - type Types = HashSetDefinition< K, Context, Formed, NoEnd >; + type Types = HashSetDefinitionTypes< K, Context, Formed >; type End = End; } -// = Entity To +// = mutator + +impl< K, Context, Formed > FormerMutator +for HashSetDefinitionTypes< K, Context, Formed > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ +} + +// = entity to impl< K, Definition > EntityToFormer< Definition > for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, Definition : FormerDefinition< Storage = HashSet< K >, Formed = () >, + Definition::Types : FormerDefinitionTypes< Storage = HashSet< K >, Formed = () >, + Definition::End : crate::FormingEnd< Definition::Types >, < Definition as definition::FormerDefinition>::End : Fn( HashSet< K >, Option< Definition::Context > ), { type Former = HashSetSubformer< K, Definition::Context, Definition::Formed, Definition::End >; @@ -178,9 +187,18 @@ impl< K, Context, Formed, End > crate::EntityToDefinition< Context, Formed, End for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, - End : crate::FormingEnd< HashSetDefinition< K, Context, Formed, NoEnd > >, + End : crate::FormingEnd< HashSetDefinitionTypes< K, Context, Formed > >, { type Definition = HashSetDefinition< K, Context, Formed, End >; + type Types = HashSetDefinitionTypes< K, Context, Formed >; +} + +impl< K, Context, Formed > crate::EntityToDefinitionTypes< Context, Formed > +for HashSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Types = HashSetDefinitionTypes< K, Context, Formed >; } // = subformer diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 2642b5b425..58a170f785 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -103,35 +103,45 @@ for Vec< E > #[ derive( Debug, Default ) ] pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > where - End : FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, + End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, { _phantom : core::marker::PhantomData< ( E, Context, Formed, End ) >, } -impl< E, Context, Formed > FormerDefinitionTypes -for VectorDefinition< E, Context, Formed, NoEnd > +impl< E, Context, Formed, End > FormerDefinition +for VectorDefinition< E, Context, Formed, End > +where + End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, { type Storage = Vec< E >; type Formed = Formed; type Context = Context; + + type Types = VectorDefinitionTypes< E, Context, Formed >; + type End = End; } -impl< E, Context, Formed > FormerMutator -for VectorDefinition< E, Context, Formed, NoEnd > +// = definition type + +#[ derive( Debug, Default ) ] +pub struct VectorDefinitionTypes< E, Context = (), Formed = Vec< E > > { + _phantom : core::marker::PhantomData< ( E, Context, Formed ) >, } -impl< E, Context, Formed, End > FormerDefinition -for VectorDefinition< E, Context, Formed, End > -where - End : FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, +impl< E, Context, Formed > FormerDefinitionTypes +for VectorDefinitionTypes< E, Context, Formed > { type Storage = Vec< E >; type Formed = Formed; type Context = Context; +} - type Types = VectorDefinition< E, Context, Formed, NoEnd >; - type End = End; +// = mutator + +impl< E, Context, Formed > FormerMutator +for VectorDefinitionTypes< E, Context, Formed > +{ } // = Entity To @@ -144,7 +154,7 @@ where Definition : FormerDefinition< Storage = Vec< E > >, Definition::Types : FormerDefinitionTypes< Storage = Vec< E >, Formed = Definition::Formed, Context = Definition::Context >, Definition::End : crate::FormingEnd< Definition::Types >, - Definition::End : Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed, + Definition::End : Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed, // xxx { type Former = VectorSubformer< E, Definition::Context, Definition::Formed, Definition::End >; } @@ -158,9 +168,16 @@ for Vec< E > impl< E, Context, Formed, End > crate::EntityToDefinition< Context, Formed, End > for Vec< E > where - End : crate::FormingEnd< VectorDefinition< E, Context, Formed, NoEnd > >, + End : crate::FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, { type Definition = VectorDefinition< E, Context, Formed, End >; + type Types = VectorDefinitionTypes< E, Context, Formed >; +} + +impl< E, Context, Formed > crate::EntityToDefinitionTypes< Context, Formed > +for Vec< E > +{ + type Types = VectorDefinitionTypes< E, Context, Formed >; } // = subformer diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index f7cd572173..0503af0f9e 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -45,6 +45,13 @@ where End : former::FormingEnd< Struct1FormerDefinitionTypes< Context, Formed > >, { type Definition = Struct1FormerDefinition< Context, Formed, End >; + type Types = Struct1FormerDefinitionTypes< Context, Formed >; +} + +impl< Context, Formed > former::EntityToDefinitionTypes< Context, Formed > +for Struct1 +{ + type Types = Struct1FormerDefinitionTypes< Context, Formed >; } // = definition types diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 237150fdb0..1e6b80e12e 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -5,8 +5,8 @@ use super::*; pub struct Struct1 { vec_1 : Vec< String >, - hashmap_1 : std::collections::HashMap< String, String >, - hashset_1 : std::collections::HashSet< String >, + hashmap_1 : collection_tools::HashMap< String, String >, + hashset_1 : collection_tools::HashSet< String >, } // == begin of generated @@ -15,10 +15,10 @@ pub struct Struct1 impl< > Struct1< > where { - #[doc = r""] - #[doc = r" Make former, variation of builder pattern to form structure defining values of fields step by step."] - #[doc = r""] - #[inline(always)] + + + + #[ inline( always ) ] pub fn former() -> Struct1Former< Struct1FormerDefinition<(), Struct1<>, former::ReturnPreformed> > @@ -105,22 +105,22 @@ where type Context = Context; } -#[doc = "Container of a corresponding former."] + pub struct Struct1FormerStorage<> where { - #[doc = r" A field"] + pub vec_1 : core::option::Option>, - #[doc = r" A field"] - pub hashmap_1 : core::option::Option>, - #[doc = r" A field"] - pub hashset_1 : core::option::Option>, + + pub hashmap_1 : core::option::Option>, + + pub hashset_1 : core::option::Option>, } impl< > core::default::Default for Struct1FormerStorage<> where { - #[inline(always)] + #[ inline( always ) ] fn default() -> Self { Self @@ -203,7 +203,7 @@ where } } - (&core::marker::PhantomData::>).maybe_default() + (&core::marker::PhantomData::>).maybe_default() } }; @@ -234,7 +234,7 @@ where } } - (&core::marker::PhantomData::>).maybe_default() + (&core::marker::PhantomData::>).maybe_default() } }; @@ -247,7 +247,7 @@ where } } -#[doc = " Object to form [Struct1]. If field's values is not set then default value of the field is set.\n\nFor specifying custom default value use attribute `default`. For example:\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] + pub struct Struct1Former< Definition = Struct1FormerDefinition<(), Struct1<>, former::ReturnPreformed>, > where Definition : former::FormerDefinition, @@ -264,19 +264,19 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { - #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] - #[inline(always)] + + + + #[ inline( always ) ] pub fn new(on_end: Definition::End) -> Self { Self::begin_coercing(None, None, on_end) } - #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] - #[inline(always)] + + + + #[ inline( always ) ] pub fn new_coercing(end: IntoEnd) -> Self where IntoEnd : Into, @@ -284,10 +284,10 @@ where Self::begin_coercing(None, None, end,) } - #[doc = r""] - #[doc = r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] - #[inline(always)] + + + + #[ inline( always ) ] pub fn begin(mut storage: core::option::Option<::Storage>, context: core::option::Option<::Context>, on_end: ::End,) -> Self { if storage.is_none() @@ -302,10 +302,10 @@ where } } - #[doc = r""] - #[doc = r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] - #[inline(always)] + + + + #[ inline( always ) ] pub fn begin_coercing(mut storage: core::option::Option<::Storage>, context: core::option::Option<::Context>, on_end: IntoEnd,) -> Self where IntoEnd : core::convert::Into<::End>, @@ -322,19 +322,19 @@ where } } - #[doc = r""] - #[doc = r" End the process of forming returning original context of forming."] - #[doc = r""] - #[inline(always)] + + + + #[ inline( always ) ] pub fn form(self) -> ::Formed { self.end() } - #[doc = r""] - #[doc = r" End the process of forming returning original context of forming."] - #[doc = r""] - #[inline(always)] + + + + #[ inline( always ) ] pub fn end(mut self) -> ::Formed { let on_end = self.on_end.take().unwrap(); @@ -342,68 +342,96 @@ where former::FormingEnd::::call(&on_end, self.storage, context) } - #[doc = "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] - #[inline(always)] - pub fn _vec_1_assign(self) -> Former2 +// #[ inline( always ) ] +// pub fn _vec_1_assign(self) -> Former2 +// where +// Former2 : former::FormerBegin,>>, +// { +// Former2::former_begin(None, Some(self), Struct1FormerAssignVec1End::::default()) +// } +// +// +// #[ inline( always ) ] +// pub fn vec_1(self) -> former::ContainerSubformer::< +// String, +// former::VectorDefinition,> +// > +// { +// self._vec_1_assign::,>>> () +// } +// +// +// #[ inline( always ) ] +// pub fn _hashmap_1_assign(self) -> Former2 +// where +// Former2 : former::FormerBegin,>>, +// { +// Former2::former_begin(None, Some(self), Struct1FormerAssignHashmap1End::::default()) +// } +// +// +// #[ inline( always ) ] +// pub fn hashmap_1(self) -> former::ContainerSubformer:: +// < +// (String, String,), +// former::HashMapDefinition,> +// > +// { +// self._hashmap_1_assign::,> +// >> () +// } +// xxx + + #[ inline( always ) ] + pub fn _hashset_1_assign< Former2 >( self ) -> Former2 where - Former2 : former::FormerBegin,>>, + Former2 : former::FormerBegin + < + former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, + >, + former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > > : former::FormerDefinition + < + Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, + Context = Struct1Former< Definition >, + End = Struct1FormerAssignHashset1End< Definition >, + >, + // Struct1FormerAssignHashset1End< Definition > : former::FormingEnd + // < + // former::HashSetDefinitionTypes< String, Struct1Former< Definition >, Struct1Former< Definition > > + // >, { - Former2::former_begin(None, Some(self), Struct1FormerAssignVec1End::::default()) + Former2::former_begin( None, Some( self ), Struct1FormerAssignHashset1End::< Definition >::default() ) } - #[doc = "Subformer setter for the 'vec_1' field. Method _vec_1_assign unlike method vec_1 accept custom container subformer."] - #[inline(always)] - pub fn vec_1(self) -> former::ContainerSubformer::< + #[ inline( always ) ] + pub fn hashset_1( self ) -> former::ContainerSubformer:: + < String, - former::VectorDefinition,> + former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, > - { - self._vec_1_assign::,>>> () - } - - #[doc = "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] - #[inline(always)] - pub fn _hashmap_1_assign(self) -> Former2 where - Former2 : former::FormerBegin,>>, + former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > > : former::FormerDefinition + < + Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, + Context = Struct1Former< Definition >, + End = Struct1FormerAssignHashset1End< Definition >, + >, + // Struct1FormerAssignHashset1End< Definition > : former::FormingEnd + // < + // former::HashSetDefinitionTypes< String, Struct1Former< Definition >, Struct1Former< Definition > >, + // >, { - Former2::former_begin(None, Some(self), Struct1FormerAssignHashmap1End::::default()) - } - - #[doc = "Subformer setter for the 'hashmap_1' field. Method _hashmap_1_assign unlike method hashmap_1 accept custom container subformer."] - #[inline(always)] - pub fn hashmap_1(self) -> former::ContainerSubformer::< - (String, String,), - former::HashMapDefinition,> - > - { - self._hashmap_1_assign::,> - >> () + self._hashset_1_assign::< former::ContainerSubformer:: + < + String, + former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, + > > () } - #[doc = "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] - #[inline(always)] - pub fn _hashset_1_assign(self) -> Former2 - where - Former2 : former::FormerBegin,>>, - { - Former2::former_begin(None, Some(self), Struct1FormerAssignHashset1End::::default()) - } + // xxx - #[doc = "Subformer setter for the 'hashset_1' field. Method _hashset_1_assign unlike method hashset_1 accept custom container subformer."] - #[inline(always)] - pub fn hashset_1(self) -> former::ContainerSubformer::< - String, - former::HashSetDefinition,> - > - { - self._hashset_1_assign::,> - >> () - } } impl< Definition, > Struct1Former< Definition, > @@ -424,15 +452,15 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<>, Formed = Struct1<> >, { - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] + + + #[doc = r" If `perform` defined then associated method is called and its result returned instead of entity."] #[doc = r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] - #[inline(always)] + + #[ inline( always ) ] pub fn perform(self) -> ::Formed { let result = self.form(); @@ -444,7 +472,7 @@ impl< Definition > former::FormerBegin< Definition > for Struct1Former< Definiti where Definition : former::FormerDefinition< Storage = Struct1FormerStorage<> >, { - #[inline(always)] + #[ inline( always ) ] fn former_begin(storage: core::option::Option, context: core::option::Option, on_end: Definition::End,) -> Self { debug_assert!(storage.is_none()); @@ -467,16 +495,16 @@ where Self : former::FormingEnd< Struct1FormerDefinitionTypes, >, {} -#[doc = -"Callback to return original former after forming of container for `$Struct1` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] -pub struct Struct1FormerAssignVec1End +// = former assign end + +pub struct Struct1FormerAssignVec1End< Definition > { - _phantom : core::marker::PhantomData<(Definition,)>, + _phantom : core::marker::PhantomData< ( Definition, ) >, } -impl Default for Struct1FormerAssignVec1End +impl Default for Struct1FormerAssignVec1End< Definition > { - #[inline(always)] + #[ inline( always ) ] fn default() -> Self { Self @@ -486,28 +514,52 @@ impl Default for Struct1FormerAssignVec1End } } -#[automatically_derived] -impl former::FormingEnd< former::VectorDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignVec1End +impl< Definition, > former::FormingEnd +< former::VectorDefinitionTypes< String, Struct1Former< Definition >, Struct1Former< Definition > > > +for Struct1FormerAssignVec1End< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, + Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { - #[inline(always)] - fn call(&self, storage: Vec, super_former: Option>,) -> Struct1Former + #[ inline( always ) ] + fn call( &self, storage : collection_tools::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 + if let Some( ref mut field ) = super_former.storage.vec_1 { - former::ContainerAssign::assign(field, storage); + former::ContainerAssign::assign( field, storage ); } else { - super_former.storage.vec_1 = Some(storage); + super_former.storage.vec_1 = Some( storage ); } super_former } } +// #[automatically_derived] +// impl former::FormingEnd< former::VectorDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignVec1End +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, +// { +// #[ inline( always ) ] +// fn call(&self, storage: Vec, super_former: Option>,) -> Struct1Former +// { +// let mut super_former = super_former.unwrap(); +// if let Some(ref mut field) = super_former.storage.vec_1 +// { +// former::ContainerAssign::assign(field, storage); +// } +// else +// { +// super_former.storage.vec_1 = Some(storage); +// } +// super_former +// } +// } + #[doc = "Callback to return original former after forming of container for `$Struct1` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] pub struct Struct1FormerAssignHashmap1End @@ -517,7 +569,7 @@ pub struct Struct1FormerAssignHashmap1End impl Default for Struct1FormerAssignHashmap1End { - #[inline(always)] + #[ inline( always ) ] fn default() -> Self { Self @@ -527,28 +579,52 @@ impl Default for Struct1FormerAssignHashmap1End } } -#[automatically_derived] -impl former::FormingEnd< former::HashMapDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignHashmap1End +impl< Definition, > former::FormingEnd +< former::HashMapDefinitionTypes< String, String, Struct1Former< Definition >, Struct1Former< Definition > > > +for Struct1FormerAssignHashmap1End< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, + Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { - #[inline(always)] - fn call(&self, storage: std::collections::HashMap, super_former: Option>,) -> Struct1Former + #[ inline( always ) ] + fn call( &self, storage : collection_tools::HashMap< String, String >, super_former : Option< Struct1Former< Definition > > ) + -> Struct1Former< Definition, > { let mut super_former = super_former.unwrap(); - if let Some(ref mut field) = super_former.storage.hashmap_1 + if let Some( ref mut field ) = super_former.storage.hashmap_1 { - former::ContainerAssign::assign(field, storage); + former::ContainerAssign::assign( field, storage ); } else { - super_former.storage.hashmap_1 = Some(storage); + super_former.storage.hashmap_1 = Some( storage ); } super_former } } +// #[automatically_derived] +// impl former::FormingEnd< former::HashMapDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignHashmap1End +// where +// Definition : former::FormerDefinition, +// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, +// { +// #[ inline( always ) ] +// fn call(&self, storage: collection_tools::HashMap, super_former: Option>,) -> Struct1Former +// { +// let mut super_former = super_former.unwrap(); +// if let Some(ref mut field) = super_former.storage.hashmap_1 +// { +// former::ContainerAssign::assign(field, storage); +// } +// else +// { +// super_former.storage.hashmap_1 = Some(storage); +// } +// super_former +// } +// } + #[doc = "Callback to return original former after forming of container for `$Struct1` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] pub struct Struct1FormerAssignHashset1End @@ -558,7 +634,7 @@ pub struct Struct1FormerAssignHashset1End impl Default for Struct1FormerAssignHashset1End { - #[inline(always)] + #[ inline( always ) ] fn default() -> Self { Self @@ -568,23 +644,25 @@ impl Default for Struct1FormerAssignHashset1End } } -#[automatically_derived] -impl former::FormingEnd< former::HashSetDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignHashset1End +impl< Definition, > former::FormingEnd +< former::HashSetDefinitionTypes< String, Struct1Former< Definition >, Struct1Former< Definition > > > +for Struct1FormerAssignHashset1End< Definition > where - Definition : former::FormerDefinition, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, + Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { - #[inline(always)] - fn call(&self, storage: std::collections::HashSet, super_former: Option>,) -> Struct1Former + #[ inline( always ) ] + fn call( &self, storage : collection_tools::HashSet< String >, super_former : Option< Struct1Former< Definition >, > ) + -> Struct1Former< Definition, > { let mut super_former = super_former.unwrap(); - if let Some(ref mut field) = super_former.storage.hashset_1 + if let Some( ref mut field ) = super_former.storage.hashset_1 { - former::ContainerAssign::assign(field, storage); + former::ContainerAssign::assign( field, storage ); } else { - super_former.storage.hashset_1 = Some(storage); + super_former.storage.hashset_1 = Some( storage ); } super_former } @@ -592,4 +670,5 @@ where // == end of generated -include!( "./only_test/containers_with_subformer.rs" ); +// include!( "./only_test/containers_with_subformer.rs" ); +// xxx \ No newline at end of file diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index 6e0df08764..7615fb090e 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -29,9 +29,9 @@ fn definitions() { } - f1( former::VectorDefinition::< String, (), Vec< String >, the_module::NoEnd >::default() ); + f1( former::VectorDefinitionTypes::< String, (), Vec< String > >::default() ); f2( former::VectorDefinition::< String, (), Vec< String >, the_module::NoEnd >::default() ); - f3::< former::VectorDefinition< String, (), Vec< String >, the_module::NoEnd >, the_module::ReturnStorage >( the_module::ReturnStorage ); + f3::< former::VectorDefinitionTypes< String, (), Vec< String > >, the_module::ReturnStorage >( the_module::ReturnStorage ); f3::< < former::VectorDefinition< String, (), Vec< String >, the_module::NoEnd > as the_module::FormerDefinition >::Types, the_module::ReturnStorage >( the_module::ReturnStorage ); } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index e5467bb3c5..cd5d0f48fc 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -24,81 +24,81 @@ mod former_tests mod a_containers_without_subformer; #[ cfg( not( feature = "no_std" ) ) ] mod a_containers_with_subformer_manual; - #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer; - - mod attribute_default_container; - mod attribute_default_primitive; - mod attribute_default_conflict; - mod attribute_storage_with_end; - mod attribute_storage_with_mutator; - mod attribute_perform; - mod attribute_setter; - mod attribute_alias; - mod attribute_feature; - - mod string_slice_manual; - mod string_slice; - mod unsigned_primitive_types; - mod default_user_type; - mod user_type_no_default; - mod user_type_no_debug; - mod visibility; - - mod name_collision_former_hashmap_without_parameter; - mod name_collision_former_vector_without_parameter; - mod name_collisions; - mod name_collision_context; - mod name_collision_end; - mod name_collision_on_end; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_manual; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_imm; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod parametrized_struct_where; - mod parametrized_field; - mod parametrized_field_where; - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - mod subformer_basic; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_manual; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_implicit; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_setter_off; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_named; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_custom; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_manual; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_named; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_named_manual; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_setter_off; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_setter_on; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_hashmap; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_hashmap_custom; - - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_and_container; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_subform_and_container_parametrized; +// #[ cfg( not( feature = "no_std" ) ) ] +// mod a_containers_with_subformer; +// +// mod attribute_default_container; +// mod attribute_default_primitive; +// mod attribute_default_conflict; +// mod attribute_storage_with_end; +// mod attribute_storage_with_mutator; +// mod attribute_perform; +// mod attribute_setter; +// mod attribute_alias; +// mod attribute_feature; +// +// mod string_slice_manual; +// mod string_slice; +// mod unsigned_primitive_types; +// mod default_user_type; +// mod user_type_no_default; +// mod user_type_no_debug; +// mod visibility; +// +// mod name_collision_former_hashmap_without_parameter; +// mod name_collision_former_vector_without_parameter; +// mod name_collisions; +// mod name_collision_context; +// mod name_collision_end; +// mod name_collision_on_end; +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_manual; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_imm; +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod parametrized_struct_where; +// mod parametrized_field; +// mod parametrized_field_where; +// +// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +// mod subformer_basic; +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container_manual; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container_implicit; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container_setter_off; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container_named; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_container_custom; +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_manual; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_named; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_named_manual; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_setter_off; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_setter_on; +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_hashmap; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_hashmap_custom; +// +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_and_container; +// #[ cfg( any( not( feature = "no_std" ) ) ) ] +// mod subformer_subform_and_container_parametrized; // xxx diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index c5e486249b..3f92df83bf 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -175,7 +175,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let ( _doc_former_mod, doc_former_struct ) = doc_generate( stru ); let ( perform, perform_output, perform_generics ) = struct_attrs.performer()?; - // let storage_fields_code = struct_attrs.storage_fields_code()?; /* fields */ @@ -207,8 +206,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > storage_field_name, storage_field_preform, former_field_setter, - former_field_assign_end, - former_field_add_end, + former_assign_end, + former_add_end, ) : ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) @@ -226,10 +225,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > &stru, &former, &former_storage, - // &as_subformer, - // &as_subformer_end, + &former_generics_ty, ), - field.former_field_assign_end + // xxx : move maybe + field.former_assign_end ( &stru, &former, @@ -237,7 +236,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > &former_generics_ty, &former_generics_where, ), - field.former_field_add_end + field.former_add_end ( &stru, &former, @@ -250,9 +249,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let former_field_setter : Vec< _ > = process_results( former_field_setter, | iter | iter.collect() )?; let storage_field_preform : Vec< _ > = process_results( storage_field_preform, | iter | iter.collect() )?; - let former_field_assign_end : Vec< _ > = process_results( former_field_assign_end, | iter | iter.collect() )?; - let former_field_add_end : Vec< _ > = process_results( former_field_add_end, | iter | iter.collect() )?; + let former_assign_end : Vec< _ > = process_results( former_assign_end, | iter | iter.collect() )?; + let former_add_end : Vec< _ > = process_results( former_add_end, | iter | iter.collect() )?; + // xxx : move to a function let former_mutator_code = if struct_attrs.mutator.custom { qt!{} @@ -346,6 +346,15 @@ where #struct_generics_where { type Definition = #former_definition < #struct_generics_ty __Context, __Formed, __End >; + type Types = #former_definition_types < #struct_generics_ty __Context, __Formed >; + } + + impl< #struct_generics_impl __Context, __Formed > former::EntityToDefinitionTypes< __Context, __Formed > + for #stru < #struct_generics_ty > + where + #struct_generics_where + { + type Types = #former_definition_types < #struct_generics_ty __Context, __Formed >; } // #[ allow( non_snake_case ) ] @@ -444,7 +453,6 @@ where /// A field #storage_field_optional, )* - // #storage_fields_code } impl < #struct_generics_impl > ::core::default::Default @@ -736,13 +744,13 @@ where // = container assign callbacks #( - #former_field_assign_end + #former_assign_end )* // = container add callbacks #( - #former_field_add_end + #former_add_end )* // } /* end of namespace */ diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index d0e0b9c443..a09cc83875 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -36,8 +36,8 @@ former_field_setter subform_setter container_setter scalar_setter -former_field_assign_end -former_field_add_end +former_assign_end +former_add_end scalar_setter_name container_setter_name @@ -345,8 +345,7 @@ scalar_setter_required stru : &syn::Ident, former : &syn::Ident, former_storage : &syn::Ident, - // as_subformer : &syn::Ident, - // as_subformer_end : &syn::Ident, + former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, ) -> Result< TokenStream > { @@ -356,21 +355,6 @@ scalar_setter_required former_storage, ); - // // scalar setter - // let r = if self.scalar_setter_required() - // { - // let r2 = self.scalar_setter(); - // qt! - // { - // #r - // #r2 - // } - // } - // else - // { - // r - // }; - // container setter let r = if let Some( _ ) = &self.attrs.container { @@ -379,6 +363,7 @@ scalar_setter_required stru, former, former_storage, + former_generics_ty, ); qt! { @@ -423,8 +408,6 @@ scalar_setter_required stru : &syn::Ident, former : &syn::Ident, former_storage : &syn::Ident, - // as_subformer : &syn::Ident, - // as_subformer_end : &syn::Ident, ) -> Result< TokenStream > { @@ -587,13 +570,14 @@ where stru : &syn::Ident, former : &syn::Ident, former_storage : &syn::Ident, + former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, ) -> TokenStream { let attr = self.attrs.container.as_ref().unwrap(); let field_ident = &self.ident; - let non_optional_ty = &self.non_optional_ty; - let params = typ::type_parameters( &non_optional_ty, .. ); + let typ = &self.non_optional_ty; + let params = typ::type_parameters( &typ, .. ); use convert_case::{ Case, Casing }; let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); @@ -621,7 +605,9 @@ where { qt! { - < #non_optional_ty as former::EntityToDefinition< Self, Self, #former_assign_end< Definition > > >::Definition + < + #typ as former::EntityToDefinition< Self, Self, #former_assign_end< Definition > > + >::Definition } // < Vec< String > as former::EntityToDefinition< Self, Self, Struct1FormerAssignVec1End > >::Definition }; @@ -637,17 +623,54 @@ where let setter1 = qt! { + + // #[ doc = #doc ] + // #[ inline( always ) ] + // pub fn #field_assign< Former2 >( self ) -> Former2 + // where + // Former2 : former::FormerBegin + // < + // #subformer_definition + // >, + // { + // Former2::former_begin( None, Some( self ), #former_assign_end::< Definition >::default() ) + // } + #[ doc = #doc ] #[ inline( always ) ] pub fn #field_assign< Former2 >( self ) -> Former2 where Former2 : former::FormerBegin < - #subformer_definition + #subformer_definition, + >, + #subformer_definition : former::FormerDefinition + < + Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, + Context = #former< #former_generics_ty >, + End = #former_assign_end< Definition >, >, { Former2::former_begin( None, Some( self ), #former_assign_end::< Definition >::default() ) } + + // #[ inline( always ) ] + // pub fn _hashset_1_assign< Former2 >( self ) -> Former2 + // where + // Former2 : former::FormerBegin + // < + // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, + // >, + // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > > : former::FormerDefinition + // < + // Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, + // Context = Struct1Former< Definition >, + // End = Struct1FormerAssignHashset1End< Definition >, + // >, + // { + // Former2::former_begin( None, Some( self ), Struct1FormerAssignHashset1End::< Definition >::default() ) + // } + }; let setter_name = self.container_setter_name(); @@ -658,20 +681,63 @@ where qt! { + // #[ doc = #doc ] + // #[ inline( always ) ] + // pub fn #setter_name( self ) -> + // former::ContainerSubformer:: + // < + // ( #( #params, )* ), #subformer_definition + // > + // { + // self.#field_assign::< former::ContainerSubformer:: + // < + // ( #( #params, )* ), #subformer_definition + // > >() + // } + #[ doc = #doc ] #[ inline( always ) ] - pub fn #setter_name( self ) -> - former::ContainerSubformer:: + pub fn #setter_name( self ) -> former::ContainerSubformer:: < - ( #( #params, )* ), #subformer_definition + ( #( #params, )* ), + #subformer_definition, > + where + #subformer_definition : former::FormerDefinition + < + Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, + Context = Struct1Former< Definition >, + End = #former_assign_end < Definition >, + >, { self.#field_assign::< former::ContainerSubformer:: < - ( #( #params, )* ), #subformer_definition - > >() + ( #( #params, )* ), + #subformer_definition, + > > () } + // #[ inline( always ) ] + // pub fn hashset_1( self ) -> former::ContainerSubformer:: + // < + // String, + // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, + // > + // where + // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > > : former::FormerDefinition + // < + // Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, + // Context = Struct1Former< Definition >, + // End = Struct1FormerAssignHashset1End< Definition >, + // >, + // { + // self._hashset_1_assign::< former::ContainerSubformer:: + // < + // String, + // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, + // > > () + // } + } } else @@ -679,20 +745,64 @@ where qt! { + // xxx : clean + // #[ doc = #doc ] + // #[ inline( always ) ] + // pub fn #setter_name( self ) -> + // former::ContainerSubformer:: + // < + // #( #params, )* #subformer_definition + // > + // { + // self.#field_assign::< former::ContainerSubformer:: + // < + // #( #params, )* #subformer_definition + // > >() + // } + #[ doc = #doc ] #[ inline( always ) ] - pub fn #setter_name( self ) -> - former::ContainerSubformer:: + pub fn #setter_name( self ) -> former::ContainerSubformer:: < - #( #params, )* #subformer_definition + #( #params, )*, // xxx : use former::Container + #subformer_definition, > + where + #subformer_definition : former::FormerDefinition + < + Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, + Context = Struct1Former< Definition >, + End = #former_assign_end < Definition >, + >, { self.#field_assign::< former::ContainerSubformer:: < - #( #params, )* #subformer_definition - > >() + #( #params, )*, // xxx : use former::Container + #subformer_definition, + > > () } + // #[ inline( always ) ] + // pub fn hashset_1( self ) -> former::ContainerSubformer:: + // < + // String, + // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, + // > + // where + // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > > : former::FormerDefinition + // < + // Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, + // Context = Struct1Former< Definition >, + // End = Struct1FormerAssignHashset1End< Definition >, + // >, + // { + // self._hashset_1_assign::< former::ContainerSubformer:: + // < + // String, + // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, + // > > () + // } + } } } @@ -701,6 +811,7 @@ where qt!{} }; + // xxx : update if attr.hint { let hint = format! @@ -727,6 +838,7 @@ where }} "#, + // xxx : update former, former_storage, field_ident, @@ -743,35 +855,6 @@ where #setter2 } - // #[ inline( always ) ] - // pub fn vec_1_assign< Former2 >( self ) -> Former2 - // where - // Former2 : former::FormerBegin - // < - // former::VectorDefinition - // < - // String, - // Self, - // Self, - // Struct1FormerVec_1End, - // > - // >, - // { - // Former2::_begin( None, Some( self ), Struct1FormerVec_1End ) - // } - // - // pub fn vec_1( self ) -> - // former::ContainerSubformer:: - // < - // String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > - // > - // { - // self.vec_1_assign::< former::ContainerSubformer:: - // < - // String, former::VectorDefinition< String, Self, Self, Struct1FormerVec_1End > - // >>() - // } - } /// @@ -908,7 +991,7 @@ where /// ``` #[ inline ] - pub fn former_field_assign_end + pub fn former_assign_end ( &self, stru : &syn::Ident, @@ -950,15 +1033,27 @@ where { qt! { - #subformer_definition < #( #params, )* #former< #former_generics_ty >, #former< #former_generics_ty >, former::NoEnd > + #subformer_definition + < + #( #params, )* + #former< #former_generics_ty >, + #former< #former_generics_ty >, + // former::NoEnd, + > } - // former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd > + // former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, > > } else { qt! { - < #field_ty as former::EntityToDefinition< #former< #former_generics_ty >, #former< #former_generics_ty >, former::NoEnd > >::Definition + < + #field_ty as former::EntityToDefinition + < + #former< #former_generics_ty >, + #former< #former_generics_ty >, + > + >::Types } // < Vec< String > as former::EntityToDefinition< Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd > >::Definition }; @@ -1028,7 +1123,7 @@ where /// zzz : write documentation #[ inline ] - pub fn former_field_add_end + pub fn former_add_end ( &self, stru : &syn::Ident, From 8a2c07c329dc9984cb18d6991d3560102d6440c8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 13:02:43 +0300 Subject: [PATCH 476/533] former : solve problem with container interface --- module/core/former/src/hash_set.rs | 30 ++--- module/core/former/src/vector.rs | 2 +- .../a_containers_with_subformer_manual.rs | 109 +++++++++++++++--- 3 files changed, 110 insertions(+), 31 deletions(-) diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index a665b42224..a8524adf41 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -113,44 +113,44 @@ where } } -// = definition types +// = definition #[ derive( Debug, Default ) ] -pub struct HashSetDefinitionTypes< K, Context = (), Formed = HashSet< K > > +pub struct HashSetDefinition< K, Context = (), Formed = HashSet< K >, End = ReturnStorage > { - _phantom : core::marker::PhantomData< ( K, Context, Formed ) >, + _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, } -impl< K, Context, Formed > FormerDefinitionTypes -for HashSetDefinitionTypes< K, Context, Formed > +impl< K, Context, Formed, End > FormerDefinition +for HashSetDefinition< K, Context, Formed, End > where K : ::core::cmp::Eq + ::core::hash::Hash, + End : FormingEnd< HashSetDefinitionTypes< K, Context, Formed > >, { type Storage = HashSet< K >; type Formed = Formed; type Context = Context; + + type Types = HashSetDefinitionTypes< K, Context, Formed >; + type End = End; } -// = definition +// = definition types #[ derive( Debug, Default ) ] -pub struct HashSetDefinition< K, Context = (), Formed = HashSet< K >, End = ReturnStorage > +pub struct HashSetDefinitionTypes< K, Context = (), Formed = HashSet< K > > { - _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, + _phantom : core::marker::PhantomData< ( K, Context, Formed ) >, } -impl< K, Context, Formed, End > FormerDefinition -for HashSetDefinition< K, Context, Formed, End > +impl< K, Context, Formed > FormerDefinitionTypes +for HashSetDefinitionTypes< K, Context, Formed > where K : ::core::cmp::Eq + ::core::hash::Hash, - End : FormingEnd< HashSetDefinitionTypes< K, Context, Formed > >, { type Storage = HashSet< K >; type Formed = Formed; type Context = Context; - - type Types = HashSetDefinitionTypes< K, Context, Formed >; - type End = End; } // = mutator @@ -170,7 +170,7 @@ where Definition : FormerDefinition< Storage = HashSet< K >, Formed = () >, Definition::Types : FormerDefinitionTypes< Storage = HashSet< K >, Formed = () >, Definition::End : crate::FormingEnd< Definition::Types >, - < Definition as definition::FormerDefinition>::End : Fn( HashSet< K >, Option< Definition::Context > ), + < Definition as definition::FormerDefinition >::End : Fn( HashSet< K >, Option< Definition::Context > ), { type Former = HashSetSubformer< K, Definition::Context, Definition::Formed, Definition::End >; } diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 58a170f785..e53ccb555c 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -154,7 +154,7 @@ where Definition : FormerDefinition< Storage = Vec< E > >, Definition::Types : FormerDefinitionTypes< Storage = Vec< E >, Formed = Definition::Formed, Context = Definition::Context >, Definition::End : crate::FormingEnd< Definition::Types >, - Definition::End : Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed, // xxx + < Definition as definition::FormerDefinition >::End : Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed, // xxx { type Former = VectorSubformer< E, Definition::Context, Definition::Formed, Definition::End >; } diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 1e6b80e12e..a835d62c59 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -331,9 +331,6 @@ where self.end() } - - - #[ inline( always ) ] pub fn end(mut self) -> ::Formed { @@ -359,8 +356,56 @@ where // { // self._vec_1_assign::,>>> () // } -// -// + + // xxx : clean + + #[ inline( always ) ] + pub fn _vec_1_assign< Former2 >( self ) -> Former2 + where + Former2 : former::FormerBegin + < + former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End< Definition > >, + >, + former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End< Definition > > : former::FormerDefinition + < + Storage : former::ContainerAdd< Entry = < collection_tools::Vec< String > as former::Container >::Entry >, + Context = Struct1Former< Definition >, + End = Struct1FormerAssignVec1End< Definition >, + >, + Struct1FormerAssignVec1End< Definition > : former::FormingEnd + < + < collection_tools::Vec< String > as former::EntityToDefinitionTypes< Self, Self > >::Types + >, + { + Former2::former_begin( None, Some( self ), Struct1FormerAssignVec1End::< Definition >::default() ) + } + + #[ inline( always ) ] + pub fn vec_1( self ) -> former::ContainerSubformer:: + < + String, + former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End< Definition > >, + > + where + former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End< Definition > > : former::FormerDefinition + < + Storage : former::ContainerAdd< Entry = < collection_tools::Vec< String > as former::Container >::Entry >, + Context = Struct1Former< Definition >, + End = Struct1FormerAssignVec1End< Definition >, + >, + Struct1FormerAssignVec1End< Definition > : former::FormingEnd + < + < collection_tools::Vec< String > as former::EntityToDefinitionTypes< Self, Self > >::Types + >, + { + self._vec_1_assign::< former::ContainerSubformer:: + < + String, + former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End< Definition > >, + > > () + } + +// xxx : clean // #[ inline( always ) ] // pub fn _hashmap_1_assign(self) -> Former2 // where @@ -382,6 +427,45 @@ where // former::HashMapDefinition,> // >> () // } + + #[ inline( always ) ] + pub fn _hashmap_1_assign< Former2 >( self ) -> Former2 + where + Former2 : former::FormerBegin + < + former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End< Definition > >, + >, + former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End< Definition > > : former::FormerDefinition + < + Storage : former::ContainerAdd< Entry = < collection_tools::HashMap< String, String > as former::Container >::Entry >, + Context = Struct1Former< Definition >, + End = Struct1FormerAssignHashmap1End< Definition >, + >, + { + Former2::former_begin( None, Some( self ), Struct1FormerAssignHashmap1End::< Definition >::default() ) + } + + #[ inline( always ) ] + pub fn hashmap_1( self ) -> former::ContainerSubformer:: + < + ( String, String ), + former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End< Definition > >, + > + where + former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End< Definition > > : former::FormerDefinition + < + Storage : former::ContainerAdd< Entry = < collection_tools::HashMap< String, String > as former::Container >::Entry >, + Context = Struct1Former< Definition >, + End = Struct1FormerAssignHashmap1End< Definition >, + >, + { + self._hashmap_1_assign::< former::ContainerSubformer:: + < + ( String, String ), + former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End< Definition > >, + > > () + } + // xxx #[ inline( always ) ] @@ -440,7 +524,7 @@ where Definition : former::FormerDefinition, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, { - pub fn preform(self) -> ::Formed + pub fn preform(self) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { former::StoragePreform::preform(self.storage) } @@ -453,13 +537,6 @@ where Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<>, Formed = Struct1<> >, { - - - #[doc = - r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = - r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[ inline( always ) ] pub fn perform(self) -> ::Formed { @@ -538,6 +615,7 @@ where } } +// xxx : clean // #[automatically_derived] // impl former::FormingEnd< former::VectorDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignVec1End // where @@ -603,6 +681,7 @@ where } } +// xxx : clean // #[automatically_derived] // impl former::FormingEnd< former::HashMapDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignHashmap1End // where @@ -670,5 +749,5 @@ where // == end of generated -// include!( "./only_test/containers_with_subformer.rs" ); -// xxx \ No newline at end of file +include!( "./only_test/containers_with_subformer.rs" ); +// xxx From 58445e6bb8f8cc72f4c90aae55170c8f14aafad3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 13:08:19 +0300 Subject: [PATCH 477/533] former : solve problem with container interface --- module/core/former/src/hash_map.rs | 3 +++ module/core/former/src/hash_set.rs | 3 +++ .../a_containers_with_subformer_manual.rs | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 079ffb3bea..501ce13caa 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -109,6 +109,9 @@ where #[ derive( Debug, Default ) ] pub struct HashMapDefinition< K, E, Context = (), Formed = HashMap< K, E >, End = ReturnStorage > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + End : FormingEnd< HashMapDefinitionTypes< K, E, Context, Formed > >, { _phantom : core::marker::PhantomData< ( K, E, Context, Formed, End ) >, } diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index a8524adf41..a73dbc7194 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -117,6 +117,9 @@ where #[ derive( Debug, Default ) ] pub struct HashSetDefinition< K, Context = (), Formed = HashSet< K >, End = ReturnStorage > +where + End : FormingEnd< HashSetDefinitionTypes< K, Context, Formed > >, + K : ::core::cmp::Eq + ::core::hash::Hash, { _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, } diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index a835d62c59..7134a721b5 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -441,6 +441,10 @@ where Context = Struct1Former< Definition >, End = Struct1FormerAssignHashmap1End< Definition >, >, + Struct1FormerAssignHashmap1End< Definition > : former::FormingEnd + < + < collection_tools::HashMap< String, String > as former::EntityToDefinitionTypes< Self, Self > >::Types + >, { Former2::former_begin( None, Some( self ), Struct1FormerAssignHashmap1End::< Definition >::default() ) } @@ -458,6 +462,10 @@ where Context = Struct1Former< Definition >, End = Struct1FormerAssignHashmap1End< Definition >, >, + Struct1FormerAssignHashmap1End< Definition > : former::FormingEnd + < + < collection_tools::HashMap< String, String > as former::EntityToDefinitionTypes< Self, Self > >::Types + >, { self._hashmap_1_assign::< former::ContainerSubformer:: < @@ -481,6 +489,11 @@ where Context = Struct1Former< Definition >, End = Struct1FormerAssignHashset1End< Definition >, >, + Struct1FormerAssignHashset1End< Definition > : former::FormingEnd + < + < collection_tools::HashSet< String > as former::EntityToDefinitionTypes< Self, Self > >::Types + >, + // Struct1FormerAssignHashset1End< Definition > : former::FormingEnd // < // former::HashSetDefinitionTypes< String, Struct1Former< Definition >, Struct1Former< Definition > > @@ -502,6 +515,11 @@ where Context = Struct1Former< Definition >, End = Struct1FormerAssignHashset1End< Definition >, >, + Struct1FormerAssignHashset1End< Definition > : former::FormingEnd + < + < collection_tools::HashSet< String > as former::EntityToDefinitionTypes< Self, Self > >::Types + >, + // Struct1FormerAssignHashset1End< Definition > : former::FormingEnd // < // former::HashSetDefinitionTypes< String, Struct1Former< Definition >, Struct1Former< Definition > >, From 10cd2315078c574ab249fe1726f0c1edbc411a92 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 13:10:40 +0300 Subject: [PATCH 478/533] former : solve problem with container interface --- .../a_containers_with_subformer_manual.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 7134a721b5..fa5e4360a6 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -493,11 +493,6 @@ where < < collection_tools::HashSet< String > as former::EntityToDefinitionTypes< Self, Self > >::Types >, - - // Struct1FormerAssignHashset1End< Definition > : former::FormingEnd - // < - // former::HashSetDefinitionTypes< String, Struct1Former< Definition >, Struct1Former< Definition > > - // >, { Former2::former_begin( None, Some( self ), Struct1FormerAssignHashset1End::< Definition >::default() ) } @@ -519,11 +514,6 @@ where < < collection_tools::HashSet< String > as former::EntityToDefinitionTypes< Self, Self > >::Types >, - - // Struct1FormerAssignHashset1End< Definition > : former::FormingEnd - // < - // former::HashSetDefinitionTypes< String, Struct1Former< Definition >, Struct1Former< Definition > >, - // >, { self._hashset_1_assign::< former::ContainerSubformer:: < @@ -532,8 +522,6 @@ where > > () } - // xxx - } impl< Definition, > Struct1Former< Definition, > @@ -548,7 +536,6 @@ where } } -#[automatically_derived] impl< Definition, > Struct1Former< Definition, > where Definition : former::FormerDefinition, @@ -656,8 +643,6 @@ where // } // } -#[doc = -"Callback to return original former after forming of container for `$Struct1` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] pub struct Struct1FormerAssignHashmap1End { _phantom : core::marker::PhantomData<(Definition,)>, From c1e17f89bae5564bcabe4c55e73ede88c08ab4c7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 13:13:14 +0300 Subject: [PATCH 479/533] former : solve problem with container interface --- module/core/former/src/hash_set.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index a73dbc7194..b9d9fc4ca4 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -118,8 +118,8 @@ where #[ derive( Debug, Default ) ] pub struct HashSetDefinition< K, Context = (), Formed = HashSet< K >, End = ReturnStorage > where - End : FormingEnd< HashSetDefinitionTypes< K, Context, Formed > >, K : ::core::cmp::Eq + ::core::hash::Hash, + End : FormingEnd< HashSetDefinitionTypes< K, Context, Formed > >, { _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, } @@ -173,7 +173,7 @@ where Definition : FormerDefinition< Storage = HashSet< K >, Formed = () >, Definition::Types : FormerDefinitionTypes< Storage = HashSet< K >, Formed = () >, Definition::End : crate::FormingEnd< Definition::Types >, - < Definition as definition::FormerDefinition >::End : Fn( HashSet< K >, Option< Definition::Context > ), + // < Definition as definition::FormerDefinition >::End : Fn( HashSet< K >, Option< Definition::Context > ), { type Former = HashSetSubformer< K, Definition::Context, Definition::Formed, Definition::End >; } From 754d8e6c65371e46c1c4f7189e5fdeedd66355a1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 15:25:19 +0300 Subject: [PATCH 480/533] former : types problem --- module/core/former/src/hash_set.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index b9d9fc4ca4..8e06b2f323 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -167,13 +167,27 @@ where // = entity to +// < Definition as definition::FormerDefinition >::End : forming::FormingEnd +// < +// HashSetDefinitionTypes +// < +// K, +// < Definition as definition::FormerDefinition >::Context, +// < Definition as definition::FormerDefinition >::Formed, +// >, +// > + impl< K, Definition > EntityToFormer< Definition > for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, - Definition : FormerDefinition< Storage = HashSet< K >, Formed = () >, - Definition::Types : FormerDefinitionTypes< Storage = HashSet< K >, Formed = () >, - Definition::End : crate::FormingEnd< Definition::Types >, - // < Definition as definition::FormerDefinition >::End : Fn( HashSet< K >, Option< Definition::Context > ), + Definition : FormerDefinition< Storage = HashSet< K >, Types = HashSetDefinitionTypes + < + K, + < Definition as definition::FormerDefinition >::Context, + < Definition as definition::FormerDefinition >::Formed, + >, + >, + Definition::End : forming::FormingEnd< Definition::Types >, { type Former = HashSetSubformer< K, Definition::Context, Definition::Formed, Definition::End >; } From ec034b0554ec01604c54ac1e66fc99ed991135fd Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 15:29:19 +0300 Subject: [PATCH 481/533] former : types problem --- module/core/former/src/hash_map.rs | 18 ++++++++++++++++-- module/core/former/src/hash_set.rs | 17 +++++------------ module/core/former/src/vector.rs | 21 +++++++++++++++++---- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 501ce13caa..0ffceca50f 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -162,10 +162,24 @@ where // = Entity To impl< K, E, Definition > EntityToFormer< Definition > for HashMap< K, E > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// Definition : FormerDefinition< Storage = HashMap< K, E >, Formed = () >, +// < Definition as definition::FormerDefinition>::End : Fn( HashMap< K, E >, Option< Definition::Context > ), where K : ::core::cmp::Eq + ::core::hash::Hash, - Definition : FormerDefinition< Storage = HashMap< K, E >, Formed = () >, - < Definition as definition::FormerDefinition>::End : Fn( HashMap< K, E >, Option< Definition::Context > ), + Definition : FormerDefinition + < + Storage = HashMap< K, E >, + Types = HashMapDefinitionTypes + < + K, + E, + < Definition as definition::FormerDefinition >::Context, + < Definition as definition::FormerDefinition >::Formed, + >, + >, + Definition::End : forming::FormingEnd< Definition::Types >, { type Former = HashMapSubformer< K, E, Definition::Context, Definition::Formed, Definition::End >; } diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 8e06b2f323..5cae4f47b6 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -167,26 +167,19 @@ where // = entity to -// < Definition as definition::FormerDefinition >::End : forming::FormingEnd -// < -// HashSetDefinitionTypes -// < -// K, -// < Definition as definition::FormerDefinition >::Context, -// < Definition as definition::FormerDefinition >::Formed, -// >, -// > - impl< K, Definition > EntityToFormer< Definition > for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, - Definition : FormerDefinition< Storage = HashSet< K >, Types = HashSetDefinitionTypes + Definition : FormerDefinition + < + Storage = HashSet< K >, + Types = HashSetDefinitionTypes < K, < Definition as definition::FormerDefinition >::Context, < Definition as definition::FormerDefinition >::Formed, >, - >, + >, Definition::End : forming::FormingEnd< Definition::Types >, { type Former = HashSetSubformer< K, Definition::Context, Definition::Formed, Definition::End >; diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index e53ccb555c..4923018c49 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -149,12 +149,25 @@ for VectorDefinitionTypes< E, Context, Formed > // zzz : qqq : implement for hashset / hashmap // zzz : qqq : cover by tests // zzz : qqq : rid off bound `Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed` for all containers + impl< E, Definition > EntityToFormer< Definition > for Vec< E > +// where +// Definition : FormerDefinition< Storage = Vec< E > >, +// Definition::Types : FormerDefinitionTypes< Storage = Vec< E >, Formed = Definition::Formed, Context = Definition::Context >, +// Definition::End : crate::FormingEnd< Definition::Types >, +// < Definition as definition::FormerDefinition >::End : Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed, // xxx where - Definition : FormerDefinition< Storage = Vec< E > >, - Definition::Types : FormerDefinitionTypes< Storage = Vec< E >, Formed = Definition::Formed, Context = Definition::Context >, - Definition::End : crate::FormingEnd< Definition::Types >, - < Definition as definition::FormerDefinition >::End : Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed, // xxx + Definition : FormerDefinition + < + Storage = Vec< E >, + Types = VectorDefinitionTypes + < + E, + < Definition as definition::FormerDefinition >::Context, + < Definition as definition::FormerDefinition >::Formed, + >, + >, + Definition::End : forming::FormingEnd< Definition::Types >, { type Former = VectorSubformer< E, Definition::Context, Definition::Formed, Definition::End >; } From 4c343e7c7cfd123a1366bfdbd837feba9a4a9b88 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 16:33:22 +0300 Subject: [PATCH 482/533] former : types problem --- module/core/former/src/vector.rs | 10 +- .../a_containers_with_subformer.rs | 351 +++++++++++++++++- .../a_containers_with_subformer_manual.rs | 34 +- module/core/former/tests/inc/mod.rs | 2 +- .../former_meta/src/derive_former/field.rs | 5 +- 5 files changed, 383 insertions(+), 19 deletions(-) diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 4923018c49..e0f7b6e7ce 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -101,7 +101,8 @@ for Vec< E > // xxx : imlement custom ContainerDefinition #[ derive( Debug, Default ) ] -pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > +// pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > +pub struct VectorDefinition< E, Context, Formed, End > where End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, { @@ -114,8 +115,8 @@ where End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, { type Storage = Vec< E >; - type Formed = Formed; type Context = Context; + type Formed = Formed; type Types = VectorDefinitionTypes< E, Context, Formed >; type End = End; @@ -133,8 +134,8 @@ impl< E, Context, Formed > FormerDefinitionTypes for VectorDefinitionTypes< E, Context, Formed > { type Storage = Vec< E >; - type Formed = Formed; type Context = Context; + type Formed = Formed; } // = mutator @@ -150,7 +151,8 @@ for VectorDefinitionTypes< E, Context, Formed > // zzz : qqq : cover by tests // zzz : qqq : rid off bound `Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed` for all containers -impl< E, Definition > EntityToFormer< Definition > for Vec< E > +impl< E, Definition > EntityToFormer< Definition > +for Vec< E > // where // Definition : FormerDefinition< Storage = Vec< E > >, // Definition::Types : FormerDefinitionTypes< Storage = Vec< E >, Formed = Definition::Formed, Context = Definition::Context >, diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index a9eaa315fa..a909b4e99b 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -4,21 +4,356 @@ use super::*; // use std::collections::HashMap; // use std::collections::HashSet; -#[ derive( Default, Debug, PartialEq, former::Former ) ] +// #[ derive( Default, Debug, PartialEq, former::Former ) ] // #[ derive( Default, Debug, PartialEq, former::Former ) ] #[ debug ] -// #[ derive( Default, Debug, PartialEq ) ] +#[ derive( Default, Debug, PartialEq ) ] pub struct Struct1 { - #[ container( definition = former::VectorDefinition ) ] + // #[ container( definition = former::VectorDefinition ) ] vec_1 : Vec< String >, - #[ container( definition = former::HashMapDefinition ) ] - hashmap_1 : std::collections::HashMap< String, String >, - #[ container( definition = former::HashSetDefinition ) ] - hashset_1 : std::collections::HashSet< String >, + // #[ container( definition = former::HashMapDefinition ) ] + // hashmap_1 : std::collections::HashMap< String, String >, + // #[ container( definition = former::HashSetDefinition ) ] + // hashset_1 : std::collections::HashSet< String >, + // xxx } // == generated begin + #[automatically_derived] impl < > Struct1 < > where + { + #[doc = r""] + #[doc = + r" Make former, variation of builder pattern to form structure defining values of fields step by step."] + #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < + Struct1FormerDefinition < (), Struct1 < > , former :: ReturnPreformed > > + { + Struct1Former :: < Struct1FormerDefinition < (), Struct1 < > , former + :: ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) + } + } impl < Definition > former :: EntityToFormer < Definition > for Struct1 < > + where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage + < > > , { type Former = Struct1Former < Definition > ; } impl < > former :: + EntityToStorage for Struct1 < > where + { type Storage = Struct1FormerStorage < > ; } impl < __Context, __Formed, + __End > former :: EntityToDefinition < __Context, __Formed, __End > for + Struct1 < > where __End : former :: FormingEnd < Struct1FormerDefinitionTypes + < __Context, __Formed > > , + { + type Definition = Struct1FormerDefinition < __Context, __Formed, __End > ; + type Types = Struct1FormerDefinitionTypes < __Context, __Formed > ; + } impl < __Context, __Formed > former :: EntityToDefinitionTypes < __Context, + __Formed > for Struct1 < > where + { type Types = Struct1FormerDefinitionTypes < __Context, __Formed > ; } + #[derive(Debug)] pub struct Struct1FormerDefinitionTypes < __Context = (), + __Formed = Struct1 < > , > where + { + _phantom : core :: marker :: PhantomData < + (* const __Context, * const __Formed) > , + } impl < __Context, __Formed, > :: core :: default :: Default for + Struct1FormerDefinitionTypes < __Context, __Formed, > where + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } impl < __Context, __Formed, > former :: FormerDefinitionTypes for + Struct1FormerDefinitionTypes < __Context, __Formed, > where + { + type Storage = Struct1FormerStorage < > ; type Formed = __Formed; type + Context = __Context; + } #[derive(Debug)] pub struct Struct1FormerDefinition < __Context = (), + __Formed = Struct1 < > , __End = former :: ReturnPreformed, > where + { + _phantom : core :: marker :: PhantomData < + (* const __Context, * const __Formed, * const __End) > , + } impl < __Context, __Formed, __End, > :: core :: default :: Default for + Struct1FormerDefinition < __Context, __Formed, __End, > where + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } impl < __Context, __Formed, __End, > former :: FormerDefinition for + Struct1FormerDefinition < __Context, __Formed, __End, > where __End : former + :: FormingEnd < Struct1FormerDefinitionTypes < __Context, __Formed, > > , + { + type Types = Struct1FormerDefinitionTypes < __Context, __Formed, > ; type + End = __End; type Storage = Struct1FormerStorage < > ; type Formed = + __Formed; type Context = __Context; + } impl < __Context, __Formed, > former :: FormerMutator for + Struct1FormerDefinitionTypes < __Context, __Formed, > where {} + #[doc = "Container of a corresponding former."] + #[allow(explicit_outlives_requirements)] pub struct Struct1FormerStorage < > + where + { + #[doc = r" A field"] pub vec_1 : :: core :: option :: Option < Vec < + String > > , + } impl < > :: core :: default :: Default for Struct1FormerStorage < > where + { + #[inline(always)] fn default() -> Self + { Self { vec_1 : :: core :: option :: Option :: None, } } + } impl < > former :: Storage for Struct1FormerStorage < > where + { type Formed = Struct1 < > ; } impl < > former :: StoragePreform for + Struct1FormerStorage < > where + { + type Preformed = Struct1 < > ; fn preform(mut self) -> Self :: Preformed + { + let vec_1 = if self.vec_1.is_some() { self.vec_1.take().unwrap() } + else + { + { + trait MaybeDefault < T > + { + fn maybe_default(self : & Self) -> T + { panic! ("Field 'vec_1' isn't initialized") } + } impl < T > MaybeDefault < T > for & :: core :: marker :: + PhantomData < T > {} impl < T > MaybeDefault < T > for :: core + :: marker :: PhantomData < T > where T : :: core :: default :: + Default, + { fn maybe_default(self : & Self) -> T { T :: default() } } + (& :: core :: marker :: PhantomData :: < Vec < String > + >).maybe_default() + } + }; let result = Struct1 :: < > { vec_1, }; return result; + } + } + #[doc = + "\nStructure to form [Struct1]. Represents a forming entity designed to construct objects through a builder pattern.\n\nThis structure holds temporary storage and context during the formation process and\nutilizes a defined end strategy to finalize the object creation. It facilitates the flexible\nconstruction of complex objects by allowing step-by-step configuration.\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] + pub struct Struct1Former < Definition = Struct1FormerDefinition < (), Struct1 + < > , former :: ReturnPreformed > , > where Definition : former :: + FormerDefinition < Storage = Struct1FormerStorage < > > , Definition :: Types + : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , + { + #[doc = + r" Temporary storage for all fields during the formation process. It contains"] + #[doc = + r" partial data that progressively builds up to the final object."] pub + storage : Definition :: Storage, + #[doc = + r" An optional context providing additional data or state necessary for custom"] + #[doc = + r" formation logic or to facilitate this former's role as a subformer within another former."] + pub context : core :: option :: Option < Definition :: Context > , + #[doc = + r" An optional closure or handler that is invoked to transform the accumulated"] + #[doc = + r" temporary storage into the final object structure once formation is complete."] + pub on_end : core :: option :: Option < Definition :: End > , + } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > + where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage + < > > , Definition :: Types : former :: FormerDefinitionTypes < Storage = + Struct1FormerStorage < > > , + { + #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> + Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > + (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , + { Self :: begin_coercing(None, None, end,) } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn + begin(mut storage : core :: option :: Option < Definition :: Storage > , + context : core :: option :: Option < Definition :: Context > , on_end : < + Definition as former :: FormerDefinition > :: End,) -> Self + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: Some(on_end), + } + } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > + (mut storage : core :: option :: Option < Definition :: Storage > , + context : core :: option :: Option < Definition :: Context > , on_end : + IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < + Definition as former :: FormerDefinition > :: End > , + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: + Some(:: core :: convert :: Into :: into(on_end)), + } + } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types + as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { + let on_end = self.on_end.take().unwrap(); let mut context = + self.context.take(); < Definition :: Types as former :: FormerMutator + > :: form_mutation(& mut self.storage, & mut context); former :: + FormingEnd :: < Definition :: Types > :: + call(& on_end, self.storage, context) + } + #[doc = + "Container setter for the 'vec_1' field. Method _vec_1_container_former unlike method vec_1 accept custom container subformer."] + #[inline(always)] pub fn _vec_1_container_former < Former2 > (self) -> + Former2 where Former2 : former :: FormerBegin < former :: VectorDefinition + < String, Self, Self, Struct1FormerAssignVec1End < Definition > , > , > , + former :: VectorDefinition < String, Self, Self, + Struct1FormerAssignVec1End < Definition > , > : former :: FormerDefinition + < Storage : former :: ContainerAdd < Entry = < Vec < String > as former :: + Container > :: Entry > , Context = Struct1Former < Definition, > , End = + Struct1FormerAssignVec1End < Definition > , > , + { + Former2 :: + former_begin(None, Some(self), Struct1FormerAssignVec1End :: < + Definition > :: default()) + } + + #[inline(always)] + pub fn vec_1(self) -> former :: ContainerSubformer :: + < String, former :: VectorDefinition < String, Self, Self, Struct1FormerAssignVec1End < Definition > , > , > + where + former :: VectorDefinition < String, Self, Self, Struct1FormerAssignVec1End < Definition > , > : former :: FormerDefinition < Storage : former :: ContainerAdd < Entry = < Vec < String > as former :: Container > :: Entry > + , Context = Struct1Former < Definition > , End = Struct1FormerAssignVec1End < Definition > , > , + { + self._vec_1_container_former :: < former :: ContainerSubformer :: < + String, former :: VectorDefinition < String, Self, Self, + Struct1FormerAssignVec1End < Definition > , > , > > () + } + + } + + impl < Definition, > Struct1Former < Definition, > where Definition : former + :: FormerDefinition < Storage = Struct1FormerStorage < > , Formed = Struct1 < + > > , Definition :: Types : former :: FormerDefinitionTypes < Storage = + Struct1FormerStorage < > , Formed = Struct1 < > > , Definition : former :: + FormerDefinition < Storage = Struct1FormerStorage < > > , Definition :: Types + : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , + { + pub fn preform(self) -> < Definition :: Types as former :: + FormerDefinitionTypes > :: Formed + { former :: StoragePreform :: preform(self.storage) } + } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > + where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage + < > , Formed = Struct1 < > , > , Definition :: Types : former :: + FormerDefinitionTypes < Storage = Struct1FormerStorage < > , Formed = Struct1 + < > , > , + { + #[doc = r""] + #[doc = r" Finish setting options and call perform on formed entity."] + #[doc = r""] + #[doc = + r" If `perform` defined then associated method is called and its result returned instead of entity."] + #[doc = + r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] + #[doc = r""] #[inline(always)] pub fn perform(self) -> Definition :: + Formed { let result = self.form(); return result; } + } impl < Definition > former :: FormerBegin < Definition > for Struct1Former < + Definition, > where Definition : former :: FormerDefinition < Storage = + Struct1FormerStorage < > > , + { + #[inline(always)] fn + former_begin(storage : core :: option :: Option < Definition :: Storage > + , context : core :: option :: Option < Definition :: Context > , on_end : + Definition :: End,) -> Self + { + debug_assert! (storage.is_none()); Self :: + begin(None, context, on_end) + } + } + #[doc = + r" Use as subformer of a field during process of forming of super structure."] + pub type Struct1AsSubformer < __Superformer, __End > = Struct1Former < + Struct1FormerDefinition < __Superformer, __Superformer, __End, > , > ; + #[doc = + "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] + pub trait Struct1AsSubformerEnd < SuperFormer > where Self : former :: + FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, SuperFormer > , > , + {} impl < SuperFormer, __T > Struct1AsSubformerEnd < SuperFormer > for __T + where Self : former :: FormingEnd < Struct1FormerDefinitionTypes < + SuperFormer, SuperFormer > , > , {} + + pub struct Struct1FormerAssignVec1End< Definition > + { + _phantom : core::marker::PhantomData< (Definition,) >, + } + + impl< Definition > Default for Struct1FormerAssignVec1End< Definition > + { + #[inline(always)] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + } + + // impl< Definition, > former::FormingEnd + // < former::VectorDefinitionTypes< String, Struct1Former< Definition >, Struct1Former< Definition > > > + // for Struct1FormerAssignVec1End< Definition > + // where + // Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, + // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, + // { + // #[ inline( always ) ] + // fn call( &self, storage : collection_tools::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 + // { + // former::ContainerAssign::assign( field, storage ); + // } + // else + // { + // super_former.storage.vec_1 = Some( storage ); + // } + // super_former + // } + // } + + // xxx + + #[automatically_derived] + impl< Definition, > former::FormingEnd + < + < + former::VectorDefinition + < + String, + Struct1Former< Definition, >, + Struct1Former< Definition, >, + > + as former::FormerDefinition + > :: Types + > + for Struct1FormerAssignVec1End< Definition > + where + Definition : former::FormerDefinition< Storage = Struct1FormerStorage< > >, + Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, + { + #[inline(always)] + 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 + { + former::ContainerAssign::assign( field, storage ); + } + else + { + super_former.storage.vec_1 = Some( storage ); + } + super_former + } + } + // == generated end -include!( "./only_test/containers_with_subformer.rs" ); +// include!( "./only_test/containers_with_subformer.rs" ); +// xxx \ No newline at end of file diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index fa5e4360a6..79b4a9288f 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -23,7 +23,7 @@ where Struct1FormerDefinition<(), Struct1<>, former::ReturnPreformed> > { - Struct1Former::, former::ReturnPreformed>>::new_coercing(former::ReturnPreformed) + Struct1Former::< Struct1FormerDefinition< (), Struct1<>, former::ReturnPreformed > >::new_coercing(former::ReturnPreformed) } } @@ -596,10 +596,38 @@ impl Default for Struct1FormerAssignVec1End< Definition > } } -impl< Definition, > former::FormingEnd -< former::VectorDefinitionTypes< String, Struct1Former< Definition >, Struct1Former< Definition > > > +// Struct1Former< Definition = Struct1FormerDefinition<(), Struct1<>, former::ReturnPreformed>, > + +impl< Definition > former::FormingEnd +< + former::VectorDefinitionTypes< String, Struct1Former< Definition >, Struct1Former< Definition > > + // < + // former::VectorDefinition + // < + // String, + // Struct1Former< Definition >, + // Struct1Former< Definition >, + // // End, + // Self, + // // Struct1FormerAssignVec1End< Definition >, + // > + // as former::FormerDefinition + // > :: Types, +> for Struct1FormerAssignVec1End< Definition > where + // Self : Sized, + // < + // former::VectorDefinition + // < + // String, + // Struct1Former< Definition, >, + // Struct1Former< Definition, >, + // Struct1FormerAssignVec1End< Definition >, + // > + // as former::FormerDefinition + // > :: Types : former::FormerDefinitionTypes, + // > :: Types : former::FormerDefinitionTypes< Context = Struct1Former< Definition, >, Formed = Struct1Former< Definition, > >, Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index cd5d0f48fc..13251f2481 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -26,7 +26,7 @@ mod former_tests mod a_containers_with_subformer_manual; // #[ cfg( not( feature = "no_std" ) ) ] // mod a_containers_with_subformer; -// + // mod attribute_default_container; // mod attribute_default_primitive; // mod attribute_default_conflict; diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index a09cc83875..8d42d6995a 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -764,7 +764,7 @@ where #[ inline( always ) ] pub fn #setter_name( self ) -> former::ContainerSubformer:: < - #( #params, )*, // xxx : use former::Container + #( #params, )* // xxx : use former::Container #subformer_definition, > where @@ -777,7 +777,7 @@ where { self.#field_assign::< former::ContainerSubformer:: < - #( #params, )*, // xxx : use former::Container + #( #params, )* // xxx : use former::Container #subformer_definition, > > () } @@ -838,7 +838,6 @@ where }} "#, - // xxx : update former, former_storage, field_ident, From e9f5eaf2f80b8b22deeabe1496adc16769618457 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 17:19:46 +0300 Subject: [PATCH 483/533] former : types problem --- .../a_containers_with_subformer.rs | 351 +----------------- module/core/former/tests/inc/mod.rs | 4 +- .../former_meta/src/derive_former/field.rs | 15 +- 3 files changed, 22 insertions(+), 348 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs index a909b4e99b..a9eaa315fa 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs @@ -4,356 +4,21 @@ use super::*; // use std::collections::HashMap; // use std::collections::HashSet; -// #[ derive( Default, Debug, PartialEq, former::Former ) ] +#[ derive( Default, Debug, PartialEq, former::Former ) ] // #[ derive( Default, Debug, PartialEq, former::Former ) ] #[ debug ] -#[ derive( Default, Debug, PartialEq ) ] +// #[ derive( Default, Debug, PartialEq ) ] pub struct Struct1 { - // #[ container( definition = former::VectorDefinition ) ] + #[ container( definition = former::VectorDefinition ) ] vec_1 : Vec< String >, - // #[ container( definition = former::HashMapDefinition ) ] - // hashmap_1 : std::collections::HashMap< String, String >, - // #[ container( definition = former::HashSetDefinition ) ] - // hashset_1 : std::collections::HashSet< String >, - // xxx + #[ container( definition = former::HashMapDefinition ) ] + hashmap_1 : std::collections::HashMap< String, String >, + #[ container( definition = former::HashSetDefinition ) ] + hashset_1 : std::collections::HashSet< String >, } // == generated begin - #[automatically_derived] impl < > Struct1 < > where - { - #[doc = r""] - #[doc = - r" Make former, variation of builder pattern to form structure defining values of fields step by step."] - #[doc = r""] #[inline(always)] pub fn former() -> Struct1Former < - Struct1FormerDefinition < (), Struct1 < > , former :: ReturnPreformed > > - { - Struct1Former :: < Struct1FormerDefinition < (), Struct1 < > , former - :: ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) - } - } impl < Definition > former :: EntityToFormer < Definition > for Struct1 < > - where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage - < > > , { type Former = Struct1Former < Definition > ; } impl < > former :: - EntityToStorage for Struct1 < > where - { type Storage = Struct1FormerStorage < > ; } impl < __Context, __Formed, - __End > former :: EntityToDefinition < __Context, __Formed, __End > for - Struct1 < > where __End : former :: FormingEnd < Struct1FormerDefinitionTypes - < __Context, __Formed > > , - { - type Definition = Struct1FormerDefinition < __Context, __Formed, __End > ; - type Types = Struct1FormerDefinitionTypes < __Context, __Formed > ; - } impl < __Context, __Formed > former :: EntityToDefinitionTypes < __Context, - __Formed > for Struct1 < > where - { type Types = Struct1FormerDefinitionTypes < __Context, __Formed > ; } - #[derive(Debug)] pub struct Struct1FormerDefinitionTypes < __Context = (), - __Formed = Struct1 < > , > where - { - _phantom : core :: marker :: PhantomData < - (* const __Context, * const __Formed) > , - } impl < __Context, __Formed, > :: core :: default :: Default for - Struct1FormerDefinitionTypes < __Context, __Formed, > where - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } impl < __Context, __Formed, > former :: FormerDefinitionTypes for - Struct1FormerDefinitionTypes < __Context, __Formed, > where - { - type Storage = Struct1FormerStorage < > ; type Formed = __Formed; type - Context = __Context; - } #[derive(Debug)] pub struct Struct1FormerDefinition < __Context = (), - __Formed = Struct1 < > , __End = former :: ReturnPreformed, > where - { - _phantom : core :: marker :: PhantomData < - (* const __Context, * const __Formed, * const __End) > , - } impl < __Context, __Formed, __End, > :: core :: default :: Default for - Struct1FormerDefinition < __Context, __Formed, __End, > where - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } impl < __Context, __Formed, __End, > former :: FormerDefinition for - Struct1FormerDefinition < __Context, __Formed, __End, > where __End : former - :: FormingEnd < Struct1FormerDefinitionTypes < __Context, __Formed, > > , - { - type Types = Struct1FormerDefinitionTypes < __Context, __Formed, > ; type - End = __End; type Storage = Struct1FormerStorage < > ; type Formed = - __Formed; type Context = __Context; - } impl < __Context, __Formed, > former :: FormerMutator for - Struct1FormerDefinitionTypes < __Context, __Formed, > where {} - #[doc = "Container of a corresponding former."] - #[allow(explicit_outlives_requirements)] pub struct Struct1FormerStorage < > - where - { - #[doc = r" A field"] pub vec_1 : :: core :: option :: Option < Vec < - String > > , - } impl < > :: core :: default :: Default for Struct1FormerStorage < > where - { - #[inline(always)] fn default() -> Self - { Self { vec_1 : :: core :: option :: Option :: None, } } - } impl < > former :: Storage for Struct1FormerStorage < > where - { type Formed = Struct1 < > ; } impl < > former :: StoragePreform for - Struct1FormerStorage < > where - { - type Preformed = Struct1 < > ; fn preform(mut self) -> Self :: Preformed - { - let vec_1 = if self.vec_1.is_some() { self.vec_1.take().unwrap() } - else - { - { - trait MaybeDefault < T > - { - fn maybe_default(self : & Self) -> T - { panic! ("Field 'vec_1' isn't initialized") } - } impl < T > MaybeDefault < T > for & :: core :: marker :: - PhantomData < T > {} impl < T > MaybeDefault < T > for :: core - :: marker :: PhantomData < T > where T : :: core :: default :: - Default, - { fn maybe_default(self : & Self) -> T { T :: default() } } - (& :: core :: marker :: PhantomData :: < Vec < String > - >).maybe_default() - } - }; let result = Struct1 :: < > { vec_1, }; return result; - } - } - #[doc = - "\nStructure to form [Struct1]. Represents a forming entity designed to construct objects through a builder pattern.\n\nThis structure holds temporary storage and context during the formation process and\nutilizes a defined end strategy to finalize the object creation. It facilitates the flexible\nconstruction of complex objects by allowing step-by-step configuration.\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] - pub struct Struct1Former < Definition = Struct1FormerDefinition < (), Struct1 - < > , former :: ReturnPreformed > , > where Definition : former :: - FormerDefinition < Storage = Struct1FormerStorage < > > , Definition :: Types - : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , - { - #[doc = - r" Temporary storage for all fields during the formation process. It contains"] - #[doc = - r" partial data that progressively builds up to the final object."] pub - storage : Definition :: Storage, - #[doc = - r" An optional context providing additional data or state necessary for custom"] - #[doc = - r" formation logic or to facilitate this former's role as a subformer within another former."] - pub context : core :: option :: Option < Definition :: Context > , - #[doc = - r" An optional closure or handler that is invoked to transform the accumulated"] - #[doc = - r" temporary storage into the final object structure once formation is complete."] - pub on_end : core :: option :: Option < Definition :: End > , - } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > - where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage - < > > , Definition :: Types : former :: FormerDefinitionTypes < Storage = - Struct1FormerStorage < > > , - { - #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> - Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > - (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , - { Self :: begin_coercing(None, None, end,) } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn - begin(mut storage : core :: option :: Option < Definition :: Storage > , - context : core :: option :: Option < Definition :: Context > , on_end : < - Definition as former :: FormerDefinition > :: End,) -> Self - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: Some(on_end), - } - } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > - (mut storage : core :: option :: Option < Definition :: Storage > , - context : core :: option :: Option < Definition :: Context > , on_end : - IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < - Definition as former :: FormerDefinition > :: End > , - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: - Some(:: core :: convert :: Into :: into(on_end)), - } - } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types - as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { - let on_end = self.on_end.take().unwrap(); let mut context = - self.context.take(); < Definition :: Types as former :: FormerMutator - > :: form_mutation(& mut self.storage, & mut context); former :: - FormingEnd :: < Definition :: Types > :: - call(& on_end, self.storage, context) - } - #[doc = - "Container setter for the 'vec_1' field. Method _vec_1_container_former unlike method vec_1 accept custom container subformer."] - #[inline(always)] pub fn _vec_1_container_former < Former2 > (self) -> - Former2 where Former2 : former :: FormerBegin < former :: VectorDefinition - < String, Self, Self, Struct1FormerAssignVec1End < Definition > , > , > , - former :: VectorDefinition < String, Self, Self, - Struct1FormerAssignVec1End < Definition > , > : former :: FormerDefinition - < Storage : former :: ContainerAdd < Entry = < Vec < String > as former :: - Container > :: Entry > , Context = Struct1Former < Definition, > , End = - Struct1FormerAssignVec1End < Definition > , > , - { - Former2 :: - former_begin(None, Some(self), Struct1FormerAssignVec1End :: < - Definition > :: default()) - } - - #[inline(always)] - pub fn vec_1(self) -> former :: ContainerSubformer :: - < String, former :: VectorDefinition < String, Self, Self, Struct1FormerAssignVec1End < Definition > , > , > - where - former :: VectorDefinition < String, Self, Self, Struct1FormerAssignVec1End < Definition > , > : former :: FormerDefinition < Storage : former :: ContainerAdd < Entry = < Vec < String > as former :: Container > :: Entry > - , Context = Struct1Former < Definition > , End = Struct1FormerAssignVec1End < Definition > , > , - { - self._vec_1_container_former :: < former :: ContainerSubformer :: < - String, former :: VectorDefinition < String, Self, Self, - Struct1FormerAssignVec1End < Definition > , > , > > () - } - - } - - impl < Definition, > Struct1Former < Definition, > where Definition : former - :: FormerDefinition < Storage = Struct1FormerStorage < > , Formed = Struct1 < - > > , Definition :: Types : former :: FormerDefinitionTypes < Storage = - Struct1FormerStorage < > , Formed = Struct1 < > > , Definition : former :: - FormerDefinition < Storage = Struct1FormerStorage < > > , Definition :: Types - : former :: FormerDefinitionTypes < Storage = Struct1FormerStorage < > > , - { - pub fn preform(self) -> < Definition :: Types as former :: - FormerDefinitionTypes > :: Formed - { former :: StoragePreform :: preform(self.storage) } - } #[automatically_derived] impl < Definition, > Struct1Former < Definition, > - where Definition : former :: FormerDefinition < Storage = Struct1FormerStorage - < > , Formed = Struct1 < > , > , Definition :: Types : former :: - FormerDefinitionTypes < Storage = Struct1FormerStorage < > , Formed = Struct1 - < > , > , - { - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] - #[doc = - r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = - r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] #[inline(always)] pub fn perform(self) -> Definition :: - Formed { let result = self.form(); return result; } - } impl < Definition > former :: FormerBegin < Definition > for Struct1Former < - Definition, > where Definition : former :: FormerDefinition < Storage = - Struct1FormerStorage < > > , - { - #[inline(always)] fn - former_begin(storage : core :: option :: Option < Definition :: Storage > - , context : core :: option :: Option < Definition :: Context > , on_end : - Definition :: End,) -> Self - { - debug_assert! (storage.is_none()); Self :: - begin(None, context, on_end) - } - } - #[doc = - r" Use as subformer of a field during process of forming of super structure."] - pub type Struct1AsSubformer < __Superformer, __End > = Struct1Former < - Struct1FormerDefinition < __Superformer, __Superformer, __End, > , > ; - #[doc = - "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] - pub trait Struct1AsSubformerEnd < SuperFormer > where Self : former :: - FormingEnd < Struct1FormerDefinitionTypes < SuperFormer, SuperFormer > , > , - {} impl < SuperFormer, __T > Struct1AsSubformerEnd < SuperFormer > for __T - where Self : former :: FormingEnd < Struct1FormerDefinitionTypes < - SuperFormer, SuperFormer > , > , {} - - pub struct Struct1FormerAssignVec1End< Definition > - { - _phantom : core::marker::PhantomData< (Definition,) >, - } - - impl< Definition > Default for Struct1FormerAssignVec1End< Definition > - { - #[inline(always)] - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } - } - - // impl< Definition, > former::FormingEnd - // < former::VectorDefinitionTypes< String, Struct1Former< Definition >, Struct1Former< Definition > > > - // for Struct1FormerAssignVec1End< Definition > - // where - // Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, - // { - // #[ inline( always ) ] - // fn call( &self, storage : collection_tools::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 - // { - // former::ContainerAssign::assign( field, storage ); - // } - // else - // { - // super_former.storage.vec_1 = Some( storage ); - // } - // super_former - // } - // } - - // xxx - - #[automatically_derived] - impl< Definition, > former::FormingEnd - < - < - former::VectorDefinition - < - String, - Struct1Former< Definition, >, - Struct1Former< Definition, >, - > - as former::FormerDefinition - > :: Types - > - for Struct1FormerAssignVec1End< Definition > - where - Definition : former::FormerDefinition< Storage = Struct1FormerStorage< > >, - Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage< > >, - { - #[inline(always)] - 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 - { - former::ContainerAssign::assign( field, storage ); - } - else - { - super_former.storage.vec_1 = Some( storage ); - } - super_former - } - } - // == generated end -// include!( "./only_test/containers_with_subformer.rs" ); -// xxx \ No newline at end of file +include!( "./only_test/containers_with_subformer.rs" ); diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 13251f2481..b4329b904d 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -24,8 +24,8 @@ mod former_tests mod a_containers_without_subformer; #[ cfg( not( feature = "no_std" ) ) ] mod a_containers_with_subformer_manual; -// #[ cfg( not( feature = "no_std" ) ) ] -// mod a_containers_with_subformer; + #[ cfg( not( feature = "no_std" ) ) ] + mod a_containers_with_subformer; // mod attribute_default_container; // mod attribute_default_primitive; diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 8d42d6995a..6825505048 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -1028,11 +1028,17 @@ where Callback replace content of container assigning new content from subformer's storage."# ); - let subformer_definition = if subformer_definition.is_some() + let subformer_definition_types = if let Some( ref _subformer_definition ) = subformer_definition { + // let subformer_definition_types_name = format!( "{}Types", qt!{ #subformer_definition } ); + // dbg!( &subformer_definition_types_name ); + // let subformer_definition_types = syn::Ident::new( &subformer_definition_types_name, field_ident.span() ); + let subformer_definition_types_string = format!( "{}Types", qt!{ #subformer_definition } ); + // let subformer_definition_types : syn::Type = subformer_definition_types_string.parse()? + let subformer_definition_types : syn::Type = syn::parse_str( &subformer_definition_types_string )?; qt! { - #subformer_definition + #subformer_definition_types < #( #params, )* #former< #former_generics_ty >, @@ -1044,6 +1050,7 @@ where } else { + qt! { < @@ -1085,7 +1092,9 @@ where #[ automatically_derived ] impl< #former_generics_impl > former::FormingEnd < - #subformer_definition, + // VectorDefinitionTypes + // #subformer_definition, + #subformer_definition_types, > for #former_assign_end< Definition > where From 5e662cb2916f1be4111c51cdddf47d8a87a1d7e9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 17:22:42 +0300 Subject: [PATCH 484/533] former : types problem --- .../parametrized_struct_manual.rs | 4 +- module/core/former/tests/inc/mod.rs | 68 +++++++++---------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index b3669e4e04..6f8901a3a5 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -339,12 +339,12 @@ where } } - #[ allow( non_camel_case_types ) ] pub struct ChildFormerPropertiesEnd; #[ automatically_derived ] -impl< K, Definition, > former::FormingEnd< former::HashMapDefinition< K, Property< K >, ChildFormer< K, Definition, >, ChildFormer< K, Definition, >, former::NoEnd >, > for ChildFormerPropertiesEnd +impl< K, Definition, > former::FormingEnd< former::HashMapDefinitionTypes< K, Property< K >, ChildFormer< K, Definition, >, ChildFormer< K, Definition, > >, > +for ChildFormerPropertiesEnd where K : core::hash::Hash + std::cmp::Eq, Definition : former::FormerDefinition< Storage = ChildFormerStorage< K, > >, diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index b4329b904d..5389f2dbec 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -27,40 +27,40 @@ mod former_tests #[ cfg( not( feature = "no_std" ) ) ] mod a_containers_with_subformer; -// mod attribute_default_container; -// mod attribute_default_primitive; -// mod attribute_default_conflict; -// mod attribute_storage_with_end; -// mod attribute_storage_with_mutator; -// mod attribute_perform; -// mod attribute_setter; -// mod attribute_alias; -// mod attribute_feature; -// -// mod string_slice_manual; -// mod string_slice; -// mod unsigned_primitive_types; -// mod default_user_type; -// mod user_type_no_default; -// mod user_type_no_debug; -// mod visibility; -// -// mod name_collision_former_hashmap_without_parameter; -// mod name_collision_former_vector_without_parameter; -// mod name_collisions; -// mod name_collision_context; -// mod name_collision_end; -// mod name_collision_on_end; -// -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_manual; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_imm; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod parametrized_struct_where; -// mod parametrized_field; -// mod parametrized_field_where; -// + mod attribute_default_container; + mod attribute_default_primitive; + mod attribute_default_conflict; + mod attribute_storage_with_end; + mod attribute_storage_with_mutator; + mod attribute_perform; + mod attribute_setter; + mod attribute_alias; + mod attribute_feature; + + mod string_slice_manual; + mod string_slice; + mod unsigned_primitive_types; + mod default_user_type; + mod user_type_no_default; + mod user_type_no_debug; + mod visibility; + + mod name_collision_former_hashmap_without_parameter; + mod name_collision_former_vector_without_parameter; + mod name_collisions; + mod name_collision_context; + mod name_collision_end; + mod name_collision_on_end; + + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_manual; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod parametrized_struct_imm; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // mod parametrized_struct_where; + // mod parametrized_field; + // mod parametrized_field_where; + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic; // From aa2bb8c5d2f6d5910de203c511d7677884e8f51a Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 17:27:42 +0300 Subject: [PATCH 485/533] former : types problem --- .../core/former/examples/former_custom_container.rs | 9 +++++---- module/core/former/tests/inc/mod.rs | 12 ++++++------ module/core/former_meta/src/derive_former/field.rs | 6 ++++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/module/core/former/examples/former_custom_container.rs b/module/core/former/examples/former_custom_container.rs index 822be42bb3..275adb25f3 100644 --- a/module/core/former/examples/former_custom_container.rs +++ b/module/core/former/examples/former_custom_container.rs @@ -14,10 +14,10 @@ fn main() // = define custom container // Custom container that logs additions - #[derive(Default)] - pub struct LoggingSet + #[ derive( Default ) ] + pub struct LoggingSet< T > { - set: HashSet, + set : HashSet< T >, } // // Implementing the container traits for LoggingSet @@ -33,7 +33,8 @@ fn main() // } // This trait allows adding entries to the LoggingSet - impl former::ContainerAdd for LoggingSet + impl< T : Eq + std::hash::Hash + fmt::Debug > former::ContainerAdd + for LoggingSet< T > { fn add(&mut self, e: Self::Entry) -> bool { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 5389f2dbec..1b636eaaa0 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -54,12 +54,12 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] mod parametrized_struct_manual; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod parametrized_struct_imm; - // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - // mod parametrized_struct_where; - // mod parametrized_field; - // mod parametrized_field_where; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_imm; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod parametrized_struct_where; + mod parametrized_field; + mod parametrized_field_where; // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic; diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 6825505048..f554b42c7a 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -706,7 +706,8 @@ where #subformer_definition : former::FormerDefinition < Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, - Context = Struct1Former< Definition >, + Context = #former< #former_generics_ty >, + // Context = Struct1Former< Definition >, End = #former_assign_end < Definition >, >, { @@ -771,7 +772,8 @@ where #subformer_definition : former::FormerDefinition < Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, - Context = Struct1Former< Definition >, + Context = #former< #former_generics_ty >, + // Context = Struct1Former< Definition >, End = #former_assign_end < Definition >, >, { From 8fe79b6453b9780651a8cbb7cfabbb24fabd429a Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 17:28:42 +0300 Subject: [PATCH 486/533] former : types problem --- .../a_containers_with_subformer_manual.rs | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 79b4a9288f..452c4ddef0 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -601,33 +601,9 @@ impl Default for Struct1FormerAssignVec1End< Definition > impl< Definition > former::FormingEnd < former::VectorDefinitionTypes< String, Struct1Former< Definition >, Struct1Former< Definition > > - // < - // former::VectorDefinition - // < - // String, - // Struct1Former< Definition >, - // Struct1Former< Definition >, - // // End, - // Self, - // // Struct1FormerAssignVec1End< Definition >, - // > - // as former::FormerDefinition - // > :: Types, > for Struct1FormerAssignVec1End< Definition > where - // Self : Sized, - // < - // former::VectorDefinition - // < - // String, - // Struct1Former< Definition, >, - // Struct1Former< Definition, >, - // Struct1FormerAssignVec1End< Definition >, - // > - // as former::FormerDefinition - // > :: Types : former::FormerDefinitionTypes, - // > :: Types : former::FormerDefinitionTypes< Context = Struct1Former< Definition, >, Formed = Struct1Former< Definition, > >, Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { From a1e74ae7f3a2b3b5780a173cf4c27722190cd59f Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 17:50:29 +0300 Subject: [PATCH 487/533] former : types problem --- module/core/former/Readme.md | 2 +- .../examples/former_custom_container.rs | 1 + .../subformer_container_custom.rs | 2 + .../subformer_container_implicit.rs | 294 +++++++++++++++++- .../subformer_container_manual.rs | 4 +- module/core/former/tests/inc/mod.rs | 10 +- .../former_meta/src/derive_former/field.rs | 2 +- 7 files changed, 303 insertions(+), 12 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 01f5ce0242..e8d51ca8c2 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -994,7 +994,7 @@ fn main() use collection_tools::HashMap; use former::Former; - xxx : write + xxx2 : write } ``` diff --git a/module/core/former/examples/former_custom_container.rs b/module/core/former/examples/former_custom_container.rs index 275adb25f3..625c2e80ac 100644 --- a/module/core/former/examples/former_custom_container.rs +++ b/module/core/former/examples/former_custom_container.rs @@ -2,6 +2,7 @@ /// /// Container interface is defined in the crate and implemented for containers like vectors, hash maps, etc, but if you want to use non-standard container you can implement container interface for the container. This example demonstrate how to do that. +// xxx2 : get complited #[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] fn main() {} diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index e0aaa9c941..5067c19b14 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -217,3 +217,5 @@ // println!("Got: {:?}", parent); // // } + +// xxx2 : get completed \ No newline at end of file diff --git a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs index 4852c502e2..94c7831fc3 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs @@ -11,19 +11,307 @@ pub struct Child } /// Parent required for the template. -#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] // #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] -// #[ derive( Debug, Default, PartialEq ) ] +#[ derive( Debug, Default, PartialEq ) ] pub struct Parent { // #[ container( definition = former::VectorDefinition ) ] #[ container ] - // #[ scalar( setter = false ) ] children : Vec< Child >, } // == begin of generated + #[automatically_derived] impl < > Parent < > where + { + #[doc = r""] + #[doc = + r" Make former, variation of builder pattern to form structure defining values of fields step by step."] + #[doc = r""] #[inline(always)] pub fn former() -> ParentFormer < + ParentFormerDefinition < (), Parent < > , former :: ReturnPreformed > > + { + ParentFormer :: < ParentFormerDefinition < (), Parent < > , former :: + ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) + } + } impl < Definition > former :: EntityToFormer < Definition > for Parent < > + where Definition : former :: FormerDefinition < Storage = ParentFormerStorage + < > > , { type Former = ParentFormer < Definition > ; } impl < > former :: + EntityToStorage for Parent < > where + { type Storage = ParentFormerStorage < > ; } impl < __Context, __Formed, __End + > former :: EntityToDefinition < __Context, __Formed, __End > for Parent < > + where __End : former :: FormingEnd < ParentFormerDefinitionTypes < __Context, + __Formed > > , + { + type Definition = ParentFormerDefinition < __Context, __Formed, __End > ; + type Types = ParentFormerDefinitionTypes < __Context, __Formed > ; + } impl < __Context, __Formed > former :: EntityToDefinitionTypes < __Context, + __Formed > for Parent < > where + { type Types = ParentFormerDefinitionTypes < __Context, __Formed > ; } + #[derive(Debug)] pub struct ParentFormerDefinitionTypes < __Context = (), + __Formed = Parent < > , > where + { + _phantom : core :: marker :: PhantomData < + (* const __Context, * const __Formed) > , + } impl < __Context, __Formed, > :: core :: default :: Default for + ParentFormerDefinitionTypes < __Context, __Formed, > where + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } impl < __Context, __Formed, > former :: FormerDefinitionTypes for + ParentFormerDefinitionTypes < __Context, __Formed, > where + { + type Storage = ParentFormerStorage < > ; type Formed = __Formed; type + Context = __Context; + } #[derive(Debug)] pub struct ParentFormerDefinition < __Context = (), + __Formed = Parent < > , __End = former :: ReturnPreformed, > where + { + _phantom : core :: marker :: PhantomData < + (* const __Context, * const __Formed, * const __End) > , + } impl < __Context, __Formed, __End, > :: core :: default :: Default for + ParentFormerDefinition < __Context, __Formed, __End, > where + { + fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } impl < __Context, __Formed, __End, > former :: FormerDefinition for + ParentFormerDefinition < __Context, __Formed, __End, > where __End : former :: + FormingEnd < ParentFormerDefinitionTypes < __Context, __Formed, > > , + { + type Types = ParentFormerDefinitionTypes < __Context, __Formed, > ; type + End = __End; type Storage = ParentFormerStorage < > ; type Formed = + __Formed; type Context = __Context; + } impl < __Context, __Formed, > former :: FormerMutator for + ParentFormerDefinitionTypes < __Context, __Formed, > where {} + #[doc = "Container of a corresponding former."] + #[allow(explicit_outlives_requirements)] pub struct ParentFormerStorage < > + where + { + #[doc = r" A field"] pub children : :: core :: option :: Option < Vec < + Child > > , + } impl < > :: core :: default :: Default for ParentFormerStorage < > where + { + #[inline(always)] fn default() -> Self + { Self { children : :: core :: option :: Option :: None, } } + } impl < > former :: Storage for ParentFormerStorage < > where + { type Formed = Parent < > ; } impl < > former :: StoragePreform for + ParentFormerStorage < > where + { + type Preformed = Parent < > ; fn preform(mut self) -> Self :: Preformed + { + let children = if self.children.is_some() + { self.children.take().unwrap() } else + { + { + trait MaybeDefault < T > + { + fn maybe_default(self : & Self) -> T + { panic! ("Field 'children' isn't initialized") } + } impl < T > MaybeDefault < T > for & :: core :: marker :: + PhantomData < T > {} impl < T > MaybeDefault < T > for :: core + :: marker :: PhantomData < T > where T : :: core :: default :: + Default, + { fn maybe_default(self : & Self) -> T { T :: default() } } + (& :: core :: marker :: PhantomData :: < Vec < Child > + >).maybe_default() + } + }; let result = Parent :: < > { children, }; return result; + } + } + #[doc = + "\nStructure to form [Parent]. Represents a forming entity designed to construct objects through a builder pattern.\n\nThis structure holds temporary storage and context during the formation process and\nutilizes a defined end strategy to finalize the object creation. It facilitates the flexible\nconstruction of complex objects by allowing step-by-step configuration.\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] + pub struct ParentFormer < Definition = ParentFormerDefinition < (), Parent < > + , former :: ReturnPreformed > , > where Definition : former :: + FormerDefinition < Storage = ParentFormerStorage < > > , Definition :: Types : + former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , + { + #[doc = + r" Temporary storage for all fields during the formation process. It contains"] + #[doc = + r" partial data that progressively builds up to the final object."] pub + storage : Definition :: Storage, + #[doc = + r" An optional context providing additional data or state necessary for custom"] + #[doc = + r" formation logic or to facilitate this former's role as a subformer within another former."] + pub context : core :: option :: Option < Definition :: Context > , + #[doc = + r" An optional closure or handler that is invoked to transform the accumulated"] + #[doc = + r" temporary storage into the final object structure once formation is complete."] + pub on_end : core :: option :: Option < Definition :: End > , + } #[automatically_derived] impl < Definition, > ParentFormer < Definition, > + where Definition : former :: FormerDefinition < Storage = ParentFormerStorage + < > > , Definition :: Types : former :: FormerDefinitionTypes < Storage = + ParentFormerStorage < > > , + { + #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> + Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] + #[doc = r" Construct new instance of former with default parameters."] + #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > + (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , + { Self :: begin_coercing(None, None, end,) } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn + begin(mut storage : core :: option :: Option < Definition :: Storage > , + context : core :: option :: Option < Definition :: Context > , on_end : < + Definition as former :: FormerDefinition > :: End,) -> Self + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: Some(on_end), + } + } #[doc = r""] + #[doc = + r" Begin the process of forming. Expects context of forming to return it after forming."] + #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > + (mut storage : core :: option :: Option < Definition :: Storage > , + context : core :: option :: Option < Definition :: Context > , on_end : + IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < + Definition as former :: FormerDefinition > :: End > , + { + if storage.is_none() + { storage = Some(:: core :: default :: Default :: default()); } Self + { + storage : storage.unwrap(), context : context, on_end : :: core :: + option :: Option :: + Some(:: core :: convert :: Into :: into(on_end)), + } + } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types + as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] + #[doc = + r" End the process of forming returning original context of forming."] + #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: + Types as former :: FormerDefinitionTypes > :: Formed + { + let on_end = self.on_end.take().unwrap(); let mut context = + self.context.take(); < Definition :: Types as former :: FormerMutator + > :: form_mutation(& mut self.storage, & mut context); former :: + FormingEnd :: < Definition :: Types > :: + call(& on_end, self.storage, context) + } + + #[inline(always)] + pub fn _children_container_former< Former2 >( self ) -> Former2 + where + Former2 : former::FormerBegin + < + < Vec< Child > as former::EntityToDefinition< Self, Self, ParentFormerAssignChildrenEnd< Definition > > >::Definition, >, + < + Vec< Child > as former::EntityToDefinition< Self, Self, ParentFormerAssignChildrenEnd< Definition > > >::Definition + : + former::FormerDefinition< Storage : former::ContainerAdd< Entry = < Vec< Child > as former::Container + >::Entry + >, + Context = ParentFormer< Definition, >, + End = ParentFormerAssignChildrenEnd< Definition >, + >, + { + Former2:: + former_begin( None, Some( self ), ParentFormerAssignChildrenEnd::< Definition >::default() ) + } + + #[inline(always)] + pub fn children(self) -> former :: ContainerSubformer :: + < Child, < Vec < Child > as former :: EntityToDefinition < Self, Self, + ParentFormerAssignChildrenEnd < Definition > > > :: Definition, > where < + Vec < Child > as former :: EntityToDefinition < Self, Self, + ParentFormerAssignChildrenEnd < Definition > > > :: Definition : former :: + FormerDefinition < Storage : former :: ContainerAdd < Entry = < Vec < + Child > as former :: Container > :: Entry > , Context = ParentFormer < + Definition, > , End = ParentFormerAssignChildrenEnd < Definition > , > , + { + self._children_container_former :: < former :: ContainerSubformer :: < + Child, < Vec < Child > as former :: EntityToDefinition < Self, Self, + ParentFormerAssignChildrenEnd < Definition > > > :: Definition, > > () + } + + } impl < Definition, > ParentFormer < Definition, > where Definition : former + :: FormerDefinition < Storage = ParentFormerStorage < > , Formed = Parent < > + > , Definition :: Types : former :: FormerDefinitionTypes < Storage = + ParentFormerStorage < > , Formed = Parent < > > , Definition : former :: + FormerDefinition < Storage = ParentFormerStorage < > > , Definition :: Types : + former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , + { + pub fn preform(self) -> < Definition :: Types as former :: + FormerDefinitionTypes > :: Formed + { former :: StoragePreform :: preform(self.storage) } + } #[automatically_derived] impl < Definition, > ParentFormer < Definition, > + where Definition : former :: FormerDefinition < Storage = ParentFormerStorage + < > , Formed = Parent < > , > , Definition :: Types : former :: + FormerDefinitionTypes < Storage = ParentFormerStorage < > , Formed = Parent < + > , > , + { + #[doc = r""] + #[doc = r" Finish setting options and call perform on formed entity."] + #[doc = r""] + #[doc = + r" If `perform` defined then associated method is called and its result returned instead of entity."] + #[doc = + r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] + #[doc = r""] #[inline(always)] pub fn perform(self) -> Definition :: + Formed { let result = self.form(); return result; } + } impl < Definition > former :: FormerBegin < Definition > for ParentFormer < + Definition, > where Definition : former :: FormerDefinition < Storage = + ParentFormerStorage < > > , + { + #[inline(always)] fn + former_begin(storage : core :: option :: Option < Definition :: Storage > + , context : core :: option :: Option < Definition :: Context > , on_end : + Definition :: End,) -> Self + { + debug_assert! (storage.is_none()); Self :: + begin(None, context, on_end) + } + } + #[doc = + r" Use as subformer of a field during process of forming of super structure."] + pub type ParentAsSubformer < __Superformer, __End > = ParentFormer < + ParentFormerDefinition < __Superformer, __Superformer, __End, > , > ; + #[doc = + "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] + pub trait ParentAsSubformerEnd < SuperFormer > where Self : former :: + FormingEnd < ParentFormerDefinitionTypes < SuperFormer, SuperFormer > , > , {} + impl < SuperFormer, __T > ParentAsSubformerEnd < SuperFormer > for __T where + Self : former :: FormingEnd < ParentFormerDefinitionTypes < SuperFormer, + SuperFormer > , > , {} + #[doc = + "Callback to return original former after forming of container for `$Parent` is done.#\n\n Callback replace content of container assigning new content from subformer's storage."] + pub struct ParentFormerAssignChildrenEnd < Definition > + { _phantom : core :: marker :: PhantomData < (Definition,) > , } impl < + Definition > Default for ParentFormerAssignChildrenEnd < Definition > + { + #[inline(always)] fn default() -> Self + { Self { _phantom : core :: marker :: PhantomData, } } + } + + #[automatically_derived] + impl < Definition, > former :: FormingEnd < < Vec < + Child > as former :: EntityToDefinitionTypes < ParentFormer < Definition, > , + ParentFormer < Definition, > , > > :: Types, > + for + ParentFormerAssignChildrenEnd < Definition > where Definition : former :: + FormerDefinition < Storage = ParentFormerStorage < > > , Definition :: Types : + former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , + { + #[inline(always)] fn + call(& self, storage : Vec < Child > , super_former : Option < + ParentFormer < Definition, > > ,) -> ParentFormer < Definition, > + { + let mut super_former = super_former.unwrap(); if let + Some(ref mut field) = super_former.storage.children + { former :: ContainerAssign :: assign(field, storage); } else + { super_former.storage.children = Some(storage); } super_former + } + } + // == end of generated include!( "./only_test/subformer_container.rs" ); diff --git a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs index a198a485fc..48aa08e251 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs @@ -75,8 +75,8 @@ impl< Definition > Default for ParentFormerAssignChildrenEnd< Definition > impl< Definition, > former::FormingEnd < < - Vec< Child > as former::EntityToDefinition< ParentFormer< Definition, >, ParentFormer< Definition, >, former::NoEnd > - >::Definition + Vec< Child > as former::EntityToDefinitionTypes< ParentFormer< Definition, >, ParentFormer< Definition, > > + >::Types > for ParentFormerAssignChildrenEnd< Definition > where diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 1b636eaaa0..9353e11fdd 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -66,17 +66,17 @@ mod former_tests // // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_container; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container_manual; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container_implicit; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_manual; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_container_implicit; // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_container_setter_off; // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_container_named; // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_container_custom; -// + // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_subform; // #[ cfg( any( not( feature = "no_std" ) ) ) ] diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index f554b42c7a..0a22e48a9a 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -1056,7 +1056,7 @@ where qt! { < - #field_ty as former::EntityToDefinition + #field_ty as former::EntityToDefinitionTypes < #former< #former_generics_ty >, #former< #former_generics_ty >, From 10a747ed2731e19d2328c6e31dc17436ad9f803b Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 17:50:42 +0300 Subject: [PATCH 488/533] former : types problem --- module/core/former/tests/inc/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 9353e11fdd..9103106f40 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -64,8 +64,8 @@ mod former_tests // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] // mod subformer_basic; // -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_container_manual; // #[ cfg( any( not( feature = "no_std" ) ) ) ] From 4ce71d308d626533bbc96d3d0690c1ccc99128fa Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 18:52:08 +0300 Subject: [PATCH 489/533] former : types problem --- .../subformer_container_implicit.rs | 624 ++++++++++-------- module/core/former/tests/inc/mod.rs | 20 +- .../former_meta/src/derive_former/field.rs | 12 +- 3 files changed, 351 insertions(+), 305 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs index 94c7831fc3..38369ba208 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs @@ -11,9 +11,9 @@ pub struct Child } /// Parent required for the template. -// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] // #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] -#[ derive( Debug, Default, PartialEq ) ] +// #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { // #[ container( definition = former::VectorDefinition ) ] @@ -23,295 +23,339 @@ pub struct Parent // == begin of generated - #[automatically_derived] impl < > Parent < > where - { - #[doc = r""] - #[doc = - r" Make former, variation of builder pattern to form structure defining values of fields step by step."] - #[doc = r""] #[inline(always)] pub fn former() -> ParentFormer < - ParentFormerDefinition < (), Parent < > , former :: ReturnPreformed > > - { - ParentFormer :: < ParentFormerDefinition < (), Parent < > , former :: - ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) - } - } impl < Definition > former :: EntityToFormer < Definition > for Parent < > - where Definition : former :: FormerDefinition < Storage = ParentFormerStorage - < > > , { type Former = ParentFormer < Definition > ; } impl < > former :: - EntityToStorage for Parent < > where - { type Storage = ParentFormerStorage < > ; } impl < __Context, __Formed, __End - > former :: EntityToDefinition < __Context, __Formed, __End > for Parent < > - where __End : former :: FormingEnd < ParentFormerDefinitionTypes < __Context, - __Formed > > , - { - type Definition = ParentFormerDefinition < __Context, __Formed, __End > ; - type Types = ParentFormerDefinitionTypes < __Context, __Formed > ; - } impl < __Context, __Formed > former :: EntityToDefinitionTypes < __Context, - __Formed > for Parent < > where - { type Types = ParentFormerDefinitionTypes < __Context, __Formed > ; } - #[derive(Debug)] pub struct ParentFormerDefinitionTypes < __Context = (), - __Formed = Parent < > , > where - { - _phantom : core :: marker :: PhantomData < - (* const __Context, * const __Formed) > , - } impl < __Context, __Formed, > :: core :: default :: Default for - ParentFormerDefinitionTypes < __Context, __Formed, > where - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } impl < __Context, __Formed, > former :: FormerDefinitionTypes for - ParentFormerDefinitionTypes < __Context, __Formed, > where - { - type Storage = ParentFormerStorage < > ; type Formed = __Formed; type - Context = __Context; - } #[derive(Debug)] pub struct ParentFormerDefinition < __Context = (), - __Formed = Parent < > , __End = former :: ReturnPreformed, > where - { - _phantom : core :: marker :: PhantomData < - (* const __Context, * const __Formed, * const __End) > , - } impl < __Context, __Formed, __End, > :: core :: default :: Default for - ParentFormerDefinition < __Context, __Formed, __End, > where - { - fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } impl < __Context, __Formed, __End, > former :: FormerDefinition for - ParentFormerDefinition < __Context, __Formed, __End, > where __End : former :: - FormingEnd < ParentFormerDefinitionTypes < __Context, __Formed, > > , - { - type Types = ParentFormerDefinitionTypes < __Context, __Formed, > ; type - End = __End; type Storage = ParentFormerStorage < > ; type Formed = - __Formed; type Context = __Context; - } impl < __Context, __Formed, > former :: FormerMutator for - ParentFormerDefinitionTypes < __Context, __Formed, > where {} - #[doc = "Container of a corresponding former."] - #[allow(explicit_outlives_requirements)] pub struct ParentFormerStorage < > - where - { - #[doc = r" A field"] pub children : :: core :: option :: Option < Vec < - Child > > , - } impl < > :: core :: default :: Default for ParentFormerStorage < > where - { - #[inline(always)] fn default() -> Self - { Self { children : :: core :: option :: Option :: None, } } - } impl < > former :: Storage for ParentFormerStorage < > where - { type Formed = Parent < > ; } impl < > former :: StoragePreform for - ParentFormerStorage < > where - { - type Preformed = Parent < > ; fn preform(mut self) -> Self :: Preformed - { - let children = if self.children.is_some() - { self.children.take().unwrap() } else - { - { - trait MaybeDefault < T > - { - fn maybe_default(self : & Self) -> T - { panic! ("Field 'children' isn't initialized") } - } impl < T > MaybeDefault < T > for & :: core :: marker :: - PhantomData < T > {} impl < T > MaybeDefault < T > for :: core - :: marker :: PhantomData < T > where T : :: core :: default :: - Default, - { fn maybe_default(self : & Self) -> T { T :: default() } } - (& :: core :: marker :: PhantomData :: < Vec < Child > - >).maybe_default() - } - }; let result = Parent :: < > { children, }; return result; - } - } - #[doc = - "\nStructure to form [Parent]. Represents a forming entity designed to construct objects through a builder pattern.\n\nThis structure holds temporary storage and context during the formation process and\nutilizes a defined end strategy to finalize the object creation. It facilitates the flexible\nconstruction of complex objects by allowing step-by-step configuration.\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] - pub struct ParentFormer < Definition = ParentFormerDefinition < (), Parent < > - , former :: ReturnPreformed > , > where Definition : former :: - FormerDefinition < Storage = ParentFormerStorage < > > , Definition :: Types : - former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , - { - #[doc = - r" Temporary storage for all fields during the formation process. It contains"] - #[doc = - r" partial data that progressively builds up to the final object."] pub - storage : Definition :: Storage, - #[doc = - r" An optional context providing additional data or state necessary for custom"] - #[doc = - r" formation logic or to facilitate this former's role as a subformer within another former."] - pub context : core :: option :: Option < Definition :: Context > , - #[doc = - r" An optional closure or handler that is invoked to transform the accumulated"] - #[doc = - r" temporary storage into the final object structure once formation is complete."] - pub on_end : core :: option :: Option < Definition :: End > , - } #[automatically_derived] impl < Definition, > ParentFormer < Definition, > - where Definition : former :: FormerDefinition < Storage = ParentFormerStorage - < > > , Definition :: Types : former :: FormerDefinitionTypes < Storage = - ParentFormerStorage < > > , - { - #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> - Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] - #[doc = r" Construct new instance of former with default parameters."] - #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > - (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , - { Self :: begin_coercing(None, None, end,) } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn - begin(mut storage : core :: option :: Option < Definition :: Storage > , - context : core :: option :: Option < Definition :: Context > , on_end : < - Definition as former :: FormerDefinition > :: End,) -> Self - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: Some(on_end), - } - } #[doc = r""] - #[doc = - r" Begin the process of forming. Expects context of forming to return it after forming."] - #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > - (mut storage : core :: option :: Option < Definition :: Storage > , - context : core :: option :: Option < Definition :: Context > , on_end : - IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < - Definition as former :: FormerDefinition > :: End > , - { - if storage.is_none() - { storage = Some(:: core :: default :: Default :: default()); } Self - { - storage : storage.unwrap(), context : context, on_end : :: core :: - option :: Option :: - Some(:: core :: convert :: Into :: into(on_end)), - } - } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types - as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] - #[doc = - r" End the process of forming returning original context of forming."] - #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: - Types as former :: FormerDefinitionTypes > :: Formed - { - let on_end = self.on_end.take().unwrap(); let mut context = - self.context.take(); < Definition :: Types as former :: FormerMutator - > :: form_mutation(& mut self.storage, & mut context); former :: - FormingEnd :: < Definition :: Types > :: - call(& on_end, self.storage, context) - } - - #[inline(always)] - pub fn _children_container_former< Former2 >( self ) -> Former2 - where - Former2 : former::FormerBegin - < - < Vec< Child > as former::EntityToDefinition< Self, Self, ParentFormerAssignChildrenEnd< Definition > > >::Definition, >, - < - Vec< Child > as former::EntityToDefinition< Self, Self, ParentFormerAssignChildrenEnd< Definition > > >::Definition - : - former::FormerDefinition< Storage : former::ContainerAdd< Entry = < Vec< Child > as former::Container - >::Entry - >, - Context = ParentFormer< Definition, >, - End = ParentFormerAssignChildrenEnd< Definition >, - >, - { - Former2:: - former_begin( None, Some( self ), ParentFormerAssignChildrenEnd::< Definition >::default() ) - } - - #[inline(always)] - pub fn children(self) -> former :: ContainerSubformer :: - < Child, < Vec < Child > as former :: EntityToDefinition < Self, Self, - ParentFormerAssignChildrenEnd < Definition > > > :: Definition, > where < - Vec < Child > as former :: EntityToDefinition < Self, Self, - ParentFormerAssignChildrenEnd < Definition > > > :: Definition : former :: - FormerDefinition < Storage : former :: ContainerAdd < Entry = < Vec < - Child > as former :: Container > :: Entry > , Context = ParentFormer < - Definition, > , End = ParentFormerAssignChildrenEnd < Definition > , > , - { - self._children_container_former :: < former :: ContainerSubformer :: < - Child, < Vec < Child > as former :: EntityToDefinition < Self, Self, - ParentFormerAssignChildrenEnd < Definition > > > :: Definition, > > () - } - - } impl < Definition, > ParentFormer < Definition, > where Definition : former - :: FormerDefinition < Storage = ParentFormerStorage < > , Formed = Parent < > - > , Definition :: Types : former :: FormerDefinitionTypes < Storage = - ParentFormerStorage < > , Formed = Parent < > > , Definition : former :: - FormerDefinition < Storage = ParentFormerStorage < > > , Definition :: Types : - former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , - { - pub fn preform(self) -> < Definition :: Types as former :: - FormerDefinitionTypes > :: Formed - { former :: StoragePreform :: preform(self.storage) } - } #[automatically_derived] impl < Definition, > ParentFormer < Definition, > - where Definition : former :: FormerDefinition < Storage = ParentFormerStorage - < > , Formed = Parent < > , > , Definition :: Types : former :: - FormerDefinitionTypes < Storage = ParentFormerStorage < > , Formed = Parent < - > , > , - { - #[doc = r""] - #[doc = r" Finish setting options and call perform on formed entity."] - #[doc = r""] - #[doc = - r" If `perform` defined then associated method is called and its result returned instead of entity."] - #[doc = - r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] - #[doc = r""] #[inline(always)] pub fn perform(self) -> Definition :: - Formed { let result = self.form(); return result; } - } impl < Definition > former :: FormerBegin < Definition > for ParentFormer < - Definition, > where Definition : former :: FormerDefinition < Storage = - ParentFormerStorage < > > , - { - #[inline(always)] fn - former_begin(storage : core :: option :: Option < Definition :: Storage > - , context : core :: option :: Option < Definition :: Context > , on_end : - Definition :: End,) -> Self - { - debug_assert! (storage.is_none()); Self :: - begin(None, context, on_end) - } - } - #[doc = - r" Use as subformer of a field during process of forming of super structure."] - pub type ParentAsSubformer < __Superformer, __End > = ParentFormer < - ParentFormerDefinition < __Superformer, __Superformer, __End, > , > ; - #[doc = - "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] - pub trait ParentAsSubformerEnd < SuperFormer > where Self : former :: - FormingEnd < ParentFormerDefinitionTypes < SuperFormer, SuperFormer > , > , {} - impl < SuperFormer, __T > ParentAsSubformerEnd < SuperFormer > for __T where - Self : former :: FormingEnd < ParentFormerDefinitionTypes < SuperFormer, - SuperFormer > , > , {} - #[doc = - "Callback to return original former after forming of container for `$Parent` is done.#\n\n Callback replace content of container assigning new content from subformer's storage."] - pub struct ParentFormerAssignChildrenEnd < Definition > - { _phantom : core :: marker :: PhantomData < (Definition,) > , } impl < - Definition > Default for ParentFormerAssignChildrenEnd < Definition > - { - #[inline(always)] fn default() -> Self - { Self { _phantom : core :: marker :: PhantomData, } } - } - - #[automatically_derived] - impl < Definition, > former :: FormingEnd < < Vec < - Child > as former :: EntityToDefinitionTypes < ParentFormer < Definition, > , - ParentFormer < Definition, > , > > :: Types, > - for - ParentFormerAssignChildrenEnd < Definition > where Definition : former :: - FormerDefinition < Storage = ParentFormerStorage < > > , Definition :: Types : - former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , - { - #[inline(always)] fn - call(& self, storage : Vec < Child > , super_former : Option < - ParentFormer < Definition, > > ,) -> ParentFormer < Definition, > - { - let mut super_former = super_former.unwrap(); if let - Some(ref mut field) = super_former.storage.children - { former :: ContainerAssign :: assign(field, storage); } else - { super_former.storage.children = Some(storage); } super_former - } - } +// // xxx : clean +// +// #[automatically_derived] impl < > Parent < > where +// { +// #[doc = r""] +// #[doc = +// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] +// #[doc = r""] #[inline(always)] pub fn former() -> ParentFormer < +// ParentFormerDefinition < (), Parent < > , former :: ReturnPreformed > > +// { +// ParentFormer :: < ParentFormerDefinition < (), Parent < > , former :: +// ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) +// } +// } impl < Definition > former :: EntityToFormer < Definition > for Parent < > +// where Definition : former :: FormerDefinition < Storage = ParentFormerStorage +// < > > , { type Former = ParentFormer < Definition > ; } impl < > former :: +// EntityToStorage for Parent < > where +// { type Storage = ParentFormerStorage < > ; } impl < __Context, __Formed, __End +// > former :: EntityToDefinition < __Context, __Formed, __End > for Parent < > +// where __End : former :: FormingEnd < ParentFormerDefinitionTypes < __Context, +// __Formed > > , +// { +// type Definition = ParentFormerDefinition < __Context, __Formed, __End > ; +// type Types = ParentFormerDefinitionTypes < __Context, __Formed > ; +// } impl < __Context, __Formed > former :: EntityToDefinitionTypes < __Context, +// __Formed > for Parent < > where +// { type Types = ParentFormerDefinitionTypes < __Context, __Formed > ; } +// #[derive(Debug)] pub struct ParentFormerDefinitionTypes < __Context = (), +// __Formed = Parent < > , > where +// { +// _phantom : core :: marker :: PhantomData < +// (* const __Context, * const __Formed) > , +// } impl < __Context, __Formed, > :: core :: default :: Default for +// ParentFormerDefinitionTypes < __Context, __Formed, > where +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < __Context, __Formed, > former :: FormerDefinitionTypes for +// ParentFormerDefinitionTypes < __Context, __Formed, > where +// { +// type Storage = ParentFormerStorage < > ; type Formed = __Formed; type +// Context = __Context; +// } #[derive(Debug)] pub struct ParentFormerDefinition < __Context = (), +// __Formed = Parent < > , __End = former :: ReturnPreformed, > where +// { +// _phantom : core :: marker :: PhantomData < +// (* const __Context, * const __Formed, * const __End) > , +// } impl < __Context, __Formed, __End, > :: core :: default :: Default for +// ParentFormerDefinition < __Context, __Formed, __End, > where +// { +// fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } impl < __Context, __Formed, __End, > former :: FormerDefinition for +// ParentFormerDefinition < __Context, __Formed, __End, > where __End : former :: +// FormingEnd < ParentFormerDefinitionTypes < __Context, __Formed, > > , +// { +// type Types = ParentFormerDefinitionTypes < __Context, __Formed, > ; type +// End = __End; type Storage = ParentFormerStorage < > ; type Formed = +// __Formed; type Context = __Context; +// } impl < __Context, __Formed, > former :: FormerMutator for +// ParentFormerDefinitionTypes < __Context, __Formed, > where {} +// #[doc = "Container of a corresponding former."] +// #[allow(explicit_outlives_requirements)] pub struct ParentFormerStorage < > +// where +// { +// #[doc = r" A field"] pub children : :: core :: option :: Option < Vec < +// Child > > , +// } impl < > :: core :: default :: Default for ParentFormerStorage < > where +// { +// #[inline(always)] fn default() -> Self +// { Self { children : :: core :: option :: Option :: None, } } +// } impl < > former :: Storage for ParentFormerStorage < > where +// { type Formed = Parent < > ; } impl < > former :: StoragePreform for +// ParentFormerStorage < > where +// { +// type Preformed = Parent < > ; fn preform(mut self) -> Self :: Preformed +// { +// let children = if self.children.is_some() +// { self.children.take().unwrap() } else +// { +// { +// trait MaybeDefault < T > +// { +// fn maybe_default(self : & Self) -> T +// { panic! ("Field 'children' isn't initialized") } +// } impl < T > MaybeDefault < T > for & :: core :: marker :: +// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core +// :: marker :: PhantomData < T > where T : :: core :: default :: +// Default, +// { fn maybe_default(self : & Self) -> T { T :: default() } } +// (& :: core :: marker :: PhantomData :: < Vec < Child > +// >).maybe_default() +// } +// }; let result = Parent :: < > { children, }; return result; +// } +// } +// #[doc = +// "\nStructure to form [Parent]. Represents a forming entity designed to construct objects through a builder pattern.\n\nThis structure holds temporary storage and context during the formation process and\nutilizes a defined end strategy to finalize the object creation. It facilitates the flexible\nconstruction of complex objects by allowing step-by-step configuration.\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] +// pub struct ParentFormer < Definition = ParentFormerDefinition < (), Parent < > +// , former :: ReturnPreformed > , > where Definition : former :: +// FormerDefinition < Storage = ParentFormerStorage < > > , Definition :: Types : +// former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , +// { +// #[doc = +// r" Temporary storage for all fields during the formation process. It contains"] +// #[doc = +// r" partial data that progressively builds up to the final object."] pub +// storage : Definition :: Storage, +// #[doc = +// r" An optional context providing additional data or state necessary for custom"] +// #[doc = +// r" formation logic or to facilitate this former's role as a subformer within another former."] +// pub context : core :: option :: Option < Definition :: Context > , +// #[doc = +// r" An optional closure or handler that is invoked to transform the accumulated"] +// #[doc = +// r" temporary storage into the final object structure once formation is complete."] +// pub on_end : core :: option :: Option < Definition :: End > , +// } #[automatically_derived] impl < Definition, > ParentFormer < Definition, > +// where Definition : former :: FormerDefinition < Storage = ParentFormerStorage +// < > > , Definition :: Types : former :: FormerDefinitionTypes < Storage = +// ParentFormerStorage < > > , +// { +// #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> +// Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] +// #[doc = r" Construct new instance of former with default parameters."] +// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > +// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , +// { Self :: begin_coercing(None, None, end,) } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn +// begin(mut storage : core :: option :: Option < Definition :: Storage > , +// context : core :: option :: Option < Definition :: Context > , on_end : < +// Definition as former :: FormerDefinition > :: End,) -> Self +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: Some(on_end), +// } +// } #[doc = r""] +// #[doc = +// r" Begin the process of forming. Expects context of forming to return it after forming."] +// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > +// (mut storage : core :: option :: Option < Definition :: Storage > , +// context : core :: option :: Option < Definition :: Context > , on_end : +// IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < +// Definition as former :: FormerDefinition > :: End > , +// { +// if storage.is_none() +// { storage = Some(:: core :: default :: Default :: default()); } Self +// { +// storage : storage.unwrap(), context : context, on_end : :: core :: +// option :: Option :: +// Some(:: core :: convert :: Into :: into(on_end)), +// } +// } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types +// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] +// #[doc = +// r" End the process of forming returning original context of forming."] +// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: +// Types as former :: FormerDefinitionTypes > :: Formed +// { +// let on_end = self.on_end.take().unwrap(); let mut context = +// self.context.take(); < Definition :: Types as former :: FormerMutator +// > :: form_mutation(& mut self.storage, & mut context); former :: +// FormingEnd :: < Definition :: Types > :: +// call(& on_end, self.storage, context) +// } +// +// // xxx +// +// #[inline(always)] +// pub fn _children_container_former< Former2 >( self ) -> Former2 +// where +// Former2 : former::FormerBegin +// < +// < +// Vec< Child > as former::EntityToDefinition< Self, Self, ParentFormerAssignChildrenEnd< Definition > > +// > +// ::Definition, +// >, +// < +// Vec< Child > as former::EntityToDefinition +// < +// Self, +// Self, +// ParentFormerAssignChildrenEnd< Definition > +// > +// > +// ::Definition +// : +// former::FormerDefinition +// < +// Storage = Vec< Child >, +// // Storage : former::ContainerAdd +// // < +// // Entry = < Vec< Child > as former::Container >::Entry +// // >, +// Context = ParentFormer< Definition, >, +// End = ParentFormerAssignChildrenEnd< Definition >, +// >, +// { +// Former2::former_begin( None, Some( self ), ParentFormerAssignChildrenEnd::< Definition >::default() ) +// } +// +// // xxx +// +// // #[inline(always)] +// // pub fn children( self ) -> former::ContainerSubformer:: +// // < +// // Child, +// // < Vec< Child > as former::EntityToDefinition< Self, Self, ParentFormerAssignChildrenEnd< Definition > > >::Definition, +// // > +// // where +// // < +// // Vec< Child > as former::EntityToDefinition +// // < +// // Self, +// // Self, +// // ParentFormerAssignChildrenEnd< Definition >, +// // > +// // >::Definition +// // : +// // former::FormerDefinition +// // < +// // Storage : former::ContainerAdd +// // < +// // Entry = < Vec< Child > as former::Container > ::Entry +// // >, +// // Context = ParentFormer< Definition, >, +// // End = ParentFormerAssignChildrenEnd< Definition >, +// // >, +// // // < Vec< Child > as former::EntityToDefinition< Self, Self, ParentFormerAssignChildrenEnd< Definition > > >::Definition : former::FormerDefinition< Storage : former::ContainerAdd< Entry = < Vec< Child > as former::Container >::Entry >, Context = ParentFormer< Definition, >, End = ParentFormerAssignChildrenEnd< Definition >, >, +// // { +// // self._children_container_former:: +// // < +// // former::ContainerSubformer:: +// // < +// // Child, +// // < Vec< Child > as former::EntityToDefinition< Self, Self, ParentFormerAssignChildrenEnd< Definition > > >::Definition, +// // > +// // >() +// // } +// +// } impl < Definition, > ParentFormer < Definition, > where Definition : former +// :: FormerDefinition < Storage = ParentFormerStorage < > , Formed = Parent < > +// > , Definition :: Types : former :: FormerDefinitionTypes < Storage = +// ParentFormerStorage < > , Formed = Parent < > > , Definition : former :: +// FormerDefinition < Storage = ParentFormerStorage < > > , Definition :: Types : +// former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , +// { +// pub fn preform(self) -> < Definition :: Types as former :: +// FormerDefinitionTypes > :: Formed +// { former :: StoragePreform :: preform(self.storage) } +// } #[automatically_derived] impl < Definition, > ParentFormer < Definition, > +// where Definition : former :: FormerDefinition < Storage = ParentFormerStorage +// < > , Formed = Parent < > , > , Definition :: Types : former :: +// FormerDefinitionTypes < Storage = ParentFormerStorage < > , Formed = Parent < +// > , > , +// { +// #[doc = r""] +// #[doc = r" Finish setting options and call perform on formed entity."] +// #[doc = r""] +// #[doc = +// r" If `perform` defined then associated method is called and its result returned instead of entity."] +// #[doc = +// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] +// #[doc = r""] #[inline(always)] pub fn perform(self) -> Definition :: +// Formed { let result = self.form(); return result; } +// } impl < Definition > former :: FormerBegin < Definition > for ParentFormer < +// Definition, > where Definition : former :: FormerDefinition < Storage = +// ParentFormerStorage < > > , +// { +// #[inline(always)] fn +// former_begin(storage : core :: option :: Option < Definition :: Storage > +// , context : core :: option :: Option < Definition :: Context > , on_end : +// Definition :: End,) -> Self +// { +// debug_assert! (storage.is_none()); Self :: +// begin(None, context, on_end) +// } +// } +// #[doc = +// r" Use as subformer of a field during process of forming of super structure."] +// pub type ParentAsSubformer < __Superformer, __End > = ParentFormer < +// ParentFormerDefinition < __Superformer, __Superformer, __End, > , > ; +// #[doc = +// "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] +// pub trait ParentAsSubformerEnd < SuperFormer > where Self : former :: +// FormingEnd < ParentFormerDefinitionTypes < SuperFormer, SuperFormer > , > , {} +// impl < SuperFormer, __T > ParentAsSubformerEnd < SuperFormer > for __T where +// Self : former :: FormingEnd < ParentFormerDefinitionTypes < SuperFormer, +// SuperFormer > , > , {} +// #[doc = +// "Callback to return original former after forming of container for `$Parent` is done.#\n\n Callback replace content of container assigning new content from subformer's storage."] +// pub struct ParentFormerAssignChildrenEnd < Definition > +// { _phantom : core :: marker :: PhantomData < (Definition,) > , } impl < +// Definition > Default for ParentFormerAssignChildrenEnd < Definition > +// { +// #[inline(always)] fn default() -> Self +// { Self { _phantom : core :: marker :: PhantomData, } } +// } +// +// #[automatically_derived] +// impl < Definition, > former :: FormingEnd < < Vec < +// Child > as former :: EntityToDefinitionTypes < ParentFormer < Definition, > , +// ParentFormer < Definition, > , > > :: Types, > +// for +// ParentFormerAssignChildrenEnd < Definition > where Definition : former :: +// FormerDefinition < Storage = ParentFormerStorage < > > , Definition :: Types : +// former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , +// { +// #[inline(always)] fn +// call(& self, storage : Vec < Child > , super_former : Option < +// ParentFormer < Definition, > > ,) -> ParentFormer < Definition, > +// { +// let mut super_former = super_former.unwrap(); if let +// Some(ref mut field) = super_former.storage.children +// { former :: ContainerAssign :: assign(field, storage); } else +// { super_former.storage.children = Some(storage); } super_former +// } +// } // == end of generated include!( "./only_test/subformer_container.rs" ); + +// xxx \ No newline at end of file diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 9103106f40..de2f9cf4bd 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -61,21 +61,21 @@ mod former_tests mod parametrized_field; mod parametrized_field_where; -// #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -// mod subformer_basic; -// + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + mod subformer_basic; + #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_container; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_container_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_implicit; // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_container_implicit; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container_setter_off; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container_named; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_container_custom; + // mod subformer_container_setter_off; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_container_named; + // #[ cfg( any( not( feature = "no_std" ) ) ) ] + // mod subformer_container_custom; // #[ cfg( any( not( feature = "no_std" ) ) ) ] // mod subformer_subform; diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 0a22e48a9a..a0414e7d81 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -646,7 +646,9 @@ where >, #subformer_definition : former::FormerDefinition < - Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, + // Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, + // Storage : former::Container< Entry = < #typ as former::Container >::Entry >, + Storage = #typ, Context = #former< #former_generics_ty >, End = #former_assign_end< Definition >, >, @@ -705,9 +707,9 @@ where where #subformer_definition : former::FormerDefinition < - Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, + // Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, + Storage = #typ, Context = #former< #former_generics_ty >, - // Context = Struct1Former< Definition >, End = #former_assign_end < Definition >, >, { @@ -771,9 +773,9 @@ where where #subformer_definition : former::FormerDefinition < - Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, + // Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, + Storage = #typ, Context = #former< #former_generics_ty >, - // Context = Struct1Former< Definition >, End = #former_assign_end < Definition >, >, { From 6acd96bf9a712123ab3e7cb1be9afd91a82e5eca Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 18:52:34 +0300 Subject: [PATCH 490/533] former : types problem --- module/core/former/tests/inc/mod.rs | 58 ++++++++++++++--------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index de2f9cf4bd..e5467bb3c5 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -70,35 +70,35 @@ mod former_tests mod subformer_container_manual; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_container_implicit; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_container_setter_off; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_container_named; - // #[ cfg( any( not( feature = "no_std" ) ) ) ] - // mod subformer_container_custom; - -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_manual; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_named; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_named_manual; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_setter_off; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_setter_on; -// -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_hashmap; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_hashmap_custom; -// -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_and_container; -// #[ cfg( any( not( feature = "no_std" ) ) ) ] -// mod subformer_subform_and_container_parametrized; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_setter_off; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_named; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_custom; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_named; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_named_manual; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_setter_off; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_setter_on; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_hashmap; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_hashmap_custom; + + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_and_container; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_subform_and_container_parametrized; // xxx From 7ef9c35292ed1066347a71d6450697e9a422d096 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 19:02:09 +0300 Subject: [PATCH 491/533] former : types problem --- .../subformer_container_implicit.rs | 333 ------------------ .../former_meta/src/derive_former/field.rs | 20 +- 2 files changed, 13 insertions(+), 340 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs index 38369ba208..b332563d53 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs @@ -23,339 +23,6 @@ pub struct Parent // == begin of generated -// // xxx : clean -// -// #[automatically_derived] impl < > Parent < > where -// { -// #[doc = r""] -// #[doc = -// r" Make former, variation of builder pattern to form structure defining values of fields step by step."] -// #[doc = r""] #[inline(always)] pub fn former() -> ParentFormer < -// ParentFormerDefinition < (), Parent < > , former :: ReturnPreformed > > -// { -// ParentFormer :: < ParentFormerDefinition < (), Parent < > , former :: -// ReturnPreformed > > :: new_coercing(former :: ReturnPreformed) -// } -// } impl < Definition > former :: EntityToFormer < Definition > for Parent < > -// where Definition : former :: FormerDefinition < Storage = ParentFormerStorage -// < > > , { type Former = ParentFormer < Definition > ; } impl < > former :: -// EntityToStorage for Parent < > where -// { type Storage = ParentFormerStorage < > ; } impl < __Context, __Formed, __End -// > former :: EntityToDefinition < __Context, __Formed, __End > for Parent < > -// where __End : former :: FormingEnd < ParentFormerDefinitionTypes < __Context, -// __Formed > > , -// { -// type Definition = ParentFormerDefinition < __Context, __Formed, __End > ; -// type Types = ParentFormerDefinitionTypes < __Context, __Formed > ; -// } impl < __Context, __Formed > former :: EntityToDefinitionTypes < __Context, -// __Formed > for Parent < > where -// { type Types = ParentFormerDefinitionTypes < __Context, __Formed > ; } -// #[derive(Debug)] pub struct ParentFormerDefinitionTypes < __Context = (), -// __Formed = Parent < > , > where -// { -// _phantom : core :: marker :: PhantomData < -// (* const __Context, * const __Formed) > , -// } impl < __Context, __Formed, > :: core :: default :: Default for -// ParentFormerDefinitionTypes < __Context, __Formed, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, > former :: FormerDefinitionTypes for -// ParentFormerDefinitionTypes < __Context, __Formed, > where -// { -// type Storage = ParentFormerStorage < > ; type Formed = __Formed; type -// Context = __Context; -// } #[derive(Debug)] pub struct ParentFormerDefinition < __Context = (), -// __Formed = Parent < > , __End = former :: ReturnPreformed, > where -// { -// _phantom : core :: marker :: PhantomData < -// (* const __Context, * const __Formed, * const __End) > , -// } impl < __Context, __Formed, __End, > :: core :: default :: Default for -// ParentFormerDefinition < __Context, __Formed, __End, > where -// { -// fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } impl < __Context, __Formed, __End, > former :: FormerDefinition for -// ParentFormerDefinition < __Context, __Formed, __End, > where __End : former :: -// FormingEnd < ParentFormerDefinitionTypes < __Context, __Formed, > > , -// { -// type Types = ParentFormerDefinitionTypes < __Context, __Formed, > ; type -// End = __End; type Storage = ParentFormerStorage < > ; type Formed = -// __Formed; type Context = __Context; -// } impl < __Context, __Formed, > former :: FormerMutator for -// ParentFormerDefinitionTypes < __Context, __Formed, > where {} -// #[doc = "Container of a corresponding former."] -// #[allow(explicit_outlives_requirements)] pub struct ParentFormerStorage < > -// where -// { -// #[doc = r" A field"] pub children : :: core :: option :: Option < Vec < -// Child > > , -// } impl < > :: core :: default :: Default for ParentFormerStorage < > where -// { -// #[inline(always)] fn default() -> Self -// { Self { children : :: core :: option :: Option :: None, } } -// } impl < > former :: Storage for ParentFormerStorage < > where -// { type Formed = Parent < > ; } impl < > former :: StoragePreform for -// ParentFormerStorage < > where -// { -// type Preformed = Parent < > ; fn preform(mut self) -> Self :: Preformed -// { -// let children = if self.children.is_some() -// { self.children.take().unwrap() } else -// { -// { -// trait MaybeDefault < T > -// { -// fn maybe_default(self : & Self) -> T -// { panic! ("Field 'children' isn't initialized") } -// } impl < T > MaybeDefault < T > for & :: core :: marker :: -// PhantomData < T > {} impl < T > MaybeDefault < T > for :: core -// :: marker :: PhantomData < T > where T : :: core :: default :: -// Default, -// { fn maybe_default(self : & Self) -> T { T :: default() } } -// (& :: core :: marker :: PhantomData :: < Vec < Child > -// >).maybe_default() -// } -// }; let result = Parent :: < > { children, }; return result; -// } -// } -// #[doc = -// "\nStructure to form [Parent]. Represents a forming entity designed to construct objects through a builder pattern.\n\nThis structure holds temporary storage and context during the formation process and\nutilizes a defined end strategy to finalize the object creation. It facilitates the flexible\nconstruction of complex objects by allowing step-by-step configuration.\n```\n\nuse former::Former;\n#[ derive( Former ) ]\npub struct Struct1\n{\n #[default( 31 ) ]\n field1 : i32,\n}\n\n```\n"] -// pub struct ParentFormer < Definition = ParentFormerDefinition < (), Parent < > -// , former :: ReturnPreformed > , > where Definition : former :: -// FormerDefinition < Storage = ParentFormerStorage < > > , Definition :: Types : -// former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , -// { -// #[doc = -// r" Temporary storage for all fields during the formation process. It contains"] -// #[doc = -// r" partial data that progressively builds up to the final object."] pub -// storage : Definition :: Storage, -// #[doc = -// r" An optional context providing additional data or state necessary for custom"] -// #[doc = -// r" formation logic or to facilitate this former's role as a subformer within another former."] -// pub context : core :: option :: Option < Definition :: Context > , -// #[doc = -// r" An optional closure or handler that is invoked to transform the accumulated"] -// #[doc = -// r" temporary storage into the final object structure once formation is complete."] -// pub on_end : core :: option :: Option < Definition :: End > , -// } #[automatically_derived] impl < Definition, > ParentFormer < Definition, > -// where Definition : former :: FormerDefinition < Storage = ParentFormerStorage -// < > > , Definition :: Types : former :: FormerDefinitionTypes < Storage = -// ParentFormerStorage < > > , -// { -// #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new(on_end : Definition :: End) -> -// Self { Self :: begin_coercing(None, None, on_end) } #[doc = r""] -// #[doc = r" Construct new instance of former with default parameters."] -// #[doc = r""] #[inline(always)] pub fn new_coercing < IntoEnd > -// (end : IntoEnd) -> Self where IntoEnd : Into < Definition :: End > , -// { Self :: begin_coercing(None, None, end,) } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn -// begin(mut storage : core :: option :: Option < Definition :: Storage > , -// context : core :: option :: Option < Definition :: Context > , on_end : < -// Definition as former :: FormerDefinition > :: End,) -> Self -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: Some(on_end), -// } -// } #[doc = r""] -// #[doc = -// r" Begin the process of forming. Expects context of forming to return it after forming."] -// #[doc = r""] #[inline(always)] pub fn begin_coercing < IntoEnd > -// (mut storage : core :: option :: Option < Definition :: Storage > , -// context : core :: option :: Option < Definition :: Context > , on_end : -// IntoEnd,) -> Self where IntoEnd : :: core :: convert :: Into < < -// Definition as former :: FormerDefinition > :: End > , -// { -// if storage.is_none() -// { storage = Some(:: core :: default :: Default :: default()); } Self -// { -// storage : storage.unwrap(), context : context, on_end : :: core :: -// option :: Option :: -// Some(:: core :: convert :: Into :: into(on_end)), -// } -// } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn form(self) -> < Definition :: Types -// as former :: FormerDefinitionTypes > :: Formed { self.end() } #[doc = r""] -// #[doc = -// r" End the process of forming returning original context of forming."] -// #[doc = r""] #[inline(always)] pub fn end(mut self) -> < Definition :: -// Types as former :: FormerDefinitionTypes > :: Formed -// { -// let on_end = self.on_end.take().unwrap(); let mut context = -// self.context.take(); < Definition :: Types as former :: FormerMutator -// > :: form_mutation(& mut self.storage, & mut context); former :: -// FormingEnd :: < Definition :: Types > :: -// call(& on_end, self.storage, context) -// } -// -// // xxx -// -// #[inline(always)] -// pub fn _children_container_former< Former2 >( self ) -> Former2 -// where -// Former2 : former::FormerBegin -// < -// < -// Vec< Child > as former::EntityToDefinition< Self, Self, ParentFormerAssignChildrenEnd< Definition > > -// > -// ::Definition, -// >, -// < -// Vec< Child > as former::EntityToDefinition -// < -// Self, -// Self, -// ParentFormerAssignChildrenEnd< Definition > -// > -// > -// ::Definition -// : -// former::FormerDefinition -// < -// Storage = Vec< Child >, -// // Storage : former::ContainerAdd -// // < -// // Entry = < Vec< Child > as former::Container >::Entry -// // >, -// Context = ParentFormer< Definition, >, -// End = ParentFormerAssignChildrenEnd< Definition >, -// >, -// { -// Former2::former_begin( None, Some( self ), ParentFormerAssignChildrenEnd::< Definition >::default() ) -// } -// -// // xxx -// -// // #[inline(always)] -// // pub fn children( self ) -> former::ContainerSubformer:: -// // < -// // Child, -// // < Vec< Child > as former::EntityToDefinition< Self, Self, ParentFormerAssignChildrenEnd< Definition > > >::Definition, -// // > -// // where -// // < -// // Vec< Child > as former::EntityToDefinition -// // < -// // Self, -// // Self, -// // ParentFormerAssignChildrenEnd< Definition >, -// // > -// // >::Definition -// // : -// // former::FormerDefinition -// // < -// // Storage : former::ContainerAdd -// // < -// // Entry = < Vec< Child > as former::Container > ::Entry -// // >, -// // Context = ParentFormer< Definition, >, -// // End = ParentFormerAssignChildrenEnd< Definition >, -// // >, -// // // < Vec< Child > as former::EntityToDefinition< Self, Self, ParentFormerAssignChildrenEnd< Definition > > >::Definition : former::FormerDefinition< Storage : former::ContainerAdd< Entry = < Vec< Child > as former::Container >::Entry >, Context = ParentFormer< Definition, >, End = ParentFormerAssignChildrenEnd< Definition >, >, -// // { -// // self._children_container_former:: -// // < -// // former::ContainerSubformer:: -// // < -// // Child, -// // < Vec< Child > as former::EntityToDefinition< Self, Self, ParentFormerAssignChildrenEnd< Definition > > >::Definition, -// // > -// // >() -// // } -// -// } impl < Definition, > ParentFormer < Definition, > where Definition : former -// :: FormerDefinition < Storage = ParentFormerStorage < > , Formed = Parent < > -// > , Definition :: Types : former :: FormerDefinitionTypes < Storage = -// ParentFormerStorage < > , Formed = Parent < > > , Definition : former :: -// FormerDefinition < Storage = ParentFormerStorage < > > , Definition :: Types : -// former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , -// { -// pub fn preform(self) -> < Definition :: Types as former :: -// FormerDefinitionTypes > :: Formed -// { former :: StoragePreform :: preform(self.storage) } -// } #[automatically_derived] impl < Definition, > ParentFormer < Definition, > -// where Definition : former :: FormerDefinition < Storage = ParentFormerStorage -// < > , Formed = Parent < > , > , Definition :: Types : former :: -// FormerDefinitionTypes < Storage = ParentFormerStorage < > , Formed = Parent < -// > , > , -// { -// #[doc = r""] -// #[doc = r" Finish setting options and call perform on formed entity."] -// #[doc = r""] -// #[doc = -// r" If `perform` defined then associated method is called and its result returned instead of entity."] -// #[doc = -// r" For example `perform()` of structure with : `#[ perform( fn after1() -> &str > )` returns `&str`."] -// #[doc = r""] #[inline(always)] pub fn perform(self) -> Definition :: -// Formed { let result = self.form(); return result; } -// } impl < Definition > former :: FormerBegin < Definition > for ParentFormer < -// Definition, > where Definition : former :: FormerDefinition < Storage = -// ParentFormerStorage < > > , -// { -// #[inline(always)] fn -// former_begin(storage : core :: option :: Option < Definition :: Storage > -// , context : core :: option :: Option < Definition :: Context > , on_end : -// Definition :: End,) -> Self -// { -// debug_assert! (storage.is_none()); Self :: -// begin(None, context, on_end) -// } -// } -// #[doc = -// r" Use as subformer of a field during process of forming of super structure."] -// pub type ParentAsSubformer < __Superformer, __End > = ParentFormer < -// ParentFormerDefinition < __Superformer, __Superformer, __End, > , > ; -// #[doc = -// "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure."] -// pub trait ParentAsSubformerEnd < SuperFormer > where Self : former :: -// FormingEnd < ParentFormerDefinitionTypes < SuperFormer, SuperFormer > , > , {} -// impl < SuperFormer, __T > ParentAsSubformerEnd < SuperFormer > for __T where -// Self : former :: FormingEnd < ParentFormerDefinitionTypes < SuperFormer, -// SuperFormer > , > , {} -// #[doc = -// "Callback to return original former after forming of container for `$Parent` is done.#\n\n Callback replace content of container assigning new content from subformer's storage."] -// pub struct ParentFormerAssignChildrenEnd < Definition > -// { _phantom : core :: marker :: PhantomData < (Definition,) > , } impl < -// Definition > Default for ParentFormerAssignChildrenEnd < Definition > -// { -// #[inline(always)] fn default() -> Self -// { Self { _phantom : core :: marker :: PhantomData, } } -// } -// -// #[automatically_derived] -// impl < Definition, > former :: FormingEnd < < Vec < -// Child > as former :: EntityToDefinitionTypes < ParentFormer < Definition, > , -// ParentFormer < Definition, > , > > :: Types, > -// for -// ParentFormerAssignChildrenEnd < Definition > where Definition : former :: -// FormerDefinition < Storage = ParentFormerStorage < > > , Definition :: Types : -// former :: FormerDefinitionTypes < Storage = ParentFormerStorage < > > , -// { -// #[inline(always)] fn -// call(& self, storage : Vec < Child > , super_former : Option < -// ParentFormer < Definition, > > ,) -> ParentFormer < Definition, > -// { -// let mut super_former = super_former.unwrap(); if let -// Some(ref mut field) = super_former.storage.children -// { former :: ContainerAssign :: assign(field, storage); } else -// { super_former.storage.children = Some(storage); } super_former -// } -// } - // == end of generated include!( "./only_test/subformer_container.rs" ); - -// xxx \ No newline at end of file diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index a0414e7d81..e5915a7938 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -701,8 +701,9 @@ where #[ inline( always ) ] pub fn #setter_name( self ) -> former::ContainerSubformer:: < - ( #( #params, )* ), - #subformer_definition, + // ( #( #params, )* ), + < #typ as former::Container >::Entry, + #subformer_definition, > where #subformer_definition : former::FormerDefinition @@ -715,8 +716,10 @@ where { self.#field_assign::< former::ContainerSubformer:: < - ( #( #params, )* ), - #subformer_definition, + _, + _, + // ( #( #params, )* ), + // #subformer_definition, > > () } @@ -767,7 +770,8 @@ where #[ inline( always ) ] pub fn #setter_name( self ) -> former::ContainerSubformer:: < - #( #params, )* // xxx : use former::Container + < #typ as former::Container >::Entry, + // #( #params, )* // xxx : use former::Container #subformer_definition, > where @@ -781,8 +785,10 @@ where { self.#field_assign::< former::ContainerSubformer:: < - #( #params, )* // xxx : use former::Container - #subformer_definition, + _, + _, + // #( #params, )* // xxx : use former::Container + // #subformer_definition, > > () } From d6fe49bac49f7d9cba2d41dd4638480b9a99b2ea Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 19:07:18 +0300 Subject: [PATCH 492/533] former : types problem --- .../former_meta/src/derive_former/field.rs | 150 +++++++++--------- 1 file changed, 76 insertions(+), 74 deletions(-) diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index e5915a7938..f209df2580 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -678,8 +678,9 @@ where let setter_name = self.container_setter_name(); let setter2 = if let Some( setter_name ) = setter_name { - if params.len() > 1 - { + // xxx : remove if + // if params.len() > 1 + // { qt! { @@ -745,83 +746,83 @@ where // } } - } - else - { - qt! - { - - // xxx : clean - // #[ doc = #doc ] - // #[ inline( always ) ] - // pub fn #setter_name( self ) -> - // former::ContainerSubformer:: - // < - // #( #params, )* #subformer_definition - // > - // { - // self.#field_assign::< former::ContainerSubformer:: - // < - // #( #params, )* #subformer_definition - // > >() - // } - - #[ doc = #doc ] - #[ inline( always ) ] - pub fn #setter_name( self ) -> former::ContainerSubformer:: - < - < #typ as former::Container >::Entry, - // #( #params, )* // xxx : use former::Container - #subformer_definition, - > - where - #subformer_definition : former::FormerDefinition - < - // Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, - Storage = #typ, - Context = #former< #former_generics_ty >, - End = #former_assign_end < Definition >, - >, - { - self.#field_assign::< former::ContainerSubformer:: - < - _, - _, - // #( #params, )* // xxx : use former::Container - // #subformer_definition, - > > () - } - - // #[ inline( always ) ] - // pub fn hashset_1( self ) -> former::ContainerSubformer:: - // < - // String, - // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, - // > - // where - // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > > : former::FormerDefinition - // < - // Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, - // Context = Struct1Former< Definition >, - // End = Struct1FormerAssignHashset1End< Definition >, - // >, - // { - // self._hashset_1_assign::< former::ContainerSubformer:: - // < - // String, - // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, - // > > () - // } - - } - } +// } +// else +// { +// qt! +// { +// +// // xxx : clean +// // #[ doc = #doc ] +// // #[ inline( always ) ] +// // pub fn #setter_name( self ) -> +// // former::ContainerSubformer:: +// // < +// // #( #params, )* #subformer_definition +// // > +// // { +// // self.#field_assign::< former::ContainerSubformer:: +// // < +// // #( #params, )* #subformer_definition +// // > >() +// // } +// +// #[ doc = #doc ] +// #[ inline( always ) ] +// pub fn #setter_name( self ) -> former::ContainerSubformer:: +// < +// < #typ as former::Container >::Entry, +// // #( #params, )* // xxx : use former::Container +// #subformer_definition, +// > +// where +// #subformer_definition : former::FormerDefinition +// < +// // Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, +// Storage = #typ, +// Context = #former< #former_generics_ty >, +// End = #former_assign_end < Definition >, +// >, +// { +// self.#field_assign::< former::ContainerSubformer:: +// < +// _, +// _, +// // #( #params, )* // xxx : use former::Container +// // #subformer_definition, +// > > () +// } +// +// // #[ inline( always ) ] +// // pub fn hashset_1( self ) -> former::ContainerSubformer:: +// // < +// // String, +// // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, +// // > +// // where +// // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > > : former::FormerDefinition +// // < +// // Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, +// // Context = Struct1Former< Definition >, +// // End = Struct1FormerAssignHashset1End< Definition >, +// // >, +// // { +// // self._hashset_1_assign::< former::ContainerSubformer:: +// // < +// // String, +// // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, +// // > > () +// // } +// +// } +// } } else { qt!{} }; - // xxx : update + // xxx2 : update if attr.hint { let hint = format! @@ -842,7 +843,7 @@ where // Replace `HashMapDefinition` with definition for your container > {{ - self._children_container_former() + self.{}() }} }} @@ -854,6 +855,7 @@ where format!( "{}", qt!{ #( #params, )* } ), format!( "{}", qt!{ #( #params, )* } ), former_assign_end, + field_assign, ); println!( "{hint}" ); } From b726e7f1238ae5467f5f7271d94bb2e8ecf8416e Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 22:02:43 +0300 Subject: [PATCH 493/533] former : cleaning and documentation --- .../a_containers_with_subformer_manual.rs | 92 --- module/core/former_meta/src/derive_former.rs | 35 +- .../former_meta/src/derive_former/field.rs | 722 +++++++++--------- 3 files changed, 400 insertions(+), 449 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs index 452c4ddef0..5b2455661f 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs @@ -339,26 +339,6 @@ where former::FormingEnd::::call(&on_end, self.storage, context) } -// #[ inline( always ) ] -// pub fn _vec_1_assign(self) -> Former2 -// where -// Former2 : former::FormerBegin,>>, -// { -// Former2::former_begin(None, Some(self), Struct1FormerAssignVec1End::::default()) -// } -// -// -// #[ inline( always ) ] -// pub fn vec_1(self) -> former::ContainerSubformer::< -// String, -// former::VectorDefinition,> -// > -// { -// self._vec_1_assign::,>>> () -// } - - // xxx : clean - #[ inline( always ) ] pub fn _vec_1_assign< Former2 >( self ) -> Former2 where @@ -405,29 +385,6 @@ where > > () } -// xxx : clean -// #[ inline( always ) ] -// pub fn _hashmap_1_assign(self) -> Former2 -// where -// Former2 : former::FormerBegin,>>, -// { -// Former2::former_begin(None, Some(self), Struct1FormerAssignHashmap1End::::default()) -// } -// -// -// #[ inline( always ) ] -// pub fn hashmap_1(self) -> former::ContainerSubformer:: -// < -// (String, String,), -// former::HashMapDefinition,> -// > -// { -// self._hashmap_1_assign::,> -// >> () -// } - #[ inline( always ) ] pub fn _hashmap_1_assign< Former2 >( self ) -> Former2 where @@ -474,8 +431,6 @@ where > > () } -// xxx - #[ inline( always ) ] pub fn _hashset_1_assign< Former2 >( self ) -> Former2 where @@ -624,29 +579,6 @@ where } } -// xxx : clean -// #[automatically_derived] -// impl former::FormingEnd< former::VectorDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignVec1End -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, -// { -// #[ inline( always ) ] -// fn call(&self, storage: Vec, super_former: Option>,) -> Struct1Former -// { -// let mut super_former = super_former.unwrap(); -// if let Some(ref mut field) = super_former.storage.vec_1 -// { -// former::ContainerAssign::assign(field, storage); -// } -// else -// { -// super_former.storage.vec_1 = Some(storage); -// } -// super_former -// } -// } - pub struct Struct1FormerAssignHashmap1End { _phantom : core::marker::PhantomData<(Definition,)>, @@ -688,29 +620,6 @@ where } } -// xxx : clean -// #[automatically_derived] -// impl former::FormingEnd< former::HashMapDefinition, Struct1Former, former::NoEnd>, > for Struct1FormerAssignHashmap1End -// where -// Definition : former::FormerDefinition, -// Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage<> >, -// { -// #[ inline( always ) ] -// fn call(&self, storage: collection_tools::HashMap, super_former: Option>,) -> Struct1Former -// { -// let mut super_former = super_former.unwrap(); -// if let Some(ref mut field) = super_former.storage.hashmap_1 -// { -// former::ContainerAssign::assign(field, storage); -// } -// else -// { -// super_former.storage.hashmap_1 = Some(storage); -// } -// super_former -// } -// } - #[doc = "Callback to return original former after forming of container for `$Struct1` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] pub struct Struct1FormerAssignHashset1End @@ -757,4 +666,3 @@ where // == end of generated include!( "./only_test/containers_with_subformer.rs" ); -// xxx diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 3f92df83bf..1de1bf7820 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -206,11 +206,11 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > storage_field_name, storage_field_preform, former_field_setter, - former_assign_end, + // former_assign_end, former_add_end, ) : - ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) + ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) = formed_fields .iter() .chain( storage_fields.iter() ) @@ -221,21 +221,23 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field.storage_field_name(), field.storage_field_preform(), field.former_field_setter - ( - &stru, - &former, - &former_storage, - &former_generics_ty, - ), - // xxx : move maybe - field.former_assign_end ( &stru, &former, &former_generics_impl, &former_generics_ty, &former_generics_where, + &former_storage, ), + // // xxx : move maybe + // field.former_assign_end + // ( + // &stru, + // &former, + // &former_generics_impl, + // &former_generics_ty, + // &former_generics_where, + // ), field.former_add_end ( &stru, @@ -247,9 +249,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > ), )}).multiunzip(); - let former_field_setter : Vec< _ > = process_results( former_field_setter, | iter | iter.collect() )?; + // let former_field_setter : Vec< _ > = process_results( former_field_setter, | iter | iter.collect() )?; + let ( former_field_setter, namespace_code ) : ( Vec< _ >, Vec< _ > ) + = former_field_setter.into_iter().process_results( | iter | iter.collect::< Vec< _ > >() )?.into_iter().unzip(); + let storage_field_preform : Vec< _ > = process_results( storage_field_preform, | iter | iter.collect() )?; - let former_assign_end : Vec< _ > = process_results( former_assign_end, | iter | iter.collect() )?; + // let former_assign_end : Vec< _ > = process_results( former_assign_end, | iter | iter.collect() )?; let former_add_end : Vec< _ > = process_results( former_add_end, | iter | iter.collect() )?; // xxx : move to a function @@ -743,8 +748,12 @@ where // = container assign callbacks + // #( + // #former_assign_end + // )* + #( - #former_assign_end + #namespace_code )* // = container add callbacks diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index f209df2580..67738edab6 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -35,8 +35,8 @@ storage_field_name former_field_setter subform_setter container_setter +// former_assign_end scalar_setter -former_assign_end former_add_end scalar_setter_name @@ -344,60 +344,58 @@ scalar_setter_required &self, stru : &syn::Ident, former : &syn::Ident, - former_storage : &syn::Ident, + former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, + former_storage : &syn::Ident, ) - -> Result< TokenStream > + -> Result< ( TokenStream, TokenStream ) > { - let r = self.scalar_setter + let namespace_code = qt! {}; + let setters_code = self.scalar_setter ( former, former_storage, ); // container setter - let r = if let Some( _ ) = &self.attrs.container + let ( setters_code, namespace_code ) = if let Some( _ ) = &self.attrs.container { - let r2 = self.container_setter + let ( setters_code2, namespace_code2 ) = self.container_setter ( stru, former, - former_storage, + former_generics_impl, former_generics_ty, - ); - qt! - { - #r - #r2 - } + former_generics_where, + former_storage, + )?; + ( qt! { #setters_code #setters_code2 }, qt! { #namespace_code #namespace_code2 } ) } else { - r + ( setters_code, namespace_code ) }; // subform setter - let r = if self.attrs.subform.is_some() + let ( setters_code, namespace_code ) = if self.attrs.subform.is_some() { - let r2 = self.subform_setter + let setters_code2 = self.subform_setter ( stru, former, former_storage, )?; - qt! - { - #r - #r2 - } + ( qt! { #setters_code #setters_code2 }, namespace_code ) } else { - r + ( setters_code, namespace_code ) }; // tree_print!( r.as_ref().unwrap() ); - Ok( r ) + // Ok( r ) + Ok( ( setters_code, namespace_code ) ) } /// zzz : write documentation @@ -563,21 +561,33 @@ where /// ``` /// zzz : update example +// pub fn former_assign_end +// ( +// &self, +// stru : &syn::Ident, +// former : &syn::Ident, +// former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, +// former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, +// former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, +// ) + #[ inline ] pub fn container_setter ( &self, stru : &syn::Ident, former : &syn::Ident, - former_storage : &syn::Ident, + former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, + former_storage : &syn::Ident, ) - -> TokenStream + -> Result< ( TokenStream, TokenStream ) > { let attr = self.attrs.container.as_ref().unwrap(); let field_ident = &self.ident; - let typ = &self.non_optional_ty; - let params = typ::type_parameters( &typ, .. ); + let field_typ = &self.non_optional_ty; + let params = typ::type_parameters( &field_typ, .. ); use convert_case::{ Case, Casing }; let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); @@ -606,7 +616,7 @@ where qt! { < - #typ as former::EntityToDefinition< Self, Self, #former_assign_end< Definition > > + #field_typ as former::EntityToDefinition< Self, Self, #former_assign_end< Definition > > >::Definition } // < Vec< String > as former::EntityToDefinition< Self, Self, Struct1FormerAssignVec1End > >::Definition @@ -624,18 +634,6 @@ where qt! { - // #[ doc = #doc ] - // #[ inline( always ) ] - // pub fn #field_assign< Former2 >( self ) -> Former2 - // where - // Former2 : former::FormerBegin - // < - // #subformer_definition - // >, - // { - // Former2::former_begin( None, Some( self ), #former_assign_end::< Definition >::default() ) - // } - #[ doc = #doc ] #[ inline( always ) ] pub fn #field_assign< Former2 >( self ) -> Former2 @@ -646,9 +644,8 @@ where >, #subformer_definition : former::FormerDefinition < - // Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, - // Storage : former::Container< Entry = < #typ as former::Container >::Entry >, - Storage = #typ, + // Storage : former::ContainerAdd< Entry = < #field_typ as former::Container >::Entry >, + Storage = #field_typ, Context = #former< #former_generics_ty >, End = #former_assign_end< Definition >, >, @@ -678,144 +675,57 @@ where let setter_name = self.container_setter_name(); let setter2 = if let Some( setter_name ) = setter_name { - // xxx : remove if - // if params.len() > 1 - // { - qt! - { + qt! + { - // #[ doc = #doc ] - // #[ inline( always ) ] - // pub fn #setter_name( self ) -> - // former::ContainerSubformer:: - // < - // ( #( #params, )* ), #subformer_definition - // > - // { - // self.#field_assign::< former::ContainerSubformer:: - // < - // ( #( #params, )* ), #subformer_definition - // > >() - // } - - #[ doc = #doc ] - #[ inline( always ) ] - pub fn #setter_name( self ) -> former::ContainerSubformer:: + #[ doc = #doc ] + #[ inline( always ) ] + pub fn #setter_name( self ) -> former::ContainerSubformer:: + < + // ( #( #params, )* ), + < #field_typ as former::Container >::Entry, + #subformer_definition, + > + where + #subformer_definition : former::FormerDefinition + < + // Storage : former::ContainerAdd< Entry = < #field_typ as former::Container >::Entry >, + Storage = #field_typ, + Context = #former< #former_generics_ty >, + End = #former_assign_end < Definition >, + >, + { + self.#field_assign::< former::ContainerSubformer:: < + _, + _, // ( #( #params, )* ), - < #typ as former::Container >::Entry, - #subformer_definition, - > - where - #subformer_definition : former::FormerDefinition - < - // Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, - Storage = #typ, - Context = #former< #former_generics_ty >, - End = #former_assign_end < Definition >, - >, - { - self.#field_assign::< former::ContainerSubformer:: - < - _, - _, - // ( #( #params, )* ), - // #subformer_definition, - > > () - } + // #subformer_definition, + > > () + } - // #[ inline( always ) ] - // pub fn hashset_1( self ) -> former::ContainerSubformer:: - // < - // String, - // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, - // > - // where - // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > > : former::FormerDefinition - // < - // Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, - // Context = Struct1Former< Definition >, - // End = Struct1FormerAssignHashset1End< Definition >, - // >, - // { - // self._hashset_1_assign::< former::ContainerSubformer:: - // < - // String, - // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, - // > > () - // } + // #[ inline( always ) ] + // pub fn hashset_1( self ) -> former::ContainerSubformer:: + // < + // String, + // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, + // > + // where + // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > > : former::FormerDefinition + // < + // Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, + // Context = Struct1Former< Definition >, + // End = Struct1FormerAssignHashset1End< Definition >, + // >, + // { + // self._hashset_1_assign::< former::ContainerSubformer:: + // < + // String, + // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, + // > > () + // } - } -// } -// else -// { -// qt! -// { -// -// // xxx : clean -// // #[ doc = #doc ] -// // #[ inline( always ) ] -// // pub fn #setter_name( self ) -> -// // former::ContainerSubformer:: -// // < -// // #( #params, )* #subformer_definition -// // > -// // { -// // self.#field_assign::< former::ContainerSubformer:: -// // < -// // #( #params, )* #subformer_definition -// // > >() -// // } -// -// #[ doc = #doc ] -// #[ inline( always ) ] -// pub fn #setter_name( self ) -> former::ContainerSubformer:: -// < -// < #typ as former::Container >::Entry, -// // #( #params, )* // xxx : use former::Container -// #subformer_definition, -// > -// where -// #subformer_definition : former::FormerDefinition -// < -// // Storage : former::ContainerAdd< Entry = < #typ as former::Container >::Entry >, -// Storage = #typ, -// Context = #former< #former_generics_ty >, -// End = #former_assign_end < Definition >, -// >, -// { -// self.#field_assign::< former::ContainerSubformer:: -// < -// _, -// _, -// // #( #params, )* // xxx : use former::Container -// // #subformer_definition, -// > > () -// } -// -// // #[ inline( always ) ] -// // pub fn hashset_1( self ) -> former::ContainerSubformer:: -// // < -// // String, -// // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, -// // > -// // where -// // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > > : former::FormerDefinition -// // < -// // Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, -// // Context = Struct1Former< Definition >, -// // End = Struct1FormerAssignHashset1End< Definition >, -// // >, -// // { -// // self._hashset_1_assign::< former::ContainerSubformer:: -// // < -// // String, -// // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, -// // > > () -// // } -// -// } -// } + } } else { @@ -860,174 +770,27 @@ where println!( "{hint}" ); } - qt! + let setters_code = qt! { #setter1 #setter2 - } - - } - - /// - /// Generate a single scalar setter for the 'field_ident' with the 'setter_name' name. - /// - /// Used as a helper function for former_field_setter(), which generates alias setters - /// - /// # Example of generated code - /// ```ignore - /// #[ doc = "Setter for the 'int_1' field." ] - /// #[ inline ] - /// pub fn int_1< Src >( mut self, src : Src ) -> Self - /// where - /// Src : ::core::convert::Into< i32 >, - /// { - /// debug_assert!( self.int_1.is_none() ); - /// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); - /// self - /// } - /// ``` - - #[ inline ] - pub fn scalar_setter - ( - &self, - former : &syn::Ident, - former_storage : &syn::Ident, - ) - -> TokenStream - { - let field_ident = self.ident; - let typ = self.non_optional_ty; - let setter_name = self.scalar_setter_name(); - let attr = self.attrs.scalar.as_ref(); - - if attr.is_some() && attr.unwrap().hint - { - let hint = format! - ( - r#" - -impl< Definition > {}< Definition > -where - Definition : former::FormerDefinition< Storage = {} >, -{{ - #[ inline ] - pub fn {}< Src >( mut self, src : Src ) -> Self - where - Src : ::core::convert::Into< {} >, - {{ - debug_assert!( self.storage.{}.is_none() ); - self.storage.{} = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); - self - }} -}} - - "#, - former, - former_storage, - field_ident, - format!( "{}", qt!{ #typ } ), - field_ident, - field_ident, - ); - println!( "{hint}" ); - } - - if !self.scalar_setter_required() - { - return qt! {}; - } - - let doc = format! - ( - "Setter for the '{}' field.", - field_ident, - ); - - qt! - { - #[ doc = #doc ] - #[ inline ] - pub fn #setter_name< Src >( mut self, src : Src ) -> Self - where - Src : ::core::convert::Into< #typ >, - { - debug_assert!( self.storage.#field_ident.is_none() ); - self.storage.#field_ident = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); - self - } - } - } - - // zzz : description and exmaple - /// Generate unit struct which is descriptor of callback which should be called after subforming process of a specific field. Childs are used insted of closures to inline code and let optimizer play with optimization. - /// - /// # Example of generated code - /// - /// ```rust, ignore - /// pub struct Struct1FormerVec_1End; - /// #[ automatically_derived ] - /// impl< Definition > former::FormingEnd - /// < - /// former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, - /// > - /// for Struct1FormerVec_1End - /// where - /// Definition : former::FormerDefinition, - /// Definition::Types : former::FormerDefinitionTypes - /// < - /// Storage = Struct1FormerStorage - /// >, - /// { - /// #[ inline( always ) ] - /// pub 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 - /// { - /// former::ContainerAssign::assign( field, storage ); - /// } - /// else - /// { - /// super_former.storage.vec_1 = Some( storage ); - /// } - /// super_former - /// } - /// } - /// ``` + }; - #[ inline ] - pub fn former_assign_end - ( - &self, - stru : &syn::Ident, - former : &syn::Ident, - former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - ) - -> - Result< TokenStream > - { + // xxx - if self.attrs.container.is_none() - { - return Ok( qt!{ } ); - } + // if self.attrs.container.is_none() + // { + // return Ok( qt!{ } ); + // } - use convert_case::{ Case, Casing }; - let field_ident = self.ident; - let field_ty = self.non_optional_ty; - let params = typ::type_parameters( field_ty, .. ); + // use convert_case::{ Case, Casing }; + // let field_ident = self.ident; + // let field_typ = self.non_optional_ty; + // let params = typ::type_parameters( field_typ, .. ); - // example : `ParentFormerAssignChildsEnd`` - let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); - let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); + // // example : `ParentFormerAssignChildsEnd`` + // let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); + // let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); // example : `former::VectorDefinition`` let subformer_definition = &self.attrs.container.as_ref().unwrap().definition; @@ -1055,10 +818,8 @@ where #( #params, )* #former< #former_generics_ty >, #former< #former_generics_ty >, - // former::NoEnd, > } - // former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, > > } else { @@ -1066,14 +827,13 @@ where qt! { < - #field_ty as former::EntityToDefinitionTypes + #field_typ as former::EntityToDefinitionTypes < #former< #former_generics_ty >, #former< #former_generics_ty >, > >::Types } - // < Vec< String > as former::EntityToDefinition< Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd > >::Definition }; let r = qt! @@ -1105,7 +865,6 @@ where impl< #former_generics_impl > former::FormingEnd < // VectorDefinitionTypes - // #subformer_definition, #subformer_definition_types, > for #former_assign_end< Definition > @@ -1116,7 +875,7 @@ where fn call ( &self, - storage : #field_ty, + storage : #field_typ, super_former : Option< #former< #former_generics_ty > >, ) -> #former< #former_generics_ty > @@ -1137,11 +896,286 @@ where }; // tree_print!( r.as_ref().unwrap() ); - Ok( r ) + let namespace_code = r; + + Ok( ( setters_code, namespace_code ) ) + } + +// // zzz : description and exmaple +// /// Generate unit struct which is descriptor of callback which should be called after subforming process of a specific field. Childs are used insted of closures to inline code and let optimizer play with optimization. +// /// +// /// # Example of generated code +// /// +// /// ```rust, ignore +// /// pub struct Struct1FormerVec_1End; +// /// #[ automatically_derived ] +// /// impl< Definition > former::FormingEnd +// /// < +// /// former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, +// /// > +// /// for Struct1FormerVec_1End +// /// where +// /// Definition : former::FormerDefinition, +// /// Definition::Types : former::FormerDefinitionTypes +// /// < +// /// Storage = Struct1FormerStorage +// /// >, +// /// { +// /// #[ inline( always ) ] +// /// pub 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 +// /// { +// /// former::ContainerAssign::assign( field, storage ); +// /// } +// /// else +// /// { +// /// super_former.storage.vec_1 = Some( storage ); +// /// } +// /// super_former +// /// } +// /// } +// /// ``` +// +// #[ inline ] +// pub fn former_assign_end +// ( +// &self, +// stru : &syn::Ident, +// former : &syn::Ident, +// former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, +// former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, +// former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, +// ) +// -> +// Result< TokenStream > +// { +// +// if self.attrs.container.is_none() +// { +// return Ok( qt!{ } ); +// } +// +// use convert_case::{ Case, Casing }; +// let field_ident = self.ident; +// let field_ty = self.non_optional_ty; +// let params = typ::type_parameters( field_ty, .. ); +// +// // example : `ParentFormerAssignChildsEnd`` +// let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); +// let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); +// +// // example : `former::VectorDefinition`` +// let subformer_definition = &self.attrs.container.as_ref().unwrap().definition; +// +// // zzz : improve description +// let former_assign_end_doc = format! +// ( +// r#"Callback to return original former after forming of container for `${stru}` is done.# +// +// Callback replace content of container assigning new content from subformer's storage."# +// ); +// +// let subformer_definition_types = if let Some( ref _subformer_definition ) = subformer_definition +// { +// // let subformer_definition_types_name = format!( "{}Types", qt!{ #subformer_definition } ); +// // dbg!( &subformer_definition_types_name ); +// // let subformer_definition_types = syn::Ident::new( &subformer_definition_types_name, field_ident.span() ); +// let subformer_definition_types_string = format!( "{}Types", qt!{ #subformer_definition } ); +// // let subformer_definition_types : syn::Type = subformer_definition_types_string.parse()? +// let subformer_definition_types : syn::Type = syn::parse_str( &subformer_definition_types_string )?; +// qt! +// { +// #subformer_definition_types +// < +// #( #params, )* +// #former< #former_generics_ty >, +// #former< #former_generics_ty >, +// // former::NoEnd, +// > +// } +// // former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, > > +// } +// else +// { +// +// qt! +// { +// < +// #field_ty as former::EntityToDefinitionTypes +// < +// #former< #former_generics_ty >, +// #former< #former_generics_ty >, +// > +// >::Types +// } +// // < Vec< String > as former::EntityToDefinition< Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd > >::Definition +// }; +// +// let r = qt! +// { +// +// // zzz : improve description +// #[ doc = #former_assign_end_doc ] +// pub struct #former_assign_end< Definition > +// { +// _phantom : core::marker::PhantomData< ( Definition, ) >, +// } +// +// impl< Definition > Default +// for #former_assign_end< Definition > +// { +// +// #[ inline( always ) ] +// fn default() -> Self +// { +// Self +// { +// _phantom : core::marker::PhantomData, +// } +// } +// +// } +// +// #[ automatically_derived ] +// impl< #former_generics_impl > former::FormingEnd +// < +// // VectorDefinitionTypes +// // #subformer_definition, +// #subformer_definition_types, +// > +// for #former_assign_end< Definition > +// where +// #former_generics_where +// { +// #[ inline( always ) ] +// fn call +// ( +// &self, +// storage : #field_ty, +// super_former : Option< #former< #former_generics_ty > >, +// ) +// -> #former< #former_generics_ty > +// { +// let mut super_former = super_former.unwrap(); +// if let Some( ref mut field ) = super_former.storage.#field_ident +// { +// former::ContainerAssign::assign( field, storage ); +// } +// else +// { +// super_former.storage.#field_ident = Some( storage ); +// } +// super_former +// } +// } +// +// }; +// +// // tree_print!( r.as_ref().unwrap() ); +// Ok( r ) +// } + + /// + /// Generate a single scalar setter for the 'field_ident' with the 'setter_name' name. + /// + /// Used as a helper function for former_field_setter(), which generates alias setters + /// + /// # Example of generated code + /// ```ignore + /// #[ doc = "Setter for the 'int_1' field." ] + /// #[ inline ] + /// pub fn int_1< Src >( mut self, src : Src ) -> Self + /// where + /// Src : ::core::convert::Into< i32 >, + /// { + /// debug_assert!( self.int_1.is_none() ); + /// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + /// self + /// } + /// ``` + + #[ inline ] + pub fn scalar_setter + ( + &self, + former : &syn::Ident, + former_storage : &syn::Ident, + ) + -> TokenStream + { + let field_ident = self.ident; + let typ = self.non_optional_ty; + let setter_name = self.scalar_setter_name(); + let attr = self.attrs.scalar.as_ref(); + + if attr.is_some() && attr.unwrap().hint + { + let hint = format! + ( + r#" + +impl< Definition > {}< Definition > +where + Definition : former::FormerDefinition< Storage = {} >, +{{ + #[ inline ] + pub fn {}< Src >( mut self, src : Src ) -> Self + where + Src : ::core::convert::Into< {} >, + {{ + debug_assert!( self.storage.{}.is_none() ); + self.storage.{} = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + self + }} +}} + + "#, + former, + former_storage, + field_ident, + format!( "{}", qt!{ #typ } ), + field_ident, + field_ident, + ); + println!( "{hint}" ); + } + + if !self.scalar_setter_required() + { + return qt! {}; + } + + let doc = format! + ( + "Setter for the '{}' field.", + field_ident, + ); + + qt! + { + #[ doc = #doc ] + #[ inline ] + pub fn #setter_name< Src >( mut self, src : Src ) -> Self + where + Src : ::core::convert::Into< #typ >, + { + debug_assert!( self.storage.#field_ident.is_none() ); + self.storage.#field_ident = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); + self + } + } } /// zzz : write documentation + // xxx : move #[ inline ] pub fn former_add_end ( From 9ecd2c4753a2d6fde543d1b2f6371b7e076bdb27 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 7 May 2024 23:28:56 +0300 Subject: [PATCH 494/533] former : cleaning and documentation --- module/core/former/Readme.md | 2 + .../former_custom_container_setter.rs | 2 +- .../examples/former_subformer_hashmap.rs | 2 + .../examples/former_subformer_hashset.rs | 1 + .../examples/former_subformer_vector.rs | 1 + ...ners_with_subformer.rs => a_containers.rs} | 0 ...ormer_manual.rs => a_containers_manual.rs} | 2 - ...ut_subformer.rs => a_containers_scalar.rs} | 0 .../inc/former_tests/a_primitives_manual.rs | 2 - module/core/former/tests/inc/mod.rs | 6 +- module/core/former_meta/src/derive_former.rs | 150 +++--- .../former_meta/src/derive_former/field.rs | 510 ++++-------------- 12 files changed, 206 insertions(+), 472 deletions(-) rename module/core/former/tests/inc/former_tests/{a_containers_with_subformer.rs => a_containers.rs} (100%) rename module/core/former/tests/inc/former_tests/{a_containers_with_subformer_manual.rs => a_containers_manual.rs} (99%) rename module/core/former/tests/inc/former_tests/{a_containers_without_subformer.rs => a_containers_scalar.rs} (100%) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index e8d51ca8c2..dcc5a132e9 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -671,6 +671,7 @@ fn main() .form(); assert_eq!( instance, StructWithVec { vec: vec![ "apple", "banana" ] } ); + dbg!( instance ); } ``` @@ -726,6 +727,7 @@ fn main() .form(); assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] }); + dbg!( instance ); } ``` diff --git a/module/core/former/examples/former_custom_container_setter.rs b/module/core/former/examples/former_custom_container_setter.rs index 381b047377..f2668bcfe8 100644 --- a/module/core/former/examples/former_custom_container_setter.rs +++ b/module/core/former/examples/former_custom_container_setter.rs @@ -42,7 +42,7 @@ fn main() pub struct Parent { // Use `hint = true` to gennerate sketch of setter. - #[ container( setter = false, hint = false ) ] + #[ container( setter = false, hint = true ) ] children : HashMap< String, Child >, } diff --git a/module/core/former/examples/former_subformer_hashmap.rs b/module/core/former/examples/former_subformer_hashmap.rs index 78472c52ce..aa0a0836e1 100644 --- a/module/core/former/examples/former_subformer_hashmap.rs +++ b/module/core/former/examples/former_subformer_hashmap.rs @@ -23,4 +23,6 @@ fn main() .form() ; assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); + dbg!( instance ); + } diff --git a/module/core/former/examples/former_subformer_hashset.rs b/module/core/former/examples/former_subformer_hashset.rs index 3bf8a65d89..92ee6889e8 100644 --- a/module/core/former/examples/former_subformer_hashset.rs +++ b/module/core/former/examples/former_subformer_hashset.rs @@ -23,5 +23,6 @@ fn main() .form(); assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] }); + dbg!( instance ); } diff --git a/module/core/former/examples/former_subformer_vector.rs b/module/core/former/examples/former_subformer_vector.rs index 8719c1155c..4bdf6e91d5 100644 --- a/module/core/former/examples/former_subformer_vector.rs +++ b/module/core/former/examples/former_subformer_vector.rs @@ -24,5 +24,6 @@ fn main() .form(); assert_eq!( instance, StructWithVec { vec: vec![ "apple", "banana" ] } ); + dbg!( instance ); } diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers.rs similarity index 100% rename from module/core/former/tests/inc/former_tests/a_containers_with_subformer.rs rename to module/core/former/tests/inc/former_tests/a_containers.rs diff --git a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_manual.rs similarity index 99% rename from module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs rename to module/core/former/tests/inc/former_tests/a_containers_manual.rs index 5b2455661f..c5f7350a3b 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_with_subformer_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_manual.rs @@ -620,8 +620,6 @@ where } } -#[doc = -"Callback to return original former after forming of container for `$Struct1` is done.#\n\nCallback replace content of container assigning new content from subformer's storage."] pub struct Struct1FormerAssignHashset1End { _phantom : core::marker::PhantomData<(Definition,)>, diff --git a/module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs b/module/core/former/tests/inc/former_tests/a_containers_scalar.rs similarity index 100% rename from module/core/former/tests/inc/former_tests/a_containers_without_subformer.rs rename to module/core/former/tests/inc/former_tests/a_containers_scalar.rs diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 35778dd7bf..f28e97ea81 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -316,12 +316,10 @@ where Definition::Storage : former::StoragePreform, Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage, Formed = Struct1 >, { - pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { former::StoragePreform::preform( self.storage ) } - } // diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index e5467bb3c5..4accf5c331 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -21,11 +21,11 @@ mod former_tests mod a_primitives_manual; mod a_primitives; - mod a_containers_without_subformer; + mod a_containers_scalar; #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer_manual; + mod a_containers_manual; #[ cfg( not( feature = "no_std" ) ) ] - mod a_containers_with_subformer; + mod a_containers; mod attribute_default_container; mod attribute_default_primitive; diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 1de1bf7820..6029048e35 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -14,6 +14,66 @@ use field_attrs::*; mod struct_attrs; use struct_attrs::*; +/// xxx : write documentation and example of generated code + +pub fn mutator +( + mutator : &AttributeMutator, + // stru : &syn::Ident, + former_definition_types : &syn::Ident, + former_definition_types_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + former_definition_types_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + former_definition_types_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, +) +-> Result< TokenStream > +{ + let former_mutator_code = if mutator.custom + { + qt!{} + } + else + { + qt! + { + impl< #former_definition_types_generics_impl > former::FormerMutator + for #former_definition_types < #former_definition_types_generics_ty > + where + #former_definition_types_generics_where + { + } + } + }; + + if mutator.hint + { + let hint = format! + ( + r#" += Example of custom mutator + +impl< {} > former::FormerMutator +for {} < {} > +where + {} +{{ + /// Mutates the context and storage of the entity just before the formation process completes. + #[ inline ] + fn form_mutation( storage : &mut Self::Storage, context : &mut Option< Self::Context > ) + {{ + }} +}} + "#, + format!( "{}", qt!{ #former_definition_types_generics_impl } ), + former_definition_types, + format!( "{}", qt!{ #former_definition_types_generics_ty } ), + format!( "{}", qt!{ #former_definition_types_generics_where } ), + ); + println!( "{hint}" ); + }; + + Ok( former_mutator_code ) +} + /// /// Generate documentation for the former. /// @@ -206,11 +266,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > storage_field_name, storage_field_preform, former_field_setter, - // former_assign_end, - former_add_end, ) : - ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) + ( Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ >, Vec< _ > ) = formed_fields .iter() .chain( storage_fields.iter() ) @@ -223,84 +281,30 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > field.former_field_setter ( &stru, + &struct_generics_impl, + &struct_generics_ty, + &struct_generics_where, &former, &former_generics_impl, &former_generics_ty, &former_generics_where, &former_storage, ), - // // xxx : move maybe - // field.former_assign_end - // ( - // &stru, - // &former, - // &former_generics_impl, - // &former_generics_ty, - // &former_generics_where, - // ), - field.former_add_end - ( - &stru, - &former, - &former_generics_ty, - &struct_generics_impl, - &struct_generics_ty, - &struct_generics_where, - ), )}).multiunzip(); - // let former_field_setter : Vec< _ > = process_results( former_field_setter, | iter | iter.collect() )?; - let ( former_field_setter, namespace_code ) : ( Vec< _ >, Vec< _ > ) - = former_field_setter.into_iter().process_results( | iter | iter.collect::< Vec< _ > >() )?.into_iter().unzip(); + let results : Result< Vec< _ > > = former_field_setter.into_iter().collect(); + let ( former_field_setter, namespace_code ) : ( Vec< _ >, Vec< _ > ) = results?.into_iter().unzip(); let storage_field_preform : Vec< _ > = process_results( storage_field_preform, | iter | iter.collect() )?; - // let former_assign_end : Vec< _ > = process_results( former_assign_end, | iter | iter.collect() )?; - let former_add_end : Vec< _ > = process_results( former_add_end, | iter | iter.collect() )?; - - // xxx : move to a function - let former_mutator_code = if struct_attrs.mutator.custom - { - qt!{} - } - else - { - qt! - { - impl< #former_definition_types_generics_impl > former::FormerMutator - for #former_definition_types < #former_definition_types_generics_ty > - where - #former_definition_types_generics_where - { - } - } - }; - - if struct_attrs.mutator.hint - { - let hint = format! - ( - r#" - = Example of custom mutator -impl< {} > former::FormerMutator -for {} < {} > -where - {} -{{ - /// Mutates the context and storage of the entity just before the formation process completes. - #[ inline ] - fn form_mutation( storage : &mut Self::Storage, context : &mut Option< Self::Context > ) - {{ - }} -}} - "#, - format!( "{}", qt!{ #former_definition_types_generics_impl } ), - former_definition_types, - format!( "{}", qt!{ #former_definition_types_generics_ty } ), - format!( "{}", qt!{ #former_definition_types_generics_where } ), - ); - println!( "{hint}" ); - }; + let former_mutator_code = mutator + ( + &struct_attrs.mutator, + &former_definition_types, + &former_definition_types_generics_impl, + &former_definition_types_generics_ty, + &former_definition_types_generics_where, + )?; let result = qt! { @@ -758,9 +762,9 @@ where // = container add callbacks - #( - #former_add_end - )* + // #( + // #former_add_end + // )* // } /* end of namespace */ // pub use #former_namespace :: *; diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 67738edab6..b87aee92df 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -35,9 +35,7 @@ storage_field_name former_field_setter subform_setter container_setter -// former_assign_end scalar_setter -former_add_end scalar_setter_name container_setter_name @@ -310,39 +308,15 @@ scalar_setter_required /// /// Generate a former setter for the field. /// - /// If aliases provided, also generate aliases - /// - /// # Example of generated code - /// - /// ```ignore - /// #[ doc = "Setter for the 'int_1' field." ] - /// #[ inline ] - /// pub fn int_1< Src >( mut self, src : Src ) -> Self - /// where - /// Src : ::core::convert::Into< i32 >, - /// { - /// debug_assert!( self.int_1.is_none() ); - /// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); - /// self - /// } - /// - /// /// #[ doc = "Setter for the 'int_1' field." ] - /// #[ inline ] - /// pub fn int_1_alias< Src >( mut self, src : Src ) -> Self - /// where - /// Src : ::core::convert::Into< i32 >, - /// { - /// debug_assert!( self.int_1.is_none() ); - /// self.storage.int_1 = ::core::option::Option::Some( ::core::convert::Into::into( src ) ); - /// self - /// } - /// ``` #[ inline ] pub fn former_field_setter ( &self, stru : &syn::Ident, + struct_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + struct_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, former : &syn::Ident, former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, @@ -365,10 +339,10 @@ scalar_setter_required ( stru, former, + former_storage, former_generics_impl, former_generics_ty, former_generics_where, - former_storage, )?; ( qt! { #setters_code #setters_code2 }, qt! { #namespace_code #namespace_code2 } ) } @@ -380,25 +354,36 @@ scalar_setter_required // subform setter let ( setters_code, namespace_code ) = if self.attrs.subform.is_some() { - let setters_code2 = self.subform_setter + let ( setters_code2, namespace_code2 ) = self.subform_setter ( stru, former, former_storage, + former_generics_ty, + struct_generics_impl, + struct_generics_ty, + struct_generics_where, )?; - ( qt! { #setters_code #setters_code2 }, namespace_code ) + ( qt! { #setters_code #setters_code2 }, qt! { #namespace_code #namespace_code2 } ) } else { ( setters_code, namespace_code ) }; - // tree_print!( r.as_ref().unwrap() ); - // Ok( r ) + // tree_print!( setters_code.as_ref().unwrap() ); Ok( ( setters_code, namespace_code ) ) } - /// zzz : write documentation + /// Generates setter functions for subforms within a container structure in a builder pattern. + /// + /// This function is a key component of the `former` crate's capability to dynamically create setters for manipulating + /// data within a nested container structure like a `HashMap` or a `Vec`. The setters facilitate the addition or + /// modification of entries within the container, directly from the parent former's context. + /// + /// See `examples/subformer_subform_manual.rs` for example of generated code. + /// + #[ inline ] pub fn subform_setter ( @@ -406,18 +391,22 @@ scalar_setter_required stru : &syn::Ident, former : &syn::Ident, former_storage : &syn::Ident, + former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + struct_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, + struct_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, ) - -> Result< TokenStream > + -> Result< ( TokenStream, TokenStream ) > { - if self.attrs.subform.is_none() - { - return Ok( qt!{ } ); - } + // if self.attrs.subform.is_none() + // { + // return Ok( qt!{ } ); + // } use convert_case::{ Case, Casing }; let field_ident = self.ident; - let field_ty = self.non_optional_ty; + let field_typ = self.non_optional_ty; let attr = self.attrs.subform.as_ref().unwrap(); // let params = typ::type_parameters( &self.non_optional_ty, .. ); @@ -432,7 +421,7 @@ scalar_setter_required let field_add_name = format!( "_{}_add", field_ident ); let field_add = syn::Ident::new( &field_add_name, field_ident.span() ); - let r = qt! + let setters_code = qt! { // zzz : improve documentation @@ -443,13 +432,13 @@ scalar_setter_required Definition2 : former::FormerDefinition < End = #former_add_end< Definition >, - Storage = < < #field_ty as former::Container >::Val as former::EntityToStorage >::Storage, + Storage = < < #field_typ as former::Container >::Val as former::EntityToStorage >::Storage, Formed = Self, Context = Self, >, Definition2::Types : former::FormerDefinitionTypes < - Storage = < < #field_ty as former::Container >::Val as former::EntityToStorage >::Storage, + Storage = < < #field_typ as former::Container >::Val as former::EntityToStorage >::Storage, Formed = Self, Context = Self, >, @@ -494,25 +483,25 @@ where println!( "{hint}" ); } - let r = if attr.setter() + let setters_code = if attr.setter() { qt! { - #r + #setters_code #[ inline( always ) ] pub fn #setter_name( self ) -> - < < #field_ty as former::Container >::Val as former::EntityToFormer + < < #field_typ as former::Container >::Val as former::EntityToFormer < < - < #field_ty as former::Container >::Val as former::EntityToDefinition< Self, Self, #former_add_end < Definition > > + < #field_typ as former::Container >::Val as former::EntityToDefinition< Self, Self, #former_add_end < Definition > > >::Definition, > >::Former // #as_subformer< Self, impl #as_subformer_end< Self > > { self.#field_add - ::< < < #field_ty as former::Container >::Val as former::EntityToFormer< _ > >::Former, _, >() + ::< < < #field_typ as former::Container >::Val as former::EntityToFormer< _ > >::Former, _, >() // ::< #former< _ >, _, >() } } @@ -528,48 +517,84 @@ where } else { - r + setters_code }; - // tree_print!( r.as_ref().unwrap() ); - Ok( r ) + let namespace_code = qt! + { + + // zzz : improve description + /// Handles the completion of an element of subformer's container. + pub struct #former_add_end< Definition > + { + _phantom : core::marker::PhantomData< fn( Definition ) >, + } + + impl< Definition > Default + for #former_add_end< Definition > + { + #[ inline( always ) ] + fn default() -> Self + { + Self + { + _phantom : core::marker::PhantomData, + } + } + } + + impl< #struct_generics_impl Types2, Definition > former::FormingEnd< Types2, > + for #former_add_end< Definition > + where + Definition : former::FormerDefinition + < + Storage = < #stru < #struct_generics_ty > as former::EntityToStorage >::Storage, + >, + Types2 : former::FormerDefinitionTypes + < + Storage = < < #field_typ as former::Container >::Val as former::EntityToStorage >::Storage, + Formed = #former< #former_generics_ty >, + Context = #former< #former_generics_ty >, + >, + #struct_generics_where + { + #[ inline( always ) ] + fn call + ( + &self, + substorage : Types2::Storage, + super_former : core::option::Option< Types2::Context >, + ) + -> Types2::Formed + { + let mut super_former = super_former.unwrap(); + if super_former.storage.#field_ident.is_none() + { + super_former.storage.#field_ident = Some( Default::default() ); + } + if let Some( ref mut field ) = super_former.storage.#field_ident + { + former::ContainerAdd::add + ( + field, + < < #field_typ as former::Container >::Val as former::ValToEntry< #field_typ > > + ::val_to_entry( former::StoragePreform::preform( substorage ) ), + ); + } + super_former + } + } + + }; + + // tree_print!( setters_code.as_ref().unwrap() ); + Ok( ( setters_code, namespace_code ) ) } /// /// Generate a container setter for the 'field_ident' with the 'setter_name' name. /// - /// # Example of generated code - /// - /// ```ignore - /// pub fn hashmap_strings_1( mut self ) -> former::HashMapSubformer - /// < - /// String, - /// String, - /// std::collections::HashMap< String, String >, - /// Struct1Former, - /// impl Fn( std::collections::HashMap< String, String >, core::option::Option< Self > ) -> Self - /// > - /// { - /// let formed = self.hashmap_strings_1.take(); - /// let on_end = | formed : std::collections::HashMap< String, String >, mut former : core::option::Option< Self > | -> Self - /// { - /// former.hashmap_strings_1 = Some( formed ); - /// former - /// }; - /// former::HashMapSubformer::begin_coercing( formed, self, on_end ) - /// } - /// ``` - /// zzz : update example - -// pub fn former_assign_end -// ( -// &self, -// stru : &syn::Ident, -// former : &syn::Ident, -// former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, -// former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, -// former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, -// ) + /// See `examples/subformer_container_manual.rs` for example of generated code. #[ inline ] pub fn container_setter @@ -577,10 +602,10 @@ where &self, stru : &syn::Ident, former : &syn::Ident, + former_storage : &syn::Ident, former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - former_storage : &syn::Ident, ) -> Result< ( TokenStream, TokenStream ) > { @@ -732,7 +757,6 @@ where qt!{} }; - // xxx2 : update if attr.hint { let hint = format! @@ -740,6 +764,7 @@ where r#" /// The containr setter provides a container setter that returns a ContainerSubformer tailored for managing a collection of child entities. It employs a generic container definition to facilitate operations on the entire collection, such as adding or updating elements. + impl< Definition, > {}< Definition, > where Definition : former::FormerDefinition< Storage = {} >, @@ -776,31 +801,19 @@ where #setter2 }; - // xxx - - // if self.attrs.container.is_none() - // { - // return Ok( qt!{ } ); - // } - - // use convert_case::{ Case, Casing }; - // let field_ident = self.ident; - // let field_typ = self.non_optional_ty; - // let params = typ::type_parameters( field_typ, .. ); - - // // example : `ParentFormerAssignChildsEnd`` - // let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); - // let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); - // example : `former::VectorDefinition`` let subformer_definition = &self.attrs.container.as_ref().unwrap().definition; - // zzz : improve description let former_assign_end_doc = format! ( - r#"Callback to return original former after forming of container for `${stru}` is done.# - - Callback replace content of container assigning new content from subformer's storage."# + r#" +A callback structure to manage the final stage of forming a `{0}` for the `{stru}` container. + +This callback is used to integrate the contents of a temporary `{0}` back into the original `{stru}` former +after the subforming process is completed. It replaces the existing content of the `{field_ident}` field in `{stru}` +with the new content generated during the subforming process. + "#, + format!( "{}", qt!{ #field_typ } ), ); let subformer_definition_types = if let Some( ref _subformer_definition ) = subformer_definition @@ -901,187 +914,6 @@ where Ok( ( setters_code, namespace_code ) ) } -// // zzz : description and exmaple -// /// Generate unit struct which is descriptor of callback which should be called after subforming process of a specific field. Childs are used insted of closures to inline code and let optimizer play with optimization. -// /// -// /// # Example of generated code -// /// -// /// ```rust, ignore -// /// pub struct Struct1FormerVec_1End; -// /// #[ automatically_derived ] -// /// impl< Definition > former::FormingEnd -// /// < -// /// former::VectorDefinition< String, Struct1Former< Definition >, Struct1Former< Definition >, former::NoEnd >, -// /// > -// /// for Struct1FormerVec_1End -// /// where -// /// Definition : former::FormerDefinition, -// /// Definition::Types : former::FormerDefinitionTypes -// /// < -// /// Storage = Struct1FormerStorage -// /// >, -// /// { -// /// #[ inline( always ) ] -// /// pub 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 -// /// { -// /// former::ContainerAssign::assign( field, storage ); -// /// } -// /// else -// /// { -// /// super_former.storage.vec_1 = Some( storage ); -// /// } -// /// super_former -// /// } -// /// } -// /// ``` -// -// #[ inline ] -// pub fn former_assign_end -// ( -// &self, -// stru : &syn::Ident, -// former : &syn::Ident, -// former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, -// former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, -// former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, -// ) -// -> -// Result< TokenStream > -// { -// -// if self.attrs.container.is_none() -// { -// return Ok( qt!{ } ); -// } -// -// use convert_case::{ Case, Casing }; -// let field_ident = self.ident; -// let field_ty = self.non_optional_ty; -// let params = typ::type_parameters( field_ty, .. ); -// -// // example : `ParentFormerAssignChildsEnd`` -// let former_assign_end_name = format!( "{}FormerAssign{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); -// let former_assign_end = syn::Ident::new( &former_assign_end_name, field_ident.span() ); -// -// // example : `former::VectorDefinition`` -// let subformer_definition = &self.attrs.container.as_ref().unwrap().definition; -// -// // zzz : improve description -// let former_assign_end_doc = format! -// ( -// r#"Callback to return original former after forming of container for `${stru}` is done.# -// -// Callback replace content of container assigning new content from subformer's storage."# -// ); -// -// let subformer_definition_types = if let Some( ref _subformer_definition ) = subformer_definition -// { -// // let subformer_definition_types_name = format!( "{}Types", qt!{ #subformer_definition } ); -// // dbg!( &subformer_definition_types_name ); -// // let subformer_definition_types = syn::Ident::new( &subformer_definition_types_name, field_ident.span() ); -// let subformer_definition_types_string = format!( "{}Types", qt!{ #subformer_definition } ); -// // let subformer_definition_types : syn::Type = subformer_definition_types_string.parse()? -// let subformer_definition_types : syn::Type = syn::parse_str( &subformer_definition_types_string )?; -// qt! -// { -// #subformer_definition_types -// < -// #( #params, )* -// #former< #former_generics_ty >, -// #former< #former_generics_ty >, -// // former::NoEnd, -// > -// } -// // former::VectorDefinition< String, Struct1Former< Definition, >, Struct1Former< Definition, > > -// } -// else -// { -// -// qt! -// { -// < -// #field_ty as former::EntityToDefinitionTypes -// < -// #former< #former_generics_ty >, -// #former< #former_generics_ty >, -// > -// >::Types -// } -// // < Vec< String > as former::EntityToDefinition< Struct1Former< Definition, >, Struct1Former< Definition, >, former::NoEnd > >::Definition -// }; -// -// let r = qt! -// { -// -// // zzz : improve description -// #[ doc = #former_assign_end_doc ] -// pub struct #former_assign_end< Definition > -// { -// _phantom : core::marker::PhantomData< ( Definition, ) >, -// } -// -// impl< Definition > Default -// for #former_assign_end< Definition > -// { -// -// #[ inline( always ) ] -// fn default() -> Self -// { -// Self -// { -// _phantom : core::marker::PhantomData, -// } -// } -// -// } -// -// #[ automatically_derived ] -// impl< #former_generics_impl > former::FormingEnd -// < -// // VectorDefinitionTypes -// // #subformer_definition, -// #subformer_definition_types, -// > -// for #former_assign_end< Definition > -// where -// #former_generics_where -// { -// #[ inline( always ) ] -// fn call -// ( -// &self, -// storage : #field_ty, -// super_former : Option< #former< #former_generics_ty > >, -// ) -// -> #former< #former_generics_ty > -// { -// let mut super_former = super_former.unwrap(); -// if let Some( ref mut field ) = super_former.storage.#field_ident -// { -// former::ContainerAssign::assign( field, storage ); -// } -// else -// { -// super_former.storage.#field_ident = Some( storage ); -// } -// super_former -// } -// } -// -// }; -// -// // tree_print!( r.as_ref().unwrap() ); -// Ok( r ) -// } - /// /// Generate a single scalar setter for the 'field_ident' with the 'setter_name' name. /// @@ -1173,110 +1005,6 @@ where } } - /// zzz : write documentation - - // xxx : move - #[ inline ] - pub fn former_add_end - ( - &self, - stru : &syn::Ident, - former : &syn::Ident, - former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - struct_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - struct_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, - struct_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - ) - -> - Result< TokenStream > - { - - if self.attrs.subform.is_none() - { - return Ok( qt!{ } ); - } - - use convert_case::{ Case, Casing }; - let field_ident = self.ident; - let field_ty = self.non_optional_ty; - // let params = typ::type_parameters( &self.non_optional_ty, .. ); - - // example : `ParentFormerAddChildrenEnd`` - let former_add_end_name = format!( "{}FormerAdd{}End", stru, field_ident.to_string().to_case( Case::Pascal ) ); - let former_add_end = syn::Ident::new( &former_add_end_name, field_ident.span() ); - - let r = qt! - { - - // zzz : improve description - /// Handles the completion of an element of subformer's container. - pub struct #former_add_end< Definition > - { - _phantom : core::marker::PhantomData< fn( Definition ) >, - } - - impl< Definition > Default - for #former_add_end< Definition > - { - #[ inline( always ) ] - fn default() -> Self - { - Self - { - _phantom : core::marker::PhantomData, - } - } - } - - impl< #struct_generics_impl Types2, Definition > former::FormingEnd< Types2, > - for #former_add_end< Definition > - where - Definition : former::FormerDefinition - < - Storage = < #stru < #struct_generics_ty > as former::EntityToStorage >::Storage, - >, - Types2 : former::FormerDefinitionTypes - < - Storage = < < #field_ty as former::Container >::Val as former::EntityToStorage >::Storage, - Formed = #former< #former_generics_ty >, - Context = #former< #former_generics_ty >, - >, - #struct_generics_where - { - #[ inline( always ) ] - fn call - ( - &self, - substorage : Types2::Storage, - super_former : core::option::Option< Types2::Context >, - ) - -> Types2::Formed - { - let mut super_former = super_former.unwrap(); - if super_former.storage.#field_ident.is_none() - { - super_former.storage.#field_ident = Some( Default::default() ); - } - if let Some( ref mut field ) = super_former.storage.#field_ident - { - former::ContainerAdd::add - ( - field, - < < #field_ty as former::Container >::Val as former::ValToEntry< #field_ty > > - ::val_to_entry( former::StoragePreform::preform( substorage ) ), - ); - } - super_former - } - } - - }; - - // tree_print!( r.as_ref().unwrap() ); - Ok( r ) - } - - /// Get name of scalar setter. pub fn scalar_setter_name( &self ) -> &syn::Ident { From 8af3d3d6597c0f0f86763f48685934c267568e9a Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 8 May 2024 00:02:56 +0300 Subject: [PATCH 495/533] former : cleaning and documentation --- module/core/former/src/definition.rs | 5 +- .../former_meta/src/derive_former/field.rs | 150 +++++++++++++----- 2 files changed, 112 insertions(+), 43 deletions(-) diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs index c3a8619dc6..b7ee6921e6 100644 --- a/module/core/former/src/definition.rs +++ b/module/core/former/src/definition.rs @@ -26,10 +26,11 @@ pub trait EntityToDefinition< Context, Formed, End > type Types : FormerDefinitionTypes; } -/// xxx : update description +/// Provides a mapping between a type of entity and its associated formation type definitions. pub trait EntityToDefinitionTypes< Context, Formed > { - /// The specific `FormerDefinitionTypes` associated with this entity. + /// Specifies the `FormerDefinitionTypes` that define the storage, formed entity, and context types used during formation. + /// This association is essential for ensuring that the formation process is carried out with the correct type-specific logic. type Types : FormerDefinitionTypes; } diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index b87aee92df..4ef71c6f50 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -304,9 +304,27 @@ scalar_setter_required } - // zzz : outdated, please update documentation + /// Generates former setters for the specified field within a struct or enum. /// - /// Generate a former setter for the field. + /// This function is responsible for dynamically creating code that allows for the building + /// or modifying of fields within a `Former`-enabled struct or enum. It supports different + /// types of setters based on the field attributes, such as scalar setters, container setters, + /// and subform setters. + /// + /// # Returns + /// + /// Returns a pair of `TokenStream` instances: + /// - The first `TokenStream` contains the generated setter functions for the field. + /// - The second `TokenStream` includes additional namespace or supporting code that might + /// be required for the setters to function correctly, such as definitions for end conditions + /// or callbacks used in the formation process. + /// + /// The generation of setters is dependent on the attributes of the field: + /// - **Scalar Setters**: Created for basic data types and simple fields. + /// - **Container Setters**: Generated when the field is annotated to behave as a container, + /// supporting operations like adding or replacing elements. + /// - **Subform Setters**: Generated for fields annotated as subforms, allowing for nested + /// forming processes where a field itself can be formed using a dedicated former. /// #[ inline ] @@ -421,11 +439,30 @@ scalar_setter_required let field_add_name = format!( "_{}_add", field_ident ); let field_add = syn::Ident::new( &field_add_name, field_ident.span() ); + let doc = format! + ( + r#" + +Initiates the addition of {field_ident} to the `{stru}` entity using a dedicated subformer. + +This method configures and returns a subformer specialized for the `{field_typ}` entities' formation process, +which is part of the `{stru}` entity's construction. The subformer is set up with a specific end condition +handled by `{former_add_end}`, ensuring that the {field_ident} are properly integrated into the +parent's structure once formed. + +# Returns + +Returns an instance of `Former2`, a subformer ready to begin the formation process for `{field_typ}` entities, +allowing for dynamic and flexible construction of the `{stru}` entity's {field_ident}. + + "#, + format!( "{}", qt!{ #field_typ } ), + ); + let setters_code = qt! { - // zzz : improve documentation - /// Setter returning former of element of container of the field as subformer. + #[ doc = doc ] #[ inline( always ) ] pub fn #field_add< Former2, Definition2 >( self ) -> Former2 where @@ -449,40 +486,6 @@ scalar_setter_required }; - if attr.hint - { - let hint = format! - ( - r#" - -/// Initializes and configures a subformer for adding named child entities. This method leverages an internal function -/// to create and return a configured subformer instance. It allows for the dynamic addition of children with specific names, -/// integrating them into the formation process of the parent entity. - -impl< Definition > {}< Definition > -where - Definition : former::FormerDefinition< Storage = {} >, -{{ - - #[ inline( always ) ] - pub fn {}( self ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > - {{ - self.{}::< ChildFormer< _ >, _, >() - }} - // Replace Child with name of type of element value. - -}} - "#, - former, - former_storage, - field_ident, - // as_subformer, - // as_subformer_end, - field_add_name, - ); - println!( "{hint}" ); - } - let setters_code = if attr.setter() { qt! @@ -520,11 +523,77 @@ where setters_code }; + if attr.hint + { + let hint = format! + ( + r#" + +/// Initializes and configures a subformer for adding named child entities. This method leverages an internal function +/// to create and return a configured subformer instance. It allows for the dynamic addition of children with specific names, +/// integrating them into the formation process of the parent entity. + +impl< Definition > {}< Definition > +where + Definition : former::FormerDefinition< Storage = {} >, +{{ + + #[ inline( always ) ] + pub fn {}( self ) -> ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > + {{ + self.{}::< ChildFormer< _ >, _, >() + }} + // Replace Child with name of type of element value. + +}} + "#, + former, + former_storage, + field_ident, + field_add_name, + ); + println!( "{hint}" ); + } + + let doc = format! + ( + r#" + +Implements the `FormingEnd` trait for `{former_add_end}` to handle the final +stage of the forming process for a `{stru}` container that contains `{0}` elements. + +This implementation is tailored to manage the transition of {field_ident} elements from a substorage +temporary state into their final state within the `{stru}`'s storage. The function ensures +that the `{stru}`'s {field_ident} storage is initialized if not already set, and then adds the +preformed elements to this storage. + +# Type Parameters + +- `Types2`: Represents the specific types associated with the `Former` trait being applied, + which include storage, formed type, and context. +- `Definition`: Defines the `FormerDefinition` that outlines the storage structure and + the end conditions for the formation process. + +# Parameters + +- `substorage`: The storage from which {field_ident} elements are preformed and retrieved. +- `super_former`: An optional context which, upon invocation, contains the `{former}` + instance being formed. + +# Returns + +Returns the updated `{former}` instance with newly added {field_ident}, completing the +formation process of the `{stru}`. + + "#, + format!( "{}", qt!{ #field_typ } ), + ); + + let namespace_code = qt! { - // zzz : improve description - /// Handles the completion of an element of subformer's container. + #[ doc = #doc ] pub struct #former_add_end< Definition > { _phantom : core::marker::PhantomData< fn( Definition ) >, @@ -852,7 +921,6 @@ with the new content generated during the subforming process. let r = qt! { - // zzz : improve description #[ doc = #former_assign_end_doc ] pub struct #former_assign_end< Definition > { From 3e36f42dc565286929216d24518ced51df024fe3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 8 May 2024 00:04:47 +0300 Subject: [PATCH 496/533] former : cleaning and documentation --- module/core/former_meta/src/derive_former/field.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 4ef71c6f50..66a84f5350 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -445,14 +445,14 @@ scalar_setter_required Initiates the addition of {field_ident} to the `{stru}` entity using a dedicated subformer. -This method configures and returns a subformer specialized for the `{field_typ}` entities' formation process, +This method configures and returns a subformer specialized for the `{0}` entities' formation process, which is part of the `{stru}` entity's construction. The subformer is set up with a specific end condition handled by `{former_add_end}`, ensuring that the {field_ident} are properly integrated into the parent's structure once formed. # Returns -Returns an instance of `Former2`, a subformer ready to begin the formation process for `{field_typ}` entities, +Returns an instance of `Former2`, a subformer ready to begin the formation process for `{0}` entities, allowing for dynamic and flexible construction of the `{stru}` entity's {field_ident}. "#, @@ -462,7 +462,7 @@ allowing for dynamic and flexible construction of the `{stru}` entity's {field_i let setters_code = qt! { - #[ doc = doc ] + #[ doc = #doc ] #[ inline( always ) ] pub fn #field_add< Former2, Definition2 >( self ) -> Former2 where @@ -988,6 +988,7 @@ with the new content generated during the subforming process. /// Used as a helper function for former_field_setter(), which generates alias setters /// /// # Example of generated code + /// /// ```ignore /// #[ doc = "Setter for the 'int_1' field." ] /// #[ inline ] From 32966ca61e33ba38d18742353a69e8beaf5628f9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 8 May 2024 00:10:29 +0300 Subject: [PATCH 497/533] former : cleaning and documentation --- module/core/former_meta/src/derive_former.rs | 26 ++------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 6029048e35..2586e62932 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -4,7 +4,6 @@ use iter_tools::{ Itertools, process_results }; use macro_tools::{ attr, diag, generic_params, generic_args, typ, derive, Result }; use proc_macro2::TokenStream; -// zzz : explain concept of Storage // qqq : implement interfaces for other containers mod field; @@ -14,7 +13,7 @@ use field_attrs::*; mod struct_attrs; use struct_attrs::*; -/// xxx : write documentation and example of generated code +/// zzz : write documentation and example of generated code pub fn mutator ( @@ -141,8 +140,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let stru = &ast.ident; let former_name = format!( "{}Former", stru ); let former = syn::Ident::new( &former_name, stru.span() ); - // let former_namespace_name = format!( "{}FormerSpace", stru ); - // let former_namespace = syn::Ident::new( &former_namespace_name, stru.span() ); let former_storage_name = format!( "{}FormerStorage", stru ); let former_storage = syn::Ident::new( &former_storage_name, stru.span() ); let former_definition_name = format!( "{}FormerDefinition", stru ); @@ -366,12 +363,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > type Types = #former_definition_types < #struct_generics_ty __Context, __Formed >; } - // #[ allow( non_snake_case ) ] - // pub mod #former_namespace - // { - // pub use super::#stru; - // use super::*; - // = definition types #[ derive( Debug ) ] @@ -750,25 +741,12 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { } - // = container assign callbacks - - // #( - // #former_assign_end - // )* + // = etc #( #namespace_code )* - // = container add callbacks - - // #( - // #former_add_end - // )* - - // } /* end of namespace */ - // pub use #former_namespace :: *; - }; if has_debug From 7c8903d88a68e6fd7bb6eea5feb90d59ce960643 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 8 May 2024 00:14:14 +0300 Subject: [PATCH 498/533] former : cleaning and documentation --- .../examples/former_custom_container.rs | 2 +- module/core/former_meta/src/derive_former.rs | 29 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/module/core/former/examples/former_custom_container.rs b/module/core/former/examples/former_custom_container.rs index 625c2e80ac..f4fb36dce2 100644 --- a/module/core/former/examples/former_custom_container.rs +++ b/module/core/former/examples/former_custom_container.rs @@ -2,7 +2,7 @@ /// /// Container interface is defined in the crate and implemented for containers like vectors, hash maps, etc, but if you want to use non-standard container you can implement container interface for the container. This example demonstrate how to do that. -// xxx2 : get complited +// xxx2 : get completed #[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] fn main() {} diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 2586e62932..d42490dbac 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -13,12 +13,37 @@ use field_attrs::*; mod struct_attrs; use struct_attrs::*; -/// zzz : write documentation and example of generated code +/// Generates the code for implementing the `FormerMutator` trait for a specified former definition type. +/// +/// This function generate code that implements the `FormerMutator` trait based on the given +/// former definition types and their associated generics. The `FormerMutator` trait provides the +/// functionality to mutate the storage and context of an entity just before its formation process +/// completes. This is particularly useful for performing final adjustments or validations on the data +/// before the entity is fully constructed. +/// +/// # Example +/// +/// Below is an example of how the generated code might look: +/// +/// ```rust +/// impl< Context, Formed > former::FormerMutator +/// for Struct1FormerDefinitionTypes< Context, Formed > +/// { +/// /// Mutates the context and storage of the entity just before the formation process completes. +/// #[ inline ] +/// fn form_mutation( storage : &mut Self::Storage, _context : &mut ::core::option::Option< Self::Context > ) +/// { +/// storage.a.get_or_insert_with( Default::default ); +/// storage.b.get_or_insert_with( Default::default ); +/// storage.c = Some( format!( "{:?} - {}", storage.a.unwrap(), storage.b.as_ref().unwrap() ) ); +/// } +/// } +/// ``` +/// pub fn mutator ( mutator : &AttributeMutator, - // stru : &syn::Ident, former_definition_types : &syn::Ident, former_definition_types_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_definition_types_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, From b69a1ffb96dc6184b0f6422b9578ff44e49c41d6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 10 May 2024 23:03:54 +0300 Subject: [PATCH 499/533] former : cleaning and documentation --- .../attribute_storage_with_mutator.rs | 2 - .../subformer_container_custom.rs | 363 ++++++++++-------- 2 files changed, 195 insertions(+), 170 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs index bf16186849..57936294d3 100644 --- a/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs +++ b/module/core/former/tests/inc/former_tests/attribute_storage_with_mutator.rs @@ -1,8 +1,6 @@ #[ allow( unused_imports ) ] use super::*; -// xxx : write example - #[ derive( Debug, PartialEq, the_module::Former ) ] #[ storage_fields( a : i32, b : Option< String > ) ] #[ mutator( custom = true ) ] diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index 5067c19b14..5a0db86e67 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -1,66 +1,83 @@ -// #![ allow( dead_code ) ] -// -// use super::*; -// use collection_tools::HashSet; -// use std::fmt; -// -// // == define custom containers -// -// // Custom container that logs additions -// #[derive(Default)] -// pub struct LoggingSet -// where -// K : core::cmp::Eq + core::hash::Hash, -// { -// set: HashSet, -// } -// -// impl< K > former::Container for LoggingSet< K > -// where -// K : core::cmp::Eq + core::hash::Hash, -// { -// type Entry = K; -// type Val = K; -// -// #[ inline( always ) ] -// fn entry_to_val( e : Self::Entry ) -> Self::Val -// { -// e -// } -// -// } -// -// impl< K > former::ContainerAdd for LoggingSet< K > -// where -// K : core::cmp::Eq + core::hash::Hash, -// { -// // type Entry = K; -// // type Val = K; -// -// #[ inline( always ) ] -// fn add( &mut self, e : Self::Entry ) -> bool -// { -// self.set.insert( e ) -// } -// -// } -// -// impl< K > former::ContainerAssign for LoggingSet< K > -// where -// K : core::cmp::Eq + core::hash::Hash, -// { -// // type Entry = K; -// -// fn assign< Elements >( &mut self, elements : Elements ) -> usize -// where -// Elements : IntoIterator< Item = Self::Entry > -// { -// let initial_len = self.len(); -// self.set.extend( elements ); -// self.set.len() - initial_len -// } -// } -// +#![ allow( dead_code ) ] + +use super::*; +use collection_tools::HashSet; +use std::fmt; + +// == define custom containers + +// Custom container that logs additions +#[ derive( Debug, PartialEq ) ] +pub struct LoggingSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + set : HashSet< K >, +} + +impl< K > Default for LoggingSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + + #[ inline( always ) ] + fn default() -> Self + { + Self + { + set : Default::default() + } + } + +} + +impl< K > former::Container for LoggingSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + type Entry = K; + type Val = K; + + #[ inline( always ) ] + fn entry_to_val( e : Self::Entry ) -> Self::Val + { + e + } + +} + +impl< K > former::ContainerAdd for LoggingSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + // type Entry = K; + // type Val = K; + + #[ inline( always ) ] + fn add( &mut self, e : Self::Entry ) -> bool + { + self.set.insert( e ) + } + +} + +impl< K > former::ContainerAssign for LoggingSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + // type Entry = K; + + fn assign< Elements >( &mut self, elements : Elements ) -> usize + where + Elements : IntoIterator< Item = Self::Entry > + { + let initial_len = self.set.len(); + self.set.extend( elements ); + self.set.len() - initial_len + } +} + +// xxx : uncomment // impl< K > former::ValToEntry< LoggingSet< K > > for K // where // K : core::cmp::Eq + core::hash::Hash, @@ -72,103 +89,113 @@ // self // } // } + + +// xxx : test with HashSetLike // -// // xxx : test with HashSetLike -// // -// // impl< K > HashSetLike< K > for LoggingSet< K > -// // where -// // K : core::cmp::Eq + core::hash::Hash, -// // { -// // fn insert( &mut self, element : K ) -> Option< K > -// // { -// // HashSet::replace( self, element ) -// // } -// // } -// -// // = storage -// -// impl< K > former::Storage -// for LoggingSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// type Formed = LoggingSet< K >; -// // xxx : rid off Formed maybe? -// } -// -// impl< K > former::StoragePreform -// for LoggingSet< K > +// impl< K > HashSetLike< K > for LoggingSet< K > // where -// K : ::core::cmp::Eq + ::core::hash::Hash, +// K : core::cmp::Eq + core::hash::Hash, // { -// type Preformed = LoggingSet< K >; -// fn preform( self ) -> Self::Preformed +// fn insert( &mut self, element : K ) -> Option< K > // { -// self +// HashSet::replace( self, element ) // } // } -// -// // = definition types -// -// #[ derive( Debug, Default ) ] -// pub struct HashSetDefinitionTypes< K, Context = (), Formed = LoggingSet< K > > -// { -// _phantom : core::marker::PhantomData< ( K, Context, Formed ) >, -// } -// -// impl< K, Context, Formed > FormerDefinitionTypes -// for HashSetDefinitionTypes< K, Context, Formed, NoEnd > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// type Storage = LoggingSet< K >; -// type Formed = Formed; -// type Context = Context; -// } -// -// // = definition -// -// #[ derive( Debug, Default ) ] -// pub struct HashSetDefinition< K, Context = (), Formed = LoggingSet< K >, End = ReturnStorage > -// { -// _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, -// } -// -// impl< K, Context, Formed, End > FormerDefinition -// for HashSetDefinition< K, Context, Formed, End > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// End : FormingEnd< HashSetDefinition< K, Context, Formed, NoEnd > >, -// { -// type Storage = LoggingSet< K >; -// type Formed = Formed; -// type Context = Context; -// -// type Types = HashSetDefinition< K, Context, Formed, NoEnd >; -// type End = End; -// } -// -// // = mutator -// -// impl< K, Context, Formed > FormerMutator -// for HashSetDefinition< K, Context, Formed, NoEnd > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// } -// -// // = Entity To -// -// impl< K, Definition > EntityToFormer< Definition > for LoggingSet< K > + +// = storage + +impl< K > former::Storage +for LoggingSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Formed = LoggingSet< K >; + // xxx : rid off Formed maybe? +} + +impl< K > former::StoragePreform +for LoggingSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Preformed = LoggingSet< K >; + fn preform( self ) -> Self::Preformed + { + self + } +} + +// = definition types + +#[ derive( Debug, Default ) ] +pub struct HashSetDefinitionTypes< K, Context = (), Formed = LoggingSet< K > > +{ + _phantom : core::marker::PhantomData< ( K, Context, Formed ) >, +} + +impl< K, Context, Formed > former::FormerDefinitionTypes +for HashSetDefinitionTypes< K, Context, Formed > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Storage = LoggingSet< K >; + type Formed = Formed; + type Context = Context; +} + +// = definition + +#[ derive( Debug, Default ) ] +pub struct HashSetDefinition< K, Context = (), Formed = LoggingSet< K >, End = former::ReturnStorage > +{ + _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, +} + +impl< K, Context, Formed, End > former::FormerDefinition +for HashSetDefinition< K, Context, Formed, End > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + End : former::FormingEnd< HashSetDefinitionTypes< K, Context, Formed > >, +{ + type Storage = LoggingSet< K >; + type Formed = Formed; + type Context = Context; + + type Types = HashSetDefinitionTypes< K, Context, Formed >; + type End = End; +} + +// = mutator + +impl< K, Context, Formed > former::FormerMutator +for HashSetDefinitionTypes< K, Context, Formed > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ +} + +// = Entity To + +// impl< K, Definition > former::EntityToFormer< Definition > for HashSet< K > // where // K : ::core::cmp::Eq + ::core::hash::Hash, -// Definition : FormerDefinition< Storage = LoggingSet< K >, Formed = () >, -// < Definition as definition::FormerDefinition>::End : Fn( LoggingSet< K >, Option< Definition::Context > ), +// Definition : former::FormerDefinition +// < +// Storage = HashSet< K >, +// Types = HashSetDefinitionTypes +// < +// K, +// < Definition as former::FormerDefinition >::Context, +// < Definition as former::FormerDefinition >::Formed, +// >, +// >, +// Definition::End : former::FormingEnd< Definition::Types >, // { // type Former = HashSetSubformer< K, Definition::Context, Definition::Formed, Definition::End >; // } // -// impl< K > crate::EntityToStorage +// impl< K > former::EntityToStorage // for LoggingSet< K > // where // K : ::core::cmp::Eq + ::core::hash::Hash, @@ -176,31 +203,31 @@ // type Storage = LoggingSet< K >; // } // -// impl< K, Context, Formed, End > crate::EntityToDefinition< Context, Formed, End > +// impl< K, Context, Formed, End > former::EntityToDefinition< Context, Formed, End > // for LoggingSet< K > // where // K : ::core::cmp::Eq + ::core::hash::Hash, -// End : crate::FormingEnd< HashSetDefinition< K, Context, Formed, NoEnd > >, +// End : former::FormingEnd< HashSetDefinition< K, Context, Formed, NoEnd > >, // { // type Definition = HashSetDefinition< K, Context, Formed, End >; // } -// -// // == use custom container -// -// /// Parent required for the template. -// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] -// // #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] -// // #[ derive( Debug, Default, PartialEq ) ] -// pub struct Parent -// { -// #[ container ] -// children: LoggingSet, -// } -// -// // == begin of generated -// -// // == end of generated -// + +// == use custom container + +/// Parent required for the template. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] +// #[ derive( Debug, Default, PartialEq ) ] +pub struct Parent +{ + // #[ container ] + children : LoggingSet< i32 >, +} + +// == begin of generated + +// == end of generated + // #[ test ] // fn basic() // { @@ -218,4 +245,4 @@ // // } -// xxx2 : get completed \ No newline at end of file +// xxx2 : get completed From affb479cd528bd02264974b635089debd5f58098 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 10 May 2024 23:28:55 +0300 Subject: [PATCH 500/533] former : custom container example and test --- module/core/former/Readme.md | 6 +- module/core/former/src/hash_map.rs | 18 ++--- module/core/former/src/hash_set.rs | 27 ++++---- module/core/former/src/vector.rs | 12 ++-- .../former_tests/container_former_common.rs | 6 +- .../former_tests/container_former_hashmap.rs | 12 ++-- .../former_tests/container_former_hashset.rs | 12 ++-- .../inc/former_tests/container_former_vec.rs | 12 ++-- .../only_test/parametrized_struct.rs | 2 +- .../former_tests/only_test/subformer_basic.rs | 2 +- .../subformer_container_custom.rs | 66 ++++++++++++------- .../src/derive_former/field_attrs.rs | 2 +- 12 files changed, 96 insertions(+), 81 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index dcc5a132e9..bccad8b3b4 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -649,7 +649,7 @@ Each type of setter is designed to address different needs in the formation proc ## Subformer example: Building a Vector -The following example illustrates how to use a `VectorSubformer` to construct a `Vec` field within a struct. The subformer enables adding elements to the vector with a fluent interface, streamlining the process of populating collection fields within structs. +The following example illustrates how to use a `VectorAsSubformer` to construct a `Vec` field within a struct. The subformer enables adding elements to the vector with a fluent interface, streamlining the process of populating collection fields within structs. ```rust #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] @@ -678,7 +678,7 @@ fn main() ## Subformer example: Building a Hashmap -This example demonstrates the use of a `HashMapSubformer` to build a hash map within a struct. The subformer provides a concise way to insert key-value pairs into the map, making it easier to manage and construct hash map fields. +This example demonstrates the use of a `HashMapAsSubformer` to build a hash map within a struct. The subformer provides a concise way to insert key-value pairs into the map, making it easier to manage and construct hash map fields. ```rust #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] @@ -705,7 +705,7 @@ fn main() ## Subformer example: Building a Hashset -In the following example, a `HashSetSubformer` is utilized to construct a hash set within a struct. This illustrates the convenience of adding elements to a set using the builder pattern facilitated by subformers. +In the following example, a `HashSetAsSubformer` is utilized to construct a hash set within a struct. This illustrates the convenience of adding elements to a set using the builder pattern facilitated by subformers. ```rust #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 0ffceca50f..150d586742 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -181,7 +181,7 @@ where >, Definition::End : forming::FormingEnd< Definition::Types >, { - type Former = HashMapSubformer< K, E, Definition::Context, Definition::Formed, Definition::End >; + type Former = HashMapAsSubformer< K, E, Definition::Context, Definition::Formed, Definition::End >; } impl< K, E > crate::EntityToStorage @@ -214,7 +214,7 @@ where /// A builder for constructing hash map-like structures with a fluent interface. /// -/// `HashMapSubformer` leverages the `HashMapLike` trait to enable a flexible and customizable +/// `HashMapAsSubformer` leverages the `HashMapLike` trait to enable a flexible and customizable /// way to build hash map-like structures. It supports the chaining of insert operations and /// allows for the definition of custom end actions to finalize the building process. /// @@ -234,7 +234,7 @@ where /// #[ derive( Debug, PartialEq, former::Former ) ] /// pub struct StructWithMap /// { -/// #[ container( definition = former::HashMapSubformer ) ] +/// #[ container( definition = former::HashMapAsSubformer ) ] /// map : std::collections::HashMap< &'static str, &'static str >, /// } /// @@ -250,11 +250,11 @@ where /// # } /// ``` -// pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, End > >; +// pub type HashMapAsSubformer< K, E, Context, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, End > >; // zzz : update documentation -// pub type HashMapSubformer< K, E, Context, End > = ContainerSubformer::< K, HashMapDefinition< K, E, Context, End > >; -pub type HashMapSubformer< K, E, Context, Formed, End > = +// pub type HashMapAsSubformer< K, E, Context, End > = ContainerSubformer::< K, HashMapDefinition< K, E, Context, End > >; +pub type HashMapAsSubformer< K, E, Context, Formed, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, Formed, End > >; // = extension @@ -263,16 +263,16 @@ pub trait HashMapExt< K, E > : sealed::Sealed where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn former() -> HashMapSubformer< K, E, (), HashMap< K, E >, ReturnStorage >; + fn former() -> HashMapAsSubformer< K, E, (), HashMap< K, E >, ReturnStorage >; } impl< K, E > HashMapExt< K, E > for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn former() -> HashMapSubformer< K, E, (), HashMap< K, E >, ReturnStorage > + fn former() -> HashMapAsSubformer< K, E, (), HashMap< K, E >, ReturnStorage > { - HashMapSubformer::< K, E, (), HashMap< K, E >, ReturnStorage >::new( ReturnStorage::default() ) + HashMapAsSubformer::< K, E, (), HashMap< K, E >, ReturnStorage >::new( ReturnStorage::default() ) } } diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 5cae4f47b6..dc30d309b5 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -1,6 +1,6 @@ -//! # HashSetLike Trait and HashSetSubformer Struct +//! # HashSetLike Trait and HashSetAsSubformer Struct //! -//! This part of the crate provides a flexible interface (`HashSetLike`) and a builder pattern implementation (`HashSetSubformer`) for `HashSet`-like containers. It's designed to extend the builder pattern, allowing for fluent and dynamic construction of sets within custom data structures. +//! This part of the crate provides a flexible interface (`HashSetLike`) and a builder pattern implementation (`HashSetAsSubformer`) for `HashSet`-like containers. It's designed to extend the builder pattern, allowing for fluent and dynamic construction of sets within custom data structures. use super::*; use collection_tools::HashSet; @@ -65,7 +65,7 @@ where /// A trait for containers behaving like a `HashSet`, allowing insertion operations. /// -/// Implementing this trait enables the associated formed to be used with `HashSetSubformer`, +/// Implementing this trait enables the associated formed to be used with `HashSetAsSubformer`, /// facilitating a builder pattern that is both intuitive and concise. /// /// # Example Implementation @@ -177,12 +177,12 @@ where < K, < Definition as definition::FormerDefinition >::Context, - < Definition as definition::FormerDefinition >::Formed, + < Definition as definition::FormerDefinition >::Formed, // xxx : ? >, >, Definition::End : forming::FormingEnd< Definition::Types >, { - type Former = HashSetSubformer< K, Definition::Context, Definition::Formed, Definition::End >; + type Former = HashSetAsSubformer< K, Definition::Context, Definition::Formed, Definition::End >; } impl< K > crate::EntityToStorage @@ -215,12 +215,12 @@ where /// Facilitates building `HashSetLike` containers with a fluent API. /// -/// `HashSetSubformer` leverages the `HashSetLike` trait to enable a concise and expressive way +/// `HashSetAsSubformer` leverages the `HashSetLike` trait to enable a concise and expressive way /// of populating `HashSet`-like containers. It exemplifies the crate's builder pattern variation for sets. /// /// # Example Usage /// -/// Using `HashSetSubformer` to populate a `HashSet` within a struct: +/// Using `HashSetAsSubformer` to populate a `HashSet` within a struct: /// /// ```rust /// # #[ cfg( all( feature = "enabled", not( feature = "no_std" ) ) ) ] @@ -230,7 +230,7 @@ where /// #[ derive( Debug, PartialEq, former::Former ) ] /// pub struct StructWithSet /// { -/// #[ container( definition = former::HashSetSubformer ) ] +/// #[ container( definition = former::HashSetAsSubformer ) ] /// set : std::collections::HashSet< &'static str >, /// } /// @@ -246,9 +246,8 @@ where /// ``` // zzz : update documentation -// write: instead of writing long version with ContainerSubformer it's possible to be more concise with help of the type alias -// -pub type HashSetSubformer< K, Context, Formed, End > = +// add: instead of writing long version with ContainerSubformer it's possible to be more concise with help of the type alias +pub type HashSetAsSubformer< K, Context, Formed, End > = ContainerSubformer::< K, HashSetDefinition< K, Context, Formed, End > >; // = extension @@ -257,16 +256,16 @@ pub trait HashSetExt< K > : sealed::Sealed where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage >; + fn former() -> HashSetAsSubformer< K, (), HashSet< K >, ReturnStorage >; } impl< K > HashSetExt< K > for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn former() -> HashSetSubformer< K, (), HashSet< K >, ReturnStorage > + fn former() -> HashSetAsSubformer< K, (), HashSet< K >, ReturnStorage > { - HashSetSubformer::< K, (), HashSet< K >, ReturnStorage >::new( ReturnStorage::default() ) + HashSetAsSubformer::< K, (), HashSet< K >, ReturnStorage >::new( ReturnStorage::default() ) } } diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index e0f7b6e7ce..0f73b0ea55 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -171,7 +171,7 @@ where >, Definition::End : forming::FormingEnd< Definition::Types >, { - type Former = VectorSubformer< E, Definition::Context, Definition::Formed, Definition::End >; + type Former = VectorAsSubformer< E, Definition::Context, Definition::Formed, Definition::End >; } impl< E > crate::EntityToStorage @@ -199,26 +199,26 @@ for Vec< E > /// A builder for constructing `VectorLike` containers, facilitating a fluent and flexible interface. /// -/// `VectorSubformer` leverages the `VectorLike` trait to enable the construction and manipulation +/// `VectorAsSubformer` 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. // zzz : update documentation -pub type VectorSubformer< E, Context, Formed, End > = +pub type VectorAsSubformer< E, Context, Formed, End > = ContainerSubformer::< E, VectorDefinition< E, Context, Formed, End > >; // = extension pub trait VecExt< E > : sealed::Sealed { - fn former() -> VectorSubformer< E, (), Vec< E >, ReturnStorage >; + fn former() -> VectorAsSubformer< E, (), Vec< E >, ReturnStorage >; } impl< E > VecExt< E > for Vec< E > { - fn former() -> VectorSubformer< E, (), Vec< E >, ReturnStorage > + fn former() -> VectorAsSubformer< E, (), Vec< E >, ReturnStorage > { - VectorSubformer::< E, (), Vec< E >, ReturnStorage >::new( ReturnStorage::default() ) + VectorAsSubformer::< E, (), Vec< E >, ReturnStorage >::new( ReturnStorage::default() ) } } diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index 7615fb090e..16d0378127 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -50,14 +50,14 @@ fn begin_and_custom_end() { 13.1 } - let got = the_module::VectorSubformer::begin( None, None, return_13 ) + let got = the_module::VectorAsSubformer::begin( None, None, return_13 ) .add( "a" ) .add( "b" ) .form(); let exp = 13.1; a_id!( got, exp ); - let got = the_module::VectorSubformer::new( return_13 ) + let got = the_module::VectorAsSubformer::new( return_13 ) .add( "a" ) .add( "b" ) .form(); @@ -77,7 +77,7 @@ fn begin_and_custom_end() 13.1 } } - let got = the_module::VectorSubformer::begin( None, Some( 10.0 ), context_plus_13 ) + let got = the_module::VectorAsSubformer::begin( None, Some( 10.0 ), context_plus_13 ) .add( "a" ) .add( "b" ) .form(); diff --git a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs index 8d1f57b79e..5c29282a7e 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs @@ -27,9 +27,9 @@ fn add() ]; a_id!( got, exp ); - // expliccit with HashMapSubformer + // expliccit with HashMapAsSubformer - let got : HashMap< String, String > = the_module::HashMapSubformer::< String, String, (), HashMap< String, String >, the_module::ReturnStorage > + let got : HashMap< String, String > = the_module::HashMapAsSubformer::< String, String, (), HashMap< String, String >, the_module::ReturnStorage > ::new( former::ReturnStorage ) .add( ( "a".into(), "x".into() ) ) .add( ( "b".into(), "y".into() ) ) @@ -41,9 +41,9 @@ fn add() ]; a_id!( got, exp ); - // compact with HashMapSubformer + // compact with HashMapAsSubformer - let got : HashMap< String, String > = the_module::HashMapSubformer::new( former::ReturnStorage ) + let got : HashMap< String, String > = the_module::HashMapAsSubformer::new( former::ReturnStorage ) .add( ( "a".into(), "x".into() ) ) .add( ( "b".into(), "y".into() ) ) .form(); @@ -56,7 +56,7 @@ fn add() // with begin - let got : HashMap< String, String > = the_module::HashMapSubformer + let got : HashMap< String, String > = the_module::HashMapAsSubformer ::begin( Some( hmap![ "a".to_string() => "x".to_string() ] ), Some( () ), former::ReturnStorage ) .add( ( "b".into(), "y".into() ) ) .form(); @@ -91,7 +91,7 @@ fn add() fn replace() { - let got : HashMap< String, String > = the_module::HashMapSubformer::new( former::ReturnStorage ) + let got : HashMap< String, String > = the_module::HashMapAsSubformer::new( former::ReturnStorage ) .add( ( "x".to_string(), "y".to_string() ) ) .replace( hmap![ "a".to_string() => "x".to_string(), "b".to_string() => "y".to_string(), ] ) .form(); diff --git a/module/core/former/tests/inc/former_tests/container_former_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs index 814d2c1095..72ea2af67b 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashset.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashset.rs @@ -27,9 +27,9 @@ fn add() ]; a_id!( got, exp ); - // expliccit with HashSetSubformer + // expliccit with HashSetAsSubformer - let got : HashSet< String > = the_module::HashSetSubformer::< String, (), HashSet< String >, the_module::ReturnStorage > + let got : HashSet< String > = the_module::HashSetAsSubformer::< String, (), HashSet< String >, the_module::ReturnStorage > ::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) @@ -41,9 +41,9 @@ fn add() ]; a_id!( got, exp ); - // compact with HashSetSubformer + // compact with HashSetAsSubformer - let got : HashSet< String > = the_module::HashSetSubformer::new( former::ReturnStorage ) + let got : HashSet< String > = the_module::HashSetAsSubformer::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -56,7 +56,7 @@ fn add() // with begin_coercing - let got : HashSet< String > = the_module::HashSetSubformer + let got : HashSet< String > = the_module::HashSetAsSubformer ::begin( Some( hset![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) .add( "b" ) .form(); @@ -91,7 +91,7 @@ fn add() fn replace() { - let got : HashSet< String > = the_module::HashSetSubformer::new( former::ReturnStorage ) + let got : HashSet< String > = the_module::HashSetAsSubformer::new( former::ReturnStorage ) .add( "x" ) .replace( hset![ "a".to_string(), "b".to_string() ] ) .form(); 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 a8951379ab..1adbd1d029 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 @@ -26,9 +26,9 @@ fn add() ]; a_id!( got, exp ); - // expliccit with VectorSubformer + // expliccit with VectorAsSubformer - let got : Vec< String > = the_module::VectorSubformer::< String, (), Vec< String >, the_module::ReturnStorage > + let got : Vec< String > = the_module::VectorAsSubformer::< String, (), Vec< String >, the_module::ReturnStorage > ::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) @@ -40,9 +40,9 @@ fn add() ]; a_id!( got, exp ); - // compact with VectorSubformer + // compact with VectorAsSubformer - let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) + let got : Vec< String > = the_module::VectorAsSubformer::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -55,7 +55,7 @@ fn add() // with begin_coercing - let got : Vec< String > = the_module::VectorSubformer + let got : Vec< String > = the_module::VectorAsSubformer ::begin( Some( vec![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) .add( "b" ) .form(); @@ -90,7 +90,7 @@ fn add() fn replace() { - let got : Vec< String > = the_module::VectorSubformer::new( former::ReturnStorage ) + let got : Vec< String > = the_module::VectorAsSubformer::new( former::ReturnStorage ) .add( "x" ) .replace( vec![ "a".to_string(), "b".to_string() ] ) .form(); diff --git a/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs b/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs index b9826fe542..a829d19a0d 100644 --- a/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs +++ b/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs @@ -45,7 +45,7 @@ fn command_form() fn command_properties() { - // with HashMapSubformer + // with HashMapAsSubformer let got = Child::< &str >::former() .name( "a" ) .properties() diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs index 323bfb4d8b..861e81d760 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs @@ -86,7 +86,7 @@ fn command_properties() }; a_id!( got, exp ); - // with HashMapSubformer + // with HashMapAsSubformer let got = Child::< &str >::former() .name( "a" ) .subject( "b" ) diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index 5a0db86e67..4252084575 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -129,13 +129,13 @@ where // = definition types #[ derive( Debug, Default ) ] -pub struct HashSetDefinitionTypes< K, Context = (), Formed = LoggingSet< K > > +pub struct LoggingSetDefinitionTypes< K, Context = (), Formed = LoggingSet< K > > { _phantom : core::marker::PhantomData< ( K, Context, Formed ) >, } impl< K, Context, Formed > former::FormerDefinitionTypes -for HashSetDefinitionTypes< K, Context, Formed > +for LoggingSetDefinitionTypes< K, Context, Formed > where K : ::core::cmp::Eq + ::core::hash::Hash, { @@ -147,29 +147,29 @@ where // = definition #[ derive( Debug, Default ) ] -pub struct HashSetDefinition< K, Context = (), Formed = LoggingSet< K >, End = former::ReturnStorage > +pub struct LoggingSetDefinition< K, Context = (), Formed = LoggingSet< K >, End = former::ReturnStorage > { _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, } impl< K, Context, Formed, End > former::FormerDefinition -for HashSetDefinition< K, Context, Formed, End > +for LoggingSetDefinition< K, Context, Formed, End > where K : ::core::cmp::Eq + ::core::hash::Hash, - End : former::FormingEnd< HashSetDefinitionTypes< K, Context, Formed > >, + End : former::FormingEnd< LoggingSetDefinitionTypes< K, Context, Formed > >, { type Storage = LoggingSet< K >; type Formed = Formed; type Context = Context; - type Types = HashSetDefinitionTypes< K, Context, Formed >; + type Types = LoggingSetDefinitionTypes< K, Context, Formed >; type End = End; } // = mutator impl< K, Context, Formed > former::FormerMutator -for HashSetDefinitionTypes< K, Context, Formed > +for LoggingSetDefinitionTypes< K, Context, Formed > where K : ::core::cmp::Eq + ::core::hash::Hash, { @@ -177,24 +177,26 @@ where // = Entity To -// impl< K, Definition > former::EntityToFormer< Definition > for HashSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// Definition : former::FormerDefinition -// < -// Storage = HashSet< K >, -// Types = HashSetDefinitionTypes -// < -// K, -// < Definition as former::FormerDefinition >::Context, -// < Definition as former::FormerDefinition >::Formed, -// >, -// >, -// Definition::End : former::FormingEnd< Definition::Types >, -// { -// type Former = HashSetSubformer< K, Definition::Context, Definition::Formed, Definition::End >; -// } -// +impl< K, Definition > former::EntityToFormer< Definition > for LoggingSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + Definition : former::FormerDefinition + < + Storage = LoggingSet< K >, + Types = LoggingSetDefinitionTypes + < + K, + < Definition as former::FormerDefinition >::Context, + < Definition as former::FormerDefinition >::Formed, + >, + >, + Definition::End : former::FormingEnd< Definition::Types >, +{ + type Former = LoggingSetAsSubformer< K, Definition::Context, Definition::Formed, Definition::End >; + // xxx : uncomment + // type Former = LoggingSetAsSubformer< K, Definition::Context, Definition::Formed, Definition::End >; +} + // impl< K > former::EntityToStorage // for LoggingSet< K > // where @@ -212,6 +214,19 @@ where // type Definition = HashSetDefinition< K, Context, Formed, End >; // } +// impl< K, Context, Formed > crate::EntityToDefinitionTypes< Context, Formed > +// for HashSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// type Types = HashSetDefinitionTypes< K, Context, Formed >; +// } + +// = subformer + +pub type LoggingSetAsSubformer< K, Context, Formed, End > = +former::ContainerSubformer::< K, LoggingSetDefinition< K, Context, Formed, End > >; + // == use custom container /// Parent required for the template. @@ -246,3 +261,4 @@ pub struct Parent // } // xxx2 : get completed + diff --git a/module/core/former_meta/src/derive_former/field_attrs.rs b/module/core/former_meta/src/derive_former/field_attrs.rs index a19a98a2f3..a2d8010a0b 100644 --- a/module/core/former_meta/src/derive_former/field_attrs.rs +++ b/module/core/former_meta/src/derive_former/field_attrs.rs @@ -271,7 +271,7 @@ pub struct AttributeContainerSetter pub name : Option< syn::Ident >, /// Controls the generation of a setter method. If false, a setter method is not generated. pub setter : Option< bool >, - /// Definition of the container former to use, e.g., `former::VectorSubformer`. + /// Definition of the container former to use, e.g., `former::VectorAsSubformer`. pub definition : Option< syn::Type >, /// Specifies whether to provide a sketch of the subform setter as a hint. /// Defaults to `false`, which means no hint is provided unless explicitly requested. From 2bbdb9a2acba1c30d3c9383b711adae623fea304 Mon Sep 17 00:00:00 2001 From: wandalen Date: Fri, 10 May 2024 23:30:48 +0300 Subject: [PATCH 501/533] former : custom container example and test --- .../former/tests/inc/former_tests/subformer_container_custom.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index 4252084575..4ac7a0cbc4 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -193,8 +193,6 @@ where Definition::End : former::FormingEnd< Definition::Types >, { type Former = LoggingSetAsSubformer< K, Definition::Context, Definition::Formed, Definition::End >; - // xxx : uncomment - // type Former = LoggingSetAsSubformer< K, Definition::Context, Definition::Formed, Definition::End >; } // impl< K > former::EntityToStorage From c16bf0cfd8330cecbbca2668aba25ea4a6b779ce Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 08:59:56 +0300 Subject: [PATCH 502/533] former : custom container example and test --- .../subformer_container_custom.rs | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index 4ac7a0cbc4..d626f11249 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -2,7 +2,7 @@ use super::*; use collection_tools::HashSet; -use std::fmt; +// use std::fmt; // == define custom containers @@ -195,22 +195,23 @@ where type Former = LoggingSetAsSubformer< K, Definition::Context, Definition::Formed, Definition::End >; } -// impl< K > former::EntityToStorage -// for LoggingSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// type Storage = LoggingSet< K >; -// } -// -// impl< K, Context, Formed, End > former::EntityToDefinition< Context, Formed, End > -// for LoggingSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// End : former::FormingEnd< HashSetDefinition< K, Context, Formed, NoEnd > >, -// { -// type Definition = HashSetDefinition< K, Context, Formed, End >; -// } +impl< K > former::EntityToStorage +for LoggingSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Storage = LoggingSet< K >; +} + +impl< K, Context, Formed, End > former::EntityToDefinition< Context, Formed, End > +for LoggingSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + End : former::FormingEnd< LoggingSetDefinitionTypes< K, Context, Formed > >, +{ + type Definition = LoggingSetDefinition< K, Context, Formed, End >; + type Types = LoggingSetDefinitionTypes< K, Context, Formed >; +} // impl< K, Context, Formed > crate::EntityToDefinitionTypes< Context, Formed > // for HashSet< K > From fdde546c3a38b7c514dca4b28dd0653308453a2f Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 09:02:16 +0300 Subject: [PATCH 503/533] former : custom container example and test --- .../former_tests/subformer_container_custom.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index d626f11249..b05b8b501c 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -90,7 +90,6 @@ where // } // } - // xxx : test with HashSetLike // // impl< K > HashSetLike< K > for LoggingSet< K > @@ -213,13 +212,13 @@ where type Types = LoggingSetDefinitionTypes< K, Context, Formed >; } -// impl< K, Context, Formed > crate::EntityToDefinitionTypes< Context, Formed > -// for HashSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// type Types = HashSetDefinitionTypes< K, Context, Formed >; -// } +impl< K, Context, Formed > former::EntityToDefinitionTypes< Context, Formed > +for LoggingSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Types = LoggingSetDefinitionTypes< K, Context, Formed >; +} // = subformer From 2fb01e63d0ab2e4180c5d4ccb5b83af85324989b Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 09:18:10 +0300 Subject: [PATCH 504/533] former : custom container example and test --- module/core/former/src/container.rs | 2 ++ .../subformer_container_custom.rs | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index d59ae3518f..4e213b06d5 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -134,6 +134,8 @@ pub trait ContainerAdd : Container /// the container with a new set. This can be useful for resetting the container's contents or bulk-updating /// them based on external criteria or operations. pub trait ContainerAssign : Container +where + Self : IntoIterator< Item = Self::Entry >, { /// Replaces all entries in the container with the provided entries and returns the count of new entries added. /// diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index b05b8b501c..70c630a51f 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -31,6 +31,32 @@ where } +impl< K > IntoIterator for LoggingSet< K > +where + K : std::cmp::Eq + std::hash::Hash, +{ + type Item = K; + type IntoIter = std::collections::hash_set::IntoIter< K >; + + fn into_iter( self ) -> Self::IntoIter + { + self.set.into_iter() + } +} + +impl<'a, K> IntoIterator for &'a LoggingSet< K > +where + K : std::cmp::Eq + std::hash::Hash, +{ + type Item = &'a K; + type IntoIter = std::collections::hash_set::Iter< 'a, K >; + + fn into_iter( self ) -> Self::IntoIter + { + self.set.iter() + } +} + impl< K > former::Container for LoggingSet< K > where K : core::cmp::Eq + core::hash::Hash, @@ -65,8 +91,6 @@ impl< K > former::ContainerAssign for LoggingSet< K > where K : core::cmp::Eq + core::hash::Hash, { - // type Entry = K; - fn assign< Elements >( &mut self, elements : Elements ) -> usize where Elements : IntoIterator< Item = Self::Entry > @@ -233,7 +257,7 @@ former::ContainerSubformer::< K, LoggingSetDefinition< K, Context, Formed, End > // #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { - // #[ container ] + #[ container ] children : LoggingSet< i32 >, } From c294feb1b912c147a267f06cc8e765c8f0a2dbe7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 09:44:49 +0300 Subject: [PATCH 505/533] former : custom container example and test --- module/core/former/src/container.rs | 31 +++++++++++++++++++ module/core/former/src/hash_set.rs | 19 ++++++++++-- module/core/former/src/vector.rs | 18 +++++++++-- .../subformer_container_custom.rs | 1 + 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 4e213b06d5..10320a56b8 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -62,6 +62,24 @@ where /// This trait is crucial for operations that require the insertion or modification of entries based on values, /// especially in complex data structures where the entry's structure is more intricate than the value it represents, /// such as inserting a new entry in a `HashMap` where the entry consists of a key-value pair. +// xxx : update description +pub trait ContainerValToEntry< Val > +{ + type Entry; + + /// Converts a value back into an entry of the container. This function is essential for operations like insertion + /// or modification, where a value needs to be transformed into a container-compatible entry, such as converting + /// a value into a (key, value) tuple for insertion into a `HashMap`. + // xxx : update description + fn val_to_entry( val : Val ) -> Self::Entry; +} + +/// Provides a mechanism for converting values back to container-specific entries. +/// +/// This trait is crucial for operations that require the insertion or modification of entries based on values, +/// especially in complex data structures where the entry's structure is more intricate than the value it represents, +/// such as inserting a new entry in a `HashMap` where the entry consists of a key-value pair. +// xxx : update description pub trait ValToEntry< Container > { type Entry; @@ -69,9 +87,22 @@ pub trait ValToEntry< Container > /// Converts a value back into an entry of the container. This function is essential for operations like insertion /// or modification, where a value needs to be transformed into a container-compatible entry, such as converting /// a value into a (key, value) tuple for insertion into a `HashMap`. + // xxx : update description fn val_to_entry( self ) -> Self::Entry; } +impl< C, Val > ValToEntry< C > for Val +where + C : ContainerValToEntry< Val >, +{ + type Entry = C::Entry; + + fn val_to_entry( self ) -> C::Entry + { + C::val_to_entry( self ) + } +} + /// Provides functionality to add individual entries to a container. /// /// This trait extends the basic `Container` trait by introducing a method to add entries to a container. diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index dc30d309b5..532fe3f246 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -51,18 +51,31 @@ where } } -impl< K > ValToEntry< HashSet< K > > for K +impl< K > ContainerValToEntry< K > for HashSet< K > where K : core::cmp::Eq + core::hash::Hash, { type Entry = K; #[ inline( always ) ] - fn val_to_entry( self ) -> Self::Entry + fn val_to_entry( val : K ) -> Self::Entry { - self + val } } +// xxx : clean +// impl< K > ValToEntry< HashSet< K > > for K +// where +// K : core::cmp::Eq + core::hash::Hash, +// { +// type Entry = K; +// #[ inline( always ) ] +// fn val_to_entry( self ) -> Self::Entry +// { +// self +// } +// } + /// A trait for containers behaving like a `HashSet`, allowing insertion operations. /// /// Implementing this trait enables the associated formed to be used with `HashSetAsSubformer`, diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 0f73b0ea55..105539f797 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -47,16 +47,28 @@ impl< E > ContainerAssign for collection_tools::Vec< E > } -impl< E > ValToEntry< collection_tools::Vec< E > > for E +impl< E > ContainerValToEntry< E > for collection_tools::Vec< E > +where { type Entry = E; #[ inline( always ) ] - fn val_to_entry( self ) -> Self::Entry + fn val_to_entry( val : E ) -> Self::Entry { - self + val } } +// xxx : clean +// impl< E > ValToEntry< collection_tools::Vec< E > > for E +// { +// type Entry = E; +// #[ inline( always ) ] +// fn val_to_entry( self ) -> Self::Entry +// { +// 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, diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index 70c630a51f..4f778cc91b 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -102,6 +102,7 @@ where } // xxx : uncomment +// // impl< K > former::ValToEntry< LoggingSet< K > > for K // where // K : core::cmp::Eq + core::hash::Hash, From 464e0b6206e6df80b543879bff7f1ddad4f5d146 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 09:45:37 +0300 Subject: [PATCH 506/533] former : custom container example and test --- .../inc/former_tests/subformer_container_custom.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index 4f778cc91b..be985358e1 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -76,8 +76,6 @@ impl< K > former::ContainerAdd for LoggingSet< K > where K : core::cmp::Eq + core::hash::Hash, { - // type Entry = K; - // type Val = K; #[ inline( always ) ] fn add( &mut self, e : Self::Entry ) -> bool @@ -101,6 +99,18 @@ where } } +impl< K > former::ContainerValToEntry< K > for LoggingSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + type Entry = K; + #[ inline( always ) ] + fn val_to_entry( val : K ) -> Self::Entry + { + val + } +} + // xxx : uncomment // // impl< K > former::ValToEntry< LoggingSet< K > > for K From 91d76c6eccdfce079cae56e50f6be63ac70c86db Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 09:46:13 +0300 Subject: [PATCH 507/533] former : custom container example and test --- .../inc/former_tests/subformer_container_custom.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index be985358e1..90a5315443 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -111,20 +111,6 @@ where } } -// xxx : uncomment -// -// impl< K > former::ValToEntry< LoggingSet< K > > for K -// where -// K : core::cmp::Eq + core::hash::Hash, -// { -// type Entry = K; -// #[ inline( always ) ] -// fn val_to_entry( self ) -> Self::Entry -// { -// self -// } -// } - // xxx : test with HashSetLike // // impl< K > HashSetLike< K > for LoggingSet< K > From a7f468dbcdfaaf3a0249070f4e41aa54fbd2bd44 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 09:53:43 +0300 Subject: [PATCH 508/533] former : custom container example and test --- module/core/former/src/container.rs | 86 +++++++++++++++++++++-------- module/core/former/src/hash_set.rs | 13 ----- module/core/former/src/vector.rs | 11 ---- 3 files changed, 64 insertions(+), 46 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 10320a56b8..4ff11cf135 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -57,46 +57,88 @@ where } } -/// Provides a mechanism for converting values back to container-specific entries. +/// Provides a mechanism for transforming a value back into a container-specific entry format. /// -/// This trait is crucial for operations that require the insertion or modification of entries based on values, -/// especially in complex data structures where the entry's structure is more intricate than the value it represents, -/// such as inserting a new entry in a `HashMap` where the entry consists of a key-value pair. -// xxx : update description -pub trait ContainerValToEntry< Val > +/// This trait is particularly valuable in scenarios where the operations on a container require +/// not just the manipulation of values but also the re-integration of these values as entries. +/// It is especially crucial in complex data structures, such as `HashMap`s, where entries +/// often involve a key-value pair, and simple values need to be restructured to fit this model +/// for operations like insertion or update. + +pub trait ContainerValToEntry { + /// The specific type of entry that corresponds to the value within the container. + /// For example, in a `HashMap`, this might be a tuple of a key and a value. type Entry; - /// Converts a value back into an entry of the container. This function is essential for operations like insertion - /// or modification, where a value needs to be transformed into a container-compatible entry, such as converting - /// a value into a (key, value) tuple for insertion into a `HashMap`. - // xxx : update description + /// Converts a value into a container-specific entry, facilitating operations that modify + /// the container. This method is key for ensuring that values can be correctly integrated + /// back into the container, particularly when the entry type is more complex than the value. + /// + /// # Parameters + /// * `val` - The value to be converted into an entry. + /// + /// # Returns + /// Returns the entry constructed from the provided value, ready for insertion or other modifications. + /// + /// # Example + /// ``` + /// struct PairMap; + /// + /// impl ContainerValToEntry<(i32, i32)> for PairMap + /// { + /// type Entry = (String, i32); + /// + /// fn val_to_entry( val : (i32, i32) ) -> Self::Entry + /// { + /// (val.0.to_string(), val.1) + /// } + /// } + /// ``` fn val_to_entry( val : Val ) -> Self::Entry; } -/// Provides a mechanism for converting values back to container-specific entries. +/// Facilitates the conversion of values back into entries for specific container types. /// -/// This trait is crucial for operations that require the insertion or modification of entries based on values, -/// especially in complex data structures where the entry's structure is more intricate than the value it represents, -/// such as inserting a new entry in a `HashMap` where the entry consists of a key-value pair. -// xxx : update description -pub trait ValToEntry< Container > +/// This trait wraps the functionality of `ContainerValToEntry`, providing a more ergonomic +/// interface for converting values directly within the type they pertain to. It is useful +/// in maintaining the integrity of container operations, especially when dealing with +/// sophisticated structures that separate the concept of values and entries, such as `HashMap`s +/// and other associative containers. +pub trait ValToEntry { + /// Represents the type of entry that corresponds to the value within the container. type Entry; - /// Converts a value back into an entry of the container. This function is essential for operations like insertion - /// or modification, where a value needs to be transformed into a container-compatible entry, such as converting - /// a value into a (key, value) tuple for insertion into a `HashMap`. - // xxx : update description + /// Transforms the instance (value) into an entry compatible with the specified container. + /// This conversion is essential for operations like insertion or modification within the container, + /// where the value needs to be formatted as an entry. + /// + /// # Returns + /// Returns the entry constructed from the instance of the value, ready for integration into the container. + /// + /// # Example + /// ``` + /// impl ValToEntry for (i32, i32) + /// { + /// type Entry = (String, i32); + /// + /// fn val_to_entry( self ) -> Self::Entry + /// { + /// (self.0.to_string(), self.1) + /// } + /// } + /// ``` fn val_to_entry( self ) -> Self::Entry; } -impl< C, Val > ValToEntry< C > for Val +impl ValToEntry for Val where - C : ContainerValToEntry< Val >, + C : ContainerValToEntry, { type Entry = C::Entry; + /// Invokes the `val_to_entry` function of the `ContainerValToEntry` trait to convert the value to an entry. fn val_to_entry( self ) -> C::Entry { C::val_to_entry( self ) diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 532fe3f246..abc392cabb 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -63,19 +63,6 @@ where } } -// xxx : clean -// impl< K > ValToEntry< HashSet< K > > for K -// where -// K : core::cmp::Eq + core::hash::Hash, -// { -// type Entry = K; -// #[ inline( always ) ] -// fn val_to_entry( self ) -> Self::Entry -// { -// self -// } -// } - /// A trait for containers behaving like a `HashSet`, allowing insertion operations. /// /// Implementing this trait enables the associated formed to be used with `HashSetAsSubformer`, diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 105539f797..23f9bb303e 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -58,17 +58,6 @@ where } } -// xxx : clean -// impl< E > ValToEntry< collection_tools::Vec< E > > for E -// { -// type Entry = E; -// #[ inline( always ) ] -// fn val_to_entry( self ) -> Self::Entry -// { -// 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, From e19219e7dd8da87f53536aaa23be8a8625ddf6b7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 09:55:11 +0300 Subject: [PATCH 509/533] former : custom container example and test --- module/core/former/src/container.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 4ff11cf135..73a186a194 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -65,7 +65,7 @@ where /// often involve a key-value pair, and simple values need to be restructured to fit this model /// for operations like insertion or update. -pub trait ContainerValToEntry +pub trait ContainerValToEntry< Val > { /// The specific type of entry that corresponds to the value within the container. /// For example, in a `HashMap`, this might be a tuple of a key and a value. @@ -87,12 +87,12 @@ pub trait ContainerValToEntry /// /// impl ContainerValToEntry<(i32, i32)> for PairMap /// { - /// type Entry = (String, i32); + /// type Entry = (String, i32); /// - /// fn val_to_entry( val : (i32, i32) ) -> Self::Entry - /// { - /// (val.0.to_string(), val.1) - /// } + /// fn val_to_entry( val : (i32, i32) ) -> Self::Entry + /// { + /// (val.0.to_string(), val.1) + /// } /// } /// ``` fn val_to_entry( val : Val ) -> Self::Entry; @@ -105,7 +105,7 @@ pub trait ContainerValToEntry /// in maintaining the integrity of container operations, especially when dealing with /// sophisticated structures that separate the concept of values and entries, such as `HashMap`s /// and other associative containers. -pub trait ValToEntry +pub trait ValToEntry< Container > { /// Represents the type of entry that corresponds to the value within the container. type Entry; @@ -121,20 +121,20 @@ pub trait ValToEntry /// ``` /// impl ValToEntry for (i32, i32) /// { - /// type Entry = (String, i32); + /// type Entry = (String, i32); /// - /// fn val_to_entry( self ) -> Self::Entry - /// { - /// (self.0.to_string(), self.1) - /// } + /// fn val_to_entry( self ) -> Self::Entry + /// { + /// (self.0.to_string(), self.1) + /// } /// } /// ``` fn val_to_entry( self ) -> Self::Entry; } -impl ValToEntry for Val +impl< C, Val > ValToEntry< C > for Val where - C : ContainerValToEntry, + C : ContainerValToEntry< Val >, { type Entry = C::Entry; From 3a3beade8ecd51bd9ddf3446cc98852ae3facec6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 13:36:43 +0300 Subject: [PATCH 510/533] former : refactoring --- module/core/former/Readme.md | 59 +++++---- .../examples/former_custom_container.rs | 124 +++++++++--------- .../former_custom_container_setter.rs | 2 +- .../examples/former_subformer_hashmap.rs | 7 +- .../examples/former_subformer_hashset.rs | 3 +- .../former/examples/former_trivial_expaned.rs | 47 +++---- module/core/former/src/hash_map.rs | 5 +- module/core/former/src/hash_set.rs | 5 +- module/core/former/src/storage.rs | 12 +- module/core/former/src/vector.rs | 5 +- .../tests/inc/former_tests/a_basic_manual.rs | 4 +- .../inc/former_tests/a_containers_manual.rs | 4 +- .../inc/former_tests/a_primitives_manual.rs | 4 +- .../tests/inc/former_tests/only_test/basic.rs | 2 +- .../parametrized_struct_manual.rs | 4 +- .../inc/former_tests/string_slice_manual.rs | 4 +- .../subformer_container_custom.rs | 4 +- .../src/component/component_assign.rs | 8 +- .../src/component/component_from.rs | 8 +- .../src/component/components_assign.rs | 11 +- .../src/component/from_components.rs | 9 +- module/core/former_meta/src/derive_former.rs | 9 +- .../former_meta/src/derive_former/field.rs | 16 ++- module/core/macro_tools/src/diag.rs | 97 +++++++------- module/core/mod_interface_meta/src/impls.rs | 8 +- 25 files changed, 265 insertions(+), 196 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index bccad8b3b4..ffb46af7de 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -73,35 +73,35 @@ fn main() bio_optional : Option< String >, // Fields could be optional } - impl< > UserProfile< > + impl UserProfile where { #[ inline( always ) ] pub fn former() -> UserProfileFormer< - UserProfileFormerDefinition< (), UserProfile< >, former::ReturnPreformed > + UserProfileFormerDefinition< (), UserProfile, former::ReturnPreformed > > { - UserProfileFormer::< UserProfileFormerDefinition< (), UserProfile< >, former::ReturnPreformed > >:: + UserProfileFormer::< UserProfileFormerDefinition< (), UserProfile, former::ReturnPreformed > >:: new_coercing(former::ReturnPreformed) } } // = entity to - impl< Definition > former::EntityToFormer< Definition > for UserProfile< > + impl< Definition > former::EntityToFormer< Definition > for UserProfile where - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage >, { type Former = UserProfileFormer< Definition >; } - impl< > former::EntityToStorage for UserProfile< > + impl former::EntityToStorage for UserProfile where { - type Storage = UserProfileFormerStorage< >; + type Storage = UserProfileFormerStorage; } - impl< Context, Formed, End > former::EntityToDefinition< Context, Formed, End > for UserProfile< > + impl< Context, Formed, End > former::EntityToDefinition< Context, Formed, End > for UserProfile where End : former::FormingEnd< UserProfileFormerDefinitionTypes< Context, Formed > >, { @@ -111,7 +111,7 @@ fn main() // = definition #[derive(Debug)] - pub struct UserProfileFormerDefinitionTypes< Context = (), Formed = UserProfile< >, > + pub struct UserProfileFormerDefinitionTypes< Context = (), Formed = UserProfile, > where { _phantom : core::marker::PhantomData< (*const Context, *const Formed) >, @@ -132,13 +132,13 @@ fn main() impl< Context, Formed, > former::FormerDefinitionTypes for UserProfileFormerDefinitionTypes< Context, Formed, > where { - type Storage = UserProfileFormerStorage< >; + type Storage = UserProfileFormerStorage; type Formed = Formed; type Context = Context; } #[derive(Debug)] - pub struct UserProfileFormerDefinition< Context = (), Formed = UserProfile< >, End = former::ReturnPreformed, > + pub struct UserProfileFormerDefinition< Context = (), Formed = UserProfile, End = former::ReturnPreformed, > where { _phantom : core::marker::PhantomData< (*const Context, *const Formed, *const End) >, @@ -162,7 +162,7 @@ fn main() { type Types = UserProfileFormerDefinitionTypes< Context, Formed, >; type End = End; - type Storage = UserProfileFormerStorage< >; + type Storage = UserProfileFormerStorage; type Formed = Formed; type Context = Context; } @@ -173,7 +173,7 @@ fn main() // = storage - pub struct UserProfileFormerStorage< > + pub struct UserProfileFormerStorage where { pub age : ::core::option::Option< i32 >, @@ -181,7 +181,7 @@ fn main() pub bio_optional : Option< String >, } - impl< > ::core::default::Default for UserProfileFormerStorage< > + impl ::core::default::Default for UserProfileFormerStorage where { #[ inline( always ) ] @@ -196,16 +196,15 @@ fn main() } } - impl< > former::Storage for UserProfileFormerStorage< > + impl former::Storage for UserProfileFormerStorage where { - type Formed = UserProfile< >; + type Performed = UserProfile; } - impl< > former::StoragePreform for UserProfileFormerStorage< > + impl former::StoragePreform for UserProfileFormerStorage where { - type Preformed = UserProfile< >; fn preform(mut self) -> Self::Preformed { let age = if self.age.is_some() @@ -280,9 +279,9 @@ fn main() } } - pub struct UserProfileFormer< Definition = UserProfileFormerDefinition< (), UserProfile< >, former::ReturnPreformed >, > + pub struct UserProfileFormer< Definition = UserProfileFormerDefinition< (), UserProfile, former::ReturnPreformed >, > where - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage >, { pub storage : Definition::Storage, pub context : core::option::Option< Definition::Context >, @@ -291,7 +290,7 @@ fn main() impl< Definition, > UserProfileFormer< Definition, > where - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, Definition::Types : former::FormerDefinitionTypes< Storage = UserProfileFormerStorage< > >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage >, Definition::Types : former::FormerDefinitionTypes< Storage = UserProfileFormerStorage >, { #[ inline( always ) ] pub fn new(on_end : Definition::End) -> Self @@ -382,7 +381,7 @@ fn main() impl< Definition, > UserProfileFormer< Definition, > where - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< >, Formed = UserProfile< > >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage, Formed = UserProfile >, { pub fn preform(self) -> ::Formed { @@ -392,7 +391,7 @@ fn main() impl< Definition, > UserProfileFormer< Definition, > where - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< >, Formed = UserProfile< >, >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage, Formed = UserProfile, >, { #[ inline( always ) ] pub fn perform(self) -> Definition::Formed @@ -404,7 +403,7 @@ fn main() impl< Definition > former::FormerBegin< Definition > for UserProfileFormer< Definition, > where - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage >, { #[ inline( always ) ] fn former_begin(storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, on_end : Definition::End,) -> Self @@ -684,22 +683,25 @@ This example demonstrates the use of a `HashMapAsSubformer` to build a hash map #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { + use collection_tools::{ HashMap, hmap }; #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithMap { #[ container ] - map : collection_tools::HashMap< &'static str, &'static str >, + map : HashMap< &'static str, &'static str >, } - let struct1 = StructWithMap::former() + let instance = StructWithMap::former() .map() .add( ( "a", "b" ) ) .add( ( "c", "d" ) ) .end() .form() ; - assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); + assert_eq!( instance, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); + dbg!( instance ); + } ``` @@ -711,12 +713,13 @@ In the following example, a `HashSetAsSubformer` is utilized to construct a hash #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { + use collection_tools::{ HashSet, hset }; #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithSet { #[ container ] - set : collection_tools::HashSet< &'static str >, + set : HashSet< &'static str >, } let instance = StructWithSet::former() diff --git a/module/core/former/examples/former_custom_container.rs b/module/core/former/examples/former_custom_container.rs index f4fb36dce2..0195042304 100644 --- a/module/core/former/examples/former_custom_container.rs +++ b/module/core/former/examples/former_custom_container.rs @@ -1,70 +1,70 @@ -/// Example former_custom_container.rs -/// -/// Container interface is defined in the crate and implemented for containers like vectors, hash maps, etc, but if you want to use non-standard container you can implement container interface for the container. This example demonstrate how to do that. +//! Example former_custom_container.rs +//! +//! Container interface is defined in the crate and implemented for containers like vectors, hash maps, etc, but if you want to use non-standard container you can implement container interface for the container. This example demonstrate how to do that. // xxx2 : get completed -#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] -fn main() {} -#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] -fn main() -{ - use collection_tools::HashSet; - use std::fmt; - - // = define custom container - - // Custom container that logs additions - #[ derive( Default ) ] - pub struct LoggingSet< T > - { - set : HashSet< T >, - } - -// // Implementing the container traits for LoggingSet -// impl former::Container for LoggingSet +// #[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +// fn main() {} +// #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +// fn main() +// { +// use collection_tools::HashSet; +// use std::fmt; +// +// // = define custom container +// +// // Custom container that logs additions +// #[ derive( Default ) ] +// pub struct LoggingSet< T > // { -// type Entry = T; -// type Val = T; +// set : HashSet< T >, +// } // -// fn entry_to_val(e: Self::Entry) -> Self::Val +// // // Implementing the container traits for LoggingSet +// // impl former::Container for LoggingSet +// // { +// // type Entry = T; +// // type Val = T; +// // +// // fn entry_to_val(e: Self::Entry) -> Self::Val +// // { +// // e // In this simple case, entry and value are the same. +// // } +// // } +// +// // This trait allows adding entries to the LoggingSet +// impl< T : Eq + std::hash::Hash + fmt::Debug > former::ContainerAdd +// for LoggingSet< T > +// { +// fn add(&mut self, e: Self::Entry) -> bool // { -// e // In this simple case, entry and value are the same. +// let result = self.set.insert(e); +// if result { +// println!("{:?} was added to the set", e); +// } +// result // } // } - - // This trait allows adding entries to the LoggingSet - impl< T : Eq + std::hash::Hash + fmt::Debug > former::ContainerAdd - for LoggingSet< T > - { - fn add(&mut self, e: Self::Entry) -> bool - { - let result = self.set.insert(e); - if result { - println!("{:?} was added to the set", e); - } - result - } - } - - // = use custom container - - // Define a struct to use with Former - #[derive(Debug, PartialEq, former::Former)] - pub struct CollectionContainer - { - #[container] - data: LoggingSet, - } - - // Using the builder pattern provided by Former to manipulate CollectionContainer - let mut container = CollectionContainer::former().data(); - - container.add(10); - container.add(20); - container.add(10); // This will not be added again, and "add" will log the attempt. - - let final_container = container.end().form(); - - println!("Final container: {:?}", final_container); -} \ No newline at end of file +// +// // = use custom container +// +// // Define a struct to use with Former +// #[derive(Debug, PartialEq, former::Former)] +// pub struct CollectionContainer +// { +// #[container] +// data: LoggingSet, +// } +// +// // Using the builder pattern provided by Former to manipulate CollectionContainer +// let mut container = CollectionContainer::former().data(); +// +// container.add(10); +// container.add(20); +// container.add(10); // This will not be added again, and "add" will log the attempt. +// +// let final_container = container.end().form(); +// +// println!("Final container: {:?}", final_container); +// } diff --git a/module/core/former/examples/former_custom_container_setter.rs b/module/core/former/examples/former_custom_container_setter.rs index f2668bcfe8..aece8ce9b4 100644 --- a/module/core/former/examples/former_custom_container_setter.rs +++ b/module/core/former/examples/former_custom_container_setter.rs @@ -38,7 +38,7 @@ fn main() // Parent struct to hold children #[ derive( Debug, PartialEq, Former ) ] - // #[ debug ] + #[ debug ] pub struct Parent { // Use `hint = true` to gennerate sketch of setter. diff --git a/module/core/former/examples/former_subformer_hashmap.rs b/module/core/former/examples/former_subformer_hashmap.rs index aa0a0836e1..8908adc7ab 100644 --- a/module/core/former/examples/former_subformer_hashmap.rs +++ b/module/core/former/examples/former_subformer_hashmap.rs @@ -7,22 +7,23 @@ fn main() {} #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { + use collection_tools::{ HashMap, hmap }; #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithMap { #[ container ] - map : collection_tools::HashMap< &'static str, &'static str >, + map : HashMap< &'static str, &'static str >, } - let struct1 = StructWithMap::former() + let instance = StructWithMap::former() .map() .add( ( "a", "b" ) ) .add( ( "c", "d" ) ) .end() .form() ; - assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); + assert_eq!( instance, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); dbg!( instance ); } diff --git a/module/core/former/examples/former_subformer_hashset.rs b/module/core/former/examples/former_subformer_hashset.rs index 92ee6889e8..2c76d24a0a 100644 --- a/module/core/former/examples/former_subformer_hashset.rs +++ b/module/core/former/examples/former_subformer_hashset.rs @@ -7,12 +7,13 @@ fn main() {} #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() { + use collection_tools::{ HashSet, hset }; #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithSet { #[ container ] - set : collection_tools::HashSet< &'static str >, + set : HashSet< &'static str >, } let instance = StructWithSet::former() diff --git a/module/core/former/examples/former_trivial_expaned.rs b/module/core/former/examples/former_trivial_expaned.rs index 984f8811cb..484f19262b 100644 --- a/module/core/former/examples/former_trivial_expaned.rs +++ b/module/core/former/examples/former_trivial_expaned.rs @@ -32,32 +32,32 @@ fn main() bio_optional : Option< String >, // Fields could be optional } - impl< > UserProfile< > + impl UserProfile where { #[ inline( always ) ] pub fn former() -> UserProfileFormer< - UserProfileFormerDefinition< (), UserProfile< >, former::ReturnPreformed > + UserProfileFormerDefinition< (), UserProfile, former::ReturnPreformed > > { - UserProfileFormer::< UserProfileFormerDefinition< (), UserProfile< >, former::ReturnPreformed > >:: + UserProfileFormer::< UserProfileFormerDefinition< (), UserProfile, former::ReturnPreformed > >:: new_coercing(former::ReturnPreformed) } } // = entity to - impl< Definition > former::EntityToFormer< Definition > for UserProfile< > + impl< Definition > former::EntityToFormer< Definition > for UserProfile where - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage >, { type Former = UserProfileFormer< Definition >; } - impl< > former::EntityToStorage for UserProfile< > + impl former::EntityToStorage for UserProfile where { - type Storage = UserProfileFormerStorage< >; + type Storage = UserProfileFormerStorage; } impl< Context, Formed, End > former::EntityToDefinition< Context, Formed, End > for UserProfile< > @@ -65,12 +65,13 @@ fn main() End : former::FormingEnd< UserProfileFormerDefinitionTypes< Context, Formed > >, { type Definition = UserProfileFormerDefinition< Context, Formed, End >; + type Types = UserProfileFormerDefinitionTypes< Context, Formed >; } // = definition #[derive(Debug)] - pub struct UserProfileFormerDefinitionTypes< Context = (), Formed = UserProfile< >, > + pub struct UserProfileFormerDefinitionTypes< Context = (), Formed = UserProfile, > where { _phantom : core::marker::PhantomData< (*const Context, *const Formed) >, @@ -91,13 +92,13 @@ fn main() impl< Context, Formed, > former::FormerDefinitionTypes for UserProfileFormerDefinitionTypes< Context, Formed, > where { - type Storage = UserProfileFormerStorage< >; + type Storage = UserProfileFormerStorage; type Formed = Formed; type Context = Context; } #[derive(Debug)] - pub struct UserProfileFormerDefinition< Context = (), Formed = UserProfile< >, End = former::ReturnPreformed, > + pub struct UserProfileFormerDefinition< Context = (), Formed = UserProfile, End = former::ReturnPreformed, > where { _phantom : core::marker::PhantomData< (*const Context, *const Formed, *const End) >, @@ -121,7 +122,7 @@ fn main() { type Types = UserProfileFormerDefinitionTypes< Context, Formed, >; type End = End; - type Storage = UserProfileFormerStorage< >; + type Storage = UserProfileFormerStorage; type Formed = Formed; type Context = Context; } @@ -132,7 +133,7 @@ fn main() // = storage - pub struct UserProfileFormerStorage< > + pub struct UserProfileFormerStorage where { pub age : ::core::option::Option< i32 >, @@ -140,7 +141,7 @@ fn main() pub bio_optional : Option< String >, } - impl< > ::core::default::Default for UserProfileFormerStorage< > + impl ::core::default::Default for UserProfileFormerStorage where { #[ inline( always ) ] @@ -155,16 +156,16 @@ fn main() } } - impl< > former::Storage for UserProfileFormerStorage< > + impl former::Storage for UserProfileFormerStorage where { - type Formed = UserProfile< >; + type Preformed = UserProfile; } - impl< > former::StoragePreform for UserProfileFormerStorage< > + impl former::StoragePreform for UserProfileFormerStorage where { - type Preformed = UserProfile< >; + // type Preformed = UserProfile; fn preform(mut self) -> Self::Preformed { let age = if self.age.is_some() @@ -239,9 +240,9 @@ fn main() } } - pub struct UserProfileFormer< Definition = UserProfileFormerDefinition< (), UserProfile< >, former::ReturnPreformed >, > + pub struct UserProfileFormer< Definition = UserProfileFormerDefinition< (), UserProfile, former::ReturnPreformed >, > where - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage >, { pub storage : Definition::Storage, pub context : core::option::Option< Definition::Context >, @@ -250,7 +251,7 @@ fn main() impl< Definition, > UserProfileFormer< Definition, > where - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, Definition::Types : former::FormerDefinitionTypes< Storage = UserProfileFormerStorage< > >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage >, Definition::Types : former::FormerDefinitionTypes< Storage = UserProfileFormerStorage >, { #[ inline( always ) ] pub fn new(on_end : Definition::End) -> Self @@ -341,7 +342,7 @@ fn main() impl< Definition, > UserProfileFormer< Definition, > where - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< >, Formed = UserProfile< > >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage, Formed = UserProfile >, { pub fn preform(self) -> ::Formed { @@ -351,7 +352,7 @@ fn main() impl< Definition, > UserProfileFormer< Definition, > where - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< >, Formed = UserProfile< >, >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage, Formed = UserProfile, >, { #[ inline( always ) ] pub fn perform(self) -> Definition::Formed @@ -363,7 +364,7 @@ fn main() impl< Definition > former::FormerBegin< Definition > for UserProfileFormer< Definition, > where - Definition : former::FormerDefinition< Storage = UserProfileFormerStorage< > >, + Definition : former::FormerDefinition< Storage = UserProfileFormerStorage >, { #[ inline( always ) ] fn former_begin(storage : core::option::Option< Definition::Storage >, context : core::option::Option< Definition::Context >, on_end : Definition::End,) -> Self diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 150d586742..4dbb3ba299 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -89,7 +89,8 @@ where K : ::core::cmp::Eq + ::core::hash::Hash, { // type Types = HashMapDefinition< K, E >; - type Formed = HashMap< K, E >; + // type Formed = HashMap< K, E >; + type Preformed = HashMap< K, E >; } impl< K, E > StoragePreform @@ -97,7 +98,7 @@ for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Preformed = HashMap< K, E >; + // type Preformed = HashMap< K, E >; // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed fn preform( self ) -> Self::Preformed { diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index abc392cabb..57b6670dcd 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -98,7 +98,8 @@ for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Formed = HashSet< K >; + // type Formed = HashSet< K >; + type Preformed = HashSet< K >; } impl< K > StoragePreform @@ -106,7 +107,7 @@ for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Preformed = HashSet< K >; + // type Preformed = HashSet< K >; fn preform( self ) -> Self::Preformed { self diff --git a/module/core/former/src/storage.rs b/module/core/former/src/storage.rs index b4a65ef38a..02e20e78d5 100644 --- a/module/core/former/src/storage.rs +++ b/module/core/former/src/storage.rs @@ -19,8 +19,10 @@ /// to a default state at the start of the forming process. pub trait Storage : ::core::default::Default { - /// The type of the fully formed entity that results from the forming process. - type Formed; + /// The type of the entity as it should appear once preformed. It could, but does not have to be the same type as `Formed`. + type Preformed; + // /// The type of the fully formed entity that results from the forming process. + // type Formed; } /// Provides a mechanism to finalize the forming process by converting storage into its final formed state. @@ -32,10 +34,10 @@ pub trait Storage : ::core::default::Default /// state of the entity. However, it can differ if a custom `FormingEnd` or a different `Formed` type /// is defined to handle specific forming logic or requirements. /// But even if `Formed` is custom `Preformed` is always that structure. -pub trait StoragePreform +pub trait StoragePreform : Storage { - /// The type of the entity as it should appear once fully formed. - type Preformed; + // /// The type of the entity as it should appear once fully formed. + // type Preformed; /// Transforms the storage into the final formed state of the entity. /// diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index 23f9bb303e..ee7624e7b7 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -82,13 +82,14 @@ impl< E > VectorLike< E > for Vec< E > impl< E > Storage for Vec< E > { - type Formed = Vec< E >; + // type Formed = Vec< E >; + type Preformed = Vec< E >; } impl< E > StoragePreform for Vec< E > { - type Preformed = Vec< E >; + // type Preformed = Vec< E >; // fn preform( self ) -> Self::Formed fn preform( self ) -> Self::Preformed { diff --git a/module/core/former/tests/inc/former_tests/a_basic_manual.rs b/module/core/former/tests/inc/former_tests/a_basic_manual.rs index 0503af0f9e..4e0fd2aebc 100644 --- a/module/core/former/tests/inc/former_tests/a_basic_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_basic_manual.rs @@ -128,12 +128,12 @@ impl ::core::default::Default for Struct1FormerStorage impl former::Storage for Struct1FormerStorage { - type Formed = Struct1; + type Preformed = Struct1; } impl former::StoragePreform for Struct1FormerStorage { - type Preformed = < Self as former::Storage >::Formed; + // type Preformed = < Self as former::Storage >::Formed; fn preform( mut self ) -> Self::Preformed { let int_1 = if self.int_1.is_some() diff --git a/module/core/former/tests/inc/former_tests/a_containers_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_manual.rs index c5f7350a3b..8f0e35deea 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_manual.rs @@ -135,13 +135,13 @@ where impl< > former::Storage for Struct1FormerStorage<> where { - type Formed = Struct1<>; + type Preformed = Struct1<>; } impl< > former::StoragePreform for Struct1FormerStorage<> where { - type Preformed = Struct1<>; + // type Preformed = Struct1<>; fn preform(mut self) -> Self::Preformed { diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index f28e97ea81..82c3a0bbf9 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -119,13 +119,13 @@ impl Default for Struct1FormerStorage impl former::Storage for Struct1FormerStorage { - type Formed = Struct1; + type Preformed = Struct1; } impl former::StoragePreform for Struct1FormerStorage { - type Preformed = Struct1; + // type Preformed = Struct1; // fn preform( mut self ) -> < Self as former::Storage >::Formed fn preform( mut self ) -> Self::Preformed diff --git a/module/core/former/tests/inc/former_tests/only_test/basic.rs b/module/core/former/tests/inc/former_tests/only_test/basic.rs index 9a07de6bde..a4b4dbf907 100644 --- a/module/core/former/tests/inc/former_tests/only_test/basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/basic.rs @@ -485,7 +485,7 @@ tests_impls! a_id!( got, exp ); // storage exists - let got = < Struct1FormerStorage as the_module::Storage >::Formed::former().form(); + let got = < Struct1FormerStorage as the_module::Storage >::Preformed::former().form(); let exp = Struct1::former().form(); a_id!( got, exp ); diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 6f8901a3a5..62c1eddc03 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -151,12 +151,12 @@ impl< K, > :: core :: default :: Default for ChildFormerStorage< K, > where K : impl< K, > former :: Storage for ChildFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, { - type Formed = Child< K, >; + type Preformed = Child< K, >; } impl< K, > former :: StoragePreform for ChildFormerStorage< K, > where K : core :: hash :: Hash + std :: cmp :: Eq, { - type Preformed = Child< K, >; + // type Preformed = Child< K, >; fn preform( mut self ) -> Self::Preformed // fn preform( mut self ) -> < Self as former :: Storage > :: Formed diff --git a/module/core/former/tests/inc/former_tests/string_slice_manual.rs b/module/core/former/tests/inc/former_tests/string_slice_manual.rs index 85d3dbc414..6b9632f366 100644 --- a/module/core/former/tests/inc/former_tests/string_slice_manual.rs +++ b/module/core/former/tests/inc/former_tests/string_slice_manual.rs @@ -102,12 +102,12 @@ impl< 'a > ::core::default::Default for Struct1FormerStorage< 'a > impl< 'a > former::Storage for Struct1FormerStorage< 'a > { - type Formed = Struct1< 'a >; + type Preformed = Struct1< 'a >; } impl< 'a > former::StoragePreform for Struct1FormerStorage< 'a > { - type Preformed = Struct1< 'a >; + // type Preformed = Struct1< 'a >; fn preform( mut self ) -> Self::Preformed // fn preform( mut self ) -> < Self as former::Storage >::Formed diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index 90a5315443..6d93805bf0 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -130,7 +130,7 @@ for LoggingSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Formed = LoggingSet< K >; + type Preformed = LoggingSet< K >; // xxx : rid off Formed maybe? } @@ -139,7 +139,7 @@ for LoggingSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - type Preformed = LoggingSet< K >; + // type Preformed = LoggingSet< K >; fn preform( self ) -> Self::Preformed { self diff --git a/module/core/former_meta/src/component/component_assign.rs b/module/core/former_meta/src/component/component_assign.rs index 1120c9da64..4677f27b0f 100644 --- a/module/core/former_meta/src/component/component_assign.rs +++ b/module/core/former_meta/src/component/component_assign.rs @@ -23,9 +23,15 @@ pub fn component_assign( input : proc_macro::TokenStream ) -> Result< proc_macro if has_debug { - diag::debug_report_print( "derive : ComponentAssign", original_input, &result ); + let about = format!( "derive : ComponentAssign\nstructure : {0}", &parsed.item_name ); + diag::report_print( about, &original_input, &result ); } + // if has_debug + // { + // diag::report_print( "derive : ComponentAssign", original_input, &result ); + // } + Ok( result ) } diff --git a/module/core/former_meta/src/component/component_from.rs b/module/core/former_meta/src/component/component_from.rs index dda6740aa5..994206b996 100644 --- a/module/core/former_meta/src/component/component_from.rs +++ b/module/core/former_meta/src/component/component_from.rs @@ -22,9 +22,15 @@ pub fn component_from( input : proc_macro::TokenStream ) -> Result< proc_macro2: if has_debug { - diag::debug_report_print( "derive : ComponentFrom", original_input, &result ); + let about = format!( "derive : ComponentFrom\nstructure : {0}", &parsed.item_name ); + diag::report_print( about, &original_input, &result ); } + // if has_debug + // { + // diag::report_print( "derive : ComponentFrom", original_input, &result ); + // } + Ok( result ) } diff --git a/module/core/former_meta/src/component/components_assign.rs b/module/core/former_meta/src/component/components_assign.rs index ac4ecac166..bcf5cc0bc9 100644 --- a/module/core/former_meta/src/component/components_assign.rs +++ b/module/core/former_meta/src/component/components_assign.rs @@ -16,7 +16,7 @@ pub fn components_assign( input : proc_macro::TokenStream ) -> Result< proc_macr let has_debug = attr::has_debug( parsed.item.attrs.iter() )?; // name - let item_name = parsed.item_name; + let item_name = &parsed.item_name; let trait_name = format!( "{}ComponentsAssign", item_name ); let trait_ident = syn::Ident::new( &trait_name, item_name.span() ); let method_name = format!( "{}_assign", item_name.to_string().to_case( Case::Snake ) ); @@ -68,8 +68,15 @@ pub fn components_assign( input : proc_macro::TokenStream ) -> Result< proc_macr if has_debug { - diag::debug_report_print( "derive : ComponentsAssign", original_input, &result ); + let about = format!( "derive : ComponentsAssign\nstructure : {0}", item_name ); + diag::report_print( about, &original_input, &result ); } + + // if has_debug + // { + // diag::report_print( "derive : ComponentsAssign", original_input, &result ); + // } + Ok( result ) } diff --git a/module/core/former_meta/src/component/from_components.rs b/module/core/former_meta/src/component/from_components.rs index b7d1d9f58f..62ae0615a9 100644 --- a/module/core/former_meta/src/component/from_components.rs +++ b/module/core/former_meta/src/component/from_components.rs @@ -69,8 +69,15 @@ pub fn from_components( input : proc_macro::TokenStream ) -> Result< proc_macro2 if has_debug { - diag::debug_report_print( "derive : FromComponents", original_input, &result ); + let about = format!( "derive : FromComponents\nstructure : {0}", &parsed.item_name ); + diag::report_print( about, &original_input, &result ); } + + // if has_debug + // { + // diag::report_print( "derive : FromComponents", original_input, &result ); + // } + Ok( result.into() ) } diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index d42490dbac..69ad902e9b 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -311,6 +311,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > &former_generics_ty, &former_generics_where, &former_storage, + &original_input, ), )}).multiunzip(); @@ -502,7 +503,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where #struct_generics_where { - type Formed = #stru < #struct_generics_ty >; + type Preformed = #stru < #struct_generics_ty >; } impl < #struct_generics_impl > former::StoragePreform @@ -510,7 +511,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > where #struct_generics_where { - type Preformed = #stru < #struct_generics_ty >; + // type Preformed = #stru < #struct_generics_ty >; fn preform( mut self ) -> Self::Preformed { @@ -776,7 +777,9 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > if has_debug { - diag::debug_report_print( "derive : Former", original_input, &result ); + let about = format!( "derive : Former\nstructure : {stru}" ); + diag::report_print( about, &original_input, &result ); + // diag::report_print( "derive : Former", original_input, &result ); } Ok( result ) diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 66a84f5350..d3d87c99ce 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -340,6 +340,7 @@ scalar_setter_required former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, former_storage : &syn::Ident, + original_input : &proc_macro::TokenStream, ) -> Result< ( TokenStream, TokenStream ) > { @@ -361,6 +362,7 @@ scalar_setter_required former_generics_impl, former_generics_ty, former_generics_where, + original_input, )?; ( qt! { #setters_code #setters_code2 }, qt! { #namespace_code #namespace_code2 } ) } @@ -675,6 +677,7 @@ formation process of the `{stru}`. former_generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, former_generics_where : &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, + original_input : &proc_macro::TokenStream, ) -> Result< ( TokenStream, TokenStream ) > { @@ -861,7 +864,18 @@ where former_assign_end, field_assign, ); - println!( "{hint}" ); + let about = format! + ( +r#"derive : Former +structure : {stru} +field : {field_ident}"#, + // format!( "{}", qt!{ #setter_name } ), + ); + // xxx + // diag::report_print( about, original_input, hint ); + // print!( "{}", diag::report_format( about, original_input, hint ) ); + diag::report_print( about, original_input, hint ); + // println!( "{hint}" ); } let setters_code = qt! diff --git a/module/core/macro_tools/src/diag.rs b/module/core/macro_tools/src/diag.rs index f35ab49712..739d92f527 100644 --- a/module/core/macro_tools/src/diag.rs +++ b/module/core/macro_tools/src/diag.rs @@ -86,39 +86,43 @@ pub( crate ) mod private result } - /// Formats a debugging report for a pair of token streams, showing the original and generated code. + /// Formats a debugging report for code transformation processes, detailing both the original and generated code for easy comparison and review. /// - /// This function takes two inputs: the original code as an `IntoTokens` (which can be converted into a `proc_macro2::TokenStream`), - /// and the generated code as a `proc_macro2::TokenStream`. It formats both inputs with indentation for better readability, - /// labeling them as "original" and "generated" respectively. + /// This function creates a structured report comprising the initial input code, the resulting generated code, and an explanatory context. It is designed to facilitate debugging and documentation of code transformations, such as those performed in procedural macros or similar code generation tasks. The report categorizes the information into labeled sections to enhance readability and traceability. /// - /// Ensure the correct conversion of `proc_macro::TokenStream` to `proc_macro2::TokenStream` where necessary, - /// especially when interfacing with procedural macros' `input` parameter + /// This function helps visualize the changes from the original to the generated code, assisting developers in verifying and understanding the transformations applied during code generation processes. /// /// # Parameters - /// - `input`: The original input code that can be converted into a `proc_macro2::TokenStream`. - /// - `output`: The generated code as a `proc_macro2::TokenStream`. /// - /// # Returns - /// A `String` containing the formatted debug report. + /// - `about` : A description or context explaining the purpose or nature of the transformation. This information is displayed at the beginning of the report to provide an overview of the code transformation context. + /// - `input` : The original code before transformation. This is typically the code that is subject to processing by macros or other code generation tools. + /// - `output` : The code generated as a result of the transformation. This reflects the changes or enhancements made to the original code. /// /// # Type Parameters - /// - `IntoTokens`: A type that can be converted into a `proc_macro2::TokenStream`. + /// + /// - `IntoAbout` : A type that can be converted into a string representation, providing a descriptive context for the report. + /// - `IntoInput` : A type representing the original code, which can be converted into a string format for display. + /// - `IntoOutput` : A type representing the generated code, which can be converted into a string format for display. + /// + /// # Returns + /// + /// A string containing the formatted debug report, organized into sections with appropriate labels and indentation to distinguish between the original and generated code segments. /// /// # Examples + /// /// ``` /// use macro_tools::exposed::*; /// - /// let original_input : proc_macro2::TokenStream = qt! + /// let original_input : proc_macro2::TokenStream = quote! /// { - /// #[ derive( Debug, PartialEq ) ] + /// #[derive(Debug, PartialEq)] /// pub struct MyStruct /// { /// pub field : i32, /// } /// }; /// - /// let generated_code : proc_macro2::TokenStream = qt! + /// let generated_code : proc_macro2::TokenStream = quote! /// { /// impl MyStruct /// { @@ -130,52 +134,55 @@ pub( crate ) mod private /// }; /// /// // Format the debug report for printing or logging - /// let formatted_report = debug_report_format( "derive :: MyDerive", original_input, &generated_code ); + /// let formatted_report = report_format( "Code Transformation for MyStruct", original_input, generated_code ); /// println!( "{}", formatted_report ); /// ``` /// - /// This will output a formatted report showing the original input code and the generated code side by side, - /// each line indented for clarity. - /// - pub fn debug_report_format< IntoAbout, IntoTokens > + + pub fn report_format< IntoAbout, IntoInput, IntoOutput > ( - about : IntoAbout, input : IntoTokens, output : &proc_macro2::TokenStream + about : IntoAbout, input : IntoInput, output : IntoOutput ) -> String where - IntoAbout : Into< String >, - // xxx : qqq : use AsRef<> - IntoTokens : Into< proc_macro2::TokenStream >, + IntoAbout : ToString, + IntoInput : ToString, + IntoOutput : ToString, { format!( "\n" ) + - &format!( " = context\n\n{}\n\n", indentation( " ", about.into(), "" ) ) + - &format!( " = original\n\n{}\n\n", indentation( " ", input.into().to_string(), "" ) ) + - &format!( " = generated\n\n{}\n", indentation( " ", qt!{ #output }.to_string(), "" ) ) + &format!( " = context\n\n{}\n\n", indentation( " ", about.to_string(), "" ) ) + + &format!( " = original\n\n{}\n\n", indentation( " ", input.to_string(), "" ) ) + + &format!( " = generated\n\n{}\n", indentation( " ", output.to_string(), "" ) ) } /// Prints a debugging report for a pair of token streams to the standard output. /// - /// This convenience function wraps `debug_report_format`, directly printing the formatted report to stdout. - /// It serves as a utility for debugging procedural macros, providing a clear comparison between original - /// and generated code. + /// This function acts as a utility for debugging transformations in procedural macros or other code generation scenarios. + /// It provides an immediate visual comparison of the original code versus the generated code by utilizing the `report_format` + /// function to format the output and then printing it directly to the standard output. This can be particularly helpful for + /// real-time debugging and quick assessments without requiring additional output management. /// /// # Parameters and Type Parameters - /// - Same as `debug_report_format`. + /// - `about` : A description of the code transformation context or operation. This is used to headline the generated report. + /// - `input` : The original code or token stream before transformation. This is what the code looked like prior to any procedural manipulations. + /// - `output` : The transformed or generated code or token stream as a result of the macro or code transformation process. + /// + /// The types for these parameters are expected to be convertible to strings, matching the `report_format` function's requirements. /// /// # Examples /// - /// ``` + /// ```rust /// use macro_tools::exposed::*; /// - /// let original_input : proc_macro2::TokenStream = qt! + /// let original_input : proc_macro2::TokenStream = quote! /// { - /// #[ derive( Debug, PartialEq ) ] + /// #[derive(Debug, PartialEq)] /// pub struct MyStruct /// { /// pub field : i32, /// } /// }; /// - /// let generated_code : proc_macro2::TokenStream = qt! + /// let generated_code : proc_macro2::TokenStream = quote! /// { /// impl MyStruct /// { @@ -187,21 +194,23 @@ pub( crate ) mod private /// }; /// /// // Directly print the debug report - /// debug_report_print( "derive :: MyDerive", original_input, &generated_code ); + /// report_print( "Code Transformation for MyStruct", original_input, generated_code ); /// ``` /// - /// This will output a formatted report showing the original input code and the generated code side by side, - /// each line indented for clarity. + /// The above example demonstrates how the `report_print` function can be used to visualize the changes from original input code to the generated code, + /// helping developers to verify and understand the modifications made during code generation processes. The output is formatted to show clear distinctions + /// between the 'original' and 'generated' sections, providing an easy-to-follow comparison. - pub fn debug_report_print< IntoAbout, IntoTokens > + pub fn report_print< IntoAbout, IntoInput, IntoOutput > ( - about : IntoAbout, input : IntoTokens, output : &proc_macro2::TokenStream + about : IntoAbout, input : IntoInput, output : IntoOutput ) where - IntoAbout : Into< String >, - IntoTokens : Into< proc_macro2::TokenStream >, + IntoAbout : ToString, + IntoInput : ToString, + IntoOutput : ToString, { - println!( "{}", debug_report_format( about, input, output ) ); + println!( "{}", report_format( about, input, output ) ); } /// @@ -408,8 +417,8 @@ pub mod exposed { Result, indentation, - debug_report_format, - debug_report_print, + report_format, + report_print, }; } diff --git a/module/core/mod_interface_meta/src/impls.rs b/module/core/mod_interface_meta/src/impls.rs index 1538fb42e4..0f4608e420 100644 --- a/module/core/mod_interface_meta/src/impls.rs +++ b/module/core/mod_interface_meta/src/impls.rs @@ -460,9 +460,15 @@ pub( crate ) mod private if has_debug { - diag::debug_report_print( "derive : mod_interface", original_input, &result ); + let about = format!( "derive : mod_interface" ); + diag::report_print( about, &original_input, &result ); } + // if has_debug + // { + // diag::report_print( "derive : mod_interface", original_input, &result ); + // } + Ok( result ) } From b392f1216a53062e9d6cfeec470c89abb33fdfc6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 13:39:04 +0300 Subject: [PATCH 511/533] former : refactoring --- .../core/former/examples/former_custom_container_setter.rs | 6 ++++-- module/core/former/examples/former_custom_scalar_setter.rs | 2 ++ .../core/former/examples/former_custom_subform_setter.rs | 2 ++ .../core/former/examples/former_custom_subform_setter2.rs | 2 ++ module/core/former/examples/former_debug.rs | 2 +- module/core/former/examples/former_trivial.rs | 1 + module/core/former_meta/src/derive_former/field.rs | 7 +------ 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/module/core/former/examples/former_custom_container_setter.rs b/module/core/former/examples/former_custom_container_setter.rs index aece8ce9b4..94e11dbecc 100644 --- a/module/core/former/examples/former_custom_container_setter.rs +++ b/module/core/former/examples/former_custom_container_setter.rs @@ -29,6 +29,7 @@ fn main() // Child struct with Former derived for builder pattern support #[ derive( Debug, PartialEq, Former ) ] + // Use `#[ debug ]` to expand and debug generate code. // #[ debug ] pub struct Child { @@ -38,11 +39,12 @@ fn main() // Parent struct to hold children #[ derive( Debug, PartialEq, Former ) ] - #[ debug ] + // Use `#[ debug ]` to expand and debug generate code. + // #[ debug ] pub struct Parent { // Use `hint = true` to gennerate sketch of setter. - #[ container( setter = false, hint = true ) ] + #[ container( setter = false, hint = false ) ] children : HashMap< String, Child >, } diff --git a/module/core/former/examples/former_custom_scalar_setter.rs b/module/core/former/examples/former_custom_scalar_setter.rs index d09f3a77d9..5005383cd0 100644 --- a/module/core/former/examples/former_custom_scalar_setter.rs +++ b/module/core/former/examples/former_custom_scalar_setter.rs @@ -30,6 +30,7 @@ fn main() // Child struct with Former derived for builder pattern support #[ derive( Debug, PartialEq, Former ) ] + // Use `#[ debug ]` to expand and debug generate code. // #[ debug ] pub struct Child { @@ -39,6 +40,7 @@ fn main() // Parent struct to hold children #[ derive( Debug, PartialEq, Former ) ] + // Use `#[ debug ]` to expand and debug generate code. // #[ debug ] pub struct Parent { diff --git a/module/core/former/examples/former_custom_subform_setter.rs b/module/core/former/examples/former_custom_subform_setter.rs index 6061c61718..7855c51886 100644 --- a/module/core/former/examples/former_custom_subform_setter.rs +++ b/module/core/former/examples/former_custom_subform_setter.rs @@ -30,6 +30,7 @@ fn main() // Child struct with Former derived for builder pattern support #[ derive( Debug, PartialEq, Former ) ] + // Use `#[ debug ]` to expand and debug generate code. // #[ debug ] pub struct Child { @@ -39,6 +40,7 @@ fn main() // Parent struct to hold children #[ derive( Debug, PartialEq, Former ) ] + // Use `#[ debug ]` to expand and debug generate code. // #[ debug ] pub struct Parent { diff --git a/module/core/former/examples/former_custom_subform_setter2.rs b/module/core/former/examples/former_custom_subform_setter2.rs index 08583a85b7..7c781d6128 100644 --- a/module/core/former/examples/former_custom_subform_setter2.rs +++ b/module/core/former/examples/former_custom_subform_setter2.rs @@ -31,6 +31,7 @@ fn main() // Child struct with Former derived for builder pattern support #[ derive( Clone, Debug, PartialEq, Former ) ] + // Use `#[ debug ]` to expand and debug generate code. // #[ debug ] pub struct Child { @@ -40,6 +41,7 @@ fn main() // Parent struct to hold children #[ derive( Debug, PartialEq, Former ) ] + // Use `#[ debug ]` to expand and debug generate code. // #[ debug ] pub struct Parent { diff --git a/module/core/former/examples/former_debug.rs b/module/core/former/examples/former_debug.rs index 0a849f684a..8d610eae3c 100644 --- a/module/core/former/examples/former_debug.rs +++ b/module/core/former/examples/former_debug.rs @@ -13,8 +13,8 @@ fn main() #[ derive( Debug, PartialEq, Former ) ] + // Use `#[ debug ]` to expand and debug generate code. // #[ debug ] - // Uncomment to see what derive expand into pub struct UserProfile { age : i32, diff --git a/module/core/former/examples/former_trivial.rs b/module/core/former/examples/former_trivial.rs index c644035cfc..b330278f68 100644 --- a/module/core/former/examples/former_trivial.rs +++ b/module/core/former/examples/former_trivial.rs @@ -26,6 +26,7 @@ fn main() // Use attribute debug to print expanded code. #[ derive( Debug, PartialEq, Former ) ] + // Uncomment to see what derive expand into // #[ debug ] pub struct UserProfile { diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index d3d87c99ce..b665b07e5a 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -869,13 +869,8 @@ where r#"derive : Former structure : {stru} field : {field_ident}"#, - // format!( "{}", qt!{ #setter_name } ), ); - // xxx - // diag::report_print( about, original_input, hint ); - // print!( "{}", diag::report_format( about, original_input, hint ) ); - diag::report_print( about, original_input, hint ); - // println!( "{hint}" ); + diag::report_print( about, original_input, hint ); } let setters_code = qt! From ffe323a99263bf24a064b98f9f538e3ef90f0bd9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 13:41:40 +0300 Subject: [PATCH 512/533] former : refactoring --- .../subformer_container_custom.rs | 38 ++- .../subformer_container_custom_like.rs | 279 ++++++++++++++++++ module/core/former/tests/inc/mod.rs | 2 + 3 files changed, 298 insertions(+), 21 deletions(-) create mode 100644 module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index 6d93805bf0..3c9a6e9dbb 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -2,7 +2,6 @@ use super::*; use collection_tools::HashSet; -// use std::fmt; // == define custom containers @@ -131,7 +130,6 @@ where K : ::core::cmp::Eq + ::core::hash::Hash, { type Preformed = LoggingSet< K >; - // xxx : rid off Formed maybe? } impl< K > former::StoragePreform @@ -139,7 +137,6 @@ for LoggingSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - // type Preformed = LoggingSet< K >; fn preform( self ) -> Self::Preformed { self @@ -250,8 +247,6 @@ former::ContainerSubformer::< K, LoggingSetDefinition< K, Context, Formed, End > /// Parent required for the template. #[ derive( Debug, Default, PartialEq, the_module::Former ) ] -// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] #[ debug ] -// #[ derive( Debug, Default, PartialEq ) ] pub struct Parent { #[ container ] @@ -262,22 +257,23 @@ pub struct Parent // == end of generated -// #[ test ] -// fn basic() -// { -// -// // Using the builder pattern provided by Former to manipulate Parent -// let mut parent = Parent::former() -// .children() -// .add(10) -// .add(20) -// .add(10) -// .end() -// .form(); -// -// println!("Got: {:?}", parent); -// -// } +#[ test ] +fn basic() +{ + + // Using the builder pattern provided by Former to manipulate Parent + let parent = Parent::former() + .children() + .add(10) + .add(20) + .add(10) + .end() + .form(); + + println!("Got: {:?}", parent); + +} // xxx2 : get completed +// xxx2 : get completed example diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs new file mode 100644 index 0000000000..3c9a6e9dbb --- /dev/null +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs @@ -0,0 +1,279 @@ +#![ allow( dead_code ) ] + +use super::*; +use collection_tools::HashSet; + +// == define custom containers + +// Custom container that logs additions +#[ derive( Debug, PartialEq ) ] +pub struct LoggingSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + set : HashSet< K >, +} + +impl< K > Default for LoggingSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + + #[ inline( always ) ] + fn default() -> Self + { + Self + { + set : Default::default() + } + } + +} + +impl< K > IntoIterator for LoggingSet< K > +where + K : std::cmp::Eq + std::hash::Hash, +{ + type Item = K; + type IntoIter = std::collections::hash_set::IntoIter< K >; + + fn into_iter( self ) -> Self::IntoIter + { + self.set.into_iter() + } +} + +impl<'a, K> IntoIterator for &'a LoggingSet< K > +where + K : std::cmp::Eq + std::hash::Hash, +{ + type Item = &'a K; + type IntoIter = std::collections::hash_set::Iter< 'a, K >; + + fn into_iter( self ) -> Self::IntoIter + { + self.set.iter() + } +} + +impl< K > former::Container for LoggingSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + type Entry = K; + type Val = K; + + #[ inline( always ) ] + fn entry_to_val( e : Self::Entry ) -> Self::Val + { + e + } + +} + +impl< K > former::ContainerAdd for LoggingSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + + #[ inline( always ) ] + fn add( &mut self, e : Self::Entry ) -> bool + { + self.set.insert( e ) + } + +} + +impl< K > former::ContainerAssign for LoggingSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + fn assign< Elements >( &mut self, elements : Elements ) -> usize + where + Elements : IntoIterator< Item = Self::Entry > + { + let initial_len = self.set.len(); + self.set.extend( elements ); + self.set.len() - initial_len + } +} + +impl< K > former::ContainerValToEntry< K > for LoggingSet< K > +where + K : core::cmp::Eq + core::hash::Hash, +{ + type Entry = K; + #[ inline( always ) ] + fn val_to_entry( val : K ) -> Self::Entry + { + val + } +} + +// xxx : test with HashSetLike +// +// impl< K > HashSetLike< K > for LoggingSet< K > +// where +// K : core::cmp::Eq + core::hash::Hash, +// { +// fn insert( &mut self, element : K ) -> Option< K > +// { +// HashSet::replace( self, element ) +// } +// } + +// = storage + +impl< K > former::Storage +for LoggingSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Preformed = LoggingSet< K >; +} + +impl< K > former::StoragePreform +for LoggingSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + fn preform( self ) -> Self::Preformed + { + self + } +} + +// = definition types + +#[ derive( Debug, Default ) ] +pub struct LoggingSetDefinitionTypes< K, Context = (), Formed = LoggingSet< K > > +{ + _phantom : core::marker::PhantomData< ( K, Context, Formed ) >, +} + +impl< K, Context, Formed > former::FormerDefinitionTypes +for LoggingSetDefinitionTypes< K, Context, Formed > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Storage = LoggingSet< K >; + type Formed = Formed; + type Context = Context; +} + +// = definition + +#[ derive( Debug, Default ) ] +pub struct LoggingSetDefinition< K, Context = (), Formed = LoggingSet< K >, End = former::ReturnStorage > +{ + _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, +} + +impl< K, Context, Formed, End > former::FormerDefinition +for LoggingSetDefinition< K, Context, Formed, End > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + End : former::FormingEnd< LoggingSetDefinitionTypes< K, Context, Formed > >, +{ + type Storage = LoggingSet< K >; + type Formed = Formed; + type Context = Context; + + type Types = LoggingSetDefinitionTypes< K, Context, Formed >; + type End = End; +} + +// = mutator + +impl< K, Context, Formed > former::FormerMutator +for LoggingSetDefinitionTypes< K, Context, Formed > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ +} + +// = Entity To + +impl< K, Definition > former::EntityToFormer< Definition > for LoggingSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + Definition : former::FormerDefinition + < + Storage = LoggingSet< K >, + Types = LoggingSetDefinitionTypes + < + K, + < Definition as former::FormerDefinition >::Context, + < Definition as former::FormerDefinition >::Formed, + >, + >, + Definition::End : former::FormingEnd< Definition::Types >, +{ + type Former = LoggingSetAsSubformer< K, Definition::Context, Definition::Formed, Definition::End >; +} + +impl< K > former::EntityToStorage +for LoggingSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Storage = LoggingSet< K >; +} + +impl< K, Context, Formed, End > former::EntityToDefinition< Context, Formed, End > +for LoggingSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, + End : former::FormingEnd< LoggingSetDefinitionTypes< K, Context, Formed > >, +{ + type Definition = LoggingSetDefinition< K, Context, Formed, End >; + type Types = LoggingSetDefinitionTypes< K, Context, Formed >; +} + +impl< K, Context, Formed > former::EntityToDefinitionTypes< Context, Formed > +for LoggingSet< K > +where + K : ::core::cmp::Eq + ::core::hash::Hash, +{ + type Types = LoggingSetDefinitionTypes< K, Context, Formed >; +} + +// = subformer + +pub type LoggingSetAsSubformer< K, Context, Formed, End > = +former::ContainerSubformer::< K, LoggingSetDefinition< K, Context, Formed, End > >; + +// == use custom container + +/// Parent required for the template. +#[ derive( Debug, Default, PartialEq, the_module::Former ) ] +pub struct Parent +{ + #[ container ] + children : LoggingSet< i32 >, +} + +// == begin of generated + +// == end of generated + +#[ test ] +fn basic() +{ + + // Using the builder pattern provided by Former to manipulate Parent + let parent = Parent::former() + .children() + .add(10) + .add(20) + .add(10) + .end() + .form(); + + println!("Got: {:?}", parent); + +} + +// xxx2 : get completed +// xxx2 : get completed example + diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 4accf5c331..12500ed533 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -76,6 +76,8 @@ mod former_tests mod subformer_container_named; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_container_custom; + #[ cfg( any( not( feature = "no_std" ) ) ) ] + mod subformer_container_custom_like; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform; From 3cfa13f32c2e9a25e9a90ae2c0ea2a3507ae3fc5 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 13:46:36 +0300 Subject: [PATCH 513/533] former : refactoring --- .../subformer_container_custom.rs | 11 - .../subformer_container_custom_like.rs | 313 +++++++++--------- 2 files changed, 155 insertions(+), 169 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index 3c9a6e9dbb..f8ffa0eba5 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -110,17 +110,6 @@ where } } -// xxx : test with HashSetLike -// -// impl< K > HashSetLike< K > for LoggingSet< K > -// where -// K : core::cmp::Eq + core::hash::Hash, -// { -// fn insert( &mut self, element : K ) -> Option< K > -// { -// HashSet::replace( self, element ) -// } -// } // = storage diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs index 3c9a6e9dbb..5ef5bdfbcc 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs @@ -110,170 +110,167 @@ where } } +// xxx2 : get completed // xxx : test with HashSetLike -// -// impl< K > HashSetLike< K > for LoggingSet< K > -// where -// K : core::cmp::Eq + core::hash::Hash, -// { -// fn insert( &mut self, element : K ) -> Option< K > -// { -// HashSet::replace( self, element ) -// } -// } - -// = storage -impl< K > former::Storage -for LoggingSet< K > +impl< K > former::HashSetLike< K > for LoggingSet< K > where - K : ::core::cmp::Eq + ::core::hash::Hash, -{ - type Preformed = LoggingSet< K >; -} - -impl< K > former::StoragePreform -for LoggingSet< K > -where - K : ::core::cmp::Eq + ::core::hash::Hash, + K : core::cmp::Eq + core::hash::Hash, { - fn preform( self ) -> Self::Preformed + fn insert( &mut self, element : K ) -> Option< K > { - self + HashSet::replace( self, element ) } } -// = definition types - -#[ derive( Debug, Default ) ] -pub struct LoggingSetDefinitionTypes< K, Context = (), Formed = LoggingSet< K > > -{ - _phantom : core::marker::PhantomData< ( K, Context, Formed ) >, -} - -impl< K, Context, Formed > former::FormerDefinitionTypes -for LoggingSetDefinitionTypes< K, Context, Formed > -where - K : ::core::cmp::Eq + ::core::hash::Hash, -{ - type Storage = LoggingSet< K >; - type Formed = Formed; - type Context = Context; -} - -// = definition - -#[ derive( Debug, Default ) ] -pub struct LoggingSetDefinition< K, Context = (), Formed = LoggingSet< K >, End = former::ReturnStorage > -{ - _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, -} - -impl< K, Context, Formed, End > former::FormerDefinition -for LoggingSetDefinition< K, Context, Formed, End > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - End : former::FormingEnd< LoggingSetDefinitionTypes< K, Context, Formed > >, -{ - type Storage = LoggingSet< K >; - type Formed = Formed; - type Context = Context; - - type Types = LoggingSetDefinitionTypes< K, Context, Formed >; - type End = End; -} - -// = mutator - -impl< K, Context, Formed > former::FormerMutator -for LoggingSetDefinitionTypes< K, Context, Formed > -where - K : ::core::cmp::Eq + ::core::hash::Hash, -{ -} - -// = Entity To - -impl< K, Definition > former::EntityToFormer< Definition > for LoggingSet< K > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - Definition : former::FormerDefinition - < - Storage = LoggingSet< K >, - Types = LoggingSetDefinitionTypes - < - K, - < Definition as former::FormerDefinition >::Context, - < Definition as former::FormerDefinition >::Formed, - >, - >, - Definition::End : former::FormingEnd< Definition::Types >, -{ - type Former = LoggingSetAsSubformer< K, Definition::Context, Definition::Formed, Definition::End >; -} - -impl< K > former::EntityToStorage -for LoggingSet< K > -where - K : ::core::cmp::Eq + ::core::hash::Hash, -{ - type Storage = LoggingSet< K >; -} - -impl< K, Context, Formed, End > former::EntityToDefinition< Context, Formed, End > -for LoggingSet< K > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - End : former::FormingEnd< LoggingSetDefinitionTypes< K, Context, Formed > >, -{ - type Definition = LoggingSetDefinition< K, Context, Formed, End >; - type Types = LoggingSetDefinitionTypes< K, Context, Formed >; -} - -impl< K, Context, Formed > former::EntityToDefinitionTypes< Context, Formed > -for LoggingSet< K > -where - K : ::core::cmp::Eq + ::core::hash::Hash, -{ - type Types = LoggingSetDefinitionTypes< K, Context, Formed >; -} - -// = subformer - -pub type LoggingSetAsSubformer< K, Context, Formed, End > = -former::ContainerSubformer::< K, LoggingSetDefinition< K, Context, Formed, End > >; - -// == use custom container - -/// Parent required for the template. -#[ derive( Debug, Default, PartialEq, the_module::Former ) ] -pub struct Parent -{ - #[ container ] - children : LoggingSet< i32 >, -} - -// == begin of generated - -// == end of generated - -#[ test ] -fn basic() -{ - - // Using the builder pattern provided by Former to manipulate Parent - let parent = Parent::former() - .children() - .add(10) - .add(20) - .add(10) - .end() - .form(); - - println!("Got: {:?}", parent); - -} - -// xxx2 : get completed -// xxx2 : get completed example +// = storage +// impl< K > former::Storage +// for LoggingSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// type Preformed = LoggingSet< K >; +// } +// +// impl< K > former::StoragePreform +// for LoggingSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// fn preform( self ) -> Self::Preformed +// { +// self +// } +// } +// +// // = definition types +// +// #[ derive( Debug, Default ) ] +// pub struct LoggingSetDefinitionTypes< K, Context = (), Formed = LoggingSet< K > > +// { +// _phantom : core::marker::PhantomData< ( K, Context, Formed ) >, +// } +// +// impl< K, Context, Formed > former::FormerDefinitionTypes +// for LoggingSetDefinitionTypes< K, Context, Formed > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// type Storage = LoggingSet< K >; +// type Formed = Formed; +// type Context = Context; +// } +// +// // = definition +// +// #[ derive( Debug, Default ) ] +// pub struct LoggingSetDefinition< K, Context = (), Formed = LoggingSet< K >, End = former::ReturnStorage > +// { +// _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, +// } +// +// impl< K, Context, Formed, End > former::FormerDefinition +// for LoggingSetDefinition< K, Context, Formed, End > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// End : former::FormingEnd< LoggingSetDefinitionTypes< K, Context, Formed > >, +// { +// type Storage = LoggingSet< K >; +// type Formed = Formed; +// type Context = Context; +// +// type Types = LoggingSetDefinitionTypes< K, Context, Formed >; +// type End = End; +// } +// +// // = mutator +// +// impl< K, Context, Formed > former::FormerMutator +// for LoggingSetDefinitionTypes< K, Context, Formed > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// } +// +// // = Entity To +// +// impl< K, Definition > former::EntityToFormer< Definition > for LoggingSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// Definition : former::FormerDefinition +// < +// Storage = LoggingSet< K >, +// Types = LoggingSetDefinitionTypes +// < +// K, +// < Definition as former::FormerDefinition >::Context, +// < Definition as former::FormerDefinition >::Formed, +// >, +// >, +// Definition::End : former::FormingEnd< Definition::Types >, +// { +// type Former = LoggingSetAsSubformer< K, Definition::Context, Definition::Formed, Definition::End >; +// } +// +// impl< K > former::EntityToStorage +// for LoggingSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// type Storage = LoggingSet< K >; +// } +// +// impl< K, Context, Formed, End > former::EntityToDefinition< Context, Formed, End > +// for LoggingSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// End : former::FormingEnd< LoggingSetDefinitionTypes< K, Context, Formed > >, +// { +// type Definition = LoggingSetDefinition< K, Context, Formed, End >; +// type Types = LoggingSetDefinitionTypes< K, Context, Formed >; +// } +// +// impl< K, Context, Formed > former::EntityToDefinitionTypes< Context, Formed > +// for LoggingSet< K > +// where +// K : ::core::cmp::Eq + ::core::hash::Hash, +// { +// type Types = LoggingSetDefinitionTypes< K, Context, Formed >; +// } +// +// // = subformer +// +// pub type LoggingSetAsSubformer< K, Context, Formed, End > = +// former::ContainerSubformer::< K, LoggingSetDefinition< K, Context, Formed, End > >; +// +// // == use custom container +// +// /// Parent required for the template. +// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] +// pub struct Parent +// { +// #[ container ] +// children : LoggingSet< i32 >, +// } +// +// // == begin of generated +// +// // == end of generated +// +// #[ test ] +// fn basic() +// { +// +// // Using the builder pattern provided by Former to manipulate Parent +// let parent = Parent::former() +// .children() +// .add(10) +// .add(20) +// .add(10) +// .end() +// .form(); +// +// println!("Got: {:?}", parent); +// +// } From 4dd38594d4d45f3873c52c5b596ef8bf44651ccb Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 13:47:03 +0300 Subject: [PATCH 514/533] former : refactoring --- .../tests/inc/former_tests/subformer_container_custom_like.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs index 5ef5bdfbcc..5fc6a62a81 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs @@ -119,7 +119,7 @@ where { fn insert( &mut self, element : K ) -> Option< K > { - HashSet::replace( self, element ) + HashSet::replace( &mut self.set, element ) } } From 966a6f0b904e039d4ffa39f727fac9756523b3f4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 14:08:39 +0300 Subject: [PATCH 515/533] former : refactoring --- module/core/former/src/hash_set.rs | 70 ++++++++++++------- .../subformer_container_custom_like.rs | 18 ++--- 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 57b6670dcd..36379ddbfc 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -5,6 +5,22 @@ use super::*; use collection_tools::HashSet; +// impl< K, T > Container for T +// where +// K : core::cmp::Eq + core::hash::Hash, +// T : HashSetLike< K >, +// { +// type Entry = K; +// type Val = K; +// +// #[ inline( always ) ] +// fn entry_to_val( e : Self::Entry ) -> Self::Val +// { +// e +// } +// +// } + impl< K > Container for collection_tools::HashSet< K > where K : core::cmp::Eq + core::hash::Hash, @@ -63,33 +79,33 @@ where } } -/// A trait for containers behaving like a `HashSet`, allowing insertion operations. -/// -/// Implementing this trait enables the associated formed to be used with `HashSetAsSubformer`, -/// facilitating a builder pattern that is both intuitive and concise. -/// -/// # Example Implementation -/// -/// Implementing `HashSetLike` for `std::collections::HashSet`: -/// - -pub trait HashSetLike< K > -where - K : core::cmp::Eq + core::hash::Hash, -{ - /// Inserts a key-value pair into the map. - fn insert( &mut self, element : K ) -> Option< K >; -} - -impl< K > HashSetLike< K > for HashSet< K > -where - K : core::cmp::Eq + core::hash::Hash, -{ - fn insert( &mut self, element : K ) -> Option< K > - { - HashSet::replace( self, element ) - } -} +// /// A trait for containers behaving like a `HashSet`, allowing insertion operations. +// /// +// /// Implementing this trait enables the associated formed to be used with `HashSetAsSubformer`, +// /// facilitating a builder pattern that is both intuitive and concise. +// /// +// /// # Example Implementation +// /// +// /// Implementing `HashSetLike` for `std::collections::HashSet`: +// /// +// +// pub trait HashSetLike< K > +// where +// K : core::cmp::Eq + core::hash::Hash, +// { +// /// Inserts a key-value pair into the map. +// fn insert( &mut self, element : K ) -> Option< K >; +// } +// +// // impl< K > HashSetLike< K > for HashSet< K > +// // where +// // K : core::cmp::Eq + core::hash::Hash, +// // { +// // fn insert( &mut self, element : K ) -> Option< K > +// // { +// // HashSet::replace( self, element ) +// // } +// // } // = storage diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs index 5fc6a62a81..ec88c813a0 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs @@ -113,15 +113,15 @@ where // xxx2 : get completed // xxx : test with HashSetLike -impl< K > former::HashSetLike< K > for LoggingSet< K > -where - K : core::cmp::Eq + core::hash::Hash, -{ - fn insert( &mut self, element : K ) -> Option< K > - { - HashSet::replace( &mut self.set, element ) - } -} +// impl< K > former::HashSetLike< K > for LoggingSet< K > +// where +// K : core::cmp::Eq + core::hash::Hash, +// { +// fn insert( &mut self, element : K ) -> Option< K > +// { +// HashSet::replace( &mut self.set, element ) +// } +// } // = storage From 3e05b52e3cd876d85db111ef94ee0ec2d441856a Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 14:13:38 +0300 Subject: [PATCH 516/533] former : refactoring --- module/core/former/Readme.md | 6 +++++ module/core/former/src/hash_set.rs | 35 ++++-------------------------- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index ffb46af7de..1a2644b203 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -650,6 +650,8 @@ Each type of setter is designed to address different needs in the formation proc The following example illustrates how to use a `VectorAsSubformer` to construct a `Vec` field within a struct. The subformer enables adding elements to the vector with a fluent interface, streamlining the process of populating collection fields within structs. + + ```rust #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() @@ -679,6 +681,8 @@ fn main() This example demonstrates the use of a `HashMapAsSubformer` to build a hash map within a struct. The subformer provides a concise way to insert key-value pairs into the map, making it easier to manage and construct hash map fields. + + ```rust #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() @@ -709,6 +713,8 @@ fn main() In the following example, a `HashSetAsSubformer` is utilized to construct a hash set within a struct. This illustrates the convenience of adding elements to a set using the builder pattern facilitated by subformers. + + ```rust #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] fn main() diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 36379ddbfc..130aae47d5 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -230,40 +230,13 @@ where // = subformer -/// Facilitates building `HashSetLike` containers with a fluent API. +/// Provides a concise alias for `ContainerSubformer` configured specifically for `HashSet`-like containers. /// -/// `HashSetAsSubformer` leverages the `HashSetLike` trait to enable a concise and expressive way -/// of populating `HashSet`-like containers. It exemplifies the crate's builder pattern variation for sets. +/// `HashSetAsSubformer` simplifies the creation of `HashSet` containers within builder patterns by leveraging +/// the `ContainerSubformer` with predefined settings. This approach minimizes boilerplate code and enhances +/// readability, making it ideal for fluent and expressive construction of set containers within custom data structures. /// -/// # Example Usage -/// -/// Using `HashSetAsSubformer` to populate a `HashSet` within a struct: -/// -/// ```rust -/// # #[ cfg( all( feature = "enabled", not( feature = "no_std" ) ) ) ] -/// # { -/// # use test_tools::exposed::*; -/// -/// #[ derive( Debug, PartialEq, former::Former ) ] -/// pub struct StructWithSet -/// { -/// #[ container( definition = former::HashSetAsSubformer ) ] -/// set : std::collections::HashSet< &'static str >, -/// } -/// -/// let instance = StructWithSet::former() -/// .set() -/// .insert( "apple" ) -/// .insert( "banana" ) -/// .end() -/// .form(); -/// -/// assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] }); -/// # } -/// ``` -// zzz : update documentation -// add: instead of writing long version with ContainerSubformer it's possible to be more concise with help of the type alias pub type HashSetAsSubformer< K, Context, Formed, End > = ContainerSubformer::< K, HashSetDefinition< K, Context, Formed, End > >; From 77e842d4bf33bf72001505c2ffa2f9ab6a781036 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 15:23:18 +0300 Subject: [PATCH 517/533] former : refactoring --- module/core/former/src/hash_map.rs | 98 +++---------------- module/core/former/src/hash_set.rs | 4 +- module/core/former/src/vector.rs | 58 ++++------- .../former_meta/src/derive_former/field.rs | 2 - 4 files changed, 33 insertions(+), 129 deletions(-) diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/hash_map.rs index 4dbb3ba299..6caa4241cd 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/hash_map.rs @@ -1,3 +1,10 @@ +//! This module provides a comprehensive approach to applying the builder pattern to `HashMap` containers. +//! +//! By leveraging traits such as `Container`, `ContainerAdd`, `ContainerAssign`, and `ContainerValToEntry`, +//! this module abstracts the operations on hashmap-like data structures, making them more flexible and easier to integrate as +//! as subformer, enabling fluid and intuitive manipulation of hashmaps via builder patterns. +//! + use super::*; use collection_tools::HashMap; @@ -21,8 +28,6 @@ impl< K, V > ContainerAdd for collection_tools::HashMap< K, V > where K : core::cmp::Eq + core::hash::Hash, { - // type Entry = ( K, V ); - // type Val = V; #[ inline( always ) ] fn add( &mut self, ( k, v ) : Self::Entry ) -> bool @@ -36,7 +41,6 @@ impl< K, V > ContainerAssign for collection_tools::HashMap< K, V > where K : core::cmp::Eq + core::hash::Hash, { - // type Entry = ( K, V ); fn assign< Elements >( &mut self, elements : Elements ) -> usize where @@ -48,39 +52,6 @@ where } } -/// 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 -/// of key-value pairs and the creation of formers for more complex construction patterns. -/// -/// # Type Parameters -/// - `K`: The type of keys stored in the hash map. Must implement `Eq` and `Hash`. -/// - `E`: The type of elements (values) stored in the hash map. -pub trait HashMapLike< K, E > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - Self : Sized + Default, -{ - - /// Inserts a key-value pair into the map. - fn insert( &mut self, k : K, e : E ) -> Option< E >; - -} - -impl< K, E > HashMapLike< K, E > for HashMap< K, E > -where - K : ::core::cmp::Eq + ::core::hash::Hash, - Self : Sized + Default, -{ - - #[ inline( always ) ] - fn insert( &mut self, k : K, e : E ) -> Option< E > - { - HashMap::insert( self, k, e ) - } - -} - // = storage impl< K, E > Storage @@ -88,8 +59,6 @@ for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - // type Types = HashMapDefinition< K, E >; - // type Formed = HashMap< K, E >; type Preformed = HashMap< K, E >; } @@ -98,8 +67,6 @@ for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - // type Preformed = HashMap< K, E >; - // fn preform( self ) -> < < Self as Storage >::Definition as FormerDefinitionTypes >::Formed fn preform( self ) -> Self::Preformed { self @@ -163,10 +130,6 @@ where // = Entity To impl< K, E, Definition > EntityToFormer< Definition > for HashMap< K, E > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// Definition : FormerDefinition< Storage = HashMap< K, E >, Formed = () >, -// < Definition as definition::FormerDefinition>::End : Fn( HashMap< K, E >, Option< Definition::Context > ), where K : ::core::cmp::Eq + ::core::hash::Hash, Definition : FormerDefinition @@ -213,48 +176,17 @@ where // = subformer -/// A builder for constructing hash map-like structures with a fluent interface. -/// -/// `HashMapAsSubformer` leverages the `HashMapLike` trait to enable a flexible and customizable -/// way to build hash map-like structures. It supports the chaining of insert operations and -/// allows for the definition of custom end actions to finalize the building process. -/// -/// # Type Parameters -/// - `K`: Key type, must implement `Eq` and `Hash`. -/// - `E`: Entry (value) type. -/// - `Formed`: The hash map-like formed being built. -/// - `Context`: Type of the optional context used during the building process. -/// - `End`: End-of-forming action to be executed upon completion. +/// Provides a streamlined builder interface for constructing hash map-like containers. /// -/// # Examples -/// ``` -/// # #[ cfg( all( feature = "enabled", not( feature = "no_std" ) ) ) ] -/// # { -/// # use test_tools::exposed::*; +/// `HashMapAsSubformer` is a type alias that configures the `ContainerSubformer` specifically for hash maps, +/// facilitating a more intuitive and flexible way to build and manipulate hash maps within custom data structures. +/// This type alias simplifies the usage of hash maps in builder patterns by encapsulating complex generic parameters +/// and leveraging the `HashMapDefinition` to handle the construction logic. It supports fluent chaining of key-value +/// insertions and can be customized with various end actions to finalize the hash map upon completion. /// -/// #[ derive( Debug, PartialEq, former::Former ) ] -/// pub struct StructWithMap -/// { -/// #[ container( definition = former::HashMapAsSubformer ) ] -/// map : std::collections::HashMap< &'static str, &'static str >, -/// } -/// -/// let struct1 = StructWithMap::former() -/// .map() -/// .insert( "a", "b" ) -/// .insert( "c", "d" ) -/// .end() -/// .form() -/// ; -/// assert_eq!( struct1, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); -/// -/// # } -/// ``` - -// pub type HashMapAsSubformer< K, E, Context, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, End > >; +/// The alias helps reduce boilerplate code and enhances readability, making the construction of hash maps in +/// a builder pattern both efficient and expressive. -// zzz : update documentation -// pub type HashMapAsSubformer< K, E, Context, End > = ContainerSubformer::< K, HashMapDefinition< K, E, Context, End > >; pub type HashMapAsSubformer< K, E, Context, Formed, End > = ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, Formed, End > >; diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index 130aae47d5..aa89f97687 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -1,6 +1,4 @@ -//! # HashSetLike Trait and HashSetAsSubformer Struct -//! -//! This part of the crate provides a flexible interface (`HashSetLike`) and a builder pattern implementation (`HashSetAsSubformer`) for `HashSet`-like containers. It's designed to extend the builder pattern, allowing for fluent and dynamic construction of sets within custom data structures. +//! This module provides a builder pattern implementation (`HashSetAsSubformer`) for `HashSet`-like containers. It is designed to extend the builder pattern, allowing for fluent and dynamic construction of sets within custom data structures. use super::*; use collection_tools::HashSet; diff --git a/module/core/former/src/vector.rs b/module/core/former/src/vector.rs index ee7624e7b7..9c9b962306 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/vector.rs @@ -1,3 +1,10 @@ +//! This module provides a comprehensive approach to applying the builder pattern to `Vec` containers. +//! +//! By leveraging traits such as `Container`, `ContainerAdd`, `ContainerAssign`, and `ContainerValToEntry`, +//! this module abstracts the operations on vector-like data structures, making them more flexible and easier to integrate as +//! as subformer, enabling fluid and intuitive manipulation of vectors via builder patterns. +//! + use super::*; // use axiomatic::*; @@ -19,8 +26,6 @@ impl< E > Container for collection_tools::Vec< E > impl< E > ContainerAdd for collection_tools::Vec< E > { - // type Entry = E; - // type Val = E; #[ inline( always ) ] fn add( &mut self, e : Self::Entry ) -> bool @@ -33,8 +38,6 @@ impl< E > ContainerAdd for collection_tools::Vec< E > impl< E > ContainerAssign for collection_tools::Vec< E > { - // type Entry = E; - #[ inline( always ) ] fn assign< Elements >( &mut self, elements : Elements ) -> usize where @@ -58,25 +61,6 @@ where } } -/// 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 ); - } -} - // = storage impl< E > Storage @@ -99,11 +83,7 @@ for Vec< E > // = definition -// xxx : split definition and definition types -// xxx : imlement custom ContainerDefinition - #[ derive( Debug, Default ) ] -// pub struct VectorDefinition< E, Context = (), Formed = Vec< E >, End = ReturnStorage > pub struct VectorDefinition< E, Context, Formed, End > where End : FormingEnd< VectorDefinitionTypes< E, Context, Formed > >, @@ -149,17 +129,8 @@ for VectorDefinitionTypes< E, Context, Formed > // = Entity To -// zzz : qqq : implement for hashset / hashmap -// zzz : qqq : cover by tests -// zzz : qqq : rid off bound `Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed` for all containers - impl< E, Definition > EntityToFormer< Definition > for Vec< E > -// where -// Definition : FormerDefinition< Storage = Vec< E > >, -// Definition::Types : FormerDefinitionTypes< Storage = Vec< E >, Formed = Definition::Formed, Context = Definition::Context >, -// Definition::End : crate::FormingEnd< Definition::Types >, -// < Definition as definition::FormerDefinition >::End : Fn( Vec< E >, Option< Definition::Context > ) -> Definition::Formed, // xxx where Definition : FormerDefinition < @@ -199,12 +170,17 @@ for Vec< E > // = subformer -/// A builder for constructing `VectorLike` containers, facilitating a fluent and flexible interface. +/// Provides a streamlined builder interface for constructing vector-like containers. +/// +/// `VectorAsSubformer` is a type alias that configures the `ContainerSubformer` for use specifically with vectors. +/// It integrates the `VectorDefinition` to facilitate the fluent and dynamic construction of vectors, leveraging +/// predefined settings to reduce boilerplate code. This approach enhances readability and simplifies the use of +/// vectors in custom data structures where builder patterns are desired. +/// +/// The alias encapsulates complex generic parameters, making the construction process more accessible and maintainable. +/// It is particularly useful in scenarios where vectors are repeatedly used or configured in similar ways across different +/// parts of an application. /// -/// `VectorAsSubformer` 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. - -// zzz : update documentation pub type VectorAsSubformer< E, Context, Formed, End > = ContainerSubformer::< E, VectorDefinition< E, Context, Formed, End > >; diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index b665b07e5a..24c966304f 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -56,8 +56,6 @@ scalar_setter_required let is_optional = typ::is_optional( ty ); let of_type = container_kind::of_optional( ty ).0; let non_optional_ty : &syn::Type = if is_optional { typ::parameter_first( ty )? } else { ty }; - // let for_storage = true; - // let for_formed = true; let field2 = Self { attrs, From 99cb8bfb024a02efb538c735c1cb240b9b8abd9d Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 15:49:40 +0300 Subject: [PATCH 518/533] former : refactoring --- module/core/former/Readme.md | 34 +- .../examples/former_custom_container.rs | 344 ++++++++++++++---- .../subformer_container_custom.rs | 5 - .../subformer_container_custom_like.rs | 276 -------------- 4 files changed, 283 insertions(+), 376 deletions(-) delete mode 100644 module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 1a2644b203..3784ef36d5 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -599,7 +599,7 @@ Storage is not just a passive container; it is an active part of a larger ecosys - **Contextual Flexibility**: The context associated with the former adds an additional layer of flexibility, allowing the former to adjust its behavior based on the broader circumstances of the object's formation. This is particularly useful when the forming process involves conditions or states external to the object itself. - **FormingEnd Callback**: The `FormingEnd` callback is a dynamic component that defines the final steps of the forming process. It can modify the storage based on final adjustments, validate the object's readiness, or integrate the object into a larger structure, such as embedding it as a subformer within another structure. -These elements work in concert to ensure that the forming process is not only about building an object step-by-step but also about integrating it seamlessly into larger, more complex structures or systems. The `Former` framework, with its sophisticated management of storage, context, and callbacks, enables a highly flexible and reusable approach to object formation, making it ideal for scenarios where objects are part of nested or interdependent systems. +These elements work in concert to ensure that the forming process is not only about building an object step-by-step but also about integrating it seamlessly into larger, more complex structures or systems. ## Concept of Definitions @@ -615,7 +615,7 @@ Two key definition Traits: ## Overview of Formation Traits -The formation process in our framework utilizes several core traits, each serving a specific purpose in the lifecycle of entity creation. These traits ensure that entities are constructed methodically, adhering to a structured pattern that enhances maintainability and scalability. Below is a summary of these key traits: +The formation process utilizes several core traits, each serving a specific purpose in the lifecycle of entity creation. These traits ensure that entities are constructed methodically, adhering to a structured pattern that enhances maintainability and scalability. Below is a summary of these key traits: - `EntityToDefinition`: Links entities to their respective formation definitions which dictate their construction process. - `EntityToFormer`: Connects entities with formers that are responsible for their step-by-step construction. @@ -632,7 +632,7 @@ These traits collectively facilitate a robust and flexible builder pattern that ## Concept of subformer -Subformers are specialized builders used within the `Former` framework to construct nested or collection-based data structures like vectors, hash maps, and hash sets. They simplify the process of adding elements to these structures by providing a fluent interface that can be seamlessly integrated into the overall builder pattern of a parent struct. This approach allows for clean and intuitive initialization of complex data structures, enhancing code readability and maintainability. +Subformers are specialized builders used within the former to construct nested or collection-based data structures like vectors, hash maps, and hash sets. They simplify the process of adding elements to these structures by providing a fluent interface that can be seamlessly integrated into the overall builder pattern of a parent struct. This approach allows for clean and intuitive initialization of complex data structures, enhancing code readability and maintainability. ## Types of Setters / Subformers @@ -648,9 +648,7 @@ Each type of setter is designed to address different needs in the formation proc ## Subformer example: Building a Vector -The following example illustrates how to use a `VectorAsSubformer` to construct a `Vec` field within a struct. The subformer enables adding elements to the vector with a fluent interface, streamlining the process of populating collection fields within structs. - - +This example demonstrates how to employ the `Former` trait to configure a `Vec` using a container setter in a structured manner. ```rust #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] @@ -679,9 +677,7 @@ fn main() ## Subformer example: Building a Hashmap -This example demonstrates the use of a `HashMapAsSubformer` to build a hash map within a struct. The subformer provides a concise way to insert key-value pairs into the map, making it easier to manage and construct hash map fields. - - +This example demonstrates how to effectively employ the `Former` trait to configure a `HashMap` using a container setter. ```rust #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] @@ -711,9 +707,7 @@ fn main() ## Subformer example: Building a Hashset -In the following example, a `HashSetAsSubformer` is utilized to construct a hash set within a struct. This illustrates the convenience of adding elements to a set using the builder pattern facilitated by subformers. - - +This example demonstrates the use of the `Former` trait to build a `collection_tools::HashSet` through subforming. ```rust #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] @@ -819,8 +813,6 @@ In this example, the `Parent` struct functions as a container for multiple `Chil - **Parent Definition**: It holds a collection of `Child` objects in a `HashMap`. The `#[setter(false)]` attribute is used to disable the default setter, and a custom method `child` is defined to facilitate the addition of children with specific attributes. - **Custom Subformer Integration**: The `child` method in the `ParentFormer` initializes a `ChildFormer` with a closure that integrates the `Child` into the `Parent`'s `child` map upon completion. -This pattern of using a structure's former as a subformer within another facilitates the creation of deeply nested or complex data structures through a coherent and fluent interface, showcasing the powerful capabilities of the `Former` framework for Rust applications. - ## Custom Container Setter This example demonstrates the use of container setters to manage complex nested data structures with the `Former` trait, focusing on a parent-child relationship structured around a container `HashMap`. Unlike typical builder patterns that add individual elements using subform setters, this example uses a container setter to manage the entire collection of children. @@ -996,19 +988,7 @@ There are suite of traits designed to abstract and enhance the functionality of Container interface is defined in the crate and implemented for containers like vectors, hash maps, etc, but if you want to use non-standard container you can implement container interface for the container. This example demonstrate how to do that. -```rust - -// Ensure the example only compiles when the appropriate features are enabled. -#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] -fn main() -{ - use collection_tools::HashMap; - use former::Former; - - xxx2 : write - -} -``` +[See code](./examples/former_custom_container.rs). ## Concept of Mutator diff --git a/module/core/former/examples/former_custom_container.rs b/module/core/former/examples/former_custom_container.rs index 0195042304..c9a55a142d 100644 --- a/module/core/former/examples/former_custom_container.rs +++ b/module/core/former/examples/former_custom_container.rs @@ -1,70 +1,278 @@ //! Example former_custom_container.rs //! -//! Container interface is defined in the crate and implemented for containers like vectors, hash maps, etc, but if you want to use non-standard container you can implement container interface for the container. This example demonstrate how to do that. - -// xxx2 : get completed - -// #[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] -// fn main() {} -// #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] -// fn main() -// { -// use collection_tools::HashSet; -// use std::fmt; -// -// // = define custom container -// -// // Custom container that logs additions -// #[ derive( Default ) ] -// pub struct LoggingSet< T > -// { -// set : HashSet< T >, -// } -// -// // // Implementing the container traits for LoggingSet -// // impl former::Container for LoggingSet -// // { -// // type Entry = T; -// // type Val = T; -// // -// // fn entry_to_val(e: Self::Entry) -> Self::Val -// // { -// // e // In this simple case, entry and value are the same. -// // } -// // } -// -// // This trait allows adding entries to the LoggingSet -// impl< T : Eq + std::hash::Hash + fmt::Debug > former::ContainerAdd -// for LoggingSet< T > -// { -// fn add(&mut self, e: Self::Entry) -> bool -// { -// let result = self.set.insert(e); -// if result { -// println!("{:?} was added to the set", e); -// } -// result -// } -// } -// -// // = use custom container -// -// // Define a struct to use with Former -// #[derive(Debug, PartialEq, former::Former)] -// pub struct CollectionContainer -// { -// #[container] -// data: LoggingSet, -// } -// -// // Using the builder pattern provided by Former to manipulate CollectionContainer -// let mut container = CollectionContainer::former().data(); -// -// container.add(10); -// container.add(20); -// container.add(10); // This will not be added again, and "add" will log the attempt. -// -// let final_container = container.end().form(); -// -// println!("Final container: {:?}", final_container); -// } +//! This example demonstrates how to define and use a custom container with former. +//! The custom container implemented here is a `LoggingSet`, which extends the basic `HashSet` behavior +//! by logging each addition. This example illustrates how to integrate such custom containers with the +//! Former trait system for use in structured data types. + +#[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +fn main() {} +#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +fn main() +{ + use collection_tools::HashSet; + + // Custom container that logs additions. + #[ derive( Debug, PartialEq ) ] + pub struct LoggingSet< K > + where + K : core::cmp::Eq + core::hash::Hash, + { + set : HashSet< K >, // Internal HashSet to store the elements. + } + + // Implement default for the custom container. + impl< K > Default for LoggingSet< K > + where + K : core::cmp::Eq + core::hash::Hash, + { + #[ inline( always ) ] + fn default() -> Self + { + Self + { + set : Default::default() // Initialize the internal HashSet. + } + } + } + + // Allow the custom container to be converted into an iterator, to iterate over the elements. + impl< K > IntoIterator for LoggingSet< K > + where + K : std::cmp::Eq + std::hash::Hash, + { + type Item = K; + type IntoIter = std::collections::hash_set::IntoIter< K >; + + fn into_iter( self ) -> Self::IntoIter + { + self.set.into_iter() // Create an iterator from the internal HashSet. + } + } + + // Similar iterator functionality but for borrowing the elements. + impl<'a, K> IntoIterator for &'a LoggingSet< K > + where + K : std::cmp::Eq + std::hash::Hash, + { + type Item = &'a K; + type IntoIter = std::collections::hash_set::Iter< 'a, K >; + + fn into_iter( self ) -> Self::IntoIter + { + self.set.iter() // Borrow the elements via an iterator. + } + } + + // Implement the Container trait to integrate with the former system. + impl< K > former::Container for LoggingSet< K > + where + K : core::cmp::Eq + core::hash::Hash, + { + type Entry = K; + type Val = K; + + #[ inline( always ) ] + fn entry_to_val( e : Self::Entry ) -> Self::Val + { + e // Direct mapping of entries to values. + } + } + + // Implement ContainerAdd to handle adding elements to the custom container. + impl< K > former::ContainerAdd for LoggingSet< K > + where + K : core::cmp::Eq + core::hash::Hash, + { + #[ inline( always ) ] + fn add( &mut self, e : Self::Entry ) -> bool + { + self.set.insert( e ) // Log the addition and add the element to the internal HashSet. + } + } + + // Implement ContainerAssign to handle bulk assignment of elements. + impl< K > former::ContainerAssign for LoggingSet< K > + where + K : core::cmp::Eq + core::hash::Hash, + { + fn assign< Elements >( &mut self, elements : Elements ) -> usize + where + Elements : IntoIterator< Item = Self::Entry > + { + let initial_len = self.set.len(); + self.set.extend( elements ); // Extend the set with a collection of elements. + self.set.len() - initial_len // Return the number of elements added. + } + } + + // Implement ContainerValToEntry to convert values back to entries. + impl< K > former::ContainerValToEntry< K > for LoggingSet< K > + where + K : core::cmp::Eq + core::hash::Hash, + { + type Entry = K; + #[ inline( always ) ] + fn val_to_entry( val : K ) -> Self::Entry + { + val // Direct conversion of value to entry. + } + } + + // = storage + + // Define storage behavior for the custom container. + impl< K > former::Storage + for LoggingSet< K > + where + K : ::core::cmp::Eq + ::core::hash::Hash, + { + type Preformed = LoggingSet< K >; // Define the type after the forming process. + } + + // Implement the preforming behavior to finalize the storage. + impl< K > former::StoragePreform + for LoggingSet< K > + where + K : ::core::cmp::Eq + ::core::hash::Hash, + { + fn preform( self ) -> Self::Preformed + { + self // Return the container as is. + } + } + + // = definition types + + // Definitions related to the type settings for the LoggingSet, which detail how the container should behave with former. + + /// Holds generic parameter types for forming operations related to `LoggingSet`. + #[ derive( Debug, Default ) ] + pub struct LoggingSetDefinitionTypes< K, Context = (), Formed = LoggingSet< K > > + { + _phantom : core::marker::PhantomData< ( K, Context, Formed ) >, // PhantomData is used to handle generic parameters safely. + } + + /// Specifies the storage, formed type, and context for the `LoggingSet` when used in a forming process. + impl< K, Context, Formed > former::FormerDefinitionTypes + for LoggingSetDefinitionTypes< K, Context, Formed > + where + K : ::core::cmp::Eq + ::core::hash::Hash, + { + type Storage = LoggingSet< K >; // Specifies that `LoggingSet` is used as the storage. + type Formed = Formed; // The final formed type after the forming process. + type Context = Context; // The context required for forming, can be specified by the user. + } + + // = definition + + /// Provides a complete definition for `LoggingSet` including the end condition of the forming process. + #[ derive( Debug, Default ) ] + pub struct LoggingSetDefinition< K, Context = (), Formed = LoggingSet< K >, End = former::ReturnStorage > + { + _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, + } + + /// Associates the `LoggingSet` with a specific forming process and defines its behavior. + impl< K, Context, Formed, End > former::FormerDefinition + for LoggingSetDefinition< K, Context, Formed, End > + where + K : ::core::cmp::Eq + ::core::hash::Hash, + End : former::FormingEnd< LoggingSetDefinitionTypes< K, Context, Formed > >, + { + type Storage = LoggingSet< K >; // The storage type during the formation process. + type Formed = Formed; // The type resulting from the formation process. + type Context = Context; // The context used during the formation process. + type Types = LoggingSetDefinitionTypes< K, Context, Formed >; // The associated type settings. + type End = End; // The ending condition for the forming process. + } + + // = mutator + + /// Optional: Implements mutating capabilities to modify the forming process of `LoggingSet` if needed. + impl< K, Context, Formed > former::FormerMutator + for LoggingSetDefinitionTypes< K, Context, Formed > + where + K : ::core::cmp::Eq + ::core::hash::Hash, + { + } + + // = Entity To + + /// Associates the `LoggingSet` with a specific `Former` for use in forming processes. + impl< K, Definition > former::EntityToFormer< Definition > for LoggingSet< K > + where + K : ::core::cmp::Eq + ::core::hash::Hash, + Definition : former::FormerDefinition + < + Storage = LoggingSet< K >, + Types = LoggingSetDefinitionTypes + < + K, + < Definition as former::FormerDefinition >::Context, + < Definition as former::FormerDefinition >::Formed, + >, + >, + Definition::End : former::FormingEnd< Definition::Types >, + { + type Former = LoggingSetAsSubformer< K, Definition::Context, Definition::Formed, Definition::End >; + } + + /// Specifies the storage for `LoggingSet`. + impl< K > former::EntityToStorage + for LoggingSet< K > + where + K : ::core::cmp::Eq + ::core::hash::Hash, + { + type Storage = LoggingSet< K >; + } + + /// Defines the relationship between `LoggingSet` and its formal definition within the forming system. + impl< K, Context, Formed, End > former::EntityToDefinition< Context, Formed, End > + for LoggingSet< K > + where + K : ::core::cmp::Eq + ::core::hash::Hash, + End : former::FormingEnd< LoggingSetDefinitionTypes< K, Context, Formed > >, + { + type Definition = LoggingSetDefinition< K, Context, Formed, End >; + type Types = LoggingSetDefinitionTypes< K, Context, Formed >; + } + + /// Provides type-specific settings for the formation process related to `LoggingSet`. + impl< K, Context, Formed > former::EntityToDefinitionTypes< Context, Formed > + for LoggingSet< K > + where + K : ::core::cmp::Eq + ::core::hash::Hash, + { + type Types = LoggingSetDefinitionTypes< K, Context, Formed >; + } + + // = subformer + + // Subformer type alias simplifies the usage of `ContainerSubformer` with `LoggingSet`. + pub type LoggingSetAsSubformer< K, Context, Formed, End > = + former::ContainerSubformer::< K, LoggingSetDefinition< K, Context, Formed, End > >; + + // == use custom container + + /// Parent required for the template. + #[ derive( Debug, Default, PartialEq, former::Former ) ] + pub struct Parent + { + #[ container ] + children : LoggingSet< i32 >, + } + + // Using the builder pattern provided by Former to manipulate Parent + let parent = Parent::former() + .children() + .add(10) + .add(20) + .add(10) + .end() + .form(); + + println!("Got: {:?}", parent); + // > Parent { children: LoggingSet { set: {10, 20} } } + +} diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index f8ffa0eba5..9bc98c4ec3 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -110,7 +110,6 @@ where } } - // = storage impl< K > former::Storage @@ -262,7 +261,3 @@ fn basic() println!("Got: {:?}", parent); } - -// xxx2 : get completed -// xxx2 : get completed example - diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs deleted file mode 100644 index ec88c813a0..0000000000 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom_like.rs +++ /dev/null @@ -1,276 +0,0 @@ -#![ allow( dead_code ) ] - -use super::*; -use collection_tools::HashSet; - -// == define custom containers - -// Custom container that logs additions -#[ derive( Debug, PartialEq ) ] -pub struct LoggingSet< K > -where - K : core::cmp::Eq + core::hash::Hash, -{ - set : HashSet< K >, -} - -impl< K > Default for LoggingSet< K > -where - K : core::cmp::Eq + core::hash::Hash, -{ - - #[ inline( always ) ] - fn default() -> Self - { - Self - { - set : Default::default() - } - } - -} - -impl< K > IntoIterator for LoggingSet< K > -where - K : std::cmp::Eq + std::hash::Hash, -{ - type Item = K; - type IntoIter = std::collections::hash_set::IntoIter< K >; - - fn into_iter( self ) -> Self::IntoIter - { - self.set.into_iter() - } -} - -impl<'a, K> IntoIterator for &'a LoggingSet< K > -where - K : std::cmp::Eq + std::hash::Hash, -{ - type Item = &'a K; - type IntoIter = std::collections::hash_set::Iter< 'a, K >; - - fn into_iter( self ) -> Self::IntoIter - { - self.set.iter() - } -} - -impl< K > former::Container for LoggingSet< K > -where - K : core::cmp::Eq + core::hash::Hash, -{ - type Entry = K; - type Val = K; - - #[ inline( always ) ] - fn entry_to_val( e : Self::Entry ) -> Self::Val - { - e - } - -} - -impl< K > former::ContainerAdd for LoggingSet< K > -where - K : core::cmp::Eq + core::hash::Hash, -{ - - #[ inline( always ) ] - fn add( &mut self, e : Self::Entry ) -> bool - { - self.set.insert( e ) - } - -} - -impl< K > former::ContainerAssign for LoggingSet< K > -where - K : core::cmp::Eq + core::hash::Hash, -{ - fn assign< Elements >( &mut self, elements : Elements ) -> usize - where - Elements : IntoIterator< Item = Self::Entry > - { - let initial_len = self.set.len(); - self.set.extend( elements ); - self.set.len() - initial_len - } -} - -impl< K > former::ContainerValToEntry< K > for LoggingSet< K > -where - K : core::cmp::Eq + core::hash::Hash, -{ - type Entry = K; - #[ inline( always ) ] - fn val_to_entry( val : K ) -> Self::Entry - { - val - } -} - -// xxx2 : get completed -// xxx : test with HashSetLike - -// impl< K > former::HashSetLike< K > for LoggingSet< K > -// where -// K : core::cmp::Eq + core::hash::Hash, -// { -// fn insert( &mut self, element : K ) -> Option< K > -// { -// HashSet::replace( &mut self.set, element ) -// } -// } - -// = storage - -// impl< K > former::Storage -// for LoggingSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// type Preformed = LoggingSet< K >; -// } -// -// impl< K > former::StoragePreform -// for LoggingSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// fn preform( self ) -> Self::Preformed -// { -// self -// } -// } -// -// // = definition types -// -// #[ derive( Debug, Default ) ] -// pub struct LoggingSetDefinitionTypes< K, Context = (), Formed = LoggingSet< K > > -// { -// _phantom : core::marker::PhantomData< ( K, Context, Formed ) >, -// } -// -// impl< K, Context, Formed > former::FormerDefinitionTypes -// for LoggingSetDefinitionTypes< K, Context, Formed > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// type Storage = LoggingSet< K >; -// type Formed = Formed; -// type Context = Context; -// } -// -// // = definition -// -// #[ derive( Debug, Default ) ] -// pub struct LoggingSetDefinition< K, Context = (), Formed = LoggingSet< K >, End = former::ReturnStorage > -// { -// _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >, -// } -// -// impl< K, Context, Formed, End > former::FormerDefinition -// for LoggingSetDefinition< K, Context, Formed, End > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// End : former::FormingEnd< LoggingSetDefinitionTypes< K, Context, Formed > >, -// { -// type Storage = LoggingSet< K >; -// type Formed = Formed; -// type Context = Context; -// -// type Types = LoggingSetDefinitionTypes< K, Context, Formed >; -// type End = End; -// } -// -// // = mutator -// -// impl< K, Context, Formed > former::FormerMutator -// for LoggingSetDefinitionTypes< K, Context, Formed > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// } -// -// // = Entity To -// -// impl< K, Definition > former::EntityToFormer< Definition > for LoggingSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// Definition : former::FormerDefinition -// < -// Storage = LoggingSet< K >, -// Types = LoggingSetDefinitionTypes -// < -// K, -// < Definition as former::FormerDefinition >::Context, -// < Definition as former::FormerDefinition >::Formed, -// >, -// >, -// Definition::End : former::FormingEnd< Definition::Types >, -// { -// type Former = LoggingSetAsSubformer< K, Definition::Context, Definition::Formed, Definition::End >; -// } -// -// impl< K > former::EntityToStorage -// for LoggingSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// type Storage = LoggingSet< K >; -// } -// -// impl< K, Context, Formed, End > former::EntityToDefinition< Context, Formed, End > -// for LoggingSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// End : former::FormingEnd< LoggingSetDefinitionTypes< K, Context, Formed > >, -// { -// type Definition = LoggingSetDefinition< K, Context, Formed, End >; -// type Types = LoggingSetDefinitionTypes< K, Context, Formed >; -// } -// -// impl< K, Context, Formed > former::EntityToDefinitionTypes< Context, Formed > -// for LoggingSet< K > -// where -// K : ::core::cmp::Eq + ::core::hash::Hash, -// { -// type Types = LoggingSetDefinitionTypes< K, Context, Formed >; -// } -// -// // = subformer -// -// pub type LoggingSetAsSubformer< K, Context, Formed, End > = -// former::ContainerSubformer::< K, LoggingSetDefinition< K, Context, Formed, End > >; -// -// // == use custom container -// -// /// Parent required for the template. -// #[ derive( Debug, Default, PartialEq, the_module::Former ) ] -// pub struct Parent -// { -// #[ container ] -// children : LoggingSet< i32 >, -// } -// -// // == begin of generated -// -// // == end of generated -// -// #[ test ] -// fn basic() -// { -// -// // Using the builder pattern provided by Former to manipulate Parent -// let parent = Parent::former() -// .children() -// .add(10) -// .add(20) -// .add(10) -// .end() -// .form(); -// -// println!("Got: {:?}", parent); -// -// } From 16e8370a8d94c3c6da86ca3928a7c187eebbaf2a Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 16:16:24 +0300 Subject: [PATCH 519/533] former : refactoring --- module/core/former/Readme.md | 63 ++++++++++++++++++- ...hashmap.rs => former_container_hashmap.rs} | 0 ...hashset.rs => former_container_hashset.rs} | 0 ...r_vector.rs => former_container_vector.rs} | 1 - .../former/examples/former_custom_mutator.rs | 1 - module/core/former/src/hash_set.rs | 2 +- module/core/former/tests/inc/mod.rs | 2 - 7 files changed, 63 insertions(+), 6 deletions(-) rename module/core/former/examples/{former_subformer_hashmap.rs => former_container_hashmap.rs} (100%) rename module/core/former/examples/{former_subformer_hashset.rs => former_container_hashset.rs} (100%) rename module/core/former/examples/{former_subformer_vector.rs => former_container_vector.rs} (97%) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 3784ef36d5..6d83940670 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -21,6 +21,13 @@ This approach abstracts away the need for manually implementing a builder for ea ## Basic use-case + + + + + + + The provided code snippet illustrates a basic use-case of the Former crate in Rust, which is used to apply the builder pattern for structured and flexible object creation. Below is a detailed explanation of each part of the markdown chapter, aimed at clarifying how the Former trait simplifies struct instantiation. ```rust @@ -449,6 +456,10 @@ fn main() +Try out `cargo run --example former_trivial`. +
+[See code](./examples/former_trivial.rs). + ## Custom and Alternative Setters With help of `Former`, it is possible to define multiple versions of a setter for a single field, providing the flexibility to include custom logic within the setter methods. This feature is particularly useful when you need to preprocess data or enforce specific constraints before assigning values to fields. Custom setters should have unique names to differentiate them from the default setters generated by `Former`, allowing for specialized behavior while maintaining clarity in your code. @@ -494,6 +505,10 @@ assert_eq!( example.word, "Hello!".to_string() ); In the example above showcases a custom alternative setter, `word_exclaimed`, which appends an exclamation mark to the input string before storing it. This approach allows for additional processing or validation of the input data without compromising the simplicity of the builder pattern. +Try out `cargo run --example former_custom_setter`. +
+[See code](./examples/former_custom_setter.rs). + ## Custom Setter Overriding But it's also possible to completely override setter and write its own from scratch. For that use attribe `[ setter( false ) ]` to disable setter. @@ -534,6 +549,10 @@ assert_eq!( example.word, "Hello!".to_string() ); In the example above, the default setter for `word` is disabled, and a custom setter is defined to automatically append an exclamation mark to the string. This method allows for complete control over the data assignment process, enabling the inclusion of any necessary logic or validation steps. +Try out `cargo run --example former_custom_setter_overriden`. +
+[See code](./examples/former_custom_setter_overriden.rs). + ## Custom Default The `Former` crate enhances struct initialization in Rust by allowing the specification of custom default values for fields through the `default` attribute. This feature not only provides a way to set initial values for struct fields without relying on the `Default` trait but also adds flexibility in handling cases where a field's type does not implement `Default`, or a non-standard default value is desired. @@ -584,6 +603,10 @@ The above code snippet showcases the `Former` crate's ability to initialize stru This approach significantly simplifies struct construction, particularly for complex types or where defaults beyond the `Default` trait's capability are required. By utilizing the `default` attribute, developers can ensure their structs are initialized safely and predictably, enhancing code clarity and maintainability. +Try out `cargo run --example former_custom_default`. +
+[See code](./examples/former_custom_default.rs). + ## Concept of Storage and Former Storage is temporary storage structure holds the intermediate state of an object during its construction. @@ -675,6 +698,10 @@ fn main() } ``` +Try out `cargo run --example former_container_vector`. +
+[See code](./examples/former_container_vector.rs). + ## Subformer example: Building a Hashmap This example demonstrates how to effectively employ the `Former` trait to configure a `HashMap` using a container setter. @@ -705,6 +732,10 @@ fn main() } ``` +Try out `cargo run --example former_container_hashmap`. +
+[See code](./examples/former_container_hashmap.rs). + ## Subformer example: Building a Hashset This example demonstrates the use of the `Former` trait to build a `collection_tools::HashSet` through subforming. @@ -735,6 +766,10 @@ fn main() } ``` +Try out `cargo run --example former_container_hashset`. +
+[See code](./examples/former_container_hashset.rs). + ## Custom Scalar Setter This example demonstrates the implementation of a scalar setter using the `Former` trait in Rust. Unlike the more complex subform and container setters shown in previous examples, this example focuses on a straightforward approach to directly set a scalar value within a parent entity. The `Parent` struct manages a `HashMap` of `Child` entities, and the scalar setter is used to set the entire `HashMap` directly. @@ -813,6 +848,10 @@ In this example, the `Parent` struct functions as a container for multiple `Chil - **Parent Definition**: It holds a collection of `Child` objects in a `HashMap`. The `#[setter(false)]` attribute is used to disable the default setter, and a custom method `child` is defined to facilitate the addition of children with specific attributes. - **Custom Subformer Integration**: The `child` method in the `ParentFormer` initializes a `ChildFormer` with a closure that integrates the `Child` into the `Parent`'s `child` map upon completion. +Try out `cargo run --example former_custom_scalar_setter`. +
+[See code](./examples/former_custom_scalar_setter.rs). + ## Custom Container Setter This example demonstrates the use of container setters to manage complex nested data structures with the `Former` trait, focusing on a parent-child relationship structured around a container `HashMap`. Unlike typical builder patterns that add individual elements using subform setters, this example uses a container setter to manage the entire collection of children. @@ -886,6 +925,10 @@ fn main() } ``` +Try out `cargo run --example former_custom_container_setter`. +
+[See code](./examples/former_custom_container_setter.rs). + ## Custom Subform Setter This example illustrates the implementation of nested builder patterns in Rust using the `Former` trait, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. @@ -974,6 +1017,10 @@ fn main() } ``` +Try out `cargo run --example former_custom_subform_setter`. +
+[See code](./examples/former_custom_subform_setter.rs). + ## General Container Interface There are suite of traits designed to abstract and enhance the functionality of container data structures within the forming process. These traits are integral to managing the complexity of container operations, such as adding, modifying, and converting between different representations within containers like vectors, hash maps, etc. They are especially useful when used in conjunction with the `container` attribute in the `former` macro, which automates the implementation of these traits to create robust and flexible builder patterns for complex data structures. @@ -988,6 +1035,8 @@ There are suite of traits designed to abstract and enhance the functionality of Container interface is defined in the crate and implemented for containers like vectors, hash maps, etc, but if you want to use non-standard container you can implement container interface for the container. This example demonstrate how to do that. +Try out `cargo run --example former_custom_container`. +
[See code](./examples/former_custom_container.rs). ## Concept of Mutator @@ -1027,7 +1076,7 @@ of whether the forming process is occurring within the context of a superformer or nested field. This makes `form_mutation` suitable for entity-specific transformations that should not interfere with the hierarchical forming logic managed by `FormingEnd`. -## Example: Mutator +## Example: Mutator and Storage Fields This example illustrates how to use the `FormerMutator` trait for implementing custom mutations and demonstrates the concept of storage-specific fields in the forming process. @@ -1080,6 +1129,18 @@ fn main() } ``` +Try out `cargo run --example former_custom_mutator`. +
+[See code](./examples/former_custom_mutator.rs). + +## Index of Examples + + + + + + + ## To add to your project ```sh diff --git a/module/core/former/examples/former_subformer_hashmap.rs b/module/core/former/examples/former_container_hashmap.rs similarity index 100% rename from module/core/former/examples/former_subformer_hashmap.rs rename to module/core/former/examples/former_container_hashmap.rs diff --git a/module/core/former/examples/former_subformer_hashset.rs b/module/core/former/examples/former_container_hashset.rs similarity index 100% rename from module/core/former/examples/former_subformer_hashset.rs rename to module/core/former/examples/former_container_hashset.rs diff --git a/module/core/former/examples/former_subformer_vector.rs b/module/core/former/examples/former_container_vector.rs similarity index 97% rename from module/core/former/examples/former_subformer_vector.rs rename to module/core/former/examples/former_container_vector.rs index 4bdf6e91d5..92f67dbd47 100644 --- a/module/core/former/examples/former_subformer_vector.rs +++ b/module/core/former/examples/former_container_vector.rs @@ -1,4 +1,3 @@ -//! # Example Usage //! //! This example demonstrates how to employ the `Former` trait to configure a `Vec` using a container setter in a structured manner. //! diff --git a/module/core/former/examples/former_custom_mutator.rs b/module/core/former/examples/former_custom_mutator.rs index aba337b185..5d83fe77c9 100644 --- a/module/core/former/examples/former_custom_mutator.rs +++ b/module/core/former/examples/former_custom_mutator.rs @@ -34,7 +34,6 @@ #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] fn main() {} - #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] fn main() { diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/hash_set.rs index aa89f97687..8476678740 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/hash_set.rs @@ -192,7 +192,7 @@ where < K, < Definition as definition::FormerDefinition >::Context, - < Definition as definition::FormerDefinition >::Formed, // xxx : ? + < Definition as definition::FormerDefinition >::Formed, >, >, Definition::End : forming::FormingEnd< Definition::Types >, diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 12500ed533..4accf5c331 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -76,8 +76,6 @@ mod former_tests mod subformer_container_named; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_container_custom; - #[ cfg( any( not( feature = "no_std" ) ) ) ] - mod subformer_container_custom_like; #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform; From 3b67cb5006b6608eae5c5481d468f24ac9a7aae9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 16:27:50 +0300 Subject: [PATCH 520/533] former : refactoring --- module/core/former/src/container.rs | 55 +++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 73a186a194..85f279f9cd 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -83,13 +83,15 @@ pub trait ContainerValToEntry< Val > /// /// # Example /// ``` + /// use former::ContainerValToEntry; + /// /// struct PairMap; /// - /// impl ContainerValToEntry<(i32, i32)> for PairMap + /// impl ContainerValToEntry< ( i32, i32 ) > for PairMap /// { - /// type Entry = (String, i32); + /// type Entry = ( String, i32 ); /// - /// fn val_to_entry( val : (i32, i32) ) -> Self::Entry + /// fn val_to_entry( val : ( i32, i32 ) ) -> Self::Entry /// { /// (val.0.to_string(), val.1) /// } @@ -119,9 +121,9 @@ pub trait ValToEntry< Container > /// /// # Example /// ``` - /// impl ValToEntry for (i32, i32) + /// impl ValToEntry< PairMap > for (i32, i32) /// { - /// type Entry = (String, i32); + /// type Entry = ( String, i32 ); /// /// fn val_to_entry( self ) -> Self::Entry /// { @@ -171,13 +173,27 @@ pub trait ContainerAdd : Container /// Basic usage: /// /// ```rust - /// use former::ContainerAdd; + /// + /// use former::{ Container, ContainerAdd }; /// /// struct MyContainer /// { /// entries : Vec< i32 >, /// } /// + /// impl Container for MyContainer + /// { + /// type Entry = i32; + /// type Val = i32; + /// + /// #[ inline( always ) ] + /// fn entry_to_val( e : Self::Entry ) -> Self::Val + /// { + /// e + /// } + /// + /// } + /// /// impl ContainerAdd for MyContainer /// { /// fn add( &mut self, e : Self::Entry ) -> bool @@ -229,13 +245,38 @@ where /// # Examples /// /// ```rust - /// use former::ContainerAssign; + /// use former::{ Container, ContainerAssign }; /// /// struct MyContainer /// { /// entries : Vec< i32 >, /// } /// + /// impl Container for MyContainer + /// { + /// type Entry = i32; + /// type Val = i32; + /// + /// #[ inline( always ) ] + /// fn entry_to_val( e : Self::Entry ) -> Self::Val + /// { + /// e + /// } + /// + /// } + /// + /// impl IntoIterator for MyContainer + /// { + /// type Item = i32; + /// type IntoIter = collection_tools::vec::IntoIter< i32 >; + // xxx : make sure collection_tools has it + /// + /// fn into_iter( self ) -> Self::IntoIter + /// { + /// self.entries.into_iter() // Create an iterator from the internal HashSet. + /// } + /// } + /// /// impl ContainerAssign for MyContainer /// { /// fn assign< Entries >( &mut self, entries : Entries ) -> usize From 514fd93e4697427b2b2b90a17e59690440209b4c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 18:21:31 +0300 Subject: [PATCH 521/533] collection_tools : review and tasks --- module/core/collection_tools/Cargo.toml | 2 +- module/core/collection_tools/Readme.md | 6 + module/core/collection_tools/src/lib.rs | 65 ++++--- module/core/collection_tools/src/vec.rs | 2 + .../collection_tools/tests/inc/components.rs | 55 ++++++ .../tests/inc/constructors.rs | 2 +- .../tests/inc/into_constructors.rs | 6 +- module/core/collection_tools/tests/inc/mod.rs | 5 + .../tests/nostd/constructors.rs | 171 ------------------ .../tests/nostd/into_constructors.rs | 168 ----------------- .../core/collection_tools/tests/nostd/mod.rs | 13 -- .../collection_tools/tests/nostd/reexport.rs | 105 ----------- .../collection_tools/tests/nostd_tests.rs | 12 -- module/core/collection_tools/tests/tests.rs | 11 +- 14 files changed, 118 insertions(+), 505 deletions(-) create mode 100644 module/core/collection_tools/src/vec.rs create mode 100644 module/core/collection_tools/tests/inc/components.rs delete mode 100644 module/core/collection_tools/tests/nostd/constructors.rs delete mode 100644 module/core/collection_tools/tests/nostd/into_constructors.rs delete mode 100644 module/core/collection_tools/tests/nostd/mod.rs delete mode 100644 module/core/collection_tools/tests/nostd/reexport.rs delete mode 100644 module/core/collection_tools/tests/nostd_tests.rs diff --git a/module/core/collection_tools/Cargo.toml b/module/core/collection_tools/Cargo.toml index 4cc1addaca..197d4e2ca2 100644 --- a/module/core/collection_tools/Cargo.toml +++ b/module/core/collection_tools/Cargo.toml @@ -57,7 +57,7 @@ collection_constructors = [] collection_into_constructors = [] # STD collection for no_std. collection_std = [] - +# qqq : is this feature used? seems not. if yes, what is it responsible for? discuss [dependencies] diff --git a/module/core/collection_tools/Readme.md b/module/core/collection_tools/Readme.md index 8d2e831832..07893f301d 100644 --- a/module/core/collection_tools/Readme.md +++ b/module/core/collection_tools/Readme.md @@ -94,6 +94,10 @@ Instead of Click to see ```rust +# #[ cfg( all( feature = "enabled", feature = "collection_std" ) ) ] +# #[ cfg( any( feature = "use_alloc", not( feature = "no_std" ) ) ) ] +# { + #[ cfg( feature = "use_alloc" ) ] use hashbrown::HashSet; // a `no_std` replacement for `HashSet` #[ cfg( not( feature = "no_std" ) ) ] @@ -102,6 +106,8 @@ use std::collections::HashSet; let mut vec : HashSet< i32 > = HashSet::new(); vec.insert( 1 ); assert_eq!( vec.contains( &1 ), true ); + +# } ``` diff --git a/module/core/collection_tools/src/lib.rs b/module/core/collection_tools/src/lib.rs index d87f6782ef..220d3689a6 100644 --- a/module/core/collection_tools/src/lib.rs +++ b/module/core/collection_tools/src/lib.rs @@ -4,6 +4,35 @@ #![ doc( html_root_url = "https://docs.rs/collection_tools/latest/collection_tools/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] +// qqq : make subdirectory for each container + +// qqq : move out of lib.rs file +/// Not meant to be called directly. +#[ doc( hidden ) ] +#[ macro_export( local_inner_macros ) ] +macro_rules! count +{ + ( @single $( $x : tt )* ) => ( () ); + + ( + @count $( $rest : expr ),* + ) + => + ( + < [ () ] >::len( &[ $( count!( @single $rest ) ),* ] ) + ); +} + +/// Macros to construct the collections. +/// Basically a tweaked version of `literally` crate but using `alloc` / `hashbrown` instead of `std` +#[ cfg( all( feature = "enabled", feature = "collection_constructors" ) ) ] +pub mod constructors; + +/// Macros to construct the collections, using `.into()` under the hood. +/// Often requires explicitly specifying type to cast to. +#[ cfg( all( feature = "enabled", feature = "collection_into_constructors" ) ) ] +pub mod into_constructors; + /// Namespace with dependencies. #[ cfg( feature = "enabled" ) ] pub mod dependency @@ -28,21 +57,30 @@ pub mod protected #[ allow( unused_imports ) ] pub use super::orphan::*; + // #[ cfg( feature = "use_alloc" ) ] extern crate alloc; + + // #[ cfg( feature = "use_alloc" ) ] #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use alloc::vec::Vec; + + // #[ cfg( feature = "use_alloc" ) ] #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use alloc::collections::{ BinaryHeap, BTreeMap, BTreeSet, LinkedList, VecDeque }; + + // qqq : what is comnination `use_alloc` + !`no_std` #[ cfg( feature = "use_alloc" ) ] #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use hashbrown::{ HashMap, HashSet }; + #[ cfg( not( feature = "no_std" ) ) ] #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use std::collections::{ HashMap, HashSet }; + } /// Parented namespace of the module. @@ -76,30 +114,3 @@ pub mod prelude #[ allow( unused_imports ) ] pub use super::into_constructors::*; } - -/// Not meant to be called directly. -#[ doc( hidden ) ] -#[ macro_export( local_inner_macros ) ] -macro_rules! count -{ - ( @single $( $x : tt )* ) => ( () ); - - ( - @count $( $rest : expr ),* - ) - => - ( - < [ () ] >::len( &[ $( count!( @single $rest ) ),* ] ) - ); -} - - -/// Macros to construct the collections. -/// Basically a tweaked version of `literally` crate but using `alloc` / `hashbrown` instead of `std` -#[ cfg( all( feature = "enabled", feature = "collection_constructors" ) ) ] -pub mod constructors; - -/// Macros to construct the collections, using `.into()` under the hood. -/// Often requires explicitly specifying type to cast to. -#[ cfg( all( feature = "enabled", feature = "collection_into_constructors" ) ) ] -pub mod into_constructors; diff --git a/module/core/collection_tools/src/vec.rs b/module/core/collection_tools/src/vec.rs new file mode 100644 index 0000000000..f4e6502089 --- /dev/null +++ b/module/core/collection_tools/src/vec.rs @@ -0,0 +1,2 @@ + +pub use core::slice::Iter diff --git a/module/core/collection_tools/tests/inc/components.rs b/module/core/collection_tools/tests/inc/components.rs new file mode 100644 index 0000000000..ee19c86a6c --- /dev/null +++ b/module/core/collection_tools/tests/inc/components.rs @@ -0,0 +1,55 @@ +#[ allow( unused_imports ) ] +use super::*; + +// + +// qqq : implement similar test for all containers +#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +#[ test ] +fn vec_iters() +{ + + struct MyContainer + { + entries : Vec< i32 >, + } + + impl IntoIterator for MyContainer + { + type Item = i32; + type IntoIter = std::vec::IntoIter< i32 >; + // type IntoIter = the_module::vec::IntoIter< i32 >; + // qqq : should work + + fn into_iter( self ) -> Self::IntoIter + { + self.entries.into_iter() // Create an iterator from the internal HashSet. + } + } + + impl< 'a > IntoIterator for &'a MyContainer + { + type Item = &'a i32; + type IntoIter = std::slice::Iter< 'a, i32 >; + // type IntoIter = the_module::vec::Iter< 'a, i32 >; + // qqq : should work + + fn into_iter( self ) -> Self::IntoIter + { + self.entries.iter() // Borrow the elements via an iterator. + } + } + + let instance = MyContainer { entries : vec![ 1, 2, 3 ] }; + let got : Vec< _ > = ( &instance ).into_iter().cloned().collect(); + let exp = vec![ 1, 2, 3 ]; + a_id!( got, exp ); + + let instance = MyContainer { entries : vec![ 1, 2, 3 ] }; + let got : Vec< _ > = instance.into_iter().collect(); + let exp = vec![ 1, 2, 3 ]; + a_id!( got, exp ); + +} + +// qqq : implement VectorInterface diff --git a/module/core/collection_tools/tests/inc/constructors.rs b/module/core/collection_tools/tests/inc/constructors.rs index f910b900aa..dda241a1a4 100644 --- a/module/core/collection_tools/tests/inc/constructors.rs +++ b/module/core/collection_tools/tests/inc/constructors.rs @@ -137,7 +137,7 @@ fn vec() // test.case( "empty" ); let got : the_module::Vec< i32 > = the_module::vec!{}; - let exp = the_module::Vec::new(); + let exp = the_module::Vec::< i32 >::new(); assert_eq!( got, exp ); // test.case( "multiple entry" ); diff --git a/module/core/collection_tools/tests/inc/into_constructors.rs b/module/core/collection_tools/tests/inc/into_constructors.rs index bce1d6fc8b..7423159092 100644 --- a/module/core/collection_tools/tests/inc/into_constructors.rs +++ b/module/core/collection_tools/tests/inc/into_constructors.rs @@ -1,3 +1,5 @@ +// xxx : uncomment + #[ allow( unused_imports ) ] use super::*; @@ -52,7 +54,7 @@ fn binary_heap() // test.case( "empty" ); let got : the_module::BinaryHeap< i32 > = the_module::into_heap!{}; - let exp = the_module::BinaryHeap::new(); + let exp = the_module::BinaryHeap::< i32 >::new(); assert_eq!( got.into_vec(), exp.into_vec() ); // test.case( "multiple entry" ); @@ -137,7 +139,7 @@ fn vec() // test.case( "empty" ); let got : the_module::Vec< i32 > = the_module::into_vec!{}; - let exp = the_module::Vec::new(); + let exp = the_module::Vec::< i32 >::new(); assert_eq!( got, exp ); // test.case( "multiple entry" ); diff --git a/module/core/collection_tools/tests/inc/mod.rs b/module/core/collection_tools/tests/inc/mod.rs index 843c19925e..00cc188bc4 100644 --- a/module/core/collection_tools/tests/inc/mod.rs +++ b/module/core/collection_tools/tests/inc/mod.rs @@ -9,3 +9,8 @@ mod constructors; #[ cfg( any( feature = "collection_std" ) ) ] mod reexport; + +mod components; + +// qqq : make subdirectory for each container +// qqq : don't put tests otsude of directory `inc` diff --git a/module/core/collection_tools/tests/nostd/constructors.rs b/module/core/collection_tools/tests/nostd/constructors.rs deleted file mode 100644 index be3df1768d..0000000000 --- a/module/core/collection_tools/tests/nostd/constructors.rs +++ /dev/null @@ -1,171 +0,0 @@ -#[ allow( unused_imports ) ] -use super::*; - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn b_tree_map() -{ - - // test.case( "empty" ); - let got : the_module::BTreeMap< i32, i32 > = the_module::bmap!{}; - let exp = the_module::BTreeMap::new(); - assert_eq!( got, exp ); - - // test.case( "multiple entry" ); - let got = the_module::bmap!{ 3 => 13, 4 => 1 }; - let mut exp = the_module::BTreeMap::new(); - exp.insert(3, 13); - exp.insert(4, 1); - assert_eq!( got, exp ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn b_tree_set() -{ - - // test.case( "empty" ); - let got : the_module::BTreeSet< i32 > = the_module::bset!{}; - let exp = the_module::BTreeSet::new(); - assert_eq!( got, exp ); - - // test.case( "multiple entry" ); - let got = the_module::bset!{ 3, 13 }; - let mut exp = the_module::BTreeSet::new(); - exp.insert(3); - exp.insert(13); - assert_eq!( got, exp ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn binary_heap() -{ - - // test.case( "empty" ); - let got : the_module::BinaryHeap< i32 > = the_module::heap!{}; - let exp = the_module::BinaryHeap::new(); - assert_eq!( got.into_vec(), exp.into_vec() ); - - // test.case( "multiple entry" ); - let got = the_module::heap!{ 3, 13 }; - let mut exp = the_module::BinaryHeap::new(); - exp.push(3); - exp.push(13); - assert_eq!( got.into_sorted_vec(), exp.into_sorted_vec() ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn hash_map() -{ - - // test.case( "empty" ); - let got : the_module::HashMap< i32, i32 > = the_module::hmap!{}; - let exp = the_module::HashMap::new(); - assert_eq!( got, exp ); - - - // test.case( "multiple entry" ); - let got = the_module::hmap!{ 3 => 13, 4 => 1 }; - let mut exp = the_module::HashMap::new(); - exp.insert( 3, 13 ); - exp.insert( 4, 1 ); - assert_eq!( got, exp ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn hash_set() -{ - - // test.case( "empty" ); - let got : the_module::HashSet< i32 > = the_module::hset!{}; - let exp = the_module::HashSet::new(); - assert_eq!( got, exp ); - - // test.case( "multiple entry" ); - let got = the_module::hset!{ 13, 11 }; - let mut exp = the_module::HashSet::new(); - exp.insert( 11 ); - exp.insert( 13 ); - assert_eq!( got, exp ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn linked_list() -{ - - // test.case( "empty" ); - let got : the_module::LinkedList< i32 > = the_module::list!{}; - let exp = the_module::LinkedList::new(); - assert_eq!( got, exp ); - - // test.case( "multiple entry" ); - let got = the_module::list!{ 13, 15 }; - let mut exp = the_module::LinkedList::new(); - exp.push_front( 15 ); - exp.push_front( 13 ); - assert_eq!( got, exp ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn vec() -{ - - // test.case( "empty" ); - let got : the_module::Vec< i32 > = the_module::vec!{}; - let exp = the_module::Vec::new(); - assert_eq!( got, exp ); - - // test.case( "multiple entry" ); - let got = the_module::vec!{ 3, 13 }; - let mut exp = the_module::Vec::new(); - exp.push( 3 ); - exp.push( 13 ); - assert_eq!( got, exp ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn vec_deque() -{ - - // test.case( "empty" ); - let got : the_module::VecDeque< i32 > = the_module::vecd!{}; - let exp = the_module::VecDeque::new(); - assert_eq!( got, exp ); - - // test.case( "multiple entry" ); - let got = the_module::vecd!{ 3, 13 }; - let mut exp = the_module::VecDeque::new(); - exp.push_front( 13 ); - exp.push_front( 3 ); - assert_eq!( got, exp ); - -} diff --git a/module/core/collection_tools/tests/nostd/into_constructors.rs b/module/core/collection_tools/tests/nostd/into_constructors.rs deleted file mode 100644 index 19569ef6e7..0000000000 --- a/module/core/collection_tools/tests/nostd/into_constructors.rs +++ /dev/null @@ -1,168 +0,0 @@ -#[ allow( unused_imports ) ] -use super::*; - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn b_tree_map() -{ - - // test.case( "empty" ); - let got : the_module::BTreeMap< i32, i32 > = the_module::into_bmap!{}; - let exp : the_module::BTreeMap< i32, i32 > = the_module::BTreeMap::new(); - assert_eq!( got, exp ); - - // test.case( "single entry" ); - let got = the_module::into_bmap!{ 3 => 13 }; - let mut exp = the_module::BTreeMap::new(); - exp.insert(3, 13); - assert_eq!( got, exp ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn b_tree_set() -{ - - // test.case( "empty" ); - let got : the_module::BTreeSet< i32 > = the_module::into_bset!{}; - let exp : the_module::BTreeSet< i32 > = the_module::BTreeSet::new(); - assert_eq!( got, exp ); - - // test.case( "single entry" ); - let got = the_module::into_bset!{ 3, 13 }; - let mut exp = the_module::BTreeSet::new(); - exp.insert(3); - exp.insert(13); - assert_eq!( got, exp ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn binary_heap() -{ - - // test.case( "empty" ); - let got : the_module::BinaryHeap< i32 > = the_module::into_heap!{}; - let exp : the_module::BinaryHeap< i32 > = the_module::BinaryHeap::new(); - assert_eq!( got.into_vec(), exp.into_vec() ); - - // test.case( "single entry" ); - let got: the_module::BinaryHeap< i32 > = the_module::into_heap!{ 3, 13 }; - let mut exp = the_module::BinaryHeap::new(); - exp.push(3); - exp.push(13); - assert_eq!( got.into_sorted_vec(), exp.into_sorted_vec() ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn hash_map() -{ - - // test.case( "empty" ); - let got : the_module::HashMap< i32, i32 > = the_module::into_hmap!{}; - let exp = the_module::HashMap::new(); - assert_eq!( got, exp ); - - - // test.case( "single entry" ); - let got = the_module::into_hmap!{ 3 => 13 }; - let mut exp = the_module::HashMap::new(); - exp.insert( 3, 13 ); - assert_eq!( got, exp ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn hash_set() -{ - - // test.case( "empty" ); - let got : the_module::HashSet< i32 > = the_module::into_hset!{}; - let exp = the_module::HashSet::new(); - assert_eq!( got, exp ); - - // test.case( "single entry" ); - let got = the_module::into_hset!{ 13 }; - let mut exp = the_module::HashSet::new(); - exp.insert( 13 ); - assert_eq!( got, exp ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn linked_list() -{ - - // test.case( "empty" ); - let got : the_module::LinkedList< i32 > = the_module::into_list!{}; - let exp = the_module::LinkedList::new(); - assert_eq!( got, exp ); - - // test.case( "single entry" ); - let got = the_module::into_list!{ 13, 15 }; - let mut exp = the_module::LinkedList::new(); - exp.push_front( 15 ); - exp.push_front( 13 ); - assert_eq!( got, exp ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn vec() -{ - - // test.case( "empty" ); - let got : the_module::Vec< i32 > = the_module::into_vec!{}; - let exp : the_module::Vec< i32 > = the_module::Vec::new(); - assert_eq!( got, exp ); - - // test.case( "single entry" ); - let got : the_module::Vec< i32 > = the_module::into_vec!{ 3, 13 }; - let mut exp = the_module::Vec::new(); - exp.push( 3 ); - exp.push( 13 ); - assert_eq!( got, exp ); - -} - -// - -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ test ] -fn vec_deque() -{ - - // test.case( "empty" ); - let got : the_module::VecDeque< i32 > = the_module::into_vecd!{}; - let exp = the_module::VecDeque::new(); - assert_eq!( got, exp ); - - // test.case( "single entry" ); - let got : the_module::VecDeque< i32 > = the_module::into_vecd!{ 3, 13 }; - let mut exp = the_module::VecDeque::new(); - exp.push_front( 13 ); - exp.push_front( 3 ); - assert_eq!( got, exp ); - -} diff --git a/module/core/collection_tools/tests/nostd/mod.rs b/module/core/collection_tools/tests/nostd/mod.rs deleted file mode 100644 index c83f7f2779..0000000000 --- a/module/core/collection_tools/tests/nostd/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -#[ allow( unused_imports ) ] -use super::*; - -#[ cfg( any( feature = "collection_constructors" ) ) ] -mod constructors; - -// aaa : xxx : does not work for `use_alloc`, make it working -- Made by switching from std collections to alloc / hashbrown -// #[ cfg( not( feature = "use_alloc" ) ) ] -#[ cfg( any( feature = "collection_into_constructors" ) ) ] -mod into_constructors; - -#[ cfg( any( feature = "collection_std" ) ) ] -mod reexport; diff --git a/module/core/collection_tools/tests/nostd/reexport.rs b/module/core/collection_tools/tests/nostd/reexport.rs deleted file mode 100644 index 000c6bc3fd..0000000000 --- a/module/core/collection_tools/tests/nostd/reexport.rs +++ /dev/null @@ -1,105 +0,0 @@ -use super::*; - -// - -#[ test ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -fn b_tree_map() -{ - let mut map : the_module::BTreeMap< i32, i32 > = the_module::BTreeMap::new(); - map.insert( 1, 2 ); - let exp = 2; - let got = *map.get( &1 ).unwrap(); - assert_eq!( exp, got ); -} - -// - -#[ test ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -fn b_tree_set() -{ - let mut map : the_module::BTreeSet< i32 > = the_module::BTreeSet::new(); - map.insert( 1 ); - assert_eq!( map.contains( &1 ), true ); - assert_eq!( map.contains( &2 ), false ); -} - -// - -#[ test ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -fn binary_heap() -{ - let mut map : the_module::BinaryHeap< i32 > = the_module::BinaryHeap::new(); - map.push( 1 ); - let exp = Some(1).as_ref(); - let got = map.peek(); - assert_eq!( exp, got ); -} - -// - -#[ test ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -fn hash_map() -{ - let mut map : the_module::HashMap< i32, i32 > = the_module::HashMap::new(); - map.insert( 1, 2 ); - let exp = 2; - let got = *map.get( &1 ).unwrap(); - assert_eq!( exp, got ); -} - -// - -#[ test ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -fn hash_set() -{ - let mut map : the_module::HashSet< i32 > = the_module::HashSet::new(); - map.insert( 1 ); - assert_eq!( map.contains( &1 ), true ); - assert_eq!( map.contains( &2 ), false ); -} - -// - -#[ test ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -fn linked_list() -{ - let mut map : the_module::LinkedList< i32 > = the_module::LinkedList::new(); - map.push_back( 1 ); - assert_eq!( map.contains( &1 ), true ); - assert_eq!( map.contains( &2 ), false ); -} - -// - -#[ test ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -fn vec() -{ - - let mut map : the_module::Vec< i32 > = the_module::Vec::new(); - map.push( 1 ); - map.push( 2 ); - let got = map.first().unwrap().clone(); - assert_eq!( got, 1 ); - let got = map.last().unwrap().clone(); - assert_eq!( got, 2 ); - -} - -// - -#[ test ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -fn vec_deque() -{ - let mut map : the_module::VecDeque< i32 > = the_module::VecDeque::new(); - map.push_back( 1 ); - assert_eq!( map.contains( &1 ), true ); - assert_eq!( map.contains( &2 ), false ); -} diff --git a/module/core/collection_tools/tests/nostd_tests.rs b/module/core/collection_tools/tests/nostd_tests.rs deleted file mode 100644 index d22a19e7b1..0000000000 --- a/module/core/collection_tools/tests/nostd_tests.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![ cfg_attr( feature = "no_std", no_std ) ] -// tests without std - -#[ allow( unused_imports ) ] -use ::collection_tools as the_module; -// #[ allow( unused_imports ) ] -// use test_tools::exposed::*; -#[ path="../../../../module/step/meta/src/module/aggregating.rs" ] -mod aggregating; - -mod nostd; -// aaa : enable \ No newline at end of file diff --git a/module/core/collection_tools/tests/tests.rs b/module/core/collection_tools/tests/tests.rs index 00689894e0..b84a5dc030 100644 --- a/module/core/collection_tools/tests/tests.rs +++ b/module/core/collection_tools/tests/tests.rs @@ -1,11 +1,12 @@ // usual tests -#[ allow( unused_imports ) ] -use ::collection_tools as the_module; -// #[ allow( unused_imports ) ] -// use test_tools::exposed::*; #[ path="../../../../module/step/meta/src/module/aggregating.rs" ] mod aggregating; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ allow( unused_imports ) ] +use ::collection_tools as the_module; + mod inc; -// aaa From 32c973565bde462504d6fa565e44eb48a14baf7b Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 18:33:35 +0300 Subject: [PATCH 522/533] former : cleaning --- module/core/former/Readme.md | 5 +- module/core/former/src/container.rs | 9 +- module/core/former/src/lib.rs | 6 - .../inc/former_tests/a_primitives_manual.rs | 7 +- .../former_tests/container_former_common.rs | 6 +- .../former_tests/container_former_hashmap.rs | 4 +- .../former_tests/container_former_hashset.rs | 4 +- .../only_test/parametrized_struct.rs | 2 +- .../former_tests/only_test/subformer_basic.rs | 6 +- .../former_tests/unsigned_primitive_types.rs | 2 +- module/core/former/tests/inc/mod.rs | 139 +++++++++--------- 11 files changed, 90 insertions(+), 100 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 6d83940670..b84b874a0b 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -113,6 +113,7 @@ fn main() End : former::FormingEnd< UserProfileFormerDefinitionTypes< Context, Formed > >, { type Definition = UserProfileFormerDefinition< Context, Formed, End >; + type Types = UserProfileFormerDefinitionTypes< Context, Formed >; } // = definition @@ -206,7 +207,7 @@ fn main() impl former::Storage for UserProfileFormerStorage where { - type Performed = UserProfile; + type Preformed = UserProfile; } impl former::StoragePreform for UserProfileFormerStorage @@ -1105,7 +1106,7 @@ fn main() impl< Context, Formed > former::FormerMutator for Struct1FormerDefinitionTypes< Context, Formed > { - Mutates the context and storage of the entity just before the formation process completes. + /// Mutates the context and storage of the entity just before the formation process completes. #[ inline ] fn form_mutation( storage : &mut Self::Storage, _context : &mut ::core::option::Option< Self::Context > ) { diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 85f279f9cd..bcac3acde0 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -121,6 +121,10 @@ pub trait ValToEntry< Container > /// /// # Example /// ``` + /// use former::ValToEntry; + /// + /// struct PairMap; + /// /// impl ValToEntry< PairMap > for (i32, i32) /// { /// type Entry = ( String, i32 ); @@ -268,8 +272,9 @@ where /// impl IntoIterator for MyContainer /// { /// type Item = i32; - /// type IntoIter = collection_tools::vec::IntoIter< i32 >; - // xxx : make sure collection_tools has it + /// type IntoIter = std::vec::IntoIter< i32 >; + /// // type IntoIter = collection_tools::vec::IntoIter< i32 >; + /// // qqq : zzz : make sure collection_tools has itearators /// /// fn into_iter( self ) -> Self::IntoIter /// { diff --git a/module/core/former/src/lib.rs b/module/core/former/src/lib.rs index 0e20de312b..cb5b976dd2 100644 --- a/module/core/former/src/lib.rs +++ b/module/core/former/src/lib.rs @@ -4,12 +4,6 @@ #![ doc( html_root_url = "https://docs.rs/former/latest/former/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -// zzz : remove -#![ allow( missing_docs ) ] - -// zzz : describe "Context-aware forming process" -// zzz : explain role of container in former - /// Axiomatic things. #[ cfg( feature = "enabled" ) ] #[ cfg( feature = "derive_former" ) ] diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 82c3a0bbf9..31aa3191cc 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -84,10 +84,6 @@ where type Context = Context; } -// // zzz : documentation -// pub type Struct1FormerWithClosure< Context, Formed > = -// Struct1FormerDefinition< Context, Formed, former::FormingEndClosure< Struct1FormerDefinitionTypes< Context, Formed > > >; - // = storage // generated by former @@ -198,7 +194,6 @@ where impl< Definition > Struct1Former< Definition > where Definition : former::FormerDefinition< Storage = Struct1FormerStorage >, - // Definition::Types : former::FormerDefinitionTypes< Storage = Struct1FormerStorage >, { #[ inline( always ) ] @@ -208,7 +203,7 @@ where return result; } - // zzz : update description + // xxx : update description #[ inline( always ) ] pub fn new( on_end : Definition::End ) -> Self { diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index 16d0378127..810268b24f 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -42,7 +42,7 @@ fn definitions() fn begin_and_custom_end() { - // zzz : make example with that + // xxx : make example with that // basic case @@ -94,7 +94,7 @@ fn begin_and_custom_end() fn custom_definition() { - // zzz : make example of that + // xxx : make example of that struct Return13; impl former::FormerDefinitionTypes for Return13 @@ -160,7 +160,7 @@ fn custom_definition() fn custom_definition_parametrized() { - // zzz : make example of that + // xxx : make example of that struct Return13< E >( ::core::marker::PhantomData< E > ); diff --git a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs index 5c29282a7e..8d8ffef410 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs @@ -5,7 +5,7 @@ use super::*; #[ allow( unused_imports ) ] use collection_tools::HashMap; -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn add() @@ -85,7 +85,7 @@ fn add() } -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn replace() diff --git a/module/core/former/tests/inc/former_tests/container_former_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs index 72ea2af67b..8ee7adb1c6 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashset.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashset.rs @@ -5,7 +5,7 @@ use super::*; #[ allow( unused_imports ) ] use collection_tools::HashSet; -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn add() @@ -85,7 +85,7 @@ fn add() } -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn replace() diff --git a/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs b/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs index a829d19a0d..5b1123de1e 100644 --- a/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs +++ b/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs @@ -39,7 +39,7 @@ fn command_form() // -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn command_properties() diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs index 861e81d760..f966003840 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs @@ -13,7 +13,7 @@ // ; // ca.execute( input ).unwrap(); -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn command_with_closure() @@ -59,7 +59,7 @@ fn command_with_closure() // -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn command_properties() @@ -113,7 +113,7 @@ fn command_properties() // -// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn aggregator() diff --git a/module/core/former/tests/inc/former_tests/unsigned_primitive_types.rs b/module/core/former/tests/inc/former_tests/unsigned_primitive_types.rs index 32bb942485..2d6fca6ac7 100644 --- a/module/core/former/tests/inc/former_tests/unsigned_primitive_types.rs +++ b/module/core/former/tests/inc/former_tests/unsigned_primitive_types.rs @@ -47,7 +47,7 @@ tests_impls! // -// zzz : make it working +// xxx : make it working fn with_u16() { // #[ derive( Debug, PartialEq, the_module::Former ) ] diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 4accf5c331..1e33431148 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -100,78 +100,73 @@ mod former_tests #[ cfg( any( not( feature = "no_std" ) ) ) ] mod subformer_subform_and_container_parametrized; - // xxx +} + +#[ cfg( feature = "derive_components" ) ] +mod components_tests +{ + use super::*; + + #[ cfg( feature = "derive_component_from" ) ] + mod component_from_manual; + #[ cfg( feature = "derive_component_from" ) ] + mod component_from; + + #[ cfg( feature = "derive_component_assign" ) ] + mod component_assign_manual; + #[ cfg( feature = "derive_component_assign" ) ] + mod component_assign; + + #[ cfg( all( feature = "derive_component_assign", feature = "derive_components_assign" ) ) ] + mod components_assign_manual; + #[ cfg( all( feature = "derive_component_assign", feature = "derive_components_assign" ) ) ] + mod components_assign; + + #[ cfg( all( feature = "derive_from_components" ) ) ] + mod from_components_manual; + #[ cfg( all( feature = "derive_from_components" ) ) ] + mod from_components; + + #[ cfg( all( feature = "derive_component_from", feature = "derive_component_assign", feature = "derive_components_assign", feature = "derive_from_components" ) ) ] + mod composite_manual; + #[ cfg( all( feature = "derive_component_from", feature = "derive_component_assign", feature = "derive_components_assign", feature = "derive_from_components" ) ) ] + mod composite; } -// xxx -// #[ cfg( feature = "derive_components" ) ] -// mod components_tests -// { -// use super::*; -// -// #[ cfg( feature = "derive_component_from" ) ] -// mod component_from_manual; -// #[ cfg( feature = "derive_component_from" ) ] -// mod component_from; -// -// #[ cfg( feature = "derive_component_assign" ) ] -// mod component_assign_manual; -// #[ cfg( feature = "derive_component_assign" ) ] -// mod component_assign; -// -// #[ cfg( all( feature = "derive_component_assign", feature = "derive_components_assign" ) ) ] -// mod components_assign_manual; -// #[ cfg( all( feature = "derive_component_assign", feature = "derive_components_assign" ) ) ] -// mod components_assign; -// -// #[ cfg( all( feature = "derive_from_components" ) ) ] -// mod from_components_manual; -// #[ cfg( all( feature = "derive_from_components" ) ) ] -// mod from_components; -// -// #[ cfg( all( feature = "derive_component_from", feature = "derive_component_assign", feature = "derive_components_assign", feature = "derive_from_components" ) ) ] -// mod composite_manual; -// #[ cfg( all( feature = "derive_component_from", feature = "derive_component_assign", feature = "derive_components_assign", feature = "derive_from_components" ) ) ] -// mod composite; -// -// } - -// xxx -// only_for_terminal_module! -// { -// -// // stable have different information about error -// // that's why these tests are active only for nightly -// #[ test_tools::nightly ] -// #[ test ] -// fn former_trybuild() -// { -// -// println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); -// let t = test_tools::compiletime::TestCases::new(); -// -// // zzz : uncomment -// t.compile_fail( "tests/inc/former_tests/compiletime/field_attr_bad.rs" ); -// t.compile_fail( "tests/inc/former_tests/compiletime/struct_attr_bad.rs" ); -// t.pass( "tests/inc/former_tests/compiletime/hashmap_without_parameter.rs" ); -// t.pass( "tests/inc/former_tests/compiletime/vector_without_parameter.rs" ); -// -// } -// -// // stable have different information about error -// // that's why these tests are active only for nightly -// #[ test_tools::nightly ] -// #[ test ] -// fn components_trybuild() -// { -// -// println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); -// let _t = test_tools::compiletime::TestCases::new(); -// -// // zzz : make it working test -// //t.run( "tests/inc/components_tests/compiletime/components_component_from_debug.rs" ); -// -// } -// -// } +only_for_terminal_module! +{ + + // stable have different information about error + // that's why these tests are active only for nightly + #[ test_tools::nightly ] + #[ test ] + fn former_trybuild() + { + + println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); + let t = test_tools::compiletime::TestCases::new(); + + t.compile_fail( "tests/inc/former_tests/compiletime/field_attr_bad.rs" ); + t.compile_fail( "tests/inc/former_tests/compiletime/struct_attr_bad.rs" ); + t.pass( "tests/inc/former_tests/compiletime/hashmap_without_parameter.rs" ); + t.pass( "tests/inc/former_tests/compiletime/vector_without_parameter.rs" ); + + } + + // stable have different information about error + // that's why these tests are active only for nightly + #[ test_tools::nightly ] + #[ test ] + fn components_trybuild() + { + + println!( "current_dir : {:?}", std::env::current_dir().unwrap() ); + let _t = test_tools::compiletime::TestCases::new(); + + // zzz : make it working test + //t.run( "tests/inc/components_tests/compiletime/components_component_from_debug.rs" ); + + } + +} From acb5dd1d12bcb848ced4df153854202a76c8014d Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 18:59:59 +0300 Subject: [PATCH 523/533] former : cleaning --- .../examples/former_custom_container.rs | 4 +- .../former_custom_container_setter.rs | 4 +- module/core/former/src/container.rs | 900 ++++++++++-------- .../former/src/{ => container}/hash_map.rs | 53 +- .../former/src/{ => container}/hash_set.rs | 69 +- .../core/former/src/{ => container}/vector.rs | 53 +- module/core/former/src/definition.rs | 3 +- module/core/former/src/lib.rs | 39 - .../inc/former_tests/a_containers_manual.rs | 12 +- .../former_tests/container_former_common.rs | 22 +- .../former_tests/container_former_hashmap.rs | 16 +- .../former_tests/container_former_hashset.rs | 16 +- .../inc/former_tests/container_former_vec.rs | 16 +- .../only_test/parametrized_struct.rs | 2 +- .../former_tests/only_test/subformer_basic.rs | 2 +- .../parametrized_struct_manual.rs | 4 +- .../subformer_container_custom.rs | 2 +- .../subformer_container_manual.rs | 4 +- .../subformer_container_setter_off.rs | 2 +- .../subformer_container_setter_on.rs | 2 +- .../former_meta/src/derive_former/field.rs | 12 +- .../src/derive_former/field_attrs.rs | 2 +- 22 files changed, 674 insertions(+), 565 deletions(-) rename module/core/former/src/{ => container}/hash_map.rs (66%) rename module/core/former/src/{ => container}/hash_set.rs (66%) rename module/core/former/src/{ => container}/vector.rs (65%) diff --git a/module/core/former/examples/former_custom_container.rs b/module/core/former/examples/former_custom_container.rs index c9a55a142d..c3e9ff0f8b 100644 --- a/module/core/former/examples/former_custom_container.rs +++ b/module/core/former/examples/former_custom_container.rs @@ -249,9 +249,9 @@ fn main() // = subformer - // Subformer type alias simplifies the usage of `ContainerSubformer` with `LoggingSet`. + // Subformer type alias simplifies the usage of `ContainerFormer` with `LoggingSet`. pub type LoggingSetAsSubformer< K, Context, Formed, End > = - former::ContainerSubformer::< K, LoggingSetDefinition< K, Context, Formed, End > >; + former::ContainerFormer::< K, LoggingSetDefinition< K, Context, Formed, End > >; // == use custom container diff --git a/module/core/former/examples/former_custom_container_setter.rs b/module/core/former/examples/former_custom_container_setter.rs index 94e11dbecc..d5565a0908 100644 --- a/module/core/former/examples/former_custom_container_setter.rs +++ b/module/core/former/examples/former_custom_container_setter.rs @@ -48,14 +48,14 @@ fn main() children : HashMap< String, Child >, } - /// The containr setter provides a container setter that returns a ContainerSubformer tailored for managing a collection of child entities. It employs a generic container definition to facilitate operations on the entire collection, such as adding or updating elements. + /// The containr setter provides a container setter that returns a ContainerFormer tailored for managing a collection of child entities. It employs a generic container definition to facilitate operations on the entire collection, such as adding or updating elements. impl< Definition, > ParentFormer< Definition, > where Definition : former::FormerDefinition< Storage = ParentFormerStorage >, { #[ inline( always ) ] - pub fn children( self ) -> former::ContainerSubformer:: + pub fn children( self ) -> former::ContainerFormer:: < ( String, Child ), former::HashMapDefinition< String, Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index bcac3acde0..41c3120a37 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -5,485 +5,557 @@ //! such as vectors, hash maps, and custom container implementations. //! -use crate::*; - -/// Represents a container by defining the types of entries and values it handles. -/// -/// This trait abstracts the nature of containers in data structures, facilitating the handling of contained -/// entries and values, especially in scenarios where the structure of the container allows for complex relationships, -/// such as `HashMap`s. It not only identifies what constitutes an entry and a value in the context of the container -/// but also provides utility for converting between these two, which is critical in operations involving entry manipulation -/// and value retrieval. - -pub trait Container +/// Internal namespace. +pub( crate ) mod private { - /// The type of entries that can be added to the container. This type can differ from `Val` in containers like `HashMap`, - /// where an entry might represent a key-value pair, and `Val` could represent just the value or the key. - type Entry; - /// The type of values stored in the container. This might be distinct from `Entry` in complex containers. - /// For example, in a `HashMap`, while `Entry` might be a (key, value) tuple, `Val` might only be the value part. - type Val; + use crate::*; - /// Converts an entry to its corresponding value within the container. This function is essential for abstracting - /// the container's internal representation from the values it manipulates. - fn entry_to_val( e : Self::Entry ) -> Self::Val; -} + /// Represents a container by defining the types of entries and values it handles. + /// + /// This trait abstracts the nature of containers in data structures, facilitating the handling of contained + /// entries and values, especially in scenarios where the structure of the container allows for complex relationships, + /// such as `HashMap`s. It not only identifies what constitutes an entry and a value in the context of the container + /// but also provides utility for converting between these two, which is critical in operations involving entry manipulation + /// and value retrieval. -/// Facilitates the conversion of container entries to their corresponding value representations. -/// -/// This trait is utilized to transform an entry of a container into a value, abstracting the operation of containers -/// like vectors or hash maps. It ensures that even in complex container structures, entries can be seamlessly managed -/// and manipulated as values. -pub trait EntryToVal -{ - type Val; + pub trait Container + { + /// The type of entries that can be added to the container. This type can differ from `Val` in containers like `HashMap`, + /// where an entry might represent a key-value pair, and `Val` could represent just the value or the key. + type Entry; - /// Converts an entry into a value representation specific to the type of container. This conversion is crucial - /// for handling operations on entries, especially when they need to be treated or accessed as individual values, - /// such as retrieving the value part from a key-value pair in a hash map. - fn entry_to_val( self ) -> Self::Val; -} + /// The type of values stored in the container. This might be distinct from `Entry` in complex containers. + /// For example, in a `HashMap`, while `Entry` might be a ( key, value ) tuple, `Val` might only be the value part. + type Val; -impl< C, E > EntryToVal< C > for E -where - C : Container< Entry = E >, -{ - type Val = C::Val; + /// Converts an entry to its corresponding value within the container. This function is essential for abstracting + /// the container's internal representation from the values it manipulates. + fn entry_to_val( e : Self::Entry ) -> Self::Val; + } - fn entry_to_val( self ) -> Self::Val + /// Facilitates the conversion of container entries to their corresponding value representations. + /// + /// This trait is utilized to transform an entry of a container into a value, abstracting the operation of containers + /// like vectors or hash maps. It ensures that even in complex container structures, entries can be seamlessly managed + /// and manipulated as values. + pub trait EntryToVal< Container > { - C::entry_to_val( self ) + /// The type of values stored in the container. This might be distinct from `Entry` in complex containers. + /// For example, in a `HashMap`, while `Entry` might be a ( key, value ) tuple, `Val` might only be the value part. + type Val; + + /// Converts an entry into a value representation specific to the type of container. This conversion is crucial + /// for handling operations on entries, especially when they need to be treated or accessed as individual values, + /// such as retrieving the value part from a key-value pair in a hash map. + fn entry_to_val( self ) -> Self::Val; } -} -/// Provides a mechanism for transforming a value back into a container-specific entry format. -/// -/// This trait is particularly valuable in scenarios where the operations on a container require -/// not just the manipulation of values but also the re-integration of these values as entries. -/// It is especially crucial in complex data structures, such as `HashMap`s, where entries -/// often involve a key-value pair, and simple values need to be restructured to fit this model -/// for operations like insertion or update. + impl< C, E > EntryToVal< C > for E + where + C : Container< Entry = E >, + { + type Val = C::Val; -pub trait ContainerValToEntry< Val > -{ - /// The specific type of entry that corresponds to the value within the container. - /// For example, in a `HashMap`, this might be a tuple of a key and a value. - type Entry; + fn entry_to_val( self ) -> Self::Val + { + C::entry_to_val( self ) + } + } - /// Converts a value into a container-specific entry, facilitating operations that modify - /// the container. This method is key for ensuring that values can be correctly integrated - /// back into the container, particularly when the entry type is more complex than the value. - /// - /// # Parameters - /// * `val` - The value to be converted into an entry. + /// Provides a mechanism for transforming a value back into a container-specific entry format. /// - /// # Returns - /// Returns the entry constructed from the provided value, ready for insertion or other modifications. - /// - /// # Example - /// ``` - /// use former::ContainerValToEntry; - /// - /// struct PairMap; - /// - /// impl ContainerValToEntry< ( i32, i32 ) > for PairMap - /// { - /// type Entry = ( String, i32 ); - /// - /// fn val_to_entry( val : ( i32, i32 ) ) -> Self::Entry - /// { - /// (val.0.to_string(), val.1) - /// } - /// } - /// ``` - fn val_to_entry( val : Val ) -> Self::Entry; -} + /// This trait is particularly valuable in scenarios where the operations on a container require + /// not just the manipulation of values but also the re-integration of these values as entries. + /// It is especially crucial in complex data structures, such as `HashMap`s, where entries + /// often involve a key-value pair, and simple values need to be restructured to fit this model + /// for operations like insertion or update. -/// Facilitates the conversion of values back into entries for specific container types. -/// -/// This trait wraps the functionality of `ContainerValToEntry`, providing a more ergonomic -/// interface for converting values directly within the type they pertain to. It is useful -/// in maintaining the integrity of container operations, especially when dealing with -/// sophisticated structures that separate the concept of values and entries, such as `HashMap`s -/// and other associative containers. -pub trait ValToEntry< Container > -{ - /// Represents the type of entry that corresponds to the value within the container. - type Entry; + pub trait ContainerValToEntry< Val > + { + /// The specific type of entry that corresponds to the value within the container. + /// For example, in a `HashMap`, this might be a tuple of a key and a value. + type Entry; + + /// Converts a value into a container-specific entry, facilitating operations that modify + /// the container. This method is key for ensuring that values can be correctly integrated + /// back into the container, particularly when the entry type is more complex than the value. + /// + /// # Parameters + /// * `val` - The value to be converted into an entry. + /// + /// # Returns + /// Returns the entry constructed from the provided value, ready for insertion or other modifications. + /// + /// # Example + /// ``` + /// use former::ContainerValToEntry; + /// + /// struct PairMap; + /// + /// impl ContainerValToEntry< ( i32, i32 ) > for PairMap + /// { + /// type Entry = ( String, i32 ); + /// + /// fn val_to_entry( val : ( i32, i32 ) ) -> Self::Entry + /// { + /// (val.0.to_string(), val.1) + /// } + /// } + /// ``` + fn val_to_entry( val : Val ) -> Self::Entry; + } - /// Transforms the instance (value) into an entry compatible with the specified container. - /// This conversion is essential for operations like insertion or modification within the container, - /// where the value needs to be formatted as an entry. - /// - /// # Returns - /// Returns the entry constructed from the instance of the value, ready for integration into the container. + /// Facilitates the conversion of values back into entries for specific container types. /// - /// # Example - /// ``` - /// use former::ValToEntry; - /// - /// struct PairMap; - /// - /// impl ValToEntry< PairMap > for (i32, i32) - /// { - /// type Entry = ( String, i32 ); - /// - /// fn val_to_entry( self ) -> Self::Entry - /// { - /// (self.0.to_string(), self.1) - /// } - /// } - /// ``` - fn val_to_entry( self ) -> Self::Entry; -} - -impl< C, Val > ValToEntry< C > for Val -where - C : ContainerValToEntry< Val >, -{ - type Entry = C::Entry; + /// This trait wraps the functionality of `ContainerValToEntry`, providing a more ergonomic + /// interface for converting values directly within the type they pertain to. It is useful + /// in maintaining the integrity of container operations, especially when dealing with + /// sophisticated structures that separate the concept of values and entries, such as `HashMap`s + /// and other associative containers. + pub trait ValToEntry< Container > + { + /// Represents the type of entry that corresponds to the value within the container. + type Entry; + + /// Transforms the instance (value) into an entry compatible with the specified container. + /// This conversion is essential for operations like insertion or modification within the container, + /// where the value needs to be formatted as an entry. + /// + /// # Returns + /// Returns the entry constructed from the instance of the value, ready for integration into the container. + /// + /// # Example + /// ``` + /// use former::ValToEntry; + /// + /// struct PairMap; + /// + /// impl ValToEntry< PairMap > for (i32, i32) + /// { + /// type Entry = ( String, i32 ); + /// + /// fn val_to_entry( self ) -> Self::Entry + /// { + /// (self.0.to_string(), self.1) + /// } + /// } + /// ``` + fn val_to_entry( self ) -> Self::Entry; + } - /// Invokes the `val_to_entry` function of the `ContainerValToEntry` trait to convert the value to an entry. - fn val_to_entry( self ) -> C::Entry + impl< C, Val > ValToEntry< C > for Val + where + C : ContainerValToEntry< Val >, { - C::val_to_entry( self ) + type Entry = C::Entry; + + /// Invokes the `val_to_entry` function of the `ContainerValToEntry` trait to convert the value to an entry. + fn val_to_entry( self ) -> C::Entry + { + C::val_to_entry( self ) + } } -} -/// Provides functionality to add individual entries to a container. -/// -/// This trait extends the basic `Container` trait by introducing a method to add entries to a container. -/// It is designed to handle the container's specific requirements and rules for adding entries, such as -/// managing duplicates, maintaining order, or handling capacity constraints. -pub trait ContainerAdd : Container -{ - /// Adds an entry to the container and returns a boolean indicating the success of the operation. - /// - /// Implementations should ensure that the entry is added according to the rules of the container, - /// which might involve checking for duplicates, ordering, or capacity limits. - /// - /// # Parameters - /// - /// * `e`: The entry to be added to the container, where the type `Entry` is defined by the `Container` trait. - /// - /// # Returns - /// - /// Returns `true` if the entry was successfully added, or `false` if not added due to reasons such as - /// the entry already existing in the container or the container reaching its capacity. - /// - /// # Examples - /// - /// Basic usage: - /// - /// ```rust - /// - /// use former::{ Container, ContainerAdd }; - /// - /// struct MyContainer - /// { - /// entries : Vec< i32 >, - /// } - /// - /// impl Container for MyContainer - /// { - /// type Entry = i32; - /// type Val = i32; + /// Provides functionality to add individual entries to a container. /// - /// #[ inline( always ) ] - /// fn entry_to_val( e : Self::Entry ) -> Self::Val - /// { - /// e - /// } - /// - /// } - /// - /// impl ContainerAdd for MyContainer - /// { - /// fn add( &mut self, e : Self::Entry ) -> bool - /// { - /// if self.entries.contains( &e ) - /// { - /// false - /// } - /// else - /// { - /// self.entries.push( e ); - /// true - /// } - /// } - /// } - /// - /// let mut container = MyContainer { entries : vec![] }; - /// assert!( container.add( 10 ) ); // Returns true, entry added - /// assert!( !container.add( 10 ) ); // Returns false, entry already exists - /// ``` - fn add( &mut self, e : Self::Entry ) -> bool; -} + /// This trait extends the basic `Container` trait by introducing a method to add entries to a container. + /// It is designed to handle the container's specific requirements and rules for adding entries, such as + /// managing duplicates, maintaining order, or handling capacity constraints. + pub trait ContainerAdd : Container + { + /// Adds an entry to the container and returns a boolean indicating the success of the operation. + /// + /// Implementations should ensure that the entry is added according to the rules of the container, + /// which might involve checking for duplicates, ordering, or capacity limits. + /// + /// # Parameters + /// + /// * `e`: The entry to be added to the container, where the type `Entry` is defined by the `Container` trait. + /// + /// # Returns + /// + /// Returns `true` if the entry was successfully added, or `false` if not added due to reasons such as + /// the entry already existing in the container or the container reaching its capacity. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```rust + /// + /// use former::{ Container, ContainerAdd }; + /// + /// struct MyContainer + /// { + /// entries : Vec< i32 >, + /// } + /// + /// impl Container for MyContainer + /// { + /// type Entry = i32; + /// type Val = i32; + /// + /// #[ inline( always ) ] + /// fn entry_to_val( e : Self::Entry ) -> Self::Val + /// { + /// e + /// } + /// + /// } + /// + /// impl ContainerAdd for MyContainer + /// { + /// fn add( &mut self, e : Self::Entry ) -> bool + /// { + /// if self.entries.contains( &e ) + /// { + /// false + /// } + /// else + /// { + /// self.entries.push( e ); + /// true + /// } + /// } + /// } + /// + /// let mut container = MyContainer { entries : vec![] }; + /// assert!( container.add( 10 ) ); // Returns true, entry added + /// assert!( !container.add( 10 ) ); // Returns false, entry already exists + /// ``` + fn add( &mut self, e : Self::Entry ) -> bool; + } -/// Defines the capability to replace all entries in a container with a new set of entries. -/// -/// This trait extends the `Container` trait by providing a method to replace the existing entries in -/// the container with a new set. This can be useful for resetting the container's contents or bulk-updating -/// them based on external criteria or operations. -pub trait ContainerAssign : Container -where - Self : IntoIterator< Item = Self::Entry >, -{ - /// Replaces all entries in the container with the provided entries and returns the count of new entries added. - /// - /// This method clears the existing entries and populates the container with new ones provided by an iterator. - /// It is ideal for scenarios where the container needs to be refreshed or updated with a new batch of entries. - /// - /// # Parameters - /// - /// * `entries` : An iterator over the entries to be added to the container. The entries must conform to - /// the `Entry` type defined by the `Container` trait. - /// - /// # Returns - /// - /// Returns the number of entries successfully added to the container. This count may differ from the total - /// number of entries in the iterator if the container imposes restrictions such as capacity limits or duplicate - /// handling. - /// - /// # Examples - /// - /// ```rust - /// use former::{ Container, ContainerAssign }; - /// - /// struct MyContainer - /// { - /// entries : Vec< i32 >, - /// } - /// - /// impl Container for MyContainer - /// { - /// type Entry = i32; - /// type Val = i32; - /// - /// #[ inline( always ) ] - /// fn entry_to_val( e : Self::Entry ) -> Self::Val - /// { - /// e - /// } + /// Defines the capability to replace all entries in a container with a new set of entries. /// - /// } - /// - /// impl IntoIterator for MyContainer - /// { - /// type Item = i32; - /// type IntoIter = std::vec::IntoIter< i32 >; - /// // type IntoIter = collection_tools::vec::IntoIter< i32 >; - /// // qqq : zzz : make sure collection_tools has itearators - /// - /// fn into_iter( self ) -> Self::IntoIter - /// { - /// self.entries.into_iter() // Create an iterator from the internal HashSet. - /// } - /// } - /// - /// impl ContainerAssign for MyContainer - /// { - /// fn assign< Entries >( &mut self, entries : Entries ) -> usize - /// where - /// Entries : IntoIterator< Item = Self::Entry >, - /// { - /// self.entries.clear(); - /// self.entries.extend( entries ); - /// self.entries.len() - /// } - /// } - /// - /// let mut container = MyContainer { entries : vec![ 1, 2, 3 ] }; - /// let new_elements = vec![ 4, 5, 6 ]; - /// assert_eq!( container.assign( new_elements ), 3 ); // Container now contains [ 4, 5, 6 ] - /// ``` - fn assign< Entries >( &mut self, entries : Entries ) -> usize + /// This trait extends the `Container` trait by providing a method to replace the existing entries in + /// the container with a new set. This can be useful for resetting the container's contents or bulk-updating + /// them based on external criteria or operations. + pub trait ContainerAssign : Container where - Entries : IntoIterator< Item = Self::Entry >; -} + Self : IntoIterator< Item = Self::Entry >, + { + /// Replaces all entries in the container with the provided entries and returns the count of new entries added. + /// + /// This method clears the existing entries and populates the container with new ones provided by an iterator. + /// It is ideal for scenarios where the container needs to be refreshed or updated with a new batch of entries. + /// + /// # Parameters + /// + /// * `entries` : An iterator over the entries to be added to the container. The entries must conform to + /// the `Entry` type defined by the `Container` trait. + /// + /// # Returns + /// + /// Returns the number of entries successfully added to the container. This count may differ from the total + /// number of entries in the iterator if the container imposes restrictions such as capacity limits or duplicate + /// handling. + /// + /// # Examples + /// + /// ```rust + /// use former::{ Container, ContainerAssign }; + /// + /// struct MyContainer + /// { + /// entries : Vec< i32 >, + /// } + /// + /// impl Container for MyContainer + /// { + /// type Entry = i32; + /// type Val = i32; + /// + /// #[ inline( always ) ] + /// fn entry_to_val( e : Self::Entry ) -> Self::Val + /// { + /// e + /// } + /// + /// } + /// + /// impl IntoIterator for MyContainer + /// { + /// type Item = i32; + /// type IntoIter = std::vec::IntoIter< i32 >; + /// // type IntoIter = collection_tools::vec::IntoIter< i32 >; + /// // qqq : zzz : make sure collection_tools has itearators + /// + /// fn into_iter( self ) -> Self::IntoIter + /// { + /// self.entries.into_iter() // Create an iterator from the internal HashSet. + /// } + /// } + /// + /// impl ContainerAssign for MyContainer + /// { + /// fn assign< Entries >( &mut self, entries : Entries ) -> usize + /// where + /// Entries : IntoIterator< Item = Self::Entry >, + /// { + /// self.entries.clear(); + /// self.entries.extend( entries ); + /// self.entries.len() + /// } + /// } + /// + /// let mut container = MyContainer { entries : vec![ 1, 2, 3 ] }; + /// let new_elements = vec![ 4, 5, 6 ]; + /// assert_eq!( container.assign( new_elements ), 3 ); // Container now contains [ 4, 5, 6 ] + /// ``` + fn assign< Entries >( &mut self, entries : Entries ) -> usize + where + Entries : IntoIterator< Item = Self::Entry >; + } -// = + // = -/// A builder structure for constructing containers with a fluent and flexible interface. -#[ derive( Default ) ] -pub struct ContainerSubformer< E, Definition > -where - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Entry = E >, -{ - storage : Definition::Storage, - context : core::option::Option< Definition::Context >, - on_end : core::option::Option< Definition::End >, -} + /// A builder structure for constructing containers with a fluent and flexible interface. + #[ derive( Default ) ] + pub struct ContainerFormer< E, Definition > + where + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Entry = E >, + { + storage : Definition::Storage, + context : core::option::Option< Definition::Context >, + on_end : core::option::Option< Definition::End >, + } -use std::fmt; -impl< E, Definition > fmt::Debug for ContainerSubformer< E, Definition > -where - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Entry = E >, -{ - fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + use std::fmt; + impl< E, Definition > fmt::Debug for ContainerFormer< E, Definition > + where + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Entry = E >, { - f - .debug_struct( "ContainerSubformer" ) - .field( "storage", &"Storage Present" ) - .field( "context", &self.context.as_ref().map( |_| "Context Present" ) ) - .field( "on_end", &self.on_end.as_ref().map( |_| "End Present" ) ) - .finish() + fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result + { + f + .debug_struct( "ContainerFormer" ) + .field( "storage", &"Storage Present" ) + .field( "context", &self.context.as_ref().map( |_| "Context Present" ) ) + .field( "on_end", &self.on_end.as_ref().map( |_| "End Present" ) ) + .finish() + } } -} -impl< E, Definition > ContainerSubformer< E, Definition > -where - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Entry = E >, -{ - /// Begins the construction process of a container with optional initial storage and context, - /// setting up an `on_end` completion handler to finalize the container's construction. - #[ inline( always ) ] - pub fn begin - ( - mut storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Definition::Context >, - on_end : Definition::End, - ) - -> Self + impl< E, Definition > ContainerFormer< E, Definition > + where + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Entry = E >, { - if storage.is_none() + /// Begins the construction process of a container with optional initial storage and context, + /// setting up an `on_end` completion handler to finalize the container's construction. + #[ inline( always ) ] + pub fn begin + ( + mut storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Definition::Context >, + on_end : Definition::End, + ) + -> Self + { + if storage.is_none() + { + storage = Some( core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context, + on_end : Some( on_end ), + } + } + + /// Provides a variation of the `begin` method allowing for coercion of the end handler, + /// facilitating ease of integration with different end conditions. + #[ inline( always ) ] + pub fn begin_coercing< IntoEnd > + ( + mut storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Definition::Context >, + on_end : IntoEnd, + ) + -> Self + where + IntoEnd : Into< Definition::End >, + { + if storage.is_none() + { + storage = Some( core::default::Default::default() ); + } + Self + { + storage : storage.unwrap(), + context, + on_end : Some( on_end.into() ), + } + } + + /// Finalizes the building process, returning the formed or a context incorporating it. + #[ inline( always ) ] + pub fn end( mut self ) -> Definition::Formed + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + on_end.call( self.storage, context ) + } + + /// Alias for the `end` method to align with typical builder pattern terminologies. + #[ inline( always ) ] + pub fn form( self ) -> Definition::Formed { - storage = Some( core::default::Default::default() ); + self.end() } - Self + + /// Replaces the current storage with a provided storage, allowing for resetting or + /// redirection of the building process. + #[ inline( always ) ] + pub fn replace( mut self, storage : Definition::Storage ) -> Self { - storage : storage.unwrap(), - context, - on_end : Some( on_end ), + self.storage = storage; + self } } - /// Provides a variation of the `begin` method allowing for coercion of the end handler, - /// facilitating ease of integration with different end conditions. - #[ inline( always ) ] - pub fn begin_coercing< IntoEnd > - ( - mut storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Definition::Context >, - on_end : IntoEnd, - ) - -> Self + impl< E, Storage, Formed, Definition > ContainerFormer< E, Definition > where - IntoEnd : Into< Definition::End >, + Definition : FormerDefinition< Context = (), Storage = Storage, Formed = Formed >, + Definition::Storage : ContainerAdd< Entry = E >, { - if storage.is_none() + /// Constructs a new `ContainerFormer` instance, starting with an empty storage. + /// This method serves as the entry point for the builder pattern, facilitating the + /// creation of a new container. + #[ inline( always ) ] + pub fn new( end : Definition::End ) -> Self { - storage = Some( core::default::Default::default() ); + Self::begin + ( + None, + None, + end, + ) } - Self + + /// Variant of the `new` method allowing for end condition coercion, providing flexibility + /// in specifying different types of end conditions dynamically. + #[ inline( always ) ] + pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self + where + IntoEnd : Into< Definition::End >, { - storage : storage.unwrap(), - context, - on_end : Some( on_end.into() ), + Self::begin + ( + None, + None, + end.into(), + ) } } - /// Finalizes the building process, returning the formed or a context incorporating it. - #[ inline( always ) ] - pub fn end( mut self ) -> Definition::Formed + impl< E, Definition > ContainerFormer< E, Definition > + where + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Entry = E >, { - let on_end = self.on_end.take().unwrap(); - let context = self.context.take(); - on_end.call( self.storage, context ) - } - /// Alias for the `end` method to align with typical builder pattern terminologies. - #[ inline( always ) ] - pub fn form( self ) -> Definition::Formed - { - self.end() - } + /// Appends an entry to the end of the storage, expanding the internal collection. + #[ inline( always ) ] + pub fn add< IntoElement >( mut self, entry : IntoElement ) -> Self + where IntoElement : core::convert::Into< E >, + { + ContainerAdd::add( &mut self.storage, entry.into() ); + self + } - /// Replaces the current storage with a provided storage, allowing for resetting or - /// redirection of the building process. - #[ inline( always ) ] - pub fn replace( mut self, storage : Definition::Storage ) -> Self - { - self.storage = storage; - self } -} -impl< E, Storage, Formed, Definition > ContainerSubformer< E, Definition > -where - Definition : FormerDefinition< Context = (), Storage = Storage, Formed = Formed >, - Definition::Storage : ContainerAdd< Entry = E >, -{ - /// Constructs a new `ContainerSubformer` instance, starting with an empty storage. - /// This method serves as the entry point for the builder pattern, facilitating the - /// creation of a new container. - #[ inline( always ) ] - pub fn new( end : Definition::End ) -> Self - { - Self::begin - ( - None, - None, - end, - ) - } + // - /// Variant of the `new` method allowing for end condition coercion, providing flexibility - /// in specifying different types of end conditions dynamically. - #[ inline( always ) ] - pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self + impl< E, Definition > FormerBegin< Definition > + for ContainerFormer< E, Definition > where - IntoEnd : Into< Definition::End >, + Definition : FormerDefinition, + Definition::Storage : ContainerAdd< Entry = E >, { - Self::begin + + #[ inline( always ) ] + fn former_begin ( - None, - None, - end.into(), + storage : core::option::Option< Definition::Storage >, + context : core::option::Option< Definition::Context >, + on_end : Definition::End, ) + -> Self + { + Self::begin( storage, context, on_end ) + } + } + } -impl< E, Definition > ContainerSubformer< E, Definition > -where - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Entry = E >, -{ +/// Former of a vector. +mod vector; +/// Former of a hash map. +mod hash_map; +/// Former of a hash set. +mod hash_set; - /// Appends an entry to the end of the storage, expanding the internal collection. - #[ inline( always ) ] - pub fn add< IntoElement >( mut self, entry : IntoElement ) -> Self - where IntoElement : core::convert::Into< E >, - { - ContainerAdd::add( &mut self.storage, entry.into() ); - self - } +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; +/// Protected namespace of the module. +pub mod protected +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; } -// +/// Parented namespace of the module. +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} -impl< E, Definition > FormerBegin< Definition > -for ContainerSubformer< E, Definition > -where - Definition : FormerDefinition, - Definition::Storage : ContainerAdd< Entry = E >, +/// Exposed namespace of the module. +pub mod exposed { - #[ inline( always ) ] - fn former_begin - ( - storage : core::option::Option< Definition::Storage >, - context : core::option::Option< Definition::Context >, - on_end : Definition::End, - ) - -> Self + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::prelude::*; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::private:: { - Self::begin( storage, context, on_end ) - } + Container, + EntryToVal, + ContainerValToEntry, + ValToEntry, + ContainerAdd, + ContainerAssign, + ContainerFormer, + }; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super:: + { + vector::*, + hash_map::*, + hash_set::*, + }; + +} +/// Prelude to use essentials: `use my_module::prelude::*`. +pub mod prelude +{ } diff --git a/module/core/former/src/hash_map.rs b/module/core/former/src/container/hash_map.rs similarity index 66% rename from module/core/former/src/hash_map.rs rename to module/core/former/src/container/hash_map.rs index 6caa4241cd..6054850903 100644 --- a/module/core/former/src/hash_map.rs +++ b/module/core/former/src/container/hash_map.rs @@ -5,8 +5,7 @@ //! as subformer, enabling fluid and intuitive manipulation of hashmaps via builder patterns. //! -use super::*; - +use crate::*; use collection_tools::HashMap; impl< K, V > Container for collection_tools::HashMap< K, V > @@ -75,6 +74,21 @@ where // = definition +/// Represents the formation definition for a hash map-like container within the former framework. +/// +/// This structure defines the essential elements required to form a hash map-like container, detailing +/// the key and value types, the contextual environment during formation, the final formed type, and the +/// behavior at the end of the formation process. It facilitates customization and extension of hash map +/// formation within any system that implements complex data management operations. +/// +/// # Type Parameters +/// - `K`: The key type of the hash map. +/// - `E`: The value type of the hash map. +/// - `Context`: The optional context provided during the formation process. +/// - `Formed`: The type of the entity produced, typically a `HashMap`. +/// - `End`: A trait defining the end behavior of the formation process, managing how the hash map is finalized. +/// + #[ derive( Debug, Default ) ] pub struct HashMapDefinition< K, E, Context = (), Formed = HashMap< K, E >, End = ReturnStorage > where @@ -102,6 +116,18 @@ where // = definition types +/// Holds the generic parameters for the `HashMapDefinition`. +/// +/// This companion struct to `HashMapDefinition` defines the storage type and the context, along with the +/// type that is ultimately formed through the process. It is crucial for maintaining the integrity and +/// consistency of type relations throughout the former lifecycle. +/// +/// # Type Parameters +/// - `K`: The key type of the hash map. +/// - `E`: The value type of the hash map. +/// - `Context`: The operational context in which the hash map is formed. +/// - `Formed`: The type produced, typically mirroring the structure of a `HashMap`. + #[ derive( Debug, Default ) ] pub struct HashMapDefinitionTypes< K, E, Context = (), Formed = HashMap< K, E > > { @@ -145,7 +171,7 @@ where >, Definition::End : forming::FormingEnd< Definition::Types >, { - type Former = HashMapAsSubformer< K, E, Definition::Context, Definition::Formed, Definition::End >; + type Former = HashMapFormer< K, E, Definition::Context, Definition::Formed, Definition::End >; } impl< K, E > crate::EntityToStorage @@ -178,7 +204,7 @@ where /// Provides a streamlined builder interface for constructing hash map-like containers. /// -/// `HashMapAsSubformer` is a type alias that configures the `ContainerSubformer` specifically for hash maps, +/// `HashMapFormer` is a type alias that configures the `ContainerFormer` specifically for hash maps, /// facilitating a more intuitive and flexible way to build and manipulate hash maps within custom data structures. /// This type alias simplifies the usage of hash maps in builder patterns by encapsulating complex generic parameters /// and leveraging the `HashMapDefinition` to handle the construction logic. It supports fluent chaining of key-value @@ -187,25 +213,34 @@ where /// The alias helps reduce boilerplate code and enhances readability, making the construction of hash maps in /// a builder pattern both efficient and expressive. -pub type HashMapAsSubformer< K, E, Context, Formed, End > = -ContainerSubformer::< ( K, E ), HashMapDefinition< K, E, Context, Formed, End > >; +pub type HashMapFormer< K, E, Context, Formed, End > = +ContainerFormer::< ( K, E ), HashMapDefinition< K, E, Context, Formed, End > >; // = extension +/// Provides an extension method for hash maps to facilitate the use of the builder pattern. +/// +/// This trait extends the `HashMap` type, enabling it to use the `HashMapFormer` interface directly. +/// It allows for fluent, expressive construction and manipulation of hash maps, integrating seamlessly +/// with the builder pattern provided by the `former` framework. It's a convenience trait that simplifies +/// creating configured hash map builders with default settings. +/// + pub trait HashMapExt< K, E > : sealed::Sealed where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn former() -> HashMapAsSubformer< K, E, (), HashMap< K, E >, ReturnStorage >; + /// Initializes a builder pattern for `HashMap` using a default `HashMapFormer`. + fn former() -> HashMapFormer< K, E, (), HashMap< K, E >, ReturnStorage >; } impl< K, E > HashMapExt< K, E > for HashMap< K, E > where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn former() -> HashMapAsSubformer< K, E, (), HashMap< K, E >, ReturnStorage > + fn former() -> HashMapFormer< K, E, (), HashMap< K, E >, ReturnStorage > { - HashMapAsSubformer::< K, E, (), HashMap< K, E >, ReturnStorage >::new( ReturnStorage::default() ) + HashMapFormer::< K, E, (), HashMap< K, E >, ReturnStorage >::new( ReturnStorage::default() ) } } diff --git a/module/core/former/src/hash_set.rs b/module/core/former/src/container/hash_set.rs similarity index 66% rename from module/core/former/src/hash_set.rs rename to module/core/former/src/container/hash_set.rs index 8476678740..6e96684ee1 100644 --- a/module/core/former/src/hash_set.rs +++ b/module/core/former/src/container/hash_set.rs @@ -1,24 +1,8 @@ -//! This module provides a builder pattern implementation (`HashSetAsSubformer`) for `HashSet`-like containers. It is designed to extend the builder pattern, allowing for fluent and dynamic construction of sets within custom data structures. +//! This module provides a builder pattern implementation (`HashSetFormer`) for `HashSet`-like containers. It is designed to extend the builder pattern, allowing for fluent and dynamic construction of sets within custom data structures. -use super::*; +use crate::*; use collection_tools::HashSet; -// impl< K, T > Container for T -// where -// K : core::cmp::Eq + core::hash::Hash, -// T : HashSetLike< K >, -// { -// type Entry = K; -// type Val = K; -// -// #[ inline( always ) ] -// fn entry_to_val( e : Self::Entry ) -> Self::Val -// { -// e -// } -// -// } - impl< K > Container for collection_tools::HashSet< K > where K : core::cmp::Eq + core::hash::Hash, @@ -79,7 +63,7 @@ where // /// A trait for containers behaving like a `HashSet`, allowing insertion operations. // /// -// /// Implementing this trait enables the associated formed to be used with `HashSetAsSubformer`, +// /// Implementing this trait enables the associated formed to be used with `HashSetFormer`, // /// facilitating a builder pattern that is both intuitive and concise. // /// // /// # Example Implementation @@ -130,6 +114,20 @@ where // = definition +/// Represents the formation definition for a hash set-like container within the former framework. +/// +/// This structure defines the essential elements required to form a hash set-like container, detailing +/// the type of elements, the contextual environment during formation, the final formed type, and the +/// behavior at the end of the formation process. It is designed to support the construction and configuration +/// of hash set containers with dynamic characteristics and behaviors. +/// +/// # Type Parameters +/// - `K`: The type of elements in the hash set. +/// - `Context`: The optional context provided during the formation process. +/// - `Formed`: The type of the entity produced, typically a `HashSet`. +/// - `End`: A trait defining the end behavior of the formation process, managing how the hash set is finalized. +/// + #[ derive( Debug, Default ) ] pub struct HashSetDefinition< K, Context = (), Formed = HashSet< K >, End = ReturnStorage > where @@ -155,6 +153,13 @@ where // = definition types +/// Holds the generic parameters for the `HashSetDefinition`. +/// +/// This struct encapsulates the type relationships and characteristics essential for the formation process +/// of a `HashSet`, including the storage type, the context, and the type ultimately formed. It ensures that +/// these elements are congruent and coherent throughout the lifecycle of the hash set formation. +/// + #[ derive( Debug, Default ) ] pub struct HashSetDefinitionTypes< K, Context = (), Formed = HashSet< K > > { @@ -197,7 +202,7 @@ where >, Definition::End : forming::FormingEnd< Definition::Types >, { - type Former = HashSetAsSubformer< K, Definition::Context, Definition::Formed, Definition::End >; + type Former = HashSetFormer< K, Definition::Context, Definition::Formed, Definition::End >; } impl< K > crate::EntityToStorage @@ -228,32 +233,40 @@ where // = subformer -/// Provides a concise alias for `ContainerSubformer` configured specifically for `HashSet`-like containers. +/// Provides a concise alias for `ContainerFormer` configured specifically for `HashSet`-like containers. /// -/// `HashSetAsSubformer` simplifies the creation of `HashSet` containers within builder patterns by leveraging -/// the `ContainerSubformer` with predefined settings. This approach minimizes boilerplate code and enhances +/// `HashSetFormer` simplifies the creation of `HashSet` containers within builder patterns by leveraging +/// the `ContainerFormer` with predefined settings. This approach minimizes boilerplate code and enhances /// readability, making it ideal for fluent and expressive construction of set containers within custom data structures. /// -pub type HashSetAsSubformer< K, Context, Formed, End > = -ContainerSubformer::< K, HashSetDefinition< K, Context, Formed, End > >; +pub type HashSetFormer< K, Context, Formed, End > = +ContainerFormer::< K, HashSetDefinition< K, Context, Formed, End > >; // = extension +/// Provides an extension method for `HashSet` to facilitate the use of the builder pattern. +/// +/// This trait extends `HashSet`, enabling direct use of the `HashSetFormer` interface for fluent and expressive +/// set construction. It simplifies the process of building `HashSet` instances by providing a straightforward +/// way to start the builder pattern with default context and termination behavior. +/// + pub trait HashSetExt< K > : sealed::Sealed where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn former() -> HashSetAsSubformer< K, (), HashSet< K >, ReturnStorage >; + /// Initializes a builder pattern for `HashSet` using a default `HashSetFormer`. + fn former() -> HashSetFormer< K, (), HashSet< K >, ReturnStorage >; } impl< K > HashSetExt< K > for HashSet< K > where K : ::core::cmp::Eq + ::core::hash::Hash, { - fn former() -> HashSetAsSubformer< K, (), HashSet< K >, ReturnStorage > + fn former() -> HashSetFormer< K, (), HashSet< K >, ReturnStorage > { - HashSetAsSubformer::< K, (), HashSet< K >, ReturnStorage >::new( ReturnStorage::default() ) + HashSetFormer::< K, (), HashSet< K >, ReturnStorage >::new( ReturnStorage::default() ) } } diff --git a/module/core/former/src/vector.rs b/module/core/former/src/container/vector.rs similarity index 65% rename from module/core/former/src/vector.rs rename to module/core/former/src/container/vector.rs index 9c9b962306..33c344d1ab 100644 --- a/module/core/former/src/vector.rs +++ b/module/core/former/src/container/vector.rs @@ -5,9 +5,7 @@ //! as subformer, enabling fluid and intuitive manipulation of vectors via builder patterns. //! -use super::*; -// use axiomatic::*; - +use crate::*; #[ allow( unused ) ] use collection_tools::Vec; @@ -66,15 +64,12 @@ where impl< E > Storage for Vec< E > { - // type Formed = Vec< E >; type Preformed = Vec< E >; } impl< E > StoragePreform for Vec< E > { - // type Preformed = Vec< E >; - // fn preform( self ) -> Self::Formed fn preform( self ) -> Self::Preformed { self @@ -83,6 +78,18 @@ for Vec< E > // = definition +/// Represents the formation definition for a vector-like container within the former framework. +/// +/// This structure defines the necessary parameters and relationships needed to form a vector-like container, +/// including its storage, context, the result of the formation process, and the behavior at the end of the formation. +/// +/// # Type Parameters +/// - `E`: The element type of the vector. +/// - `Context`: The context needed for the formation, can be provided externally. +/// - `Formed`: The type formed at the end of the formation process, typically a `Vec`. +/// - `End`: A trait determining the behavior at the end of the formation process. +/// + #[ derive( Debug, Default ) ] pub struct VectorDefinition< E, Context, Formed, End > where @@ -106,6 +113,18 @@ where // = definition type +/// Holds the generic parameters for the `VectorDefinition`. +/// +/// This struct acts as a companion to `VectorDefinition`, providing a concrete definition of types used +/// in the formation process. It is crucial for linking the type parameters with the operational mechanics +/// of the formation and ensuring type safety and correctness throughout the formation lifecycle. +/// +/// # Type Parameters +/// +/// - `E`: The element type of the vector. +/// - `Context`: The context in which the vector is formed. +/// - `Formed`: The type produced as a result of the formation process. + #[ derive( Debug, Default ) ] pub struct VectorDefinitionTypes< E, Context = (), Formed = Vec< E > > { @@ -144,7 +163,7 @@ where >, Definition::End : forming::FormingEnd< Definition::Types >, { - type Former = VectorAsSubformer< E, Definition::Context, Definition::Formed, Definition::End >; + type Former = VectorFormer< E, Definition::Context, Definition::Formed, Definition::End >; } impl< E > crate::EntityToStorage @@ -172,7 +191,7 @@ for Vec< E > /// Provides a streamlined builder interface for constructing vector-like containers. /// -/// `VectorAsSubformer` is a type alias that configures the `ContainerSubformer` for use specifically with vectors. +/// `VectorFormer` is a type alias that configures the `ContainerFormer` for use specifically with vectors. /// It integrates the `VectorDefinition` to facilitate the fluent and dynamic construction of vectors, leveraging /// predefined settings to reduce boilerplate code. This approach enhances readability and simplifies the use of /// vectors in custom data structures where builder patterns are desired. @@ -182,21 +201,29 @@ for Vec< E > /// parts of an application. /// -pub type VectorAsSubformer< E, Context, Formed, End > = -ContainerSubformer::< E, VectorDefinition< E, Context, Formed, End > >; +pub type VectorFormer< E, Context, Formed, End > = +ContainerFormer::< E, VectorDefinition< E, Context, Formed, End > >; // = extension +/// Provides an extension method for vectors to facilitate the use of the builder pattern. +/// +/// This trait extends the `Vec` type, enabling it to use the `VectorFormer` interface directly. +/// This allows for fluent, expressive construction and manipulation of vectors, integrating seamlessly +/// with the builder pattern provided by the `former` framework. It's a convenience trait that simplifies +/// creating configured vector builders with default settings. +/// pub trait VecExt< E > : sealed::Sealed { - fn former() -> VectorAsSubformer< E, (), Vec< E >, ReturnStorage >; + /// Initializes a builder pattern for `Vec` using a default `VectorFormer`. + fn former() -> VectorFormer< E, (), Vec< E >, ReturnStorage >; } impl< E > VecExt< E > for Vec< E > { - fn former() -> VectorAsSubformer< E, (), Vec< E >, ReturnStorage > + fn former() -> VectorFormer< E, (), Vec< E >, ReturnStorage > { - VectorAsSubformer::< E, (), Vec< E >, ReturnStorage >::new( ReturnStorage::default() ) + VectorFormer::< E, (), Vec< E >, ReturnStorage >::new( ReturnStorage::default() ) } } diff --git a/module/core/former/src/definition.rs b/module/core/former/src/definition.rs index b7ee6921e6..38563df0e8 100644 --- a/module/core/former/src/definition.rs +++ b/module/core/former/src/definition.rs @@ -21,8 +21,9 @@ /// during the formation process. pub trait EntityToDefinition< Context, Formed, End > { - /// The specific `FormerDefinition` associated with this entity. + /// The specific [`FormerDefinition`] associated with this entity. type Definition : FormerDefinition; + /// The specific [`FormerDefinitionTypes`] associated with this entity. type Types : FormerDefinitionTypes; } diff --git a/module/core/former/src/lib.rs b/module/core/former/src/lib.rs index cb5b976dd2..9653b8152e 100644 --- a/module/core/former/src/lib.rs +++ b/module/core/former/src/lib.rs @@ -26,32 +26,12 @@ mod storage; #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] #[ cfg( feature = "derive_former" ) ] mod container; -/// Former of a vector. -#[ cfg( feature = "enabled" ) ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ cfg( feature = "derive_former" ) ] -mod vector; -/// Former of a hash map. -#[ cfg( feature = "enabled" ) ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ cfg( feature = "derive_former" ) ] -mod hash_map; -/// Former of a hash set. -#[ cfg( feature = "enabled" ) ] -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] -#[ cfg( feature = "derive_former" ) ] -mod hash_set; /// Component-based forming. #[ cfg( feature = "enabled" ) ] #[ cfg( any( feature = "derive_component_from", feature = "derive_component_assign" ) ) ] mod component; -// mod axiomatic2; -// mod axiomatic3; -// mod vector2; -// mod vector3; - /// Namespace with dependencies. #[ cfg( feature = "enabled" ) ] pub mod dependency @@ -116,24 +96,6 @@ pub mod exposed #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] #[ cfg( feature = "derive_former" ) ] pub use super::container::*; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - #[ cfg( feature = "enabled" ) ] - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - #[ cfg( feature = "derive_former" ) ] - pub use super::vector::*; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - #[ cfg( feature = "enabled" ) ] - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - #[ cfg( feature = "derive_former" ) ] - pub use super::hash_map::*; - #[ doc( inline ) ] - #[ allow( unused_imports ) ] - #[ cfg( feature = "enabled" ) ] - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - #[ cfg( feature = "derive_former" ) ] - pub use super::hash_set::*; } @@ -147,4 +109,3 @@ pub mod prelude #[ cfg( any( feature = "derive_component_from", feature = "derive_component_assign" ) ) ] pub use super::component::*; } - diff --git a/module/core/former/tests/inc/former_tests/a_containers_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_manual.rs index 8f0e35deea..87f2bf5b00 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_manual.rs @@ -361,7 +361,7 @@ where } #[ inline( always ) ] - pub fn vec_1( self ) -> former::ContainerSubformer:: + pub fn vec_1( self ) -> former::ContainerFormer:: < String, former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End< Definition > >, @@ -378,7 +378,7 @@ where < collection_tools::Vec< String > as former::EntityToDefinitionTypes< Self, Self > >::Types >, { - self._vec_1_assign::< former::ContainerSubformer:: + self._vec_1_assign::< former::ContainerFormer:: < String, former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End< Definition > >, @@ -407,7 +407,7 @@ where } #[ inline( always ) ] - pub fn hashmap_1( self ) -> former::ContainerSubformer:: + pub fn hashmap_1( self ) -> former::ContainerFormer:: < ( String, String ), former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End< Definition > >, @@ -424,7 +424,7 @@ where < collection_tools::HashMap< String, String > as former::EntityToDefinitionTypes< Self, Self > >::Types >, { - self._hashmap_1_assign::< former::ContainerSubformer:: + self._hashmap_1_assign::< former::ContainerFormer:: < ( String, String ), former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End< Definition > >, @@ -453,7 +453,7 @@ where } #[ inline( always ) ] - pub fn hashset_1( self ) -> former::ContainerSubformer:: + pub fn hashset_1( self ) -> former::ContainerFormer:: < String, former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, @@ -470,7 +470,7 @@ where < collection_tools::HashSet< String > as former::EntityToDefinitionTypes< Self, Self > >::Types >, { - self._hashset_1_assign::< former::ContainerSubformer:: + self._hashset_1_assign::< former::ContainerFormer:: < String, former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index 810268b24f..4528ef7312 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -50,14 +50,14 @@ fn begin_and_custom_end() { 13.1 } - let got = the_module::VectorAsSubformer::begin( None, None, return_13 ) + let got = the_module::VectorFormer::begin( None, None, return_13 ) .add( "a" ) .add( "b" ) .form(); let exp = 13.1; a_id!( got, exp ); - let got = the_module::VectorAsSubformer::new( return_13 ) + let got = the_module::VectorFormer::new( return_13 ) .add( "a" ) .add( "b" ) .form(); @@ -77,7 +77,7 @@ fn begin_and_custom_end() 13.1 } } - let got = the_module::VectorAsSubformer::begin( None, Some( 10.0 ), context_plus_13 ) + let got = the_module::VectorFormer::begin( None, Some( 10.0 ), context_plus_13 ) .add( "a" ) .add( "b" ) .form(); @@ -136,14 +136,14 @@ fn custom_definition() // - let got = the_module::ContainerSubformer::< String, Return13 >::begin_coercing( None, None, Return13 ) + let got = the_module::ContainerFormer::< String, Return13 >::begin_coercing( None, None, Return13 ) .add( "a" ) .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); - let got = the_module::ContainerSubformer::< String, Return13 >::new( Return13 ) + let got = the_module::ContainerFormer::< String, Return13 >::new( Return13 ) .add( "a" ) .add( "b" ) .form(); @@ -211,14 +211,14 @@ fn custom_definition_parametrized() // - let got = the_module::ContainerSubformer::< String, Return13< String > >::begin_coercing( None, None, Return13::new() ) + let got = the_module::ContainerFormer::< String, Return13< String > >::begin_coercing( None, None, Return13::new() ) .add( "a" ) .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); - let got = the_module::ContainerSubformer::< String, Return13< String > >::new_coercing( Return13::new() ) + let got = the_module::ContainerFormer::< String, Return13< String > >::new_coercing( Return13::new() ) .add( "a" ) .add( "b" ) .form(); @@ -227,7 +227,7 @@ fn custom_definition_parametrized() // - type MyContainer< E > = the_module::ContainerSubformer::< E, Return13< E > >; + type MyContainer< E > = the_module::ContainerFormer::< E, Return13< E > >; let got = MyContainer::< String >::begin_coercing( None, None, Return13::new() ) .add( "a" ) @@ -279,21 +279,21 @@ fn custom_definition_custom_end() } let end_wrapper : the_module::FormingEndClosure< Return13 > = the_module::FormingEndClosure::new( return_13 ); - let got = the_module::ContainerSubformer::< String, Return13 >::new( end_wrapper ) + let got = the_module::ContainerFormer::< String, Return13 >::new( end_wrapper ) .add( "a" ) .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); - let got = the_module::ContainerSubformer::< String, Return13 >::new( return_13.into() ) + let got = the_module::ContainerFormer::< String, Return13 >::new( return_13.into() ) .add( "a" ) .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); - let got = the_module::ContainerSubformer::< String, Return13 >::new_coercing( return_13 ) + let got = the_module::ContainerFormer::< String, Return13 >::new_coercing( return_13 ) .add( "a" ) .add( "b" ) .form(); diff --git a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs index 8d8ffef410..d08fb1e319 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs @@ -11,10 +11,10 @@ use collection_tools::HashMap; fn add() { - // expliccit with ContainerSubformer + // expliccit with ContainerFormer let got : HashMap< String, String > = the_module - ::ContainerSubformer + ::ContainerFormer ::< ( String, String ), former::HashMapDefinition< String, String, (), HashMap< String, String >, the_module::ReturnStorage > > ::new( former::ReturnStorage ) .add( ( "a".into(), "x".into() ) ) @@ -27,9 +27,9 @@ fn add() ]; a_id!( got, exp ); - // expliccit with HashMapAsSubformer + // expliccit with HashMapFormer - let got : HashMap< String, String > = the_module::HashMapAsSubformer::< String, String, (), HashMap< String, String >, the_module::ReturnStorage > + let got : HashMap< String, String > = the_module::HashMapFormer::< String, String, (), HashMap< String, String >, the_module::ReturnStorage > ::new( former::ReturnStorage ) .add( ( "a".into(), "x".into() ) ) .add( ( "b".into(), "y".into() ) ) @@ -41,9 +41,9 @@ fn add() ]; a_id!( got, exp ); - // compact with HashMapAsSubformer + // compact with HashMapFormer - let got : HashMap< String, String > = the_module::HashMapAsSubformer::new( former::ReturnStorage ) + let got : HashMap< String, String > = the_module::HashMapFormer::new( former::ReturnStorage ) .add( ( "a".into(), "x".into() ) ) .add( ( "b".into(), "y".into() ) ) .form(); @@ -56,7 +56,7 @@ fn add() // with begin - let got : HashMap< String, String > = the_module::HashMapAsSubformer + let got : HashMap< String, String > = the_module::HashMapFormer ::begin( Some( hmap![ "a".to_string() => "x".to_string() ] ), Some( () ), former::ReturnStorage ) .add( ( "b".into(), "y".into() ) ) .form(); @@ -91,7 +91,7 @@ fn add() fn replace() { - let got : HashMap< String, String > = the_module::HashMapAsSubformer::new( former::ReturnStorage ) + let got : HashMap< String, String > = the_module::HashMapFormer::new( former::ReturnStorage ) .add( ( "x".to_string(), "y".to_string() ) ) .replace( hmap![ "a".to_string() => "x".to_string(), "b".to_string() => "y".to_string(), ] ) .form(); diff --git a/module/core/former/tests/inc/former_tests/container_former_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs index 8ee7adb1c6..f14c826831 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashset.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashset.rs @@ -11,10 +11,10 @@ use collection_tools::HashSet; fn add() { - // expliccit with ContainerSubformer + // expliccit with ContainerFormer let got : HashSet< String > = the_module - ::ContainerSubformer + ::ContainerFormer ::< String, former::HashSetDefinition< String, (), HashSet< String >, the_module::ReturnStorage > > ::new( former::ReturnStorage ) .add( "a" ) @@ -27,9 +27,9 @@ fn add() ]; a_id!( got, exp ); - // expliccit with HashSetAsSubformer + // expliccit with HashSetFormer - let got : HashSet< String > = the_module::HashSetAsSubformer::< String, (), HashSet< String >, the_module::ReturnStorage > + let got : HashSet< String > = the_module::HashSetFormer::< String, (), HashSet< String >, the_module::ReturnStorage > ::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) @@ -41,9 +41,9 @@ fn add() ]; a_id!( got, exp ); - // compact with HashSetAsSubformer + // compact with HashSetFormer - let got : HashSet< String > = the_module::HashSetAsSubformer::new( former::ReturnStorage ) + let got : HashSet< String > = the_module::HashSetFormer::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -56,7 +56,7 @@ fn add() // with begin_coercing - let got : HashSet< String > = the_module::HashSetAsSubformer + let got : HashSet< String > = the_module::HashSetFormer ::begin( Some( hset![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) .add( "b" ) .form(); @@ -91,7 +91,7 @@ fn add() fn replace() { - let got : HashSet< String > = the_module::HashSetAsSubformer::new( former::ReturnStorage ) + let got : HashSet< String > = the_module::HashSetFormer::new( former::ReturnStorage ) .add( "x" ) .replace( hset![ "a".to_string(), "b".to_string() ] ) .form(); 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 1adbd1d029..ec76210448 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 @@ -10,10 +10,10 @@ use collection_tools::Vec; fn add() { - // expliccit with ContainerSubformer + // expliccit with ContainerFormer let got : Vec< String > = the_module - ::ContainerSubformer + ::ContainerFormer ::< String, former::VectorDefinition< String, (), Vec< String >, the_module::ReturnStorage > > ::new( former::ReturnStorage ) .add( "a" ) @@ -26,9 +26,9 @@ fn add() ]; a_id!( got, exp ); - // expliccit with VectorAsSubformer + // expliccit with VectorFormer - let got : Vec< String > = the_module::VectorAsSubformer::< String, (), Vec< String >, the_module::ReturnStorage > + let got : Vec< String > = the_module::VectorFormer::< String, (), Vec< String >, the_module::ReturnStorage > ::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) @@ -40,9 +40,9 @@ fn add() ]; a_id!( got, exp ); - // compact with VectorAsSubformer + // compact with VectorFormer - let got : Vec< String > = the_module::VectorAsSubformer::new( former::ReturnStorage ) + let got : Vec< String > = the_module::VectorFormer::new( former::ReturnStorage ) .add( "a" ) .add( "b" ) .form(); @@ -55,7 +55,7 @@ fn add() // with begin_coercing - let got : Vec< String > = the_module::VectorAsSubformer + let got : Vec< String > = the_module::VectorFormer ::begin( Some( vec![ "a".to_string() ] ), Some( () ), former::ReturnStorage ) .add( "b" ) .form(); @@ -90,7 +90,7 @@ fn add() fn replace() { - let got : Vec< String > = the_module::VectorAsSubformer::new( former::ReturnStorage ) + let got : Vec< String > = the_module::VectorFormer::new( former::ReturnStorage ) .add( "x" ) .replace( vec![ "a".to_string(), "b".to_string() ] ) .form(); diff --git a/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs b/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs index 5b1123de1e..d62e770a9f 100644 --- a/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs +++ b/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs @@ -45,7 +45,7 @@ fn command_form() fn command_properties() { - // with HashMapAsSubformer + // with HashMapFormer let got = Child::< &str >::former() .name( "a" ) .properties() diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs index f966003840..c77e69cff8 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs @@ -86,7 +86,7 @@ fn command_properties() }; a_id!( got, exp ); - // with HashMapAsSubformer + // with HashMapFormer let got = Child::< &str >::former() .name( "a" ) .subject( "b" ) diff --git a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs index 62c1eddc03..95e081b39e 100644 --- a/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs +++ b/module/core/former/tests/inc/former_tests/parametrized_struct_manual.rs @@ -318,9 +318,9 @@ where } #[ inline( always ) ] - pub fn properties( self ) -> former::ContainerSubformer::< ( K, Property< K >, ), former::HashMapDefinition< K, Property< K >, Self, Self, ChildFormerPropertiesEnd > > + pub fn properties( self ) -> former::ContainerFormer::< ( K, Property< K >, ), former::HashMapDefinition< K, Property< K >, Self, Self, ChildFormerPropertiesEnd > > { - self.properties_set::< former::ContainerSubformer::< ( K, Property< K >, ), former::HashMapDefinition< K, Property< K >, Self, Self, ChildFormerPropertiesEnd > >>() + self.properties_set::< former::ContainerFormer::< ( K, Property< K >, ), former::HashMapDefinition< K, Property< K >, Self, Self, ChildFormerPropertiesEnd > >>() } } diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index 9bc98c4ec3..0c9bca8827 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -229,7 +229,7 @@ where // = subformer pub type LoggingSetAsSubformer< K, Context, Formed, End > = -former::ContainerSubformer::< K, LoggingSetDefinition< K, Context, Formed, End > >; +former::ContainerFormer::< K, LoggingSetDefinition< K, Context, Formed, End > >; // == use custom container diff --git a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs index 48aa08e251..82811c38eb 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_manual.rs @@ -38,13 +38,13 @@ where } #[ inline( always ) ] - pub fn children( self ) -> former::ContainerSubformer:: + pub fn children( self ) -> former::ContainerFormer:: < Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > { - self._children_container_former::< former::ContainerSubformer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > >() + self._children_container_former::< former::ContainerFormer::< Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > > >() } } diff --git a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs index 216aaa0afb..5f3ca56708 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_off.rs @@ -37,7 +37,7 @@ where } #[ inline( always ) ] - pub fn children2( self ) -> former::ContainerSubformer:: + pub fn children2( self ) -> former::ContainerFormer:: < Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > diff --git a/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs b/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs index 3259e27d04..83233366cf 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs @@ -30,7 +30,7 @@ where { #[ inline( always ) ] - pub fn children2( self ) -> former::ContainerSubformer:: + pub fn children2( self ) -> former::ContainerFormer:: < Child, former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 24c966304f..936477d380 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -775,7 +775,7 @@ formation process of the `{stru}`. #[ doc = #doc ] #[ inline( always ) ] - pub fn #setter_name( self ) -> former::ContainerSubformer:: + pub fn #setter_name( self ) -> former::ContainerFormer:: < // ( #( #params, )* ), < #field_typ as former::Container >::Entry, @@ -790,7 +790,7 @@ formation process of the `{stru}`. End = #former_assign_end < Definition >, >, { - self.#field_assign::< former::ContainerSubformer:: + self.#field_assign::< former::ContainerFormer:: < _, _, @@ -800,7 +800,7 @@ formation process of the `{stru}`. } // #[ inline( always ) ] - // pub fn hashset_1( self ) -> former::ContainerSubformer:: + // pub fn hashset_1( self ) -> former::ContainerFormer:: // < // String, // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, @@ -813,7 +813,7 @@ formation process of the `{stru}`. // End = Struct1FormerAssignHashset1End< Definition >, // >, // { - // self._hashset_1_assign::< former::ContainerSubformer:: + // self._hashset_1_assign::< former::ContainerFormer:: // < // String, // former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > >, @@ -833,7 +833,7 @@ formation process of the `{stru}`. ( r#" -/// The containr setter provides a container setter that returns a ContainerSubformer tailored for managing a collection of child entities. It employs a generic container definition to facilitate operations on the entire collection, such as adding or updating elements. +/// The containr setter provides a container setter that returns a ContainerFormer tailored for managing a collection of child entities. It employs a generic container definition to facilitate operations on the entire collection, such as adding or updating elements. impl< Definition, > {}< Definition, > where @@ -841,7 +841,7 @@ where {{ #[ inline( always ) ] - pub fn {}( self ) -> former::ContainerSubformer:: + pub fn {}( self ) -> former::ContainerFormer:: < ( {} ), former::HashMapDefinition< {} Self, Self, {}< Definition >, > diff --git a/module/core/former_meta/src/derive_former/field_attrs.rs b/module/core/former_meta/src/derive_former/field_attrs.rs index a2d8010a0b..5aea94b80d 100644 --- a/module/core/former_meta/src/derive_former/field_attrs.rs +++ b/module/core/former_meta/src/derive_former/field_attrs.rs @@ -271,7 +271,7 @@ pub struct AttributeContainerSetter pub name : Option< syn::Ident >, /// Controls the generation of a setter method. If false, a setter method is not generated. pub setter : Option< bool >, - /// Definition of the container former to use, e.g., `former::VectorAsSubformer`. + /// Definition of the container former to use, e.g., `former::VectorFormer`. pub definition : Option< syn::Type >, /// Specifies whether to provide a sketch of the subform setter as a hint. /// Defaults to `false`, which means no hint is provided unless explicitly requested. From 74a1f4af80ac8a9d56cb3b56516b91558af3d69f Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 19:43:04 +0300 Subject: [PATCH 524/533] former : cleaning --- module/core/former/Readme.md | 109 ++++++++++++--- ...m_default.rs => former_custom_defaults.rs} | 5 +- .../examples/former_custom_definition.rs | 72 ++++++++++ .../examples/former_custom_scalar_setter.rs | 5 +- .../examples/former_custom_subform_setter.rs | 2 +- .../former/examples/former_many_fields.rs | 2 +- module/core/former/src/container.rs | 51 +++---- .../former_tests/container_former_common.rs | 18 +-- .../former_tests/container_former_hashmap.rs | 4 +- .../former_tests/container_former_hashset.rs | 4 +- .../only_test/parametrized_struct.rs | 2 +- .../former_tests/only_test/subformer_basic.rs | 6 +- .../former_tests/unsigned_primitive_types.rs | 129 +++++++++--------- module/core/former_meta/src/derive_former.rs | 14 +- module/core/former_meta/src/lib.rs | 6 +- 15 files changed, 288 insertions(+), 141 deletions(-) rename module/core/former/examples/{former_custom_default.rs => former_custom_defaults.rs} (92%) create mode 100644 module/core/former/examples/former_custom_definition.rs diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index b84b874a0b..3725c64a8e 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -19,7 +19,7 @@ It offers specialized subformers for common Rust collections like `Vec`, `HashMa This approach abstracts away the need for manually implementing a builder for each struct, making code more readable and maintainable. -## Basic use-case +## Example : Trivial @@ -28,7 +28,7 @@ This approach abstracts away the need for manually implementing a builder for ea -The provided code snippet illustrates a basic use-case of the Former crate in Rust, which is used to apply the builder pattern for structured and flexible object creation. Below is a detailed explanation of each part of the markdown chapter, aimed at clarifying how the Former trait simplifies struct instantiation. +The provided code snippet illustrates a basic use-case of the Former, which is used to apply the builder pattern for structured and flexible object creation. Below is a detailed explanation of each part of the markdown chapter, aimed at clarifying how the Former trait simplifies struct instantiation. ```rust #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] @@ -461,7 +461,7 @@ Try out `cargo run --example former_trivial`.
[See code](./examples/former_trivial.rs). -## Custom and Alternative Setters +## Example : Custom and Alternative Setters With help of `Former`, it is possible to define multiple versions of a setter for a single field, providing the flexibility to include custom logic within the setter methods. This feature is particularly useful when you need to preprocess data or enforce specific constraints before assigning values to fields. Custom setters should have unique names to differentiate them from the default setters generated by `Former`, allowing for specialized behavior while maintaining clarity in your code. @@ -510,7 +510,7 @@ Try out `cargo run --example former_custom_setter`.
[See code](./examples/former_custom_setter.rs). -## Custom Setter Overriding +## Example : Custom Setter Overriding But it's also possible to completely override setter and write its own from scratch. For that use attribe `[ setter( false ) ]` to disable setter. @@ -554,9 +554,9 @@ Try out `cargo run --example former_custom_setter_overriden`.
[See code](./examples/former_custom_setter_overriden.rs). -## Custom Default +## Example : Custom Defaults -The `Former` crate enhances struct initialization in Rust by allowing the specification of custom default values for fields through the `default` attribute. This feature not only provides a way to set initial values for struct fields without relying on the `Default` trait but also adds flexibility in handling cases where a field's type does not implement `Default`, or a non-standard default value is desired. +The `Former` crate enhances struct initialization by allowing the specification of custom default values for fields through the `default` attribute. This feature not only provides a way to set initial values for struct fields without relying on the `Default` trait but also adds flexibility in handling cases where a field's type does not implement `Default`, or a non-standard default value is desired. ```rust # #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] @@ -604,9 +604,9 @@ The above code snippet showcases the `Former` crate's ability to initialize stru This approach significantly simplifies struct construction, particularly for complex types or where defaults beyond the `Default` trait's capability are required. By utilizing the `default` attribute, developers can ensure their structs are initialized safely and predictably, enhancing code clarity and maintainability. -Try out `cargo run --example former_custom_default`. +Try out `cargo run --example former_custom_defaults`.
-[See code](./examples/former_custom_default.rs). +[See code](./examples/former_custom_defaults.rs). ## Concept of Storage and Former @@ -654,6 +654,76 @@ The formation process utilizes several core traits, each serving a specific purp These traits collectively facilitate a robust and flexible builder pattern that supports complex object creation and configuration scenarios. +## Example : Custom Definition + +Define a custom former definition and custom forming logic, and apply them to a container. + +The example showcases how to accumulate elements into a container and then transform them into a single result using a custom `FormingEnd` implementation. This pattern is useful for scenarios where the formation process involves aggregation or transformation of input elements into a different type or form. + +```rust +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + // Define a struct `Sum` that will act as a custom former definition. + struct Sum; + + // Implement `FormerDefinitionTypes` for `Sum`. + // This trait defines the types used during the forming process. + impl former::FormerDefinitionTypes for Sum + { + type Storage = Vec; // Container for the integers. + type Formed = i32; // The final type after forming, which is a single integer. + type Context = (); // No additional context is used in this example. + } + + // Implement `FormerMutator` for `Sum`. + // This trait could include custom mutation logic applied during the forming process, but it's empty in this example. + impl former::FormerMutator for Sum + { + } + + // Implement `FormerDefinition` for `Sum`. + // This trait links the custom types to the former. + impl former::FormerDefinition for Sum + { + type Types = Sum; // Associate the `FormerDefinitionTypes` with `Sum`. + type End = Sum; // Use `Sum` itself as the end handler. + type Storage = Vec; // Specify the storage type. + type Formed = i32; // Specify the final formed type. + type Context = (); // Specify the context type, not used here. + } + + // Implement `FormingEnd` for `Sum`. + // This trait handles the final step of the forming process. + impl former::FormingEnd for Sum + { + fn call + ( + &self, + storage: < Sum as former::FormerDefinitionTypes >::Storage, + _context: Option< < Sum as former::FormerDefinitionTypes >::Context> + ) + -> < Sum as former::FormerDefinitionTypes >::Formed + { + // Sum all integers in the storage vector. + storage.iter().sum() + } + } + + // Use the custom `Former` to sum a list of integers. + let got = former::ContainerFormer::::new(Sum) + .add( 1 ) // Add an integer to the storage. + .add( 2 ) // Add another integer. + .add( 10 ) // Add another integer. + .form(); // Perform the form operation, which triggers the summing logic. + let exp = 13; // Expected result after summing 1, 2, and 10. + assert_eq!(got, exp); // Assert the result is as expected. + + dbg!(got); // Debug print the result to verify the output. + // > got = 13 +} +``` + ## Concept of subformer Subformers are specialized builders used within the former to construct nested or collection-based data structures like vectors, hash maps, and hash sets. They simplify the process of adding elements to these structures by providing a fluent interface that can be seamlessly integrated into the overall builder pattern of a parent struct. This approach allows for clean and intuitive initialization of complex data structures, enhancing code readability and maintainability. @@ -670,7 +740,7 @@ It's crucial to understand the differences among subform setters, container sett Each type of setter is designed to address different needs in the formation process, ensuring that users can build complex, nested structures or simply set individual field values as required. -## Subformer example: Building a Vector +## Example : Container Setter for a Vector This example demonstrates how to employ the `Former` trait to configure a `Vec` using a container setter in a structured manner. @@ -703,7 +773,7 @@ Try out `cargo run --example former_container_vector`.
[See code](./examples/former_container_vector.rs). -## Subformer example: Building a Hashmap +## Example : Container Setter for a Hashmap This example demonstrates how to effectively employ the `Former` trait to configure a `HashMap` using a container setter. @@ -737,7 +807,7 @@ Try out `cargo run --example former_container_hashmap`.
[See code](./examples/former_container_hashmap.rs). -## Subformer example: Building a Hashset +## Example : Container Setter for a Hashset This example demonstrates the use of the `Former` trait to build a `collection_tools::HashSet` through subforming. @@ -771,9 +841,9 @@ Try out `cargo run --example former_container_hashset`.
[See code](./examples/former_container_hashset.rs). -## Custom Scalar Setter +## Example : Custom Scalar Setter -This example demonstrates the implementation of a scalar setter using the `Former` trait in Rust. Unlike the more complex subform and container setters shown in previous examples, this example focuses on a straightforward approach to directly set a scalar value within a parent entity. The `Parent` struct manages a `HashMap` of `Child` entities, and the scalar setter is used to set the entire `HashMap` directly. +This example demonstrates the implementation of a scalar setter using the `Former` trait. Unlike the more complex subform and container setters shown in previous examples, this example focuses on a straightforward approach to directly set a scalar value within a parent entity. The `Parent` struct manages a `HashMap` of `Child` entities, and the scalar setter is used to set the entire `HashMap` directly. The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. @@ -853,7 +923,7 @@ Try out `cargo run --example former_custom_scalar_setter`.
[See code](./examples/former_custom_scalar_setter.rs). -## Custom Container Setter +## Example : Custom Container Setter This example demonstrates the use of container setters to manage complex nested data structures with the `Former` trait, focusing on a parent-child relationship structured around a container `HashMap`. Unlike typical builder patterns that add individual elements using subform setters, this example uses a container setter to manage the entire collection of children. @@ -930,9 +1000,9 @@ Try out `cargo run --example former_custom_container_setter`.
[See code](./examples/former_custom_container_setter.rs). -## Custom Subform Setter +## Example : Custom Subform Setter -This example illustrates the implementation of nested builder patterns in Rust using the `Former` trait, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. +This example illustrates the implementation of nested builder patterns using the `Former` trait, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. @@ -1077,7 +1147,7 @@ of whether the forming process is occurring within the context of a superformer or nested field. This makes `form_mutation` suitable for entity-specific transformations that should not interfere with the hierarchical forming logic managed by `FormingEnd`. -## Example: Mutator and Storage Fields +## Example : Mutator and Storage Fields This example illustrates how to use the `FormerMutator` trait for implementing custom mutations and demonstrates the concept of storage-specific fields in the forming process. @@ -1140,6 +1210,11 @@ Try out `cargo run --example former_custom_mutator`. + + +- [Custom Defaults](./examples/former_custom_defaults.rs) - Former allows the specification of custom default values for fields through the `former( default )` attribute. +- [Custom Definition](./examples/former_custom_definition.rs) - Define a custom former definition and custom forming logic, and apply them to a container. + ## To add to your project diff --git a/module/core/former/examples/former_custom_default.rs b/module/core/former/examples/former_custom_defaults.rs similarity index 92% rename from module/core/former/examples/former_custom_default.rs rename to module/core/former/examples/former_custom_defaults.rs index c80eb0e1be..e7f8e779d7 100644 --- a/module/core/former/examples/former_custom_default.rs +++ b/module/core/former/examples/former_custom_defaults.rs @@ -1,4 +1,7 @@ -//! The `Former` crate enhances struct initialization in Rust by allowing the specification of custom default values for fields through the `default` attribute. + +//! ## Example : Custom Defaults +//! +//! Former allows the specification of custom default values for fields through the `former( default )` attribute. //! //! This feature not only provides a way to set initial values for struct fields without relying on the `Default` trait but also adds flexibility in handling cases where a field's type does not implement `Default`, or a non-standard default value is desired. //! The example showcases the `Former` crate's ability to initialize struct fields with custom default values: diff --git a/module/core/former/examples/former_custom_definition.rs b/module/core/former/examples/former_custom_definition.rs new file mode 100644 index 0000000000..40957cf3ce --- /dev/null +++ b/module/core/former/examples/former_custom_definition.rs @@ -0,0 +1,72 @@ +//! ## Example : Custom Definition +//! +//! Define a custom former definition and custom forming logic, and apply them to a container. +//! +//! The example showcases how to accumulate elements into a container and then transform them into a single result +//! using a custom `FormingEnd` implementation. This pattern is useful for scenarios where the formation process +//! involves aggregation or transformation of input elements into a different type or form. + +#[ cfg( not( all( feature = "derive_former", feature = "enabled" ) ) ) ] +fn main() {} + +#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +fn main() +{ + // Define a struct `Sum` that will act as a custom former definition. + struct Sum; + + // Implement `FormerDefinitionTypes` for `Sum`. + // This trait defines the types used during the forming process. + impl former::FormerDefinitionTypes for Sum + { + type Storage = Vec; // Container for the integers. + type Formed = i32; // The final type after forming, which is a single integer. + type Context = (); // No additional context is used in this example. + } + + // Implement `FormerMutator` for `Sum`. + // This trait could include custom mutation logic applied during the forming process, but it's empty in this example. + impl former::FormerMutator for Sum + { + } + + // Implement `FormerDefinition` for `Sum`. + // This trait links the custom types to the former. + impl former::FormerDefinition for Sum + { + type Types = Sum; // Associate the `FormerDefinitionTypes` with `Sum`. + type End = Sum; // Use `Sum` itself as the end handler. + type Storage = Vec; // Specify the storage type. + type Formed = i32; // Specify the final formed type. + type Context = (); // Specify the context type, not used here. + } + + // Implement `FormingEnd` for `Sum`. + // This trait handles the final step of the forming process. + impl former::FormingEnd for Sum + { + fn call + ( + &self, + storage: < Sum as former::FormerDefinitionTypes >::Storage, + _context: Option< < Sum as former::FormerDefinitionTypes >::Context> + ) + -> < Sum as former::FormerDefinitionTypes >::Formed + { + // Sum all integers in the storage vector. + storage.iter().sum() + } + } + + // Use the custom `Former` to sum a list of integers. + let got = former::ContainerFormer::::new(Sum) + .add( 1 ) // Add an integer to the storage. + .add( 2 ) // Add another integer. + .add( 10 ) // Add another integer. + .form(); // Perform the form operation, which triggers the summing logic. + let exp = 13; // Expected result after summing 1, 2, and 10. + assert_eq!(got, exp); // Assert the result is as expected. + + dbg!(got); // Debug print the result to verify the output. + // > got = 13 +} diff --git a/module/core/former/examples/former_custom_scalar_setter.rs b/module/core/former/examples/former_custom_scalar_setter.rs index 5005383cd0..e5acb1847b 100644 --- a/module/core/former/examples/former_custom_scalar_setter.rs +++ b/module/core/former/examples/former_custom_scalar_setter.rs @@ -1,9 +1,10 @@ // Example former_custom_scalar_setter.rs +//! ## Example : Custom Scalar Setter //! -//! This example demonstrates the implementation of a scalar setter using the `Former` trait in Rust. Unlike the more complex subform and container setters shown in previous examples, this example focuses on a straightforward approach to directly set a scalar value within a parent entity. The `Parent` struct manages a `HashMap` of `Child` entities, and the scalar setter is used to set the entire `HashMap` directly. +//! Use of a scalar setter within a `Former` trait implementation to directly assign a `HashMap` of `Child` entities to a `Parent` structure using a custom setter function. //! -//! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. +//! Unlike the more complex subform and container setters shown in previous examples, this example focuses on a straightforward approach to directly set a scalar value within a parent entity. The `Parent` struct manages a `HashMap` of `Child` entities, and the scalar setter is used to set the entire `HashMap` directly. The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. //! //! #### Types of Setters //! diff --git a/module/core/former/examples/former_custom_subform_setter.rs b/module/core/former/examples/former_custom_subform_setter.rs index 7855c51886..bff35ac6ea 100644 --- a/module/core/former/examples/former_custom_subform_setter.rs +++ b/module/core/former/examples/former_custom_subform_setter.rs @@ -1,7 +1,7 @@ // Example former_custom_subformer.rs //! -//! This example illustrates the implementation of nested builder patterns in Rust using the `Former` trait, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. +//! This example illustrates the implementation of nested builder patterns using the `Former` trait, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. //! //! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. //! diff --git a/module/core/former/examples/former_many_fields.rs b/module/core/former/examples/former_many_fields.rs index e275d99897..2e04953c77 100644 --- a/module/core/former/examples/former_many_fields.rs +++ b/module/core/former/examples/former_many_fields.rs @@ -15,7 +15,7 @@ //! //! The builder pattern methods significantly streamline the process of struct initialization, especially for structs with complex or optional fields. By leveraging `Former`, developers can write more readable and maintainable initialization code, avoiding the verbosity and complexity often associated with manual struct instantiation. //! -//! The `dbg!` macro is utilized to print the constructed `Structure1` instance, confirming that all fields are correctly assigned, including the handling of optional fields and collections. This example underscores the power and convenience of using `Former` for struct initialization in Rust projects. +//! The `dbg!` macro is utilized to print the constructed `Structure1` instance, confirming that all fields are correctly assigned, including the handling of optional fields and collections. #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] fn main() {} diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index 41c3120a37..eb94619057 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -11,29 +11,6 @@ pub( crate ) mod private use crate::*; - /// Represents a container by defining the types of entries and values it handles. - /// - /// This trait abstracts the nature of containers in data structures, facilitating the handling of contained - /// entries and values, especially in scenarios where the structure of the container allows for complex relationships, - /// such as `HashMap`s. It not only identifies what constitutes an entry and a value in the context of the container - /// but also provides utility for converting between these two, which is critical in operations involving entry manipulation - /// and value retrieval. - - pub trait Container - { - /// The type of entries that can be added to the container. This type can differ from `Val` in containers like `HashMap`, - /// where an entry might represent a key-value pair, and `Val` could represent just the value or the key. - type Entry; - - /// The type of values stored in the container. This might be distinct from `Entry` in complex containers. - /// For example, in a `HashMap`, while `Entry` might be a ( key, value ) tuple, `Val` might only be the value part. - type Val; - - /// Converts an entry to its corresponding value within the container. This function is essential for abstracting - /// the container's internal representation from the values it manipulates. - fn entry_to_val( e : Self::Entry ) -> Self::Val; - } - /// Facilitates the conversion of container entries to their corresponding value representations. /// /// This trait is utilized to transform an entry of a container into a value, abstracting the operation of containers @@ -157,6 +134,29 @@ pub( crate ) mod private } } + /// Represents a container by defining the types of entries and values it handles. + /// + /// This trait abstracts the nature of containers in data structures, facilitating the handling of contained + /// entries and values, especially in scenarios where the structure of the container allows for complex relationships, + /// such as `HashMap`s. It not only identifies what constitutes an entry and a value in the context of the container + /// but also provides utility for converting between these two, which is critical in operations involving entry manipulation + /// and value retrieval. + + pub trait Container + { + /// The type of entries that can be added to the container. This type can differ from `Val` in containers like `HashMap`, + /// where an entry might represent a key-value pair, and `Val` could represent just the value or the key. + type Entry; + + /// The type of values stored in the container. This might be distinct from `Entry` in complex containers. + /// For example, in a `HashMap`, while `Entry` might be a ( key, value ) tuple, `Val` might only be the value part. + type Val; + + /// Converts an entry to its corresponding value within the container. This function is essential for abstracting + /// the container's internal representation from the values it manipulates. + fn entry_to_val( e : Self::Entry ) -> Self::Val; + } + /// Provides functionality to add individual entries to a container. /// /// This trait extends the basic `Container` trait by introducing a method to add entries to a container. @@ -535,13 +535,16 @@ pub mod exposed #[ allow( unused_imports ) ] pub use super::private:: { - Container, + EntryToVal, ContainerValToEntry, ValToEntry, + + Container, ContainerAdd, ContainerAssign, ContainerFormer, + }; #[ doc( inline ) ] diff --git a/module/core/former/tests/inc/former_tests/container_former_common.rs b/module/core/former/tests/inc/former_tests/container_former_common.rs index 4528ef7312..3bc9c84dfc 100644 --- a/module/core/former/tests/inc/former_tests/container_former_common.rs +++ b/module/core/former/tests/inc/former_tests/container_former_common.rs @@ -42,8 +42,6 @@ fn definitions() fn begin_and_custom_end() { - // xxx : make example with that - // basic case fn return_13( _storage : Vec< String >, _context : Option< () > ) -> f32 @@ -94,8 +92,6 @@ fn begin_and_custom_end() fn custom_definition() { - // xxx : make example of that - struct Return13; impl former::FormerDefinitionTypes for Return13 { @@ -120,15 +116,15 @@ fn custom_definition() // - - impl the_module::FormingEnd< Return13 > + impl former::FormingEnd< Return13 > for Return13 { fn call ( &self, - _storage : < Return13 as the_module::FormerDefinitionTypes >::Storage, - _context : Option< < Return13 as the_module::FormerDefinitionTypes >::Context > - ) -> < Return13 as the_module::FormerDefinitionTypes >::Formed + _storage : < Return13 as former::FormerDefinitionTypes >::Storage, + _context : Option< < Return13 as former::FormerDefinitionTypes >::Context > + ) -> < Return13 as former::FormerDefinitionTypes >::Formed { 13 } @@ -136,14 +132,14 @@ fn custom_definition() // - let got = the_module::ContainerFormer::< String, Return13 >::begin_coercing( None, None, Return13 ) + let got = former::ContainerFormer::< String, Return13 >::begin( None, None, Return13 ) .add( "a" ) .add( "b" ) .form(); let exp = 13; a_id!( got, exp ); - let got = the_module::ContainerFormer::< String, Return13 >::new( Return13 ) + let got = former::ContainerFormer::< String, Return13 >::new( Return13 ) .add( "a" ) .add( "b" ) .form(); @@ -160,8 +156,6 @@ fn custom_definition() fn custom_definition_parametrized() { - // xxx : make example of that - struct Return13< E >( ::core::marker::PhantomData< E > ); impl< E > Return13< E > diff --git a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs index d08fb1e319..1b34ebbb3b 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashmap.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashmap.rs @@ -5,7 +5,7 @@ use super::*; #[ allow( unused_imports ) ] use collection_tools::HashMap; -// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn add() @@ -85,7 +85,7 @@ fn add() } -// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn replace() diff --git a/module/core/former/tests/inc/former_tests/container_former_hashset.rs b/module/core/former/tests/inc/former_tests/container_former_hashset.rs index f14c826831..83b8e7a994 100644 --- a/module/core/former/tests/inc/former_tests/container_former_hashset.rs +++ b/module/core/former/tests/inc/former_tests/container_former_hashset.rs @@ -5,7 +5,7 @@ use super::*; #[ allow( unused_imports ) ] use collection_tools::HashSet; -// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn add() @@ -85,7 +85,7 @@ fn add() } -// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn replace() diff --git a/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs b/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs index d62e770a9f..620e42198b 100644 --- a/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs +++ b/module/core/former/tests/inc/former_tests/only_test/parametrized_struct.rs @@ -39,7 +39,7 @@ fn command_form() // -// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn command_properties() diff --git a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs index c77e69cff8..ea039d9835 100644 --- a/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/only_test/subformer_basic.rs @@ -13,7 +13,7 @@ // ; // ca.execute( input ).unwrap(); -// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : for Antont : zzz : here and in all similar tests remove `#[ cfg( not( feature = "use_alloc" ) ) ]` #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn command_with_closure() @@ -59,7 +59,7 @@ fn command_with_closure() // -// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn command_properties() @@ -113,7 +113,7 @@ fn command_properties() // -// qqq : xxx : remove #[ cfg( not( feature = "use_alloc" ) ) ] +// qqq : zzz : remove #[ cfg( not( feature = "use_alloc" ) ) ] #[ cfg( not( feature = "use_alloc" ) ) ] #[ test ] fn aggregator() diff --git a/module/core/former/tests/inc/former_tests/unsigned_primitive_types.rs b/module/core/former/tests/inc/former_tests/unsigned_primitive_types.rs index 2d6fca6ac7..abfbe7d183 100644 --- a/module/core/former/tests/inc/former_tests/unsigned_primitive_types.rs +++ b/module/core/former/tests/inc/former_tests/unsigned_primitive_types.rs @@ -47,91 +47,90 @@ tests_impls! // -// xxx : make it working fn with_u16() { -// #[ derive( Debug, PartialEq, the_module::Former ) ] -// pub struct Counter -// { -// count : u16, -// } -// -// let counter = Counter::former() -// .count( 0 ) -// .form(); -// -// let expected = Counter -// { -// count : 0, -// }; -// -// a_id!( counter, expected ); + #[ derive( Debug, PartialEq, the_module::Former ) ] + pub struct Counter + { + count : u16, + } + + let counter = Counter::former() + .count( 0u16 ) + .form(); + + let expected = Counter + { + count : 0, + }; + + a_id!( counter, expected ); } // fn with_u32() { - // #[ derive( Debug, PartialEq, Former ) ] - // pub struct Counter - // { - // count : u32, - // } - // - // let counter = Counter::former() - // .count( 0 ) - // .form(); - // - // let expected = Counter - // { - // count : 0, - // }; - // - // a_id!( counter, expected ); + #[ derive( Debug, PartialEq, the_module::Former ) ] + pub struct Counter + { + count : u32, + } + + let counter = Counter::former() + .count( 0u32 ) + .form(); + + let expected = Counter + { + count : 0, + }; + + a_id!( counter, expected ); } // fn with_u64() { - // #[ derive( Debug, PartialEq, Former ) ] - // pub struct Counter - // { - // count : u64, - // } - // - // let counter = Counter::former() - // .count( 0 ) - // .form(); - // - // let expected = Counter - // { - // count : 0, - // }; - // - // a_id!( counter, expected ); + #[ derive( Debug, PartialEq, the_module::Former ) ] + pub struct Counter + { + count : u64, + } + + let counter = Counter::former() + .count( 0u64 ) + .form(); + + let expected = Counter + { + count : 0, + }; + + a_id!( counter, expected ); } // fn with_usize() { - // #[ derive( Debug, PartialEq, Former ) ] - // pub struct Counter - // { - // count : usize, - // } - // - // let counter = Counter::former() - // .count( 0 ) - // .form(); - // - // let expected = Counter - // { - // count : 0, - // }; - // - // a_id!( counter, expected ); + #[ derive( Debug, PartialEq, the_module::Former ) ] + pub struct Counter + { + count : usize, + } + + let counter = Counter::former() + .count( 0usize ) + .form(); + + let expected = Counter + { + count : 0, + }; + + a_id!( counter, expected ); } } diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 69ad902e9b..f57f67ed6d 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -176,7 +176,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let as_subformer_end_name = format!( "{}AsSubformerEnd", stru ); let as_subformer_end = syn::Ident::new( &as_subformer_end_name, stru.span() ); - // zzz : improve + // xxx : improve let as_subformer_end_doc = format!( "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure." ); /* parameters for structure */ @@ -555,7 +555,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// /// Construct new instance of former with default parameters. /// - // zzz : improve description + // xxx : improve description #[ inline( always ) ] pub fn new( on_end : Definition::End ) -> Self { @@ -565,7 +565,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// /// Construct new instance of former with default parameters. /// - // zzz : improve description + // xxx : improve description #[ inline( always ) ] pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self where @@ -582,7 +582,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// /// Begin the process of forming. Expects context of forming to return it after forming. /// - // zzz : improve description + // xxx : improve description #[ inline( always ) ] pub fn begin ( @@ -607,7 +607,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > /// /// Begin the process of forming. Expects context of forming to return it after forming. /// - // zzz : improve description + // xxx : improve description #[ inline( always ) ] pub fn begin_coercing< IntoEnd > ( @@ -727,7 +727,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = subformer - // zzz : improve description + // xxx : improve description /// Use as subformer of a field during process of forming of super structure. pub type #as_subformer < #struct_generics_ty __Superformer, __End > = #former < @@ -744,7 +744,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = as subformer end - // zzz : imporove documentation + // xxx : imporove documentation #[ doc = #as_subformer_end_doc ] pub trait #as_subformer_end < #struct_generics_impl SuperFormer > where diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index eff1761cd9..157a8a7b93 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -31,7 +31,7 @@ use macro_tools::prelude::*; #[ cfg( feature = "derive_former" ) ] mod derive_former; -// zzz : outdated +// xxx : outdated /// /// Derive macro to generate former for a structure. Former is variation of Builder Pattern. /// @@ -144,7 +144,7 @@ mod derive_former; /// > /// where /// End : former::FormingEnd< UserProfile, Context >, -/// // zzz : update +/// // xxx : update /// { /// storage : UserProfileFormerStorage, /// context : Option< Context >, @@ -192,7 +192,7 @@ mod derive_former; /// return result.greet_user(); /// } /// -/// // qqq : zzz : outdated, update +/// // qqq : xxx : outdated, update /// #[ inline( always ) ] /// pub fn new_coercing() -> UserProfileFormer< UserProfile, former::ReturnFormed > /// { From cc6a4ca80910bffeea8811d519514b48c1ccf562 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 19:44:36 +0300 Subject: [PATCH 525/533] former : cleaning --- module/core/former_meta/src/derive_former.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index f57f67ed6d..1ac55b5bb7 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -779,7 +779,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { let about = format!( "derive : Former\nstructure : {stru}" ); diag::report_print( about, &original_input, &result ); - // diag::report_print( "derive : Former", original_input, &result ); } Ok( result ) From cbb16e933b72912d8ed3c6a9ed6120bf7be804b3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 11 May 2024 23:41:03 +0300 Subject: [PATCH 526/533] former : cleaning --- .../inc/former_tests/a_containers_manual.rs | 3 +- .../inc/former_tests/a_primitives_manual.rs | 2 +- module/core/former_meta/src/derive_former.rs | 60 ++--- .../former_meta/src/derive_former/field.rs | 6 +- module/core/former_meta/src/lib.rs | 235 ++---------------- 5 files changed, 56 insertions(+), 250 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_manual.rs index 87f2bf5b00..60648737fa 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_manual.rs @@ -524,7 +524,8 @@ pub type Struct1AsSubformer< Superformer, End > = Struct1Former >; #[ allow( dead_code ) ] -pub trait Struct1AsSubformerEnd where Self : former::FormingEnd< Struct1FormerDefinitionTypes, > +pub trait Struct1AsSubformerEnd +where Self : former::FormingEnd< Struct1FormerDefinitionTypes, > {} impl Struct1AsSubformerEnd for T diff --git a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs index 31aa3191cc..90e1290d6b 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives_manual.rs @@ -17,7 +17,7 @@ impl Struct1 { pub fn former() -> Struct1Former { - Struct1Former::new_coercing( the_module::ReturnPreformed ) + Struct1Former::new_coercing( former::ReturnPreformed ) } } diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 1ac55b5bb7..65044ba5cb 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -112,30 +112,15 @@ r#" Implementation of former for [{}]. stru ); - let doc_example1 = -r#" -use former::Former; -#[ derive( Former ) ] -pub struct Struct1 -{ - #[default( 31 ) ] - field1 : i32, -} -"#; - let doc_former_struct = format! ( r#" Structure to form [{}]. Represents a forming entity designed to construct objects through a builder pattern. This structure holds temporary storage and context during the formation process and -utilizes a defined end strategy to finalize the object creation. It facilitates the flexible -construction of complex objects by allowing step-by-step configuration. -``` -{} -``` +utilizes a defined end strategy to finalize the object creation. "#, - stru, doc_example1 + stru ); ( doc_former_mod, doc_former_struct ) @@ -176,8 +161,15 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > let as_subformer_end_name = format!( "{}AsSubformerEnd", stru ); let as_subformer_end = syn::Ident::new( &as_subformer_end_name, stru.span() ); - // xxx : improve - let as_subformer_end_doc = format!( "Alias for trait former::FormingEnd with context and formed the same type and definition of structure [`$(stru)`]. Use as subformer end of a field during process of forming of super structure." ); + let as_subformer_end_doc = format! + ( + r#" +Represents an end condition for former of [`${stru}`], tying the lifecycle of forming processes to a broader context. + +This trait is intended for use with subformer alias, ensuring that end conditions are met according to the +specific needs of the broader forming context. It mandates the implementation of `former::FormingEnd`. + "# + ); /* parameters for structure */ @@ -341,7 +333,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { /// - /// Make former, variation of builder pattern to form structure defining values of fields step by step. + /// Provides a mechanism to initiate the formation process with a default completion behavior. /// #[ inline( always ) ] @@ -391,6 +383,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = definition types + /// Defines the generic parameters for formation behavior including context, form, and end conditions. #[ derive( Debug ) ] pub struct #former_definition_types < #former_definition_types_generics_with_defaults > where @@ -426,6 +419,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = definition + /// Holds the definition types used during the formation process. #[ derive( Debug ) ] pub struct #former_definition < #former_definition_generics_with_defaults > where @@ -468,9 +462,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = storage - #[ doc = "Container of a corresponding former." ] + #[ doc = "Stores potential values for fields during the formation process." ] #[ allow( explicit_outlives_requirements ) ] - // pub struct #former_storage < #struct_generics_ty > pub struct #former_storage < #struct_generics_with_defaults > where #struct_generics_where @@ -553,9 +546,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > { /// - /// Construct new instance of former with default parameters. + /// Initializes a former with an end condition and default storage. /// - // xxx : improve description #[ inline( always ) ] pub fn new( on_end : Definition::End ) -> Self { @@ -563,9 +555,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } /// - /// Construct new instance of former with default parameters. + /// Initializes a former with a coercible end condition. /// - // xxx : improve description #[ inline( always ) ] pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self where @@ -580,9 +571,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } /// - /// Begin the process of forming. Expects context of forming to return it after forming. + /// Begins the formation process with specified context and termination logic. /// - // xxx : improve description #[ inline( always ) ] pub fn begin ( @@ -605,9 +595,8 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } /// - /// Begin the process of forming. Expects context of forming to return it after forming. + /// Starts the formation process with coercible end condition and optional initial values. /// - // xxx : improve description #[ inline( always ) ] pub fn begin_coercing< IntoEnd > ( @@ -631,7 +620,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } /// - /// End the process of forming returning original context of forming. + /// Wrapper for `end` to align with common builder pattern terminologies. /// #[ inline( always ) ] pub fn form( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed @@ -640,7 +629,7 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > } /// - /// End the process of forming returning original context of forming. + /// Completes the formation and returns the formed object. /// #[ inline( always ) ] pub fn end( mut self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed @@ -727,8 +716,10 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = subformer - // xxx : improve description - /// Use as subformer of a field during process of forming of super structure. + /// Provides a specialized former for structure using predefined settings for superformer and end conditions. + /// + /// This type alias configures former of the structure with a specific definition to streamline its usage in broader contexts, + /// especially where structure needs to be integrated into larger structures with a clear termination condition. pub type #as_subformer < #struct_generics_ty __Superformer, __End > = #former < #struct_generics_ty @@ -744,7 +735,6 @@ pub fn former( input : proc_macro::TokenStream ) -> Result< TokenStream > // = as subformer end - // xxx : imporove documentation #[ doc = #as_subformer_end_doc ] pub trait #as_subformer_end < #struct_generics_impl SuperFormer > where diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 936477d380..cba88da221 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -894,11 +894,7 @@ with the new content generated during the subforming process. let subformer_definition_types = if let Some( ref _subformer_definition ) = subformer_definition { - // let subformer_definition_types_name = format!( "{}Types", qt!{ #subformer_definition } ); - // dbg!( &subformer_definition_types_name ); - // let subformer_definition_types = syn::Ident::new( &subformer_definition_types_name, field_ident.span() ); let subformer_definition_types_string = format!( "{}Types", qt!{ #subformer_definition } ); - // let subformer_definition_types : syn::Type = subformer_definition_types_string.parse()? let subformer_definition_types : syn::Type = syn::parse_str( &subformer_definition_types_string )?; qt! { @@ -1062,7 +1058,7 @@ where let doc = format! ( - "Setter for the '{}' field.", + "Scalar setter for the '{}' field.", field_ident, ); diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index 157a8a7b93..8d1a1f67e6 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -31,79 +31,41 @@ use macro_tools::prelude::*; #[ cfg( feature = "derive_former" ) ] mod derive_former; -// xxx : outdated +/// Derive macro for generating a `Former` struct, applying a Builder Pattern to the annotated struct. /// -/// Derive macro to generate former for a structure. Former is variation of Builder Pattern. +/// This macro simplifies the construction of complex objects by automatically generating a builder (former) for +/// the specified struct. It supports extensive customization through attributes that control defaults, setter generation, +/// and field customization, allowing for flexible and fluent object construction. /// -/// Derives a 'Former' for a struct, implementing a variation of the Builder Pattern. +/// # Struct Attributes /// -/// This macro simplifies the creation of builder patterns for structs by automatically -/// generating a 'former' (builder) struct and implementation. It supports customization -/// through attributes to control default values, setter generation, subformer inclusion, -/// and field aliases. +/// - `debug`: Enables debug mode which can be used to print or log the internal state of the builder for debugging purposes. +/// - `perform`: Specifies a custom method to be invoked automatically at the end of the build process. +/// - `storage_fields`: Specifies fields that should be treated as part of the storage for the former. +/// - `mutator`: Defines a custom mutator class or function to manipulate the data just before the object is finalized. /// -/// # Attributes : -/// - `perform` : Specifies a method to call on the built object immediately after its construction. -/// - `default` : Sets a default value for a field. -/// - `setter` : Enables or disables the generation of a setter method for a field. -/// - `subformer` : Defines a sub-former for complex field types, allowing nested builders. -/// - `alias` : Creates an alias for a field setter. -/// - `doc` : Adds documentation to the generated setter methods. (deprecated) +/// # Field Attributes /// -/// # Input Example : +/// - `former`: General attribute to specify various options like defaults or inclusion in the former. +/// - `scalar`: Indicates that the field is a scalar value, enabling direct assignment without the need for a sub-former. +/// - `container`: Marks the field as a container that can use specific former methods to manage its contents. +/// - `subform`: Specifies that the field should utilize a nested former, facilitating the construction of complex nested structures. /// -/// ```rust -/// use former::Former; -/// -/// #[ derive( Debug, PartialEq, Former ) ] -/// #[ perform( fn greet_user() ) ] -/// pub struct UserProfile -/// { -/// #[ former( default = 1 ) ] -/// age : i32, -/// -/// username : String, -/// -/// #[alias(bio)] -/// bio_optional : Option< String >, // Fields could be optional -/// } -/// -/// impl UserProfile -/// { -/// fn greet_user(self) -> Self -/// { -/// println!("Hello, {}", self.username); -/// self -/// } -/// } -/// -/// let profile = UserProfile::former() -/// .age( 30 ) -/// .username( "JohnDoe".to_string() ) -/// .bio_optional( "Software Developer".to_string() ) // Optionally provide a bio -/// .form(); -/// // .perform(); // same as `form()` but will execute method passed to perform attribute -/// -/// dbg!( &profile ); -/// // Expected output: -/// // &profile = UserProfile { -/// // age: 30, -/// // username: "JohnDoe", -/// // bio_optional: Some("Software Developer"), -/// // } -/// ``` +/// # Usage Example /// -/// # Generated Code Example : -/// -/// Assuming the struct above, the macro generates something like this : +/// Below is a typical usage example where the macro is applied to a struct: /// /// ```rust -/// # #[ cfg( feature = "enabled" ) ] -/// # #[ allow( dead_code ) ] +/// +/// # #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] /// # fn main() /// # { +/// use former::Former; /// -/// #[ derive( Debug, PartialEq ) ] +/// // Use attribute debug to print expanded code. +/// #[ derive( Debug, PartialEq, Former ) ] +/// // Uncomment to see what derive expand into +/// // #[ debug ] /// pub struct UserProfile /// { /// age : i32, @@ -111,155 +73,10 @@ mod derive_former; /// bio_optional : Option< String >, // Fields could be optional /// } /// -/// impl UserProfile -/// { -/// fn greet_user(self) -> Self -/// { -/// println!("Hello, {}", self.username); -/// self -/// } -/// } -/// -/// impl UserProfile -/// { -/// #[ inline( always ) ] -/// pub fn former() -> UserProfileFormer< UserProfile, former::ReturnFormed > -/// { -/// UserProfileFormer::< UserProfile, former::ReturnFormed >::new_coercing() -/// } -/// } -/// -/// #[ derive( Debug, Default ) ] -/// pub struct UserProfileFormerStorage -/// { -/// age : Option< i32 >, -/// username : Option< String >, -/// bio_optional : Option< String >, -/// } -/// -/// pub struct UserProfileFormer -/// < -/// Context = UserProfile, -/// End = former::ReturnFormed, -/// > -/// where -/// End : former::FormingEnd< UserProfile, Context >, -/// // xxx : update -/// { -/// storage : UserProfileFormerStorage, -/// context : Option< Context >, -/// on_end : Option< End >, -/// } -/// -/// impl< Context, End > UserProfileFormer< Context, End > -/// where -/// End : former::FormingEnd< UserProfile, Context >, -/// { -/// #[ inline( always ) ] -/// pub fn form( mut self ) -> UserProfile -/// { -/// let age = if self.storage.age.is_some() -/// { -/// self.storage.age.take().unwrap() -/// } -/// else -/// { -/// (1).into() -/// }; -/// let username = if self.storage.username.is_some() -/// { -/// self.storage.username.take().unwrap() -/// } -/// else -/// { -/// String::default() -/// }; -/// let bio_optional = if self.storage.bio_optional.is_some() -/// { -/// Some( self.storage.bio_optional.take().unwrap() ) -/// } -/// else -/// { -/// None -/// }; -/// UserProfile { age, username, bio_optional } -/// } -/// -/// #[ inline( always ) ] -/// pub fn perform( self ) -> UserProfile -/// { -/// let result = self.form(); -/// return result.greet_user(); -/// } -/// -/// // qqq : xxx : outdated, update -/// #[ inline( always ) ] -/// pub fn new_coercing() -> UserProfileFormer< UserProfile, former::ReturnFormed > -/// { -/// UserProfileFormer::< UserProfile, former::ReturnFormed >::begin_coercing( None, former::ReturnFormed ) -/// } -/// -/// #[ inline( always ) ] -/// pub fn begin_coercing( context : Option< Context >, on_end : End ) -> Self -/// { -/// Self -/// { -/// storage : Default::default(), -/// context, -/// on_end : Some( on_end ), -/// } -/// } -/// -/// #[ inline( always ) ] -/// pub fn end( mut self ) -> Context -/// { -/// let on_end = self.on_end.take().unwrap(); -/// let context = self.context.take(); -/// let formed = self.form(); -/// on_end.call( formed, context ) -/// } -/// -/// #[ inline ] -/// pub fn age< Src >( mut self, src : Src ) -> Self -/// where -/// Src : Into< i32 >, -/// { -/// self.storage.age = Some( src.into() ); -/// self -/// } -/// -/// #[ inline ] -/// pub fn username< Src >( mut self, src : Src ) -> Self -/// where -/// Src : Into< String >, -/// { -/// self.storage.username = Some( src.into() ); -/// self -/// } -/// -/// #[ inline ] -/// pub fn bio_optional< Src >( mut self, src : Src ) -> Self -/// where -/// Src : Into< String >, -/// { -/// self.storage.bio_optional = Some( src.into() ); -/// self -/// } -/// -/// #[inline] -/// pub fn bio< Src >( mut self, src : Src ) -> Self -/// where -/// Src : Into< String >, -/// { -/// self.storage.bio_optional = Some( src.into() ); -/// self -/// } -/// } -/// /// let profile = UserProfile::former() /// .age( 30 ) /// .username( "JohnDoe".to_string() ) -/// .bio_optional( "Software Developer".to_string() ) +/// .bio_optional( "Software Developer".to_string() ) // Optionally provide a bio /// .form(); /// /// dbg!( &profile ); @@ -269,10 +86,12 @@ mod derive_former; /// // username: "JohnDoe", /// // bio_optional: Some("Software Developer"), /// // } +/// /// # } +/// /// ``` /// -/// This generated code allows building an instance of `MyStruct` fluently, with optional customization for each field. +/// This pattern enables fluent and customizable construction of `UserProfile` instances, allowing for easy setting and modification of its fields. #[ cfg( feature = "enabled" ) ] #[ cfg( feature = "derive_former" ) ] From c89af80641dd12ff541e8afd1cb5dd37a83f75f4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 12 May 2024 00:03:20 +0300 Subject: [PATCH 527/533] former : cleaning --- module/core/clone_dyn/tests/inc/mod.rs | 2 +- module/core/former/Readme.md | 4 ++-- module/core/former/src/container.rs | 2 +- module/core/former/src/forming.rs | 21 ++++++++++--------- module/core/former/tests/inc/mod.rs | 2 ++ module/core/former_meta/src/derive_former.rs | 2 +- module/core/macro_tools/src/generic_args.rs | 4 ++-- module/core/macro_tools/src/generic_params.rs | 8 +++---- module/core/macro_tools/src/tokens.rs | 10 ++++----- .../macro_tools/tests/inc/generic_args.rs | 4 ++-- .../macro_tools/tests/inc/generic_params.rs | 14 ++++++------- module/core/process_tools/src/process.rs | 4 ++-- .../reflect_tools/src/reflect/axiomatic.rs | 16 +++++++------- 13 files changed, 48 insertions(+), 45 deletions(-) diff --git a/module/core/clone_dyn/tests/inc/mod.rs b/module/core/clone_dyn/tests/inc/mod.rs index 6477b35c67..99cee0a3c6 100644 --- a/module/core/clone_dyn/tests/inc/mod.rs +++ b/module/core/clone_dyn/tests/inc/mod.rs @@ -119,7 +119,7 @@ tests_impls! #[ clone_dyn ] trait Trait2< T1 : Copy, T2 : Copy > where - T2 : Clone + std::fmt::Debug, + T2 : Clone + core::fmt::Debug, { } diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 3725c64a8e..df859cb0aa 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -60,8 +60,8 @@ fn main() // bio_optional: Some("Software Developer"), // } - } - ``` +} +```
The code above will be expanded to this diff --git a/module/core/former/src/container.rs b/module/core/former/src/container.rs index eb94619057..2e0897da73 100644 --- a/module/core/former/src/container.rs +++ b/module/core/former/src/container.rs @@ -323,7 +323,7 @@ pub( crate ) mod private on_end : core::option::Option< Definition::End >, } - use std::fmt; + use core::fmt; impl< E, Definition > fmt::Debug for ContainerFormer< E, Definition > where Definition : FormerDefinition, diff --git a/module/core/former/src/forming.rs b/module/core/former/src/forming.rs index 8bb8968418..d4c6ae3331 100644 --- a/module/core/former/src/forming.rs +++ b/module/core/former/src/forming.rs @@ -132,7 +132,7 @@ where /// A placeholder `FormingEnd` used when no end operation is required or applicable. /// /// This implementation is useful in generic or templated scenarios where a `FormingEnd` is required by the interface, -/// but no meaningful end operation is applicable. It serves a role similar to `std::marker::PhantomData` by filling +/// but no meaningful end operation is applicable. It serves a role similar to `core::marker::PhantomData` by filling /// generic parameter slots without contributing operational logic. #[ derive( Debug, Default ) ] pub struct NoEnd; @@ -156,13 +156,14 @@ where /// `FormingEnd` trait's `call` method signature. It is useful for cases where /// a closure needs to be stored or passed around as an object implementing /// `FormingEnd`. -#[ cfg( not( feature = "no_std" ) ) ] +#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] pub struct FormingEndClosure< Definition : crate::FormerDefinitionTypes > { closure : Box< dyn Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed >, - _marker : std::marker::PhantomData< Definition::Storage >, + _marker : core::marker::PhantomData< Definition::Storage >, } +#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] impl< T, Definition > From< T > for FormingEndClosure< Definition > where T : Fn( Definition::Storage, Option< Definition::Context > ) -> Definition::Formed + 'static, @@ -174,12 +175,12 @@ where Self { closure : Box::new( closure ), - _marker : std::marker::PhantomData + _marker : core::marker::PhantomData } } } -#[ cfg( not( feature = "no_std" ) ) ] +#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] impl< Definition : crate::FormerDefinitionTypes > FormingEndClosure< Definition > { /// Constructs a new `FormingEndClosure` with the provided closure. @@ -198,14 +199,14 @@ impl< Definition : crate::FormerDefinitionTypes > FormingEndClosure< Definition Self { closure : Box::new( closure ), - _marker : std::marker::PhantomData + _marker : core::marker::PhantomData } } } -#[ cfg( not( feature = "no_std" ) ) ] -use std::fmt; -#[ cfg( not( feature = "no_std" ) ) ] +#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +use core::fmt; +#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] impl< Definition : crate::FormerDefinitionTypes > fmt::Debug for FormingEndClosure< Definition > { fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result @@ -217,7 +218,7 @@ impl< Definition : crate::FormerDefinitionTypes > fmt::Debug for FormingEndClosu } } -#[ cfg( not( feature = "no_std" ) ) ] +#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] impl< Definition : crate::FormerDefinitionTypes > FormingEnd< Definition > for FormingEndClosure< Definition > { diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 1e33431148..a3de17fa64 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -139,6 +139,8 @@ only_for_terminal_module! // stable have different information about error // that's why these tests are active only for nightly + + #[ cfg( feature = "derive_former" ) ] #[ test_tools::nightly ] #[ test ] fn former_trybuild() diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index 65044ba5cb..dac0eb6e8a 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -25,7 +25,7 @@ use struct_attrs::*; /// /// Below is an example of how the generated code might look: /// -/// ```rust +/// ```rust, ignore /// impl< Context, Formed > former::FormerMutator /// for Struct1FormerDefinitionTypes< Context, Formed > /// { diff --git a/module/core/macro_tools/src/generic_args.rs b/module/core/macro_tools/src/generic_args.rs index 81cf77cd73..aeea032b5a 100644 --- a/module/core/macro_tools/src/generic_args.rs +++ b/module/core/macro_tools/src/generic_args.rs @@ -90,10 +90,10 @@ pub( crate ) mod private /// }; /// /// let a: AngleBracketedGenericArguments = parse_quote! { <'a, T: Clone, U: Default> }; - /// let b: AngleBracketedGenericArguments = parse_quote! { <'b, V: std::fmt::Debug> }; + /// let b: AngleBracketedGenericArguments = parse_quote! { <'b, V: core::fmt::Debug> }; /// let merged = generic_args::merge(&a, &b); /// - /// let expected: AngleBracketedGenericArguments = parse_quote! { <'a, 'b, T: Clone, U: Default, V: std::fmt::Debug> }; + /// let expected: AngleBracketedGenericArguments = parse_quote! { <'a, 'b, T: Clone, U: Default, V: core::fmt::Debug> }; /// assert_eq!(merged, expected); /// ``` /// diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index 380e82e3ed..f2e852f125 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -128,13 +128,13 @@ pub( crate ) mod private /// /// let mut generics_a : syn::Generics = parse_quote!{ < T : Clone, U : Default > }; /// generics_a.where_clause = parse_quote!{ where T : Default }; - /// let mut generics_b : syn::Generics = parse_quote!{ < V : std::fmt::Debug > }; + /// let mut generics_b : syn::Generics = parse_quote!{ < V : core::fmt::Debug > }; /// generics_b.where_clause = parse_quote!{ where V : Sized }; /// let got = generic_params::merge( &generics_a, &generics_b ); /// /// let mut exp : syn::Generics = parse_quote! /// { - /// < T : Clone, U : Default, V : std::fmt::Debug > + /// < T : Clone, U : Default, V : core::fmt::Debug > /// }; /// exp.where_clause = parse_quote! /// { @@ -212,8 +212,8 @@ pub( crate ) mod private /// # use macro_tools::syn::parse_quote; /// /// let mut generics : syn::Generics = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > }; - /// generics.where_clause = parse_quote!{ where T: std::fmt::Debug }; - /// // let generics : Generics = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > where T: std::fmt::Debug }; + /// generics.where_clause = parse_quote!{ where T: core::fmt::Debug }; + /// // let generics : Generics = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > where T: core::fmt::Debug }; /// let simplified_generics = macro_tools::generic_params::names( &generics ); /// /// assert_eq!( simplified_generics.params.len(), 4 ); // Contains T, U, 'a, and N diff --git a/module/core/macro_tools/src/tokens.rs b/module/core/macro_tools/src/tokens.rs index b1740ad332..9f0cd32435 100644 --- a/module/core/macro_tools/src/tokens.rs +++ b/module/core/macro_tools/src/tokens.rs @@ -6,7 +6,7 @@ pub( crate ) mod private { use super::super::*; - use std::fmt; + use core::fmt; /// `Tokens` is a wrapper around `proc_macro2::TokenStream`. /// It is designed to facilitate the parsing and manipulation of token streams @@ -63,9 +63,9 @@ pub( crate ) mod private } } - impl std::fmt::Display for Tokens + impl core::fmt::Display for Tokens { - fn fmt( &self, f : &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result + fn fmt( &self, f : &mut core::fmt::Formatter< '_ > ) -> core::fmt::Result { write!( f, "{}", self.inner.to_string() ) } @@ -137,9 +137,9 @@ pub( crate ) mod private } } - // impl std::fmt::Display for Equation + // impl core::fmt::Display for Equation // { - // fn fmt( &self, f : &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result + // fn fmt( &self, f : &mut core::fmt::Formatter< '_ > ) -> core::fmt::Result // { // write!( f, "{}", self.left.to_string() ); // write!( f, "{}", self.op.to_string() ); diff --git a/module/core/macro_tools/tests/inc/generic_args.rs b/module/core/macro_tools/tests/inc/generic_args.rs index 0ad7085baa..8076737930 100644 --- a/module/core/macro_tools/tests/inc/generic_args.rs +++ b/module/core/macro_tools/tests/inc/generic_args.rs @@ -314,8 +314,8 @@ fn merge_complex_generic_constraints() use macro_tools::generic_args; let a : AngleBracketedGenericArguments = parse_quote! { < T : Clone + Send, U: Default > }; - let b : AngleBracketedGenericArguments = parse_quote! { < V : std::fmt::Debug + Sync > }; - let exp : AngleBracketedGenericArguments = parse_quote! { < T: Clone + Send, U: Default, V: std::fmt::Debug + Sync > }; + let b : AngleBracketedGenericArguments = parse_quote! { < V : core::fmt::Debug + Sync > }; + let exp : AngleBracketedGenericArguments = parse_quote! { < T: Clone + Send, U: Default, V: core::fmt::Debug + Sync > }; let got = generic_args::merge( &a, &b ); a_id!( got, exp, "Complex constraints should be merged correctly" ); diff --git a/module/core/macro_tools/tests/inc/generic_params.rs b/module/core/macro_tools/tests/inc/generic_params.rs index d0bb3b0dbe..d9395b74a2 100644 --- a/module/core/macro_tools/tests/inc/generic_params.rs +++ b/module/core/macro_tools/tests/inc/generic_params.rs @@ -9,7 +9,7 @@ fn generics_with_where() let got : the_module::GenericsWithWhere = parse_quote! { - < 'a, T : Clone, U : Default, V : std::fmt::Debug > + < 'a, T : Clone, U : Default, V : core::fmt::Debug > where Definition : former::FormerDefinition, }; @@ -17,7 +17,7 @@ fn generics_with_where() let mut exp : syn::Generics = parse_quote! { - < 'a, T : Clone, U : Default, V : std::fmt::Debug > + < 'a, T : Clone, U : Default, V : core::fmt::Debug > }; exp.where_clause = parse_quote! { @@ -46,13 +46,13 @@ fn merge_assumptions() let mut generics_a : syn::Generics = parse_quote!{ < T : Clone, U : Default > }; generics_a.where_clause = parse_quote!{ where T : Default }; - let mut generics_b : syn::Generics = parse_quote!{ < V : std::fmt::Debug > }; + let mut generics_b : syn::Generics = parse_quote!{ < V : core::fmt::Debug > }; generics_b.where_clause = parse_quote!{ where V : Sized }; let got = generic_params::merge( &generics_a, &generics_b ); let mut exp : syn::Generics = parse_quote! { - < T : Clone, U : Default, V : std::fmt::Debug > + < T : Clone, U : Default, V : core::fmt::Debug > }; exp.where_clause = parse_quote! { @@ -82,13 +82,13 @@ fn merge_defaults() let mut generics_a : syn::Generics = parse_quote!{ < T : Clone, U : Default = Default1 > }; generics_a.where_clause = parse_quote!{ where T : Default }; - let mut generics_b : syn::Generics = parse_quote!{ < V : std::fmt::Debug = Debug1 > }; + let mut generics_b : syn::Generics = parse_quote!{ < V : core::fmt::Debug = Debug1 > }; generics_b.where_clause = parse_quote!{ where V : Sized }; let got = generic_params::merge( &generics_a, &generics_b ); let mut exp : syn::Generics = parse_quote! { - < T : Clone, U : Default = Default1, V : std::fmt::Debug = Debug1 > + < T : Clone, U : Default = Default1, V : core::fmt::Debug = Debug1 > }; exp.where_clause = parse_quote! { @@ -117,7 +117,7 @@ fn names() use macro_tools::syn::parse_quote; - let generics : the_module::GenericsWithWhere = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > where T: std::fmt::Debug }; + let generics : the_module::GenericsWithWhere = parse_quote!{ < T : Clone + Default, U, 'a, const N : usize > where T: core::fmt::Debug }; let simplified_generics = macro_tools::generic_params::names( &generics.unwrap() ); assert_eq!( simplified_generics.params.len(), 4 ); // Contains T, U, 'a, and N diff --git a/module/core/process_tools/src/process.rs b/module/core/process_tools/src/process.rs index 3060f0d105..7250458510 100644 --- a/module/core/process_tools/src/process.rs +++ b/module/core/process_tools/src/process.rs @@ -298,9 +298,9 @@ pub( crate ) mod private } } } - impl std::fmt::Display for Report + impl core::fmt::Display for Report { - fn fmt( &self, f : &mut Formatter< '_ > ) -> std::fmt::Result + fn fmt( &self, f : &mut Formatter< '_ > ) -> core::fmt::Result { // Trim prevents writing unnecessary whitespace or empty lines f.write_fmt( format_args!( "> {}\n", self.command ) )?; diff --git a/module/core/reflect_tools/src/reflect/axiomatic.rs b/module/core/reflect_tools/src/reflect/axiomatic.rs index 4dd0cfb454..df63730d59 100644 --- a/module/core/reflect_tools/src/reflect/axiomatic.rs +++ b/module/core/reflect_tools/src/reflect/axiomatic.rs @@ -349,36 +349,36 @@ pub( crate ) mod private } } - impl< T > std::fmt::Debug for EntityDescriptor< T > + impl< T > core::fmt::Debug for EntityDescriptor< T > where T : Instance + 'static, EntityDescriptor< T > : Entity, { - fn fmt( &self, f: &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result + fn fmt( &self, f: &mut core::fmt::Formatter< '_ > ) -> core::fmt::Result { f .write_str( &format!( "{}#{:?}", self.type_name(), self.type_id() ) ) } } - impl< T > std::fmt::Debug for CollectionDescriptor< T > + impl< T > core::fmt::Debug for CollectionDescriptor< T > where T : Instance + 'static, CollectionDescriptor< T > : Entity, { - fn fmt( &self, f: &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result + fn fmt( &self, f: &mut core::fmt::Formatter< '_ > ) -> core::fmt::Result { f .write_str( &format!( "{}#{:?}", self.type_name(), self.type_id() ) ) } } - impl< T > std::fmt::Debug for KeyedCollectionDescriptor< T > + impl< T > core::fmt::Debug for KeyedCollectionDescriptor< T > where T : Instance + 'static, KeyedCollectionDescriptor< T > : Entity, { - fn fmt( &self, f: &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result + fn fmt( &self, f: &mut core::fmt::Formatter< '_ > ) -> core::fmt::Result { f .write_str( &format!( "{}#{:?}", self.type_name(), self.type_id() ) ) @@ -415,9 +415,9 @@ pub( crate ) mod private } } - impl std::fmt::Debug for KeyVal + impl core::fmt::Debug for KeyVal { - fn fmt( &self, f: &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result + fn fmt( &self, f: &mut core::fmt::Formatter< '_ > ) -> core::fmt::Result { f .debug_struct( "KeyVal" ) From 5079701028bc49f58eb7e55729565074584b6f6c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 12 May 2024 00:15:56 +0300 Subject: [PATCH 528/533] former : cleaning --- module/core/former/Readme.md | 129 ++++++++++++++++++++++++----------- 1 file changed, 89 insertions(+), 40 deletions(-) diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index df859cb0aa..35aea33b92 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -31,9 +31,13 @@ This approach abstracts away the need for manually implementing a builder for ea The provided code snippet illustrates a basic use-case of the Former, which is used to apply the builder pattern for structured and flexible object creation. Below is a detailed explanation of each part of the markdown chapter, aimed at clarifying how the Former trait simplifies struct instantiation. ```rust -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -fn main() -{ +# #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +# fn main() {} + +# #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +# fn main() +# { + use former::Former; // Use attribute debug to print expanded code. @@ -60,16 +64,19 @@ fn main() // bio_optional: Some("Software Developer"), // } -} +# } ```
The code above will be expanded to this ```rust -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -fn main() -{ +# #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +# fn main() {} + +# #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +# fn main() +# { // Use attribute debug to print expanded code. #[ derive( Debug, PartialEq ) ] @@ -452,7 +459,7 @@ fn main() // bio_optional: Some("Software Developer"), // } -} +# } ```
@@ -466,7 +473,11 @@ Try out `cargo run --example former_trivial`. With help of `Former`, it is possible to define multiple versions of a setter for a single field, providing the flexibility to include custom logic within the setter methods. This feature is particularly useful when you need to preprocess data or enforce specific constraints before assigning values to fields. Custom setters should have unique names to differentiate them from the default setters generated by `Former`, allowing for specialized behavior while maintaining clarity in your code. ```rust +# #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +# fn main() {} + # #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +# fn main() # { use former::Former; @@ -515,7 +526,11 @@ Try out `cargo run --example former_custom_setter`. But it's also possible to completely override setter and write its own from scratch. For that use attribe `[ setter( false ) ]` to disable setter. ```rust +# #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +# fn main() {} + # #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +# fn main() # { use former::Former; @@ -545,6 +560,7 @@ let example = StructWithCustomSetters::former() .word( "Hello" ) .form(); assert_eq!( example.word, "Hello!".to_string() ); + # } ``` @@ -559,7 +575,11 @@ Try out `cargo run --example former_custom_setter_overriden`. The `Former` crate enhances struct initialization by allowing the specification of custom default values for fields through the `default` attribute. This feature not only provides a way to set initial values for struct fields without relying on the `Default` trait but also adds flexibility in handling cases where a field's type does not implement `Default`, or a non-standard default value is desired. ```rust +# #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +# fn main() {} + # #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +# fn main() # { use former::Former; @@ -594,6 +614,7 @@ dbg!( &instance ); // > 30, // > ], // > } + # } ``` @@ -661,9 +682,13 @@ Define a custom former definition and custom forming logic, and apply them to a The example showcases how to accumulate elements into a container and then transform them into a single result using a custom `FormingEnd` implementation. This pattern is useful for scenarios where the formation process involves aggregation or transformation of input elements into a different type or form. ```rust -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -fn main() -{ +# #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] +# fn main() {} + +# #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +# fn main() +# { + // Define a struct `Sum` that will act as a custom former definition. struct Sum; @@ -721,7 +746,8 @@ fn main() dbg!(got); // Debug print the result to verify the output. // > got = 13 -} + +# } ``` ## Concept of subformer @@ -745,9 +771,12 @@ Each type of setter is designed to address different needs in the formation proc This example demonstrates how to employ the `Former` trait to configure a `Vec` using a container setter in a structured manner. ```rust -#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] -fn main() -{ +# #[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +# fn main() {} + +# #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +# fn main() +# { #[ derive( Debug, PartialEq, former::Former ) ] pub struct StructWithVec @@ -766,7 +795,7 @@ fn main() assert_eq!( instance, StructWithVec { vec: vec![ "apple", "banana" ] } ); dbg!( instance ); -} +# } ``` Try out `cargo run --example former_container_vector`. @@ -778,9 +807,12 @@ Try out `cargo run --example former_container_vector`. This example demonstrates how to effectively employ the `Former` trait to configure a `HashMap` using a container setter. ```rust -#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] -fn main() -{ +# #[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +# fn main() {} + +# #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +# fn main() +# { use collection_tools::{ HashMap, hmap }; #[ derive( Debug, PartialEq, former::Former ) ] @@ -800,7 +832,7 @@ fn main() assert_eq!( instance, StructWithMap { map : hmap!{ "a" => "b", "c" => "d" } } ); dbg!( instance ); -} +# } ``` Try out `cargo run --example former_container_hashmap`. @@ -812,8 +844,11 @@ Try out `cargo run --example former_container_hashmap`. This example demonstrates the use of the `Former` trait to build a `collection_tools::HashSet` through subforming. ```rust -#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] -fn main() +# #[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +# fn main() {} + +# #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +# fn main() { use collection_tools::{ HashSet, hset }; @@ -834,7 +869,7 @@ fn main() assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] }); dbg!( instance ); -} +# } ``` Try out `cargo run --example former_container_hashset`. @@ -848,9 +883,12 @@ This example demonstrates the implementation of a scalar setter using the `Forme The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. ```rust -#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] -fn main() -{ +# #[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +# fn main() {} + +# #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +# fn main() +# { use collection_tools::HashMap; use former::Former; @@ -910,7 +948,8 @@ fn main() // > }, // > }, // > } -} + +# } ``` In this example, the `Parent` struct functions as a container for multiple `Child` structs, each identified by a unique child name. The `ParentFormer` implements a custom method `child`, which serves as a subformer for adding `Child` instances into the `Parent`. @@ -930,10 +969,13 @@ This example demonstrates the use of container setters to manage complex nested The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. ```rust +# #[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +# fn main() {} + // Ensure the example only compiles when the appropriate features are enabled. -#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] -fn main() -{ +# #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +# fn main() +# { use collection_tools::HashMap; use former::Former; @@ -993,7 +1035,8 @@ fn main() // > }, // > }, // > } -} + +# } ``` Try out `cargo run --example former_custom_container_setter`. @@ -1007,11 +1050,13 @@ This example illustrates the implementation of nested builder patterns using the The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a container—each child entity in this case. ```rust +# #[ cfg( not( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ) ] +# fn main() {} -// Ensure the example only compiles when the appropriate features are enabled. -#[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] -fn main() -{ +# // Ensure the example only compiles when the appropriate features are enabled. +# #[ cfg( all( feature = "enabled", feature = "derive_former", not( feature = "no_std" ) ) ) ] +# fn main() +# { use collection_tools::HashMap; use former::Former; @@ -1085,7 +1130,7 @@ fn main() // > }, // > }, // > } -} +# } ``` Try out `cargo run --example former_custom_subform_setter`. @@ -1158,9 +1203,13 @@ allows for a richer and more flexible formation logic that can adapt based on th held within the storage. ```rust -#[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] -fn main() -{ +# #[ cfg( not( all( feature = "enabled", feature = "derive_former" ) ) ) ] +# fn main() {} + +# #[ cfg( all( feature = "derive_former", feature = "enabled" ) ) ] +# fn main() +# { + use former::Former; #[ derive( Debug, PartialEq, Former ) ] @@ -1197,7 +1246,7 @@ fn main() // > c: "13 - abc", // > } -} +# } ``` Try out `cargo run --example former_custom_mutator`. From c5e1d39238db2a7567696da00cb76d9abcca3cb1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 12 May 2024 00:26:36 +0300 Subject: [PATCH 529/533] former : cleaning --- module/core/former_meta/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/core/former_meta/src/lib.rs b/module/core/former_meta/src/lib.rs index 8d1a1f67e6..cf131eef6f 100644 --- a/module/core/former_meta/src/lib.rs +++ b/module/core/former_meta/src/lib.rs @@ -4,7 +4,7 @@ #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] #[ cfg( feature = "enabled" ) ] -#[ cfg( feature = "derive_component_from" ) ] +// #[ cfg( feature = "derive_component_from" ) ] mod component { From bc45eaf855c0f9927fcc024ce3b27d99f80184fa Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 12 May 2024 00:39:43 +0300 Subject: [PATCH 530/533] former : cleaning --- module/core/former/src/forming.rs | 6 ++++++ module/core/former/tests/inc/former_tests/a_basic.rs | 2 ++ module/core/former/tests/inc/former_tests/a_containers.rs | 2 ++ .../former/tests/inc/former_tests/a_containers_scalar.rs | 2 ++ module/core/former/tests/inc/former_tests/a_primitives.rs | 2 ++ .../core/former/tests/inc/former_tests/subformer_basic.rs | 1 + .../tests/inc/former_tests/subformer_container_custom.rs | 1 + .../tests/inc/former_tests/subformer_container_implicit.rs | 1 + .../tests/inc/former_tests/subformer_subform_named.rs | 1 + .../inc/former_tests/subformer_subform_named_manual.rs | 1 + module/core/former/tests/inc/mod.rs | 2 ++ 11 files changed, 21 insertions(+) diff --git a/module/core/former/src/forming.rs b/module/core/former/src/forming.rs index d4c6ae3331..892f4ad526 100644 --- a/module/core/former/src/forming.rs +++ b/module/core/former/src/forming.rs @@ -150,6 +150,12 @@ where } } +#[ allow( unused_extern_crates ) ] +#[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ] +extern crate alloc; +#[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ] +use alloc::boxed::Box; + /// A wrapper around a closure to be used as a `FormingEnd`. /// /// This struct allows for dynamic dispatch of a closure that matches the diff --git a/module/core/former/tests/inc/former_tests/a_basic.rs b/module/core/former/tests/inc/former_tests/a_basic.rs index 04ef5312c9..a3f7e74e5f 100644 --- a/module/core/former/tests/inc/former_tests/a_basic.rs +++ b/module/core/former/tests/inc/former_tests/a_basic.rs @@ -1,3 +1,5 @@ +#![ deny( missing_docs ) ] + #[ allow( unused_imports ) ] use super::*; diff --git a/module/core/former/tests/inc/former_tests/a_containers.rs b/module/core/former/tests/inc/former_tests/a_containers.rs index a9eaa315fa..c2466841bf 100644 --- a/module/core/former/tests/inc/former_tests/a_containers.rs +++ b/module/core/former/tests/inc/former_tests/a_containers.rs @@ -1,3 +1,5 @@ +#![ deny( missing_docs ) ] + #[ allow( unused_imports ) ] use super::*; diff --git a/module/core/former/tests/inc/former_tests/a_containers_scalar.rs b/module/core/former/tests/inc/former_tests/a_containers_scalar.rs index b87ae9a9e1..4b3efafb88 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_scalar.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_scalar.rs @@ -1,3 +1,5 @@ +#![ deny( missing_docs ) ] + #[ allow( unused_imports ) ] use super::*; diff --git a/module/core/former/tests/inc/former_tests/a_primitives.rs b/module/core/former/tests/inc/former_tests/a_primitives.rs index 446b7c98d8..658420597c 100644 --- a/module/core/former/tests/inc/former_tests/a_primitives.rs +++ b/module/core/former/tests/inc/former_tests/a_primitives.rs @@ -1,3 +1,5 @@ +#![ deny( missing_docs ) ] + #[ allow( unused_imports ) ] use super::*; diff --git a/module/core/former/tests/inc/former_tests/subformer_basic.rs b/module/core/former/tests/inc/former_tests/subformer_basic.rs index f81bbda527..11f5a65779 100644 --- a/module/core/former/tests/inc/former_tests/subformer_basic.rs +++ b/module/core/former/tests/inc/former_tests/subformer_basic.rs @@ -1,3 +1,4 @@ +#![ deny( missing_docs ) ] #![ allow( dead_code ) ] use super::*; diff --git a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs index 0c9bca8827..58f3a72356 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_custom.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_custom.rs @@ -1,3 +1,4 @@ +#![ deny( missing_docs ) ] #![ allow( dead_code ) ] use super::*; diff --git a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs index b332563d53..55b91e69de 100644 --- a/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs +++ b/module/core/former/tests/inc/former_tests/subformer_container_implicit.rs @@ -1,3 +1,4 @@ +#![ deny( missing_docs ) ] #![ allow( dead_code ) ] use super::*; diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs index 89370b9881..e834e8b30d 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named.rs @@ -1,3 +1,4 @@ +#![ deny( missing_docs ) ] #![ allow( dead_code ) ] use super::*; diff --git a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs index fa6e91d223..c169a74d79 100644 --- a/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs +++ b/module/core/former/tests/inc/former_tests/subformer_subform_named_manual.rs @@ -1,3 +1,4 @@ +#![ deny( missing_docs ) ] #![ allow( dead_code ) ] use super::*; diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index a3de17fa64..2cb4dab571 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -1,3 +1,5 @@ +// #![ deny( missing_docs ) ] + #[ allow( unused_imports ) ] use super::*; From dea8bdff99d356b251e0c503d8f4257e240dbfb0 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 12 May 2024 00:47:53 +0300 Subject: [PATCH 531/533] former : cleaning --- .../inc/former_tests/a_containers_manual.rs | 18 ++++++++++++------ module/move/wca/src/ca/grammar/command.rs | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/module/core/former/tests/inc/former_tests/a_containers_manual.rs b/module/core/former/tests/inc/former_tests/a_containers_manual.rs index b25115678e..eed2cbfa9a 100644 --- a/module/core/former/tests/inc/former_tests/a_containers_manual.rs +++ b/module/core/former/tests/inc/former_tests/a_containers_manual.rs @@ -347,7 +347,8 @@ where >, former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End< Definition > > : former::FormerDefinition < - Storage : former::ContainerAdd< Entry = < collection_tools::Vec< String > as former::Container >::Entry >, + // Storage : former::ContainerAdd< Entry = < collection_tools::Vec< String > as former::Container >::Entry >, + Storage = Vec< String >, Context = Struct1Former< Definition >, End = Struct1FormerAssignVec1End< Definition >, >, @@ -368,7 +369,8 @@ where where former::VectorDefinition< String, Self, Self, Struct1FormerAssignVec1End< Definition > > : former::FormerDefinition < - Storage : former::ContainerAdd< Entry = < collection_tools::Vec< String > as former::Container >::Entry >, + // Storage : former::ContainerAdd< Entry = < collection_tools::Vec< String > as former::Container >::Entry >, + Storage = Vec< String >, Context = Struct1Former< Definition >, End = Struct1FormerAssignVec1End< Definition >, >, @@ -393,7 +395,8 @@ where >, former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End< Definition > > : former::FormerDefinition < - Storage : former::ContainerAdd< Entry = < collection_tools::HashMap< String, String > as former::Container >::Entry >, + // Storage : former::ContainerAdd< Entry = < collection_tools::HashMap< String, String > as former::Container >::Entry >, + Storage = collection_tools::HashMap< String, String >, Context = Struct1Former< Definition >, End = Struct1FormerAssignHashmap1End< Definition >, >, @@ -414,7 +417,8 @@ where where former::HashMapDefinition< String, String, Self, Self, Struct1FormerAssignHashmap1End< Definition > > : former::FormerDefinition < - Storage : former::ContainerAdd< Entry = < collection_tools::HashMap< String, String > as former::Container >::Entry >, + // Storage : former::ContainerAdd< Entry = < collection_tools::HashMap< String, String > as former::Container >::Entry >, + Storage = collection_tools::HashMap< String, String >, Context = Struct1Former< Definition >, End = Struct1FormerAssignHashmap1End< Definition >, >, @@ -439,7 +443,8 @@ where >, former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > > : former::FormerDefinition < - Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, + // Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, + Storage = collection_tools::HashSet< String >, Context = Struct1Former< Definition >, End = Struct1FormerAssignHashset1End< Definition >, >, @@ -460,7 +465,8 @@ where where former::HashSetDefinition< String, Self, Self, Struct1FormerAssignHashset1End< Definition > > : former::FormerDefinition < - Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, + // Storage : former::ContainerAdd< Entry = < collection_tools::HashSet< String > as former::Container >::Entry >, + Storage = collection_tools::HashSet< String >, Context = Struct1Former< Definition >, End = Struct1FormerAssignHashset1End< Definition >, >, diff --git a/module/move/wca/src/ca/grammar/command.rs b/module/move/wca/src/ca/grammar/command.rs index 93648eda09..e5427f7b50 100644 --- a/module/move/wca/src/ca/grammar/command.rs +++ b/module/move/wca/src/ca/grammar/command.rs @@ -5,7 +5,7 @@ pub( crate ) mod private use { Handler, Routine, Type }; use std::collections::HashMap; - use former::{ Former, StoragePreform }; + use former::Former; /// A description of a Value in a command. Used to specify the expected type and provide a hint for the Value. /// From 57f9f994a4ce4091773e6b30ed0ac726174d1047 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 12 May 2024 00:48:24 +0300 Subject: [PATCH 532/533] former : cleaning --- module/move/wca/src/ca/grammar/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/move/wca/src/ca/grammar/command.rs b/module/move/wca/src/ca/grammar/command.rs index e5427f7b50..93648eda09 100644 --- a/module/move/wca/src/ca/grammar/command.rs +++ b/module/move/wca/src/ca/grammar/command.rs @@ -5,7 +5,7 @@ pub( crate ) mod private use { Handler, Routine, Type }; use std::collections::HashMap; - use former::Former; + use former::{ Former, StoragePreform }; /// A description of a Value in a command. Used to specify the expected type and provide a hint for the Value. /// From 21829bb4e80a1ef02d48c6b4951ee943b7aa526c Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 12 May 2024 01:15:29 +0300 Subject: [PATCH 533/533] former : cleaning --- module/core/former_meta/src/derive_former.rs | 1 + .../core/former_meta/src/derive_former/field.rs | 17 ++++++++++++++++- module/move/wca/src/ca/aggregator.rs | 3 ++- module/move/wca/src/ca/grammar/command.rs | 5 +++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/module/core/former_meta/src/derive_former.rs b/module/core/former_meta/src/derive_former.rs index dac0eb6e8a..92beeefef0 100644 --- a/module/core/former_meta/src/derive_former.rs +++ b/module/core/former_meta/src/derive_former.rs @@ -655,6 +655,7 @@ specific needs of the broader forming context. It mandates the implementation of #former_generics_where { + /// Executes the transformation from the former's storage state to the preformed object as specified by the definition. pub fn preform( self ) -> < Definition::Types as former::FormerDefinitionTypes >::Formed { former::StoragePreform::preform( self.storage ) diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index cba88da221..a38cdead95 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -488,10 +488,26 @@ allowing for dynamic and flexible construction of the `{stru}` entity's {field_i let setters_code = if attr.setter() { + + let doc = format! + ( + r#" +Provides a user-friendly interface to add an instancce of {field_ident} to the {stru}. + +# Returns + +Returns an instance of `Former2`, a subformer ready to begin the formation process for `{0}` entities, +allowing for dynamic and flexible construction of the `{stru}` entity's {field_ident}. + + "#, + format!( "{}", qt!{ #field_typ } ), + ); + qt! { #setters_code + #[ doc = #doc ] #[ inline( always ) ] pub fn #setter_name( self ) -> < < #field_typ as former::Container >::Val as former::EntityToFormer @@ -908,7 +924,6 @@ with the new content generated during the subforming process. } else { - qt! { < diff --git a/module/move/wca/src/ca/aggregator.rs b/module/move/wca/src/ca/aggregator.rs index 197c1ff6e4..1174de448f 100644 --- a/module/move/wca/src/ca/aggregator.rs +++ b/module/move/wca/src/ca/aggregator.rs @@ -102,6 +102,7 @@ pub( crate ) mod private #[ derive( former::Former ) ] #[ storage_fields( help_generator : HelpGeneratorFn, help_variants : HashSet< HelpVariants > ) ] #[ mutator( custom = true ) ] + // #[ debug ] pub struct CommandsAggregator { #[ former( default = Dictionary::default() ) ] @@ -119,7 +120,7 @@ pub( crate ) mod private callback_fn : Option< CommandsAggregatorCallback >, } - + impl< Context, Formed > former::FormerMutator for CommandsAggregatorFormerDefinitionTypes< Context, Formed > { fn form_mutation( storage : &mut Self::Storage, _context : &mut Option< Self::Context > ) diff --git a/module/move/wca/src/ca/grammar/command.rs b/module/move/wca/src/ca/grammar/command.rs index 93648eda09..2f12e03921 100644 --- a/module/move/wca/src/ca/grammar/command.rs +++ b/module/move/wca/src/ca/grammar/command.rs @@ -44,7 +44,7 @@ pub( crate ) mod private /// subject optional parameter #[ former( default = false ) ] optional : bool, - #[ scalar( setter = false, hint = false ) ] + #[ scalar( setter = false ) ] #[ former( default = Vec::new() ) ] properties_aliases : Vec< String >, } @@ -86,6 +86,7 @@ pub( crate ) mod private #[ derive( Debug, Clone, PartialEq, Eq ) ] #[ derive( Former ) ] + // #[ debug ] pub struct Command { /// Command common hint. @@ -106,7 +107,7 @@ pub( crate ) mod private // aaa : here it is // qqq : make it usable and remove default(?) /// The type `Routine` represents the specific implementation of the routine. - #[ scalar( setter = false, hint = false ) ] + #[ scalar( setter = false ) ] #[ former( default = Routine::from( Handler::from( || { panic!( "No routine available: A handler function for the command is missing" ) } ) ) ) ] pub routine : Routine, }