pub trait SplitTag {
type Remainder: MergeTag;
// Required method
fn split_tag(self) -> (Self::Remainder, Tag);
}
Expand description
Split (and merge) tags.
Useful and required for implementing lossless read/modify/write round trips.
Its counterpart MergeTag
is used for recombining the results later.
§Example
use lofty::mpeg::MpegFile;
use lofty::{AudioFile, ItemKey, MergeTag as _, SplitTag as _};
// Read the tag from a file
let mut mpeg_file = <MpegFile as AudioFile>::read_from(&mut file, parse_options)?;
let mut id3v2 = mpeg_file
.id3v2_mut()
.map(std::mem::take)
.unwrap_or_default();
// Split: ID3v2 -> [`lofty::Tag`]
let (mut remainder, mut tag) = id3v2.split_tag();
// Modify the metadata in the generic [`lofty::Tag`], independent
// of the underlying tag and file format.
tag.insert_text(ItemKey::TrackTitle, "Track Title".to_owned());
tag.remove_key(&ItemKey::Composer);
// ID3v2 <- [`lofty::Tag`]
let id3v2 = remainder.merge_tag(tag);
// Write the changes back into the file
mpeg_file.set_id3v2(id3v2);
mpeg_file.save_to(&mut file)?;