about summary refs log tree commit diff
path: root/src/libstd/rand.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-08-05 16:47:01 -0700
committerbors <bors@rust-lang.org>2013-08-05 16:47:01 -0700
commitbbda3fa9383dba653b20bd064102caceef91897a (patch)
tree8fa4abc474568ca3a63992b5eea6cf62b7e04259 /src/libstd/rand.rs
parent29099e450a912cfcd0a0ccc72f55751bc2e209f2 (diff)
parent0ac7a219f043d3b1c8c239089d9dd6e6c9fa830b (diff)
auto merge of #8288 : Kimundi/rust/opteitres4, r=brson
This is an alternative version to https://github.com/mozilla/rust/pull/8268, where instead of transitioning to `get()` completely, I transitioned to `unwrap()` completely.

My reasoning for also opening this PR is that having two different functions with identical behavior on a common datatype is bad for consistency and confusing for users, and should be solved as soon as possible. The fact that apparently half the code uses `get()`, and the other half `unwrap()` only makes it worse.

If the final naming decision ends up different, there needs to be a big renaming anyway, but until then it should at least be consistent.

---

- Made naming schemes consistent between Option, Result and Either
- Lifted the quality of the either and result module to that of option
- Changed Options Add implementation to work like the maybe Monad (return None if any of the inputs is None)  
  See https://github.com/mozilla/rust/issues/6002, especially my last comment.
- Removed duplicate Option::get and renamed all related functions to use the term `unwrap` instead  
  See also https://github.com/mozilla/rust/issues/7887.

Todo: 

Adding testcases for all function in the three modules. Even without the few functions I added, the coverage wasn't complete to begin with. But I'd rather do that as a follow up PR, I've touched to much code here already, need to go through them again later.
Diffstat (limited to 'src/libstd/rand.rs')
-rw-r--r--src/libstd/rand.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs
index b7d72c11ff7..4ef524d7715 100644
--- a/src/libstd/rand.rs
+++ b/src/libstd/rand.rs
@@ -533,7 +533,7 @@ impl<R: Rng> RngUtil for R {
 
     /// Choose an item randomly, failing if values is empty
     fn choose<T:Clone>(&mut self, values: &[T]) -> T {
-        self.choose_option(values).get()
+        self.choose_option(values).unwrap()
     }
 
     /// Choose Some(item) randomly, returning None if values is empty
@@ -549,7 +549,7 @@ impl<R: Rng> RngUtil for R {
      * the weights is 0
      */
     fn choose_weighted<T:Clone>(&mut self, v: &[Weighted<T>]) -> T {
-        self.choose_weighted_option(v).get()
+        self.choose_weighted_option(v).unwrap()
     }
 
     /**