Skip to content

Commit

Permalink
AUTO : Forward from derives_refactoring_2 to alpha (#1378)
Browse files Browse the repository at this point in the history
macro_tools: fix problem with lack of clonability
  • Loading branch information
wtools-bot authored Jun 10, 2024
1 parent de369ae commit 6a1ee3c
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 185 deletions.
3 changes: 2 additions & 1 deletion module/core/clone_dyn/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
{
}

Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion module/core/clone_dyn/examples/clone_dyn_trivial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
{
}

Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion module/core/clone_dyn/tests/inc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ use super::*;
mod basic_manual;
mod basic;
mod parametrized;

1 change: 1 addition & 0 deletions module/core/clone_dyn_types/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion module/core/clone_dyn_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion module/core/derive_tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions module/core/derive_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
10 changes: 8 additions & 2 deletions module/core/derive_tools/tests/inc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

#[ derive( Debug, PartialEq, Eq, the_module::New ) ]
#[ debug ]
// #[ debug ]
struct StructNamedFields
{
a : i32,
Expand Down
2 changes: 1 addition & 1 deletion module/core/derive_tools_meta/src/derive/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,4 +541,4 @@ field : {variant_name}"#,
}
)

}
}
2 changes: 2 additions & 0 deletions module/core/format_tools/src/format/wrapper/aref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down
1 change: 0 additions & 1 deletion module/core/macro_tools/examples/macro_tools_attr_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ fn main()

use macro_tools::
{
attr,
syn_err,
return_syn_err,
qt,
Expand Down
8 changes: 7 additions & 1 deletion module/core/macro_tools/src/generic_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
17 changes: 9 additions & 8 deletions module/core/macro_tools/src/item_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
142 changes: 1 addition & 141 deletions module/core/macro_tools/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ]
Expand Down Expand Up @@ -57,7 +57,6 @@ pub( crate ) mod private
/// }
/// }
///
/// impl _IterTrait< '_, i32 > for MyIterator {}
/// ```
pub trait _IterTrait< 'a, T >
where
Expand Down Expand Up @@ -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.
Expand All @@ -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 ) ]
Expand Down Expand Up @@ -323,10 +187,6 @@ pub mod exposed
_IterTrait,
IterTrait,
BoxedIter,
// DynIter,
// DynIterFrom,
// IterTrait2,
// IterTrait3,
};
}

Expand Down
Loading

0 comments on commit 6a1ee3c

Please sign in to comment.