diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index c7ea2ede..494540b0 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -485,7 +485,6 @@ forwarded_impl!((), Box, CString::into_boxed_c_str); struct OptionVisitor { marker: PhantomData, } -struct OptionFromVisitor<'a, T: 'a>(&'a mut Option); impl<'de, T> Visitor<'de> for OptionVisitor where @@ -522,49 +521,6 @@ where } } -impl<'a, 'de, T> Visitor<'de> for OptionFromVisitor<'a, T> -where - T: Deserialize<'de>, -{ - type Value = (); - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("option") - } - - #[inline] - fn visit_unit(self) -> Result<(), E> - where - E: Error, - { - *self.0 = None; - Ok(()) - } - - #[inline] - fn visit_none(self) -> Result<(), E> - where - E: Error, - { - *self.0 = None; - Ok(()) - } - - #[inline] - fn visit_some(self, deserializer: D) -> Result<(), D::Error> - where - D: Deserializer<'de>, - { - // The some enum's repr is opaque, so we can't play cute tricks with - // its tag to build this in place unconditionally. - // - // FIXME: investigate whether branching on the old value being Some to - // deserialize_from the value is profitable (probably data-dependent?) - *self.0 = try!(T::deserialize(deserializer).map(Some)); - Ok(()) - } -} - impl<'de, T> Deserialize<'de> for Option where T: Deserialize<'de>, @@ -576,12 +532,11 @@ where deserializer.deserialize_option(OptionVisitor { marker: PhantomData }) } - fn deserialize_from(&mut self, deserializer: D) -> Result<(), D::Error> - where - D: Deserializer<'de>, - { - deserializer.deserialize_option(OptionFromVisitor(self)) - } + // The Some variant's repr is opaque, so we can't play cute tricks with its + // tag to have deserialize_from build the content in place unconditionally. + // + // FIXME: investigate whether branching on the old value being Some to + // deserialize_from the value is profitable (probably data-dependent?) } ////////////////////////////////////////////////////////////////////////////////