Allow #[serde(borrow)] for non-std Cow#1754
Merged
dtolnay merged 1 commit intoserde-rs:masterfrom Mar 18, 2020
maciejhirsz:non-std-cow-borrow
Merged
Allow #[serde(borrow)] for non-std Cow#1754dtolnay merged 1 commit intoserde-rs:masterfrom maciejhirsz:non-std-cow-borrow
dtolnay merged 1 commit intoserde-rs:masterfrom
maciejhirsz:non-std-cow-borrow
Conversation
Member
|
Published in 1.0.105. |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've written a custom
Cowimplementation that's meant to be (mostly) a drop-in replacement forstd::borrow::Cow.The
#[derive(Deserialize)]macro currently does specialization forCowby ident name when using#[serde(borrow)], which is smart, but it also means we get the false positives, as it is in this case:Will produce following compile error:
This PR modifies
serde::private::de::borrow_cow_*functions to return a generic typeRwith a boundR: From<std::borrow::Cow>. It would allow any custom type namedCowthat also implementsFrom<std::borrow::Cow<T>>(which it probably should) to be consistent withstd::borrow::Cowin deserializing behavior. This should obviously just add a no-op for stdCow.Breakage?
All the usage of the function within the derive macros should continue working since types will be always easily inferred. Given this function is not part of public documentation I reckon this should be fine even though it's technically a breaking change. Thoughts?