use crate::config::WriteOptions;
use crate::error::LoftyError;
use crate::io::{FileLike, Length, Truncate};
use crate::tag::{Accessor, Tag, TagType};
use std::path::Path;
pub trait TagExt: Accessor + Into<Tag> + Sized + private::Sealed {
type Err: From<std::io::Error> + From<LoftyError>;
type RefKey<'a>
where
Self: 'a;
#[doc(hidden)]
fn tag_type(&self) -> TagType;
fn len(&self) -> usize;
fn contains<'a>(&'a self, key: Self::RefKey<'a>) -> bool;
fn is_empty(&self) -> bool;
fn save_to_path<P: AsRef<Path>>(
&self,
path: P,
write_options: WriteOptions,
) -> std::result::Result<(), Self::Err> {
self.save_to(
&mut std::fs::OpenOptions::new()
.read(true)
.write(true)
.open(path)?,
write_options,
)
}
fn save_to<F>(
&self,
file: &mut F,
write_options: WriteOptions,
) -> std::result::Result<(), Self::Err>
where
F: FileLike,
LoftyError: From<<F as Truncate>::Error>,
LoftyError: From<<F as Length>::Error>;
#[allow(clippy::missing_errors_doc)]
fn dump_to<W: std::io::Write>(
&self,
writer: &mut W,
write_options: WriteOptions,
) -> std::result::Result<(), Self::Err>;
fn remove_from_path<P: AsRef<Path>>(&self, path: P) -> std::result::Result<(), Self::Err> {
self.tag_type().remove_from_path(path).map_err(Into::into)
}
fn remove_from<F>(&self, file: &mut F) -> std::result::Result<(), Self::Err>
where
F: FileLike,
LoftyError: From<<F as Truncate>::Error>,
LoftyError: From<<F as Length>::Error>,
{
self.tag_type().remove_from(file).map_err(Into::into)
}
fn clear(&mut self);
}
mod private {
use crate::ape::ApeTag;
use crate::id3::v1::Id3v1Tag;
use crate::id3::v2::Id3v2Tag;
use crate::iff::aiff::AiffTextChunks;
use crate::iff::wav::RiffInfoList;
use crate::mp4::Ilst;
use crate::ogg::VorbisComments;
use crate::tag::Tag;
pub trait Sealed {}
impl Sealed for AiffTextChunks {}
impl Sealed for ApeTag {}
impl Sealed for Id3v1Tag {}
impl Sealed for Id3v2Tag {}
impl Sealed for Ilst {}
impl Sealed for RiffInfoList {}
impl Sealed for Tag {}
impl Sealed for VorbisComments {}
}