diff options
author | Vika <vika@fireburn.ru> | 2021-12-06 20:49:58 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2021-12-06 21:00:02 +0300 |
commit | c02037628e36e71e528b3c76ffb88dc103d73228 (patch) | |
tree | e0d78a61af2f6e1ca7effcca1722f0da31293c05 /src/database/file | |
parent | 9a9776230ce8d12d305ca8db19cc76f20ae40926 (diff) | |
download | kittybox-c02037628e36e71e528b3c76ffb88dc103d73228.tar.zst |
Make rustfmt and clippy happy
Diffstat (limited to 'src/database/file')
-rw-r--r-- | src/database/file/mod.rs | 24 |
1 files changed, 13 insertions, 11 deletions
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<super::MicropubChannel>; - 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<super::MicropubChannel> = 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<String, String> = if content.len() == 0 { + let mut settings: HashMap<String, String> = if content.is_empty() { HashMap::default() } else { serde_json::from_str(&content)? |