aboutsummaryrefslogtreecommitdiff
path: root/azalea-nbt/src/error.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-08-27 01:27:45 -0500
committermat <git@matdoes.dev>2023-08-27 01:27:45 -0500
commitbf8f533d9f75dc6a1e218b5c576fe9a1275b17ec (patch)
tree8f1ed86affe6fbaa8789317f9e0206e826a63640 /azalea-nbt/src/error.rs
parent12118ebfa3f8165c345c98596957b25a156c8b74 (diff)
downloadazalea-drasl-bf8f533d9f75dc6a1e218b5c576fe9a1275b17ec.tar.xz
use thiserror for azalea_nbt::Error
Diffstat (limited to 'azalea-nbt/src/error.rs')
-rwxr-xr-xazalea-nbt/src/error.rs36
1 files changed, 10 insertions, 26 deletions
diff --git a/azalea-nbt/src/error.rs b/azalea-nbt/src/error.rs
index d3c5ff44..ace7fcd3 100755
--- a/azalea-nbt/src/error.rs
+++ b/azalea-nbt/src/error.rs
@@ -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)
- }
-}