blob: fe3bdee74182bf37f8478806f78bf6d4148b4598 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()
}
}
|