diff --git a/src/error.rs b/src/error.rs index 2ade0a1..bd8b8f3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,5 +1,6 @@ //! Error handling. +use std::fmt::Display; use std::io; use std::result; @@ -22,3 +23,38 @@ impl From for Error { Error::IOError(e) } } + +impl Display for Error { + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::IOError(e) => e.fmt(fmt), + Error::LZMAError(e) => e.fmt(fmt), + Error::XZError(e) => e.fmt(fmt), + } + } +} + +#[cfg(test)] +mod test { + use super::Error; + + #[test] + fn test_display() { + assert_eq!( + Error::IOError(std::io::Error::new( + std::io::ErrorKind::Other, + "this is an error" + )) + .to_string(), + "this is an error" + ); + assert_eq!( + Error::LZMAError("this is an error".to_string()).to_string(), + "this is an error" + ); + assert_eq!( + Error::XZError("this is an error".to_string()).to_string(), + "this is an error" + ); + } +}