Skip to content

Commit 7c036d5

Browse files
henrybarretootavio
authored andcommitted
fix: update code to solve clippy issues
1 parent 39d0d2c commit 7c036d5

48 files changed

Lines changed: 141 additions & 144 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

updatehub-cloud-sdk/src/api.rs

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

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

88
#[derive(Debug)]
99
pub enum ProbeResponse {
@@ -33,7 +33,7 @@ pub struct FirmwareMetadata<'a> {
3333

3434
pub struct MetadataValue<'a>(pub &'a BTreeMap<String, Vec<String>>);
3535

36-
impl<'a> serde::ser::Serialize for MetadataValue<'a> {
36+
impl serde::ser::Serialize for MetadataValue<'_> {
3737
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
3838
where
3939
S: serde::ser::Serializer,
@@ -59,7 +59,11 @@ impl UpdatePackage {
5959
}
6060

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

6569
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-cloud-sdk/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ pub enum Error {
2424
ParseInt(std::num::ParseIntError),
2525

2626
Http(reqwest::Error),
27-
#[display(fmt = "Invalid status response: {}", _0)]
27+
#[display(fmt = "Invalid status response: {_0}")]
2828
InvalidStatusResponse(#[error(not(source))] reqwest::StatusCode),
29-
#[display(fmt = "Invalid header value: {}", _0)]
29+
#[display(fmt = "Invalid header value: {_0}")]
3030
HeaderParse(reqwest::header::ToStrError),
31-
#[display(fmt = "Invalid url: {}", _0)]
31+
#[display(fmt = "Invalid url: {_0}")]
3232
UrlParse(url::ParseError),
3333
}

updatehub-cloud-sdk/tests/integration_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ async fn probe_response_with_signature() {
243243
.unwrap()
244244
),
245245
ProbeResponse::Update(_, None) => panic!("No signature extracted from update response"),
246-
r => panic!("Unexpected probe response: {:?}", r),
246+
r => panic!("Unexpected probe response: {r:?}"),
247247
}
248248
mocks.assert();
249249
}
@@ -256,7 +256,7 @@ async fn probe_response_with_extra_poll() {
256256
sdk::Client::new(&server.url()).probe(0, FakeMetadata::new().get()).await.unwrap();
257257
match response {
258258
ProbeResponse::ExtraPoll(n) => assert_eq!(n, 10),
259-
r => panic!("Unexpected probe response: {:?}", r),
259+
r => panic!("Unexpected probe response: {r:?}"),
260260
}
261261
mocks.assert();
262262
}

updatehub-package-schema/src/definitions/chunk_size.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<'de> Deserialize<'de> for ChunkSize {
2424
if n > 1 {
2525
return Ok(ChunkSize(n));
2626
}
27-
Err(de::Error::custom(format!("Invalid chunk size: {}", n)))
27+
Err(de::Error::custom(format!("Invalid chunk size: {n}")))
2828
}
2929
}
3030

updatehub-package-schema/src/definitions/count.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<'de> Deserialize<'de> for Count {
2222
match isize::deserialize(deserializer)? {
2323
-1 => Ok(Count::All),
2424
n if n >= 0 => Ok(Count::Limited(n)),
25-
n => Err(de::Error::custom(format!("Invalid count: {}", n))),
25+
n => Err(de::Error::custom(format!("Invalid count: {n}"))),
2626
}
2727
}
2828
}

updatehub-package-schema/src/definitions/install_if_different.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub enum InstallIfDifferent {
1414
#[display(fmt = "checksum")]
1515
CheckSum,
1616
/// Use a predefined (known) pattern to check.
17-
#[display(fmt = "pattern({} equal to '{}')", pattern, version)]
17+
#[display(fmt = "pattern({pattern} equal to '{version}')")]
1818
KnownPattern { version: String, pattern: KnownPatternKind },
1919
/// Use a custom pattern to check.
2020
#[display(fmt = "custom pattern({} uqual to '{}')", "pattern.regexp", version)]
@@ -50,7 +50,7 @@ where
5050
{
5151
match String::deserialize(deserializer)?.to_lowercase().as_str() {
5252
"sha256sum" => Ok(()),
53-
s => Err(serde::de::Error::custom(format!("Not a vliad CheckSum format: {}", s))),
53+
s => Err(serde::de::Error::custom(format!("Not a vliad CheckSum format: {s}"))),
5454
}
5555
}
5656

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/api/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub mod log {
140140
impl core::fmt::Display for Log {
141141
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
142142
for entry in &self.entries {
143-
writeln!(f, "{}", entry)?;
143+
writeln!(f, "{entry}")?;
144144
}
145145
Ok(())
146146
}

updatehub-sdk/src/client.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Default for Client {
2525
impl Client {
2626
/// Constructs a new `Client`.
2727
pub fn new(server_address: &str) -> Self {
28-
Client { server_address: format!("http://{}", server_address), ..Self::default() }
28+
Client { server_address: format!("http://{server_address}"), ..Self::default() }
2929
}
3030

3131
/// Get the current state of the agent.
@@ -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?),

0 commit comments

Comments
 (0)