chore: more pedantic clippy suggestions

This commit is contained in:
Cheong Lau 2025-10-26 16:20:51 +10:00
parent 5863671217
commit 5f729829d7
17 changed files with 1063 additions and 998 deletions

View file

@ -34,24 +34,28 @@ pub(crate) fn err_str<T: ToString>(err: T) -> String {
}
pub fn desktop_dir() -> PathBuf {
match dirs::desktop_dir() {
Some(path) => path,
None => {
let path = home_dir().join("Desktop");
log::warn!("failed to locate desktop directory, falling back to {path:?}");
path
}
if let Some(path) = dirs::desktop_dir() {
path
} else {
let path = home_dir().join("Desktop");
log::warn!(
"failed to locate desktop directory, falling back to {}",
path.display()
);
path
}
}
pub fn home_dir() -> PathBuf {
match dirs::home_dir() {
Some(home) => home,
None => {
let path = PathBuf::from("/");
log::warn!("failed to locate home directory, falling back to {path:?}");
path
}
if let Some(home) = dirs::home_dir() {
home
} else {
let path = PathBuf::from("/");
log::warn!(
"failed to locate home directory, falling back to {}",
path.display()
);
path
}
}
@ -123,12 +127,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
} else {
//TODO: support more URLs
let path = match url::Url::parse(&arg) {
Ok(url) if url.scheme() == "file" => match url.to_file_path() {
Ok(path) => path,
Err(()) => {
log::warn!("invalid argument {:?}", arg);
continue;
}
Ok(url) if url.scheme() == "file" => if let Ok(path) = url.to_file_path() { path } else {
log::warn!("invalid argument {arg:?}");
continue;
},
Ok(url) => {
uris.push(url);
@ -139,7 +140,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
match fs::canonicalize(&path) {
Ok(absolute) => Location::Path(absolute),
Err(err) => {
log::warn!("failed to canonicalize {:?}: {}", path, err);
log::warn!("failed to canonicalize {}: {}", path.display(), err);
continue;
}
}
@ -153,7 +154,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(fork::Fork::Child) => (),
Ok(fork::Fork::Parent(_child_pid)) => process::exit(0),
Err(err) => {
eprintln!("failed to daemonize: {:?}", err);
eprintln!("failed to daemonize: {err:?}");
process::exit(1);
}
}