From e83b8e6f4a108040cd7bf83d3705047ab19018fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sun, 18 Dec 2022 23:12:28 +0300 Subject: [PATCH] fix(lints): apply clippy suggestions --- src/main.rs | 2 +- src/paste.rs | 6 +++--- src/server.rs | 28 ++++++++++++++-------------- src/util.rs | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index badcf04..55e3afc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,7 +80,7 @@ async fn main() -> IoResult<()> { }; hotwatch .watch(&config_path, config_watcher) - .unwrap_or_else(|_| panic!("failed to watch {:?}", config_path)); + .unwrap_or_else(|_| panic!("failed to watch {config_path:?}")); // Create a thread for cleaning up expired files. thread::spawn(move || loop { diff --git a/src/paste.rs b/src/paste.rs index 34d185c..44e26bb 100644 --- a/src/paste.rs +++ b/src/paste.rs @@ -139,7 +139,7 @@ impl Paste { .unwrap_or_default() .to_string(); if let Some(timestamp) = expiry_date { - path.set_file_name(format!("{}.{}", file_name, timestamp)); + path.set_file_name(format!("{file_name}.{timestamp}")); } let mut buffer = File::create(&path)?; buffer.write_all(&self.data)?; @@ -225,7 +225,7 @@ impl Paste { .get_path(&config.server.upload_path) .join(&file_name); if let Some(timestamp) = expiry_date { - path.set_file_name(format!("{}.{}", file_name, timestamp)); + path.set_file_name(format!("{file_name}.{timestamp}")); } fs::write(&path, url.to_string())?; Ok(file_name) @@ -303,7 +303,7 @@ mod tests { let file_name = paste.store_file("test.file", Some(expiry_date), &config)?; let file_path = PasteType::Oneshot .get_path(&config.server.upload_path) - .join(format!("{}.{}", file_name, expiry_date)); + .join(format!("{file_name}.{expiry_date}")); assert_eq!("test", fs::read_to_string(&file_path)?); fs::remove_file(file_path)?; diff --git a/src/server.rs b/src/server.rs index eab55a6..dc0ff3e 100644 --- a/src/server.rs +++ b/src/server.rs @@ -454,10 +454,10 @@ mod tests { ) .await; assert_eq!(StatusCode::OK, response.status()); - assert_body(response, &format!("http://localhost:8080/{}\n", file_name)).await?; + assert_body(response, &format!("http://localhost:8080/{file_name}\n")).await?; let serve_request = TestRequest::get() - .uri(&format!("/{}", file_name)) + .uri(&format!("/{file_name}")) .to_request(); let response = test::call_service(&app, serve_request).await; assert_eq!(StatusCode::OK, response.status()); @@ -465,7 +465,7 @@ mod tests { fs::remove_file(file_name)?; let serve_request = TestRequest::get() - .uri(&format!("/{}", file_name)) + .uri(&format!("/{file_name}")) .to_request(); let response = test::call_service(&app, serve_request).await; assert_eq!(StatusCode::NOT_FOUND, response.status()); @@ -548,10 +548,10 @@ mod tests { ) .await; assert_eq!(StatusCode::OK, response.status()); - assert_body(response, &format!("http://localhost:8080/{}\n", file_name)).await?; + assert_body(response, &format!("http://localhost:8080/{file_name}\n")).await?; let serve_request = TestRequest::get() - .uri(&format!("/{}", file_name)) + .uri(&format!("/{file_name}")) .to_request(); let response = test::call_service(&app, serve_request).await; assert_eq!(StatusCode::OK, response.status()); @@ -560,12 +560,12 @@ mod tests { thread::sleep(Duration::from_millis(40)); let serve_request = TestRequest::get() - .uri(&format!("/{}", file_name)) + .uri(&format!("/{file_name}")) .to_request(); let response = test::call_service(&app, serve_request).await; assert_eq!(StatusCode::NOT_FOUND, response.status()); - if let Some(glob_path) = glob(&format!("{}.[0-9]*", file_name)) + if let Some(glob_path) = glob(&format!("{file_name}.[0-9]*")) .map_err(error::ErrorInternalServerError)? .next() { @@ -605,10 +605,10 @@ mod tests { ) .await; assert_eq!(StatusCode::OK, response.status()); - assert_body(response, &format!("http://localhost:8080/{}\n", file_name)).await?; + assert_body(response, &format!("http://localhost:8080/{file_name}\n")).await?; let serve_request = TestRequest::get() - .uri(&format!("/{}", file_name)) + .uri(&format!("/{file_name}")) .to_request(); let response = test::call_service(&app, serve_request).await; assert_eq!(StatusCode::OK, response.status()); @@ -623,7 +623,7 @@ mod tests { fs::remove_file(file_name)?; let serve_request = TestRequest::get() - .uri(&format!("/{}", file_name)) + .uri(&format!("/{file_name}")) .to_request(); let response = test::call_service(&app, serve_request).await; assert_eq!(StatusCode::NOT_FOUND, response.status()); @@ -695,24 +695,24 @@ mod tests { ) .await; assert_eq!(StatusCode::OK, response.status()); - assert_body(response, &format!("http://localhost:8080/{}\n", file_name)).await?; + assert_body(response, &format!("http://localhost:8080/{file_name}\n")).await?; let serve_request = TestRequest::get() - .uri(&format!("/{}", file_name)) + .uri(&format!("/{file_name}")) .to_request(); let response = test::call_service(&app, serve_request).await; assert_eq!(StatusCode::OK, response.status()); assert_body(response, ×tamp).await?; let serve_request = TestRequest::get() - .uri(&format!("/{}", file_name)) + .uri(&format!("/{file_name}")) .to_request(); let response = test::call_service(&app, serve_request).await; assert_eq!(StatusCode::NOT_FOUND, response.status()); if let Some(glob_path) = glob( &oneshot_upload_path - .join(format!("{}.[0-9]*", file_name)) + .join(format!("{file_name}.[0-9]*")) .to_string_lossy(), ) .map_err(error::ErrorInternalServerError)? diff --git a/src/util.rs b/src/util.rs index 93fce27..d4126e2 100644 --- a/src/util.rs +++ b/src/util.rs @@ -94,7 +94,7 @@ pub fn sha256_digest(input: R) -> Result { .iter() .collect::>() .iter() - .map(|byte| format!("{:02x}", byte)) + .map(|byte| format!("{byte:02x}")) .collect::()) } @@ -148,7 +148,7 @@ mod tests { fn test_get_expired_files() -> Result<(), ActixError> { let current_dir = env::current_dir()?; let expiration_time = get_system_time()?.as_millis() + 50; - let path = PathBuf::from(format!("expired.file2.{}", expiration_time)); + let path = PathBuf::from(format!("expired.file2.{expiration_time}")); fs::write(&path, String::new())?; assert_eq!(Vec::::new(), get_expired_files(¤t_dir)); thread::sleep(Duration::from_millis(75));