Skip to content

Commit 28f1cb5

Browse files
committed
---
yaml --- r: 151882 b: refs/heads/try2 c: 803e92d h: refs/heads/master v: v3
1 parent a088697 commit 28f1cb5

File tree

5 files changed

+20
-26
lines changed

5 files changed

+20
-26
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: feb91f3216c7a60c9f7da582b3a02551fe73bb40
8+
refs/heads/try2: 803e92de89def55197244269a5d1feffa00c93d9
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ struct Foo { x: int, y: Box<int> }
944944
// `a` is the owner of the struct, and thus the owner of the struct's fields
945945
let a = Foo { x: 5, y: box 10 };
946946
}
947-
// when `a` goes out of scope, the destructor for the `~int` in the struct's
947+
// when `a` goes out of scope, the destructor for the `Box<int>` in the struct's
948948
// field is called
949949
950950
// `b` is mutable, and the mutability is inherited by the objects it owns

branches/try2/src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ pub struct RangeInclusive<A> {
20162016

20172017
/// Return an iterator over the range [start, stop]
20182018
#[inline]
2019-
pub fn range_inclusive<A: Add<A, A> + Ord + Clone + One + ToPrimitive>(start: A, stop: A)
2019+
pub fn range_inclusive<A: Add<A, A> + Ord + Clone + One>(start: A, stop: A)
20202020
-> RangeInclusive<A> {
20212021
RangeInclusive{range: range(start, stop), done: false}
20222022
}

branches/try2/src/libflate/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ mod tests {
125125
for _ in range(0, 20) {
126126
let mut input = vec![];
127127
for _ in range(0, 2000) {
128-
input.push_all(r.choose(words.as_slice()).as_slice());
128+
input.push_all(r.choose(words.as_slice()).unwrap().as_slice());
129129
}
130130
debug!("de/inflate of {} bytes of random word-sequences",
131131
input.len());

branches/try2/src/librand/lib.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -266,37 +266,39 @@ pub trait Rng {
266266
0123456789");
267267
let mut s = StrBuf::with_capacity(len);
268268
for _ in range(0, len) {
269-
s.push_char(self.choose(GEN_ASCII_STR_CHARSET) as char)
269+
s.push_char(*self.choose(GEN_ASCII_STR_CHARSET).unwrap() as char)
270270
}
271271
s
272272
}
273273

274-
/// Choose an item randomly, failing if `values` is empty.
275-
fn choose<T: Clone>(&mut self, values: &[T]) -> T {
276-
self.choose_option(values).expect("Rng.choose: `values` is empty").clone()
277-
}
278-
279-
/// Choose `Some(&item)` randomly, returning `None` if values is
280-
/// empty.
274+
/// Return a random element from `values`.
275+
///
276+
/// Return `None` if `values` is empty.
281277
///
282278
/// # Example
283279
///
284-
/// ```rust
280+
/// ```
285281
/// use rand::{task_rng, Rng};
286282
///
287283
/// let choices = [1, 2, 4, 8, 16, 32];
288284
/// let mut rng = task_rng();
289-
/// println!("{:?}", rng.choose_option(choices));
290-
/// println!("{:?}", rng.choose_option(choices.slice_to(0)));
285+
/// println!("{}", rng.choose(choices));
286+
/// assert_eq!(rng.choose(choices.slice_to(0)), None);
291287
/// ```
292-
fn choose_option<'a, T>(&mut self, values: &'a [T]) -> Option<&'a T> {
288+
fn choose<'a, T>(&mut self, values: &'a [T]) -> Option<&'a T> {
293289
if values.is_empty() {
294290
None
295291
} else {
296292
Some(&values[self.gen_range(0u, values.len())])
297293
}
298294
}
299295

296+
/// Deprecated name for `choose()`.
297+
#[deprecated = "replaced by .choose()"]
298+
fn choose_option<'a, T>(&mut self, values: &'a [T]) -> Option<&'a T> {
299+
self.choose(values)
300+
}
301+
300302
/// Shuffle a mutable slice in place.
301303
///
302304
/// # Example
@@ -793,18 +795,10 @@ mod test {
793795
#[test]
794796
fn test_choose() {
795797
let mut r = task_rng();
796-
assert_eq!(r.choose([1, 1, 1]), 1);
797-
}
798+
assert_eq!(r.choose([1, 1, 1]).map(|&x|x), Some(1));
798799

799-
#[test]
800-
fn test_choose_option() {
801-
let mut r = task_rng();
802800
let v: &[int] = &[];
803-
assert!(r.choose_option(v).is_none());
804-
805-
let i = 1;
806-
let v = [1,1,1];
807-
assert_eq!(r.choose_option(v), Some(&i));
801+
assert_eq!(r.choose(v), None);
808802
}
809803

810804
#[test]

0 commit comments

Comments
 (0)