mirror of
https://github.com/mbilker/kbinxml-rs.git
synced 2026-09-10 03:25:14 -05:00
error: use StandardType for TypeMismatch error
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user