From dd19e2745ed20135e1e42a52bf3a27557bd97f67 Mon Sep 17 00:00:00 2001 From: onalante-msft <89409054+onalante-msft@users.noreply.github.com> Date: Fri, 8 Apr 2022 07:13:41 -0700 Subject: [PATCH] [main] Add must_use attributes to methods returning Self (#6268) Satisfy clippy. ## Azure IoT Edge PR checklist: --- mqtt/edgelet-client/src/workload/client.rs | 2 +- mqtt/edgelet-client/src/workload/models/cert_response.rs | 6 ++++++ mqtt/edgelet-client/src/workload/models/identity_cert.rs | 5 +++-- mqtt/edgelet-client/src/workload/models/server_cert.rs | 2 ++ mqtt/edgelet-client/src/workload/models/sign_request.rs | 4 ++++ mqtt/edgelet-client/src/workload/models/trust_bundle.rs | 1 + mqtt/mqtt-bridge/src/pump/builder.rs | 2 ++ mqtt/mqtt-broker-tests-util/src/client.rs | 5 +++++ mqtt/mqtt-broker/src/broker.rs | 2 ++ mqtt/mqtt-broker/src/persist.rs | 1 + mqtt/policy/src/core/builder.rs | 1 + 11 files changed, 28 insertions(+), 3 deletions(-) diff --git a/mqtt/edgelet-client/src/workload/client.rs b/mqtt/edgelet-client/src/workload/client.rs index bea47c7845f..cc021fdab99 100644 --- a/mqtt/edgelet-client/src/workload/client.rs +++ b/mqtt/edgelet-client/src/workload/client.rs @@ -74,7 +74,7 @@ impl WorkloadClient { let uri = make_hyper_uri(&self.scheme, &path).map_err(|e| ApiError::ConstructRequestUrl(e))?; - let req = SignRequest::new(base64::encode(data.to_string())); + let req = SignRequest::new(base64::encode(data)); self.post(uri, req, StatusCode::OK).await } diff --git a/mqtt/edgelet-client/src/workload/models/cert_response.rs b/mqtt/edgelet-client/src/workload/models/cert_response.rs index 61209753e5e..e556b9aada3 100644 --- a/mqtt/edgelet-client/src/workload/models/cert_response.rs +++ b/mqtt/edgelet-client/src/workload/models/cert_response.rs @@ -26,6 +26,7 @@ impl CertificateResponse { self.private_key = private_key; } + #[must_use] pub fn with_private_key(mut self, private_key: PrivateKey) -> Self { self.private_key = private_key; self @@ -39,6 +40,7 @@ impl CertificateResponse { self.certificate = certificate; } + #[must_use] pub fn with_certificate(mut self, certificate: String) -> Self { self.certificate = certificate; self @@ -52,6 +54,7 @@ impl CertificateResponse { self.expiration = expiration; } + #[must_use] pub fn with_expiration(mut self, expiration: String) -> Self { self.expiration = expiration; self @@ -90,6 +93,7 @@ impl PrivateKey { self.type_ = type_; } + #[must_use] pub fn with_type(mut self, type_: String) -> Self { self.type_ = type_; self @@ -103,6 +107,7 @@ impl PrivateKey { self.ref_ = Some(ref_); } + #[must_use] pub fn with_ref(mut self, ref_: String) -> Self { self.ref_ = Some(ref_); self @@ -120,6 +125,7 @@ impl PrivateKey { self.bytes = Some(bytes); } + #[must_use] pub fn with_bytes(mut self, bytes: String) -> Self { self.bytes = Some(bytes); self diff --git a/mqtt/edgelet-client/src/workload/models/identity_cert.rs b/mqtt/edgelet-client/src/workload/models/identity_cert.rs index 8ef44785e63..830b44b225c 100644 --- a/mqtt/edgelet-client/src/workload/models/identity_cert.rs +++ b/mqtt/edgelet-client/src/workload/models/identity_cert.rs @@ -8,7 +8,7 @@ pub struct IdentityCertificateRequest { } impl IdentityCertificateRequest { - pub fn new(expiration: Option) -> IdentityCertificateRequest { + pub fn new(expiration: Option) -> Self { IdentityCertificateRequest { expiration } } @@ -16,7 +16,8 @@ impl IdentityCertificateRequest { self.expiration = Some(expiration); } - pub fn with_expiration(mut self, expiration: String) -> IdentityCertificateRequest { + #[must_use] + pub fn with_expiration(mut self, expiration: String) -> Self { self.expiration = Some(expiration); self } diff --git a/mqtt/edgelet-client/src/workload/models/server_cert.rs b/mqtt/edgelet-client/src/workload/models/server_cert.rs index 7a3dce9a9cb..f7394b0bbe9 100644 --- a/mqtt/edgelet-client/src/workload/models/server_cert.rs +++ b/mqtt/edgelet-client/src/workload/models/server_cert.rs @@ -23,6 +23,7 @@ impl ServerCertificateRequest { self.common_name = common_name; } + #[must_use] pub fn with_common_name(mut self, common_name: String) -> Self { self.common_name = common_name; self @@ -36,6 +37,7 @@ impl ServerCertificateRequest { self.expiration = expiration; } + #[must_use] pub fn with_expiration(mut self, expiration: String) -> Self { self.expiration = expiration; self diff --git a/mqtt/edgelet-client/src/workload/models/sign_request.rs b/mqtt/edgelet-client/src/workload/models/sign_request.rs index c077c17f21d..1f53ed7c960 100644 --- a/mqtt/edgelet-client/src/workload/models/sign_request.rs +++ b/mqtt/edgelet-client/src/workload/models/sign_request.rs @@ -28,6 +28,7 @@ impl SignRequest { self.key_id = key_id; } + #[must_use] pub fn with_key_id(mut self, key_id: String) -> Self { self.key_id = key_id; self @@ -41,6 +42,7 @@ impl SignRequest { self.algorithm = algorithm; } + #[must_use] pub fn with_algorithm(mut self, algorithm: Algorithm) -> Self { self.algorithm = algorithm; self @@ -54,6 +56,7 @@ impl SignRequest { self.data = data; } + #[must_use] pub fn with_data(mut self, data: String) -> Self { self.data = data; self @@ -86,6 +89,7 @@ impl SignResponse { self.digest = digest; } + #[must_use] pub fn with_digest(mut self, digest: String) -> Self { self.digest = digest; self diff --git a/mqtt/edgelet-client/src/workload/models/trust_bundle.rs b/mqtt/edgelet-client/src/workload/models/trust_bundle.rs index eb16c797dfe..fe90ab9004c 100644 --- a/mqtt/edgelet-client/src/workload/models/trust_bundle.rs +++ b/mqtt/edgelet-client/src/workload/models/trust_bundle.rs @@ -16,6 +16,7 @@ impl TrustBundleResponse { self.certificate = certificate; } + #[must_use] pub fn with_certificate(mut self, certificate: String) -> Self { self.certificate = certificate; self diff --git a/mqtt/mqtt-bridge/src/pump/builder.rs b/mqtt/mqtt-bridge/src/pump/builder.rs index bac7fb1de00..124b52d72c6 100644 --- a/mqtt/mqtt-bridge/src/pump/builder.rs +++ b/mqtt/mqtt-bridge/src/pump/builder.rs @@ -56,6 +56,7 @@ where S: StreamWakeableState + Send, { /// Apples parameters to create local pump. + #[must_use] pub fn with_local(mut self, mut apply: F) -> Self where F: FnMut(&mut PumpBuilder), @@ -65,6 +66,7 @@ where } /// Applies parameters to create remote pump. + #[must_use] pub fn with_remote(mut self, mut apply: F) -> Self where F: FnMut(&mut PumpBuilder), diff --git a/mqtt/mqtt-broker-tests-util/src/client.rs b/mqtt/mqtt-broker-tests-util/src/client.rs index cdcb7f539ad..c31f2468088 100644 --- a/mqtt/mqtt-broker-tests-util/src/client.rs +++ b/mqtt/mqtt-broker-tests-util/src/client.rs @@ -167,26 +167,31 @@ where } } + #[must_use] pub fn with_client_id(mut self, client_id: ClientId) -> Self { self.client_id = client_id; self } + #[must_use] pub fn with_username(mut self, username: &str) -> Self { self.username = Some(username.into()); self } + #[must_use] pub fn with_password(mut self, password: &str) -> Self { self.password = Some(password.into()); self } + #[must_use] pub fn with_will(mut self, will: Publication) -> Self { self.will = Some(will); self } + #[must_use] pub fn with_keep_alive(mut self, keep_alive: Duration) -> Self { self.keep_alive = keep_alive; self diff --git a/mqtt/mqtt-broker/src/broker.rs b/mqtt/mqtt-broker/src/broker.rs index 8dab9b0fa0d..dd1084b7a06 100644 --- a/mqtt/mqtt-broker/src/broker.rs +++ b/mqtt/mqtt-broker/src/broker.rs @@ -1063,11 +1063,13 @@ where } } + #[must_use] pub fn with_state(mut self, state: BrokerSnapshot) -> Self { self.state = Some(state); self } + #[must_use] pub fn with_config(mut self, config: BrokerConfig) -> Self { self.config = config; self diff --git a/mqtt/mqtt-broker/src/persist.rs b/mqtt/mqtt-broker/src/persist.rs index 07f1cc5f022..f8f8e85834f 100644 --- a/mqtt/mqtt-broker/src/persist.rs +++ b/mqtt/mqtt-broker/src/persist.rs @@ -104,6 +104,7 @@ impl FilePersistor { /// The intent is to allow rollback to a pervious state. /// The default is `2`, which saves the current and previous state. /// The minimum value is `1` (the current state). + #[must_use] pub fn with_previous_count(mut self, previous_count: usize) -> Self { self.previous_count = cmp::max(1, previous_count); self diff --git a/mqtt/policy/src/core/builder.rs b/mqtt/policy/src/core/builder.rs index ebee89ca15e..322d59a7986 100644 --- a/mqtt/policy/src/core/builder.rs +++ b/mqtt/policy/src/core/builder.rs @@ -101,6 +101,7 @@ where /// Specifies the default decision that `Policy` will return if /// no rules match the request. + #[must_use] pub fn with_default_decision(mut self, decision: Decision) -> Self { self.default_decision = decision; self