diff --git a/src/error.rs b/src/error.rs index 3f0242b..ea087fc 100644 --- a/src/error.rs +++ b/src/error.rs @@ -105,7 +105,7 @@ pub enum KbinErrorKind { MissingTypeHint, #[fail(display = "Type mismatch, expected: {}, found: {}", _0, _1)] - TypeMismatch(KbinType, KbinType), + TypeMismatch(StandardType, StandardType), #[fail(display = "Invalid input for boolean: {}", _0)] InvalidBooleanInput(u8), diff --git a/src/node_types.rs b/src/node_types.rs index ccacb02..4a8c091 100644 --- a/src/node_types.rs +++ b/src/node_types.rs @@ -93,6 +93,16 @@ macro_rules! construct_types { } } + impl fmt::Display for StandardType { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + $( + StandardType::$konst => f.write_str(stringify!($konst)), + )+ + } + } + } + impl Deref for StandardType { type Target = KbinType; diff --git a/src/ser/map.rs b/src/ser/map.rs index 27347ef..1b5073a 100644 --- a/src/ser/map.rs +++ b/src/ser/map.rs @@ -79,7 +79,7 @@ impl<'a> SerializeMap for Map<'a> { match hint.node_type { StandardType::Attribute | StandardType::String => Ok(()), - node_type => Err(KbinErrorKind::TypeMismatch(*StandardType::String, *node_type).into()), + node_type => Err(KbinErrorKind::TypeMismatch(StandardType::String, node_type).into()), } } diff --git a/src/ser/seq.rs b/src/ser/seq.rs index b35e0ce..1702e53 100644 --- a/src/ser/seq.rs +++ b/src/ser/seq.rs @@ -51,7 +51,7 @@ impl<'a> SerializeSeq for Seq<'a> { // permitted by kbin if let Some(node_type) = self.node_type { if node_type != hint.node_type { - return Err(KbinErrorKind::TypeMismatch(*node_type, *hint.node_type).into()); + return Err(KbinErrorKind::TypeMismatch(node_type, hint.node_type).into()); } } else { self.node_type = Some(hint.node_type); diff --git a/src/ser/structure.rs b/src/ser/structure.rs index d93ef5d..b8ace62 100644 --- a/src/ser/structure.rs +++ b/src/ser/structure.rs @@ -71,7 +71,7 @@ impl<'a> SerializeStruct for Struct<'a> { // Attribute nodes are always strings if node_type != StandardType::String { - return Err(KbinErrorKind::TypeMismatch(*StandardType::String, *node_type).into()); + return Err(KbinErrorKind::TypeMismatch(StandardType::String, node_type).into()); } (StandardType::Attribute, key) diff --git a/src/ser/tuple.rs b/src/ser/tuple.rs index f90e406..ac7c625 100644 --- a/src/ser/tuple.rs +++ b/src/ser/tuple.rs @@ -58,7 +58,7 @@ impl<'a> SerializeTuple for Tuple<'a> { // permitted by kbin if let Some(known) = self.node_type { if known != node_type { - return Err(KbinErrorKind::TypeMismatch(*known, *node_type).into()); + return Err(KbinErrorKind::TypeMismatch(known, node_type).into()); } } else { self.node_type = Some(node_type);