err_mac
A simple no dependency macro for creating error enums with automatic From implementations.
Features
- Automatically implements
Fromtraits for wrapped error types - Supports both unit variants and struct variants
- Implements
std::fmt::Displayusing theDebugimplementation - Works seamlessly with the
?operator for error propagation
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
The macro create_err_with_impls! takes:
- Optional attributes for the enum (e.g.,
#[derive(Debug)]) - Visibility modifier and enum name
- A list of unit variants, optionally with wrapped types
- A semicolon (;)
- A list of struct variants with named fields
Basic Example
use create_err_with_impls;
// Define errors that our application might wrap
;
;
// Create our error enum
create_err_with_impls!;
// The macro enables ergonomic error handling with '?'
Generated Code
For the example above, the macro generates:
// Automatic From implementations for wrapped types
// Display implementation