Switch to cfg-if for rustfmt support

This commit is contained in:
Serial 2022-02-12 14:33:00 -05:00
parent 8b39695a61
commit 91e5d5984b
16 changed files with 111 additions and 98 deletions

View file

@ -22,6 +22,8 @@ ogg_pager = "0.3.0"
once_cell = "1.9.0"
paste = "1.0.6"
byteorder = "1.4.3"
# TODO: rustfmt only works with cfg_if for now (https://github.com/rust-lang/rustfmt/issues/3253)
cfg-if = "1.0.0"
[features]
default = ["mp4_ilst", "vorbis_comments", "ape", "id3v1", "id3v2", "aiff_text_chunks", "riff_info_list"]

View file

@ -24,14 +24,14 @@ use std::io::{Read, Seek};
// Exports
crate::macros::feature_locked! {
#![cfg(feature = "ape")]
cfg_if::cfg_if! {
if #[cfg(feature = "ape")] {
pub(crate) mod tag;
pub use tag::ape_tag::ApeTag;
pub use tag::item::ApeItem;
pub(crate) mod tag;
pub use tag::ape_tag::ApeTag;
pub use tag::item::ApeItem;
pub use crate::types::picture::APE_PICTURE_TYPES;
pub use crate::types::picture::APE_PICTURE_TYPES;
}
}
pub use properties::ApeProperties;

View file

@ -16,14 +16,14 @@
//! Additionally, there is no track total field.
pub(crate) mod constants;
crate::macros::feature_locked! {
#![cfg(feature = "id3v1")]
cfg_if::cfg_if! {
if #[cfg(feature = "id3v1")] {
pub use constants::GENRES;
pub use constants::GENRES;
pub(crate) mod tag;
pub use tag::Id3v1Tag;
pub(crate) mod tag;
pub use tag::Id3v1Tag;
pub(crate) mod read;
pub(crate) mod write;
pub(crate) mod read;
pub(crate) mod write;
}
}

View file

@ -145,8 +145,7 @@ fn parse_user_defined(content: &mut &[u8], link: bool) -> Result<FrameValue> {
let description = decode_text(content, encoding, true)?.unwrap_or_default();
Ok(if link {
let content =
decode_text(content, TextEncoding::Latin1, false)?.unwrap_or_default();
let content = decode_text(content, TextEncoding::Latin1, false)?.unwrap_or_default();
FrameValue::UserURL(EncodedTextFrame {
encoding,

View file

@ -11,44 +11,43 @@ mod flags;
pub(crate) mod util;
use crate::error::{ErrorKind, Id3v2Error, Id3v2ErrorKind, LoftyError, Result};
use crate::macros::feature_locked;
use std::io::Read;
use byteorder::{BigEndian, ByteOrder, ReadBytesExt};
feature_locked! {
#![cfg(feature = "id3v2")]
cfg_if::cfg_if! {
if #[cfg(feature = "id3v2")] {
pub use flags::Id3v2TagFlags;
pub use util::text_utils::TextEncoding;
pub use util::upgrade::{upgrade_v2, upgrade_v3};
pub use flags::Id3v2TagFlags;
pub use util::text_utils::TextEncoding;
pub use util::upgrade::{upgrade_v2, upgrade_v3};
pub(crate) mod tag;
pub use tag::Id3v2Tag;
pub(crate) mod tag;
pub use tag::Id3v2Tag;
mod items;
pub use items::encapsulated_object::{GEOBInformation, GeneralEncapsulatedObject};
pub use items::sync_text::{SyncTextContentType, SyncTextInformation, SynchronizedText, TimestampFormat};
mod items;
pub use items::encapsulated_object::{GEOBInformation, GeneralEncapsulatedObject};
pub use items::sync_text::{SyncTextContentType, SyncTextInformation, SynchronizedText, TimestampFormat};
mod frame;
pub use frame::content::{EncodedTextFrame, LanguageFrame};
pub use frame::id::FrameID;
pub use frame::Frame;
pub use frame::FrameFlags;
pub use frame::FrameValue;
mod frame;
pub use frame::content::{EncodedTextFrame, LanguageFrame};
pub use frame::id::FrameID;
pub use frame::Frame;
pub use frame::FrameFlags;
pub use frame::FrameValue;
pub(crate) mod read;
pub(crate) mod write;
pub(crate) mod read;
pub(crate) mod write;
}
}
feature_locked! {
#![cfg(feature = "id3v2_restrictions")]
mod restrictions;
pub use restrictions::{
ImageSizeRestrictions, TagRestrictions, TagSizeRestrictions, TextSizeRestrictions,
};
cfg_if::cfg_if! {
if #[cfg(feature = "id3v2_restrictions")] {
mod restrictions;
pub use restrictions::{
ImageSizeRestrictions, TagRestrictions, TagSizeRestrictions, TextSizeRestrictions,
};
}
}
#[cfg(not(feature = "id3v2"))]

View file

@ -4,7 +4,7 @@ use crate::iff::chunk::Chunks;
use std::fs::File;
use std::io::{Read, Seek, SeekFrom, Write};
use byteorder::{ByteOrder, WriteBytesExt, ReadBytesExt};
use byteorder::{ByteOrder, ReadBytesExt, WriteBytesExt};
pub(in crate::id3::v2) fn write_to_chunk_file<B>(data: &mut File, tag: &[u8]) -> Result<()>
where

View file

@ -11,11 +11,11 @@ use crate::types::tag::{Tag, TagType};
use std::io::{Read, Seek};
crate::macros::feature_locked! {
#![cfg(feature = "aiff_text_chunks")]
pub(crate) mod tag;
use tag::AiffTextChunks;
cfg_if::cfg_if! {
if #[cfg(feature = "aiff_text_chunks")] {
pub(crate) mod tag;
use tag::AiffTextChunks;
}
}
/// An AIFF file

View file

@ -468,7 +468,9 @@ mod tests {
.unwrap();
// Create a fake AIFF signature
let mut writer = vec![b'F', b'O', b'R', b'M', 0, 0, 0, 0xC6, b'A', b'I', b'F', b'F'];
let mut writer = vec![
b'F', b'O', b'R', b'M', 0, 0, 0, 0xC6, b'A', b'I', b'F', b'F',
];
parsed_tag.dump_to(&mut writer).unwrap();
let temp_parsed_tag = super::super::read::read_from(&mut Cursor::new(writer), false)

View file

@ -3,22 +3,20 @@ pub(crate) mod aiff;
pub(crate) mod chunk;
pub(crate) mod wav;
use crate::macros::feature_locked;
// Exports
pub use aiff::AiffFile;
pub use wav::{WavFile, WavFormat, WavProperties};
feature_locked! {
#![cfg(feature = "aiff_text_chunks")]
pub use aiff::tag::AiffTextChunks;
pub use aiff::tag::Comment;
cfg_if::cfg_if! {
if #[cfg(feature = "aiff_text_chunks")] {
pub use aiff::tag::AiffTextChunks;
pub use aiff::tag::Comment;
}
}
feature_locked! {
#![cfg(feature = "riff_info_list")]
pub use wav::tag::RiffInfoList;
cfg_if::cfg_if! {
if #[cfg(feature = "riff_info_list")] {
pub use wav::tag::RiffInfoList;
}
}

View file

@ -11,11 +11,11 @@ use crate::types::tag::{Tag, TagType};
use std::io::{Read, Seek};
crate::macros::feature_locked! {
#![cfg(feature = "riff_info_list")]
pub(crate) mod tag;
use tag::RiffInfoList;
cfg_if::cfg_if! {
if #[cfg(feature = "riff_info_list")] {
pub(crate) mod tag;
use tag::RiffInfoList;
}
}
// Exports

View file

@ -152,7 +152,7 @@ impl From<Tag> for RiffInfoList {
let item_key = match item.item_key {
ItemKey::Unknown(unknown) => {
if !(unknown.len() == 4 && unknown.is_ascii()) {
continue
continue;
}
unknown
@ -230,9 +230,9 @@ mod tests {
use crate::iff::RiffInfoList;
use crate::{Tag, TagIO, TagType};
use std::io::Cursor;
use byteorder::LittleEndian;
use crate::iff::chunk::Chunks;
use byteorder::LittleEndian;
use std::io::Cursor;
#[test]
fn parse_riff_info() {
@ -296,8 +296,13 @@ mod tests {
let mut reader = std::io::Cursor::new(&tag_bytes[..]);
let mut riff_info = RiffInfoList::default();
super::read::parse_riff_info(&mut reader, &mut Chunks::<LittleEndian>::new(tag_bytes.len() as u32), (tag_bytes.len() - 1) as u64, &mut riff_info)
.unwrap();
super::read::parse_riff_info(
&mut reader,
&mut Chunks::<LittleEndian>::new(tag_bytes.len() as u32),
(tag_bytes.len() - 1) as u64,
&mut riff_info,
)
.unwrap();
let tag: Tag = riff_info.into();

View file

@ -30,17 +30,19 @@ macro_rules! tag_methods {
}
}
macro_rules! feature_locked {
(
#![cfg($meta:meta)]
$($item:item)+
) => {
$(
#[cfg($meta)]
$item
)+
}
}
// See cfg-if comment in `Cargo.toml`
//
// macro_rules! feature_locked {
// (
// #![cfg($meta:meta)]
// $($item:item)+
// ) => {
// $(
// #[cfg($meta)]
// $item
// )+
// }
// }
macro_rules! try_vec {
($elem:expr; $size:expr) => {{
@ -52,4 +54,4 @@ macro_rules! try_vec {
}};
}
pub(crate) use {feature_locked, tag_methods, try_vec};
pub(crate) use {tag_methods, try_vec};

View file

@ -2,10 +2,10 @@ use super::{Atom, AtomData, AtomIdent, Ilst};
use crate::error::{ErrorKind, LoftyError, Result};
use crate::id3::v1::constants::GENRES;
use crate::id3::v2::util::text_utils::utf16_decode;
use crate::macros::try_vec;
use crate::mp4::atom_info::AtomInfo;
use crate::mp4::read::skip_unneeded;
use crate::types::picture::{MimeType, Picture, PictureType};
use crate::macros::try_vec;
use std::borrow::Cow;
use std::io::{Cursor, Read, Seek, SeekFrom};

View file

@ -18,13 +18,14 @@ use std::io::{Read, Seek};
// Exports
crate::macros::feature_locked! {
#![cfg(feature = "mp4_ilst")]
pub(crate) mod ilst;
cfg_if::cfg_if! {
if #[cfg(feature = "mp4_ilst")] {
pub(crate) mod ilst;
pub use atom_info::AtomIdent;
pub use ilst::atom::{Atom, AtomData};
pub use ilst::Ilst;
pub use atom_info::AtomIdent;
pub use ilst::atom::{Atom, AtomData};
pub use ilst::Ilst;
}
}
pub use crate::mp4::properties::{Mp4Codec, Mp4Properties};

View file

@ -19,12 +19,13 @@ use ogg_pager::Page;
// Exports
crate::macros::feature_locked! {
#![cfg(feature = "vorbis_comments")]
pub(crate) mod write;
cfg_if::cfg_if! {
if #[cfg(feature = "vorbis_comments")] {
pub(crate) mod write;
pub(crate) mod tag;
pub use tag::VorbisComments;
pub(crate) mod tag;
pub use tag::VorbisComments;
}
}
pub use flac::FlacFile;

View file

@ -1,10 +1,10 @@
use super::verify_signature;
use crate::error::{ErrorKind, LoftyError, Result};
use crate::macros::try_vec;
use crate::ogg::constants::{OPUSTAGS, VORBIS_COMMENT_HEAD};
use crate::ogg::tag::VorbisCommentsRef;
use crate::types::picture::PictureInformation;
use crate::types::tag::{Tag, TagType};
use crate::macros::try_vec;
use std::convert::TryFrom;
use std::fs::File;
@ -106,7 +106,11 @@ pub(super) fn create_pages(
}
#[cfg(feature = "vorbis_comments")]
pub(super) fn write(data: &mut File, tag: &mut VorbisCommentsRef<'_>, format: OGGFormat) -> Result<()> {
pub(super) fn write(
data: &mut File,
tag: &mut VorbisCommentsRef<'_>,
format: OGGFormat,
) -> Result<()> {
let first_page = Page::read(data, false)?;
let ser = first_page.serial;