1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00

Merge pull request #289 from BartWillems/master

Remove unwraps from websocket-chat
This commit is contained in:
Yuki Okushi 2020-04-06 22:46:46 +09:00 committed by GitHub
commit 32d821d321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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);
}
}