Skip to content

Commit 043f57f

Browse files
committed
Clippy auto fixes
1 parent 3d86a78 commit 043f57f

File tree

6 files changed

+19
-35
lines changed

6 files changed

+19
-35
lines changed

src/dmi.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,10 @@ impl RawDmi {
9494
}
9595
}
9696
if chunk_ihdr == None {
97-
return Err(error::DmiError::Generic(format!(
98-
"Failed to load DMI. Buffer end reached without finding an IHDR chunk."
99-
)));
97+
return Err(error::DmiError::Generic("Failed to load DMI. Buffer end reached without finding an IHDR chunk.".to_string()));
10098
};
101-
if chunks_idat.len() == 0 {
102-
return Err(error::DmiError::Generic(format!(
103-
"Failed to load DMI. Buffer end reached without finding an IDAT chunk."
104-
)));
99+
if chunks_idat.is_empty() {
100+
return Err(error::DmiError::Generic("Failed to load DMI. Buffer end reached without finding an IDAT chunk.".to_string()));
105101
}
106102
let other_chunks = match other_chunks.len() {
107103
0 => None,

src/dmi/chunk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl RawGenericChunk {
5252
)));
5353
};
5454

55-
let data: Vec<u8> = chunk_bytes[8..(chunk_length - 4)].iter().cloned().collect();
55+
let data: Vec<u8> = chunk_bytes[8..(chunk_length - 4)].to_vec();
5656

5757
let crc = [
5858
chunk_bytes[chunk_length - 4],

src/dmi/icon.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::error;
22
use super::ztxt;
33
use super::RawDmi;
4-
use image;
4+
55
use image::imageops;
66
use image::GenericImageView;
77
use std::collections::HashMap;
@@ -21,9 +21,7 @@ impl Icon {
2121
let chunk_ztxt = match &raw_dmi.chunk_ztxt {
2222
Some(chunk) => chunk.clone(),
2323
None => {
24-
return Err(error::DmiError::Generic(format!(
25-
"Error loading icon: no zTXt chunk found."
26-
)))
24+
return Err(error::DmiError::Generic("Error loading icon: no zTXt chunk found.".to_string()))
2725
}
2826
};
2927
let decompressed_text = chunk_ztxt.data.decode()?;
@@ -41,9 +39,7 @@ impl Icon {
4139
let current_line = match decompressed_text.next() {
4240
Some(thing) => thing,
4341
None => {
44-
return Err(error::DmiError::Generic(format!(
45-
"Error loading icon: no version header found."
46-
)))
42+
return Err(error::DmiError::Generic("Error loading icon: no version header found.".to_string()))
4743
}
4844
};
4945
let split_version: Vec<&str> = current_line.split_terminator(" = ").collect();
@@ -58,9 +54,7 @@ impl Icon {
5854
let current_line = match decompressed_text.next() {
5955
Some(thing) => thing,
6056
None => {
61-
return Err(error::DmiError::Generic(format!(
62-
"Error loading icon: no width found."
63-
)))
57+
return Err(error::DmiError::Generic("Error loading icon: no width found.".to_string()))
6458
}
6559
};
6660
let split_version: Vec<&str> = current_line.split_terminator(" = ").collect();
@@ -75,9 +69,7 @@ impl Icon {
7569
let current_line = match decompressed_text.next() {
7670
Some(thing) => thing,
7771
None => {
78-
return Err(error::DmiError::Generic(format!(
79-
"Error loading icon: no height found."
80-
)))
72+
return Err(error::DmiError::Generic("Error loading icon: no height found.".to_string()))
8173
}
8274
};
8375
let split_version: Vec<&str> = current_line.split_terminator(" = ").collect();
@@ -118,9 +110,7 @@ impl Icon {
118110
let mut current_line = match decompressed_text.next() {
119111
Some(thing) => thing,
120112
None => {
121-
return Err(error::DmiError::Generic(format!(
122-
"Error loading icon: no DMI trailer nor states found."
123-
)))
113+
return Err(error::DmiError::Generic("Error loading icon: no DMI trailer nor states found.".to_string()))
124114
}
125115
};
126116

@@ -151,7 +141,7 @@ impl Icon {
151141
)))
152142
}
153143
2 => String::new(), //Only the quotes, empty name otherwise.
154-
length @ _ => String::from_utf8(name[1..(length - 1)].to_vec())?, //Hacky way to trim. Blame the cool methods being nightly experimental.
144+
length => String::from_utf8(name[1..(length - 1)].to_vec())?, //Hacky way to trim. Blame the cool methods being nightly experimental.
155145
};
156146

157147
let mut dirs = None;
@@ -167,9 +157,7 @@ impl Icon {
167157
current_line = match decompressed_text.next() {
168158
Some(thing) => thing,
169159
None => {
170-
return Err(error::DmiError::Generic(format!(
171-
"Error loading icon: no DMI trailer found."
172-
)))
160+
return Err(error::DmiError::Generic("Error loading icon: no DMI trailer found.".to_string()))
173161
}
174162
};
175163

@@ -189,7 +177,7 @@ impl Icon {
189177
"\tframes" => frames = Some(split_version[1].parse::<u32>()?),
190178
"\tdelay" => {
191179
let mut delay_vector = vec![];
192-
let text_delays = split_version[1].split_terminator(",");
180+
let text_delays = split_version[1].split_terminator(',');
193181
for text_entry in text_delays {
194182
delay_vector.push(text_entry.parse::<f32>()?);
195183
}
@@ -199,7 +187,7 @@ impl Icon {
199187
"\trewind" => rewind = Some(split_version[1].parse::<u32>()?),
200188
"\tmovement" => movement = Some(split_version[1].parse::<u32>()?),
201189
"\thotspot" => {
202-
let text_coordinates: Vec<&str> = split_version[1].split_terminator(",").collect();
190+
let text_coordinates: Vec<&str> = split_version[1].split_terminator(',').collect();
203191
if text_coordinates.len() != 3 {
204192
return Err(error::DmiError::Generic(format!(
205193
"Error loading icon: improper hotspot found: {:#?}",
@@ -362,7 +350,7 @@ impl Icon {
362350

363351
new_dmi.chunk_ztxt = Some(new_ztxt);
364352

365-
Ok(new_dmi.save(&mut writter)?)
353+
new_dmi.save(&mut writter)
366354
}
367355
}
368356

src/dmi/iend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl Default for RawIendChunk {
128128
impl TryFrom<chunk::RawGenericChunk> for RawIendChunk {
129129
type Error = error::DmiError;
130130
fn try_from(raw_generic_chunk: chunk::RawGenericChunk) -> Result<Self, Self::Error> {
131-
if raw_generic_chunk.data.len() > 0 {
131+
if !raw_generic_chunk.data.is_empty() {
132132
return Err(error::DmiError::Generic(format!(
133133
"Failed to convert RawGenericChunk into RawIendChunk. Non-empty data field. Chunk: {:#?}.",
134134
raw_generic_chunk

src/dmi/ztxt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use super::chunk;
22
use super::crc;
33
use super::error;
4-
use deflate;
5-
use inflate;
4+
5+
66
use std::convert::TryFrom;
77
use std::fmt;
88
use std::io::prelude::*;

src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ fn load_dmi() {
88
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
99
path.push("tests/load_test.dmi");
1010
let path = Path::new(&path);
11-
let file = File::open(&path).expect(&format!("No lights dmi: {:?}", path));
11+
let file = File::open(&path).unwrap_or_else(|_| panic!("No lights dmi: {:?}", path));
1212
let _lights_icon = icon::Icon::load(&file).expect("Unable to load lights dmi");
1313
}

0 commit comments

Comments
 (0)