1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
use darling::{FromDeriveInput, FromMeta};
fn parse<T: FromDeriveInput>(src: &str) -> T {
let ast = syn::parse_str(src).unwrap();
FromDeriveInput::from_derive_input(&ast).unwrap()
}
#[derive(FromMeta, PartialEq, Eq, Debug)]
enum Volume {
Whisper,
Talk,
Shout,
}
#[derive(FromDeriveInput)]
#[darling(attributes(speak))]
struct SpeakingOptions<T: Default, U> {
max_volume: U,
#[darling(skip)]
#[allow(dead_code)]
additional_data: T,
}
#[derive(Default)]
struct Phoneme {
#[allow(dead_code)]
first: String,
}
#[test]
fn skipped_field() {
let parsed: SpeakingOptions<Phoneme, Volume> = parse(
r#"
#[derive(Speak)]
#[speak(max_volume = "shout")]
enum HtmlElement {
Div(String)
}
"#,
);
assert_eq!(parsed.max_volume, Volume::Shout);
}
|