Files
wasmtime/cranelift/peepmatic/crates/macro/src/into_dyn_ast_ref.rs
Nick Fitzgerald 0f03a97475 peepmatic: Introduce the peepmatic-macro crate
This crate provides the derive macros used by `peepmatic`, notable AST-related
derives that enumerate child AST nodes, and operator-related derives that
provide helpers for type checking.
2020-05-14 07:50:58 -07:00

24 lines
647 B
Rust

use quote::quote;
use syn::DeriveInput;
use syn::Result;
pub fn derive_into_dyn_ast_ref(input: &DeriveInput) -> Result<impl quote::ToTokens> {
let ty = &input.ident;
let opts = crate::PeepmaticOpts::from_attrs(&mut input.attrs.clone())?;
if opts.no_into_dyn_node {
return Ok(quote! {});
}
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
Ok(quote! {
impl #impl_generics From<&'a #ty #ty_generics> for DynAstRef<'a> #where_clause {
#[inline]
fn from(x: &'a #ty #ty_generics) -> Self {
Self::#ty(x)
}
}
})
}