aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn-John Tedro <udoprog@tedro.se>2018-05-07 04:56:25 +0200
committerJohn-John Tedro <udoprog@tedro.se>2018-05-07 04:57:16 +0200
commit579cf491e6cca04b5e4cfe63f3132eed1f2a4e93 (patch)
treece0ac3d1dd8e9024d592382657dc6417e768516a
parent6c067202e061910d5018c4f96e9a7595c4291a08 (diff)
downloadmilf-rs-579cf491e6cca04b5e4cfe63f3132eed1f2a4e93.tar.gz
milf-rs-579cf491e6cca04b5e4cfe63f3132eed1f2a4e93.zip
Use BorrowedStrDeserializer instead of generated key deserializers
-rw-r--r--Cargo.toml1
-rw-r--r--src/de.rs7
-rw-r--r--src/lib.rs2
-rw-r--r--src/spanned.rs53
4 files changed, 7 insertions, 56 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 13b5beb..3518d6e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,7 +20,6 @@ travis-ci = { repository = "alexcrichton/toml-rs" }
[dependencies]
serde = "1.0"
-serde_derive = "1.0"
[dev-dependencies]
serde_json = "1.0"
diff --git a/src/de.rs b/src/de.rs
index 4e2b4b7..5521e00 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -12,6 +12,7 @@ use std::vec;
use serde::de;
use serde::de::IntoDeserializer;
+use serde::de::value::BorrowedStrDeserializer;
use tokens::{Tokenizer, Token, Error as TokenError, Span};
use datetime;
@@ -620,11 +621,11 @@ impl<'de> de::MapAccess<'de> for SpannedDeserializer<'de> {
K: de::DeserializeSeed<'de>,
{
if self.start.is_some() {
- seed.deserialize(spanned::START.into_deserializer()).map(Some)
+ seed.deserialize(BorrowedStrDeserializer::new(spanned::START)).map(Some)
} else if self.end.is_some() {
- seed.deserialize(spanned::END.into_deserializer()).map(Some)
+ seed.deserialize(BorrowedStrDeserializer::new(spanned::END)).map(Some)
} else if self.value.is_some() {
- seed.deserialize(spanned::VALUE.into_deserializer()).map(Some)
+ seed.deserialize(BorrowedStrDeserializer::new(spanned::VALUE)).map(Some)
} else {
Ok(None)
}
diff --git a/src/lib.rs b/src/lib.rs
index f42512f..b90612c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -153,8 +153,6 @@
#[macro_use]
extern crate serde;
-#[macro_use]
-extern crate serde_derive;
pub mod value;
#[doc(no_inline)]
diff --git a/src/spanned.rs b/src/spanned.rs
index 1673d66..8fbc529 100644
--- a/src/spanned.rs
+++ b/src/spanned.rs
@@ -32,43 +32,6 @@ pub const END: &'static str = "$__toml_private_end";
#[doc(hidden)]
pub const VALUE: &'static str = "$__toml_private_value";
-macro_rules! key_deserialize {
- ($ident:ident, $field:expr, $name:expr) => {
- struct $ident;
-
- impl<'de> de::Deserialize<'de> for $ident {
- fn deserialize<D>(deserializer: D) -> Result<$ident, D::Error>
- where D: de::Deserializer<'de>
- {
- struct FieldVisitor;
-
- impl<'de> de::Visitor<'de> for FieldVisitor {
- type Value = ();
-
- fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
- formatter.write_str("a valid spanned field")
- }
-
- fn visit_str<E>(self, s: &str) -> Result<(), E>
- where E: de::Error
- {
- if s == $field {
- Ok(())
- } else {
- Err(de::Error::custom(
- concat!("expected spanned field `", $name, "`")))
- }
- }
- }
-
- deserializer.deserialize_identifier(FieldVisitor)?;
- Ok($ident)
- }
- }
- }
-}
-
-
/// A spanned value, indicating the range at which it is defined in the source.
#[derive(Debug)]
pub struct Spanned<T> {
@@ -100,25 +63,19 @@ impl<'de, T> de::Deserialize<'de> for Spanned<T>
fn visit_map<V>(self, mut visitor: V) -> Result<Spanned<T>, V::Error>
where V: de::MapAccess<'de>
{
- let start = visitor.next_key::<StartKey>()?;
-
- if start.is_none() {
+ if visitor.next_key()? != Some(START) {
return Err(de::Error::custom("spanned start key not found"))
}
let start: usize = visitor.next_value()?;
- let end = visitor.next_key::<EndKey>()?;
-
- if end.is_none() {
+ if visitor.next_key()? != Some(END) {
return Err(de::Error::custom("spanned end key not found"))
}
let end: usize = visitor.next_value()?;
- let value = visitor.next_key::<ValueKey>()?;
-
- if value.is_none() {
+ if visitor.next_key()? != Some(VALUE) {
return Err(de::Error::custom("spanned value key not found"))
}
@@ -132,10 +89,6 @@ impl<'de, T> de::Deserialize<'de> for Spanned<T>
}
}
- key_deserialize!(StartKey, START, "start");
- key_deserialize!(EndKey, END, "end");
- key_deserialize!(ValueKey, VALUE, "value");
-
let visitor = SpannedVisitor(::std::marker::PhantomData);
static FIELDS: [&'static str; 3] = [START, END, VALUE];