aboutsummaryrefslogtreecommitdiff
path: root/src/deserialize.rs
diff options
context:
space:
mode:
authorJoey Sacchini <joey@sacchini.net>2020-09-30 14:50:23 -0400
committerJoey Sacchini <joey@sacchini.net>2020-09-30 14:50:23 -0400
commit1827ef6ae21798d1f8882f1be5d445b42efd4f9f (patch)
treec494d499ba5d81ae3e9792e8e808b74e37f8f8e1 /src/deserialize.rs
parent3b6ddcb69918984ea122350b580c962a69eea017 (diff)
downloadmcproto-rs-1827ef6ae21798d1f8882f1be5d445b42efd4f9f.tar.gz
mcproto-rs-1827ef6ae21798d1f8882f1be5d445b42efd4f9f.tar.bz2
mcproto-rs-1827ef6ae21798d1f8882f1be5d445b42efd4f9f.zip
implement error correctly for the error types
Diffstat (limited to 'src/deserialize.rs')
-rw-r--r--src/deserialize.rs26
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> {