quick-impl
quick-impl
is a Rust procedural macro that simplifies working with enums and structs by generating common methods and traits for each variant or field. This helps reduce boilerplate code and enhances the ergonomics of using enums and structs in your Rust projects.
Features
Enums methods
as_ref
- Returns an immutable reference to the associated data of the enum variant.as_ref_mut
- Returns a mutable reference to the associated data of the enum variant.from
- Creates an instance of the enum variant from the associated data.into
- Converts the enum into the associated data of the variant, returning anOption
.is
- Checks if the enum variant matches a specified variant.set
- Replaces the current instance with a new instance of the specified variant.try_into
- Converts the enum into the associated data of the variant, returning aResult
.
Enums traits
Default
- Implements theDefault
trait.From
- Implements theFrom
trait.TryInto
- Implements theTryInto
trait.
Structures methods
get
- A getter for the field. Returns a reference to the field.get_clone
- A getter for the field. Returns a clone of the field.get_mut
- A mutable getter for a field.into
- Converts the struct into the field.set
- A setter for the field.take
- Returns the field and replaces it with its default value.with
- Returns the struct with the field modified.
Structures traits
AsRef
- Implements theAsRef
trait.AsMut
- Implements theAsMut
trait.Deref
- Implements theDeref
trait.DerefMut
- Implements theDerefMut
trait.Into
- Implements theInto
trait.
Usage
Add quick-impl
to your Cargo.toml
:
[]
= "0.1"
In your Rust code:
use QuickImpl;
More examples can be found in the examples.