diff options
author | Dennis Kobert <d-kobert@web.de> | 2019-06-11 23:38:13 +0200 |
---|---|---|
committer | Dennis Kobert <d-kobert@web.de> | 2019-06-11 23:38:13 +0200 |
commit | 2fa4a0e50ebfc97059c8b84dbd17e79f9afc8a8d (patch) | |
tree | c3b34ccb2737e347a73768536895cbbaab13cc01 /game_server/src/lobby.rs | |
parent | ec991104f56e90d7bb2878da2fe6ed4e585dfc46 (diff) | |
parent | af74efccf8d21e6151022b71f3cacd3fa83024ee (diff) |
Merge branch 'rework-backend'
Diffstat (limited to 'game_server/src/lobby.rs')
-rw-r--r-- | game_server/src/lobby.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/game_server/src/lobby.rs b/game_server/src/lobby.rs new file mode 100644 index 0000000..fe3bdee --- /dev/null +++ b/game_server/src/lobby.rs @@ -0,0 +1,35 @@ +use std::collections::HashMap; + +use super::group::{Group, GroupId}; + +pub struct Lobby { + groups: HashMap<GroupId, Box<Group>>, +} + +impl Lobby { + pub fn new() -> Lobby { + Self { + groups: HashMap::new(), + } + } + + pub fn add_group(&mut self, group: Box<Group>) { + self.groups.insert(group.id(), group); + } + + pub fn iter<'a>(&'a self) -> GroupIterator<'a> { + GroupIterator { groups: self.groups.values() } + } +} + +pub struct GroupIterator<'a> { + groups: std::collections::hash_map::Values<'a, GroupId, Box<Group>> +} + +impl<'a> Iterator for GroupIterator<'a> { + type Item = &'a Box<Group>; + + fn next(&mut self) -> Option<Self::Item> { + self.groups.next() + } +} |