Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address clippy warnings for azure_iot_hub #1402

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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