From 514b7cddaad720042e4989896937a1e58cddb63d Mon Sep 17 00:00:00 2001 From: Birk Tjelmeland Date: Fri, 3 May 2019 22:17:00 +0200 Subject: [PATCH] Change minimal rustc version to 1.24.1 --- .travis.yml | 7 +++--- src/decoder/ifd.rs | 11 +++++----- src/decoder/mod.rs | 13 ++++++------ src/encoder/colortype.rs | 2 +- src/encoder/mod.rs | 46 +++++++++++++++++++++++----------------- src/encoder/writer.rs | 2 +- tests/decode_images.rs | 6 +++--- 7 files changed, 48 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index b4f863c..2a633ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: rust rust: - - stable - - beta - - nightly + - 1.24.1 + - stable + - beta + - nightly diff --git a/src/decoder/ifd.rs b/src/decoder/ifd.rs index 057ce6e..ba663d9 100644 --- a/src/decoder/ifd.rs +++ b/src/decoder/ifd.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::io::{self, Read, Seek}; +use std::mem; use super::stream::{ByteOrder, EndianReader, SmartReader}; use {TiffError, TiffFormatError, TiffResult, TiffUnsupportedError}; @@ -27,9 +28,9 @@ macro_rules! tags { } } pub fn to_u16(&self) -> u16 { - match self { + match *self { $( Tag::$tag => $val, )* - Tag::Unknown(n) => *n, + Tag::Unknown(n) => n, } } } @@ -174,7 +175,7 @@ impl Entry { ])) } (Type::SHORT, n) => { - if n as usize > limits.decoding_buffer_size / std::mem::size_of::() { + if n as usize > limits.decoding_buffer_size / mem::size_of::() { return Err(TiffError::LimitsExceeded); } let mut v = Vec::with_capacity(n as usize); @@ -186,7 +187,7 @@ impl Entry { } (Type::LONG, 1) => Ok(Unsigned(try!(self.r(bo).read_u32()))), (Type::LONG, n) => { - if n as usize > limits.decoding_buffer_size / std::mem::size_of::() { + if n as usize > limits.decoding_buffer_size / mem::size_of::() { return Err(TiffError::LimitsExceeded); } let mut v = Vec::with_capacity(n as usize); @@ -203,7 +204,7 @@ impl Entry { Ok(Rational(numerator, denominator)) } (Type::RATIONAL, n) => { - if n as usize > limits.decoding_buffer_size / std::mem::size_of::() { + if n as usize > limits.decoding_buffer_size / mem::size_of::() { return Err(TiffError::LimitsExceeded); } let mut v = Vec::with_capacity(n as usize); diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index 71da7dd..21805b7 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -1,6 +1,7 @@ use num_traits::{FromPrimitive, Num}; use std::collections::HashMap; use std::io::{self, Read, Seek}; +use std::cmp; use {ColorType, TiffError, TiffFormatError, TiffResult, TiffUnsupportedError}; @@ -38,7 +39,7 @@ impl DecodingResult { } pub fn as_buffer(&mut self, start: usize) -> DecodingBuffer { - match self { + match *self { DecodingResult::U8(ref mut buf) => DecodingBuffer::U8(&mut buf[start..]), DecodingResult::U16(ref mut buf) => DecodingBuffer::U16(&mut buf[start..]), } @@ -55,14 +56,14 @@ pub enum DecodingBuffer<'a> { impl<'a> DecodingBuffer<'a> { fn len(&self) -> usize { - match self { + match *self { DecodingBuffer::U8(ref buf) => buf.len(), DecodingBuffer::U16(ref buf) => buf.len(), } } fn byte_len(&self) -> usize { - match self { + match *self { DecodingBuffer::U8(_) => 1, DecodingBuffer::U16(_) => 2, } @@ -72,7 +73,7 @@ impl<'a> DecodingBuffer<'a> { where 'a: 'b, { - match self { + match *self { DecodingBuffer::U8(ref mut buf) => DecodingBuffer::U8(buf), DecodingBuffer::U16(ref mut buf) => DecodingBuffer::U16(buf), } @@ -661,7 +662,7 @@ impl Decoder { .get_tag_u32(ifd::Tag::RowsPerStrip) .unwrap_or(self.height) as usize; - let strip_height = std::cmp::min( + let strip_height = cmp::min( rows_per_strip, self.height as usize - index * rows_per_strip, ); @@ -716,7 +717,7 @@ impl Decoder { .get_tag_u32(ifd::Tag::RowsPerStrip) .unwrap_or(self.height) as usize; - let strip_height = std::cmp::min( + let strip_height = cmp::min( rows_per_strip, self.height as usize - index * rows_per_strip, ); diff --git a/src/encoder/colortype.rs b/src/encoder/colortype.rs index bc52a3d..a348ee7 100644 --- a/src/encoder/colortype.rs +++ b/src/encoder/colortype.rs @@ -1,4 +1,4 @@ -use crate::decoder::PhotometricInterpretation; +use decoder::PhotometricInterpretation; /// Trait for different colortypes that can be encoded. pub trait ColorType { diff --git a/src/encoder/mod.rs b/src/encoder/mod.rs index a1da74e..ed7ab56 100644 --- a/src/encoder/mod.rs +++ b/src/encoder/mod.rs @@ -2,8 +2,8 @@ use byteorder::NativeEndian; use std::collections::BTreeMap; use std::io::{Seek, Write}; -use crate::decoder::ifd::{self, Tag}; -use crate::error::{TiffError, TiffFormatError, TiffResult}; +use decoder::ifd::{self, Tag}; +use error::{TiffError, TiffFormatError, TiffResult}; pub mod colortype; mod writer; @@ -61,7 +61,7 @@ impl TiffValue for [u16] { fn write(&self, writer: &mut TiffWriter) -> TiffResult<()> { // We write using nativeedian so this sould be safe let slice = - unsafe { std::slice::from_raw_parts(self.as_ptr() as *const u8, self.len() * 2) }; + unsafe { ::std::slice::from_raw_parts(self.as_ptr() as *const u8, self.len() * 2) }; writer.write_bytes(slice)?; Ok(()) } @@ -78,7 +78,7 @@ impl TiffValue for [u32] { fn write(&self, writer: &mut TiffWriter) -> TiffResult<()> { // We write using nativeedian so this sould be safe let slice = - unsafe { std::slice::from_raw_parts(self.as_ptr() as *const u8, self.len() * 4) }; + unsafe { ::std::slice::from_raw_parts(self.as_ptr() as *const u8, self.len() * 4) }; writer.write_bytes(slice)?; Ok(()) } @@ -199,6 +199,8 @@ impl<'a, T: TiffValue + ?Sized> TiffValue for &'a T { /// # Examples /// ``` /// # extern crate tempfile; +/// # extern crate tiff; +/// # fn main() { /// # let mut file = tempfile::tempfile().unwrap(); /// # let image_data = vec![0; 100*100*3]; /// use tiff::encoder::*; @@ -206,6 +208,7 @@ impl<'a, T: TiffValue + ?Sized> TiffValue for &'a T { /// let mut tiff = TiffEncoder::new(&mut file).unwrap(); /// /// tiff.write_image::(100, 100, &image_data).unwrap(); +/// # } /// ``` pub struct TiffEncoder { writer: TiffWriter, @@ -248,12 +251,12 @@ impl TiffEncoder { [C::Inner]: TiffValue, { let num_pix = (width as usize).checked_mul(height as usize) - .ok_or_else(|| std::io::Error::new( - std::io::ErrorKind::InvalidInput, + .ok_or_else(|| ::std::io::Error::new( + ::std::io::ErrorKind::InvalidInput, "Image width * height exceeds usize"))?; if data.len() < num_pix { - return Err(std::io::Error::new( - std::io::ErrorKind::InvalidData, + return Err(::std::io::Error::new( + ::std::io::ErrorKind::InvalidData, "Input data slice is undersized for provided dimensions").into()); } @@ -274,7 +277,7 @@ impl TiffEncoder { /// /// You should call `finish` on this when you are finished with it. /// Encoding can silently fail while this is dropping. -pub struct DirectoryEncoder<'a, W: Write + Seek> { +pub struct DirectoryEncoder<'a, W: 'a + Write + Seek> { writer: &'a mut TiffWriter, dropped: bool, // We use BTreeMap to make sure tags are written in correct order @@ -282,7 +285,7 @@ pub struct DirectoryEncoder<'a, W: Write + Seek> { ifd: BTreeMap)>, } -impl<'a, W: Write + Seek> DirectoryEncoder<'a, W> { +impl<'a, W: 'a + Write + Seek> DirectoryEncoder<'a, W> { fn new(writer: &'a mut TiffWriter) -> TiffResult> { writer.pad_word_boundary()?; let ifd_pointer_pos = writer.offset(); @@ -310,7 +313,7 @@ impl<'a, W: Write + Seek> DirectoryEncoder<'a, W> { fn write_directory(&mut self) -> TiffResult { // Start by writing out all values - for (_, _, ref mut bytes) in self.ifd.values_mut() { + for &mut (_, _, ref mut bytes) in self.ifd.values_mut() { if bytes.len() > 4 { let offset = self.writer.offset(); self.writer.write_bytes(bytes)?; @@ -327,7 +330,7 @@ impl<'a, W: Write + Seek> DirectoryEncoder<'a, W> { let offset = self.writer.offset(); self.writer.write_u16(self.ifd.len() as u16)?; - for (tag, (field_type, count, offset)) in self.ifd.iter() { + for (tag, &(ref field_type, ref count, ref offset)) in self.ifd.iter() { self.writer.write_u16(*tag)?; self.writer.write_u16(*field_type)?; self.writer.write_u32(*count)?; @@ -382,6 +385,8 @@ impl<'a, W: Write + Seek> Drop for DirectoryEncoder<'a, W> { /// # Examples /// ``` /// # extern crate tempfile; +/// # extern crate tiff; +/// # fn main() { /// # let mut file = tempfile::tempfile().unwrap(); /// # let image_data = vec![0; 100*100*3]; /// use tiff::encoder::*; @@ -396,8 +401,9 @@ impl<'a, W: Write + Seek> Drop for DirectoryEncoder<'a, W> { /// idx += sample_count; /// } /// image.finish().unwrap(); +/// # } /// ``` -pub struct ImageEncoder<'a, W: Write + Seek, C: ColorType> { +pub struct ImageEncoder<'a, W: 'a + Write + Seek, C: ColorType> { encoder: DirectoryEncoder<'a, W>, strip_idx: u64, strip_count: u64, @@ -407,10 +413,10 @@ pub struct ImageEncoder<'a, W: Write + Seek, C: ColorType> { strip_offsets: Vec, strip_byte_count: Vec, dropped: bool, - _phantom: std::marker::PhantomData, + _phantom: ::std::marker::PhantomData, } -impl<'a, W: Write + Seek, T: ColorType> ImageEncoder<'a, W, T> { +impl<'a, W: 'a + Write + Seek, T: ColorType> ImageEncoder<'a, W, T> { fn new( mut encoder: DirectoryEncoder<'a, W>, width: u32, @@ -448,7 +454,7 @@ impl<'a, W: Write + Seek, T: ColorType> ImageEncoder<'a, W, T> { strip_offsets: Vec::new(), strip_byte_count: Vec::new(), dropped: false, - _phantom: std::marker::PhantomData, + _phantom: ::std::marker::PhantomData, }) } @@ -458,8 +464,8 @@ impl<'a, W: Write + Seek, T: ColorType> ImageEncoder<'a, W, T> { return 0; } - let start_row = std::cmp::min(u64::from(self.height), self.strip_idx * self.rows_per_strip); - let end_row = std::cmp::min( + let start_row = ::std::cmp::min(u64::from(self.height), self.strip_idx * self.rows_per_strip); + let end_row = ::std::cmp::min( u64::from(self.height), (self.strip_idx + 1) * self.rows_per_strip, ); @@ -475,8 +481,8 @@ impl<'a, W: Write + Seek, T: ColorType> ImageEncoder<'a, W, T> { // TODO: Compression let samples = self.next_strip_sample_count(); if value.len() as u64 != samples { - return Err(std::io::Error::new( - std::io::ErrorKind::InvalidData, + return Err(::std::io::Error::new( + ::std::io::ErrorKind::InvalidData, "Slice is wrong size for strip").into()); } diff --git a/src/encoder/writer.rs b/src/encoder/writer.rs index a689f0c..812093f 100644 --- a/src/encoder/writer.rs +++ b/src/encoder/writer.rs @@ -1,4 +1,4 @@ -use crate::error::TiffResult; +use error::TiffResult; use byteorder::{BigEndian, ByteOrder, LittleEndian, NativeEndian, WriteBytesExt}; use std::io::{self, Seek, SeekFrom, Write}; diff --git a/tests/decode_images.rs b/tests/decode_images.rs index 78ceb6c..14ae2ac 100644 --- a/tests/decode_images.rs +++ b/tests/decode_images.rs @@ -1,6 +1,6 @@ extern crate tiff; -use tiff::decoder::{ifd::Tag, ifd::Value, Decoder, DecodingResult}; +use tiff::decoder::{ifd, Decoder, DecodingResult}; use tiff::ColorType; use std::fs::File; @@ -52,9 +52,9 @@ fn test_string_tags() { let path = format!("./tests/images/{}", filename); let img_file = File::open(path).expect("can't open file"); let mut decoder = Decoder::new(img_file).expect("Cannot create decoder"); - let software = decoder.get_tag(Tag::Software).unwrap(); + let software = decoder.get_tag(ifd::Tag::Software).unwrap(); match software { - Value::Ascii(s) => assert_eq!( + ifd::Value::Ascii(s) => assert_eq!( s, String::from("GraphicsMagick 1.2 unreleased Q16 http://www.GraphicsMagick.org/") ),