From adb8db9dde15599a9c580f0a7fe8c27f5c57f399 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Tue, 7 Sep 2021 01:46:42 -0400 Subject: [PATCH] Add mutable getter methods for all file tags --- src/logic/ape/mod.rs | 18 ++++++++++++++++++ src/logic/iff/aiff/mod.rs | 12 ++++++++++++ src/logic/iff/wav/mod.rs | 12 ++++++++++++ src/logic/mp4/mod.rs | 7 +++++++ src/logic/mpeg/mod.rs | 18 ++++++++++++++++++ src/logic/ogg/flac/mod.rs | 6 ++++++ src/logic/ogg/opus/mod.rs | 6 ++++++ src/logic/ogg/vorbis/mod.rs | 6 ++++++ 8 files changed, 85 insertions(+) diff --git a/src/logic/ape/mod.rs b/src/logic/ape/mod.rs index bc6be88a..e9f5f01a 100644 --- a/src/logic/ape/mod.rs +++ b/src/logic/ape/mod.rs @@ -58,15 +58,33 @@ impl ApeFile { self.id3v2.as_ref() } + #[cfg(feature = "id3v2")] + /// Returns a mutable reference to the ID3v2 tag if it exists + pub fn id3v2_tag_mut(&mut self) -> Option<&mut Tag> { + self.id3v2.as_mut() + } + #[cfg(feature = "id3v1")] /// Returns a reference to the ID3v1 tag if it exists pub fn id3v1_tag(&self) -> Option<&Tag> { self.id3v1.as_ref() } + #[cfg(feature = "id3v1")] + /// Returns a mutable reference to the ID3v1 tag if it exists + pub fn id3v1_tag_mut(&mut self) -> Option<&mut Tag> { + self.id3v1.as_mut() + } + #[cfg(feature = "ape")] /// Returns a reference to the APEv1/2 tag if it exists pub fn ape_tag(&self) -> Option<&Tag> { self.ape.as_ref() } + + #[cfg(feature = "ape")] + /// Returns a mutable reference to the APEv1/2 tag if it exists + pub fn ape_tag_mut(&mut self) -> Option<&mut Tag> { + self.ape.as_mut() + } } diff --git a/src/logic/iff/aiff/mod.rs b/src/logic/iff/aiff/mod.rs index 79ccc1cb..b8714fa5 100644 --- a/src/logic/iff/aiff/mod.rs +++ b/src/logic/iff/aiff/mod.rs @@ -53,9 +53,21 @@ impl AiffFile { self.id3v2.as_ref() } + #[cfg(feature = "id3v2")] + /// Returns a mutable reference to the ID3v2 tag if it exists + pub fn id3v2_tag_mut(&mut self) -> Option<&mut Tag> { + self.id3v2.as_mut() + } + #[cfg(feature = "aiff_text_chunks")] /// Returns a reference to the text chunks tag if it exists pub fn text_chunks(&self) -> Option<&Tag> { self.text_chunks.as_ref() } + + #[cfg(feature = "aiff_text_chunks")] + /// Returns a mutable reference to the text chunks tag if it exists + pub fn text_chunks_mut(&mut self) -> Option<&mut Tag> { + self.text_chunks.as_mut() + } } diff --git a/src/logic/iff/wav/mod.rs b/src/logic/iff/wav/mod.rs index 2a639e17..41645e87 100644 --- a/src/logic/iff/wav/mod.rs +++ b/src/logic/iff/wav/mod.rs @@ -53,9 +53,21 @@ impl WavFile { self.id3v2.as_ref() } + #[cfg(feature = "id3v2")] + /// Returns a mutable reference to the ID3v2 tag if it exists + pub fn id3v2_tag_mut(&mut self) -> Option<&mut Tag> { + self.id3v2.as_mut() + } + #[cfg(feature = "riff_info_list")] /// Returns a reference to the RIFF INFO tag if it exists pub fn riff_info(&self) -> Option<&Tag> { self.riff_info.as_ref() } + + #[cfg(feature = "riff_info_list")] + /// Returns a mutable reference to the RIFF INFO tag if it exists + pub fn riff_info_mut(&mut self) -> Option<&mut Tag> { + self.riff_info.as_mut() + } } diff --git a/src/logic/mp4/mod.rs b/src/logic/mp4/mod.rs index ef192002..15aef5da 100644 --- a/src/logic/mp4/mod.rs +++ b/src/logic/mp4/mod.rs @@ -50,9 +50,16 @@ impl Mp4File { pub fn ftyp(&self) -> &str { self.ftyp.as_ref() } + #[cfg(feature = "mp4_atoms")] /// Returns a reference to the "ilst" tag if it exists pub fn ilst(&self) -> Option<&Tag> { self.ilst.as_ref() } + + #[cfg(feature = "mp4_atoms")] + /// Returns a mutable reference to the "ilst" tag if it exists + pub fn ilst_mut(&mut self) -> Option<&mut Tag> { + self.ilst.as_mut() + } } diff --git a/src/logic/mpeg/mod.rs b/src/logic/mpeg/mod.rs index 2cae6654..844a4811 100644 --- a/src/logic/mpeg/mod.rs +++ b/src/logic/mpeg/mod.rs @@ -55,15 +55,33 @@ impl MpegFile { self.id3v2.as_ref() } + #[cfg(feature = "id3v2")] + /// Returns a mutable reference to the ID3v2 tag if it exists + pub fn id3v2_tag_mut(&mut self) -> Option<&mut Tag> { + self.id3v2.as_mut() + } + #[cfg(feature = "id3v1")] /// Returns a reference to the ID3v1 tag if it exists pub fn id3v1_tag(&self) -> Option<&Tag> { self.id3v1.as_ref() } + #[cfg(feature = "id3v1")] + /// Returns a mutable reference to the ID3v1 tag if it exists + pub fn id3v1_tag_mut(&mut self) -> Option<&mut Tag> { + self.id3v1.as_mut() + } + #[cfg(feature = "ape")] /// Returns a reference to the APEv1/2 tag if it exists pub fn ape_tag(&self) -> Option<&Tag> { self.ape.as_ref() } + + #[cfg(feature = "ape")] + /// Returns a mutable reference to the APEv1/2 tag if it exists + pub fn ape_tag_mut(&mut self) -> Option<&mut Tag> { + self.ape.as_mut() + } } diff --git a/src/logic/ogg/flac/mod.rs b/src/logic/ogg/flac/mod.rs index 669b7e1a..ed4b6160 100644 --- a/src/logic/ogg/flac/mod.rs +++ b/src/logic/ogg/flac/mod.rs @@ -54,4 +54,10 @@ impl FlacFile { pub fn vorbis_comments(&self) -> Option<&Tag> { self.vorbis_comments.as_ref() } + + #[cfg(feature = "vorbis_comments")] + /// Returns a mutable reference to the Vorbis comments tag if it exists + pub fn vorbis_comments_mut(&mut self) -> Option<&mut Tag> { + self.vorbis_comments.as_mut() + } } diff --git a/src/logic/ogg/opus/mod.rs b/src/logic/ogg/opus/mod.rs index d5af15ed..31010555 100644 --- a/src/logic/ogg/opus/mod.rs +++ b/src/logic/ogg/opus/mod.rs @@ -61,4 +61,10 @@ impl OpusFile { pub fn vorbis_comments(&self) -> &Tag { &self.vorbis_comments } + + #[cfg(feature = "vorbis_comments")] + /// Returns a mutable reference to the Vorbis comments tag + pub fn vorbis_comments_mut(&mut self) -> &mut Tag { + &mut self.vorbis_comments + } } diff --git a/src/logic/ogg/vorbis/mod.rs b/src/logic/ogg/vorbis/mod.rs index 04fa0211..d2ae32e2 100644 --- a/src/logic/ogg/vorbis/mod.rs +++ b/src/logic/ogg/vorbis/mod.rs @@ -62,4 +62,10 @@ impl VorbisFile { pub fn vorbis_comments(&self) -> &Tag { &self.vorbis_comments } + + #[cfg(feature = "vorbis_comments")] + /// Returns a mutable reference to the Vorbis comments tag + pub fn vorbis_comments_mut(&mut self) -> &mut Tag { + &mut self.vorbis_comments + } }