From 70532d7b483760632ca57215027fd210430dab11 Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Sat, 10 Jan 2015 15:52:05 +0100 Subject: [PATCH] Fixed int/uint, and use as much stable as possible --- src/crc32.rs | 6 +++--- src/lib.rs | 1 + src/reader.rs | 10 +++++----- src/reader_spec.rs | 16 ++++++++-------- src/spec.rs | 2 +- src/util.rs | 6 +++--- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/crc32.rs b/src/crc32.rs index 2fba0aeb..d5468499 100644 --- a/src/crc32.rs +++ b/src/crc32.rs @@ -55,7 +55,7 @@ pub fn update(prev: u32, buf: &[u8]) -> u32 for byte in buf.iter() { - crc = CRC32_TABLE[((crc ^ (*byte as u32)) & 0xFF) as uint] ^ (crc >> 8); + crc = CRC32_TABLE[((crc ^ (*byte as u32)) & 0xFF) as usize] ^ (crc >> 8); } return crc ^ !0u32; @@ -90,7 +90,7 @@ impl Crc32Reader impl Reader for Crc32Reader { - fn read(&mut self, buf: &mut [u8]) -> io::IoResult + fn read(&mut self, buf: &mut [u8]) -> io::IoResult { let count = match self.inner.read(buf) { @@ -103,7 +103,7 @@ impl Reader for Crc32Reader }, Err(e) => return Err(e), }; - self.crc = update(self.crc, buf.slice_to(count)); + self.crc = update(self.crc, &buf[0..count]); Ok(count) } } diff --git a/src/lib.rs b/src/lib.rs index d0cd29f3..b95c1c3c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ #![feature(unsafe_destructor)] #![warn(missing_docs)] +#![allow(unstable)] #[macro_use] extern crate log; extern crate time; diff --git a/src/reader.rs b/src/reader.rs index e6e6e9e0..02eb4896 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -38,7 +38,7 @@ pub struct ZipReader { inner: RefCell, files: Vec, - names_map: HashMap, + names_map: HashMap, } fn unsupported_zip_error(detail: &'static str) -> ZipResult @@ -56,13 +56,13 @@ impl ZipReader if footer.disk_number != footer.disk_with_central_directory { return unsupported_zip_error("Support for multi-disk files is not implemented") } let directory_start = footer.central_directory_offset as i64; - let number_of_files = footer.number_of_files_on_this_disk as uint; + let number_of_files = footer.number_of_files_on_this_disk as usize; let mut files = Vec::with_capacity(number_of_files); let mut names_map = HashMap::new(); try!(reader.seek(directory_start, io::SeekSet)); - for _ in range(0, number_of_files) + for _ in (0 .. number_of_files) { let file = try!(reader_spec::central_header_to_zip_file(&mut reader)); names_map.insert(file.file_name.clone(), files.len()); @@ -75,7 +75,7 @@ impl ZipReader /// An iterator over the information of all contained files. pub fn files(&self) -> ::std::slice::Iter { - self.files.as_slice().iter() + (&*self.files).iter() } /// Search for a file entry by name @@ -103,7 +103,7 @@ impl ZipReader try!(inner_reader.seek(pos, io::SeekSet)); let refmut_reader = ::util::RefMutReader::new(inner_reader); - let limit_reader = io::util::LimitReader::new(refmut_reader, file.compressed_size as uint); + let limit_reader = io::util::LimitReader::new(refmut_reader, file.compressed_size as usize); let reader = match file.compression_method { diff --git a/src/reader_spec.rs b/src/reader_spec.rs index bf715a94..94e9e1ae 100644 --- a/src/reader_spec.rs +++ b/src/reader_spec.rs @@ -26,9 +26,9 @@ pub fn central_header_to_zip_file(reader: &mut R) -> ZipResult(reader: &mut R) -> ZipResult String::from_utf8_lossy(file_name_raw.as_slice()).into_owned(), - false => ::cp437::to_string(file_name_raw.as_slice()), + true => String::from_utf8_lossy(&*file_name_raw).into_owned(), + false => ::cp437::to_string(&*file_name_raw), }; let file_comment = match is_utf8 { - true => String::from_utf8_lossy(file_comment_raw.as_slice()).into_owned(), - false => ::cp437::to_string(file_comment_raw.as_slice()), + true => String::from_utf8_lossy(&*file_comment_raw).into_owned(), + false => ::cp437::to_string(&*file_comment_raw), }; // Remember end of central header @@ -80,7 +80,7 @@ pub fn central_header_to_zip_file(reader: &mut R) -> ZipResult Tm let years = (date & 0b1111111000000000) >> 9; let datetime = format!("{:04}-{:02}-{:02} {:02}:{:02}:{:02}", - years as uint + 1980, + years as u32 + 1980, months, days, hours, @@ -20,7 +20,7 @@ pub fn msdos_datetime_to_tm(time: u16, date: u16) -> Tm seconds); let format = "%Y-%m-%d %H:%M:%S"; - match time::strptime(datetime.as_slice(), format) + match time::strptime(&*datetime, format) { Ok(tm) => tm, Err(m) => { debug!("Failed parsing date: {}", m); time::empty_tm() }, @@ -52,7 +52,7 @@ impl<'a, R: Reader> RefMutReader<'a, R> impl<'a, R: Reader> Reader for RefMutReader<'a, R> { - fn read(&mut self, buf: &mut [u8]) -> ::std::io::IoResult + fn read(&mut self, buf: &mut [u8]) -> ::std::io::IoResult { self.inner.read(buf) }