Skip to content

Commit d92d777

Browse files
committed
Add must_use attribute to config constructors and methods
These all don't have side effects so discarding the result wouldn't make sense.
1 parent f6d7933 commit d92d777

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

crates/matrix-sdk-base/src/client.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ impl std::fmt::Debug for BaseClientConfig {
133133

134134
impl BaseClientConfig {
135135
/// Create a new default `BaseClientConfig`.
136+
#[must_use]
136137
pub fn new() -> Self {
137138
Default::default()
138139
}
@@ -141,6 +142,7 @@ impl BaseClientConfig {
141142
///
142143
/// The crypto store should be opened before being set.
143144
#[cfg(feature = "encryption")]
145+
#[must_use]
144146
pub fn crypto_store(mut self, store: Box<dyn CryptoStore>) -> Self {
145147
self.crypto_store = Some(store);
146148
self
@@ -157,6 +159,7 @@ impl BaseClientConfig {
157159
/// implementations for the crypto store and the state store. It will use
158160
/// the given path to open the stores. If no path is provided no store will
159161
/// be opened
162+
#[must_use]
160163
pub fn store_path<P: AsRef<Path>>(mut self, path: P) -> Self {
161164
self.store_path = Some(path.as_ref().into());
162165
self
@@ -170,6 +173,7 @@ impl BaseClientConfig {
170173
/// the cryptostore.
171174
///
172175
/// This is only used if no custom cryptostore is set.
176+
#[must_use]
173177
pub fn passphrase(mut self, passphrase: String) -> Self {
174178
self.passphrase = Some(Zeroizing::new(passphrase));
175179
self

crates/matrix-sdk/src/config/client.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl Debug for ClientConfig {
6969

7070
impl ClientConfig {
7171
/// Create a new default `ClientConfig`.
72+
#[must_use]
7273
pub fn new() -> Self {
7374
Default::default()
7475
}
@@ -98,6 +99,7 @@ impl ClientConfig {
9899
}
99100

100101
/// Disable SSL verification for the HTTP requests.
102+
#[must_use]
101103
pub fn disable_ssl_verification(mut self) -> Self {
102104
self.disable_ssl_verification = true;
103105
self
@@ -112,6 +114,7 @@ impl ClientConfig {
112114
///// Set a custom implementation of a `StateStore`.
113115
/////
114116
///// The state store should be opened before being set.
117+
//#[must_use]
115118
//pub fn state_store(mut self, store: Box<dyn StateStore>) -> Self {
116119
// self.base_config = self.base_config.state_store(store);
117120
// self
@@ -128,6 +131,7 @@ impl ClientConfig {
128131
/// implementations for the crypto store and the state store. It will use
129132
/// the given path to open the stores. If no path is provided no store will
130133
/// be opened
134+
#[must_use]
131135
pub fn store_path(mut self, path: impl AsRef<Path>) -> Self {
132136
self.base_config = self.base_config.store_path(path);
133137
self
@@ -141,12 +145,14 @@ impl ClientConfig {
141145
/// the cryptostore.
142146
///
143147
/// This is only used if no custom cryptostore is set.
148+
#[must_use]
144149
pub fn passphrase(mut self, passphrase: String) -> Self {
145150
self.base_config = self.base_config.passphrase(passphrase);
146151
self
147152
}
148153

149154
/// Set the default timeout, fail and retry behavior for all HTTP requests.
155+
#[must_use]
150156
pub fn request_config(mut self, request_config: RequestConfig) -> Self {
151157
self.request_config = request_config;
152158
self
@@ -161,6 +167,7 @@ impl ClientConfig {
161167
///
162168
/// Any type that implements the `HttpSend` trait can be used to
163169
/// send/receive `http` types.
170+
#[must_use]
164171
pub fn client(mut self, client: Arc<dyn HttpSend>) -> Self {
165172
self.client = Some(client);
166173
self
@@ -171,6 +178,7 @@ impl ClientConfig {
171178
/// This is low-level functionality. For an high-level API check the
172179
/// `matrix_sdk_appservice` crate.
173180
#[cfg(feature = "appservice")]
181+
#[must_use]
174182
pub fn appservice_mode(mut self) -> Self {
175183
self.appservice_mode = true;
176184
self
@@ -180,6 +188,7 @@ impl ClientConfig {
180188
///
181189
/// The crypto store should be opened before being set.
182190
#[cfg(feature = "encryption")]
191+
#[must_use]
183192
pub fn crypto_store(
184193
mut self,
185194
store: Box<dyn matrix_sdk_base::crypto::store::CryptoStore>,
@@ -190,6 +199,7 @@ impl ClientConfig {
190199

191200
/// Update the client's homeserver URL with the discovery information
192201
/// present in the login response, if any.
202+
#[must_use]
193203
pub fn use_discovery_response(mut self) -> Self {
194204
self.use_discovery_response = true;
195205
self

crates/matrix-sdk/src/config/request.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,38 +72,44 @@ impl Default for RequestConfig {
7272

7373
impl RequestConfig {
7474
/// Create a new default `RequestConfig`.
75+
#[must_use]
7576
pub fn new() -> Self {
7677
Default::default()
7778
}
7879

7980
/// This is a convince method to disable the retries of a request. Setting
8081
/// the `retry_limit` to `0` has the same effect.
82+
#[must_use]
8183
pub fn disable_retry(mut self) -> Self {
8284
self.retry_limit = Some(0);
8385
self
8486
}
8587

8688
/// The number of times a request should be retried. The default is no limit
89+
#[must_use]
8790
pub fn retry_limit(mut self, retry_limit: u64) -> Self {
8891
self.retry_limit = Some(retry_limit);
8992
self
9093
}
9194

9295
/// Set the timeout duration for all HTTP requests.
96+
#[must_use]
9397
pub fn timeout(mut self, timeout: Duration) -> Self {
9498
self.timeout = timeout;
9599
self
96100
}
97101

98102
/// Set a timeout for how long a request should be retried. The default is
99103
/// no timeout, meaning requests are retried forever.
104+
#[must_use]
100105
pub fn retry_timeout(mut self, retry_timeout: Duration) -> Self {
101106
self.retry_timeout = Some(retry_timeout);
102107
self
103108
}
104109

105110
/// Force sending authorization even if the endpoint does not require it.
106111
/// Default is only sending authorization if it is required.
112+
#[must_use]
107113
pub(crate) fn force_auth(mut self) -> Self {
108114
self.force_auth = true;
109115
self
@@ -116,6 +122,7 @@ impl RequestConfig {
116122
///
117123
/// [identity assertion]: https://spec.matrix.org/unstable/application-service-api/#identity-assertion
118124
#[cfg(feature = "appservice")]
125+
#[must_use]
119126
pub fn assert_identity(mut self) -> Self {
120127
self.assert_identity = true;
121128
self

crates/matrix-sdk/src/config/sync.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl<'a> Default for SyncSettings<'a> {
4040

4141
impl<'a> SyncSettings<'a> {
4242
/// Create new default sync settings.
43+
#[must_use]
4344
pub fn new() -> Self {
4445
Default::default()
4546
}
@@ -49,6 +50,7 @@ impl<'a> SyncSettings<'a> {
4950
/// # Arguments
5051
///
5152
/// * `token` - The sync token that should be used for the sync call.
53+
#[must_use]
5254
pub fn token(mut self, token: impl Into<String>) -> Self {
5355
self.token = Some(token.into());
5456
self
@@ -60,6 +62,7 @@ impl<'a> SyncSettings<'a> {
6062
/// # Arguments
6163
///
6264
/// * `timeout` - The time the server is allowed to wait.
65+
#[must_use]
6366
pub fn timeout(mut self, timeout: Duration) -> Self {
6467
self.timeout = Some(timeout);
6568
self
@@ -72,6 +75,7 @@ impl<'a> SyncSettings<'a> {
7275
///
7376
/// * `filter` - The filter configuration that should be used for the sync
7477
/// call.
78+
#[must_use]
7579
pub fn filter(mut self, filter: sync_events::Filter<'a>) -> Self {
7680
self.filter = Some(filter);
7781
self
@@ -84,6 +88,7 @@ impl<'a> SyncSettings<'a> {
8488
/// # Arguments
8589
/// * `full_state` - A boolean deciding if the server should return the full
8690
/// state or not.
91+
#[must_use]
8792
pub fn full_state(mut self, full_state: bool) -> Self {
8893
self.full_state = full_state;
8994
self

0 commit comments

Comments
 (0)