mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-18 12:01:04 +00:00
Fix #[derive_deserialize] for deserializing empty sequences named units
This commit is contained in:
@@ -827,6 +827,15 @@ fn deserialize_struct_empty_fields(
|
|||||||
Err(::serde2::de::Error::syntax_error())
|
Err(::serde2::de::Error::syntax_error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_seq<V>(&mut self, mut visitor: V) -> Result<$type_ident, V::Error>
|
||||||
|
where V: de::SeqVisitor,
|
||||||
|
{
|
||||||
|
try!(visitor.end());
|
||||||
|
self.visit_unit()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$state.visit(__Visitor)
|
$state.visit(__Visitor)
|
||||||
|
|||||||
+1
-37
@@ -324,45 +324,9 @@ impl<'a, 'b> de::EnumVisitor for TokenDeserializerEnumVisitor<'a, 'b> {
|
|||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Copy, PartialEq, Debug)]
|
#[derive(Copy, PartialEq, Debug)]
|
||||||
|
#[derive_deserialize]
|
||||||
struct NamedUnit;
|
struct NamedUnit;
|
||||||
|
|
||||||
impl Deserialize for NamedUnit {
|
|
||||||
fn deserialize<D>(deserializer: &mut D) -> Result<NamedUnit, D::Error>
|
|
||||||
where D: Deserializer,
|
|
||||||
{
|
|
||||||
deserializer.visit(NamedUnitVisitor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct NamedUnitVisitor;
|
|
||||||
|
|
||||||
impl Visitor for NamedUnitVisitor {
|
|
||||||
type Value = NamedUnit;
|
|
||||||
|
|
||||||
fn visit_unit<E>(&mut self) -> Result<NamedUnit, E>
|
|
||||||
where E: de::Error,
|
|
||||||
{
|
|
||||||
Ok(NamedUnit)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_named_unit<E>(&mut self, name: &str) -> Result<NamedUnit, E>
|
|
||||||
where E: de::Error,
|
|
||||||
{
|
|
||||||
if name == "NamedUnit" {
|
|
||||||
Ok(NamedUnit)
|
|
||||||
} else {
|
|
||||||
Err(de::Error::syntax_error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_seq<V>(&mut self, mut visitor: V) -> Result<NamedUnit, V::Error>
|
|
||||||
where V: de::SeqVisitor,
|
|
||||||
{
|
|
||||||
try!(visitor.end());
|
|
||||||
Ok(NamedUnit)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
|
|||||||
Reference in New Issue
Block a user