diff options
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/error.rs b/src/error.rs index 86e7928..199a0f4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,12 +1,15 @@ #![forbid(unsafe_code)] +use std::fmt::{ Display, Formatter }; pub type Result<T> = std::result::Result<T, Error>; #[derive(Debug)] pub enum Error { - IO(std::io::Error), + CommandLine(::clap::error::Error), Internal(String), + IO(std::io::Error), + UTF8, } impl From<std::io::Error> for Error { @@ -15,3 +18,34 @@ impl From<std::io::Error> for Error { } } +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") + }, + } + } +} + |