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

Switched to Into<Option<T>> for parameters in Builder #185

Merged
merged 2 commits into from
Jan 20, 2024

Conversation

fpagliughi
Copy link
Contributor

Hey, I know this is minor, but it seems so much nicer for optional parameters in a public API to take Into<Option<T>> rather than just taking Option<T>. That way the user can just send a value of T for Some<T>, and of course can still send None when desired.

Thus we could do:

Builder::new().min_idle(2)...

rather than

Builder::new().min_idle(Some(2))...

but, min_idle(Some(2)) and min_idle(None) still work, so it's all backward compatible.

Copy link
Owner

@djc djc left a comment

Choose a reason for hiding this comment

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

Seems nice, thanks!

bb8/src/api.rs Outdated
@@ -165,8 +165,11 @@ impl<M: ManageConnection> Builder<M> {
///
/// Defaults to None.
#[must_use]
pub fn min_idle(mut self, min_idle: Option<u32>) -> Self {
self.min_idle = min_idle;
pub fn min_idle<U>(mut self, min_idle: U) -> Self
Copy link
Owner

Choose a reason for hiding this comment

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

Nit: if we're going to do this, I'd like it spelled min_idle: impl Into<Option<u32>> (same for the others).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I had never done it like that, but actually that looks pretty good.

Copy link

codecov bot commented Jan 19, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (aa46db8) 72.05% compared to head (9997546) 71.97%.

Files Patch % Lines
bb8/src/api.rs 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #185      +/-   ##
==========================================
- Coverage   72.05%   71.97%   -0.08%     
==========================================
  Files           6        6              
  Lines         594      596       +2     
==========================================
+ Hits          428      429       +1     
- Misses        166      167       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@djc djc merged commit 6feafb9 into djc:main Jan 20, 2024
8 of 10 checks passed
@djc
Copy link
Owner

djc commented Jan 20, 2024

Thanks!

@fpagliughi fpagliughi deleted the builder-optional branch January 20, 2024 18:24
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