ngyn_macros 0.2.2

Modular backend framework for web applications
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use syn::{Data, Ident, Type};

pub fn parse_macro_data(data: Data) -> (Vec<Type>, Vec<Ident>) {
    let raw_fields = match data {
        syn::Data::Struct(d) => d.fields,
        _ => panic!("Only structs are supported"),
    };
    let types = raw_fields
        .iter()
        .map(|f| f.ty.clone())
        .collect::<Vec<Type>>();
    let keys = raw_fields
        .iter()
        .map(|f| f.ident.clone().unwrap())
        .collect::<Vec<Ident>>();
    (types, keys)
}