Skip to content

Commit 6d17e84

Browse files
chore: follow clippy lints
1 parent 7a2c330 commit 6d17e84

File tree

7 files changed

+104
-101
lines changed

7 files changed

+104
-101
lines changed

src/backend/borg.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
impl TryFrom<serde_json::Value> for Event {
1212
type Error = Error;
1313
fn try_from(value: serde_json::Value) -> Result<Self> {
14-
let _type = match value.get("type") {
14+
let r#type = match value.get("type") {
1515
Some(serde_json::Value::String(t)) => t,
1616
_ => return Err("no type".into()),
1717
};
@@ -37,14 +37,14 @@ impl TryFrom<serde_json::Value> for Event {
3737
value
3838
.get("message")
3939
.and_then(|m| m.as_str())
40-
.map(|m| m.to_owned())
40+
.map(ToOwned::to_owned)
4141
};
4242
let finished = || value.get("finished").and_then(|f| f.as_bool());
4343
let msgid = || {
4444
value
4545
.get("msgid")
4646
.and_then(|m| m.as_str())
47-
.map(|m| m.to_owned())
47+
.map(ToOwned::to_owned)
4848
};
4949
let operation = || value.get("operation").and_then(|o| o.as_u64());
5050
let level = || {
@@ -57,7 +57,7 @@ impl TryFrom<serde_json::Value> for Event {
5757
"warning" => Some(Level::Warn),
5858
"error" => Some(Level::Error),
5959
_ => {
60-
warn!("unknown log level: {}", l);
60+
warn!("unknown log level: {l}");
6161
None
6262
}
6363
})
@@ -74,7 +74,7 @@ impl TryFrom<serde_json::Value> for Event {
7474
"WARNING" => Some(Level::Warn),
7575
"ERROR" => Some(Level::Error),
7676
_ => {
77-
warn!("unknown log level: {}", l);
77+
warn!("unknown log level: {l}");
7878
None
7979
}
8080
})
@@ -88,24 +88,24 @@ impl TryFrom<serde_json::Value> for Event {
8888
value
8989
.get("name")
9090
.and_then(|n| n.as_str())
91-
.map(|n| n.to_owned())
91+
.map(ToOwned::to_owned)
9292
};
9393
let status = || {
9494
value
9595
.get("status")
9696
.and_then(|s| s.as_str())
97-
.map(|s| s.to_owned())
97+
.map(ToOwned::to_owned)
9898
};
9999
let current = || value.get("current").and_then(|c| c.as_u64());
100100
let total = || value.get("total").and_then(|t| t.as_u64());
101101
let env_var = || {
102102
value
103103
.get("env_var")
104104
.and_then(|e| e.as_str())
105-
.map(|e| e.to_owned())
105+
.map(ToOwned::to_owned)
106106
};
107107

108-
let event = match _type.as_str() {
108+
let event = match r#type.as_str() {
109109
"archive_progress" => Self::ArchiveProgress {
110110
nfiles: nfiles().unwrap_or_default(),
111111
compressed_size: compressed_size().unwrap_or_default(),
@@ -153,7 +153,7 @@ impl TryFrom<serde_json::Value> for Event {
153153
env_var: env_var(),
154154
msgid: msgid().unwrap(),
155155
},
156-
_ => return Err(format!("Unknown event type: {}", _type).into()),
156+
_ => return Err(format!("Unknown event type: {type}").into()),
157157
};
158158
Ok(event)
159159
}
@@ -165,7 +165,7 @@ pub struct Events<R: Read> {
165165

166166
impl<R: Read> From<R> for Events<R> {
167167
fn from(readable: R) -> Self {
168-
Events {
168+
Self {
169169
lines: BufReader::new(readable).lines(),
170170
}
171171
}
@@ -181,7 +181,7 @@ impl<R: Read> Iterator for Events<R> {
181181
Err(err) => return Some(Event::Error(Box::new(err))),
182182
};
183183

184-
trace!("[borg] {:#?}", line);
184+
trace!("[borg] {line:#?}");
185185

186186
let json: std::result::Result<serde_json::Value, _> = serde_json::from_str(&line);
187187
let json = match json {
@@ -192,11 +192,11 @@ impl<R: Read> Iterator for Events<R> {
192192
}
193193
};
194194

195-
debug!("{:#?}", json);
195+
debug!("{json:#?}");
196196

197197
match Event::try_from(json) {
198198
Ok(event) => {
199-
debug!("{:#?}", event);
199+
debug!("{event:#?}");
200200
Some(event)
201201
}
202202
Err(e) => {
@@ -216,7 +216,7 @@ fn log_command(cmd: &Command) {
216216
.collect::<Vec<_>>()
217217
.join(" ")
218218
);
219-
debug!("Executing command: {}", command);
219+
debug!("Executing command: {command}");
220220
}
221221

222222
impl TryFrom<serde_json::Value> for RepoInfo {
@@ -297,7 +297,7 @@ impl TryFrom<serde_json::Value> for RepoInfo {
297297
.map(PathBuf::from)
298298
.ok_or("missing key: \"security_dir\"")?;
299299

300-
Ok(RepoInfo {
300+
Ok(Self {
301301
cache_path,
302302
total_chunks,
303303
total_csize,
@@ -576,7 +576,7 @@ impl Backend for BorgWrapper {
576576
}
577577

578578
cmd.arg("--json");
579-
cmd.arg(&repository.to_string());
579+
cmd.arg(repository.to_string());
580580

581581
log_command(&cmd);
582582

src/borrg.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ pub enum Encryption {
3131
impl Display for Encryption {
3232
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3333
match self {
34-
Encryption::None => write!(f, "none"),
35-
Encryption::RepoKey => write!(f, "repokey"),
36-
Encryption::RepoKeyBlake2 => write!(f, "repokey-blake2"),
37-
Encryption::KeyFile => write!(f, "keyfile"),
38-
Encryption::KeyFileBlake2 => write!(f, "keyfile-blake2"),
39-
Encryption::Authenticated => write!(f, "authenticated"),
40-
Encryption::AuthenticatedBlake2 => write!(f, "authenticated-blake2"),
34+
Self::None => write!(f, "none"),
35+
Self::RepoKey => write!(f, "repokey"),
36+
Self::RepoKeyBlake2 => write!(f, "repokey-blake2"),
37+
Self::KeyFile => write!(f, "keyfile"),
38+
Self::KeyFileBlake2 => write!(f, "keyfile-blake2"),
39+
Self::Authenticated => write!(f, "authenticated"),
40+
Self::AuthenticatedBlake2 => write!(f, "authenticated-blake2"),
4141
}
4242
}
4343
}
@@ -72,19 +72,19 @@ pub enum Compression {
7272
impl Display for Compression {
7373
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7474
fn fmt_obfuscation(obfuscate: &Option<NonZeroU8>) -> String {
75-
obfuscate.map_or("".to_string(), |o| format!("obfuscate,{},", o.get()))
75+
obfuscate.map_or(String::new(), |o| format!("obfuscate,{},", o.get()))
7676
}
7777

7878
fn fmt_auto(auto: &bool) -> String {
7979
if *auto {
8080
"auto,".to_string()
8181
} else {
82-
"".to_string()
82+
String::new()
8383
}
8484
}
8585

8686
fn fmt_level(level: &Option<u8>) -> String {
87-
level.map_or("".to_string(), |l| format!(",{}", l))
87+
level.map_or(String::new(), |l| format!(",{l}"))
8888
}
8989

9090
use Compression::*;
@@ -149,8 +149,8 @@ pub struct Archive {
149149
}
150150

151151
impl Archive {
152-
pub fn new(name: String) -> Self {
153-
Archive {
152+
pub const fn new(name: String) -> Self {
153+
Self {
154154
name,
155155
paths: Vec::new(),
156156
compression: None,
@@ -276,19 +276,19 @@ impl Display for Event {
276276
}
277277
ProgressMessage { message, .. } => {
278278
if let Some(message) = message {
279-
write!(f, "{}", message)
279+
write!(f, "{message}")
280280
} else {
281281
Ok(())
282282
}
283283
}
284284
LogMessage { message, .. } => {
285-
write!(f, "{}", message)
285+
write!(f, "{message}")
286286
}
287287
ProgressPercent { message, .. } => write!(f, "{message}"),
288288
FileStatus { path, status } => write!(f, "{} {}", status, path.display()),
289-
Prompt { prompt, .. } => write!(f, "{}", prompt),
290-
Answer { answer, .. } => write!(f, "{}", answer),
291-
Other(s) => write!(f, "{}", s),
289+
Prompt { prompt, .. } => write!(f, "{prompt}"),
290+
Answer { answer, .. } => write!(f, "{answer}"),
291+
Other(s) => write!(f, "{s}"),
292292
Error(e) => write!(f, "{e}"),
293293
}
294294
}

src/borrg/repo.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl FromStr for Repo {
5959
type Err = &'static str;
6060
fn from_str(s: &str) -> Result<Self, Self::Err> {
6161
if let Some(path) = s.strip_prefix("file://") {
62-
return Ok(Repo {
62+
return Ok(Self {
6363
remote: None,
6464
path: path.into(),
6565
passphrase: None,
@@ -72,13 +72,13 @@ impl FromStr for Repo {
7272
.ok_or("Invalid repository specifier (No \"/\" after \"ssh://\")")?;
7373
let remote = remote.parse()?;
7474
if !path.starts_with('.') && !path.starts_with('~') {
75-
return Ok(Repo {
75+
return Ok(Self {
7676
remote: Some(remote),
7777
path: PathBuf::from("/").join(path),
7878
passphrase: None,
7979
});
8080
}
81-
return Ok(Repo {
81+
return Ok(Self {
8282
remote: Some(remote),
8383
path: path.into(),
8484
passphrase: None,
@@ -92,14 +92,14 @@ impl FromStr for Repo {
9292
Note: borrg will still support the old format by converting it internally."
9393
);
9494
let remote = remote.parse()?;
95-
return Ok(Repo {
95+
return Ok(Self {
9696
remote: Some(remote),
9797
path: path.into(),
9898
passphrase: None,
9999
});
100100
}
101101

102-
Ok(Repo {
102+
Ok(Self {
103103
remote: None,
104104
path: s.into(),
105105
passphrase: None,
@@ -151,11 +151,14 @@ impl FromStr for Remote {
151151
rest = h;
152152
}
153153
if let Some((h, p)) = rest.split_once(':') {
154-
port.replace(p.parse().map_err(|_| "Invalid remote: Failed to parse port")?);
154+
port.replace(
155+
p.parse()
156+
.map_err(|_| "Invalid remote: Failed to parse port")?,
157+
);
155158
rest = h;
156159
}
157160

158-
Ok(Remote {
161+
Ok(Self {
159162
user,
160163
host: rest.to_string(),
161164
port,
@@ -166,11 +169,11 @@ impl FromStr for Remote {
166169
impl Display for Remote {
167170
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
168171
if let Some(user) = &self.user {
169-
write!(f, "{}@", user)?;
172+
write!(f, "{user}@")?;
170173
}
171174
write!(f, "{}", self.host)?;
172175
if let Some(port) = &self.port {
173-
write!(f, ":{}", port)?;
176+
write!(f, ":{port}")?;
174177
}
175178
Ok(())
176179
}

0 commit comments

Comments
 (0)