mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-11-10 06:34:18 +00:00
downcast
This commit is contained in:
parent
c72f09d3e2
commit
47ae10071a
6 changed files with 28 additions and 5 deletions
|
@ -14,4 +14,4 @@ id3 = "0.5.1"
|
|||
mp4ameta = "0.6"
|
||||
metaflac = "0.2"
|
||||
thiserror = "1.0.21"
|
||||
audiotags-dev-macro = {path = "./audiotags-dev-macro", version = "0.1.1"}
|
||||
audiotags-dev-macro = {path = "./audiotags-dev-macro", version = "0.1.2"}
|
BIN
assets/a.mp3
BIN
assets/a.mp3
Binary file not shown.
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "audiotags-dev-macro"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
authors = ["Tianyi <ShiTianyi2001@outlook.com>"]
|
||||
edition = "2018"
|
||||
description = "macros used during the development of audiotags"
|
||||
|
|
|
@ -37,13 +37,16 @@ macro_rules! impl_tag {
|
|||
fn into_anytag(&self) -> AnyTag<'_> {
|
||||
self.into()
|
||||
}
|
||||
fn into_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioTag for $tag {}
|
||||
|
||||
impl From<$tag> for $inner {
|
||||
fn from(inp: $tag) -> Self {
|
||||
inp.inner
|
||||
impl From<&$tag> for $inner {
|
||||
fn from(inp: &$tag) -> Self {
|
||||
inp.inner.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -148,4 +148,5 @@ pub trait IntoAnyTag {
|
|||
TagType::Flac => Box::new(FlacTag::from(self.into_anytag())),
|
||||
}
|
||||
}
|
||||
fn into_any(&self) -> &dyn std::any::Any;
|
||||
}
|
||||
|
|
|
@ -12,4 +12,23 @@ fn test_inner() {
|
|||
|
||||
let id3tag_reload = Tag::default().read_from_path("assets/a.mp3").unwrap();
|
||||
assert_eq!(id3tag_reload.title(), Some("title from metaflac::Tag"));
|
||||
|
||||
let mut id3tag_inner: id3::Tag = id3tag_reload
|
||||
.into_any()
|
||||
.downcast_ref::<Id3v2Tag>()
|
||||
.unwrap()
|
||||
.into();
|
||||
let timestamp = id3::Timestamp {
|
||||
year: 2013,
|
||||
month: Some(2u8),
|
||||
day: Some(5u8),
|
||||
hour: Some(6u8),
|
||||
minute: None,
|
||||
second: None,
|
||||
};
|
||||
id3tag_inner.set_date_recorded(timestamp.clone());
|
||||
id3tag_inner.write_to_path("assets/a.mp3", id3::Version::Id3v24);
|
||||
|
||||
let id3tag_reload = id3::Tag::read_from_path("assets/a.mp3").unwrap();
|
||||
assert_eq!(id3tag_reload.date_recorded(), Some(timestamp));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue