Browse Source

Comment RoomMap.

wip
Titouan Rigoudy 9 years ago
parent
commit
58d5840d1b
1 changed files with 15 additions and 0 deletions
  1. +15
    -0
      src/room.rs

+ 15
- 0
src/room.rs View File

@ -29,22 +29,36 @@ pub struct Room {
pub user_count: usize, pub user_count: usize,
} }
/// Contains the mapping from room names to room data and provides a clean
/// interface to interact with it.
#[derive(Debug)] #[derive(Debug)]
pub struct RoomMap { pub struct RoomMap {
/// The actual map from room names to room data.
map: collections::HashMap<String, Room>, map: collections::HashMap<String, Room>,
} }
impl RoomMap { impl RoomMap {
/// Creates an empty mapping.
pub fn new() -> Self { pub fn new() -> Self {
RoomMap { RoomMap {
map: collections::HashMap::new() map: collections::HashMap::new()
} }
} }
/// Looks up the given room name in the map, returning an immutable
/// reference to the associated data if found.
pub fn get(&self, name: &str) -> Option<&Room> { pub fn get(&self, name: &str) -> Option<&Room> {
self.map.get(name) self.map.get(name)
} }
/// Looks up the given room name in the map, returning a mutable reference
/// to the associated data if found.
pub fn get_mut(&mut self, name: &str) -> Option<&mut Room> {
self.map.get_mut(name)
}
/// Updates the map to reflect the information contained in the given
/// server response.
pub fn update(&mut self, mut response: server::RoomListResponse) { pub fn update(&mut self, mut response: server::RoomListResponse) {
// First, clear the current map, keeping backing memory. // First, clear the current map, keeping backing memory.
self.map.clear(); self.map.clear();
@ -91,6 +105,7 @@ impl RoomMap {
} }
} }
/// Creates a control response containing the list of visible rooms.
pub fn get_room_list_response(&self) pub fn get_room_list_response(&self)
-> control::RoomListResponse -> control::RoomListResponse
{ {


Loading…
Cancel
Save