1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
extern crate proc_macro; use proc_macro::TokenStream; use quote::quote; use syn::{parse_macro_input, DeriveInput}; #[proc_macro_derive(Pipeline)] pub fn derive_pipeline(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); let ident = &input.ident; let gen = quote! { impl render::Pipeline for #ident { fn box_eq(&self, other: &dyn Any) -> bool { other.downcast_ref::<Self>().map_or(false, |a| self == a) } fn as_any(&self) -> &dyn Any { self } fn clone_box(&self) -> Box<dyn render::Pipeline> { Box::new(self.clone()) } } }; TokenStream::from(gen) }