Skip to content

Commit 1bbf919

Browse files
authored
address clippy warnings for azure_iot_hub (#1402)
1 parent 44e926f commit 1bbf919

File tree

7 files changed

+41
-31
lines changed

7 files changed

+41
-31
lines changed

sdk/iot_hub/src/service/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,15 @@ impl ServiceClient {
216216
));
217217
}
218218

219-
for val in parts.iter() {
219+
for val in &parts {
220220
let start = match val.find('=') {
221221
Some(size) => size + 1,
222222
None => continue,
223223
};
224224

225225
if val.contains("HostName=") {
226-
let end = match val.find(".azure-devices.net") {
227-
Some(size) => size,
228-
None => continue,
226+
let Some(end) = val.find(".azure-devices.net") else {
227+
continue;
229228
};
230229
iot_hub_name = Some(&val[start..end]);
231230
}

sdk/iot_hub/src/service/operations/create_or_update_configuration.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,51 @@ azure_core::operation! {
2424
impl CreateOrUpdateConfigurationBuilder {
2525
/// Sets the device content for the configuration
2626
/// The content cannot be updated once it has been created.
27+
#[must_use]
2728
pub fn device_content(mut self, device_content: serde_json::Value) -> Self {
28-
let content = self.content.get_or_insert(Default::default());
29+
let content = self.content.get_or_insert(ConfigurationContent::default());
2930
content.device_content = Some(device_content);
3031
self
3132
}
3233

3334
/// Sets the module content for the configuration.
3435
/// The content cannot be updated once it has been created.
36+
#[must_use]
3537
pub fn module_content(mut self, module_content: serde_json::Value) -> Self {
36-
let content = self.content.get_or_insert(Default::default());
38+
let content = self.content.get_or_insert(ConfigurationContent::default());
3739
content.module_content = Some(module_content);
3840
self
3941
}
4042

4143
/// Sets the module content for the configuration
4244
/// The content cannot be updated once it has been created.
45+
#[must_use]
4346
pub fn modules_content(mut self, modules_content: serde_json::Value) -> Self {
44-
let content = self.content.get_or_insert(Default::default());
47+
let content = self.content.get_or_insert(ConfigurationContent::default());
4548
content.modules_content = Some(modules_content);
4649
self
4750
}
4851

4952
/// Add a metric to the configuration
53+
#[must_use]
5054
pub fn metric<S, T>(mut self, key: S, value: T) -> Self
5155
where
5256
S: Into<String>,
5357
T: Into<String>,
5458
{
55-
let metrics = self.metrics.get_or_insert(Default::default());
59+
let metrics = self.metrics.get_or_insert(HashMap::default());
5660
metrics.insert(key.into(), value.into());
5761
self
5862
}
5963

6064
/// Add a label to the configuration.
65+
#[must_use]
6166
pub fn label<S, T>(mut self, key: S, value: T) -> Self
6267
where
6368
S: Into<String>,
6469
T: Into<String>,
6570
{
66-
let labels = self.labels.get_or_insert(Default::default());
71+
let labels = self.labels.get_or_insert(HashMap::default());
6772
labels.insert(key.into(), value.into());
6873
self
6974
}

sdk/iot_hub/src/service/operations/create_or_update_device_identity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ azure_core::operation! {
2424

2525
impl CreateOrUpdateDeviceIdentityBuilder {
2626
/// Sets a device capability on the device
27+
#[must_use]
2728
pub fn device_capability(mut self, desired_capability: DesiredCapability) -> Self {
2829
match desired_capability {
2930
DesiredCapability::IotEdge => {

sdk/iot_hub/src/service/operations/get_configuration.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ impl GetConfigurationBuilder {
1414
/// Execute the request to get the configuration of a given identifier.
1515
pub fn into_future(self) -> GetConfiguration {
1616
Box::pin(async move {
17-
let uri = match self.configuration_id {
18-
Some(val) => format!(
17+
let uri = if let Some(val) = self.configuration_id {
18+
format!(
1919
"https://{}.azure-devices.net/configurations/{}?api-version={}",
2020
self.client.iot_hub_name, val, API_VERSION
21-
),
22-
None => format!(
21+
)
22+
} else {
23+
format!(
2324
"https://{}.azure-devices.net/configurations?api-version={}",
2425
self.client.iot_hub_name, API_VERSION
25-
),
26+
)
2627
};
2728

2829
let mut request = self.client.finalize_request(&uri, Method::Get)?;

sdk/iot_hub/src/service/operations/get_identity.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ impl GetIdentityBuilder {
1313
/// Execute the request to get the identity of a device or module.
1414
pub fn into_future(self) -> GetIdentity {
1515
Box::pin(async move {
16-
let uri = match self.module_id {
17-
Some(module_id) => format!(
16+
let url = if let Some(module_id) = &self.module_id {
17+
format!(
1818
"https://{}.azure-devices.net/devices/{}/modules/{}?api-version={}",
1919
self.client.iot_hub_name, self.device_id, module_id, API_VERSION
20-
),
21-
None => format!(
20+
)
21+
} else {
22+
format!(
2223
"https://{}.azure-devices.net/devices/{}?api-version={}",
2324
self.client.iot_hub_name, self.device_id, API_VERSION
24-
),
25+
)
2526
};
2627

27-
let mut request = self.client.finalize_request(&uri, Method::Get)?;
28+
let mut request = self.client.finalize_request(&url, Method::Get)?;
2829
request.set_body(azure_core::EMPTY_BODY);
2930

3031
let response = self.client.send(&self.context, &mut request).await?;

sdk/iot_hub/src/service/operations/get_twin.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ impl GetTwinBuilder {
1313
/// Execute the request to get the twin of a module or device.
1414
pub fn into_future(self) -> GetTwin {
1515
Box::pin(async move {
16-
let uri = match self.module_id {
17-
Some(val) => format!(
16+
let uri = if let Some(val) = self.module_id {
17+
format!(
1818
"https://{}.azure-devices.net/twins/{}/modules/{}?api-version={}",
1919
self.client.iot_hub_name, self.device_id, val, API_VERSION
20-
),
21-
None => format!(
20+
)
21+
} else {
22+
format!(
2223
"https://{}.azure-devices.net/twins/{}?api-version={}",
2324
self.client.iot_hub_name, self.device_id, API_VERSION
24-
),
25+
)
2526
};
2627

2728
let mut request = self.client.finalize_request(&uri, Method::Get)?;

sdk/iot_hub/src/service/operations/update_or_replace_twin.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ impl UpdateOrReplaceTwinBuilder {
3535
/// .tag("AnotherTag", "WithAnotherValue")
3636
/// .tag("LastTag", "LastValue");
3737
/// ```
38+
#[must_use]
3839
pub fn tag<T>(mut self, tag_name: T, tag_value: T) -> Self
3940
where
4041
T: Into<String>,
4142
{
42-
let tags = self.desired_tags.get_or_insert(Default::default());
43+
let tags = self.desired_tags.get_or_insert(HashMap::default());
4344
tags.insert(tag_name.into(), tag_value.into());
4445
self
4546
}
@@ -65,15 +66,16 @@ impl UpdateOrReplaceTwinBuilder {
6566
},
6667
};
6768

68-
let uri = match self.module_id {
69-
Some(val) => format!(
69+
let uri = if let Some(val) = self.module_id {
70+
format!(
7071
"https://{}.azure-devices.net/twins/{}/modules/{}?api-version={}",
7172
self.client.iot_hub_name, self.device_id, val, API_VERSION
72-
),
73-
None => format!(
73+
)
74+
} else {
75+
format!(
7476
"https://{}.azure-devices.net/twins/{}?api-version={}",
7577
self.client.iot_hub_name, self.device_id, API_VERSION
76-
),
78+
)
7779
};
7880

7981
let mut request = self.client.finalize_request(&uri, self.method)?;

0 commit comments

Comments
 (0)