macro_rules! group {
(
$(#[$meta:meta])*
$vis:vis enum $name:ident {
$(
$(#[$vmeta:meta])*
$variant:ident($source_type:ty)
),* $(,)?
}
) => { ... };
}Expand description
Macro for composing multi-error enums with automatic
From<OtherError> conversions and full ForgeError delegation.
Every variant must wrap exactly one source type that itself
implements ForgeError. The macro generates:
- the enum declaration,
DisplayandErrorimplementations that forward to the wrapped source,From<T>for each wrapped type,- a
ForgeErrorimpl whose methods delegate directly to the wrapped source’sForgeErrormethods (no type-erased downcast, no fallback values).
§Example
use error_forge::{group, AppError};
// `AppError` already implements `ForgeError`, so it can be
// wrapped directly. Other types you wrap with `group!` must
// also implement `ForgeError` (use `define_errors!` or
// `#[derive(ModError)]` to produce them).
group! {
#[derive(Debug)]
pub enum ServiceError {
App(AppError),
}
}
// `From<AppError>` is generated, so `?` works against any
// function that returns an `AppError`.
let _err: ServiceError = AppError::config("missing").into();§ForgeError requirement
Each wrapped source type must implement ForgeError. If you
need to compose with a type that does not (e.g. std::io::Error),
wrap it once in a define_errors! enum variant or
#[derive(ModError)] enum and then group the result.
This is a breaking change from 0.9.x, where group!
accepted any wrapped type but the resulting ForgeError impl
was silently incorrect — every method returned default
fallback values regardless of the wrapped type. The 1.0
rewrite removes the type-erased downcast and trades it for a
trait bound the compiler can verify.