-
Notifications
You must be signed in to change notification settings - Fork 260
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
refactor!(client): replace the optional RequestConfig
arg to Client::send()
with a with_request_config()
builder method
#4443
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4443 +/- ##
==========================================
+ Coverage 85.42% 85.44% +0.02%
==========================================
Files 283 283
Lines 31556 31566 +10
==========================================
+ Hits 26958 26973 +15
+ Misses 4598 4593 -5 ☔ View full report in Codecov by Sentry. |
…t::send()` with a `with_request_config()` builder method Instead of `Client::send(request, request_config)`, consumers can now do `Client::send(request).with_request_config(request_config)`. The parameter is still `Option`al to avoid messy patterns, when the `request_config` is an `Option` passed from the caller. The messy pattern would look like this, if `with_request_config` took a `RequestConfig` and not an `Option<RequestConfig>`: ``` let mut send_req = client.send(req); if let Some(request_config) = request_config { send_req = send_req.with_request_config(request_config); } ```
8260578
to
c7b87f3
Compare
@@ -77,6 +77,13 @@ impl<R> SendRequest<R> { | |||
self | |||
} | |||
|
|||
/// Use the given [`RequestConfig`] for this send request, instead of the | |||
/// one provided by default. | |||
pub fn with_request_config(mut self, request_config: Option<RequestConfig>) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we take an option here? Not calling this is the same as passing None
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's to avoid the messy pattern described in OP and commit message. I was a bit torn about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do impl Into<Option<RequestConfig>>
so people can pass a RequestConfig
directly. There's no reason to ever call it with None
(as in, write that out in code such that the T
of Option::<T>::None
can't be inferred) so type inference should not be an issue.
Instead of
Client::send(request, request_config)
, consumers can now doClient::send(request).with_request_config(request_config)
. The parameter is stillOption
al to avoid messy patterns, when therequest_config
is anOption
passed from the caller.The messy pattern would look like this, if
with_request_config
took aRequestConfig
and not anOption<RequestConfig>
: