Inventory
Build an inventory tracker! Start with an empty HashMap, then:
- Add
"apples"with quantity5 - Add
"bananas"with quantity3 - Add
"oranges"with quantity7 - Update
"apples"to quantity10(just insert again with the new value)
Print each item and its quantity in alphabetical order.
Expected output:
text
apples: 10 bananas: 3 oranges: 7
Hints:
- Start with
let mut inventory = HashMap::new(); - Use
.insert()to add items -- inserting the same key again updates the value - Collect keys, sort, and loop to print in order
rust
fn main() {
}