From d92d7771d942182bb473ab0724bd49bbcfb87da4 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 27 Dec 2021 15:19:58 +0100 Subject: [PATCH] Add must_use attribute to config constructors and methods These all don't have side effects so discarding the result wouldn't make sense. --- crates/matrix-sdk-base/src/client.rs | 4 ++++ crates/matrix-sdk/src/config/client.rs | 10 ++++++++++ crates/matrix-sdk/src/config/request.rs | 7 +++++++ crates/matrix-sdk/src/config/sync.rs | 5 +++++ 4 files changed, 26 insertions(+) diff --git a/crates/matrix-sdk-base/src/client.rs b/crates/matrix-sdk-base/src/client.rs index f0998ebd8..f06179c2a 100644 --- a/crates/matrix-sdk-base/src/client.rs +++ b/crates/matrix-sdk-base/src/client.rs @@ -133,6 +133,7 @@ impl std::fmt::Debug for BaseClientConfig { impl BaseClientConfig { /// Create a new default `BaseClientConfig`. + #[must_use] pub fn new() -> Self { Default::default() } @@ -141,6 +142,7 @@ impl BaseClientConfig { /// /// The crypto store should be opened before being set. #[cfg(feature = "encryption")] + #[must_use] pub fn crypto_store(mut self, store: Box) -> Self { self.crypto_store = Some(store); self @@ -157,6 +159,7 @@ impl BaseClientConfig { /// implementations for the crypto store and the state store. It will use /// the given path to open the stores. If no path is provided no store will /// be opened + #[must_use] pub fn store_path>(mut self, path: P) -> Self { self.store_path = Some(path.as_ref().into()); self @@ -170,6 +173,7 @@ impl BaseClientConfig { /// the cryptostore. /// /// This is only used if no custom cryptostore is set. + #[must_use] pub fn passphrase(mut self, passphrase: String) -> Self { self.passphrase = Some(Zeroizing::new(passphrase)); self diff --git a/crates/matrix-sdk/src/config/client.rs b/crates/matrix-sdk/src/config/client.rs index 1c0260686..fbd761110 100644 --- a/crates/matrix-sdk/src/config/client.rs +++ b/crates/matrix-sdk/src/config/client.rs @@ -69,6 +69,7 @@ impl Debug for ClientConfig { impl ClientConfig { /// Create a new default `ClientConfig`. + #[must_use] pub fn new() -> Self { Default::default() } @@ -98,6 +99,7 @@ impl ClientConfig { } /// Disable SSL verification for the HTTP requests. + #[must_use] pub fn disable_ssl_verification(mut self) -> Self { self.disable_ssl_verification = true; self @@ -112,6 +114,7 @@ impl ClientConfig { ///// Set a custom implementation of a `StateStore`. ///// ///// The state store should be opened before being set. + //#[must_use] //pub fn state_store(mut self, store: Box) -> Self { // self.base_config = self.base_config.state_store(store); // self @@ -128,6 +131,7 @@ impl ClientConfig { /// implementations for the crypto store and the state store. It will use /// the given path to open the stores. If no path is provided no store will /// be opened + #[must_use] pub fn store_path(mut self, path: impl AsRef) -> Self { self.base_config = self.base_config.store_path(path); self @@ -141,12 +145,14 @@ impl ClientConfig { /// the cryptostore. /// /// This is only used if no custom cryptostore is set. + #[must_use] pub fn passphrase(mut self, passphrase: String) -> Self { self.base_config = self.base_config.passphrase(passphrase); self } /// Set the default timeout, fail and retry behavior for all HTTP requests. + #[must_use] pub fn request_config(mut self, request_config: RequestConfig) -> Self { self.request_config = request_config; self @@ -161,6 +167,7 @@ impl ClientConfig { /// /// Any type that implements the `HttpSend` trait can be used to /// send/receive `http` types. + #[must_use] pub fn client(mut self, client: Arc) -> Self { self.client = Some(client); self @@ -171,6 +178,7 @@ impl ClientConfig { /// This is low-level functionality. For an high-level API check the /// `matrix_sdk_appservice` crate. #[cfg(feature = "appservice")] + #[must_use] pub fn appservice_mode(mut self) -> Self { self.appservice_mode = true; self @@ -180,6 +188,7 @@ impl ClientConfig { /// /// The crypto store should be opened before being set. #[cfg(feature = "encryption")] + #[must_use] pub fn crypto_store( mut self, store: Box, @@ -190,6 +199,7 @@ impl ClientConfig { /// Update the client's homeserver URL with the discovery information /// present in the login response, if any. + #[must_use] pub fn use_discovery_response(mut self) -> Self { self.use_discovery_response = true; self diff --git a/crates/matrix-sdk/src/config/request.rs b/crates/matrix-sdk/src/config/request.rs index 690329537..e76476d62 100644 --- a/crates/matrix-sdk/src/config/request.rs +++ b/crates/matrix-sdk/src/config/request.rs @@ -72,24 +72,28 @@ impl Default for RequestConfig { impl RequestConfig { /// Create a new default `RequestConfig`. + #[must_use] pub fn new() -> Self { Default::default() } /// This is a convince method to disable the retries of a request. Setting /// the `retry_limit` to `0` has the same effect. + #[must_use] pub fn disable_retry(mut self) -> Self { self.retry_limit = Some(0); self } /// The number of times a request should be retried. The default is no limit + #[must_use] pub fn retry_limit(mut self, retry_limit: u64) -> Self { self.retry_limit = Some(retry_limit); self } /// Set the timeout duration for all HTTP requests. + #[must_use] pub fn timeout(mut self, timeout: Duration) -> Self { self.timeout = timeout; self @@ -97,6 +101,7 @@ impl RequestConfig { /// Set a timeout for how long a request should be retried. The default is /// no timeout, meaning requests are retried forever. + #[must_use] pub fn retry_timeout(mut self, retry_timeout: Duration) -> Self { self.retry_timeout = Some(retry_timeout); self @@ -104,6 +109,7 @@ impl RequestConfig { /// Force sending authorization even if the endpoint does not require it. /// Default is only sending authorization if it is required. + #[must_use] pub(crate) fn force_auth(mut self) -> Self { self.force_auth = true; self @@ -116,6 +122,7 @@ impl RequestConfig { /// /// [identity assertion]: https://spec.matrix.org/unstable/application-service-api/#identity-assertion #[cfg(feature = "appservice")] + #[must_use] pub fn assert_identity(mut self) -> Self { self.assert_identity = true; self diff --git a/crates/matrix-sdk/src/config/sync.rs b/crates/matrix-sdk/src/config/sync.rs index 939d250af..86187458b 100644 --- a/crates/matrix-sdk/src/config/sync.rs +++ b/crates/matrix-sdk/src/config/sync.rs @@ -40,6 +40,7 @@ impl<'a> Default for SyncSettings<'a> { impl<'a> SyncSettings<'a> { /// Create new default sync settings. + #[must_use] pub fn new() -> Self { Default::default() } @@ -49,6 +50,7 @@ impl<'a> SyncSettings<'a> { /// # Arguments /// /// * `token` - The sync token that should be used for the sync call. + #[must_use] pub fn token(mut self, token: impl Into) -> Self { self.token = Some(token.into()); self @@ -60,6 +62,7 @@ impl<'a> SyncSettings<'a> { /// # Arguments /// /// * `timeout` - The time the server is allowed to wait. + #[must_use] pub fn timeout(mut self, timeout: Duration) -> Self { self.timeout = Some(timeout); self @@ -72,6 +75,7 @@ impl<'a> SyncSettings<'a> { /// /// * `filter` - The filter configuration that should be used for the sync /// call. + #[must_use] pub fn filter(mut self, filter: sync_events::Filter<'a>) -> Self { self.filter = Some(filter); self @@ -84,6 +88,7 @@ impl<'a> SyncSettings<'a> { /// # Arguments /// * `full_state` - A boolean deciding if the server should return the full /// state or not. + #[must_use] pub fn full_state(mut self, full_state: bool) -> Self { self.full_state = full_state; self