1use darling::{FromDeriveInput, FromMeta};
2use proc_macro::TokenStream;
3use quote::quote;
4use syn::{parse_macro_input, DeriveInput, Ident, Type};
5
6#[derive(FromDeriveInput, Default)]
8#[darling(default, attributes(msg), forward_attrs(allow, doc, cfg))]
9struct MessageOpts {
10 rtype: Option<Type>,
12}
13
14#[proc_macro_derive(Message, attributes(msg))]
32pub fn derive_message_impl(input: TokenStream) -> TokenStream {
33 let input: DeriveInput = parse_macro_input!(input);
34 let opts: MessageOpts = MessageOpts::from_derive_input(&input).expect("Invalid options");
35
36 let ident: Ident = input.ident;
37
38 let rtype: Type = match opts.rtype {
39 Some(value) => value,
41 None => Type::from_string("()").unwrap(),
43 };
44
45 quote! {
46 impl interlink::msg::Message for #ident {
47 type Response = #rtype;
48 }
49 }
50 .into()
51}
52
53#[proc_macro_derive(Service)]
56pub fn derive_service_impl(input: TokenStream) -> TokenStream {
57 let input: DeriveInput = parse_macro_input!(input);
58 let ident = input.ident;
59 quote! {
60 impl interlink::service::Service for #ident { }
61 }
62 .into()
63}