feat!: Refactor, Update to version 2.5.x, Add Battle Scepter
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "proto-derive"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
syn = "2.0.53"
|
||||
quote = "1.0.35"
|
||||
proc-macro2 = "1.0.79"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
@@ -0,0 +1,27 @@
|
||||
use proc_macro::TokenStream;
|
||||
use quote::{quote, ToTokens};
|
||||
use syn::{parse_macro_input, DeriveInput, Meta, MetaList};
|
||||
|
||||
#[proc_macro_derive(CmdID, attributes(cmdid))]
|
||||
pub fn message_id_derive(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as DeriveInput);
|
||||
let struct_name = input.ident;
|
||||
|
||||
let id = match input
|
||||
.attrs
|
||||
.iter()
|
||||
.find(|attr| attr.path().is_ident("cmdid"))
|
||||
{
|
||||
Some(attr) => match attr.meta {
|
||||
Meta::List(MetaList { ref tokens, .. }) => tokens.into_token_stream(),
|
||||
_ => panic!("Invalid cmdid attribute value"),
|
||||
},
|
||||
_ => 0u16.into_token_stream(),
|
||||
};
|
||||
|
||||
TokenStream::from(quote! {
|
||||
impl crate::CmdID for #struct_name {
|
||||
const CMD_ID: u16 = #id;
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user