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
|
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)]
|
||||||
|
|
Loading…
Reference in a new issue