1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

use thiserror for azalea_nbt::Error

This commit is contained in:
mat 2023-08-27 01:27:45 -05:00
parent 12118ebfa3
commit bf8f533d9f
3 changed files with 16 additions and 30 deletions

9
Cargo.lock generated
View file

@ -416,6 +416,7 @@ dependencies = [
"graphite_binary",
"log",
"serde",
"thiserror",
"valence_nbt",
]
@ -2621,18 +2622,18 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.46"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9207952ae1a003f42d3d5e892dac3c6ba42aa6ac0c79a6a91a2b5cb4253e75c"
checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.46"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1728216d3244de4f14f14f8c15c79be1a7c67867d28d69b719690e2a19fb445"
checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b"
dependencies = [
"proc-macro2",
"quote",

View file

@ -16,6 +16,7 @@ enum-as-inner = "0.6.0"
flate2 = "^1.0.27"
log = "0.4.20"
serde = { version = "^1.0", features = ["derive"], optional = true }
thiserror = "1.0.47"
[dev-dependencies]
criterion = { version = "^0.5.1", features = ["html_reports"] }

View file

@ -1,31 +1,15 @@
#[derive(Debug)]
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("Invalid tag type: {0}")]
InvalidTagType(u8),
#[error("Invalid tag")]
InvalidTag,
WriteError(std::io::Error),
Utf8Error(std::str::Utf8Error),
#[error("Write error: {0}")]
WriteError(#[from] std::io::Error),
#[error("Utf8 error: {0}")]
Utf8Error(#[from] std::str::Utf8Error),
#[error("Unexpected EOF")]
UnexpectedEof,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::InvalidTagType(id) => write!(f, "Invalid tag type: {id}"),
Error::InvalidTag => write!(f, "Invalid tag"),
Error::WriteError(e) => write!(f, "Write error: {e}"),
Error::Utf8Error(e) => write!(f, "Utf8 error: {e}"),
Error::UnexpectedEof => write!(f, "Unexpected EOF"),
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error::WriteError(e)
}
}
impl From<std::str::Utf8Error> for Error {
fn from(e: std::str::Utf8Error) -> Self {
Error::Utf8Error(e)
}
}