Merge pull request #1754 from maciejhirsz/non-std-cow-borrow

Allow #[serde(borrow)] for non-std Cow
This commit is contained in:
David Tolnay 2020-03-18 11:40:35 -07:00 committed by GitHub
commit c33fb95127
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,9 +53,10 @@ where
} }
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(any(feature = "std", feature = "alloc"))]
pub fn borrow_cow_str<'de: 'a, 'a, D>(deserializer: D) -> Result<Cow<'a, str>, D::Error> pub fn borrow_cow_str<'de: 'a, 'a, D, R>(deserializer: D) -> Result<R, D::Error>
where where
D: Deserializer<'de>, D: Deserializer<'de>,
R: From<Cow<'a, str>>,
{ {
struct CowStrVisitor; struct CowStrVisitor;
@ -121,13 +122,14 @@ where
} }
} }
deserializer.deserialize_str(CowStrVisitor) deserializer.deserialize_str(CowStrVisitor).map(From::from)
} }
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(any(feature = "std", feature = "alloc"))]
pub fn borrow_cow_bytes<'de: 'a, 'a, D>(deserializer: D) -> Result<Cow<'a, [u8]>, D::Error> pub fn borrow_cow_bytes<'de: 'a, 'a, D, R>(deserializer: D) -> Result<R, D::Error>
where where
D: Deserializer<'de>, D: Deserializer<'de>,
R: From<Cow<'a, [u8]>>,
{ {
struct CowBytesVisitor; struct CowBytesVisitor;
@ -181,7 +183,7 @@ where
} }
} }
deserializer.deserialize_bytes(CowBytesVisitor) deserializer.deserialize_bytes(CowBytesVisitor).map(From::from)
} }
pub mod size_hint { pub mod size_hint {