mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-13 06:02:32 +00:00
Add attribute to lofty-attr to skip From<AnyTag> conversion
Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
parent
6836b759f7
commit
3091da92cd
3 changed files with 47 additions and 37 deletions
2
lofty-attr/Cargo.lock
generated
2
lofty-attr/Cargo.lock
generated
|
@ -4,7 +4,7 @@ version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lofty_attr"
|
name = "lofty_attr"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "lofty_attr"
|
name = "lofty_attr"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
authors = ["Serial <69764315+Serial-ATA@users.noreply.github.com>"]
|
authors = ["Serial <69764315+Serial-ATA@users.noreply.github.com>"]
|
||||||
description = "Macro for Lofty tag struct creation"
|
description = "Macro for Lofty tag struct creation"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
|
@ -23,6 +23,50 @@ pub fn impl_tag(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
if let Some(inner) = inner.get_ident() {
|
if let Some(inner) = inner.get_ident() {
|
||||||
let input_ident = input.ident;
|
let input_ident = input.ident;
|
||||||
|
|
||||||
|
let mut anytag_convert = quote! {
|
||||||
|
impl<'a> From<AnyTag<'a>> for #input_ident {
|
||||||
|
fn from(inp: AnyTag<'a>) -> Self {
|
||||||
|
let mut tag = #input_ident::default();
|
||||||
|
|
||||||
|
if let Some(v) = inp.title() {
|
||||||
|
tag.set_title(v)
|
||||||
|
}
|
||||||
|
if let Some(v) = inp.artists_as_string() {
|
||||||
|
tag.set_artist(&v)
|
||||||
|
}
|
||||||
|
if let Some(v) = inp.year {
|
||||||
|
tag.set_year(v)
|
||||||
|
}
|
||||||
|
if let Some(v) = inp.album().title {
|
||||||
|
tag.set_album_title(v)
|
||||||
|
}
|
||||||
|
if let Some(v) = inp.album().artists {
|
||||||
|
tag.set_album_artist(&v.join("/"))
|
||||||
|
}
|
||||||
|
if let Some(v) = inp.track_number() {
|
||||||
|
tag.set_track_number(v)
|
||||||
|
}
|
||||||
|
if let Some(v) = inp.total_tracks() {
|
||||||
|
tag.set_total_tracks(v)
|
||||||
|
}
|
||||||
|
if let Some(v) = inp.disc_number() {
|
||||||
|
tag.set_disc_number(v)
|
||||||
|
}
|
||||||
|
if let Some(v) = inp.total_discs() {
|
||||||
|
tag.set_total_discs(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
tag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(attr) = input.attrs.first() {
|
||||||
|
if attr.path.is_ident("custom_convert") {
|
||||||
|
anytag_convert = quote! {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let expanded = quote! {
|
let expanded = quote! {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct #input_ident {
|
pub struct #input_ident {
|
||||||
|
@ -102,41 +146,7 @@ pub fn impl_tag(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<AnyTag<'a>> for #input_ident {
|
#anytag_convert
|
||||||
fn from(inp: AnyTag<'a>) -> Self {
|
|
||||||
let mut tag = #input_ident::default();
|
|
||||||
|
|
||||||
if let Some(v) = inp.title() {
|
|
||||||
tag.set_title(v)
|
|
||||||
}
|
|
||||||
if let Some(v) = inp.artists_as_string() {
|
|
||||||
tag.set_artist(&v)
|
|
||||||
}
|
|
||||||
if let Some(v) = inp.year {
|
|
||||||
tag.set_year(v)
|
|
||||||
}
|
|
||||||
if let Some(v) = inp.album().title {
|
|
||||||
tag.set_album_title(v)
|
|
||||||
}
|
|
||||||
if let Some(v) = inp.album().artists {
|
|
||||||
tag.set_album_artist(&v.join("/"))
|
|
||||||
}
|
|
||||||
if let Some(v) = inp.track_number() {
|
|
||||||
tag.set_track_number(v)
|
|
||||||
}
|
|
||||||
if let Some(v) = inp.total_tracks() {
|
|
||||||
tag.set_total_tracks(v)
|
|
||||||
}
|
|
||||||
if let Some(v) = inp.disc_number() {
|
|
||||||
tag.set_disc_number(v)
|
|
||||||
}
|
|
||||||
if let Some(v) = inp.total_discs() {
|
|
||||||
tag.set_total_discs(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
tag
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// From dyn AudioTag to wrapper (any type)
|
// From dyn AudioTag to wrapper (any type)
|
||||||
impl From<Box<dyn AudioTag>> for #input_ident {
|
impl From<Box<dyn AudioTag>> for #input_ident {
|
||||||
|
|
Loading…
Reference in a new issue