Trait lofty::TaggedFileExt
source · pub trait TaggedFileExt {
Show 13 methods
// Required methods
fn file_type(&self) -> FileType;
fn tags(&self) -> &[Tag];
fn tag(&self, tag_type: TagType) -> Option<&Tag>;
fn tag_mut(&mut self, tag_type: TagType) -> Option<&mut Tag>;
fn first_tag_mut(&mut self) -> Option<&mut Tag>;
fn insert_tag(&mut self, tag: Tag) -> Option<Tag>;
fn remove(&mut self, tag_type: TagType) -> Option<Tag>;
fn clear(&mut self);
// Provided methods
fn primary_tag_type(&self) -> TagType { ... }
fn supports_tag_type(&self, tag_type: TagType) -> bool { ... }
fn primary_tag(&self) -> Option<&Tag> { ... }
fn primary_tag_mut(&mut self) -> Option<&mut Tag> { ... }
fn first_tag(&self) -> Option<&Tag> { ... }
}
Expand description
Provides a common interface between TaggedFile
and BoundTaggedFile
Required Methods§
Returns all tags
§Examples
use lofty::{FileType, TaggedFileExt};
// An MP3 file with 3 tags
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;
let tags = tagged_file.tags();
assert_eq!(tags.len(), 3);
sourcefn tag(&self, tag_type: TagType) -> Option<&Tag>
fn tag(&self, tag_type: TagType) -> Option<&Tag>
Get a reference to a specific TagType
§Examples
use lofty::{TagType, TaggedFileExt};
// Read an MP3 file with an ID3v2 tag
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;
// An ID3v2 tag
let tag = tagged_file.tag(TagType::Id3v2);
assert!(tag.is_some());
assert_eq!(tag.unwrap().tag_type(), TagType::Id3v2);
sourcefn tag_mut(&mut self, tag_type: TagType) -> Option<&mut Tag>
fn tag_mut(&mut self, tag_type: TagType) -> Option<&mut Tag>
Get a mutable reference to a specific TagType
§Examples
use lofty::{TagType, TaggedFileExt};
// Read an MP3 file with an ID3v2 tag
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;
// An ID3v2 tag
let tag = tagged_file.tag(TagType::Id3v2);
assert!(tag.is_some());
assert_eq!(tag.unwrap().tag_type(), TagType::Id3v2);
// Alter the tag...
sourcefn first_tag_mut(&mut self) -> Option<&mut Tag>
fn first_tag_mut(&mut self) -> Option<&mut Tag>
Gets a mutable reference to the first tag, if there are any
NOTE: This will grab the first available tag, you cannot rely on the result being a specific type
§Examples
use lofty::TaggedFileExt;
// A file we know has tags
let mut tagged_file = lofty::read_from_path(path)?;
// A tag of a (currently) unknown type
let tag = tagged_file.first_tag_mut();
assert!(tag.is_some());
// Alter the tag...
sourcefn insert_tag(&mut self, tag: Tag) -> Option<Tag>
fn insert_tag(&mut self, tag: Tag) -> Option<Tag>
Inserts a Tag
NOTE: This will do nothing if the FileType
does not support
the TagType
. See FileType::supports_tag_type
If a tag is replaced, it will be returned
§Examples
use lofty::{AudioFile, Tag, TagType, TaggedFileExt};
// Read an MP3 file without an ID3v2 tag
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;
assert!(!tagged_file.contains_tag_type(TagType::Id3v2));
// Insert the ID3v2 tag
let new_id3v2_tag = Tag::new(TagType::Id3v2);
tagged_file.insert_tag(new_id3v2_tag);
assert!(tagged_file.contains_tag_type(TagType::Id3v2));
sourcefn remove(&mut self, tag_type: TagType) -> Option<Tag>
fn remove(&mut self, tag_type: TagType) -> Option<Tag>
Removes a specific TagType
and returns it
§Examples
use lofty::{AudioFile, TagType, TaggedFileExt};
// Read an MP3 file containing an ID3v2 tag
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;
assert!(tagged_file.contains_tag_type(TagType::Id3v2));
// Take the ID3v2 tag
let id3v2 = tagged_file.remove(TagType::Id3v2);
assert!(!tagged_file.contains_tag_type(TagType::Id3v2));
Provided Methods§
sourcefn primary_tag_type(&self) -> TagType
fn primary_tag_type(&self) -> TagType
Returns the file type’s primary TagType
See FileType::primary_tag_type
§Examples
use lofty::{TagType, TaggedFileExt};
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;
assert_eq!(tagged_file.primary_tag_type(), TagType::Id3v2);
sourcefn supports_tag_type(&self, tag_type: TagType) -> bool
fn supports_tag_type(&self, tag_type: TagType) -> bool
sourcefn primary_tag(&self) -> Option<&Tag>
fn primary_tag(&self) -> Option<&Tag>
Returns the primary tag
See FileType::primary_tag_type
§Examples
use lofty::{TagType, TaggedFileExt};
// Read an MP3 file with an ID3v2 tag
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;
// An ID3v2 tag
let tag = tagged_file.primary_tag();
assert!(tag.is_some());
assert_eq!(tag.unwrap().tag_type(), TagType::Id3v2);
sourcefn primary_tag_mut(&mut self) -> Option<&mut Tag>
fn primary_tag_mut(&mut self) -> Option<&mut Tag>
Gets a mutable reference to the file’s “Primary tag”
See FileType::primary_tag_type
§Examples
use lofty::{TagType, TaggedFileExt};
// Read an MP3 file with an ID3v2 tag
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;
// An ID3v2 tag
let tag = tagged_file.primary_tag_mut();
assert!(tag.is_some());
assert_eq!(tag.unwrap().tag_type(), TagType::Id3v2);
// Alter the tag...
sourcefn first_tag(&self) -> Option<&Tag>
fn first_tag(&self) -> Option<&Tag>
Gets the first tag, if there are any
NOTE: This will grab the first available tag, you cannot rely on the result being a specific type
§Examples
use lofty::TaggedFileExt;
// A file we know has tags
let mut tagged_file = lofty::read_from_path(path)?;
// A tag of a (currently) unknown type
let tag = tagged_file.first_tag();
assert!(tag.is_some());