Create macro for manual From impls for Error

This commit is contained in:
Yash Karandikar 2022-08-14 19:11:44 -05:00
parent 4717946fa3
commit 76249c3a0c

View file

@ -67,30 +67,24 @@ impl IntoResponse for Error {
} }
} }
// We need to implement this manually because pbkdf2's Error type does not meet the bounds required macro_rules! manual_from {
// for `thiserror` ($($f:ty => $t:ident),*) => {
impl From<pbkdf2::password_hash::Error> for Error { $(
fn from(e: pbkdf2::password_hash::Error) -> Self { impl From<$f> for Error {
Self::Pbkdf2(e) fn from(source: $f) -> Self {
} Self::$t(source)
}
}
)*
};
} }
impl From<String> for Error { // We need to implement these manually because they don't meet the bounds set by thiserror
fn from(e: String) -> Self { manual_from! {
Self::Other(e) pbkdf2::password_hash::Error => Pbkdf2,
} String => Other,
} Redirect => Redirect,
StatusCode => StatusCode
impl From<Redirect> for Error {
fn from(e: Redirect) -> Self {
Self::Redirect(e)
}
}
impl From<StatusCode> for Error {
fn from(c: StatusCode) -> Self {
Self::StatusCode(c)
}
} }
#[derive(Deserialize, Debug, Clone)] #[derive(Deserialize, Debug, Clone)]