From 93cdf1f2783e3a863929a5ef2032e7de752e4e40 Mon Sep 17 00:00:00 2001 From: Alexis Date: Sun, 1 Mar 2015 09:42:11 -0500 Subject: update everything to use Entry defaults --- src/libstd/collections/mod.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/libstd/collections') diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index 8d24f6b1916..b51948c160b 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -307,10 +307,7 @@ //! let message = "she sells sea shells by the sea shore"; //! //! for c in message.chars() { -//! match count.entry(c) { -//! Entry::Vacant(entry) => { entry.insert(1); }, -//! Entry::Occupied(mut entry) => *entry.get_mut() += 1, -//! } +//! *count.entry(c).default(0) += 1; //! } //! //! assert_eq!(count.get(&'s'), Some(&8)); @@ -343,10 +340,7 @@ //! for id in orders.into_iter() { //! // If this is the first time we've seen this customer, initialize them //! // with no blood alcohol. Otherwise, just retrieve them. -//! let person = match blood_alcohol.entry(id) { -//! Entry::Vacant(entry) => entry.insert(Person{id: id, blood_alcohol: 0.0}), -//! Entry::Occupied(entry) => entry.into_mut(), -//! }; +//! let person = blood_alcohol.entry(id).default(Person{id: id, blood_alcohol: 0.0}); //! //! // Reduce their blood alcohol level. It takes time to order and drink a beer! //! person.blood_alcohol *= 0.9; -- cgit 1.4.1-3-g733a5