Error enum
This commit is contained in:
parent
460b05963d
commit
df7642e89b
1 changed files with 8 additions and 8 deletions
16
src/error.rs
16
src/error.rs
|
|
@ -2,29 +2,29 @@ use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PngError {
|
pub enum PngError {
|
||||||
description: String,
|
Other(Box<str>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for PngError {
|
impl Error for PngError {
|
||||||
#[inline]
|
// deprecated
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
&self.description
|
""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for PngError {
|
impl fmt::Display for PngError {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{}", self.description)
|
match self {
|
||||||
|
PngError::Other(s) => f.write_str(s),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PngError {
|
impl PngError {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(description: &str) -> PngError {
|
pub fn new(description: &str) -> PngError {
|
||||||
PngError {
|
PngError::Other(description.into())
|
||||||
description: description.to_owned(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue