From b69da26af1ab2abbb63cf501459fb33d5a73e464 Mon Sep 17 00:00:00 2001 From: Saecki Date: Mon, 28 Aug 2023 13:40:36 +0200 Subject: [PATCH] refactor: enforce rust_2018_idioms --- src/atom/data.rs | 4 ++-- src/atom/ident.rs | 20 ++++++++++---------- src/error.rs | 4 ++-- src/lib.rs | 24 ++---------------------- src/tag/genre.rs | 2 +- src/tag/mod.rs | 24 ++++++++++++------------ src/tag/readonly.rs | 10 +++++----- src/tag/tuple.rs | 4 ++-- 8 files changed, 36 insertions(+), 56 deletions(-) diff --git a/src/atom/data.rs b/src/atom/data.rs index e939f32..4beabdb 100644 --- a/src/atom/data.rs +++ b/src/atom/data.rs @@ -350,7 +350,7 @@ impl Data { /// Returns a reference to an image if `self` is of type [`Self::Jpeg`], [`Self::Png`] or /// [`Self::Bmp`]. - pub fn image(&self) -> Option { + pub fn image(&self) -> Option> { match self { Self::Jpeg(v) => Some(Img::new(ImgFmt::Jpeg, v)), Self::Png(v) => Some(Img::new(ImgFmt::Png, v)), @@ -361,7 +361,7 @@ impl Data { /// Returns a mutable reference to an image if `self` is of type [`Self::Jpeg`], [`Self::Png`] /// or [`Self::Bmp`]. - pub fn image_mut(&mut self) -> Option { + pub fn image_mut(&mut self) -> Option> { match self { Self::Jpeg(v) => Some(Img::new(ImgFmt::Jpeg, v)), Self::Png(v) => Some(Img::new(ImgFmt::Png, v)), diff --git a/src/atom/ident.rs b/src/atom/ident.rs index 439fbe7..60b9254 100644 --- a/src/atom/ident.rs +++ b/src/atom/ident.rs @@ -147,16 +147,16 @@ pub const SHOW_MOVEMENT: Fourcc = Fourcc(*b"shwm"); pub const APPLE_ITUNES_MEAN: &str = "com.apple.iTunes"; /// (`----:com.apple.iTunes:ISRC`) -pub const ISRC: FreeformIdent = FreeformIdent::new(APPLE_ITUNES_MEAN, "ISRC"); +pub const ISRC: FreeformIdent<'_> = FreeformIdent::new(APPLE_ITUNES_MEAN, "ISRC"); /// (`----:com.apple.iTunes:LYRICIST`) -pub const LYRICIST: FreeformIdent = FreeformIdent::new(APPLE_ITUNES_MEAN, "LYRICIST"); +pub const LYRICIST: FreeformIdent<'_> = FreeformIdent::new(APPLE_ITUNES_MEAN, "LYRICIST"); /// A trait providing information about an identifier. pub trait Ident: PartialEq { /// Returns a 4 byte atom identifier. fn fourcc(&self) -> Option; /// Returns a freeform identifier. - fn freeform(&self) -> Option; + fn freeform(&self) -> Option>; } // TODO: figure out how to implement PartialEq for Ident or require an implementation as a trait bound. @@ -197,7 +197,7 @@ impl Ident for Fourcc { Some(*self) } - fn freeform(&self) -> Option { + fn freeform(&self) -> Option> { None } } @@ -245,13 +245,13 @@ impl Ident for FreeformIdent<'_> { None } - fn freeform(&self) -> Option { + fn freeform(&self) -> Option> { Some(self.clone()) } } impl fmt::Display for FreeformIdent<'_> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "----:{}:{}", self.mean, self.name) } } @@ -285,7 +285,7 @@ impl Ident for DataIdent { } } - fn freeform(&self) -> Option { + fn freeform(&self) -> Option> { match self { Self::Fourcc(_) => None, Self::Freeform { mean, name } => Some(FreeformIdent::new(mean.as_str(), name.as_str())), @@ -294,7 +294,7 @@ impl Ident for DataIdent { } impl fmt::Display for DataIdent { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Fourcc(ident) => write!(f, "{ident}"), Self::Freeform { mean, name } => write!(f, "----:{mean}:{name}"), @@ -309,13 +309,13 @@ impl From for DataIdent { } impl From> for DataIdent { - fn from(value: FreeformIdent) -> Self { + fn from(value: FreeformIdent<'_>) -> Self { Self::freeform(value.mean, value.name) } } impl From<&FreeformIdent<'_>> for DataIdent { - fn from(value: &FreeformIdent) -> Self { + fn from(value: &FreeformIdent<'_>) -> Self { Self::freeform(value.mean, value.name) } } diff --git a/src/error.rs b/src/error.rs index 4006800..9aafdf2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -84,7 +84,7 @@ impl From for Error { } impl fmt::Debug for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.description.is_empty() { write!(f, "{:?}", self.kind) } else { @@ -94,7 +94,7 @@ impl fmt::Debug for Error { } impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.description.is_empty() { write!(f, "{:?}", self.kind) } else { diff --git a/src/lib.rs b/src/lib.rs index c35fa10..ec53db9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,28 +39,8 @@ //! tag.set_data(isrc_ident, Data::Utf8("isrc".to_owned())); //! tag.write_to_path("music.m4a").unwrap(); //! ``` -#![deny( - bad_style, - dead_code, - improper_ctypes, - non_shorthand_field_patterns, - no_mangle_generic_items, - overflowing_literals, - path_statements, - patterns_in_fns_without_body, - private_in_public, - unconditional_recursion, - unused, - unused_allocation, - unused_comparisons, - unused_parens, - while_true, - missing_docs, - trivial_casts, - trivial_numeric_casts, - unused_extern_crates, - unused_import_braces -)] +#![deny(rust_2018_idioms)] + pub use crate::atom::{ident, Data, DataIdent, Fourcc, FreeformIdent, Ident}; pub use crate::error::{Error, ErrorKind, Result}; pub use crate::tag::{Tag, STANDARD_GENRES}; diff --git a/src/tag/genre.rs b/src/tag/genre.rs index 4b19f5a..06e8369 100644 --- a/src/tag/genre.rs +++ b/src/tag/genre.rs @@ -199,7 +199,7 @@ impl Tag { } /// Returns all genres formatted in an easily readable way. - pub(crate) fn format_genres(&self, f: &mut fmt::Formatter) -> fmt::Result { + pub(crate) fn format_genres(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.genres().count() > 1 { writeln!(f, "genres:")?; for v in self.genres() { diff --git a/src/tag/mod.rs b/src/tag/mod.rs index be4caca..0a8f464 100644 --- a/src/tag/mod.rs +++ b/src/tag/mod.rs @@ -30,7 +30,7 @@ pub struct Tag { } impl fmt::Display for Tag { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.format_album_artists(f)?; self.format_artists(f)?; self.format_composers(f)?; @@ -168,12 +168,12 @@ mp4ameta_proc::u32_value_accessor!("tv_season", "tvsn"); /// ### Artwork impl Tag { /// Returns all artwork images (`covr`). - pub fn artworks(&self) -> impl Iterator { + pub fn artworks(&self) -> impl Iterator> { self.images_of(&ident::ARTWORK) } /// Returns the first artwork image (`covr`). - pub fn artwork(&self) -> Option { + pub fn artwork(&self) -> Option> { self.images_of(&ident::ARTWORK).next() } @@ -213,8 +213,8 @@ impl Tag { } /// Returns information about all artworks formatted in an easily readable way. - fn format_artworks(&self, f: &mut fmt::Formatter) -> fmt::Result { - fn format_artwork(f: &mut fmt::Formatter, i: ImgRef) -> fmt::Result { + fn format_artworks(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn format_artwork(f: &mut fmt::Formatter<'_>, i: ImgRef<'_>) -> fmt::Result { match i.fmt { ImgFmt::Png => write!(f, "png")?, ImgFmt::Jpeg => write!(f, "jpeg")?, @@ -272,7 +272,7 @@ impl Tag { self.remove_data_of(&ident::MEDIA_TYPE); } - fn format_media_type(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn format_media_type(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.media_type() { Some(m) => writeln!(f, "media type: {m}"), None => Ok(()), @@ -303,7 +303,7 @@ impl Tag { self.remove_data_of(&ident::ADVISORY_RATING); } - fn format_advisory_rating(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn format_advisory_rating(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.advisory_rating() { Some(r) => writeln!(f, "advisory rating: {r}"), None => Ok(()), @@ -438,7 +438,7 @@ impl Tag { /// let img = tag.images_of(&test).next().unwrap(); /// assert_eq!(img.data, b"image"); /// ``` - pub fn images_of<'a>(&'a self, ident: &'a impl Ident) -> impl Iterator { + pub fn images_of<'a>(&'a self, ident: &'a impl Ident) -> impl Iterator> { self.data_of(ident).filter_map(Data::image) } @@ -706,7 +706,7 @@ impl Tag { /// assert_eq!(images.next().unwrap(), (&test, Img::jpeg(&b"image2"[..]))); /// assert_eq!(images.next(), None); /// ``` - pub fn images(&self) -> impl Iterator { + pub fn images(&self) -> impl Iterator)> { self.data().filter_map(|(i, d)| Some((i, d.image()?))) } @@ -730,7 +730,7 @@ impl Tag { /// assert_eq!(images.next().unwrap(), (&test, Img::bmp(&b"data1"[..]))); /// assert_eq!(images.next(), None); /// ``` - pub fn images_mut(&mut self) -> impl Iterator { + pub fn images_mut(&mut self) -> impl Iterator)> { self.data_mut().filter_map(|(i, d)| Some((i, d.image_mut()?))) } @@ -1022,7 +1022,7 @@ impl Tag { /// assert_eq!(images.next(), Some(Img::new(ImgFmt::Jpeg, &[6; 16][..]))); /// assert_eq!(images.next(), None); /// ``` - pub fn retain_images_of(&mut self, ident: &impl Ident, predicate: impl Fn(ImgRef) -> bool) { + pub fn retain_images_of(&mut self, ident: &impl Ident, predicate: impl Fn(ImgRef<'_>) -> bool) { #[allow(clippy::redundant_closure)] self.retain_data_of(ident, |d| d.image().map_or(true, |i| predicate(i))) } @@ -1155,7 +1155,7 @@ impl Tag { /// assert_eq!(data.next(), Some(&Data::Utf8("data3".into()))); /// assert_eq!(data.next(), None); /// ``` - pub fn retain_images(&mut self, predicate: impl Fn(&DataIdent, ImgRef) -> bool) { + pub fn retain_images(&mut self, predicate: impl Fn(&DataIdent, ImgRef<'_>) -> bool) { self.retain_data(|i, d| d.image().map_or(true, |s| predicate(i, s))); } diff --git a/src/tag/readonly.rs b/src/tag/readonly.rs index de913c3..9a2c30d 100644 --- a/src/tag/readonly.rs +++ b/src/tag/readonly.rs @@ -16,7 +16,7 @@ impl Tag { } /// Returns the duration formatted in an easily readable way. - pub(crate) fn format_duration(&self, f: &mut fmt::Formatter) -> fmt::Result { + pub(crate) fn format_duration(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let duration = match self.duration() { Some(d) => d, None => return Ok(()), @@ -44,7 +44,7 @@ impl Tag { self.info.channel_config } - pub(crate) fn format_channel_config(&self, f: &mut fmt::Formatter) -> fmt::Result { + pub(crate) fn format_channel_config(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.channel_config() { Some(c) => writeln!(f, "channel config: {c}"), None => Ok(()), @@ -56,7 +56,7 @@ impl Tag { self.info.sample_rate } - pub(crate) fn format_sample_rate(&self, f: &mut fmt::Formatter) -> fmt::Result { + pub(crate) fn format_sample_rate(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.sample_rate() { Some(r) => writeln!(f, "sample rate: {r}"), None => Ok(()), @@ -68,7 +68,7 @@ impl Tag { self.info.avg_bitrate } - pub(crate) fn format_avg_bitrate(&self, f: &mut fmt::Formatter) -> fmt::Result { + pub(crate) fn format_avg_bitrate(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.avg_bitrate() { Some(c) => writeln!(f, "average bitrate: {}kbps", c / 1024), None => Ok(()), @@ -80,7 +80,7 @@ impl Tag { self.info.max_bitrate } - pub(crate) fn format_max_bitrate(&self, f: &mut fmt::Formatter) -> fmt::Result { + pub(crate) fn format_max_bitrate(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.max_bitrate() { Some(c) => writeln!(f, "maximum bitrate: {}kbps", c / 1024), None => Ok(()), diff --git a/src/tag/tuple.rs b/src/tag/tuple.rs index 234292d..7bb3a96 100644 --- a/src/tag/tuple.rs +++ b/src/tag/tuple.rs @@ -88,7 +88,7 @@ impl Tag { } /// Returns the track numer and total number of tracks formatted in an easily readable way. - pub(crate) fn format_track(&self, f: &mut fmt::Formatter) -> fmt::Result { + pub(crate) fn format_track(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.track() { (Some(n), Some(t)) => writeln!(f, "track: {n} of {t}"), (Some(n), None) => writeln!(f, "track: {n}"), @@ -184,7 +184,7 @@ impl Tag { } /// Returns the disc numer and total number of discs formatted in an easily readable way. - pub(crate) fn format_disc(&self, f: &mut fmt::Formatter) -> fmt::Result { + pub(crate) fn format_disc(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.disc() { (Some(d), Some(t)) => writeln!(f, "disc: {d} of {t}"), (Some(d), None) => writeln!(f, "disc: {d}"),