blob: 3e900b258b4c15f852956def4be60a1bf09b8363 (
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
|
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 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);
}
}
|