From 732e2bd2f3b7b7e1f64d861676af820bd3abbfe8 Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Sun, 16 Jan 2022 00:49:42 -0800 Subject: [PATCH] Use fstrings where possible --- cli/src/main.rs | 6 +++--- server/src/main.rs | 26 +++++++++++++------------- web/src/decrypt.rs | 2 +- web/src/main.rs | 13 ++++++------- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 15828b5..f9b5631 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -162,14 +162,14 @@ fn handle_upload( url.set_fragment(Some(&fragment.build().expose_secret())); - println!("{}", url); + println!("{url}"); Ok(()) } fn handle_download(mut url: ParsedUrl) -> Result<()> { url.sanitized_url - .set_path(&format!("{}{}", API_ENDPOINT, url.sanitized_url.path())); + .set_path(&format!("{API_ENDPOINT}{}", url.sanitized_url.path())); let res = Client::new() .get(url.sanitized_url) .send() @@ -212,7 +212,7 @@ fn handle_download(mut url: ParsedUrl) -> Result<()> { std::io::stdout().write_all(&data)?; } - eprintln!("{}", expiration_text); + eprintln!("{expiration_text}"); Ok(()) } diff --git a/server/src/main.rs b/server/src/main.rs index 59edf2f..1029b55 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -97,7 +97,7 @@ async fn main() -> Result<()> { .route("/:code", get(|| async { INDEX_PAGE })) .nest("/static", root_service) .route( - &format!("{}{}", API_ENDPOINT, "/:code"), + &format!("{API_ENDPOINT}/:code"), get(paste::).delete(delete::), ) .layer(AddExtensionLayer::new(db)) @@ -163,11 +163,11 @@ fn set_up_expirations(db: &Arc) { if corrupted == 0 { info!("No corrupted pastes found."); } else { - warn!("Found {} corrupted pastes.", corrupted); + warn!("Found {corrupted} corrupted pastes."); } - info!("Found {} expired pastes.", expired); - info!("Found {} active pastes.", pending); + info!("Found {expired} expired pastes."); + info!("Found {pending} active pastes."); info!("Cleanup timers have been initialized."); } @@ -196,7 +196,7 @@ async fn upload( if let Some(header) = maybe_expires { if let Expiration::UnixTime(time) = header.0 { if (time - Utc::now()) > *MAX_PASTE_AGE { - warn!("{} exceeds allowed paste lifetime", time); + warn!("{time} exceeds allowed paste lifetime"); return Err(StatusCode::BAD_REQUEST); } } @@ -223,7 +223,7 @@ async fn upload( .await; if matches!(query, Ok(false)) { new_key = Some(key); - trace!("Found new key after {} attempts.", i); + trace!("Found new key after {i} attempts."); break; } } @@ -271,7 +271,7 @@ async fn upload( } } e => { - error!("Failed to insert paste into db: {:?}", e); + error!("Failed to insert paste into db: {e:?}"); return Err(StatusCode::INTERNAL_SERVER_ERROR); } } @@ -289,7 +289,7 @@ async fn paste( let metadata: Expiration = { let meta_cf = db.cf_handle(META_CF_NAME).unwrap(); let query_result = db.get_cf(meta_cf, key).map_err(|e| { - error!("Failed to fetch initial query: {}", e); + error!("Failed to fetch initial query: {e}"); StatusCode::INTERNAL_SERVER_ERROR })?; @@ -308,7 +308,7 @@ async fn paste( if let Expiration::UnixTime(expires) = metadata { if expires < Utc::now() { delete_entry(db, url.as_bytes()).await.map_err(|e| { - error!("Failed to join handle: {}", e); + error!("Failed to join handle: {e}"); StatusCode::INTERNAL_SERVER_ERROR })??; return Err(StatusCode::NOT_FOUND); @@ -319,7 +319,7 @@ async fn paste( // not sure if perf of get_pinned is better than spawn_blocking let blob_cf = db.cf_handle(BLOB_CF_NAME).unwrap(); let query_result = db.get_pinned_cf(blob_cf, key).map_err(|e| { - error!("Failed to fetch initial query: {}", e); + error!("Failed to fetch initial query: {e}"); StatusCode::INTERNAL_SERVER_ERROR })?; @@ -340,7 +340,7 @@ async fn paste( Expiration::BurnAfterReading | Expiration::BurnAfterReadingWithDeadline(_) ) { delete_entry(db, key).await.map_err(|e| { - error!("Failed to join handle: {}", e); + error!("Failed to join handle: {e}"); StatusCode::INTERNAL_SERVER_ERROR })??; } @@ -367,11 +367,11 @@ fn delete_entry(db: Arc, key: [u8; N]) -> JoinHandle, container: Vec) -> DecryptedData { log!("Unsupported: ", s.to_string()); } _ => { - log!(format!("Error: {}", err)); + log!(format!("Error: {err}")); } }, } diff --git a/web/src/main.rs b/web/src/main.rs index 54a8229..2103fb9 100644 --- a/web/src/main.rs +++ b/web/src/main.rs @@ -114,7 +114,7 @@ fn main() { Ok(partial_parsed_url) => partial_parsed_url, Err(e) => { error!("Failed to parse text fragment; bailing."); - render_message(format!("Invalid paste link: {}", e).into()); + render_message(format!("Invalid paste link: {e}").into()); return; } }; @@ -148,7 +148,7 @@ fn main() { } e => { render_message("Internal error occurred.".into()); - error!(format!("Error occurred at pw prompt: {:?}", e)); + error!(format!("Error occurred at pw prompt: {e:?}")); return; } } @@ -191,8 +191,7 @@ async fn fetch_resources( "Network failure: Failed to completely read encryption paste.".into(), ); bail!(format!( - "JsFuture returned an error while fetching resp buffer: {:?}", - e + "JsFuture returned an error while fetching resp buffer: {e:?}", )); } }; @@ -204,14 +203,14 @@ async fn fetch_resources( return Ok(()); } - let (decrypted, mimetype) = match decrypt(data, &key, password) { + let (decrypted, mimetype) = match decrypt(data, &key, password, name.as_deref()) { Ok(data) => data, Err(e) => { let msg = match e { CryptoError::Password => "The provided password was incorrect.", CryptoError::SecretKey => "The secret key in the URL was incorrect.", ref e => { - log!(format!("Bad kdf or corrupted blob: {}", e)); + log!(format!("Bad kdf or corrupted blob: {e}")); "An internal error occurred." } }; @@ -248,7 +247,7 @@ async fn fetch_resources( render_message(err.status_text().into()); } Err(err) => { - render_message(format!("{}", err).into()); + render_message(format!("{err}").into()); } }