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

refactor!(client): replace the optional RequestConfig arg to Client::send() with a with_request_config() builder method #4443

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Dec 19, 2024

Instead of Client::send(request, request_config), consumers can now do Client::send(request).with_request_config(request_config). The parameter is still Optional 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);
}

@bnjbvr bnjbvr requested a review from a team as a code owner December 19, 2024 16:08
@bnjbvr bnjbvr requested review from poljar and removed request for a team December 19, 2024 16:08
Copy link

codecov bot commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 89.51613% with 13 lines in your changes missing coverage. Please review.

Project coverage is 85.44%. Comparing base (bc8c4f5) to head (c7b87f3).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/notification_settings/mod.rs 80.95% 4 Missing ⚠️
crates/matrix-sdk/src/encryption/mod.rs 83.33% 2 Missing ⚠️
crates/matrix-sdk/src/media.rs 77.77% 2 Missing ⚠️
crates/matrix-sdk/src/sliding_sync/mod.rs 66.66% 2 Missing ⚠️
crates/matrix-sdk/src/client/mod.rs 93.33% 1 Missing ⚠️
...ates/matrix-sdk/src/encryption/verification/sas.rs 0.00% 1 Missing ⚠️
crates/matrix-sdk/src/widget/matrix.rs 75.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

…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);
}
```
@bnjbvr bnjbvr force-pushed the bnjbvr/remove-config-from-clientsend branch from 8260578 to c7b87f3 Compare December 19, 2024 16:23
@@ -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 {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Collaborator

@jplatte jplatte Dec 19, 2024

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.

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.

3 participants