Skip to content

Commit

Permalink
derive_tools : rid off alias FromInner
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed May 14, 2024
1 parent 9806451 commit 51daee2
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 80 deletions.
2 changes: 1 addition & 1 deletion module/core/derive_tools/tests/inc/all_test.rs
Original file line number Diff line number Diff line change
@@ -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 );

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

#[ derive( Debug, PartialEq, Eq, the_module::FromInner ) ]
#[ derive( Debug, PartialEq, Eq, the_module::From ) ]
struct StructNamedFields
{
a: i32,
Expand Down
Original file line number Diff line number Diff line change
@@ -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" );
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

#[ derive( Debug, PartialEq, Eq, the_module::FromInner ) ]
#[ derive( Debug, PartialEq, Eq, the_module::From ) ]
struct MyStruct
{
a: i32,
Expand Down
2 changes: 1 addition & 1 deletion module/core/derive_tools/tests/inc/from_inner_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
2 changes: 1 addition & 1 deletion module/core/derive_tools/tests/inc/from_inner_unit_test.rs
Original file line number Diff line number Diff line change
@@ -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" );
2 changes: 1 addition & 1 deletion module/core/derive_tools/tests/inc/only_test/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
92 changes: 46 additions & 46 deletions module/core/derive_tools_meta/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion module/core/reflect_tools/tests/inc/only_test/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 );

Expand Down Expand Up @@ -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() )
}
Expand Down
38 changes: 19 additions & 19 deletions module/move/optimization_tools/src/problems/sudoku/sudoku.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -113,13 +113,13 @@ impl Individual for SudokuPerson
{
true
}
else
else
{
false
}
}

fn fitness( &self ) -> usize
fn fitness( &self ) -> usize
{
self.cost.into()
}
Expand Down Expand Up @@ -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 ) ;
Expand All @@ -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();
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
Expand All @@ -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();
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -311,7 +311,7 @@ impl CrossoverOperator for MultiplePointsBlockCrossover
}
}
}

let child = SudokuPerson::with_board( Board::new( child_storage ) );
child
}
Expand All @@ -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 ];
Expand Down Expand Up @@ -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 ) ) );
Expand All @@ -411,6 +411,6 @@ impl CrossoverOperator for BestRowsColumnsCrossover
.unwrap()
;

SudokuPerson::with_board( min_board )
SudokuPerson::with_board( min_board )
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 51daee2

Please sign in to comment.