Skip to content

Commit

Permalink
Clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Aely0 committed Dec 13, 2024
1 parent 8d1a977 commit 9735719
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
12 changes: 6 additions & 6 deletions crates/egui/src/widgets/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -837,7 +837,7 @@ fn animated_image_frame_index(ctx: &Context, uri: &str) -> usize {
let durations: Option<FrameDurations> = 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;
Expand All @@ -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"
}
Expand Down
5 changes: 2 additions & 3 deletions crates/egui_extras/src/loaders/webp_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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})"))?;
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 9735719

Please sign in to comment.