From afd97a3e7e8cf4b27f8b6a13b070046b385d2734 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 1 Jun 2024 09:04:42 +0300 Subject: [PATCH 01/45] derive_tools : rearrange tests --- .../basic_manual_test.rs} | 2 +- .../{deref_test.rs => deref/basic_test.rs} | 2 +- .../tests/inc/deref/bounds_inlined.rs | 2 +- .../tests/inc/deref/bounds_inlined_manual.rs | 2 +- .../tests/inc/deref/bounds_mixed.rs | 2 +- .../tests/inc/deref/bounds_mixed_manual.rs | 2 +- .../tests/inc/deref/bounds_where.rs | 2 +- .../tests/inc/deref/bounds_where_manual.rs | 2 +- .../tests/inc/deref/enum_named.rs | 2 +- .../tests/inc/deref/enum_named_empty.rs | 2 +- .../inc/deref/enum_named_empty_manual.rs | 4 +-- .../tests/inc/deref/enum_named_manual.rs | 2 +- .../tests/inc/deref/enum_tuple.rs | 2 +- .../tests/inc/deref/enum_tuple_empty.rs | 2 +- .../inc/deref/enum_tuple_empty_manual.rs | 2 +- .../tests/inc/deref/enum_tuple_manual.rs | 2 +- .../derive_tools/tests/inc/deref/enum_unit.rs | 2 +- .../tests/inc/deref/enum_unit_manual.rs | 2 +- .../tests/inc/deref/generics_constants.rs | 2 +- .../inc/deref/generics_constants_default.rs | 2 +- .../generics_constants_default_manual.rs | 2 +- .../inc/deref/generics_constants_manual.rs | 2 +- .../tests/inc/deref/generics_lifetimes.rs | 2 +- .../inc/deref/generics_lifetimes_manual.rs | 2 +- .../tests/inc/deref/generics_types.rs | 2 +- .../tests/inc/deref/generics_types_default.rs | 2 +- .../deref/generics_types_default_manual.rs | 2 +- .../tests/inc/deref/generics_types_manual.rs | 2 +- .../tests/inc/deref/name_collisions.rs | 2 +- .../deref.rs => deref/only_test/basic.rs} | 0 .../bounds_inlined.rs | 0 .../{only_tests => only_test}/bounds_mixed.rs | 0 .../{only_tests => only_test}/bounds_where.rs | 0 .../{only_tests => only_test}/enum_named.rs | 0 .../enum_named_empty.rs | 0 .../{only_tests => only_test}/enum_tuple.rs | 0 .../enum_tuple_empty.rs | 0 .../{only_tests => only_test}/enum_unit.rs | 0 .../generics_constants.rs | 0 .../generics_constants_default.rs | 0 .../generics_lifetimes.rs | 0 .../generics_types.rs | 0 .../generics_types_default.rs | 0 .../name_collisions.rs | 0 .../{only_tests => only_test}/struct_named.rs | 0 .../struct_named_empty.rs | 0 .../{only_tests => only_test}/struct_tuple.rs | 0 .../struct_tuple_empty.rs | 0 .../{only_tests => only_test}/struct_unit.rs | 0 .../tests/inc/deref/struct_named.rs | 2 +- .../tests/inc/deref/struct_named_empty.rs | 2 +- .../inc/deref/struct_named_empty_manual.rs | 2 +- .../tests/inc/deref/struct_named_manual.rs | 2 +- .../tests/inc/deref/struct_tuple.rs | 2 +- .../tests/inc/deref/struct_tuple_empty.rs | 2 +- .../inc/deref/struct_tuple_empty_manual.rs | 2 +- .../tests/inc/deref/struct_tuple_manual.rs | 2 +- .../tests/inc/deref/struct_unit.rs | 2 +- .../tests/inc/deref/struct_unit_manual.rs | 2 +- .../basic_manual_test.rs} | 2 +- .../basic_test.rs} | 2 +- .../tests/inc/deref_mut/bounds_inlined.rs | 2 +- .../inc/deref_mut/bounds_inlined_manual.rs | 2 +- .../tests/inc/deref_mut/bounds_mixed.rs | 2 +- .../inc/deref_mut/bounds_mixed_manual.rs | 2 +- .../tests/inc/deref_mut/bounds_where.rs | 2 +- .../inc/deref_mut/bounds_where_manual.rs | 2 +- .../tests/inc/deref_mut/enum_named.rs | 2 +- .../tests/inc/deref_mut/enum_named_manual.rs | 2 +- .../tests/inc/deref_mut/enum_tuple.rs | 2 +- .../tests/inc/deref_mut/enum_tuple_manual.rs | 2 +- .../tests/inc/deref_mut/generics_constants.rs | 2 +- .../deref_mut/generics_constants_default.rs | 2 +- .../generics_constants_default_manual.rs | 2 +- .../deref_mut/generics_constants_manual.rs | 2 +- .../tests/inc/deref_mut/generics_lifetimes.rs | 2 +- .../deref_mut/generics_lifetimes_manual.rs | 2 +- .../tests/inc/deref_mut/generics_types.rs | 2 +- .../inc/deref_mut/generics_types_default.rs | 2 +- .../generics_types_default_manual.rs | 2 +- .../inc/deref_mut/generics_types_manual.rs | 2 +- .../tests/inc/deref_mut/name_collisions.rs | 2 +- .../only_test/basic.rs} | 0 .../bounds_inlined.rs | 0 .../{only_tests => only_test}/bounds_mixed.rs | 0 .../{only_tests => only_test}/bounds_where.rs | 0 .../{only_tests => only_test}/enum_named.rs | 0 .../{only_tests => only_test}/enum_tuple.rs | 0 .../generics_constants.rs | 0 .../generics_constants_default.rs | 0 .../generics_lifetimes.rs | 0 .../generics_types.rs | 0 .../generics_types_default.rs | 0 .../name_collisions.rs | 0 .../{only_tests => only_test}/struct_named.rs | 0 .../{only_tests => only_test}/struct_tuple.rs | 0 .../tests/inc/deref_mut/struct_named.rs | 2 +- .../inc/deref_mut/struct_named_manual.rs | 2 +- .../tests/inc/deref_mut/struct_tuple.rs | 2 +- .../inc/deref_mut/struct_tuple_manual.rs | 2 +- .../{manual_test.rs => basic_manual_test.rs} | 0 .../tests/inc/from/{test.rs => basic_test.rs} | 0 .../{manual_test.rs => basic_manual_test.rs} | 0 .../inc/inner_from/{test.rs => basic_test.rs} | 0 module/core/derive_tools/tests/inc/mod.rs | 28 ++++++++++++++++--- 105 files changed, 91 insertions(+), 71 deletions(-) rename module/core/derive_tools/tests/inc/{deref_manual_test.rs => deref/basic_manual_test.rs} (95%) rename module/core/derive_tools/tests/inc/{deref_test.rs => deref/basic_test.rs} (92%) rename module/core/derive_tools/tests/inc/{only_test/deref.rs => deref/only_test/basic.rs} (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/bounds_inlined.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/bounds_mixed.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/bounds_where.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/enum_named.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/enum_named_empty.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/enum_tuple.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/enum_tuple_empty.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/enum_unit.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/generics_constants.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/generics_constants_default.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/generics_lifetimes.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/generics_types.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/generics_types_default.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/name_collisions.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/struct_named.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/struct_named_empty.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/struct_tuple.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/struct_tuple_empty.rs (100%) rename module/core/derive_tools/tests/inc/deref/{only_tests => only_test}/struct_unit.rs (100%) rename module/core/derive_tools/tests/inc/{deref_mut_manual_test.rs => deref_mut/basic_manual_test.rs} (96%) rename module/core/derive_tools/tests/inc/{deref_mut_test.rs => deref_mut/basic_test.rs} (92%) rename module/core/derive_tools/tests/inc/{only_test/deref_mut.rs => deref_mut/only_test/basic.rs} (100%) rename module/core/derive_tools/tests/inc/deref_mut/{only_tests => only_test}/bounds_inlined.rs (100%) rename module/core/derive_tools/tests/inc/deref_mut/{only_tests => only_test}/bounds_mixed.rs (100%) rename module/core/derive_tools/tests/inc/deref_mut/{only_tests => only_test}/bounds_where.rs (100%) rename module/core/derive_tools/tests/inc/deref_mut/{only_tests => only_test}/enum_named.rs (100%) rename module/core/derive_tools/tests/inc/deref_mut/{only_tests => only_test}/enum_tuple.rs (100%) rename module/core/derive_tools/tests/inc/deref_mut/{only_tests => only_test}/generics_constants.rs (100%) rename module/core/derive_tools/tests/inc/deref_mut/{only_tests => only_test}/generics_constants_default.rs (100%) rename module/core/derive_tools/tests/inc/deref_mut/{only_tests => only_test}/generics_lifetimes.rs (100%) rename module/core/derive_tools/tests/inc/deref_mut/{only_tests => only_test}/generics_types.rs (100%) rename module/core/derive_tools/tests/inc/deref_mut/{only_tests => only_test}/generics_types_default.rs (100%) rename module/core/derive_tools/tests/inc/deref_mut/{only_tests => only_test}/name_collisions.rs (100%) rename module/core/derive_tools/tests/inc/deref_mut/{only_tests => only_test}/struct_named.rs (100%) rename module/core/derive_tools/tests/inc/deref_mut/{only_tests => only_test}/struct_tuple.rs (100%) rename module/core/derive_tools/tests/inc/from/{manual_test.rs => basic_manual_test.rs} (100%) rename module/core/derive_tools/tests/inc/from/{test.rs => basic_test.rs} (100%) rename module/core/derive_tools/tests/inc/inner_from/{manual_test.rs => basic_manual_test.rs} (100%) rename module/core/derive_tools/tests/inc/inner_from/{test.rs => basic_test.rs} (100%) diff --git a/module/core/derive_tools/tests/inc/deref_manual_test.rs b/module/core/derive_tools/tests/inc/deref/basic_manual_test.rs similarity index 95% rename from module/core/derive_tools/tests/inc/deref_manual_test.rs rename to module/core/derive_tools/tests/inc/deref/basic_manual_test.rs index 3ad2c5c1b4..f8bea6f288 100644 --- a/module/core/derive_tools/tests/inc/deref_manual_test.rs +++ b/module/core/derive_tools/tests/inc/deref/basic_manual_test.rs @@ -31,4 +31,4 @@ where 'a : 'b, T : AsRef< U > } } -include!( "./only_test/deref.rs" ); +include!( "./only_test/basic.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_test.rs b/module/core/derive_tools/tests/inc/deref/basic_test.rs similarity index 92% rename from module/core/derive_tools/tests/inc/deref_test.rs rename to module/core/derive_tools/tests/inc/deref/basic_test.rs index df445ac9b4..b5d1621ae8 100644 --- a/module/core/derive_tools/tests/inc/deref_test.rs +++ b/module/core/derive_tools/tests/inc/deref/basic_test.rs @@ -12,4 +12,4 @@ where 'a : 'b, T : AsRef< U >; -include!( "./only_test/deref.rs" ); +include!( "./only_test/basic.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/bounds_inlined.rs b/module/core/derive_tools/tests/inc/deref/bounds_inlined.rs index 8d31b2d56d..99b7190e46 100644 --- a/module/core/derive_tools/tests/inc/deref/bounds_inlined.rs +++ b/module/core/derive_tools/tests/inc/deref/bounds_inlined.rs @@ -7,4 +7,4 @@ use derive_tools::Deref; #[ derive( Deref ) ] struct BoundsInlined< T : ToString, U : Debug >( T, U ); -include!( "./only_tests/bounds_inlined.rs" ); +include!( "./only_test/bounds_inlined.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/bounds_inlined_manual.rs b/module/core/derive_tools/tests/inc/deref/bounds_inlined_manual.rs index a6e4306512..efca73bd13 100644 --- a/module/core/derive_tools/tests/inc/deref/bounds_inlined_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/bounds_inlined_manual.rs @@ -14,4 +14,4 @@ impl< T : ToString, U : Debug > Deref for BoundsInlined< T, U > } } -include!( "./only_tests/bounds_inlined.rs" ); +include!( "./only_test/bounds_inlined.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/bounds_mixed.rs b/module/core/derive_tools/tests/inc/deref/bounds_mixed.rs index b539d8a862..441193a2ee 100644 --- a/module/core/derive_tools/tests/inc/deref/bounds_mixed.rs +++ b/module/core/derive_tools/tests/inc/deref/bounds_mixed.rs @@ -9,4 +9,4 @@ struct BoundsMixed< T : ToString, U >( T, U ) where U : Debug; -include!( "./only_tests/bounds_mixed.rs" ); +include!( "./only_test/bounds_mixed.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/bounds_mixed_manual.rs b/module/core/derive_tools/tests/inc/deref/bounds_mixed_manual.rs index fbd3ae91e5..98c4830781 100644 --- a/module/core/derive_tools/tests/inc/deref/bounds_mixed_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/bounds_mixed_manual.rs @@ -18,4 +18,4 @@ where } } -include!( "./only_tests/bounds_mixed.rs" ); +include!( "./only_test/bounds_mixed.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/bounds_where.rs b/module/core/derive_tools/tests/inc/deref/bounds_where.rs index 9fb1a3f08a..e9f38ace7e 100644 --- a/module/core/derive_tools/tests/inc/deref/bounds_where.rs +++ b/module/core/derive_tools/tests/inc/deref/bounds_where.rs @@ -11,4 +11,4 @@ where T : ToString, for< 'a > U : Trait< 'a >; -include!( "./only_tests/bounds_where.rs" ); +include!( "./only_test/bounds_where.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/bounds_where_manual.rs b/module/core/derive_tools/tests/inc/deref/bounds_where_manual.rs index 0b440a2c94..18afda143a 100644 --- a/module/core/derive_tools/tests/inc/deref/bounds_where_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/bounds_where_manual.rs @@ -21,4 +21,4 @@ where } } -include!( "./only_tests/bounds_where.rs" ); +include!( "./only_test/bounds_where.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/enum_named.rs b/module/core/derive_tools/tests/inc/deref/enum_named.rs index 98f87a8797..8f0356878d 100644 --- a/module/core/derive_tools/tests/inc/deref/enum_named.rs +++ b/module/core/derive_tools/tests/inc/deref/enum_named.rs @@ -9,4 +9,4 @@ enum EnumNamed B { a : String, b : i32 }, } -include!( "./only_tests/enum_named.rs" ); +include!( "./only_test/enum_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/enum_named_empty.rs b/module/core/derive_tools/tests/inc/deref/enum_named_empty.rs index 22a7c2f8ad..526bbe4b60 100644 --- a/module/core/derive_tools/tests/inc/deref/enum_named_empty.rs +++ b/module/core/derive_tools/tests/inc/deref/enum_named_empty.rs @@ -9,4 +9,4 @@ enum EnumNamedEmpty B {}, } -include!( "./only_tests/enum_named_empty.rs" ); +include!( "./only_test/enum_named_empty.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/enum_named_empty_manual.rs b/module/core/derive_tools/tests/inc/deref/enum_named_empty_manual.rs index 533dc78b0e..8e3bd73806 100644 --- a/module/core/derive_tools/tests/inc/deref/enum_named_empty_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/enum_named_empty_manual.rs @@ -3,7 +3,7 @@ use core::ops::Deref; #[ allow( dead_code) ] enum EnumNamedEmpty { - A {}, + A {}, B {}, } @@ -16,4 +16,4 @@ impl Deref for EnumNamedEmpty } } -include!( "./only_tests/enum_named_empty.rs" ); +include!( "./only_test/enum_named_empty.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/enum_named_manual.rs b/module/core/derive_tools/tests/inc/deref/enum_named_manual.rs index 238192d0b3..9027655111 100644 --- a/module/core/derive_tools/tests/inc/deref/enum_named_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/enum_named_manual.rs @@ -19,4 +19,4 @@ impl Deref for EnumNamed } } -include!( "./only_tests/enum_named.rs" ); +include!( "./only_test/enum_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/enum_tuple.rs b/module/core/derive_tools/tests/inc/deref/enum_tuple.rs index 2c6701331b..816cbbddf1 100644 --- a/module/core/derive_tools/tests/inc/deref/enum_tuple.rs +++ b/module/core/derive_tools/tests/inc/deref/enum_tuple.rs @@ -9,4 +9,4 @@ enum EnumTuple B( String, i32 ), } -include!( "./only_tests/enum_tuple.rs" ); +include!( "./only_test/enum_tuple.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/enum_tuple_empty.rs b/module/core/derive_tools/tests/inc/deref/enum_tuple_empty.rs index df423d9893..a05a748911 100644 --- a/module/core/derive_tools/tests/inc/deref/enum_tuple_empty.rs +++ b/module/core/derive_tools/tests/inc/deref/enum_tuple_empty.rs @@ -9,4 +9,4 @@ enum EnumTupleEmpty B(), } -include!( "./only_tests/enum_tuple_empty.rs" ); +include!( "./only_test/enum_tuple_empty.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/enum_tuple_empty_manual.rs b/module/core/derive_tools/tests/inc/deref/enum_tuple_empty_manual.rs index df54d3101e..e390de4ea3 100644 --- a/module/core/derive_tools/tests/inc/deref/enum_tuple_empty_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/enum_tuple_empty_manual.rs @@ -16,4 +16,4 @@ impl Deref for EnumTupleEmpty } } -include!( "./only_tests/enum_tuple_empty.rs" ); +include!( "./only_test/enum_tuple_empty.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/enum_tuple_manual.rs b/module/core/derive_tools/tests/inc/deref/enum_tuple_manual.rs index efd16f833a..4e716956f1 100644 --- a/module/core/derive_tools/tests/inc/deref/enum_tuple_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/enum_tuple_manual.rs @@ -19,4 +19,4 @@ impl Deref for EnumTuple } } -include!( "./only_tests/enum_tuple.rs" ); +include!( "./only_test/enum_tuple.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/enum_unit.rs b/module/core/derive_tools/tests/inc/deref/enum_unit.rs index 3ef2b204ce..0635a277b6 100644 --- a/module/core/derive_tools/tests/inc/deref/enum_unit.rs +++ b/module/core/derive_tools/tests/inc/deref/enum_unit.rs @@ -9,4 +9,4 @@ enum EnumUnit B, } -include!( "./only_tests/enum_unit.rs" ); +include!( "./only_test/enum_unit.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/enum_unit_manual.rs b/module/core/derive_tools/tests/inc/deref/enum_unit_manual.rs index 1cc6fdc94b..55b874c1c5 100644 --- a/module/core/derive_tools/tests/inc/deref/enum_unit_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/enum_unit_manual.rs @@ -16,4 +16,4 @@ impl Deref for EnumUnit } } -include!( "./only_tests/enum_unit.rs" ); +include!( "./only_test/enum_unit.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/generics_constants.rs b/module/core/derive_tools/tests/inc/deref/generics_constants.rs index f4198931f3..d6cfd619eb 100644 --- a/module/core/derive_tools/tests/inc/deref/generics_constants.rs +++ b/module/core/derive_tools/tests/inc/deref/generics_constants.rs @@ -5,4 +5,4 @@ use derive_tools::Deref; #[ derive( Deref ) ] struct GenericsConstants< const N : usize >( i32 ); -include!( "./only_tests/generics_constants.rs" ); +include!( "./only_test/generics_constants.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/generics_constants_default.rs b/module/core/derive_tools/tests/inc/deref/generics_constants_default.rs index b5b03688dc..a3cac37db9 100644 --- a/module/core/derive_tools/tests/inc/deref/generics_constants_default.rs +++ b/module/core/derive_tools/tests/inc/deref/generics_constants_default.rs @@ -5,4 +5,4 @@ use derive_tools::Deref; #[ derive( Deref ) ] struct GenericsConstantsDefault< const N : usize = 0 >( i32 ); -include!( "./only_tests/generics_constants_default.rs" ); +include!( "./only_test/generics_constants_default.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/generics_constants_default_manual.rs b/module/core/derive_tools/tests/inc/deref/generics_constants_default_manual.rs index b56469fe34..cd0f435138 100644 --- a/module/core/derive_tools/tests/inc/deref/generics_constants_default_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/generics_constants_default_manual.rs @@ -12,4 +12,4 @@ impl< const N : usize > Deref for GenericsConstantsDefault< N > } } -include!( "./only_tests/generics_constants_default.rs" ); +include!( "./only_test/generics_constants_default.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/generics_constants_manual.rs b/module/core/derive_tools/tests/inc/deref/generics_constants_manual.rs index fcc6b6da76..c7bc212fe5 100644 --- a/module/core/derive_tools/tests/inc/deref/generics_constants_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/generics_constants_manual.rs @@ -12,4 +12,4 @@ impl< const N : usize > Deref for GenericsConstants< N > } } -include!( "./only_tests/generics_constants.rs" ); +include!( "./only_test/generics_constants.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/generics_lifetimes.rs b/module/core/derive_tools/tests/inc/deref/generics_lifetimes.rs index a308db8fee..37c3a3218d 100644 --- a/module/core/derive_tools/tests/inc/deref/generics_lifetimes.rs +++ b/module/core/derive_tools/tests/inc/deref/generics_lifetimes.rs @@ -5,4 +5,4 @@ use derive_tools::Deref; #[ derive( Deref ) ] struct GenericsLifetimes< 'a >( &'a i32 ); -include!( "./only_tests/generics_lifetimes.rs" ); +include!( "./only_test/generics_lifetimes.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/generics_lifetimes_manual.rs b/module/core/derive_tools/tests/inc/deref/generics_lifetimes_manual.rs index 57f647c9ff..557ef83a23 100644 --- a/module/core/derive_tools/tests/inc/deref/generics_lifetimes_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/generics_lifetimes_manual.rs @@ -12,4 +12,4 @@ impl< 'a > Deref for GenericsLifetimes< 'a > } } -include!( "./only_tests/generics_lifetimes.rs" ); +include!( "./only_test/generics_lifetimes.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/generics_types.rs b/module/core/derive_tools/tests/inc/deref/generics_types.rs index d6acb22702..301a9e82bc 100644 --- a/module/core/derive_tools/tests/inc/deref/generics_types.rs +++ b/module/core/derive_tools/tests/inc/deref/generics_types.rs @@ -5,4 +5,4 @@ use derive_tools::Deref; #[ derive( Deref ) ] struct GenericsTypes< T >( T ); -include!( "./only_tests/generics_types.rs" ); +include!( "./only_test/generics_types.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/generics_types_default.rs b/module/core/derive_tools/tests/inc/deref/generics_types_default.rs index f89f5d9430..a87144b54c 100644 --- a/module/core/derive_tools/tests/inc/deref/generics_types_default.rs +++ b/module/core/derive_tools/tests/inc/deref/generics_types_default.rs @@ -5,4 +5,4 @@ use derive_tools::Deref; #[ derive ( Deref ) ] struct GenericsTypesDefault< T = i32 >( T ); -include!( "./only_tests/generics_types_default.rs" ); +include!( "./only_test/generics_types_default.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/generics_types_default_manual.rs b/module/core/derive_tools/tests/inc/deref/generics_types_default_manual.rs index 773061023c..5e0f0f1e81 100644 --- a/module/core/derive_tools/tests/inc/deref/generics_types_default_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/generics_types_default_manual.rs @@ -12,4 +12,4 @@ impl< T > Deref for GenericsTypesDefault< T > } } -include!( "./only_tests/generics_types_default.rs" ); +include!( "./only_test/generics_types_default.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/generics_types_manual.rs b/module/core/derive_tools/tests/inc/deref/generics_types_manual.rs index 8b9ab74909..bce6949e12 100644 --- a/module/core/derive_tools/tests/inc/deref/generics_types_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/generics_types_manual.rs @@ -12,4 +12,4 @@ impl< T > Deref for GenericsTypes< T > } } -include!( "./only_tests/generics_types.rs" ); +include!( "./only_test/generics_types.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/name_collisions.rs b/module/core/derive_tools/tests/inc/deref/name_collisions.rs index 3a0fe2a74f..995aec56d6 100644 --- a/module/core/derive_tools/tests/inc/deref/name_collisions.rs +++ b/module/core/derive_tools/tests/inc/deref/name_collisions.rs @@ -20,4 +20,4 @@ struct NameCollisions b : String, } -include!( "./only_tests/name_collisions.rs" ); +include!( "./only_test/name_collisions.rs" ); diff --git a/module/core/derive_tools/tests/inc/only_test/deref.rs b/module/core/derive_tools/tests/inc/deref/only_test/basic.rs similarity index 100% rename from module/core/derive_tools/tests/inc/only_test/deref.rs rename to module/core/derive_tools/tests/inc/deref/only_test/basic.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/bounds_inlined.rs b/module/core/derive_tools/tests/inc/deref/only_test/bounds_inlined.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/bounds_inlined.rs rename to module/core/derive_tools/tests/inc/deref/only_test/bounds_inlined.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/bounds_mixed.rs b/module/core/derive_tools/tests/inc/deref/only_test/bounds_mixed.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/bounds_mixed.rs rename to module/core/derive_tools/tests/inc/deref/only_test/bounds_mixed.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/bounds_where.rs b/module/core/derive_tools/tests/inc/deref/only_test/bounds_where.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/bounds_where.rs rename to module/core/derive_tools/tests/inc/deref/only_test/bounds_where.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/enum_named.rs b/module/core/derive_tools/tests/inc/deref/only_test/enum_named.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/enum_named.rs rename to module/core/derive_tools/tests/inc/deref/only_test/enum_named.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/enum_named_empty.rs b/module/core/derive_tools/tests/inc/deref/only_test/enum_named_empty.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/enum_named_empty.rs rename to module/core/derive_tools/tests/inc/deref/only_test/enum_named_empty.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/enum_tuple.rs b/module/core/derive_tools/tests/inc/deref/only_test/enum_tuple.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/enum_tuple.rs rename to module/core/derive_tools/tests/inc/deref/only_test/enum_tuple.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/enum_tuple_empty.rs b/module/core/derive_tools/tests/inc/deref/only_test/enum_tuple_empty.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/enum_tuple_empty.rs rename to module/core/derive_tools/tests/inc/deref/only_test/enum_tuple_empty.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/enum_unit.rs b/module/core/derive_tools/tests/inc/deref/only_test/enum_unit.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/enum_unit.rs rename to module/core/derive_tools/tests/inc/deref/only_test/enum_unit.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/generics_constants.rs b/module/core/derive_tools/tests/inc/deref/only_test/generics_constants.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/generics_constants.rs rename to module/core/derive_tools/tests/inc/deref/only_test/generics_constants.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/generics_constants_default.rs b/module/core/derive_tools/tests/inc/deref/only_test/generics_constants_default.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/generics_constants_default.rs rename to module/core/derive_tools/tests/inc/deref/only_test/generics_constants_default.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/generics_lifetimes.rs b/module/core/derive_tools/tests/inc/deref/only_test/generics_lifetimes.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/generics_lifetimes.rs rename to module/core/derive_tools/tests/inc/deref/only_test/generics_lifetimes.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/generics_types.rs b/module/core/derive_tools/tests/inc/deref/only_test/generics_types.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/generics_types.rs rename to module/core/derive_tools/tests/inc/deref/only_test/generics_types.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/generics_types_default.rs b/module/core/derive_tools/tests/inc/deref/only_test/generics_types_default.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/generics_types_default.rs rename to module/core/derive_tools/tests/inc/deref/only_test/generics_types_default.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/name_collisions.rs b/module/core/derive_tools/tests/inc/deref/only_test/name_collisions.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/name_collisions.rs rename to module/core/derive_tools/tests/inc/deref/only_test/name_collisions.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/struct_named.rs b/module/core/derive_tools/tests/inc/deref/only_test/struct_named.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/struct_named.rs rename to module/core/derive_tools/tests/inc/deref/only_test/struct_named.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/struct_named_empty.rs b/module/core/derive_tools/tests/inc/deref/only_test/struct_named_empty.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/struct_named_empty.rs rename to module/core/derive_tools/tests/inc/deref/only_test/struct_named_empty.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/struct_tuple.rs b/module/core/derive_tools/tests/inc/deref/only_test/struct_tuple.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/struct_tuple.rs rename to module/core/derive_tools/tests/inc/deref/only_test/struct_tuple.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/struct_tuple_empty.rs b/module/core/derive_tools/tests/inc/deref/only_test/struct_tuple_empty.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/struct_tuple_empty.rs rename to module/core/derive_tools/tests/inc/deref/only_test/struct_tuple_empty.rs diff --git a/module/core/derive_tools/tests/inc/deref/only_tests/struct_unit.rs b/module/core/derive_tools/tests/inc/deref/only_test/struct_unit.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref/only_tests/struct_unit.rs rename to module/core/derive_tools/tests/inc/deref/only_test/struct_unit.rs diff --git a/module/core/derive_tools/tests/inc/deref/struct_named.rs b/module/core/derive_tools/tests/inc/deref/struct_named.rs index 470670a206..0d9356a409 100644 --- a/module/core/derive_tools/tests/inc/deref/struct_named.rs +++ b/module/core/derive_tools/tests/inc/deref/struct_named.rs @@ -9,4 +9,4 @@ struct StructNamed b : i32, } -include!( "./only_tests/struct_named.rs" ); +include!( "./only_test/struct_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/struct_named_empty.rs b/module/core/derive_tools/tests/inc/deref/struct_named_empty.rs index ebe217835d..da9f348550 100644 --- a/module/core/derive_tools/tests/inc/deref/struct_named_empty.rs +++ b/module/core/derive_tools/tests/inc/deref/struct_named_empty.rs @@ -5,4 +5,4 @@ use derive_tools::Deref; #[ derive( Deref ) ] struct StructNamedEmpty{} -include!( "./only_tests/struct_named_empty.rs" ); +include!( "./only_test/struct_named_empty.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/struct_named_empty_manual.rs b/module/core/derive_tools/tests/inc/deref/struct_named_empty_manual.rs index efd92be335..d0aa1502ce 100644 --- a/module/core/derive_tools/tests/inc/deref/struct_named_empty_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/struct_named_empty_manual.rs @@ -12,4 +12,4 @@ impl Deref for StructNamedEmpty } } -include!( "./only_tests/struct_named_empty.rs" ); +include!( "./only_test/struct_named_empty.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/struct_named_manual.rs b/module/core/derive_tools/tests/inc/deref/struct_named_manual.rs index 88e31246e6..a508a73cb2 100644 --- a/module/core/derive_tools/tests/inc/deref/struct_named_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/struct_named_manual.rs @@ -16,4 +16,4 @@ impl Deref for StructNamed } } -include!( "./only_tests/struct_named.rs" ); +include!( "./only_test/struct_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/struct_tuple.rs b/module/core/derive_tools/tests/inc/deref/struct_tuple.rs index 29c4b3c4ff..07555ba421 100644 --- a/module/core/derive_tools/tests/inc/deref/struct_tuple.rs +++ b/module/core/derive_tools/tests/inc/deref/struct_tuple.rs @@ -5,4 +5,4 @@ use derive_tools::Deref; #[ derive ( Deref ) ] struct StructTuple( String, i32 ); -include!( "./only_tests/struct_tuple.rs" ); +include!( "./only_test/struct_tuple.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/struct_tuple_empty.rs b/module/core/derive_tools/tests/inc/deref/struct_tuple_empty.rs index 57e2ea7257..4dc0b8826d 100644 --- a/module/core/derive_tools/tests/inc/deref/struct_tuple_empty.rs +++ b/module/core/derive_tools/tests/inc/deref/struct_tuple_empty.rs @@ -5,4 +5,4 @@ use derive_tools::Deref; #[ derive ( Deref ) ] struct StructTupleEmpty(); -include!( "./only_tests/struct_tuple_empty.rs" ); +include!( "./only_test/struct_tuple_empty.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/struct_tuple_empty_manual.rs b/module/core/derive_tools/tests/inc/deref/struct_tuple_empty_manual.rs index b239eccd44..49e58ac4d7 100644 --- a/module/core/derive_tools/tests/inc/deref/struct_tuple_empty_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/struct_tuple_empty_manual.rs @@ -12,4 +12,4 @@ impl Deref for StructTupleEmpty } } -include!( "./only_tests/struct_tuple_empty.rs" ); +include!( "./only_test/struct_tuple_empty.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/struct_tuple_manual.rs b/module/core/derive_tools/tests/inc/deref/struct_tuple_manual.rs index 7a97225d3b..27de8dc468 100644 --- a/module/core/derive_tools/tests/inc/deref/struct_tuple_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/struct_tuple_manual.rs @@ -12,4 +12,4 @@ impl Deref for StructTuple } } -include!( "./only_tests/struct_tuple.rs" ); +include!( "./only_test/struct_tuple.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/struct_unit.rs b/module/core/derive_tools/tests/inc/deref/struct_unit.rs index 30c742a68e..fbef89b933 100644 --- a/module/core/derive_tools/tests/inc/deref/struct_unit.rs +++ b/module/core/derive_tools/tests/inc/deref/struct_unit.rs @@ -5,4 +5,4 @@ use derive_tools::Deref; #[ derive ( Deref ) ] struct StructUnit; -include!( "./only_tests/struct_unit.rs" ); +include!( "./only_test/struct_unit.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref/struct_unit_manual.rs b/module/core/derive_tools/tests/inc/deref/struct_unit_manual.rs index c43a711d50..a89b73ce19 100644 --- a/module/core/derive_tools/tests/inc/deref/struct_unit_manual.rs +++ b/module/core/derive_tools/tests/inc/deref/struct_unit_manual.rs @@ -12,4 +12,4 @@ impl Deref for StructUnit } } -include!( "./only_tests/struct_unit.rs" ); +include!( "./only_test/struct_unit.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut_manual_test.rs b/module/core/derive_tools/tests/inc/deref_mut/basic_manual_test.rs similarity index 96% rename from module/core/derive_tools/tests/inc/deref_mut_manual_test.rs rename to module/core/derive_tools/tests/inc/deref_mut/basic_manual_test.rs index a5541fbc52..bca3746f67 100644 --- a/module/core/derive_tools/tests/inc/deref_mut_manual_test.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/basic_manual_test.rs @@ -50,4 +50,4 @@ where 'a : 'b, T : AsRef< U > } } -include!( "./only_test/deref_mut.rs" ); +include!( "./only_test/basic.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut_test.rs b/module/core/derive_tools/tests/inc/deref_mut/basic_test.rs similarity index 92% rename from module/core/derive_tools/tests/inc/deref_mut_test.rs rename to module/core/derive_tools/tests/inc/deref_mut/basic_test.rs index aae9db0775..4ba677e7b0 100644 --- a/module/core/derive_tools/tests/inc/deref_mut_test.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/basic_test.rs @@ -12,4 +12,4 @@ where 'a : 'b, T : AsRef< U >; -include!( "./only_test/deref_mut.rs" ); +include!( "./only_test/basic.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/bounds_inlined.rs b/module/core/derive_tools/tests/inc/deref_mut/bounds_inlined.rs index ebb9fe65b6..5c51bcaa71 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/bounds_inlined.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/bounds_inlined.rs @@ -7,4 +7,4 @@ use derive_tools::{ Deref, DerefMut }; #[ derive( Deref, DerefMut ) ] struct BoundsInlined< T : ToString, U : Debug >( T, U ); -include!( "./only_tests/bounds_inlined.rs" ); +include!( "./only_test/bounds_inlined.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/bounds_inlined_manual.rs b/module/core/derive_tools/tests/inc/deref_mut/bounds_inlined_manual.rs index 84051196bf..856447a7a3 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/bounds_inlined_manual.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/bounds_inlined_manual.rs @@ -21,4 +21,4 @@ impl< T : ToString, U : Debug > DerefMut for BoundsInlined< T, U > } } -include!( "./only_tests/bounds_inlined.rs" ); +include!( "./only_test/bounds_inlined.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/bounds_mixed.rs b/module/core/derive_tools/tests/inc/deref_mut/bounds_mixed.rs index 5b8d13196f..b511219c03 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/bounds_mixed.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/bounds_mixed.rs @@ -9,4 +9,4 @@ struct BoundsMixed< T : ToString, U >( T, U ) where U : Debug; -include!( "./only_tests/bounds_mixed.rs" ); +include!( "./only_test/bounds_mixed.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/bounds_mixed_manual.rs b/module/core/derive_tools/tests/inc/deref_mut/bounds_mixed_manual.rs index 4bbfa33c21..23ef9fcb11 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/bounds_mixed_manual.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/bounds_mixed_manual.rs @@ -28,4 +28,4 @@ where } -include!( "./only_tests/bounds_mixed.rs" ); +include!( "./only_test/bounds_mixed.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/bounds_where.rs b/module/core/derive_tools/tests/inc/deref_mut/bounds_where.rs index 25a61c35d1..aa6a9640b8 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/bounds_where.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/bounds_where.rs @@ -11,4 +11,4 @@ where T : ToString, for< 'a > U : Trait< 'a >; -include!( "./only_tests/bounds_where.rs" ); +include!( "./only_test/bounds_where.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/bounds_where_manual.rs b/module/core/derive_tools/tests/inc/deref_mut/bounds_where_manual.rs index 3a61604a87..7d984c999f 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/bounds_where_manual.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/bounds_where_manual.rs @@ -31,4 +31,4 @@ where } } -include!( "./only_tests/bounds_where.rs" ); +include!( "./only_test/bounds_where.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/enum_named.rs b/module/core/derive_tools/tests/inc/deref_mut/enum_named.rs index f6ced02179..0c74b79ac6 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/enum_named.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/enum_named.rs @@ -9,4 +9,4 @@ enum EnumNamed B { a : String, b : i32 }, } -include!( "./only_tests/enum_named.rs" ); +include!( "./only_test/enum_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/enum_named_manual.rs b/module/core/derive_tools/tests/inc/deref_mut/enum_named_manual.rs index 096c52cf20..5128c63693 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/enum_named_manual.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/enum_named_manual.rs @@ -29,4 +29,4 @@ impl DerefMut for EnumNamed } } -include!( "./only_tests/enum_named.rs" ); +include!( "./only_test/enum_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/enum_tuple.rs b/module/core/derive_tools/tests/inc/deref_mut/enum_tuple.rs index 8957e47e25..c8ae4d03b4 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/enum_tuple.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/enum_tuple.rs @@ -9,4 +9,4 @@ enum EnumTuple B( String, i32 ), } -include!( "./only_tests/enum_tuple.rs" ); +include!( "./only_test/enum_tuple.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/enum_tuple_manual.rs b/module/core/derive_tools/tests/inc/deref_mut/enum_tuple_manual.rs index c04408ef45..71decb8809 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/enum_tuple_manual.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/enum_tuple_manual.rs @@ -29,4 +29,4 @@ impl DerefMut for EnumTuple } } -include!( "./only_tests/enum_tuple.rs" ); +include!( "./only_test/enum_tuple.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/generics_constants.rs b/module/core/derive_tools/tests/inc/deref_mut/generics_constants.rs index 33ff0ff89f..24833da41a 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/generics_constants.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/generics_constants.rs @@ -5,4 +5,4 @@ use derive_tools::{ Deref, DerefMut }; #[ derive( Deref, DerefMut ) ] struct GenericsConstants< const N : usize >( i32 ); -include!( "./only_tests/generics_constants.rs" ); +include!( "./only_test/generics_constants.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/generics_constants_default.rs b/module/core/derive_tools/tests/inc/deref_mut/generics_constants_default.rs index a5591f7569..9539193a96 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/generics_constants_default.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/generics_constants_default.rs @@ -5,4 +5,4 @@ use derive_tools::{ Deref, DerefMut }; #[ derive( Deref, DerefMut ) ] struct GenericsConstantsDefault< const N : usize = 0 >( i32 ); -include!( "./only_tests/generics_constants_default.rs" ); +include!( "./only_test/generics_constants_default.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/generics_constants_default_manual.rs b/module/core/derive_tools/tests/inc/deref_mut/generics_constants_default_manual.rs index 6348347253..e0e4495eab 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/generics_constants_default_manual.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/generics_constants_default_manual.rs @@ -19,4 +19,4 @@ impl< const N : usize > DerefMut for GenericsConstantsDefault< N > } } -include!( "./only_tests/generics_constants_default.rs" ); +include!( "./only_test/generics_constants_default.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/generics_constants_manual.rs b/module/core/derive_tools/tests/inc/deref_mut/generics_constants_manual.rs index efe320d565..0578607114 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/generics_constants_manual.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/generics_constants_manual.rs @@ -19,4 +19,4 @@ impl< const N : usize > DerefMut for GenericsConstants< N > } } -include!( "./only_tests/generics_constants.rs" ); +include!( "./only_test/generics_constants.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/generics_lifetimes.rs b/module/core/derive_tools/tests/inc/deref_mut/generics_lifetimes.rs index 3a3ff17bdd..cece76f3d6 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/generics_lifetimes.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/generics_lifetimes.rs @@ -5,4 +5,4 @@ use derive_tools::{ Deref, DerefMut }; #[ derive( Deref, DerefMut ) ] struct GenericsLifetimes< 'a >( &'a i32 ); -include!( "./only_tests/generics_lifetimes.rs" ); +include!( "./only_test/generics_lifetimes.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/generics_lifetimes_manual.rs b/module/core/derive_tools/tests/inc/deref_mut/generics_lifetimes_manual.rs index 7d16d699c9..2d9d86a08f 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/generics_lifetimes_manual.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/generics_lifetimes_manual.rs @@ -19,4 +19,4 @@ impl< 'a > DerefMut for GenericsLifetimes< 'a > } } -include!( "./only_tests/generics_lifetimes.rs" ); +include!( "./only_test/generics_lifetimes.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/generics_types.rs b/module/core/derive_tools/tests/inc/deref_mut/generics_types.rs index dc64f4ec43..3567e862b9 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/generics_types.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/generics_types.rs @@ -5,4 +5,4 @@ use derive_tools::{ Deref, DerefMut }; #[ derive( Deref, DerefMut ) ] struct GenericsTypes< T >( T ); -include!( "./only_tests/generics_types.rs" ); +include!( "./only_test/generics_types.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/generics_types_default.rs b/module/core/derive_tools/tests/inc/deref_mut/generics_types_default.rs index 8680954981..89182ec9f4 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/generics_types_default.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/generics_types_default.rs @@ -5,4 +5,4 @@ use derive_tools::{ Deref, DerefMut }; #[ derive ( Deref, DerefMut ) ] struct GenericsTypesDefault< T = i32 >( T ); -include!( "./only_tests/generics_types_default.rs" ); +include!( "./only_test/generics_types_default.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/generics_types_default_manual.rs b/module/core/derive_tools/tests/inc/deref_mut/generics_types_default_manual.rs index 00b41e2ece..6f638b4535 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/generics_types_default_manual.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/generics_types_default_manual.rs @@ -19,4 +19,4 @@ impl< T > DerefMut for GenericsTypesDefault< T > } } -include!( "./only_tests/generics_types_default.rs" ); +include!( "./only_test/generics_types_default.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/generics_types_manual.rs b/module/core/derive_tools/tests/inc/deref_mut/generics_types_manual.rs index 2bdeb3183f..a015cdda72 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/generics_types_manual.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/generics_types_manual.rs @@ -19,4 +19,4 @@ impl< T > DerefMut for GenericsTypes< T > } } -include!( "./only_tests/generics_types.rs" ); +include!( "./only_test/generics_types.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/name_collisions.rs b/module/core/derive_tools/tests/inc/deref_mut/name_collisions.rs index 66f82b0fb1..8e37f1a33f 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/name_collisions.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/name_collisions.rs @@ -20,4 +20,4 @@ struct NameCollisions b : String, } -include!( "./only_tests/name_collisions.rs" ); +include!( "./only_test/name_collisions.rs" ); diff --git a/module/core/derive_tools/tests/inc/only_test/deref_mut.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/basic.rs similarity index 100% rename from module/core/derive_tools/tests/inc/only_test/deref_mut.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/basic.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/only_tests/bounds_inlined.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/bounds_inlined.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref_mut/only_tests/bounds_inlined.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/bounds_inlined.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/only_tests/bounds_mixed.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/bounds_mixed.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref_mut/only_tests/bounds_mixed.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/bounds_mixed.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/only_tests/bounds_where.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/bounds_where.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref_mut/only_tests/bounds_where.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/bounds_where.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/only_tests/enum_named.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/enum_named.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref_mut/only_tests/enum_named.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/enum_named.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/only_tests/enum_tuple.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/enum_tuple.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref_mut/only_tests/enum_tuple.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/enum_tuple.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/only_tests/generics_constants.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/generics_constants.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref_mut/only_tests/generics_constants.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/generics_constants.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/only_tests/generics_constants_default.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/generics_constants_default.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref_mut/only_tests/generics_constants_default.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/generics_constants_default.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/only_tests/generics_lifetimes.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/generics_lifetimes.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref_mut/only_tests/generics_lifetimes.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/generics_lifetimes.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/only_tests/generics_types.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/generics_types.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref_mut/only_tests/generics_types.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/generics_types.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/only_tests/generics_types_default.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/generics_types_default.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref_mut/only_tests/generics_types_default.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/generics_types_default.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/only_tests/name_collisions.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/name_collisions.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref_mut/only_tests/name_collisions.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/name_collisions.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/only_tests/struct_named.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/struct_named.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref_mut/only_tests/struct_named.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/struct_named.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/only_tests/struct_tuple.rs b/module/core/derive_tools/tests/inc/deref_mut/only_test/struct_tuple.rs similarity index 100% rename from module/core/derive_tools/tests/inc/deref_mut/only_tests/struct_tuple.rs rename to module/core/derive_tools/tests/inc/deref_mut/only_test/struct_tuple.rs diff --git a/module/core/derive_tools/tests/inc/deref_mut/struct_named.rs b/module/core/derive_tools/tests/inc/deref_mut/struct_named.rs index 4cf35f59df..5cb059f6d6 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/struct_named.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/struct_named.rs @@ -9,4 +9,4 @@ struct StructNamed b : i32, } -include!( "./only_tests/struct_named.rs" ); +include!( "./only_test/struct_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/struct_named_manual.rs b/module/core/derive_tools/tests/inc/deref_mut/struct_named_manual.rs index 24cff7f14a..cac020e425 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/struct_named_manual.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/struct_named_manual.rs @@ -23,4 +23,4 @@ impl DerefMut for StructNamed } } -include!( "./only_tests/struct_named.rs" ); +include!( "./only_test/struct_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/struct_tuple.rs b/module/core/derive_tools/tests/inc/deref_mut/struct_tuple.rs index 5d5d439859..c0d4893595 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/struct_tuple.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/struct_tuple.rs @@ -5,4 +5,4 @@ use derive_tools::{ Deref, DerefMut }; #[ derive ( Deref, DerefMut ) ] struct StructTuple( String, i32 ); -include!( "./only_tests/struct_tuple.rs" ); +include!( "./only_test/struct_tuple.rs" ); diff --git a/module/core/derive_tools/tests/inc/deref_mut/struct_tuple_manual.rs b/module/core/derive_tools/tests/inc/deref_mut/struct_tuple_manual.rs index de82ac329c..4212b878b1 100644 --- a/module/core/derive_tools/tests/inc/deref_mut/struct_tuple_manual.rs +++ b/module/core/derive_tools/tests/inc/deref_mut/struct_tuple_manual.rs @@ -19,4 +19,4 @@ impl DerefMut for StructTuple } } -include!( "./only_tests/struct_tuple.rs" ); +include!( "./only_test/struct_tuple.rs" ); diff --git a/module/core/derive_tools/tests/inc/from/manual_test.rs b/module/core/derive_tools/tests/inc/from/basic_manual_test.rs similarity index 100% rename from module/core/derive_tools/tests/inc/from/manual_test.rs rename to module/core/derive_tools/tests/inc/from/basic_manual_test.rs diff --git a/module/core/derive_tools/tests/inc/from/test.rs b/module/core/derive_tools/tests/inc/from/basic_test.rs similarity index 100% rename from module/core/derive_tools/tests/inc/from/test.rs rename to module/core/derive_tools/tests/inc/from/basic_test.rs diff --git a/module/core/derive_tools/tests/inc/inner_from/manual_test.rs b/module/core/derive_tools/tests/inc/inner_from/basic_manual_test.rs similarity index 100% rename from module/core/derive_tools/tests/inc/inner_from/manual_test.rs rename to module/core/derive_tools/tests/inc/inner_from/basic_manual_test.rs diff --git a/module/core/derive_tools/tests/inc/inner_from/test.rs b/module/core/derive_tools/tests/inc/inner_from/basic_test.rs similarity index 100% rename from module/core/derive_tools/tests/inc/inner_from/test.rs rename to module/core/derive_tools/tests/inc/inner_from/basic_test.rs diff --git a/module/core/derive_tools/tests/inc/mod.rs b/module/core/derive_tools/tests/inc/mod.rs index 518d8757d4..3c5a721784 100644 --- a/module/core/derive_tools/tests/inc/mod.rs +++ b/module/core/derive_tools/tests/inc/mod.rs @@ -48,6 +48,11 @@ mod deref_tests // + mod basic_test; + mod basic_manual_test; + + // + mod struct_unit; mod struct_unit_manual; mod struct_tuple; @@ -108,6 +113,11 @@ mod deref_mut_tests // + mod basic_test; + mod basic_manual_test; + + // + mod struct_tuple; mod struct_tuple_manual; mod struct_named; @@ -154,14 +164,19 @@ mod from #[ allow( unused_imports ) ] use super::*; + // + + mod basic_test; + mod basic_manual_test; + + // + mod named_test; mod named_manual_test; - mod manual_test; mod multiple_named_manual_test; mod multiple_manual_test; mod unit_manual_test; - mod test; mod multiple_named_test; mod unit_test; mod multiple_test; @@ -185,12 +200,17 @@ mod inner_from_tests #[ allow( unused_imports ) ] use super::*; - mod manual_test; + // + + mod basic_test; + mod basic_manual_test; + + // + mod named_manual_test; mod multiple_named_manual_test; mod multiple_manual_test; mod unit_manual_test; - mod test; mod named_test; mod multiple_named_test; mod unit_test; From 3815eba562ca667e65e6664aec013a173b903732 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 1 Jun 2024 10:07:39 +0300 Subject: [PATCH 02/45] derive_tools : evolving derive new --- ...est.rs => multiple_unnamed_manual_test.rs} | 2 +- .../tests/inc/from/multiple_unnamed_test.rs | 6 ++++ .../{multiple.rs => multiple_unnamed.rs} | 0 .../tests/inc/from/variants_collisions.rs | 2 ++ ...est.rs => multiple_unnamed_manual_test.rs} | 0 ...tiple_test.rs => multiple_unnamed_test.rs} | 0 module/core/derive_tools/tests/inc/mod.rs | 34 ++++++++++++++++--- .../tests/inc/new/basic_manual_test.rs | 18 ++++++++++ .../derive_tools/tests/inc/new/basic_test.rs | 10 ++++++ .../tests/inc/new/multiple_manual_test.rs | 15 ++++++++ .../inc/new/multiple_named_manual_test.rs | 19 +++++++++++ .../tests/inc/new/multiple_named_test.rs | 10 ++++++ .../tests/inc/{from => new}/multiple_test.rs | 2 +- .../tests/inc/new/named_manual_test.rs | 18 ++++++++++ .../derive_tools/tests/inc/new/named_test.rs | 9 +++++ .../tests/inc/new/only_test/basic.rs | 33 ++++++++++++++++++ .../tests/inc/new/only_test/multiple_named.rs | 7 ++++ .../inc/new/only_test/multiple_unnamed.rs | 7 ++++ .../tests/inc/new/only_test/named.rs | 7 ++++ .../tests/inc/new/only_test/unit.rs | 7 ++++ .../tests/inc/new/unit_manual_test.rs | 15 ++++++++ .../derive_tools/tests/inc/new/unit_test.rs | 6 ++++ 22 files changed, 220 insertions(+), 7 deletions(-) rename module/core/derive_tools/tests/inc/from/{multiple_manual_test.rs => multiple_unnamed_manual_test.rs} (84%) create mode 100644 module/core/derive_tools/tests/inc/from/multiple_unnamed_test.rs rename module/core/derive_tools/tests/inc/from/only_test/{multiple.rs => multiple_unnamed.rs} (100%) rename module/core/derive_tools/tests/inc/inner_from/{multiple_manual_test.rs => multiple_unnamed_manual_test.rs} (100%) rename module/core/derive_tools/tests/inc/inner_from/{multiple_test.rs => multiple_unnamed_test.rs} (100%) create mode 100644 module/core/derive_tools/tests/inc/new/basic_manual_test.rs create mode 100644 module/core/derive_tools/tests/inc/new/basic_test.rs create mode 100644 module/core/derive_tools/tests/inc/new/multiple_manual_test.rs create mode 100644 module/core/derive_tools/tests/inc/new/multiple_named_manual_test.rs create mode 100644 module/core/derive_tools/tests/inc/new/multiple_named_test.rs rename module/core/derive_tools/tests/inc/{from => new}/multiple_test.rs (70%) create mode 100644 module/core/derive_tools/tests/inc/new/named_manual_test.rs create mode 100644 module/core/derive_tools/tests/inc/new/named_test.rs create mode 100644 module/core/derive_tools/tests/inc/new/only_test/basic.rs create mode 100644 module/core/derive_tools/tests/inc/new/only_test/multiple_named.rs create mode 100644 module/core/derive_tools/tests/inc/new/only_test/multiple_unnamed.rs create mode 100644 module/core/derive_tools/tests/inc/new/only_test/named.rs create mode 100644 module/core/derive_tools/tests/inc/new/only_test/unit.rs create mode 100644 module/core/derive_tools/tests/inc/new/unit_manual_test.rs create mode 100644 module/core/derive_tools/tests/inc/new/unit_test.rs diff --git a/module/core/derive_tools/tests/inc/from/multiple_manual_test.rs b/module/core/derive_tools/tests/inc/from/multiple_unnamed_manual_test.rs similarity index 84% rename from module/core/derive_tools/tests/inc/from/multiple_manual_test.rs rename to module/core/derive_tools/tests/inc/from/multiple_unnamed_manual_test.rs index b44fc6b651..8f3feba833 100644 --- a/module/core/derive_tools/tests/inc/from/multiple_manual_test.rs +++ b/module/core/derive_tools/tests/inc/from/multiple_unnamed_manual_test.rs @@ -12,4 +12,4 @@ impl From< ( i32, bool ) > for StructWithManyFields } } -include!( "./only_test/multiple.rs" ); +include!( "./only_test/multiple_unnamed.rs" ); diff --git a/module/core/derive_tools/tests/inc/from/multiple_unnamed_test.rs b/module/core/derive_tools/tests/inc/from/multiple_unnamed_test.rs new file mode 100644 index 0000000000..f4757f1a1a --- /dev/null +++ b/module/core/derive_tools/tests/inc/from/multiple_unnamed_test.rs @@ -0,0 +1,6 @@ +use super::*; + +#[ derive( Debug, PartialEq, Eq, the_module::From ) ] +struct StructWithManyFields( i32, bool ); + +include!( "./only_test/multiple_unnamed.rs" ); diff --git a/module/core/derive_tools/tests/inc/from/only_test/multiple.rs b/module/core/derive_tools/tests/inc/from/only_test/multiple_unnamed.rs similarity index 100% rename from module/core/derive_tools/tests/inc/from/only_test/multiple.rs rename to module/core/derive_tools/tests/inc/from/only_test/multiple_unnamed.rs diff --git a/module/core/derive_tools/tests/inc/from/variants_collisions.rs b/module/core/derive_tools/tests/inc/from/variants_collisions.rs index aefa3be96f..386e9eec59 100644 --- a/module/core/derive_tools/tests/inc/from/variants_collisions.rs +++ b/module/core/derive_tools/tests/inc/from/variants_collisions.rs @@ -10,6 +10,8 @@ pub mod FromString {} pub mod FromPair {} pub mod FromBin {} +// qqq : add collision nests for 4 outher branches + #[ derive( Debug, PartialEq, the_module::From ) ] // #[ debug ] pub enum GetData diff --git a/module/core/derive_tools/tests/inc/inner_from/multiple_manual_test.rs b/module/core/derive_tools/tests/inc/inner_from/multiple_unnamed_manual_test.rs similarity index 100% rename from module/core/derive_tools/tests/inc/inner_from/multiple_manual_test.rs rename to module/core/derive_tools/tests/inc/inner_from/multiple_unnamed_manual_test.rs diff --git a/module/core/derive_tools/tests/inc/inner_from/multiple_test.rs b/module/core/derive_tools/tests/inc/inner_from/multiple_unnamed_test.rs similarity index 100% rename from module/core/derive_tools/tests/inc/inner_from/multiple_test.rs rename to module/core/derive_tools/tests/inc/inner_from/multiple_unnamed_test.rs diff --git a/module/core/derive_tools/tests/inc/mod.rs b/module/core/derive_tools/tests/inc/mod.rs index 3c5a721784..fe32a395ef 100644 --- a/module/core/derive_tools/tests/inc/mod.rs +++ b/module/core/derive_tools/tests/inc/mod.rs @@ -157,6 +157,30 @@ mod deref_mut_tests mod name_collisions; } +// #[ cfg( feature = "derive_new" ) ] +// #[ path = "new" ] +// mod from +// { +// #[ allow( unused_imports ) ] +// use super::*; +// +// // +// +// mod basic_test; +// mod basic_manual_test; +// mod named_test; +// mod named_manual_test; +// mod multiple_named_manual_test; +// mod multiple_unnamed_manual_test; +// mod unit_manual_test; +// mod multiple_named_test; +// mod unit_test; +// mod multiple_test; +// +// // +// +// } + #[ cfg( feature = "derive_from" ) ] #[ path = "from" ] mod from @@ -175,11 +199,11 @@ mod from mod named_manual_test; mod multiple_named_manual_test; - mod multiple_manual_test; + mod multiple_unnamed_manual_test; mod unit_manual_test; mod multiple_named_test; mod unit_test; - mod multiple_test; + mod multiple_unnamed_test; mod variants_manual; mod variants_derive; @@ -207,13 +231,13 @@ mod inner_from_tests // + mod unit_test; mod named_manual_test; mod multiple_named_manual_test; - mod multiple_manual_test; mod unit_manual_test; mod named_test; mod multiple_named_test; - mod unit_test; - mod multiple_test; + mod multiple_unnamed_manual_test; + mod multiple_unnamed_test; } diff --git a/module/core/derive_tools/tests/inc/new/basic_manual_test.rs b/module/core/derive_tools/tests/inc/new/basic_manual_test.rs new file mode 100644 index 0000000000..c9dd6093f2 --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/basic_manual_test.rs @@ -0,0 +1,18 @@ +use super::*; + +// use diagnostics_tools::prelude::*; +// use derives::*; + +#[ derive( Debug, Clone, Copy, PartialEq ) ] +pub struct IsTransparent( bool ); + +impl IsTransparent +{ + #[ inline( always ) ] + fn new( src : bool ) -> Self + { + Self( src ) + } +} + +include!( "./only_test/basic.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/basic_test.rs b/module/core/derive_tools/tests/inc/new/basic_test.rs new file mode 100644 index 0000000000..1214ad5a43 --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/basic_test.rs @@ -0,0 +1,10 @@ +use super::*; + +// use diagnostics_tools::prelude::*; +// use derives::*; + +#[ derive( Debug, Clone, Copy, PartialEq, the_module::From ) ] +pub struct IsTransparent( bool ); + +// include!( "./manual/basic.rs" ); +include!( "./only_test/basic.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/multiple_manual_test.rs b/module/core/derive_tools/tests/inc/new/multiple_manual_test.rs new file mode 100644 index 0000000000..4a13d937ac --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/multiple_manual_test.rs @@ -0,0 +1,15 @@ +use super::*; + +#[ derive( Debug, PartialEq, Eq ) ] +struct StructWithManyFields( i32, bool ); + +impl StructWithManyFields +{ + #[ inline( always ) ] + fn new( src : ( i32, bool ) ) -> Self + { + Self( src.0, src.1 ) + } +} + +include!( "./only_test/multiple_unnamed.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/multiple_named_manual_test.rs b/module/core/derive_tools/tests/inc/new/multiple_named_manual_test.rs new file mode 100644 index 0000000000..29a49de639 --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/multiple_named_manual_test.rs @@ -0,0 +1,19 @@ +use super::*; + +#[ derive( Debug, PartialEq, Eq ) ] +struct StructNamedFields +{ + a: i32, + b: bool, +} + +impl StructNamedFields +{ + #[ inline( always ) ] + fn new( src : ( i32, bool ) ) -> Self + { + Self{ a: src.0, b: src.1 } + } +} + +include!( "./only_test/multiple_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/multiple_named_test.rs b/module/core/derive_tools/tests/inc/new/multiple_named_test.rs new file mode 100644 index 0000000000..ddb088c624 --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/multiple_named_test.rs @@ -0,0 +1,10 @@ +use super::*; + +#[ derive( Debug, PartialEq, Eq, the_module::From ) ] +struct StructNamedFields +{ + a: i32, + b: bool, +} + +include!( "./only_test/multiple_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/from/multiple_test.rs b/module/core/derive_tools/tests/inc/new/multiple_test.rs similarity index 70% rename from module/core/derive_tools/tests/inc/from/multiple_test.rs rename to module/core/derive_tools/tests/inc/new/multiple_test.rs index 925cd66ca0..f4757f1a1a 100644 --- a/module/core/derive_tools/tests/inc/from/multiple_test.rs +++ b/module/core/derive_tools/tests/inc/new/multiple_test.rs @@ -3,4 +3,4 @@ use super::*; #[ derive( Debug, PartialEq, Eq, the_module::From ) ] struct StructWithManyFields( i32, bool ); -include!( "./only_test/multiple.rs" ); +include!( "./only_test/multiple_unnamed.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/named_manual_test.rs b/module/core/derive_tools/tests/inc/new/named_manual_test.rs new file mode 100644 index 0000000000..5dd0c41745 --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/named_manual_test.rs @@ -0,0 +1,18 @@ +use super::*; + +#[ derive( Debug, PartialEq, Eq ) ] +struct MyStruct +{ + a: i32, +} + +impl MyStruct +{ + #[ inline( always ) ] + fn new( src : i32 ) -> Self + { + Self{ a: src } + } +} + +include!( "./only_test/named.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/named_test.rs b/module/core/derive_tools/tests/inc/new/named_test.rs new file mode 100644 index 0000000000..49a1e564d1 --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/named_test.rs @@ -0,0 +1,9 @@ +use super::*; + +#[ derive( Debug, PartialEq, Eq, the_module::From ) ] +struct MyStruct +{ + a : i32, +} + +include!( "./only_test/named.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/only_test/basic.rs b/module/core/derive_tools/tests/inc/new/only_test/basic.rs new file mode 100644 index 0000000000..f7f591e3c0 --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/only_test/basic.rs @@ -0,0 +1,33 @@ + +#[ test ] +fn from_test() +{ + + // let got = IsTransparent::default(); + // let exp = IsTransparent( true ); + // a_id!( got, exp ); + + let got = IsTransparent::from( true ); + let exp = IsTransparent( true ); + a_id!( got, exp ); + let got = IsTransparent::from( false ); + let exp = IsTransparent( false ); + a_id!( got, exp ); + + // let got : bool = IsTransparent::from( true ).into(); + // let exp = true; + // a_id!( got, exp ); + // let got : bool = IsTransparent::from( false ).into(); + // let exp = false; + // a_id!( got, exp ); + +// let got = IsTransparent::default(); +// let exp = true; +// a_id!( *got, exp ); +// +// let mut got = IsTransparent::default(); +// *got = false; +// let exp = false; +// a_id!( *got, exp ); + +} diff --git a/module/core/derive_tools/tests/inc/new/only_test/multiple_named.rs b/module/core/derive_tools/tests/inc/new/only_test/multiple_named.rs new file mode 100644 index 0000000000..5c3d06c3ab --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/only_test/multiple_named.rs @@ -0,0 +1,7 @@ +#[ test ] +fn from_named() +{ + let got : StructNamedFields = StructNamedFields::from( 10, true ); + let exp = StructNamedFields{ a : 10 , b : true }; + a_id!( got, exp ); +} diff --git a/module/core/derive_tools/tests/inc/new/only_test/multiple_unnamed.rs b/module/core/derive_tools/tests/inc/new/only_test/multiple_unnamed.rs new file mode 100644 index 0000000000..94abf3c133 --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/only_test/multiple_unnamed.rs @@ -0,0 +1,7 @@ +#[ test ] +fn from_named() +{ + let got : StructWithManyFields = StructWithManyFields::new( 10, true ); + let exp = StructWithManyFields( 10 , true ); + a_id!( got, exp ); +} diff --git a/module/core/derive_tools/tests/inc/new/only_test/named.rs b/module/core/derive_tools/tests/inc/new/only_test/named.rs new file mode 100644 index 0000000000..b654961735 --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/only_test/named.rs @@ -0,0 +1,7 @@ +#[ test ] +fn from_named() +{ + let got : MyStruct = MyStruct::new( 13 ); + let exp = MyStruct { a : 13 }; + a_id!( got, exp ); +} diff --git a/module/core/derive_tools/tests/inc/new/only_test/unit.rs b/module/core/derive_tools/tests/inc/new/only_test/unit.rs new file mode 100644 index 0000000000..03d80d5033 --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/only_test/unit.rs @@ -0,0 +1,7 @@ +#[ test ] +fn from_named() +{ + let got : UnitStruct = UnitStruct::new( () ); + let exp = UnitStruct; + a_id!( got, exp ); +} diff --git a/module/core/derive_tools/tests/inc/new/unit_manual_test.rs b/module/core/derive_tools/tests/inc/new/unit_manual_test.rs new file mode 100644 index 0000000000..e1117f06eb --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/unit_manual_test.rs @@ -0,0 +1,15 @@ +use super::*; + +#[ derive( Debug, Clone, Copy, PartialEq ) ] +struct UnitStruct; + +impl UnitStruct +{ + #[ inline( always ) ] + fn new( _src : () ) -> Self + { + Self + } +} + +include!( "./only_test/unit.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/unit_test.rs b/module/core/derive_tools/tests/inc/new/unit_test.rs new file mode 100644 index 0000000000..82690e5190 --- /dev/null +++ b/module/core/derive_tools/tests/inc/new/unit_test.rs @@ -0,0 +1,6 @@ +use super::*; + +#[ derive( Debug, Clone, Copy, PartialEq, the_module::From ) ] +struct UnitStruct; + +include!( "./only_test/unit.rs" ); From fd3ad595870e40b9d08b4438fc66b90f7b5c6592 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 1 Jun 2024 10:26:37 +0300 Subject: [PATCH 03/45] derive_tools : evolving derive new --- .../inc/from/multiple_named_manual_test.rs | 6 +- .../tests/inc/from/multiple_named_test.rs | 4 +- .../tests/inc/from/named_manual_test.rs | 4 +- .../tests/inc/from/only_test/basic.rs | 2 + .../inner_from/multiple_named_manual_test.rs | 4 +- .../inc/inner_from/multiple_named_test.rs | 4 +- .../tests/inc/inner_from/named_manual_test.rs | 2 +- .../tests/inc/inner_from/named_test.rs | 2 +- .../inner_from/only_test/multiple_named.rs | 2 +- .../tests/inc/inner_from/only_test/named.rs | 4 +- module/core/derive_tools/tests/inc/mod.rs | 48 +++++----- .../tests/inc/new/basic_manual_test.rs | 3 - .../derive_tools/tests/inc/new/basic_test.rs | 6 +- .../inc/new/multiple_named_manual_test.rs | 8 +- .../tests/inc/new/multiple_named_test.rs | 6 +- ...est.rs => multiple_unnamed_manual_test.rs} | 4 +- ...tiple_test.rs => multiple_unnamed_test.rs} | 2 +- .../tests/inc/new/named_manual_test.rs | 4 +- .../derive_tools/tests/inc/new/named_test.rs | 2 +- .../tests/inc/new/only_test/basic.rs | 24 +---- .../tests/inc/new/only_test/multiple_named.rs | 2 +- .../tests/inc/new/only_test/unit.rs | 2 +- .../tests/inc/new/unit_manual_test.rs | 2 +- .../derive_tools/tests/inc/new/unit_test.rs | 2 +- .../core/derive_tools_meta/src/derive/new.rs | 2 +- module/core/derive_tools_meta/src/lib.rs | 8 +- module/core/former/Readme.md | 2 +- .../former/examples/former_custom_mutator.rs | 2 +- module/core/macro_tools/src/generic_args.rs | 4 +- .../core/macro_tools/tests/inc/derive_test.rs | 4 +- .../proper_path_tools/tests/inc/path_join.rs | 58 ++++++------ .../tests/inc/path_relative.rs | 88 +++++++++---------- module/core/variadic_from/Readme.md | 8 +- .../examples/variadic_from_trivial.rs | 4 +- .../variadic_from_trivial_expanded.rs | 4 +- 35 files changed, 154 insertions(+), 179 deletions(-) rename module/core/derive_tools/tests/inc/new/{multiple_manual_test.rs => multiple_unnamed_manual_test.rs} (75%) rename module/core/derive_tools/tests/inc/new/{multiple_test.rs => multiple_unnamed_test.rs} (66%) diff --git a/module/core/derive_tools/tests/inc/from/multiple_named_manual_test.rs b/module/core/derive_tools/tests/inc/from/multiple_named_manual_test.rs index 02b756b5f5..ff1a641cbf 100644 --- a/module/core/derive_tools/tests/inc/from/multiple_named_manual_test.rs +++ b/module/core/derive_tools/tests/inc/from/multiple_named_manual_test.rs @@ -3,8 +3,8 @@ use super::*; #[ derive( Debug, PartialEq, Eq ) ] struct StructNamedFields { - a: i32, - b: bool, + a : i32, + b : bool, } impl From< ( i32, bool ) > for StructNamedFields @@ -12,7 +12,7 @@ impl From< ( i32, bool ) > for StructNamedFields #[ inline( always ) ] fn from( src : ( i32, bool ) ) -> Self { - Self{ a: src.0, b: src.1 } + Self{ a : src.0, b : src.1 } } } diff --git a/module/core/derive_tools/tests/inc/from/multiple_named_test.rs b/module/core/derive_tools/tests/inc/from/multiple_named_test.rs index ddb088c624..dbb2c6c4dc 100644 --- a/module/core/derive_tools/tests/inc/from/multiple_named_test.rs +++ b/module/core/derive_tools/tests/inc/from/multiple_named_test.rs @@ -3,8 +3,8 @@ use super::*; #[ derive( Debug, PartialEq, Eq, the_module::From ) ] struct StructNamedFields { - a: i32, - b: bool, + a : i32, + b : bool, } include!( "./only_test/multiple_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/from/named_manual_test.rs b/module/core/derive_tools/tests/inc/from/named_manual_test.rs index 6118d32e69..cc3b47f4c5 100644 --- a/module/core/derive_tools/tests/inc/from/named_manual_test.rs +++ b/module/core/derive_tools/tests/inc/from/named_manual_test.rs @@ -3,7 +3,7 @@ use super::*; #[ derive( Debug, PartialEq, Eq ) ] struct MyStruct { - a: i32, + a : i32, } impl From< i32 > for MyStruct @@ -11,7 +11,7 @@ impl From< i32 > for MyStruct #[ inline( always ) ] fn from( src : i32 ) -> Self { - Self{ a: src } + Self{ a : src } } } diff --git a/module/core/derive_tools/tests/inc/from/only_test/basic.rs b/module/core/derive_tools/tests/inc/from/only_test/basic.rs index f7f591e3c0..edd9526697 100644 --- a/module/core/derive_tools/tests/inc/from/only_test/basic.rs +++ b/module/core/derive_tools/tests/inc/from/only_test/basic.rs @@ -31,3 +31,5 @@ fn from_test() // a_id!( *got, exp ); } + +// xxx \ No newline at end of file diff --git a/module/core/derive_tools/tests/inc/inner_from/multiple_named_manual_test.rs b/module/core/derive_tools/tests/inc/inner_from/multiple_named_manual_test.rs index 0a934e454f..915d9061be 100644 --- a/module/core/derive_tools/tests/inc/inner_from/multiple_named_manual_test.rs +++ b/module/core/derive_tools/tests/inc/inner_from/multiple_named_manual_test.rs @@ -3,8 +3,8 @@ use super::*; #[ derive( Debug, PartialEq, Eq ) ] struct StructNamedFields { - a: i32, - b: bool, + a : i32, + b : bool, } impl From< StructNamedFields > for ( i32, bool ) diff --git a/module/core/derive_tools/tests/inc/inner_from/multiple_named_test.rs b/module/core/derive_tools/tests/inc/inner_from/multiple_named_test.rs index 6177841adf..a26eb047ea 100644 --- a/module/core/derive_tools/tests/inc/inner_from/multiple_named_test.rs +++ b/module/core/derive_tools/tests/inc/inner_from/multiple_named_test.rs @@ -3,8 +3,8 @@ use super::*; #[ derive( Debug, PartialEq, Eq, the_module::InnerFrom ) ] struct StructNamedFields { - a: i32, - b: bool, + a : i32, + b : bool, } include!( "./only_test/multiple_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/inner_from/named_manual_test.rs b/module/core/derive_tools/tests/inc/inner_from/named_manual_test.rs index 4d7805644d..f8a3976094 100644 --- a/module/core/derive_tools/tests/inc/inner_from/named_manual_test.rs +++ b/module/core/derive_tools/tests/inc/inner_from/named_manual_test.rs @@ -3,7 +3,7 @@ use super::*; #[ derive( Debug, PartialEq, Eq ) ] struct MyStruct { - a: i32, + a : i32, } impl From< MyStruct > for i32 diff --git a/module/core/derive_tools/tests/inc/inner_from/named_test.rs b/module/core/derive_tools/tests/inc/inner_from/named_test.rs index 2f6d3ccccc..1d686dd38c 100644 --- a/module/core/derive_tools/tests/inc/inner_from/named_test.rs +++ b/module/core/derive_tools/tests/inc/inner_from/named_test.rs @@ -3,7 +3,7 @@ use super::*; #[ derive( Debug, PartialEq, Eq, the_module::InnerFrom ) ] struct MyStruct { - a: i32, + a : i32, } include!( "./only_test/named.rs" ); diff --git a/module/core/derive_tools/tests/inc/inner_from/only_test/multiple_named.rs b/module/core/derive_tools/tests/inc/inner_from/only_test/multiple_named.rs index 05b9a66e9d..0d38366da1 100644 --- a/module/core/derive_tools/tests/inc/inner_from/only_test/multiple_named.rs +++ b/module/core/derive_tools/tests/inc/inner_from/only_test/multiple_named.rs @@ -1,7 +1,7 @@ #[ test ] fn from_named() { - let got : ( i32, bool ) = StructNamedFields{ a: 10, b: true }.into(); + let got : ( i32, bool ) = StructNamedFields{ a : 10, b : true }.into(); let exp = ( 10 , true ); a_id!( got, exp ); } diff --git a/module/core/derive_tools/tests/inc/inner_from/only_test/named.rs b/module/core/derive_tools/tests/inc/inner_from/only_test/named.rs index a733f46367..72ada9af15 100644 --- a/module/core/derive_tools/tests/inc/inner_from/only_test/named.rs +++ b/module/core/derive_tools/tests/inc/inner_from/only_test/named.rs @@ -1,7 +1,7 @@ #[ test ] -fn inner_from_named() +fn inner_from_named() { - let got : i32 = MyStruct{ a: 10 }.into(); + let got : i32 = MyStruct{ a : 10 }.into(); let exp = 10; a_id!( got, exp ); } diff --git a/module/core/derive_tools/tests/inc/mod.rs b/module/core/derive_tools/tests/inc/mod.rs index fe32a395ef..308fc8bae6 100644 --- a/module/core/derive_tools/tests/inc/mod.rs +++ b/module/core/derive_tools/tests/inc/mod.rs @@ -157,33 +157,33 @@ mod deref_mut_tests mod name_collisions; } -// #[ cfg( feature = "derive_new" ) ] -// #[ path = "new" ] -// mod from -// { -// #[ allow( unused_imports ) ] -// use super::*; -// -// // -// -// mod basic_test; -// mod basic_manual_test; -// mod named_test; -// mod named_manual_test; -// mod multiple_named_manual_test; -// mod multiple_unnamed_manual_test; -// mod unit_manual_test; -// mod multiple_named_test; -// mod unit_test; -// mod multiple_test; -// -// // -// -// } +#[ cfg( feature = "derive_new" ) ] +#[ path = "new" ] +mod new_tests +{ + #[ allow( unused_imports ) ] + use super::*; + + // + + mod basic_manual_test; + // mod basic_test; + mod unit_manual_test; + // mod unit_test; + mod named_manual_test; + // mod named_test; + mod multiple_named_manual_test; + // mod multiple_named_test; + mod multiple_unnamed_manual_test; + // mod multiple_unnamed_test; + + // + +} #[ cfg( feature = "derive_from" ) ] #[ path = "from" ] -mod from +mod from_tests { #[ allow( unused_imports ) ] use super::*; diff --git a/module/core/derive_tools/tests/inc/new/basic_manual_test.rs b/module/core/derive_tools/tests/inc/new/basic_manual_test.rs index c9dd6093f2..993956eefa 100644 --- a/module/core/derive_tools/tests/inc/new/basic_manual_test.rs +++ b/module/core/derive_tools/tests/inc/new/basic_manual_test.rs @@ -1,8 +1,5 @@ use super::*; -// use diagnostics_tools::prelude::*; -// use derives::*; - #[ derive( Debug, Clone, Copy, PartialEq ) ] pub struct IsTransparent( bool ); diff --git a/module/core/derive_tools/tests/inc/new/basic_test.rs b/module/core/derive_tools/tests/inc/new/basic_test.rs index 1214ad5a43..6cea8c5a49 100644 --- a/module/core/derive_tools/tests/inc/new/basic_test.rs +++ b/module/core/derive_tools/tests/inc/new/basic_test.rs @@ -1,10 +1,6 @@ use super::*; -// use diagnostics_tools::prelude::*; -// use derives::*; - -#[ derive( Debug, Clone, Copy, PartialEq, the_module::From ) ] +#[ derive( Debug, Clone, Copy, PartialEq, the_module::New ) ] pub struct IsTransparent( bool ); -// include!( "./manual/basic.rs" ); include!( "./only_test/basic.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/multiple_named_manual_test.rs b/module/core/derive_tools/tests/inc/new/multiple_named_manual_test.rs index 29a49de639..839456b1a0 100644 --- a/module/core/derive_tools/tests/inc/new/multiple_named_manual_test.rs +++ b/module/core/derive_tools/tests/inc/new/multiple_named_manual_test.rs @@ -3,16 +3,16 @@ use super::*; #[ derive( Debug, PartialEq, Eq ) ] struct StructNamedFields { - a: i32, - b: bool, + a : i32, + b : bool, } impl StructNamedFields { #[ inline( always ) ] - fn new( src : ( i32, bool ) ) -> Self + fn new( a : i32, b : bool ) -> Self { - Self{ a: src.0, b: src.1 } + Self{ a, b } } } diff --git a/module/core/derive_tools/tests/inc/new/multiple_named_test.rs b/module/core/derive_tools/tests/inc/new/multiple_named_test.rs index ddb088c624..aa4c3de5ab 100644 --- a/module/core/derive_tools/tests/inc/new/multiple_named_test.rs +++ b/module/core/derive_tools/tests/inc/new/multiple_named_test.rs @@ -1,10 +1,10 @@ use super::*; -#[ derive( Debug, PartialEq, Eq, the_module::From ) ] +#[ derive( Debug, PartialEq, Eq, the_module::New ) ] struct StructNamedFields { - a: i32, - b: bool, + a : i32, + b : bool, } include!( "./only_test/multiple_named.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/multiple_manual_test.rs b/module/core/derive_tools/tests/inc/new/multiple_unnamed_manual_test.rs similarity index 75% rename from module/core/derive_tools/tests/inc/new/multiple_manual_test.rs rename to module/core/derive_tools/tests/inc/new/multiple_unnamed_manual_test.rs index 4a13d937ac..08ee277851 100644 --- a/module/core/derive_tools/tests/inc/new/multiple_manual_test.rs +++ b/module/core/derive_tools/tests/inc/new/multiple_unnamed_manual_test.rs @@ -6,9 +6,9 @@ struct StructWithManyFields( i32, bool ); impl StructWithManyFields { #[ inline( always ) ] - fn new( src : ( i32, bool ) ) -> Self + fn new( src1 : i32, src2 : bool ) -> Self { - Self( src.0, src.1 ) + Self( src1, src2 ) } } diff --git a/module/core/derive_tools/tests/inc/new/multiple_test.rs b/module/core/derive_tools/tests/inc/new/multiple_unnamed_test.rs similarity index 66% rename from module/core/derive_tools/tests/inc/new/multiple_test.rs rename to module/core/derive_tools/tests/inc/new/multiple_unnamed_test.rs index f4757f1a1a..6a8f882287 100644 --- a/module/core/derive_tools/tests/inc/new/multiple_test.rs +++ b/module/core/derive_tools/tests/inc/new/multiple_unnamed_test.rs @@ -1,6 +1,6 @@ use super::*; -#[ derive( Debug, PartialEq, Eq, the_module::From ) ] +#[ derive( Debug, PartialEq, Eq, the_module::New ) ] struct StructWithManyFields( i32, bool ); include!( "./only_test/multiple_unnamed.rs" ); diff --git a/module/core/derive_tools/tests/inc/new/named_manual_test.rs b/module/core/derive_tools/tests/inc/new/named_manual_test.rs index 5dd0c41745..679afeec66 100644 --- a/module/core/derive_tools/tests/inc/new/named_manual_test.rs +++ b/module/core/derive_tools/tests/inc/new/named_manual_test.rs @@ -3,7 +3,7 @@ use super::*; #[ derive( Debug, PartialEq, Eq ) ] struct MyStruct { - a: i32, + a : i32, } impl MyStruct @@ -11,7 +11,7 @@ impl MyStruct #[ inline( always ) ] fn new( src : i32 ) -> Self { - Self{ a: src } + Self{ a : src } } } diff --git a/module/core/derive_tools/tests/inc/new/named_test.rs b/module/core/derive_tools/tests/inc/new/named_test.rs index 49a1e564d1..1df964f76f 100644 --- a/module/core/derive_tools/tests/inc/new/named_test.rs +++ b/module/core/derive_tools/tests/inc/new/named_test.rs @@ -1,6 +1,6 @@ use super::*; -#[ derive( Debug, PartialEq, Eq, the_module::From ) ] +#[ derive( Debug, PartialEq, Eq, the_module::New ) ] struct MyStruct { a : i32, diff --git a/module/core/derive_tools/tests/inc/new/only_test/basic.rs b/module/core/derive_tools/tests/inc/new/only_test/basic.rs index f7f591e3c0..7dadc915f2 100644 --- a/module/core/derive_tools/tests/inc/new/only_test/basic.rs +++ b/module/core/derive_tools/tests/inc/new/only_test/basic.rs @@ -3,31 +3,11 @@ fn from_test() { - // let got = IsTransparent::default(); - // let exp = IsTransparent( true ); - // a_id!( got, exp ); - - let got = IsTransparent::from( true ); + let got = IsTransparent::new( true ); let exp = IsTransparent( true ); a_id!( got, exp ); - let got = IsTransparent::from( false ); + let got = IsTransparent::new( false ); let exp = IsTransparent( false ); a_id!( got, exp ); - // let got : bool = IsTransparent::from( true ).into(); - // let exp = true; - // a_id!( got, exp ); - // let got : bool = IsTransparent::from( false ).into(); - // let exp = false; - // a_id!( got, exp ); - -// let got = IsTransparent::default(); -// let exp = true; -// a_id!( *got, exp ); -// -// let mut got = IsTransparent::default(); -// *got = false; -// let exp = false; -// a_id!( *got, exp ); - } diff --git a/module/core/derive_tools/tests/inc/new/only_test/multiple_named.rs b/module/core/derive_tools/tests/inc/new/only_test/multiple_named.rs index 5c3d06c3ab..eebdbba992 100644 --- a/module/core/derive_tools/tests/inc/new/only_test/multiple_named.rs +++ b/module/core/derive_tools/tests/inc/new/only_test/multiple_named.rs @@ -1,7 +1,7 @@ #[ test ] fn from_named() { - let got : StructNamedFields = StructNamedFields::from( 10, true ); + let got : StructNamedFields = StructNamedFields::new( 10, true ); let exp = StructNamedFields{ a : 10 , b : true }; a_id!( got, exp ); } diff --git a/module/core/derive_tools/tests/inc/new/only_test/unit.rs b/module/core/derive_tools/tests/inc/new/only_test/unit.rs index 03d80d5033..279908a05d 100644 --- a/module/core/derive_tools/tests/inc/new/only_test/unit.rs +++ b/module/core/derive_tools/tests/inc/new/only_test/unit.rs @@ -1,7 +1,7 @@ #[ test ] fn from_named() { - let got : UnitStruct = UnitStruct::new( () ); + let got : UnitStruct = UnitStruct::new(); let exp = UnitStruct; a_id!( got, exp ); } diff --git a/module/core/derive_tools/tests/inc/new/unit_manual_test.rs b/module/core/derive_tools/tests/inc/new/unit_manual_test.rs index e1117f06eb..d5fc60e6c5 100644 --- a/module/core/derive_tools/tests/inc/new/unit_manual_test.rs +++ b/module/core/derive_tools/tests/inc/new/unit_manual_test.rs @@ -6,7 +6,7 @@ struct UnitStruct; impl UnitStruct { #[ inline( always ) ] - fn new( _src : () ) -> Self + fn new() -> Self { Self } diff --git a/module/core/derive_tools/tests/inc/new/unit_test.rs b/module/core/derive_tools/tests/inc/new/unit_test.rs index 82690e5190..606df185d8 100644 --- a/module/core/derive_tools/tests/inc/new/unit_test.rs +++ b/module/core/derive_tools/tests/inc/new/unit_test.rs @@ -1,6 +1,6 @@ use super::*; -#[ derive( Debug, Clone, Copy, PartialEq, the_module::From ) ] +#[ derive( Debug, Clone, Copy, PartialEq, the_module::New ) ] struct UnitStruct; include!( "./only_test/unit.rs" ); diff --git a/module/core/derive_tools_meta/src/derive/new.rs b/module/core/derive_tools_meta/src/derive/new.rs index 4bfb0761bb..8552f1a81b 100644 --- a/module/core/derive_tools_meta/src/derive/new.rs +++ b/module/core/derive_tools_meta/src/derive/new.rs @@ -178,7 +178,7 @@ fn generate_single_field_named // fn new( src : i32 ) -> Self fn new( src : #field_type ) -> Self { - // Self { a: src } + // Self { a : src } Self { #field_name: src } } } diff --git a/module/core/derive_tools_meta/src/lib.rs b/module/core/derive_tools_meta/src/lib.rs index b2ea174a1f..b3e15ba826 100644 --- a/module/core/derive_tools_meta/src/lib.rs +++ b/module/core/derive_tools_meta/src/lib.rs @@ -473,8 +473,8 @@ pub fn as_mut( input : proc_macro::TokenStream ) -> proc_macro::TokenStream /// /// dbg!( exp ); /// //> MyStruct { -/// //> a: 13, -/// //> b: 14, +/// //> a : 13, +/// //> b : 14, /// //> } /// } /// ``` @@ -489,8 +489,8 @@ pub fn as_mut( input : proc_macro::TokenStream ) -> proc_macro::TokenStream /// // #[ debug ] /// struct MyStruct /// { -/// a: i32, -/// b: i32, +/// a : i32, +/// b : i32, /// } /// ``` /// diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 05852dba11..966ec2f65d 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -1224,7 +1224,7 @@ held within the storage. assert_eq!( got, exp ); dbg!( got ); // > got = Struct1 { - // > c: "13 - abc", + // > c : "13 - abc", // > } # } diff --git a/module/core/former/examples/former_custom_mutator.rs b/module/core/former/examples/former_custom_mutator.rs index e70323e588..af2956c29e 100644 --- a/module/core/former/examples/former_custom_mutator.rs +++ b/module/core/former/examples/former_custom_mutator.rs @@ -70,7 +70,7 @@ fn main() assert_eq!( got, exp ); dbg!( got ); // > got = Struct1 { - // > c: "13 - abc", + // > c : "13 - abc", // > } } diff --git a/module/core/macro_tools/src/generic_args.rs b/module/core/macro_tools/src/generic_args.rs index 56f70d64a6..a2a175989b 100644 --- a/module/core/macro_tools/src/generic_args.rs +++ b/module/core/macro_tools/src/generic_args.rs @@ -88,8 +88,8 @@ pub( crate ) mod private /// syn::{parse_quote, AngleBracketedGenericArguments}, /// }; /// - /// let a: AngleBracketedGenericArguments = parse_quote! { <'a, T: Clone, U: Default> }; - /// let b: AngleBracketedGenericArguments = parse_quote! { <'b, V: core::fmt::Debug> }; + /// let a : AngleBracketedGenericArguments = parse_quote! { <'a, T: Clone, U: Default> }; + /// let b : AngleBracketedGenericArguments = parse_quote! { <'b, V: core::fmt::Debug> }; /// let merged = generic_args::merge(&a, &b); /// /// let expected: AngleBracketedGenericArguments = parse_quote! { <'a, 'b, T: Clone, U: Default, V: core::fmt::Debug> }; diff --git a/module/core/macro_tools/tests/inc/derive_test.rs b/module/core/macro_tools/tests/inc/derive_test.rs index b6983e34d5..bd36f417cf 100644 --- a/module/core/macro_tools/tests/inc/derive_test.rs +++ b/module/core/macro_tools/tests/inc/derive_test.rs @@ -21,8 +21,8 @@ fn named_fields_with_named_fields() let result = derive::named_fields( &ast ).expect( "Expected successful extraction of named fields" ); let mut expected_fields = Punctuated::new(); - let field_a : Field = parse_quote! { a: i32 }; - let field_b : Field = parse_quote! { b: String }; + let field_a : Field = parse_quote! { a : i32 }; + let field_b : Field = parse_quote! { b : String }; expected_fields.push_value( field_a); expected_fields.push_punct( Comma::default() ); expected_fields.push_value( field_b ); diff --git a/module/core/proper_path_tools/tests/inc/path_join.rs b/module/core/proper_path_tools/tests/inc/path_join.rs index 4bc1c3db62..59217c1fe5 100644 --- a/module/core/proper_path_tools/tests/inc/path_join.rs +++ b/module/core/proper_path_tools/tests/inc/path_join.rs @@ -2,7 +2,7 @@ use super::*; #[ test ] -fn join_empty() +fn join_empty() { let ( expected, paths ) = ( "", vec![ "" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -10,7 +10,7 @@ fn join_empty() } #[ test ] -fn join_several_empties() +fn join_several_empties() { let ( expected, paths ) = ( "", vec![ "", "" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -19,7 +19,7 @@ fn join_several_empties() #[ test ] -fn root_with_absolute() +fn root_with_absolute() { let ( expected, paths ) = ( "/a/b", vec![ "/", "/a/b" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -28,7 +28,7 @@ fn root_with_absolute() #[ test ] -fn root_with_relative() +fn root_with_relative() { let ( expected, paths ) = ( "/a/b", vec![ "/", "a/b" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -37,7 +37,7 @@ fn root_with_relative() #[ test ] -fn dir_with_absolute() +fn dir_with_absolute() { let ( expected, paths ) = ( "/a/b", vec![ "/dir", "/a/b" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -47,7 +47,7 @@ fn dir_with_absolute() #[ test ] -fn dir_with_relative() +fn dir_with_relative() { let ( expected, paths ) = ( "/dir/a/b", vec![ "/dir", "a/b" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -56,7 +56,7 @@ fn dir_with_relative() #[ test ] -fn trailed_dir_with_absolute() +fn trailed_dir_with_absolute() { let ( expected, paths ) = ( "/a/b", vec![ "/dir/", "/a/b" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -64,7 +64,7 @@ fn trailed_dir_with_absolute() } #[ test ] -fn trailed_dir_with_relative() +fn trailed_dir_with_relative() { let ( expected, paths ) = ( "/dir/a/b", vec![ "/dir/", "a/b" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -73,7 +73,7 @@ fn trailed_dir_with_relative() #[ test ] -fn dir_with_down() +fn dir_with_down() { let ( expected, paths ) = ( "/a/b", vec![ "/dir", "../a/b" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -82,7 +82,7 @@ fn dir_with_down() #[ test ] -fn trailed_dir_with_down() +fn trailed_dir_with_down() { let ( expected, paths ) = ( "/dir/a/b", vec![ "/dir/", "../a/b" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -92,7 +92,7 @@ fn trailed_dir_with_down() #[ test ] -fn dir_with_several_down() +fn dir_with_several_down() { let ( expected, paths ) = ( "/a/b", vec![ "/dir/dir2", "../../a/b" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -101,7 +101,7 @@ fn dir_with_several_down() #[ test ] -fn trailed_dir_with_several_down() +fn trailed_dir_with_several_down() { let ( expected, paths ) = ( "/a/b", vec![ "/dir/", "../../a/b" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -110,7 +110,7 @@ fn trailed_dir_with_several_down() #[ test ] -fn dir_with_several_down_go_out_of_root() +fn dir_with_several_down_go_out_of_root() { let ( expected, paths ) = ( "/../a/b", vec![ "/dir", "../../a/b" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -118,7 +118,7 @@ fn dir_with_several_down_go_out_of_root() } #[ test ] -fn trailed_absolute_with_trailed_down() +fn trailed_absolute_with_trailed_down() { let ( expected, paths ) = ( "/a/b/", vec![ "/a/b/", "../" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -127,7 +127,7 @@ fn trailed_absolute_with_trailed_down() #[ test ] -fn absolute_with_trailed_down() +fn absolute_with_trailed_down() { let ( expected, paths ) = ( "/a/", vec![ "/a/b", "../" ]) ; let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -136,7 +136,7 @@ fn absolute_with_trailed_down() #[ test ] -fn trailed_absolute_with_down() +fn trailed_absolute_with_down() { let ( expected, paths ) = ( "/a/b", vec![ "/a/b/", ".." ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -145,7 +145,7 @@ fn trailed_absolute_with_down() #[ test ] -fn trailed_absolute_with_trailed_here() +fn trailed_absolute_with_trailed_here() { let ( expected, paths ) = ( "/a/b/", vec![ "/a/b/", "./" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -155,7 +155,7 @@ fn trailed_absolute_with_trailed_here() #[ test ] -fn absolute_with_trailed_here() +fn absolute_with_trailed_here() { let ( expected, paths ) = ( "/a/b/", vec![ "/a/b", "./" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -164,7 +164,7 @@ fn absolute_with_trailed_here() #[ test ] -fn trailed_absolute_with_here() +fn trailed_absolute_with_here() { let ( expected, paths ) = ( "/a/b", vec![ "/a/b/", "." ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -173,7 +173,7 @@ fn trailed_absolute_with_here() #[ test ] -fn join_with_empty() +fn join_with_empty() { let ( expected, paths ) = ( "/a/b/c", vec![ "", "a/b", "", "c", "" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -181,16 +181,16 @@ fn join_with_empty() } #[ test ] -fn join_windows_os_paths() +fn join_windows_os_paths() { - let ( expected, paths ) = ( "/c/foo/bar/", vec![ "c:\\", "foo\\", "bar\\" ] ); + let ( expected, paths ) = ( "/c/foo/bar/", vec![ "c :\\", "foo\\", "bar\\" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); assert_eq!( result, std::path::PathBuf::from( expected ), "Test failed. Paths: '{:?}', Expected: '{}', Got: '{}'", paths, expected, result.to_string_lossy() ); } #[ test ] -fn join_unix_os_paths() +fn join_unix_os_paths() { let ( expected, paths ) = ( "/baz/foo", vec![ "/bar/", "/baz", "foo/", "." ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -199,7 +199,7 @@ fn join_unix_os_paths() #[ test ] -fn join_unix_os_paths_2() +fn join_unix_os_paths_2() { let ( expected, paths ) = ( "/baz/foo/z", vec![ "/bar/", "/baz", "foo/", ".", "z" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -208,7 +208,7 @@ fn join_unix_os_paths_2() #[ test ] -fn more_complicated_cases_1() +fn more_complicated_cases_1() { let ( expected, paths ) = ( "/aa/bb//cc", vec![ "/aa", "bb//", "cc" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -218,7 +218,7 @@ fn more_complicated_cases_1() #[ test ] -fn more_complicated_cases_2() +fn more_complicated_cases_2() { let ( expected, paths ) = ( "/bb/cc", vec![ "/aa", "/bb", "cc" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -227,7 +227,7 @@ fn more_complicated_cases_2() #[ test ] -fn more_complicated_cases_3() +fn more_complicated_cases_3() { let ( expected, paths ) = ( "//aa/bb//cc//", vec![ "//aa", "bb//", "cc//" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -236,7 +236,7 @@ fn more_complicated_cases_3() #[ test ] -fn more_complicated_cases_4() +fn more_complicated_cases_4() { let ( expected, paths ) = ( "/aa/bb//cc", vec![ "/aa", "bb//", "cc", "." ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); @@ -244,7 +244,7 @@ fn more_complicated_cases_4() } #[ test ] -fn more_complicated_cases_5() +fn more_complicated_cases_5() { let ( expected, paths ) = ( "//b//d/..e", vec![ "/", "a", "//b//", "././c", "../d", "..e" ] ); let result = the_module::path::join_paths( paths.clone().into_iter() ); diff --git a/module/core/proper_path_tools/tests/inc/path_relative.rs b/module/core/proper_path_tools/tests/inc/path_relative.rs index 7c9f6bfbed..f94fcc5ed6 100644 --- a/module/core/proper_path_tools/tests/inc/path_relative.rs +++ b/module/core/proper_path_tools/tests/inc/path_relative.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; // absolute path relative #[ test ] -fn test_absolute_a_minus_b() +fn test_absolute_a_minus_b() { let from = "/a"; let to = "/b"; @@ -15,7 +15,7 @@ fn test_absolute_a_minus_b() } #[ test ] -fn test_absolute_root_minus_b() +fn test_absolute_root_minus_b() { let from = "/"; let to = "/b"; @@ -24,7 +24,7 @@ fn test_absolute_root_minus_b() } #[ test ] -fn test_absolute_same_path() +fn test_absolute_same_path() { let from = "/aa/bb/cc"; let to = "/aa/bb/cc"; @@ -33,7 +33,7 @@ fn test_absolute_same_path() } #[ test ] -fn test_absolute_same_path_with_trail() +fn test_absolute_same_path_with_trail() { let from = "/aa/bb/cc"; let to = "/aa/bb/cc/"; @@ -42,7 +42,7 @@ fn test_absolute_same_path_with_trail() } #[ test ] -fn test_absolute_two_trailed_absolute_paths() +fn test_absolute_two_trailed_absolute_paths() { let from = "/a/b/"; let to = "/a/b/"; @@ -51,7 +51,7 @@ fn test_absolute_two_trailed_absolute_paths() } #[ test ] -fn test_absolute_two_absolute_paths_with_trail() +fn test_absolute_two_absolute_paths_with_trail() { let from = "/a/b"; let to = "/a/b/"; @@ -60,7 +60,7 @@ fn test_absolute_two_absolute_paths_with_trail() } #[ test ] -fn test_absolute_two_absolute_paths() +fn test_absolute_two_absolute_paths() { let from = "/a/b/"; let to = "/a/b"; @@ -69,7 +69,7 @@ fn test_absolute_two_absolute_paths() } #[ test ] -fn test_absolute_same_path_trail_to_not() +fn test_absolute_same_path_trail_to_not() { let from = "/aa/bb/cc/"; let to = "/aa/bb/cc"; @@ -78,7 +78,7 @@ fn test_absolute_same_path_trail_to_not() } #[ test ] -fn test_absolute_a_to_double_slash_b() +fn test_absolute_a_to_double_slash_b() { let from = "/a"; let to = "//b"; @@ -88,7 +88,7 @@ fn test_absolute_a_to_double_slash_b() #[ test ] -fn test_absolute_relative_to_nested() +fn test_absolute_relative_to_nested() { let from = "/foo/bar/baz/asdf/quux"; let to = "/foo/bar/baz/asdf/quux/new1"; @@ -97,7 +97,7 @@ fn test_absolute_relative_to_nested() } #[ test ] -fn test_absolute_out_of_relative_dir() +fn test_absolute_out_of_relative_dir() { let from = "/abc"; let to = "/a/b/z"; @@ -106,7 +106,7 @@ fn test_absolute_out_of_relative_dir() } #[ test ] -fn test_absolute_relative_root() +fn test_absolute_relative_root() { let from = "/"; let to = "/a/b/z"; @@ -116,7 +116,7 @@ fn test_absolute_relative_root() #[ test ] -fn test_long_not_direct() +fn test_long_not_direct() { let from = "/a/b/xx/yy/zz"; let to = "/a/b/files/x/y/z.txt"; @@ -125,7 +125,7 @@ fn test_long_not_direct() } #[ test ] -fn test_absolute_relative_to_parent_directory() +fn test_absolute_relative_to_parent_directory() { let from = "/aa/bb/cc"; let to = "/aa/bb"; @@ -134,7 +134,7 @@ fn test_absolute_relative_to_parent_directory() } #[ test ] -fn test_absolute_relative_to_parent_directory_file_trailed() +fn test_absolute_relative_to_parent_directory_file_trailed() { let from = "/aa/bb/cc"; let to = "/aa/bb/"; @@ -143,7 +143,7 @@ fn test_absolute_relative_to_parent_directory_file_trailed() } #[ test ] -fn test_absolute_relative_root_to_root() +fn test_absolute_relative_root_to_root() { let from = "/"; let to = "/"; @@ -152,17 +152,17 @@ fn test_absolute_relative_root_to_root() } #[ test ] -fn test_windows_disks() +fn test_windows_disks() { let from = "d:/"; - let to = "c:/x/y"; + let to = "c :/x/y"; let expected = "../c/x/y"; assert_eq!( the_module::path::path_relative( from, to ), PathBuf::from( expected ) ); } #[ test ] -fn test_absolute_relative_to_parent_directory_both_trailed() +fn test_absolute_relative_to_parent_directory_both_trailed() { let from = "/aa/bb/cc/"; let to = "/aa/bb/"; @@ -172,7 +172,7 @@ fn test_absolute_relative_to_parent_directory_both_trailed() #[ test ] -fn test_absolute_a_with_trail_to_double_slash_b_with_trail() +fn test_absolute_a_with_trail_to_double_slash_b_with_trail() { let from = "/a/"; let to = "//b/"; @@ -181,7 +181,7 @@ fn test_absolute_a_with_trail_to_double_slash_b_with_trail() } #[ test ] -fn test_absolute_4_down() +fn test_absolute_4_down() { let from = "/aa//bb/cc/"; let to = "//xx/yy/zz/"; @@ -190,7 +190,7 @@ fn test_absolute_4_down() } #[ test ] -fn test_absolute_same_length_both_trailed() +fn test_absolute_same_length_both_trailed() { let from = "/aa//bb/cc/"; let to = "//xx/yy/zz/"; @@ -199,7 +199,7 @@ fn test_absolute_same_length_both_trailed() } #[ test ] -fn test_absolute_relative_to_parent_directory_base_trailed() +fn test_absolute_relative_to_parent_directory_base_trailed() { let from = "/aa/bb/cc/"; let to = "/aa/bb"; @@ -214,7 +214,7 @@ fn test_absolute_relative_to_parent_directory_base_trailed() // relative_path_relative #[ test ] -fn test_relative_dot_to_dot() +fn test_relative_dot_to_dot() { let from = "."; let to = "."; @@ -223,7 +223,7 @@ fn test_relative_dot_to_dot() } #[ test ] -fn test_relative_a_to_b() +fn test_relative_a_to_b() { let from = "a"; let to = "b"; @@ -232,7 +232,7 @@ fn test_relative_a_to_b() } #[ test ] -fn test_relative_a_b_to_b_c() +fn test_relative_a_b_to_b_c() { let from = "a/b"; let to = "b/c"; @@ -241,7 +241,7 @@ fn test_relative_a_b_to_b_c() } #[ test ] -fn test_relative_a_b_to_a_b_c() +fn test_relative_a_b_to_a_b_c() { let from = "a/b"; let to = "a/b/c"; @@ -250,7 +250,7 @@ fn test_relative_a_b_to_a_b_c() } #[ test ] -fn test_relative_a_b_c_to_a_b() +fn test_relative_a_b_c_to_a_b() { let from = "a/b/c"; let to = "a/b"; @@ -259,7 +259,7 @@ fn test_relative_a_b_c_to_a_b() } #[ test ] -fn test_relative_a_b_c_d_to_a_b_d_c() +fn test_relative_a_b_c_d_to_a_b_d_c() { let from = "a/b/c/d"; let to = "a/b/d/c"; @@ -268,7 +268,7 @@ fn test_relative_a_b_c_d_to_a_b_d_c() } #[ test ] -fn test_relative_a_to_dot_dot_a() +fn test_relative_a_to_dot_dot_a() { let from = "a"; let to = "../a"; @@ -277,7 +277,7 @@ fn test_relative_a_to_dot_dot_a() } #[ test ] -fn test_relative_a_slash_slash_b_to_a_slash_slash_c() +fn test_relative_a_slash_slash_b_to_a_slash_slash_c() { let from = "a//b"; let to = "a//c"; @@ -286,7 +286,7 @@ fn test_relative_a_slash_slash_b_to_a_slash_slash_c() } #[ test ] -fn test_relative_a_dot_slash_b_to_a_dot_slash_c() +fn test_relative_a_dot_slash_b_to_a_dot_slash_c() { let from = "a/./b"; let to = "a/./c"; @@ -295,7 +295,7 @@ fn test_relative_a_dot_slash_b_to_a_dot_slash_c() } #[ test ] -fn test_relative_a_dot_dot_slash_b_to_b() +fn test_relative_a_dot_dot_slash_b_to_b() { let from = "a/../b"; let to = "b"; @@ -304,7 +304,7 @@ fn test_relative_a_dot_dot_slash_b_to_b() } #[ test ] -fn test_relative_b_to_b_dot_dot_slash_b() +fn test_relative_b_to_b_dot_dot_slash_b() { let from = "b"; let to = "b/../b"; @@ -313,7 +313,7 @@ fn test_relative_b_to_b_dot_dot_slash_b() } #[ test ] -fn test_relative_dot_to_dot_dot() +fn test_relative_dot_to_dot_dot() { let from = "."; let to = ".."; @@ -322,7 +322,7 @@ fn test_relative_dot_to_dot_dot() } #[ test ] -fn test_relative_dot_to_dot_dot_dot() +fn test_relative_dot_to_dot_dot_dot() { let from = "."; let to = "../.."; @@ -331,7 +331,7 @@ fn test_relative_dot_to_dot_dot_dot() } #[ test ] -fn test_relative_dot_dot_to_dot_dot() +fn test_relative_dot_dot_to_dot_dot() { let from = ".."; let to = "../.."; @@ -340,7 +340,7 @@ fn test_relative_dot_dot_to_dot_dot() } #[ test ] -fn test_relative_dot_dot_to_dot_dot_dot() +fn test_relative_dot_dot_to_dot_dot_dot() { let from = ".."; let to = ".."; @@ -349,7 +349,7 @@ fn test_relative_dot_dot_to_dot_dot_dot() } #[ test ] -fn test_relative_dot_dot_a_b_to_dot_dot_c_d() +fn test_relative_dot_dot_a_b_to_dot_dot_c_d() { let from = "../a/b"; let to = "../c/d"; @@ -358,7 +358,7 @@ fn test_relative_dot_dot_a_b_to_dot_dot_c_d() } #[ test ] -fn test_relative_dot_to_b() +fn test_relative_dot_to_b() { let from = "."; let to = "b"; @@ -367,7 +367,7 @@ fn test_relative_dot_to_b() } #[ test ] -fn test_relative_dot_slash_to_b() +fn test_relative_dot_slash_to_b() { let from = "./"; let to = "b"; @@ -376,7 +376,7 @@ fn test_relative_dot_slash_to_b() } #[ test ] -fn test_relative_dot_to_b_slash() +fn test_relative_dot_to_b_slash() { let from = "."; let to = "b/"; @@ -385,7 +385,7 @@ fn test_relative_dot_to_b_slash() } #[ test ] -fn test_relative_dot_slash_to_b_slash() +fn test_relative_dot_slash_to_b_slash() { let from = "./"; let to = "b/"; @@ -394,7 +394,7 @@ fn test_relative_dot_slash_to_b_slash() } #[ test ] -fn test_relative_a_dot_dot_to_b_dot_dot() +fn test_relative_a_dot_dot_to_b_dot_dot() { let from = "a/../b/.."; let to = "b"; diff --git a/module/core/variadic_from/Readme.md b/module/core/variadic_from/Readme.md index c06be02938..1389bf6828 100644 --- a/module/core/variadic_from/Readme.md +++ b/module/core/variadic_from/Readme.md @@ -60,8 +60,8 @@ fn main() dbg!( exp ); //> MyStruct { - //> a: 13, - //> b: 14, + //> a : 13, + //> b : 14, //> } } @@ -127,8 +127,8 @@ fn main() dbg!( exp ); //> MyStruct { - //> a: 13, - //> b: 14, + //> a : 13, + //> b : 14, //> } } diff --git a/module/core/variadic_from/examples/variadic_from_trivial.rs b/module/core/variadic_from/examples/variadic_from_trivial.rs index a1c68018ec..bccf54bacf 100644 --- a/module/core/variadic_from/examples/variadic_from_trivial.rs +++ b/module/core/variadic_from/examples/variadic_from_trivial.rs @@ -45,8 +45,8 @@ fn main() dbg!( exp ); //> MyStruct { - //> a: 13, - //> b: 14, + //> a : 13, + //> b : 14, //> } } diff --git a/module/core/variadic_from/examples/variadic_from_trivial_expanded.rs b/module/core/variadic_from/examples/variadic_from_trivial_expanded.rs index 3f32182add..4ca52fcb56 100644 --- a/module/core/variadic_from/examples/variadic_from_trivial_expanded.rs +++ b/module/core/variadic_from/examples/variadic_from_trivial_expanded.rs @@ -59,8 +59,8 @@ fn main() dbg!( exp ); //> MyStruct { - //> a: 13, - //> b: 14, + //> a : 13, + //> b : 14, //> } } From 58be91031df891f24bad4fde3c3936610904658a Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 1 Jun 2024 12:06:09 +0300 Subject: [PATCH 04/45] macro_tools : iterators experiment --- module/core/derive_tools/tests/inc/mod.rs | 12 +- .../tests/inc/new/multiple_named_test.rs | 1 + .../core/derive_tools_meta/src/derive/new.rs | 30 +++-- module/core/macro_tools/src/item_struct.rs | 4 +- module/core/macro_tools/src/iter.rs | 109 +++++++++++++++++- 5 files changed, 138 insertions(+), 18 deletions(-) diff --git a/module/core/derive_tools/tests/inc/mod.rs b/module/core/derive_tools/tests/inc/mod.rs index 308fc8bae6..a79deeb407 100644 --- a/module/core/derive_tools/tests/inc/mod.rs +++ b/module/core/derive_tools/tests/inc/mod.rs @@ -164,16 +164,18 @@ mod new_tests #[ allow( unused_imports ) ] use super::*; + // qqq : for each branch add generic test + // mod basic_manual_test; - // mod basic_test; + mod basic_test; mod unit_manual_test; - // mod unit_test; + mod unit_test; mod named_manual_test; - // mod named_test; + mod named_test; mod multiple_named_manual_test; - // mod multiple_named_test; + mod multiple_named_test; mod multiple_unnamed_manual_test; // mod multiple_unnamed_test; @@ -188,6 +190,8 @@ mod from_tests #[ allow( unused_imports ) ] use super::*; + // qqq : for each branch add generic test + // mod basic_test; diff --git a/module/core/derive_tools/tests/inc/new/multiple_named_test.rs b/module/core/derive_tools/tests/inc/new/multiple_named_test.rs index aa4c3de5ab..c0a19cf001 100644 --- a/module/core/derive_tools/tests/inc/new/multiple_named_test.rs +++ b/module/core/derive_tools/tests/inc/new/multiple_named_test.rs @@ -1,6 +1,7 @@ use super::*; #[ derive( Debug, PartialEq, Eq, the_module::New ) ] +#[ debug ] struct StructNamedFields { a : i32, diff --git a/module/core/derive_tools_meta/src/derive/new.rs b/module/core/derive_tools_meta/src/derive/new.rs index 8552f1a81b..d1947c6730 100644 --- a/module/core/derive_tools_meta/src/derive/new.rs +++ b/module/core/derive_tools_meta/src/derive/new.rs @@ -225,22 +225,38 @@ fn generate_multiple_fields_named< 'a > generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_where: &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - field_names : Box< dyn macro_tools::IterTrait< 'a, &'a syn::Ident > + '_ >, + field_names : impl macro_tools::IterTrait< 'a, &'a syn::Ident >, field_types : impl macro_tools::IterTrait< 'a, &'a syn::Type >, + // xxx ) -> proc_macro2::TokenStream +// where + // dyn macro_tools::IterTrait< 'a, &'a syn::Ident > : Clone, { - let params : Vec< proc_macro2::TokenStream > = field_names + // xxx : is collect required? + // let params : Vec< proc_macro2::TokenStream > = field_names + // .enumerate() + // .map(| ( index, field_name ) | + // { + // let index = index.to_string().parse::< proc_macro2::TokenStream >().unwrap(); + // qt! { #field_name : src.#index } + // }) + // .collect(); + + let field_names : Vec< _ > = field_names.collect(); // xxx + + let val_type : Vec< proc_macro2::TokenStream > = field_names.iter() + .zip( field_types ) .enumerate() - .map(| ( index, field_name ) | + .map(| ( index, ( field_name, field_type ) ) | { let index = index.to_string().parse::< proc_macro2::TokenStream >().unwrap(); - qt! { #field_name : src.#index } + qt! { #field_name : #field_type } }) .collect(); - let field_types : Vec< _ > = field_types.collect(); + // let field_types : Vec< _ > = field_types.collect(); qt! { // impl StructNamedFields @@ -250,10 +266,10 @@ fn generate_multiple_fields_named< 'a > { #[ inline( always ) ] // fn new( src : ( i32, bool ) ) -> Self - fn new( src : ( #( #field_types ),* ) ) -> Self + fn new( #( #val_type ),* ) -> Self { // StructNamedFields{ a : src.0, b : src.1 } - #item_name { #(#params),* } + #item_name { #( #field_names ),* } } } } diff --git a/module/core/macro_tools/src/item_struct.rs b/module/core/macro_tools/src/item_struct.rs index 6404e000c0..f00aa307c1 100644 --- a/module/core/macro_tools/src/item_struct.rs +++ b/module/core/macro_tools/src/item_struct.rs @@ -15,10 +15,8 @@ pub( crate ) mod private } /// Retrieves the names of each field, if they exist. - // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< impl IterTrait< 'a, &'a syn::Ident > + 'a > pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< Box< dyn IterTrait< 'a, &'a syn::Ident > + '_ > > - // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< Box< dyn IterTrait< 'a, syn::Ident > + '_ > > - // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> impl IterTrait< 'a, syn::Ident > + // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< DynIter< 'a, syn::Ident > > { match &t.fields { diff --git a/module/core/macro_tools/src/iter.rs b/module/core/macro_tools/src/iter.rs index 59d4d614f3..5ebae1668f 100644 --- a/module/core/macro_tools/src/iter.rs +++ b/module/core/macro_tools/src/iter.rs @@ -20,22 +20,121 @@ pub( crate ) mod private T : 'a, Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, { - // fn clone_box( &self ) -> Box< dyn IterTrait< 'a, T > + 'a >; + // fn clone_box( self ) -> Box< dyn IterTrait< 'a, T > + 'a >; } impl< 'a, T, I > IterTrait< 'a, T > for I where T : 'a, - Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator // + Clone, + I : 'a, + Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, { - // fn clone_box( &self ) -> Box< dyn IterTrait< 'a, T > + 'a > + // fn clone_box( self ) -> Box< dyn IterTrait< 'a, T > + 'a > // { - // Box::new( self.clone() ) + // Box::new( self ).clone() // } } + pub trait IterTraitClonable< 'a, T > + where + T : 'a, + Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator + Clone, + { + // fn clone_box( self ) -> Box< dyn IterTraitClonable< 'a, T > + 'a >; + } + + impl< 'a, T, I > IterTraitClonable< 'a, T > for I + where + T : 'a, + I : 'a, + Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator + Clone, + { + + // fn clone_box( self ) -> Box< dyn IterTraitClonable< 'a, T > + 'a > + // { + // Box::new( self ).clone() + // } + + } + + pub struct DynIter< 'a, T >( Box< dyn IterTrait< 'a, &'a T > > ); + + impl< 'a, T > core::ops::Deref for DynIter< 'a, T > + { + type Target = Box< dyn IterTrait< 'a, &'a T > >; + fn deref( &self ) -> &Self::Target + { + &self.0 + } + } + + impl< 'a, T > core::convert::AsRef< Box< dyn IterTrait< 'a, &'a T > > > for DynIter< 'a, T > + { + fn as_ref( &self ) -> &Box< dyn IterTrait< 'a, &'a T > > + { + &self.0 + } + } + + impl< 'a, T > From< Box< dyn IterTrait< 'a, &'a T > > > for DynIter< 'a, T > + where + { + fn from( src : Box< dyn IterTrait< 'a, &'a T > > ) -> Self + { + Self( src ) + } + } + + impl< 'a, T > Iterator for DynIter< 'a, T > + { + type Item = & 'a T; + + fn next( & mut self ) -> Option< Self::Item > + { + self.0.next() + } + } + + impl< 'a, T > ExactSizeIterator for DynIter< 'a, T > + { + fn len( & self ) -> usize + { + self.0.len() + } + } + + impl< 'a, T > DoubleEndedIterator for DynIter< 'a, T > + { + fn next_back( & mut self ) -> Option< Self::Item > + { + self.0.next_back() + } + } + +// pub trait IterTrait< 'a, T > +// where +// T : 'a, +// Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator + Clone, +// { +// // fn clone_box( self ) -> Box< dyn IterTrait< 'a, T > + 'a >; +// } +// +// impl< 'a, T, I > IterTrait< 'a, T > for I +// where +// T : 'a, +// I : 'a, +// Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator + Clone, +// { +// +// // fn clone_box( self ) -> Box< dyn IterTrait< 'a, T > + 'a > +// // { +// // Box::new( self ).clone() +// // } +// +// } + // /// Trait that encapsulates an iterator with specific characteristics, tailored for use with the `syn` crate. // /// // /// The `IterTrait2` trait is designed to represent iterators that yield references to items (`&'a T`) within the `syn` crate. @@ -115,6 +214,8 @@ pub mod exposed pub use super::private:: { IterTrait, + IterTraitClonable, + DynIter, // IterTrait2, // IterTrait3, }; From ca82483c31064a360646d4657c3d82b5be9ab350 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 1 Jun 2024 16:18:16 +0300 Subject: [PATCH 05/45] former : better description, avoiding confusing mentioning Former trait --- module/core/former/Cargo.toml | 2 +- module/core/former/Readme.md | 42 ++++++++++++------- .../examples/former_collection_hashmap.rs | 2 +- .../examples/former_collection_hashset.rs | 2 +- .../examples/former_collection_vector.rs | 2 +- .../examples/former_custom_scalar_setter.rs | 2 +- .../former_custom_subform_collection.rs | 2 +- .../examples/former_custom_subform_entry.rs | 2 +- .../examples/former_custom_subform_entry2.rs | 2 +- .../examples/former_custom_subform_scalar.rs | 2 +- module/core/former/examples/former_trivial.rs | 17 +------- .../former/examples/former_trivial_expaned.rs | 18 ++------ 12 files changed, 41 insertions(+), 54 deletions(-) diff --git a/module/core/former/Cargo.toml b/module/core/former/Cargo.toml index 746331fb21..400646fd00 100644 --- a/module/core/former/Cargo.toml +++ b/module/core/former/Cargo.toml @@ -12,7 +12,7 @@ documentation = "https://docs.rs/former" repository = "https://github.com/Wandalen/wTools/tree/master/module/core/former" homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/former" description = """ -A flexible and extensible implementation of the builder pattern. +A flexible implementation of the Builder pattern supporting nested builders and collection-specific subformers. """ categories = [ "algorithms", "development-tools" ] keywords = [ "fundamental", "general-purpose", "builder-pattern" ] diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 966ec2f65d..40992b6116 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -5,19 +5,29 @@ [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_former_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_former_push.yml) [![docs.rs](https://img.shields.io/docsrs/former?color=e3e8f0&logo=docs.rs)](https://docs.rs/former) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fformer%2Fexamples%2Fformer_trivial.rs,RUN_POSTFIX=--example%20former_trivial/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) -A flexible and extensible implementation of the builder pattern. +A flexible implementation of the Builder pattern supporting nested builders and collection-specific subformers. -It offers specialized subformers for common Rust collections like `Vec`, `HashMap`, and `HashSet`, enabling the construction of complex data structures in a fluent and intuitive manner. +The Builder pattern allows you to construct objects step by step, using only the steps you need. Any fields not explicitly set will receive default values. By implementing this pattern, you can avoid passing numerous parameters into your constructors. + +This crate offers specialized subformers for common Rust collections, enabling the construction of complex data structures in a fluent and intuitive manner. Additionally, it provides the ability to define and reuse formers as subformers within other formers. ## 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. +- **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. +- **Subforming**: If a field has its own former defined or is a container of items for which a former is defined, it can be used as a subformer. + +This approach abstracts away the need for manually implementing a builder for each struct, making the code more readable and maintainable. + +## Comparison + +The Former crate and the abstract Builder pattern concept share a common goal: to construct complex objects step-by-step, ensuring they are always in a valid state and hiding internal structures. Both use a fluent interface for setting fields and support default values for fields that aren't explicitly set. They also have a finalization method to return the constructed object (.form() in Former, build() in [traditional Builder](https://refactoring.guru/design-patterns/builder)). + +However, the Former crate extends the traditional Builder pattern by automating the generation of builder methods using macros. This eliminates the need for manual implementation, which is often required in the abstract concept. Additionally, Former supports nested builders and subformers for complex data structures, allowing for more sophisticated object construction. -This approach abstracts away the need for manually implementing a builder for each struct, making code more readable and maintainable. +Advanced features such as custom setters, subformer reuse, storage-specific fields, mutators, and context management further differentiate Former from the [traditional approach](https://refactoring.guru/design-patterns/builder), which generally focuses on simpler use-cases without these capabilities. Moreover, while the traditional Builder pattern often includes a director class to manage the construction process, Former is not responsible for that aspect. ## Example : Trivial @@ -28,7 +38,7 @@ This approach abstracts away the need for manually implementing a builder for ea -The provided code snippet illustrates a basic use-case of the Former, which is used to apply the builder pattern for structured and flexible object creation. Below is a detailed explanation of each part of the markdown chapter, aimed at clarifying how the Former trait simplifies struct instantiation. +The provided code snippet illustrates a basic use-case of the Former, which is used to apply the builder pattern for to construct complex objects step-by-step, ensuring they are always in a valid state and hiding internal structures. ```rust # #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] @@ -674,7 +684,7 @@ These setters ensure that developers can precisely and efficiently set propertie ## Example : Collection Setter for a Vector -This example demonstrates how to employ the `Former` trait to configure a `Vec` using a collection setter in a structured manner. +This example demonstrates how to employ the `Former` to configure a `Vec` using a collection setter in a structured manner. ```rust # #[ cfg( not( all( feature = "enabled", feature = "derive_former", any( feature = "use_alloc", not( feature = "no_std" ) ) ) ) ) ] @@ -710,7 +720,7 @@ Try out `cargo run --example former_collection_vector`. ## Example : Collection Setter for a Hashmap -This example demonstrates how to effectively employ the `Former` trait to configure a `HashMap` using a collection setter. +This example demonstrates how to effectively employ the `Former` to configure a `HashMap` using a collection setter. ```rust # #[ cfg( not( all( feature = "enabled", feature = "derive_former", any( feature = "use_alloc", not( feature = "no_std" ) ) ) ) ) ] @@ -747,7 +757,7 @@ Try out `cargo run --example former_collection_hashmap`. ## Example : Collection Setter for a Hashset -This example demonstrates the use of the `Former` trait to build a `collection_tools::HashSet` through subforming. +This example demonstrates the use of the `Former` to build a `collection_tools::HashSet` through subforming. ```rust # #[ cfg( not( all( feature = "enabled", feature = "derive_former", any( feature = "use_alloc", not( feature = "no_std" ) ) ) ) ) ] @@ -784,7 +794,7 @@ Try out `cargo run --example former_collection_hashset`. ## Example : Custom Scalar Setter -This example demonstrates the implementation of a scalar setter using the `Former` trait. Unlike the more complex subform and collection setters shown in previous examples, this example focuses on a straightforward approach to directly set a scalar value within a parent entity. The `Parent` struct manages a `HashMap` of `Child` entities, and the scalar setter is used to set the entire `HashMap` directly. +This example demonstrates the implementation of a scalar setter using the `Former`. Unlike the more complex subform and collection setters shown in previous examples, this example focuses on a straightforward approach to directly set a scalar value within a parent entity. The `Parent` struct manages a `HashMap` of `Child` entities, and the scalar setter is used to set the entire `HashMap` directly. The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a collection—each child entity in this case. @@ -870,7 +880,7 @@ Try out `cargo run --example former_custom_scalar_setter`. ## Example : Custom Subform Scalar Setter -Implementation of a custom subform scalar setter using the `Former` trait in Rust. +Implementation of a custom subform scalar setter using the `Former`. This example focuses on the usage of a subform scalar setter to manage complex scalar types within a parent structure. Unlike more general subform setters that handle collections, this setter specifically configures scalar fields that have @@ -945,7 +955,7 @@ their own formers, allowing for detailed configuration within a nested builder p ## Example : Custom Subform Collection Setter -This example demonstrates the use of collection setters to manage complex nested data structures with the `Former` trait, focusing on a parent-child relationship structured around a collection `HashMap`. Unlike typical builder patterns that add individual elements using subform setters, this example uses a collection setter to manage the entire collection of children. +This example demonstrates the use of collection setters to manage complex nested data structures with the `Former`, focusing on a parent-child relationship structured around a collection `HashMap`. Unlike typical builder patterns that add individual elements using subform setters, this example uses a collection setter to manage the entire collection of children. The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a collection—each child entity in this case. @@ -1026,7 +1036,7 @@ Try out `cargo run --example former_custom_subform_collection`. ## Example : Custom Subform Entry Setter -This example illustrates the implementation of nested builder patterns using the `Former` trait, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. +This example illustrates the implementation of nested builder patterns using the `Former`, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a collection—each child entity in this case. diff --git a/module/core/former/examples/former_collection_hashmap.rs b/module/core/former/examples/former_collection_hashmap.rs index 93b7ea3526..81380c81f3 100644 --- a/module/core/former/examples/former_collection_hashmap.rs +++ b/module/core/former/examples/former_collection_hashmap.rs @@ -1,5 +1,5 @@ //! -//! This example demonstrates how to effectively employ the `Former` trait to configure a `HashMap` using a collection setter. +//! This example demonstrates how to effectively employ the `Former` to configure a `HashMap` using a collection setter. //! #[ cfg( not( all( feature = "enabled", feature = "derive_former", any( feature = "use_alloc", not( feature = "no_std" ) ) ) ) ) ] diff --git a/module/core/former/examples/former_collection_hashset.rs b/module/core/former/examples/former_collection_hashset.rs index 81c81f604f..1eda3a38e8 100644 --- a/module/core/former/examples/former_collection_hashset.rs +++ b/module/core/former/examples/former_collection_hashset.rs @@ -1,5 +1,5 @@ //! -//! This example demonstrates the use of the `Former` trait to build a `collection_tools::HashSet` through subforming. +//! This example demonstrates the use of the `Former` to build a `collection_tools::HashSet` through subforming. //! #[ cfg( not( all( feature = "enabled", feature = "derive_former", any( feature = "use_alloc", not( feature = "no_std" ) ) ) ) ) ] diff --git a/module/core/former/examples/former_collection_vector.rs b/module/core/former/examples/former_collection_vector.rs index b51b4fa378..cb8ff724d7 100644 --- a/module/core/former/examples/former_collection_vector.rs +++ b/module/core/former/examples/former_collection_vector.rs @@ -1,5 +1,5 @@ //! -//! This example demonstrates how to employ the `Former` trait to configure a `Vec` using a collection setter in a structured manner. +//! This example demonstrates how to employ the `Former` to configure a `Vec` using a collection setter in a structured manner. //! #[ cfg( not( all( feature = "enabled", feature = "derive_former", any( feature = "use_alloc", not( feature = "no_std" ) ) ) ) ) ] diff --git a/module/core/former/examples/former_custom_scalar_setter.rs b/module/core/former/examples/former_custom_scalar_setter.rs index 753adcc618..13a90a4fef 100644 --- a/module/core/former/examples/former_custom_scalar_setter.rs +++ b/module/core/former/examples/former_custom_scalar_setter.rs @@ -2,7 +2,7 @@ //! ## Example : Custom Scalar Setter //! -//! Use of a scalar setter within a `Former` trait implementation to directly assign a `HashMap` of `Child` entities to a `Parent` structure using a custom setter function. +//! Use of a scalar setter within a `Former` implementation to directly assign a `HashMap` of `Child` entities to a `Parent` structure using a custom setter function. //! //! Unlike the more complex subform and collection setters shown in previous examples, this example focuses on a straightforward approach to directly set a scalar value within a parent entity. The `Parent` struct manages a `HashMap` of `Child` entities, and the scalar setter is used to set the entire `HashMap` directly. The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a collection—each child entity in this case. //! diff --git a/module/core/former/examples/former_custom_subform_collection.rs b/module/core/former/examples/former_custom_subform_collection.rs index f0de7350a0..e2012c04f8 100644 --- a/module/core/former/examples/former_custom_subform_collection.rs +++ b/module/core/former/examples/former_custom_subform_collection.rs @@ -3,7 +3,7 @@ //! //! ## Example : Custom Subform Collection Setter //! -//! This example demonstrates the use of collection setters to manage complex nested data structures with the `Former` trait, focusing on a parent-child relationship structured around a collection `HashMap`. Unlike typical builder patterns that add individual elements using subform setters, this example uses a collection setter to manage the entire collection of children. +//! This example demonstrates the use of collection setters to manage complex nested data structures with the `Former`, focusing on a parent-child relationship structured around a collection `HashMap`. Unlike typical builder patterns that add individual elements using subform setters, this example uses a collection setter to manage the entire collection of children. //! //! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a collection—each child entity in this case. //! diff --git a/module/core/former/examples/former_custom_subform_entry.rs b/module/core/former/examples/former_custom_subform_entry.rs index e046434da8..5b70161373 100644 --- a/module/core/former/examples/former_custom_subform_entry.rs +++ b/module/core/former/examples/former_custom_subform_entry.rs @@ -2,7 +2,7 @@ //! ## Example : Custom Subform Entry Setter //! -//! This example illustrates the implementation of nested builder patterns using the `Former` trait, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. +//! This example illustrates the implementation of nested builder patterns using the `Former`, emphasizing a parent-child relationship. Here, the `Parent` struct utilizes `ChildFormer` as a custom subformer to dynamically manage its `child` field—a `HashMap`. Each child in the `HashMap` is uniquely identified and configured via the `ChildFormer`. //! //! The `child` function within `ParentFormer` is a custom subform setter that plays a crucial role. It uniquely employs the `ChildFormer` to add and configure children by their names within the parent's builder pattern. This method demonstrates a powerful technique for integrating subformers that manage specific elements of a collection—each child entity in this case. //! diff --git a/module/core/former/examples/former_custom_subform_entry2.rs b/module/core/former/examples/former_custom_subform_entry2.rs index c4592ee34f..b8199fb36c 100644 --- a/module/core/former/examples/former_custom_subform_entry2.rs +++ b/module/core/former/examples/former_custom_subform_entry2.rs @@ -1,7 +1,7 @@ // Example former_custom_subformer2.rs //! -//! This example extends the demonstration of nested builder patterns using the `Former` trait, highlighting a parent-child relationship similar to the `former_custom_subformer.rs`. However, this variant, `former_custom_subformer2.rs`, showcases a more flexible but complex approach to managing the `child` field in the `Parent` struct—a `HashMap` of `Child` entities. Instead of relying on a predefined subformer setter (`_child_subform_entry`), this example constructs the subformer logic directly using closures. This method provides greater control over how children are added and managed within the `Parent`. +//! This example extends the demonstration of nested builder patterns using the `Former`, highlighting a parent-child relationship similar to the `former_custom_subformer.rs`. However, this variant, `former_custom_subformer2.rs`, showcases a more flexible but complex approach to managing the `child` field in the `Parent` struct—a `HashMap` of `Child` entities. Instead of relying on a predefined subformer setter (`_child_subform_entry`), this example constructs the subformer logic directly using closures. This method provides greater control over how children are added and managed within the `Parent`. //! //! #### Custom Subform Setter //! diff --git a/module/core/former/examples/former_custom_subform_scalar.rs b/module/core/former/examples/former_custom_subform_scalar.rs index 7bb0eb97cd..436cbea3e9 100644 --- a/module/core/former/examples/former_custom_subform_scalar.rs +++ b/module/core/former/examples/former_custom_subform_scalar.rs @@ -3,7 +3,7 @@ //! //! ## Example : Custom Subform Scalar Setter //! -//! Implementation of a custom subform scalar setter using the `Former` trait in Rust. +//! Implementation of a custom subform scalar setter using the `Former`. //! //! This example focuses on the usage of a subform scalar setter to manage complex scalar types within a parent structure. //! Unlike more general subform setters that handle collections, this setter specifically configures scalar fields that have diff --git a/module/core/former/examples/former_trivial.rs b/module/core/former/examples/former_trivial.rs index b330278f68..3d19f12dd6 100644 --- a/module/core/former/examples/former_trivial.rs +++ b/module/core/former/examples/former_trivial.rs @@ -1,19 +1,6 @@ -//! # Builder Pattern Implementation with Former +//! ## Example : Trivial //! -//! 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. +//! The provided code snippet illustrates a basic use-case of the Former, which is used to apply the builder pattern for to construct complex objects step-by-step, ensuring they are always in a valid state and hiding internal structures. //! #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] diff --git a/module/core/former/examples/former_trivial_expaned.rs b/module/core/former/examples/former_trivial_expaned.rs index 4968b11838..a2e557bedf 100644 --- a/module/core/former/examples/former_trivial_expaned.rs +++ b/module/core/former/examples/former_trivial_expaned.rs @@ -1,20 +1,10 @@ #![ allow( dead_code ) ] -//! # Builder Pattern Implementation with Former -//! -//! This module demonstrates the use of the `Former` trait to apply the builder pattern for Rust structs. -//! 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 + +//! ## Example : Trivial //! -//! - **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. +//! The provided code snippet illustrates a basic use-case of the Former, which is used to apply the builder pattern for to construct complex objects step-by-step, ensuring they are always in a valid state and hiding internal structures. //! -//! This approach abstracts away the need for manually implementing a builder for each struct, making code more readable and maintainable. +//! It's generated by macros code. //! #[ cfg( any( not( feature = "derive_former" ), not( feature = "enabled" ) ) ) ] From 82cbf47dca2bf117bcf288eefd839c0c52a5d7f6 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 1 Jun 2024 16:18:52 +0300 Subject: [PATCH 06/45] derive_tools : evolving derive new --- .../core/derive_tools_meta/src/derive/from.rs | 15 ++- .../core/derive_tools_meta/src/derive/new.rs | 30 ++---- .../former_meta/src/derive_former/field.rs | 2 +- module/core/former_types/src/definition.rs | 2 +- module/core/former_types/src/storage.rs | 2 +- module/core/macro_tools/src/item_struct.rs | 10 +- module/core/macro_tools/src/iter.rs | 93 ++++++++++++++----- module/core/macro_tools/src/struct_like.rs | 10 +- 8 files changed, 94 insertions(+), 70 deletions(-) diff --git a/module/core/derive_tools_meta/src/derive/from.rs b/module/core/derive_tools_meta/src/derive/from.rs index 65334d453d..2e375e5d86 100644 --- a/module/core/derive_tools_meta/src/derive/from.rs +++ b/module/core/derive_tools_meta/src/derive/from.rs @@ -262,7 +262,7 @@ fn generate_single_field_named /// #[ derive( From ) ] /// pub struct IsTransparent( bool ); /// ``` -/// +/// /// ## Output /// ```rust /// pub struct IsTransparent( bool ); @@ -348,21 +348,21 @@ fn generate_multiple_fields_named< 'a > generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_where: &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - field_names : Box< dyn macro_tools::IterTrait< 'a, &'a syn::Ident > + '_ >, + field_names : impl macro_tools::IterTrait< 'a, &'a syn::Ident >, field_types : impl macro_tools::IterTrait< 'a, &'a syn::Type >, ) -> proc_macro2::TokenStream { - let params : Vec< proc_macro2::TokenStream > = field_names + let params = field_names .enumerate() .map(| ( index, field_name ) | { let index = index.to_string().parse::< proc_macro2::TokenStream >().unwrap(); qt! { #field_name : src.#index } - }) - .collect(); + }); + // xxx : qqq : rid off collects let field_types : Vec< _ > = field_types.collect(); qt! { @@ -417,13 +417,12 @@ fn generate_multiple_fields< 'a > -> proc_macro2::TokenStream { - let params : Vec< proc_macro2::TokenStream > = ( 0..field_types.len() ) + let params = ( 0..field_types.len() ) .map( | index | { let index = index.to_string().parse::< proc_macro2::TokenStream >().unwrap(); qt!( src.#index ) - }) - .collect(); + }); let field_types : Vec< _ > = field_types.collect(); diff --git a/module/core/derive_tools_meta/src/derive/new.rs b/module/core/derive_tools_meta/src/derive/new.rs index d1947c6730..af9a1f8645 100644 --- a/module/core/derive_tools_meta/src/derive/new.rs +++ b/module/core/derive_tools_meta/src/derive/new.rs @@ -227,36 +227,21 @@ fn generate_multiple_fields_named< 'a > generics_where: &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, field_names : impl macro_tools::IterTrait< 'a, &'a syn::Ident >, field_types : impl macro_tools::IterTrait< 'a, &'a syn::Type >, - // xxx ) -> proc_macro2::TokenStream -// where - // dyn macro_tools::IterTrait< 'a, &'a syn::Ident > : Clone, { - // xxx : is collect required? - // let params : Vec< proc_macro2::TokenStream > = field_names - // .enumerate() - // .map(| ( index, field_name ) | - // { - // let index = index.to_string().parse::< proc_macro2::TokenStream >().unwrap(); - // qt! { #field_name : src.#index } - // }) - // .collect(); + let field_names : Vec< _ > = field_names.collect(); // xxx : qqq : rid off collects - let field_names : Vec< _ > = field_names.collect(); // xxx - - let val_type : Vec< proc_macro2::TokenStream > = field_names.iter() + let val_type = field_names.iter() .zip( field_types ) .enumerate() .map(| ( index, ( field_name, field_type ) ) | { - let index = index.to_string().parse::< proc_macro2::TokenStream >().unwrap(); + // let index = index.to_string().parse::< proc_macro2::TokenStream >().unwrap(); qt! { #field_name : #field_type } - }) - .collect(); + }); - // let field_types : Vec< _ > = field_types.collect(); qt! { // impl StructNamedFields @@ -289,15 +274,12 @@ fn generate_multiple_fields< 'a > -> proc_macro2::TokenStream { - let params : Vec< proc_macro2::TokenStream > = ( 0..field_types.len() ) + let params = ( 0..field_types.len() ) .map( | index | { let index = index.to_string().parse::< proc_macro2::TokenStream >().unwrap(); qt!( src.#index ) - }) - .collect(); - - let field_types : Vec< _ > = field_types.collect(); + }); qt! { diff --git a/module/core/former_meta/src/derive_former/field.rs b/module/core/former_meta/src/derive_former/field.rs index 13a702b308..7135d9370a 100644 --- a/module/core/former_meta/src/derive_former/field.rs +++ b/module/core/former_meta/src/derive_former/field.rs @@ -1040,7 +1040,7 @@ preformed elements to this storage. # Type Parameters -- `Types2`: Represents the specific types associated with the `Former` trait being applied, +- `Types2`: Represents the specific types associated with the `Former` being applied, which include storage, formed type, and context. - `Definition`: Defines the `FormerDefinition` that outlines the storage structure and the end conditions for the formation process. diff --git a/module/core/former_types/src/definition.rs b/module/core/former_types/src/definition.rs index 38563df0e8..3605ddef0c 100644 --- a/module/core/former_types/src/definition.rs +++ b/module/core/former_types/src/definition.rs @@ -90,7 +90,7 @@ pub trait FormerDefinition : Sized type Storage : Default; /// The type of the entity being formed. It is - /// generally the structure for which the `Former` trait is derived, representing the fully formed + /// generally the structure for which the `Former` is derived, representing the fully formed /// state of the entity. However, it can differ if a custom `FormingEnd` or a different `Formed` type /// is defined to handle specific forming logic or requirements. type Formed; diff --git a/module/core/former_types/src/storage.rs b/module/core/former_types/src/storage.rs index 02e20e78d5..8b37f0e654 100644 --- a/module/core/former_types/src/storage.rs +++ b/module/core/former_types/src/storage.rs @@ -30,7 +30,7 @@ pub trait Storage : ::core::default::Default /// This trait is crucial for transitioning the mutable, intermediate storage state into the final, /// immutable state of an entity. The transformation is typically performed once all configurations /// and modifications are applied to the storage during the forming process. The type `Preformed` and `Formed` is -/// generally the structure for which the `Former` trait is derived, representing the fully formed +/// generally the structure for which the `Former` is derived, representing the fully formed /// state of the entity. However, it can differ if a custom `FormingEnd` or a different `Formed` type /// is defined to handle specific forming logic or requirements. /// But even if `Formed` is custom `Preformed` is always that structure. diff --git a/module/core/macro_tools/src/item_struct.rs b/module/core/macro_tools/src/item_struct.rs index f00aa307c1..50b1318866 100644 --- a/module/core/macro_tools/src/item_struct.rs +++ b/module/core/macro_tools/src/item_struct.rs @@ -15,13 +15,15 @@ pub( crate ) mod private } /// Retrieves the names of each field, if they exist. - pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< Box< dyn IterTrait< 'a, &'a syn::Ident > + '_ > > - // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< DynIter< 'a, syn::Ident > > + // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< Box< dyn IterTrait< 'a, &'a syn::Ident > + '_ > > + pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< DynIter< 'a, syn::Ident > > { match &t.fields { - syn::Fields::Named( fields ) => Some( Box::new( fields.named.iter().map( | field | field.ident.as_ref().unwrap() ) ) ), - syn::Fields::Unit => Some( Box::new( core::iter::empty() ) ), + // syn::Fields::Named( fields ) => Some( Box::new( fields.named.iter().map( | field | field.ident.as_ref().unwrap() ) ) ), + // syn::Fields::Unit => Some( Box::new( core::iter::empty() ) ), + syn::Fields::Named( fields ) => Some( DynIter::new( fields.named.iter().map( | field | field.ident.as_ref().unwrap() ) ) ), + syn::Fields::Unit => Some( DynIter::new( core::iter::empty() ) ), _ => None, } } diff --git a/module/core/macro_tools/src/iter.rs b/module/core/macro_tools/src/iter.rs index 5ebae1668f..f4b5fcbfc9 100644 --- a/module/core/macro_tools/src/iter.rs +++ b/module/core/macro_tools/src/iter.rs @@ -2,9 +2,13 @@ //! Iterators. //! +// use std::fmt::Debug; + /// Internal namespace. pub( crate ) mod private { + use std::fmt; + // use crate::*; /// Trait that encapsulates an iterator with specific characteristics, tailored for use with the `syn` crate. @@ -20,7 +24,6 @@ pub( crate ) mod private T : 'a, Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, { - // fn clone_box( self ) -> Box< dyn IterTrait< 'a, T > + 'a >; } impl< 'a, T, I > IterTrait< 'a, T > for I @@ -29,61 +32,100 @@ pub( crate ) mod private I : 'a, Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, { - - // fn clone_box( self ) -> Box< dyn IterTrait< 'a, T > + 'a > - // { - // Box::new( self ).clone() - // } - } + /// Trait that encapsulates a clonable iterator with specific characteristics, tailored for use with the `syn` crate. + /// + /// The `IterTraitClonable` trait is designed to represent iterators that may yield references to items (`&'a T`) within the `syn` crate. + /// These iterators must also implement the `ExactSizeIterator`, `DoubleEndedIterator`, and `Clone` traits. + /// This combination ensures that the iterator can: + /// - Provide an exact size hint (`ExactSizeIterator`), + /// - Be traversed from both ends (`DoubleEndedIterator`), + /// - Be clonable (`Clone`). + /// pub trait IterTraitClonable< 'a, T > where T : 'a, Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator + Clone, { - // fn clone_box( self ) -> Box< dyn IterTraitClonable< 'a, T > + 'a >; } impl< 'a, T, I > IterTraitClonable< 'a, T > for I where T : 'a, - I : 'a, Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator + Clone, { + } - // fn clone_box( self ) -> Box< dyn IterTraitClonable< 'a, T > + 'a > - // { - // Box::new( self ).clone() - // } + /// Wrapper around a boxed iterator that implements `IterTrait`. + /// + /// The `DynIter` struct provides a way to work with trait objects that implement the `IterTrait` trait. It acts as a + /// wrapper around a boxed iterator and provides methods to interact with the iterator in a type-safe manner. + /// + /// # Examples + /// + /// ```rust + /// use crate::DynIter; + /// use std::vec::Vec; + /// + /// let v = vec![1, 2, 3]; + /// let iter = DynIter::new(v.iter()); + /// for val in iter { + /// println!("{}", val); + /// } + /// ``` + pub struct DynIter< 'a, T >( Box< dyn IterTrait< 'a, & 'a T > + 'a > ); + impl< 'a, T > fmt::Debug for DynIter< 'a, T > + { + fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result + { + f.write_fmt( format_args!( "DynIter" ) ) + } } - pub struct DynIter< 'a, T >( Box< dyn IterTrait< 'a, &'a T > > ); + impl< 'a, T > DynIter< 'a, T > + { + /// Creates a new `DynIter` from an iterator that implements `IterTrait`. + /// + /// # Parameters + /// + /// - `src`: The source iterator to be wrapped. + /// + /// # Returns + /// + /// A new instance of `DynIter`. + pub fn new< It >( src : It ) -> Self + where + It : IterTrait< 'a, & 'a T > + 'a, + { + Self( Box::new( src ) ) + } + } - impl< 'a, T > core::ops::Deref for DynIter< 'a, T > + impl< 'a, T > From< DynIter< 'a, T > > for Box< dyn IterTrait< 'a, & 'a T > + 'a > { - type Target = Box< dyn IterTrait< 'a, &'a T > >; - fn deref( &self ) -> &Self::Target + fn from( src : DynIter< 'a, T > ) -> Self { - &self.0 + src.0 } } - impl< 'a, T > core::convert::AsRef< Box< dyn IterTrait< 'a, &'a T > > > for DynIter< 'a, T > + impl< 'a, T > core::ops::Deref for DynIter< 'a, T > { - fn as_ref( &self ) -> &Box< dyn IterTrait< 'a, &'a T > > + type Target = Box< dyn IterTrait< 'a, & 'a T > + 'a >; + + fn deref( & self ) -> & Self::Target { - &self.0 + & self.0 } } - impl< 'a, T > From< Box< dyn IterTrait< 'a, &'a T > > > for DynIter< 'a, T > - where + impl< 'a, T > core::convert::AsRef< Box< dyn IterTrait< 'a, & 'a T > + 'a > > for DynIter< 'a, T > { - fn from( src : Box< dyn IterTrait< 'a, &'a T > > ) -> Self + fn as_ref( & self ) -> & Box< dyn IterTrait< 'a, & 'a T > + 'a > { - Self( src ) + & self.0 } } @@ -216,6 +258,7 @@ pub mod exposed IterTrait, IterTraitClonable, DynIter, + // DynIterFrom, // IterTrait2, // IterTrait3, }; diff --git a/module/core/macro_tools/src/struct_like.rs b/module/core/macro_tools/src/struct_like.rs index 55b90ba0eb..d95ef0f01b 100644 --- a/module/core/macro_tools/src/struct_like.rs +++ b/module/core/macro_tools/src/struct_like.rs @@ -371,10 +371,8 @@ pub( crate ) mod private } /// Extracts the name of each field. - // pub fn field_names( &self ) -> Box< dyn Iterator< Item = Option< &syn::Ident > > + '_ > - // pub fn field_names< 'a >( &'a self ) -> Box< dyn IterTrait< 'a, Option< &'a syn::Ident > > + '_ > - // pub fn field_names< 'a >( &'a self ) -> Option< Box< dyn IterTrait< 'a, &'a syn::Ident > + '_ > > - pub fn field_names< 'a >( &'a self ) -> Option< impl IterTrait< 'a, &'a syn::Ident > + '_ > + // pub fn field_names< 'a >( &'a self ) -> Option< impl IterTrait< 'a, &'a syn::Ident > + '_ > + pub fn field_names< 'a >( &'a self ) -> Option< DynIter< 'a, syn::Ident > > { match self { @@ -388,11 +386,11 @@ pub( crate ) mod private }, StructLike::Enum( _item ) => { - Some( Box::new( self.fields().map( | field | field.ident.as_ref().unwrap() ) ) ) + Some( DynIter::new( self.fields().map( | field | field.ident.as_ref().unwrap() ) ) ) + // Some( DynIterFrom::dyn_iter_from( self.fields().map( | field | field.ident.as_ref().unwrap() ) ) ) // Box::new( std::iter::empty() ) }, } - // Box::new( self.fields().map( | field | field.ident.as_ref() ) ) } From 8754d786836156da8fe75f1deeb037f2c91686cf Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 1 Jun 2024 16:19:21 +0300 Subject: [PATCH 07/45] former_types-v2.3.0 --- Cargo.toml | 2 +- module/core/former_types/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4e75221932..cb4ca41d7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -215,7 +215,7 @@ path = "module/core/former_meta" default-features = false [workspace.dependencies.former_types] -version = "~2.2.0" +version = "~2.3.0" path = "module/core/former_types" default-features = false diff --git a/module/core/former_types/Cargo.toml b/module/core/former_types/Cargo.toml index d6b6ca5fb3..5bdd81e4c0 100644 --- a/module/core/former_types/Cargo.toml +++ b/module/core/former_types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former_types" -version = "2.2.0" +version = "2.3.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From bfd819712e70d008ce6776ab289b7030a7712f51 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 1 Jun 2024 16:19:36 +0300 Subject: [PATCH 08/45] macro_tools-v0.29.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 cb4ca41d7c..1c33b7de47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -260,7 +260,7 @@ default-features = false ## macro tools [workspace.dependencies.macro_tools] -version = "~0.28.0" +version = "~0.29.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 7b960db025..e7bc4d0e13 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.28.0" +version = "0.29.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From f1e74ea501af043118e53644f45bd8d3a0a30aad Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 1 Jun 2024 21:24:30 +0300 Subject: [PATCH 09/45] experimenting with deps --- Cargo.toml | 8 ++++---- module/core/former_meta/Cargo.toml | 6 +++--- module/core/former_meta/Readme.md | 2 +- module/core/former_types/Cargo.toml | 2 +- module/core/former_types/Readme.md | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1c33b7de47..352d8629dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -204,10 +204,10 @@ version = "~2.2.0" path = "module/core/former" default-features = false -[workspace.dependencies.former_stable] -package = "former" -version = "=2.0.0" -default-features = false +# [workspace.dependencies.former_stable] +# package = "former" +# version = "=2.2.0" +# default-features = false [workspace.dependencies.former_meta] version = "~2.2.0" diff --git a/module/core/former_meta/Cargo.toml b/module/core/former_meta/Cargo.toml index 3e865a04a8..e6241b07b3 100644 --- a/module/core/former_meta/Cargo.toml +++ b/module/core/former_meta/Cargo.toml @@ -12,7 +12,7 @@ documentation = "https://docs.rs/former_meta" repository = "https://github.com/Wandalen/wTools/tree/master/module/core/former_meta" homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/former_meta" description = """ -Former - a variation of builder pattern. Implementation of its derive macro. Should not be used independently, instead use module::former which relies on the module. +A flexible implementation of the Builder pattern supporting nested builders and collection-specific subformers. Implementation of its derive macro. Should not be used independently, instead use module::former which relies on the module. """ categories = [ "algorithms", "development-tools" ] keywords = [ "fundamental", "general-purpose", "builder-pattern" ] @@ -57,8 +57,8 @@ derive_from_components = [ "derive_components" ] proc-macro = true [dependencies] -macro_tools = { workspace = true } # qqq : optimize set of features -former_types = { workspace = true, features = [ "enabled", "types_component_assign" ] } +macro_tools = { workspace = true } # qqq : xxx : optimize set of features +former_types = { workspace = true, features = [ "types_component_assign" ] } iter_tools = { workspace = true } convert_case = { version = "0.6.0", default-features = false, optional = true, features = [] } const_format = { version = "0.2.32" } diff --git a/module/core/former_meta/Readme.md b/module/core/former_meta/Readme.md index e7eeaec814..716940ba96 100644 --- a/module/core/former_meta/Readme.md +++ b/module/core/former_meta/Readme.md @@ -5,7 +5,7 @@ [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_former_meta_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_former_meta_push.yml) [![docs.rs](https://img.shields.io/docsrs/former_meta?color=e3e8f0&logo=docs.rs)](https://docs.rs/former_meta) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) -Former - a variation of builder pattern. Implementation of its derive macro. Should not be used independently, instead use module::former which relies on the module. +A flexible implementation of the Builder pattern supporting nested builders and collection-specific subformers. Implementation of its derive macro. Should not be used independently, instead use module::former which relies on the module. Not intended to be used without runtime. This module and runtime is aggregate in module::former is [here](https://github.com/Wandalen/wTools/tree/master/module/core/former). diff --git a/module/core/former_types/Cargo.toml b/module/core/former_types/Cargo.toml index 5bdd81e4c0..de68b49579 100644 --- a/module/core/former_types/Cargo.toml +++ b/module/core/former_types/Cargo.toml @@ -11,7 +11,7 @@ documentation = "https://docs.rs/former" repository = "https://github.com/Wandalen/wTools/tree/master/module/core/former" homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/former" description = """ -A flexible and extensible implementation of the builder pattern. Its compile-time structures and traits that are not generated but reused. +A flexible implementation of the Builder pattern supporting nested builders and collection-specific subformers. Its compile-time structures and traits that are not generated but reused. """ categories = [ "algorithms", "development-tools" ] keywords = [ "fundamental", "general-purpose", "builder-pattern" ] diff --git a/module/core/former_types/Readme.md b/module/core/former_types/Readme.md index 42346b3bc0..ac57ecfc04 100644 --- a/module/core/former_types/Readme.md +++ b/module/core/former_types/Readme.md @@ -6,7 +6,7 @@ [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_former_types_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_former_types_push.yml) [![docs.rs](https://img.shields.io/docsrs/former_types?color=e3e8f0&logo=docs.rs)](https://docs.rs/former_types) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fformer_types%2Fexamples%2Fformer_types_trivial.rs,RUN_POSTFIX=--example%20former_types_trivial/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) -A flexible and extensible implementation of the builder pattern. Its compile-time structures and traits that are not generated but reused. +A flexible implementation of the Builder pattern supporting nested builders and collection-specific subformers. Its compile-time structures and traits that are not generated but reused. ## Example: Using Trait Assign From 0025f0b02ecdffa057e597f906bdf450653ed5ef Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 1 Jun 2024 23:37:56 +0300 Subject: [PATCH 10/45] former_types-v2.4.0 --- Cargo.toml | 6 +++--- module/core/former_types/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 352d8629dc..1615bf4e72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -200,7 +200,7 @@ path = "module/core/for_each" default-features = false [workspace.dependencies.former] -version = "~2.2.0" +version = "~2.3.0" path = "module/core/former" default-features = false @@ -210,12 +210,12 @@ default-features = false # default-features = false [workspace.dependencies.former_meta] -version = "~2.2.0" +version = "~2.3.0" path = "module/core/former_meta" default-features = false [workspace.dependencies.former_types] -version = "~2.3.0" +version = "~2.4.0" path = "module/core/former_types" default-features = false diff --git a/module/core/former_types/Cargo.toml b/module/core/former_types/Cargo.toml index de68b49579..96047371a5 100644 --- a/module/core/former_types/Cargo.toml +++ b/module/core/former_types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former_types" -version = "2.3.0" +version = "2.4.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 11f61bc64348c4f457cb445f35640b9eb87f927b Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 1 Jun 2024 23:38:10 +0300 Subject: [PATCH 11/45] macro_tools-v0.30.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 1615bf4e72..008dd82f22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -260,7 +260,7 @@ default-features = false ## macro tools [workspace.dependencies.macro_tools] -version = "~0.29.0" +version = "~0.30.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 e7bc4d0e13..824ce77097 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.29.0" +version = "0.30.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 277be76dc5c994f46be669a8e3df3210443274b2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 1 Jun 2024 23:40:31 +0300 Subject: [PATCH 12/45] publishing --- module/core/former/Cargo.toml | 2 +- module/core/former_meta/Cargo.toml | 2 +- module/move/willbe/src/tool/cargo.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/module/core/former/Cargo.toml b/module/core/former/Cargo.toml index 400646fd00..812cda2467 100644 --- a/module/core/former/Cargo.toml +++ b/module/core/former/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former" -version = "2.2.0" +version = "2.3.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/core/former_meta/Cargo.toml b/module/core/former_meta/Cargo.toml index e6241b07b3..5dda6a07f7 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.2.0" +version = "2.3.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/move/willbe/src/tool/cargo.rs b/module/move/willbe/src/tool/cargo.rs index d24ac23565..96e716d8c6 100644 --- a/module/move/willbe/src/tool/cargo.rs +++ b/module/move/willbe/src/tool/cargo.rs @@ -15,7 +15,7 @@ mod private pub struct PackOptions { pub( crate ) path : PathBuf, - #[ former( default = false ) ] + #[ former( default = true ) ] pub( crate ) allow_dirty : bool, #[ former( default = false ) ] pub( crate ) no_verify : bool, From 9d8ee00b8869a78e92cb5d1d2172d07b6eda6269 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 2 Jun 2024 00:25:48 +0300 Subject: [PATCH 13/45] publishing --- Cargo.toml | 2 +- module/core/former_meta/Cargo.toml | 2 +- module/core/former_types/Cargo.toml | 2 +- module/move/willbe/src/tool/cargo.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 008dd82f22..8db5f9bf66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -215,7 +215,7 @@ path = "module/core/former_meta" default-features = false [workspace.dependencies.former_types] -version = "~2.4.0" +version = "~2.3.0" path = "module/core/former_types" default-features = false diff --git a/module/core/former_meta/Cargo.toml b/module/core/former_meta/Cargo.toml index 5dda6a07f7..5363d0dd89 100644 --- a/module/core/former_meta/Cargo.toml +++ b/module/core/former_meta/Cargo.toml @@ -66,4 +66,4 @@ const_format = { version = "0.2.32" } [dev-dependencies] test_tools = { workspace = true, features = [ "full" ] } -former = { workspace = true, features = [ "full" ] } +# former = { workspace = true, features = [ "full" ] } diff --git a/module/core/former_types/Cargo.toml b/module/core/former_types/Cargo.toml index 96047371a5..de68b49579 100644 --- a/module/core/former_types/Cargo.toml +++ b/module/core/former_types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former_types" -version = "2.4.0" +version = "2.3.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", diff --git a/module/move/willbe/src/tool/cargo.rs b/module/move/willbe/src/tool/cargo.rs index 96e716d8c6..2d28da4d96 100644 --- a/module/move/willbe/src/tool/cargo.rs +++ b/module/move/willbe/src/tool/cargo.rs @@ -17,7 +17,7 @@ mod private pub( crate ) path : PathBuf, #[ former( default = true ) ] pub( crate ) allow_dirty : bool, - #[ former( default = false ) ] + #[ former( default = true ) ] pub( crate ) no_verify : bool, pub( crate ) temp_path : Option< PathBuf >, pub( crate ) dry : bool, From 11ffe76b1b9bc2007054790140ad4097b14a46a2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 2 Jun 2024 00:27:59 +0300 Subject: [PATCH 14/45] publishing --- Cargo.toml | 2 +- module/core/former_types/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8db5f9bf66..008dd82f22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -215,7 +215,7 @@ path = "module/core/former_meta" default-features = false [workspace.dependencies.former_types] -version = "~2.3.0" +version = "~2.4.0" path = "module/core/former_types" default-features = false diff --git a/module/core/former_types/Cargo.toml b/module/core/former_types/Cargo.toml index de68b49579..96047371a5 100644 --- a/module/core/former_types/Cargo.toml +++ b/module/core/former_types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former_types" -version = "2.3.0" +version = "2.4.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From a7f8bfa9dd5924a3569e57844829417e1c53360b Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 2 Jun 2024 09:04:29 +0300 Subject: [PATCH 15/45] macro_tools : clonable iterator wip --- module/core/clone_dyn/src/lib.rs | 1 + module/core/clone_dyn/tests/inc/mod.rs | 2 +- module/core/derive_tools/Cargo.toml | 6 + module/core/derive_tools/src/lib.rs | 26 +- .../core/derive_tools_meta/src/derive/from.rs | 6 +- .../src/derive/inner_from.rs | 2 +- .../core/derive_tools_meta/src/derive/new.rs | 6 +- module/core/former/Readme.md | 2 +- .../src/component/from_components.rs | 2 +- module/core/macro_tools/src/generic_params.rs | 2 +- module/core/macro_tools/src/item_struct.rs | 20 +- module/core/macro_tools/src/iter.rs | 282 +++++++++--------- module/core/macro_tools/src/struct_like.rs | 35 ++- module/move/willbe/src/tool/cargo.rs | 4 +- 14 files changed, 199 insertions(+), 197 deletions(-) diff --git a/module/core/clone_dyn/src/lib.rs b/module/core/clone_dyn/src/lib.rs index 54e6f3ef40..7875f819bd 100644 --- a/module/core/clone_dyn/src/lib.rs +++ b/module/core/clone_dyn/src/lib.rs @@ -5,6 +5,7 @@ #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] #[ allow( unused_extern_crates ) ] +#[ cfg( feature = "enabled" ) ] #[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ] extern crate alloc; diff --git a/module/core/clone_dyn/tests/inc/mod.rs b/module/core/clone_dyn/tests/inc/mod.rs index 99cee0a3c6..57f266f8f6 100644 --- a/module/core/clone_dyn/tests/inc/mod.rs +++ b/module/core/clone_dyn/tests/inc/mod.rs @@ -9,7 +9,7 @@ tests_impls! // - // qqq : organize tests in the same way tests organized for derive_tools + // qqq2 : organize tests in the same way tests organized for derive_tools fn manual() { diff --git a/module/core/derive_tools/Cargo.toml b/module/core/derive_tools/Cargo.toml index 3f2b08fe4b..ab446e7407 100644 --- a/module/core/derive_tools/Cargo.toml +++ b/module/core/derive_tools/Cargo.toml @@ -17,14 +17,17 @@ A collection of derive macros designed to enhance STD. categories = [ "algorithms", "development-tools" ] keywords = [ "fundamental", "general-purpose" ] + [lints] workspace = true + [package.metadata.docs.rs] features = [ "full" ] all-features = false # exclude = [ "/tests", "/examples", "-*" ] + [features] default = [ @@ -176,6 +179,7 @@ derive_new = [ "derive_tools_meta/derive_new" ] parse_display = [ "parse-display" ] + [dependencies] ## external @@ -190,8 +194,10 @@ derive_tools_meta = { workspace = true, features = [] } variadic_from = { workspace = true, features = [] } clone_dyn = { workspace = true, features = [] } + [dev-dependencies] test_tools = { workspace = true } + [build-dependencies] cfg_aliases = "0.1.1" diff --git a/module/core/derive_tools/src/lib.rs b/module/core/derive_tools/src/lib.rs index d99c9c9455..42db822d27 100644 --- a/module/core/derive_tools/src/lib.rs +++ b/module/core/derive_tools/src/lib.rs @@ -87,6 +87,19 @@ pub use variadic_from as variadic; #[ cfg( feature = "enabled" ) ] pub mod dependency { + + #[ doc( inline ) ] + #[ cfg( any_derive ) ] + pub use ::derive_tools_meta; + + #[ doc( inline ) ] + #[ cfg( feature = "clone_dyn" ) ] + pub use ::clone_dyn::{ self, dependency::* }; + + #[ doc( inline ) ] + #[ cfg( any( feature = "derive_variadic_from", feature = "type_variadic_from" ) ) ] + pub use ::variadic_from::{ self, dependency::* }; + #[ doc( inline ) ] #[ cfg( feature = "derive_more" ) ] pub use ::derive_more; @@ -96,18 +109,7 @@ pub mod dependency #[ doc( inline ) ] #[ cfg( feature = "parse_display" ) ] pub use ::parse_display; - #[ doc( inline ) ] - #[ cfg( feature = "clone_dyn" ) ] - pub use ::clone_dyn; - #[ doc( inline ) ] - #[ cfg( feature = "clone_dyn" ) ] - pub use ::clone_dyn::dependency::*; - #[ doc( inline ) ] - #[ cfg( any_derive ) ] - pub use ::derive_tools_meta; - #[ doc( inline ) ] - #[ cfg( any( feature = "derive_variadic_from", feature = "type_variadic_from" ) ) ] - pub use ::variadic_from; + } #[ doc( inline ) ] diff --git a/module/core/derive_tools_meta/src/derive/from.rs b/module/core/derive_tools_meta/src/derive/from.rs index 2e375e5d86..e38040ebe2 100644 --- a/module/core/derive_tools_meta/src/derive/from.rs +++ b/module/core/derive_tools_meta/src/derive/from.rs @@ -348,8 +348,8 @@ fn generate_multiple_fields_named< 'a > generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_where: &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - field_names : impl macro_tools::IterTrait< 'a, &'a syn::Ident >, - field_types : impl macro_tools::IterTrait< 'a, &'a syn::Type >, + field_names : impl macro_tools::IterTraitClonable< 'a, &'a syn::Ident >, + field_types : impl macro_tools::IterTraitClonable< 'a, &'a syn::Type >, ) -> proc_macro2::TokenStream { @@ -412,7 +412,7 @@ fn generate_multiple_fields< 'a > generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_where: &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - field_types : impl macro_tools::IterTrait< 'a, &'a macro_tools::syn::Type >, + field_types : impl macro_tools::IterTraitClonable< 'a, &'a macro_tools::syn::Type >, ) -> proc_macro2::TokenStream { diff --git a/module/core/derive_tools_meta/src/derive/inner_from.rs b/module/core/derive_tools_meta/src/derive/inner_from.rs index 427f447087..aa78a69a42 100644 --- a/module/core/derive_tools_meta/src/derive/inner_from.rs +++ b/module/core/derive_tools_meta/src/derive/inner_from.rs @@ -194,7 +194,7 @@ fn from_impl fn from_impl_multiple_fields< 'a > ( item_name : &syn::Ident, - field_types : impl macro_tools::IterTrait< 'a, &'a macro_tools::syn::Type >, + field_types : impl macro_tools::IterTraitClonable< 'a, &'a macro_tools::syn::Type >, params : &Vec< proc_macro2::TokenStream >, ) -> proc_macro2::TokenStream { diff --git a/module/core/derive_tools_meta/src/derive/new.rs b/module/core/derive_tools_meta/src/derive/new.rs index af9a1f8645..d173b3d6f6 100644 --- a/module/core/derive_tools_meta/src/derive/new.rs +++ b/module/core/derive_tools_meta/src/derive/new.rs @@ -225,8 +225,8 @@ fn generate_multiple_fields_named< 'a > generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_where: &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - field_names : impl macro_tools::IterTrait< 'a, &'a syn::Ident >, - field_types : impl macro_tools::IterTrait< 'a, &'a syn::Type >, + field_names : impl macro_tools::IterTraitClonable< 'a, &'a syn::Ident > + Clone, // xxx + field_types : impl macro_tools::IterTraitClonable< 'a, &'a syn::Type > + Clone, // xxx ) -> proc_macro2::TokenStream { @@ -269,7 +269,7 @@ fn generate_multiple_fields< 'a > generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_where: &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - field_types : impl macro_tools::IterTrait< 'a, &'a macro_tools::syn::Type >, + field_types : impl macro_tools::IterTraitClonable< 'a, &'a macro_tools::syn::Type >, ) -> proc_macro2::TokenStream { diff --git a/module/core/former/Readme.md b/module/core/former/Readme.md index 40992b6116..d36ce4b061 100644 --- a/module/core/former/Readme.md +++ b/module/core/former/Readme.md @@ -1256,7 +1256,7 @@ Two key definition Traits: - Building upon `FormerDefinitionTypes`, this trait incorporates the `FormingEnd` callback, linking the formation types with a definitive ending. It specifies how the formation process should conclude, which may involve validations, transformations, or integrations into larger structures. - The inclusion of the `End` type parameter specifies the end conditions of the formation process, effectively connecting the temporary state held in storage to its ultimate form. -## Overview of Formation Traits +## Overview of Formation Traits System The formation process utilizes several core traits, each serving a specific purpose in the lifecycle of entity creation. These traits ensure that entities are constructed methodically, adhering to a structured pattern that enhances maintainability and scalability. Below is a summary of these key traits: diff --git a/module/core/former_meta/src/component/from_components.rs b/module/core/former_meta/src/component/from_components.rs index d76029ca0a..34c48f7c6f 100644 --- a/module/core/former_meta/src/component/from_components.rs +++ b/module/core/former_meta/src/component/from_components.rs @@ -99,7 +99,7 @@ pub fn from_components( input : proc_macro::TokenStream ) -> Result< proc_macro2 #[ inline ] // fn trait_bounds( field_types : &[ &syn::Type ] ) -> Vec< proc_macro2::TokenStream > -fn trait_bounds< 'a >( field_types : impl macro_tools::IterTrait< 'a, &'a syn::Type > ) -> Vec< proc_macro2::TokenStream > +fn trait_bounds< 'a >( field_types : impl macro_tools::IterTraitClonable< 'a, &'a syn::Type > ) -> Vec< proc_macro2::TokenStream > { field_types.map( | field_type | { diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index 09f4445e5b..71a98e113c 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -281,7 +281,7 @@ pub( crate ) mod private /// ]); /// ``` - pub fn names< 'a >( generics : &'a syn::Generics ) -> impl IterTrait< 'a, &'a syn::Ident > + Clone + pub fn names< 'a >( generics : &'a syn::Generics ) -> impl IterTraitClonable< 'a, &'a syn::Ident > + Clone { generics.params.iter().map( | param | match param { diff --git a/module/core/macro_tools/src/item_struct.rs b/module/core/macro_tools/src/item_struct.rs index 50b1318866..3b5275d9ae 100644 --- a/module/core/macro_tools/src/item_struct.rs +++ b/module/core/macro_tools/src/item_struct.rs @@ -9,23 +9,25 @@ pub( crate ) mod private /// Extracts the types of each field into a vector. // pub fn field_types< 'a >( t : &'a syn::ItemStruct ) -> impl IterTrait< 'a, &'a syn::Type > + Clone - pub fn field_types< 'a >( t : &'a syn::ItemStruct ) -> impl IterTrait< 'a, &'a syn::Type > + Clone + pub fn field_types< 'a >( t : &'a syn::ItemStruct ) -> impl IterTraitClonable< 'a, &'a syn::Type > + Clone { t.fields.iter().map( | field | &field.ty ) } /// Retrieves the names of each field, if they exist. - // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< Box< dyn IterTrait< 'a, &'a syn::Ident > + '_ > > - pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< DynIter< 'a, syn::Ident > > + pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< impl IterTraitClonable< 'a, &'a syn::Ident > > + // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< Box< dyn _IterTrait< 'a, &'a syn::Ident > + '_ > > + // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< DynIter< 'a, syn::Ident > > { - match &t.fields + let result : Option< Box< dyn _IterTrait< 'a, &'a syn::Ident > + '_ > > = match &t.fields { - // syn::Fields::Named( fields ) => Some( Box::new( fields.named.iter().map( | field | field.ident.as_ref().unwrap() ) ) ), - // syn::Fields::Unit => Some( Box::new( core::iter::empty() ) ), - syn::Fields::Named( fields ) => Some( DynIter::new( fields.named.iter().map( | field | field.ident.as_ref().unwrap() ) ) ), - syn::Fields::Unit => Some( DynIter::new( core::iter::empty() ) ), + syn::Fields::Named( fields ) => Some( Box::new( fields.named.iter().map( | field | field.ident.as_ref().unwrap() ) ) ), + syn::Fields::Unit => Some( Box::new( core::iter::empty() ) ), + // syn::Fields::Named( fields ) => Some( DynIter::new( fields.named.iter().map( | field | field.ident.as_ref().unwrap() ) ) ), + // syn::Fields::Unit => Some( DynIter::new( core::iter::empty() ) ), _ => None, - } + }; + return result; } /// Retrieves the type of the first field of the struct. diff --git a/module/core/macro_tools/src/iter.rs b/module/core/macro_tools/src/iter.rs index f4b5fcbfc9..aaf57d3086 100644 --- a/module/core/macro_tools/src/iter.rs +++ b/module/core/macro_tools/src/iter.rs @@ -13,27 +13,50 @@ pub( crate ) mod private /// Trait that encapsulates an iterator with specific characteristics, tailored for use with the `syn` crate. /// - /// The `IterTrait` trait is designed to represent iterators that may yield references to items (`&'a T`) within the `syn` crate. + /// The `_IterTrait` trait is designed to represent iterators that may yield references to items (`&'a T`) within the `syn` crate. /// These iterators must also implement the `ExactSizeIterator` and `DoubleEndedIterator` traits. /// This combination ensures that the iterator can: /// - Provide an exact size hint (`ExactSizeIterator`), /// - Be traversed from both ends (`DoubleEndedIterator`). /// - pub trait IterTrait< 'a, T > + pub trait _IterTrait< 'a, T > where T : 'a, Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, { } - impl< 'a, T, I > IterTrait< 'a, T > for I + impl< 'a, T, I > _IterTrait< 'a, T > for I where T : 'a, - I : 'a, Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, { } + pub type DynIter2< 'a, T > = Box< dyn _IterTrait< 'a, T > + 'a >; + // xxx + + impl< 'c, 'a, T > Clone + for Box< dyn _IterTrait< 'a, T > + 'c > + { + #[ inline ] + fn clone( &self ) -> Self { _clone_boxed( &**self ) } + } + + #[ inline ] + fn _clone_boxed< T >( t : &T ) -> Box< T > + where + T : ?Sized, + { + unsafe + { + let mut ptr = t as *const T; + let data_ptr = &mut ptr as *mut *const T as *mut *mut (); + *data_ptr = Box::into_raw( Box::new( t.clone() ) ) as *mut (); + Box::from_raw( ptr as *mut T ) + } + } + /// Trait that encapsulates a clonable iterator with specific characteristics, tailored for use with the `syn` crate. /// /// The `IterTraitClonable` trait is designed to represent iterators that may yield references to items (`&'a T`) within the `syn` crate. @@ -46,175 +69,137 @@ pub( crate ) mod private pub trait IterTraitClonable< 'a, T > where T : 'a, - Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator + Clone, + Self : _IterTrait< 'a, T > + Clone, { } impl< 'a, T, I > IterTraitClonable< 'a, T > for I where T : 'a, - Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator + Clone, + Self : _IterTrait< 'a, T > + Clone, { } - /// Wrapper around a boxed iterator that implements `IterTrait`. - /// - /// The `DynIter` struct provides a way to work with trait objects that implement the `IterTrait` trait. It acts as a - /// wrapper around a boxed iterator and provides methods to interact with the iterator in a type-safe manner. - /// - /// # Examples - /// - /// ```rust - /// use crate::DynIter; - /// use std::vec::Vec; - /// - /// let v = vec![1, 2, 3]; - /// let iter = DynIter::new(v.iter()); - /// for val in iter { - /// println!("{}", val); - /// } - /// ``` - pub struct DynIter< 'a, T >( Box< dyn IterTrait< 'a, & 'a T > + 'a > ); - - impl< 'a, T > fmt::Debug for DynIter< 'a, T > - { - fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result - { - f.write_fmt( format_args!( "DynIter" ) ) - } - } - - impl< 'a, T > DynIter< 'a, T > - { - /// Creates a new `DynIter` from an iterator that implements `IterTrait`. - /// - /// # Parameters - /// - /// - `src`: The source iterator to be wrapped. - /// - /// # Returns - /// - /// A new instance of `DynIter`. - pub fn new< It >( src : It ) -> Self - where - It : IterTrait< 'a, & 'a T > + 'a, - { - Self( Box::new( src ) ) - } - } - - impl< 'a, T > From< DynIter< 'a, T > > for Box< dyn IterTrait< 'a, & 'a T > + 'a > - { - fn from( src : DynIter< 'a, T > ) -> Self - { - src.0 - } - } - - impl< 'a, T > core::ops::Deref for DynIter< 'a, T > - { - type Target = Box< dyn IterTrait< 'a, & 'a T > + 'a >; - - fn deref( & self ) -> & Self::Target - { - & self.0 - } - } - - impl< 'a, T > core::convert::AsRef< Box< dyn IterTrait< 'a, & 'a T > + 'a > > for DynIter< 'a, T > - { - fn as_ref( & self ) -> & Box< dyn IterTrait< 'a, & 'a T > + 'a > - { - & self.0 - } - } - - impl< 'a, T > Iterator for DynIter< 'a, T > - { - type Item = & 'a T; - - fn next( & mut self ) -> Option< Self::Item > - { - self.0.next() - } - } - - impl< 'a, T > ExactSizeIterator for DynIter< 'a, T > - { - fn len( & self ) -> usize - { - self.0.len() - } - } - - impl< 'a, T > DoubleEndedIterator for DynIter< 'a, T > - { - fn next_back( & mut self ) -> Option< Self::Item > - { - self.0.next_back() - } - } - -// pub trait IterTrait< 'a, T > -// where -// T : 'a, -// Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator + Clone, +// xxx : qqq : make command to autogenerate it +// /// Wrapper around a boxed iterator that implements `_IterTrait`. +// /// +// /// The `DynIter` struct provides a way to work with trait objects that implement the `_IterTrait` trait. It acts as a +// /// wrapper around a boxed iterator and provides methods to interact with the iterator in a type-safe manner. +// /// +// /// # Examples +// /// +// /// ```rust +// /// use crate::DynIter; +// /// use std::vec::Vec; +// /// +// /// let v = vec![ 1, 2, 3 ]; +// /// let iter = DynIter::new( v.iter() ); +// /// for val in iter +// /// { +// /// println!( "{}", val ); +// /// } +// /// ``` +// pub struct DynIter< 'a, T >( Box< dyn _IterTrait< 'a, & 'a T > + 'a > ); +// +// impl< 'a, T > fmt::Debug for DynIter< 'a, T > // { -// // fn clone_box( self ) -> Box< dyn IterTrait< 'a, T > + 'a >; +// fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result +// { +// f.write_fmt( format_args!( "DynIter" ) ) +// } // } // -// impl< 'a, T, I > IterTrait< 'a, T > for I -// where -// T : 'a, -// I : 'a, -// Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator + Clone, +// impl< 'a, T > DynIter< 'a, T > +// { +// /// Creates a new `DynIter` from an iterator that implements `_IterTrait`. +// /// +// /// # Parameters +// /// +// /// - `src`: The source iterator to be wrapped. +// /// +// /// # Returns +// /// +// /// A new instance of `DynIter`. +// pub fn new< It >( src : It ) -> Self +// where +// It : _IterTrait< 'a, & 'a T > + 'a, +// { +// Self( Box::new( src ) ) +// } +// } +// +// impl< 'a, T > From< DynIter< 'a, T > > for Box< dyn _IterTrait< 'a, & 'a T > + 'a > // { +// fn from( src : DynIter< 'a, T > ) -> Self +// { +// src.0 +// } +// } // -// // fn clone_box( self ) -> Box< dyn IterTrait< 'a, T > + 'a > -// // { -// // Box::new( self ).clone() -// // } +// impl< 'a, T > core::ops::Deref for DynIter< 'a, T > +// { +// type Target = Box< dyn _IterTrait< 'a, & 'a T > + 'a >; // +// fn deref( & self ) -> & Self::Target +// { +// & self.0 +// } // } - -// /// Trait that encapsulates an iterator with specific characteristics, tailored for use with the `syn` crate. -// /// -// /// The `IterTrait2` trait is designed to represent iterators that yield references to items (`&'a T`) within the `syn` crate. -// /// These iterators must also implement the `ExactSizeIterator` and `DoubleEndedIterator` traits. -// /// This combination ensures that the iterator can: -// /// - Provide an exact size hint (`ExactSizeIterator`), -// /// - Be traversed from both ends (`DoubleEndedIterator`). -// /// -// pub trait IterTrait2< T > -// where -// Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, +// +// impl< 'a, T > core::convert::AsRef< Box< dyn _IterTrait< 'a, & 'a T > + 'a > > for DynIter< 'a, T > // { +// fn as_ref( & self ) -> & Box< dyn _IterTrait< 'a, & 'a T > + 'a > +// { +// & self.0 +// } // } // -// impl< T, I > IterTrait2< T > for I -// where -// Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, +// impl< 'a, T > Iterator for DynIter< 'a, T > // { +// type Item = & 'a T; +// +// fn next( & mut self ) -> Option< Self::Item > +// { +// self.0.next() +// } // } // -// /// Trait that encapsulates an iterator with specific characteristics, tailored for use with the `syn` crate. -// /// -// /// The `IterTrait3` trait is designed to represent iterators that yield references to items (`&'a T`) within the `syn` crate. -// /// These iterators must also implement the `ExactSizeIterator` and `DoubleEndedIterator` traits. -// /// This combination ensures that the iterator can: -// /// - Provide an exact size hint (`ExactSizeIterator`), -// /// - Be traversed from both ends (`DoubleEndedIterator`). -// /// -// pub trait IterTrait3< 'a, T : 'a > -// where -// Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, +// impl< 'a, T > ExactSizeIterator for DynIter< 'a, T > // { +// fn len( & self ) -> usize +// { +// self.0.len() +// } // } // -// impl< 'a, T : 'a, I > IterTrait3< 'a, T > for I +// impl< 'a, T > DoubleEndedIterator for DynIter< 'a, T > +// { +// fn next_back( & mut self ) -> Option< Self::Item > +// { +// self.0.next_back() +// } +// } + + // = + +// trait Cloneable : Clone +// { +// fn clone_box( & self ) -> Box< dyn Cloneable >; +// } +// +// impl< T > Cloneable for T // where -// Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, +// T : 'static + Clone, +// { +// fn clone_box( & self ) -> Box< dyn Cloneable > +// { +// Box::new( self.clone() ) +// } +// } +// +// pub fn clone_boxed( t : & dyn Cloneable ) -> Box< dyn Cloneable > // { +// t.clone_box() // } } @@ -255,9 +240,10 @@ pub mod exposed #[ allow( unused_imports ) ] pub use super::private:: { - IterTrait, + _IterTrait, IterTraitClonable, - DynIter, + DynIter2, + // DynIter, // DynIterFrom, // IterTrait2, // IterTrait3, diff --git a/module/core/macro_tools/src/struct_like.rs b/module/core/macro_tools/src/struct_like.rs index d95ef0f01b..111048e372 100644 --- a/module/core/macro_tools/src/struct_like.rs +++ b/module/core/macro_tools/src/struct_like.rs @@ -246,24 +246,24 @@ pub( crate ) mod private { /// Returns an iterator over elements of the item. - pub fn elements< 'a >( &'a self ) -> impl IterTrait< 'a, FieldOrVariant< 'a > > + 'a + pub fn elements< 'a >( &'a self ) -> impl IterTraitClonable< 'a, FieldOrVariant< 'a > > + 'a { match self { StructLike::Unit( _ ) => { let empty : Vec< FieldOrVariant< 'a > > = vec![]; - Box::new( empty.into_iter() ) as Box< dyn IterTrait< 'a, FieldOrVariant< 'a > > > + Box::new( empty.into_iter() ) as DynIter2< 'a, FieldOrVariant< 'a > > }, StructLike::Struct( item ) => { let fields = item.fields.iter().map( FieldOrVariant::from ); - Box::new( fields ) as Box< dyn IterTrait< 'a, FieldOrVariant< 'a > > > + Box::new( fields ) as DynIter2< 'a, FieldOrVariant< 'a > > }, StructLike::Enum( item ) => { let variants = item.variants.iter().map( FieldOrVariant::from ); - Box::new( variants ) as Box< dyn IterTrait< 'a, FieldOrVariant< 'a > > > + Box::new( variants ) as DynIter2< 'a, FieldOrVariant< 'a > > }, } } @@ -349,11 +349,11 @@ pub( crate ) mod private } /// Returns an iterator over fields of the item. - // pub fn fields( &self ) -> Box< dyn Iterator< Item = &syn::Field > + '_ > - pub fn fields< 'a >( &'a self ) -> Box< dyn IterTrait< 'a, &'a syn::Field > + '_ > - // pub fn fields< 'a >( &'a self ) -> impl IterTrait< 'a, &'a syn::Field > + // pub fn fields< 'a >( &'a self ) -> DynIter2< 'a, &'a syn::Field > + pub fn fields< 'a >( &'a self ) -> impl IterTraitClonable< 'a, &'a syn::Field > + // xxx { - match self + let result : DynIter2< 'a, &'a syn::Field > = match self { StructLike::Unit( _item ) => { @@ -367,12 +367,13 @@ pub( crate ) mod private { Box::new( std::iter::empty() ) }, - } + }; + result } /// Extracts the name of each field. - // pub fn field_names< 'a >( &'a self ) -> Option< impl IterTrait< 'a, &'a syn::Ident > + '_ > - pub fn field_names< 'a >( &'a self ) -> Option< DynIter< 'a, syn::Ident > > + pub fn field_names< 'a >( &'a self ) -> Option< impl IterTraitClonable< 'a, &'a syn::Ident > + '_ > + // pub fn field_names< 'a >( &'a self ) -> Option< DynIter< 'a, syn::Ident > > { match self { @@ -386,7 +387,9 @@ pub( crate ) mod private }, StructLike::Enum( _item ) => { - Some( DynIter::new( self.fields().map( | field | field.ident.as_ref().unwrap() ) ) ) + let iter : DynIter2< 'a, &'a syn::Ident > = Box::new( self.fields().map( | field | field.ident.as_ref().unwrap() ) ); + Some( iter ) + // Some( DynIter::new( self.fields().map( | field | field.ident.as_ref().unwrap() ) ) ) // Some( DynIterFrom::dyn_iter_from( self.fields().map( | field | field.ident.as_ref().unwrap() ) ) ) // Box::new( std::iter::empty() ) }, @@ -396,16 +399,16 @@ pub( crate ) mod private /// Extracts the type of each field. // pub fn field_types( &self ) -> Box< dyn Iterator< Item = &syn::Type > + '_ > - // pub fn field_types< 'a >( &'a self ) -> Box< dyn IterTrait< 'a, &'a syn::Type > + '_ > - pub fn field_types< 'a >( &'a self ) -> impl IterTrait< 'a, &'a syn::Type > + // pub fn field_types< 'a >( &'a self ) -> Box< dyn _IterTrait< 'a, &'a syn::Type > + '_ > + pub fn field_types< 'a >( &'a self ) -> impl IterTraitClonable< 'a, &'a syn::Type > { Box::new( self.fields().map( | field | &field.ty ) ) } /// Extracts the name of each field. // pub fn field_attrs( &self ) -> Box< dyn Iterator< Item = &Vec< syn::Attribute > > + '_ > - // pub fn field_attrs< 'a >( &'a self ) -> Box< dyn IterTrait< 'a, &'a Vec< syn::Attribute > > + '_ > - pub fn field_attrs< 'a >( &'a self ) -> impl IterTrait< 'a, &'a Vec< syn::Attribute > > + // pub fn field_attrs< 'a >( &'a self ) -> Box< dyn _IterTrait< 'a, &'a Vec< syn::Attribute > > + '_ > + pub fn field_attrs< 'a >( &'a self ) -> impl IterTraitClonable< 'a, &'a Vec< syn::Attribute > > { Box::new( self.fields().map( | field | &field.attrs ) ) } diff --git a/module/move/willbe/src/tool/cargo.rs b/module/move/willbe/src/tool/cargo.rs index 2d28da4d96..f1037c7761 100644 --- a/module/move/willbe/src/tool/cargo.rs +++ b/module/move/willbe/src/tool/cargo.rs @@ -17,7 +17,9 @@ mod private pub( crate ) path : PathBuf, #[ former( default = true ) ] pub( crate ) allow_dirty : bool, - #[ former( default = true ) ] + // qqq : rename to checking_changes + #[ former( default = false ) ] + // qqq : don't abuse negative form, rename to checking_consistency pub( crate ) no_verify : bool, pub( crate ) temp_path : Option< PathBuf >, pub( crate ) dry : bool, From 5727a73fba934a73304a6783798e2ef9e208d1fd Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 2 Jun 2024 09:09:46 +0300 Subject: [PATCH 16/45] macro_tools : clonable iterator wip --- module/core/macro_tools/src/item_struct.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/core/macro_tools/src/item_struct.rs b/module/core/macro_tools/src/item_struct.rs index 3b5275d9ae..94a01c66d5 100644 --- a/module/core/macro_tools/src/item_struct.rs +++ b/module/core/macro_tools/src/item_struct.rs @@ -15,9 +15,9 @@ pub( crate ) mod private } /// Retrieves the names of each field, if they exist. - pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< impl IterTraitClonable< 'a, &'a syn::Ident > > + // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< impl IterTraitClonable< 'a, &'a syn::Ident > > // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< Box< dyn _IterTrait< 'a, &'a syn::Ident > + '_ > > - // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< DynIter< 'a, syn::Ident > > + pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< DynIter2< 'a, &'a syn::Ident > > { let result : Option< Box< dyn _IterTrait< 'a, &'a syn::Ident > + '_ > > = match &t.fields { From e2001cfef0c13a02961ca6b4e184dff8269a592e Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 3 Jun 2024 00:19:57 +0300 Subject: [PATCH 17/45] clone_dyn : fixing it --- module/core/clone_dyn/Cargo.toml | 2 + .../clone_dyn/examples/clone_dyn_trivial.rs | 21 +- module/core/clone_dyn/src/lib.rs | 73 ++++- module/core/clone_dyn/tests/inc/basic.rs | 48 +++ .../core/clone_dyn/tests/inc/basic_manual.rs | 112 +++++++ module/core/clone_dyn/tests/inc/mod.rs | 309 ++++++++++-------- module/core/clone_dyn_meta/src/derive.rs | 8 +- module/core/derive_tools/Cargo.toml | 1 - module/core/derive_tools/src/lib.rs | 1 + .../core/derive_tools_meta/src/derive/from.rs | 6 +- .../src/derive/inner_from.rs | 2 +- .../core/derive_tools_meta/src/derive/new.rs | 15 +- .../src/component/from_components.rs | 2 +- module/core/inspect_type/src/lib.rs | 14 - module/core/macro_tools/src/generic_params.rs | 2 +- module/core/macro_tools/src/item_struct.rs | 11 +- module/core/macro_tools/src/iter.rs | 24 +- module/core/macro_tools/src/struct_like.rs | 34 +- 18 files changed, 467 insertions(+), 218 deletions(-) create mode 100644 module/core/clone_dyn/tests/inc/basic.rs create mode 100644 module/core/clone_dyn/tests/inc/basic_manual.rs diff --git a/module/core/clone_dyn/Cargo.toml b/module/core/clone_dyn/Cargo.toml index 0c2804d339..cad394cd65 100644 --- a/module/core/clone_dyn/Cargo.toml +++ b/module/core/clone_dyn/Cargo.toml @@ -35,6 +35,8 @@ enabled = [ "clone_dyn_meta/enabled" ] [dependencies] clone_dyn_meta = { workspace = true } +inspect_type = { workspace = true, features = [ "full" ] } [dev-dependencies] test_tools = { workspace = true } +inspect_type = { workspace = true, features = [ "full" ] } diff --git a/module/core/clone_dyn/examples/clone_dyn_trivial.rs b/module/core/clone_dyn/examples/clone_dyn_trivial.rs index 980bb02488..58686ee449 100644 --- a/module/core/clone_dyn/examples/clone_dyn_trivial.rs +++ b/module/core/clone_dyn/examples/clone_dyn_trivial.rs @@ -6,19 +6,20 @@ #[ cfg( any( not( feature = "enabled" ), all( feature = "no_std", not( feature = "use_alloc" ) ) ) ) ] fn main() {} - #[ cfg( all( feature = "enabled", any( not( feature = "no_std" ), feature = "use_alloc" ) ) ) ] fn main() { - use clone_dyn::clone_dyn; - - #[ clone_dyn ] - trait Trait1 - { - } - - let vec = Vec::< Box< dyn Trait1 > >::new(); - let _vec2 = vec.clone(); /* <- it does not work without `clone_dyn` */ +// use clone_dyn::clone_dyn; +// +// #[ clone_dyn ] +// trait Trait1 +// { +// } +// +// let vec = Vec::< Box< dyn Trait1 > >::new(); +// let _vec2 = vec.clone(); /* <- it does not work without `clone_dyn` */ } + +// xxx : improve \ No newline at end of file diff --git a/module/core/clone_dyn/src/lib.rs b/module/core/clone_dyn/src/lib.rs index 7875f819bd..3f86087183 100644 --- a/module/core/clone_dyn/src/lib.rs +++ b/module/core/clone_dyn/src/lib.rs @@ -31,13 +31,64 @@ pub( crate ) mod private #[ cfg( all( feature = "use_std", not( feature = "use_alloc" ) ) ) ] use std::boxed::Box; + /// A trait to upcast a clonable entity and clone it. + /// It's implemented for all entities which can be cloned. + pub trait CloneDyn + { + fn __clone_dyn( &self ) -> *mut (); + } + + // clonable + impl< T > CloneDyn for T + where + T : Clone, + { + fn __clone_dyn( &self ) -> *mut () + { + Box::< T >::into_raw( Box::new( self.clone() ) ) as *mut () + } + } + + // slice + impl< T > CloneDyn for [ T ] + where + T : Clone, + { + fn __clone_dyn( &self ) -> *mut () + { + Box::< [ T ] >::into_raw( self.iter().cloned().collect() ) as *mut () + } + } + + // str slice + impl CloneDyn for str + { + fn __clone_dyn( &self ) -> *mut () + { + Box::< str >::into_raw( Box::from( self ) ) as *mut () + } + } + + /// + /// True clone which is applicable not only to clonable entities, but to trait object implementing CloneDyn. + /// + pub fn clone< T >( src : &T ) -> T + where + T : CloneDyn, + { + unsafe + { + *Box::from_raw( < T as CloneDyn >::__clone_dyn( src ) as *mut T ) + } + } + /// Clone boxed dyn. /// /// Not intended to be used directly. #[ inline ] - pub fn _clone_boxed< T >( t : &T ) -> Box< T > + pub fn clone_into_box< T >( ref_dyn : &T ) -> Box< T > where - T : ?Sized, + T : ?Sized + CloneDyn, { // Explanation for the use of `unsafe`: // The `unsafe` block is necessary here because we're performing low-level memory manipulations @@ -50,9 +101,16 @@ pub( crate ) mod private #[ allow( unsafe_code ) ] unsafe { - let mut ptr = t as *const T; + let mut ptr = ref_dyn as *const T; + // println!( "ptr : {:p} | size : {}", ptr, core::mem::size_of_val( &ptr ) ); + // inspect_type::inspect_type_of!( ptr ); let data_ptr = &mut ptr as *mut *const T as *mut *mut (); - *data_ptr = Box::into_raw( Box::new( < &T >::clone( &t ) ) ) as *mut (); + // println!( "data_ptr : {:p} | size : {}", data_ptr, core::mem::size_of_val( &data_ptr ) ); + // inspect_type::inspect_type_of!( data_ptr ); + // println!( "*data_ptr : {:p} | size : {}", *data_ptr, core::mem::size_of_val( &*data_ptr ) ); + // inspect_type::inspect_type_of!( data_ptr ); + *data_ptr = < T as CloneDyn >::__clone_dyn( ref_dyn ); + // println!( "" ); Box::from_raw( ptr as *mut T ) } } @@ -102,5 +160,10 @@ pub mod prelude #[ doc( inline ) ] #[ allow( unused_imports ) ] #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - pub use super::private::_clone_boxed; + pub use super::private:: + { + CloneDyn, + clone_into_box, + clone, + }; } diff --git a/module/core/clone_dyn/tests/inc/basic.rs b/module/core/clone_dyn/tests/inc/basic.rs new file mode 100644 index 0000000000..74629f266c --- /dev/null +++ b/module/core/clone_dyn/tests/inc/basic.rs @@ -0,0 +1,48 @@ +// +// #[ allow( unused_imports ) ] +// use super::*; +// +// #[ test ] +// fn basic() +// { +// use the_module::clone_dyn; +// +// #[ clone_dyn ] +// trait Trait1 +// { +// fn val( &self ) -> i32; +// } +// +// impl Trait1 for i32 +// { +// fn val( &self ) -> i32 +// { +// self.clone() +// } +// }; +// impl Trait1 for i64 +// { +// fn val( &self ) -> i32 +// { +// self.clone().try_into().unwrap() +// } +// }; +// +// // impl PartialEq< Box< dyn Trait1 > > for Box< dyn Trait1 > +// // { +// // fn eq( &self, other : &Box< dyn Trait1 > ) -> bool +// // { +// // self == other +// // } +// // } +// +// // +// +// let vec : Vec< Box< dyn Trait1 > > = vec![ Box::new( 13 ), Box::new( 14 ) ]; +// let vec2 = vec.clone(); +// +// a_id!( vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(), vec2.iter().map( | e | e.val() ).collect::< Vec< _ > >() ) +// +// // xxx2 : continue +// +// } diff --git a/module/core/clone_dyn/tests/inc/basic_manual.rs b/module/core/clone_dyn/tests/inc/basic_manual.rs new file mode 100644 index 0000000000..3cd883ed61 --- /dev/null +++ b/module/core/clone_dyn/tests/inc/basic_manual.rs @@ -0,0 +1,112 @@ + +#[ allow( unused_imports ) ] +use super::*; + +// + +// qqq2 : organize tests in the same way tests organized for derive_tools +#[ test ] +fn manual() +{ + + trait Trait1 + where + Self : clone_dyn::CloneDyn, + { + fn val( &self ) -> i32; + } + + // + + impl Trait1 for i32 + { + fn val( &self ) -> i32 + { + self.clone() + } + } + + impl Trait1 for i64 + { + fn val( &self ) -> i32 + { + self.clone().try_into().unwrap() + } + } + + // + + #[ allow( non_local_definitions ) ] + impl < 'c > Clone + for Box< dyn Trait1 + 'c > + { + #[ inline ] + fn clone( &self ) -> Self + { + let x = &**self; + // inspect_type::inspect_type_of!( x ); + // clone_dyn::clone( self ) + clone_dyn::clone_into_box( &**self ) + } + } + + #[ allow( non_local_definitions ) ] + impl < 'c > Clone + for Box< dyn Trait1 + Send + 'c > + { + #[ inline ] + fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } + } + + #[ allow( non_local_definitions ) ] + impl < 'c > Clone + for Box< dyn Trait1 + Sync + 'c > + { + #[ inline ] + fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } + } + + #[ allow( non_local_definitions ) ] + impl < 'c > Clone + for Box< dyn Trait1 + Send + Sync + 'c > + { + #[ inline ] + fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } + } + + // + + let a : String = "abc".to_string(); + let b : Box< String > = clone_dyn::clone_into_box( &a ); + a_id!( a, *b ); + + // + + let a : String = "abc".to_string(); + let b = clone_dyn::clone( &a ); + a_id!( a, b ); + + // + + let a : &str = "abc"; + let b = clone_dyn::clone( &a ); + // let b = a.clone(); + a_id!( a, b ); + + // + + let vec : Vec< Box< dyn Trait1 > > = vec![ Box::new( 13 ), Box::new( 14 ) ]; + let vec2 = clone_dyn::clone( &vec ); + let vec = vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(); + let vec2 = vec2.iter().map( | e | e.val() ).collect::< Vec< _ > >(); + a_id!( vec, vec2 ); + + // + + let vec : Vec< Box< dyn Trait1 > > = vec![ Box::new( 13 ), Box::new( 14 ) ]; + let vec2 = vec.clone(); + let vec = vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(); + let vec2 = vec2.iter().map( | e | e.val() ).collect::< Vec< _ > >(); + a_id!( vec, vec2 ); + +} diff --git a/module/core/clone_dyn/tests/inc/mod.rs b/module/core/clone_dyn/tests/inc/mod.rs index 57f266f8f6..1dca330f92 100644 --- a/module/core/clone_dyn/tests/inc/mod.rs +++ b/module/core/clone_dyn/tests/inc/mod.rs @@ -9,142 +9,171 @@ tests_impls! // - // qqq2 : organize tests in the same way tests organized for derive_tools - fn manual() - { - - trait Trait1 - { - } - - // - - #[ inline ] - pub fn _clone_boxed< T >( t : &T ) -> Box< T > - where - T : ?Sized, - { - unsafe - { - let mut ptr = t as *const T; - let data_ptr = &mut ptr as *mut *const T as *mut *mut (); - *data_ptr = Box::into_raw( Box::new( t.clone() ) ) as *mut (); - Box::from_raw( ptr as *mut T ) - } - } - - // - - #[ allow( non_local_definitions ) ] - impl < 'c > Clone - for Box< dyn Trait1 + 'c > - { - #[ inline ] - fn clone( &self ) -> Self { _clone_boxed( &**self ) } - } - - #[ allow( non_local_definitions ) ] - impl < 'c > Clone - for Box< dyn Trait1 + Send + 'c > - { - #[ inline ] - fn clone( &self ) -> Self { _clone_boxed( &**self ) } - } - - #[ allow( non_local_definitions ) ] - impl < 'c > Clone - for Box< dyn Trait1 + Sync + 'c > - { - #[ inline ] - fn clone( &self ) -> Self { _clone_boxed( &**self ) } - } - - #[ allow( non_local_definitions ) ] - impl < 'c > Clone - for Box< dyn Trait1 + Send + Sync + 'c > - { - #[ inline ] - fn clone( &self ) -> Self { _clone_boxed( &**self ) } - } - - // - - let vec = Vec::< Box< dyn Trait1 > >::new(); - let vec2 = vec.clone(); - - } - - // - - fn basic() - { - use the_module::clone_dyn; - - #[ clone_dyn ] - trait Trait1 - { - } - - // - - let vec = Vec::< Box< dyn Trait1 > >::new(); - let vec2 = vec.clone(); - - } - - // - - fn prelude() - { - use the_module::prelude::*; - - #[ clone_dyn ] - trait Trait1 - { - } - - // - - let vec = Vec::< Box< dyn Trait1 > >::new(); - let vec2 = vec.clone(); - - } - - // - - fn parametrized() - { - use the_module::clone_dyn; - - #[ clone_dyn ] - trait Trait2< T1 : Copy, T2 : Copy > - where - T2 : Clone + core::fmt::Debug, - { - } - - // - - let vec = Vec::< Box< dyn Trait2< i32, f32 > > >::new(); - let vec2 = vec.clone(); - - } +// // qqq2 : organize tests in the same way tests organized for derive_tools +// fn manual() +// { +// +// trait Trait1 +// { +// } +// +// // +// +// #[ inline ] +// pub fn clone_into_box< T >( t : &T ) -> Box< T > +// where +// T : ?Sized, +// { +// unsafe +// { +// let mut ptr = t as *const T; +// let data_ptr = &mut ptr as *mut *const T as *mut *mut (); +// *data_ptr = Box::into_raw( Box::new( t.clone() ) ) as *mut (); +// Box::from_raw( ptr as *mut T ) +// } +// } +// +// // +// +// #[ allow( non_local_definitions ) ] +// impl < 'c > Clone +// for Box< dyn Trait1 + 'c > +// { +// #[ inline ] +// fn clone( &self ) -> Self { clone_into_box( &**self ) } +// } +// +// #[ allow( non_local_definitions ) ] +// impl < 'c > Clone +// for Box< dyn Trait1 + Send + 'c > +// { +// #[ inline ] +// fn clone( &self ) -> Self { clone_into_box( &**self ) } +// } +// +// #[ allow( non_local_definitions ) ] +// impl < 'c > Clone +// for Box< dyn Trait1 + Sync + 'c > +// { +// #[ inline ] +// fn clone( &self ) -> Self { clone_into_box( &**self ) } +// } +// +// #[ allow( non_local_definitions ) ] +// impl < 'c > Clone +// for Box< dyn Trait1 + Send + Sync + 'c > +// { +// #[ inline ] +// fn clone( &self ) -> Self { clone_into_box( &**self ) } +// } +// +// // +// +// let vec = Vec::< Box< dyn Trait1 > >::new(); +// let vec2 = vec.clone(); +// +// } +// +// // +// +// fn basic() +// { +// use the_module::clone_dyn; +// +// #[ clone_dyn ] +// trait Trait1 +// { +// fn val( &self ) -> i32; +// } +// +// impl Trait1 for i32 +// { +// fn val( &self ) -> i32 +// { +// self.clone() +// } +// }; +// impl Trait1 for i64 +// { +// fn val( &self ) -> i32 +// { +// self.clone().try_into().unwrap() +// } +// }; +// +// // impl PartialEq< Box< dyn Trait1 > > for Box< dyn Trait1 > +// // { +// // fn eq( &self, other : &Box< dyn Trait1 > ) -> bool +// // { +// // self == other +// // } +// // } +// +// // +// +// let vec : Vec< Box< dyn Trait1 > > = vec![ Box::new( 13 ), Box::new( 14 ) ]; +// let vec2 = vec.clone(); +// +// a_id!( vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(), vec2.iter().map( | e | e.val() ).collect::< Vec< _ > >() ) +// +// // xxx2 : continue +// +// } // - fn sample() - { - use the_module::clone_dyn; - - #[ clone_dyn ] - trait Trait1 - { - } - - let vec = Vec::< Box< dyn Trait1 > >::new(); - let vec2 = vec.clone(); /* <- it does not work without `clone_dyn` */ - - } +// fn prelude() +// { +// use the_module::prelude::*; +// +// #[ clone_dyn ] +// trait Trait1 +// { +// } +// +// // +// +// let vec = Vec::< Box< dyn Trait1 > >::new(); +// // let vec2 = vec.clone(); +// // xxx +// +// } +// +// // +// +// fn parametrized() +// { +// use the_module::clone_dyn; +// +// #[ clone_dyn ] +// trait Trait2< T1 : Copy, T2 : Copy > +// where +// T2 : Clone + core::fmt::Debug, +// { +// } +// +// // +// +// let vec = Vec::< Box< dyn Trait2< i32, f32 > > >::new(); +// let vec2 = vec.clone(); +// +// } +// +// // +// +// fn sample() +// { +// use the_module::clone_dyn; +// +// #[ clone_dyn ] +// trait Trait1 +// { +// } +// +// let vec = Vec::< Box< dyn Trait1 > >::new(); +// let vec2 = vec.clone(); /* <- it does not work without `clone_dyn` */ +// +// } } @@ -152,9 +181,13 @@ tests_impls! tests_index! { - manual, - basic, - prelude, - parametrized, - sample, + // manual, + // basic, + // prelude, + // parametrized, + // sample, } +// xxx + +mod basic_manual; +mod basic; diff --git a/module/core/clone_dyn_meta/src/derive.rs b/module/core/clone_dyn_meta/src/derive.rs index cb006d1a9e..8cb49974e9 100644 --- a/module/core/clone_dyn_meta/src/derive.rs +++ b/module/core/clone_dyn_meta/src/derive.rs @@ -30,7 +30,7 @@ pub fn clone_dyn( _attr : proc_macro::TokenStream, item : proc_macro::TokenStrea #generics_where { #[ inline ] - fn clone( &self ) -> Self { clone_dyn::_clone_boxed( &**self ) } + fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } } #[ allow( non_local_definitions ) ] @@ -40,7 +40,7 @@ pub fn clone_dyn( _attr : proc_macro::TokenStream, item : proc_macro::TokenStrea #generics_where { #[ inline ] - fn clone( &self ) -> Self { clone_dyn::_clone_boxed( &**self ) } + fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } } #[ allow( non_local_definitions ) ] @@ -50,7 +50,7 @@ pub fn clone_dyn( _attr : proc_macro::TokenStream, item : proc_macro::TokenStrea #generics_where { #[ inline ] - fn clone( &self ) -> Self { clone_dyn::_clone_boxed( &**self ) } + fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } } #[ allow( non_local_definitions ) ] @@ -60,7 +60,7 @@ pub fn clone_dyn( _attr : proc_macro::TokenStream, item : proc_macro::TokenStrea #generics_where { #[ inline ] - fn clone( &self ) -> Self { clone_dyn::_clone_boxed( &**self ) } + fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } } }; diff --git a/module/core/derive_tools/Cargo.toml b/module/core/derive_tools/Cargo.toml index ab446e7407..dd7714b587 100644 --- a/module/core/derive_tools/Cargo.toml +++ b/module/core/derive_tools/Cargo.toml @@ -198,6 +198,5 @@ clone_dyn = { workspace = true, features = [] } [dev-dependencies] test_tools = { workspace = true } - [build-dependencies] cfg_aliases = "0.1.1" diff --git a/module/core/derive_tools/src/lib.rs b/module/core/derive_tools/src/lib.rs index 42db822d27..5bf65c972a 100644 --- a/module/core/derive_tools/src/lib.rs +++ b/module/core/derive_tools/src/lib.rs @@ -84,6 +84,7 @@ pub use variadic_from as variadic; /// Namespace with dependencies. +#[ allow( unused_imports ) ] #[ cfg( feature = "enabled" ) ] pub mod dependency { diff --git a/module/core/derive_tools_meta/src/derive/from.rs b/module/core/derive_tools_meta/src/derive/from.rs index e38040ebe2..2e375e5d86 100644 --- a/module/core/derive_tools_meta/src/derive/from.rs +++ b/module/core/derive_tools_meta/src/derive/from.rs @@ -348,8 +348,8 @@ fn generate_multiple_fields_named< 'a > generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_where: &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - field_names : impl macro_tools::IterTraitClonable< 'a, &'a syn::Ident >, - field_types : impl macro_tools::IterTraitClonable< 'a, &'a syn::Type >, + field_names : impl macro_tools::IterTrait< 'a, &'a syn::Ident >, + field_types : impl macro_tools::IterTrait< 'a, &'a syn::Type >, ) -> proc_macro2::TokenStream { @@ -412,7 +412,7 @@ fn generate_multiple_fields< 'a > generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_where: &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - field_types : impl macro_tools::IterTraitClonable< 'a, &'a macro_tools::syn::Type >, + field_types : impl macro_tools::IterTrait< 'a, &'a macro_tools::syn::Type >, ) -> proc_macro2::TokenStream { diff --git a/module/core/derive_tools_meta/src/derive/inner_from.rs b/module/core/derive_tools_meta/src/derive/inner_from.rs index aa78a69a42..427f447087 100644 --- a/module/core/derive_tools_meta/src/derive/inner_from.rs +++ b/module/core/derive_tools_meta/src/derive/inner_from.rs @@ -194,7 +194,7 @@ fn from_impl fn from_impl_multiple_fields< 'a > ( item_name : &syn::Ident, - field_types : impl macro_tools::IterTraitClonable< 'a, &'a macro_tools::syn::Type >, + field_types : impl macro_tools::IterTrait< 'a, &'a macro_tools::syn::Type >, params : &Vec< proc_macro2::TokenStream >, ) -> proc_macro2::TokenStream { diff --git a/module/core/derive_tools_meta/src/derive/new.rs b/module/core/derive_tools_meta/src/derive/new.rs index d173b3d6f6..51913eacd8 100644 --- a/module/core/derive_tools_meta/src/derive/new.rs +++ b/module/core/derive_tools_meta/src/derive/new.rs @@ -225,19 +225,22 @@ fn generate_multiple_fields_named< 'a > generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_where: &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - field_names : impl macro_tools::IterTraitClonable< 'a, &'a syn::Ident > + Clone, // xxx - field_types : impl macro_tools::IterTraitClonable< 'a, &'a syn::Type > + Clone, // xxx + field_names : impl macro_tools::IterTrait< 'a, &'a syn::Ident >, + field_types : impl macro_tools::IterTrait< 'a, &'a syn::Type >, ) -> proc_macro2::TokenStream { - let field_names : Vec< _ > = field_names.collect(); // xxx : qqq : rid off collects + // let field_names : Vec< _ > = field_names.collect(); // xxx : qqq : rid off collects - let val_type = field_names.iter() + let val_type = field_names + // .iter() + .clone() .zip( field_types ) .enumerate() - .map(| ( index, ( field_name, field_type ) ) | + .map(| ( _index, ( field_name, field_type ) ) | { + // xxx // let index = index.to_string().parse::< proc_macro2::TokenStream >().unwrap(); qt! { #field_name : #field_type } }); @@ -269,7 +272,7 @@ fn generate_multiple_fields< 'a > generics_impl : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_ty : &syn::punctuated::Punctuated< syn::GenericParam, syn::token::Comma >, generics_where: &syn::punctuated::Punctuated< syn::WherePredicate, syn::token::Comma >, - field_types : impl macro_tools::IterTraitClonable< 'a, &'a macro_tools::syn::Type >, + field_types : impl macro_tools::IterTrait< 'a, &'a macro_tools::syn::Type >, ) -> proc_macro2::TokenStream { diff --git a/module/core/former_meta/src/component/from_components.rs b/module/core/former_meta/src/component/from_components.rs index 34c48f7c6f..d76029ca0a 100644 --- a/module/core/former_meta/src/component/from_components.rs +++ b/module/core/former_meta/src/component/from_components.rs @@ -99,7 +99,7 @@ pub fn from_components( input : proc_macro::TokenStream ) -> Result< proc_macro2 #[ inline ] // fn trait_bounds( field_types : &[ &syn::Type ] ) -> Vec< proc_macro2::TokenStream > -fn trait_bounds< 'a >( field_types : impl macro_tools::IterTraitClonable< 'a, &'a syn::Type > ) -> Vec< proc_macro2::TokenStream > +fn trait_bounds< 'a >( field_types : impl macro_tools::IterTrait< 'a, &'a syn::Type > ) -> Vec< proc_macro2::TokenStream > { field_types.map( | field_type | { diff --git a/module/core/inspect_type/src/lib.rs b/module/core/inspect_type/src/lib.rs index 046f3332f9..b0e8da7f37 100644 --- a/module/core/inspect_type/src/lib.rs +++ b/module/core/inspect_type/src/lib.rs @@ -2,20 +2,6 @@ #![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] #![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] #![ doc( html_root_url = "https://docs.rs/inspect_type/latest/inspect_type/" ) ] -// #![ deny( rust_2018_idioms ) ] -// #![ deny( missing_debug_implementations ) ] -// #![ deny( missing_docs ) ] - -// #![ cfg( rustversion::nightly ) ] -// #![ feature( type_name_of_val ) ] -// #![ cfg_attr( feature = "type_name_of_val", feature( type_name_of_val ) ) ] - -// #![ cfg_attr( RUSTC_IS_NIGHTLY, feature( type_name_of_val ) ) ] - -//! -//! Diagnostic-purpose tools to inspect type of a variable and its size. -//! - #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index 71a98e113c..09f4445e5b 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -281,7 +281,7 @@ pub( crate ) mod private /// ]); /// ``` - pub fn names< 'a >( generics : &'a syn::Generics ) -> impl IterTraitClonable< 'a, &'a syn::Ident > + Clone + pub fn names< 'a >( generics : &'a syn::Generics ) -> impl IterTrait< 'a, &'a syn::Ident > + Clone { generics.params.iter().map( | param | match param { diff --git a/module/core/macro_tools/src/item_struct.rs b/module/core/macro_tools/src/item_struct.rs index 94a01c66d5..d98dcfcfd8 100644 --- a/module/core/macro_tools/src/item_struct.rs +++ b/module/core/macro_tools/src/item_struct.rs @@ -8,18 +8,17 @@ pub( crate ) mod private use crate::*; /// Extracts the types of each field into a vector. - // pub fn field_types< 'a >( t : &'a syn::ItemStruct ) -> impl IterTrait< 'a, &'a syn::Type > + Clone - pub fn field_types< 'a >( t : &'a syn::ItemStruct ) -> impl IterTraitClonable< 'a, &'a syn::Type > + Clone + pub fn field_types< 'a >( t : &'a syn::ItemStruct ) -> impl IterTrait< 'a, &'a syn::Type > + Clone { t.fields.iter().map( | field | &field.ty ) } /// Retrieves the names of each field, if they exist. - // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< impl IterTraitClonable< 'a, &'a syn::Ident > > - // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< Box< dyn _IterTrait< 'a, &'a syn::Ident > + '_ > > - pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< DynIter2< 'a, &'a syn::Ident > > + // pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< impl IterTrait< 'a, &'a syn::Ident > > + pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< BoxedIter< 'a, &'a syn::Ident > > + // xxx { - let result : Option< Box< dyn _IterTrait< 'a, &'a syn::Ident > + '_ > > = match &t.fields + let result : Option< BoxedIter< 'a, &'a syn::Ident > > = match &t.fields { syn::Fields::Named( fields ) => Some( Box::new( fields.named.iter().map( | field | field.ident.as_ref().unwrap() ) ) ), syn::Fields::Unit => Some( Box::new( core::iter::empty() ) ), diff --git a/module/core/macro_tools/src/iter.rs b/module/core/macro_tools/src/iter.rs index aaf57d3086..15863431c7 100644 --- a/module/core/macro_tools/src/iter.rs +++ b/module/core/macro_tools/src/iter.rs @@ -7,8 +7,7 @@ /// Internal namespace. pub( crate ) mod private { - use std::fmt; - + // use std::fmt; // use crate::*; /// Trait that encapsulates an iterator with specific characteristics, tailored for use with the `syn` crate. @@ -33,18 +32,16 @@ pub( crate ) mod private { } - pub type DynIter2< 'a, T > = Box< dyn _IterTrait< 'a, T > + 'a >; - // xxx - impl< 'c, 'a, T > Clone for Box< dyn _IterTrait< 'a, T > + 'c > { #[ inline ] - fn clone( &self ) -> Self { _clone_boxed( &**self ) } + fn clone( &self ) -> Self { clone_into_box( &**self ) } } + // xxx2 #[ inline ] - fn _clone_boxed< T >( t : &T ) -> Box< T > + fn clone_into_box< T >( t : &T ) -> Box< T > where T : ?Sized, { @@ -57,23 +54,26 @@ pub( crate ) mod private } } + // xxx + pub type BoxedIter< 'a, T > = Box< dyn _IterTrait< 'a, T > + 'a >; + /// Trait that encapsulates a clonable iterator with specific characteristics, tailored for use with the `syn` crate. /// - /// The `IterTraitClonable` trait is designed to represent iterators that may yield references to items (`&'a T`) within the `syn` crate. + /// The `IterTrait` trait is designed to represent iterators that may yield references to items (`&'a T`) within the `syn` crate. /// These iterators must also implement the `ExactSizeIterator`, `DoubleEndedIterator`, and `Clone` traits. /// This combination ensures that the iterator can: /// - Provide an exact size hint (`ExactSizeIterator`), /// - Be traversed from both ends (`DoubleEndedIterator`), /// - Be clonable (`Clone`). /// - pub trait IterTraitClonable< 'a, T > + pub trait IterTrait< 'a, T > where T : 'a, Self : _IterTrait< 'a, T > + Clone, { } - impl< 'a, T, I > IterTraitClonable< 'a, T > for I + impl< 'a, T, I > IterTrait< 'a, T > for I where T : 'a, Self : _IterTrait< 'a, T > + Clone, @@ -241,8 +241,8 @@ pub mod exposed pub use super::private:: { _IterTrait, - IterTraitClonable, - DynIter2, + IterTrait, + BoxedIter, // DynIter, // DynIterFrom, // IterTrait2, diff --git a/module/core/macro_tools/src/struct_like.rs b/module/core/macro_tools/src/struct_like.rs index 111048e372..81d3866a0e 100644 --- a/module/core/macro_tools/src/struct_like.rs +++ b/module/core/macro_tools/src/struct_like.rs @@ -246,24 +246,24 @@ pub( crate ) mod private { /// Returns an iterator over elements of the item. - pub fn elements< 'a >( &'a self ) -> impl IterTraitClonable< 'a, FieldOrVariant< 'a > > + 'a + pub fn elements< 'a >( &'a self ) -> impl IterTrait< 'a, FieldOrVariant< 'a > > + 'a { match self { StructLike::Unit( _ ) => { let empty : Vec< FieldOrVariant< 'a > > = vec![]; - Box::new( empty.into_iter() ) as DynIter2< 'a, FieldOrVariant< 'a > > + Box::new( empty.into_iter() ) as BoxedIter< 'a, FieldOrVariant< 'a > > }, StructLike::Struct( item ) => { let fields = item.fields.iter().map( FieldOrVariant::from ); - Box::new( fields ) as DynIter2< 'a, FieldOrVariant< 'a > > + Box::new( fields ) as BoxedIter< 'a, FieldOrVariant< 'a > > }, StructLike::Enum( item ) => { let variants = item.variants.iter().map( FieldOrVariant::from ); - Box::new( variants ) as DynIter2< 'a, FieldOrVariant< 'a > > + Box::new( variants ) as BoxedIter< 'a, FieldOrVariant< 'a > > }, } } @@ -349,11 +349,11 @@ pub( crate ) mod private } /// Returns an iterator over fields of the item. - // pub fn fields< 'a >( &'a self ) -> DynIter2< 'a, &'a syn::Field > - pub fn fields< 'a >( &'a self ) -> impl IterTraitClonable< 'a, &'a syn::Field > + // pub fn fields< 'a >( &'a self ) -> BoxedIter< 'a, &'a syn::Field > + pub fn fields< 'a >( &'a self ) -> impl IterTrait< 'a, &'a syn::Field > // xxx { - let result : DynIter2< 'a, &'a syn::Field > = match self + let result : BoxedIter< 'a, &'a syn::Field > = match self { StructLike::Unit( _item ) => { @@ -372,7 +372,7 @@ pub( crate ) mod private } /// Extracts the name of each field. - pub fn field_names< 'a >( &'a self ) -> Option< impl IterTraitClonable< 'a, &'a syn::Ident > + '_ > + pub fn field_names< 'a >( &'a self ) -> Option< impl IterTrait< 'a, &'a syn::Ident > + '_ > // pub fn field_names< 'a >( &'a self ) -> Option< DynIter< 'a, syn::Ident > > { match self @@ -387,7 +387,7 @@ pub( crate ) mod private }, StructLike::Enum( _item ) => { - let iter : DynIter2< 'a, &'a syn::Ident > = Box::new( self.fields().map( | field | field.ident.as_ref().unwrap() ) ); + let iter : BoxedIter< 'a, &'a syn::Ident > = Box::new( self.fields().map( | field | field.ident.as_ref().unwrap() ) ); Some( iter ) // Some( DynIter::new( self.fields().map( | field | field.ident.as_ref().unwrap() ) ) ) // Some( DynIterFrom::dyn_iter_from( self.fields().map( | field | field.ident.as_ref().unwrap() ) ) ) @@ -398,19 +398,21 @@ pub( crate ) mod private } /// Extracts the type of each field. - // pub fn field_types( &self ) -> Box< dyn Iterator< Item = &syn::Type > + '_ > - // pub fn field_types< 'a >( &'a self ) -> Box< dyn _IterTrait< 'a, &'a syn::Type > + '_ > - pub fn field_types< 'a >( &'a self ) -> impl IterTraitClonable< 'a, &'a syn::Type > + pub fn field_types< 'a >( &'a self ) -> impl IterTrait< 'a, &'a syn::Type > + // pub fn field_types< 'a >( &'a self ) -> BoxedIter< 'a, &'a syn::Type > { - Box::new( self.fields().map( | field | &field.ty ) ) + // Box::new( self.fields().map( | field | &field.ty ) ) + self.fields().map( | field | &field.ty ) } /// Extracts the name of each field. // pub fn field_attrs( &self ) -> Box< dyn Iterator< Item = &Vec< syn::Attribute > > + '_ > - // pub fn field_attrs< 'a >( &'a self ) -> Box< dyn _IterTrait< 'a, &'a Vec< syn::Attribute > > + '_ > - pub fn field_attrs< 'a >( &'a self ) -> impl IterTraitClonable< 'a, &'a Vec< syn::Attribute > > + pub fn field_attrs< 'a >( &'a self ) -> impl IterTrait< 'a, &'a Vec< syn::Attribute > > + // pub fn field_attrs< 'a >( &'a self ) -> BoxedIter< 'a, &'a Vec< syn::Attribute > > { - Box::new( self.fields().map( | field | &field.attrs ) ) + self.fields().map( | field | &field.attrs ) + // Box::new( self.fields().map( | field | &field.attrs ) ) + // xxx } /// Extract the first field. From a7bf9fc6d717fdd1d61738ddfc46d9cb60b0d86b Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 3 Jun 2024 08:23:17 +0300 Subject: [PATCH 18/45] clone_dyn : fixing it --- module/core/clone_dyn/Cargo.toml | 2 +- module/core/clone_dyn/tests/inc/basic.rs | 81 +++++----- .../core/clone_dyn/tests/inc/basic_manual.rs | 150 ++++++++---------- .../clone_dyn/tests/inc/only_test/basic.rs | 93 +++++++++++ 4 files changed, 207 insertions(+), 119 deletions(-) create mode 100644 module/core/clone_dyn/tests/inc/only_test/basic.rs diff --git a/module/core/clone_dyn/Cargo.toml b/module/core/clone_dyn/Cargo.toml index cad394cd65..4a8c70efe2 100644 --- a/module/core/clone_dyn/Cargo.toml +++ b/module/core/clone_dyn/Cargo.toml @@ -35,7 +35,7 @@ enabled = [ "clone_dyn_meta/enabled" ] [dependencies] clone_dyn_meta = { workspace = true } -inspect_type = { workspace = true, features = [ "full" ] } +# inspect_type = { workspace = true, features = [ "full" ] } [dev-dependencies] test_tools = { workspace = true } diff --git a/module/core/clone_dyn/tests/inc/basic.rs b/module/core/clone_dyn/tests/inc/basic.rs index 74629f266c..7b3e8d15e2 100644 --- a/module/core/clone_dyn/tests/inc/basic.rs +++ b/module/core/clone_dyn/tests/inc/basic.rs @@ -2,47 +2,56 @@ // #[ allow( unused_imports ) ] // use super::*; // -// #[ test ] -// fn basic() +// use the_module::clone_dyn; +// +// #[ clone_dyn ] +// trait Trait1 // { -// use the_module::clone_dyn; +// fn val( &self ) -> i32; +// } +// +// // // -// #[ clone_dyn ] -// trait Trait1 +// impl Trait1 for i32 +// { +// fn val( &self ) -> i32 // { -// fn val( &self ) -> i32; +// self.clone() // } +// } // -// impl Trait1 for i32 -// { -// fn val( &self ) -> i32 -// { -// self.clone() -// } -// }; -// impl Trait1 for i64 +// impl Trait1 for i64 +// { +// fn val( &self ) -> i32 // { -// fn val( &self ) -> i32 -// { -// self.clone().try_into().unwrap() -// } -// }; -// -// // impl PartialEq< Box< dyn Trait1 > > for Box< dyn Trait1 > -// // { -// // fn eq( &self, other : &Box< dyn Trait1 > ) -> bool -// // { -// // self == other -// // } -// // } -// -// // -// -// let vec : Vec< Box< dyn Trait1 > > = vec![ Box::new( 13 ), Box::new( 14 ) ]; -// let vec2 = vec.clone(); -// -// a_id!( vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(), vec2.iter().map( | e | e.val() ).collect::< Vec< _ > >() ) -// -// // xxx2 : continue +// self.clone().try_into().unwrap() +// } +// } // +// impl Trait1 for String +// { +// fn val( &self ) -> i32 +// { +// self.len().try_into().unwrap() +// } // } +// +// // impl< T > Trait1 for [ T ] +// // where +// // T : clone_dyn::CloneDyn, +// // { +// // fn val( &self ) -> i32 +// // { +// // self.len() +// // } +// // } +// // +// // impl Trait1 for str +// // { +// // fn val( &self ) -> i32 +// // { +// // self.len() +// // } +// // } +// +// // include!( "./only_test/basic.rs" ); diff --git a/module/core/clone_dyn/tests/inc/basic_manual.rs b/module/core/clone_dyn/tests/inc/basic_manual.rs index 3cd883ed61..8ca604aa91 100644 --- a/module/core/clone_dyn/tests/inc/basic_manual.rs +++ b/module/core/clone_dyn/tests/inc/basic_manual.rs @@ -2,111 +2,97 @@ #[ allow( unused_imports ) ] use super::*; +trait Trait1 +where + Self : clone_dyn::CloneDyn, +{ + fn val( &self ) -> i32; +} + // -// qqq2 : organize tests in the same way tests organized for derive_tools -#[ test ] -fn manual() +impl Trait1 for i32 { - - trait Trait1 - where - Self : clone_dyn::CloneDyn, + fn val( &self ) -> i32 { - fn val( &self ) -> i32; + self.clone() } +} - // - - impl Trait1 for i32 +impl Trait1 for i64 +{ + fn val( &self ) -> i32 { - fn val( &self ) -> i32 - { - self.clone() - } + self.clone().try_into().unwrap() } +} - impl Trait1 for i64 +impl Trait1 for String +{ + fn val( &self ) -> i32 { - fn val( &self ) -> i32 - { - self.clone().try_into().unwrap() - } + self.len().try_into().unwrap() } +} - // - - #[ allow( non_local_definitions ) ] - impl < 'c > Clone - for Box< dyn Trait1 + 'c > +impl< T > Trait1 for &[ T ] +// where +// T : clone_dyn::CloneDyn, +{ + fn val( &self ) -> i32 { - #[ inline ] - fn clone( &self ) -> Self - { - let x = &**self; - // inspect_type::inspect_type_of!( x ); - // clone_dyn::clone( self ) - clone_dyn::clone_into_box( &**self ) - } + self.len().try_into().unwrap() } +} - #[ allow( non_local_definitions ) ] - impl < 'c > Clone - for Box< dyn Trait1 + Send + 'c > +impl Trait1 for &str +{ + fn val( &self ) -> i32 { - #[ inline ] - fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } + self.len().try_into().unwrap() } +} - #[ allow( non_local_definitions ) ] - impl < 'c > Clone - for Box< dyn Trait1 + Sync + 'c > - { - #[ inline ] - fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } - } +// == begin of generated - #[ allow( non_local_definitions ) ] - impl < 'c > Clone - for Box< dyn Trait1 + Send + Sync + 'c > +#[ allow( non_local_definitions ) ] +impl < 'c > Clone +for Box< dyn Trait1 + 'c > +{ + #[ inline ] + fn clone( &self ) -> Self { - #[ inline ] - fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } + let x = &**self; + // inspect_type::inspect_type_of!( x ); + // clone_dyn::clone( self ) + clone_dyn::clone_into_box( &**self ) } +} - // - - let a : String = "abc".to_string(); - let b : Box< String > = clone_dyn::clone_into_box( &a ); - a_id!( a, *b ); - - // - - let a : String = "abc".to_string(); - let b = clone_dyn::clone( &a ); - a_id!( a, b ); - - // - - let a : &str = "abc"; - let b = clone_dyn::clone( &a ); - // let b = a.clone(); - a_id!( a, b ); - - // +#[ allow( non_local_definitions ) ] +impl < 'c > Clone +for Box< dyn Trait1 + Send + 'c > +{ + #[ inline ] + fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } +} - let vec : Vec< Box< dyn Trait1 > > = vec![ Box::new( 13 ), Box::new( 14 ) ]; - let vec2 = clone_dyn::clone( &vec ); - let vec = vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(); - let vec2 = vec2.iter().map( | e | e.val() ).collect::< Vec< _ > >(); - a_id!( vec, vec2 ); +#[ allow( non_local_definitions ) ] +impl < 'c > Clone +for Box< dyn Trait1 + Sync + 'c > +{ + #[ inline ] + fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } +} - // +#[ allow( non_local_definitions ) ] +impl < 'c > Clone +for Box< dyn Trait1 + Send + Sync + 'c > +{ + #[ inline ] + fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } +} - let vec : Vec< Box< dyn Trait1 > > = vec![ Box::new( 13 ), Box::new( 14 ) ]; - let vec2 = vec.clone(); - let vec = vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(); - let vec2 = vec2.iter().map( | e | e.val() ).collect::< Vec< _ > >(); - a_id!( vec, vec2 ); +// == end of generated -} +include!( "./only_test/basic.rs" ); diff --git a/module/core/clone_dyn/tests/inc/only_test/basic.rs b/module/core/clone_dyn/tests/inc/only_test/basic.rs new file mode 100644 index 0000000000..7615e54d36 --- /dev/null +++ b/module/core/clone_dyn/tests/inc/only_test/basic.rs @@ -0,0 +1,93 @@ + +#[ test ] +fn clone_into_box() +{ + + // copyable + + let a : i32 = 13; + let b : Box< i32 > = clone_dyn::clone_into_box( &a ); + a_id!( a, *b ); + + // clonable + + let a : String = "abc".to_string(); + let b : Box< String > = clone_dyn::clone_into_box( &a ); + a_id!( a, *b ); + + // str slice + + let a : &str = "abc"; + let b : Box< str > = clone_dyn::clone_into_box( a ); + a_id!( *a, *b ); + + // slice + + let a : &[ i32 ] = &[ 1, 2, 3 ]; + let b : Box< [ i32 ] > = clone_dyn::clone_into_box( a ); + a_id!( *a, *b ); + + // + +} + +#[ test ] +fn clone() +{ + + // copyable + + let a : i32 = 13; + let b : i32 = clone_dyn::clone( &a ); + a_id!( a, b ); + + // clonable + + let a : String = "abc".to_string(); + let b : String = clone_dyn::clone( &a ); + a_id!( a, b ); + + // str slice + + let a : &str = "abc"; + let b : &str = clone_dyn::clone( &a ); + a_id!( a, b ); + + // slice + + let a : &[ i32 ] = &[ 1, 2, 3 ]; + let b : &[ i32 ] = clone_dyn::clone( &a ); + a_id!( a, b ); + + // + +} + +#[ test ] +fn vector() +{ + + // + + let e_i32 : Box< dyn Trait1 > = Box::new( 13 ); + let e_i64 : Box< dyn Trait1 > = Box::new( 13 ); + let e_string : Box< dyn Trait1 > = Box::new( "abc".to_string() ); + let e_str_slice : Box< dyn Trait1 > = Box::new( "abc" ); + // let e_slice : Box< dyn Trait1 > = Box::new( &[ 1, 2, 3 ][ 0 ] ); + // xxx2 : continue + + let vec : Vec< Box< dyn Trait1 > > = vec![ e_i32, e_i64, e_string, e_str_slice ]; + let vec2 = clone_dyn::clone( &vec ); + let vec = vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(); + let vec2 = vec2.iter().map( | e | e.val() ).collect::< Vec< _ > >(); + a_id!( vec, vec2 ); + + // + + let vec : Vec< Box< dyn Trait1 > > = vec![ Box::new( 13 ), Box::new( 14i64 ) ]; + let vec2 = vec.clone(); + let vec = vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(); + let vec2 = vec2.iter().map( | e | e.val() ).collect::< Vec< _ > >(); + a_id!( vec, vec2 ); + +} From fd262d4bbbddef367cc7c6bd4f04864ae3488db9 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 3 Jun 2024 08:31:57 +0300 Subject: [PATCH 19/45] clone_dyn : fixing it --- .../core/clone_dyn/tests/inc/basic_manual.rs | 27 ++++++++++++++++--- .../clone_dyn/tests/inc/only_test/basic.rs | 2 +- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/module/core/clone_dyn/tests/inc/basic_manual.rs b/module/core/clone_dyn/tests/inc/basic_manual.rs index 8ca604aa91..e23459961a 100644 --- a/module/core/clone_dyn/tests/inc/basic_manual.rs +++ b/module/core/clone_dyn/tests/inc/basic_manual.rs @@ -15,10 +15,19 @@ impl Trait1 for i32 { fn val( &self ) -> i32 { - self.clone() + *self } } +// xxx : ? +// impl Trait1 for &i32 +// { +// fn val( &self ) -> i32 +// { +// **self +// } +// } + impl Trait1 for i64 { fn val( &self ) -> i32 @@ -36,8 +45,8 @@ impl Trait1 for String } impl< T > Trait1 for &[ T ] -// where -// T : clone_dyn::CloneDyn, +where + T : clone_dyn::CloneDyn, { fn val( &self ) -> i32 { @@ -45,6 +54,16 @@ impl< T > Trait1 for &[ T ] } } +// impl< T > Trait1 for &[ &T ] +// where +// T : clone_dyn::CloneDyn, +// { +// fn val( &self ) -> i32 +// { +// self.len().try_into().unwrap() +// } +// } + impl Trait1 for &str { fn val( &self ) -> i32 @@ -62,7 +81,7 @@ for Box< dyn Trait1 + 'c > #[ inline ] fn clone( &self ) -> Self { - let x = &**self; + // let x = &**self; // inspect_type::inspect_type_of!( x ); // clone_dyn::clone( self ) clone_dyn::clone_into_box( &**self ) diff --git a/module/core/clone_dyn/tests/inc/only_test/basic.rs b/module/core/clone_dyn/tests/inc/only_test/basic.rs index 7615e54d36..ce0b925053 100644 --- a/module/core/clone_dyn/tests/inc/only_test/basic.rs +++ b/module/core/clone_dyn/tests/inc/only_test/basic.rs @@ -73,7 +73,7 @@ fn vector() let e_i64 : Box< dyn Trait1 > = Box::new( 13 ); let e_string : Box< dyn Trait1 > = Box::new( "abc".to_string() ); let e_str_slice : Box< dyn Trait1 > = Box::new( "abc" ); - // let e_slice : Box< dyn Trait1 > = Box::new( &[ 1, 2, 3 ][ 0 ] ); + let e_slice : Box< dyn Trait1 > = Box::new( &[ 1i32, 2i32, 3i32 ][ 0 ] ); // xxx2 : continue let vec : Vec< Box< dyn Trait1 > > = vec![ e_i32, e_i64, e_string, e_str_slice ]; From 739b528e90db67443e0007d3bff8b0e9ee3b66ca Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 3 Jun 2024 14:45:00 +0300 Subject: [PATCH 20/45] clone_dyn : fixing it --- .../core/clone_dyn/tests/inc/basic_manual.rs | 19 ------------------- .../clone_dyn/tests/inc/only_test/basic.rs | 3 +-- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/module/core/clone_dyn/tests/inc/basic_manual.rs b/module/core/clone_dyn/tests/inc/basic_manual.rs index e23459961a..f4d8d2958d 100644 --- a/module/core/clone_dyn/tests/inc/basic_manual.rs +++ b/module/core/clone_dyn/tests/inc/basic_manual.rs @@ -19,15 +19,6 @@ impl Trait1 for i32 } } -// xxx : ? -// impl Trait1 for &i32 -// { -// fn val( &self ) -> i32 -// { -// **self -// } -// } - impl Trait1 for i64 { fn val( &self ) -> i32 @@ -54,16 +45,6 @@ where } } -// impl< T > Trait1 for &[ &T ] -// where -// T : clone_dyn::CloneDyn, -// { -// fn val( &self ) -> i32 -// { -// self.len().try_into().unwrap() -// } -// } - impl Trait1 for &str { fn val( &self ) -> i32 diff --git a/module/core/clone_dyn/tests/inc/only_test/basic.rs b/module/core/clone_dyn/tests/inc/only_test/basic.rs index ce0b925053..4431aed5f7 100644 --- a/module/core/clone_dyn/tests/inc/only_test/basic.rs +++ b/module/core/clone_dyn/tests/inc/only_test/basic.rs @@ -73,8 +73,7 @@ fn vector() let e_i64 : Box< dyn Trait1 > = Box::new( 13 ); let e_string : Box< dyn Trait1 > = Box::new( "abc".to_string() ); let e_str_slice : Box< dyn Trait1 > = Box::new( "abc" ); - let e_slice : Box< dyn Trait1 > = Box::new( &[ 1i32, 2i32, 3i32 ][ 0 ] ); - // xxx2 : continue + let e_slice : Box< dyn Trait1 > = Box::new( &[ 1i32, 2i32, 3i32 ] as &[ i32 ] ); let vec : Vec< Box< dyn Trait1 > > = vec![ e_i32, e_i64, e_string, e_str_slice ]; let vec2 = clone_dyn::clone( &vec ); From a0d18cbd728f32fd77602e1dcc70b849f3a8ff31 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 3 Jun 2024 14:48:26 +0300 Subject: [PATCH 21/45] clone_dyn : fixing it --- .../clone_dyn/tests/inc/only_test/basic.rs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/module/core/clone_dyn/tests/inc/only_test/basic.rs b/module/core/clone_dyn/tests/inc/only_test/basic.rs index 4431aed5f7..a5f2d7d74a 100644 --- a/module/core/clone_dyn/tests/inc/only_test/basic.rs +++ b/module/core/clone_dyn/tests/inc/only_test/basic.rs @@ -70,12 +70,21 @@ fn vector() // let e_i32 : Box< dyn Trait1 > = Box::new( 13 ); - let e_i64 : Box< dyn Trait1 > = Box::new( 13 ); + let e_i64 : Box< dyn Trait1 > = Box::new( 14 ); let e_string : Box< dyn Trait1 > = Box::new( "abc".to_string() ); - let e_str_slice : Box< dyn Trait1 > = Box::new( "abc" ); - let e_slice : Box< dyn Trait1 > = Box::new( &[ 1i32, 2i32, 3i32 ] as &[ i32 ] ); + let e_str_slice : Box< dyn Trait1 > = Box::new( "abcd" ); + let e_slice : Box< dyn Trait1 > = Box::new( &[ 1i32, 2i32 ] as &[ i32 ] ); - let vec : Vec< Box< dyn Trait1 > > = vec![ e_i32, e_i64, e_string, e_str_slice ]; + // + + let vec : Vec< Box< dyn Trait1 > > = vec![ e_i32.clone(), e_i64.clone(), e_string.clone(), e_str_slice.clone(), e_slice.clone() ]; + let vec = vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(); + let vec2 = vec![ 13, 14, 3, 4, 2 ]; + a_id!( vec, vec2 ); + + // + + let vec : Vec< Box< dyn Trait1 > > = vec![ e_i32.clone(), e_i64.clone(), e_string.clone(), e_str_slice.clone(), e_slice.clone() ]; let vec2 = clone_dyn::clone( &vec ); let vec = vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(); let vec2 = vec2.iter().map( | e | e.val() ).collect::< Vec< _ > >(); @@ -83,10 +92,12 @@ fn vector() // - let vec : Vec< Box< dyn Trait1 > > = vec![ Box::new( 13 ), Box::new( 14i64 ) ]; + let vec : Vec< Box< dyn Trait1 > > = vec![ e_i32.clone(), e_i64.clone(), e_string.clone(), e_str_slice.clone(), e_slice.clone() ]; let vec2 = vec.clone(); let vec = vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(); let vec2 = vec2.iter().map( | e | e.val() ).collect::< Vec< _ > >(); a_id!( vec, vec2 ); + // + } From 2d0621f76c241155dcb64c6db2d6287811444210 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 3 Jun 2024 18:34:06 +0300 Subject: [PATCH 22/45] clone_dyn : fixing it --- module/core/clone_dyn/tests/inc/basic.rs | 116 ++++++++-------- module/core/clone_dyn_meta/Cargo.toml | 6 +- module/core/clone_dyn_meta/src/derive.rs | 155 +++++++++++++++++++--- module/core/derive_tools/tests/inc/mod.rs | 1 + module/core/derive_tools_meta/src/lib.rs | 6 +- 5 files changed, 204 insertions(+), 80 deletions(-) diff --git a/module/core/clone_dyn/tests/inc/basic.rs b/module/core/clone_dyn/tests/inc/basic.rs index 7b3e8d15e2..08f937c225 100644 --- a/module/core/clone_dyn/tests/inc/basic.rs +++ b/module/core/clone_dyn/tests/inc/basic.rs @@ -1,57 +1,59 @@ -// -// #[ allow( unused_imports ) ] -// use super::*; -// -// use the_module::clone_dyn; -// -// #[ clone_dyn ] -// trait Trait1 -// { -// fn val( &self ) -> i32; -// } -// -// // -// -// impl Trait1 for i32 -// { -// fn val( &self ) -> i32 -// { -// self.clone() -// } -// } -// -// impl Trait1 for i64 -// { -// fn val( &self ) -> i32 -// { -// self.clone().try_into().unwrap() -// } -// } -// -// impl Trait1 for String -// { -// fn val( &self ) -> i32 -// { -// self.len().try_into().unwrap() -// } -// } -// -// // impl< T > Trait1 for [ T ] -// // where -// // T : clone_dyn::CloneDyn, -// // { -// // fn val( &self ) -> i32 -// // { -// // self.len() -// // } -// // } -// // -// // impl Trait1 for str -// // { -// // fn val( &self ) -> i32 -// // { -// // self.len() -// // } -// // } -// -// // include!( "./only_test/basic.rs" ); + +#[ allow( unused_imports ) ] +use super::*; + +use the_module::clone_dyn; + +#[ clone_dyn( debug ) ] +trait Trait1 +where + Self : clone_dyn::CloneDyn, +{ + fn val( &self ) -> i32; +} + +// + +impl Trait1 for i32 +{ + fn val( &self ) -> i32 + { + *self + } +} + +impl Trait1 for i64 +{ + fn val( &self ) -> i32 + { + self.clone().try_into().unwrap() + } +} + +impl Trait1 for String +{ + fn val( &self ) -> i32 + { + self.len().try_into().unwrap() + } +} + +impl< T > Trait1 for &[ T ] +where + T : clone_dyn::CloneDyn, +{ + fn val( &self ) -> i32 + { + self.len().try_into().unwrap() + } +} + +impl Trait1 for &str +{ + fn val( &self ) -> i32 + { + self.len().try_into().unwrap() + } +} + +include!( "./only_test/basic.rs" ); diff --git a/module/core/clone_dyn_meta/Cargo.toml b/module/core/clone_dyn_meta/Cargo.toml index 3b371d1629..54470330db 100644 --- a/module/core/clone_dyn_meta/Cargo.toml +++ b/module/core/clone_dyn_meta/Cargo.toml @@ -31,10 +31,12 @@ proc-macro = true [features] default = [ "enabled" ] full = [ "enabled" ] -enabled = [ "macro_tools/enabled" ] +enabled = [ "macro_tools/enabled", "former_types/enabled" ] [dependencies] -macro_tools = { workspace = true } +macro_tools = { workspace = true } # qqq : xxx : optimize set of features +former_types = { workspace = true, features = [ "types_component_assign" ] } +const_format = { version = "0.2.32" } [dev-dependencies] test_tools = { workspace = true } diff --git a/module/core/clone_dyn_meta/src/derive.rs b/module/core/clone_dyn_meta/src/derive.rs index 8cb49974e9..ae226b1494 100644 --- a/module/core/clone_dyn_meta/src/derive.rs +++ b/module/core/clone_dyn_meta/src/derive.rs @@ -1,22 +1,45 @@ use macro_tools::prelude::*; -use macro_tools::{ Result, generic_params }; +use macro_tools:: +{ + Result, + AttributePropertyOptionalSingletone, + AttributePropertyComponent, + attr, + diag, + generic_params, +}; +use former_types::{ Assign }; +// use const_format::concatcp; +// xxx : incapsulate into macro_tools and put all that udner features // -pub fn clone_dyn( _attr : proc_macro::TokenStream, item : proc_macro::TokenStream ) -> Result< proc_macro2::TokenStream > +pub fn clone_dyn( attr_input : proc_macro::TokenStream, item_input : proc_macro::TokenStream ) +-> Result< proc_macro2::TokenStream > { - let item_parsed = match syn::parse::< syn::ItemTrait >( item ) + println!( "attr_input : \"{}\"", attr_input.to_string() ); + println!( "item_input : \"{}\"", item_input.to_string() ); + + // let attrs : ItemAttributes = item_input.parse()?; + let attrs = syn::parse::< ItemAttributes >( attr_input )?; + let original_input = item_input.clone(); + let item_parsed = match syn::parse::< syn::ItemTrait >( item_input ) { Ok( original ) => original, Err( err ) => return Err( err ), }; - let name_ident = &item_parsed.ident; + // let has_debug = attr::has_debug( item_parsed.attrs.iter() )?; + let has_debug = attrs.debug.value( false ); + let item_name = &item_parsed.ident; - let generic_params = &item_parsed.generics.params; - let generics_where = &item_parsed.generics.where_clause; + let ( _generics_with_defaults, generics_impl, _generics_ty, generics_where ) + = generic_params::decompose( &item_parsed.generics ); + + // let generic_params = &item_parsed.generics.params; + // let generics_where = &item_parsed.generics.where_clause; let generics_names : Vec< _ > = generic_params::names( &item_parsed.generics ).collect(); let result = qt! @@ -24,40 +47,40 @@ pub fn clone_dyn( _attr : proc_macro::TokenStream, item : proc_macro::TokenStrea #item_parsed #[ allow( non_local_definitions ) ] - impl < 'c, #generic_params > Clone - for Box< dyn #name_ident< #( #generics_names ),* > + 'c > + impl < 'c, #generics_impl > Clone + for Box< dyn #item_name< #( #generics_names ),* > + 'c > // where - #generics_where + // #generics_where { #[ inline ] fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } } #[ allow( non_local_definitions ) ] - impl < 'c, #generic_params > Clone - for Box< dyn #name_ident< #( #generics_names ),* > + Send + 'c > + impl < 'c, #generics_impl > Clone + for Box< dyn #item_name< #( #generics_names ),* > + Send + 'c > // where - #generics_where + // #generics_where { #[ inline ] fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } } #[ allow( non_local_definitions ) ] - impl < 'c, #generic_params > Clone - for Box< dyn #name_ident< #( #generics_names ),* > + Sync + 'c > + impl < 'c, #generics_impl > Clone + for Box< dyn #item_name< #( #generics_names ),* > + Sync + 'c > // where - #generics_where + // #generics_where { #[ inline ] fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } } #[ allow( non_local_definitions ) ] - impl < 'c, #generic_params > Clone - for Box< dyn #name_ident< #( #generics_names ),* > + Send + Sync + 'c > + impl < 'c, #generics_impl > Clone + for Box< dyn #item_name< #( #generics_names ),* > + Send + Sync + 'c > // where - #generics_where + // #generics_where { #[ inline ] fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } @@ -65,5 +88,101 @@ pub fn clone_dyn( _attr : proc_macro::TokenStream, item : proc_macro::TokenStrea }; + if has_debug + { + let about = format!( "macro : CloneDny\ntrait : {item_name}" ); + diag::report_print( about, &original_input, &result ); + } + Ok( result ) } + +// == attributes + +/// Represents the attributes of a struct. Aggregates all its attributes. +#[ derive( Debug, Default ) ] +pub struct ItemAttributes +{ + /// Attribute for customizing generated code. + pub debug : AttributePropertyDebug, +} + +impl syn::parse::Parse for ItemAttributes +{ + fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self > + { + let mut result = Self::default(); + + let error = | ident : &syn::Ident | -> syn::Error + { + let known = const_format::concatcp! + ( + "Known properties of attribute `clone_dyn` are : ", + AttributePropertyDebug::KEYWORD, + ".", + ); + syn_err! + ( + ident, + r#"Expects an attribute of format '#[ clone_dyn( {} ) ]' + {known} + But got: '{}' +"#, + AttributePropertyDebug::KEYWORD, + qt!{ #ident } + ) + }; + + while !input.is_empty() + { + let lookahead = input.lookahead1(); + if lookahead.peek( syn::Ident ) + { + let ident : syn::Ident = input.parse()?; + match ident.to_string().as_str() + { + AttributePropertyDebug::KEYWORD => result.assign( AttributePropertyDebug::from( true ) ), + _ => return Err( error( &ident ) ), + } + } + else + { + return Err( lookahead.error() ); + } + + // Optional comma handling + if input.peek( syn::Token![ , ] ) + { + input.parse::< syn::Token![ , ] >()?; + } + } + + Ok( result ) + } +} + +impl< IntoT > Assign< AttributePropertyDebug, IntoT > for ItemAttributes +where + IntoT : Into< AttributePropertyDebug >, +{ + #[ inline( always ) ] + fn assign( &mut self, prop : IntoT ) + { + self.debug = prop.into(); + } +} + +// == attribute properties + +/// Marker type for attribute property to specify whether to provide a generated code as a hint. +#[ derive( Debug, Default, Clone, Copy ) ] +pub struct AttributePropertyDebugMarker; + +impl AttributePropertyComponent for AttributePropertyDebugMarker +{ + const KEYWORD : &'static str = "debug"; +} + +/// Specifies whether to provide a generated code as a hint. +/// Defaults to `false`, which means no debug is provided unless explicitly requested. +pub type AttributePropertyDebug = AttributePropertyOptionalSingletone< AttributePropertyDebugMarker >; diff --git a/module/core/derive_tools/tests/inc/mod.rs b/module/core/derive_tools/tests/inc/mod.rs index a79deeb407..8dc439c8d8 100644 --- a/module/core/derive_tools/tests/inc/mod.rs +++ b/module/core/derive_tools/tests/inc/mod.rs @@ -178,6 +178,7 @@ mod new_tests mod multiple_named_test; mod multiple_unnamed_manual_test; // mod multiple_unnamed_test; + // xxx : continue // diff --git a/module/core/derive_tools_meta/src/lib.rs b/module/core/derive_tools_meta/src/lib.rs index b3e15ba826..451bce9df8 100644 --- a/module/core/derive_tools_meta/src/lib.rs +++ b/module/core/derive_tools_meta/src/lib.rs @@ -77,7 +77,7 @@ mod derive; From, attributes ( - debug, // struct + debug, // item from, // field ) )] @@ -132,7 +132,7 @@ pub fn from( input : proc_macro::TokenStream ) -> proc_macro::TokenStream New, attributes ( - debug, // struct + debug, // item new, // field ) )] @@ -487,7 +487,7 @@ pub fn as_mut( input : proc_macro::TokenStream ) -> proc_macro::TokenStream /// #[ derive( Debug, PartialEq, Default, VariadicFrom ) ] /// // Use `#[ debug ]` to expand and debug generate code. /// // #[ debug ] -/// struct MyStruct +/// item MyStruct /// { /// a : i32, /// b : i32, From 5aa444819d293af2ff0c4b6b914c296e92f7d7ff Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 00:47:37 +0300 Subject: [PATCH 23/45] clone_dyn : fixing it --- module/core/clone_dyn/Readme.md | 2 +- module/core/clone_dyn/src/lib.rs | 115 ++++++++--- module/core/clone_dyn/tests/inc/basic.rs | 4 +- .../core/clone_dyn/tests/inc/basic_manual.rs | 3 - module/core/clone_dyn/tests/inc/mod.rs | 189 +----------------- .../clone_dyn/tests/inc/only_test/basic.rs | 2 +- .../core/clone_dyn/tests/inc/parametrized.rs | 130 ++++++++++++ module/core/clone_dyn_meta/src/derive.rs | 42 ++-- module/core/macro_tools/Cargo.toml | 3 +- module/core/macro_tools/src/iter.rs | 44 ++-- 10 files changed, 269 insertions(+), 265 deletions(-) create mode 100644 module/core/clone_dyn/tests/inc/parametrized.rs diff --git a/module/core/clone_dyn/Readme.md b/module/core/clone_dyn/Readme.md index 4a8efa5ae2..3ddf29a341 100644 --- a/module/core/clone_dyn/Readme.md +++ b/module/core/clone_dyn/Readme.md @@ -10,7 +10,7 @@ By default, Rust does not support cloning for trait objects due to the `Clone` t ### Alternative -There are few alternatives [dyn-clone](https://github.com/dtolnay/dyn-clone), [dyn-clonable](https://github.com/kardeiz/objekt-clonable). Unlike other options, this solution is more concise and demands less effort to use, all without compromising the quality of the outcome. Also, you can ask an inquiry and get answers, which is problematic in the case of alternatives. +There are few alternatives [dyn-clone](https://github.com/dtolnay/dyn-clone), [dyn-clonable](https://github.com/kardeiz/objekt-clonable). Unlike other options, this solution is more concise and demands less effort to use, all without compromising the quality of the outcome. ### Basic use-case diff --git a/module/core/clone_dyn/src/lib.rs b/module/core/clone_dyn/src/lib.rs index 3f86087183..2e98942937 100644 --- a/module/core/clone_dyn/src/lib.rs +++ b/module/core/clone_dyn/src/lib.rs @@ -2,7 +2,8 @@ #![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] #![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] #![ doc( html_root_url = "https://docs.rs/clone_dyn/latest/clone_dyn/" ) ] -#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] +// #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] +// xxx #[ allow( unused_extern_crates ) ] #[ cfg( feature = "enabled" ) ] @@ -33,9 +34,9 @@ pub( crate ) mod private /// A trait to upcast a clonable entity and clone it. /// It's implemented for all entities which can be cloned. - pub trait CloneDyn + pub trait CloneDyn : Sealed { - fn __clone_dyn( &self ) -> *mut (); + fn __clone_dyn( &self, _ : DontCallMe ) -> *mut (); } // clonable @@ -43,7 +44,8 @@ pub( crate ) mod private where T : Clone, { - fn __clone_dyn( &self ) -> *mut () + #[ inline ] + fn __clone_dyn( &self, _ : DontCallMe ) -> *mut () { Box::< T >::into_raw( Box::new( self.clone() ) ) as *mut () } @@ -54,7 +56,8 @@ pub( crate ) mod private where T : Clone, { - fn __clone_dyn( &self ) -> *mut () + #[ inline ] + fn __clone_dyn( &self, _ : DontCallMe ) -> *mut () { Box::< [ T ] >::into_raw( self.iter().cloned().collect() ) as *mut () } @@ -63,58 +66,120 @@ pub( crate ) mod private // str slice impl CloneDyn for str { - fn __clone_dyn( &self ) -> *mut () + #[ inline ] + fn __clone_dyn( &self, _ : DontCallMe ) -> *mut () { Box::< str >::into_raw( Box::from( self ) ) as *mut () } } /// - /// True clone which is applicable not only to clonable entities, but to trait object implementing CloneDyn. + /// True clone which is applicable not only to clonable entities, but to trait objects implementing CloneDyn. /// + /// # Example + /// + /// ``` + /// use clone_dyn::clone; + /// + /// #[ derive( Clone ) ] + /// struct MyStruct + /// { + /// value : i32, + /// } + /// + /// let original = MyStruct { value : 42 }; + /// let cloned = clone( &original ); + /// + /// assert_eq!( original.value, cloned.value ); + /// ``` + + #[ inline ] pub fn clone< T >( src : &T ) -> T where T : CloneDyn, { + /// # Safety + /// + /// This function uses an `unsafe` block because it performs low-level memory manipulations. Specifically, it handles + /// raw pointers and converts them to and from `Box< T >`. This is necessary to dynamically clone a trait object, which + /// does not support cloning through the standard `Clone` trait. The safety of this function depends on the guarantee + /// that the `CloneDyn` trait is correctly implemented for the given type `T`, ensuring that `__clone_dyn` returns a + /// valid pointer to a cloned instance of `T`. + /// + #[ allow( unsafe_code ) ] unsafe { - *Box::from_raw( < T as CloneDyn >::__clone_dyn( src ) as *mut T ) + *Box::from_raw( < T as CloneDyn >::__clone_dyn( src, DontCallMe ) as *mut T ) } } + /// /// Clone boxed dyn. /// - /// Not intended to be used directly. + /// Clones a dynamically sized trait object into a `Box< T >`. + /// + /// # Example + /// + /// ``` + /// use clone_dyn::{ clone_into_box, clone_dyn }; + /// + /// #[ derive( Clone ) ] + /// struct MyStruct + /// { + /// value : i32, + /// } + /// + /// #[ clone_dyn ] + /// trait MyTrait + /// { + /// fn val( &self ) -> i32; + /// } + /// + /// impl MyTrait for MyStruct + /// { + /// fn val( &self ) -> i32 + /// { + /// self.value + /// } + /// } + /// + /// let cloned : Box< dyn MyTrait > = clone_into_box( &MyStruct { value : 42 } ); + /// + /// ``` + #[ inline ] pub fn clone_into_box< T >( ref_dyn : &T ) -> Box< T > where T : ?Sized + CloneDyn, { - // Explanation for the use of `unsafe`: - // The `unsafe` block is necessary here because we're performing low-level memory manipulations - // that cannot be checked by the Rust compiler for safety. Specifically, we're manually handling - // raw pointers and converting them to and from `Box< T >`, which is considered unsafe as it - // bypasses Rust's ownership and borrowing rules. This is done to dynamically clone a boxed - // trait object, which doesn't support cloning through the standard `Clone` trait. The operations - // within this block are carefully crafted to ensure memory safety manually, including proper - // allocation and deallocation of heap memory for the clone. + /// # Safety + /// + /// This function uses an `unsafe` block because it performs low-level memory manipulations involving raw pointers. + /// The `unsafe` block is necessary here because we're manually handling raw pointers and converting them to and from + /// `Box`. This bypasses Rust's ownership and borrowing rules to achieve dynamic cloning of a boxed trait object. + /// The safety of this function relies on the correct implementation of the `CloneDyn` trait for the given type `T`. + /// Specifically, `__clone_dyn` must return a valid pointer to a cloned instance of `T`. + /// #[ allow( unsafe_code ) ] unsafe { let mut ptr = ref_dyn as *const T; - // println!( "ptr : {:p} | size : {}", ptr, core::mem::size_of_val( &ptr ) ); - // inspect_type::inspect_type_of!( ptr ); let data_ptr = &mut ptr as *mut *const T as *mut *mut (); - // println!( "data_ptr : {:p} | size : {}", data_ptr, core::mem::size_of_val( &data_ptr ) ); - // inspect_type::inspect_type_of!( data_ptr ); - // println!( "*data_ptr : {:p} | size : {}", *data_ptr, core::mem::size_of_val( &*data_ptr ) ); - // inspect_type::inspect_type_of!( data_ptr ); - *data_ptr = < T as CloneDyn >::__clone_dyn( ref_dyn ); - // println!( "" ); + *data_ptr = < T as CloneDyn >::__clone_dyn( ref_dyn, DontCallMe ); Box::from_raw( ptr as *mut T ) } } + mod sealed + { + pub struct DontCallMe; + pub trait Sealed {} + impl< T : Clone > Sealed for T {} + impl< T : Clone > Sealed for [ T ] {} + impl Sealed for str {} + } + use sealed::*; + } #[ cfg( feature = "enabled" ) ] diff --git a/module/core/clone_dyn/tests/inc/basic.rs b/module/core/clone_dyn/tests/inc/basic.rs index 08f937c225..72a8770a6a 100644 --- a/module/core/clone_dyn/tests/inc/basic.rs +++ b/module/core/clone_dyn/tests/inc/basic.rs @@ -4,10 +4,8 @@ use super::*; use the_module::clone_dyn; -#[ clone_dyn( debug ) ] +#[ clone_dyn ] trait Trait1 -where - Self : clone_dyn::CloneDyn, { fn val( &self ) -> i32; } diff --git a/module/core/clone_dyn/tests/inc/basic_manual.rs b/module/core/clone_dyn/tests/inc/basic_manual.rs index f4d8d2958d..7ee9519120 100644 --- a/module/core/clone_dyn/tests/inc/basic_manual.rs +++ b/module/core/clone_dyn/tests/inc/basic_manual.rs @@ -62,9 +62,6 @@ for Box< dyn Trait1 + 'c > #[ inline ] fn clone( &self ) -> Self { - // let x = &**self; - // inspect_type::inspect_type_of!( x ); - // clone_dyn::clone( self ) clone_dyn::clone_into_box( &**self ) } } diff --git a/module/core/clone_dyn/tests/inc/mod.rs b/module/core/clone_dyn/tests/inc/mod.rs index 1dca330f92..8b790f55cf 100644 --- a/module/core/clone_dyn/tests/inc/mod.rs +++ b/module/core/clone_dyn/tests/inc/mod.rs @@ -2,192 +2,7 @@ #[ allow( unused_imports ) ] use super::*; -// - -tests_impls! -{ - - // - -// // qqq2 : organize tests in the same way tests organized for derive_tools -// fn manual() -// { -// -// trait Trait1 -// { -// } -// -// // -// -// #[ inline ] -// pub fn clone_into_box< T >( t : &T ) -> Box< T > -// where -// T : ?Sized, -// { -// unsafe -// { -// let mut ptr = t as *const T; -// let data_ptr = &mut ptr as *mut *const T as *mut *mut (); -// *data_ptr = Box::into_raw( Box::new( t.clone() ) ) as *mut (); -// Box::from_raw( ptr as *mut T ) -// } -// } -// -// // -// -// #[ allow( non_local_definitions ) ] -// impl < 'c > Clone -// for Box< dyn Trait1 + 'c > -// { -// #[ inline ] -// fn clone( &self ) -> Self { clone_into_box( &**self ) } -// } -// -// #[ allow( non_local_definitions ) ] -// impl < 'c > Clone -// for Box< dyn Trait1 + Send + 'c > -// { -// #[ inline ] -// fn clone( &self ) -> Self { clone_into_box( &**self ) } -// } -// -// #[ allow( non_local_definitions ) ] -// impl < 'c > Clone -// for Box< dyn Trait1 + Sync + 'c > -// { -// #[ inline ] -// fn clone( &self ) -> Self { clone_into_box( &**self ) } -// } -// -// #[ allow( non_local_definitions ) ] -// impl < 'c > Clone -// for Box< dyn Trait1 + Send + Sync + 'c > -// { -// #[ inline ] -// fn clone( &self ) -> Self { clone_into_box( &**self ) } -// } -// -// // -// -// let vec = Vec::< Box< dyn Trait1 > >::new(); -// let vec2 = vec.clone(); -// -// } -// -// // -// -// fn basic() -// { -// use the_module::clone_dyn; -// -// #[ clone_dyn ] -// trait Trait1 -// { -// fn val( &self ) -> i32; -// } -// -// impl Trait1 for i32 -// { -// fn val( &self ) -> i32 -// { -// self.clone() -// } -// }; -// impl Trait1 for i64 -// { -// fn val( &self ) -> i32 -// { -// self.clone().try_into().unwrap() -// } -// }; -// -// // impl PartialEq< Box< dyn Trait1 > > for Box< dyn Trait1 > -// // { -// // fn eq( &self, other : &Box< dyn Trait1 > ) -> bool -// // { -// // self == other -// // } -// // } -// -// // -// -// let vec : Vec< Box< dyn Trait1 > > = vec![ Box::new( 13 ), Box::new( 14 ) ]; -// let vec2 = vec.clone(); -// -// a_id!( vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(), vec2.iter().map( | e | e.val() ).collect::< Vec< _ > >() ) -// -// // xxx2 : continue -// -// } - - // - -// fn prelude() -// { -// use the_module::prelude::*; -// -// #[ clone_dyn ] -// trait Trait1 -// { -// } -// -// // -// -// let vec = Vec::< Box< dyn Trait1 > >::new(); -// // let vec2 = vec.clone(); -// // xxx -// -// } -// -// // -// -// fn parametrized() -// { -// use the_module::clone_dyn; -// -// #[ clone_dyn ] -// trait Trait2< T1 : Copy, T2 : Copy > -// where -// T2 : Clone + core::fmt::Debug, -// { -// } -// -// // -// -// let vec = Vec::< Box< dyn Trait2< i32, f32 > > >::new(); -// let vec2 = vec.clone(); -// -// } -// -// // -// -// fn sample() -// { -// use the_module::clone_dyn; -// -// #[ clone_dyn ] -// trait Trait1 -// { -// } -// -// let vec = Vec::< Box< dyn Trait1 > >::new(); -// let vec2 = vec.clone(); /* <- it does not work without `clone_dyn` */ -// -// } - -} - -// - -tests_index! -{ - // manual, - // basic, - // prelude, - // parametrized, - // sample, -} -// xxx - mod basic_manual; mod basic; +mod parametrized; + diff --git a/module/core/clone_dyn/tests/inc/only_test/basic.rs b/module/core/clone_dyn/tests/inc/only_test/basic.rs index a5f2d7d74a..3883351320 100644 --- a/module/core/clone_dyn/tests/inc/only_test/basic.rs +++ b/module/core/clone_dyn/tests/inc/only_test/basic.rs @@ -64,7 +64,7 @@ fn clone() } #[ test ] -fn vector() +fn basic() { // diff --git a/module/core/clone_dyn/tests/inc/parametrized.rs b/module/core/clone_dyn/tests/inc/parametrized.rs new file mode 100644 index 0000000000..96edbc1456 --- /dev/null +++ b/module/core/clone_dyn/tests/inc/parametrized.rs @@ -0,0 +1,130 @@ + +#[ allow( unused_imports ) ] +use super::*; +use the_module::prelude::*; + +// + +#[ clone_dyn ] +trait Trait1< T1 : ::core::fmt::Debug, T2 > +where + T2 : ::core::fmt::Debug, + Self : ::core::fmt::Debug, +{ + fn dbg( &self ) -> String + { + format!( "{:?}", self ) + } +} + +// + +#[ derive( Debug, Clone ) ] +struct Struct1< T1, T2 > +where + T1 : ::core::fmt::Debug, + T2 : ::core::fmt::Debug, +{ + a : T1, + b : T2, +} + +impl Trait1< i32, char > for Struct1< i32, char > +{ + fn dbg( &self ) -> String + { + format!( "{self:?}( {:?} {:?} )", self.a, self.b ) + } +} + +// + +impl Trait1< i32, char > for i32 +{ + fn dbg( &self ) -> String + { + format!( "{:?}", self ) + } +} + +impl Trait1< i32, char > for i64 +{ + fn dbg( &self ) -> String + { + format!( "{:?}", self ) + } +} + +impl Trait1< i32, char > for String +{ + fn dbg( &self ) -> String + { + format!( "{:?}", self ) + } +} + +impl< T > Trait1< i32, char > for &[ T ] +where + T : clone_dyn::CloneDyn, + Self : ::core::fmt::Debug, +{ + fn dbg( &self ) -> String + { + format!( "{:?}", self ) + } +} + +impl Trait1< i32, char > for &str +{ + fn dbg( &self ) -> String + { + format!( "{:?}", self ) + } +} + + +#[ test ] +fn basic() +{ + + // + + let e_i32 : Box< dyn Trait1< i32, char > > = Box::new( 13 ); + let e_i64 : Box< dyn Trait1< i32, char > > = Box::new( 14 ); + let e_string : Box< dyn Trait1< i32, char > > = Box::new( "abc".to_string() ); + let e_str_slice : Box< dyn Trait1< i32, char > > = Box::new( "abcd" ); + let e_slice : Box< dyn Trait1< i32, char > > = Box::new( &[ 1i32, 2i32 ] as &[ i32 ] ); + + // + + let vec : Vec< Box< dyn Trait1< i32, char > > > = vec![ e_i32.clone(), e_i64.clone(), e_string.clone(), e_str_slice.clone(), e_slice.clone() ]; + let vec = vec.iter().map( | e | e.dbg() ).collect::< Vec< _ > >(); + let vec2 = vec! + [ + "13".to_string(), + "14".to_string(), + "\"abc\"".to_string(), + "\"abcd\"".to_string(), + "[1, 2]".to_string(), + ]; + a_id!( vec, vec2 ); + + // + + let vec : Vec< Box< dyn Trait1< i32, char > > > = vec![ e_i32.clone(), e_i64.clone(), e_string.clone(), e_str_slice.clone(), e_slice.clone() ]; + let vec2 = clone_dyn::clone( &vec ); + let vec = vec.iter().map( | e | e.dbg() ).collect::< Vec< _ > >(); + let vec2 = vec2.iter().map( | e | e.dbg() ).collect::< Vec< _ > >(); + a_id!( vec, vec2 ); + + // + + let vec : Vec< Box< dyn Trait1< i32, char > > > = vec![ e_i32.clone(), e_i64.clone(), e_string.clone(), e_str_slice.clone(), e_slice.clone() ]; + let vec2 = vec.clone(); + let vec = vec.iter().map( | e | e.dbg() ).collect::< Vec< _ > >(); + let vec2 = vec2.iter().map( | e | e.dbg() ).collect::< Vec< _ > >(); + a_id!( vec, vec2 ); + + // + +} diff --git a/module/core/clone_dyn_meta/src/derive.rs b/module/core/clone_dyn_meta/src/derive.rs index ae226b1494..0aff3b32d7 100644 --- a/module/core/clone_dyn_meta/src/derive.rs +++ b/module/core/clone_dyn_meta/src/derive.rs @@ -19,28 +19,26 @@ pub fn clone_dyn( attr_input : proc_macro::TokenStream, item_input : proc_macro: -> Result< proc_macro2::TokenStream > { - println!( "attr_input : \"{}\"", attr_input.to_string() ); - println!( "item_input : \"{}\"", item_input.to_string() ); - - // let attrs : ItemAttributes = item_input.parse()?; let attrs = syn::parse::< ItemAttributes >( attr_input )?; let original_input = item_input.clone(); - let item_parsed = match syn::parse::< syn::ItemTrait >( item_input ) + let mut item_parsed = match syn::parse::< syn::ItemTrait >( item_input ) { Ok( original ) => original, Err( err ) => return Err( err ), }; - // let has_debug = attr::has_debug( item_parsed.attrs.iter() )?; let has_debug = attrs.debug.value( false ); let item_name = &item_parsed.ident; - let ( _generics_with_defaults, generics_impl, _generics_ty, generics_where ) + let ( _generics_with_defaults, generics_impl, generics_ty, generics_where ) = generic_params::decompose( &item_parsed.generics ); - // let generic_params = &item_parsed.generics.params; - // let generics_where = &item_parsed.generics.where_clause; - let generics_names : Vec< _ > = generic_params::names( &item_parsed.generics ).collect(); + let extra : macro_tools::GenericsWithWhere = parse_quote! + { + where + Self : clone_dyn::CloneDyn, + }; + item_parsed.generics = generic_params::merge( &item_parsed.generics, &extra.into() ); let result = qt! { @@ -48,9 +46,9 @@ pub fn clone_dyn( attr_input : proc_macro::TokenStream, item_input : proc_macro: #[ allow( non_local_definitions ) ] impl < 'c, #generics_impl > Clone - for Box< dyn #item_name< #( #generics_names ),* > + 'c > - // where - // #generics_where + for Box< dyn #item_name< #generics_ty > + 'c > + where + #generics_where { #[ inline ] fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } @@ -58,9 +56,9 @@ pub fn clone_dyn( attr_input : proc_macro::TokenStream, item_input : proc_macro: #[ allow( non_local_definitions ) ] impl < 'c, #generics_impl > Clone - for Box< dyn #item_name< #( #generics_names ),* > + Send + 'c > - // where - // #generics_where + for Box< dyn #item_name< #generics_ty > + Send + 'c > + where + #generics_where { #[ inline ] fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } @@ -68,9 +66,9 @@ pub fn clone_dyn( attr_input : proc_macro::TokenStream, item_input : proc_macro: #[ allow( non_local_definitions ) ] impl < 'c, #generics_impl > Clone - for Box< dyn #item_name< #( #generics_names ),* > + Sync + 'c > - // where - // #generics_where + for Box< dyn #item_name< #generics_ty > + Sync + 'c > + where + #generics_where { #[ inline ] fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } @@ -78,9 +76,9 @@ pub fn clone_dyn( attr_input : proc_macro::TokenStream, item_input : proc_macro: #[ allow( non_local_definitions ) ] impl < 'c, #generics_impl > Clone - for Box< dyn #item_name< #( #generics_names ),* > + Send + Sync + 'c > - // where - // #generics_where + for Box< dyn #item_name< #generics_ty > + Send + Sync + 'c > + where + #generics_where { #[ inline ] fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } diff --git a/module/core/macro_tools/Cargo.toml b/module/core/macro_tools/Cargo.toml index 824ce77097..043160ed1b 100644 --- a/module/core/macro_tools/Cargo.toml +++ b/module/core/macro_tools/Cargo.toml @@ -28,7 +28,7 @@ all-features = false [features] default = [ "enabled" ] full = [ "enabled" ] -enabled = [ "former_types/enabled", "interval_adapter/enabled" ] +enabled = [ "former_types/enabled", "interval_adapter/enabled", "clone_dyn_types/enabled" ] # qqq : put all files under features: macro_attr, macro_container_kind, ... @@ -44,6 +44,7 @@ syn = { version = "~2.0.52", features = [ "full", "extra-traits" ] } ## internal interval_adapter = { workspace = true, features = [] } former_types = { workspace = true, features = [ "types_component_assign" ] } +clone_dyn_types = { workspace = true, features = [] } # xxx : qqq : optimize features [dev-dependencies] test_tools = { workspace = true } diff --git a/module/core/macro_tools/src/iter.rs b/module/core/macro_tools/src/iter.rs index 15863431c7..7d9a241d68 100644 --- a/module/core/macro_tools/src/iter.rs +++ b/module/core/macro_tools/src/iter.rs @@ -32,27 +32,27 @@ pub( crate ) mod private { } - impl< 'c, 'a, T > Clone - for Box< dyn _IterTrait< 'a, T > + 'c > - { - #[ inline ] - fn clone( &self ) -> Self { clone_into_box( &**self ) } - } + // impl< 'c, 'a, T > Clone + // for Box< dyn _IterTrait< 'a, T > + 'c > + // { + // #[ inline ] + // fn clone( &self ) -> Self { clone_into_box( &**self ) } + // } - // xxx2 - #[ inline ] - fn clone_into_box< T >( t : &T ) -> Box< T > - where - T : ?Sized, - { - unsafe - { - let mut ptr = t as *const T; - let data_ptr = &mut ptr as *mut *const T as *mut *mut (); - *data_ptr = Box::into_raw( Box::new( t.clone() ) ) as *mut (); - Box::from_raw( ptr as *mut T ) - } - } + // // xxx2 + // #[ inline ] + // fn clone_into_box< T >( t : &T ) -> Box< T > + // where + // T : ?Sized, + // { + // unsafe + // { + // let mut ptr = t as *const T; + // let data_ptr = &mut ptr as *mut *const T as *mut *mut (); + // *data_ptr = Box::into_raw( Box::new( t.clone() ) ) as *mut (); + // Box::from_raw( ptr as *mut T ) + // } + // } // xxx pub type BoxedIter< 'a, T > = Box< dyn _IterTrait< 'a, T > + 'a >; @@ -69,14 +69,14 @@ pub( crate ) mod private pub trait IterTrait< 'a, T > where T : 'a, - Self : _IterTrait< 'a, T > + Clone, + Self : _IterTrait< 'a, T > + CloneDyn, { } impl< 'a, T, I > IterTrait< 'a, T > for I where T : 'a, - Self : _IterTrait< 'a, T > + Clone, + Self : _IterTrait< 'a, T > + CloneDyn, { } From 18390540cc260a9434a8dd0c79bed3f8114c2855 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 4 Jun 2024 08:24:48 +0300 Subject: [PATCH 24/45] clone_dyn : fixing it --- .gitignore | 1 + module/core/macro_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8cba9a9a97..f92ef56646 100755 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /target /node_modules /.module +/.data /package-lock.json /Cargo.lock /.vscode diff --git a/module/core/macro_tools/Cargo.toml b/module/core/macro_tools/Cargo.toml index 043160ed1b..ea84ffb8ab 100644 --- a/module/core/macro_tools/Cargo.toml +++ b/module/core/macro_tools/Cargo.toml @@ -44,7 +44,7 @@ syn = { version = "~2.0.52", features = [ "full", "extra-traits" ] } ## internal interval_adapter = { workspace = true, features = [] } former_types = { workspace = true, features = [ "types_component_assign" ] } -clone_dyn_types = { workspace = true, features = [] } # xxx : qqq : optimize features +clone_dyn_types = { workspace = true, features = [ "clone_dyn_type" ] } # xxx : qqq : optimize features [dev-dependencies] test_tools = { workspace = true } From 616808ad7b76a4f526d33b6967ba7c3a87db8437 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 22:29:26 +0300 Subject: [PATCH 25/45] format_tools : experimenting with field iterator --- .../format_tools/tests/inc/fields_test.rs | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/module/core/format_tools/tests/inc/fields_test.rs b/module/core/format_tools/tests/inc/fields_test.rs index 9f6b62261e..493046d3fb 100644 --- a/module/core/format_tools/tests/inc/fields_test.rs +++ b/module/core/format_tools/tests/inc/fields_test.rs @@ -40,16 +40,16 @@ where { let mut dst : Vec< ( &'static str, MaybeAs< 'a, String, How > ) > = Vec::new(); - // fn into< 'a, V, How >( src : &'a V ) -> MaybeAs< 'a, String, How > - // where - // How : Clone + Copy + 'static, - // V : ToStringWith< How > + 'a, - // { - // MaybeAs::< 'a, String, How >::from - // ( - // < V as ToStringWith< How > >::to_string_with( src ) - // ) - // } + fn from< 'a, V, How >( src : &'a V ) -> MaybeAs< 'a, String, How > + where + How : Clone + Copy + 'static, + V : ToStringWith< How > + 'a, + { + MaybeAs::< 'a, String, How >::from + ( + < V as ToStringWith< How > >::to_string_with( src ) + ) + } fn add< 'a, V, How > ( @@ -61,15 +61,12 @@ where How : Clone + Copy + 'static, V : ToStringWith< How > + 'a, { - let val = MaybeAs::< 'a, String, How >::from - ( - < V as ToStringWith< How > >::to_string_with( src ) - ); + let val = from( src ); dst.push( ( key, val ) ); } - // dst.push( ( "id", MaybeAs::< 'a, String, How >::from( &self.id ) ) ); - add( &mut dst, "id", &self.id ); + dst.push( ( "id", from( &self.id ) ) ); + // add( &mut dst, "id", &self.id ); add( &mut dst, "created_at", &self.created_at ); add( &mut dst, "file_ids", &self.file_ids ); From 8c48ba4d9a3a045161358cb942a792feb640a524 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 8 Jun 2024 22:31:00 +0300 Subject: [PATCH 26/45] format_tools : experimenting with field iterator --- module/core/reflect_tools/src/reflect/fields.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/module/core/reflect_tools/src/reflect/fields.rs b/module/core/reflect_tools/src/reflect/fields.rs index 888517f730..2956c8180f 100644 --- a/module/core/reflect_tools/src/reflect/fields.rs +++ b/module/core/reflect_tools/src/reflect/fields.rs @@ -35,28 +35,30 @@ pub( crate ) mod private { } + /// /// A trait for iterating over all fields convertible into a specified type within an entity. /// /// # Type Parameters /// /// - `K`: The key type. - /// - `E`: The element type. - pub trait Fields< 'a, K, E > + /// - `V`: The value type. + /// + pub trait Fields< 'a, K, V > where - E : Clone + 'a, + V : Clone + 'a, { /// Returns an iterator over all fields of the specified type within the entity. - fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, E ) >; - // fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, Option< Cow< 'a, E > > ) >; + fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, V ) >; + // fn fields( &'a self ) -> impl IteratorTrait< Item = ( K, Option< Cow< 'a, V > > ) >; } // /// Return number of fields convertible into a specified type withing an entity. // /// // /// # Type Parameters // /// - // /// - `E`: The element type. + // /// - `V`: The value type. // /// - // pub trait FieldsLen< E > + // pub trait FieldsLen< V > // { // /// Return number of fields convertible into a specified type withing an entity. // fn len( &self ) -> usize; From 0afd13ef0a2f379df4ee4e99579cc8540d917b01 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 9 Jun 2024 08:43:41 +0300 Subject: [PATCH 27/45] format_tools : experimenting with field iterator --- .../format_tools/tests/inc/fields_test.rs | 28 ++----------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/module/core/format_tools/tests/inc/fields_test.rs b/module/core/format_tools/tests/inc/fields_test.rs index 493046d3fb..f0da3129c3 100644 --- a/module/core/format_tools/tests/inc/fields_test.rs +++ b/module/core/format_tools/tests/inc/fields_test.rs @@ -79,32 +79,6 @@ where dst.push( ( "tools", MaybeAs::none() ) ); } -// dst.push( ( "id", into( &self.id ) ) ); -// dst.push( ( "created_at", into( &self.created_at ) ) ); -// dst.push( ( "file_ids", into( &self.file_ids ) ) ); -// -// if let Some( tools ) = &self.tools -// { -// dst.push( ( "tools", into( &self.tools ) ) ); -// } -// else -// { -// dst.push( ( "tools", MaybeAs::none() ) ); -// } - - // dst.push( ( "id", MaybeAs::< 'a, String, How >::from( < String as ToStringWith< How > >::to_string_with( &self.id ) ) ) ); -// dst.push( ( "created_at", self.created_at.to_string_with().into() ) ); -// dst.push( ( "file_ids", self.file_ids.to_string_with().into() ) ); -// -// if let Some( tools ) = &self.tools -// { -// dst.push( ( "tools", self.tools.to_string_with().into() ) ); -// } -// else -// { -// dst.push( ( "tools", MaybeAs::none() ) ); -// } - dst.into_iter() } } @@ -167,6 +141,7 @@ fn basic() #[ test ] fn test_vec_fields() { + let test_objects = vec! [ TestObject @@ -198,4 +173,5 @@ fn test_vec_fields() assert_eq!( fields.len(), 2 ); assert_eq!( fields[ 0 ].0, 0 ); assert_eq!( fields[ 1 ].0, 1 ); + } From e5df1cd089c94efdb5d17ae4c65ef9e62e10ca4b Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 9 Jun 2024 09:38:19 +0300 Subject: [PATCH 28/45] macro_tools : integrating clone_dyn --- Cargo.toml | 6 + module/core/clone_dyn/Cargo.toml | 15 +- module/core/clone_dyn/Readme.md | 1 + module/core/clone_dyn_types/Cargo.toml | 39 +++ module/core/clone_dyn_types/License | 22 ++ module/core/clone_dyn_types/Readme.md | 52 ++++ .../examples/clone_dyn_types_trivial.rs | 25 ++ module/core/clone_dyn_types/src/lib.rs | 230 ++++++++++++++++++ module/core/clone_dyn_types/tests/inc/mod.rs | 13 + .../core/clone_dyn_types/tests/smoke_test.rs | 14 ++ module/core/clone_dyn_types/tests/tests.rs | 8 + module/core/macro_tools/Cargo.toml | 8 +- module/core/macro_tools/src/iter.rs | 46 +++- module/move/wca/Cargo.toml | 1 + 14 files changed, 471 insertions(+), 9 deletions(-) create mode 100644 module/core/clone_dyn_types/Cargo.toml create mode 100644 module/core/clone_dyn_types/License create mode 100644 module/core/clone_dyn_types/Readme.md create mode 100644 module/core/clone_dyn_types/examples/clone_dyn_types_trivial.rs create mode 100644 module/core/clone_dyn_types/src/lib.rs create mode 100644 module/core/clone_dyn_types/tests/inc/mod.rs create mode 100644 module/core/clone_dyn_types/tests/smoke_test.rs create mode 100644 module/core/clone_dyn_types/tests/tests.rs diff --git a/Cargo.toml b/Cargo.toml index 787b070893..b821ec379d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -169,6 +169,12 @@ version = "~0.18.0" path = "module/core/clone_dyn_meta" features = [ "enabled" ] +[workspace.dependencies.clone_dyn_types] +version = "~0.18.0" +path = "module/core/clone_dyn_types" +default-features = false +features = [ "enabled" ] + ## mem diff --git a/module/core/clone_dyn/Cargo.toml b/module/core/clone_dyn/Cargo.toml index 4a8c70efe2..85dc6a48ac 100644 --- a/module/core/clone_dyn/Cargo.toml +++ b/module/core/clone_dyn/Cargo.toml @@ -27,15 +27,20 @@ all-features = false [features] -default = [ "enabled" ] -full = [ "enabled" ] +default = [ "enabled", "clone_dyn_types", "clone_dyn_meta" ] +full = [ "enabled", "clone_dyn_types", "clone_dyn_meta" ] no_std = [] use_alloc = [ "no_std" ] -enabled = [ "clone_dyn_meta/enabled" ] +enabled = [ "clone_dyn_meta/enabled", "clone_dyn_types/enabled" ] + +# xxx : implement no_std + +clone_dyn_types = [ "dep:clone_dyn_types" ] +clone_dyn_meta = [ "dep:clone_dyn_meta", "clone_dyn_types" ] [dependencies] -clone_dyn_meta = { workspace = true } -# inspect_type = { workspace = true, features = [ "full" ] } +clone_dyn_meta = { workspace = true, optional = true } +clone_dyn_types = { workspace = true, optional = true } [dev-dependencies] test_tools = { workspace = true } diff --git a/module/core/clone_dyn/Readme.md b/module/core/clone_dyn/Readme.md index 3ddf29a341..bbce1c386b 100644 --- a/module/core/clone_dyn/Readme.md +++ b/module/core/clone_dyn/Readme.md @@ -14,6 +14,7 @@ There are few alternatives [dyn-clone](https://github.com/dtolnay/dyn-clone), [d ### Basic use-case + ```rust diff --git a/module/core/clone_dyn_types/Cargo.toml b/module/core/clone_dyn_types/Cargo.toml new file mode 100644 index 0000000000..9c86870d24 --- /dev/null +++ b/module/core/clone_dyn_types/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "clone_dyn_types" +version = "0.18.0" +edition = "2021" +authors = [ + "Kostiantyn Wandalen ", +] +license = "MIT" +readme = "Readme.md" +documentation = "https://docs.rs/clone_dyn_types" +repository = "https://github.com/Wandalen/wTools/tree/master/module/core/clone_dyn_types" +homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/clone_dyn_types" +description = """ +Derive to clone dyn structures. +""" +categories = [ "algorithms", "development-tools" ] +keywords = [ "fundamental", "general-purpose" ] + +[lints] +workspace = true + +[package.metadata.docs.rs] +features = [ "full" ] +all-features = false + +[features] + +default = [ "enabled" ] +full = [ "enabled" ] +no_std = [] +use_alloc = [ "no_std" ] +# xxx : implement no_std +enabled = [] + +[dependencies] + +[dev-dependencies] +test_tools = { workspace = true } +# inspect_type = { workspace = true, features = [ "full" ] } diff --git a/module/core/clone_dyn_types/License b/module/core/clone_dyn_types/License new file mode 100644 index 0000000000..6d5ef8559f --- /dev/null +++ b/module/core/clone_dyn_types/License @@ -0,0 +1,22 @@ +Copyright Kostiantyn W and Out of the Box Systems (c) 2013-2024 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/module/core/clone_dyn_types/Readme.md b/module/core/clone_dyn_types/Readme.md new file mode 100644 index 0000000000..2cf1457031 --- /dev/null +++ b/module/core/clone_dyn_types/Readme.md @@ -0,0 +1,52 @@ + +# Module :: clone_dyn_types + + [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_clone_dyn_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_clone_dyn_push.yml) [![docs.rs](https://img.shields.io/docsrs/clone_dyn_types?color=e3e8f0&logo=docs.rs)](https://docs.rs/clone_dyn_types) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Fcore%2Fclone_dyn%2Fexamples%2Fclone_dyn_trivial.rs,RUN_POSTFIX=--example%20clone_dyn_trivial/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY) + + +Derive to clone dyn structures. + +It's types, use `clone_dyn` to avoid bolerplate. + +By default, Rust does not support cloning for trait objects due to the `Clone` trait requiring compile-time knowledge of the type's size. The `clone_dyn` crate addresses this limitation through procedural macros, allowing for cloning collections of trait objects. Prefer to use `clone_dyn` instead of this crate, because `clone_dyn` includes this crate and also provides an attribute macro to generate boilerplate with one line of code. + +### Alternative + +There are few alternatives [dyn-clone](https://github.com/dtolnay/dyn-clone), [dyn-clonable](https://github.com/kardeiz/objekt-clonable). Unlike other options, this solution is more concise and demands less effort to use, all without compromising the quality of the outcome. + +### Basic use-case + + + + +```rust +# #[ cfg( all( feature = "enabled", any( not( feature = "no_std" ), feature = "use_alloc" ) ) ) ] +# { + use clone_dyn_types::clone_dyn_types; + + #[ clone_dyn_types ] + trait Trait1 + { + } + + let vec = Vec::< Box< dyn Trait1 > >::new(); + let vec2 = vec.clone(); /* <- it does not work without `clone_dyn_types` */ +# } +``` + + + +### To add to your project + +```sh +cargo add clone_dyn_types +``` + +### Try out from the repository + +```sh +git clone https://github.com/Wandalen/wTools +cd wTools +cd examples/clone_dyn_types_trivial +cargo run +``` diff --git a/module/core/clone_dyn_types/examples/clone_dyn_types_trivial.rs b/module/core/clone_dyn_types/examples/clone_dyn_types_trivial.rs new file mode 100644 index 0000000000..58686ee449 --- /dev/null +++ b/module/core/clone_dyn_types/examples/clone_dyn_types_trivial.rs @@ -0,0 +1,25 @@ +//! Demonstrates the usage of `clone_dyn` to enable cloning for trait objects. +//! +//! By default, Rust does not support cloning for trait objects due to the `Clone` trait +//! requiring compile-time knowledge of the type's size. The `clone_dyn` crate addresses +//! this limitation through procedural macros, allowing for cloning collections of trait objects. + +#[ cfg( any( not( feature = "enabled" ), all( feature = "no_std", not( feature = "use_alloc" ) ) ) ) ] +fn main() {} +#[ cfg( all( feature = "enabled", any( not( feature = "no_std" ), feature = "use_alloc" ) ) ) ] +fn main() +{ + +// use clone_dyn::clone_dyn; +// +// #[ clone_dyn ] +// trait Trait1 +// { +// } +// +// let vec = Vec::< Box< dyn Trait1 > >::new(); +// let _vec2 = vec.clone(); /* <- it does not work without `clone_dyn` */ + +} + +// xxx : improve \ No newline at end of file diff --git a/module/core/clone_dyn_types/src/lib.rs b/module/core/clone_dyn_types/src/lib.rs new file mode 100644 index 0000000000..2caae7c291 --- /dev/null +++ b/module/core/clone_dyn_types/src/lib.rs @@ -0,0 +1,230 @@ +#![ cfg_attr( feature = "no_std", no_std ) ] +#![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] +#![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] +#![ doc( html_root_url = "https://docs.rs/clone_dyn_types/latest/clone_dyn_types/" ) ] +// #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] +// xxx : fix + +#[ allow( unused_extern_crates ) ] +#[ cfg( feature = "enabled" ) ] +#[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ] +extern crate alloc; + +/// Namespace with dependencies. + +#[ cfg( feature = "enabled" ) ] +pub mod dependency +{ + // pub use ::clone_dyn_meta; +} + +/// Internal namespace. +#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] +#[ cfg( feature = "enabled" ) ] +pub( crate ) mod private +{ + + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + extern crate alloc; + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + #[ allow( unused_imports ) ] + use alloc::boxed::Box; + #[ cfg( all( feature = "use_std", not( feature = "use_alloc" ) ) ) ] + use std::boxed::Box; + + /// A trait to upcast a clonable entity and clone it. + /// It's implemented for all entities which can be cloned. + pub trait CloneDyn : Sealed + { + fn __clone_dyn( &self, _ : DontCallMe ) -> *mut (); + } + + // clonable + impl< T > CloneDyn for T + where + T : Clone, + { + #[ inline ] + fn __clone_dyn( &self, _ : DontCallMe ) -> *mut () + { + Box::< T >::into_raw( Box::new( self.clone() ) ) as *mut () + } + } + + // slice + impl< T > CloneDyn for [ T ] + where + T : Clone, + { + #[ inline ] + fn __clone_dyn( &self, _ : DontCallMe ) -> *mut () + { + Box::< [ T ] >::into_raw( self.iter().cloned().collect() ) as *mut () + } + } + + // str slice + impl CloneDyn for str + { + #[ inline ] + fn __clone_dyn( &self, _ : DontCallMe ) -> *mut () + { + Box::< str >::into_raw( Box::from( self ) ) as *mut () + } + } + + /// + /// True clone which is applicable not only to clonable entities, but to trait objects implementing CloneDyn. + /// + /// # Example + /// + /// ``` + /// use clone_dyn_types::clone; + /// + /// #[ derive( Clone ) ] + /// struct MyStruct + /// { + /// value : i32, + /// } + /// + /// let original = MyStruct { value : 42 }; + /// let cloned = clone( &original ); + /// + /// assert_eq!( original.value, cloned.value ); + /// ``` + + #[ inline ] + pub fn clone< T >( src : &T ) -> T + where + T : CloneDyn, + { + /// # Safety + /// + /// This function uses an `unsafe` block because it performs low-level memory manipulations. Specifically, it handles + /// raw pointers and converts them to and from `Box< T >`. This is necessary to dynamically clone a trait object, which + /// does not support cloning through the standard `Clone` trait. The safety of this function depends on the guarantee + /// that the `CloneDyn` trait is correctly implemented for the given type `T`, ensuring that `__clone_dyn` returns a + /// valid pointer to a cloned instance of `T`. + /// + #[ allow( unsafe_code ) ] + unsafe + { + *Box::from_raw( < T as CloneDyn >::__clone_dyn( src, DontCallMe ) as *mut T ) + } + } + + /// + /// Clone boxed dyn. + /// + /// Clones a dynamically sized trait object into a `Box< T >`. + /// + /// # Example + /// + /// ``` + /// use clone_dyn_types::{ clone_into_box, clone_dyn_types }; + /// + /// #[ derive( Clone ) ] + /// struct MyStruct + /// { + /// value : i32, + /// } + /// + /// #[ clone_dyn_types ] + /// trait MyTrait + /// { + /// fn val( &self ) -> i32; + /// } + /// + /// impl MyTrait for MyStruct + /// { + /// fn val( &self ) -> i32 + /// { + /// self.value + /// } + /// } + /// + /// let cloned : Box< dyn MyTrait > = clone_into_box( &MyStruct { value : 42 } ); + /// + /// ``` + + #[ inline ] + pub fn clone_into_box< T >( ref_dyn : &T ) -> Box< T > + where + T : ?Sized + CloneDyn, + { + /// # Safety + /// + /// This function uses an `unsafe` block because it performs low-level memory manipulations involving raw pointers. + /// The `unsafe` block is necessary here because we're manually handling raw pointers and converting them to and from + /// `Box`. This bypasses Rust's ownership and borrowing rules to achieve dynamic cloning of a boxed trait object. + /// The safety of this function relies on the correct implementation of the `CloneDyn` trait for the given type `T`. + /// Specifically, `__clone_dyn` must return a valid pointer to a cloned instance of `T`. + /// + #[ allow( unsafe_code ) ] + unsafe + { + let mut ptr = ref_dyn as *const T; + let data_ptr = &mut ptr as *mut *const T as *mut *mut (); + *data_ptr = < T as CloneDyn >::__clone_dyn( ref_dyn, DontCallMe ); + Box::from_raw( ptr as *mut T ) + } + } + + mod sealed + { + pub struct DontCallMe; + pub trait Sealed {} + impl< T : Clone > Sealed for T {} + impl< T : Clone > Sealed for [ T ] {} + impl Sealed for str {} + } + use sealed::*; + +} + +#[ cfg( feature = "enabled" ) ] +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use protected::*; + +/// Protected namespace of the module. +#[ cfg( feature = "enabled" ) ] +pub mod protected +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::orphan::*; +} + +/// Orphan namespace of the module. +#[ cfg( feature = "enabled" ) ] +pub mod orphan +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::exposed::*; +} + +/// Exposed namespace of the module. +#[ cfg( feature = "enabled" ) ] +pub mod exposed +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use super::prelude::*; +} + +/// Prelude to use essentials: `use my_module::prelude::*`. +#[ cfg( feature = "enabled" ) ] +pub mod prelude +{ + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + pub use super::private:: + { + CloneDyn, + clone_into_box, + clone, + }; +} diff --git a/module/core/clone_dyn_types/tests/inc/mod.rs b/module/core/clone_dyn_types/tests/inc/mod.rs new file mode 100644 index 0000000000..282582f586 --- /dev/null +++ b/module/core/clone_dyn_types/tests/inc/mod.rs @@ -0,0 +1,13 @@ + +#[ allow( unused_imports ) ] +use super::*; + +#[ path = "../../clone_dyn/tests/inc" ] +mod tests +{ + + mod basic_manual; + mod basic; + mod parametrized; + +} diff --git a/module/core/clone_dyn_types/tests/smoke_test.rs b/module/core/clone_dyn_types/tests/smoke_test.rs new file mode 100644 index 0000000000..828e9b016b --- /dev/null +++ b/module/core/clone_dyn_types/tests/smoke_test.rs @@ -0,0 +1,14 @@ + + +#[ test ] +fn local_smoke_test() +{ + ::test_tools::smoke_test_for_local_run(); +} + + +#[ test ] +fn published_smoke_test() +{ + ::test_tools::smoke_test_for_published_run(); +} diff --git a/module/core/clone_dyn_types/tests/tests.rs b/module/core/clone_dyn_types/tests/tests.rs new file mode 100644 index 0000000000..a465740896 --- /dev/null +++ b/module/core/clone_dyn_types/tests/tests.rs @@ -0,0 +1,8 @@ + +#[ allow( unused_imports ) ] +use clone_dyn as the_module; +#[ allow( unused_imports ) ] +use test_tools::exposed::*; + +#[ cfg( all( feature = "enabled", any( not( feature = "no_std" ), feature = "use_alloc" ) ) ) ] +mod inc; diff --git a/module/core/macro_tools/Cargo.toml b/module/core/macro_tools/Cargo.toml index ea84ffb8ab..782e5da96d 100644 --- a/module/core/macro_tools/Cargo.toml +++ b/module/core/macro_tools/Cargo.toml @@ -28,7 +28,11 @@ all-features = false [features] default = [ "enabled" ] full = [ "enabled" ] -enabled = [ "former_types/enabled", "interval_adapter/enabled", "clone_dyn_types/enabled" ] +enabled = [ + "former_types/enabled", + "interval_adapter/enabled", + "clone_dyn_types/enabled", +] # qqq : put all files under features: macro_attr, macro_container_kind, ... @@ -44,7 +48,7 @@ syn = { version = "~2.0.52", features = [ "full", "extra-traits" ] } ## internal interval_adapter = { workspace = true, features = [] } former_types = { workspace = true, features = [ "types_component_assign" ] } -clone_dyn_types = { workspace = true, features = [ "clone_dyn_type" ] } # xxx : qqq : optimize features +clone_dyn_types = { workspace = true, features = [] } # xxx : qqq : optimize features [dev-dependencies] test_tools = { workspace = true } diff --git a/module/core/macro_tools/src/iter.rs b/module/core/macro_tools/src/iter.rs index 7d9a241d68..1ece7544f5 100644 --- a/module/core/macro_tools/src/iter.rs +++ b/module/core/macro_tools/src/iter.rs @@ -9,6 +9,7 @@ pub( crate ) mod private { // use std::fmt; // use crate::*; + use clone_dyn_types::CloneDyn; /// Trait that encapsulates an iterator with specific characteristics, tailored for use with the `syn` crate. /// @@ -22,6 +23,7 @@ pub( crate ) mod private where T : 'a, Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, + Self : CloneDyn, { } @@ -29,9 +31,49 @@ pub( crate ) mod private where T : 'a, Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, + Self : CloneDyn, { } + // = + + #[ allow( non_local_definitions ) ] + impl< 'c, T > Clone + for Box< dyn _IterTrait< 'c, T > + 'c > + { + #[ inline ] + fn clone( &self ) -> Self + { + clone_dyn_types::clone_into_box( &**self ) + } + } + + #[ allow( non_local_definitions ) ] + impl< 'c, T > Clone + for Box< dyn _IterTrait< 'c, T > + Send + 'c > + { + #[ inline ] + fn clone( &self ) -> Self { clone_dyn_types::clone_into_box( &**self ) } + } + + #[ allow( non_local_definitions ) ] + impl< 'c, T > Clone + for Box< dyn _IterTrait< 'c, T > + Sync + 'c > + { + #[ inline ] + fn clone( &self ) -> Self { clone_dyn_types::clone_into_box( &**self ) } + } + + #[ allow( non_local_definitions ) ] + impl< 'c, T > Clone + for Box< dyn _IterTrait< 'c, T > + Send + Sync + 'c > + { + #[ inline ] + fn clone( &self ) -> Self { clone_dyn_types::clone_into_box( &**self ) } + } + + // = + // impl< 'c, 'a, T > Clone // for Box< dyn _IterTrait< 'a, T > + 'c > // { @@ -69,14 +111,14 @@ pub( crate ) mod private pub trait IterTrait< 'a, T > where T : 'a, - Self : _IterTrait< 'a, T > + CloneDyn, + Self : _IterTrait< 'a, T > + Clone, { } impl< 'a, T, I > IterTrait< 'a, T > for I where T : 'a, - Self : _IterTrait< 'a, T > + CloneDyn, + Self : _IterTrait< 'a, T > + Clone, { } diff --git a/module/move/wca/Cargo.toml b/module/move/wca/Cargo.toml index 7489b66fbb..f4d6f7c861 100644 --- a/module/move/wca/Cargo.toml +++ b/module/move/wca/Cargo.toml @@ -45,6 +45,7 @@ strs_tools = { workspace = true, features = [ "default" ] } mod_interface = { workspace = true, features = [ "default" ] } iter_tools = { workspace = true, features = [ "default" ] } former = { workspace = true, features = [ "default" ] } +# xxx : qqq : optimize set of features ## external log = "0.4" From a073873e9d56b0493c7ff94b0ad259dcc0e924f5 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 9 Jun 2024 23:46:36 +0300 Subject: [PATCH 29/45] clone_dyn_types : fix --- module/core/clone_dyn/tests/inc/basic.rs | 2 +- .../core/clone_dyn/tests/inc/basic_manual.rs | 12 +++--- .../clone_dyn/tests/inc/only_test/basic.rs | 18 ++++----- .../core/clone_dyn/tests/inc/parametrized.rs | 4 +- module/core/clone_dyn_types/src/lib.rs | 37 +++++++++++++++++-- module/core/clone_dyn_types/tests/inc/mod.rs | 8 ++-- module/core/clone_dyn_types/tests/tests.rs | 2 +- module/core/macro_tools/src/struct_like.rs | 7 +++- module/core/process_tools/src/process.rs | 2 +- 9 files changed, 65 insertions(+), 27 deletions(-) diff --git a/module/core/clone_dyn/tests/inc/basic.rs b/module/core/clone_dyn/tests/inc/basic.rs index 72a8770a6a..55e7eee3cd 100644 --- a/module/core/clone_dyn/tests/inc/basic.rs +++ b/module/core/clone_dyn/tests/inc/basic.rs @@ -38,7 +38,7 @@ impl Trait1 for String impl< T > Trait1 for &[ T ] where - T : clone_dyn::CloneDyn, + T : the_module::CloneDyn, { fn val( &self ) -> i32 { diff --git a/module/core/clone_dyn/tests/inc/basic_manual.rs b/module/core/clone_dyn/tests/inc/basic_manual.rs index 7ee9519120..04ff392acb 100644 --- a/module/core/clone_dyn/tests/inc/basic_manual.rs +++ b/module/core/clone_dyn/tests/inc/basic_manual.rs @@ -4,7 +4,7 @@ use super::*; trait Trait1 where - Self : clone_dyn::CloneDyn, + Self : the_module::CloneDyn, { fn val( &self ) -> i32; } @@ -37,7 +37,7 @@ impl Trait1 for String impl< T > Trait1 for &[ T ] where - T : clone_dyn::CloneDyn, + T : the_module::CloneDyn, { fn val( &self ) -> i32 { @@ -62,7 +62,7 @@ for Box< dyn Trait1 + 'c > #[ inline ] fn clone( &self ) -> Self { - clone_dyn::clone_into_box( &**self ) + the_module::clone_into_box( &**self ) } } @@ -71,7 +71,7 @@ impl < 'c > Clone for Box< dyn Trait1 + Send + 'c > { #[ inline ] - fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } + fn clone( &self ) -> Self { the_module::clone_into_box( &**self ) } } #[ allow( non_local_definitions ) ] @@ -79,7 +79,7 @@ impl < 'c > Clone for Box< dyn Trait1 + Sync + 'c > { #[ inline ] - fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } + fn clone( &self ) -> Self { the_module::clone_into_box( &**self ) } } #[ allow( non_local_definitions ) ] @@ -87,7 +87,7 @@ impl < 'c > Clone for Box< dyn Trait1 + Send + Sync + 'c > { #[ inline ] - fn clone( &self ) -> Self { clone_dyn::clone_into_box( &**self ) } + fn clone( &self ) -> Self { the_module::clone_into_box( &**self ) } } // == end of generated diff --git a/module/core/clone_dyn/tests/inc/only_test/basic.rs b/module/core/clone_dyn/tests/inc/only_test/basic.rs index 3883351320..1ae447ea14 100644 --- a/module/core/clone_dyn/tests/inc/only_test/basic.rs +++ b/module/core/clone_dyn/tests/inc/only_test/basic.rs @@ -6,25 +6,25 @@ fn clone_into_box() // copyable let a : i32 = 13; - let b : Box< i32 > = clone_dyn::clone_into_box( &a ); + let b : Box< i32 > = the_module::clone_into_box( &a ); a_id!( a, *b ); // clonable let a : String = "abc".to_string(); - let b : Box< String > = clone_dyn::clone_into_box( &a ); + let b : Box< String > = the_module::clone_into_box( &a ); a_id!( a, *b ); // str slice let a : &str = "abc"; - let b : Box< str > = clone_dyn::clone_into_box( a ); + let b : Box< str > = the_module::clone_into_box( a ); a_id!( *a, *b ); // slice let a : &[ i32 ] = &[ 1, 2, 3 ]; - let b : Box< [ i32 ] > = clone_dyn::clone_into_box( a ); + let b : Box< [ i32 ] > = the_module::clone_into_box( a ); a_id!( *a, *b ); // @@ -38,25 +38,25 @@ fn clone() // copyable let a : i32 = 13; - let b : i32 = clone_dyn::clone( &a ); + let b : i32 = the_module::clone( &a ); a_id!( a, b ); // clonable let a : String = "abc".to_string(); - let b : String = clone_dyn::clone( &a ); + let b : String = the_module::clone( &a ); a_id!( a, b ); // str slice let a : &str = "abc"; - let b : &str = clone_dyn::clone( &a ); + let b : &str = the_module::clone( &a ); a_id!( a, b ); // slice let a : &[ i32 ] = &[ 1, 2, 3 ]; - let b : &[ i32 ] = clone_dyn::clone( &a ); + let b : &[ i32 ] = the_module::clone( &a ); a_id!( a, b ); // @@ -85,7 +85,7 @@ fn basic() // let vec : Vec< Box< dyn Trait1 > > = vec![ e_i32.clone(), e_i64.clone(), e_string.clone(), e_str_slice.clone(), e_slice.clone() ]; - let vec2 = clone_dyn::clone( &vec ); + let vec2 = the_module::clone( &vec ); let vec = vec.iter().map( | e | e.val() ).collect::< Vec< _ > >(); let vec2 = vec2.iter().map( | e | e.val() ).collect::< Vec< _ > >(); a_id!( vec, vec2 ); diff --git a/module/core/clone_dyn/tests/inc/parametrized.rs b/module/core/clone_dyn/tests/inc/parametrized.rs index 96edbc1456..851acf30b0 100644 --- a/module/core/clone_dyn/tests/inc/parametrized.rs +++ b/module/core/clone_dyn/tests/inc/parametrized.rs @@ -65,7 +65,7 @@ impl Trait1< i32, char > for String impl< T > Trait1< i32, char > for &[ T ] where - T : clone_dyn::CloneDyn, + T : the_module::CloneDyn, Self : ::core::fmt::Debug, { fn dbg( &self ) -> String @@ -112,7 +112,7 @@ fn basic() // let vec : Vec< Box< dyn Trait1< i32, char > > > = vec![ e_i32.clone(), e_i64.clone(), e_string.clone(), e_str_slice.clone(), e_slice.clone() ]; - let vec2 = clone_dyn::clone( &vec ); + let vec2 = the_module::clone( &vec ); let vec = vec.iter().map( | e | e.dbg() ).collect::< Vec< _ > >(); let vec2 = vec2.iter().map( | e | e.dbg() ).collect::< Vec< _ > >(); a_id!( vec, vec2 ); diff --git a/module/core/clone_dyn_types/src/lib.rs b/module/core/clone_dyn_types/src/lib.rs index 2caae7c291..47eb1a404b 100644 --- a/module/core/clone_dyn_types/src/lib.rs +++ b/module/core/clone_dyn_types/src/lib.rs @@ -121,7 +121,7 @@ pub( crate ) mod private /// # Example /// /// ``` - /// use clone_dyn_types::{ clone_into_box, clone_dyn_types }; + /// use clone_dyn_types::{ CloneDyn, clone_into_box }; /// /// #[ derive( Clone ) ] /// struct MyStruct @@ -129,8 +129,7 @@ pub( crate ) mod private /// value : i32, /// } /// - /// #[ clone_dyn_types ] - /// trait MyTrait + /// trait MyTrait : CloneDyn /// { /// fn val( &self ) -> i32; /// } @@ -143,6 +142,38 @@ pub( crate ) mod private /// } /// } /// + /// #[ allow( non_local_definitions ) ] + /// impl < 'c > Clone + /// for Box< dyn MyTrait + 'c > + /// { + /// #[ inline ] + /// fn clone( &self ) -> Self { clone_into_box( &**self ) } + /// } + /// + /// #[ allow( non_local_definitions ) ] + /// impl < 'c > Clone + /// for Box< dyn MyTrait + Send + 'c > + /// { + /// #[ inline ] + /// fn clone( &self ) -> Self { clone_into_box( &**self ) } + /// } + /// + /// #[ allow( non_local_definitions ) ] + /// impl < 'c > Clone + /// for Box< dyn MyTrait + Sync + 'c > + /// { + /// #[ inline ] + /// fn clone( &self ) -> Self { clone_into_box( &**self ) } + /// } + /// + /// #[ allow( non_local_definitions ) ] + /// impl < 'c > Clone + /// for Box< dyn MyTrait + Send + Sync + 'c > + /// { + /// #[ inline ] + /// fn clone( &self ) -> Self { clone_into_box( &**self ) } + /// } + /// /// let cloned : Box< dyn MyTrait > = clone_into_box( &MyStruct { value : 42 } ); /// /// ``` diff --git a/module/core/clone_dyn_types/tests/inc/mod.rs b/module/core/clone_dyn_types/tests/inc/mod.rs index 282582f586..c5bda8ed18 100644 --- a/module/core/clone_dyn_types/tests/inc/mod.rs +++ b/module/core/clone_dyn_types/tests/inc/mod.rs @@ -2,12 +2,14 @@ #[ allow( unused_imports ) ] use super::*; -#[ path = "../../clone_dyn/tests/inc" ] +#[ path = "../../../clone_dyn/tests/inc" ] mod tests { + #[ allow( unused_imports ) ] + use super::*; mod basic_manual; - mod basic; - mod parametrized; + // mod basic; + // mod parametrized; } diff --git a/module/core/clone_dyn_types/tests/tests.rs b/module/core/clone_dyn_types/tests/tests.rs index a465740896..e2210e22b4 100644 --- a/module/core/clone_dyn_types/tests/tests.rs +++ b/module/core/clone_dyn_types/tests/tests.rs @@ -1,6 +1,6 @@ #[ allow( unused_imports ) ] -use clone_dyn as the_module; +use clone_dyn_types as the_module; #[ allow( unused_imports ) ] use test_tools::exposed::*; diff --git a/module/core/macro_tools/src/struct_like.rs b/module/core/macro_tools/src/struct_like.rs index 81d3866a0e..9f021670c2 100644 --- a/module/core/macro_tools/src/struct_like.rs +++ b/module/core/macro_tools/src/struct_like.rs @@ -9,7 +9,7 @@ pub( crate ) mod private // use interval_adapter::BoundExt; /// Enum to encapsulate either a field from a struct or a variant from an enum. - #[ derive( Debug, PartialEq ) ] + #[ derive( Debug, PartialEq, Clone ) ] pub enum FieldOrVariant< 'a > { /// Represents a field within a struct or union. @@ -18,6 +18,11 @@ pub( crate ) mod private Variant( &'a syn::Variant ), } + // xxx + impl< 'a > Copy for FieldOrVariant< 'a > + { + } + impl< 'a > From< &'a syn::Field > for FieldOrVariant< 'a > { fn from( field : &'a syn::Field ) -> Self diff --git a/module/core/process_tools/src/process.rs b/module/core/process_tools/src/process.rs index db954da17c..6c34f298f5 100644 --- a/module/core/process_tools/src/process.rs +++ b/module/core/process_tools/src/process.rs @@ -272,7 +272,7 @@ pub( crate ) mod private { fn clone( &self ) -> Self { - Report + Self { command : self.command.clone(), current_path : self.current_path.clone(), From 2fe809637a29d02775536d406fe0ddcac26a8617 Mon Sep 17 00:00:00 2001 From: wandalen Date: Sun, 9 Jun 2024 23:50:32 +0300 Subject: [PATCH 30/45] clone_dyn : cleaning --- module/core/clone_dyn/src/lib.rs | 189 ++++--------------------------- 1 file changed, 20 insertions(+), 169 deletions(-) diff --git a/module/core/clone_dyn/src/lib.rs b/module/core/clone_dyn/src/lib.rs index 2e98942937..9470e40463 100644 --- a/module/core/clone_dyn/src/lib.rs +++ b/module/core/clone_dyn/src/lib.rs @@ -5,17 +5,20 @@ // #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] // xxx -#[ allow( unused_extern_crates ) ] -#[ cfg( feature = "enabled" ) ] -#[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ] -extern crate alloc; +// #[ allow( unused_extern_crates ) ] +// #[ cfg( feature = "enabled" ) ] +// #[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ] +// extern crate alloc; /// Namespace with dependencies. #[ cfg( feature = "enabled" ) ] pub mod dependency { + #[ cfg( feature = "clone_dyn_meta" ) ] pub use ::clone_dyn_meta; + #[ cfg( feature = "clone_dyn_types" ) ] + pub use ::clone_dyn_types; } /// Internal namespace. @@ -23,163 +26,6 @@ pub mod dependency #[ cfg( feature = "enabled" ) ] pub( crate ) mod private { - - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - extern crate alloc; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - #[ allow( unused_imports ) ] - use alloc::boxed::Box; - #[ cfg( all( feature = "use_std", not( feature = "use_alloc" ) ) ) ] - use std::boxed::Box; - - /// A trait to upcast a clonable entity and clone it. - /// It's implemented for all entities which can be cloned. - pub trait CloneDyn : Sealed - { - fn __clone_dyn( &self, _ : DontCallMe ) -> *mut (); - } - - // clonable - impl< T > CloneDyn for T - where - T : Clone, - { - #[ inline ] - fn __clone_dyn( &self, _ : DontCallMe ) -> *mut () - { - Box::< T >::into_raw( Box::new( self.clone() ) ) as *mut () - } - } - - // slice - impl< T > CloneDyn for [ T ] - where - T : Clone, - { - #[ inline ] - fn __clone_dyn( &self, _ : DontCallMe ) -> *mut () - { - Box::< [ T ] >::into_raw( self.iter().cloned().collect() ) as *mut () - } - } - - // str slice - impl CloneDyn for str - { - #[ inline ] - fn __clone_dyn( &self, _ : DontCallMe ) -> *mut () - { - Box::< str >::into_raw( Box::from( self ) ) as *mut () - } - } - - /// - /// True clone which is applicable not only to clonable entities, but to trait objects implementing CloneDyn. - /// - /// # Example - /// - /// ``` - /// use clone_dyn::clone; - /// - /// #[ derive( Clone ) ] - /// struct MyStruct - /// { - /// value : i32, - /// } - /// - /// let original = MyStruct { value : 42 }; - /// let cloned = clone( &original ); - /// - /// assert_eq!( original.value, cloned.value ); - /// ``` - - #[ inline ] - pub fn clone< T >( src : &T ) -> T - where - T : CloneDyn, - { - /// # Safety - /// - /// This function uses an `unsafe` block because it performs low-level memory manipulations. Specifically, it handles - /// raw pointers and converts them to and from `Box< T >`. This is necessary to dynamically clone a trait object, which - /// does not support cloning through the standard `Clone` trait. The safety of this function depends on the guarantee - /// that the `CloneDyn` trait is correctly implemented for the given type `T`, ensuring that `__clone_dyn` returns a - /// valid pointer to a cloned instance of `T`. - /// - #[ allow( unsafe_code ) ] - unsafe - { - *Box::from_raw( < T as CloneDyn >::__clone_dyn( src, DontCallMe ) as *mut T ) - } - } - - /// - /// Clone boxed dyn. - /// - /// Clones a dynamically sized trait object into a `Box< T >`. - /// - /// # Example - /// - /// ``` - /// use clone_dyn::{ clone_into_box, clone_dyn }; - /// - /// #[ derive( Clone ) ] - /// struct MyStruct - /// { - /// value : i32, - /// } - /// - /// #[ clone_dyn ] - /// trait MyTrait - /// { - /// fn val( &self ) -> i32; - /// } - /// - /// impl MyTrait for MyStruct - /// { - /// fn val( &self ) -> i32 - /// { - /// self.value - /// } - /// } - /// - /// let cloned : Box< dyn MyTrait > = clone_into_box( &MyStruct { value : 42 } ); - /// - /// ``` - - #[ inline ] - pub fn clone_into_box< T >( ref_dyn : &T ) -> Box< T > - where - T : ?Sized + CloneDyn, - { - /// # Safety - /// - /// This function uses an `unsafe` block because it performs low-level memory manipulations involving raw pointers. - /// The `unsafe` block is necessary here because we're manually handling raw pointers and converting them to and from - /// `Box`. This bypasses Rust's ownership and borrowing rules to achieve dynamic cloning of a boxed trait object. - /// The safety of this function relies on the correct implementation of the `CloneDyn` trait for the given type `T`. - /// Specifically, `__clone_dyn` must return a valid pointer to a cloned instance of `T`. - /// - #[ allow( unsafe_code ) ] - unsafe - { - let mut ptr = ref_dyn as *const T; - let data_ptr = &mut ptr as *mut *const T as *mut *mut (); - *data_ptr = < T as CloneDyn >::__clone_dyn( ref_dyn, DontCallMe ); - Box::from_raw( ptr as *mut T ) - } - } - - mod sealed - { - pub struct DontCallMe; - pub trait Sealed {} - impl< T : Clone > Sealed for T {} - impl< T : Clone > Sealed for [ T ] {} - impl Sealed for str {} - } - use sealed::*; - } #[ cfg( feature = "enabled" ) ] @@ -200,9 +46,16 @@ pub mod protected #[ cfg( feature = "enabled" ) ] pub mod orphan { + #[ doc( inline ) ] #[ allow( unused_imports ) ] pub use super::exposed::*; + + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + #[ cfg( feature = "clone_dyn_types" ) ] + pub use super::dependency::clone_dyn_types::exposed::*; + } /// Exposed namespace of the module. @@ -218,17 +71,15 @@ pub mod exposed #[ cfg( feature = "enabled" ) ] pub mod prelude { + #[ doc( inline ) ] #[ allow( unused_imports ) ] - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + #[ cfg( feature = "clone_dyn_meta" ) ] pub use ::clone_dyn_meta::clone_dyn; + #[ doc( inline ) ] #[ allow( unused_imports ) ] - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - pub use super::private:: - { - CloneDyn, - clone_into_box, - clone, - }; + #[ cfg( feature = "clone_dyn_types" ) ] + pub use super::dependency::clone_dyn_types::prelude::*; + } From 2e958a315ee618e5b950ce15cd80c8c1517e8849 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 00:00:52 +0300 Subject: [PATCH 31/45] clone_dyn : cleaning --- module/core/clone_dyn/Readme.md | 4 +-- module/core/clone_dyn/src/lib.rs | 2 +- module/core/clone_dyn_meta/src/derive.rs | 2 +- module/core/clone_dyn_types/Readme.md | 4 +-- module/core/clone_dyn_types/src/lib.rs | 39 +++++++++++++----------- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/module/core/clone_dyn/Readme.md b/module/core/clone_dyn/Readme.md index bbce1c386b..7f3a89cdd5 100644 --- a/module/core/clone_dyn/Readme.md +++ b/module/core/clone_dyn/Readme.md @@ -17,7 +17,7 @@ There are few alternatives [dyn-clone](https://github.com/dtolnay/dyn-clone), [d -```rust + diff --git a/module/core/clone_dyn/src/lib.rs b/module/core/clone_dyn/src/lib.rs index 9470e40463..16d5b89cff 100644 --- a/module/core/clone_dyn/src/lib.rs +++ b/module/core/clone_dyn/src/lib.rs @@ -2,7 +2,7 @@ #![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] #![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] #![ doc( html_root_url = "https://docs.rs/clone_dyn/latest/clone_dyn/" ) ] -// #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] // xxx // #[ allow( unused_extern_crates ) ] diff --git a/module/core/clone_dyn_meta/src/derive.rs b/module/core/clone_dyn_meta/src/derive.rs index 0aff3b32d7..353f33f2ce 100644 --- a/module/core/clone_dyn_meta/src/derive.rs +++ b/module/core/clone_dyn_meta/src/derive.rs @@ -5,7 +5,7 @@ use macro_tools:: Result, AttributePropertyOptionalSingletone, AttributePropertyComponent, - attr, + // attr, diag, generic_params, }; diff --git a/module/core/clone_dyn_types/Readme.md b/module/core/clone_dyn_types/Readme.md index 2cf1457031..1fad07a5ad 100644 --- a/module/core/clone_dyn_types/Readme.md +++ b/module/core/clone_dyn_types/Readme.md @@ -19,7 +19,7 @@ There are few alternatives [dyn-clone](https://github.com/dtolnay/dyn-clone), [d -```rust + diff --git a/module/core/clone_dyn_types/src/lib.rs b/module/core/clone_dyn_types/src/lib.rs index 47eb1a404b..377a365eac 100644 --- a/module/core/clone_dyn_types/src/lib.rs +++ b/module/core/clone_dyn_types/src/lib.rs @@ -2,7 +2,7 @@ #![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] #![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] #![ doc( html_root_url = "https://docs.rs/clone_dyn_types/latest/clone_dyn_types/" ) ] -// #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] +#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] // xxx : fix #[ allow( unused_extern_crates ) ] @@ -36,6 +36,7 @@ pub( crate ) mod private /// It's implemented for all entities which can be cloned. pub trait CloneDyn : Sealed { + #[ doc( hidden ) ] fn __clone_dyn( &self, _ : DontCallMe ) -> *mut (); } @@ -98,14 +99,14 @@ pub( crate ) mod private where T : CloneDyn, { - /// # Safety - /// - /// This function uses an `unsafe` block because it performs low-level memory manipulations. Specifically, it handles - /// raw pointers and converts them to and from `Box< T >`. This is necessary to dynamically clone a trait object, which - /// does not support cloning through the standard `Clone` trait. The safety of this function depends on the guarantee - /// that the `CloneDyn` trait is correctly implemented for the given type `T`, ensuring that `__clone_dyn` returns a - /// valid pointer to a cloned instance of `T`. - /// + // # Safety + // + // This function uses an `unsafe` block because it performs low-level memory manipulations. Specifically, it handles + // raw pointers and converts them to and from `Box< T >`. This is necessary to dynamically clone a trait object, which + // does not support cloning through the standard `Clone` trait. The safety of this function depends on the guarantee + // that the `CloneDyn` trait is correctly implemented for the given type `T`, ensuring that `__clone_dyn` returns a + // valid pointer to a cloned instance of `T`. + // #[ allow( unsafe_code ) ] unsafe { @@ -183,14 +184,14 @@ pub( crate ) mod private where T : ?Sized + CloneDyn, { - /// # Safety - /// - /// This function uses an `unsafe` block because it performs low-level memory manipulations involving raw pointers. - /// The `unsafe` block is necessary here because we're manually handling raw pointers and converting them to and from - /// `Box`. This bypasses Rust's ownership and borrowing rules to achieve dynamic cloning of a boxed trait object. - /// The safety of this function relies on the correct implementation of the `CloneDyn` trait for the given type `T`. - /// Specifically, `__clone_dyn` must return a valid pointer to a cloned instance of `T`. - /// + // # Safety + // + // This function uses an `unsafe` block because it performs low-level memory manipulations involving raw pointers. + // The `unsafe` block is necessary here because we're manually handling raw pointers and converting them to and from + // `Box`. This bypasses Rust's ownership and borrowing rules to achieve dynamic cloning of a boxed trait object. + // The safety of this function relies on the correct implementation of the `CloneDyn` trait for the given type `T`. + // Specifically, `__clone_dyn` must return a valid pointer to a cloned instance of `T`. + // #[ allow( unsafe_code ) ] unsafe { @@ -201,9 +202,13 @@ pub( crate ) mod private } } + #[ doc( hidden ) ] mod sealed { + #[ doc( hidden ) ] + #[ allow( missing_debug_implementations ) ] pub struct DontCallMe; + #[ doc( hidden ) ] pub trait Sealed {} impl< T : Clone > Sealed for T {} impl< T : Clone > Sealed for [ T ] {} From 5286893aad6f05379df081325ff6a378fa4a4293 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 00:05:41 +0300 Subject: [PATCH 32/45] clone_dyn, derive_tools : cleaning --- module/core/derive_tools_meta/Cargo.toml | 2 +- .../core/derive_tools_meta/src/derive/new.rs | 19 +++++-------- module/core/macro_tools/src/iter.rs | 27 +------------------ 3 files changed, 9 insertions(+), 39 deletions(-) diff --git a/module/core/derive_tools_meta/Cargo.toml b/module/core/derive_tools_meta/Cargo.toml index eade555900..28db43d34a 100644 --- a/module/core/derive_tools_meta/Cargo.toml +++ b/module/core/derive_tools_meta/Cargo.toml @@ -64,7 +64,7 @@ derive_inner_from = [] derive_variadic_from = [] [dependencies] -# xxx : qqq : optimize features set +# zzz : qqq : optimize features set macro_tools = { workspace = true, features = [ "full" ] } iter_tools = { workspace = true, features = [ "full" ] } former_types = { workspace = true, features = [ "types_component_assign" ] } diff --git a/module/core/derive_tools_meta/src/derive/new.rs b/module/core/derive_tools_meta/src/derive/new.rs index 51913eacd8..2f0341c159 100644 --- a/module/core/derive_tools_meta/src/derive/new.rs +++ b/module/core/derive_tools_meta/src/derive/new.rs @@ -18,7 +18,7 @@ use item_attributes::*; // -// xxx : qqq : implement +// zzz : qqq : implement pub fn new( input : proc_macro::TokenStream ) -> Result< proc_macro2::TokenStream > { // use macro_tools::quote::ToTokens; @@ -126,7 +126,7 @@ pub fn new( input : proc_macro::TokenStream ) -> Result< proc_macro2::TokenStrea Ok( result ) } -// xxx : qqq : implement +// zzz : qqq : implement // qqq : document, add example of generated code fn generate_unit ( @@ -153,7 +153,7 @@ fn generate_unit } } -// xxx : qqq : implement +// zzz : qqq : implement // qqq : document, add example of generated code fn generate_single_field_named ( @@ -185,7 +185,7 @@ fn generate_single_field_named } } -// xxx : qqq : implement +// zzz : qqq : implement // qqq : document, add example of generated code fn generate_single_field ( @@ -217,7 +217,7 @@ fn generate_single_field } } -// xxx : qqq : implement +// zzz : qqq : implement // qqq : document, add example of generated code fn generate_multiple_fields_named< 'a > ( @@ -231,17 +231,12 @@ fn generate_multiple_fields_named< 'a > -> proc_macro2::TokenStream { - // let field_names : Vec< _ > = field_names.collect(); // xxx : qqq : rid off collects - let val_type = field_names - // .iter() .clone() .zip( field_types ) .enumerate() .map(| ( _index, ( field_name, field_type ) ) | { - // xxx - // let index = index.to_string().parse::< proc_macro2::TokenStream >().unwrap(); qt! { #field_name : #field_type } }); @@ -264,7 +259,7 @@ fn generate_multiple_fields_named< 'a > } -// xxx : qqq : implement +// zzz : qqq : implement // qqq : document, add example of generated code fn generate_multiple_fields< 'a > ( @@ -302,7 +297,7 @@ fn generate_multiple_fields< 'a > } } -// xxx : qqq : implement +// zzz : qqq : implement // qqq : document, add example of generated code fn variant_generate ( diff --git a/module/core/macro_tools/src/iter.rs b/module/core/macro_tools/src/iter.rs index 1ece7544f5..772c687355 100644 --- a/module/core/macro_tools/src/iter.rs +++ b/module/core/macro_tools/src/iter.rs @@ -42,10 +42,7 @@ pub( crate ) mod private for Box< dyn _IterTrait< 'c, T > + 'c > { #[ inline ] - fn clone( &self ) -> Self - { - clone_dyn_types::clone_into_box( &**self ) - } + fn clone( &self ) -> Self { clone_dyn_types::clone_into_box( &**self ) } } #[ allow( non_local_definitions ) ] @@ -74,28 +71,6 @@ pub( crate ) mod private // = - // impl< 'c, 'a, T > Clone - // for Box< dyn _IterTrait< 'a, T > + 'c > - // { - // #[ inline ] - // fn clone( &self ) -> Self { clone_into_box( &**self ) } - // } - - // // xxx2 - // #[ inline ] - // fn clone_into_box< T >( t : &T ) -> Box< T > - // where - // T : ?Sized, - // { - // unsafe - // { - // let mut ptr = t as *const T; - // let data_ptr = &mut ptr as *mut *const T as *mut *mut (); - // *data_ptr = Box::into_raw( Box::new( t.clone() ) ) as *mut (); - // Box::from_raw( ptr as *mut T ) - // } - // } - // xxx pub type BoxedIter< 'a, T > = Box< dyn _IterTrait< 'a, T > + 'a >; From e55a651165616bf5f311c69232023d03e32cf1fd Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 09:28:17 +0300 Subject: [PATCH 33/45] collection_tools-v0.9.0 --- Cargo.toml | 2 +- module/core/collection_tools/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b821ec379d..81890d0512 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -104,7 +104,7 @@ default-features = false features = [ "enabled" ] [workspace.dependencies.collection_tools] -version = "~0.8.0" +version = "~0.9.0" path = "module/core/collection_tools" default-features = false diff --git a/module/core/collection_tools/Cargo.toml b/module/core/collection_tools/Cargo.toml index 65a81d7cde..bb7609b9c9 100644 --- a/module/core/collection_tools/Cargo.toml +++ b/module/core/collection_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "collection_tools" -version = "0.8.0" +version = "0.9.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 30faa10e9197cce9d1afd5d5c89d1a0f7d999a71 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 09:31:06 +0300 Subject: [PATCH 34/45] former_types-v2.5.0 --- Cargo.toml | 2 +- module/core/former_types/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 81890d0512..6a6060bcb7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -228,7 +228,7 @@ path = "module/core/former_meta" default-features = false [workspace.dependencies.former_types] -version = "~2.4.0" +version = "~2.5.0" path = "module/core/former_types" default-features = false diff --git a/module/core/former_types/Cargo.toml b/module/core/former_types/Cargo.toml index 96047371a5..371a31a76a 100644 --- a/module/core/former_types/Cargo.toml +++ b/module/core/former_types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former_types" -version = "2.4.0" +version = "2.5.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 0caac9688b2bca87858841fd4b55304904269c02 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 09:31:12 +0300 Subject: [PATCH 35/45] clone_dyn_types-v0.19.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 6a6060bcb7..fe7ca22721 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -170,7 +170,7 @@ path = "module/core/clone_dyn_meta" features = [ "enabled" ] [workspace.dependencies.clone_dyn_types] -version = "~0.18.0" +version = "~0.19.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 9c86870d24..8b0e815051 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.18.0" +version = "0.19.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From c11d2d789e243338107594896fe1c4343725b3cc Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 09:31:44 +0300 Subject: [PATCH 36/45] . --- module/core/derive_tools_meta/src/derive/from.rs | 7 ++++--- module/core/macro_tools/src/iter.rs | 8 +++----- module/core/macro_tools/src/struct_like.rs | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/module/core/derive_tools_meta/src/derive/from.rs b/module/core/derive_tools_meta/src/derive/from.rs index 2e375e5d86..d9168768a9 100644 --- a/module/core/derive_tools_meta/src/derive/from.rs +++ b/module/core/derive_tools_meta/src/derive/from.rs @@ -363,7 +363,8 @@ fn generate_multiple_fields_named< 'a > }); // xxx : qqq : rid off collects - let field_types : Vec< _ > = field_types.collect(); + // let field_types : Vec< _ > = field_types.collect(); + let field_types2 = field_types.clone(); qt! { impl< #generics_impl > From< (# ( #field_types ),* ) > for #item_name< #generics_ty > @@ -372,9 +373,9 @@ fn generate_multiple_fields_named< 'a > { #[ inline( always ) ] // fn from( src : (i32, bool) ) -> Self - fn from( src : ( #( #field_types ),* ) ) -> Self + fn from( src : ( #( #field_types2 ),* ) ) -> Self { - #item_name { #(#params),* } + #item_name { #( #params ),* } } } } diff --git a/module/core/macro_tools/src/iter.rs b/module/core/macro_tools/src/iter.rs index 772c687355..a2897b0521 100644 --- a/module/core/macro_tools/src/iter.rs +++ b/module/core/macro_tools/src/iter.rs @@ -2,13 +2,9 @@ //! Iterators. //! -// use std::fmt::Debug; - /// Internal namespace. pub( crate ) mod private { - // use std::fmt; - // use crate::*; use clone_dyn_types::CloneDyn; /// Trait that encapsulates an iterator with specific characteristics, tailored for use with the `syn` crate. @@ -19,6 +15,7 @@ pub( crate ) mod private /// - Provide an exact size hint (`ExactSizeIterator`), /// - Be traversed from both ends (`DoubleEndedIterator`). /// + pub trait _IterTrait< 'a, T > where T : 'a, @@ -71,7 +68,8 @@ pub( crate ) mod private // = - // xxx + // xxx : write docuemntation + /// Prefer `BoxedIter` over `impl IterTrait` always when ypu use trait object ( dyn Itrator ) because concrete type in return is less restrictive than `impl IterTrait`. pub type BoxedIter< 'a, T > = Box< dyn _IterTrait< 'a, T > + 'a >; /// Trait that encapsulates a clonable iterator with specific characteristics, tailored for use with the `syn` crate. diff --git a/module/core/macro_tools/src/struct_like.rs b/module/core/macro_tools/src/struct_like.rs index 9f021670c2..4658265551 100644 --- a/module/core/macro_tools/src/struct_like.rs +++ b/module/core/macro_tools/src/struct_like.rs @@ -392,6 +392,7 @@ pub( crate ) mod private }, StructLike::Enum( _item ) => { + // xxx let iter : BoxedIter< 'a, &'a syn::Ident > = Box::new( self.fields().map( | field | field.ident.as_ref().unwrap() ) ); Some( iter ) // Some( DynIter::new( self.fields().map( | field | field.ident.as_ref().unwrap() ) ) ) From df23eced4524a33123e42db4ed3e4044ca34e23e Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 09:51:28 +0300 Subject: [PATCH 37/45] macro_tools-v0.31.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 fe7ca22721..f2fd6b6592 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -273,7 +273,7 @@ default-features = false ## macro tools [workspace.dependencies.macro_tools] -version = "~0.30.0" +version = "~0.31.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 782e5da96d..4f48b5095d 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.30.0" +version = "0.31.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 0d0be1da37ef98cd92fc473b6bb1133f3cc9260f Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 09:51:43 +0300 Subject: [PATCH 38/45] iter_tools-v0.18.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 f2fd6b6592..562cfc1c68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -195,7 +195,7 @@ default-features = false ## iter [workspace.dependencies.iter_tools] -version = "~0.17.0" +version = "~0.18.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 233ac33f5b..0675b432e9 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.17.0" +version = "0.18.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 5cb4fc6617c60fac993f822ffd99c0d0aa49171f Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 09:52:09 +0300 Subject: [PATCH 39/45] former_meta-v2.4.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 562cfc1c68..eb7f79ede8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -223,7 +223,7 @@ default-features = false # default-features = false [workspace.dependencies.former_meta] -version = "~2.3.0" +version = "~2.4.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 5363d0dd89..32b6323ecc 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.3.0" +version = "2.4.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 4f2778f0731dcf28b30c32a58433eaecbf977d24 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 09:52:28 +0300 Subject: [PATCH 40/45] former-v2.4.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 eb7f79ede8..bd25dc3b93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -213,7 +213,7 @@ path = "module/core/for_each" default-features = false [workspace.dependencies.former] -version = "~2.3.0" +version = "~2.4.0" path = "module/core/former" default-features = false diff --git a/module/core/former/Cargo.toml b/module/core/former/Cargo.toml index 812cda2467..ca855af42a 100644 --- a/module/core/former/Cargo.toml +++ b/module/core/former/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "former" -version = "2.3.0" +version = "2.4.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 57a08c14a295b621fdfc57eaf62be7478399fb66 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 16:37:47 +0300 Subject: [PATCH 41/45] clone_dyn and clone_dyn_types completed --- module/core/clone_dyn/Cargo.toml | 11 +- module/core/clone_dyn/Readme.md | 200 +++++++++++++++- .../clone_dyn/examples/clone_dyn_trivial.rs | 143 ++++++++++-- module/core/clone_dyn/src/lib.rs | 9 +- module/core/clone_dyn_meta/Cargo.toml | 2 + module/core/clone_dyn_meta/src/derive.rs | 3 +- module/core/clone_dyn_types/Cargo.toml | 3 - module/core/clone_dyn_types/Readme.md | 220 ++++++++++++++++-- .../examples/clone_dyn_types_trivial.rs | 153 ++++++++++-- module/core/clone_dyn_types/src/lib.rs | 20 +- module/core/derive_tools/Cargo.toml | 2 +- module/core/macro_tools/src/iter.rs | 119 +++++++--- 12 files changed, 767 insertions(+), 118 deletions(-) diff --git a/module/core/clone_dyn/Cargo.toml b/module/core/clone_dyn/Cargo.toml index 85dc6a48ac..db1c0f9f85 100644 --- a/module/core/clone_dyn/Cargo.toml +++ b/module/core/clone_dyn/Cargo.toml @@ -23,20 +23,15 @@ workspace = true [package.metadata.docs.rs] features = [ "full" ] all-features = false -# exclude = [ "/tests", "/examples", "-*" ] [features] default = [ "enabled", "clone_dyn_types", "clone_dyn_meta" ] full = [ "enabled", "clone_dyn_types", "clone_dyn_meta" ] -no_std = [] -use_alloc = [ "no_std" ] -enabled = [ "clone_dyn_meta/enabled", "clone_dyn_types/enabled" ] +enabled = [] -# xxx : implement no_std - -clone_dyn_types = [ "dep:clone_dyn_types" ] -clone_dyn_meta = [ "dep:clone_dyn_meta", "clone_dyn_types" ] +clone_dyn_types = [ "dep:clone_dyn_types", "clone_dyn_types/enabled" ] +clone_dyn_meta = [ "dep:clone_dyn_meta", "clone_dyn_meta/enabled", "clone_dyn_types" ] [dependencies] clone_dyn_meta = { workspace = true, optional = true } diff --git a/module/core/clone_dyn/Readme.md b/module/core/clone_dyn/Readme.md index 7f3a89cdd5..eda69277ee 100644 --- a/module/core/clone_dyn/Readme.md +++ b/module/core/clone_dyn/Readme.md @@ -12,27 +12,205 @@ By default, Rust does not support cloning for trait objects due to the `Clone` t There are few alternatives [dyn-clone](https://github.com/dtolnay/dyn-clone), [dyn-clonable](https://github.com/kardeiz/objekt-clonable). Unlike other options, this solution is more concise and demands less effort to use, all without compromising the quality of the outcome. -### Basic use-case +## Basic use-case - - +Demonstrates the usage of `clone_dyn` to enable cloning for trait objects. - +``` + +
+If you use multithreading or asynchronous paradigms implement trait `Clone` also for `Send` and `Sync` + +```rust, ignore + +#[ allow( non_local_definitions ) ] +impl< 'c, T > Clone for Box< dyn IterTrait< 'c, T > + 'c > +{ + #[ inline ] + fn clone( &self ) -> Self + { + clone_dyn::clone_into_box( &**self ) + } +} + +#[ allow( non_local_definitions ) ] +impl< 'c, T > Clone for Box< dyn IterTrait< 'c, T > + Send + 'c > +{ + #[ inline ] + fn clone( &self ) -> Self + { + clone_dyn::clone_into_box( &**self ) + } +} + +#[ allow( non_local_definitions ) ] +impl< 'c, T > Clone for Box< dyn IterTrait< 'c, T > + Sync + 'c > +{ + #[ inline ] + fn clone( &self ) -> Self + { + clone_dyn::clone_into_box( &**self ) + } +} + +#[ allow( non_local_definitions ) ] +impl< 'c, T > Clone for Box< dyn IterTrait< 'c, T > + Send + Sync + 'c > +{ + #[ inline ] + fn clone( &self ) -> Self + { + clone_dyn::clone_into_box( &**self ) + } +} + +``` + +
+ +
- +Try out `cargo run --example clone_dyn_trivial`. +
+[See code](./examples/clone_dyn_trivial.rs). ### To add to your project diff --git a/module/core/clone_dyn/examples/clone_dyn_trivial.rs b/module/core/clone_dyn/examples/clone_dyn_trivial.rs index 58686ee449..e14bbc9a8a 100644 --- a/module/core/clone_dyn/examples/clone_dyn_trivial.rs +++ b/module/core/clone_dyn/examples/clone_dyn_trivial.rs @@ -1,25 +1,142 @@ +//! +//! ## Basic use-case +//! //! Demonstrates the usage of `clone_dyn` to enable cloning for trait objects. //! //! By default, Rust does not support cloning for trait objects due to the `Clone` trait //! requiring compile-time knowledge of the type's size. The `clone_dyn` crate addresses //! this limitation through procedural macros, allowing for cloning collections of trait objects. +//! +//! ##### Overview +//! +//! This example shows how to use the `clone_dyn` crate to enable cloning for trait objects, +//! specifically for iterators. It defines a custom trait, `IterTrait`, that encapsulates +//! an iterator with specific characteristics and demonstrates how to use `CloneDyn` to +//! overcome the object safety constraints of the `Clone` trait. +//! +//! ##### The `IterTrait` Trait +//! +//! The `IterTrait` trait is designed to represent iterators that yield references to items (`&'a T`). +//! These iterators must also implement the `ExactSizeIterator` and `DoubleEndedIterator` traits. +//! Additionally, the iterator must implement the `CloneDyn` trait, which allows cloning of trait objects. +//! +//! The trait is implemented for any type that meets the specified requirements. +//! +//! ##### Cloning Trait Objects +//! +//! Rust's type system does not allow trait objects to implement the `Clone` trait directly due to object safety constraints. +//! Specifically, the `Clone` trait requires knowledge of the concrete type at compile time, which is not available for trait objects. +//! +//! The `CloneDyn` trait from the `clone_dyn` crate provides a workaround for this limitation by allowing trait objects to be cloned. +//! Procedural macros generates the necessary code for cloning trait objects, making it possible to clone collections of trait objects. +//! +//! The example demonstrates how to implement `Clone` for boxed `IterTrait` trait objects. +//! +//! ##### `get_iter` Function +//! +//! The `get_iter` function returns a boxed iterator that implements the `IterTrait` trait. +//! If the input is `Some`, it returns an iterator over the vector. +//! If the input is `None`, it returns an empty iterator. +//! +//! It's not possible to use `impl Iterator` here because the code returns iterators of two different types: +//! - `std::slice::Iter` when the input is `Some`. +//! - `std::iter::Empty` when the input is `None`. +//! +//! To handle this, the function returns a trait object ( `Box< dyn IterTrait >` ). +//! However, Rust's `Clone` trait cannot be implemented for trait objects due to object safety constraints. +//! The `CloneDyn` trait addresses this problem by enabling cloning of trait objects. +//! +//! ##### `use_iter` Function +//! +//! The `use_iter` function demonstrates the use of the `CloneDyn` trait by cloning the iterator. +//! It then iterates over the cloned iterator and prints each element. +//! +//! ##### Main Function +//! +//! The main function demonstrates the overall usage by creating a vector, obtaining an iterator, and using the iterator to print elements. +//! -#[ cfg( any( not( feature = "enabled" ), all( feature = "no_std", not( feature = "use_alloc" ) ) ) ) ] +#[ cfg( not( feature = "enabled" ) ) ] fn main() {} -#[ cfg( all( feature = "enabled", any( not( feature = "no_std" ), feature = "use_alloc" ) ) ) ] +#[ cfg( feature = "enabled" ) ] fn main() { + use clone_dyn::{ clone_dyn, CloneDyn }; -// use clone_dyn::clone_dyn; -// -// #[ clone_dyn ] -// trait Trait1 -// { -// } -// -// let vec = Vec::< Box< dyn Trait1 > >::new(); -// let _vec2 = vec.clone(); /* <- it does not work without `clone_dyn` */ + /// Trait that encapsulates an iterator with specific characteristics, tailored for your needs. + #[ clone_dyn ] + pub trait IterTrait< 'a, T > + where + T : 'a, + Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, + // Self : CloneDyn, + // no need to explicitly to define this bound, because macro will do it for you anyway + { + } -} + impl< 'a, T, I > IterTrait< 'a, T > for I + where + T : 'a, + Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, + Self : CloneDyn, + { + } -// xxx : improve \ No newline at end of file + /// + /// Function to get an iterator over a vector of integers. + /// + /// This function returns a boxed iterator that implements the `IterTrait` trait. + /// If the input is `Some`, it returns an iterator over the vector. + /// If the input is `None`, it returns an empty iterator. + /// + /// Rust's type system does not allow trait objects to implement the `Clone` trait directly due to object safety constraints. + /// Specifically, the `Clone` trait requires knowledge of the concrete type at compile time, which is not available for trait objects. + /// + /// In this example, we need to return an iterator that can be cloned. Since we are returning a trait object ( `Box< dyn IterTrait >` ), + /// we cannot directly implement `Clone` for this trait object. This is where the `CloneDyn` trait from the `clone_dyn` crate comes in handy. + /// + /// The `CloneDyn` trait provides a workaround for this limitation by allowing trait objects to be cloned. + /// It uses procedural macros to generate the necessary code for cloning trait objects, making it possible to clone collections of trait objects. + /// + /// It's not possible to use `impl Iterator` here because the code returns iterators of two different types: + /// - `std::slice::Iter` when the input is `Some`. + /// - `std::iter::Empty` when the input is `None`. + /// + /// To handle this, the function returns a trait object (`Box`). + /// However, Rust's `Clone` trait cannot be implemented for trait objects due to object safety constraints. + /// The `CloneDyn` trait addresses this problem by enabling cloning of trait objects. + + pub fn get_iter< 'a >( src : Option< &'a Vec< i32 > > ) -> Box< dyn IterTrait< 'a, &'a i32 > + 'a > + { + match &src + { + Some( src ) => Box::new( src.iter() ), + _ => Box::new( core::iter::empty() ), + } + } + + /// Function to use an iterator and print its elements. + /// + /// This function demonstrates the use of the `CloneDyn` trait by cloning the iterator. + /// It then iterates over the cloned iterator and prints each element. + pub fn use_iter< 'a >( iter : Box< dyn IterTrait< 'a, &'a i32 > + 'a > ) + { + // Clone would not be available if CloneDyn is not implemented for the iterator. + // And being an object-safe trait, it can't implement Clone. + // Nevertheless, thanks to CloneDyn, the object is clonable. + // + // This line demonstrates cloning the iterator and iterating over the cloned iterator. + iter.clone().for_each( | e | println!( "{e}" ) ); + + // Iterate over the original iterator and print each element. + iter.for_each( | e | println!( "{e}" ) ); + } + + // Create a vector of integers. + let data = vec![ 1, 2, 3 ]; + // Get an iterator over the vector. + let iter = get_iter( Some( &data ) ); + // Use the iterator to print its elements. + use_iter( iter ); + +} diff --git a/module/core/clone_dyn/src/lib.rs b/module/core/clone_dyn/src/lib.rs index 16d5b89cff..251186abd6 100644 --- a/module/core/clone_dyn/src/lib.rs +++ b/module/core/clone_dyn/src/lib.rs @@ -1,14 +1,8 @@ -#![ cfg_attr( feature = "no_std", no_std ) ] +#![ no_std ] #![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] #![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] #![ doc( html_root_url = "https://docs.rs/clone_dyn/latest/clone_dyn/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -// xxx - -// #[ allow( unused_extern_crates ) ] -// #[ cfg( feature = "enabled" ) ] -// #[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ] -// extern crate alloc; /// Namespace with dependencies. @@ -22,7 +16,6 @@ pub mod dependency } /// Internal namespace. -#[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] #[ cfg( feature = "enabled" ) ] pub( crate ) mod private { diff --git a/module/core/clone_dyn_meta/Cargo.toml b/module/core/clone_dyn_meta/Cargo.toml index 54470330db..11f0b4743e 100644 --- a/module/core/clone_dyn_meta/Cargo.toml +++ b/module/core/clone_dyn_meta/Cargo.toml @@ -36,7 +36,9 @@ enabled = [ "macro_tools/enabled", "former_types/enabled" ] [dependencies] macro_tools = { workspace = true } # qqq : xxx : optimize set of features former_types = { workspace = true, features = [ "types_component_assign" ] } +# xxx : incapsulate into macro_tools const_format = { version = "0.2.32" } +# xxx : incapsulate into macro_tools [dev-dependencies] test_tools = { workspace = true } diff --git a/module/core/clone_dyn_meta/src/derive.rs b/module/core/clone_dyn_meta/src/derive.rs index 353f33f2ce..40e1cb9de0 100644 --- a/module/core/clone_dyn_meta/src/derive.rs +++ b/module/core/clone_dyn_meta/src/derive.rs @@ -5,13 +5,12 @@ use macro_tools:: Result, AttributePropertyOptionalSingletone, AttributePropertyComponent, - // attr, diag, generic_params, }; use former_types::{ Assign }; // use const_format::concatcp; -// xxx : incapsulate into macro_tools and put all that udner features +// xxx : incapsulate into macro_tools and put all that under features // diff --git a/module/core/clone_dyn_types/Cargo.toml b/module/core/clone_dyn_types/Cargo.toml index 8b0e815051..9dec565157 100644 --- a/module/core/clone_dyn_types/Cargo.toml +++ b/module/core/clone_dyn_types/Cargo.toml @@ -27,9 +27,6 @@ all-features = false default = [ "enabled" ] full = [ "enabled" ] -no_std = [] -use_alloc = [ "no_std" ] -# xxx : implement no_std enabled = [] [dependencies] diff --git a/module/core/clone_dyn_types/Readme.md b/module/core/clone_dyn_types/Readme.md index 1fad07a5ad..8485e1c9db 100644 --- a/module/core/clone_dyn_types/Readme.md +++ b/module/core/clone_dyn_types/Readme.md @@ -10,39 +10,225 @@ It's types, use `clone_dyn` to avoid bolerplate. By default, Rust does not support cloning for trait objects due to the `Clone` trait requiring compile-time knowledge of the type's size. The `clone_dyn` crate addresses this limitation through procedural macros, allowing for cloning collections of trait objects. Prefer to use `clone_dyn` instead of this crate, because `clone_dyn` includes this crate and also provides an attribute macro to generate boilerplate with one line of code. -### Alternative +## Alternative There are few alternatives [dyn-clone](https://github.com/dtolnay/dyn-clone), [dyn-clonable](https://github.com/kardeiz/objekt-clonable). Unlike other options, this solution is more concise and demands less effort to use, all without compromising the quality of the outcome. -### Basic use-case +## Basic use-case - - +Demonstrates the usage of `clone_dyn` to enable cloning for trait objects. - + impl< 'a, T, I > IterTrait< 'a, T > for I + where + T : 'a, + Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, + Self : CloneDyn, + { + } + + // Implement `Clone` for boxed `IterTrait` trait objects. + impl< 'c, T > Clone for Box< dyn IterTrait< 'c, T > + 'c > + { + #[ inline ] + fn clone( &self ) -> Self + { + clone_dyn_types::clone_into_box( &**self ) + } + } + + /// + /// Function to get an iterator over a vector of integers. + /// + /// This function returns a boxed iterator that implements the `IterTrait` trait. + /// If the input is `Some`, it returns an iterator over the vector. + /// If the input is `None`, it returns an empty iterator. + /// + /// Rust's type system does not allow trait objects to implement the `Clone` trait directly due to object safety constraints. + /// Specifically, the `Clone` trait requires knowledge of the concrete type at compile time, which is not available for trait objects. + /// + /// In this example, we need to return an iterator that can be cloned. Since we are returning a trait object ( `Box< dyn IterTrait >` ), + /// we cannot directly implement `Clone` for this trait object. This is where the `CloneDyn` trait from the `clone_dyn_types` crate comes in handy. + /// + /// The `CloneDyn` trait provides a workaround for this limitation by allowing trait objects to be cloned. + /// It uses procedural macros to generate the necessary code for cloning trait objects, making it possible to clone collections of trait objects. + /// + /// It's not possible to use `impl Iterator` here because the code returns iterators of two different types: + /// - `std::slice::Iter` when the input is `Some`. + /// - `std::iter::Empty` when the input is `None`. + /// + /// To handle this, the function returns a trait object (`Box`). + /// However, Rust's `Clone` trait cannot be implemented for trait objects due to object safety constraints. + /// The `CloneDyn` trait addresses this problem by enabling cloning of trait objects. + /// + + pub fn get_iter< 'a >( src : Option< &'a Vec< i32 > > ) -> Box< dyn IterTrait< 'a, &'a i32 > + 'a > + { + match &src + { + Some( src ) => Box::new( src.iter() ), + _ => Box::new( core::iter::empty() ), + } + } + + /// Function to use an iterator and print its elements. + /// + /// This function demonstrates the use of the `CloneDyn` trait by cloning the iterator. + /// It then iterates over the cloned iterator and prints each element. + pub fn use_iter< 'a >( iter : Box< dyn IterTrait< 'a, &'a i32 > + 'a > ) + { + // Clone would not be available if CloneDyn is not implemented for the iterator. + // And being an object-safe trait, it can't implement Clone. + // Nevertheless, thanks to CloneDyn, the object is clonable. + // + // This line demonstrates cloning the iterator and iterating over the cloned iterator. + iter.clone().for_each( | e | println!( "{e}" ) ); + + // Iterate over the original iterator and print each element. + iter.for_each( | e | println!( "{e}" ) ); + } + + // Create a vector of integers. + let data = vec![ 1, 2, 3 ]; + // Get an iterator over the vector. + let iter = get_iter( Some( &data ) ); + // Use the iterator to print its elements. + use_iter( iter ); + +} +``` + +
+If you use multithreading or asynchronous paradigms implement trait `Clone` also for `Send` and `Sync` + +```rust, ignore + +#[ allow( non_local_definitions ) ] +impl< 'c, T > Clone for Box< dyn IterTrait< 'c, T > + 'c > +{ + #[ inline ] + fn clone( &self ) -> Self + { + clone_dyn_types::clone_into_box( &**self ) + } +} + +#[ allow( non_local_definitions ) ] +impl< 'c, T > Clone for Box< dyn IterTrait< 'c, T > + Send + 'c > +{ + #[ inline ] + fn clone( &self ) -> Self + { + clone_dyn_types::clone_into_box( &**self ) + } +} + +#[ allow( non_local_definitions ) ] +impl< 'c, T > Clone for Box< dyn IterTrait< 'c, T > + Sync + 'c > +{ + #[ inline ] + fn clone( &self ) -> Self + { + clone_dyn_types::clone_into_box( &**self ) + } +} + +#[ allow( non_local_definitions ) ] +impl< 'c, T > Clone for Box< dyn IterTrait< 'c, T > + Send + Sync + 'c > +{ + #[ inline ] + fn clone( &self ) -> Self + { + clone_dyn_types::clone_into_box( &**self ) + } +} + +``` + +
+ +
- +Try out `cargo run --example clone_dyn_types_trivial`. +
+[See code](./examples/clone_dyn_types_trivial.rs). -### To add to your project +## To add to your project ```sh cargo add clone_dyn_types ``` -### Try out from the repository +## Try out from the repository ```sh git clone https://github.com/Wandalen/wTools diff --git a/module/core/clone_dyn_types/examples/clone_dyn_types_trivial.rs b/module/core/clone_dyn_types/examples/clone_dyn_types_trivial.rs index 58686ee449..dce84eb919 100644 --- a/module/core/clone_dyn_types/examples/clone_dyn_types_trivial.rs +++ b/module/core/clone_dyn_types/examples/clone_dyn_types_trivial.rs @@ -1,25 +1,150 @@ +//! +//! ## Basic use-case +//! //! Demonstrates the usage of `clone_dyn` to enable cloning for trait objects. //! //! By default, Rust does not support cloning for trait objects due to the `Clone` trait //! requiring compile-time knowledge of the type's size. The `clone_dyn` crate addresses -//! this limitation through procedural macros, allowing for cloning collections of trait objects. +//! this limitation through procedural macros, allowing for cloning collections of trait objects +//! and crate `clone_dyn_types` contains implementation of all types. +//! +//! ##### Overview +//! +//! This example shows how to use the `clone_dyn` crate to enable cloning for trait objects, +//! specifically for iterators. It defines a custom trait, `IterTrait`, that encapsulates +//! an iterator with specific characteristics and demonstrates how to use `CloneDyn` to +//! overcome the object safety constraints of the `Clone` trait. +//! +//! ##### The `IterTrait` Trait +//! +//! The `IterTrait` trait is designed to represent iterators that yield references to items (`&'a T`). +//! These iterators must also implement the `ExactSizeIterator` and `DoubleEndedIterator` traits. +//! Additionally, the iterator must implement the `CloneDyn` trait, which allows cloning of trait objects. +//! +//! The trait is implemented for any type that meets the specified requirements. +//! +//! ##### Cloning Trait Objects +//! +//! Rust's type system does not allow trait objects to implement the `Clone` trait directly due to object safety constraints. +//! Specifically, the `Clone` trait requires knowledge of the concrete type at compile time, which is not available for trait objects. +//! +//! The `CloneDyn` trait from the `clone_dyn_types` crate provides a workaround for this limitation by allowing trait objects to be cloned. +//! +//! The example demonstrates how to implement `Clone` for boxed `IterTrait` trait objects. +//! +//! ##### `get_iter` Function +//! +//! The `get_iter` function returns a boxed iterator that implements the `IterTrait` trait. +//! If the input is `Some`, it returns an iterator over the vector. +//! If the input is `None`, it returns an empty iterator. +//! +//! It's not possible to use `impl Iterator` here because the code returns iterators of two different types: +//! - `std::slice::Iter` when the input is `Some`. +//! - `std::iter::Empty` when the input is `None`. +//! +//! To handle this, the function returns a trait object ( `Box< dyn IterTrait >` ). +//! However, Rust's `Clone` trait cannot be implemented for trait objects due to object safety constraints. +//! The `CloneDyn` trait addresses this problem by enabling cloning of trait objects. +//! +//! ##### `use_iter` Function +//! +//! The `use_iter` function demonstrates the use of the `CloneDyn` trait by cloning the iterator. +//! It then iterates over the cloned iterator and prints each element. +//! +//! ##### Main Function +//! +//! The main function demonstrates the overall usage by creating a vector, obtaining an iterator, and using the iterator to print elements. +//! -#[ cfg( any( not( feature = "enabled" ), all( feature = "no_std", not( feature = "use_alloc" ) ) ) ) ] +#[ cfg( not( feature = "enabled" ) ) ] fn main() {} -#[ cfg( all( feature = "enabled", any( not( feature = "no_std" ), feature = "use_alloc" ) ) ) ] +#[ cfg( feature = "enabled" ) ] fn main() { + use clone_dyn_types::CloneDyn; -// use clone_dyn::clone_dyn; -// -// #[ clone_dyn ] -// trait Trait1 -// { -// } -// -// let vec = Vec::< Box< dyn Trait1 > >::new(); -// let _vec2 = vec.clone(); /* <- it does not work without `clone_dyn` */ + /// Trait that encapsulates an iterator with specific characteristics, tailored for your needs. + pub trait IterTrait< 'a, T > + where + T : 'a, + Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, + Self : CloneDyn, + { + } -} + impl< 'a, T, I > IterTrait< 'a, T > for I + where + T : 'a, + Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator, + Self : CloneDyn, + { + } -// xxx : improve \ No newline at end of file + // Implement `Clone` for boxed `IterTrait` trait objects. + #[ allow( non_local_definitions ) ] + impl< 'c, T > Clone for Box< dyn IterTrait< 'c, T > + 'c > + { + #[ inline ] + fn clone( &self ) -> Self + { + clone_dyn_types::clone_into_box( &**self ) + } + } + + /// + /// Function to get an iterator over a vector of integers. + /// + /// This function returns a boxed iterator that implements the `IterTrait` trait. + /// If the input is `Some`, it returns an iterator over the vector. + /// If the input is `None`, it returns an empty iterator. + /// + /// Rust's type system does not allow trait objects to implement the `Clone` trait directly due to object safety constraints. + /// Specifically, the `Clone` trait requires knowledge of the concrete type at compile time, which is not available for trait objects. + /// + /// In this example, we need to return an iterator that can be cloned. Since we are returning a trait object ( `Box< dyn IterTrait >` ), + /// we cannot directly implement `Clone` for this trait object. This is where the `CloneDyn` trait from the `clone_dyn_types` crate comes in handy. + /// + /// The `CloneDyn` trait provides a workaround for this limitation by allowing trait objects to be cloned. + /// + /// It's not possible to use `impl Iterator` here because the code returns iterators of two different types: + /// - `std::slice::Iter` when the input is `Some`. + /// - `std::iter::Empty` when the input is `None`. + /// + /// To handle this, the function returns a trait object (`Box`). + /// However, Rust's `Clone` trait cannot be implemented for trait objects due to object safety constraints. + /// The `CloneDyn` trait addresses this problem by enabling cloning of trait objects. + + pub fn get_iter< 'a >( src : Option< &'a Vec< i32 > > ) -> Box< dyn IterTrait< 'a, &'a i32 > + 'a > + { + match &src + { + Some( src ) => Box::new( src.iter() ), + _ => Box::new( core::iter::empty() ), + } + } + + /// Function to use an iterator and print its elements. + /// + /// This function demonstrates the use of the `CloneDyn` trait by cloning the iterator. + /// It then iterates over the cloned iterator and prints each element. + pub fn use_iter< 'a >( iter : Box< dyn IterTrait< 'a, &'a i32 > + 'a > ) + { + // Clone would not be available if CloneDyn is not implemented for the iterator. + // And being an object-safe trait, it can't implement Clone. + // Nevertheless, thanks to CloneDyn, the object is clonable. + // + // This line demonstrates cloning the iterator and iterating over the cloned iterator. + iter.clone().for_each( | e | println!( "{e}" ) ); + + // Iterate over the original iterator and print each element. + iter.for_each( | e | println!( "{e}" ) ); + } + + // Create a vector of integers. + let data = vec![ 1, 2, 3 ]; + // Get an iterator over the vector. + let iter = get_iter( Some( &data ) ); + // Use the iterator to print its elements. + use_iter( iter ); + +} diff --git a/module/core/clone_dyn_types/src/lib.rs b/module/core/clone_dyn_types/src/lib.rs index 377a365eac..3ace741087 100644 --- a/module/core/clone_dyn_types/src/lib.rs +++ b/module/core/clone_dyn_types/src/lib.rs @@ -1,21 +1,13 @@ -#![ cfg_attr( feature = "no_std", no_std ) ] +#![ no_std ] #![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ] #![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ] #![ doc( html_root_url = "https://docs.rs/clone_dyn_types/latest/clone_dyn_types/" ) ] #![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ] -// xxx : fix - -#[ allow( unused_extern_crates ) ] -#[ cfg( feature = "enabled" ) ] -#[ cfg( all( feature = "no_std", feature = "use_alloc" ) ) ] -extern crate alloc; /// Namespace with dependencies. - #[ cfg( feature = "enabled" ) ] pub mod dependency { - // pub use ::clone_dyn_meta; } /// Internal namespace. @@ -24,13 +16,13 @@ pub mod dependency pub( crate ) mod private { - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] extern crate alloc; - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] - #[ allow( unused_imports ) ] + // #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] + // #[ allow( unused_imports ) ] use alloc::boxed::Box; - #[ cfg( all( feature = "use_std", not( feature = "use_alloc" ) ) ) ] - use std::boxed::Box; + // #[ cfg( all( feature = "use_std", not( feature = "use_alloc" ) ) ) ] + // use std::boxed::Box; /// A trait to upcast a clonable entity and clone it. /// It's implemented for all entities which can be cloned. diff --git a/module/core/derive_tools/Cargo.toml b/module/core/derive_tools/Cargo.toml index dd7714b587..2dc4b4afb6 100644 --- a/module/core/derive_tools/Cargo.toml +++ b/module/core/derive_tools/Cargo.toml @@ -120,7 +120,7 @@ full = [ # "use_std", ] no_std = [] -use_alloc = [ "no_std", "clone_dyn/use_alloc" ] +use_alloc = [ "no_std" ] enabled = [ "derive_tools_meta/enabled" ] # nightly = [ "derive_more/nightly" ] diff --git a/module/core/macro_tools/src/iter.rs b/module/core/macro_tools/src/iter.rs index a2897b0521..13bb883dfb 100644 --- a/module/core/macro_tools/src/iter.rs +++ b/module/core/macro_tools/src/iter.rs @@ -7,15 +7,58 @@ pub( crate ) mod private { use clone_dyn_types::CloneDyn; - /// Trait that encapsulates an iterator with specific characteristics, tailored for use with the `syn` crate. + /// Trait that encapsulates an iterator with specific characteristics, tailored for use with the `syn` crate and implemetning `CloneDyn`. /// - /// The `_IterTrait` trait is designed to represent iterators that may yield references to items (`&'a T`) within the `syn` crate. + /// The `_IterTrait` trait is designed to represent iterators that may yield references to items ( `&'a T` ) within the `syn` crate. /// These iterators must also implement the `ExactSizeIterator` and `DoubleEndedIterator` traits. /// This combination ensures that the iterator can: - /// - Provide an exact size hint (`ExactSizeIterator`), - /// - Be traversed from both ends (`DoubleEndedIterator`). + /// - Provide an exact size hint ( `ExactSizeIterator` ), + /// - Be traversed from both ends ( `DoubleEndedIterator` ). /// - + /// Additionally, the iterator must implement the `CloneDyn` trait, which allows cloning of trait objects. + /// + /// # Example + /// ```rust + /// use assistant::_IterTrait; + /// + /// // Example struct that implements Iterator, ExactSizeIterator, DoubleEndedIterator, and CloneDyn. + /// #[ derive( Clone ) ] + /// struct MyIterator + /// { + /// // internal fields + /// } + /// + /// impl Iterator for MyIterator + /// { + /// type Item = i32; + /// + /// fn next( &mut self ) -> Option< Self::Item > + /// { + /// // implementation + /// Some( 1 ) + /// } + /// } + /// + /// impl ExactSizeIterator for MyIterator + /// { + /// fn len( &self ) -> usize + /// { + /// // implementation + /// 1 + /// } + /// } + /// + /// impl DoubleEndedIterator for MyIterator + /// { + /// fn next_back( &mut self ) -> Option< Self::Item > + /// { + /// // implementation + /// Some( 1 ) + /// } + /// } + /// + /// impl _IterTrait< '_, i32 > for MyIterator {} + /// ``` pub trait _IterTrait< 'a, T > where T : 'a, @@ -32,54 +75,76 @@ pub( crate ) mod private { } - // = - + /// Implement `Clone` for boxed `_IterTrait` trait objects. + /// + /// This allows cloning of boxed iterators that implement `_IterTrait`. #[ allow( non_local_definitions ) ] - impl< 'c, T > Clone - for Box< dyn _IterTrait< 'c, T > + 'c > + impl< 'c, T > Clone for Box< dyn _IterTrait< 'c, T > + 'c > { #[ inline ] - fn clone( &self ) -> Self { clone_dyn_types::clone_into_box( &**self ) } + fn clone( &self ) -> Self + { + clone_dyn_types::clone_into_box( &**self ) + } } #[ allow( non_local_definitions ) ] - impl< 'c, T > Clone - for Box< dyn _IterTrait< 'c, T > + Send + 'c > + impl< 'c, T > Clone for Box< dyn _IterTrait< 'c, T > + Send + 'c > { #[ inline ] - fn clone( &self ) -> Self { clone_dyn_types::clone_into_box( &**self ) } + fn clone( &self ) -> Self + { + clone_dyn_types::clone_into_box( &**self ) + } } #[ allow( non_local_definitions ) ] - impl< 'c, T > Clone - for Box< dyn _IterTrait< 'c, T > + Sync + 'c > + impl< 'c, T > Clone for Box< dyn _IterTrait< 'c, T > + Sync + 'c > { #[ inline ] - fn clone( &self ) -> Self { clone_dyn_types::clone_into_box( &**self ) } + fn clone( &self ) -> Self + { + clone_dyn_types::clone_into_box( &**self ) + } } #[ allow( non_local_definitions ) ] - impl< 'c, T > Clone - for Box< dyn _IterTrait< 'c, T > + Send + Sync + 'c > + impl< 'c, T > Clone for Box< dyn _IterTrait< 'c, T > + Send + Sync + 'c > { #[ inline ] - fn clone( &self ) -> Self { clone_dyn_types::clone_into_box( &**self ) } + fn clone( &self ) -> Self + { + clone_dyn_types::clone_into_box( &**self ) + } } - // = - - // xxx : write docuemntation - /// Prefer `BoxedIter` over `impl IterTrait` always when ypu use trait object ( dyn Itrator ) because concrete type in return is less restrictive than `impl IterTrait`. + /// Type alias for boxed `_IterTrait` trait objects. + /// + /// Prefer `BoxedIter` over `impl _IterTrait` when using trait objects ( `dyn _IterTrait` ) because the concrete type in return is less restrictive than `impl _IterTrait`. + /// + /// # Example + /// ```rust + /// use assistant::{ _IterTrait, BoxedIter }; + /// + /// // Example function that returns a BoxedIter. + /// fn example_iterator() -> BoxedIter< 'static, i32 > + /// { + /// Box::new( MyIterator + /// { + /// // initialize fields + /// }) + /// } + /// ``` pub type BoxedIter< 'a, T > = Box< dyn _IterTrait< 'a, T > + 'a >; /// Trait that encapsulates a clonable iterator with specific characteristics, tailored for use with the `syn` crate. /// - /// The `IterTrait` trait is designed to represent iterators that may yield references to items (`&'a T`) within the `syn` crate. + /// The `IterTrait` trait is designed to represent iterators that may yield references to items ( `&'a T` ) within the `syn` crate. /// These iterators must also implement the `ExactSizeIterator`, `DoubleEndedIterator`, and `Clone` traits. /// This combination ensures that the iterator can: - /// - Provide an exact size hint (`ExactSizeIterator`), - /// - Be traversed from both ends (`DoubleEndedIterator`), - /// - Be clonable (`Clone`). + /// - Provide an exact size hint ( `ExactSizeIterator` ), + /// - Be traversed from both ends ( `DoubleEndedIterator` ), + /// - Be clonable ( `Clone` ). /// pub trait IterTrait< 'a, T > where From 9d3c16c40bb662091cf12bfe72e764d19ef41b50 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 16:38:57 +0300 Subject: [PATCH 42/45] clone_dyn_types-v0.20.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 bd25dc3b93..d231da939b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -170,7 +170,7 @@ path = "module/core/clone_dyn_meta" features = [ "enabled" ] [workspace.dependencies.clone_dyn_types] -version = "~0.19.0" +version = "~0.20.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 9dec565157..55535ac954 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.19.0" +version = "0.20.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From e873b0c772a2ac4e0107303afc8d576beae6c44c Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 16:39:09 +0300 Subject: [PATCH 43/45] macro_tools-v0.32.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 d231da939b..bd7430fe9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -273,7 +273,7 @@ default-features = false ## macro tools [workspace.dependencies.macro_tools] -version = "~0.31.0" +version = "~0.32.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 4f48b5095d..5071cdb8d0 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.31.0" +version = "0.32.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 06d4324266f8c70a1eff150c1feb826869dd3d9b Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 16:39:23 +0300 Subject: [PATCH 44/45] clone_dyn_meta-v0.19.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 bd7430fe9c..e040af249c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -165,7 +165,7 @@ default-features = false features = [ "enabled" ] [workspace.dependencies.clone_dyn_meta] -version = "~0.18.0" +version = "~0.19.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 11f0b4743e..e8b060725b 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.18.0" +version = "0.19.0" edition = "2021" authors = [ "Kostiantyn Wandalen ", From 23937cf7edf4075b1c9e4585d76ceb20cbaae2ba Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 10 Jun 2024 16:39:32 +0300 Subject: [PATCH 45/45] clone_dyn-v0.19.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 e040af249c..1b52be3898 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -159,7 +159,7 @@ default-features = false features = [ "enabled" ] [workspace.dependencies.clone_dyn] -version = "~0.18.0" +version = "~0.19.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 db1c0f9f85..a4110df3bd 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.18.0" +version = "0.19.0" edition = "2021" authors = [ "Kostiantyn Wandalen ",