1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

Use captured args in format string (#558)

This commit is contained in:
Yuri Astrakhan
2022-06-07 22:53:38 -04:00
committed by GitHub
parent 912de4aa46
commit db5f00e771
37 changed files with 57 additions and 60 deletions

View File

@ -42,7 +42,7 @@ async fn chat_route(
/// Displays state
async fn get_count(count: web::Data<AtomicUsize>) -> impl Responder {
let current_count = count.load(Ordering::SeqCst);
format!("Visitors: {}", current_count)
format!("Visitors: {current_count}")
}
#[actix_web::main]

View File

@ -135,7 +135,7 @@ impl Handler<Connect> 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

View File

@ -114,7 +114,7 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> 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<Result<ws::Message, ws::ProtocolError>> 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()
};