From 8023de47d0c134f928e8cbc76287719734e0b97c Mon Sep 17 00:00:00 2001 From: Johannes Barthel Date: Thu, 5 Sep 2024 13:04:45 +0200 Subject: [PATCH 1/2] fix deserializing Option::Some --- src/xmlfmt/de.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/xmlfmt/de.rs b/src/xmlfmt/de.rs index 2dddd8e..f9180e7 100644 --- a/src/xmlfmt/de.rs +++ b/src/xmlfmt/de.rs @@ -232,20 +232,25 @@ impl<'de> serde::Deserializer<'de> for Value { where V: Visitor<'de>, { - if let Value::Array(mut v) = self { - let v1 = v.pop(); - if !v.is_empty() { - return Err(serde::de::Error::invalid_value( - Unexpected::Seq, - &"array with a single element", - )); - } - match v1 { - Some(x) => visitor.visit_some(x), - None => visitor.visit_none(), + match self { + Value::Array(mut v) => { + let v1 = v.pop(); + if !v.is_empty() { + return Err(serde::de::Error::invalid_value( + Unexpected::Seq, + &"array with a single element", + )); + } + match v1 { + Some(x) => visitor.visit_some(x), + None => visitor.visit_none(), + } + }, + + v => { + visitor.visit_some(v) + //Err(serde::de::Error::invalid_value(self.unexpected(), &visitor)) } - } else { - Err(serde::de::Error::invalid_value(self.unexpected(), &visitor)) } } From ccce9354e3056db5f1b09f42a82a02c91f0b0a43 Mon Sep 17 00:00:00 2001 From: Johannes Barthel Date: Thu, 5 Sep 2024 13:08:21 +0200 Subject: [PATCH 2/2] remove commented line --- src/xmlfmt/de.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/xmlfmt/de.rs b/src/xmlfmt/de.rs index f9180e7..3794054 100644 --- a/src/xmlfmt/de.rs +++ b/src/xmlfmt/de.rs @@ -249,7 +249,6 @@ impl<'de> serde::Deserializer<'de> for Value { v => { visitor.visit_some(v) - //Err(serde::de::Error::invalid_value(self.unexpected(), &visitor)) } } }