35 lines
1.3 KiB
Rust
35 lines
1.3 KiB
Rust
use quote::quote;
|
|
use syn::{parse_macro_input, DeriveInput};
|
|
|
|
#[proc_macro_derive(RenderGraphLabel)]
|
|
pub fn derive_render_graph_label(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
|
let input = parse_macro_input!(input as DeriveInput);
|
|
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
|
|
|
let type_ident = &input.ident;
|
|
|
|
proc_macro::TokenStream::from(quote! {
|
|
impl #impl_generics crate::render::graph::RenderGraphLabel for #type_ident #ty_generics #where_clause {
|
|
fn rc_clone(&self) -> std::rc::Rc<dyn crate::render::graph::RenderGraphLabel> {
|
|
std::rc::Rc::new(self.clone())
|
|
}
|
|
|
|
/* fn as_dyn(&self) -> &dyn crate::render::graph::RenderGraphLabel {
|
|
&self
|
|
}
|
|
|
|
fn as_partial_eq(&self) -> &dyn PartialEq<dyn crate::render::graph::RenderGraphLabel> {
|
|
self
|
|
} */
|
|
|
|
fn as_label_hash(&self) -> u64 {
|
|
let tyid = ::std::any::TypeId::of::<Self>();
|
|
|
|
let mut s = ::std::hash::DefaultHasher::new();
|
|
::std::hash::Hash::hash(&tyid, &mut s);
|
|
::std::hash::Hash::hash(self, &mut s);
|
|
::std::hash::Hasher::finish(&s)
|
|
}
|
|
}
|
|
})
|
|
} |