From 7ae33fba15b2adf9f903869b3c896a7490427b04 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Mon, 26 Apr 2021 10:06:58 +0200 Subject: Initial commit --- src/inventory.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/inventory.rs (limited to 'src/inventory.rs') diff --git a/src/inventory.rs b/src/inventory.rs new file mode 100644 index 0000000..0e44313 --- /dev/null +++ b/src/inventory.rs @@ -0,0 +1,41 @@ +use crate::dice::RiskDie; + +#[derive(Clone, Debug)] +pub enum Item +{ + Countable(String, u8), + Approximate(String, RiskDie), +} + +#[derive(Clone, Debug)] +pub struct Inventory +{ + items: Vec, +} + +impl Inventory +{ + pub fn new() -> Self { Self { items: Vec::new() } } + + pub fn size(&self) -> usize { self.items.len() } + + pub fn add_item(&mut self, item: Item) { self.items.push(item); } +} + +impl Default for Inventory +{ + fn default() -> Self { Self::new() } +} + +#[cfg(test)] +mod tests +{ + use super::*; + + #[test] + pub fn new_empty_inventory() + { + let inventory = Inventory::new(); + assert_eq!(inventory.size(), 0); + } +} -- cgit v1.2.3-70-g09d2