Procedural macro implementations for common derive macros extending std.
derive_tools_meta is the proc-macro companion crate for derive_tools. It provides derive macro implementations for common traits like Deref, DerefMut, From, Index, AsRef, AsMut, New, and more.
Important: This crate should not be used directly. Use the derive_tools crate which re-exports this functionality with additional convenience features.
derive_tools_meta is responsible for providing procedural macro implementations that generate trait implementations for structs, reducing boilerplate code.
- Derive macros:
Deref,DerefMut,From,InnerFrom,New,Index,IndexMut,AsRef,AsMut,VariadicFrom,Not,Phantom - Struct analysis: Parse struct definitions and field types
- Code generation: Generate trait implementations
- Attribute support: Handle derive attributes and configuration
- Runtime behavior: Pure compile-time code generation
- User-facing API: Use
derive_toolscrate instead - Enum support: Most derives are struct-focused
- Upstream: Uses
macro_toolsfor syntax parsing - Downstream: Re-exported by
derive_toolscrate - Compile-time only: No runtime dependencies
derive_tools_meta/
├── src/
│ └── lib.rs # Proc-macro entry points
├── Cargo.toml
├── readme.md
└── spec.md
Auto-implement Deref for newtype structs.
#[derive(Deref)]
struct Wrapper( String );
let w = Wrapper( "hello".into() );
assert_eq!( w.len(), 5 ); // Derefs to StringAuto-implement DerefMut for newtype structs.
Auto-implement From<Inner> for newtype structs.
#[derive(From)]
struct UserId( u64 );
let id: UserId = 42u64.into();Auto-implement From<Wrapper> returning inner type.
Generate new() constructor.
#[derive(New)]
struct Point { x: f32, y: f32 }
let p = Point::new( 1.0, 2.0 );Auto-implement indexing traits.
Auto-implement reference conversion traits.
Implement variadic From1, From2, From3 traits.
Auto-implement logical Not trait.
Generate phantom data handling.
| Feature | Default | Description |
|---|---|---|
enabled |
✓ | Enable the crate |
full |
- | All features |
derive_deref |
✓ | Enable Deref derive |
derive_deref_mut |
✓ | Enable DerefMut derive |
derive_from |
✓ | Enable From derive |
derive_new |
✓ | Enable New derive |
derive_index |
✓ | Enable Index derive |
derive_index_mut |
✓ | Enable IndexMut derive |
derive_inner_from |
✓ | Enable InnerFrom derive |
derive_as_ref |
✓ | Enable AsRef derive |
derive_as_mut |
✓ | Enable AsMut derive |
derive_variadic_from |
✓ | Enable VariadicFrom derive |
derive_not |
✓ | Enable Not derive |
derive_phantom |
✓ | Enable Phantom derive |
| Dependency | Purpose |
|---|---|
macro_tools |
Syntax parsing utilities |
iter_tools |
Iterator extensions |
component_model_types |
Component types |
derive_tools- Re-exports this crate's macros
Rust requires proc-macro crates to be separate. The derive_tools facade provides the user-facing API while this crate handles implementations.
Not all projects need all derives. Feature flags allow:
- Faster compilation by excluding unused code
- Reduced dependency footprint
- Selective functionality
| Crate | Relationship |
|---|---|
derive_tools |
Parent facade crate |
macro_tools |
Upstream syntax utilities |
derive_more |
Alternative derive collection |