Skip to content

Commit

Permalink
[main] Add must_use attributes to methods returning Self (Azure#6268)
Browse files Browse the repository at this point in the history
Satisfy clippy.

## Azure IoT Edge PR checklist:
  • Loading branch information
onalante-msft authored Apr 8, 2022
1 parent 519769b commit e047407
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mqtt/edgelet-client/src/workload/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions mqtt/edgelet-client/src/workload/models/cert_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,6 +40,7 @@ impl CertificateResponse {
self.certificate = certificate;
}

#[must_use]
pub fn with_certificate(mut self, certificate: String) -> Self {
self.certificate = certificate;
self
Expand All @@ -52,6 +54,7 @@ impl CertificateResponse {
self.expiration = expiration;
}

#[must_use]
pub fn with_expiration(mut self, expiration: String) -> Self {
self.expiration = expiration;
self
Expand Down Expand Up @@ -90,6 +93,7 @@ impl PrivateKey {
self.type_ = type_;
}

#[must_use]
pub fn with_type(mut self, type_: String) -> Self {
self.type_ = type_;
self
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions mqtt/edgelet-client/src/workload/models/identity_cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ pub struct IdentityCertificateRequest {
}

impl IdentityCertificateRequest {
pub fn new(expiration: Option<String>) -> IdentityCertificateRequest {
pub fn new(expiration: Option<String>) -> Self {
IdentityCertificateRequest { expiration }
}

pub fn set_expiration(&mut self, expiration: String) {
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
}
Expand Down
2 changes: 2 additions & 0 deletions mqtt/edgelet-client/src/workload/models/server_cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +37,7 @@ impl ServerCertificateRequest {
self.expiration = expiration;
}

#[must_use]
pub fn with_expiration(mut self, expiration: String) -> Self {
self.expiration = expiration;
self
Expand Down
4 changes: 4 additions & 0 deletions mqtt/edgelet-client/src/workload/models/sign_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,6 +42,7 @@ impl SignRequest {
self.algorithm = algorithm;
}

#[must_use]
pub fn with_algorithm(mut self, algorithm: Algorithm) -> Self {
self.algorithm = algorithm;
self
Expand All @@ -54,6 +56,7 @@ impl SignRequest {
self.data = data;
}

#[must_use]
pub fn with_data(mut self, data: String) -> Self {
self.data = data;
self
Expand Down Expand Up @@ -86,6 +89,7 @@ impl SignResponse {
self.digest = digest;
}

#[must_use]
pub fn with_digest(mut self, digest: String) -> Self {
self.digest = digest;
self
Expand Down
1 change: 1 addition & 0 deletions mqtt/edgelet-client/src/workload/models/trust_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl TrustBundleResponse {
self.certificate = certificate;
}

#[must_use]
pub fn with_certificate(mut self, certificate: String) -> Self {
self.certificate = certificate;
self
Expand Down
2 changes: 2 additions & 0 deletions mqtt/mqtt-bridge/src/pump/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ where
S: StreamWakeableState + Send,
{
/// Apples parameters to create local pump.
#[must_use]
pub fn with_local<F>(mut self, mut apply: F) -> Self
where
F: FnMut(&mut PumpBuilder),
Expand All @@ -65,6 +66,7 @@ where
}

/// Applies parameters to create remote pump.
#[must_use]
pub fn with_remote<F>(mut self, mut apply: F) -> Self
where
F: FnMut(&mut PumpBuilder),
Expand Down
5 changes: 5 additions & 0 deletions mqtt/mqtt-broker-tests-util/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mqtt/mqtt-broker/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions mqtt/mqtt-broker/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl<F> FilePersistor<F> {
/// 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
Expand Down
1 change: 1 addition & 0 deletions mqtt/policy/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e047407

Please sign in to comment.