mirror of
https://github.com/actix/examples
synced 2024-11-27 16:02:57 +01:00
remove unneeded RefCells (#62)
This commit is contained in:
parent
e30915d98d
commit
8a81a3bb58
@ -3,8 +3,7 @@
|
||||
//! room through `ChatServer`.
|
||||
|
||||
use actix::prelude::*;
|
||||
use rand::{self, Rng, ThreadRng};
|
||||
use std::cell::RefCell;
|
||||
use rand::{self, rngs::ThreadRng, Rng};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
/// Chat server sends this messages to session
|
||||
@ -58,7 +57,7 @@ pub struct Join {
|
||||
pub struct ChatServer {
|
||||
sessions: HashMap<usize, Recipient<Message>>,
|
||||
rooms: HashMap<String, HashSet<usize>>,
|
||||
rng: RefCell<ThreadRng>,
|
||||
rng: ThreadRng,
|
||||
}
|
||||
|
||||
impl Default for ChatServer {
|
||||
@ -70,7 +69,7 @@ impl Default for ChatServer {
|
||||
ChatServer {
|
||||
sessions: HashMap::new(),
|
||||
rooms: rooms,
|
||||
rng: RefCell::new(rand::thread_rng()),
|
||||
rng: rand::thread_rng(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,7 +109,7 @@ impl Handler<Connect> for ChatServer {
|
||||
self.send_message(&"Main".to_owned(), "Someone joined", 0);
|
||||
|
||||
// register session with random id
|
||||
let id = self.rng.borrow_mut().gen::<usize>();
|
||||
let id = self.rng.gen::<usize>();
|
||||
self.sessions.insert(id, msg.addr);
|
||||
|
||||
// auto join session to Main room
|
||||
|
@ -3,8 +3,7 @@
|
||||
//! room through `ChatServer`.
|
||||
|
||||
use actix::prelude::*;
|
||||
use rand::{self, Rng, ThreadRng};
|
||||
use std::cell::RefCell;
|
||||
use rand::{self, rngs::ThreadRng, Rng};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use session;
|
||||
@ -56,7 +55,7 @@ pub struct Join {
|
||||
pub struct ChatServer {
|
||||
sessions: HashMap<usize, Recipient<session::Message>>,
|
||||
rooms: HashMap<String, HashSet<usize>>,
|
||||
rng: RefCell<ThreadRng>,
|
||||
rng: ThreadRng,
|
||||
}
|
||||
|
||||
impl Default for ChatServer {
|
||||
@ -68,7 +67,7 @@ impl Default for ChatServer {
|
||||
ChatServer {
|
||||
sessions: HashMap::new(),
|
||||
rooms: rooms,
|
||||
rng: RefCell::new(rand::thread_rng()),
|
||||
rng: rand::thread_rng(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -108,7 +107,7 @@ impl Handler<Connect> for ChatServer {
|
||||
self.send_message(&"Main".to_owned(), "Someone joined", 0);
|
||||
|
||||
// register session with random id
|
||||
let id = self.rng.borrow_mut().gen::<usize>();
|
||||
let id = self.rng.gen::<usize>();
|
||||
self.sessions.insert(id, msg.addr);
|
||||
|
||||
// auto join session to Main room
|
||||
|
Loading…
Reference in New Issue
Block a user