misc: Introduce prelude

This commit is contained in:
Serial 2024-04-10 14:08:28 -04:00 committed by Alex
parent 9cf5d9c2ab
commit df0be9e53e
28 changed files with 97 additions and 65 deletions

View file

@ -1,4 +1,6 @@
use lofty::{Accessor, AudioFile, Probe, TaggedFileExt};
use lofty::prelude::*;
use lofty::{Probe, TaggedFileExt};
use std::path::Path;
fn main() {

View file

@ -1,4 +1,5 @@
use lofty::{Accessor, Probe, Tag, TagExt, TaggedFileExt, WriteOptions};
use lofty::prelude::*;
use lofty::{Probe, Tag, TaggedFileExt, WriteOptions};
use structopt::StructOpt;

View file

@ -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<proc_macro2::TokenSt
let struct_name = &file.struct_info.name;
let ret = quote! {
#assert_properties_impl
impl ::lofty::AudioFile for #struct_name {
impl ::lofty::prelude::AudioFile for #struct_name {
type Properties = #properties_field_ty;
fn read_from<R>(reader: &mut R, parse_options: ::lofty::ParseOptions) -> ::lofty::error::Result<Self>
@ -446,7 +446,7 @@ fn generate_audiofile_impl(file: &LoftyFile) -> syn::Result<proc_macro2::TokenSt
}
fn save_to(&self, file: &mut ::std::fs::File, write_options: ::lofty::WriteOptions) -> ::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,

View file

@ -544,9 +544,10 @@ pub(crate) fn tagitems_into_ape(tag: &Tag) -> impl Iterator<Item = ApeItemRef<'_
#[cfg(test)]
mod tests {
use crate::ape::{ApeItem, ApeTag};
use crate::{Accessor, ItemKey, ItemValue, Tag, TagExt, TagItem, TagType, WriteOptions};
use crate::id3::v2::util::pairs::DEFAULT_NUMBER_IN_PAIR;
use crate::prelude::*;
use crate::{ItemKey, ItemValue, Tag, TagItem, TagType, WriteOptions};
use std::io::Cursor;
#[test]

View file

@ -441,7 +441,8 @@ impl<'a> 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() {

View file

@ -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.

View file

@ -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() {

View file

@ -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]

View file

@ -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]

View file

@ -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};
}

View file

@ -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 {

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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]

View file

@ -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]

View file

@ -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]

View file

@ -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;

View file

@ -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]

View file

@ -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

View file

@ -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]

View file

@ -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"));

View file

@ -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]

View file

@ -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]

View file

@ -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<A: AudioFile>(path: &str) -> bool {
let res = <A as AudioFile>::read_from(

View file

@ -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;

View file

@ -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() {

View file

@ -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<<WavFile as AudioFile>::Properties> {
let mut f = File::open(path).unwrap();
let wav_file = WavFile::read_from(&mut f, ParseOptions::new())?;