thiserror-ext

Useful extension utilities for thiserror
. See the documentation for more details.
#[derive(
Debug,
thiserror::Error,
thiserror_ext::Box,
thiserror_ext::Construct,
thiserror_ext::ContextInto,
thiserror_ext::Macro,
)]
#[thiserror_ext(
newtype(name = Error, backtrace),
macro(path = "crate::foo"),
)]
enum ErrorKind {
#[error("cannot parse int from `{from}`")]
Parse {
source: std::num::ParseIntError,
from: String,
},
#[error("not yet implemented: {msg}")]
NotImplemented {
issue: Option<i32>,
#[message] msg: String,
}
#[error("internal error: {0}")]
Internal(String),
}
assert_eq!(std::mem::size_of::<Error>(), std::mem::size_of::<usize>());
let _: &Backtrace = std::error::request_ref(&error).unwrap();
let _: Error = Error::internal("oops");
let _: Result<i32, Error> = "foo".parse::<i32>().into_parse("foo");
bail_not_implemented!(issue = 42, "an {} feature", "awesome");