Created
February 15, 2016 00:09
-
-
Save Fishrock123/e96a6fcc1eb10f0925cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
src/inventory.rs:30:9: 48:10 error: type mismatch resolving `<core::slice::IterMut<'_, inventory::Slot<T>> as core::iter::Iterator>::Item == inventory::Slot<_>`: | |
expected &-ptr, | |
found enum `inventory::Slot` [E0271] | |
src/inventory.rs:30 for slot in self.slots.iter_mut() { | |
src/inventory.rs:31 if let Slot::Some(other, stackSize) = slot { | |
src/inventory.rs:32 if itemType != other.itemType() { continue; } | |
src/inventory.rs:33 | |
src/inventory.rs:34 let remainder = other.maxStackSize() - stackSize; | |
src/inventory.rs:35 if remainder >= sum { | |
... | |
src/inventory.rs:30:9: 48:10 help: run `rustc --explain E0271` to see a detailed explanation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Slot<T> { | |
None, | |
Some(T, i32), | |
} | |
pub struct Inventory<T> { | |
slots: Vec<Slot<T>>, | |
} | |
impl<T: Item + Clone> Inventory<T> { | |
pub fn new(length: usize) -> Inventory<T> { | |
Inventory { slots: Vec::<Slot<T>>::with_capacity(length) } | |
} | |
pub fn len(&self) -> usize { | |
self.slots.len(); | |
} | |
pub fn give(&self, item: T, amount: i32) -> bool { | |
let itemType: &str = item.itemType(); | |
if !self.hasSpace(item, amount) { | |
return false; | |
} | |
let mut sum: i32 = amount; | |
for slot in self.slots.iter_mut() { | |
if let Slot::Some(other, stackSize) = slot { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment