aboutsummaryrefslogtreecommitdiffstats
path: root/src/de.rs
diff options
context:
space:
mode:
authorEdward Barnard2015-12-25 01:16:23 +0000
committerEdward Barnard2015-12-25 10:58:40 +0000
commit35ee8e80f25d852620061fc6e9627485467d12ea (patch)
tree0cc6071d933548fad8f2c2c25012c1a2c7f34ec0 /src/de.rs
parentbce38e77de935d1d06ab220dacc8870a3362b80a (diff)
downloadrust-plist-35ee8e80f25d852620061fc6e9627485467d12ea.tar.bz2
Better handling of u64 to usize conversions
Diffstat (limited to 'src/de.rs')
-rw-r--r--src/de.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/de.rs b/src/de.rs
index 4290254..9affd01 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -5,7 +5,7 @@ use serde::de::{Deserializer as SerdeDeserializer, Error as SerdeError, Visitor,
MapVisitor, VariantVisitor, Deserialize, EnumVisitor};
use std::iter::Peekable;
-use PlistEvent;
+use {PlistEvent, u64_option_to_usize};
macro_rules! expect {
($next:expr, $pat:pat) => {
@@ -39,6 +39,12 @@ pub enum Error {
None,
}
+impl From<::Error> for Error {
+ fn from(_: ::Error) -> Error {
+ Error::None
+ }
+}
+
impl SerdeError for Error {
fn syntax(_msg: &str) -> Self {
panic!("stx");
@@ -87,12 +93,14 @@ impl<I, E> SerdeDeserializer for Deserializer<I, E>
PlistEvent::EndPlist => panic!(),
PlistEvent::StartArray(len) => {
- visitor.visit_seq(MapSeq::new(self, len.map(|l| l as usize)))
+ let len = try!(u64_option_to_usize(len));
+ visitor.visit_seq(MapSeq::new(self, len))
}
PlistEvent::EndArray => return Err(Error::syntax("")),
PlistEvent::StartDictionary(len) => {
- visitor.visit_map(MapSeq::new(self, len.map(|l| l as usize)))
+ let len = try!(u64_option_to_usize(len));
+ visitor.visit_map(MapSeq::new(self, len))
}
PlistEvent::EndDictionary => return Err(Error::syntax("")),
@@ -120,7 +128,13 @@ impl<I, E> SerdeDeserializer for Deserializer<I, E>
let ret = match try_next!(self.events.next()) {
PlistEvent::StringValue(ref s) if &s[..] == "None" => {
- let ret = try!(visitor.visit_none());
+ let ret = match visitor.visit_none() {
+ Ok(ret) => ret,
+ Err(e) => return Err(e)
+ };
+ // For some reason the try! below doesn't work - probably a macro hygene issue
+ // with Error and ::Error
+ //let ret = try!(visitor.visit_none());
expect!(self.events.next(), PlistEvent::StringValue(_));
ret
}