File: multiple.rs

package info (click to toggle)
rust-darling 0.20.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 396 kB
  • sloc: makefile: 2; sh: 1
file content (30 lines) | stat: -rw-r--r-- 603 bytes parent folder | download | duplicates (46)
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
use darling::{FromDeriveInput, FromMeta};
use syn::parse_quote;

#[derive(FromDeriveInput)]
#[darling(attributes(hello))]
#[allow(dead_code)]
struct Lorem {
    ident: syn::Ident,
    ipsum: Ipsum,
}

#[derive(FromMeta)]
struct Ipsum {
    #[darling(multiple)]
    dolor: Vec<String>,
}

#[test]
fn expand_many() {
    let di = parse_quote! {
        #[hello(ipsum(dolor = "Hello", dolor = "World"))]
        pub struct Baz;
    };

    let lorem: Lorem = Lorem::from_derive_input(&di).unwrap();
    assert_eq!(
        lorem.ipsum.dolor,
        vec!["Hello".to_string(), "World".to_string()]
    );
}