derive_tools 0.54.0

A collection of derive macros designed to enhance STD.
Documentation

Module :: derive_tools

experimental rust-status docs.rs Open in Gitpod discord

Basic use-case

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

  #[ derive( From, Display, FromStr, PartialEq, Debug ) ]
  #[ display( "{0}" ) ]
  struct Struct1( i32 );

  // derived From
  let src : Struct1 = 42.into();
  let exp = Struct1( 42 );
  assert_eq!( src, exp );

  // derived Display
  let src = Struct1( 42 );
  let got = format!( "{}", src );
  let exp = "42";
  println!( "{}", got );
  assert_eq!( got, exp );

  // derived FromStr  
  use std::str::FromStr;
  let src = Struct1::from_str( "42" );
  let exp = Ok( Struct1( 42 ) );
  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