Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Jun 8, 2024
1 parent 2927b3c commit 640ae4e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
31 changes: 20 additions & 11 deletions examples/animated-image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@ fn main() {
.run();
}

#[derive(Component, Clone, Copy, PartialEq, Eq, Debug)]
#[derive(Component, Clone, Copy, PartialEq, Eq)]
enum Image {
Gif,
Webp,
}

impl std::fmt::Display for Image {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Image::Gif => write!(f, "GIF"),
Image::Webp => write!(f, "WebP"),
}
}
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>, window: Query<&Window>) {
commands.spawn(Camera2dBundle::default());

Expand Down Expand Up @@ -55,6 +64,13 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, window: Query<&
.with_children(|parent| {
parent.spawn((
TextBundle::from_sections(vec![
TextSection {
value: format!("{}\n", kind),
style: TextStyle {
font_size: 60.0,
..default()
},
},
TextSection {
value: "play count: ".to_string(),
style: TextStyle {
Expand Down Expand Up @@ -97,13 +113,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, window: Query<&
..default()
},
},
TextSection {
value: format!("\n{:?}", kind),
style: TextStyle {
font_size: 20.0,
..default()
},
},
]),
kind,
));
Expand All @@ -121,9 +130,9 @@ fn log_updates(
if image_kind != text_kind {
continue;
}
text.sections[1].value = format!("{}", animated_image.play_count());
text.sections[3].value = format!("{:>4}", animated_image.current_frame());
text.sections[5].value = format!("{}", animated_image.frame_count() as i32 - 1);
text.sections[2].value = format!("{}", animated_image.play_count());
text.sections[4].value = format!("{:>4}", animated_image.current_frame());
text.sections[6].value = format!("{}", animated_image.frame_count() as i32 - 1);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ impl AnimatedImageLoader {
#[cfg(feature = "gif")]
{
let decoder = image::codecs::gif::GifDecoder::new(Cursor::new(bytes))
.map_err(|err| AnimatedImageLoaderError::DecodingError(err))?;
.map_err(AnimatedImageLoaderError::DecodingError)?;
let frames = decoder.into_frames();
frames
.collect_frames()
.map_err(|err| AnimatedImageLoaderError::DecodingError(err))?
.map_err(AnimatedImageLoaderError::DecodingError)?
}
#[cfg(not(feature = "gif"))]
{
Expand All @@ -58,11 +58,11 @@ impl AnimatedImageLoader {
#[cfg(feature = "webp")]
{
let decoder = image::codecs::webp::WebPDecoder::new(Cursor::new(bytes))
.map_err(|err| AnimatedImageLoaderError::DecodingError(err))?;
.map_err(AnimatedImageLoaderError::DecodingError)?;
let frames = decoder.into_frames();
frames
.collect_frames()
.map_err(|err| AnimatedImageLoaderError::DecodingError(err))?
.map_err(AnimatedImageLoaderError::DecodingError)?
}
#[cfg(not(feature = "webp"))]
{
Expand Down Expand Up @@ -97,7 +97,7 @@ impl AnimatedImageLoader {
app: &mut App,
) -> Result<Handle<AnimatedImage>, AnimatedImageLoaderError> {
let mut images = app.world_mut().resource_mut::<Assets<Image>>();
let bytes = std::fs::read(&path).map_err(|err| AnimatedImageLoaderError::IoError(err))?;
let bytes = std::fs::read(&path).map_err(AnimatedImageLoaderError::IoError)?;
let gif = Self::internal_load(bytes, &mut *images, Path::new(&path))?;
Ok(app
.world_mut()
Expand Down Expand Up @@ -130,7 +130,7 @@ impl AssetLoader for AnimatedImageLoader {
reader
.read_to_end(&mut bytes)
.await
.map_err(|err| AnimatedImageLoaderError::IoError(err))?;
.map_err(AnimatedImageLoaderError::IoError)?;
let path = load_context.path().to_owned();
let gif = Self::internal_load(bytes, load_context, &path)?;
Ok(gif)
Expand Down

0 comments on commit 640ae4e

Please sign in to comment.