diff options
Diffstat (limited to 'azalea-buf/buf-macros/src')
| -rw-r--r-- | azalea-buf/buf-macros/src/lib.rs | 15 |
1 files changed, 10 insertions, 5 deletions
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 }), } } } |
