diff options
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..051a8c3 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,32 @@ +pub type Result<T> = std::result::Result<T, Error>; + +#[derive(Debug)] +pub enum Error { + Io(std::io::Error), + Utf8(std::str::Utf8Error), + Opts(String), +} + +impl std::error::Error for Error {} + +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::Io(e) => write!(f, "cat: {}", e), + Error::Utf8(e) => write!(f, "cat: {}", e), + Error::Opts(s) => write!(f, "cat: unrecognized option '{}'", s), + } + } +} + +impl From<std::io::Error> for Error { + fn from(value: std::io::Error) -> Self { + Error::Io(value) + } +} + +impl From<std::str::Utf8Error> for Error { + fn from(value: std::str::Utf8Error) -> Self { + Error::Utf8(value) + } +} |