Update lofty_attr

Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
Serial 2021-07-09 11:43:10 -04:00
parent 4cdc4a7589
commit 18f6789a5a
3 changed files with 92 additions and 4 deletions

2
lofty-attr/Cargo.lock generated
View file

@ -4,7 +4,7 @@ version = 3
[[package]]
name = "lofty_attr"
version = "0.1.5"
version = "0.1.6"
dependencies = [
"quote",
"syn",

View file

@ -1,6 +1,6 @@
[package]
name = "lofty_attr"
version = "0.1.5"
version = "0.1.6"
authors = ["Serial <69764315+Serial-ATA@users.noreply.github.com>"]
description = "Macro for Lofty tag struct creation"
license = "MIT OR Apache-2.0"

View file

@ -85,11 +85,11 @@ pub fn impl_tag(args: TokenStream, input: TokenStream) -> TokenStream {
fn from(inp: &'a #input_ident) -> Self {
Self {
title: inp.title(),
artist: inp.artist_str(),
artist: inp.artist(),
year: inp.year().map(|y| y as i32),
album: Album::new(
inp.album_title(),
inp.album_artist_str(),
inp.album_artist(),
inp.album_covers(),
),
track_number: inp.track_number(),
@ -180,3 +180,91 @@ pub fn impl_tag(args: TokenStream, input: TokenStream) -> TokenStream {
.to_compile_error()
.into()
}
#[proc_macro]
pub fn str_accessor(input: TokenStream) -> TokenStream {
let input_str = input.to_string();
let name = input_str.replace("_", " ");
format!(
"/// Returns the {display}
fn {ident}(&self) -> Option<&str> {{
None
}}
/// Sets the {display}
fn set_{ident}(&mut self, _{ident}: &str) {{}}
/// Removes the {display}
fn remove_{ident}(&mut self) {{}}
",
ident = input_str,
display = name,
)
.parse()
.expect("Unable to parse str accessor:")
}
#[proc_macro]
pub fn u16_accessor(input: TokenStream) -> TokenStream {
let input_str = input.to_string();
let name = input_str.replace("_", " ");
format!(
"/// Returns the {display}
fn {ident}(&self) -> Option<u16> {{
None
}}
/// Sets the {display}
fn set_{ident}(&mut self, _{ident}: u16) {{}}
/// Removes the {display}
fn remove_{ident}(&mut self) {{}}
",
ident = input_str,
display = name,
)
.parse()
.expect("Unable to parse u16 accessor:")
}
#[proc_macro]
pub fn u32_accessor(input: TokenStream) -> TokenStream {
let input_str = input.to_string();
let name = input_str.replace("_", " ");
format!(
"/// Returns the {display}
fn {ident}(&self) -> Option<u32> {{
None
}}
/// Sets the {display}
fn set_{ident}(&mut self, _{ident}: u32) {{}}
/// Removes the {display}
fn remove_{ident}(&mut self) {{}}
",
ident = input_str,
display = name,
)
.parse()
.expect("Unable to parse u32 accessor:")
}
#[proc_macro]
pub fn i32_accessor(input: TokenStream) -> TokenStream {
let input_str = input.to_string();
let name = input_str.replace("_", " ");
format!(
"/// Returns the {display}
fn {ident}(&self) -> Option<i32> {{
None
}}
/// Sets the {display}
fn set_{ident}(&mut self, _{ident}: i32) {{}}
/// Removes the {display}
fn remove_{ident}(&mut self) {{}}
",
ident = input_str,
display = name,
)
.parse()
.expect("Unable to parse i32 accessor:")
}