Error enum

This commit is contained in:
Kornel Lesiński 2018-06-01 15:09:50 +01:00
parent 460b05963d
commit df7642e89b

View file

@ -2,29 +2,29 @@ use std::error::Error;
use std::fmt;
#[derive(Debug, Clone)]
pub struct PngError {
description: String,
pub enum PngError {
Other(Box<str>),
}
impl Error for PngError {
#[inline]
// deprecated
fn description(&self) -> &str {
&self.description
""
}
}
impl fmt::Display for PngError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description)
match self {
PngError::Other(s) => f.write_str(s),
}
}
}
impl PngError {
#[inline]
pub fn new(description: &str) -> PngError {
PngError {
description: description.to_owned(),
}
PngError::Other(description.into())
}
}