Skip to content

Commit ba88dad

Browse files
authored
Merge pull request #366 from pitdicker/deny_doctest_warnings
Some more documentation work
2 parents 683d6b9 + f953c4b commit ba88dad

File tree

15 files changed

+361
-289
lines changed

15 files changed

+361
-289
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ matrix:
3434
- cargo test --features serde-1,log,nightly
3535
- cargo test --benches
3636
- cargo doc --no-deps --all --all-features
37+
- cargo --list | egrep "^\s*deadlinks$" -q || cargo install cargo-deadlinks
38+
- cargo deadlinks --dir target/doc
3739
after_success:
3840
- travis-cargo --only nightly doc-upload
3941

Cargo.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rand"
3-
version = "0.5.0-pre.0"
3+
version = "0.5.0-pre.0" # NB: When modifying, also modify html_root_url in lib.rs
44
authors = ["The Rust Project Developers"]
55
license = "MIT/Apache-2.0"
66
readme = "README.md"
@@ -29,7 +29,7 @@ serde-1 = ["serde", "serde_derive"] # enables serialisation for PRNGs
2929
members = ["rand_core"]
3030

3131
[dependencies]
32-
rand_core = { version = '0.1.0-pre.0', default-features = false }
32+
rand_core = { path="rand_core", default-features = false }
3333
log = { version = "0.4", optional = true }
3434
serde = { version = "1", optional = true }
3535
serde_derive = { version = "1", optional = true }
@@ -54,3 +54,7 @@ stdweb = { version = "0.4", optional = true }
5454
# This is for testing serde, unfortunately we can't specify feature-gated dev
5555
# deps yet, see: https://github.com/rust-lang/cargo/issues/1596
5656
bincode = "1.0"
57+
58+
[package.metadata.docs.rs]
59+
all-features = true
60+
rustdoc-args = [ "--all" ] # also document rand_core

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 {

rand_core/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rand_core"
3-
version = "0.1.0-pre.0"
3+
version = "0.1.0-pre.0" # NB: When modifying, also modify html_root_url in lib.rs
44
authors = ["The Rust Project Developers"]
55
license = "MIT/Apache-2.0"
66
readme = "README.md"

rand_core/src/lib.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ pub mod le;
8383
/// output (except by communicating that the release has breaking changes).
8484
///
8585
/// Typically implementators will implement only one of the methods available
86-
/// in this trait directly, then use the helper functions from the [`impls`]
87-
/// module to implement the other methods.
86+
/// in this trait directly, then use the helper functions from the
87+
/// [`rand_core::impls`] module to implement the other methods.
8888
///
8989
/// It is recommended that implementations also implement:
9090
///
@@ -131,7 +131,7 @@ pub mod le;
131131
/// [rand]: https://crates.io/crates/rand
132132
/// [`Rng`]: ../rand/trait.Rng.html
133133
/// [`SeedableRng`]: trait.SeedableRng.html
134-
/// [`impls`]: impls/index.html
134+
/// [`rand_core::impls`]: ../rand_core/impls/index.html
135135
/// [`try_fill_bytes`]: trait.RngCore.html#tymethod.try_fill_bytes
136136
/// [`fill_bytes`]: trait.RngCore.html#tymethod.fill_bytes
137137
/// [`next_u32`]: trait.RngCore.html#tymethod.next_u32
@@ -143,23 +143,23 @@ pub trait RngCore {
143143
/// RNGs must implement at least one method from this trait directly. In
144144
/// the case this method is not implemented directly, it can be implemented
145145
/// using `self.next_u64() as u32` or
146-
/// [via `fill_bytes`](impls/fn.next_u32_via_fill.html).
146+
/// [via `fill_bytes`](../rand_core/impls/fn.next_u32_via_fill.html).
147147
fn next_u32(&mut self) -> u32;
148148

149149
/// Return the next random `u64`.
150150
///
151151
/// RNGs must implement at least one method from this trait directly. In
152152
/// the case this method is not implemented directly, it can be implemented
153-
/// [via `next_u32`](impls/fn.next_u64_via_u32.html) or
154-
/// [via `fill_bytes`](impls/fn.next_u64_via_fill.html).
153+
/// [via `next_u32`](../rand_core/impls/fn.next_u64_via_u32.html) or
154+
/// [via `fill_bytes`](../rand_core/impls/fn.next_u64_via_fill.html).
155155
fn next_u64(&mut self) -> u64;
156156

157157
/// Fill `dest` with random data.
158158
///
159159
/// RNGs must implement at least one method from this trait directly. In
160160
/// the case this method is not implemented directly, it can be implemented
161-
/// [via `next_u32`](impls/fn.fill_bytes_via_u32.html) or
162-
/// [via `next_u64`](impls/fn.fill_bytes_via_u64.html) or
161+
/// [via `next_u32`](../rand_core/impls/fn.fill_bytes_via_u32.html) or
162+
/// [via `next_u64`](../rand_core/impls/fn.fill_bytes_via_u64.html) or
163163
/// via `try_fill_bytes`; if this generator can fail the implementation
164164
/// must choose how best to handle errors here (e.g. panic with a
165165
/// descriptive message or log a warning and retry a few times).
@@ -329,7 +329,7 @@ pub trait SeedableRng: Sized {
329329
///
330330
/// Seeding a small PRNG from another small PRNG is possible, but
331331
/// something to be careful with. An extreme example of how this can go
332-
/// wrong is seeding an [`XorShiftRng`] from another [`XorShiftRng`], which
332+
/// wrong is seeding an Xorshift RNG from another Xorshift RNG, which
333333
/// will effectively clone the generator. In general seeding from a
334334
/// generator which is hard to predict is probably okay.
335335
///
@@ -338,7 +338,6 @@ pub trait SeedableRng: Sized {
338338
///
339339
/// [`NewRng`]: ../rand/trait.NewRng.html
340340
/// [`OsRng`]: ../rand/os/struct.OsRng.html
341-
/// [`XorShiftRng`]: ../rand/struct.XorShiftRng.html
342341
fn from_rng<R: RngCore>(mut rng: R) -> Result<Self, Error> {
343342
let mut seed = Self::Seed::default();
344343
rng.try_fill_bytes(seed.as_mut())?;

src/distributions/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<'a, T, D: Distribution<T>> Distribution<T> for &'a D {
246246
/// use rand::distributions::Uniform;
247247
///
248248
/// let mut rng = thread_rng();
249-
/// let mut erased_rng: &mut RngCore = &mut rng;
249+
/// let erased_rng: &mut RngCore = &mut rng;
250250
/// let val: f32 = erased_rng.sample(Uniform);
251251
/// println!("f32 from (0,1): {}", val);
252252
/// ```

src/distributions/range.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,29 @@ use distributions::float::IntoFloat;
5353
/// ```
5454
#[derive(Clone, Copy, Debug)]
5555
pub struct Range<X: SampleRange> {
56-
inner: X::T,
56+
inner: X::Impl,
5757
}
5858

5959
impl<X: SampleRange> Range<X> {
6060
/// Create a new `Range` instance which samples uniformly from the half
6161
/// open range `[low, high)` (excluding `high`). Panics if `low >= high`.
6262
pub fn new(low: X, high: X) -> Range<X> {
6363
assert!(low < high, "Range::new called with `low >= high`");
64-
Range { inner: X::T::new(low, high) }
64+
Range { inner: X::Impl::new(low, high) }
6565
}
6666

6767
/// Create a new `Range` instance which samples uniformly from the closed
6868
/// range `[low, high]` (inclusive). Panics if `low >= high`.
6969
pub fn new_inclusive(low: X, high: X) -> Range<X> {
7070
assert!(low < high, "Range::new called with `low >= high`");
71-
Range { inner: X::T::new_inclusive(low, high) }
71+
Range { inner: X::Impl::new_inclusive(low, high) }
7272
}
7373

7474
/// Sample a single value uniformly from `[low, high)`.
7575
/// Panics if `low >= high`.
7676
pub fn sample_single<R: Rng + ?Sized>(low: X, high: X, rng: &mut R) -> X {
7777
assert!(low < high, "Range::sample_single called with low >= high");
78-
X::T::sample_single(low, high, rng)
78+
X::Impl::sample_single(low, high, rng)
7979
}
8080
}
8181

@@ -88,7 +88,8 @@ impl<X: SampleRange> Distribution<X> for Range<X> {
8888
/// Helper trait for creating objects using the correct implementation of
8989
/// `RangeImpl` for the sampling type; this enables `Range::new(a, b)` to work.
9090
pub trait SampleRange: PartialOrd+Sized {
91-
type T: RangeImpl<X = Self>;
91+
/// The `RangeImpl` implementation supporting type `X`.
92+
type Impl: RangeImpl<X = Self>;
9293
}
9394

9495
/// Helper trait handling actual range sampling.
@@ -124,7 +125,7 @@ pub trait SampleRange: PartialOrd+Sized {
124125
/// }
125126
///
126127
/// impl SampleRange for MyF32 {
127-
/// type T = RangeMyF32;
128+
/// type Impl = RangeMyF32;
128129
/// }
129130
///
130131
/// let (low, high) = (MyF32(17.0f32), MyF32(22.0f32));
@@ -183,7 +184,7 @@ macro_rules! range_int_impl {
183184
($ty:ty, $signed:ty, $unsigned:ident,
184185
$i_large:ident, $u_large:ident) => {
185186
impl SampleRange for $ty {
186-
type T = RangeInt<$ty>;
187+
type Impl = RangeInt<$ty>;
187188
}
188189

189190
impl RangeImpl for RangeInt<$ty> {
@@ -428,7 +429,7 @@ pub struct RangeFloat<X> {
428429
macro_rules! range_float_impl {
429430
($ty:ty, $bits_to_discard:expr, $next_u:ident) => {
430431
impl SampleRange for $ty {
431-
type T = RangeFloat<$ty>;
432+
type Impl = RangeFloat<$ty>;
432433
}
433434

434435
impl RangeImpl for RangeFloat<$ty> {
@@ -566,7 +567,7 @@ mod tests {
566567
}
567568
}
568569
impl SampleRange for MyF32 {
569-
type T = RangeMyF32;
570+
type Impl = RangeMyF32;
570571
}
571572

572573
let (low, high) = (MyF32{ x: 17.0f32 }, MyF32{ x: 22.0f32 });

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).

0 commit comments

Comments
 (0)