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, ItemKey
s 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
sourceimpl Tag
impl Tag
sourcepub fn item_count(&self) -> u32
pub fn item_count(&self) -> u32
Returns the number of TagItem
s
sourcepub fn picture_count(&self) -> u32
pub fn picture_count(&self) -> u32
Returns the number of Picture
s
sourcepub fn get_item_ref(&self, item_key: &ItemKey) -> Option<&TagItem>
pub fn get_item_ref(&self, item_key: &ItemKey) -> Option<&TagItem>
sourcepub fn get_string(&self, item_key: &ItemKey) -> Option<&str>
pub fn get_string(&self, item_key: &ItemKey) -> Option<&str>
Get a string value from an ItemKey
sourcepub fn get_binary(&self, item_key: &ItemKey, convert: bool) -> Option<&[u8]>
pub fn get_binary(&self, item_key: &ItemKey, convert: bool) -> Option<&[u8]>
Gets a byte slice from an ItemKey
Use convert
to convert ItemValue::Text
and ItemValue::Locator
to byte slices
sourcepub fn insert_item(&mut self, item: TagItem) -> bool
pub fn insert_item(&mut self, item: TagItem) -> bool
sourcepub fn insert_item_unchecked(&mut self, item: TagItem)
pub fn insert_item_unchecked(&mut self, item: TagItem)
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
.
sourcepub fn push_item(&mut self, item: TagItem) -> bool
pub fn push_item(&mut self, item: TagItem) -> bool
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.
sourcepub fn push_item_unchecked(&mut self, item: TagItem)
pub fn push_item_unchecked(&mut self, item: TagItem)
Append a TagItem
to the tag
Notes: See Tag::insert_item_unchecked
sourcepub fn insert_text(&mut self, item_key: ItemKey, text: String) -> bool
pub fn insert_text(&mut self, item_key: ItemKey, text: String) -> bool
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
sourcepub fn take(&mut self, key: &ItemKey) -> impl Iterator<Item = TagItem> + '_
pub fn take(&mut self, key: &ItemKey) -> impl Iterator<Item = TagItem> + '_
Removes all items with the specified ItemKey
, and returns them
sourcepub fn take_strings(
&mut self,
key: &ItemKey
) -> impl Iterator<Item = String> + '_
pub fn take_strings(
&mut self,
key: &ItemKey
) -> impl Iterator<Item = String> + '_
Removes all items with the specified ItemKey
, and filters them through ItemValue::into_string
sourcepub fn get_items<'a>(
&'a self,
key: &'a ItemKey
) -> impl Iterator<Item = &'a TagItem>
pub fn get_items<'a>(
&'a self,
key: &'a ItemKey
) -> impl Iterator<Item = &'a TagItem>
Returns references to all TagItem
s with the specified key
sourcepub fn get_texts<'a>(
&'a self,
key: &'a ItemKey
) -> impl Iterator<Item = &'a str>
pub fn get_texts<'a>(
&'a self,
key: &'a ItemKey
) -> impl Iterator<Item = &'a str>
Returns references to all texts of TagItem
s with the specified key, and ItemValue::Text
sourcepub fn get_locators<'a>(
&'a self,
key: &'a ItemKey
) -> impl Iterator<Item = &'a str>
pub fn get_locators<'a>(
&'a self,
key: &'a ItemKey
) -> impl Iterator<Item = &'a str>
Returns references to all locators of TagItem
s with the specified key, and ItemValue::Locator
sourcepub fn get_bytes<'a>(
&'a self,
key: &'a ItemKey
) -> impl Iterator<Item = &'a [u8]>
pub fn get_bytes<'a>(
&'a self,
key: &'a ItemKey
) -> impl Iterator<Item = &'a [u8]>
Returns references to all bytes of TagItem
s with the specified key, and ItemValue::Binary
sourcepub fn remove_key(&mut self, key: &ItemKey)
pub fn remove_key(&mut self, key: &ItemKey)
Remove an item by its key
This will remove all items with this key.
sourcepub fn retain_items<F>(&mut self, f: F) where
F: FnMut(&TagItem) -> bool,
pub fn retain_items<F>(&mut self, f: F) where
F: FnMut(&TagItem) -> bool,
Retain tag items based on the predicate
See Vec::retain
sourcepub fn get_picture_type(&self, picture_type: PictureType) -> Option<&Picture>
pub fn get_picture_type(&self, picture_type: PictureType) -> Option<&Picture>
Returns the first occurrence of the PictureType
sourcepub fn push_picture(&mut self, picture: Picture)
pub fn push_picture(&mut self, picture: Picture)
Pushes a Picture
to the tag
sourcepub fn remove_picture_type(&mut self, picture_type: PictureType)
pub fn remove_picture_type(&mut self, picture_type: PictureType)
Removes all Picture
s of a PictureType
Trait Implementations
sourceimpl Accessor for Tag
impl Accessor for Tag
sourcefn set_artist(&mut self, value: String)
fn set_artist(&mut self, value: String)
Sets the artist Read more
sourcefn remove_artist(&mut self)
fn remove_artist(&mut self)
Removes the artist Read more
sourcefn remove_title(&mut self)
fn remove_title(&mut self)
Removes the title Read more
sourcefn remove_album(&mut self)
fn remove_album(&mut self)
Removes the album Read more
sourcefn remove_genre(&mut self)
fn remove_genre(&mut self)
Removes the genre Read more
sourceimpl From<AiffTextChunks> for Tag
impl From<AiffTextChunks> for Tag
sourcefn from(input: AiffTextChunks) -> Self
fn from(input: AiffTextChunks) -> Self
Converts to this type from the input type.
sourceimpl From<RiffInfoList> for Tag
impl From<RiffInfoList> for Tag
sourcefn from(input: RiffInfoList) -> Self
fn from(input: RiffInfoList) -> Self
Converts to this type from the input type.
sourceimpl From<Tag> for AiffTextChunks
impl From<Tag> for AiffTextChunks
sourceimpl From<Tag> for RiffInfoList
impl From<Tag> for RiffInfoList
sourceimpl From<Tag> for VorbisComments
impl From<Tag> for VorbisComments
sourceimpl From<VorbisComments> for Tag
impl From<VorbisComments> for Tag
sourcefn from(input: VorbisComments) -> Self
fn from(input: VorbisComments) -> Self
Converts to this type from the input type.
sourceimpl IntoIterator for Tag
impl IntoIterator for Tag
sourceimpl TagExt for Tag
impl TagExt for Tag
sourcefn save_to(&self, file: &mut File) -> Result<(), Self::Err>
fn save_to(&self, file: &mut File) -> Result<(), Self::Err>
Save the Tag
to a File
Errors
- A
FileType
couldn’t be determined from the File - Attempting to write a tag to a format that does not support it. See
FileType::supports_tag_type
type Err = LoftyError
type Err = LoftyError
The associated error which can be returned from IO operations
Auto Trait Implementations
impl RefUnwindSafe for Tag
impl Send for Tag
impl Sync for Tag
impl Unpin for Tag
impl UnwindSafe for Tag
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more