Skip to content

Commit 7855941

Browse files
committed
fixup: clippy errors
Signed-off-by: Philip H. <[email protected]>
1 parent e4c4441 commit 7855941

File tree

3 files changed

+25
-36
lines changed

3 files changed

+25
-36
lines changed

src/config.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl fmt::Display for Device {
185185
if self.zram_fraction.is_some() || self.max_zram_size_mb.is_some() {
186186
f.write_str(" (")?;
187187
if let Some(zf) = self.zram_fraction {
188-
write!(f, "zram-fraction={}", zf)?;
188+
write!(f, "zram-fraction={zf}")?;
189189
}
190190
if self.max_zram_size_mb.is_some() {
191191
f.write_str(" ")?;
@@ -203,7 +203,7 @@ struct OptMB(Option<u64>);
203203
impl fmt::Display for OptMB {
204204
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
205205
match self.0 {
206-
Some(val) => write!(f, "{}MB", val),
206+
Some(val) => write!(f, "{val}MB"),
207207
None => f.write_str("<none>"),
208208
}
209209
}
@@ -221,12 +221,12 @@ impl fmt::Display for Algorithms {
221221
[(first, firstparams), more @ ..] => {
222222
f.write_str(first)?;
223223
if !firstparams.is_empty() {
224-
write!(f, " ({})", firstparams)?;
224+
write!(f, " ({firstparams})")?;
225225
}
226226
for (algo, params) in more {
227-
write!(f, " then {}", algo)?;
227+
write!(f, " then {algo}")?;
228228
if !params.is_empty() {
229-
write!(f, " ({})", params)?;
229+
write!(f, " ({params})")?;
230230
}
231231
}
232232
}
@@ -302,7 +302,7 @@ fn toplevel_line(
302302
.code()
303303
.unwrap_or_else(|| 128 + out.status.signal().unwrap());
304304
if exit != 0 {
305-
warn!("{}: {} exited {}", k, val, exit);
305+
warn!("{k}: {val} exited {exit}");
306306
}
307307

308308
let expr = String::from_utf8(out.stdout)
@@ -416,15 +416,15 @@ fn parse_optional_size(val: &str) -> Result<Option<u64>> {
416416
} else {
417417
Some(
418418
val.parse()
419-
.with_context(|| format!("Failed to parse optional size \"{}\"", val))?,
419+
.with_context(|| format!("Failed to parse optional size \"{val}\""))?,
420420
)
421421
})
422422
}
423423

424424
fn parse_swap_priority(val: &str) -> Result<i32> {
425425
let val = val
426426
.parse()
427-
.with_context(|| format!("Failed to parse priority \"{}\"", val))?;
427+
.with_context(|| format!("Failed to parse priority \"{val}\""))?;
428428

429429
/* See --priority in swapon(8). */
430430
match val {
@@ -531,7 +531,7 @@ fn parse_line(dev: &mut Device, key: &str, value: &str) -> Result<()> {
531531
dev.zram_fraction = Some(
532532
value
533533
.parse()
534-
.with_context(|| format!("Failed to parse zram-fraction \"{}\"", value))
534+
.with_context(|| format!("Failed to parse zram-fraction \"{value}\""))
535535
.and_then(|f| {
536536
if f >= 0. {
537537
Ok(f)
@@ -607,7 +607,7 @@ pub fn kernel_zram_option(root: &Path) -> Option<bool> {
607607
Some(false)
608608
}
609609
Err(e) => {
610-
warn!("Failed to parse /proc/cmdline ({}), ignoring.", e);
610+
warn!("Failed to parse /proc/cmdline ({e}), ignoring.");
611611
None
612612
}
613613
}

src/generator.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ fn virtualization_container() -> Result<bool> {
3434
{
3535
Ok(child) => child,
3636
Err(e) => {
37-
warn!(
38-
"systemd-detect-virt call failed, assuming we're not in a container: {}",
39-
e
40-
);
37+
warn!("systemd-detect-virt call failed, assuming we're not in a container: {e}");
4138
return Ok(false);
4239
}
4340
};
@@ -58,14 +55,12 @@ fn modprobe(modname: &str, required: bool) {
5855

5956
log!(
6057
level,
61-
"modprobe \"{}\" cannot be spawned, ignoring: {}",
62-
modname,
63-
e
58+
"modprobe \"{modname}\" cannot be spawned, ignoring: {e}"
6459
);
6560
}
6661
Ok(status) => {
6762
if !status.success() {
68-
warn!("modprobe \"{}\" failed, ignoring: code {}", modname, status);
63+
warn!("modprobe \"{modname}\" failed, ignoring: code {status}");
6964
}
7065
}
7166
};
@@ -101,10 +96,7 @@ pub fn run_generator(devices: &[Device], output_directory: &Path, fake_mode: boo
10196
})
10297
.fold(0, cmp::max);
10398

104-
if !Path::new("/dev")
105-
.join(format!("zram{}", max_device))
106-
.exists()
107-
{
99+
if !Path::new("/dev").join(format!("zram{max_device}")).exists() {
108100
while fs::read_to_string("/sys/class/zram-control/hot_add")
109101
.context("Adding zram device")?
110102
.trim_end()
@@ -128,13 +120,13 @@ pub fn run_generator(devices: &[Device], output_directory: &Path, fake_mode: boo
128120

129121
if !compressors.is_empty() {
130122
let proc_crypto = fs::read_to_string("/proc/crypto").unwrap_or_else(|e| {
131-
warn!("Failed to read /proc/crypto, proceeding as if empty: {}", e);
123+
warn!("Failed to read /proc/crypto, proceeding as if empty: {e}");
132124
String::new()
133125
});
134126
let known = parse_known_compressors(&proc_crypto);
135127

136128
for comp in compressors.difference(&known) {
137-
modprobe(&format!("crypto-{}", comp), false);
129+
modprobe(&format!("crypto-{comp}"), false);
138130
}
139131
}
140132

@@ -257,7 +249,7 @@ Options={options}
257249

258250
/* enablement symlink */
259251
let symlink_path = output_directory.join("swap.target.wants").join(&swap_name);
260-
let target_path = format!("../{}", swap_name);
252+
let target_path = format!("../{swap_name}");
261253
make_symlink(&target_path, &symlink_path)?;
262254

263255
Ok(())
@@ -271,7 +263,7 @@ fn unit_name_from_path(path: &Path, suffix: &str) -> String {
271263

272264
let trimmed = path.to_str().unwrap().trim_matches('/');
273265
if trimmed.is_empty() {
274-
format!("-{}", suffix)
266+
format!("-{suffix}")
275267
} else {
276268
let mut obuf = Vec::with_capacity(path.as_os_str().len() + suffix.len());
277269
let mut just_slash = false;
@@ -284,7 +276,7 @@ fn unit_name_from_path(path: &Path, suffix: &str) -> String {
284276
b'/' => obuf.push(b'-'),
285277
b'.' if i == 0 => write!(obuf, "\\x{:02x}", b'.').unwrap(),
286278
b'0'..=b'9' | b'a'..=b'z' | b'A'..=b'Z' | b':' | b'_' | b'.' => obuf.push(b),
287-
_ => write!(obuf, "\\x{:02x}", b).unwrap(),
279+
_ => write!(obuf, "\\x{b:02x}").unwrap(),
288280
}
289281
}
290282
obuf.extend_from_slice(suffix.as_bytes());
@@ -335,7 +327,7 @@ Options={options}
335327
let symlink_path = output_directory
336328
.join("local-fs.target.wants")
337329
.join(mount_name);
338-
let target_path = format!("../{}", mount_name);
330+
let target_path = format!("../{mount_name}");
339331
make_symlink(&target_path, &symlink_path)?;
340332

341333
Ok(())

src/setup.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ pub fn run_device_setup(device: Option<Device>, device_name: &str) -> Result<()>
4747
params.as_ref().map(|p| {
4848
(
4949
device_sysfs_path.join("algorithm_params"),
50-
format!("algo={} {}", algo, p),
50+
format!("algo={algo} {p}"),
5151
)
5252
}),
5353
)
5454
} else {
5555
(
5656
device_sysfs_path.join("recomp_algorithm"),
57-
&format!("algo={} priority={}", algo, prio),
57+
&format!("algo={algo} priority={prio}"),
5858
params.as_ref().map(|p| {
5959
(
6060
device_sysfs_path.join("recompress"),
61-
format!("{} priority={}", p, prio),
61+
format!("{p} priority={prio}"),
6262
)
6363
}),
6464
)
@@ -71,8 +71,7 @@ pub fn run_device_setup(device: Option<Device>, device_name: &str) -> Result<()>
7171
Ok(_) => {}
7272
Err(err) => {
7373
warn!(
74-
"Warning: algorithm {:?} supplemental data {:?} not written: {}",
75-
algo, data, err,
74+
"Warning: algorithm {algo:?} supplemental data {data:?} not written: {err}",
7675
);
7776
}
7877
}
@@ -143,9 +142,7 @@ pub fn run_device_setup(device: Option<Device>, device_name: &str) -> Result<()>
143142
Err(e) =>
144143
Err(e).with_context(|| {
145144
format!(
146-
"{} call failed for /dev/{}",
147-
SYSTEMD_MAKEFS_COMMAND,
148-
device_name
145+
"{SYSTEMD_MAKEFS_COMMAND} call failed for /dev/{device_name}"
149146
)
150147
}),
151148
}

0 commit comments

Comments
 (0)