From 9a6ad0e67b52e419c8a1c59c9cd187d1b85cd9f8 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 1 May 2022 13:56:13 +0300 Subject: chore: code cleanup --- src/database/file/mod.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/database/file') diff --git a/src/database/file/mod.rs b/src/database/file/mod.rs index 53dea04..853240a 100644 --- a/src/database/file/mod.rs +++ b/src/database/file/mod.rs @@ -5,9 +5,6 @@ use tokio::fs::{File, OpenOptions}; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::task::spawn_blocking; use async_trait::async_trait; -/*use futures_util::stream; -use futures_util::StreamExt; -use futures_util::TryStreamExt;*/ use futures::{stream, StreamExt, TryStreamExt}; use log::debug; use serde_json::json; @@ -111,7 +108,7 @@ fn url_to_path(root: &Path, url: &str) -> PathBuf { fn url_to_relative_path(url: &str) -> relative_path::RelativePathBuf { let url = warp::http::Uri::try_from(url).expect("Couldn't parse a URL"); let mut path = relative_path::RelativePathBuf::new(); - path.push(url.authority().unwrap().to_string() + &url.path().to_string() + ".json"); + path.push(url.authority().unwrap().to_string() + url.path() + ".json"); path } @@ -402,12 +399,11 @@ impl Storage for FileStorage { let mut content = String::new(); file.read_to_string(&mut content).await?; drop(file); - let mut channels: Vec; - if !content.is_empty() { - channels = serde_json::from_str(&content)?; + let mut channels: Vec = if !content.is_empty() { + serde_json::from_str(&content)? } else { - channels = Vec::default(); - } + Vec::default() + }; channels.push(super::MicropubChannel { uid: key.to_string(), @@ -614,6 +610,6 @@ impl Storage for FileStorage { tempfile.write_all(serde_json::to_string(&settings)?.as_bytes()).await?; drop(tempfile); tokio::fs::rename(temppath, path).await?; - Result::Ok(()) + Ok(()) } } -- cgit 1.4.1