Create macro for manual From impls for Error
This commit is contained in:
parent
4717946fa3
commit
76249c3a0c
38
src/main.rs
38
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<pbkdf2::password_hash::Error> 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<String> for Error {
|
||||
fn from(e: String) -> Self {
|
||||
Self::Other(e)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
// 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)]
|
||||
|
|
Loading…
Reference in a new issue