parsable-macro 0.1.1

Macro to generate the `parsable` trait on enums or structs.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use proc_macro2::{Span};
use syn::{Type, Ident};

pub fn is_type(ty: &Type, name: &str) -> bool {
    get_type_name(ty) == name
}

fn get_type_name(ty: &Type) -> String {
    match ty {
        Type::Path(type_path) => type_path.path.segments.last().unwrap().ident.to_string(),
        _ => todo!(),
    }
}

pub fn make_ident(name: String) -> Ident {
    Ident::new(&name, Span::call_site())
}