use item::Item; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Storage { items : Vec, capacity : usize, } impl Storage { pub fn new(items : Vec) -> Storage { Storage { items : items, capacity : 100, } } pub fn take(&mut self, name : &str) -> Option { 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); } }