mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-13 14:12:31 +00:00
add frominner and intoinner traits
This commit is contained in:
parent
873a6e831d
commit
c72f09d3e2
6 changed files with 37 additions and 6 deletions
BIN
assets/a.mp3
BIN
assets/a.mp3
Binary file not shown.
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
15
tests/inner.rs
Normal 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"));
|
||||
}
|
Loading…
Reference in a new issue