Skip to content

Commit

Permalink
Deprecate Rng::gen_iter
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Mar 6, 2018
1 parent 7b70da2 commit 966f278
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions benches/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ fn gen_1k_iter_repeat(b: &mut Bencher) {
b.bytes = 1024;
}

#[allow(deprecated)]
#[bench]
fn gen_1k_gen_iter(b: &mut Bencher) {
let mut rng = weak_rng();
Expand Down
11 changes: 8 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,8 @@ pub trait Rng: RngCore + Sized {
/// println!("{:?}", rng.gen_iter::<(f64, bool)>().take(5)
/// .collect::<Vec<(f64, bool)>>());
/// ```
#[allow(deprecated)]
#[deprecated(since="0.5.0", note="replaced by Rng::iter")]
fn gen_iter<T>(&mut self) -> Generator<T, &mut Self> where Uniform: Distribution<T> {
Generator { rng: self, _marker: marker::PhantomData }
}
Expand Down Expand Up @@ -891,11 +893,14 @@ impl_as_byte_slice_arrays!(32, N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N
/// [`gen_iter`]: trait.Rng.html#method.gen_iter
/// [`Rng`]: trait.Rng.html
#[derive(Debug)]
#[allow(deprecated)]
#[deprecated(since="0.5.0", note="replaced by Rng::iter")]
pub struct Generator<T, R: RngCore> {
rng: R,
_marker: marker::PhantomData<fn() -> T>,
}

#[allow(deprecated)]
impl<T, R: RngCore> Iterator for Generator<T, R> where Uniform: Distribution<T> {
type Item = T;

Expand Down Expand Up @@ -1252,9 +1257,9 @@ mod test {
#[test]
fn test_gen_vec() {
let mut r = rng(106);
assert_eq!(r.gen_iter::<u8>().take(0).count(), 0);
assert_eq!(r.gen_iter::<u8>().take(10).count(), 10);
assert_eq!(r.gen_iter::<f64>().take(16).count(), 16);
assert_eq!(r.iter().map(|rng| rng.gen::<u8>()).take(0).count(), 0);
assert_eq!(r.iter().map(|rng| rng.gen::<u8>()).take(10).count(), 10);
assert_eq!(r.iter().map(|rng| rng.gen::<f64>()).take(16).count(), 16);
}

#[test]
Expand Down

0 comments on commit 966f278

Please sign in to comment.