Add must_use attribute to config constructors and methods

These all don't have side effects so discarding the result wouldn't make
sense.
This commit is contained in:
Jonas Platte
2021-12-27 15:19:58 +01:00
parent f6d7933601
commit d92d7771d9
4 changed files with 26 additions and 0 deletions
+4
View File
@@ -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<dyn CryptoStore>) -> 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<P: AsRef<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
+10
View File
@@ -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<dyn StateStore>) -> 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<Path>) -> 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<dyn HttpSend>) -> 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<dyn matrix_sdk_base::crypto::store::CryptoStore>,
@@ -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
+7
View File
@@ -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
+5
View File
@@ -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<String>) -> 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