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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions bb8/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,11 @@
///
/// 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.

where
U: Into<Option<u32>>,
{
self.min_idle = min_idle.into();
self
}

Expand Down Expand Up @@ -194,7 +197,11 @@
///
/// Will panic if `max_lifetime` is 0.
#[must_use]
pub fn max_lifetime(mut self, max_lifetime: Option<Duration>) -> Self {
pub fn max_lifetime<D>(mut self, max_lifetime: D) -> Self
where
D: Into<Option<Duration>>,
{
let max_lifetime = max_lifetime.into();
assert_ne!(
max_lifetime,
Some(Duration::from_secs(0)),
Expand All @@ -215,7 +222,11 @@
///
/// Will panic if `idle_timeout` is 0.
#[must_use]
pub fn idle_timeout(mut self, idle_timeout: Option<Duration>) -> Self {
pub fn idle_timeout<D>(mut self, idle_timeout: D) -> Self
where
D: Into<Option<Duration>>,
{
let idle_timeout = idle_timeout.into();

Check warning on line 229 in bb8/src/api.rs

View check run for this annotation

Codecov / codecov/patch

bb8/src/api.rs#L225-L229

Added lines #L225 - L229 were not covered by tests
assert_ne!(
idle_timeout,
Some(Duration::from_secs(0)),
Expand Down
Loading