From 706a61383d8f75378bcf1896ad090bdd7d9aec81 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Tue, 24 Aug 2021 23:10:11 -0400 Subject: [PATCH] Switch from Into to From --- src/logic/ape/mod.rs | 13 ------ src/logic/iff/aiff.rs | 19 ++------- src/logic/iff/wav.rs | 19 ++------- src/logic/mpeg/mod.rs | 21 ++-------- src/logic/ogg/flac.rs | 18 +------- src/logic/ogg/opus.rs | 16 ++----- src/logic/ogg/vorbis.rs | 16 ++----- src/types/file.rs | 93 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 111 insertions(+), 104 deletions(-) diff --git a/src/logic/ape/mod.rs b/src/logic/ape/mod.rs index 9a4151b9..6d4e927b 100644 --- a/src/logic/ape/mod.rs +++ b/src/logic/ape/mod.rs @@ -22,19 +22,6 @@ pub struct ApeFile { pub(crate) properties: FileProperties, } -impl Into for ApeFile { - fn into(self) -> TaggedFile { - TaggedFile { - ty: FileType::APE, - properties: self.properties, - tags: vec![self.id3v1, self.id3v2, self.ape] - .into_iter() - .flatten() - .collect(), - } - } -} - impl AudioFile for ApeFile { fn read_from(reader: &mut R) -> Result where diff --git a/src/logic/iff/aiff.rs b/src/logic/iff/aiff.rs index 3bd01747..d0ad523a 100644 --- a/src/logic/iff/aiff.rs +++ b/src/logic/iff/aiff.rs @@ -11,24 +11,11 @@ use byteorder::{BigEndian, LittleEndian, ReadBytesExt}; /// An AIFF file pub struct AiffFile { /// The file's audio properties - properties: FileProperties, + pub(crate) properties: FileProperties, /// Any text chunks included in the file - text_chunks: Option, + pub(crate) text_chunks: Option, /// An ID3v2 tag - id3v2: Option, -} - -impl Into for AiffFile { - fn into(self) -> TaggedFile { - TaggedFile { - ty: FileType::AIFF, - properties: self.properties, - tags: vec![self.text_chunks, self.id3v2] - .into_iter() - .flatten() - .collect(), - } - } + pub(crate) id3v2: Option, } impl AudioFile for AiffFile { diff --git a/src/logic/iff/wav.rs b/src/logic/iff/wav.rs index 56c2ab14..82081924 100644 --- a/src/logic/iff/wav.rs +++ b/src/logic/iff/wav.rs @@ -19,24 +19,11 @@ const EXTENSIBLE: u16 = 0xfffe; /// A WAV file pub struct WavFile { /// The file's audio properties - properties: FileProperties, + pub(crate) properties: FileProperties, /// A RIFF INFO LIST - riff_info: Option, + pub(crate) riff_info: Option, /// An ID3v2 tag - id3v2: Option, -} - -impl Into for WavFile { - fn into(self) -> TaggedFile { - TaggedFile { - ty: FileType::WAV, - properties: self.properties, - tags: vec![self.riff_info, self.id3v2] - .into_iter() - .flatten() - .collect(), - } - } + pub(crate) id3v2: Option, } impl AudioFile for WavFile { diff --git a/src/logic/mpeg/mod.rs b/src/logic/mpeg/mod.rs index 1ab95200..d2f031b7 100644 --- a/src/logic/mpeg/mod.rs +++ b/src/logic/mpeg/mod.rs @@ -11,26 +11,13 @@ use std::io::{Read, Seek}; /// An MPEG file pub struct MpegFile { /// An ID3v2 tag - id3v2: Option, + pub(crate) id3v2: Option, /// An ID3v1 tag - id3v1: Option, + pub(crate) id3v1: Option, /// An APEv1/v2 tag - ape: Option, + pub(crate) ape: Option, /// The file's audio properties - properties: FileProperties, -} - -impl Into for MpegFile { - fn into(self) -> TaggedFile { - TaggedFile { - ty: FileType::MP3, - properties: self.properties, - tags: vec![self.id3v1, self.id3v2, self.ape] - .into_iter() - .flatten() - .collect(), - } - } + pub(crate) properties: FileProperties, } impl AudioFile for MpegFile { diff --git a/src/logic/ogg/flac.rs b/src/logic/ogg/flac.rs index 730d1041..2cf469e0 100644 --- a/src/logic/ogg/flac.rs +++ b/src/logic/ogg/flac.rs @@ -18,25 +18,11 @@ use byteorder::{BigEndian, LittleEndian, ReadBytesExt, WriteBytesExt}; /// A FLAC file pub struct FlacFile { /// The file's audio properties - properties: FileProperties, + pub(crate) properties: FileProperties, /// The vorbis comments contained in the file /// /// NOTE: This field being `Some` does not mean the file has vorbis comments, as Picture blocks exist. - metadata: Option, -} - -impl Into for FlacFile { - fn into(self) -> TaggedFile { - TaggedFile { - ty: FileType::FLAC, - properties: self.properties, - tags: if let Some(metadata) = self.metadata { - vec![metadata] - } else { - Vec::new() - }, - } - } + pub(crate) metadata: Option, } impl AudioFile for FlacFile { diff --git a/src/logic/ogg/opus.rs b/src/logic/ogg/opus.rs index dec4f42b..af0a2f09 100644 --- a/src/logic/ogg/opus.rs +++ b/src/logic/ogg/opus.rs @@ -16,23 +16,13 @@ use ogg_pager::Page; /// An OGG Opus file pub struct OpusFile { /// The file's audio properties - properties: FileProperties, + pub(crate) properties: FileProperties, /// The file vendor's name - vendor: String, + pub(crate) vendor: String, /// The vorbis comments contained in the file /// /// NOTE: While a metadata packet is required, it isn't required to actually have any data. - vorbis_comments: Tag, -} - -impl Into for OpusFile { - fn into(self) -> TaggedFile { - TaggedFile { - ty: FileType::Opus, - properties: self.properties, - tags: vec![self.vorbis_comments], - } - } + pub(crate) vorbis_comments: Tag, } impl AudioFile for OpusFile { diff --git a/src/logic/ogg/vorbis.rs b/src/logic/ogg/vorbis.rs index a0cca5c8..470e76a9 100644 --- a/src/logic/ogg/vorbis.rs +++ b/src/logic/ogg/vorbis.rs @@ -16,23 +16,13 @@ use ogg_pager::Page; /// An OGG Vorbis file pub struct VorbisFile { /// The file's audio properties - pub properties: FileProperties, + pub(crate) properties: FileProperties, /// The file vendor's name - pub vendor: String, + pub(crate) vendor: String, /// The vorbis comments contained in the file /// /// NOTE: While a metadata packet is required, it isn't required to actually have any data. - pub vorbis_comments: Tag, -} - -impl Into for VorbisFile { - fn into(self) -> TaggedFile { - TaggedFile { - ty: FileType::Vorbis, - properties: self.properties, - tags: vec![self.vorbis_comments], - } - } + pub(crate) vorbis_comments: Tag, } impl AudioFile for VorbisFile { diff --git a/src/types/file.rs b/src/types/file.rs index 7da803f9..d3bb1bab 100644 --- a/src/types/file.rs +++ b/src/types/file.rs @@ -1,6 +1,13 @@ use crate::logic::id3::v2::Id3v2Version; use crate::{FileProperties, LoftyError, Result, Tag, TagType}; +use crate::logic::ape::ApeFile; +use crate::logic::iff::aiff::AiffFile; +use crate::logic::iff::wav::WavFile; +use crate::logic::mpeg::MpegFile; +use crate::logic::ogg::flac::FlacFile; +use crate::logic::ogg::opus::OpusFile; +use crate::logic::ogg::vorbis::VorbisFile; use byteorder::ReadBytesExt; use std::convert::TryInto; use std::io::{Read, Seek, SeekFrom}; @@ -100,6 +107,92 @@ impl TaggedFile { } } +impl From for TaggedFile { + fn from(input: AiffFile) -> Self { + Self { + ty: FileType::AIFF, + properties: input.properties, + tags: vec![input.text_chunks, input.id3v2] + .into_iter() + .flatten() + .collect(), + } + } +} + +impl From for TaggedFile { + fn from(input: OpusFile) -> Self { + Self { + ty: FileType::Opus, + properties: input.properties, + tags: vec![input.vorbis_comments], + } + } +} + +impl From for TaggedFile { + fn from(input: VorbisFile) -> Self { + Self { + ty: FileType::Vorbis, + properties: input.properties, + tags: vec![input.vorbis_comments], + } + } +} + +impl From for TaggedFile { + fn from(input: FlacFile) -> Self { + Self { + ty: FileType::FLAC, + properties: input.properties, + tags: if let Some(metadata) = input.metadata { + vec![metadata] + } else { + Vec::new() + }, + } + } +} + +impl From for TaggedFile { + fn from(input: WavFile) -> Self { + Self { + ty: FileType::WAV, + properties: input.properties, + tags: vec![input.riff_info, input.id3v2] + .into_iter() + .flatten() + .collect(), + } + } +} + +impl From for TaggedFile { + fn from(input: MpegFile) -> Self { + Self { + ty: FileType::MP3, + properties: input.properties, + tags: vec![input.id3v1, input.id3v2, input.ape] + .into_iter() + .flatten() + .collect(), + } + } +} + +impl From for TaggedFile { + fn from(input: ApeFile) -> Self { + Self { + ty: FileType::APE, + properties: input.properties, + tags: vec![input.id3v1, input.id3v2, input.ape] + .into_iter() + .flatten() + .collect(), + } + } +} + #[derive(PartialEq, Copy, Clone, Debug)] #[allow(missing_docs)] /// The type of file read