1
0
mirror of https://github.com/actix/examples synced 2025-06-28 18:00:37 +02:00

Fix clippy warnings (#168)

This commit is contained in:
Yuki Okushi
2019-09-05 00:04:57 +09:00
committed by GitHub
parent bb639d5fe3
commit f232b6c684
18 changed files with 41 additions and 46 deletions

View File

@ -68,7 +68,7 @@ impl WsChatSession {
fn send_msg(&self, msg: &str) {
let content = format!(
"{}: {}",
self.name.clone().unwrap_or("anon".to_string()),
self.name.clone().unwrap_or_else(|| "anon".to_string()),
msg
);
let msg = SendMessage(self.room.clone(), self.id, content);
@ -87,7 +87,7 @@ impl Actor for WsChatSession {
fn stopped(&mut self, _ctx: &mut Self::Context) {
info!(
"WsChatSession closed for {}({}) in room {}",
self.name.clone().unwrap_or("anon".to_string()),
self.name.clone().unwrap_or_else(|| "anon".to_string()),
self.id,
self.room
);

View File

@ -42,7 +42,7 @@ impl WsChatServer {
id: Option<usize>,
client: Client,
) -> usize {
let mut id = id.unwrap_or_else(|| rand::random::<usize>());
let mut id = id.unwrap_or_else(rand::random::<usize>);
if let Some(room) = self.rooms.get_mut(room_name) {
loop {
if room.contains_key(&id) {
@ -94,7 +94,7 @@ impl Handler<JoinRoom> for WsChatServer {
let id = self.add_client_to_room(&room_name, None, client);
let join_msg = format!(
"{} joined {}",
client_name.unwrap_or("anon".to_string()),
client_name.unwrap_or_else(|| "anon".to_string()),
room_name
);
self.send_chat_message(&room_name, &join_msg, id);