Crates.io | quickerr |
lib.rs | quickerr |
version | 0.3.2 |
source | src |
created_at | 2023-05-17 15:07:00.603224 |
updated_at | 2023-08-18 21:50:29.444735 |
description | A macro to define errors quickly, like `thiserror` but terser and more opinionated |
homepage | |
repository | https://github.com/PROMETHIA-27/quickerr |
max_upload_size | |
id | 867032 |
size | 28,313 |
A macro to define errors quickly, like thiserror
but terser and more opinionated. Exclusively uses a decl macro, so compile times should not be greatly impacted. It uses markdown-like syntax. Primarily for my own personal use as I find it extremely helpful for quickly defining high quality errors.
# use quickerr::error;
# error! { MyOtherError "" }
# error! { MySecondOtherError "" }
error! {
pub EnumError
"a problem happened!"
MyOtherError,
MySecondOtherError,
}
this roughly expands to:
#[derive(Debug)]
#[non_exhaustive]
pub enum EnumError {
MyOtherError(MyOtherError),
MySecondOtherError(MySecondOtherError),
}
impl ::std::fmt::Display for EnumError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("a problem happened!")
}
}
impl ::std::error::Error for EnumError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(match self {
MyOtherError(err) => err,
MySecondOtherError(err) => err,
})
}
}
impl ::std::convert::From<MyOtherError> for EnumError {
fn from(source: MyOtherError) -> Self {
Self::MyOtherError(source)
}
}
impl ::std::convert::From<MySecondOtherError> for EnumError {
fn from(source: MySecondOtherError) -> Self {
Self::MySecondOtherError(source)
}
}