nexus_actor_message_derive_rs/
lib.rs

1use proc_macro::TokenStream;
2use quote::quote;
3use syn::{parse_macro_input, DeriveInput};
4
5#[proc_macro_derive(Message)]
6pub fn derive_message(input: TokenStream) -> TokenStream {
7  let input = parse_macro_input!(input as DeriveInput);
8  let name = &input.ident;
9
10  let expanded = quote! {
11      impl Message for #name {
12          fn eq_message(&self, other: &dyn Message) -> bool {
13              other.as_any().downcast_ref::<Self>()
14                  .map_or(false, |other| self == other)
15          }
16
17          fn as_any(&self) -> &(dyn std::any::Any + Send + Sync + 'static) {
18              self
19          }
20
21          fn get_type_name(&self) -> String {
22              std::any::type_name_of_val(self).to_string()
23          }
24      }
25  };
26
27  TokenStream::from(expanded)
28}