ID deserialization: Borrow from the deserializer if possible

… by using Cow<'_, str> instead of String
This commit is contained in:
Jonas Platte 2019-12-15 20:40:51 +01:00
parent 2a0414cd60
commit 7d3cfd769e
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -15,6 +15,7 @@
extern crate diesel;
use std::{
borrow::Cow,
convert::TryFrom,
fmt::{Formatter, Result as FmtResult},
};
@ -125,7 +126,7 @@ where
D: Deserializer<'de>,
T: for<'a> TryFrom<&'a str>,
{
String::deserialize(deserializer).and_then(|v| {
Cow::<'_, str>::deserialize(deserializer).and_then(|v| {
T::try_from(&v).map_err(|_| de::Error::invalid_value(Unexpected::Str(&v), &expected_str))
})
}