Struct lofty::BoundTaggedFile
source · pub struct BoundTaggedFile { /* private fields */ }Expand description
A variant of TaggedFile that holds a File handle, and reflects changes
such as tag removals.
For example:
use lofty::{AudioFile, Tag, TagType, TaggedFileExt};
// 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")?;
assert!(tagged_file.contains_tag_type(TagType::Id3v2));However, when using BoundTaggedFile:
use lofty::{AudioFile, BoundTaggedFile, ParseOptions, Tag, TagType, TaggedFileExt};
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()?;
assert!(!bound_tagged_file.contains_tag_type(TagType::Id3v2));Implementations§
source§impl BoundTaggedFile
impl BoundTaggedFile
sourcepub fn read_from(file: File, parse_options: ParseOptions) -> Result<Self>
pub fn read_from(file: File, parse_options: ParseOptions) -> Result<Self>
Create a new BoundTaggedFile
Errors
Examples
use lofty::{AudioFile, BoundTaggedFile, ParseOptions, Tag, TagType, TaggedFileExt};
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) -> Result<()>
pub fn save(&mut self) -> Result<()>
Save the tags to the file stored internally
Errors
Examples
use lofty::{AudioFile, BoundTaggedFile, ParseOptions, Tag, TagType, TaggedFileExt};
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()?;Trait Implementations§
source§impl AudioFile for BoundTaggedFile
impl AudioFile for BoundTaggedFile
§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>where
R: Read + Seek,
Self: Sized,
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(&self, file: &mut File) -> Result<()>
fn save_to(&self, file: &mut File) -> 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§impl From<BoundTaggedFile> for TaggedFile
impl From<BoundTaggedFile> for TaggedFile
source§fn from(input: BoundTaggedFile) -> Self
fn from(input: BoundTaggedFile) -> Self
Converts to this type from the input type.
source§impl TaggedFileExt for BoundTaggedFile
impl TaggedFileExt for BoundTaggedFile
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 supports_tag_type(&self, tag_type: TagType) -> bool
fn supports_tag_type(&self, tag_type: TagType) -> bool
Auto Trait Implementations§
impl RefUnwindSafe for BoundTaggedFile
impl Send for BoundTaggedFile
impl Sync for BoundTaggedFile
impl Unpin for BoundTaggedFile
impl UnwindSafe for BoundTaggedFile
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