Skip to main content

serde_env/
error.rs

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