aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Schneider <git1984941651981@oli-obk.de>2015-04-20 12:29:58 +0200
committerOliver Schneider <git1984941651981@oli-obk.de>2015-04-20 12:29:58 +0200
commitac86f4c9415adc37e49aa645f2e930dc89fa5f8a (patch)
tree4f52e7f648a23d255e339add24d1bb2986875e94
parent41563ee01b4eb3481207a88bbb2e3a54d6e96b2b (diff)
downloadmilf-rs-ac86f4c9415adc37e49aa645f2e930dc89fa5f8a.tar.gz
milf-rs-ac86f4c9415adc37e49aa645f2e930dc89fa5f8a.zip
updated to master
-rw-r--r--Cargo.toml4
-rw-r--r--src/decoder/mod.rs4
-rw-r--r--src/decoder/serde.rs14
3 files changed, 19 insertions, 3 deletions
diff --git a/Cargo.toml b/Cargo.toml
index da4f3c6..3b7eeca 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,11 +17,11 @@ facilitate deserializing and serializing Rust structures.
[dependencies]
rustc-serialize = { optional = true, version = "0.3.0" }
-serde = { optional = true, git = "https://github.com/alexcrichton/rust-serde", branch = "tweak-some-impls" }
+serde = { optional = true }
[features]
default = ["rustc-serialize"]
[dev-dependencies]
rustc-serialize = "0.3"
-serde_macros = { git = "https://github.com/alexcrichton/rust-serde", branch = "tweak-some-impls" }
+serde_macros = "*"
diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs
index a3cc29a..62de223 100644
--- a/src/decoder/mod.rs
+++ b/src/decoder/mod.rs
@@ -35,6 +35,8 @@ pub enum DecodeErrorKind {
ApplicationError(String),
/// A field was expected, but none was found.
ExpectedField(/* type */ Option<&'static str>),
+ /// A field was found, but it was not an expected one.
+ UnknownField,
/// A field was found, but it had the wrong type.
ExpectedType(/* expected */ &'static str, /* found */ &'static str),
/// The nth map key was expected, but none was found.
@@ -149,6 +151,7 @@ impl fmt::Display for DecodeError {
None => write!(f, "expected a value"),
}
}
+ UnknownField => write!(f, "unknown field"),
ExpectedType(expected, found) => {
fn humanize(s: &str) -> String {
if s == "section" {
@@ -194,6 +197,7 @@ impl error::Error for DecodeError {
match self.kind {
ApplicationError(ref s) => &**s,
ExpectedField(..) => "expected a field",
+ UnknownField => "found an unknown field",
ExpectedType(..) => "expected a type",
ExpectedMapKey(..) => "expected a map key",
ExpectedMapElement(..) => "expected a map element",
diff --git a/src/decoder/serde.rs b/src/decoder/serde.rs
index 6f60892..326f7ee 100644
--- a/src/decoder/serde.rs
+++ b/src/decoder/serde.rs
@@ -15,7 +15,13 @@ fn se2toml(err: de::value::Error, ty: &'static str) -> DecodeError {
field: Some(s.to_string()),
kind: DecodeErrorKind::ExpectedField(Some(ty)),
}
- }
+ },
+ de::value::Error::UnknownFieldError(s) => {
+ DecodeError {
+ field: Some(s.to_string()),
+ kind: DecodeErrorKind::UnknownField,
+ }
+ },
}
}
@@ -91,6 +97,12 @@ impl de::Error for DecodeError {
kind: DecodeErrorKind::ExpectedField(None),
}
}
+ fn unknown_field_error(name: &str) -> DecodeError {
+ DecodeError {
+ field: Some(name.to_string()),
+ kind: DecodeErrorKind::UnknownField,
+ }
+ }
}
impl de::Deserializer for SubDecoder {