Struct lofty::Tag

source · []
pub struct Tag { /* private fields */ }
Expand description

Represents a parsed tag

This is a tag that is loosely bound to a specific TagType. It is used for conversions and as the return type for read_from.

Compared to other formats, this gives a much higher-level view of the tag items. Rather than storing items according to their format-specific keys, ItemKeys are used.

You can easily remap this to another TagType with Tag::re_map.

Any conversion will, of course, be lossy to a varying degree.

Usage

Accessing common items

use lofty::{Accessor, Tag, TagType};

let tag = Tag::new(TagType::Id3v2);

// There are multiple quick getter methods for common items

let title = tag.title();
let artist = tag.artist();
let album = tag.album();
let genre = tag.genre();

Getting an item of a known type

use lofty::{ItemKey, Tag, TagType};

let tag = Tag::new(TagType::Id3v2);

// If the type of an item is known, there are getter methods
// to prevent having to match against the value

tag.get_string(&ItemKey::TrackTitle);
tag.get_binary(&ItemKey::TrackTitle, false);

Converting between formats

use lofty::id3::v2::Id3v2Tag;
use lofty::{Tag, TagType};

// Converting between formats is as simple as an `into` call.
// However, such conversions can potentially be *very* lossy.

let tag = Tag::new(TagType::Id3v2);
let id3v2_tag: Id3v2Tag = tag.into();

Implementations

Initialize a new tag with a certain TagType

Change the TagType, remapping all items

Returns the TagType

Returns the number of TagItems

Returns the number of Pictures

Returns the stored TagItems as a slice

Returns a reference to a TagItem matching an ItemKey

Get a string value from an ItemKey

Gets a byte slice from an ItemKey

Use convert to convert ItemValue::Text and ItemValue::Locator to byte slices

Insert a TagItem, replacing any existing one of the same ItemKey

NOTE: This will verify an ItemKey mapping exists for the target TagType

This will return true if the item was inserted.

Insert a TagItem, replacing any existing one of the same ItemKey

Notes:

  • This will not verify an ItemKey mapping exists
  • This will not allow writing item keys that are out of spec (keys are verified before writing)

This is only necessary if dealing with ItemKey::Unknown.

Append a TagItem to the tag

This will not remove any items of the same ItemKey, unlike Tag::insert_item

NOTE: This will verify an ItemKey mapping exists for the target TagType

Multiple items of the same ItemKey are not valid in all formats, in which case the first available item will be used.

This will return true if the item was pushed.

Append a TagItem to the tag

Notes: See Tag::insert_item_unchecked

An alias for Tag::insert_item that doesn’t require the user to create a TagItem

NOTE: This will replace any existing item with item_key. See Tag::insert_item

Removes all items with the specified ItemKey, and returns them

Removes all items with the specified ItemKey, and filters them through ItemValue::into_string

Returns references to all TagItems with the specified key

Returns references to all texts of TagItems with the specified key, and ItemValue::Text

Returns references to all locators of TagItems with the specified key, and ItemValue::Locator

Returns references to all bytes of TagItems with the specified key, and ItemValue::Binary

Remove an item by its key

This will remove all items with this key.

Retain tag items based on the predicate

See Vec::retain

Returns the stored Pictures as a slice

Returns the first occurrence of the PictureType

Pushes a Picture to the tag

Removes all Pictures of a PictureType

Trait Implementations

Returns the artist Read more

Sets the artist Read more

Removes the artist Read more

Returns the title Read more

Sets the title Read more

Removes the title Read more

Returns the album Read more

Sets the album Read more

Removes the album Read more

Returns the genre Read more

Sets the genre Read more

Removes the genre Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Save the Tag to a path

Errors
  • Path doesn’t exist
  • Path is not writable
  • See Tag::save_to

Save the Tag to a File

Errors

Remove a tag from a Path

Errors

See TagType::remove_from

Remove a tag from a File

Errors

See TagType::remove_from

The associated error which can be returned from IO operations

Whether the tag has any items Read more

Dump the tag to a writer Read more

Clear the tag, removing all items Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.