Implement constants via calling the constant.

This commit is contained in:
Stephen Chung
2020-09-17 11:56:10 +08:00
committed by J Henry Waugh
parent c07c4561eb
commit 92be487e80
4 changed files with 23 additions and 63 deletions

View File

@@ -20,11 +20,12 @@ pub(crate) fn generate_body(
let mut set_flattened_mod_blocks: Vec<syn::ExprBlock> = Vec::new();
let str_type_path = syn::parse2::<syn::Path>(quote! { str }).unwrap();
for (const_name, const_type, const_expr) in consts {
for (const_name, _, _) in consts {
let const_literal = syn::LitStr::new(&const_name, proc_macro2::Span::call_site());
let const_ref = syn::Ident::new(&const_name, proc_macro2::Span::call_site());
set_const_stmts.push(
syn::parse2::<syn::Stmt>(quote! {
m.set_var(#const_literal, (#const_expr) as #const_type);
m.set_var(#const_literal, #const_ref);
})
.unwrap(),
);