Support Option in from_dynamic.

This commit is contained in:
Stephen Chung
2021-12-02 12:50:11 +08:00
parent 5003d836d9
commit 5363b0724f
3 changed files with 43 additions and 2 deletions

View File

@@ -365,8 +365,15 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
self.type_error()
}
fn deserialize_option<V: Visitor<'de>>(self, _: V) -> Result<V::Value, Box<EvalAltResult>> {
self.type_error()
fn deserialize_option<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Box<EvalAltResult>> {
if self.value.is::<()>() {
visitor.visit_none()
} else {
visitor.visit_some(self)
}
}
fn deserialize_unit<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Box<EvalAltResult>> {