Skip to content

Commit 64ed582

Browse files
committed
fix: update code to solve clippy issues
1 parent 618d93a commit 64ed582

13 files changed

Lines changed: 43 additions & 23 deletions

File tree

updatehub-cloud-sdk/src/api.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
use serde::Serialize;
6+
use std::fmt::Write;
67
use std::{collections::BTreeMap, fs, path::Path};
78

89
#[derive(Debug)]
@@ -33,7 +34,7 @@ pub struct FirmwareMetadata<'a> {
3334

3435
pub struct MetadataValue<'a>(pub &'a BTreeMap<String, Vec<String>>);
3536

36-
impl<'a> serde::ser::Serialize for MetadataValue<'a> {
37+
impl serde::ser::Serialize for MetadataValue<'_> {
3738
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
3839
where
3940
S: serde::ser::Serializer,
@@ -59,7 +60,11 @@ impl UpdatePackage {
5960
}
6061

6162
pub fn package_uid(&self) -> String {
62-
openssl::sha::sha256(&self.raw).iter().map(|c| format!("{:02x}", c)).collect()
63+
openssl::sha::sha256(&self.raw).iter().fold(String::new(), |mut output, c| {
64+
let _ = write!(output, "{c:02X}");
65+
66+
output
67+
})
6368
}
6469

6570
pub fn version(&self) -> &str {

updatehub-cloud-sdk/src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'a> Client<'a> {
8585

8686
let response = self
8787
.client
88-
.post(&format!("{}/upgrades", &self.server))
88+
.post(format!("{}/upgrades", &self.server))
8989
.header("api-retries", num_retries.to_string())
9090
.json(&firmware)
9191
.send()
@@ -181,7 +181,7 @@ impl<'a> Client<'a> {
181181
let payload =
182182
Payload { state, firmware, package_uid, previous_state, error_message, current_log };
183183

184-
self.client.post(&format!("{}/report", &self.server)).json(&payload).send().await?;
184+
self.client.post(format!("{}/report", &self.server)).json(&payload).send().await?;
185185
Ok(())
186186
}
187187
}

updatehub-sdk/src/api/info/firmware.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'de> Deserialize<'de> for MetadataValue {
125125
}
126126
}
127127

128-
impl<'a> Index<&'a str> for MetadataValue {
128+
impl Index<&str> for MetadataValue {
129129
type Output = Vec<String>;
130130

131131
#[inline]

updatehub-sdk/src/client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Client {
4343
/// This method fails when cannot complete the request at the address or
4444
/// cannot parse the body json as a `info::Response`.
4545
pub async fn info(&self) -> Result<api::info::Response> {
46-
let response = self.client.get(&format!("{}/info", self.server_address)).send().await?;
46+
let response = self.client.get(format!("{}/info", self.server_address)).send().await?;
4747

4848
match response.status() {
4949
StatusCode::OK => Ok(response.json().await?),
@@ -110,7 +110,7 @@ impl Client {
110110
pub async fn local_install(&self, file: &Path) -> Result<api::state::Response> {
111111
let response = self
112112
.client
113-
.post(&format!("{}/local_install", self.server_address))
113+
.post(format!("{}/local_install", self.server_address))
114114
.json(&api::local_install::Request { file: file.to_owned() })
115115
.send()
116116
.await?;
@@ -139,7 +139,7 @@ impl Client {
139139
pub async fn remote_install(&self, url: &str) -> Result<api::state::Response> {
140140
let response = self
141141
.client
142-
.post(&format!("{}/remote_install", self.server_address))
142+
.post(format!("{}/remote_install", self.server_address))
143143
.json(&api::remote_install::Request { url: url.to_owned() })
144144
.send()
145145
.await?;
@@ -167,7 +167,7 @@ impl Client {
167167
pub async fn abort_download(&self) -> Result<api::state::Response> {
168168
let response = self
169169
.client
170-
.post(&format!("{}/update/download/abort", self.server_address))
170+
.post(format!("{}/update/download/abort", self.server_address))
171171
.send()
172172
.await?;
173173

@@ -193,7 +193,7 @@ impl Client {
193193
/// This method fails when cannot complete the request at the address or
194194
/// cannot parse the body json as a `log::Log`.
195195
pub async fn log(&self) -> Result<api::log::Log> {
196-
let response = self.client.get(&format!("{}/log", self.server_address)).send().await?;
196+
let response = self.client.get(format!("{}/log", self.server_address)).send().await?;
197197

198198
match response.status() {
199199
StatusCode::OK => Ok(response.json().await?),

updatehub-sdk/src/listener.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl StateChange {
103103
F: Fn(Handler) -> Fut + 'static,
104104
Fut: Future<Output = Result<()>> + 'static,
105105
{
106-
self.callbacks.entry(state).or_insert_with(Vec::new).push(Box::new(move |d| Box::pin(f(d))))
106+
self.callbacks.entry(state).or_default().push(Box::new(move |d| Box::pin(f(d))))
107107
}
108108

109109
/// Start the agent to listen for messages on the socket.

updatehub/src/firmware/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ pub(crate) fn create_fake_starup_callbacks(metadata_dir: &Path, output_file: &Pa
124124
let mut file = fs::OpenOptions::new()
125125
.write(true)
126126
.create(true)
127-
.open(&metadata_dir.join(script))
127+
.truncate(true)
128+
.open(metadata_dir.join(script))
128129
.unwrap();
129130
writeln!(file, "#!/bin/sh\necho $0 >> {}", output_file.to_string_lossy()).unwrap();
130131
let mut permissions = fs::metadata(metadata_dir).unwrap().permissions();

updatehub/src/mem_drain.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl Serialize for MemDrain {
4949
}
5050
}
5151

52+
#[allow(clippy::to_string_trait_impl)]
5253
impl ToString for MemDrain {
5354
fn to_string(&self) -> String {
5455
let records = self.records.read().unwrap();

updatehub/src/object/installer/imxkobs.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ impl Installer for objects::Imxkobs {
2525

2626
let should_skip_install =
2727
super::should_skip_install(&self.install_if_different, &self.sha256sum, async {
28-
let path = self
29-
.chip_0_device_path
30-
.as_ref()
31-
.map(PathBuf::clone)
32-
.unwrap_or_else(|| PathBuf::from("/dev/mtd0"));
28+
let path =
29+
self.chip_0_device_path.clone().unwrap_or_else(|| PathBuf::from("/dev/mtd0"));
3330
let f = path.file_name().ok_or(Error::InvalidPath)?;
3431
let mut file_name = f.to_os_string();
3532
file_name.push("ro");

updatehub/src/runtime_settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl RuntimeSettings {
103103
.map(|s| RuntimeSettings { inner: s, v1_content: Some(content.to_string()) })
104104
});
105105

106-
runtime_settings.map_err(Error::from)
106+
runtime_settings
107107
}
108108

109109
fn save(&self) -> Result<()> {

updatehub/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl TestEnvironmentBuilder {
164164
}
165165

166166
for bin in self.extra_binaries.into_iter() {
167-
let mut file = fs::File::create(&bin_dir_path.join(&bin)).unwrap();
167+
let mut file = fs::File::create(bin_dir_path.join(&bin)).unwrap();
168168
writeln!(file, "#!/bin/sh\necho {} $@ >> {}", bin, output_file.to_string_lossy())
169169
.unwrap();
170170
let mut permissions = file.metadata().unwrap().permissions();

0 commit comments

Comments
 (0)