Skip to content

Commit 7445924

Browse files
committed
Fix clippy lints
1 parent 0eb2932 commit 7445924

File tree

9 files changed

+81
-65
lines changed

9 files changed

+81
-65
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target/
2+
/Cargo.lock

src/isobmff.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct Location {
8888
impl<R> Parser<R> where R: BufRead + Seek {
8989
fn new(reader: R) -> Self {
9090
Self {
91-
reader: reader,
91+
reader,
9292
ftyp_checked: false,
9393
item_id: None,
9494
item_location: None,
@@ -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/reader.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ pub struct Reader {
6363
continue_on_error: bool,
6464
}
6565

66+
impl Default for Reader {
67+
fn default() -> Self {
68+
Self::new()
69+
}
70+
}
71+
6672
impl Reader {
6773
/// Constructs a new `Reader`.
6874
pub fn new() -> Self {
@@ -106,14 +112,14 @@ impl Reader {
106112
/// If an error occurred, `exif::Error` is returned.
107113
pub fn read_raw(&self, data: Vec<u8>) -> Result<Exif, Error> {
108114
let mut parser = tiff::Parser::new();
109-
parser.continue_on_error = self.continue_on_error.then(|| Vec::new());
115+
parser.continue_on_error = self.continue_on_error.then(Vec::new);
110116
parser.parse(&data)?;
111117
let entry_map = parser.entries.iter().enumerate()
112118
.map(|(i, e)| (e.ifd_num_tag(), i)).collect();
113119
let exif = Exif {
114120
buf: data,
115121
entries: parser.entries,
116-
entry_map: entry_map,
122+
entry_map,
117123
little_endian: parser.little_endian,
118124
};
119125
match parser.continue_on_error {

src/tag.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -749,10 +749,10 @@ 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) {
754-
Some(ti) => value::Display { fmt: ti.dispval, value: value },
755-
None => value::Display { fmt: d_default, value: value },
754+
Some(ti) => value::Display { fmt: ti.dispval, value },
755+
None => value::Display { fmt: d_default, value },
756756
}
757757
}
758758

@@ -1048,13 +1048,13 @@ fn d_subjarea(w: &mut dyn fmt::Write, value: &Value) -> fmt::Result {
10481048
// Acceleration (Exif 0x9404), CameraElevationAngle (Exif 0x9405)
10491049
fn d_optdecimal(w: &mut dyn fmt::Write, value: &Value) -> fmt::Result {
10501050
match *value {
1051-
Value::Rational(ref v) if v.len() > 0 =>
1051+
Value::Rational(ref v) if !v.is_empty() =>
10521052
if v[0].denom != 0xffffffff {
10531053
write!(w, "{}", v[0].to_f64())
10541054
} else {
10551055
w.write_str("unknown")
10561056
},
1057-
Value::SRational(ref v) if v.len() > 0 =>
1057+
Value::SRational(ref v) if !v.is_empty() =>
10581058
if v[0].denom != -1 {
10591059
write!(w, "{}", v[0].to_f64())
10601060
} else {
@@ -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: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl Parser {
239239
}
240240
let entry = Self::parse_ifd_entry::<E>(data, offset);
241241
offset += 12;
242-
let (tag, val) = match entry {
242+
let (tag, value) = match entry {
243243
Ok(x) => x,
244244
Err(e) => {
245245
self.check_error(e)?;
@@ -256,11 +256,11 @@ impl Parser {
256256
Tag::InteropIFDPointer => Context::Interop,
257257
_ => {
258258
self.entries.push(IfdEntry { field: Field {
259-
tag: tag, ifd_num: In(ifd_num), value: val }.into()});
259+
tag, ifd_num: In(ifd_num), value }.into()});
260260
continue;
261261
},
262262
};
263-
self.parse_child_ifd::<E>(data, val, child_ctx, ifd_num)
263+
self.parse_child_ifd::<E>(data, value, child_ctx, ifd_num)
264264
.or_else(|e| self.check_error(e))?;
265265
}
266266

@@ -313,7 +313,10 @@ impl Parser {
313313

314314
fn check_error(&mut self, err: Error) -> Result<(), Error> {
315315
match self.continue_on_error {
316-
Some(ref mut v) => Ok(v.push(err)),
316+
Some(ref mut v) => {
317+
v.push(err);
318+
Ok(())
319+
},
317320
None => Err(err),
318321
}
319322
}
@@ -502,12 +505,12 @@ impl<'a> DisplayValue<'a> {
502505
ifd_num: self.ifd_num,
503506
value_display: self.value_display,
504507
unit: self.tag.unit(),
505-
unit_provider: unit_provider,
508+
unit_provider,
506509
}
507510
}
508511
}
509512

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

src/util.rs

Lines changed: 2 additions & 2 deletions
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),
@@ -106,7 +106,7 @@ impl<T> ReadExt for T where T: io::Read {
106106
// This function must not be called with more than 4 bytes.
107107
pub fn atou16(bytes: &[u8]) -> Result<u16, Error> {
108108
debug_assert!(bytes.len() <= 4);
109-
if bytes.len() == 0 {
109+
if bytes.is_empty() {
110110
return Err(Error::InvalidFormat("Not a number"));
111111
}
112112
let mut n = 0;

src/value.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl Value {
180180
Value::Short(ref v) =>
181181
Some(UIntIter { iter: Box::new(v.iter().map(|&x| x as u32)) }),
182182
Value::Long(ref v) =>
183-
Some(UIntIter { iter: Box::new(v.iter().map(|&x| x)) }),
183+
Some(UIntIter { iter: Box::new(v.iter().copied()) }),
184184
_ => None,
185185
}
186186
}
@@ -213,7 +213,7 @@ impl UIntValue {
213213
match self.0 {
214214
Value::Byte(ref v) => v.get(index).map(|&x| x.into()),
215215
Value::Short(ref v) => v.get(index).map(|&x| x.into()),
216-
Value::Long(ref v) => v.get(index).map(|&x| x),
216+
Value::Long(ref v) => v.get(index).copied(),
217217
_ => panic!(),
218218
}
219219
}
@@ -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)

0 commit comments

Comments
 (0)