diff options
Diffstat (limited to 'src/deserialize.rs')
-rw-r--r-- | src/deserialize.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/deserialize.rs b/src/deserialize.rs index f87cb49..f6eca35 100644 --- a/src/deserialize.rs +++ b/src/deserialize.rs @@ -1,7 +1,7 @@ use crate::types::VarInt; use std::string::FromUtf8Error; +use std::fmt; -#[derive(Debug)] pub enum DeserializeErr { Eof, VarNumTooLong(Vec<u8>), @@ -15,6 +15,30 @@ pub enum DeserializeErr { FailedJsonDeserialize(String), } +impl fmt::Display for DeserializeErr { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + use DeserializeErr::*; + match self { + Eof => f.write_str("unexpected eof"), + VarNumTooLong(data) => f.write_fmt(format_args!("var num is too long: data={:?}", data)), + NegativeLength(data) => f.write_fmt(format_args!("negative length encountered {:?}", data)), + BadStringEncoding(data) => f.write_fmt(format_args!("failed to decode string, utf error: {:?}", data)), + InvalidBool(value) => f.write_fmt(format_args!("could not decode boolean, unexpected byte: {:?}", value)), + NbtUnknownTagType(data) => f.write_fmt(format_args!("nbt: bad tag type {}", data)), + NbtBadLength(data) => f.write_fmt(format_args!("nbt: bad length {:?}", data)), + NbtInvalidStartTag(data) => f.write_fmt(format_args!("nbt: unexpected start tag id: {:?}", data)), + CannotUnderstandValue(data) => f.write_fmt(format_args!("cannot understand value: {:?}", data)), + FailedJsonDeserialize(data) => f.write_fmt(format_args!("failed to deserialize json: {:?}", data)), + } + } +} + +impl fmt::Debug for DeserializeErr { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + <dyn fmt::Display>::fmt(self, f) + } +} + impl<'b, R> Into<DeserializeResult<'b, R>> for DeserializeErr { #[inline] fn into(self) -> DeserializeResult<'b, R> { |