Packet proc macro
This commit is contained in:
parent
4fa1cced79
commit
a5110eb939
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -1167,6 +1167,15 @@ dependencies = [
|
|||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pumpkin-macros"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.72",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pumpkin-protocol"
|
name = "pumpkin-protocol"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = [ "pumpkin-protocol/", "pumpkin-registry/", "pumpkin-world", "pumpkin/"]
|
members = [ "pumpkin-macros", "pumpkin-protocol/", "pumpkin-registry/", "pumpkin-world", "pumpkin/"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|||||||
12
pumpkin-macros/Cargo.toml
Normal file
12
pumpkin-macros/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "pumpkin-macros"
|
||||||
|
version.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
proc-macro = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
proc-macro2 = "1.0.86"
|
||||||
|
quote = "1.0.36"
|
||||||
|
syn = "2.0.72"
|
||||||
24
pumpkin-macros/src/lib.rs
Normal file
24
pumpkin-macros/src/lib.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
use proc_macro::TokenStream;
|
||||||
|
use quote::quote;
|
||||||
|
|
||||||
|
extern crate proc_macro;
|
||||||
|
#[proc_macro_attribute]
|
||||||
|
pub fn packet(input: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
|
let ast: syn::DeriveInput = syn::parse(item.clone()).unwrap();
|
||||||
|
|
||||||
|
let name = &ast.ident;
|
||||||
|
|
||||||
|
let (impl_generics, ty_generics, _) = ast.generics.split_for_impl();
|
||||||
|
|
||||||
|
let input: proc_macro2::TokenStream = input.into();
|
||||||
|
let item: proc_macro2::TokenStream = item.into();
|
||||||
|
|
||||||
|
let gen = quote! {
|
||||||
|
#item
|
||||||
|
impl #impl_generics crate::bytebuf::packet_id::Packet for #name #ty_generics {
|
||||||
|
const PACKET_ID: i32 = #input;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
gen.into()
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user