Skip to content

Commit 71c3a81

Browse files
jayvdbkamadak
authored andcommitted
Fix clippy lints
1 parent 0eb2932 commit 71c3a81

File tree

7 files changed

+31
-32
lines changed

7 files changed

+31
-32
lines changed

src/isobmff.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<R> Parser<R> where R: BufRead + Seek {
127127
let mut buf = [0; 8];
128128
self.reader.read_exact(&mut buf)?;
129129
let size = match BigEndian::loadu32(&buf, 0) {
130-
0 => Some(std::u64::MAX),
130+
0 => Some(u64::MAX),
131131
1 => read64(&mut self.reader)?.checked_sub(16),
132132
x => u64::from(x).checked_sub(8),
133133
}.ok_or("Invalid box size")?;
@@ -138,7 +138,7 @@ impl<R> Parser<R> where R: BufRead + Seek {
138138
fn read_file_level_box(&mut self, size: u64) -> Result<Vec<u8>, Error> {
139139
let mut buf;
140140
match size {
141-
std::u64::MAX => {
141+
u64::MAX => {
142142
buf = Vec::new();
143143
self.reader.read_to_end(&mut buf)?;
144144
},
@@ -154,7 +154,7 @@ impl<R> Parser<R> where R: BufRead + Seek {
154154

155155
fn skip_file_level_box(&mut self, size: u64) -> Result<(), Error> {
156156
match size {
157-
std::u64::MAX => self.reader.seek(SeekFrom::End(0))?,
157+
u64::MAX => self.reader.seek(SeekFrom::End(0))?,
158158
_ => self.reader.seek(SeekFrom::Current(
159159
size.try_into().or(Err("Large seek not supported"))?))?,
160160
};
@@ -164,7 +164,7 @@ impl<R> Parser<R> where R: BufRead + Seek {
164164
fn parse_ftyp(&mut self, mut boxp: BoxSplitter) -> Result<(), Error> {
165165
let head = boxp.slice(8)?;
166166
let _major_brand = &head[0..4];
167-
let _minor_version = BigEndian::loadu32(&head, 4);
167+
let _minor_version = BigEndian::loadu32(head, 4);
168168
while let Ok(compat_brand) = boxp.array4() {
169169
if HEIF_BRANDS.contains(&compat_brand) {
170170
return Ok(());
@@ -301,9 +301,8 @@ impl<R> Parser<R> where R: BufRead + Seek {
301301
};
302302
for _ in 0..entry_count {
303303
let (boxtype, body) = boxp.child_box()?;
304-
match boxtype {
305-
b"infe" => self.parse_infe(body)?,
306-
_ => {},
304+
if boxtype == b"infe" {
305+
self.parse_infe(body)?;
307306
}
308307
}
309308
Ok(())
@@ -483,7 +482,7 @@ mod tests {
483482
// to the end of the file
484483
let mut p = Parser::new(Cursor::new(b"\0\0\0\0abcd"));
485484
assert_eq!(p.read_box_header().unwrap(),
486-
Some((std::u64::MAX, *b"abcd")));
485+
Some((u64::MAX, *b"abcd")));
487486
// largesize
488487
let mut p = Parser::new(Cursor::new(
489488
b"\0\0\0\x01abcd\0\0\0\0\0\0\0\x10"));
@@ -498,7 +497,7 @@ mod tests {
498497
let mut p = Parser::new(Cursor::new(
499498
b"\0\0\0\x01abcd\xff\xff\xff\xff\xff\xff\xff\xff"));
500499
assert_eq!(p.read_box_header().unwrap(),
501-
Some((std::u64::MAX.wrapping_sub(16), *b"abcd")));
500+
Some((u64::MAX.wrapping_sub(16), *b"abcd")));
502501
}
503502

504503
#[test]

src/tag.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ generate_well_known_tag_constants!(
749749
);
750750

751751
// For Value::display_as().
752-
pub fn display_value_as<'a>(value: &'a Value, tag: Tag) -> value::Display<'a> {
752+
pub fn display_value_as(value: &Value, tag: Tag) -> value::Display<'_> {
753753
match get_tag_info(tag) {
754754
Some(ti) => value::Display { fmt: ti.dispval, value: value },
755755
None => value::Display { fmt: d_default, value: value },
@@ -1463,7 +1463,7 @@ where I: IntoIterator<Item = T>, T: fmt::Display {
14631463

14641464
struct AsciiDisplay<'a>(&'a [u8]);
14651465

1466-
impl<'a> fmt::Display for AsciiDisplay<'a> {
1466+
impl fmt::Display for AsciiDisplay<'_> {
14671467
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14681468
d_sub_ascii(f, self.0)
14691469
}

src/tiff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl<'a> DisplayValue<'a> {
507507
}
508508
}
509509

510-
impl<'a> fmt::Display for DisplayValue<'a> {
510+
impl fmt::Display for DisplayValue<'_> {
511511
#[inline]
512512
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
513513
self.value_display.fmt(f)

src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<T> BufReadExt for T where T: io::BufRead {
5858
fn discard_exact(&mut self, mut len: usize) -> io::Result<()> {
5959
while len > 0 {
6060
let consume_len = match self.fill_buf() {
61-
Ok(buf) if buf.is_empty() =>
61+
Ok([]) =>
6262
return Err(io::Error::new(
6363
io::ErrorKind::UnexpectedEof, "unexpected EOF")),
6464
Ok(buf) => buf.len().min(len),

src/value.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub struct UIntIter<'a> {
224224
iter: Box<dyn ExactSizeIterator<Item=u32> + 'a>
225225
}
226226

227-
impl<'a> Iterator for UIntIter<'a> {
227+
impl Iterator for UIntIter<'_> {
228228
type Item = u32;
229229

230230
#[inline]
@@ -238,7 +238,7 @@ impl<'a> Iterator for UIntIter<'a> {
238238
}
239239
}
240240

241-
impl<'a> ExactSizeIterator for UIntIter<'a> {}
241+
impl ExactSizeIterator for UIntIter<'_> {}
242242

243243
/// Helper struct for printing a value in a tag-specific format.
244244
#[derive(Copy, Clone)]
@@ -247,7 +247,7 @@ pub struct Display<'a> {
247247
pub value: &'a Value,
248248
}
249249

250-
impl<'a> fmt::Display for Display<'a> {
250+
impl fmt::Display for Display<'_> {
251251
#[inline]
252252
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
253253
(self.fmt)(f, self.value)
@@ -292,7 +292,7 @@ where F: Fn() -> T, T: Iterator<Item = I>, I: fmt::Debug {
292292

293293
struct AsciiDebugAdapter<'a>(&'a [u8]);
294294

295-
impl<'a> fmt::Debug for AsciiDebugAdapter<'a> {
295+
impl fmt::Debug for AsciiDebugAdapter<'_> {
296296
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
297297
f.write_char('"')?;
298298
self.0.iter().try_for_each(|&c| match c {
@@ -306,7 +306,7 @@ impl<'a> fmt::Debug for AsciiDebugAdapter<'a> {
306306

307307
struct HexDebugAdapter<'a>(&'a [u8]);
308308

309-
impl<'a> fmt::Debug for HexDebugAdapter<'a> {
309+
impl fmt::Debug for HexDebugAdapter<'_> {
310310
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
311311
f.write_str("0x")?;
312312
self.0.iter().try_for_each(|x| write!(f, "{:02x}", x))
@@ -471,9 +471,9 @@ fn parse_byte(data: &[u8], offset: usize, count: usize) -> Value {
471471
fn parse_ascii(data: &[u8], offset: usize, count: usize) -> Value {
472472
// Any ASCII field can contain multiple strings [TIFF6 Image File
473473
// Directory].
474-
let iter = (&data[offset .. offset + count]).split(|&b| b == b'\0');
474+
let iter = data[offset .. offset + count].split(|&b| b == b'\0');
475475
let mut v: Vec<Vec<u8>> = iter.map(|x| x.to_vec()).collect();
476-
if v.last().map_or(false, |x| x.len() == 0) {
476+
if v.last().map_or(false, |x| x.is_empty()) {
477477
v.pop();
478478
}
479479
Value::Ascii(v)

src/writer.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct Ifd<'a> {
7474
jpeg: Option<&'a [u8]>,
7575
}
7676

77-
impl<'a> Ifd<'a> {
77+
impl Ifd<'_> {
7878
fn is_empty(&self) -> bool {
7979
self.tiff_fields.is_empty() &&
8080
self.exif_fields.is_empty() &&
@@ -191,7 +191,7 @@ impl<'a> Writer<'a> {
191191
ifd_num_ck.ok_or(Error::InvalidFormat("Too many IFDs"))?;
192192
if ifd_num > 0 {
193193
let next_ifd_offset = pad_and_get_offset(w)?;
194-
let origpos = w.seek(SeekFrom::Current(0))?;
194+
let origpos = w.stream_position()?;
195195
w.seek(SeekFrom::Start(next_ifd_offset_offset as u64))?;
196196
match little_endian {
197197
false => BigEndian::writeu32(w, next_ifd_offset)?,
@@ -342,15 +342,15 @@ fn write_image<W, E>(w: &mut W, ws: &WriterState, ifd: &Ifd)
342342
strip_offsets_offset, tile_offsets_offset, jpeg_offset) =
343343
write_ifd_and_fields::<_, E>(
344344
w, &ws.tiff_fields, ws.tiff_ifd_offset)?;
345-
if ws.exif_fields.len() > 0 {
345+
if !ws.exif_fields.is_empty() {
346346
write_ifd_and_fields::<_, E>(
347347
w, &ws.exif_fields, ws.exif_ifd_offset)?;
348348
}
349-
if ws.gps_fields.len() > 0 {
349+
if !ws.gps_fields.is_empty() {
350350
write_ifd_and_fields::<_, E>(
351351
w, &ws.gps_fields, ws.gps_ifd_offset)?;
352352
}
353-
if ws.interop_fields.len() > 0 {
353+
if !ws.interop_fields.is_empty() {
354354
write_ifd_and_fields::<_, E>(
355355
w, &ws.interop_fields, ws.interop_ifd_offset)?;
356356
}
@@ -361,7 +361,7 @@ fn write_image<W, E>(w: &mut W, ws: &WriterState, ifd: &Ifd)
361361
strip_offsets.push(get_offset(w)?);
362362
w.write_all(strip)?;
363363
}
364-
let origpos = w.seek(SeekFrom::Current(0))?;
364+
let origpos = w.stream_position()?;
365365
w.seek(SeekFrom::Start(strip_offsets_offset as u64))?;
366366
for ofs in strip_offsets {
367367
E::writeu32(w, ofs)?;
@@ -374,7 +374,7 @@ fn write_image<W, E>(w: &mut W, ws: &WriterState, ifd: &Ifd)
374374
tile_offsets.push(get_offset(w)?);
375375
w.write_all(tile)?;
376376
}
377-
let origpos = w.seek(SeekFrom::Current(0))?;
377+
let origpos = w.stream_position()?;
378378
w.seek(SeekFrom::Start(tile_offsets_offset as u64))?;
379379
for ofs in tile_offsets {
380380
E::writeu32(w, ofs)?;
@@ -384,7 +384,7 @@ fn write_image<W, E>(w: &mut W, ws: &WriterState, ifd: &Ifd)
384384
if let Some(jpeg) = ifd.jpeg {
385385
let offset = get_offset(w)?;
386386
w.write_all(jpeg)?;
387-
let origpos = w.seek(SeekFrom::Current(0))?;
387+
let origpos = w.stream_position()?;
388388
w.seek(SeekFrom::Start(jpeg_offset as u64))?;
389389
E::writeu32(w, offset)?;
390390
w.seek(SeekFrom::Start(origpos))?;
@@ -552,7 +552,7 @@ fn compose_value<E>(value: &Value)
552552

553553
fn write_at<W>(w: &mut W, buf: &[u8], offset: u32)
554554
-> io::Result<()> where W: Write + Seek {
555-
let orig = w.seek(SeekFrom::Current(0))?;
555+
let orig = w.stream_position()?;
556556
w.seek(SeekFrom::Start(offset as u64))?;
557557
w.write_all(buf)?;
558558
w.seek(SeekFrom::Start(orig))?;
@@ -562,7 +562,7 @@ fn write_at<W>(w: &mut W, buf: &[u8], offset: u32)
562562
// Aligns `w` to the two-byte (word) boundary and returns the new offset.
563563
fn pad_and_get_offset<W>(w: &mut W)
564564
-> Result<u32, Error> where W: Write + Seek {
565-
let mut pos = w.seek(SeekFrom::Current(0))?;
565+
let mut pos = w.stream_position()?;
566566
if pos >= (1 << 32) - 1 {
567567
return Err(Error::TooBig("Offset too large"));
568568
}
@@ -575,7 +575,7 @@ fn pad_and_get_offset<W>(w: &mut W)
575575

576576
fn get_offset<W>(w: &mut W)
577577
-> Result<u32, Error> where W: Write + Seek {
578-
let pos = w.seek(SeekFrom::Current(0))?;
578+
let pos = w.stream_position()?;
579579
if pos as u32 as u64 != pos {
580580
return Err(Error::TooBig("Offset too large"));
581581
}

tests/rwrcmp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn rwr_compare<P>(path: P) where P: AsRef<Path> {
106106
if let Some(ref tiles) = tiles {
107107
writer.set_tiles(tiles, In::PRIMARY);
108108
}
109-
if let Some(ref tn_jpeg) = tn_jpeg {
109+
if let Some(tn_jpeg) = tn_jpeg {
110110
writer.set_jpeg(tn_jpeg, In::THUMBNAIL);
111111
}
112112
let mut out = Cursor::new(Vec::new());

0 commit comments

Comments
 (0)