From bf8f533d9f75dc6a1e218b5c576fe9a1275b17ec Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 27 Aug 2023 01:27:45 -0500 Subject: use thiserror for azalea_nbt::Error --- azalea-nbt/src/error.rs | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) (limited to 'azalea-nbt/src/error.rs') 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 for Error { - fn from(e: std::io::Error) -> Self { - Error::WriteError(e) - } -} -impl From for Error { - fn from(e: std::str::Utf8Error) -> Self { - Error::Utf8Error(e) - } -} -- cgit v1.2.3