[pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits
Lukas Wagner
l.wagner at proxmox.com
Tue Aug 8 10:01:39 CEST 2023
See: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
proxmox-apt/src/repositories/file.rs | 2 +-
proxmox-apt/src/repositories/repository.rs | 2 +-
proxmox-openid/src/auth_state.rs | 2 +-
proxmox-rest-server/src/worker_task.rs | 10 +++++-----
proxmox-schema/src/ser/mod.rs | 4 ++--
proxmox-serde/src/lib.rs | 9 ++++-----
proxmox-subscription/src/check.rs | 2 +-
7 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/proxmox-apt/src/repositories/file.rs b/proxmox-apt/src/repositories/file.rs
index b4c6b08..bfd7836 100644
--- a/proxmox-apt/src/repositories/file.rs
+++ b/proxmox-apt/src/repositories/file.rs
@@ -293,7 +293,7 @@ impl APTRepositoryFile {
}
if self.repositories.is_empty() {
- return std::fs::remove_file(&path)
+ return std::fs::remove_file(path)
.map_err(|err| self.err(format_err!("unable to remove file - {}", err)));
}
diff --git a/proxmox-apt/src/repositories/repository.rs b/proxmox-apt/src/repositories/repository.rs
index c2df2c7..0b04802 100644
--- a/proxmox-apt/src/repositories/repository.rs
+++ b/proxmox-apt/src/repositories/repository.rs
@@ -414,7 +414,7 @@ fn uri_to_filename(uri: &str) -> String {
if *b <= 0x20 || *b >= 0x7F || encode_chars.contains(*b as char) {
let mut hex = [0u8; 2];
// unwrap: we're hex-encoding a single byte into a 2-byte slice
- hex::encode_to_slice(&[*b], &mut hex).unwrap();
+ hex::encode_to_slice([*b], &mut hex).unwrap();
let hex = unsafe { std::str::from_utf8_unchecked(&hex) };
encoded = format!("{}%{}", encoded, hex);
} else {
diff --git a/proxmox-openid/src/auth_state.rs b/proxmox-openid/src/auth_state.rs
index 8d940ec..f2a299a 100644
--- a/proxmox-openid/src/auth_state.rs
+++ b/proxmox-openid/src/auth_state.rs
@@ -97,7 +97,7 @@ pub fn store_auth_state(
bail!("too many pending openid auth request for realm {}", realm);
}
- data.push(serde_json::to_value(&auth_state)?);
+ data.push(serde_json::to_value(auth_state)?);
replace_auth_state(&path, &data)?;
diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs
index 6263ce7..54b6bc2 100644
--- a/proxmox-rest-server/src/worker_task.rs
+++ b/proxmox-rest-server/src/worker_task.rs
@@ -1023,11 +1023,11 @@ impl WorkerTaskContext for WorkerTask {
fn log(&self, level: log::Level, message: &std::fmt::Arguments) {
match level {
- log::Level::Error => self.log_warning(&message.to_string()),
- log::Level::Warn => self.log_warning(&message.to_string()),
- log::Level::Info => self.log_message(&message.to_string()),
- log::Level::Debug => self.log_message(&format!("DEBUG: {}", message)),
- log::Level::Trace => self.log_message(&format!("TRACE: {}", message)),
+ log::Level::Error => self.log_warning(message.to_string()),
+ log::Level::Warn => self.log_warning(message.to_string()),
+ log::Level::Info => self.log_message(message.to_string()),
+ log::Level::Debug => self.log_message(format!("DEBUG: {}", message)),
+ log::Level::Trace => self.log_message(format!("TRACE: {}", message)),
}
}
}
diff --git a/proxmox-schema/src/ser/mod.rs b/proxmox-schema/src/ser/mod.rs
index bcf473d..3dad6d6 100644
--- a/proxmox-schema/src/ser/mod.rs
+++ b/proxmox-schema/src/ser/mod.rs
@@ -448,7 +448,7 @@ impl<T: fmt::Write> Serializer for ElementSerializer<T> {
}
fn serialize_str(mut self, v: &str) -> Result<Self::Ok, Error> {
- if v.contains(&['"', '\\', '\n']) {
+ if v.contains(['"', '\\', '\n']) {
self.inner.write_char('"')?;
crate::property_string::quote(v, &mut self.inner)?;
self.inner.write_char('"')?;
@@ -643,7 +643,7 @@ impl<T: fmt::Write> ElementSerializeSeq<T> {
fn finish(mut self) -> Result<T, Error> {
let value = self.inner.finish()?;
- if value.contains(&[',', ';', ' ', '"', '\\', '\n']) {
+ if value.contains([',', ';', ' ', '"', '\\', '\n']) {
self.output.write_char('"')?;
crate::property_string::quote(&value, &mut self.output)?;
self.output.write_char('"')?;
diff --git a/proxmox-serde/src/lib.rs b/proxmox-serde/src/lib.rs
index e1dc16a..2f1ccca 100644
--- a/proxmox-serde/src/lib.rs
+++ b/proxmox-serde/src/lib.rs
@@ -86,9 +86,8 @@ pub mod bytes_as_base64 {
D: Deserializer<'de>,
{
use serde::de::Error;
- String::deserialize(deserializer).and_then(|string| {
- base64::decode(&string).map_err(|err| Error::custom(err.to_string()))
- })
+ String::deserialize(deserializer)
+ .and_then(|string| base64::decode(string).map_err(|err| Error::custom(err.to_string())))
}
}
@@ -125,7 +124,7 @@ pub mod string_as_base64 {
fn finish_deserializing<'de, D: Deserializer<'de>>(string: String) -> Result<String, D::Error> {
use serde::de::Error;
- let bytes = base64::decode(&string).map_err(|err| {
+ let bytes = base64::decode(string).map_err(|err| {
let msg = format!("base64 decode: {}", err);
Error::custom(msg)
})?;
@@ -219,7 +218,7 @@ pub mod bytes_as_base64url_nopad {
{
use serde::de::Error;
String::deserialize(deserializer).and_then(|string| {
- base64::decode_config(&string, base64::URL_SAFE_NO_PAD)
+ base64::decode_config(string, base64::URL_SAFE_NO_PAD)
.map_err(|err| Error::custom(err.to_string()))
})
}
diff --git a/proxmox-subscription/src/check.rs b/proxmox-subscription/src/check.rs
index 3838e9c..9d074ea 100644
--- a/proxmox-subscription/src/check.rs
+++ b/proxmox-subscription/src/check.rs
@@ -25,7 +25,7 @@ fn register_subscription<C: HttpClient<String, String>>(
client: C,
) -> Result<(String, String), Error> {
// WHCMS sample code feeds the key into this, but it's just a challenge, so keep it simple
- let rand = hex::encode(&proxmox_sys::linux::random_data(16)?);
+ let rand = hex::encode(proxmox_sys::linux::random_data(16)?);
let challenge = format!("{}{}", checktime, rand);
let params = json!({
--
2.39.2
More information about the pbs-devel
mailing list