diff --git a/examples/tag_reader.rs b/examples/tag_reader.rs index d486241e..96bfb369 100644 --- a/examples/tag_reader.rs +++ b/examples/tag_reader.rs @@ -1,4 +1,6 @@ -use lofty::{Accessor, AudioFile, Probe, TaggedFileExt}; +use lofty::prelude::*; +use lofty::{Probe, TaggedFileExt}; + use std::path::Path; fn main() { diff --git a/examples/tag_writer.rs b/examples/tag_writer.rs index f72a9ce7..9a08844b 100644 --- a/examples/tag_writer.rs +++ b/examples/tag_writer.rs @@ -1,4 +1,5 @@ -use lofty::{Accessor, Probe, Tag, TagExt, TaggedFileExt, WriteOptions}; +use lofty::prelude::*; +use lofty::{Probe, Tag, TaggedFileExt, WriteOptions}; use structopt::StructOpt; diff --git a/lofty_attr/src/lofty_file.rs b/lofty_attr/src/lofty_file.rs index 12bd8137..50bf7d03 100644 --- a/lofty_attr/src/lofty_file.rs +++ b/lofty_attr/src/lofty_file.rs @@ -178,7 +178,7 @@ impl LoftyFile { let name = format_ident!("_AssertTagExt{}", i); let field_ty = &f.ty; quote_spanned! {field_ty.span()=> - struct #name where #field_ty: lofty::TagExt; + struct #name where #field_ty: ::lofty::prelude::TagExt; } }); @@ -435,7 +435,7 @@ fn generate_audiofile_impl(file: &LoftyFile) -> syn::Result(reader: &mut R, parse_options: ::lofty::ParseOptions) -> ::lofty::error::Result @@ -446,7 +446,7 @@ fn generate_audiofile_impl(file: &LoftyFile) -> syn::Result ::lofty::error::Result<()> { - use ::lofty::TagExt as _; + use ::lofty::prelude::TagExt as _; use ::std::io::Seek as _; #save_to_body } @@ -533,7 +533,7 @@ fn generate_from_taggedfile_impl(file: &LoftyFile) -> proc_macro2::TokenStream { quote! { impl ::std::convert::From<#struct_name> for ::lofty::TaggedFile { fn from(input: #struct_name) -> Self { - use ::lofty::TaggedFileExt as _; + use ::lofty::prelude::TaggedFileExt as _; ::lofty::TaggedFile::new( #file_type_variant, diff --git a/src/ape/tag/mod.rs b/src/ape/tag/mod.rs index ec2d76f2..e4a4e8a3 100644 --- a/src/ape/tag/mod.rs +++ b/src/ape/tag/mod.rs @@ -544,9 +544,10 @@ pub(crate) fn tagitems_into_ape(tag: &Tag) -> impl Iterator Id3v1TagRef<'a> { #[cfg(test)] mod tests { use crate::id3::v1::Id3v1Tag; - use crate::{Tag, TagExt, TagType, WriteOptions}; + use crate::prelude::*; + use crate::{Tag, TagType, WriteOptions}; #[test] fn parse_id3v1() { diff --git a/src/id3/v2/read.rs b/src/id3/v2/read.rs index 3bb369bc..622b8ed7 100644 --- a/src/id3/v2/read.rs +++ b/src/id3/v2/read.rs @@ -116,7 +116,9 @@ fn zero_size_id3v2() { #[test] fn bad_frame_id_relaxed_id3v2() { use crate::id3::v2::header::Id3v2Header; - use crate::{Accessor, ParsingMode, TagExt}; + use crate::prelude::*; + use crate::ParsingMode; + use std::io::Cursor; // Contains a frame with a "+" in the ID, which is invalid. diff --git a/src/id3/v2/write/mod.rs b/src/id3/v2/write/mod.rs index 008648f4..b2b07e03 100644 --- a/src/id3/v2/write/mod.rs +++ b/src/id3/v2/write/mod.rs @@ -284,7 +284,8 @@ fn calculate_crc(content: &[u8]) -> [u8; 5] { #[cfg(test)] mod tests { use crate::id3::v2::{Id3v2Tag, Id3v2TagFlags}; - use crate::{Accessor, TagExt, WriteOptions}; + use crate::prelude::*; + use crate::WriteOptions; #[test] fn id3v2_write_crc32() { diff --git a/src/iff/aiff/tag.rs b/src/iff/aiff/tag.rs index 0b607e88..5bbc0f07 100644 --- a/src/iff/aiff/tag.rs +++ b/src/iff/aiff/tag.rs @@ -484,9 +484,10 @@ where #[cfg(test)] mod tests { use crate::iff::aiff::{AIFFTextChunks, Comment}; - use crate::{ItemKey, ItemValue, Tag, TagExt, TagItem, TagType, WriteOptions}; - + use crate::prelude::*; use crate::probe::ParseOptions; + use crate::{ItemKey, ItemValue, Tag, TagItem, TagType, WriteOptions}; + use std::io::Cursor; #[test] diff --git a/src/iff/wav/tag/mod.rs b/src/iff/wav/tag/mod.rs index 5906239f..8e732bd3 100644 --- a/src/iff/wav/tag/mod.rs +++ b/src/iff/wav/tag/mod.rs @@ -348,11 +348,13 @@ pub(crate) fn tagitems_into_riff<'a>( #[cfg(test)] mod tests { - use crate::iff::wav::RIFFInfoList; - use crate::{Tag, TagExt, TagType, WriteOptions}; - use crate::iff::chunk::Chunks; + use crate::iff::wav::RIFFInfoList; + use crate::prelude::*; + use crate::{Tag, TagType, WriteOptions}; + use byteorder::LittleEndian; + use std::io::Cursor; #[test] diff --git a/src/lib.rs b/src/lib.rs index 904643f4..8bbe9166 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -174,21 +174,32 @@ mod util; pub mod wavpack; mod write_options; -pub use crate::error::{LoftyError, Result}; - pub use crate::probe::{read_from, read_from_path, ParseOptions, ParsingMode, Probe}; pub use crate::write_options::WriteOptions; -pub use crate::file::{AudioFile, BoundTaggedFile, FileType, TaggedFile, TaggedFileExt}; +pub use crate::file::{BoundTaggedFile, FileType, TaggedFile, TaggedFileExt}; pub use crate::picture::{MimeType, Picture, PictureType}; pub use crate::tag::{Tag, TagType}; pub use tag::item::{ItemKey, ItemValue, TagItem}; pub use util::text::TextEncoding; -pub use crate::traits::{Accessor, MergeTag, SplitTag, TagExt}; - pub use picture::PictureInformation; pub use global_options::{apply_global_options, GlobalOptions}; pub use lofty_attr::LoftyFile; + +pub mod prelude { + //! A prelude for commonly used items in the library. + //! + //! This module is intended to be glob imported. + //! + //! ```rust + //! use lofty::prelude::*; + //! ``` + + pub use crate::error::LoftyError; + pub use crate::file::{AudioFile, TaggedFileExt}; + pub use crate::tag::item::ItemKey; + pub use crate::traits::{Accessor, MergeTag, SplitTag, TagExt}; +} diff --git a/src/mp4/ilst/mod.rs b/src/mp4/ilst/mod.rs index 7fd00d02..3ab103b4 100644 --- a/src/mp4/ilst/mod.rs +++ b/src/mp4/ilst/mod.rs @@ -763,12 +763,13 @@ mod tests { use crate::mp4::ilst::TITLE; use crate::mp4::read::AtomReader; use crate::mp4::{AdvisoryRating, Atom, AtomData, AtomIdent, Ilst, Mp4File}; + use crate::prelude::*; use crate::tag::utils::test_utils; use crate::tag::utils::test_utils::read_path; use crate::{ - Accessor as _, AudioFile, ItemKey, ItemValue, ParseOptions, ParsingMode, SplitTag as _, - Tag, TagExt as _, TagItem, TagType, WriteOptions, + ItemKey, ItemValue, ParseOptions, ParsingMode, Tag, TagItem, TagType, WriteOptions, }; + use std::io::{Cursor, Read as _, Seek as _, Write as _}; fn read_ilst(path: &str, parse_mode: ParsingMode) -> Ilst { diff --git a/src/ogg/tag.rs b/src/ogg/tag.rs index a4567e90..e5a6b9c5 100644 --- a/src/ogg/tag.rs +++ b/src/ogg/tag.rs @@ -694,10 +694,8 @@ pub(crate) fn create_vorbis_comments_ref( #[cfg(test)] mod tests { use crate::ogg::{OggPictureStorage, VorbisComments}; - use crate::{ - ItemKey, ItemValue, MergeTag as _, ParsingMode, SplitTag as _, Tag, TagExt as _, TagItem, - TagType, WriteOptions, - }; + use crate::prelude::*; + use crate::{ItemKey, ItemValue, ParsingMode, Tag, TagItem, TagType, WriteOptions}; fn read_tag(tag: &[u8]) -> VorbisComments { let mut reader = std::io::Cursor::new(tag); diff --git a/src/properties/tests.rs b/src/properties/tests.rs index 27489472..7112bf3d 100644 --- a/src/properties/tests.rs +++ b/src/properties/tests.rs @@ -1,5 +1,6 @@ use crate::aac::{AACProperties, AacFile}; use crate::ape::{ApeFile, ApeProperties}; +use crate::file::AudioFile; use crate::flac::{FlacFile, FlacProperties}; use crate::iff::aiff::{AiffFile, AiffProperties}; use crate::iff::wav::{WavFile, WavFormat, WavProperties}; @@ -15,7 +16,6 @@ use crate::ogg::{ use crate::probe::ParseOptions; use crate::properties::ChannelMask; use crate::wavpack::{WavPackFile, WavPackProperties}; -use crate::AudioFile; use std::fs::File; use std::time::Duration; diff --git a/src/tag/mod.rs b/src/tag/mod.rs index 7a6b0513..b6115875 100644 --- a/src/tag/mod.rs +++ b/src/tag/mod.rs @@ -663,8 +663,10 @@ impl TagType { #[cfg(test)] mod tests { use super::try_parse_year; + use crate::prelude::*; use crate::tag::utils::test_utils::read_path; - use crate::{Accessor, Picture, PictureType, Tag, TagExt, TagType, WriteOptions}; + use crate::{Picture, PictureType, Tag, TagType, WriteOptions}; + use std::io::{Seek, Write}; use std::process::Command; diff --git a/tests/files/aac.rs b/tests/files/aac.rs index 5af2445a..13a0a9d2 100644 --- a/tests/files/aac.rs +++ b/tests/files/aac.rs @@ -1,8 +1,7 @@ use crate::{set_artist, temp_file, verify_artist}; -use lofty::{ - Accessor, FileType, ItemKey, ItemValue, ParseOptions, Probe, TagExt, TagItem, TagType, - TaggedFileExt, -}; +use lofty::prelude::*; +use lofty::{FileType, ItemKey, ItemValue, ParseOptions, Probe, TagItem, TagType, TaggedFileExt}; + use std::io::{Seek, Write}; #[test] diff --git a/tests/files/aiff.rs b/tests/files/aiff.rs index df459f37..30a3316b 100644 --- a/tests/files/aiff.rs +++ b/tests/files/aiff.rs @@ -1,7 +1,7 @@ use crate::{set_artist, temp_file, verify_artist}; -use lofty::{ - FileType, ItemKey, ItemValue, ParseOptions, Probe, TagExt, TagItem, TagType, TaggedFileExt, -}; +use lofty::prelude::*; +use lofty::{FileType, ItemKey, ItemValue, ParseOptions, Probe, TagItem, TagType, TaggedFileExt}; + use std::io::{Seek, Write}; #[test] diff --git a/tests/files/ape.rs b/tests/files/ape.rs index 502189f8..32b48e06 100644 --- a/tests/files/ape.rs +++ b/tests/files/ape.rs @@ -1,7 +1,7 @@ use crate::{set_artist, temp_file, verify_artist}; -use lofty::{ - FileType, ItemKey, ItemValue, ParseOptions, Probe, TagExt, TagItem, TagType, TaggedFileExt, -}; +use lofty::prelude::*; +use lofty::{FileType, ItemKey, ItemValue, ParseOptions, Probe, TagItem, TagType, TaggedFileExt}; + use std::io::{Seek, Write}; #[test] diff --git a/tests/files/flac.rs b/tests/files/flac.rs index 6d17b628..954938b1 100644 --- a/tests/files/flac.rs +++ b/tests/files/flac.rs @@ -1,5 +1,6 @@ use lofty::flac::FlacFile; -use lofty::{Accessor, AudioFile, ParseOptions, ParsingMode}; +use lofty::prelude::*; +use lofty::{ParseOptions, ParsingMode}; use std::fs::File; use std::io::Seek; diff --git a/tests/files/mp4.rs b/tests/files/mp4.rs index 946a6af6..abff918b 100644 --- a/tests/files/mp4.rs +++ b/tests/files/mp4.rs @@ -1,7 +1,7 @@ use crate::{set_artist, temp_file, verify_artist}; -use lofty::{ - FileType, ItemKey, ItemValue, ParseOptions, Probe, TagExt, TagItem, TagType, TaggedFileExt, -}; +use lofty::prelude::*; +use lofty::{FileType, ItemKey, ItemValue, ParseOptions, Probe, TagItem, TagType, TaggedFileExt}; + use std::io::{Seek, Write}; #[test] diff --git a/tests/files/mpc.rs b/tests/files/mpc.rs index 36484fa1..69cee552 100644 --- a/tests/files/mpc.rs +++ b/tests/files/mpc.rs @@ -1,9 +1,10 @@ use crate::{set_artist, temp_file, verify_artist}; use lofty::musepack::MpcFile; +use lofty::prelude::*; use lofty::{ - AudioFile, FileType, ItemKey, ItemValue, ParseOptions, Probe, TagExt, TagItem, TagType, - TaggedFile, TaggedFileExt, + FileType, ItemKey, ItemValue, ParseOptions, Probe, TagItem, TagType, TaggedFile, TaggedFileExt, }; + use std::io::{Seek, Write}; // Marker test so IntelliJ Rust recognizes this as a test module diff --git a/tests/files/mpeg.rs b/tests/files/mpeg.rs index 9bc9aa26..6b9c4040 100644 --- a/tests/files/mpeg.rs +++ b/tests/files/mpeg.rs @@ -1,12 +1,13 @@ use crate::{set_artist, temp_file, verify_artist}; -use std::borrow::Cow; - use lofty::id3::v2::{Frame, FrameFlags, FrameId, FrameValue, Id3v2Tag, KeyValueFrame}; use lofty::mpeg::MpegFile; +use lofty::prelude::*; use lofty::{ - Accessor, AudioFile, FileType, ItemKey, ItemValue, ParseOptions, Probe, Tag, TagExt, TagItem, - TagType, TaggedFileExt, WriteOptions, + FileType, ItemKey, ItemValue, ParseOptions, Probe, Tag, TagItem, TagType, TaggedFileExt, + WriteOptions, }; + +use std::borrow::Cow; use std::io::{Seek, Write}; #[test] diff --git a/tests/files/ogg.rs b/tests/files/ogg.rs index b6c808f9..9528eb36 100644 --- a/tests/files/ogg.rs +++ b/tests/files/ogg.rs @@ -1,8 +1,10 @@ use crate::{set_artist, temp_file, verify_artist}; +use lofty::prelude::*; use lofty::{ - FileType, ItemKey, ItemValue, ParseOptions, Probe, TagExt, TagItem, TagType, TaggedFileExt, + FileType, ItemKey, ItemValue, ParseOptions, Probe, TagItem, TagType, TaggedFileExt, WriteOptions, }; + use std::io::{Seek, Write}; // The tests for OGG Opus/Vorbis are nearly identical @@ -151,7 +153,6 @@ fn remove(path: &str, tag_type: TagType) { #[test] fn flac_with_id3v2() { use lofty::flac::FlacFile; - use lofty::{Accessor, AudioFile}; let file = std::fs::read("tests/files/assets/flac_with_id3v2.flac").unwrap(); let flac_file = @@ -174,7 +175,6 @@ fn flac_remove_id3v2() { #[test] fn flac_try_write_non_empty_id3v2() { use lofty::id3::v2::Id3v2Tag; - use lofty::Accessor; let mut tag = Id3v2Tag::default(); tag.set_artist(String::from("Foo artist")); diff --git a/tests/files/wav.rs b/tests/files/wav.rs index 0bbf2422..1bf888a1 100644 --- a/tests/files/wav.rs +++ b/tests/files/wav.rs @@ -1,7 +1,7 @@ use crate::{set_artist, temp_file, verify_artist}; -use lofty::{ - FileType, ItemKey, ItemValue, ParseOptions, Probe, TagExt, TagItem, TagType, TaggedFileExt, -}; +use lofty::prelude::*; +use lofty::{FileType, ItemKey, ItemValue, ParseOptions, Probe, TagItem, TagType, TaggedFileExt}; + use std::io::{Seek, Write}; #[test] diff --git a/tests/files/wavpack.rs b/tests/files/wavpack.rs index ae4c3b50..8e11de57 100644 --- a/tests/files/wavpack.rs +++ b/tests/files/wavpack.rs @@ -1,7 +1,7 @@ use crate::{set_artist, temp_file, verify_artist}; -use lofty::{ - FileType, ItemKey, ItemValue, ParseOptions, Probe, TagExt, TagItem, TagType, TaggedFileExt, -}; +use lofty::prelude::*; +use lofty::{FileType, ItemKey, ItemValue, ParseOptions, Probe, TagItem, TagType, TaggedFileExt}; + use std::io::{Seek, Write}; #[test] diff --git a/tests/files/zero_sized.rs b/tests/files/zero_sized.rs index 876dd2e7..07598501 100644 --- a/tests/files/zero_sized.rs +++ b/tests/files/zero_sized.rs @@ -4,7 +4,8 @@ use lofty::iff::aiff::AiffFile; use lofty::iff::wav::WavFile; use lofty::mp4::Mp4File; use lofty::mpeg::MpegFile; -use lofty::{AudioFile, ParseOptions, ParsingMode}; +use lofty::prelude::*; +use lofty::{ParseOptions, ParsingMode}; fn read_file_with_properties(path: &str) -> bool { let res = ::read_from( diff --git a/tests/fuzz/main.rs b/tests/fuzz/main.rs index 1404e48b..2141671c 100644 --- a/tests/fuzz/main.rs +++ b/tests/fuzz/main.rs @@ -1,4 +1,6 @@ -use lofty::{AudioFile, ParseOptions}; +use lofty::prelude::*; +use lofty::ParseOptions; + use std::io::Cursor; use std::path::Path; use std::thread; diff --git a/tests/fuzz/mpegfile_read_from.rs b/tests/fuzz/mpegfile_read_from.rs index 197f6e47..d51b48af 100644 --- a/tests/fuzz/mpegfile_read_from.rs +++ b/tests/fuzz/mpegfile_read_from.rs @@ -1,6 +1,7 @@ use crate::{get_reader, oom_test}; use lofty::mpeg::MpegFile; -use lofty::{AudioFile, ParseOptions}; +use lofty::prelude::*; +use lofty::ParseOptions; #[test] fn crash1() { diff --git a/tests/hound.rs b/tests/hound.rs index 2f8dd5d2..ad9b7f5a 100644 --- a/tests/hound.rs +++ b/tests/hound.rs @@ -1,11 +1,14 @@ +use lofty::error::Result; +use lofty::iff::wav::WavFile; +use lofty::prelude::*; +use lofty::ParseOptions; + +use hound::WavReader; + use std::fs; use std::fs::File; use std::path::Path; -use hound::WavReader; -use lofty::iff::wav::WavFile; -use lofty::{AudioFile, ParseOptions, Result}; - fn get_properties(path: &Path) -> Result<::Properties> { let mut f = File::open(path).unwrap(); let wav_file = WavFile::read_from(&mut f, ParseOptions::new())?;