1use std::fmt::{self, Display};
4
5#[derive(Debug)]
6#[allow(dead_code)]
7pub enum Error {
8 Eof,
9 Message(String),
10}
11
12impl std::error::Error for Error {}
13
14impl serde::ser::Error for Error {
15 fn custom<T: Display>(msg: T) -> Self {
16 Error::Message(msg.to_string())
17 }
18}
19
20impl serde::de::Error for Error {
21 fn custom<T: Display>(msg: T) -> Self {
22 Error::Message(msg.to_string())
23 }
24}
25
26impl From<serde_yaml::Error> for Error {
27 fn from(err: serde_yaml::Error) -> Self {
28 Error::Message(err.to_string())
29 }
30}
31
32impl Display for Error {
33 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
34 match self {
35 Error::Eof => formatter.write_str("unexpected end of input"),
36 Error::Message(msg) => formatter.write_str(msg),
37 }
38 }
39}