yoshi-derive

Derive macros for automatically generating Yoshi error types. Because writing error boilerplate is boring.
What's this?
Generates std::error::Error implementations, Display, and conversion to Yoshi types automatically.
Installation
[]
= "0.1"
= "0.1"
Basic Usage
use YoshiError;
Attributes
Container Attributes (#[yoshi(...)] on enums)
| Attribute | Description | Example |
|---|---|---|
error_code_prefix |
Prefix for error codes | #[yoshi(error_code_prefix = "HTTP")] |
default_severity |
Default severity (0-255) | #[yoshi(default_severity = 75)] |
Variant Attributes (#[yoshi(...)] on enum variants)
| Attribute | Description | Example |
|---|---|---|
display |
Custom display format | #[yoshi(display = "Error: {message}")] |
kind |
Map to YoshiKind | #[yoshi(kind = "Network")] |
error_code |
Unique error code | #[yoshi(error_code = 1001)] |
severity |
Severity level | #[yoshi(severity = 80)] |
transient |
Mark as retryable | #[yoshi(transient = true)] |
suggestion |
Recovery suggestion | #[yoshi(suggestion = "Check network")] |
Field Attributes (#[yoshi(...)] on struct fields)
| Attribute | Description | Example |
|---|---|---|
source |
Mark as error source | #[yoshi(source)] |
context |
Add to context metadata | #[yoshi(context = "file_path")] |
shell |
Add as typed shell | #[yoshi(shell)] |
skip |
Skip in Display | #[yoshi(skip)] |
Advanced Example
use YoshiError;
Generated Code
The derive macro automatically creates:
std::fmt::Displayimplementationstd::error::ErrorimplementationFrom<YourError> for yoshi_std::Yoshiconversion- Error code and severity methods
Smart Inference
The macro automatically infers attributes based on naming:
timeout,expired→kind = "Timeout"network,connection→kind = "Network"not_found,missing→kind = "NotFound"std::io::Errorfields →source = true
Performance
- Compilation: <100ms for typical enums (<50 variants)
- Runtime: Zero overhead - generates efficient code
- Memory: Uses static strings where possible
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.