aboutsummaryrefslogtreecommitdiff
path: root/azalea-buf/buf-macros
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-buf/buf-macros')
-rw-r--r--azalea-buf/buf-macros/Cargo.toml2
-rw-r--r--azalea-buf/buf-macros/src/lib.rs15
2 files changed, 11 insertions, 6 deletions
diff --git a/azalea-buf/buf-macros/Cargo.toml b/azalea-buf/buf-macros/Cargo.toml
index fecf64ed..64e9a228 100644
--- a/azalea-buf/buf-macros/Cargo.toml
+++ b/azalea-buf/buf-macros/Cargo.toml
@@ -10,4 +10,4 @@ proc-macro = true
[dependencies]
proc-macro2 = "^1.0.36"
quote = "^1.0.10"
-syn = "^1.0.82"
+syn = {version = "^1.0.82", features = ["extra-traits"]}
diff --git a/azalea-buf/buf-macros/src/lib.rs b/azalea-buf/buf-macros/src/lib.rs
index a735a920..25bceef0 100644
--- a/azalea-buf/buf-macros/src/lib.rs
+++ b/azalea-buf/buf-macros/src/lib.rs
@@ -41,7 +41,7 @@ fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt
quote! {
impl azalea_buf::McBufReadable for #ident {
- fn read_from(buf: &mut impl std::io::Read) -> Result<Self, String> {
+ fn read_from(buf: &mut impl std::io::Read) -> Result<Self, azalea_buf::BufReadError> {
#(#read_fields)*
Ok(#ident {
#(#read_field_names: #read_field_names),*
@@ -60,9 +60,14 @@ fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt
variant_discrim = match &d.1 {
syn::Expr::Lit(e) => match &e.lit {
syn::Lit::Int(i) => i.base10_parse().unwrap(),
- _ => panic!("Error parsing enum discriminant"),
+ _ => panic!("Error parsing enum discriminant as int"),
},
- _ => panic!("Error parsing enum discriminant"),
+ syn::Expr::Unary(_) => {
+ panic!("Negative enum discriminants are not supported")
+ }
+ _ => {
+ panic!("Error parsing enum discriminant as literal (is {:?})", d.1)
+ }
}
}
None => {
@@ -76,12 +81,12 @@ fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt
quote! {
impl azalea_buf::McBufReadable for #ident {
- fn read_from(buf: &mut impl std::io::Read) -> Result<Self, String>
+ fn read_from(buf: &mut impl std::io::Read) -> Result<Self, azalea_buf::BufReadError>
{
let id = azalea_buf::McBufVarReadable::var_read_from(buf)?;
match id {
#match_contents
- _ => Err(format!("Unknown enum variant {}", id)),
+ _ => Err(azalea_buf::BufReadError::UnexpectedEnumVariant { id: id as i32 }),
}
}
}