Skip to content

Commit 7b4528f

Browse files
committed
modify example a bit
1 parent 75d917f commit 7b4528f

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/example0.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ struct ShoppingList {
55
items: Vec<String>,
66
}
77

8-
impl ShoppingList {
9-
fn new(items: Vec<String>) -> ShoppingList {
10-
ShoppingList {
11-
items: items
12-
}
13-
}
14-
}
15-
168
struct Store {
179
name: String,
1810
prices: HashMap<String, f32>,
@@ -53,13 +45,14 @@ fn build_stores() -> Vec<Store> {
5345
let mut store = Store::new(format!("Woolmart"));
5446
store.add_item(format!("chocolate"), 2.0);
5547
store.add_item(format!("doll"), 23.0);
56-
store.add_item(format!("bike"), 145.0);
48+
store.add_item(format!("bike"), 146.0);
5749
stores.push(store);
5850

5951
stores
6052
}
6153

6254
fn find_best_store<'a>(stores: &'a [Store], shopping_list: &ShoppingList) -> &'a Store {
55+
assert!(stores.len() > 0);
6356
let mut best = None;
6457
let mut best_price = INFINITY;
6558
for store in stores {
@@ -71,7 +64,7 @@ fn find_best_store<'a>(stores: &'a [Store], shopping_list: &ShoppingList) -> &'a
7164
best_price = sum;
7265
}
7366
}
74-
best.unwrap()
67+
best.unwrap() // there will always be at least one store
7568
}
7669

7770
fn main() {

0 commit comments

Comments
 (0)