From 9b7fbd316a680fb0f1cad46af7c65eba80526318 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 25 Apr 2017 12:06:04 +0900 Subject: Remove everything other than enum variant code --- src/de.rs | 97 --------------------------------------------------------------- 1 file changed, 97 deletions(-) diff --git a/src/de.rs b/src/de.rs index 7e534f5..b29fc98 100644 --- a/src/de.rs +++ b/src/de.rs @@ -123,9 +123,7 @@ enum ErrorKind { Custom, /// TODO - ExpectedMapEnd, ExpectedEnum, - ExpectedMapColon, ExpectedString, #[doc(hidden)] @@ -216,15 +214,6 @@ impl<'de, 'b> de::Deserializer<'de> for &'b mut Deserializer<'de> { }, _ => Err(Error::from_kind(ErrorKind::ExpectedString)) } - } else if self.next_char()? == '{' { - // Visit a newtype variant, tuple variant, or struct variant. - let value = visitor.visit_enum(Enum::new(self))?; - // Parse the matching close brace. - if self.next_char()? == '}' { - Ok(value) - } else { - Err(Error::from_kind(ErrorKind::ExpectedMapEnd)) - } } else { Err(Error::from_kind(ErrorKind::ExpectedEnum)) } @@ -613,82 +602,6 @@ impl<'de> de::MapAccess<'de> for InlineTableDeserializer<'de> { } } -struct Enum<'a, 'de: 'a> { - de: &'a mut Deserializer<'de>, -} - -impl<'a, 'de> Enum<'a, 'de> { - fn new(de: &'a mut Deserializer<'de>) -> Self { - Enum { de: de } - } -} - -// `EnumAccess` is provided to the `Visitor` to give it the ability to determine -// which variant of the enum is supposed to be deserialized. -// -// Note that all enum deserialization methods in Serde refer exclusively to the -// "externally tagged" enum representation. -impl<'de, 'a> de::EnumAccess<'de> for Enum<'a, 'de> { - type Error = Error; - type Variant = Self; - - fn variant_seed(self, seed: V) -> Result<(V::Value, Self::Variant), Error> - where V: de::DeserializeSeed<'de> - { - // The `deserialize_enum` method parsed a `{` character so we are - // currently inside of a map. The seed will be deserializing itself from - // the key of the map. - let val = seed.deserialize(&mut *self.de)?; - // Parse the colon separating map key from value. - if self.de.next_char()? == ':' { - Ok((val, self)) - } else { - Err(Error::from_kind(ErrorKind::ExpectedMapColon)) - } - } -} - -// `VariantAccess` is provided to the `Visitor` to give it the ability to see -// the content of the single variant that it decided to deserialize. -impl<'de, 'a> de::VariantAccess<'de> for Enum<'a, 'de> { - type Error = Error; - - // If the `Visitor` expected this variant to be a unit variant, the input - // should have been the plain string case handled in `deserialize_enum`. - fn unit_variant(self) -> Result<(), Error> { - Err(Error::from_kind(ErrorKind::ExpectedString)) - } - - // Newtype variants are represented in JSON as `{ NAME: VALUE }` so - // deserialize the value here. - fn newtype_variant_seed(self, seed: T) -> Result - where T: de::DeserializeSeed<'de> - { - seed.deserialize(self.de) - } - - // Tuple variants are represented in JSON as `{ NAME: [DATA...] }` so - // deserialize the sequence of data here. - fn tuple_variant(self, _len: usize, visitor: V) -> Result - where V: de::Visitor<'de> - { - de::Deserializer::deserialize_seq(self.de, visitor) - } - - // Struct variants are represented in JSON as `{ NAME: { K: V, ... } }` so - // deserialize the inner map here. - fn struct_variant( - self, - _fields: &'static [&'static str], - visitor: V, - ) -> Result - where V: de::Visitor<'de> - { - de::Deserializer::deserialize_map(self.de, visitor) - } -} - - impl<'a> Deserializer<'a> { /// Creates a new deserializer which will be deserializing the string /// provided. @@ -1078,12 +991,6 @@ impl<'a> Deserializer<'a> { self.input.chars().next().ok_or(Error::from_kind(ErrorKind::UnexpectedEof)) } - fn next_char(&mut self) -> Result { - let ch = self.peek_char()?; - self.input = &self.input[ch.len_utf8()..]; - Ok(ch) - } - fn eof(&self) -> Error { self.error(self.input.len(), ErrorKind::UnexpectedEof) } @@ -1217,9 +1124,7 @@ impl fmt::Display for Error { ErrorKind::RedefineAsArray => "table redefined as array".fmt(f)?, ErrorKind::EmptyTableKey => "empty table key found".fmt(f)?, ErrorKind::Custom => self.inner.message.fmt(f)?, - ErrorKind::ExpectedMapEnd => "expected end of map".fmt(f)?, ErrorKind::ExpectedEnum => "expected enum".fmt(f)?, - ErrorKind::ExpectedMapColon => "expected map colon".fmt(f)?, ErrorKind::ExpectedString => "expected string".fmt(f)?, ErrorKind::__Nonexhaustive => panic!(), } @@ -1263,9 +1168,7 @@ impl error::Error for Error { ErrorKind::RedefineAsArray => "table redefined as array", ErrorKind::EmptyTableKey => "empty table key found", ErrorKind::Custom => "a custom error", - ErrorKind::ExpectedMapEnd => "expected end of map", ErrorKind::ExpectedEnum => "expected enum", - ErrorKind::ExpectedMapColon => "expected map colon", ErrorKind::ExpectedString => "expected string", ErrorKind::__Nonexhaustive => panic!(), } -- cgit v1.2.3