30 breaking releases

0.32.0 Oct 30, 2024
0.30.0 Oct 30, 2024
0.26.0 Jul 13, 2024
0.20.0 Mar 26, 2024
0.1.5 Jul 15, 2022

#1887 in Development tools

Download history 1591/week @ 2024-08-17 2760/week @ 2024-08-24 2218/week @ 2024-08-31 2717/week @ 2024-09-07 601/week @ 2024-09-14 517/week @ 2024-09-21 652/week @ 2024-09-28 354/week @ 2024-10-05 679/week @ 2024-10-12 326/week @ 2024-10-19 1065/week @ 2024-10-26 1401/week @ 2024-11-02 712/week @ 2024-11-09 933/week @ 2024-11-16 372/week @ 2024-11-23 1585/week @ 2024-11-30

3,994 downloads per month
Used in 89 crates (10 directly)

MIT license

40KB
338 lines

Module :: derive_tools

experimental rust-status docs.rs Open in Gitpod discord

Basic use-case

# #[ cfg( all( feature = "derive_from", feature = "derive_inner_from", feature = "derive_display", feature = "derive_from_str" ) ) ]
{
  use derive_tools::*;

  #[ derive( From, InnerFrom, Display, FromStr, PartialEq, Debug ) ]
  #[ display( "{a}-{b}" ) ]
  struct Struct1
  {
    a : i32,
    b : i32,
  }

  // derived InnerFrom
  let src = Struct1 { a : 1, b : 3 };
  let got : ( i32, i32 ) = src.into();
  let exp = ( 1, 3 );
  assert_eq!( got, exp );

  // derived From
  let src : Struct1 = ( 1, 3 ).into();
  let got : ( i32, i32 ) = src.into();
  let exp = ( 1, 3 );
  assert_eq!( got, exp );

  // derived Display
  let src = Struct1 { a : 1, b : 3 };
  let got = format!( "{}", src );
  let exp = "1-3";
  println!( "{}", got );
  assert_eq!( got, exp );

  // derived FromStr
  use std::str::FromStr;
  let src = Struct1::from_str( "1-3" );
  let exp = Ok( Struct1 { a : 1, b : 3 } );
  assert_eq!( src, exp );

}

To add to your project

cargo add derive_tools

Try out from the repository

git clone https://github.com/Wandalen/wTools
cd wTools
cd examples/derive_tools_trivial
cargo run

Dependencies

~0–1MB
~17K SLoC