Skip to content

Commit dadf335

Browse files
Made the Cow Encode constraints more permissive (#524)
* Made the Cow Encode constraints more permissive * Made Decode more permissive for Cow
1 parent 7ef6fe2 commit dadf335

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/features/impl_alloc.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ where
285285

286286
impl<'cow, T> Decode for Cow<'cow, T>
287287
where
288-
T: ToOwned,
288+
T: ToOwned + ?Sized,
289289
<T as ToOwned>::Owned: Decode,
290290
{
291291
fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError> {
@@ -296,7 +296,8 @@ where
296296

297297
impl<'cow, T> Encode for Cow<'cow, T>
298298
where
299-
T: Encode + Clone,
299+
T: ToOwned + ?Sized,
300+
for<'a> &'a T: Encode,
300301
{
301302
fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError> {
302303
self.as_ref().encode(encoder)

tests/issues.rs

+3
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ mod issue_498;
2020

2121
#[path = "issues/issue_500.rs"]
2222
mod issue_500;
23+
24+
#[path = "issues/issue_523.rs"]
25+
mod issue_523;

tests/issues/issue_523.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![cfg(all(feature = "derive", feature = "std"))]
2+
3+
extern crate std;
4+
5+
use bincode::{Decode, Encode};
6+
use std::borrow::Cow;
7+
8+
#[derive(Clone, Encode, Decode)]
9+
pub struct Foo<'a>(Cow<'a, str>);

0 commit comments

Comments
 (0)