nova_macro/
lib.rs

1//! This crate implements the macro for `nova` and should not be used directly.
2
3extern crate proc_macro;
4
5use proc_macro::TokenStream;
6use syn::{parse_macro_input, AttributeArgs};
7
8#[proc_macro_attribute]
9/// Create a newtype from a `type` declaration.
10pub fn newtype(attr: TokenStream, item: TokenStream) -> TokenStream {
11    let attrs = parse_macro_input!(attr as AttributeArgs);
12    let item = parse_macro_input!(item as proc_macro2::TokenStream);
13
14    match nova_impl::newtype(attrs, item) {
15        Ok(tokens) => tokens.into(),
16        Err(err) => TokenStream::from(err.to_compile_error()),
17    }
18}