mando-lib-macro
Procedural macro crate for the Mando workspace. Provides the #[derive(ErrorCode)] macro used throughout mando-lib.
#[derive(ErrorCode)]
Auto-generates error code tracking for enum variants. Maps each variant to a static string identifier for structured error reporting and observability.
Usage
use mando_lib_macro::ErrorCode;
use thiserror::Error;
#[derive(Error, ErrorCode)]
pub enum DataPointError {
#[error("path fragment '{0}' must contain...")]
InvalidPathFragmentFormat(usize, String),
#[error("data point not found: {0}")]
NotFound(String),
}Generated Output
impl ErrorCode for DataPointError {
fn error_code(&self) -> &'static str {
match self {
Self::InvalidPathFragmentFormat(..) =>
"crate::datapoint::DataPointError::InvalidPathFragmentFormat",
Self::NotFound(..) =>
"crate::datapoint::DataPointError::NotFound",
}
}
}Each variant maps to a fully qualified path string, making error codes stable, unique, and grep-friendly across the codebase.
Dependencies
| Crate | Purpose |
|---|---|
syn | Rust syntax parsing |
quote | Code generation |
proc-macro2 | Token stream manipulation |
proc-macro-crate 3.4.0 | Resolves renamed crate imports |
Notes
proc-macro-cratehandles cases wheremando-libis imported under a different name- The macro is a proc-macro crate (
libtype withproc-macro = true) - Used alongside
thiserrorforDisplay+std::error::Errorimplementations