Skip to content
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

Add BorrowCow type to force Cow to borrow str from the input #347

Merged
merged 9 commits into from
Aug 27, 2021
Merged

Conversation

jonasbb
Copy link
Owner

@jonasbb jonasbb commented Aug 24, 2021

TODOs:

  • Should serde_as automatically apply borrow?
  • Documentation
  • Changelog
  • Guide

@codecov
Copy link

codecov bot commented Aug 24, 2021

Codecov Report

Merging #347 (e0ea794) into master (67ce4af) will decrease coverage by 1.13%.
The diff coverage is 42.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #347      +/-   ##
==========================================
- Coverage   77.90%   76.77%   -1.14%     
==========================================
  Files          45       45              
  Lines        2616     2704      +88     
==========================================
+ Hits         2038     2076      +38     
- Misses        578      628      +50     
Impacted Files Coverage Δ
serde_with_macros/src/lib.rs 0.00% <0.00%> (ø)
src/lib.rs 75.00% <ø> (ø)
src/ser/const_arrays.rs 81.25% <0.00%> (-5.42%) ⬇️
src/de/const_arrays.rs 36.36% <50.00%> (-0.38%) ⬇️
src/de/impls.rs 73.73% <57.14%> (-1.15%) ⬇️
src/ser/impls.rs 93.63% <100.00%> (+0.24%) ⬆️
tests/serde_as/lib.rs 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 67ce4af...e0ea794. Read the comment docs.

This is a convenience feature and works since `BorrowCow` is only
implemented for types which can borrow from the input.

The behaviour can be prohibited, by providing a borrow annotation
manually. Duplicate annotations would lead to an error, so the macro
will not do that.
The borrow annotation could be wrong, if the field type has multiple
lifetime parameters, but not all should borrow.
This implementation differs from the `Bytes` implementation in that it
serializes the data as a sequence of u8 values, not as bytes.
The deserialization is identical, borrowing if possible, otherwise
creating an owned version.
`BorrowCow` only works as documented with the newest serde_with_macros
version. Already bump the version, such that it cannot be forgotten
later.
@jonasbb jonasbb marked this pull request as ready for review August 27, 2021 20:53
@jonasbb
Copy link
Owner Author

jonasbb commented Aug 27, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Aug 27, 2021

Build succeeded:

@bors bors bot merged commit 9d9ddb8 into master Aug 27, 2021
@bors bors bot deleted the borrowcow branch August 27, 2021 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant