black magic

This commit is contained in:
Tianyi Shi 2020-10-27 15:33:19 +00:00
parent 47ae10071a
commit fececf76e9
3 changed files with 13 additions and 5 deletions

Binary file not shown.

View file

@ -144,3 +144,10 @@ impl Tag {
} }
} }
} }
#[macro_export]
macro_rules! downcast {
($tag:expr, $type:ty) => {
$tag.into_any().downcast_ref::<$type>().unwrap().into()
};
}

View file

@ -13,11 +13,12 @@ fn test_inner() {
let id3tag_reload = Tag::default().read_from_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")); assert_eq!(id3tag_reload.title(), Some("title from metaflac::Tag"));
let mut id3tag_inner: id3::Tag = id3tag_reload // let mut id3tag_inner: id3::Tag = id3tag_reload
.into_any() // .into_any()
.downcast_ref::<Id3v2Tag>() // .downcast_ref::<Id3v2Tag>()
.unwrap() // .unwrap()
.into(); // .into();
let mut id3tag_inner: id3::Tag = downcast!(id3tag_reload, Id3v2Tag);
let timestamp = id3::Timestamp { let timestamp = id3::Timestamp {
year: 2013, year: 2013,
month: Some(2u8), month: Some(2u8),