1use std::{error::Error, fmt::Display, string::FromUtf8Error};
5
6#[derive(Debug)]
14pub enum RcErr {
15 Regex(regex::Error),
17 Read(std::io::Error),
19 Utf8(FromUtf8Error),
23}
24
25impl Display for RcErr {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 match self {
28 RcErr::Regex(e) => write!(f, "regex error: {}", &e),
29 RcErr::Read(e) => write!(f, "read error: {}", &e),
30 RcErr::Utf8(e) => write!(f, "UTF-8 decoding error: {}", &e),
31 }
32 }
33}
34
35impl From<regex::Error> for RcErr {
36 fn from(e: regex::Error) -> Self {
37 RcErr::Regex(e)
38 }
39}
40
41impl From<std::io::Error> for RcErr {
42 fn from(e: std::io::Error) -> Self {
43 RcErr::Read(e)
44 }
45}
46
47impl From<FromUtf8Error> for RcErr {
48 fn from(e: FromUtf8Error) -> Self {
49 RcErr::Utf8(e)
50 }
51}
52
53impl Error for RcErr {
54 fn source<'a>(&'a self) -> Option<&(dyn Error + 'static)> {
55 match self {
56 RcErr::Regex(e) => Some(e),
57 RcErr::Read(e) => Some(e),
58 RcErr::Utf8(e) => Some(e),
59 }
60 }
61}