kitty_remote_bindings_macros/
lib.rs1use proc_macro::TokenStream;
2use syn::{DeriveInput, ItemEnum, ItemStruct};
3
4mod kitty_command;
5mod kitty_command_option;
6
7#[proc_macro_derive(KittyCommand, attributes(kitty_command, top_level, option))]
11pub fn derive_command(item: TokenStream) -> TokenStream {
12 let item_parsed = {
13 let cloned = item.clone();
14 syn::parse_macro_input!(cloned as DeriveInput)
15 };
16
17 match item_parsed.data {
18 syn::Data::Struct(_) => {
19 kitty_command::derive_impl(&syn::parse_macro_input!(item as ItemStruct))
20 }
21 _ => panic!("Only struct is supported by the KittyCommand macro"),
22 }
23}
24
25#[proc_macro_derive(KittyCommandOption, attributes(prefix))]
29pub fn derive_command_option(item: TokenStream) -> TokenStream {
30 let item_parsed = {
31 let cloned = item.clone();
32 syn::parse_macro_input!(cloned as DeriveInput)
33 };
34
35 match item_parsed.data {
36 syn::Data::Struct(_) => {
37 kitty_command_option::struct_impl(&syn::parse_macro_input!(item as ItemStruct))
38 }
39 syn::Data::Enum(_) => {
40 kitty_command_option::enum_impl(&syn::parse_macro_input!(item as ItemEnum))
41 }
42 syn::Data::Union(_) => {
43 panic!("Only enum and struct is supported by the KittyCommand macro")
44 }
45 }
46}