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 tag_support(&self, tag_type: TagType) -> TagSupport { ... }
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::file::{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::file::TaggedFileExt;
use lofty::tag::TagType;
// 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::file::TaggedFileExt;
use lofty::tag::TagType;
// 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::file::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::tag_support()
If a tag is replaced, it will be returned
§Examples
use lofty::file::{AudioFile, TaggedFileExt};
use lofty::tag::{Tag, TagType};
// 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::file::{AudioFile, TaggedFileExt};
use lofty::tag::TagType;
// 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::file::TaggedFileExt;
use lofty::tag::TagType;
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;
assert_eq!(tagged_file.primary_tag_type(), TagType::Id3v2);Sourcefn tag_support(&self, tag_type: TagType) -> TagSupport
fn tag_support(&self, tag_type: TagType) -> TagSupport
Determines whether the file supports the given TagType
§Examples
use lofty::file::TaggedFileExt;
use lofty::tag::TagType;
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;
// MP3 supports both reading and writing ID3v2
assert!(tagged_file.tag_support(TagType::Id3v2).is_writable());
// But doesn't support Vorbis Comments at all
assert!(
!tagged_file
.tag_support(TagType::VorbisComments)
.is_readable()
);Sourcefn primary_tag(&self) -> Option<&Tag>
fn primary_tag(&self) -> Option<&Tag>
Returns the primary tag
See FileType::primary_tag_type
§Examples
use lofty::file::TaggedFileExt;
use lofty::tag::TagType;
// 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::file::TaggedFileExt;
use lofty::tag::TagType;
// 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::file::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());