Trait lofty::SplitTag

source ·
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)?;

Required Associated Types§

source

type Remainder: MergeTag

The remainder of the split operation that is not represented in the resulting Tag.

Required Methods§

source

fn split_tag(self) -> (Self::Remainder, Tag)

Extract and split generic contents into a Tag.

Returns the remaining content that cannot be represented in the resulting Tag in Self::Remainder. This is useful if the modified Tag is merged later using MergeTag::merge_tag.

Implementors§

source§

impl SplitTag for ApeTag

§

type Remainder = SplitTagRemainder

source§

impl SplitTag for Id3v1Tag

§

type Remainder = SplitTagRemainder

source§

impl SplitTag for Id3v2Tag

§

type Remainder = SplitTagRemainder

source§

impl SplitTag for AIFFTextChunks

§

type Remainder = SplitTagRemainder

source§

impl SplitTag for RIFFInfoList

§

type Remainder = SplitTagRemainder

source§

impl SplitTag for Ilst

§

type Remainder = SplitTagRemainder

source§

impl SplitTag for VorbisComments

§

type Remainder = SplitTagRemainder

source§

impl SplitTag for Tag

§

type Remainder = SplitTagRemainder