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 support for core::ops::Bound #655

Merged
merged 1 commit into from
Oct 14, 2023
Merged

Add support for core::ops::Bound #655

merged 1 commit into from
Oct 14, 2023

Conversation

qsantos
Copy link
Contributor

@qsantos qsantos commented Oct 12, 2023

I have encountered a case where I would like to use Bound<Cow<'a, str>> and borrow the string from the deserialized buffer instead of copying. To use BorrowStr, I had to add support for core::ops::Bound to serde_with.

@codecov
Copy link

codecov bot commented Oct 12, 2023

Codecov Report

Merging #655 (e144133) into master (04bf8f3) will increase coverage by 0.17%.
Report is 4 commits behind head on master.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #655      +/-   ##
==========================================
+ Coverage   64.85%   65.03%   +0.17%     
==========================================
  Files          36       36              
  Lines        2177     2188      +11     
==========================================
+ Hits         1412     1423      +11     
  Misses        765      765              
Files Coverage Δ
serde_with/src/de/impls.rs 60.00% <100.00%> (+0.40%) ⬆️
serde_with/src/ser/impls.rs 92.00% <100.00%> (+0.33%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Bound::Excluded(ref v) => Bound::Excluded(SerializeAsWrap::<T, U>::new(v)),
}
.serialize(serializer)
/*
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove the commented code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that! Done.

fn test_bound() {
#[serde_as]
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct S(#[serde_as(as = "_")] Bound<u32>);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not test your code, but instead the already existing Serialize and Deserialize implementations for Bound. You want as = "Bound<_>".

Can you please add a test that converts the inner type somehow? For example Bound<DisplayFromStr>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not test your code, but instead the already existing Serialize and Deserialize implementations for Bound. You want as = "Bound<_>".

Oh, that makes sense! Done.

By the way, wouldn't it be the same with test_option then?

Can you please add a test that converts the inner type somehow? For example Bound<DisplayFromStr>.

Done.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. That test looks wrong too.

@jonasbb
Copy link
Owner

jonasbb commented Oct 13, 2023

Thanks for the PR. It makes sense to support Bounds. The code needs some updates, especially the tests. The trait implementations look OK.

@qsantos
Copy link
Contributor Author

qsantos commented Oct 14, 2023

Thanks for taking the time to review my changes. I have applied your suggestions.

@jonasbb
Copy link
Owner

jonasbb commented Oct 14, 2023

Thanks for the changes. It looks good now.
bors r+

@bors
Copy link
Contributor

bors bot commented Oct 14, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit e1657b4 into jonasbb:master Oct 14, 2023
22 checks passed
@qsantos qsantos deleted the add-bound branch October 15, 2023 17:33
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.

2 participants