Skip to content

Commit

Permalink
address clippy warnings for azure_iot_hub (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
demoray authored Sep 20, 2023
1 parent 44e926f commit 1bbf919
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 31 deletions.
7 changes: 3 additions & 4 deletions sdk/iot_hub/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,15 @@ impl ServiceClient {
));
}

for val in parts.iter() {
for val in &parts {
let start = match val.find('=') {
Some(size) => size + 1,
None => continue,
};

if val.contains("HostName=") {
let end = match val.find(".azure-devices.net") {
Some(size) => size,
None => continue,
let Some(end) = val.find(".azure-devices.net") else {
continue;
};
iot_hub_name = Some(&val[start..end]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,51 @@ azure_core::operation! {
impl CreateOrUpdateConfigurationBuilder {
/// Sets the device content for the configuration
/// The content cannot be updated once it has been created.
#[must_use]
pub fn device_content(mut self, device_content: serde_json::Value) -> Self {
let content = self.content.get_or_insert(Default::default());
let content = self.content.get_or_insert(ConfigurationContent::default());
content.device_content = Some(device_content);
self
}

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

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

/// Add a metric to the configuration
#[must_use]
pub fn metric<S, T>(mut self, key: S, value: T) -> Self
where
S: Into<String>,
T: Into<String>,
{
let metrics = self.metrics.get_or_insert(Default::default());
let metrics = self.metrics.get_or_insert(HashMap::default());
metrics.insert(key.into(), value.into());
self
}

/// Add a label to the configuration.
#[must_use]
pub fn label<S, T>(mut self, key: S, value: T) -> Self
where
S: Into<String>,
T: Into<String>,
{
let labels = self.labels.get_or_insert(Default::default());
let labels = self.labels.get_or_insert(HashMap::default());
labels.insert(key.into(), value.into());
self
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ azure_core::operation! {

impl CreateOrUpdateDeviceIdentityBuilder {
/// Sets a device capability on the device
#[must_use]
pub fn device_capability(mut self, desired_capability: DesiredCapability) -> Self {
match desired_capability {
DesiredCapability::IotEdge => {
Expand Down
11 changes: 6 additions & 5 deletions sdk/iot_hub/src/service/operations/get_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ impl GetConfigurationBuilder {
/// Execute the request to get the configuration of a given identifier.
pub fn into_future(self) -> GetConfiguration {
Box::pin(async move {
let uri = match self.configuration_id {
Some(val) => format!(
let uri = if let Some(val) = self.configuration_id {
format!(
"https://{}.azure-devices.net/configurations/{}?api-version={}",
self.client.iot_hub_name, val, API_VERSION
),
None => format!(
)
} else {
format!(
"https://{}.azure-devices.net/configurations?api-version={}",
self.client.iot_hub_name, API_VERSION
),
)
};

let mut request = self.client.finalize_request(&uri, Method::Get)?;
Expand Down
13 changes: 7 additions & 6 deletions sdk/iot_hub/src/service/operations/get_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ impl GetIdentityBuilder {
/// Execute the request to get the identity of a device or module.
pub fn into_future(self) -> GetIdentity {
Box::pin(async move {
let uri = match self.module_id {
Some(module_id) => format!(
let url = if let Some(module_id) = &self.module_id {
format!(
"https://{}.azure-devices.net/devices/{}/modules/{}?api-version={}",
self.client.iot_hub_name, self.device_id, module_id, API_VERSION
),
None => format!(
)
} else {
format!(
"https://{}.azure-devices.net/devices/{}?api-version={}",
self.client.iot_hub_name, self.device_id, API_VERSION
),
)
};

let mut request = self.client.finalize_request(&uri, Method::Get)?;
let mut request = self.client.finalize_request(&url, Method::Get)?;
request.set_body(azure_core::EMPTY_BODY);

let response = self.client.send(&self.context, &mut request).await?;
Expand Down
11 changes: 6 additions & 5 deletions sdk/iot_hub/src/service/operations/get_twin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ impl GetTwinBuilder {
/// Execute the request to get the twin of a module or device.
pub fn into_future(self) -> GetTwin {
Box::pin(async move {
let uri = match self.module_id {
Some(val) => format!(
let uri = if let Some(val) = self.module_id {
format!(
"https://{}.azure-devices.net/twins/{}/modules/{}?api-version={}",
self.client.iot_hub_name, self.device_id, val, API_VERSION
),
None => format!(
)
} else {
format!(
"https://{}.azure-devices.net/twins/{}?api-version={}",
self.client.iot_hub_name, self.device_id, API_VERSION
),
)
};

let mut request = self.client.finalize_request(&uri, Method::Get)?;
Expand Down
14 changes: 8 additions & 6 deletions sdk/iot_hub/src/service/operations/update_or_replace_twin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ impl UpdateOrReplaceTwinBuilder {
/// .tag("AnotherTag", "WithAnotherValue")
/// .tag("LastTag", "LastValue");
/// ```
#[must_use]
pub fn tag<T>(mut self, tag_name: T, tag_value: T) -> Self
where
T: Into<String>,
{
let tags = self.desired_tags.get_or_insert(Default::default());
let tags = self.desired_tags.get_or_insert(HashMap::default());
tags.insert(tag_name.into(), tag_value.into());
self
}
Expand All @@ -65,15 +66,16 @@ impl UpdateOrReplaceTwinBuilder {
},
};

let uri = match self.module_id {
Some(val) => format!(
let uri = if let Some(val) = self.module_id {
format!(
"https://{}.azure-devices.net/twins/{}/modules/{}?api-version={}",
self.client.iot_hub_name, self.device_id, val, API_VERSION
),
None => format!(
)
} else {
format!(
"https://{}.azure-devices.net/twins/{}?api-version={}",
self.client.iot_hub_name, self.device_id, API_VERSION
),
)
};

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

0 comments on commit 1bbf919

Please sign in to comment.