This commit is contained in:
Tianyi Shi 2020-10-27 14:01:03 +00:00
parent f233955413
commit 0dca646968
6 changed files with 23 additions and 10 deletions

View file

@ -118,7 +118,7 @@ fn main() {
## Getters and Setters
```rust
pub trait AudioTag {
pub trait AudioTagEdit{
fn title(&self) -> Option<&str>;
fn set_title(&mut self, title: &str);
fn remove_title(&mut self);

View file

@ -28,5 +28,7 @@ macro_rules! impl_tag {
self.into()
}
}
impl AudioTag for $tag {}
};
}

View file

@ -57,7 +57,7 @@ impl FlacTag {
}
}
impl AudioTag for FlacTag {
impl AudioTagEdit for FlacTag {
fn title(&self) -> Option<&str> {
self.get_first("TITLE")
}
@ -201,6 +201,9 @@ impl AudioTag for FlacTag {
fn remove_total_discs(&mut self) {
self.remove("TOTALDISCS");
}
}
impl AudioTagWrite for FlacTag {
fn write_to(&mut self, file: &mut File) -> crate::Result<()> {
self.inner.write_to(file)?;
Ok(())

View file

@ -61,7 +61,7 @@ impl<'a> std::convert::TryFrom<&'a id3::frame::Picture> for Picture<'a> {
}
}
impl AudioTag for Id3v2Tag {
impl AudioTagEdit for Id3v2Tag {
fn title(&self) -> Option<&str> {
self.inner.title()
}
@ -178,7 +178,9 @@ impl AudioTag for Id3v2Tag {
fn remove_total_discs(&mut self) {
self.inner.remove_total_discs();
}
}
impl AudioTagWrite for Id3v2Tag {
fn write_to(&mut self, file: &mut File) -> crate::Result<()> {
self.inner.write_to(file, id3::Version::Id3v24)?;
Ok(())

View file

@ -101,7 +101,7 @@ impl Tag {
}
}
pub fn read_from_path(&self, path: impl AsRef<Path>) -> crate::Result<Box<dyn AudioTag>> {
pub fn read_from_path(&self, path: impl AsRef<Path>) -> crate::Result<Box<dyn AudioTagEdit>> {
match self.tag_type.unwrap_or(TagType::try_from_ext(
path.as_ref()
.extension()
@ -272,15 +272,17 @@ impl AnyTag<'_> {
}
}
pub trait TagIo {
fn read_from_path(path: &str) -> crate::Result<AnyTag>;
fn write_to_path(path: &str) -> crate::Result<()>;
}
pub trait AudioTag: AudioTagEdit + AudioTagWrite {}
// pub trait TagIo {
// fn read_from_path(path: &str) -> crate::Result<AnyTag>;
// fn write_to_path(path: &str) -> crate::Result<()>;
// }
/// Implementors of this trait are able to read and write audio metadata.
///
/// Constructor methods e.g. `from_file` should be implemented separately.
pub trait AudioTag: AudioTagCommon {
pub trait AudioTagEdit: AudioTagCommon {
fn title(&self) -> Option<&str>;
fn set_title(&mut self, title: &str);
fn remove_title(&mut self);
@ -394,7 +396,9 @@ pub trait AudioTag: AudioTagCommon {
fn total_discs(&self) -> Option<u16>;
fn set_total_discs(&mut self, total_discs: u16);
fn remove_total_discs(&mut self);
}
pub trait AudioTagWrite {
fn write_to(&mut self, file: &mut File) -> crate::Result<()>;
// cannot use impl AsRef<Path>
fn write_to_path(&mut self, path: &str) -> crate::Result<()>;

View file

@ -77,7 +77,7 @@ impl<'a> std::convert::TryFrom<&'a mp4ameta::Data> for Picture<'a> {
}
}
impl AudioTag for Mp4Tag {
impl AudioTagEdit for Mp4Tag {
fn title(&self) -> Option<&str> {
self.inner.title()
}
@ -228,7 +228,9 @@ impl AudioTag for Mp4Tag {
fn remove_total_discs(&mut self) {
self.inner.remove_total_discs();
}
}
impl AudioTagWrite for Mp4Tag {
fn write_to(&mut self, file: &mut File) -> crate::Result<()> {
self.inner.write_to(file)?;
Ok(())