]> git.lizzy.rs Git - rust.git/commitdiff
Simplifications
authorest31 <MTest31@outlook.com>
Wed, 3 May 2017 15:11:34 +0000 (17:11 +0200)
committerest31 <MTest31@outlook.com>
Wed, 3 May 2017 15:11:34 +0000 (17:11 +0200)
src/utils.rs

index 8648b8f2f579b5e6f5d9450ada60b61343b79724..d177e01b42b41502b92593a15d12b5d199194a96 100644 (file)
@@ -195,15 +195,14 @@ macro_rules! impl_enum_decodable {
     ( $e:ident, $( $x:ident ),* ) => {
         impl<'de> ::serde::de::Deserialize<'de> for $e {
             fn deserialize<D>(d: D) -> Result<Self, D::Error>
-                    where D: ::serde::de::Deserializer<'de> {
+                    where D: ::serde::Deserializer<'de> {
                 use std::ascii::AsciiExt;
-                use serde::{Deserializer};
                 use serde::de::{Error, Visitor};
                 use std::marker::PhantomData;
                 use std::fmt;
                 struct StringOnly<T>(PhantomData<T>);
                 impl<'de, T> Visitor<'de> for StringOnly<T>
-                        where T: Deserializer<'de> {
+                        where T: ::serde::Deserializer<'de> {
                     type Value = String;
                     fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
                         formatter.write_str("string")
@@ -218,7 +217,8 @@ fn visit_str<E>(self, value :&str) -> Result<String, E> {
                       return Ok($e::$x);
                     }
                 )*
-                Err(<D as Deserializer<'de>>::Error::custom("Bad variant"))
+                static ALLOWED: &'static[&str] = &[$(stringify!($x),)*];
+                Err(D::Error::unknown_variant(&s, ALLOWED))
             }
         }