28 releases (breaking)

0.24.0 May 31, 2024
0.22.0 May 14, 2024
0.20.0 Mar 26, 2024
0.8.0 Dec 9, 2023
0.1.5 Jul 15, 2022

#1422 in Development tools

Download history 474/week @ 2024-02-14 486/week @ 2024-02-21 979/week @ 2024-02-28 934/week @ 2024-03-06 4383/week @ 2024-03-13 3236/week @ 2024-03-20 683/week @ 2024-03-27 775/week @ 2024-04-03 532/week @ 2024-04-10 395/week @ 2024-04-17 633/week @ 2024-04-24 856/week @ 2024-05-01 4370/week @ 2024-05-08 2202/week @ 2024-05-15 1490/week @ 2024-05-22 4320/week @ 2024-05-29

12,435 downloads per month
Used in 90 crates (5 directly)

MIT license

64KB
608 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

~1.5–2.7MB
~52K SLoC