diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/decoder/serde.rs | 89 |
1 files changed, 81 insertions, 8 deletions
diff --git a/src/decoder/serde.rs b/src/decoder/serde.rs index 2f69eb9..be4e3bc 100644 --- a/src/decoder/serde.rs +++ b/src/decoder/serde.rs @@ -3,13 +3,6 @@ use Value; use super::{Decoder, DecodeError, DecodeErrorKind}; use std::collections::BTreeMap; -struct MapVisitor<'a, I> { - iter: I, - toml: &'a mut Option<Value>, - key: Option<String>, - value: Option<Value>, -} - fn se2toml(err: de::value::Error, ty: &'static str) -> DecodeError { match err { de::value::Error::SyntaxError => de::Error::syntax(ty), @@ -59,7 +52,7 @@ impl de::Deserializer for Decoder { Some(Value::Table(t)) => { visitor.visit_map(MapVisitor { iter: t.into_iter(), - toml: &mut self.toml, + de: self, key: None, value: None, }) @@ -68,6 +61,86 @@ impl de::Deserializer for Decoder { } } + fn visit_isize<V>(&mut self, visitor: V) -> Result<V::Value, DecodeError> + where V: de::Visitor + { + self.visit_i64(visitor) + } + + fn visit_i8<V>(&mut self, visitor: V) -> Result<V::Value, DecodeError> + where V: de::Visitor + { + self.visit_i64(visitor) + } + fn visit_i16<V>(&mut self, visitor: V) -> Result<V::Value, DecodeError> + where V: de::Visitor + { + self.visit_i64(visitor) + } + + fn visit_i32<V>(&mut self, visitor: V) -> Result<V::Value, DecodeError> + where V: de::Visitor + { + self.visit_i64(visitor) + } + + fn visit_i64<V>(&mut self, mut visitor: V) -> Result<V::Value, DecodeError> + where V: de::Visitor + { + match self.toml.take() { + Some(Value::Integer(f)) => { + visitor.visit_i64(f).map_err(|e| se2toml(e, "integer")) + } + ref found => Err(self.mismatch("integer", found)), + } + } + + fn visit_usize<V>(&mut self, visitor: V) -> Result<V::Value, DecodeError> + where V: de::Visitor + { + self.visit_i64(visitor) + } + + fn visit_u8<V>(&mut self, visitor: V) -> Result<V::Value, DecodeError> + where V: de::Visitor + { + self.visit_i64(visitor) + } + fn visit_u16<V>(&mut self, visitor: V) -> Result<V::Value, DecodeError> + where V: de::Visitor + { + self.visit_i64(visitor) + } + + fn visit_u32<V>(&mut self, visitor: V) -> Result<V::Value, DecodeError> + where V: de::Visitor + { + self.visit_i64(visitor) + } + + fn visit_u64<V>(&mut self, visitor: V) -> Result<V::Value, DecodeError> + where V: de::Visitor + { + self.visit_i64(visitor) + } + + fn visit_f32<V>(&mut self, visitor: V) -> Result<V::Value, DecodeError> + where V: de::Visitor + { + self.visit_f64(visitor) + } + + fn visit_f64<V>(&mut self, mut visitor: V) -> Result<V::Value, DecodeError> + where V: de::Visitor + { + match self.toml.take() { + Some(Value::Float(f)) => { + visitor.visit_f64(f).map_err(|e| se2toml(e, "float")) + } + ref found => Err(self.mismatch("float", found)), + } + } + fn visit_option<V>(&mut self, mut visitor: V) -> Result<V::Value, DecodeError> where V: de::Visitor { |