Update ZipError to latest rust

This commit is contained in:
Mathijs van de Nes 2015-01-24 13:24:19 +01:00
parent c2686b3b2e
commit b88abe1582
2 changed files with 32 additions and 12 deletions

View file

@ -1,7 +1,7 @@
[package] [package]
name = "zip" name = "zip"
version = "0.0.7" version = "0.0.8"
authors = ["Mathijs van de Nes <git@mathijs.vd-nes.nl>"] authors = ["Mathijs van de Nes <git@mathijs.vd-nes.nl>"]
license = "MIT" license = "MIT"
repository = "https://github.com/mvdnes/zip-rs.git" repository = "https://github.com/mvdnes/zip-rs.git"

View file

@ -2,6 +2,7 @@
use std::io; use std::io;
use std::error; use std::error;
use std::fmt;
/// Generic result type with ZipError as its error variant /// Generic result type with ZipError as its error variant
pub type ZipResult<T> = Result<T, ZipError>; pub type ZipResult<T> = Result<T, ZipError>;
@ -23,6 +24,28 @@ pub enum ZipError
ReaderUnavailable, ReaderUnavailable,
} }
impl ZipError
{
fn detail(&self) -> ::std::string::CowString
{
use ::std::error::Error;
use ::std::borrow::IntoCow;
match *self
{
ZipError::Io(ref io_err) => {
("Io Error: ".to_string() + io_err.description()).into_cow()
},
ZipError::InvalidZipFile(msg) | ZipError::UnsupportedZipFile(msg) => {
(self.description().to_string() + ": " + msg).into_cow()
},
ZipError::ReaderUnavailable => {
self.description().into_cow()
},
}
}
}
impl error::FromError<io::IoError> for ZipError impl error::FromError<io::IoError> for ZipError
{ {
fn from_error(err: io::IoError) -> ZipError fn from_error(err: io::IoError) -> ZipError
@ -31,6 +54,14 @@ impl error::FromError<io::IoError> for ZipError
} }
} }
impl fmt::Display for ZipError
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error>
{
fmt.write_str(&*self.detail())
}
}
impl error::Error for ZipError impl error::Error for ZipError
{ {
fn description(&self) -> &str fn description(&self) -> &str
@ -44,17 +75,6 @@ impl error::Error for ZipError
} }
} }
fn detail(&self) -> Option<String>
{
match *self
{
ZipError::Io(ref io_err) => io_err.detail(),
ZipError::InvalidZipFile(detail) |
ZipError::UnsupportedZipFile(detail) => Some(detail.to_string()),
ZipError::ReaderUnavailable => None,
}
}
fn cause(&self) -> Option<&error::Error> fn cause(&self) -> Option<&error::Error>
{ {
match *self match *self