Made the Cow Encode constraints more permissive (#524)

* Made the Cow Encode constraints more permissive

* Made Decode more permissive for Cow
This commit is contained in:
Trangar 2022-03-17 11:31:22 +01:00 committed by GitHub
parent 8eac3e9d4f
commit a7fba80e23
3 changed files with 15 additions and 2 deletions

View File

@ -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> {
@ -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)

View File

@ -20,3 +20,6 @@ mod issue_498;
#[path = "issues/issue_500.rs"]
mod issue_500;
#[path = "issues/issue_523.rs"]
mod issue_523;

View File

@ -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>);