Namespaced enums fix

This commit is contained in:
Mathijs van de Nes 2014-11-19 18:43:07 +01:00
parent 1f08866d84
commit ccdba3efc0
5 changed files with 44 additions and 44 deletions

View file

@ -1,9 +1,9 @@
use crc32::Crc32Reader; use crc32::Crc32Reader;
use types::ZipFile; use types::ZipFile;
use compression; use compression::CompressionMethod;
use spec; use spec;
use reader_spec; use reader_spec;
use result::ZipResult; use result::{ZipResult, ZipError};
use std::io; use std::io;
use std::cell::RefCell; use std::cell::RefCell;
use flate2::FlateReader; use flate2::FlateReader;
@ -40,7 +40,7 @@ pub struct ZipReader<T>
fn unsupported_zip_error<T>(detail: &'static str) -> ZipResult<T> fn unsupported_zip_error<T>(detail: &'static str) -> ZipResult<T>
{ {
Err(::result::UnsupportedZipFile(detail)) Err(ZipError::UnsupportedZipFile(detail))
} }
impl<T: Reader+Seek> ZipReader<T> impl<T: Reader+Seek> ZipReader<T>
@ -80,7 +80,7 @@ impl<T: Reader+Seek> ZipReader<T>
let mut inner_reader = match self.inner.try_borrow_mut() let mut inner_reader = match self.inner.try_borrow_mut()
{ {
Some(reader) => reader, Some(reader) => reader,
None => return Err(::result::ReaderUnavailable), None => return Err(ZipError::ReaderUnavailable),
}; };
let pos = file.data_start as i64; let pos = file.data_start as i64;
@ -95,7 +95,7 @@ impl<T: Reader+Seek> ZipReader<T>
let reader = match file.compression_method let reader = match file.compression_method
{ {
compression::Stored => CompressionMethod::Stored =>
{ {
box box
Crc32Reader::new( Crc32Reader::new(
@ -103,7 +103,7 @@ impl<T: Reader+Seek> ZipReader<T>
file.crc32) file.crc32)
as Box<Reader> as Box<Reader>
}, },
compression::Deflated => CompressionMethod::Deflated =>
{ {
let deflate_reader = limit_reader.deflate_decode(); let deflate_reader = limit_reader.deflate_decode();
box box

View file

@ -1,7 +1,7 @@
use std::io; use std::io;
use result::ZipResult; use result::{ZipResult, ZipError};
use compression;
use types::ZipFile; use types::ZipFile;
use compression::CompressionMethod;
use spec; use spec;
use util; use util;
@ -11,7 +11,7 @@ pub fn central_header_to_zip_file<R: Reader+Seek>(reader: &mut R) -> ZipResult<Z
let signature = try!(reader.read_le_u32()); let signature = try!(reader.read_le_u32());
if signature != spec::CENTRAL_DIRECTORY_HEADER_SIGNATURE if signature != spec::CENTRAL_DIRECTORY_HEADER_SIGNATURE
{ {
return Err(::result::InvalidZipFile("Invalid Central Directory header")) return Err(ZipError::InvalidZipFile("Invalid Central Directory header"))
} }
try!(reader.read_le_u16()); try!(reader.read_le_u16());
@ -55,7 +55,7 @@ pub fn central_header_to_zip_file<R: Reader+Seek>(reader: &mut R) -> ZipResult<Z
let signature = try!(reader.read_le_u32()); let signature = try!(reader.read_le_u32());
if signature != spec::LOCAL_FILE_HEADER_SIGNATURE if signature != spec::LOCAL_FILE_HEADER_SIGNATURE
{ {
return Err(::result::InvalidZipFile("Invalid local file header")) return Err(ZipError::InvalidZipFile("Invalid local file header"))
} }
try!(reader.seek(22, io::SeekCur)); try!(reader.seek(22, io::SeekCur));
@ -68,7 +68,7 @@ pub fn central_header_to_zip_file<R: Reader+Seek>(reader: &mut R) -> ZipResult<Z
let mut result = ZipFile let mut result = ZipFile
{ {
encrypted: encrypted, encrypted: encrypted,
compression_method: FromPrimitive::from_u16(compression_method).unwrap_or(compression::Unknown), compression_method: FromPrimitive::from_u16(compression_method).unwrap_or(CompressionMethod::Unknown),
last_modified_time: util::msdos_datetime_to_tm(last_mod_time, last_mod_date), last_modified_time: util::msdos_datetime_to_tm(last_mod_time, last_mod_date),
crc32: crc32, crc32: crc32,
compressed_size: compressed_size as u64, compressed_size: compressed_size as u64,

View file

@ -26,7 +26,7 @@ impl error::FromError<io::IoError> for ZipError
{ {
fn from_error(err: io::IoError) -> ZipError fn from_error(err: io::IoError) -> ZipError
{ {
Io(err) ZipError::Io(err)
} }
} }
@ -36,10 +36,10 @@ impl error::Error for ZipError
{ {
match *self match *self
{ {
Io(ref io_err) => io_err.description(), ZipError::Io(ref io_err) => io_err.description(),
InvalidZipFile(..) => "Invalid Zip File", ZipError::InvalidZipFile(..) => "Invalid Zip File",
UnsupportedZipFile(..) => "Unsupported Zip File", ZipError::UnsupportedZipFile(..) => "Unsupported Zip File",
ReaderUnavailable => "No reader available", ZipError::ReaderUnavailable => "No reader available",
} }
} }
@ -47,10 +47,10 @@ impl error::Error for ZipError
{ {
match *self match *self
{ {
Io(ref io_err) => io_err.detail(), ZipError::Io(ref io_err) => io_err.detail(),
InvalidZipFile(detail) | ZipError::InvalidZipFile(detail) |
UnsupportedZipFile(detail) => Some(detail.to_string()), ZipError::UnsupportedZipFile(detail) => Some(detail.to_string()),
ReaderUnavailable => None, ZipError::ReaderUnavailable => None,
} }
} }
@ -58,7 +58,7 @@ impl error::Error for ZipError
{ {
match *self match *self
{ {
Io(ref io_err) => Some(io_err as &error::Error), ZipError::Io(ref io_err) => Some(io_err as &error::Error),
_ => None, _ => None,
} }
} }

View file

@ -1,5 +1,5 @@
use std::io; use std::io;
use result::ZipResult; use result::{ZipResult, ZipError};
use std::iter::range_step_inclusive; use std::iter::range_step_inclusive;
pub static LOCAL_FILE_HEADER_SIGNATURE : u32 = 0x04034b50; pub static LOCAL_FILE_HEADER_SIGNATURE : u32 = 0x04034b50;
@ -24,7 +24,7 @@ impl CentralDirectoryEnd
let magic = try!(reader.read_le_u32()); let magic = try!(reader.read_le_u32());
if magic != CENTRAL_DIRECTORY_END_SIGNATURE if magic != CENTRAL_DIRECTORY_END_SIGNATURE
{ {
return Err(::result::UnsupportedZipFile("Invalid digital signature header")) return Err(ZipError::UnsupportedZipFile("Invalid digital signature header"))
} }
let disk_number = try!(reader.read_le_u16()); let disk_number = try!(reader.read_le_u16());
let disk_with_central_directory = try!(reader.read_le_u16()); let disk_with_central_directory = try!(reader.read_le_u16());
@ -69,7 +69,7 @@ impl CentralDirectoryEnd
} }
} }
} }
Err(::result::UnsupportedZipFile("Could not find central directory end")) Err(ZipError::UnsupportedZipFile("Could not find central directory end"))
} }
pub fn write<T: Writer>(&self, writer: &mut T) -> ZipResult<()> pub fn write<T: Writer>(&self, writer: &mut T) -> ZipResult<()>

View file

@ -1,9 +1,9 @@
use compression; use compression::CompressionMethod;
use types::ZipFile; use types::ZipFile;
use spec; use spec;
use writer_spec; use writer_spec;
use crc32; use crc32;
use result::ZipResult; use result::{ZipResult, ZipError};
use std::default::Default; use std::default::Default;
use std::io; use std::io;
use std::mem; use std::mem;
@ -63,9 +63,9 @@ impl<W: Writer+Seek> Writer for ZipWriter<W>
self.stats.update(buf); self.stats.update(buf);
match self.inner match self.inner
{ {
Storer(ref mut w) => w.write(buf), GenericZipWriter::Storer(ref mut w) => w.write(buf),
Deflater(ref mut w) => w.write(buf), GenericZipWriter::Deflater(ref mut w) => w.write(buf),
Closed => Err(io::standard_error(io::Closed)), GenericZipWriter::Closed => Err(io::standard_error(io::Closed)),
} }
} }
} }
@ -88,14 +88,14 @@ impl<W: Writer+Seek> ZipWriter<W>
{ {
ZipWriter ZipWriter
{ {
inner: Storer(inner), inner: GenericZipWriter::Storer(inner),
files: Vec::new(), files: Vec::new(),
stats: Default::default(), stats: Default::default(),
} }
} }
/// Start a new file for with the requested compression method. /// Start a new file for with the requested compression method.
pub fn start_file(&mut self, name: &str, compression: compression::CompressionMethod) -> ZipResult<()> pub fn start_file(&mut self, name: &str, compression: CompressionMethod) -> ZipResult<()>
{ {
try!(self.finish_file()); try!(self.finish_file());
@ -135,7 +135,7 @@ impl<W: Writer+Seek> ZipWriter<W>
fn finish_file(&mut self) -> ZipResult<()> fn finish_file(&mut self) -> ZipResult<()>
{ {
try!(self.inner.switch_to(compression::Stored)); try!(self.inner.switch_to(CompressionMethod::Stored));
let writer = self.inner.get_plain(); let writer = self.inner.get_plain();
let file = match self.files.last_mut() let file = match self.files.last_mut()
@ -159,7 +159,7 @@ impl<W: Writer+Seek> ZipWriter<W>
pub fn finish(mut self) -> ZipResult<W> pub fn finish(mut self) -> ZipResult<W>
{ {
try!(self.finalize()); try!(self.finalize());
let inner = mem::replace(&mut self.inner, Closed); let inner = mem::replace(&mut self.inner, GenericZipWriter::Closed);
Ok(inner.unwrap()) Ok(inner.unwrap())
} }
@ -213,20 +213,20 @@ impl<W: Writer+Seek> Drop for ZipWriter<W>
impl<W: Writer+Seek> GenericZipWriter<W> impl<W: Writer+Seek> GenericZipWriter<W>
{ {
fn switch_to(&mut self, compression: compression::CompressionMethod) -> ZipResult<()> fn switch_to(&mut self, compression: CompressionMethod) -> ZipResult<()>
{ {
let bare = match mem::replace(self, Closed) let bare = match mem::replace(self, GenericZipWriter::Closed)
{ {
Storer(w) => w, GenericZipWriter::Storer(w) => w,
Deflater(w) => try!(w.finish()), GenericZipWriter::Deflater(w) => try!(w.finish()),
Closed => try!(Err(io::standard_error(io::Closed))), GenericZipWriter::Closed => try!(Err(io::standard_error(io::Closed))),
}; };
*self = match compression *self = match compression
{ {
compression::Stored => Storer(bare), CompressionMethod::Stored => GenericZipWriter::Storer(bare),
compression::Deflated => Deflater(bare.deflate_encode(flate2::Default)), CompressionMethod::Deflated => GenericZipWriter::Deflater(bare.deflate_encode(flate2::Default)),
_ => return Err(::result::UnsupportedZipFile("Unsupported compression")), _ => return Err(ZipError::UnsupportedZipFile("Unsupported compression")),
}; };
Ok(()) Ok(())
@ -236,7 +236,7 @@ impl<W: Writer+Seek> GenericZipWriter<W>
{ {
match *self match *self
{ {
Closed => true, GenericZipWriter::Closed => true,
_ => false, _ => false,
} }
} }
@ -245,7 +245,7 @@ impl<W: Writer+Seek> GenericZipWriter<W>
{ {
match *self match *self
{ {
Storer(ref mut w) => w, GenericZipWriter::Storer(ref mut w) => w,
_ => panic!("Should have switched to stored beforehand"), _ => panic!("Should have switched to stored beforehand"),
} }
} }
@ -254,7 +254,7 @@ impl<W: Writer+Seek> GenericZipWriter<W>
{ {
match self match self
{ {
Storer(w) => w, GenericZipWriter::Storer(w) => w,
_ => panic!("Should have switched to stored beforehand"), _ => panic!("Should have switched to stored beforehand"),
} }
} }