blob: 6aa8417da1c4a313548868dd9c05d18da82e0820 (
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
|
use item::Item;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Storage {
items : Vec<Item>,
capacity : usize,
}
impl Storage {
pub fn new(items : Vec<Item>) -> Storage {
Storage {
items : items,
capacity : 100,
}
}
pub fn has_minerals(&self) -> bool {
match self.items.iter().position(|item| item.name == "Iron") {
Some(_) => true,
None => false,
}
}
pub fn take(&mut self, name : &str) -> Option<Item> {
match self.items.iter().position(|item| item.name == name) {
Some(index) => Some(self.items.remove(index)),
None => None,
}
}
pub fn give(&mut self, item : Item) {
self.items.push(item);
}
}
|