feat: use TxSendMessage
This commit is contained in:
15
src/types.rs
15
src/types.rs
@@ -7,3 +7,18 @@ use std::sync::{Mutex, Arc};
|
||||
pub type Tx = UnboundedSender<Message>;
|
||||
pub type PeerMap = Arc<Mutex<HashMap<SocketAddr, Tx>>>;
|
||||
pub type RoomMap = Arc<Mutex<BTreeMap<String, BTreeMap<String, SocketAddr>>>>;
|
||||
|
||||
pub trait TxSendMessage {
|
||||
fn send_close(&self) -> bool;
|
||||
fn send_text<S>(&self, text: S) -> bool where S: Into<String>;
|
||||
}
|
||||
|
||||
impl TxSendMessage for Tx {
|
||||
fn send_close(&self) -> bool {
|
||||
self.unbounded_send(Message::Close(None)).is_ok()
|
||||
}
|
||||
|
||||
fn send_text<S>(&self, text: S) -> bool where S: Into<String> {
|
||||
self.unbounded_send(Message::Text(text.into())).is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user