diff --git a/auth/casbin/src/main.rs b/auth/casbin/src/main.rs index 1858f20..ff2cf90 100644 --- a/auth/casbin/src/main.rs +++ b/auth/casbin/src/main.rs @@ -7,7 +7,7 @@ use actix_web::{middleware, web, App, HttpRequest, HttpResponse, HttpServer}; /// simple handle async fn success(enforcer: web::Data>, req: HttpRequest) -> HttpResponse { let mut e = enforcer.write().await; - println!("{:?}", req); + println!("{req:?}"); assert_eq!(vec!["data2_admin"], e.get_roles_for_user("alice", None)); HttpResponse::Ok().body("Success: alice is data2_admin.") @@ -15,7 +15,7 @@ async fn success(enforcer: web::Data>, req: HttpRequest) -> Htt async fn fail(enforcer: web::Data>, req: HttpRequest) -> HttpResponse { let mut e = enforcer.write().await; - println!("{:?}", req); + println!("{req:?}"); assert_eq!(vec!["data1_admin"], e.get_roles_for_user("alice", None)); HttpResponse::Ok().body("Fail: alice is not data1_admin.") // In fact, it can't be displayed. diff --git a/auth/cookie-session/src/main.rs b/auth/cookie-session/src/main.rs index 1dd5b0e..a1c2298 100644 --- a/auth/cookie-session/src/main.rs +++ b/auth/cookie-session/src/main.rs @@ -10,12 +10,12 @@ use actix_web::{middleware::Logger, web, App, HttpRequest, HttpServer, Result}; /// simple index handler with session async fn index(session: Session, req: HttpRequest) -> Result<&'static str> { - log::info!("{:?}", req); + log::info!("{req:?}"); // RequestSession trait is used for session access let mut counter = 1; if let Some(count) = session.get::("counter")? { - log::info!("SESSION value: {}", count); + log::info!("SESSION value: {count}"); counter = count + 1; session.insert("counter", counter)?; } else { diff --git a/auth/redis-session/src/main.rs b/auth/redis-session/src/main.rs index 18c5af4..a897da8 100644 --- a/auth/redis-session/src/main.rs +++ b/auth/redis-session/src/main.rs @@ -65,7 +65,7 @@ async fn logout(session: Session) -> Result { let id: Option = session.get("user_id")?; if let Some(x) = id { session.purge(); - Ok(format!("Logged out: {}", x)) + Ok(format!("Logged out: {x}")) } else { Ok("Could not log out anonymous user".into()) } diff --git a/basics/basics/src/main.rs b/basics/basics/src/main.rs index a8186e8..33a0edd 100644 --- a/basics/basics/src/main.rs +++ b/basics/basics/src/main.rs @@ -22,12 +22,12 @@ async fn favicon() -> Result { /// simple index handler #[get("/welcome")] async fn welcome(req: HttpRequest, session: Session) -> Result { - println!("{:?}", req); + println!("{req:?}"); // session let mut counter = 1; if let Some(count) = session.get::("counter")? { - println!("SESSION value: {}", count); + println!("SESSION value: {count}"); counter = count + 1; } @@ -63,7 +63,7 @@ async fn response_body(path: web::Path) -> HttpResponse { /// handler with path parameters like `/user/{name}/` async fn with_param(req: HttpRequest, path: web::Path<(String,)>) -> HttpResponse { - println!("{:?}", req); + println!("{req:?}"); HttpResponse::Ok() .content_type(ContentType::plaintext()) @@ -110,7 +110,7 @@ async fn main() -> io::Result<()> { // redirect .service( web::resource("/").route(web::get().to(|req: HttpRequest| async move { - println!("{:?}", req); + println!("{req:?}"); HttpResponse::Found() .insert_header((header::LOCATION, "static/welcome.html")) .finish() diff --git a/basics/hello-world/src/main.rs b/basics/hello-world/src/main.rs index 9f6ebe2..e38da71 100644 --- a/basics/hello-world/src/main.rs +++ b/basics/hello-world/src/main.rs @@ -1,7 +1,7 @@ use actix_web::{middleware, web, App, HttpRequest, HttpServer}; async fn index(req: HttpRequest) -> &'static str { - println!("REQ: {:?}", req); + println!("REQ: {req:?}"); "Hello world!" } diff --git a/basics/state/src/main.rs b/basics/state/src/main.rs index 4142463..0d37bdf 100644 --- a/basics/state/src/main.rs +++ b/basics/state/src/main.rs @@ -36,7 +36,7 @@ async fn index( counter_atomic: Data, req: HttpRequest, ) -> HttpResponse { - println!("{:?}", req); + println!("{req:?}"); // Increment the counters *counter_mutex.lock().unwrap() += 1; diff --git a/basics/todo/src/api.rs b/basics/todo/src/api.rs index 15f9431..173e48a 100644 --- a/basics/todo/src/api.rs +++ b/basics/todo/src/api.rs @@ -80,7 +80,7 @@ pub async fn update( "put" => toggle(db, params).await, "delete" => delete(db, params, session).await, unsupported_method => { - let msg = format!("Unsupported HTTP method: {}", unsupported_method); + let msg = format!("Unsupported HTTP method: {unsupported_method}"); Err(error::ErrorBadRequest(msg)) } } diff --git a/cors/backend/src/user.rs b/cors/backend/src/user.rs index 7766494..a7a1120 100644 --- a/cors/backend/src/user.rs +++ b/cors/backend/src/user.rs @@ -11,7 +11,7 @@ pub struct Info { #[post("/user/info")] pub async fn info(info: web::Json) -> web::Json { - println!("=========={:?}=========", info); + println!("=========={info:?}========="); web::Json(Info { username: info.username.clone(), email: info.email.clone(), diff --git a/databases/diesel/src/main.rs b/databases/diesel/src/main.rs index 5d8c6ee..62c68e3 100644 --- a/databases/diesel/src/main.rs +++ b/databases/diesel/src/main.rs @@ -36,7 +36,7 @@ async fn get_user( if let Some(user) = user { Ok(HttpResponse::Ok().json(user)) } else { - let res = HttpResponse::NotFound().body(format!("No user found with uid: {}", user_uid)); + let res = HttpResponse::NotFound().body(format!("No user found with uid: {user_uid}")); Ok(res) } } diff --git a/databases/mongodb/src/main.rs b/databases/mongodb/src/main.rs index 8dc22c5..e5f88a4 100644 --- a/databases/mongodb/src/main.rs +++ b/databases/mongodb/src/main.rs @@ -34,7 +34,7 @@ async fn get_user(client: web::Data, username: web::Path) -> Htt { Ok(Some(user)) => HttpResponse::Ok().json(user), Ok(None) => { - HttpResponse::NotFound().body(format!("No user found with username {}", username)) + HttpResponse::NotFound().body(format!("No user found with username {username}")) } Err(err) => HttpResponse::InternalServerError().body(err.to_string()), } diff --git a/databases/redis/src/main.rs b/databases/redis/src/main.rs index 0f95ad2..da822cc 100644 --- a/databases/redis/src/main.rs +++ b/databases/redis/src/main.rs @@ -64,7 +64,7 @@ async fn del_stuff(redis: web::Data>) -> actix_web::Result { - log::error!("{:?}", res); + log::error!("{res:?}"); Ok(HttpResponse::InternalServerError().finish()) } } diff --git a/forms/form/src/main.rs b/forms/form/src/main.rs index 547c09b..2c4bef3 100644 --- a/forms/form/src/main.rs +++ b/forms/form/src/main.rs @@ -62,7 +62,7 @@ async fn handle_post_2( /// Request and POST Params async fn handle_post_3(req: HttpRequest, params: web::Form) -> impl Responder { - println!("Handling POST request: {:?}", req); + println!("Handling POST request: {req:?}"); HttpResponse::Ok() .content_type("text/plain") diff --git a/forms/multipart-s3/src/main.rs b/forms/multipart-s3/src/main.rs index 0d32702..1522a27 100644 --- a/forms/multipart-s3/src/main.rs +++ b/forms/multipart-s3/src/main.rs @@ -81,9 +81,9 @@ async fn main() -> std::io::Result<()> { let aws_s3_bucket_name = env::var("AWS_S3_BUCKET_NAME").expect("AWS_S3_BUCKET_NAME must be set"); - log::info!("aws_access_key_id: {}", aws_access_key_id); - log::info!("aws_secret_access_key: {}", aws_secret_access_key); - log::info!("aws_s3_bucket_name: {}", aws_s3_bucket_name); + log::info!("aws_access_key_id: {aws_access_key_id}"); + log::info!("aws_secret_access_key: {aws_secret_access_key}"); + log::info!("aws_s3_bucket_name: {aws_s3_bucket_name}"); std::fs::create_dir_all("./tmp").unwrap(); diff --git a/forms/multipart-s3/src/utils/s3.rs b/forms/multipart-s3/src/utils/s3.rs index 5e2aaee..8a354c9 100644 --- a/forms/multipart-s3/src/utils/s3.rs +++ b/forms/multipart-s3/src/utils/s3.rs @@ -24,10 +24,9 @@ impl Client { pub fn url(&self, key: &str) -> String { format!( - "https://{}.s3.{}.amazonaws.com/{}", + "https://{}.s3.{}.amazonaws.com/{key}", std::env::var("AWS_S3_BUCKET_NAME").unwrap(), std::env::var("AWS_REGION").unwrap(), - key ) } diff --git a/forms/multipart-s3/src/utils/upload.rs b/forms/multipart-s3/src/utils/upload.rs index 04717ba..dd5be03 100644 --- a/forms/multipart-s3/src/utils/upload.rs +++ b/forms/multipart-s3/src/utils/upload.rs @@ -39,7 +39,7 @@ impl Tmpfile { fn new(filename: &str) -> Tmpfile { Tmpfile { name: filename.to_string(), - tmp_path: format!("./tmp/{}", filename), + tmp_path: format!("./tmp/{filename}"), s3_key: "".to_string(), s3_url: "".to_string(), } @@ -51,7 +51,7 @@ impl Tmpfile { } async fn s3_upload(&mut self, s3_upload_key: String) { - let key = format!("{}{}", &s3_upload_key, &self.name); + let key = format!("{s3_upload_key}{}", &self.name); self.s3_key = key.clone(); let url: String = Client::new().put_object(&self.tmp_path, &key.clone()).await; self.s3_url = url; diff --git a/forms/multipart/src/main.rs b/forms/multipart/src/main.rs index 7971e3a..d829e4e 100644 --- a/forms/multipart/src/main.rs +++ b/forms/multipart/src/main.rs @@ -14,7 +14,7 @@ async fn save_file(mut payload: Multipart) -> Result { let filename = content_disposition .get_filename() .map_or_else(|| Uuid::new_v4().to_string(), sanitize_filename::sanitize); - let filepath = format!("./tmp/{}", filename); + let filepath = format!("./tmp/{filename}"); // File::create is blocking operation, use threadpool let mut f = web::block(|| std::fs::File::create(filepath)).await??; diff --git a/http-proxy/src/main.rs b/http-proxy/src/main.rs index 99edfec..03c32a6 100644 --- a/http-proxy/src/main.rs +++ b/http-proxy/src/main.rs @@ -59,7 +59,7 @@ async fn main() -> std::io::Result<()> { .next() .expect("given forwarding address was not valid"); - let forward_url = format!("http://{}", forward_socket_addr); + let forward_url = format!("http://{forward_socket_addr}"); let forward_url = Url::parse(&forward_url).unwrap(); log::info!( diff --git a/https-tls/openssl-auto-le/src/main.rs b/https-tls/openssl-auto-le/src/main.rs index a621f34..dfa08c4 100644 --- a/https-tls/openssl-auto-le/src/main.rs +++ b/https-tls/openssl-auto-le/src/main.rs @@ -90,7 +90,7 @@ pub async fn gen_tls_cert(user_email: &str, user_domain: &str) -> anyhow::Result let proof = chall.http_proof()?; // Place the file/contents in the correct place. - let path = format!("acme-challenge/{}", token); + let path = format!("acme-challenge/{token}"); fs::write(&path, &proof)?; // After the file is accessible from the web, the calls diff --git a/https-tls/openssl/src/main.rs b/https-tls/openssl/src/main.rs index 40108ae..64a7b0c 100644 --- a/https-tls/openssl/src/main.rs +++ b/https-tls/openssl/src/main.rs @@ -5,7 +5,7 @@ use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod}; /// simple handle async fn index(req: HttpRequest) -> Result { - println!("{:?}", req); + println!("{req:?}"); Ok(HttpResponse::Ok() .content_type("text/plain") .body("Welcome!")) diff --git a/https-tls/rustls/src/main.rs b/https-tls/rustls/src/main.rs index b0785d7..c1d3286 100644 --- a/https-tls/rustls/src/main.rs +++ b/https-tls/rustls/src/main.rs @@ -11,7 +11,7 @@ use rustls_pemfile::{certs, pkcs8_private_keys}; /// simple handle async fn index(req: HttpRequest) -> HttpResponse { - debug!("{:?}", req); + debug!("{req:?}"); HttpResponse::Ok().content_type(ContentType::html()).body( "\ diff --git a/json/json-validation/src/main.rs b/json/json-validation/src/main.rs index 250b8f8..610e2f9 100644 --- a/json/json-validation/src/main.rs +++ b/json/json-validation/src/main.rs @@ -59,7 +59,7 @@ async fn step_x(data: SomeData, client: &Client) -> actix_web::Result let body: HttpBinResponse = serde_json::from_slice(&body).unwrap(); - println!("{:?}", body); + println!("{body:?}"); Ok(body.json) } diff --git a/json/json/src/main.rs b/json/json/src/main.rs index 11de7fe..b6754c2 100644 --- a/json/json/src/main.rs +++ b/json/json/src/main.rs @@ -17,8 +17,8 @@ async fn index(item: web::Json) -> HttpResponse { /// This handler uses json extractor with limit async fn extract_item(item: web::Json, req: HttpRequest) -> HttpResponse { - println!("request: {:?}", req); - println!("model: {:?}", item); + println!("request: {req:?}"); + println!("model: {item:?}"); HttpResponse::Ok().json(item.0) // <- send json response } diff --git a/json/jsonrpc/src/main.rs b/json/jsonrpc/src/main.rs index d288b34..91388bc 100644 --- a/json/jsonrpc/src/main.rs +++ b/json/jsonrpc/src/main.rs @@ -70,7 +70,7 @@ async fn rpc_select( .await { Ok(ok) => Ok(Value::from(ok)), - Err(e) => Err(convention::ErrorData::new(500, &format!("{:?}", e)[..])), + Err(e) => Err(convention::ErrorData::new(500, &format!("{e:?}")[..])), } } "get" => { diff --git a/middleware/middleware-http-to-https/src/main.rs b/middleware/middleware-http-to-https/src/main.rs index d41745e..e3ceb32 100644 --- a/middleware/middleware-http-to-https/src/main.rs +++ b/middleware/middleware-http-to-https/src/main.rs @@ -41,7 +41,7 @@ async fn main() -> std::io::Result<()> { .wrap_fn(|sreq, srv| { let host = sreq.connection_info().host().to_owned(); let uri = sreq.uri().to_owned(); - let url = format!("https://{}{}", host, uri); + let url = format!("https://{host}{uri}"); // If the scheme is "https" then it will let other services below this wrap_fn // handle the request and if it's "http" then a response with redirect status code diff --git a/middleware/middleware/src/read_request_body.rs b/middleware/middleware/src/read_request_body.rs index 40d3859..9896cc9 100644 --- a/middleware/middleware/src/read_request_body.rs +++ b/middleware/middleware/src/read_request_body.rs @@ -58,7 +58,7 @@ where body.extend_from_slice(&chunk?); } - println!("request body: {:?}", body); + println!("request body: {body:?}"); let res = svc.call(req).await?; println!("response: {:?}", res.headers()); diff --git a/protobuf/src/main.rs b/protobuf/src/main.rs index bb189f0..3fa291a 100644 --- a/protobuf/src/main.rs +++ b/protobuf/src/main.rs @@ -12,7 +12,7 @@ pub struct MyObj { } async fn index(msg: ProtoBuf) -> Result { - log::info!("model: {:?}", msg); + log::info!("model: {msg:?}"); HttpResponse::Ok().protobuf(msg.0) // <- send response } diff --git a/run-in-thread/src/main.rs b/run-in-thread/src/main.rs index 8de935e..845692a 100644 --- a/run-in-thread/src/main.rs +++ b/run-in-thread/src/main.rs @@ -7,7 +7,7 @@ use std::{sync::mpsc, thread, time}; use actix_web::{dev::ServerHandle, middleware, rt, web, App, HttpRequest, HttpServer}; async fn index(req: HttpRequest) -> &'static str { - log::info!("REQ: {:?}", req); + log::info!("REQ: {req:?}"); "Hello world!" } diff --git a/websockets/chat-broker/src/server.rs b/websockets/chat-broker/src/server.rs index ed53337..f09ed77 100644 --- a/websockets/chat-broker/src/server.rs +++ b/websockets/chat-broker/src/server.rs @@ -75,9 +75,8 @@ impl Handler for WsChatServer { let id = self.add_client_to_room(&room_name, None, client); let join_msg = format!( - "{} joined {}", + "{} joined {room_name}", client_name.unwrap_or_else(|| "anon".to_string()), - room_name ); self.send_chat_message(&room_name, &join_msg, id); diff --git a/websockets/chat-broker/src/session.rs b/websockets/chat-broker/src/session.rs index 84afc7d..30f7a41 100644 --- a/websockets/chat-broker/src/session.rs +++ b/websockets/chat-broker/src/session.rs @@ -63,9 +63,8 @@ impl WsChatSession { pub fn send_msg(&self, msg: &str) { let content = format!( - "{}: {}", + "{}: {msg}", self.name.clone().unwrap_or_else(|| "anon".to_string()), - msg ); let msg = SendMessage(self.room.clone(), self.id, content); @@ -110,7 +109,7 @@ impl StreamHandler> for WsChatSession { Ok(msg) => msg, }; - log::debug!("WEBSOCKET MESSAGE: {:?}", msg); + log::debug!("WEBSOCKET MESSAGE: {msg:?}"); match msg { ws::Message::Text(text) => { @@ -133,13 +132,13 @@ impl StreamHandler> for WsChatSession { Some("/name") => { if let Some(name) = command.next() { self.name = Some(name.to_owned()); - ctx.text(format!("name changed to: {}", name)); + ctx.text(format!("name changed to: {name}")); } else { ctx.text("!!! name is required"); } } - _ => ctx.text(format!("!!! unknown command: {:?}", msg)), + _ => ctx.text(format!("!!! unknown command: {msg:?}")), } return; diff --git a/websockets/chat-tcp/src/client.rs b/websockets/chat-tcp/src/client.rs index 0ea94b3..16ef0a3 100644 --- a/websockets/chat-tcp/src/client.rs +++ b/websockets/chat-tcp/src/client.rs @@ -40,23 +40,23 @@ async fn main() { Some(msg) = framed.next() => { match msg { Ok(codec::ChatResponse::Message(ref msg)) => { - println!("message: {}", msg); + println!("message: {msg}"); } Ok(codec::ChatResponse::Joined(ref msg)) => { - println!("!!! joined: {}", msg); + println!("!!! joined: {msg}"); } Ok(codec::ChatResponse::Rooms(rooms)) => { println!("!!! Available rooms:"); for room in rooms { - println!("{}", room); + println!("{room}"); } } // respond to pings with a "pong" Ok(codec::ChatResponse::Ping) => { framed.send(codec::ChatRequest::Ping).await.unwrap(); }, - _ => { eprintln!("{:?}", msg); } + _ => { eprintln!("{msg:?}"); } } } diff --git a/websockets/chat-tcp/src/main.rs b/websockets/chat-tcp/src/main.rs index 125eb18..f006e0b 100644 --- a/websockets/chat-tcp/src/main.rs +++ b/websockets/chat-tcp/src/main.rs @@ -110,7 +110,7 @@ impl StreamHandler> for WsChatSession { Ok(msg) => msg, }; - log::debug!("WEBSOCKET MESSAGE: {:?}", msg); + log::debug!("WEBSOCKET MESSAGE: {msg:?}"); match msg { ws::Message::Ping(msg) => { self.hb = Instant::now(); @@ -168,11 +168,11 @@ impl StreamHandler> for WsChatSession { ctx.text("!!! name is required"); } } - _ => ctx.text(format!("!!! unknown command: {:?}", m)), + _ => ctx.text(format!("!!! unknown command: {m:?}")), } } else { let msg = if let Some(ref name) = self.name { - format!("{}: {}", name, m) + format!("{name}: {m}") } else { m.to_owned() }; diff --git a/websockets/chat-tcp/src/session.rs b/websockets/chat-tcp/src/session.rs index 687548e..42f4a04 100644 --- a/websockets/chat-tcp/src/session.rs +++ b/websockets/chat-tcp/src/session.rs @@ -102,7 +102,7 @@ impl StreamHandler> for ChatSession { // so actor wont receive any new messages until it get list of rooms back } Ok(ChatRequest::Join(name)) => { - println!("Join to room: {}", name); + println!("Join to room: {name}"); self.room = name.clone(); self.addr.do_send(server::Join { id: self.id, @@ -112,7 +112,7 @@ impl StreamHandler> for ChatSession { } Ok(ChatRequest::Message(message)) => { // send message to chat server - println!("Peer message: {}", message); + println!("Peer message: {message}"); self.addr.do_send(server::Message { id: self.id, msg: message, diff --git a/websockets/chat/src/main.rs b/websockets/chat/src/main.rs index 13ddcdb..932810f 100644 --- a/websockets/chat/src/main.rs +++ b/websockets/chat/src/main.rs @@ -42,7 +42,7 @@ async fn chat_route( /// Displays state async fn get_count(count: web::Data) -> impl Responder { let current_count = count.load(Ordering::SeqCst); - format!("Visitors: {}", current_count) + format!("Visitors: {current_count}") } #[actix_web::main] diff --git a/websockets/chat/src/server.rs b/websockets/chat/src/server.rs index fb23691..6861cb1 100644 --- a/websockets/chat/src/server.rs +++ b/websockets/chat/src/server.rs @@ -135,7 +135,7 @@ impl Handler for ChatServer { .insert(id); let count = self.visitor_count.fetch_add(1, Ordering::SeqCst); - self.send_message("Main", &format!("Total visitors {}", count), 0); + self.send_message("Main", &format!("Total visitors {count}"), 0); // send id back id diff --git a/websockets/chat/src/session.rs b/websockets/chat/src/session.rs index 8594711..ce3f418 100644 --- a/websockets/chat/src/session.rs +++ b/websockets/chat/src/session.rs @@ -114,7 +114,7 @@ impl StreamHandler> for WsChatSession { Ok(msg) => msg, }; - log::debug!("WEBSOCKET MESSAGE: {:?}", msg); + log::debug!("WEBSOCKET MESSAGE: {msg:?}"); match msg { ws::Message::Ping(msg) => { self.hb = Instant::now(); @@ -172,11 +172,11 @@ impl StreamHandler> for WsChatSession { ctx.text("!!! name is required"); } } - _ => ctx.text(format!("!!! unknown command: {:?}", m)), + _ => ctx.text(format!("!!! unknown command: {m:?}")), } } else { let msg = if let Some(ref name) = self.name { - format!("{}: {}", name, m) + format!("{name}: {m}") } else { m.to_owned() }; diff --git a/websockets/echo/src/client.rs b/websockets/echo/src/client.rs index b0e519d..6bcfd95 100644 --- a/websockets/echo/src/client.rs +++ b/websockets/echo/src/client.rs @@ -44,7 +44,7 @@ async fn main() { match msg { Ok(ws::Frame::Text(txt)) => { // log echoed messages from server - log::info!("Server: {:?}", txt) + log::info!("Server: {txt:?}") } Ok(ws::Frame::Ping(_)) => { diff --git a/websockets/echo/src/server.rs b/websockets/echo/src/server.rs index f1bf818..9ae6df6 100644 --- a/websockets/echo/src/server.rs +++ b/websockets/echo/src/server.rs @@ -57,7 +57,7 @@ impl Actor for MyWebSocket { impl StreamHandler> for MyWebSocket { fn handle(&mut self, msg: Result, ctx: &mut Self::Context) { // process websocket messages - println!("WS: {:?}", msg); + println!("WS: {msg:?}"); match msg { Ok(ws::Message::Ping(msg)) => { self.hb = Instant::now();