1
0
mirror of https://github.com/actix/examples synced 2025-01-22 22:05:57 +01:00

removed unnecessary unwraps from websocket-chat

Signed-off-by: Bart Willems <bwillems@protonmail.com>
This commit is contained in:
Bart Willems 2020-04-05 22:30:15 +02:00
parent 0fb09fdf62
commit ed8d4b5a8b

View File

@ -117,7 +117,10 @@ impl Handler<Connect> for ChatServer {
self.sessions.insert(id, msg.addr);
// auto join session to Main room
self.rooms.get_mut(&"Main".to_owned()).unwrap().insert(id);
self.rooms
.entry("Main".to_owned())
.or_insert(HashSet::new())
.insert(id);
// send id back
id
@ -193,10 +196,11 @@ impl Handler<Join> for ChatServer {
self.send_message(&room, "Someone disconnected", 0);
}
if self.rooms.get_mut(&name).is_none() {
self.rooms.insert(name.clone(), HashSet::new());
}
self.rooms
.entry(name.clone())
.or_insert(HashSet::new())
.insert(id);
self.send_message(&name, "Someone connected", id);
self.rooms.get_mut(&name).unwrap().insert(id);
}
}