Skip to content

Instantly share code, notes, and snippets.

@ptrkrlsrd
Last active November 18, 2022 14:40
Show Gist options
  • Save ptrkrlsrd/5f35b60986ca837ab526fe99cbd3709c to your computer and use it in GitHub Desktop.
Save ptrkrlsrd/5f35b60986ca837ab526fe99cbd3709c to your computer and use it in GitHub Desktop.
#[derive(Debug)]
pub enum Err {
JSONError(serde_json::Error),
HTTPError(reqwest::Error),
}
macro_rules! convert_error {
($a:ty, $b:ident, $c:expr) => {
impl From<$a> for $b {
fn from(err: $a) -> Self {
$c(err)
}
}
}
}
convert_error!(serde_json::Error, Err, Err::JSONError);
convert_error!(reqwest::Error, Err, Err::HTTPError);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment