summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlexis Beingessner <a.beingessner@gmail.com>2015-03-20 13:43:01 -0400
committerAlexis <a.beingessner@gmail.com>2015-03-27 07:42:03 -0400
commit1b98f6da7af8cea31066588776b7190c511455b1 (patch)
tree59e9a6e2b8803eea091517ba75cfea54e59faa6f /src/libstd
parent93cdf1f2783e3a863929a5ef2032e7de752e4e40 (diff)
downloadrust-1b98f6da7af8cea31066588776b7190c511455b1.tar.gz
rust-1b98f6da7af8cea31066588776b7190c511455b1.zip
default => or_insert per RFC
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/collections/hash/map.rs7
-rw-r--r--src/libstd/collections/mod.rs4
2 files changed, 6 insertions, 5 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs
index b3557529a66..91225891338 100644
--- a/src/libstd/collections/hash/map.rs
+++ b/src/libstd/collections/hash/map.rs
@@ -1489,7 +1489,8 @@ impl<'a, K, V> Entry<'a, K, V> {
     #[unstable(feature = "std_misc",
                reason = "will soon be replaced by or_insert")]
     #[deprecated(since = "1.0",
-                reason = "replaced with more ergonomic `default` and `default_with`")]
+                reason = "replaced with more ergonomic `or_insert` and `or_insert_with`")]
+    /// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
     pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> {
         match self {
             Occupied(entry) => Ok(entry.into_mut()),
@@ -1501,7 +1502,7 @@ impl<'a, K, V> Entry<'a, K, V> {
                reason = "matches entry v3 specification, waiting for dust to settle")]
     /// Ensures a value is in the entry by inserting the default if empty, and returns
     /// a mutable reference to the value in the entry.
-    pub fn default(self, default: V) -> &'a mut V {
+    pub fn or_insert(self, default: V) -> &'a mut V {
         match self {
             Occupied(entry) => entry.into_mut(),
             Vacant(entry) => entry.insert(default),
@@ -1512,7 +1513,7 @@ impl<'a, K, V> Entry<'a, K, V> {
                reason = "matches entry v3 specification, waiting for dust to settle")]
     /// Ensures a value is in the entry by inserting the result of the default function if empty,
     /// and returns a mutable reference to the value in the entry.
-    pub fn default_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
+    pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
         match self {
             Occupied(entry) => entry.into_mut(),
             Vacant(entry) => entry.insert(default()),
diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs
index b51948c160b..0ac97b71298 100644
--- a/src/libstd/collections/mod.rs
+++ b/src/libstd/collections/mod.rs
@@ -307,7 +307,7 @@
 //! let message = "she sells sea shells by the sea shore";
 //!
 //! for c in message.chars() {
-//!     *count.entry(c).default(0) += 1;
+//!     *count.entry(c).or_insert(0) += 1;
 //! }
 //!
 //! assert_eq!(count.get(&'s'), Some(&8));
@@ -340,7 +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 = blood_alcohol.entry(id).default(Person{id: id, blood_alcohol: 0.0});
+//!     let person = blood_alcohol.entry(id).or_insert(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;