Skip to content

Commit

Permalink
Implement Display for ImageError
Browse files Browse the repository at this point in the history
This is currently required by `Result<T, ImageError>::unwrap`.  Fixes build
errors in test files.
  • Loading branch information
mbrubeck committed Jan 23, 2015
1 parent 1aff46f commit 273c322
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/image.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::error::FromError;
use std::fmt;
use std::mem;
use std::io;
use std::slice;
Expand All @@ -13,7 +14,7 @@ use animation::{Frame, Frames};
use dynimage::decoder_to_image;

/// An enumeration of Image Errors
#[derive(Clone, Show, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ImageError {
/// The Image is not formatted properly
FormatError(String),
Expand Down Expand Up @@ -44,6 +45,12 @@ impl FromError<io::IoError> for ImageError {
}
}

// required for Result<T, ImageError>::unwrap
impl fmt::Display for ImageError {

This comment has been minimized.

Copy link
@mbrubeck

mbrubeck Jan 23, 2015

Author Owner

See rust-lang/rfcs#565 for discussion about this new requirement. It's not clear if this will stick or be reverted/changed. For now, I just provided the simplest possible implementation to make the tests pass.

fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.to_string(), f)
}
}

/// Result of an image decoding/encoding process
pub type ImageResult<T> = Result<T, ImageError>;
Expand All @@ -66,7 +73,7 @@ pub enum DecodingBuffer<'a> {

/// An enumeration of supported image formats.
/// Not all formats support both encoding and decoding.
#[derive(Copy, PartialEq, Eq, Show)]
#[derive(Copy, PartialEq, Eq, Debug)]
pub enum ImageFormat {
/// An Image in PNG Format
PNG,
Expand Down

0 comments on commit 273c322

Please sign in to comment.