Trait lofty::AudioFile

source ·
pub trait AudioFile: Into<TaggedFile> {
    type Properties;

    // Required methods
    fn read_from<R>(reader: &mut R, parse_options: ParseOptions) -> Result<Self>
       where R: Read + Seek,
             Self: Sized;
    fn save_to(&self, file: &mut File) -> Result<()>;
    fn properties(&self) -> &Self::Properties;
    fn contains_tag(&self) -> bool;
    fn contains_tag_type(&self, tag_type: TagType) -> bool;

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

Provides various methods for interaction with a file

Required Associated Types§

source

type Properties

The struct the file uses for audio properties

Not all formats can use FileProperties since they may contain additional information

Required Methods§

source

fn read_from<R>(reader: &mut R, parse_options: ParseOptions) -> Result<Self>where R: Read + Seek, Self: Sized,

Read a file from a reader

Errors

Errors depend on the file and tags being read. See LoftyError

source

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

Attempts to write all tags to a file

Errors

See Tag::save_to, however this is applicable to every tag in the file.

Examples
use lofty::{AudioFile, TaggedFileExt};
use std::fs::OpenOptions;

let mut tagged_file = lofty::read_from_path(path)?;

// Edit the tags

let mut file = OpenOptions::new().read(true).write(true).open(path)?;
tagged_file.save_to(&mut file)?;
source

fn properties(&self) -> &Self::Properties

Returns a reference to the file’s properties

source

fn contains_tag(&self) -> bool

Checks if the file contains any tags

source

fn contains_tag_type(&self, tag_type: TagType) -> bool

Checks if the file contains the given TagType

Provided Methods§

source

fn save_to_path(&self, path: impl AsRef<Path>) -> Result<()>

Attempts to write all tags to a path

Errors
Examples
use lofty::{AudioFile, TaggedFileExt};

let mut tagged_file = lofty::read_from_path(path)?;

// Edit the tags

tagged_file.save_to_path(path)?;

Implementors§