mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-14 06:32:33 +00:00
41 lines
1.3 KiB
Text
41 lines
1.3 KiB
Text
|
# Downcast
|
||
|
|
||
|
The following example shows how you can downcast a `Box<dyn AudioTag>` into its "backend" tag type. This allows you to set the uncommon metadata supported by the corresponding backend but not by **audiotags**.
|
||
|
|
||
|
```rust
|
||
|
use audiotags::*;
|
||
|
|
||
|
fn main() {
|
||
|
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")
|
||
|
.expect("Fail to write!");
|
||
|
|
||
|
let id3tag_reload = Tag::default()
|
||
|
.read_from_path("assets/a.mp3")
|
||
|
.expect("Fail to read!");
|
||
|
assert_eq!(id3tag_reload.title(), Some("title from metaflac::Tag"));
|
||
|
|
||
|
let mut id3tag_inner: id3::Tag = downcast!(id3tag_reload, Id3v2Tag);
|
||
|
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)
|
||
|
.expect("Fail to write!");
|
||
|
|
||
|
let id3tag_reload = id3::Tag::read_from_path("assets/a.mp3").expect("Fail to read!");
|
||
|
assert_eq!(id3tag_reload.date_recorded(), Some(timestamp));
|
||
|
}
|
||
|
```
|