mirror of
https://github.com/mbilker/kbinxml-rs.git
synced 2026-09-09 02:55:30 -05:00
value: add a method to get the StandardType of a Value
This commit is contained in:
@@ -86,7 +86,7 @@ impl<'de> Deserialize<'de> for Value {
|
||||
{
|
||||
trace!("ValueVisitor::visit_map()");
|
||||
|
||||
let mut values: IndexMap<String, Self::Value> = IndexMap::new();
|
||||
let mut values: IndexMap<String, Value> = IndexMap::new();
|
||||
|
||||
while let Some((key, value)) = try!(map.next_entry()) {
|
||||
// Check to see if this is an attribute
|
||||
|
||||
@@ -35,6 +35,20 @@ macro_rules! construct_types {
|
||||
}
|
||||
)+
|
||||
|
||||
impl Value {
|
||||
pub fn standard_type(&self) -> Option<StandardType> {
|
||||
match *self {
|
||||
$(
|
||||
Value::$konst(_) => Some(StandardType::$konst),
|
||||
)+
|
||||
Value::Time(_) => Some(StandardType::Time),
|
||||
Value::Attribute(_) => Some(StandardType::Attribute),
|
||||
Value::Array(_) => None,
|
||||
Value::Map(_) => Some(StandardType::NodeStart),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> DeserializeSeed<'de> for StandardType {
|
||||
type Value = Value;
|
||||
|
||||
@@ -44,12 +58,12 @@ macro_rules! construct_types {
|
||||
trace!("<StandardType as DeserializeSeed>::deserialize(self: {:?})", self);
|
||||
match self {
|
||||
$(
|
||||
StandardType::$konst => <$($value_type)*>::deserialize(deserializer).map(Value::from),
|
||||
StandardType::$konst => <$($value_type)*>::deserialize(deserializer).map(Value::$konst),
|
||||
)+
|
||||
StandardType::Time => u32::deserialize(deserializer).map(Value::Time),
|
||||
StandardType::Attribute => String::deserialize(deserializer).map(Value::Attribute),
|
||||
StandardType::NodeStart => Value::deserialize(deserializer),
|
||||
StandardType::NodeEnd => unimplemented!(),
|
||||
StandardType::NodeEnd |
|
||||
StandardType::FileEnd => unimplemented!(),
|
||||
}
|
||||
}
|
||||
@@ -57,6 +71,7 @@ macro_rules! construct_types {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl fmt::Debug for Value {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
macro_rules! field {
|
||||
|
||||
Reference in New Issue
Block a user