-
-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deriving Decode with nested Cows #431
Comments
Ah, because This is the code that is generated: impl < '__de : 'a, 'a, A : Clone + Encode + Decode > bincode :: de ::
BorrowDecode < '__de > for U < 'a, A >
{
fn borrow_decode < D : bincode :: de :: BorrowDecoder < '__de > >
(mut decoder : D) -> core :: result :: Result < Self, bincode :: error ::
DecodeError >
{
Ok(Self
{
u : bincode :: de :: BorrowDecode ::
borrow_decode(& mut decoder) ?,
})
}
} However We've been considering making For now you can solve this by making a manual implementation of Decode for U: impl<'a, A: Clone + Encode + Decode> bincode::de::Decode for U<'a, A> {
fn decode<D: bincode::de::Decoder>(
mut decoder: D,
) -> core::result::Result<Self, bincode::error::DecodeError> {
Ok(Self {
u: bincode::de::Decode::decode(&mut decoder)?,
})
}
} |
Also In an ideal world we'd impl BorrowDecode for Cow<T> where T: BorrowDecode {
// return Cow::Borrowed
} and if T doesn't implement impl Decode for Cow<T> where <T as ToOwned>::Decode {
// return Cow::Owned
} But implementation specialization seems to be a long way from being stabilized |
Can you try #432 and see if that fixes your issue? I added tests/issues/issue_431.rs which contains your situation |
* split off BorrowDecode from Decode in bincode_derive * Added test case for issue #431 * Fixed Cow implementation having the wrong constraint, added BlockedTODO for cow implementation specialization * Re-exported the Decode and Encode traits in the crate root * Removed outdated comments * Removed some ::de::Decode that were introduced by the merge
I will give it a try tomorrow. |
It worked for me. Thanks! |
Hello
Apologies if this isn't the proper medium to ask this. I'm trying something similar to the code below:
which gives me the following error:
The code works if one of the
Cow
s is removed. Is it possible toderive(Decode)
in the nested case?The text was updated successfully, but these errors were encountered: