From 51daee2cbee40d8283ac4c23499ce5098594e613 Mon Sep 17 00:00:00 2001 From: wandalen Date: Tue, 14 May 2024 16:54:38 +0300 Subject: [PATCH] derive_tools : rid off alias FromInner --- .../core/derive_tools/tests/inc/all_test.rs | 2 +- .../inc/from_inner_multiple_named_test.rs | 2 +- .../tests/inc/from_inner_multiple_test.rs | 2 +- .../tests/inc/from_inner_named_test.rs | 2 +- .../derive_tools/tests/inc/from_inner_test.rs | 2 +- .../tests/inc/from_inner_unit_test.rs | 2 +- .../derive_tools/tests/inc/only_test/all.rs | 2 +- module/core/derive_tools_meta/src/lib.rs | 92 +++++++++---------- .../reflect_tools/tests/inc/only_test/all.rs | 2 +- .../src/hybrid_optimizer/sim_anneal.rs | 10 +- .../src/problems/sudoku/sudoku.rs | 38 ++++---- .../src/problems/traveling_salesman.rs | 4 +- 12 files changed, 80 insertions(+), 80 deletions(-) diff --git a/module/core/derive_tools/tests/inc/all_test.rs b/module/core/derive_tools/tests/inc/all_test.rs index a72ffa1741..8ca0db403f 100644 --- a/module/core/derive_tools/tests/inc/all_test.rs +++ b/module/core/derive_tools/tests/inc/all_test.rs @@ -1,6 +1,6 @@ use super::*; -#[ derive( Debug, Clone, Copy, PartialEq, /* the_module::Default,*/ the_module::FromInner, the_module::InnerFrom, the_module::Deref, the_module::DerefMut, the_module::AsRef, the_module::AsMut ) ] +#[ derive( Debug, Clone, Copy, PartialEq, /* the_module::Default,*/ the_module::From, the_module::InnerFrom, the_module::Deref, the_module::DerefMut, the_module::AsRef, the_module::AsMut ) ] // #[ default( value = false ) ] pub struct IsTransparent( bool ); diff --git a/module/core/derive_tools/tests/inc/from_inner_multiple_named_test.rs b/module/core/derive_tools/tests/inc/from_inner_multiple_named_test.rs index 436683a3b5..f12692c40a 100644 --- a/module/core/derive_tools/tests/inc/from_inner_multiple_named_test.rs +++ b/module/core/derive_tools/tests/inc/from_inner_multiple_named_test.rs @@ -1,6 +1,6 @@ use super::*; -#[ derive( Debug, PartialEq, Eq, the_module::FromInner ) ] +#[ derive( Debug, PartialEq, Eq, the_module::From ) ] struct StructNamedFields { a: i32, diff --git a/module/core/derive_tools/tests/inc/from_inner_multiple_test.rs b/module/core/derive_tools/tests/inc/from_inner_multiple_test.rs index dd18c948c9..db54cef54b 100644 --- a/module/core/derive_tools/tests/inc/from_inner_multiple_test.rs +++ b/module/core/derive_tools/tests/inc/from_inner_multiple_test.rs @@ -1,6 +1,6 @@ use super::*; -#[ derive( Debug, PartialEq, Eq, the_module::FromInner ) ] +#[ derive( Debug, PartialEq, Eq, the_module::From ) ] struct StructWithManyFields( i32, bool ); include!( "./only_test/from_inner_multiple.rs" ); diff --git a/module/core/derive_tools/tests/inc/from_inner_named_test.rs b/module/core/derive_tools/tests/inc/from_inner_named_test.rs index 0ea85ef088..c6a0f032d9 100644 --- a/module/core/derive_tools/tests/inc/from_inner_named_test.rs +++ b/module/core/derive_tools/tests/inc/from_inner_named_test.rs @@ -1,6 +1,6 @@ use super::*; -#[ derive( Debug, PartialEq, Eq, the_module::FromInner ) ] +#[ derive( Debug, PartialEq, Eq, the_module::From ) ] struct MyStruct { a: i32, diff --git a/module/core/derive_tools/tests/inc/from_inner_test.rs b/module/core/derive_tools/tests/inc/from_inner_test.rs index 4848773fde..98890e6c2e 100644 --- a/module/core/derive_tools/tests/inc/from_inner_test.rs +++ b/module/core/derive_tools/tests/inc/from_inner_test.rs @@ -3,7 +3,7 @@ use super::*; // use diagnostics_tools::prelude::*; // use derives::*; -#[ derive( Debug, Clone, Copy, PartialEq, the_module::FromInner ) ] +#[ derive( Debug, Clone, Copy, PartialEq, the_module::From ) ] pub struct IsTransparent( bool ); // include!( "./manual/basic.rs" ); diff --git a/module/core/derive_tools/tests/inc/from_inner_unit_test.rs b/module/core/derive_tools/tests/inc/from_inner_unit_test.rs index 2aa637a05b..e551263159 100644 --- a/module/core/derive_tools/tests/inc/from_inner_unit_test.rs +++ b/module/core/derive_tools/tests/inc/from_inner_unit_test.rs @@ -1,6 +1,6 @@ use super::*; -#[ derive( Debug, Clone, Copy, PartialEq, the_module::FromInner ) ] +#[ derive( Debug, Clone, Copy, PartialEq, the_module::From ) ] struct UnitStruct; include!( "./only_test/from_inner_unit.rs" ); diff --git a/module/core/derive_tools/tests/inc/only_test/all.rs b/module/core/derive_tools/tests/inc/only_test/all.rs index 9708a9f8cf..5fe5831993 100644 --- a/module/core/derive_tools/tests/inc/only_test/all.rs +++ b/module/core/derive_tools/tests/inc/only_test/all.rs @@ -7,7 +7,7 @@ fn basic_test() let exp = IsTransparent( true ); a_id!( got, exp ); - // FromInner + // From let got = IsTransparent::from( true ); let exp = IsTransparent( true ); diff --git a/module/core/derive_tools_meta/src/lib.rs b/module/core/derive_tools_meta/src/lib.rs index 97cb37042f..338eb397f6 100644 --- a/module/core/derive_tools_meta/src/lib.rs +++ b/module/core/derive_tools_meta/src/lib.rs @@ -83,52 +83,52 @@ pub fn from( input : proc_macro::TokenStream ) -> proc_macro::TokenStream } } -/// -/// Alias for derive `From`. Provides an automatic `From` implementation for struct wrapping a single value. -/// -/// This macro simplifies the conversion of an inner type to an outer struct type -/// when the outer type is a simple wrapper around the inner type. -/// -/// ## Example Usage -/// -/// Instead of manually implementing `From< bool >` for `IsTransparent`: -/// -/// ```rust -/// pub struct IsTransparent( bool ); -/// -/// impl From< bool > for IsTransparent -/// { -/// #[ inline( always ) ] -/// fn from( src : bool ) -> Self -/// { -/// Self( src ) -/// } -/// } -/// ``` -/// -/// Use `#[ derive( FromInner ) ]` to automatically generate the implementation: -/// -/// ```rust -/// # use derive_tools_meta::*; -/// #[ derive( FromInner ) ] -/// pub struct IsTransparent( bool ); -/// ``` -/// -/// The macro facilitates the conversion without additional boilerplate code. -/// - -#[ cfg( feature = "enabled" ) ] -#[ cfg( feature = "derive_from" ) ] -#[ proc_macro_derive( FromInner ) ] -pub fn from_inner( input : proc_macro::TokenStream ) -> proc_macro::TokenStream -{ - let result = derive::from::from( input ); - match result - { - Ok( stream ) => stream.into(), - Err( err ) => err.to_compile_error().into(), - } -} +// /// +// /// Alias for derive `From`. Provides an automatic `From` implementation for struct wrapping a single value. +// /// +// /// This macro simplifies the conversion of an inner type to an outer struct type +// /// when the outer type is a simple wrapper around the inner type. +// /// +// /// ## Example Usage +// /// +// /// Instead of manually implementing `From< bool >` for `IsTransparent`: +// /// +// /// ```rust +// /// pub struct IsTransparent( bool ); +// /// +// /// impl From< bool > for IsTransparent +// /// { +// /// #[ inline( always ) ] +// /// fn from( src : bool ) -> Self +// /// { +// /// Self( src ) +// /// } +// /// } +// /// ``` +// /// +// /// Use `#[ derive( FromInner ) ]` to automatically generate the implementation: +// /// +// /// ```rust +// /// # use derive_tools_meta::*; +// /// #[ derive( FromInner ) ] +// /// pub struct IsTransparent( bool ); +// /// ``` +// /// +// /// The macro facilitates the conversion without additional boilerplate code. +// /// +// +// #[ cfg( feature = "enabled" ) ] +// #[ cfg( feature = "derive_from" ) ] +// #[ proc_macro_derive( FromInner ) ] +// pub fn from_inner( input : proc_macro::TokenStream ) -> proc_macro::TokenStream +// { +// let result = derive::from::from( input ); +// match result +// { +// Ok( stream ) => stream.into(), +// Err( err ) => err.to_compile_error().into(), +// } +// } /// /// Derive macro to implement From converting outer type into inner when-ever it's possible to do automatically. diff --git a/module/core/reflect_tools/tests/inc/only_test/all.rs b/module/core/reflect_tools/tests/inc/only_test/all.rs index 9708a9f8cf..5fe5831993 100644 --- a/module/core/reflect_tools/tests/inc/only_test/all.rs +++ b/module/core/reflect_tools/tests/inc/only_test/all.rs @@ -7,7 +7,7 @@ fn basic_test() let exp = IsTransparent( true ); a_id!( got, exp ); - // FromInner + // From let got = IsTransparent::from( true ); let exp = IsTransparent( true ); diff --git a/module/move/optimization_tools/src/hybrid_optimizer/sim_anneal.rs b/module/move/optimization_tools/src/hybrid_optimizer/sim_anneal.rs index c176729441..f7d4c5743a 100644 --- a/module/move/optimization_tools/src/hybrid_optimizer/sim_anneal.rs +++ b/module/move/optimization_tools/src/hybrid_optimizer/sim_anneal.rs @@ -1,8 +1,8 @@ //! Implementation of Simulated Annealing for Hybrid Optimizer. -use derive_tools::{ FromInner, InnerFrom, exposed::Display }; +use derive_tools::{ From, InnerFrom, exposed::Display }; /// Represents temperature of SA process. -#[ derive( Default, Debug, Display, Clone, Copy, PartialEq, PartialOrd, FromInner, InnerFrom ) ] +#[ derive( Default, Debug, Display, Clone, Copy, PartialEq, PartialOrd, From, InnerFrom ) ] pub struct Temperature( f64 ); impl Temperature @@ -27,7 +27,7 @@ impl From< f32 > for Temperature // use derive_tools::{ Add, Sub, Mul, Div, AddAssign, SubAssign, MulAssign, DivAssign }; /// Struct that represents coefficient to change temperature value. -#[ derive( Debug, Display, Clone, Copy, PartialEq, PartialOrd, FromInner, InnerFrom ) ] +#[ derive( Debug, Display, Clone, Copy, PartialEq, PartialOrd, From, InnerFrom ) ] // #[ derive( Add, Sub, Mul, Div, AddAssign, SubAssign, MulAssign, DivAssign ) ] pub struct TemperatureFactor( pub f64 ); @@ -83,12 +83,12 @@ pub struct LinearTempSchedule impl TemperatureSchedule for LinearTempSchedule { - fn calculate_next_temp( &self, prev_temp : Temperature ) -> Temperature + fn calculate_next_temp( &self, prev_temp : Temperature ) -> Temperature { Temperature::from( prev_temp.unwrap() * self.coefficient.unwrap() + self.constant.unwrap() ) } - fn reset_temperature( &self, prev_temp : Temperature ) -> Temperature + fn reset_temperature( &self, prev_temp : Temperature ) -> Temperature { Temperature( prev_temp.unwrap() + self.reset_increase_value.unwrap() ) } diff --git a/module/move/optimization_tools/src/problems/sudoku/sudoku.rs b/module/move/optimization_tools/src/problems/sudoku/sudoku.rs index b016fa4cda..eac6a5dbda 100644 --- a/module/move/optimization_tools/src/problems/sudoku/sudoku.rs +++ b/module/move/optimization_tools/src/problems/sudoku/sudoku.rs @@ -4,7 +4,7 @@ use std::collections::HashSet; use crate::hybrid_optimizer::*; use crate::problems::sudoku::*; -use derive_tools::{ FromInner, InnerFrom, exposed::Display }; +use derive_tools::{ From, InnerFrom, exposed::Display }; use deterministic_rand::{ Hrng, Rng, seq::SliceRandom }; use iter_tools::Itertools; @@ -72,7 +72,7 @@ pub fn cells_pair_random_in_block( initial : &Board, block : BlockIndex, hrng : } /// Represents number of errors in sudoku board. -#[ derive( Default, Debug, Display, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash, FromInner, InnerFrom ) ] +#[ derive( Default, Debug, Display, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash, From, InnerFrom ) ] pub struct SudokuCost( usize ); // xxx : derive, please @@ -113,13 +113,13 @@ impl Individual for SudokuPerson { true } - else + else { false } } - fn fitness( &self ) -> usize + fn fitness( &self ) -> usize { self.cost.into() } @@ -153,7 +153,7 @@ impl SudokuPerson { let old_cross_error = self.board.cross_error( mutagen.cell1 ) + self.board.cross_error( mutagen.cell2 ); - + log::trace!( "cells_swap( {:?}, {:?} )", mutagen.cell1, mutagen.cell2 ); self.board.cells_swap( mutagen.cell1, mutagen.cell2 ); self.cost = SudokuCost( self.cost.unwrap() - old_cross_error ) ; @@ -174,8 +174,8 @@ impl SudokuPerson pub fn mutagen( &self, initial : &Board, hrng : Hrng ) -> SudokuMutagen { let mutagen; - loop - { + loop + { let rng_ref = hrng.rng_ref(); let mut rng = rng_ref.lock().unwrap(); let block : BlockIndex = rng.gen(); @@ -191,7 +191,7 @@ impl SudokuPerson } /// Represents single change(mutation) which contains indeces of two swapped cells. It is used to generate new state of the board for sudoku solving process. -#[ derive( PartialEq, Eq, Clone, Debug, FromInner, InnerFrom ) ] +#[ derive( PartialEq, Eq, Clone, Debug, From, InnerFrom ) ] pub struct SudokuMutagen { /// Index of cell swapped in mutation. @@ -221,12 +221,12 @@ impl InitialProblem for SudokuInitial { type Person = SudokuPerson; - fn get_random_person( &self, hrng : Hrng ) -> SudokuPerson + fn get_random_person( &self, hrng : Hrng ) -> SudokuPerson { SudokuPerson::new( &self.board, hrng.clone() ) } - fn evaluate( &self, person : &SudokuPerson ) -> f64 + fn evaluate( &self, person : &SudokuPerson ) -> f64 { person.board.total_error() as f64 } @@ -241,11 +241,11 @@ impl MutationOperator for RandomPairInBlockMutation type Person = SudokuPerson; type Problem = SudokuInitial; - fn mutate( &self, hrng : Hrng, person : &mut Self::Person, context : &Self::Problem ) + fn mutate( &self, hrng : Hrng, person : &mut Self::Person, context : &Self::Problem ) { let mutagen : SudokuMutagen = - loop - { + loop + { let rng_ref = hrng.rng_ref(); let mut rng = rng_ref.lock().unwrap(); let block : BlockIndex = rng.gen(); @@ -257,7 +257,7 @@ impl MutationOperator for RandomPairInBlockMutation }.into(); let old_cross_error = person.board.cross_error( mutagen.cell1 ) + person.board.cross_error( mutagen.cell2 ); - + log::trace!( "cells_swap( {:?}, {:?} )", mutagen.cell1, mutagen.cell2 ); person.board.cells_swap( mutagen.cell1, mutagen.cell2 ); person.cost = SudokuCost( person.cost.unwrap() - old_cross_error ); @@ -301,7 +301,7 @@ impl CrossoverOperator for MultiplePointsBlockCrossover child_storage[ usize::from( cell_index ) ] = parent_block[ index ]; } } - else + else { let parent_block = parent2.board.block( i ).collect_vec(); let cells = parent2.board.block_cells( i ); @@ -311,7 +311,7 @@ impl CrossoverOperator for MultiplePointsBlockCrossover } } } - + let child = SudokuPerson::with_board( Board::new( child_storage ) ); child } @@ -324,7 +324,7 @@ pub struct BestRowsColumnsCrossover; impl CrossoverOperator for BestRowsColumnsCrossover { type Person = < SudokuInitial as InitialProblem >::Person; - + fn crossover( &self, _hrng : Hrng, parent1 : &Self::Person, parent2 : &Self::Person ) -> Self::Person { let mut rows_costs = vec![ Vec::new(); 2 ]; @@ -393,7 +393,7 @@ impl CrossoverOperator for BestRowsColumnsCrossover child2_storage[ usize::from( cell_index ) ] = parent_block[ index ]; } } - else + else { let parent_block = parent2.board.block( BlockIndex::from( ( j as u8, i as u8 ) ) ).collect_vec(); let cells = parent2.board.block_cells( BlockIndex::from( ( j as u8, i as u8 ) ) ); @@ -411,6 +411,6 @@ impl CrossoverOperator for BestRowsColumnsCrossover .unwrap() ; - SudokuPerson::with_board( min_board ) + SudokuPerson::with_board( min_board ) } } diff --git a/module/move/optimization_tools/src/problems/traveling_salesman.rs b/module/move/optimization_tools/src/problems/traveling_salesman.rs index 2c3e5bb9a1..2eab112158 100644 --- a/module/move/optimization_tools/src/problems/traveling_salesman.rs +++ b/module/move/optimization_tools/src/problems/traveling_salesman.rs @@ -17,7 +17,7 @@ use std::collections::HashMap; use crate::hybrid_optimizer::*; -use derive_tools::{ FromInner, InnerFrom }; +use derive_tools::{ From, InnerFrom }; use deterministic_rand::{ Hrng, seq::{ SliceRandom, IteratorRandom } }; use iter_tools::Itertools; @@ -89,7 +89,7 @@ pub struct Node< T > pub struct NodeIndex( pub usize ); /// Weight of graph edge. -#[ derive( Debug, FromInner, InnerFrom, Clone, Copy ) ] +#[ derive( Debug, From, InnerFrom, Clone, Copy ) ] pub struct EdgeWeight( pub f64 ); /// Edge for undirected weighted graph.