Crate derive_tools
source ·Expand description
Collection of derives which extend STD.
§Module :: derive_tools
Collection of derives which extend STD.
§Basic use-case
#[ cfg( all( feature = "derive_from", feature = "derive_into", feature = "derive_display", feature = "derive_from_str" ) ) ]
{
  use derive_tools::*;
  #[ derive( Into, Display, FromStr, PartialEq, Debug ) ]
  #[ display( "{a}-{b}" ) ]
  struct Struct1
  {
    a : i32,
    b : i32,
  }
  // derived Into
  let src = Struct1 { a : 1, b : 3 };
  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
Re-exports§
pub use super::wtools;
Modules§
- Rust-PHF is a library to generate efficient lookup tables at compile time using perfect hash functions.
 - Documentation for Additional Attributes
 - Derive to clone dyn structures.
 - Dependencies.
 - Exposed namespace of the module.
 - Orphan namespace of the module.
 - Prelude to use essentials:
use my_module::prelude::*. - Protected namespace of the module.
 - System of Types for Reflection
 - Types, which are extension of std.
 
Macros§
- Variadic constructor.
 
Enums§
- The
ParseErrorenum is a collection of all the possible reasons an enum can fail to parse from a string. 
Traits§
- AsStaticRefDeprecatedA cheap reference-to-reference conversion. Used to convert a value to a reference value with
'staticlifetime within generic code. - A trait for capturing the number of variants in Enum. This trait can be autoderived by
strum_macros. - Associates additional pieces of information with an Enum. This can be autoimplemented by deriving
EnumMessageand annotating your variants with#[strum(message="...")]. EnumPropertyis a trait that makes it possible to store additional information with enum variants. This trait is designed to be used with the macro of the same name in thestrum_macroscrate. Currently, the only string literals are supported in attributes, the other methods will be implemented as additional attribute types become stabilized.- Constructor without arguments. Alias of Default.
 - Constructor with single argument.
 - Constructor with two arguments.
 - Constructor with three arguments.
 - value-to-value conversion that consumes the input value. Change left and rught, but keep semantic of `From_1``.
 - This trait designates that an
Enumcan be iterated over. It can be auto generated usingstrum_macroson your behalf. - A trait for retrieving the names of each variant in Enum. This trait can be autoderived by
strum_macros. 
Functions§
- Clone boxed dyn.
 - Provides a reflection of an instance that implements the
Instancetrait. 
Attribute Macros§
- Derive macro to generate former for a structure. Former is variation of Builder Pattern.
 
Derive Macros§
- Derive macro to implement AsMut when-ever it’s possible to do automatically.
 - Derive macro to implement AsRef when-ever it’s possible to do automatically.
 - Converts enum variants to
&'static str. - Derive macro to implement Deref when-ever it’s possible to do automatically.
 - Derive macro to implement Deref when-ever it’s possible to do automatically.
 - Add a constant
usizeequal to the number of variants. - Generate a new type with only the discriminant names.
 - Generated
is_*()methods for each variant. E.g.Color.is_red(). - Creates a new type that iterates of the variants of an enum.
 - Add a verbose message to an enum variant.
 - Add custom properties to enum variants.
 - Converts strings to enum variants based on their name.
 - Generated
try_as_*()methods for all tuple-style variants. E.g.Message.try_as_write(). - Implements
Strum::VariantNameswhich adds an associated constantVARIANTSwhich is an array of discriminant names. - Derive macro to implement From converting inner type into outer when-ever it’s possible to do automatically.
 - Derive macro to implement From converting inner type into outer when-ever it’s possible to do automatically.
 - Add a function to enum that allows accessing variants by its discriminant
 - Derive macro to implement From converting outer type into inner when-ever it’s possible to do automatically.
 - Implements
From<MyEnum> for &'static stron an enum. - Reflect structure of any kind.
 - implements
std::string::ToStringon an enum - Derive macro to implement default constructors
From_0,From_1,From_2,From_3.