diff --git a/actix/src/auth.rs b/actix/src/auth.rs index 336b03e..25a56bd 100644 --- a/actix/src/auth.rs +++ b/actix/src/auth.rs @@ -31,7 +31,7 @@ fn check(token: Option) -> bool { } pub fn gen_token() -> String { - let token_text = "session-token".to_string(); + let token_text = String::from("session-token"); let time = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .expect("Time went backwards!") diff --git a/actix/src/database.rs b/actix/src/database.rs index 5057570..0c903f9 100644 --- a/actix/src/database.rs +++ b/actix/src/database.rs @@ -9,7 +9,7 @@ pub fn find_url(shortlink: &str, db: &Connection) -> String { .query_map([shortlink], |row| row.get("long_url")) .unwrap(); - let mut longlink = "".to_string(); + let mut longlink = String::new(); for link in links { longlink = link.unwrap(); } diff --git a/actix/src/main.rs b/actix/src/main.rs index 06772da..f419800 100644 --- a/actix/src/main.rs +++ b/actix/src/main.rs @@ -50,7 +50,7 @@ async fn getall(data: web::Data, session: Session) -> HttpResponse { #[get("/api/siteurl")] async fn siteurl(session: Session) -> HttpResponse { if auth::validate(session) { - let site_url = env::var("site_url").unwrap_or("unset".to_string()); + let site_url = env::var("site_url").unwrap_or(String::from("unset")); HttpResponse::Ok().body(site_url) } else { HttpResponse::Forbidden().body("logged_out") @@ -73,7 +73,7 @@ async fn link_handler(shortlink: web::Path, data: web::Data) - if longlink == *"" { Redirect::to("/err/404") } else { - let redirect_method = env::var("redirect_method").unwrap_or("PERMANENT".to_string()); + let redirect_method = env::var("redirect_method").unwrap_or(String::from("PERMANENT")); database::add_hit(shortlink.as_str(), &data.db); if redirect_method == *"TEMPORARY" { Redirect::to(longlink) @@ -118,9 +118,9 @@ async fn main() -> std::io::Result<()> { // Generate session key in runtime so that restart invalidates older logins let secret_key = Key::generate(); - let db_location = env::var("db_url").unwrap_or("/urls.sqlite".to_string()); + let db_location = env::var("db_url").unwrap_or(String::from("/urls.sqlite")); let port = env::var("port") - .unwrap_or("4567".to_string()) + .unwrap_or(String::from("4567")) .parse::() .expect("Supplied port is not an integer"); diff --git a/actix/src/utils.rs b/actix/src/utils.rs index c798a51..b7c9d0a 100644 --- a/actix/src/utils.rs +++ b/actix/src/utils.rs @@ -7,7 +7,7 @@ pub fn get_longurl(shortlink: String, db: &Connection) -> String { if validate_link(&shortlink) { database::find_url(shortlink.as_str(), db) } else { - "".to_string() + String::new() } } @@ -23,7 +23,7 @@ pub fn getall(db: &Connection) -> String { pub fn add_link(req: String, db: &Connection) -> (bool, String) { let chunks: Vec<&str> = req.split(';').collect(); - let longlink = chunks[0].to_string(); + let longlink = String::from(chunks[0]); let mut shortlink; if chunks.len() > 1 { @@ -41,7 +41,7 @@ pub fn add_link(req: String, db: &Connection) -> (bool, String) { shortlink, ) } else { - (false, "shortUrl not valid or already in use".to_string()) + (false, String::from("shortUrl not valid or already in use")) } }