summaryrefslogtreecommitdiffstats
path: root/lib/src/de.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/de.rs')
-rw-r--r--lib/src/de.rs52
1 files changed, 17 insertions, 35 deletions
diff --git a/lib/src/de.rs b/lib/src/de.rs
index d1673d5..369d6de 100644
--- a/lib/src/de.rs
+++ b/lib/src/de.rs
@@ -10,14 +10,16 @@ impl de::Deserializer for Value {
type Error = ConfigError;
#[inline]
- fn deserialize<V: de::Visitor>(self, visitor: V) -> Result<V::Value> {
+ fn deserialize<V>(self, visitor: V) -> Result<V::Value>
+ where V: de::Visitor,
+ {
// Deserialize based on the underlying type
match self.kind {
ValueKind::Integer(i) => visitor.visit_i64(i),
ValueKind::Boolean(b) => visitor.visit_bool(b),
ValueKind::Float(f) => visitor.visit_f64(f),
- // ValueKind::String(Cow::Borrowed(s)) => visitor.visit_str(s),
- // ValueKind::String(Cow::Owned(s)) => visitor.visit_string(s),
+ ValueKind::String(s) => visitor.visit_string(s),
+ ValueKind::Array(values) => unimplemented!(),
ValueKind::Table(map) => visitor.visit_map(MapVisitor::new(map)),
_ => { unimplemented!(); }
}
@@ -32,6 +34,12 @@ impl de::Deserializer for Value {
struct StrDeserializer<'a>(&'a str);
+impl<'a> StrDeserializer<'a> {
+ fn new(key: &'a str) -> Self {
+ StrDeserializer(key)
+ }
+}
+
impl<'a> de::Deserializer for StrDeserializer<'a> {
type Error = ConfigError;
@@ -41,35 +49,9 @@ impl<'a> de::Deserializer for StrDeserializer<'a> {
}
forward_to_deserialize! {
- bool
- u8
- u16
- u32
- u64
- i8
- i16
- i32
- i64
- f32
- f64
- char
- str
- string
- bytes
- byte_buf
- option
- unit
- unit_struct
- newtype_struct
- seq
- seq_fixed_size
- tuple
- tuple_struct
- map
- struct
- struct_field
- enum
- ignored_any
+ bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq
+ seq_fixed_size bytes byte_buf map struct unit enum newtype_struct
+ struct_field ignored_any unit_struct tuple_struct tuple option
}
}
@@ -79,7 +61,7 @@ struct MapVisitor {
}
impl MapVisitor {
- fn new(mut table: HashMap<String, Value>) -> MapVisitor {
+ fn new(mut table: HashMap<String, Value>) -> Self {
MapVisitor { elements: table.drain().collect(), index: 0 }
}
}
@@ -94,8 +76,8 @@ impl de::MapVisitor for MapVisitor {
return Ok(None);
}
- let ref key_s = self.elements[0].0;
- let key_de = StrDeserializer(&key_s);
+ let key_s = &self.elements[0].0;
+ let key_de = StrDeserializer(key_s);
let key = de::DeserializeSeed::deserialize(seed, key_de)?;
Ok(Some(key))