diff options
| author | mat <git@matdoes.dev> | 2025-12-16 09:42:54 -0200 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-12-16 09:42:54 -0200 |
| commit | 6f2fe2c9e5af1f2fa2c1b99c3d4ea0a7e90ae16c (patch) | |
| tree | b01afabf10b51e3024dfdc139803b590a36b08c2 /azalea-buf/azalea-buf-macros/src/write.rs | |
| parent | 9bd529277f5025805da95f081657c180972e487e (diff) | |
| download | azalea-drasl-6f2fe2c9e5af1f2fa2c1b99c3d4ea0a7e90ae16c.tar.xz | |
change KnockbackEvent to an EntityEvent and fix ClientboundExplode representation
ty mahtog for pointing out the latter issue <3
Diffstat (limited to 'azalea-buf/azalea-buf-macros/src/write.rs')
| -rw-r--r-- | azalea-buf/azalea-buf-macros/src/write.rs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/azalea-buf/azalea-buf-macros/src/write.rs b/azalea-buf/azalea-buf-macros/src/write.rs index 12739eb5..7bd58d29 100644 --- a/azalea-buf/azalea-buf-macros/src/write.rs +++ b/azalea-buf/azalea-buf-macros/src/write.rs @@ -1,8 +1,14 @@ use proc_macro2::Span; use quote::{ToTokens, quote}; -use syn::{Data, Field, FieldsNamed, Ident, punctuated::Punctuated, token::Comma}; +use syn::{Data, Field, FieldsNamed, Generics, Ident, punctuated::Punctuated, token::Comma}; + +pub fn create_impl_azaleawrite( + ident: &Ident, + generics: &Generics, + data: &Data, +) -> proc_macro2::TokenStream { + let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); -pub fn create_impl_azaleawrite(ident: &Ident, data: &Data) -> proc_macro2::TokenStream { match data { syn::Data::Struct(syn::DataStruct { fields, .. }) => match fields { syn::Fields::Named(FieldsNamed { named, .. }) => { @@ -10,7 +16,7 @@ pub fn create_impl_azaleawrite(ident: &Ident, data: &Data) -> proc_macro2::Token write_named_fields(named, Some(&Ident::new("self", Span::call_site()))); quote! { - impl azalea_buf::AzaleaWrite for #ident { + impl #impl_generics azalea_buf::AzaleaWrite for #ident #ty_generics #where_clause { fn azalea_write(&self, buf: &mut impl std::io::Write) -> std::result::Result<(), std::io::Error> { #write_fields Ok(()) @@ -20,7 +26,7 @@ pub fn create_impl_azaleawrite(ident: &Ident, data: &Data) -> proc_macro2::Token } syn::Fields::Unit => { quote! { - impl azalea_buf::AzaleaWrite for #ident { + impl #impl_generics azalea_buf::AzaleaWrite for #ident #ty_generics #where_clause { fn azalea_write(&self, buf: &mut impl std::io::Write) -> std::result::Result<(), std::io::Error> { Ok(()) } @@ -31,7 +37,7 @@ pub fn create_impl_azaleawrite(ident: &Ident, data: &Data) -> proc_macro2::Token let write_fields = write_unnamed_fields(&fields.unnamed); quote! { - impl azalea_buf::AzaleaWrite for #ident { + impl #impl_generics azalea_buf::AzaleaWrite for #ident #ty_generics #where_clause { fn azalea_write(&self, buf: &mut impl std::io::Write) -> std::result::Result<(), std::io::Error> { #write_fields Ok(()) @@ -143,7 +149,7 @@ pub fn create_impl_azaleawrite(ident: &Ident, data: &Data) -> proc_macro2::Token } if is_data_enum { quote! { - impl azalea_buf::AzaleaWrite for #ident { + impl #impl_generics azalea_buf::AzaleaWrite for #ident #ty_generics #where_clause { fn azalea_write(&self, buf: &mut impl std::io::Write) -> std::result::Result<(), std::io::Error> { match self { #match_arms @@ -151,7 +157,7 @@ pub fn create_impl_azaleawrite(ident: &Ident, data: &Data) -> proc_macro2::Token Ok(()) } } - impl #ident { + impl #impl_generics #ident #ty_generics #where_clause { pub fn write_without_id(&self, buf: &mut impl std::io::Write) -> std::result::Result<(), std::io::Error> { match self { #match_arms_without_id @@ -163,7 +169,7 @@ pub fn create_impl_azaleawrite(ident: &Ident, data: &Data) -> proc_macro2::Token } else { // optimization: if it doesn't have data we can just do `as u32` quote! { - impl azalea_buf::AzaleaWrite for #ident { + impl #impl_generics azalea_buf::AzaleaWrite for #ident #ty_generics #where_clause { fn azalea_write(&self, buf: &mut impl std::io::Write) -> std::result::Result<(), std::io::Error> { azalea_buf::AzaleaWriteVar::azalea_write_var(&(*self as u32), buf) } |
