Macro impl_more::impl_error_enum
source · macro_rules! impl_error_enum { ($ty:ty, $($variant:ident ($($inner:ident),+) => $source:expr),+ ,) => { ... }; ($ty:ty, $($variant:ident ($($inner:ident),+) => $source:expr),+) => { ... }; ($ty:ty, $($variant:ident { $($inner:ident),+ } => $source:expr),+ ,) => { ... }; ($ty:ty, $($variant:ident { $($inner:ident),+ } => $source:expr),+) => { ... }; ($ty:ty,) => { ... }; ($ty:ty) => { ... }; }
Expand description
Implements Error
for enums.
Emitted code is not compatible with #[no_std]
.
§Examples
use std::error::Error as _;
#[derive(Debug)]
enum Err {
Io(std::io::Error),
Generic(String),
}
impl_more::impl_display_enum!(Err, Io(err) => "{err}", Generic(msg) => "{msg}");
impl_more::impl_error_enum!(Err, Io(err) => err);
assert!(Err::Io(io_err).source().is_some());
assert!(Err::Generic("oops".to_owned()).source().is_none());