Trait lofty::TagExt

source ·
pub trait TagExt: Accessor + Into<Tag> + Sized {
    type Err: From<Error>;
    type RefKey<'a>
       where Self: 'a;

    // Required methods
    fn len(&self) -> usize;
    fn contains<'a>(&'a self, key: Self::RefKey<'a>) -> bool;
    fn is_empty(&self) -> bool;
    fn save_to(&self, file: &mut File) -> Result<(), Self::Err>;
    fn dump_to<W: Write>(&self, writer: &mut W) -> Result<(), Self::Err>;
    fn remove_from_path<P: AsRef<Path>>(&self, path: P) -> Result<(), Self::Err>;
    fn remove_from(&self, file: &mut File) -> Result<(), Self::Err>;
    fn clear(&mut self);

    // Provided method
    fn save_to_path<P: AsRef<Path>>(&self, path: P) -> Result<(), Self::Err> { ... }
}
Expand description

A set of common methods between tags

This provides a set of methods to make interaction with all tags a similar experience.

This can be implemented downstream to provide a familiar interface for custom tags.

Required Associated Types§

source

type Err: From<Error>

The associated error which can be returned from IO operations

source

type RefKey<'a> where Self: 'a

The type of key used in the tag for non-mutating functions

Required Methods§

source

fn len(&self) -> usize

Returns the number of items in the tag

This will also include any extras, such as pictures.

Example
use lofty::{Accessor, ItemKey, Tag, TagExt};

let mut tag = Tag::new(tag_type);
assert_eq!(tag.len(), 0);

tag.set_artist(String::from("Foo artist"));
assert_eq!(tag.len(), 1);
source

fn contains<'a>(&'a self, key: Self::RefKey<'a>) -> bool

Whether the tag contains an item with the key

Example
use lofty::{Accessor, ItemKey, Tag, TagExt};

let mut tag = Tag::new(tag_type);
assert!(tag.is_empty());

tag.set_artist(String::from("Foo artist"));
assert!(tag.contains(&ItemKey::TrackArtist));
source

fn is_empty(&self) -> bool

Whether the tag has any items

Example
use lofty::{Accessor, Tag, TagExt};

let mut tag = Tag::new(tag_type);
assert!(tag.is_empty());

tag.set_artist(String::from("Foo artist"));
assert!(!tag.is_empty());
source

fn save_to(&self, file: &mut File) -> Result<(), Self::Err>

Save the tag to a File

Errors
  • The file format could not be determined
  • Attempting to write a tag to a format that does not support it.
source

fn dump_to<W: Write>(&self, writer: &mut W) -> Result<(), Self::Err>

Dump the tag to a writer

This will only write the tag, it will not produce a usable file.

source

fn remove_from_path<P: AsRef<Path>>(&self, path: P) -> Result<(), Self::Err>

Remove a tag from a Path

Errors

See TagExt::remove_from

source

fn remove_from(&self, file: &mut File) -> Result<(), Self::Err>

Remove a tag from a File

Errors
  • It is unable to guess the file format
  • The format doesn’t support the tag
  • It is unable to write to the file
source

fn clear(&mut self)

Clear the tag, removing all items

NOTE: This will not remove any format-specific extras, such as flags

Provided Methods§

source

fn save_to_path<P: AsRef<Path>>(&self, path: P) -> Result<(), Self::Err>

Save the tag to a path

Errors

Object Safety§

This trait is not object safe.

Implementors§

source§

impl TagExt for ApeTag

§

type Err = LoftyError

§

type RefKey<'a> = &'a str

source§

impl TagExt for Id3v1Tag

§

type Err = LoftyError

§

type RefKey<'a> = &'a ItemKey

source§

impl TagExt for Id3v2Tag

§

type Err = LoftyError

§

type RefKey<'a> = &'a FrameId<'a>

source§

impl TagExt for AIFFTextChunks

§

type Err = LoftyError

§

type RefKey<'a> = &'a ItemKey

source§

impl TagExt for RIFFInfoList

§

type Err = LoftyError

§

type RefKey<'a> = &'a str

source§

impl TagExt for Ilst

§

type Err = LoftyError

§

type RefKey<'a> = &'a AtomIdent<'a>

source§

impl TagExt for VorbisComments

§

type Err = LoftyError

§

type RefKey<'a> = &'a str

source§

impl TagExt for Tag

§

type Err = LoftyError

§

type RefKey<'a> = &'a ItemKey