1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#![forbid(unsafe_code)]
use std::fmt::{ Display, Formatter };
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
CommandLine(::clap::error::Error),
Internal(String),
IO(std::io::Error),
UTF8,
}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Error::IO(value)
}
}
impl From<::clap::error::Error> for Error {
fn from(value: ::clap::error::Error) -> Self {
Error::CommandLine(value)
}
}
impl From<std::string::FromUtf8Error> for Error {
fn from(_value: std::string::FromUtf8Error) -> Self {
Error::UTF8
}
}
impl Display for Error {
fn fmt(&self, fmt: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Error::CommandLine(error) => {
write!(fmt, "{}", error.to_string())
},
Error::Internal(string) => {
write!(fmt, "{}", string)
},
Error::IO(error) => {
write!(fmt, "{}", error.to_string())
},
Error::UTF8 => {
write!(fmt, "Invalid UTF8 received")
},
}
}
}
|