Crates.io | syn-unnamed-struct |
lib.rs | syn-unnamed-struct |
version | 0.1.0 |
source | src |
created_at | 2022-04-03 18:11:08.510734 |
updated_at | 2022-04-03 18:11:08.510734 |
description | Extends syn expressions and meta structs with unnamed structs and meta lists |
homepage | |
repository | https://github.com/andrewlowndes/syn-unnamed-struct |
max_upload_size | |
id | 561394 |
size | 17,595 |
Parse and convert structs with no name to tokens. For usage in attribute macro arguments in place of Meta attributes to allow more structured data to be used (nested objects).
use syn_unnamed_struct::Meta;
#[proc_macro_derive(CustomMacro, attributes(customMacro))]
pub fn derive(tokens: TokenStream) -> TokenStream {
let input = parse_macro_input!(tokens);
input.attrs.map(|attr| {
let obj: Meta = attr.parse().expect("Coult not parse attribute");
//can now interact and extract the properties from the Meta enum
//...
});
}
#[derive(CustomMacro)]
#[customMacro(name="something", other={ entry1: "val1", entry2: "val2" })]
struct MyStruct {
//...
}
#[customMacro({ prop1: 123, prop2: 245 })]
#[customMacro({ prop1: 123, prop2: { prop2a: 123, prop2b: 245 } })]
#[customMacro(prop1=123, prop2={ prop2a: 123, prop2b: 245 })]
#[customMacro(prop1, prop2, (prop3a=123, prop3b=245)))]
#[customMacro(prop1=123, prop2=(prop2a=123, prop2b=245)))]