serenity_slash_decode/
errors.rs

1use std::fmt::{Display, Formatter};
2
3#[derive(Debug)]
4pub enum Error {
5    WrongType {
6        expected: String,
7        found: String,
8        name: String,
9    },
10    MissingValue {
11        name: String,
12    },
13}
14
15impl Display for Error {
16    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
17        match self {
18            Error::WrongType {
19                expected,
20                found,
21                name,
22            } => f.write_str(&*format!(
23                "Wrong type in field `{}` (expected `{}`, got `{}`)",
24                name, expected, found
25            )),
26            Error::MissingValue { name } => {
27                f.write_str(&*format!("Missing value in field `{}`", name))
28            }
29        }
30    }
31}
32
33impl std::error::Error for Error {}
34
35pub type Result<T> = std::result::Result<T, Error>;