Provide optimized collect_str methods for Value serializer

This commit is contained in:
David Tolnay 2020-03-27 23:00:55 -07:00
parent f59b637295
commit da0a39fff7
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -267,6 +267,13 @@ impl serde::Serializer for Serializer {
map: Map::new(),
})
}
fn collect_str<T: ?Sized>(self, value: &T) -> Result<Value>
where
T: Display,
{
Ok(Value::String(value.to_string()))
}
}
pub struct SerializeVec {
@ -593,6 +600,13 @@ impl serde::Serializer for MapKeySerializer {
) -> Result<Self::SerializeStructVariant> {
Err(key_must_be_a_string())
}
fn collect_str<T: ?Sized>(self, value: &T) -> Result<String>
where
T: Display,
{
Ok(value.to_string())
}
}
impl serde::ser::SerializeStruct for SerializeMap {