25 次重大版本发布

0.27.0 2024 年 8 月 16 日
0.26.0 2024 年 7 月 13 日
0.25.0 2024 年 6 月 29 日
0.20.0 2024 年 3 月 26 日
0.1.5 2022 年 7 月 15 日

#1834开发工具

Download history 586/week @ 2024-04-27 760/week @ 2024-05-04 4654/week @ 2024-05-11 1798/week @ 2024-05-18 3580/week @ 2024-05-25 2848/week @ 2024-06-01 1106/week @ 2024-06-08 658/week @ 2024-06-15 416/week @ 2024-06-22 1439/week @ 2024-06-29 349/week @ 2024-07-06 1836/week @ 2024-07-13 831/week @ 2024-07-20 1385/week @ 2024-07-27 406/week @ 2024-08-03 1031/week @ 2024-08-10

每月 3,788 次下载
用于 93 开源软件包(7 个直接使用)

MIT 许可证

44KB
338 行代码

模块 :: derive_tools

experimental rust-status docs.rs Open in Gitpod discord

基本用例

# #[ 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 );

}

添加到您的项目中

cargo add derive_tools

从仓库中尝试

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

依赖关系

~0–1MB
~17K SLoC