Allow #[serde(borrow)] for non-std Cow #1754
Merged
+6
−4
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
Cow
implementation that's meant to be (mostly) a drop-in replacement forstd::borrow::Cow
.The
#[derive(Deserialize)]
macro currently does specialization forCow
by 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 typeR
with a boundR: From<std::borrow::Cow>
. It would allow any custom type namedCow
that also implementsFrom<std::borrow::Cow<T>>
(which it probably should) to be consistent withstd::borrow::Cow
in 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?