Skip to main content

Crate derive_tools

Crate derive_tools 

Source
Expand description

§Module :: derive_tools

Facade crate aggregating 30+ derive macros from workspace and external sources, providing a unified feature-gated interface for ergonomic trait derivation.

experimental rust-status docs.rs Open in Gitpod discord

§Basic use-case

{
  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

§Rule Compliance & Architectural Notes

This crate has been systematically updated to comply with the Design and Codestyle Rulebooks. Key compliance achievements :

§Completed Compliance Work :

  1. Feature Architecture : All functionality is properly gated behind the “enabled” feature following the mandatory ‘enabled’ and ‘full’ features requirement.

  2. Dependencies : Uses workspace dependency inheritance with { workspace = true }. All derive macro dependencies are centralized in the workspace Cargo.toml.

  3. Attribute Formatting : All attributes use proper spacing per Universal Formatting Rule.

  4. Documentation Strategy : Uses #![ doc = include_str!(...) ] to include readme.md instead of duplicating documentation.

  5. Namespace Organization : Uses the standard own/orphan/exposed/prelude namespace pattern for controlled visibility and re-exports.

Modules§

_private_phf_reexport_for_macro_if_phf_feature
Rust-PHF is a library to generate efficient lookup tables at compile time using perfect hash functions.
additional_attributes
Documentation for Additional Attributes
clone_dyn
Dynamic cloning utilities
dependency
Namespace with dependencies.
exposed
Exposed namespace of the module.
orphan
Orphan namespace of the module.
own
Own namespace of the module.
prelude
Prelude to use essentials: use my_module ::prelude :: *.
variadic
Variadic conversion utilities

Macros§

from
Macro to construct a struct from variadic arguments.

Enums§

ParseError
The ParseError enum is a collection of all the possible reasons an enum can fail to parse from a string.

Traits§

AsStaticRefDeprecated
A cheap reference-to-reference conversion. Used to convert a value to a reference value with 'static lifetime within generic code.
CloneDyn
A trait to upcast a clonable entity and clone it. It’s implemented for all entities which can be cloned.
EnumCount
A trait for capturing the number of variants in Enum. This trait can be autoderived by strum_macros.
EnumMessage
Associates additional pieces of information with an Enum. This can be autoimplemented by deriving EnumMessage and annotating your variants with #[strum(message="...")].
EnumProperty
EnumProperty is 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 the strum_macros crate. Currently, the string, integer and bool literals are supported in attributes.
From1
Trait for converting from one argument.
From2
Trait for converting from two arguments.
From3
Trait for converting from three arguments.
IntoDiscriminant
A trait for retrieving the enum generated by EnumDiscriminants from an associated Type on the original enumeration. This trait can be autoderived by strum_macros.
IntoEnumIterator
This trait designates that an Enum can be iterated over. It can be auto generated using the EnumIter derive macro.
VariantArray
A trait for retrieving a static array containing all the variants in an Enum. This trait can be autoderived by strum_macros. For derived usage, all the variants in the enumerator need to be unit-types, which means you can’t autoderive enums with inner data in one or more variants. Consider using it alongside EnumDiscriminants if you require inner data but still want to have an static array of variants.
VariantIterator
VariantMetadata
VariantNames
A trait for retrieving the names of each variant in Enum. This trait can be autoderived by strum_macros.

Functions§

clone
True clone which is applicable not only to clonable entities, but to trait objects implementing CloneDyn.
clone_into_box
Clone boxed dyn.

Attribute Macros§

clone_dyn
Derive macro for CloneDyn trait.

Derive Macros§

Add
What #[derive(Add)] generates
AddAssign
What #[derive(AddAssign)] generates
AsMut
Implement AsMut for a structure.
AsRef
Implement AsRef for a structure.
AsRefStr
Converts enum variants to &'a str, where 'a is the lifetime of the input enum reference.
Constructor
What #[derive(Constructor)] generates
Deref
Implement Deref for a structure.
DerefMut
Implement DerefMut for a structure.
Display
Div
What #[derive(Mul)] generates
DivAssign
What #[derive(MulAssign)] generates
EnumCount
Add a constant usize equal to the number of variants.
EnumDiscriminants
Generate a new type with only the discriminant names.
EnumIs
Generated is_*() methods for each variant. E.g. Color.is_red().
EnumIter
Creates a new type that iterates over the variants of an enum.
EnumMessage
Add a verbose message to an enum variant.
EnumProperty
Add custom properties to enum variants.
EnumString
Converts strings to enum variants based on their name.
EnumTryAs
Generated try_as_*() methods for all tuple-style variants. E.g. Message.try_as_write().
Error
Using #[derive(Error)]
From
Implement From for a structure.
FromRepr
Add a function to enum that allows accessing variants by its discriminant
FromStr
Index
Implement Index for a structure.
IndexMut
Implement IndexMut for a structure.
InnerFrom
Implement InnerFrom for a structure.
Into
What #[derive(Into)] generates
IntoIterator
Using #[derive(IntoIterator)]
IntoStaticStr
Implements From<MyEnum> for &'static str on an enum.
IsVariant
What #[derive(IsVariant)] generates
Mul
What #[derive(Mul)] generates
MulAssign
What #[derive(MulAssign)] generates
New
Implement New for a structure.
Not
Implement Not for a structure.
Sub
What #[derive(Add)] generates
SubAssign
What #[derive(AddAssign)] generates
Sum
Using #[derive(Sum)]
TryInto
What #[derive(TryInto)] generates
Unwrap
What #[derive(Unwrap)] generates
VariadicFrom
Implement VariadicFrom for a structure.
VariantArray
Adds a 'static slice with all of the Enum’s variants.
VariantNames
Implements Strum::VariantNames which adds an associated constant VARIANTS which is a 'static slice of discriminant names.