Skip to content

Commit c33fb95

Browse files
authored
Merge pull request #1754 from maciejhirsz/non-std-cow-borrow
Allow #[serde(borrow)] for non-std Cow
2 parents 078e88b + ec6ca6b commit c33fb95

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

serde/src/private/de.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ where
5353
}
5454

5555
#[cfg(any(feature = "std", feature = "alloc"))]
56-
pub fn borrow_cow_str<'de: 'a, 'a, D>(deserializer: D) -> Result<Cow<'a, str>, D::Error>
56+
pub fn borrow_cow_str<'de: 'a, 'a, D, R>(deserializer: D) -> Result<R, D::Error>
5757
where
5858
D: Deserializer<'de>,
59+
R: From<Cow<'a, str>>,
5960
{
6061
struct CowStrVisitor;
6162

@@ -121,13 +122,14 @@ where
121122
}
122123
}
123124

124-
deserializer.deserialize_str(CowStrVisitor)
125+
deserializer.deserialize_str(CowStrVisitor).map(From::from)
125126
}
126127

127128
#[cfg(any(feature = "std", feature = "alloc"))]
128-
pub fn borrow_cow_bytes<'de: 'a, 'a, D>(deserializer: D) -> Result<Cow<'a, [u8]>, D::Error>
129+
pub fn borrow_cow_bytes<'de: 'a, 'a, D, R>(deserializer: D) -> Result<R, D::Error>
129130
where
130131
D: Deserializer<'de>,
132+
R: From<Cow<'a, [u8]>>,
131133
{
132134
struct CowBytesVisitor;
133135

@@ -181,7 +183,7 @@ where
181183
}
182184
}
183185

184-
deserializer.deserialize_bytes(CowBytesVisitor)
186+
deserializer.deserialize_bytes(CowBytesVisitor).map(From::from)
185187
}
186188

187189
pub mod size_hint {

0 commit comments

Comments
 (0)