diff --git a/module/core/clone_dyn/Readme.md b/module/core/clone_dyn/Readme.md index eda69277ee..a5fece766e 100644 --- a/module/core/clone_dyn/Readme.md +++ b/module/core/clone_dyn/Readme.md @@ -85,7 +85,7 @@ The main function demonstrates the overall usage by creating a vector, obtaining 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 + // There’s no need to explicitly define this bound because the macro will handle it for you. { } @@ -141,6 +141,7 @@ The main function demonstrates the overall usage by creating a vector, obtaining // Nevertheless, thanks to CloneDyn, the object is clonable. // // This line demonstrates cloning the iterator and iterating over the cloned iterator. + // Without `CloneDyn`, you would need to collect the iterator into a container, allocating memory on the heap. iter.clone().for_each( | e | println!( "{e}" ) ); // Iterate over the original iterator and print each element. diff --git a/module/core/clone_dyn/examples/clone_dyn_trivial.rs b/module/core/clone_dyn/examples/clone_dyn_trivial.rs index e14bbc9a8a..f62d7bccfc 100644 --- a/module/core/clone_dyn/examples/clone_dyn_trivial.rs +++ b/module/core/clone_dyn/examples/clone_dyn_trivial.rs @@ -70,7 +70,7 @@ fn main() 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 + // There’s no need to explicitly define this bound because the macro will handle it for you. { } @@ -126,6 +126,7 @@ fn main() // Nevertheless, thanks to CloneDyn, the object is clonable. // // This line demonstrates cloning the iterator and iterating over the cloned iterator. + // Without `CloneDyn`, you would need to collect the iterator into a container, allocating memory on the heap. iter.clone().for_each( | e | println!( "{e}" ) ); // Iterate over the original iterator and print each element. diff --git a/module/core/clone_dyn/tests/inc/mod.rs b/module/core/clone_dyn/tests/inc/mod.rs index 8b790f55cf..8a1bb73c62 100644 --- a/module/core/clone_dyn/tests/inc/mod.rs +++ b/module/core/clone_dyn/tests/inc/mod.rs @@ -5,4 +5,3 @@ use super::*; mod basic_manual; mod basic; mod parametrized; - diff --git a/module/core/clone_dyn_types/Readme.md b/module/core/clone_dyn_types/Readme.md index 8485e1c9db..12cc1e5f46 100644 --- a/module/core/clone_dyn_types/Readme.md +++ b/module/core/clone_dyn_types/Readme.md @@ -151,6 +151,7 @@ fn main() // Nevertheless, thanks to CloneDyn, the object is clonable. // // This line demonstrates cloning the iterator and iterating over the cloned iterator. + // Without `CloneDyn`, you would need to collect the iterator into a container, allocating memory on the heap. iter.clone().for_each( | e | println!( "{e}" ) ); // Iterate over the original iterator and print each element. 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 dce84eb919..055864e8e5 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 @@ -134,6 +134,7 @@ fn main() // Nevertheless, thanks to CloneDyn, the object is clonable. // // This line demonstrates cloning the iterator and iterating over the cloned iterator. + // Without `CloneDyn`, you would need to collect the iterator into a container, allocating memory on the heap. iter.clone().for_each( | e | println!( "{e}" ) ); // Iterate over the original iterator and print each element. diff --git a/module/core/clone_dyn_types/src/lib.rs b/module/core/clone_dyn_types/src/lib.rs index 3ace741087..a6c60f2824 100644 --- a/module/core/clone_dyn_types/src/lib.rs +++ b/module/core/clone_dyn_types/src/lib.rs @@ -248,7 +248,6 @@ pub mod prelude { #[ doc( inline ) ] #[ allow( unused_imports ) ] - #[ cfg( any( not( feature = "no_std" ), feature = "use_alloc" ) ) ] pub use super::private:: { CloneDyn, diff --git a/module/core/derive_tools/Cargo.toml b/module/core/derive_tools/Cargo.toml index 2dc4b4afb6..6c7b624b38 100644 --- a/module/core/derive_tools/Cargo.toml +++ b/module/core/derive_tools/Cargo.toml @@ -192,7 +192,7 @@ parse-display = { version = "~0.8.2", optional = true, default-features = false ## internal derive_tools_meta = { workspace = true, features = [] } variadic_from = { workspace = true, features = [] } -clone_dyn = { workspace = true, features = [] } +clone_dyn = { workspace = true, features = [ "clone_dyn_types", "clone_dyn_meta" ] } [dev-dependencies] diff --git a/module/core/derive_tools/src/lib.rs b/module/core/derive_tools/src/lib.rs index 5bf65c972a..8cec034b59 100644 --- a/module/core/derive_tools/src/lib.rs +++ b/module/core/derive_tools/src/lib.rs @@ -252,6 +252,11 @@ pub mod exposed #[ allow( unused_imports ) ] pub use ::clone_dyn::exposed::*; + #[ cfg( feature = "derive_clone_dyn" ) ] + #[ doc( inline ) ] + #[ allow( unused_imports ) ] + pub use ::clone_dyn; + // #[ doc( inline ) ] // #[ allow( unused_imports ) ] // pub use super::wtools::exposed::*; diff --git a/module/core/derive_tools/tests/inc/mod.rs b/module/core/derive_tools/tests/inc/mod.rs index 8dc439c8d8..3a192d777a 100644 --- a/module/core/derive_tools/tests/inc/mod.rs +++ b/module/core/derive_tools/tests/inc/mod.rs @@ -3,8 +3,14 @@ use super::*; // = import tests of clone_dyn #[ cfg( feature = "derive_clone_dyn" ) ] -#[ path = "../../../../core/clone_dyn/tests/inc/mod.rs" ] -mod clone_dyn_test; +mod clone_dyn_test +{ + use super::*; + + #[ path = "../../../../../core/clone_dyn/tests/inc/mod.rs" ] + mod clone_dyn_test; + +} // = import tests of variadic_from 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 c0a19cf001..c3988146df 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,7 +1,7 @@ use super::*; #[ derive( Debug, PartialEq, Eq, the_module::New ) ] -#[ debug ] +// #[ debug ] struct StructNamedFields { a : i32, diff --git a/module/core/derive_tools_meta/src/derive/from.rs b/module/core/derive_tools_meta/src/derive/from.rs index d9168768a9..1e503d8480 100644 --- a/module/core/derive_tools_meta/src/derive/from.rs +++ b/module/core/derive_tools_meta/src/derive/from.rs @@ -541,4 +541,4 @@ field : {variant_name}"#, } ) -} \ No newline at end of file +} diff --git a/module/core/format_tools/src/format/wrapper/aref.rs b/module/core/format_tools/src/format/wrapper/aref.rs index 7e6afeb049..0be38207e0 100644 --- a/module/core/format_tools/src/format/wrapper/aref.rs +++ b/module/core/format_tools/src/format/wrapper/aref.rs @@ -2,6 +2,8 @@ //! It's often necessary to wrap something inot a local structure and this file contains a resusable local structure for wrapping. //! +// xxx : make command to autogenerate it, maybe + // use core::fmt; use core::ops::{ Deref }; diff --git a/module/core/macro_tools/examples/macro_tools_attr_prop.rs b/module/core/macro_tools/examples/macro_tools_attr_prop.rs index 4625e15154..8a5f62d22c 100644 --- a/module/core/macro_tools/examples/macro_tools_attr_prop.rs +++ b/module/core/macro_tools/examples/macro_tools_attr_prop.rs @@ -34,7 +34,6 @@ fn main() use macro_tools:: { - attr, syn_err, return_syn_err, qt, diff --git a/module/core/macro_tools/src/generic_params.rs b/module/core/macro_tools/src/generic_params.rs index 09f4445e5b..3729237876 100644 --- a/module/core/macro_tools/src/generic_params.rs +++ b/module/core/macro_tools/src/generic_params.rs @@ -281,7 +281,13 @@ 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 IterTrait< 'a, &'a syn::Ident > + // -> std::iter::Map + // < + // syn::punctuated::Iter< 'a, syn::GenericParam >, + // impl FnMut( &'a syn::GenericParam ) -> &'a syn::Ident + 'a, + // > { 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 d98dcfcfd8..f5a33a21c2 100644 --- a/module/core/macro_tools/src/item_struct.rs +++ b/module/core/macro_tools/src/item_struct.rs @@ -8,25 +8,26 @@ 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 IterTrait< 'a, &'a syn::Type > + // -> std::iter::Map + // < + // syn::punctuated::Iter< 'a, syn::Field >, + // impl FnMut( &'a syn::Field ) -> &'a syn::Type + 'a, + // > { 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 IterTrait< 'a, &'a syn::Ident > > pub fn field_names< 'a >( t : &'a syn::ItemStruct ) -> Option< BoxedIter< 'a, &'a syn::Ident > > - // xxx { - let result : Option< BoxedIter< 'a, &'a syn::Ident > > = match &t.fields + 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() ) ), _ => 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 13bb883dfb..f3553f773b 100644 --- a/module/core/macro_tools/src/iter.rs +++ b/module/core/macro_tools/src/iter.rs @@ -19,7 +19,7 @@ pub( crate ) mod private /// /// # Example /// ```rust - /// use assistant::_IterTrait; + /// use macro_tools::_IterTrait; /// /// // Example struct that implements Iterator, ExactSizeIterator, DoubleEndedIterator, and CloneDyn. /// #[ derive( Clone ) ] @@ -57,7 +57,6 @@ pub( crate ) mod private /// } /// } /// - /// impl _IterTrait< '_, i32 > for MyIterator {} /// ``` pub trait _IterTrait< 'a, T > where @@ -122,19 +121,6 @@ pub( crate ) mod private /// /// 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. @@ -160,128 +146,6 @@ pub( crate ) mod private { } -// 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 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() -// } -// } - - // = - -// trait Cloneable : Clone -// { -// fn clone_box( & self ) -> Box< dyn Cloneable >; -// } -// -// impl< T > Cloneable for T -// where -// 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() -// } - } #[ doc( inline ) ] @@ -323,10 +187,6 @@ pub mod exposed _IterTrait, IterTrait, BoxedIter, - // 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 4658265551..5a58f5df7d 100644 --- a/module/core/macro_tools/src/struct_like.rs +++ b/module/core/macro_tools/src/struct_like.rs @@ -250,25 +250,27 @@ pub( crate ) mod private impl StructLike { + /// 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 IterTrait< 'a, FieldOrVariant< 'a > > + 'a + pub fn elements< 'a >( &'a self ) -> BoxedIter< 'a, FieldOrVariant< 'a > > { match self { StructLike::Unit( _ ) => { let empty : Vec< FieldOrVariant< 'a > > = vec![]; - Box::new( empty.into_iter() ) as BoxedIter< 'a, FieldOrVariant< 'a > > + Box::new( empty.into_iter() ) }, StructLike::Struct( item ) => { let fields = item.fields.iter().map( FieldOrVariant::from ); - Box::new( fields ) as BoxedIter< 'a, FieldOrVariant< 'a > > + Box::new( fields ) }, StructLike::Enum( item ) => { let variants = item.variants.iter().map( FieldOrVariant::from ); - Box::new( variants ) as BoxedIter< 'a, FieldOrVariant< 'a > > + Box::new( variants ) }, } } @@ -354,9 +356,8 @@ pub( crate ) mod private } /// Returns an iterator over fields of the item. - // pub fn fields< 'a >( &'a self ) -> BoxedIter< 'a, &'a syn::Field > - pub fn fields< 'a >( &'a self ) -> impl IterTrait< 'a, &'a syn::Field > - // xxx + // pub fn fields< 'a >( &'a self ) -> impl IterTrait< 'a, &'a syn::Field > + pub fn fields< 'a >( &'a self ) -> BoxedIter< 'a, &'a syn::Field > { let result : BoxedIter< 'a, &'a syn::Field > = match self { @@ -377,8 +378,8 @@ pub( crate ) mod private } /// 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 IterTrait< 'a, &'a syn::Ident > + '_ > + pub fn field_names< 'a >( &'a self ) -> Option< BoxedIter< 'a, &'a syn::Ident >> { match self { @@ -392,33 +393,35 @@ 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() ) ); + let iter = 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() ) }, } - // Box::new( self.fields().map( | field | field.ident.as_ref() ) ) } /// Extracts the type of each field. - 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 > + pub fn field_types<'a>( &'a self ) + -> BoxedIter< 'a, &'a syn::Type > + // -> std::iter::Map + // < + // std::boxed::Box< dyn _IterTrait< '_, &syn::Field > + 'a >, + // impl FnMut( &'a syn::Field ) -> &'a syn::Type + 'a, + // > { - // Box::new( self.fields().map( | field | &field.ty ) ) - self.fields().map( | field | &field.ty ) + Box::new( self.fields().map( move | 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 ) -> impl IterTrait< 'a, &'a Vec< syn::Attribute > > - // pub fn field_attrs< 'a >( &'a self ) -> BoxedIter< '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 > > + // -> std::iter::Map + // < + // std::boxed::Box< dyn _IterTrait< '_, &syn::Field > + 'a >, + // impl FnMut( &'a syn::Field ) -> &'a Vec< syn::Attribute > + 'a, + // > { - self.fields().map( | field | &field.attrs ) - // Box::new( self.fields().map( | field | &field.attrs ) ) - // xxx + Box::new( self.fields().map( | field | &field.attrs ) ) } /// Extract the first field. diff --git a/module/core/reflect_tools/src/reflect/wrapper/aref.rs b/module/core/reflect_tools/src/reflect/wrapper/aref.rs index 7e6afeb049..0be38207e0 100644 --- a/module/core/reflect_tools/src/reflect/wrapper/aref.rs +++ b/module/core/reflect_tools/src/reflect/wrapper/aref.rs @@ -2,6 +2,8 @@ //! It's often necessary to wrap something inot a local structure and this file contains a resusable local structure for wrapping. //! +// xxx : make command to autogenerate it, maybe + // use core::fmt; use core::ops::{ Deref };