Skip to content

Commit

Permalink
Made the Cow Encode constraints more permissive (#524)
Browse files Browse the repository at this point in the history
* Made the Cow Encode constraints more permissive

* Made Decode more permissive for Cow
  • Loading branch information
VictorKoenders authored Mar 17, 2022
1 parent 7ef6fe2 commit dadf335
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/features/impl_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ where

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

impl<'cow, T> Encode for Cow<'cow, T>
where
T: Encode + Clone,
T: ToOwned + ?Sized,
for<'a> &'a T: Encode,
{
fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError> {
self.as_ref().encode(encoder)
Expand Down
3 changes: 3 additions & 0 deletions tests/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ mod issue_498;

#[path = "issues/issue_500.rs"]
mod issue_500;

#[path = "issues/issue_523.rs"]
mod issue_523;
9 changes: 9 additions & 0 deletions tests/issues/issue_523.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![cfg(all(feature = "derive", feature = "std"))]

extern crate std;

use bincode::{Decode, Encode};
use std::borrow::Cow;

#[derive(Clone, Encode, Decode)]
pub struct Foo<'a>(Cow<'a, str>);

0 comments on commit dadf335

Please sign in to comment.