From 9735719948d87e2b0872c4e7395568a5e029daf8 Mon Sep 17 00:00:00 2001 From: Aely0 <29923178+Aely0@users.noreply.github.com> Date: Fri, 13 Dec 2024 05:47:17 +0200 Subject: [PATCH] Clippy suggestions --- crates/egui/src/widgets/image.rs | 12 ++++++------ crates/egui_extras/src/loaders/webp_loader.rs | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/egui/src/widgets/image.rs b/crates/egui/src/widgets/image.rs index 2cd8f6732e1..4c61c1a6358 100644 --- a/crates/egui/src/widgets/image.rs +++ b/crates/egui/src/widgets/image.rs @@ -807,7 +807,7 @@ impl FrameDurations { Self(Arc::new(durations)) } - pub fn iter(&self) -> Iter<'_, Duration> { + pub fn all(&self) -> Iter<'_, Duration> { self.0.iter() } } @@ -837,7 +837,7 @@ fn animated_image_frame_index(ctx: &Context, uri: &str) -> usize { let durations: Option = ctx.data(|data| data.get_temp(Id::new(uri))); if let Some(durations) = durations { - let frames: Duration = durations.iter().sum(); + let frames: Duration = durations.all().sum(); let pos_ms = now.as_millis() % frames.as_millis().max(1); let mut cumulative_ms = 0; @@ -858,22 +858,22 @@ fn animated_image_frame_index(ctx: &Context, uri: &str) -> usize { } } -/// Checks if uri is a GIF file +/// Checks if uri is a gif file fn is_gif_uri(uri: &str) -> bool { uri.ends_with(".gif") || uri.contains(".gif#") } -/// Checks if bytes are GIFs +/// Checks if bytes are gifs pub fn has_gif_magic_header(bytes: &[u8]) -> bool { bytes.starts_with(b"GIF87a") || bytes.starts_with(b"GIF89a") } -/// Checks if uri is a WebP file +/// Checks if uri is a webp file fn is_webp_uri(uri: &str) -> bool { uri.ends_with(".webp") || uri.contains(".webp#") } -/// Checks if bytes are WebP +/// Checks if bytes are webp pub fn has_webp_header(bytes: &[u8]) -> bool { bytes.len() >= 12 && &bytes[0..4] == b"RIFF" && &bytes[8..12] == b"WEBP" } diff --git a/crates/egui_extras/src/loaders/webp_loader.rs b/crates/egui_extras/src/loaders/webp_loader.rs index e6e54da7d61..bb042093b17 100644 --- a/crates/egui_extras/src/loaders/webp_loader.rs +++ b/crates/egui_extras/src/loaders/webp_loader.rs @@ -51,8 +51,7 @@ impl WebP { let (width, height) = decoder.dimensions(); let size = decoder.total_bytes() as usize; - let mut data = Vec::with_capacity(size); - data.resize(size, 0); + let mut data = vec![0; size]; decoder .read_image(&mut data) .map_err(|error| format!("WebP image read failure ({error})"))?; @@ -121,7 +120,7 @@ impl ImageLoader for WebPLoader { fn load(&self, ctx: &egui::Context, frame_uri: &str, _: SizeHint) -> ImageLoadResult { let (image_uri, frame_index) = - decode_animated_image_uri(frame_uri).map_err(|_| LoadError::NotSupported)?; + decode_animated_image_uri(frame_uri).map_err(|_error| LoadError::NotSupported)?; let mut cache = self.cache.lock(); if let Some(entry) = cache.get(image_uri).cloned() {