Revert "Support deserialization of struct keys from integers"

This is not as useful as expected because the Serializer does not know the real
index of each struct field being serialized. The best it can do is keep a
counter, which goes wrong if fields are conditionally skipped.

This reverts commit eec7101894.
This commit is contained in:
David Tolnay 2017-06-18 09:11:21 -07:00
parent 75eed8cdde
commit 4fdba725fe
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 19 additions and 25 deletions

View File

@ -1386,21 +1386,26 @@ fn deserialize_identifier(
"field identifier"
};
let variant_indices = 0u32..;
let fallthrough_msg = format!("variant index 0 <= i < {}", fields.len());
let visit_index = quote! {
fn visit_u32<__E>(self, __value: u32) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error
{
match __value {
#(
#variant_indices => _serde::export::Ok(#constructors),
)*
_ => _serde::export::Err(_serde::de::Error::invalid_value(
_serde::de::Unexpected::Unsigned(__value as u64),
&#fallthrough_msg))
let visit_index = if is_variant {
let variant_indices = 0u32..;
let fallthrough_msg = format!("variant index 0 <= i < {}", fields.len());
let visit_index = quote! {
fn visit_u32<__E>(self, __value: u32) -> _serde::export::Result<Self::Value, __E>
where __E: _serde::de::Error
{
match __value {
#(
#variant_indices => _serde::export::Ok(#constructors),
)*
_ => _serde::export::Err(_serde::de::Error::invalid_value(
_serde::de::Unexpected::Unsigned(__value as u64),
&#fallthrough_msg))
}
}
}
};
Some(visit_index)
} else {
None
};
let bytes_to_str = if fallthrough.is_some() {

View File

@ -605,17 +605,6 @@ declare_tests! {
Token::StructEnd,
],
}
test_struct_integer_keys {
Struct { a: 1, b: 2, c: 0 } => &[
Token::Struct { name: "Struct", len: 2 },
Token::U32(0),
Token::I32(1),
Token::U32(1),
Token::I32(2),
Token::StructEnd,
],
}
test_enum_unit {
Enum::Unit => &[
Token::UnitVariant { name: "Enum", variant: "Unit" },