diff --git a/src/main.rs b/src/main.rs index cc6be29..857731c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 -// for `thiserror` -impl From for Error { - fn from(e: pbkdf2::password_hash::Error) -> Self { - Self::Pbkdf2(e) - } +macro_rules! manual_from { + ($($f:ty => $t:ident),*) => { + $( + impl From<$f> for Error { + fn from(source: $f) -> Self { + Self::$t(source) + } + } + )* + }; } -impl From for Error { - fn from(e: String) -> Self { - Self::Other(e) - } -} - -impl From for Error { - fn from(e: Redirect) -> Self { - Self::Redirect(e) - } -} - -impl From for Error { - fn from(c: StatusCode) -> Self { - Self::StatusCode(c) - } +// We need to implement these manually because they don't meet the bounds set by thiserror +manual_from! { + pbkdf2::password_hash::Error => Pbkdf2, + String => Other, + Redirect => Redirect, + StatusCode => StatusCode } #[derive(Deserialize, Debug, Clone)]