From 5dc2a1804e291ea582c2d1c958c96f6a255b02a9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:18:06 +0300 Subject: [PATCH 01/17] former : for enum, wip --- .../standalone_constructor_args_manual.rs | 11 +++-- module/core/former/tests/inc/mod.rs | 43 ------------------- 2 files changed, 7 insertions(+), 47 deletions(-) diff --git a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_manual.rs b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_manual.rs index a5defb6766..5960c14a01 100644 --- a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_manual.rs +++ b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_manual.rs @@ -4,7 +4,9 @@ //! Uses distinct names to avoid conflicts with zero-arg tests. //! +#[ allow( unused_imports ) ] use ::former::prelude::*; +#[ allow( unused_imports ) ] use ::former_types:: { Storage, StoragePreform, @@ -140,7 +142,7 @@ where } #[ inline( always ) ] - #[ allow( dead_code) ] + #[allow(dead_code)] pub fn new( on_end : Definition::End ) -> Self { Self::begin( None, None, on_end ) @@ -150,7 +152,7 @@ where #[ inline ] pub fn _0( mut self, src : impl Into< i32 > ) -> Self { - // debug_assert!( self.storage._0.is_none(), "Field '_0' was already set" ); // <<< Removed assert + // debug_assert!( self.storage._0.is_none(), "Field '_0' was already set" ); self.storage._0 = Some( src.into() ); self } @@ -288,7 +290,7 @@ where } #[ inline( always ) ] - #[ allow( dead_code) ] + #[allow(dead_code)] pub fn new( on_end : Definition::End ) -> Self { Self::begin( None, None, on_end ) @@ -296,9 +298,10 @@ where /// Setter for the struct field. #[ inline ] + #[allow(dead_code)] // <<< Added allow(dead_code) pub fn field( mut self, src : impl Into< String > ) -> Self { - // debug_assert!( self.storage.field.is_none(), "Field 'field' was already set" ); // <<< Removed assert + // debug_assert!( self.storage.field.is_none(), "Field 'field' was already set" ); self.storage.field = Some( src.into() ); self } diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index d6f5dee223..156d620b1c 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -273,49 +273,6 @@ mod former_enum_tests } -#[ cfg( feature = "derive_former" ) ] -mod former_enum_tests -{ - use super::*; - - // = enum - - // xxx : qqq : enable or remove - mod usecase1; - - mod basic_manual; - mod basic_derive; - mod multi_field_manual; - mod multi_field_derive; - mod unit_variant_manual; - mod unit_variant_derive; - mod enum_named_fields_manual; - mod enum_named_fields_derive; - - // = generics - - mod generics_in_tuple_variant_manual; - mod generics_in_tuple_variant_derive; - mod generics_shared_tuple_manual; - mod generics_shared_tuple_derive; - mod generics_shared_struct_manual; - mod generics_shared_struct_derive; - - mod generics_independent_tuple_manual; - mod generics_independent_tuple_derive; - mod generics_independent_struct_manual; - mod generics_independent_struct_derive; - - mod scalar_generic_tuple_manual; - mod scalar_generic_tuple_derive; - - // = conflicts - - mod keyword_variant_derive; - -} - - #[ cfg( feature = "derive_components" ) ] mod components_tests { From c233dd47b29c29a1e9d07f321390bae4a9a553c7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:23:58 +0300 Subject: [PATCH 02/17] clone_dyn_types-v0.31.0 --- Cargo.toml | 2 +- module/core/clone_dyn_types/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1ec080455a..a523ac5c18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -183,7 +183,7 @@ path = "module/core/clone_dyn_meta" # features = [ "enabled" ] [workspace.dependencies.clone_dyn_types] -version = "~0.30.0" +version = "~0.31.0" path = "module/core/clone_dyn_types" default-features = false # features = [ "enabled" ] diff --git a/module/core/clone_dyn_types/Cargo.toml b/module/core/clone_dyn_types/Cargo.toml index 9992acae46..6734d7e5c9 100644 --- a/module/core/clone_dyn_types/Cargo.toml +++ b/module/core/clone_dyn_types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clone_dyn_types" -version = "0.30.0" +version = "0.31.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 4c4dfb07875717df1b27b9a7b21c492f1d8bb0c7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:24:08 +0300 Subject: [PATCH 03/17] iter_tools-v0.29.0 --- Cargo.toml | 2 +- module/core/iter_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a523ac5c18..0f2d548ef7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -208,7 +208,7 @@ default-features = false ## iter [workspace.dependencies.iter_tools] -version = "~0.28.0" +version = "~0.29.0" path = "module/core/iter_tools" default-features = false diff --git a/module/core/iter_tools/Cargo.toml b/module/core/iter_tools/Cargo.toml index be262d50c1..442572a8a5 100644 --- a/module/core/iter_tools/Cargo.toml +++ b/module/core/iter_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iter_tools" -version = "0.28.0" +version = "0.29.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From e83ced6c0bd57dfd5d912eb2fbdb17c02a538ad4 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:24:26 +0300 Subject: [PATCH 04/17] macro_tools-v0.53.0 --- Cargo.toml | 2 +- module/core/macro_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0f2d548ef7..c76ca022c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -296,7 +296,7 @@ default-features = false ## macro tools [workspace.dependencies.macro_tools] -version = "~0.52.0" +version = "~0.53.0" path = "module/core/macro_tools" default-features = false diff --git a/module/core/macro_tools/Cargo.toml b/module/core/macro_tools/Cargo.toml index d26ea79c59..25f110709b 100644 --- a/module/core/macro_tools/Cargo.toml +++ b/module/core/macro_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "macro_tools" -version = "0.52.0" +version = "0.53.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From f8c1bf9f6367f740063cd623a27e059d2f51605c Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:24:51 +0300 Subject: [PATCH 05/17] derive_tools_meta-v0.34.0 --- Cargo.toml | 2 +- module/core/derive_tools_meta/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c76ca022c2..26354663d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -124,7 +124,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.derive_tools_meta] -version = "~0.33.0" +version = "~0.34.0" path = "module/core/derive_tools_meta" default-features = false # features = [ "enabled" ] diff --git a/module/core/derive_tools_meta/Cargo.toml b/module/core/derive_tools_meta/Cargo.toml index 82a2749d44..dda38632f7 100644 --- a/module/core/derive_tools_meta/Cargo.toml +++ b/module/core/derive_tools_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "derive_tools_meta" -version = "0.33.0" +version = "0.34.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 7c845e6265f4508e9781634c7d1a75750b1baed1 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:25:07 +0300 Subject: [PATCH 06/17] variadic_from-v0.30.0 --- Cargo.toml | 2 +- module/core/variadic_from/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 26354663d9..5fccd19a94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -166,7 +166,7 @@ path = "module/alias/fundamental_data_type" default-features = false [workspace.dependencies.variadic_from] -version = "~0.29.0" +version = "~0.30.0" path = "module/core/variadic_from" default-features = false # features = [ "enabled" ] diff --git a/module/core/variadic_from/Cargo.toml b/module/core/variadic_from/Cargo.toml index e1746d2494..64d9bf0c36 100644 --- a/module/core/variadic_from/Cargo.toml +++ b/module/core/variadic_from/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "variadic_from" -version = "0.29.0" +version = "0.30.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 7583450d2dbbe11ed91204ac00562bfb94b92d93 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:25:18 +0300 Subject: [PATCH 07/17] clone_dyn_meta-v0.30.0 --- Cargo.toml | 2 +- module/core/clone_dyn_meta/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5fccd19a94..560f70b9e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -178,7 +178,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.clone_dyn_meta] -version = "~0.29.0" +version = "~0.30.0" path = "module/core/clone_dyn_meta" # features = [ "enabled" ] diff --git a/module/core/clone_dyn_meta/Cargo.toml b/module/core/clone_dyn_meta/Cargo.toml index a6e215f343..3bce911a14 100644 --- a/module/core/clone_dyn_meta/Cargo.toml +++ b/module/core/clone_dyn_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clone_dyn_meta" -version = "0.29.0" +version = "0.30.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 69ac6344e22eb4a4bb89b76d894fe69dc23feac3 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:25:29 +0300 Subject: [PATCH 08/17] clone_dyn-v0.32.0 --- Cargo.toml | 2 +- module/core/clone_dyn/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 560f70b9e4..ffc390c3ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -172,7 +172,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.clone_dyn] -version = "~0.31.0" +version = "~0.32.0" path = "module/core/clone_dyn" default-features = false # features = [ "enabled" ] diff --git a/module/core/clone_dyn/Cargo.toml b/module/core/clone_dyn/Cargo.toml index 49c4362a39..18b1b5e373 100644 --- a/module/core/clone_dyn/Cargo.toml +++ b/module/core/clone_dyn/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clone_dyn" -version = "0.31.0" +version = "0.32.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From ac23b2e4e812caaef5a1aaaae5ec9a9074d8b3eb Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:25:50 +0300 Subject: [PATCH 09/17] derive_tools-v0.35.0 --- Cargo.toml | 2 +- module/core/derive_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ffc390c3ac..7bfd1c640c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,7 +118,7 @@ default-features = false ## derive [workspace.dependencies.derive_tools] -version = "~0.34.0" +version = "~0.35.0" path = "module/core/derive_tools" default-features = false # features = [ "enabled" ] diff --git a/module/core/derive_tools/Cargo.toml b/module/core/derive_tools/Cargo.toml index 1025bffeb1..bc4be998b8 100644 --- a/module/core/derive_tools/Cargo.toml +++ b/module/core/derive_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "derive_tools" -version = "0.34.0" +version = "0.35.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 4e05e8de927da24b5da40d2f3075aaf1c0ff1d3e Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:26:10 +0300 Subject: [PATCH 10/17] reflect_tools_meta-v0.6.0 --- Cargo.toml | 2 +- module/core/reflect_tools_meta/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7bfd1c640c..9684261d51 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,7 +136,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.reflect_tools_meta] -version = "~0.5.0" +version = "~0.6.0" path = "module/core/reflect_tools_meta" default-features = false # features = [ "enabled" ] diff --git a/module/core/reflect_tools_meta/Cargo.toml b/module/core/reflect_tools_meta/Cargo.toml index 8538a62817..cfbfa009de 100644 --- a/module/core/reflect_tools_meta/Cargo.toml +++ b/module/core/reflect_tools_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reflect_tools_meta" -version = "0.5.0" +version = "0.6.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From c9c7dd0ded7d655800a40e3c5734b6dfa9596197 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:26:22 +0300 Subject: [PATCH 11/17] reflect_tools-v0.6.0 --- Cargo.toml | 2 +- module/core/reflect_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9684261d51..04318b293a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -130,7 +130,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.reflect_tools] -version = "~0.5.0" +version = "~0.6.0" path = "module/core/reflect_tools" default-features = false # features = [ "enabled" ] diff --git a/module/core/reflect_tools/Cargo.toml b/module/core/reflect_tools/Cargo.toml index b4af9b6b5d..a496466509 100644 --- a/module/core/reflect_tools/Cargo.toml +++ b/module/core/reflect_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reflect_tools" -version = "0.5.0" +version = "0.6.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From c82b2f6d5c7d74a475860392ba1633cd4a25e2cb Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:26:36 +0300 Subject: [PATCH 12/17] former_meta-v2.16.0 --- Cargo.toml | 2 +- module/core/former_meta/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 04318b293a..d19825f392 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -231,7 +231,7 @@ path = "module/core/former" default-features = false [workspace.dependencies.former_meta] -version = "~2.15.0" +version = "~2.16.0" path = "module/core/former_meta" default-features = false diff --git a/module/core/former_meta/Cargo.toml b/module/core/former_meta/Cargo.toml index 4713ff50ac..0c7a9aae27 100644 --- a/module/core/former_meta/Cargo.toml +++ b/module/core/former_meta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former_meta" -version = "2.15.0" +version = "2.16.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From a93a7ce288579b6bf7f4ab75243b2c97f29cd565 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:26:54 +0300 Subject: [PATCH 13/17] former-v2.17.0 --- Cargo.toml | 2 +- module/core/former/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d19825f392..a4ae8613c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -226,7 +226,7 @@ path = "module/core/for_each" default-features = false [workspace.dependencies.former] -version = "~2.16.0" +version = "~2.17.0" path = "module/core/former" default-features = false diff --git a/module/core/former/Cargo.toml b/module/core/former/Cargo.toml index 2dadab4cce..61b616c264 100644 --- a/module/core/former/Cargo.toml +++ b/module/core/former/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former" -version = "2.16.0" +version = "2.17.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 4766295fdba1cd78d150e13942aaf351ede515de Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 00:27:14 +0300 Subject: [PATCH 14/17] format_tools-v0.5.0 --- Cargo.toml | 2 +- module/core/format_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a4ae8613c7..8b9862db60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -142,7 +142,7 @@ default-features = false # features = [ "enabled" ] [workspace.dependencies.format_tools] -version = "~0.4.0" +version = "~0.5.0" path = "module/core/format_tools" default-features = false # features = [ "enabled" ] diff --git a/module/core/format_tools/Cargo.toml b/module/core/format_tools/Cargo.toml index 91a431d192..b581ce66ed 100644 --- a/module/core/format_tools/Cargo.toml +++ b/module/core/format_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "format_tools" -version = "0.4.0" +version = "0.5.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From d3b99dd5b86045d25bc87740b05f19f5553545e8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 01:06:46 +0300 Subject: [PATCH 15/17] former : for enum --- .../standalone_constructor_args_derive.rs | 18 + .../standalone_constructor_args_manual.rs | 349 +++++++++++++++++- .../standalone_constructor_args_only_test.rs | 63 ++-- 3 files changed, 388 insertions(+), 42 deletions(-) diff --git a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs index 86907f01e2..ede8d321f8 100644 --- a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs +++ b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs @@ -29,6 +29,24 @@ pub enum TestEnumArgs // Use the distinct name #[ arg_for_constructor ] // Mark field as constructor arg field : String, }, + /// A tuple variant with multiple fields marked as constructor args. + #[ scalar ] // <<< Keep scalar attribute + MultiTupleArgs // Use the distinct name + ( + // #[ arg_for_constructor ] // <<< REMOVED + i32, + // #[ arg_for_constructor ] // <<< REMOVED + bool, + ), + /// A struct variant with multiple fields marked as constructor args. + // #[ scalar ] // <<< Keep scalar attribute + MultiStructArgs // Use the distinct name + { + #[ arg_for_constructor ] + a : i32, + #[ arg_for_constructor ] + b : bool, + }, } // === Include Test Logic === diff --git a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_manual.rs b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_manual.rs index 5960c14a01..aef29713ce 100644 --- a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_manual.rs +++ b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_manual.rs @@ -29,6 +29,14 @@ pub enum TestEnumArgs // New name { field : String, }, + /// A tuple variant with multiple fields (intended as constructor args). + MultiTupleArgs( i32, bool ), // <<< New Variant + /// A struct variant with multiple fields (intended as constructor args). + MultiStructArgs // <<< New Variant + { + a : i32, + b : bool, + }, } // === Manual Former Implementation for TupleVariantArgs === @@ -83,7 +91,8 @@ for TestEnumArgsTupleVariantArgsFormerDefinitionTypes< Context, Formed > // Definition /// Definition for TestEnumArgsTupleVariantArgsFormer. #[ derive( Debug, Default ) ] -pub struct TestEnumArgsTupleVariantArgsFormerDefinition< Context = (), Formed = TestEnumArgs, End = TestEnumArgsTupleVariantArgsEnd > +pub struct TestEnumArgsTupleVariantArgsFormerDefinition +< Context = (), Formed = TestEnumArgs, End = TestEnumArgsTupleVariantArgsEnd > { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } @@ -103,7 +112,8 @@ where // Former /// Manual Former implementation for TestEnumArgs::TupleVariantArgs. #[ derive( Debug ) ] -pub struct TestEnumArgsTupleVariantArgsFormer< Definition = TestEnumArgsTupleVariantArgsFormerDefinition > +pub struct TestEnumArgsTupleVariantArgsFormer +< Definition = TestEnumArgsTupleVariantArgsFormerDefinition > where Definition : FormerDefinition< Storage = TestEnumArgsTupleVariantArgsFormerStorage >, { @@ -119,7 +129,10 @@ where Definition::Types : FormerMutator, { #[ inline( always ) ] - pub fn form( self ) -> < Definition::Types as FormerDefinitionTypes >::Formed { self.end() } + pub fn form( self ) -> < Definition::Types as FormerDefinitionTypes >::Formed + { + self.end() + } #[ inline( always ) ] pub fn end( mut self ) -> < Definition::Types as FormerDefinitionTypes >::Formed @@ -231,7 +244,8 @@ for TestEnumArgsStructVariantArgsFormerDefinitionTypes< Context, Formed > // Definition /// Definition for TestEnumArgsStructVariantArgsFormer. #[ derive( Debug, Default ) ] -pub struct TestEnumArgsStructVariantArgsFormerDefinition< Context = (), Formed = TestEnumArgs, End = TestEnumArgsStructVariantArgsEnd > +pub struct TestEnumArgsStructVariantArgsFormerDefinition +< Context = (), Formed = TestEnumArgs, End = TestEnumArgsStructVariantArgsEnd > { _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, } @@ -251,7 +265,8 @@ where // Former /// Manual Former implementation for TestEnumArgs::StructVariantArgs. #[ derive( Debug ) ] -pub struct TestEnumArgsStructVariantArgsFormer< Definition = TestEnumArgsStructVariantArgsFormerDefinition > +pub struct TestEnumArgsStructVariantArgsFormer +< Definition = TestEnumArgsStructVariantArgsFormerDefinition > where Definition : FormerDefinition< Storage = TestEnumArgsStructVariantArgsFormerStorage >, { @@ -267,7 +282,10 @@ where Definition::Types : FormerMutator, { #[ inline( always ) ] - pub fn form( self ) -> < Definition::Types as FormerDefinitionTypes >::Formed { self.end() } + pub fn form( self ) -> < Definition::Types as FormerDefinitionTypes >::Formed + { + self.end() + } #[ inline( always ) ] pub fn end( mut self ) -> < Definition::Types as FormerDefinitionTypes >::Formed @@ -298,7 +316,7 @@ where /// Setter for the struct field. #[ inline ] - #[allow(dead_code)] // <<< Added allow(dead_code) + #[allow(dead_code)] pub fn field( mut self, src : impl Into< String > ) -> Self { // debug_assert!( self.storage.field.is_none(), "Field 'field' was already set" ); @@ -329,6 +347,280 @@ for TestEnumArgsStructVariantArgsEnd } +// === Manual Former Implementation for MultiTupleArgs === <<< NEW >>> + +// Storage +#[ derive( Debug, Default ) ] +pub struct TestEnumArgsMultiTupleArgsFormerStorage +{ + pub _0 : ::core::option::Option< i32 >, + pub _1 : ::core::option::Option< bool >, +} +impl Storage for TestEnumArgsMultiTupleArgsFormerStorage +{ + type Preformed = ( i32, bool ); +} +impl StoragePreform for TestEnumArgsMultiTupleArgsFormerStorage +{ + #[ inline( always ) ] + fn preform( mut self ) -> Self::Preformed + { + ( self._0.take().unwrap_or_default(), self._1.take().unwrap_or_default() ) + } +} +// Definition Types +#[ derive( Debug, Default ) ] +pub struct TestEnumArgsMultiTupleArgsFormerDefinitionTypes +< Context = (), Formed = TestEnumArgs > +{ + _phantom : core::marker::PhantomData< ( Context, Formed ) >, +} +impl< Context, Formed > FormerDefinitionTypes +for TestEnumArgsMultiTupleArgsFormerDefinitionTypes< Context, Formed > +{ + type Storage = TestEnumArgsMultiTupleArgsFormerStorage; + type Formed = Formed; + type Context = Context; +} +impl< Context, Formed > FormerMutator +for TestEnumArgsMultiTupleArgsFormerDefinitionTypes< Context, Formed > +{ +} +// Definition +#[ derive( Debug, Default ) ] +pub struct TestEnumArgsMultiTupleArgsFormerDefinition +< Context = (), Formed = TestEnumArgs, End = TestEnumArgsMultiTupleArgsEnd > +{ + _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, +} +impl< Context, Formed, End > FormerDefinition +for TestEnumArgsMultiTupleArgsFormerDefinition< Context, Formed, End > +where + End : FormingEnd< TestEnumArgsMultiTupleArgsFormerDefinitionTypes< Context, Formed > >, +{ + type Storage = TestEnumArgsMultiTupleArgsFormerStorage; + type Formed = Formed; + type Context = Context; + type Types = TestEnumArgsMultiTupleArgsFormerDefinitionTypes< Context, Formed >; + type End = End; +} +// Former +#[ derive( Debug ) ] +pub struct TestEnumArgsMultiTupleArgsFormer +< Definition = TestEnumArgsMultiTupleArgsFormerDefinition > +where + Definition : FormerDefinition< Storage = TestEnumArgsMultiTupleArgsFormerStorage >, +{ + storage : Definition::Storage, + context : Option< Definition::Context >, + on_end : Option< Definition::End >, +} +impl< Definition > TestEnumArgsMultiTupleArgsFormer< Definition > +where + Definition : FormerDefinition< Storage = TestEnumArgsMultiTupleArgsFormerStorage >, + Definition::Types : FormerDefinitionTypes< Storage = TestEnumArgsMultiTupleArgsFormerStorage >, + Definition::Types : FormerMutator, +{ + #[ inline( always ) ] + pub fn form( self ) -> < Definition::Types as FormerDefinitionTypes >::Formed + { + self.end() + } + #[ inline( always ) ] + pub fn end( mut self ) -> < Definition::Types as FormerDefinitionTypes >::Formed + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + < Definition::Types as FormerMutator >::form_mutation( &mut self.storage, &mut self.context ); + on_end.call( self.storage, context ) + } + #[ inline( always ) ] + pub fn begin + ( + storage : Option< Definition::Storage >, + context : Option< Definition::Context >, + on_end : Definition::End, + ) -> Self + { + Self { storage : storage.unwrap_or_default(), context, on_end : Some( on_end ) } + } + #[ inline( always ) ] + #[allow(dead_code)] + pub fn new( on_end : Definition::End ) -> Self + { + Self::begin( None, None, on_end ) + } + #[ inline ] + pub fn _0( mut self, src : impl Into< i32 > ) -> Self + { + self.storage._0 = Some( src.into() ); + self + } + #[ inline ] + pub fn _1( mut self, src : impl Into< bool > ) -> Self + { + self.storage._1 = Some( src.into() ); + self + } +} +// End Struct +#[ derive( Debug, Default ) ] +pub struct TestEnumArgsMultiTupleArgsEnd; +impl FormingEnd< TestEnumArgsMultiTupleArgsFormerDefinitionTypes< (), TestEnumArgs > > +for TestEnumArgsMultiTupleArgsEnd +{ + #[ inline( always ) ] + fn call + ( + &self, + storage : TestEnumArgsMultiTupleArgsFormerStorage, + _context : Option< () >, + ) -> TestEnumArgs + { + let ( val0, val1 ) = storage.preform(); + TestEnumArgs::MultiTupleArgs( val0, val1 ) + } +} + + +// === Manual Former Implementation for MultiStructArgs === <<< NEW >>> + +// Storage +#[ derive( Debug, Default ) ] +pub struct TestEnumArgsMultiStructArgsFormerStorage +{ + pub a : ::core::option::Option< i32 >, + pub b : ::core::option::Option< bool >, +} +impl Storage for TestEnumArgsMultiStructArgsFormerStorage +{ + type Preformed = ( i32, bool ); +} +impl StoragePreform for TestEnumArgsMultiStructArgsFormerStorage +{ + #[ inline( always ) ] + fn preform( mut self ) -> Self::Preformed + { + ( self.a.take().unwrap_or_default(), self.b.take().unwrap_or_default() ) + } +} +// Definition Types +#[ derive( Debug, Default ) ] +pub struct TestEnumArgsMultiStructArgsFormerDefinitionTypes +< Context = (), Formed = TestEnumArgs > +{ + _phantom : core::marker::PhantomData< ( Context, Formed ) >, +} +impl< Context, Formed > FormerDefinitionTypes +for TestEnumArgsMultiStructArgsFormerDefinitionTypes< Context, Formed > +{ + type Storage = TestEnumArgsMultiStructArgsFormerStorage; + type Formed = Formed; + type Context = Context; +} +impl< Context, Formed > FormerMutator +for TestEnumArgsMultiStructArgsFormerDefinitionTypes< Context, Formed > +{ +} +// Definition +#[ derive( Debug, Default ) ] +pub struct TestEnumArgsMultiStructArgsFormerDefinition +< Context = (), Formed = TestEnumArgs, End = TestEnumArgsMultiStructArgsEnd > +{ + _phantom : core::marker::PhantomData< ( Context, Formed, End ) >, +} +impl< Context, Formed, End > FormerDefinition +for TestEnumArgsMultiStructArgsFormerDefinition< Context, Formed, End > +where + End : FormingEnd< TestEnumArgsMultiStructArgsFormerDefinitionTypes< Context, Formed > >, +{ + type Storage = TestEnumArgsMultiStructArgsFormerStorage; + type Formed = Formed; + type Context = Context; + type Types = TestEnumArgsMultiStructArgsFormerDefinitionTypes< Context, Formed >; + type End = End; +} +// Former +#[ derive( Debug ) ] +pub struct TestEnumArgsMultiStructArgsFormer +< Definition = TestEnumArgsMultiStructArgsFormerDefinition > +where + Definition : FormerDefinition< Storage = TestEnumArgsMultiStructArgsFormerStorage >, +{ + storage : Definition::Storage, + context : Option< Definition::Context >, + on_end : Option< Definition::End >, +} +impl< Definition > TestEnumArgsMultiStructArgsFormer< Definition > +where + Definition : FormerDefinition< Storage = TestEnumArgsMultiStructArgsFormerStorage >, + Definition::Types : FormerDefinitionTypes< Storage = TestEnumArgsMultiStructArgsFormerStorage >, + Definition::Types : FormerMutator, +{ + #[ inline( always ) ] + pub fn form( self ) -> < Definition::Types as FormerDefinitionTypes >::Formed + { + self.end() + } + #[ inline( always ) ] + pub fn end( mut self ) -> < Definition::Types as FormerDefinitionTypes >::Formed + { + let on_end = self.on_end.take().unwrap(); + let context = self.context.take(); + < Definition::Types as FormerMutator >::form_mutation( &mut self.storage, &mut self.context ); + on_end.call( self.storage, context ) + } + #[ inline( always ) ] + pub fn begin + ( + storage : Option< Definition::Storage >, + context : Option< Definition::Context >, + on_end : Definition::End, + ) -> Self + { + Self { storage : storage.unwrap_or_default(), context, on_end : Some( on_end ) } + } + #[ inline( always ) ] + #[allow(dead_code)] + pub fn new( on_end : Definition::End ) -> Self + { + Self::begin( None, None, on_end ) + } + #[ inline ] + #[allow(dead_code)] + pub fn a( mut self, src : impl Into< i32 > ) -> Self + { + self.storage.a = Some( src.into() ); + self + } + #[ inline ] + #[allow(dead_code)] + pub fn b( mut self, src : impl Into< bool > ) -> Self + { + self.storage.b = Some( src.into() ); + self + } +} +// End Struct +#[ derive( Debug, Default ) ] +pub struct TestEnumArgsMultiStructArgsEnd; +impl FormingEnd< TestEnumArgsMultiStructArgsFormerDefinitionTypes< (), TestEnumArgs > > +for TestEnumArgsMultiStructArgsEnd +{ + #[ inline( always ) ] + fn call + ( + &self, + storage : TestEnumArgsMultiStructArgsFormerStorage, + _context : Option< () >, + ) -> TestEnumArgs + { + let ( val_a, val_b ) = storage.preform(); + TestEnumArgs::MultiStructArgs { a : val_a, b : val_b } + } +} + + // === Standalone Constructors (Manual - Argument Taking) === /// Manual standalone constructor for TestEnumArgs::UnitVariantArgs. @@ -340,7 +632,10 @@ pub fn unit_variant_args() -> TestEnumArgs /// Manual standalone constructor for TestEnumArgs::TupleVariantArgs (takes arg). pub fn tuple_variant_args( _0 : impl Into< i32 > ) -> -TestEnumArgsTupleVariantArgsFormer< TestEnumArgsTupleVariantArgsFormerDefinition< (), TestEnumArgs, TestEnumArgsTupleVariantArgsEnd > > +TestEnumArgsTupleVariantArgsFormer +< + TestEnumArgsTupleVariantArgsFormerDefinition< (), TestEnumArgs, TestEnumArgsTupleVariantArgsEnd > +> { let initial_storage = TestEnumArgsTupleVariantArgsFormerStorage { @@ -352,7 +647,10 @@ TestEnumArgsTupleVariantArgsFormer< TestEnumArgsTupleVariantArgsFormerDefinition /// Manual standalone constructor for TestEnumArgs::StructVariantArgs (takes arg). pub fn struct_variant_args( field : impl Into< String > ) -> -TestEnumArgsStructVariantArgsFormer< TestEnumArgsStructVariantArgsFormerDefinition< (), TestEnumArgs, TestEnumArgsStructVariantArgsEnd > > +TestEnumArgsStructVariantArgsFormer +< + TestEnumArgsStructVariantArgsFormerDefinition< (), TestEnumArgs, TestEnumArgsStructVariantArgsEnd > +> { let initial_storage = TestEnumArgsStructVariantArgsFormerStorage { @@ -361,5 +659,38 @@ TestEnumArgsStructVariantArgsFormer< TestEnumArgsStructVariantArgsFormerDefiniti TestEnumArgsStructVariantArgsFormer::begin( Some( initial_storage ), None, TestEnumArgsStructVariantArgsEnd ) } +/// Manual standalone constructor for TestEnumArgs::MultiTupleArgs (takes args). <<< NEW >>> +pub fn multi_tuple_args( _0 : impl Into< i32 >, _1 : impl Into< bool > ) +-> +TestEnumArgsMultiTupleArgsFormer +< + TestEnumArgsMultiTupleArgsFormerDefinition< (), TestEnumArgs, TestEnumArgsMultiTupleArgsEnd > +> +{ + let initial_storage = TestEnumArgsMultiTupleArgsFormerStorage + { + _0 : Some( _0.into() ), + _1 : Some( _1.into() ), + }; + TestEnumArgsMultiTupleArgsFormer::begin( Some( initial_storage ), None, TestEnumArgsMultiTupleArgsEnd ) +} + +/// Manual standalone constructor for TestEnumArgs::MultiStructArgs (takes args). <<< NEW >>> +pub fn multi_struct_args( a : impl Into< i32 >, b : impl Into< bool > ) +-> +TestEnumArgsMultiStructArgsFormer +< + TestEnumArgsMultiStructArgsFormerDefinition< (), TestEnumArgs, TestEnumArgsMultiStructArgsEnd > +> +{ + let initial_storage = TestEnumArgsMultiStructArgsFormerStorage + { + a : Some( a.into() ), + b : Some( b.into() ), + }; + TestEnumArgsMultiStructArgsFormer::begin( Some( initial_storage ), None, TestEnumArgsMultiStructArgsEnd ) +} + + // === Include Test Logic === include!( "standalone_constructor_args_only_test.rs" ); \ No newline at end of file diff --git a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_only_test.rs b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_only_test.rs index c39afa5116..0ed162aba4 100644 --- a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_only_test.rs +++ b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_only_test.rs @@ -12,8 +12,8 @@ use super::*; fn unit_variant_args_test() // New test name { // Assumes `unit_variant_args` is defined in the including scope - let instance = unit_variant_args(); - let expected = TestEnumArgs::UnitVariantArgs; // Use new enum name + let instance = unit_variant_args(); // Returns Enum directly + let expected = TestEnumArgs::UnitVariantArgs; assert_eq!( instance, expected ); } @@ -21,45 +21,42 @@ fn unit_variant_args_test() // New test name #[ test ] fn tuple_variant_args_test() // New test name { - // Assumes `tuple_variant_args` takes an i32 argument - let former = tuple_variant_args( 202 ); // Call constructor with arg - - // Form directly (no other fields to set in this simple case) - let instance = former.form(); - - // Define the expected enum instance - let expected = TestEnumArgs::TupleVariantArgs( 202 ); // Use new enum name - + // Assumes `tuple_variant_args` takes an i32 argument and returns a Former + let former = tuple_variant_args( 202 ); + let instance = former.form(); // Call form() + let expected = TestEnumArgs::TupleVariantArgs( 202 ); assert_eq!( instance, expected ); - - // // Test setting another value via setter (optional, but good check) - // // <<< Removed this part as it conflicts with setter assert >>> - // let former2 = tuple_variant_args( 0 ); // Init with 0 - // let instance2 = former2._0( 303 ).form(); // Override with setter - // let expected2 = TestEnumArgs::TupleVariantArgs( 303 ); - // assert_eq!( instance2, expected2 ); - } /// Tests the standalone constructor for a struct variant that takes arguments. #[ test ] fn struct_variant_args_test() // New test name { - // Assumes `struct_variant_args` takes a String argument - let former = struct_variant_args( "arg_value" ); // Call constructor with arg - - // Form directly (no other fields to set in this simple case) - let instance = former.form(); - - // Define the expected enum instance - let expected = TestEnumArgs::StructVariantArgs { field : "arg_value".to_string() }; // Use new enum name + // Assumes `struct_variant_args` takes a String argument and returns a Former + let former = struct_variant_args( "arg_value" ); + let instance = former.form(); // Call form() + let expected = TestEnumArgs::StructVariantArgs { field : "arg_value".to_string() }; + assert_eq!( instance, expected ); +} +/// Tests the standalone constructor for a multi-field tuple variant that takes arguments. +#[ test ] +fn multi_tuple_variant_args_test() +{ + // Assumes `multi_tuple_args` takes i32 and bool arguments and returns a Former + let former = multi_tuple_args( 99, true ); // <<< Get the former + let instance = former.form(); // <<< Call .form() + let expected = TestEnumArgs::MultiTupleArgs( 99, true ); assert_eq!( instance, expected ); +} - // // Test setting another value via setter (optional, but good check) - // // <<< Removed this part as it conflicts with setter assert >>> - // let former2 = struct_variant_args( "" ); // Init with "" - // let instance2 = former2.field( "override".to_string() ).form(); // Override with setter - // let expected2 = TestEnumArgs::StructVariantArgs { field : "override".to_string() }; - // assert_eq!( instance2, expected2 ); +/// Tests the standalone constructor for a multi-field struct variant that takes arguments. +#[ test ] +fn multi_struct_variant_args_test() +{ + // Assumes `multi_struct_args` takes i32 and bool arguments and returns a Former + let former = multi_struct_args( -1, false ); + let instance = former.form(); // Call form() + let expected = TestEnumArgs::MultiStructArgs { a : -1, b : false }; + assert_eq!( instance, expected ); } \ No newline at end of file From 01654e0ff120adb6e4ed3dc1a4246cb1232df5be Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 09:09:51 +0300 Subject: [PATCH 16/17] former : wip --- .../standalone_constructor_args_derive.rs | 106 +++++++++--------- .../standalone_constructor_args_only_test.rs | 6 +- .../subform_collection_test.rs | 64 +++++++++++ module/core/former/tests/inc/mod.rs | 4 + 4 files changed, 124 insertions(+), 56 deletions(-) create mode 100644 module/core/former/tests/inc/former_enum_tests/subform_collection_test.rs diff --git a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs index ede8d321f8..87e49093c0 100644 --- a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs +++ b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs @@ -1,53 +1,53 @@ -// module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs -//! -//! Derive-based tests for standalone constructors for enums with arguments. -//! Uses distinct names matching the manual version for testing. -//! - -#[ allow( unused_imports ) ] -use ::former::prelude::*; -use ::former::Former; // Import derive macro - -// === Enum Definition === - -/// Enum using derive for standalone constructors with arguments. -#[ derive( Debug, PartialEq, Clone, Former ) ] -#[ standalone_constructors ] // Enable standalone constructors -pub enum TestEnumArgs // Use the distinct name -{ - /// A unit variant. - UnitVariantArgs, // Use the distinct name - /// A tuple variant with one field marked as constructor arg. - TupleVariantArgs // Use the distinct name - ( - #[ arg_for_constructor ] // Mark field as constructor arg - i32 - ), - /// A struct variant with one field marked as constructor arg. - StructVariantArgs // Use the distinct name - { - #[ arg_for_constructor ] // Mark field as constructor arg - field : String, - }, - /// A tuple variant with multiple fields marked as constructor args. - #[ scalar ] // <<< Keep scalar attribute - MultiTupleArgs // Use the distinct name - ( - // #[ arg_for_constructor ] // <<< REMOVED - i32, - // #[ arg_for_constructor ] // <<< REMOVED - bool, - ), - /// A struct variant with multiple fields marked as constructor args. - // #[ scalar ] // <<< Keep scalar attribute - MultiStructArgs // Use the distinct name - { - #[ arg_for_constructor ] - a : i32, - #[ arg_for_constructor ] - b : bool, - }, -} - -// === Include Test Logic === -include!( "standalone_constructor_args_only_test.rs" ); // Include the specific test file \ No newline at end of file +// // module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs +// //! +// //! Derive-based tests for standalone constructors for enums with arguments. +// //! Uses distinct names matching the manual version for testing. +// //! +// +// #[ allow( unused_imports ) ] +// use ::former::prelude::*; +// use ::former::Former; // Import derive macro +// +// // === Enum Definition === +// +// /// Enum using derive for standalone constructors with arguments. +// #[ derive( Debug, PartialEq, Clone, Former ) ] +// #[ standalone_constructors ] // Enable standalone constructors +// pub enum TestEnumArgs // Use the distinct name +// { +// /// A unit variant. +// UnitVariantArgs, // Use the distinct name +// /// A tuple variant with one field marked as constructor arg. +// TupleVariantArgs // Use the distinct name +// ( +// #[ arg_for_constructor ] // Mark field as constructor arg +// i32 +// ), +// /// A struct variant with one field marked as constructor arg. +// StructVariantArgs // Use the distinct name +// { +// #[ arg_for_constructor ] // Mark field as constructor arg +// field : String, +// }, +// /// A tuple variant with multiple fields marked as constructor args. +// #[ scalar ] // <<< Keep scalar attribute +// MultiTupleArgs // Use the distinct name +// ( +// // #[ arg_for_constructor ] // <<< REMOVED +// i32, +// // #[ arg_for_constructor ] // <<< REMOVED +// bool, +// ), +// /// A struct variant with multiple fields marked as constructor args. +// // #[ scalar ] // <<< Keep scalar attribute +// MultiStructArgs // Use the distinct name +// { +// #[ arg_for_constructor ] +// a : i32, +// #[ arg_for_constructor ] +// b : bool, +// }, +// } +// +// // === Include Test Logic === +// include!( "standalone_constructor_args_only_test.rs" ); // Include the specific test file \ No newline at end of file diff --git a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_only_test.rs b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_only_test.rs index 0ed162aba4..841a53a606 100644 --- a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_only_test.rs +++ b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_only_test.rs @@ -44,8 +44,8 @@ fn struct_variant_args_test() // New test name fn multi_tuple_variant_args_test() { // Assumes `multi_tuple_args` takes i32 and bool arguments and returns a Former - let former = multi_tuple_args( 99, true ); // <<< Get the former - let instance = former.form(); // <<< Call .form() + let former = multi_tuple_args( 99, true ); // <<< Get the former + let instance = former.form(); // <<< Call .form() let expected = TestEnumArgs::MultiTupleArgs( 99, true ); assert_eq!( instance, expected ); } @@ -59,4 +59,4 @@ fn multi_struct_variant_args_test() let instance = former.form(); // Call form() let expected = TestEnumArgs::MultiStructArgs { a : -1, b : false }; assert_eq!( instance, expected ); -} \ No newline at end of file +} diff --git a/module/core/former/tests/inc/former_enum_tests/subform_collection_test.rs b/module/core/former/tests/inc/former_enum_tests/subform_collection_test.rs new file mode 100644 index 0000000000..0864196046 --- /dev/null +++ b/module/core/former/tests/inc/former_enum_tests/subform_collection_test.rs @@ -0,0 +1,64 @@ +// // File: module/core/former/tests/inc/former_enum_tests/subform_collection_test.rs +// //! Minimal test case demonstrating the compilation failure +// //! when using `#[subform_entry]` on a `Vec`. +// +// use super::*; +// use former::Former; +// use std::vec::Vec; +// +// /// A simple enum deriving Former. +// #[ derive( Debug, PartialEq, Clone, Former ) ] +// pub enum SimpleEnum +// { +// /// Unit variant. +// Unit, +// /// Tuple variant with a single value. +// #[ scalar ] // Use scalar for direct constructor +// Value( i32 ), +// } +// +// /// A struct containing a vector of the enum. +// #[ derive( Debug, PartialEq, Default, Former ) ] +// pub struct StructWithEnumVec +// { +// /// Field attempting to use subform_entry on Vec. +// #[ subform_entry ] +// items : Vec< SimpleEnum >, +// } +// +// /// Test attempting to use the subformer generated for `items`. +// /// This test FAIL TO COMPILE because `former` does not +// /// currently support generating the necessary subformer logic for enum entries +// /// within a collection via `#[subform_entry]`. +// #[ test ] +// fn attempt_subform_enum_vec() +// { +// // This code block demonstrates the intended usage that fails. +// /* +// let _result = StructWithEnumVec::former() +// // Trying to access the subformer for the Vec field. +// // The derive macro does not generate the `.items()` method correctly +// // for Vec with #[subform_entry]. It doesn't know how to +// // return a former that can then construct *specific enum variants*. +// .items() +// // Attempting to call a variant constructor method (e.g., .value()) +// // on the hypothetical subformer returned by .items(). This method +// // would not be generated. +// .value( 10 ) +// // Ending the hypothetical subformer for the first enum entry. +// .end() +// // Attempting to start another entry. +// .items() +// // Attempting to call the unit variant constructor method. +// .unit() +// // Ending the hypothetical subformer for the second enum entry. +// .end() +// // Finalizing the parent struct. +// .form(); +// */ +// +// // Assertion to make the test function valid, though it won't be reached +// // if the compilation fails as expected. +// assert!( true, "Test executed - compilation should have failed before this point." ); +// } +// // qqq : xxx : make it working diff --git a/module/core/former/tests/inc/mod.rs b/module/core/former/tests/inc/mod.rs index 156d620b1c..2429e28433 100644 --- a/module/core/former/tests/inc/mod.rs +++ b/module/core/former/tests/inc/mod.rs @@ -271,6 +271,10 @@ mod former_enum_tests mod standalone_constructor_args_manual; mod standalone_constructor_args_derive; + // = subform + + mod subform_collection_test; + } #[ cfg( feature = "derive_components" ) ] From d43396273359a1bd8f8b8520679dadc57b31e5e2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Wed, 23 Apr 2025 09:44:49 +0300 Subject: [PATCH 17/17] plan --- module/core/former/plan.md | 96 +++++++++++++++++++ .../standalone_constructor_args_derive.rs | 5 +- 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 module/core/former/plan.md diff --git a/module/core/former/plan.md b/module/core/former/plan.md new file mode 100644 index 0000000000..85583947f5 --- /dev/null +++ b/module/core/former/plan.md @@ -0,0 +1,96 @@ +# Former Standalone Constructors Feature Plan + +This plan outlines the steps to implement and verify the `#[standalone_constructors]` and `#[arg_for_constructor]` features for the `former` crate, adopting **Option 2** logic where `#[arg_for_constructor]` solely determines constructor arguments and return type. + +## Progress Summary + +* [✅] **Increment 1:** Verify Zero-Argument Standalone Constructors (Existing Files - Modified) +* [✅] **Increment 2:** Create New Test Files for Argument Constructors (Enums & Structs) +* [⬜] **Increment 3 (Rework):** Modify Derive Macro for Option 2 Logic (Enums) +* [⬜] **Increment 4 (Rework):** Update Manual Implementation for Option 2 (Enums) +* [⬜] **Increment 5 (Rework):** Update Tests for Option 2 (Enums) +* [⬜] **Increment 6 (Rework):** Verify Enum Tests (Option 2) +* [⬜] **Increment 7 (Rework):** Implement Manual Argument Constructor Tests (Structs - Option 2) +* [⬜] **Increment 8 (Rework):** Implement Derive Argument Constructor Tests (Structs - Option 2) +* [⬜] **Increment 9 (Rework):** Update Documentation + +## Detailed Plan + +1. **Increment 1: Verify Zero-Argument Standalone Constructors (Existing Files - Modified)** + * **Status:** ✅ Done + * **Goal:** Ensure the basic `#[standalone_constructors]` feature (without `#[arg_for_constructor]`) works correctly for both structs and enums using the *existing* test files, with argument-related tests commented out. + * **Files & Actions:** + * `standalone_constructor_manual.rs` (structs & enums): Ensured constructors take **zero** arguments. + * `standalone_constructor_derive.rs` (structs & enums): Ensured `#[standalone_constructors]` is present, but `#[arg_for_constructor]` is **commented out**. + * `standalone_constructor_only_test.rs` (structs & enums): Ensured **only** the zero-argument tests (`no_args_test`, `unit_variant_test`, `tuple_variant_test`, `struct_variant_test`) are **uncommented**. Commented out the `*_with_args_test` functions. + * **Verification:** Ran `cargo test`. All uncommented tests passed for both manual and derive targets. + +2. **Increment 2: Create New Test Files for Argument Constructors** + * **Status:** ✅ Done + * **Goal:** Set up the file structure for testing the `#[arg_for_constructor]` feature separately. + * **Action:** + * Created `module/core/former/tests/inc/former_struct_tests/standalone_constructor_args_manual.rs`. + * Created `module/core/former/tests/inc/former_struct_tests/standalone_constructor_args_derive.rs`. + * Created `module/core/former/tests/inc/former_struct_tests/standalone_constructor_args_only_test.rs`. + * Created `module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_manual.rs`. + * Created `module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs`. + * Created `module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_only_test.rs`. + * Added `mod standalone_constructor_args_manual;` and `mod standalone_constructor_args_derive;` to `module/core/former/tests/inc/former_struct_tests/mod.rs`. + * Added `mod standalone_constructor_args_manual;` and `mod standalone_constructor_args_derive;` to `module/core/former/tests/inc/former_enum_tests/mod.rs`. + +3. **Increment 3 (Rework): Modify Derive Macro for Option 2 Logic (Enums)** + * **Status:** ⬜ Not Started + * **Goal:** Update `former_enum.rs` to generate standalone constructors according to Option 2 rules (checking if all fields have `#[arg_for_constructor]` to determine return type and body). Remove dependency on `#[scalar]` for standalone constructor generation. + * **File:** `module/core/former_meta/src/derive_former/former_enum.rs` + +4. **Increment 4 (Rework): Update Manual Implementation for Option 2 (Enums)** + * **Status:** ⬜ Not Started + * **Goal:** Align the manual enum implementation (`standalone_constructor_args_manual.rs`) with Option 2 logic. Constructors for variants where all fields are args should return `Self`. Others return the Former. + * **File:** `module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_manual.rs` + +5. **Increment 5 (Rework): Update Tests for Option 2 (Enums)** + * **Status:** ⬜ Not Started + * **Goal:** Adjust tests in `standalone_constructor_args_only_test.rs` to match Option 2 expectations (check return type based on whether all fields are args). + * **File:** `module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_only_test.rs` + +6. **Increment 6 (Rework): Verify Enum Tests (Option 2)** + * **Status:** ⬜ Not Started + * **Goal:** Run tests and ensure they pass for both manual and derive implementations according to Option 2 logic. + * **Action:** `cargo test`. + +7. **Increment 7 (Rework): Implement Manual Argument Constructor Tests (Structs - Option 2)** + * **Status:** ⬜ Not Started + * **Goal:** Implement manual struct tests reflecting Option 2 (constructor returns `Self` if all fields have `#[arg_for_constructor]`, otherwise returns `Former`). + * **Files:** `standalone_constructor_args_manual.rs` (struct), `standalone_constructor_args_only_test.rs` (struct). + +8. **Increment 8 (Rework): Implement Derive Argument Constructor Tests (Structs - Option 2)** + * **Status:** ⬜ Not Started + * **Goal:** Implement derive struct tests reflecting Option 2. Ensure derive logic in `former_struct.rs` is updated if necessary. + * **Files:** `standalone_constructor_args_derive.rs` (struct), `standalone_constructor_args_only_test.rs` (struct), `module/core/former_meta/src/derive_former/former_struct.rs`. + +9. **Increment 9 (Rework): Update Documentation** + * **Status:** ⬜ Not Started + * **Goal:** Document Option 2 behavior for the attributes. + * **Files:** + * `module/core/former/Readme.md` + * `module/core/former/advanced.md` + * `module/core/former_meta/src/lib.rs` + +## Notes / Struggling Points / Insights + +* **Initial Struggle (Enum Tests):** Encountered significant difficulty verifying the `#[arg_for_constructor]` implementation for enums using the initial test setup (`standalone_constructor_manual.rs`, `_derive.rs`, `_only_test.rs`). The shared test file (`_only_test.rs`) contained tests for both zero-argument and argument-taking constructors. +* **Conflict:** The manual implementation (`_manual.rs`) could only define standalone constructors with a single signature (either zero-args or arg-taking). This created a conflict: + * If manual constructors took zero args, the argument-taking tests failed compilation against the manual target. + * If manual constructors took arguments, the zero-argument tests failed compilation against the manual target. +* **Resolution/Insight:** The correct approach was to **separate the test cases**. + * The original files (`standalone_constructor_*`) were adjusted to *only* test the zero-argument constructor scenario (where `#[arg_for_constructor]` is absent or commented out). + * New files (`standalone_constructor_args_*`) were created specifically to test the argument-taking constructor scenario (where `#[arg_for_constructor]` is active). This resolved the conflict and allowed independent verification of both scenarios for manual and derive implementations. +* **Derive vs Manual Behavior:** Realized that standalone constructors for non-unit enum variants (even scalar ones) should return a `Former` type, not `Self` directly. The tests were adjusted accordingly. (Note: This insight is now being revised based on the switch to Option 2). +* **`#[scalar]` vs `#[arg_for_constructor]`:** Clarified that `#[scalar]` on an enum variant implies a direct *associated method* returning `Self`, but the *standalone constructor* still returns a Former. `#[arg_for_constructor]` controls the arguments for the standalone constructor (and potentially initial storage state). Using `#[arg_for_constructor]` within a `#[scalar]` variant is disallowed by the derive macro. (Note: This insight is now being revised based on the switch to Option 2). +* **Decision Change:** Switched from implementing Option 1 (where `#[scalar]` dictated direct return) to **Option 2** (where `#[arg_for_constructor]` on *all* fields dictates direct return). This requires reworking the derive logic and tests for argument handling. + +## General Notes + +* This plan adopts **Option 2**: `#[arg_for_constructor]` on fields solely determines the standalone constructor's arguments. Standalone constructor returns `Self` if *all* fields have `#[arg_for_constructor]`, otherwise returns the implicit `VariantFormer`. `#[scalar]` is irrelevant for standalone constructors. +* Each increment involving code changes should be followed by running `cargo test` to ensure stability and verify the specific goal of the increment. +* Warnings should be addressed as they appear. diff --git a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs index 87e49093c0..c58c13942f 100644 --- a/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs +++ b/module/core/former/tests/inc/former_enum_tests/standalone_constructor_args_derive.rs @@ -50,4 +50,7 @@ // } // // // === Include Test Logic === -// include!( "standalone_constructor_args_only_test.rs" ); // Include the specific test file \ No newline at end of file +// include!( "standalone_constructor_args_only_test.rs" ); // Include the specific test file +// +// qqq : finish it please +// \ No newline at end of file