cgp-macro-lib 0.7.0

Context-generic programming core component macros implemented as a library.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use proc_macro2::TokenStream;
use syn::{Error, Item, parse2};

use crate::{derive_cgp_record_from_struct, derive_cgp_variant_from_enum};

pub fn derive_cgp_data(body: TokenStream) -> syn::Result<TokenStream> {
    let item: Item = parse2(body)?;

    match item {
        Item::Struct(item_struct) => derive_cgp_record_from_struct(&item_struct),
        Item::Enum(item_enum) => derive_cgp_variant_from_enum(&item_enum),
        _ => Err(Error::new_spanned(
            item,
            "expect body to be either a struct or enum",
        )),
    }
}