add serde de/ser impls for error
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -2,6 +2,7 @@ mod err;
|
|||||||
mod log;
|
mod log;
|
||||||
mod panic;
|
mod panic;
|
||||||
mod response;
|
mod response;
|
||||||
|
mod serde;
|
||||||
|
|
||||||
use std::{any::Any, borrow::Cow, convert::Infallible, fmt};
|
use std::{any::Any, borrow::Cow, convert::Infallible, fmt};
|
||||||
|
|
||||||
@@ -56,6 +57,10 @@ pub enum Error {
|
|||||||
Regex(#[from] regex::Error),
|
Regex(#[from] regex::Error),
|
||||||
#[error("Request error: {0}")]
|
#[error("Request error: {0}")]
|
||||||
Reqwest(#[from] reqwest::Error),
|
Reqwest(#[from] reqwest::Error),
|
||||||
|
#[error("{0}")]
|
||||||
|
SerdeDe(Cow<'static, str>),
|
||||||
|
#[error("{0}")]
|
||||||
|
SerdeSer(Cow<'static, str>),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
TomlDe(#[from] toml::de::Error),
|
TomlDe(#[from] toml::de::Error),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
|
|||||||
13
src/core/error/serde.rs
Normal file
13
src/core/error/serde.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use serde::{de, ser};
|
||||||
|
|
||||||
|
use crate::Error;
|
||||||
|
|
||||||
|
impl de::Error for Error {
|
||||||
|
fn custom<T: Display + ToString>(msg: T) -> Self { Self::SerdeDe(msg.to_string().into()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ser::Error for Error {
|
||||||
|
fn custom<T: Display + ToString>(msg: T) -> Self { Self::SerdeSer(msg.to_string().into()) }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user