Skip to main content

BoundTaggedFile

Struct BoundTaggedFile 

Source
pub struct BoundTaggedFile<F> { /* private fields */ }
Expand description

A variant of TaggedFile that holds a handle to its original FileLike buffer, and reflects changes such as tag removals.

For example:

use lofty::config::WriteOptions;
use lofty::file::{AudioFile, TaggedFileExt};
use lofty::tag::{Tag, TagType};

// We create an empty tag
let tag = Tag::new(TagType::Id3v2);

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

// Push our empty tag into the TaggedFile
tagged_file.insert_tag(tag);

// After saving, our file still "contains" the ID3v2 tag, but if we were to read
// "foo.mp3", it would not have an ID3v2 tag. Lofty does not write empty tags, but this
// change will not be reflected in `TaggedFile`.
tagged_file.save_to_path("foo.mp3", WriteOptions::default())?;
assert!(tagged_file.contains_tag_type(TagType::Id3v2));

However, when using BoundTaggedFile:

use lofty::config::{ParseOptions, WriteOptions};
use lofty::file::{AudioFile, BoundTaggedFile, TaggedFileExt};
use lofty::tag::{Tag, TagType};
use std::fs::OpenOptions;

// We create an empty tag
let tag = Tag::new(TagType::Id3v2);

// We'll need to open our file for reading *and* writing
let file = OpenOptions::new().read(true).write(true).open(path)?;
let parse_options = ParseOptions::new();

let mut bound_tagged_file = BoundTaggedFile::read_from(file, parse_options)?;

// Push our empty tag into the TaggedFile
bound_tagged_file.insert_tag(tag);

// Now when saving, we no longer have to specify a path, and the tags in the `BoundTaggedFile`
// reflect those in the actual file on disk.
bound_tagged_file.save(WriteOptions::default())?;
assert!(!bound_tagged_file.contains_tag_type(TagType::Id3v2));

Implementations§

Source§

impl<F> BoundTaggedFile<F>

Source

pub fn into_inner(self) -> F

Consume this tagged file and return the internal file “buffer”. This allows you to reuse the internal file.

Any changes that haven’t been commited will be discarded once you call this function.

Source§

impl<F: FileLike> BoundTaggedFile<F>
where LoftyError: From<<F as Truncate>::Error> + From<<F as Length>::Error>,

Source

pub fn read_from(file: F, parse_options: ParseOptions) -> Result<Self>

Create a new BoundTaggedFile

§Errors

See AudioFile::read_from

§Examples
use lofty::config::ParseOptions;
use lofty::file::{AudioFile, BoundTaggedFile, TaggedFileExt};
use lofty::tag::{Tag, TagType};
use std::fs::OpenOptions;

// We'll need to open our file for reading *and* writing
let file = OpenOptions::new().read(true).write(true).open(path)?;
let parse_options = ParseOptions::new();

let bound_tagged_file = BoundTaggedFile::read_from(file, parse_options)?;
Source

pub fn save(&mut self, write_options: WriteOptions) -> Result<()>

Save the tags to the file stored internally

§Errors

See TaggedFile::save_to

§Examples
use lofty::config::{ParseOptions, WriteOptions};
use lofty::file::{AudioFile, BoundTaggedFile, TaggedFileExt};
use lofty::tag::{Tag, TagType};
use std::fs::OpenOptions;

// We'll need to open our file for reading *and* writing
let file = OpenOptions::new().read(true).write(true).open(path)?;
let parse_options = ParseOptions::new();

let mut bound_tagged_file = BoundTaggedFile::read_from(file, parse_options)?;

// Do some work to the tags...

// This will save the tags to the file we provided to `read_from`
bound_tagged_file.save(WriteOptions::default())?;

Trait Implementations§

Source§

impl<T> AudioFile for BoundTaggedFile<T>

Source§

type Properties = FileProperties

The struct the file uses for audio properties Read more
Source§

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

Read a file from a reader Read more
Source§

fn save_to<F>(&self, file: &mut F, write_options: WriteOptions) -> Result<()>
where F: FileLike, LoftyError: From<<F as Truncate>::Error> + From<<F as Length>::Error>,

Attempts to write all tags to a file Read more
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
Source§

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

Attempts to write all tags to a path Read more
Source§

impl<F> From<BoundTaggedFile<F>> for TaggedFile

Source§

fn from(input: BoundTaggedFile<F>) -> Self

Converts to this type from the input type.
Source§

impl<F> TaggedFileExt for BoundTaggedFile<F>

Source§

fn file_type(&self) -> FileType

Returns the file’s FileType Read more
Source§

fn tags(&self) -> &[Tag]

Returns all tags Read more
Source§

fn tag(&self, tag_type: TagType) -> Option<&Tag>

Get a reference to a specific TagType Read more
Source§

fn tag_mut(&mut self, tag_type: TagType) -> Option<&mut Tag>

Get a mutable reference to a specific TagType Read more
Source§

fn first_tag_mut(&mut self) -> Option<&mut Tag>

Gets a mutable reference to the first tag, if there are any Read more
Source§

fn insert_tag(&mut self, tag: Tag) -> Option<Tag>

Inserts a Tag Read more
Source§

fn remove(&mut self, tag_type: TagType) -> Option<Tag>

Removes a specific TagType and returns it Read more
Source§

fn clear(&mut self)

Removes all tags from the file Read more
Source§

fn primary_tag_type(&self) -> TagType

Returns the file type’s primary TagType Read more
Source§

fn tag_support(&self, tag_type: TagType) -> TagSupport

Determines whether the file supports the given TagType Read more
Source§

fn primary_tag(&self) -> Option<&Tag>

Returns the primary tag Read more
Source§

fn primary_tag_mut(&mut self) -> Option<&mut Tag>

Gets a mutable reference to the file’s “Primary tag” Read more
Source§

fn first_tag(&self) -> Option<&Tag>

Gets the first tag, if there are any Read more

Auto Trait Implementations§

§

impl<F> Freeze for BoundTaggedFile<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for BoundTaggedFile<F>
where F: RefUnwindSafe,

§

impl<F> Send for BoundTaggedFile<F>
where F: Send,

§

impl<F> Sync for BoundTaggedFile<F>
where F: Sync,

§

impl<F> Unpin for BoundTaggedFile<F>
where F: Unpin,

§

impl<F> UnwindSafe for BoundTaggedFile<F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.