Skip to content

Commit 6db4a61

Browse files
committed
Add prelude module
1 parent fe12a45 commit 6db4a61

File tree

8 files changed

+40
-21
lines changed

8 files changed

+40
-21
lines changed

benches/generators.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@ const BYTES_LEN: usize = 1024;
99
use std::mem::size_of;
1010
use test::{black_box, Bencher};
1111

12-
use rand::{RngCore, Rng, SeedableRng, FromEntropy};
13-
use rand::entropy::{OsRng, EntropyRng};
14-
use rand::entropy::jitter::JitterRng;
12+
use rand::prelude::*;
13+
use rand::entropy::{OsRng, EntropyRng, jitter::JitterRng};
1514
use rand::prng::{XorShiftRng, Hc128Rng, IsaacRng, Isaac64Rng, ChaChaRng};
1615
use rand::prng::hc128::Hc128Core;
1716
use rand::reseeding::ReseedingRng;
18-
use rand::rngs::{StdRng, SmallRng};
19-
use rand::thread_rng;
2017

2118
macro_rules! gen_bytes {
2219
($fnn:ident, $gen:expr) => {

benches/misc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ const RAND_BENCH_N: u64 = 1000;
77

88
use test::{black_box, Bencher};
99

10-
use rand::{SeedableRng, Rng, thread_rng};
11-
use rand::rngs::SmallRng;
10+
use rand::prelude::*;
1211
use rand::seq::*;
1312

1413
#[bench]

src/distributions/exponential.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ use distributions::{ziggurat, ziggurat_tables, Distribution};
3030
///
3131
/// # Example
3232
/// ```rust
33-
/// use rand::{FromEntropy, Rng};
34-
/// use rand::rngs::SmallRng;
33+
/// use rand::prelude::*;
3534
/// use rand::distributions::Exp1;
3635
///
3736
/// let val: f64 = SmallRng::from_entropy().sample(Exp1);

src/distributions/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,7 @@ impl<'a, D, R, T> Iterator for DistIter<'a, D, R, T>
400400
///
401401
/// # Example
402402
/// ```
403-
/// use rand::{FromEntropy, Rng};
404-
/// use rand::rngs::SmallRng;
403+
/// use rand::prelude::*;
405404
/// use rand::distributions::Standard;
406405
///
407406
/// let val: f32 = SmallRng::from_entropy().sample(Standard);

src/distributions/normal.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ use distributions::{ziggurat, ziggurat_tables, Distribution, Open01};
2828
///
2929
/// # Example
3030
/// ```rust
31-
/// use rand::{FromEntropy, Rng};
32-
/// use rand::rngs::SmallRng;
31+
/// use rand::prelude::*;
3332
/// use rand::distributions::StandardNormal;
3433
///
3534
/// let val: f64 = SmallRng::from_entropy().sample(StandardNormal);

src/distributions/uniform.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@
5353
//! The example below merely wraps another back-end.
5454
//!
5555
//! ```
56-
//! use rand::{Rng, thread_rng};
57-
//! use rand::distributions::Distribution;
58-
//! use rand::distributions::uniform::{Uniform, SampleUniform};
59-
//! use rand::distributions::uniform::{UniformSampler, UniformFloat};
56+
//! use rand::prelude::*;
57+
//! use rand::distributions::uniform::{Uniform, SampleUniform,
58+
//! UniformSampler, UniformFloat};
6059
//!
6160
//! #[derive(Clone, Copy, PartialEq, PartialOrd)]
6261
//! struct MyF32(f32);

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ pub mod distributions;
214214
pub mod entropy;
215215
pub mod mock; // Public so we don't export `StepRng` directly, making it a bit
216216
// more clear it is intended for testing.
217+
pub mod prelude;
217218
pub mod prng;
218219
#[cfg(feature="std")] pub mod read;
219220
pub mod reseeding;
@@ -809,10 +810,8 @@ pub trait FromEntropy: SeedableRng {
809810
/// errors, use the following code, equivalent aside from error handling:
810811
///
811812
/// ```rust
812-
/// # use rand::Error;
813-
/// use rand::{Rng, SeedableRng};
814-
/// use rand::entropy::EntropyRng;
815-
/// use rand::rngs::StdRng;
813+
/// use rand::{Error, prelude::*};
814+
/// use rand::entropy::EntropyRng;;
816815
///
817816
/// # fn try_inner() -> Result<(), Error> {
818817
/// // This uses StdRng, but is valid for any R: SeedableRng

src/prelude.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// https://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Convenience re-export of common members
12+
//!
13+
//! Like the standard library's prelude, this module simplifies importing of
14+
//! common items. Unlike the standard prelude, the contents of this module must
15+
//! be imported manually:
16+
//!
17+
//! ```
18+
//! use rand::prelude::*;
19+
//! # let _ = StdRng::from_entropy();
20+
//! # let mut r = SmallRng::from_rng(thread_rng()).unwrap();
21+
//! # let _: f32 = r.gen();
22+
//! ```
23+
24+
#[doc(no_inline)] pub use distributions::Distribution;
25+
#[doc(no_inline)] pub use rngs::{SmallRng, StdRng};
26+
#[doc(no_inline)] #[cfg(feature="std")] pub use rngs::ThreadRng;
27+
#[doc(no_inline)] pub use {Rng, RngCore, CryptoRng, SeedableRng};
28+
#[doc(no_inline)] #[cfg(feature="std")] pub use {FromEntropy, random, thread_rng};

0 commit comments

Comments
 (0)