Skip to content

Commit

Permalink
Merge pull request #1337 from Wandalen/program_tools_v1
Browse files Browse the repository at this point in the history
AUTO : Forward from program_tools_v1 to alpha
  • Loading branch information
Wandalen committed May 14, 2024
2 parents 42716ac + 33ce102 commit c39b70c
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 108 deletions.
2 changes: 1 addition & 1 deletion module/core/derive_tools/examples/derive_tools_trivial.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! qqq : write proper description
//! qqq : for Petro : write proper description

fn main()
{
Expand Down
2 changes: 1 addition & 1 deletion module/core/derive_tools/src/wtools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Types, which are extension of std.
//!

// qqq : xxx : rid off the file
// qqq : for Petro : xxx : rid off the file

/// Internal namespace.
pub( crate ) mod private
Expand Down
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
2 changes: 1 addition & 1 deletion module/core/derive_tools/tests/inc/basic_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tests_impls!
{
use the_module::*;

// xxx : qqq : make it working
// xxx : qqq : for Petro : make it working
#[ derive( From, InnerFrom, Display, FromStr, PartialEq, Debug ) ]
#[ display( "{a}-{b}" ) ]
struct Struct1
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" );
27 changes: 27 additions & 0 deletions module/core/derive_tools/tests/inc/from_inner_variants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#[ derive( Debug, PartialEq ) ]
pub enum GetData
{
FromString( String ),
FromBin( &'static [ u8 ] ),
}

impl From< String > for GetData
{
#[ inline ]
fn from( src : String ) -> Self
{
Self::FromString( src )
}
}

impl From< &'static [ u8 ] > for GetData
{
#[ inline ]
fn from( src : &'static [ u8 ] ) -> Self
{
Self::FromBin( src )
}
}

include!( "./only_test/from_inner_variants.rs" );
4 changes: 3 additions & 1 deletion module/core/derive_tools/tests/inc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ mod from_inner_multiple_named_test;
mod from_inner_unit_test;
#[ cfg( feature = "derive_from" ) ]
mod from_inner_multiple_test;
#[ cfg( feature = "derive_from" ) ]
mod from_inner_variants;

mod inner_from_manual_test;
mod inner_from_named_manual_test;
Expand All @@ -68,7 +70,7 @@ mod inner_from_unit_test;
#[ cfg( feature = "derive_inner_from" ) ]
mod inner_from_multiple_test;

// qqq : xxx : fix
// qqq : for Petro : xxx : fix
// #[ cfg( all( feature = "type_variadic_from" ) ) ]
// mod variadic_from_manual_test;
//
Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use super::*;

#[ test ]
fn from_inner_named()
{

let got : GetData = From::from( "abc".to_string() );
let exp = GetData::FromString( "abc".to_string() );
a_id!( got, exp );

let got : GetData = From::from( &b"abc"[ .. ] );
let exp = GetData::FromBin( b"abc" );
a_id!( got, exp );

}
2 changes: 1 addition & 1 deletion module/core/derive_tools_meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ derive_variadic_from = []
[dependencies]
macro_tools = { workspace = true, features = [ "full" ] }
iter_tools = { workspace = true, features = [ "full" ] }
# xxx : qqq : optimize features set
# xxx : qqq : for Petro : optimize features set

[dev-dependencies]
test_tools = { workspace = true }
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 @@ -71,7 +71,7 @@ fn generate_from_single_field
}
}

// qqq : document, add example of generated code
// qqq : for Petro : document, add example of generated code
fn generate_from_multiple_fields_named
(
field_types : &Vec< &syn::Type >,
Expand Down
94 changes: 47 additions & 47 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 Expand Up @@ -374,7 +374,7 @@ pub fn as_mut( input : proc_macro::TokenStream ) -> proc_macro::TokenStream
///
/// ```

// qqq : xxx : why no run/ignore? fix
// qqq : for Petro : xxx : why no run/ignore? fix

#[ cfg( feature = "enabled" ) ]
#[ cfg( feature = "derive_variadic_from" ) ]
Expand Down
38 changes: 17 additions & 21 deletions module/core/program_tools/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,23 @@ pub( crate ) mod private
}
}

// impl< IntoVariant > From< IntoVariant > for GetData
// where
// IntoVariant : Into< PathBuf >,
// {
// #[ inline ]
// fn from( src : IntoVariant ) -> Self
// {
// Self::FromStr( core::convert::Into::into( src ) )
// }
// }
//
// impl< IntoVariant > From< IntoVariant > for GetData
// where
// IntoVariant : Into< String >,
// {
// #[ inline ]
// fn from( src : IntoVariant ) -> Self
// {
// Self::FromStr( core::convert::Into::into( src ) )
// }
// }
impl From< PathBuf > for GetData
{
#[ inline ]
fn from( src : PathBuf ) -> Self
{
Self::FromFile( src )
}
}

impl From< String > for GetData
{
#[ inline ]
fn from( src : String ) -> Self
{
Self::FromString( src )
}
}

impl Default for GetData
{
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

0 comments on commit c39b70c

Please sign in to comment.