deref-rs
A simple Rust autodereference implementation that provides macros and derive macros to easily implement the Deref and DerefMut traits for your custom types.
Features
- Macro-based implementation: Simple procedural macros for quick
DerefandDerefMutimplementation - Derive macro support: Attribute-based derive macros for more ergonomic usage
- Generic type support: Works with both regular types and generic types
- Field access: Supports both named fields and tuple-style field access
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Using Procedural Macros
Basic Usage
use ;
;
// Implement Deref for MyType
deref!;
// Implement both Deref and DerefMut for MyType
deref_mut!;
With Generic Types
use ;
// Implement Deref for a generic type
deref!;
// Implement both Deref and DerefMut for a generic type
deref_mut!;
Using Derive Macros
Basic Usage
use ;
With Named Fields
use Deref;
With Tuple Structs
use Deref;
;
;
Examples
Smart Pointer Implementation
use Deref;
use Deref as DerefTrait;
Nested Dereferencing
use ;
// Implement DerefMut for Outer using the macro
deref_mut!;
API Reference
Macros
deref! Macro
Implements the Deref trait for a struct.
deref!
deref!
deref_mut! Macro
Implements both Deref and DerefMut traits for a struct.
deref_mut!
deref_mut!
Derive Macros
Deref Derive Macro
Implements the Deref trait using the #[deref] attribute to mark the target field.
DerefMut Derive Macro
Implements both Deref and DerefMut traits using the #[deref_mut] attribute to mark the target field.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Changelog
0.1.0
- Initial release
- Basic
deref!andderef_mut!macros DerefandDerefMutderive macros- Support for generic types