From c02037628e36e71e528b3c76ffb88dc103d73228 Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 6 Dec 2021 20:49:58 +0300 Subject: Make rustfmt and clippy happy --- src/database/file/mod.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/database/file/mod.rs') diff --git a/src/database/file/mod.rs b/src/database/file/mod.rs index d556f46..ee7d30b 100644 --- a/src/database/file/mod.rs +++ b/src/database/file/mod.rs @@ -88,7 +88,7 @@ mod tests { } fn url_to_path(root: &Path, url: &str) -> PathBuf { - url_to_relative_path(url).to_path(root).to_path_buf() + url_to_relative_path(url).to_path(root) } fn url_to_relative_path(url: &str) -> relative_path::RelativePathBuf { @@ -321,11 +321,13 @@ impl Storage for FileStorage { let orig = path.clone(); spawn_blocking::<_, Result<()>>(move || { // We're supposed to have a parent here. - let basedir = link.parent().ok_or(StorageError::new( - ErrorKind::Backend, - "Failed to calculate parent directory when creating a symlink", - ))?; - let relative = path_relative_from(&orig, &basedir).unwrap(); + let basedir = link.parent().ok_or_else(|| { + StorageError::new( + ErrorKind::Backend, + "Failed to calculate parent directory when creating a symlink", + ) + })?; + let relative = path_relative_from(&orig, basedir).unwrap(); println!("{:?} - {:?} = {:?}", &orig, &basedir, &relative); println!("Created a symlink at {:?}", &link); let symlink_result; @@ -374,7 +376,7 @@ impl Storage for FileStorage { let mut content = String::new(); guard.read_to_string(&mut content).await?; let mut channels: Vec; - if content.len() > 0 { + if !content.is_empty() { channels = serde_json::from_str(&content)?; } else { channels = Vec::default(); @@ -385,7 +387,7 @@ impl Storage for FileStorage { name: post["properties"]["name"][0] .as_str() .map(|s| s.to_string()) - .unwrap_or_else(|| String::default()), + .unwrap_or_else(String::default), }); guard.seek(std::io::SeekFrom::Start(0)).await?; guard.set_len(0).await?; @@ -438,7 +440,7 @@ impl Storage for FileStorage { let mut content = String::new(); (&mut &*guard).read_to_string(&mut content).await?; // This should not happen, but if it does, let's handle it gracefully instead of failing. - if content.len() == 0 { + if content.is_empty() { return Ok(vec![]); } let channels: Vec = serde_json::from_str(&content)?; @@ -541,7 +543,7 @@ impl Storage for FileStorage { // it might come with a performance hit and/or memory usage inflation settings .get(setting) - .map(|s| s.clone()) + .cloned() .ok_or_else(|| StorageError::new(ErrorKind::Backend, "Setting not set")) } @@ -572,7 +574,7 @@ impl Storage for FileStorage { log::debug!("Locked. Writing."); let mut content = String::new(); guard.read_to_string(&mut content).await?; - let mut settings: HashMap = if content.len() == 0 { + let mut settings: HashMap = if content.is_empty() { HashMap::default() } else { serde_json::from_str(&content)? -- cgit 1.4.1