1
0
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:
Philip Jenvey 2018-11-16 21:04:24 -08:00 committed by Douman
parent e30915d98d
commit 8a81a3bb58
2 changed files with 8 additions and 10 deletions

View File

@ -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

View File

@ -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