error: use StandardType for TypeMismatch error

This commit is contained in:
Matt Bilker
2018-09-07 14:54:32 +00:00
parent 3cbe1f51db
commit 92a25aed22
6 changed files with 15 additions and 5 deletions

View File

@@ -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),

View File

@@ -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;

View File

@@ -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()),
}
}

View File

@@ -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);

View File

@@ -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)

View File

@@ -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);