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>
impl<F> BoundTaggedFile<F>
Sourcepub fn into_inner(self) -> F
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>
impl<F: FileLike> BoundTaggedFile<F>
Sourcepub fn read_from(file: F, parse_options: ParseOptions) -> Result<Self>
pub fn read_from(file: F, parse_options: ParseOptions) -> Result<Self>
Create a new BoundTaggedFile
§Errors
§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)?;Sourcepub fn save(&mut self, write_options: WriteOptions) -> Result<()>
pub fn save(&mut self, write_options: WriteOptions) -> Result<()>
Save the tags to the file stored internally
§Errors
§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>
impl<T> AudioFile for BoundTaggedFile<T>
Source§type Properties = FileProperties
type Properties = FileProperties
The struct the file uses for audio properties Read more
Source§fn read_from<R>(_: &mut R, _: ParseOptions) -> Result<Self>
fn read_from<R>(_: &mut R, _: ParseOptions) -> Result<Self>
Read a file from a reader Read more
Source§fn save_to<F>(&self, file: &mut F, write_options: WriteOptions) -> Result<()>
fn save_to<F>(&self, file: &mut F, write_options: WriteOptions) -> Result<()>
Attempts to write all tags to a file Read more
Source§fn properties(&self) -> &Self::Properties
fn properties(&self) -> &Self::Properties
Returns a reference to the file’s properties
Source§fn contains_tag(&self) -> bool
fn contains_tag(&self) -> bool
Checks if the file contains any tags
Source§fn contains_tag_type(&self, tag_type: TagType) -> bool
fn contains_tag_type(&self, tag_type: TagType) -> bool
Checks if the file contains the given
TagTypeSource§fn save_to_path(
&self,
path: impl AsRef<Path>,
write_options: WriteOptions,
) -> Result<()>
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
impl<F> From<BoundTaggedFile<F>> for TaggedFile
Source§fn from(input: BoundTaggedFile<F>) -> Self
fn from(input: BoundTaggedFile<F>) -> Self
Converts to this type from the input type.
Source§impl<F> TaggedFileExt for BoundTaggedFile<F>
impl<F> TaggedFileExt for BoundTaggedFile<F>
Returns all tags Read more
Source§fn 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 Read more
Source§fn tag_support(&self, tag_type: TagType) -> TagSupport
fn tag_support(&self, tag_type: TagType) -> TagSupport
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more