From 559afd224e98803755a2cec2c94a23fdc1e4cf38 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 23 Mar 2024 12:01:59 +0200 Subject: [PATCH] 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 // {