Skip to content

Commit b0bddcf

Browse files
committed
fixed clippy
1 parent acd7696 commit b0bddcf

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

src/ifd.rs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,9 @@ async fn read_tag_value(
887887
// value fits in offset field
888888
let res = cursor.read(value_byte_length).await?;
889889
if bigtiff {
890-
cursor.advance(8-value_byte_length);
890+
cursor.advance(8 - value_byte_length);
891891
} else {
892-
cursor.advance(4-value_byte_length);
892+
cursor.advance(4 - value_byte_length);
893893
}
894894
res
895895
} else {
@@ -899,7 +899,11 @@ async fn read_tag_value(
899899
} else {
900900
cursor.read_u32().await?.into()
901901
};
902-
let reader = cursor.reader().get_bytes(offset..offset+value_byte_length).await?.reader();
902+
let reader = cursor
903+
.reader()
904+
.get_bytes(offset..offset + value_byte_length)
905+
.await?
906+
.reader();
903907
EndianAwareReader::new(reader, cursor.endianness())
904908
// cursor.seek(offset);
905909
// cursor.read(value_byte_length).await?
@@ -934,18 +938,18 @@ async fn read_tag_value(
934938

935939
match tag_type {
936940
Type::BYTE | Type::UNDEFINED => {
937-
let mut v = Vec::new();
941+
let mut v = Vec::with_capacity(count as _);
938942
for _ in 0..count {
939943
v.push(Value::Byte(data.read_u8()?));
940944
}
941-
return Ok(Value::List(v));
945+
Ok(Value::List(v))
942946
}
943947
Type::SBYTE => {
944-
let mut v = Vec::new();
948+
let mut v = Vec::with_capacity(count as _);
945949
for _ in 0..count {
946950
v.push(Value::SignedByte(data.read_i8()?));
947951
}
948-
return Ok(Value::List(v));
952+
Ok(Value::List(v))
949953
}
950954
Type::ASCII => {
951955
let mut buf = vec![0; count as usize];
@@ -954,95 +958,95 @@ async fn read_tag_value(
954958
let v = std::str::from_utf8(&buf)
955959
.map_err(|err| AsyncTiffError::General(err.to_string()))?;
956960
let v = v.trim_matches(char::from(0));
957-
return Ok(Value::Ascii(v.into()));
961+
Ok(Value::Ascii(v.into()))
958962
} else {
959963
panic!("Invalid tag");
960964
// return Err(TiffError::FormatError(TiffFormatError::InvalidTag));
961965
}
962966
}
963967
Type::SHORT => {
964-
let mut v = Vec::new();
968+
let mut v = Vec::with_capacity(count as _);
965969
for _ in 0..count {
966970
v.push(Value::Short(data.read_u16()?));
967971
}
968-
return Ok(Value::List(v));
972+
Ok(Value::List(v))
969973
}
970974
Type::SSHORT => {
971-
let mut v = Vec::new();
975+
let mut v = Vec::with_capacity(count as _);
972976
for _ in 0..count {
973977
v.push(Value::Signed(i32::from(data.read_i16()?)));
974978
}
975-
return Ok(Value::List(v));
979+
Ok(Value::List(v))
976980
}
977981
Type::LONG => {
978-
let mut v = Vec::new();
982+
let mut v = Vec::with_capacity(count as _);
979983
for _ in 0..count {
980984
v.push(Value::Unsigned(data.read_u32()?));
981985
}
982-
return Ok(Value::List(v));
986+
Ok(Value::List(v))
983987
}
984988
Type::SLONG => {
985-
let mut v = Vec::new();
989+
let mut v = Vec::with_capacity(count as _);
986990
for _ in 0..count {
987991
v.push(Value::Signed(data.read_i32()?));
988992
}
989-
return Ok(Value::List(v));
993+
Ok(Value::List(v))
990994
}
991995
Type::FLOAT => {
992-
let mut v = Vec::new();
996+
let mut v = Vec::with_capacity(count as _);
993997
for _ in 0..count {
994998
v.push(Value::Float(data.read_f32()?));
995999
}
996-
return Ok(Value::List(v));
1000+
Ok(Value::List(v))
9971001
}
9981002
Type::DOUBLE => {
9991003
let mut v = Vec::with_capacity(count as _);
10001004
for _ in 0..count {
10011005
v.push(Value::Double(data.read_f64()?))
10021006
}
1003-
return Ok(Value::List(v));
1007+
Ok(Value::List(v))
10041008
}
10051009
Type::RATIONAL => {
10061010
let mut v = Vec::with_capacity(count as _);
10071011
for _ in 0..count {
10081012
v.push(Value::Rational(data.read_u32()?, data.read_u32()?))
10091013
}
1010-
return Ok(Value::List(v));
1014+
Ok(Value::List(v))
10111015
}
10121016
Type::SRATIONAL => {
10131017
let mut v = Vec::with_capacity(count as _);
10141018
for _ in 0..count {
10151019
v.push(Value::SRational(data.read_i32()?, data.read_i32()?))
10161020
}
1017-
return Ok(Value::List(v));
1021+
Ok(Value::List(v))
10181022
}
10191023
Type::LONG8 => {
10201024
let mut v = Vec::with_capacity(count as _);
10211025
for _ in 0..count {
10221026
v.push(Value::UnsignedBig(data.read_u64()?))
10231027
}
1024-
return Ok(Value::List(v));
1028+
Ok(Value::List(v))
10251029
}
10261030
Type::SLONG8 => {
10271031
let mut v = Vec::with_capacity(count as _);
10281032
for _ in 0..count {
10291033
v.push(Value::SignedBig(data.read_i64()?))
10301034
}
1031-
return Ok(Value::List(v));
1035+
Ok(Value::List(v))
10321036
}
10331037
Type::IFD => {
10341038
let mut v = Vec::with_capacity(count as _);
10351039
for _ in 0..count {
10361040
v.push(Value::Ifd(data.read_u32()?))
10371041
}
1038-
return Ok(Value::List(v));
1042+
Ok(Value::List(v))
10391043
}
10401044
Type::IFD8 => {
10411045
let mut v = Vec::with_capacity(count as _);
10421046
for _ in 0..count {
10431047
v.push(Value::IfdBig(data.read_u64()?))
10441048
}
1045-
return Ok(Value::List(v));
1049+
Ok(Value::List(v))
10461050
}
10471051
}
10481052
}

src/reader.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,31 +341,37 @@ impl AsyncCursor {
341341
}
342342

343343
/// Read a u8 from the cursor, advancing the internal state by 1 byte.
344+
#[allow(dead_code)]
344345
pub(crate) async fn read_u8(&mut self) -> AsyncTiffResult<u8> {
345346
self.read(1).await?.read_u8()
346347
}
347348

348349
/// Read a i8 from the cursor, advancing the internal state by 1 byte.
350+
#[allow(dead_code)]
349351
pub(crate) async fn read_i8(&mut self) -> AsyncTiffResult<i8> {
350352
self.read(1).await?.read_i8()
351353
}
352354

353355
/// Read a u16 from the cursor, advancing the internal state by 2 bytes.
356+
#[allow(dead_code)]
354357
pub(crate) async fn read_u16(&mut self) -> AsyncTiffResult<u16> {
355358
self.read(2).await?.read_u16()
356359
}
357360

358361
/// Read a i16 from the cursor, advancing the internal state by 2 bytes.
362+
#[allow(dead_code)]
359363
pub(crate) async fn read_i16(&mut self) -> AsyncTiffResult<i16> {
360364
self.read(2).await?.read_i16()
361365
}
362366

363367
/// Read a u32 from the cursor, advancing the internal state by 4 bytes.
368+
#[allow(dead_code)]
364369
pub(crate) async fn read_u32(&mut self) -> AsyncTiffResult<u32> {
365370
self.read(4).await?.read_u32()
366371
}
367372

368373
/// Read a i32 from the cursor, advancing the internal state by 4 bytes.
374+
#[allow(dead_code)]
369375
pub(crate) async fn read_i32(&mut self) -> AsyncTiffResult<i32> {
370376
self.read(4).await?.read_i32()
371377
}
@@ -376,24 +382,25 @@ impl AsyncCursor {
376382
}
377383

378384
/// Read a i64 from the cursor, advancing the internal state by 8 bytes.
385+
#[allow(dead_code)]
379386
pub(crate) async fn read_i64(&mut self) -> AsyncTiffResult<i64> {
380387
self.read(8).await?.read_i64()
381388
}
382389

390+
#[allow(dead_code)]
383391
pub(crate) async fn read_f32(&mut self) -> AsyncTiffResult<f32> {
384392
self.read(4).await?.read_f32()
385393
}
386394

395+
#[allow(dead_code)]
387396
pub(crate) async fn read_f64(&mut self) -> AsyncTiffResult<f64> {
388397
self.read(8).await?.read_f64()
389398
}
390399

391-
#[allow(dead_code)]
392400
pub(crate) fn reader(&self) -> &Arc<dyn AsyncFileReader> {
393401
&self.reader
394402
}
395403

396-
#[allow(dead_code)]
397404
pub(crate) fn endianness(&self) -> Endianness {
398405
self.endianness
399406
}
@@ -407,6 +414,7 @@ impl AsyncCursor {
407414
self.offset = offset;
408415
}
409416

417+
#[allow(dead_code)]
410418
pub(crate) fn position(&self) -> u64 {
411419
self.offset
412420
}

0 commit comments

Comments
 (0)