about summary refs log tree commit diff
path: root/src/libstd/hashmap.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-09-14 00:01:04 -0700
committerbors <bors@rust-lang.org>2013-09-14 00:01:04 -0700
commit2aa578efd9834e37ad52879ff10ee2c2aa938389 (patch)
treeaa459cb42c65433dfbddca28040db544aea89f59 /src/libstd/hashmap.rs
parent4ac10f8f6e8e07c70fadb676170c5402442e2243 (diff)
parent93683ae6da3a47f1cd0644a093cb4b1b0bee7faa (diff)
downloadrust-2aa578efd9834e37ad52879ff10ee2c2aa938389.tar.gz
rust-2aa578efd9834e37ad52879ff10ee2c2aa938389.zip
auto merge of #9115 : erickt/rust/master, r=erickt
This is a series of patches to modernize option and result. The highlights are:

* rename `.unwrap_or_default(value)` and etc to `.unwrap_or(value)`
* add `.unwrap_or_default()` that uses the `Default` trait
* add `Default` implementations for vecs, HashMap, Option
* add  `Option.and(T) -> Option<T>`, `Option.and_then(&fn() -> Option<T>) -> Option<T>`, `Option.or(T) -> Option<T>`, and `Option.or_else(&fn() -> Option<T>) -> Option<T>`
* add `option::ToOption`, `option::IntoOption`, `option::AsOption`, `result::ToResult`, `result::IntoResult`, `result::AsResult`, `either::ToEither`, and `either::IntoEither`, `either::AsEither`
* renamed `Option::chain*` and `Result::chain*` to `and_then` and `or_else` to avoid the eventual collision with `Iterator.chain`.
* Added a bunch of impls of `Default`
* Added a `#[deriving(Default)]` syntax extension
* Removed impls of `Zero` for `Option<T>` and vecs. 
Diffstat (limited to 'src/libstd/hashmap.rs')
-rw-r--r--src/libstd/hashmap.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs
index 09f0af00417..6c0a6a4ea0a 100644
--- a/src/libstd/hashmap.rs
+++ b/src/libstd/hashmap.rs
@@ -18,6 +18,7 @@
 use container::{Container, Mutable, Map, MutableMap, Set, MutableSet};
 use clone::Clone;
 use cmp::{Eq, Equiv};
+use default::Default;
 use hash::Hash;
 use iter::{Iterator, FromIterator, Extendable};
 use iter::{FilterMap, Chain, Repeat, Zip};
@@ -622,6 +623,10 @@ impl<K: Eq + Hash, V> Extendable<(K, V)> for HashMap<K, V> {
     }
 }
 
+impl<K: Eq + Hash, V> Default for HashMap<K, V> {
+    fn default() -> HashMap<K, V> { HashMap::new() }
+}
+
 /// An implementation of a hash set using the underlying representation of a
 /// HashMap where the value is (). As with the `HashMap` type, a `HashSet`
 /// requires that the elements implement the `Eq` and `Hash` traits.
@@ -781,6 +786,10 @@ impl<K: Eq + Hash> Extendable<K> for HashSet<K> {
     }
 }
 
+impl<K: Eq + Hash> Default for HashSet<K> {
+    fn default() -> HashSet<K> { HashSet::new() }
+}
+
 // `Repeat` is used to feed the filter closure an explicit capture
 // of a reference to the other set
 /// Set operations iterator