add frominner and intoinner traits

This commit is contained in:
Tianyi Shi 2020-10-27 15:00:22 +00:00
parent 873a6e831d
commit c72f09d3e2
6 changed files with 37 additions and 6 deletions

Binary file not shown.

View file

@ -40,5 +40,20 @@ macro_rules! impl_tag {
}
impl AudioTag for $tag {}
impl From<$tag> for $inner {
fn from(inp: $tag) -> Self {
inp.inner
}
}
impl From<$inner> for $tag {
fn from(inp: $inner) -> Self {
Self {
inner: inp,
config: Config::default(),
}
}
}
};
}

View file

@ -1,8 +1,9 @@
use crate::*;
use metaflac;
use metaflac::Tag as InnerTag;
impl_tag!(FlacTag, InnerTag);
pub use metaflac::Tag as FlacInnerTag;
impl_tag!(FlacTag, FlacInnerTag);
impl<'a> From<AnyTag<'a>> for FlacTag {
fn from(inp: AnyTag<'a>) -> Self {

View file

@ -1,9 +1,9 @@
use crate::*;
use id3;
use id3::Tag as InnerTag;
pub use id3::Tag as Id3v2InnerTag;
impl_tag!(Id3v2Tag, InnerTag);
impl_tag!(Id3v2Tag, Id3v2InnerTag);
impl<'a> From<&'a Id3v2Tag> for AnyTag<'a> {
fn from(inp: &'a Id3v2Tag) -> Self {

View file

@ -1,9 +1,9 @@
use crate::*;
use mp4ameta;
use mp4ameta::Tag as InnerTag;
pub use mp4ameta::Tag as Mp4InnerTag;
impl_tag!(Mp4Tag, InnerTag);
impl_tag!(Mp4Tag, Mp4InnerTag);
impl<'a> From<&'a Mp4Tag> for AnyTag<'a> {
fn from(inp: &'a Mp4Tag) -> Self {

15
tests/inner.rs Normal file
View file

@ -0,0 +1,15 @@
use audiotags::*;
#[test]
fn test_inner() {
let mut innertag = metaflac::Tag::default();
innertag
.vorbis_comments_mut()
.set_title(vec!["title from metaflac::Tag"]);
let tag: FlacTag = innertag.into();
let mut id3tag = tag.into_tag(TagType::Id3v2);
id3tag.write_to_path("assets/a.mp3").unwrap();
let id3tag_reload = Tag::default().read_from_path("assets/a.mp3").unwrap();
assert_eq!(id3tag_reload.title(), Some("title from metaflac::Tag"));
}