feat(de): Support struct key hinting

Formats that do not provide type hints in the serialized format
(bincode, redis) rely on hinting in the deserializer. Struct key hinting
was not previously supported. This was not an issue in the past because
bincode serializes structs as a keyless sequence of values. However,
redis data is stored (key, value, key, value, ...), and the keys must be
deserialized to properly create a struct.

The default implementation of `visit_struct_key` is simply `visit` since
that was the previous method called in codegen.
This commit is contained in:
Joe Wilm 2016-01-28 08:38:07 -08:00
parent a5d0703e44
commit 6d25fc9dbb
2 changed files with 11 additions and 1 deletions

View File

@ -403,6 +403,16 @@ pub trait Deserializer {
self.visit_seq(visitor)
}
/// This method hints that the `Deserialize` type is expecting some sort of struct key mapping.
/// This allows deserializers to choose between &str, usize, or &[u8] to properly deserialize a
/// struct key.
#[inline]
fn visit_struct_key<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor,
{
self.visit(visitor)
}
/// Specify a format string for the deserializer.
///
/// The deserializer format is used to determine which format

View File

@ -917,7 +917,7 @@ fn deserialize_field_visitor(
}
}
deserializer.visit(__FieldVisitor::<D>{ phantom: PhantomData })
deserializer.visit_struct_key(__FieldVisitor::<D>{ phantom: PhantomData })
}
}
).unwrap();