Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.

Commit 9360b50

Browse files
committed
improve style of many things (all hail clippy!!!)
1 parent f549f5c commit 9360b50

File tree

16 files changed

+153
-155
lines changed

16 files changed

+153
-155
lines changed

client/build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ fn main() -> Result<(), Error> {
2626
let shells = [Shell::Bash, Shell::Zsh, Shell::Fish, Shell::Elvish];
2727
for shell in shells {
2828
let comp_file = generate_to(shell, &mut app, APP_NAME, &outdir)?;
29-
println!("cargo:warning=generated shell completion file: {comp_file:?}");
29+
println!(
30+
"cargo:warning=generated shell completion file: {}",
31+
comp_file.display()
32+
);
3033
}
3134
Ok(())
3235
}

client/src/cli.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ pub enum Filter {
5050
}
5151

5252
impl Filter {
53-
pub fn as_str(&self) -> &'static str {
53+
#[must_use]
54+
pub fn as_str(self) -> &'static str {
5455
match self {
5556
Self::Nearest => "Nearest",
5657
Self::Bilinear => "Bilinear",
@@ -136,6 +137,7 @@ pub struct CliPosition {
136137
}
137138

138139
impl CliPosition {
140+
#[must_use]
139141
pub fn new(x: CliCoord, y: CliCoord) -> Self {
140142
Self { x, y }
141143
}
@@ -293,7 +295,8 @@ pub enum ResizeStrategy {
293295
}
294296

295297
impl ResizeStrategy {
296-
pub fn as_str(&self) -> &'static str {
298+
#[must_use]
299+
pub fn as_str(self) -> &'static str {
297300
match self {
298301
ResizeStrategy::No => "no",
299302
ResizeStrategy::Crop => "crop",
@@ -549,12 +552,12 @@ pub fn parse_image(raw: &str) -> Result<CliImage, String> {
549552
{
550553
return Ok(CliImage::Color(color));
551554
}
552-
Err(format!("Path '{}' does not exist", raw))
555+
Err(format!("Path '{raw}' does not exist"))
553556
}
554557

555558
// parses Percents and numbers in format of "<coord1>,<coord2>"
556559
fn parse_coords(raw: &str) -> Result<CliPosition, String> {
557-
let coords = raw.split(',').map(|s| s.trim()).collect::<Vec<&str>>();
560+
let coords = raw.split(',').map(str::trim).collect::<Vec<&str>>();
558561
if coords.len() != 2 {
559562
match coords[0] {
560563
"center" => {

client/src/imgproc.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl ImgBuf {
130130
pub struct RasterImage<'a>((&'a ImgBuf, &'a ImageFormat));
131131
pub struct VectorImage<'a>(&'a Tree);
132132

133-
impl<'a> RasterImage<'a> {
133+
impl RasterImage<'_> {
134134
pub fn decode(&self, format: PixelFormat) -> Result<Image, String> {
135135
let (imgbuf, image_format) = self.0;
136136
let mut reader = image::ImageReader::new(Cursor::new(&imgbuf.bytes));
@@ -160,8 +160,8 @@ impl<'a> RasterImage<'a> {
160160
Ok(Image {
161161
width,
162162
height,
163-
bytes,
164163
format,
164+
bytes,
165165
})
166166
}
167167

@@ -174,7 +174,7 @@ impl<'a> RasterImage<'a> {
174174
}
175175
}
176176

177-
impl<'a> VectorImage<'a> {
177+
impl VectorImage<'_> {
178178
pub fn decode(&self, format: PixelFormat, width: u32, height: u32) -> Result<Image, String> {
179179
use resvg::{tiny_skia::PixmapMut, usvg::Transform};
180180
let tree = self.0;
@@ -223,8 +223,8 @@ impl<'a> VectorImage<'a> {
223223
Ok(Image {
224224
width,
225225
height,
226-
bytes,
227226
format,
227+
bytes,
228228
})
229229
}
230230
}
@@ -303,7 +303,7 @@ pub fn compress_frames(
303303
format: PixelFormat,
304304
filter: FilterType,
305305
resize: ResizeStrategy,
306-
color: &[u8; 4],
306+
color: [u8; 4],
307307
) -> Result<Vec<(BitPack, Duration)>, String> {
308308
let mut compressor = Compressor::new();
309309
let mut compressed_frames = Vec::new();
@@ -314,7 +314,7 @@ pub fn compress_frames(
314314
let mut first_duration = Duration::from_millis((first_duration.0 / first_duration.1).into());
315315
let first_img = Image::from_frame(first, format);
316316
let first_img = match resize {
317-
ResizeStrategy::No => img_pad(&first_img, dim, color)?,
317+
ResizeStrategy::No => img_pad(&first_img, dim, color),
318318
ResizeStrategy::Crop => img_resize_crop(&first_img, dim, filter)?,
319319
ResizeStrategy::Fit => img_resize_fit(&first_img, dim, filter, color)?,
320320
ResizeStrategy::Stretch => img_resize_stretch(&first_img, dim, filter)?,
@@ -327,7 +327,7 @@ pub fn compress_frames(
327327

328328
let img = Image::from_frame(frame, format);
329329
let img = match resize {
330-
ResizeStrategy::No => img_pad(&img, dim, color)?,
330+
ResizeStrategy::No => img_pad(&img, dim, color),
331331
ResizeStrategy::Crop => img_resize_crop(&img, dim, filter)?,
332332
ResizeStrategy::Fit => img_resize_fit(&img, dim, filter, color)?,
333333
ResizeStrategy::Stretch => img_resize_stretch(&img, dim, filter)?,
@@ -364,7 +364,7 @@ pub fn compress_frames(
364364
Ok(compressed_frames)
365365
}
366366

367-
pub fn make_filter(filter: &cli::Filter) -> fast_image_resize::FilterType {
367+
pub fn make_filter(filter: cli::Filter) -> fast_image_resize::FilterType {
368368
match filter {
369369
cli::Filter::Nearest => fast_image_resize::FilterType::Box,
370370
cli::Filter::Bilinear => fast_image_resize::FilterType::Bilinear,
@@ -374,7 +374,7 @@ pub fn make_filter(filter: &cli::Filter) -> fast_image_resize::FilterType {
374374
}
375375
}
376376

377-
pub fn img_pad(img: &Image, dimensions: (u32, u32), color: &[u8; 4]) -> Result<Box<[u8]>, String> {
377+
pub fn img_pad(img: &Image, dimensions: (u32, u32), color: [u8; 4]) -> Box<[u8]> {
378378
let channels = img.format.channels() as usize;
379379

380380
let mut color4 = color.to_owned();
@@ -432,7 +432,7 @@ pub fn img_pad(img: &Image, dimensions: (u32, u32), color: &[u8; 4]) -> Result<B
432432
padded.extend_from_slice(color);
433433
}
434434

435-
Ok(padded.into_boxed_slice())
435+
padded.into_boxed_slice()
436436
}
437437

438438
/// Resize an image to fit within the given dimensions, covering as much space as possible without
@@ -441,13 +441,15 @@ pub fn img_resize_fit(
441441
img: &Image,
442442
dimensions: (u32, u32),
443443
filter: FilterType,
444-
padding_color: &[u8; 4],
444+
padding_color: [u8; 4],
445445
) -> Result<Box<[u8]>, String> {
446446
let (width, height) = dimensions;
447-
if (img.width, img.height) != (width, height) {
447+
if (img.width, img.height) == (width, height) {
448+
Ok(img.bytes.clone())
449+
} else {
448450
// if our image is already scaled to fit, skip resizing it and just pad it directly
449451
if img.width == width || img.height == height {
450-
return img_pad(img, dimensions, padding_color);
452+
return Ok(img_pad(img, dimensions, padding_color));
451453
}
452454

453455
let ratio = width as f32 / height as f32;
@@ -490,9 +492,7 @@ pub fn img_resize_fit(
490492
format: img.format,
491493
bytes: dst.into_vec().into_boxed_slice(),
492494
};
493-
img_pad(&img, dimensions, padding_color)
494-
} else {
495-
Ok(img.bytes.clone())
495+
Ok(img_pad(&img, dimensions, padding_color))
496496
}
497497
}
498498

@@ -502,7 +502,9 @@ pub fn img_resize_stretch(
502502
filter: FilterType,
503503
) -> Result<Box<[u8]>, String> {
504504
let (width, height) = dimensions;
505-
let resized_img = if (img.width, img.height) != (width, height) {
505+
let resized_img = if (img.width, img.height) == (width, height) {
506+
img.bytes.clone()
507+
} else {
506508
let pixel_type = if img.format.channels() == 3 {
507509
PixelType::U8x3
508510
} else {
@@ -528,8 +530,6 @@ pub fn img_resize_stretch(
528530
}
529531

530532
dst.into_vec().into_boxed_slice()
531-
} else {
532-
img.bytes.clone()
533533
};
534534

535535
Ok(resized_img)
@@ -541,7 +541,9 @@ pub fn img_resize_crop(
541541
filter: FilterType,
542542
) -> Result<Box<[u8]>, String> {
543543
let (width, height) = dimensions;
544-
let resized_img = if (img.width, img.height) != (width, height) {
544+
let resized_img = if (img.width, img.height) == (width, height) {
545+
img.bytes.clone()
546+
} else {
545547
let pixel_type = if img.format.channels() == 3 {
546548
PixelType::U8x3
547549
} else {
@@ -568,8 +570,6 @@ pub fn img_resize_crop(
568570
}
569571

570572
dst.into_vec().into_boxed_slice()
571-
} else {
572-
img.bytes.clone()
573573
};
574574

575575
Ok(resized_img)

client/src/main.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn process_swww_args(args: &Swww, namespace: &str) -> Result<(), String> {
7373
let bytes = socket.recv().map_err(|err| err.to_string())?;
7474
drop(socket);
7575
match Answer::receive(bytes) {
76-
Answer::Info(info) => info.iter().for_each(|i| println!("{namespace}: {}", i)),
76+
Answer::Info(info) => info.iter().for_each(|i| println!("{namespace}: {i}")),
7777
Answer::Ok => {
7878
if let Swww::Kill(_) = args {
7979
#[cfg(debug_assertions)]
@@ -89,7 +89,7 @@ fn process_swww_args(args: &Swww, namespace: &str) -> Result<(), String> {
8989
}
9090
return Err(format!(
9191
"Could not confirm socket deletion at: {}",
92-
path.to_string_lossy()
92+
path.display()
9393
));
9494
}
9595
}
@@ -180,7 +180,7 @@ fn make_img_request(
180180

181181
for (&dim, outputs) in dims.iter().zip(outputs) {
182182
let path = match img_path.canonicalize() {
183-
Ok(p) => p.to_string_lossy().to_string(),
183+
Ok(p) => p.display().to_string(),
184184
Err(e) => {
185185
if let Some("-") = img_path.to_str() {
186186
"STDIN".to_string()
@@ -190,45 +190,48 @@ fn make_img_request(
190190
}
191191
};
192192

193-
let animation = if !imgbuf.is_animated() {
194-
None
195-
} else {
193+
let animation = if imgbuf.is_animated() {
196194
match cache::load_animation_frames(&path, dim, resize, pixel_format) {
197195
Ok(Some(animation)) => Some(animation),
198196
otherwise => {
199197
if let Err(e) = otherwise {
200-
eprintln!("Error loading cache for {:?}: {e}", img_path);
198+
eprintln!(
199+
"Error loading cache for {}: {e}",
200+
img_path.display()
201+
);
201202
}
202203
Some({
203204
ipc::Animation {
204205
animation: compress_frames(
205206
imgbuf.as_frames()?,
206207
dim,
207208
pixel_format,
208-
make_filter(&img.filter),
209+
make_filter(img.filter),
209210
img.resize,
210-
&img.fill_color,
211+
img.fill_color,
211212
)?
212213
.into_boxed_slice(),
213214
}
214215
})
215216
}
216217
}
218+
} else {
219+
None
217220
};
218221

219222
let img = match img.resize {
220-
ResizeStrategy::No => img_pad(&img_raw, dim, &img.fill_color)?,
223+
ResizeStrategy::No => img_pad(&img_raw, dim, img.fill_color),
221224
ResizeStrategy::Crop => {
222-
img_resize_crop(&img_raw, dim, make_filter(&img.filter))?
225+
img_resize_crop(&img_raw, dim, make_filter(img.filter))?
223226
}
224227
ResizeStrategy::Fit => img_resize_fit(
225228
&img_raw,
226229
dim,
227-
make_filter(&img.filter),
228-
&img.fill_color,
230+
make_filter(img.filter),
231+
img.fill_color,
229232
)?,
230233
ResizeStrategy::Stretch => {
231-
img_resize_stretch(&img_raw, dim, make_filter(&img.filter))?
234+
img_resize_stretch(&img_raw, dim, make_filter(img.filter))?
232235
}
233236
};
234237

@@ -252,7 +255,7 @@ fn make_img_request(
252255
DecodeBuffer::VectorImage(imgbuf) => {
253256
for (&dim, outputs) in dims.iter().zip(outputs) {
254257
let path = match img_path.canonicalize() {
255-
Ok(p) => p.to_string_lossy().to_string(),
258+
Ok(p) => p.display().to_string(),
256259
Err(e) => {
257260
if let Some("-") = img_path.to_str() {
258261
"STDIN".to_string()
@@ -264,18 +267,18 @@ fn make_img_request(
264267
let filter = img.filter.as_str();
265268
let img_raw = imgbuf.decode(pixel_format, dim.0, dim.1)?;
266269
let img = match img.resize {
267-
ResizeStrategy::No => img_pad(&img_raw, dim, &img.fill_color)?,
270+
ResizeStrategy::No => img_pad(&img_raw, dim, img.fill_color),
268271
ResizeStrategy::Crop => {
269-
img_resize_crop(&img_raw, dim, make_filter(&img.filter))?
272+
img_resize_crop(&img_raw, dim, make_filter(img.filter))?
270273
}
271274
ResizeStrategy::Fit => img_resize_fit(
272275
&img_raw,
273276
dim,
274-
make_filter(&img.filter),
275-
&img.fill_color,
277+
make_filter(img.filter),
278+
img.fill_color,
276279
)?,
277280
ResizeStrategy::Stretch => {
278-
img_resize_stretch(&img_raw, dim, make_filter(&img.filter))?
281+
img_resize_stretch(&img_raw, dim, make_filter(img.filter))?
279282
}
280283
};
281284
img_req_builder.push(
@@ -317,7 +320,7 @@ fn get_format_dims_and_outputs(
317320
match answer {
318321
Answer::Info(infos) => {
319322
let mut format = ipc::PixelFormat::Argb;
320-
for info in infos.iter() {
323+
for info in &infos {
321324
format = info.pixel_format;
322325
let info_img = &info.img;
323326
let name = info.name.to_string();
@@ -351,7 +354,7 @@ fn get_format_dims_and_outputs(
351354
fn split_cmdline_outputs(outputs: &str) -> Box<[String]> {
352355
outputs
353356
.split(',')
354-
.map(|s| s.to_owned())
357+
.map(ToOwned::to_owned)
355358
.filter(|s| !s.is_empty())
356359
.collect()
357360
}

0 commit comments

Comments
 (0)