#macro-derive #general-purpose #fundamental #collection #from-str #enhance

no-std derive_tools

A collection of derive macros designed to enhance STD

26 releases (breaking)

new 0.22.0 May 14, 2024
0.20.0 Mar 26, 2024
0.8.0 Dec 9, 2023
0.7.0 Oct 28, 2023
0.1.5 Jul 15, 2022

#1327 in Development tools

Download history 187/week @ 2024-01-22 195/week @ 2024-01-29 219/week @ 2024-02-05 393/week @ 2024-02-12 471/week @ 2024-02-19 750/week @ 2024-02-26 1045/week @ 2024-03-04 3603/week @ 2024-03-11 3530/week @ 2024-03-18 1072/week @ 2024-03-25 960/week @ 2024-04-01 459/week @ 2024-04-08 461/week @ 2024-04-15 711/week @ 2024-04-22 583/week @ 2024-04-29 1977/week @ 2024-05-06

3,778 downloads per month
Used in 83 crates (5 directly)

MIT license

46KB
563 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–2.1MB
~42K SLoC