From 9698e3cbc06c9a4e12666faec19ff25402b5528c Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Tue, 6 Jul 2021 21:33:10 -0400 Subject: [PATCH] Cleanup Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com> --- src/components/logic/flac.rs | 5 ++--- src/components/logic/ogg/write.rs | 8 ++++---- src/components/logic/riff.rs | 10 +++------- src/components/tags/ape_tag.rs | 12 +++++------- src/components/tags/id3_tag.rs | 10 ++++------ src/components/tags/mp4_tag.rs | 8 +++----- src/components/tags/ogg_tag.rs | 10 ++-------- src/components/tags/riff_tag.rs | 5 ++--- src/tag.rs | 1 + src/types/picture.rs | 15 ++++++++------- 10 files changed, 34 insertions(+), 50 deletions(-) diff --git a/src/components/logic/flac.rs b/src/components/logic/flac.rs index f2694d55..38b341c9 100644 --- a/src/components/logic/flac.rs +++ b/src/components/logic/flac.rs @@ -1,12 +1,11 @@ -#![cfg(feature = "format-flac")] - use crate::{Picture, Result}; -use metaflac::BlockType; use std::borrow::Cow; use std::collections::HashMap; use std::io::{Read, Seek, SeekFrom, Write}; +use metaflac::BlockType; + pub(crate) fn write_to( mut data: T, vendor: &str, diff --git a/src/components/logic/ogg/write.rs b/src/components/logic/ogg/write.rs index df1da820..3ec84fbc 100644 --- a/src/components/logic/ogg/write.rs +++ b/src/components/logic/ogg/write.rs @@ -1,3 +1,4 @@ +use super::{is_metadata, page_from_packet}; use crate::{LoftyError, Picture, Result}; #[cfg(feature = "format-opus")] @@ -5,15 +6,14 @@ use crate::components::logic::ogg::constants::OPUSTAGS; #[cfg(feature = "format-vorbis")] use crate::components::logic::ogg::constants::{VORBIS_COMMENT_HEAD, VORBIS_SETUP_HEAD}; -use byteorder::{LittleEndian, ReadBytesExt}; use std::borrow::Cow; use std::collections::HashMap; - -use crate::components::logic::ogg::{is_metadata, page_from_packet}; -use ogg_pager::Page; use std::fs::File; use std::io::{Cursor, Read, Seek, SeekFrom, Write}; +use byteorder::{LittleEndian, ReadBytesExt}; +use ogg_pager::Page; + pub(crate) fn create_pages( file: &mut File, sig: &[u8], diff --git a/src/components/logic/riff.rs b/src/components/logic/riff.rs index c9ad59c8..1671ee70 100644 --- a/src/components/logic/riff.rs +++ b/src/components/logic/riff.rs @@ -1,14 +1,10 @@ use crate::{LoftyError, Result}; -use byteorder::{LittleEndian, ReadBytesExt}; use std::collections::HashMap; use std::fs::File; use std::io::{Cursor, Read, Seek, SeekFrom, Write}; -// Used to determine the RIFF metadata format -pub const LIST_ID: &[u8] = b"LIST"; - -// FourCC +use byteorder::{LittleEndian, ReadBytesExt}; // Standard pub const IART: &[u8] = &[73, 65, 82, 84]; @@ -75,7 +71,7 @@ where let mut chunk_name = [0; 4]; data.read_exact(&mut chunk_name)?; - if chunk_name == LIST_ID { + if &chunk_name == b"LIST" { data.seek(SeekFrom::Current(4))?; let mut list_type = [0; 4]; @@ -140,7 +136,7 @@ pub fn key_to_fourcc(key: &str) -> Option<&[u8]> { pub(crate) fn write_to(data: &mut File, metadata: HashMap) -> Result<()> { let mut packet = Vec::new(); - packet.extend(LIST_ID.iter()); + packet.extend(b"LIST".iter()); packet.extend(b"INFO".iter()); for (k, v) in metadata { diff --git a/src/components/tags/ape_tag.rs b/src/components/tags/ape_tag.rs index 36cbc4e8..657c3de7 100644 --- a/src/components/tags/ape_tag.rs +++ b/src/components/tags/ape_tag.rs @@ -1,18 +1,16 @@ -#![cfg(feature = "format-ape")] - +use crate::types::picture::APE_PICTYPES; use crate::{ Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite, Picture, Result, TagType, ToAny, ToAnyTag, }; -use lofty_attr::impl_tag; -pub use ape::Tag as ApeInnerTag; - -use crate::types::picture::APE_PICTYPES; -use ape::Item; use std::borrow::Cow; use std::fs::File; use std::io::{Read, Seek}; +use ape::Item; +pub use ape::Tag as ApeInnerTag; +use lofty_attr::impl_tag; + #[impl_tag(ApeInnerTag, TagType::Ape)] pub struct ApeTag; diff --git a/src/components/tags/id3_tag.rs b/src/components/tags/id3_tag.rs index bebb6ff4..a23d3e5c 100644 --- a/src/components/tags/id3_tag.rs +++ b/src/components/tags/id3_tag.rs @@ -1,20 +1,18 @@ -#![cfg(feature = "format-id3")] - use crate::tag::Id3Format; use crate::{ Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite, LoftyError, MimeType, Picture, PictureType, Result, TagType, ToAny, ToAnyTag, }; -use lofty_attr::impl_tag; -pub use id3::Tag as Id3v2InnerTag; - -use filepath::FilePath; use std::borrow::Cow; use std::convert::{TryFrom, TryInto}; use std::fs::File; use std::io::{Read, Seek, SeekFrom}; +use filepath::FilePath; +pub use id3::Tag as Id3v2InnerTag; +use lofty_attr::impl_tag; + #[impl_tag(Id3v2InnerTag, TagType::Id3v2(Id3Format::Default))] pub struct Id3v2Tag; diff --git a/src/components/tags/mp4_tag.rs b/src/components/tags/mp4_tag.rs index fd66fa79..43d8f3f6 100644 --- a/src/components/tags/mp4_tag.rs +++ b/src/components/tags/mp4_tag.rs @@ -1,17 +1,15 @@ -#![cfg(feature = "format-mp4")] - use crate::{ Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite, LoftyError, MimeType, Picture, PictureType, Result, TagType, ToAny, ToAnyTag, }; -use lofty_attr::impl_tag; - -pub use mp4ameta::{Fourcc, Tag as Mp4InnerTag}; use std::borrow::Cow; use std::fs::File; use std::io::{Read, Seek}; +use lofty_attr::impl_tag; +pub use mp4ameta::{Fourcc, Tag as Mp4InnerTag}; + #[impl_tag(Mp4InnerTag, TagType::Mp4)] pub struct Mp4Tag {} diff --git a/src/components/tags/ogg_tag.rs b/src/components/tags/ogg_tag.rs index 86e355b7..0943edfc 100644 --- a/src/components/tags/ogg_tag.rs +++ b/src/components/tags/ogg_tag.rs @@ -1,9 +1,3 @@ -#![cfg(any( - feature = "format-vorbis", - feature = "format-opus", - feature = "format-flac" -))] - #[cfg(feature = "format-flac")] use crate::components::logic::flac; #[cfg(any(feature = "format-opus", feature = "format-vorbis"))] @@ -20,14 +14,14 @@ use crate::{ #[cfg(any(feature = "format-opus", feature = "format-vorbis"))] use crate::components::logic::ogg::read::OGGTags; -use lofty_attr::impl_tag; - use std::borrow::Cow; use std::collections::HashMap; use std::convert::{TryFrom, TryInto}; use std::fs::File; use std::io::{Read, Seek, SeekFrom}; +use lofty_attr::impl_tag; + struct OggInnerTag { vendor: String, comments: HashMap, diff --git a/src/components/tags/riff_tag.rs b/src/components/tags/riff_tag.rs index b4205f31..92dd7dea 100644 --- a/src/components/tags/riff_tag.rs +++ b/src/components/tags/riff_tag.rs @@ -1,16 +1,15 @@ -#![cfg(feature = "format-riff")] - use crate::components::logic::riff; use crate::{ Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite, Picture, Result, TagType, ToAny, ToAnyTag, }; -use lofty_attr::impl_tag; use std::borrow::Cow; use std::collections::HashMap; use std::fs::File; use std::io::{Read, Seek}; +use lofty_attr::impl_tag; + struct RiffInnerTag { data: HashMap, } diff --git a/src/tag.rs b/src/tag.rs index 77c2549d..67a1c56d 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -1,6 +1,7 @@ #[allow(clippy::wildcard_imports)] use crate::components::tags::*; use crate::{AudioTag, LoftyError, Result}; + use std::io::{Cursor, Read, Seek, SeekFrom}; use std::path::Path; diff --git a/src/types/picture.rs b/src/types/picture.rs index 612049fa..eccf9a5e 100644 --- a/src/types/picture.rs +++ b/src/types/picture.rs @@ -1,12 +1,5 @@ use crate::{LoftyError, Result}; -#[cfg(any( - feature = "format-id3", - feature = "format-opus", - feature = "format-vorbis", - feature = "format-flac", -))] -use byteorder::{BigEndian, ReadBytesExt}; use std::borrow::Cow; use std::convert::TryFrom; #[cfg(any( @@ -18,6 +11,14 @@ use std::convert::TryFrom; ))] use std::io::{Cursor, Read}; +#[cfg(any( + feature = "format-id3", + feature = "format-opus", + feature = "format-vorbis", + feature = "format-flac", +))] +use byteorder::{BigEndian, ReadBytesExt}; + #[cfg(feature = "format-ape")] pub const APE_PICTYPES: [&str; 21] = [ "Other",