Skip to content

Commit f1aaf37

Browse files
committed
Clean up public exports in documentation
Mostly just hide, to avoid API breakage.
1 parent e365f9c commit f1aaf37

File tree

6 files changed

+38
-34
lines changed

6 files changed

+38
-34
lines changed

benches/generators.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use std::mem::size_of;
1010
use test::{black_box, Bencher};
1111

1212
use rand::{RngCore, Rng, SeedableRng, NewRng};
13-
use rand::{StdRng, SmallRng, OsRng, JitterRng, EntropyRng};
14-
use rand::{XorShiftRng, Hc128Rng, IsaacRng, Isaac64Rng, ChaChaRng};
15-
use rand::reseeding::ReseedingRng;
13+
use rand::{StdRng, SmallRng, OsRng, EntropyRng, ReseedingRng};
14+
use rand::prng::{XorShiftRng, Hc128Rng, IsaacRng, Isaac64Rng, ChaChaRng};
1615
use rand::prng::hc128::Hc128Core;
16+
use rand::jitter::JitterRng;
1717
use rand::thread_rng;
1818

1919
macro_rules! gen_bytes {

src/entropy_rng.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
//! Entropy generator, or wrapper around external generators
1212
1313
use rand_core::{RngCore, CryptoRng, Error, impls};
14-
use {OsRng, JitterRng};
14+
use os::OsRng;
15+
use jitter::JitterRng;
1516

1617
/// A generator provided specifically for securely seeding algorithmic
1718
/// generators (PRNGs).

src/jitter.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl JitterRng {
203203
///
204204
/// ```rust
205205
/// # use rand::{Rng, Error};
206-
/// use rand::JitterRng;
206+
/// use rand::jitter::JitterRng;
207207
///
208208
/// # fn try_inner() -> Result<(), Error> {
209209
/// fn get_nstime() -> u64 {
@@ -682,7 +682,7 @@ impl JitterRng {
682682
/// for the available entropy.
683683
///
684684
/// ```rust,no_run
685-
/// use rand::JitterRng;
685+
/// use rand::jitter::JitterRng;
686686
/// #
687687
/// # use std::error::Error;
688688
/// # use std::fs::File;
@@ -816,7 +816,7 @@ impl CryptoRng for JitterRng {}
816816

817817
#[cfg(test)]
818818
mod test_jitter_init {
819-
use JitterRng;
819+
use jitter::JitterRng;
820820

821821
#[cfg(feature="std")]
822822
#[test]

src/lib.rs

+25-23
Original file line numberDiff line numberDiff line change
@@ -213,53 +213,55 @@ extern crate rand_core;
213213
#[cfg(all(feature="std", not(feature = "log")))] macro_rules! error { ($($x:tt)*) => () }
214214

215215

216-
use core::{marker, mem, slice};
217-
218-
// re-exports from rand_core
216+
// Re-exports from rand_core
219217
pub use rand_core::{RngCore, BlockRngCore, CryptoRng, SeedableRng};
220218
pub use rand_core::{ErrorKind, Error};
221219

222-
// external rngs
223-
#[doc(inline)] pub use jitter::JitterRng;
224-
#[cfg(feature="std")] #[doc(inline)] pub use os::OsRng;
225-
226-
// pseudo rngs
227-
pub mod prng;
228-
#[doc(no_inline)]
229-
pub use prng::{ChaChaRng, Hc128Rng, IsaacRng, Isaac64Rng, XorShiftRng};
230-
231-
// convenience and derived rngs
220+
// Public exports
232221
#[cfg(feature="std")] pub use entropy_rng::EntropyRng;
222+
#[cfg(feature="std")] pub use os::OsRng;
223+
#[cfg(feature="std")] pub use read::ReadRng;
224+
pub use reseeding::ReseedingRng;
233225
#[cfg(feature="std")] pub use thread_rng::{ThreadRng, thread_rng};
234226
#[cfg(feature="std")] #[allow(deprecated)] pub use thread_rng::random;
235227

236-
use distributions::{Distribution, Uniform, Range};
237-
use distributions::range::SampleRange;
238-
239-
// public modules
228+
// Public modules
240229
pub mod distributions;
241-
pub mod jitter;
242-
pub mod mock;
243-
#[cfg(feature="std")] pub mod os;
244-
#[cfg(feature="std")] pub mod read;
245-
pub mod reseeding;
230+
pub mod jitter; // Public because of the error type.
231+
pub mod mock; // Public so we don't export `StepRng` directly, making it a bit
232+
// more clear it is intended for testing.
233+
pub mod prng;
246234
#[cfg(feature = "alloc")] pub mod seq;
247235

248-
// These tiny modules are here to avoid API breakage, probably only temporarily
236+
// These modules are public to avoid API breakage, probably only temporarily.
237+
// Hidden in the documentation.
238+
#[cfg(feature="std")] #[doc(hidden)] pub mod os;
239+
#[cfg(feature="std")] #[doc(hidden)] pub mod read;
240+
#[doc(hidden)] pub use prng::{ChaChaRng, IsaacRng, Isaac64Rng, XorShiftRng};
241+
#[doc(hidden)]
249242
pub mod chacha {
250243
//! The ChaCha random number generator.
251244
pub use prng::ChaChaRng;
252245
}
246+
#[doc(hidden)]
253247
pub mod isaac {
254248
//! The ISAAC random number generator.
255249
pub use prng::{IsaacRng, Isaac64Rng};
256250
}
257251

258252
// private modules
259253
#[cfg(feature="std")] mod entropy_rng;
254+
mod reseeding;
260255
#[cfg(feature="std")] mod thread_rng;
261256

262257

258+
// Normal imports just for this file
259+
use core::{marker, mem, slice};
260+
use distributions::{Distribution, Uniform, Range};
261+
use distributions::range::SampleRange;
262+
use prng::hc128::Hc128Rng;
263+
264+
263265
/// A type that can be randomly generated using an [`Rng`].
264266
///
265267
/// This is merely an adaptor around the [`Uniform`] distribution for

src/prng/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ mod xorshift;
4949
#[cfg(feature="serde-1")]
5050
mod isaac_serde;
5151

52-
pub use self::chacha::ChaChaRng;
53-
pub use self::hc128::Hc128Rng;
52+
#[doc(inline)] pub use self::chacha::ChaChaRng;
53+
#[doc(inline)] pub use self::hc128::Hc128Rng;
5454
pub use self::isaac::IsaacRng;
5555
pub use self::isaac64::Isaac64Rng;
5656
pub use self::xorshift::XorShiftRng;

src/read.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ use std::io::Read;
1515
use rand_core::{RngCore, Error, ErrorKind, impls};
1616

1717

18-
/// An RNG that reads random bytes straight from a `Read`. This will
19-
/// work best with an infinite reader, but that is not required.
18+
/// An RNG that reads random bytes straight from a `Read`.
19+
///
20+
/// This will work best with an infinite reader, but that is not required.
2021
///
2122
/// # Panics
2223
///

0 commit comments

Comments
 (0)