From 8a81a3bb58d0b720fe2fd727c29e6e2274e33368 Mon Sep 17 00:00:00 2001 From: Philip Jenvey Date: Fri, 16 Nov 2018 21:04:24 -0800 Subject: [PATCH] remove unneeded RefCells (#62) --- websocket-chat/src/server.rs | 9 ++++----- websocket-tcp-chat/src/server.rs | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/websocket-chat/src/server.rs b/websocket-chat/src/server.rs index a4da2936..80d62b6d 100644 --- a/websocket-chat/src/server.rs +++ b/websocket-chat/src/server.rs @@ -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>, rooms: HashMap>, - rng: RefCell, + 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 for ChatServer { self.send_message(&"Main".to_owned(), "Someone joined", 0); // register session with random id - let id = self.rng.borrow_mut().gen::(); + let id = self.rng.gen::(); self.sessions.insert(id, msg.addr); // auto join session to Main room diff --git a/websocket-tcp-chat/src/server.rs b/websocket-tcp-chat/src/server.rs index 594beb17..efc946a8 100644 --- a/websocket-tcp-chat/src/server.rs +++ b/websocket-tcp-chat/src/server.rs @@ -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>, rooms: HashMap>, - rng: RefCell, + 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 for ChatServer { self.send_message(&"Main".to_owned(), "Someone joined", 0); // register session with random id - let id = self.rng.borrow_mut().gen::(); + let id = self.rng.gen::(); self.sessions.insert(id, msg.addr); // auto join session to Main room