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

@ -75,9 +75,8 @@ impl Handler<JoinRoom> 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);

View File

@ -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<Result<ws::Message, ws::ProtocolError>> 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<Result<ws::Message, ws::ProtocolError>> 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;