serde_envfile/
error.rs

1use std::fmt::Display;
2
3use serde::{de, ser};
4
5pub type Result<T> = std::result::Result<T, Error>;
6
7/// Possible errors.
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10    #[error("{0}")]
11    Message(String),
12
13    #[error("Unexpected end of input")]
14    Eof,
15    #[error("Syntax error")]
16    Syntax,
17    #[error("Expected boolean")]
18    ExpectedBoolean,
19    #[error("Expected integer")]
20    ExpectedInteger,
21    #[error("Tuple structs are not supported")]
22    UnsupportedTupleStruct,
23    #[error("Unsupported structure in sequence")]
24    UnsupportedStructureInSeq,
25}
26
27impl ser::Error for Error {
28    fn custom<T: Display>(msg: T) -> Self {
29        Error::Message(msg.to_string())
30    }
31}
32
33impl de::Error for Error {
34    fn custom<T: Display>(msg: T) -> Self {
35        Error::Message(msg.to_string())
36    }
37}
38
39impl Error {
40    pub fn new<E>(e: E) -> Self
41    where
42        E: std::error::Error,
43    {
44        Self::Message(e.to_string())
45    }
46}