From a4e7c6b4447183f89cb974acddd0f3ec16249449 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Tue, 23 May 2023 18:03:27 -0500 Subject: [PATCH] change: Do not dereference str whenever possible --- actix/src/main.rs | 4 ++-- actix/src/utils.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/actix/src/main.rs b/actix/src/main.rs index f419800..439d5fe 100644 --- a/actix/src/main.rs +++ b/actix/src/main.rs @@ -70,12 +70,12 @@ async fn error404() -> impl Responder { async fn link_handler(shortlink: web::Path, data: web::Data) -> impl Responder { let shortlink_str = shortlink.to_string(); let longlink = utils::get_longurl(shortlink_str, &data.db); - if longlink == *"" { + if longlink.is_empty() { Redirect::to("/err/404") } else { let redirect_method = env::var("redirect_method").unwrap_or(String::from("PERMANENT")); database::add_hit(shortlink.as_str(), &data.db); - if redirect_method == *"TEMPORARY" { + if redirect_method == "TEMPORARY" { Redirect::to(longlink) } else { // Defaults to permanent redirection diff --git a/actix/src/utils.rs b/actix/src/utils.rs index b7c9d0a..d470643 100644 --- a/actix/src/utils.rs +++ b/actix/src/utils.rs @@ -28,14 +28,14 @@ pub fn add_link(req: String, db: &Connection) -> (bool, String) { let mut shortlink; if chunks.len() > 1 { shortlink = chunks[1].to_string().to_lowercase(); - if shortlink == *"" { + if shortlink.is_empty() { shortlink = random_name(); } } else { shortlink = random_name(); } - if validate_link(shortlink.as_str()) && get_longurl(shortlink.clone(), db) == *"" { + if validate_link(shortlink.as_str()) && get_longurl(shortlink.clone(), db).is_empty() { ( database::add_link(shortlink.clone(), longlink, db), shortlink,