1use std::fmt::{self, Debug, Display};
2
3use anyhow::anyhow;
4use serde::{de, ser};
5
6#[derive(Debug)]
10pub struct Error(anyhow::Error);
11
12impl ser::Error for Error {
13 fn custom<T: Display>(msg: T) -> Self {
14 Error(anyhow!("{}", msg))
15 }
16}
17
18impl de::Error for Error {
19 fn custom<T: Display>(msg: T) -> Self {
20 Error(anyhow!("{}", msg))
21 }
22}
23
24impl Display for Error {
25 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26 Display::fmt(&self.0, f)
27 }
28}
29
30impl std::error::Error for Error {}
31
32impl Error {
33 pub(crate) fn new<E>(err: E) -> Self
34 where
35 E: std::error::Error,
36 {
37 Self(anyhow!("{}", err))
38 }
39}