| Crates.io | masterror-derive |
| lib.rs | masterror-derive |
| version | 0.9.0 |
| created_at | 2025-09-21 00:07:59.719682+00 |
| updated_at | 2025-09-24 11:27:21.767015+00 |
| description | Derive macros for masterror |
| homepage | |
| repository | https://github.com/RAprogramm/masterror |
| max_upload_size | |
| id | 1848317 |
| size | 161,640 |
Procedural macros that power masterror's
#[derive(Error)]. The derive generates ergonomic std::error::Error and
Display implementations together with seamless integration into
masterror's domain-centric AppError type.
Tip: Depend on the
masterrorcrate in application code and import the macros from there (use masterror::Error;). This standalone crate is published to makecargo install/cargo packageflows happy and to support advanced macro integrations.
[dependencies]
masterror = "0.10"
use masterror::{AppError, Error};
#[derive(Error)]
#[error(display = "failed to parse payload: {source}")]
#[app_error(kind = "BadRequest")]
pub struct PayloadInvalid {
#[source]
pub source: serde_json::Error,
}
fn parse(input: &str) -> Result<(), AppError> {
serde_json::from_str::<serde_json::Value>(input)
.map(|_| ())
.map_err(PayloadInvalid::from)
}
The derive implements Display, std::error::Error, and conversion glue so
you can return rich AppError values with a single ?.
#[error(display = ...)] – formats the error message using captured fields.#[source] / #[from] – wires source error propagation and conversion.#[backtrace] – exposes an optional captured Backtrace.#[app_error(...)] – configures how the error maps into AppError
(kind, HTTP status, telemetry).#[provide(...)] – attaches structured telemetry providers that surface
typed context (IDs, domains, tenant information) through tracing layers.See the main masterror README for an end-to-end guide and
advanced examples covering templated display strings, telemetry providers and
OpenAPI/schema integrations.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.