1use std::fmt::{Display, Formatter};
2
3#[derive(Debug)]
5pub enum Error {
6 BadRegex(regex::Error),
8
9 NoMatch(),
11
12 BadValue {
14 name: String,
16
17 value: String,
19 },
20
21 Custom(String),
23}
24
25impl serde::de::Error for Error {
26 fn custom<T>(msg: T) -> Self where T: Display {
27 Self::Custom(msg.to_string())
28 }
29}
30
31impl std::error::Error for Error {}
32
33impl Display for Error {
34 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
35 use Error::*;
36 match self {
37 BadRegex(err) => err.fmt(f),
38 NoMatch() => write!(f, "String doesn't match pattern"),
39 BadValue { name, value } => write!(f, "Unable to convert value for group {}: {}", name, value),
40 Custom(err) => write!(f, "{}", err),
41 }
42 }
43}
44
45pub(crate) type Result<T> = std::result::Result<T, Error>;