aboutsummaryrefslogtreecommitdiff
path: root/src/decoder/mod.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-07-29 09:22:22 -0700
committerGitHub <noreply@github.com>2016-07-29 09:22:22 -0700
commit456cd1c7aa86896b0e87a7a995eefcd65ef79b01 (patch)
tree0c3efc8e1372aef3f6edefa95564da9718e8b029 /src/decoder/mod.rs
parentfb8050d2d556dd613971f15e7bd73cfd43acad82 (diff)
parentdca3eca564ac53620b0f8f66c76675bfc8c62203 (diff)
downloadmilf-rs-456cd1c7aa86896b0e87a7a995eefcd65ef79b01.tar.gz
milf-rs-456cd1c7aa86896b0e87a7a995eefcd65ef79b01.zip
Merge pull request #105 from dtolnay/up
Update to serde 0.8.0
Diffstat (limited to 'src/decoder/mod.rs')
-rw-r--r--src/decoder/mod.rs40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs
index b223e03..9720528 100644
--- a/src/decoder/mod.rs
+++ b/src/decoder/mod.rs
@@ -1,6 +1,9 @@
use std::error;
use std::fmt;
+
+#[cfg(feature = "rustc-serialize")]
use std::collections::{btree_map, BTreeMap};
+#[cfg(feature = "rustc-serialize")]
use std::iter::Peekable;
use Value;
@@ -19,7 +22,9 @@ pub struct Decoder {
/// whether fields were decoded or not.
pub toml: Option<Value>,
cur_field: Option<String>,
+ #[cfg(feature = "rustc-serialize")]
cur_map: Peekable<btree_map::IntoIter<String, Value>>,
+ #[cfg(feature = "rustc-serialize")]
leftover_map: ::Table,
}
@@ -115,27 +120,36 @@ impl Decoder {
/// This decoder can be passed to the `Decodable` methods or driven
/// manually.
pub fn new(toml: Value) -> Decoder {
+ Decoder::new_empty(Some(toml), None)
+ }
+
+ fn sub_decoder(&self, toml: Option<Value>, field: &str) -> Decoder {
+ let cur_field = if field.is_empty() {
+ self.cur_field.clone()
+ } else {
+ match self.cur_field {
+ None => Some(field.to_string()),
+ Some(ref s) => Some(format!("{}.{}", s, field))
+ }
+ };
+ Decoder::new_empty(toml, cur_field)
+ }
+
+ #[cfg(feature = "rustc-serialize")]
+ fn new_empty(toml: Option<Value>, cur_field: Option<String>) -> Decoder {
Decoder {
- toml: Some(toml),
- cur_field: None,
+ toml: toml,
+ cur_field: cur_field,
leftover_map: BTreeMap::new(),
cur_map: BTreeMap::new().into_iter().peekable(),
}
}
- fn sub_decoder(&self, toml: Option<Value>, field: &str) -> Decoder {
+ #[cfg(not(feature = "rustc-serialize"))]
+ fn new_empty(toml: Option<Value>, cur_field: Option<String>) -> Decoder {
Decoder {
toml: toml,
- cur_field: if field.is_empty() {
- self.cur_field.clone()
- } else {
- match self.cur_field {
- None => Some(field.to_string()),
- Some(ref s) => Some(format!("{}.{}", s, field))
- }
- },
- leftover_map: BTreeMap::new(),
- cur_map: BTreeMap::new().into_iter().peekable(),
+ cur_field: cur_field,
}
}