numext_constructor/
lib.rs#![recursion_limit = "1024"]
extern crate proc_macro;
#[macro_use]
extern crate quote;
#[macro_use]
mod utils;
mod definition;
mod fixed_hash;
mod fixed_uint;
use quote::quote;
use syn::parse_macro_input;
#[proc_macro]
pub fn construct_fixed_uints(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let inputs = parse_macro_input!(input as definition::Definitions);
let expanded = {
inputs
.inner
.into_iter()
.map(|input| {
let parsed: fixed_uint::parsed::UintDefinition = input.into();
fixed_uint::core::UintConstructor::new(parsed)
})
.fold((quote!(), Vec::new()), |(uints, mut ucs), uc| {
let (uint, public) = uc.construct_all(&ucs[..]);
let uints = quote!(#uints #public #uint);
ucs.push(uc);
(uints, ucs)
})
.0
};
expanded.into()
}
#[proc_macro]
pub fn construct_fixed_hashes(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let inputs = parse_macro_input!(input as definition::Definitions);
let expanded = {
inputs
.inner
.into_iter()
.map(|input| {
let parsed: fixed_hash::parsed::HashDefinition = input.into();
fixed_hash::core::HashConstructor::new(parsed)
})
.fold((quote!(), Vec::new()), |(hashes, mut ucs), uc| {
let (hash, public) = uc.construct_all(&ucs[..]);
let hashes = quote!(#hashes #public #hash);
ucs.push(uc);
(hashes, ucs)
})
.0
};
expanded.into()
}