Skip to content

Commit 92a5c71

Browse files
committed
📝 Use doc_auto_cfg
1 parent d38b5d1 commit 92a5c71

10 files changed

+14
-18
lines changed

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ edition = "2021"
1111
license = "Zlib"
1212

1313
[features]
14-
default = ["std", "tls", "wyrand", "pcg64", "chacha"]
14+
default = ["entropy", "std", "tls", "wyrand", "pcg64", "chacha"]
15+
entropy = []
1516
alloc = []
1617
std = ["alloc"]
17-
tls = ["std", "wyrand"]
18+
tls = ["entropy", "std", "wyrand"]
1819
wyrand = []
1920
pcg64 = []
2021
chacha = []

src/buffer.rs

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ impl<InternalGenerator: Rng<OUTPUT>, const OUTPUT: usize> Rng<OUTPUT>
7272
}
7373

7474
#[cfg(feature = "std")]
75-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
7675
impl<InternalGenerator: Rng<OUTPUT>, const OUTPUT: usize> std::io::Read
7776
for BufferedRng<InternalGenerator, OUTPUT>
7877
{

src/crypto.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
/// Implementation of the ChaCha cryptographic primitives.
2-
/// More details can be seen at https://en.wikipedia.org/wiki/Salsa20
1+
/// Implementation of the ChaCha cryptographic primitives.
2+
/// More details can be seen at <https://en.wikipedia.org/wiki/Salsa20>
33
pub mod chacha;

src/entropy.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#[cfg(feature = "getrandom_custom")]
2-
#[cfg_attr(docsrs, doc(cfg(feature = "getrandom_custom")))]
32
pub use getrandom::register_custom_getrandom;
43

54
#[cfg(all(target_vendor = "apple", not(feature = "getrandom")))]

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![cfg_attr(not(feature = "std"), no_std)]
2-
#![cfg_attr(docsrs, feature(doc_cfg))]
2+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
33
#![forbid(missing_docs)]
44
#![warn(
55
clippy::perf,
@@ -85,6 +85,7 @@
8585
//! ## Feature Flags
8686
//!
8787
//! * `alloc` (default) - Enables Rust `alloc` lib features, such as a buffering Rng wrapper.
88+
//! * `entropy` (default) - Allows sourcing entropy from the system. Implied by `getrandom`, too.
8889
//! * `std` (default) - Enables Rust `std` lib features, such as seeding from OS entropy sources. Requires `alloc` to be enabled.
8990
//! * `tls` (default) - Enables a thread-local [`WyRand`](rand/wyrand/struct.WyRand.html) RNG (see below). Requires `std` to be enabled.
9091
//! * `wyrand` (default) - Enable the [`WyRand`](rand/wyrand/struct.WyRand.html) RNG.
@@ -108,18 +109,17 @@ pub use rand::*;
108109
pub use tls::tls_rng;
109110

110111
#[cfg(feature = "alloc")]
111-
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
112112
/// Provides a buffered wrapper for RNGs, preventing bits from being wasted.
113113
pub mod buffer;
114114
/// Implementation of cryptography, for CSPRNGs.
115115
pub mod crypto;
116116
/// Sources for obtaining entropy.
117+
#[cfg(any(feature = "entropy", feature = "getrandom"))]
117118
pub mod entropy;
118119
/// Traits for generating types from an RNG.
119120
pub mod gen;
120121
/// RNG algorithms.
121122
pub mod rand;
122123
#[cfg(feature = "tls")]
123-
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
124124
/// Provides a thread-local [`WyRand`] RNG.
125125
pub mod tls;

src/rand.rs

-3
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@ use core::ops::RangeBounds;
1111
/// Implementation of the wyrand PRNG algorithm.
1212
/// More details can be seen at <https://github.com/wangyi-fudan/wyhash>
1313
#[cfg(feature = "wyrand")]
14-
#[cfg_attr(docsrs, doc(cfg(feature = "wyrand")))]
1514
pub mod wyrand;
1615

1716
/// Implementation of the Pcg64 PRNG algorithm.
1817
/// More details can be seen at <https://www.pcg-random.org/index.html>
1918
#[cfg(feature = "pcg64")]
20-
#[cfg_attr(docsrs, doc(cfg(feature = "pcg64")))]
2119
pub mod pcg64;
2220

2321
/// Implementation of the ChaCha CSPRNG algorithm.
2422
/// More details can be seen at <https://en.wikipedia.org/wiki/Salsa20>
2523
#[cfg(feature = "chacha")]
26-
#[cfg_attr(docsrs, doc(cfg(feature = "chacha")))]
2724
pub mod chacha;
2825

2926
/// A trait that represents a random number generator.

src/rand/chacha.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ pub type ChaCha20 = ChaCha<20>;
2020
/// **This generator _is theoretically_ cryptographically secure.**
2121
#[cfg_attr(feature = "zeroize", derive(Zeroize))]
2222
#[cfg_attr(feature = "zeroize", zeroize(drop))]
23-
#[cfg_attr(docsrs, doc(cfg(feature = "chacha")))]
2423
pub struct ChaCha<const ROUNDS: u8> {
2524
state: [u32; 16],
2625
}
2726

2827
impl<const ROUNDS: u8> ChaCha<ROUNDS> {
2928
/// Create a new [`ChaCha`] instance, seeding from the system's default source of entropy.
29+
#[cfg(any(feature = "entropy", feature = "getrandom"))]
3030
#[must_use]
3131
pub fn new() -> Self {
3232
let mut key: [u8; 32] = Default::default();
@@ -45,6 +45,7 @@ impl<const ROUNDS: u8> ChaCha<ROUNDS> {
4545
}
4646
}
4747

48+
#[cfg(any(feature = "entropy", feature = "getrandom"))]
4849
impl<const ROUNDS: u8> Default for ChaCha<ROUNDS> {
4950
fn default() -> Self {
5051
let mut key: [u8; 32] = Default::default();

src/rand/pcg64.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const PCG_DEFAULT_MULTIPLIER_128: u128 = 47026247687942121848144207491837523525;
1212
/// **This generator is _NOT_ cryptographically secure.**
1313
#[cfg_attr(feature = "zeroize", derive(Zeroize))]
1414
#[cfg_attr(feature = "zeroize", zeroize(drop))]
15-
#[cfg_attr(docsrs, doc(cfg(feature = "pcg64")))]
1615
pub struct Pcg64 {
1716
seed: u128,
1817
state: u128,
@@ -21,7 +20,7 @@ pub struct Pcg64 {
2120

2221
impl Pcg64 {
2322
/// Create a new [`Pcg64`] instance, seeding from the system's default source of entropy.
24-
#[cfg(feature = "std")]
23+
#[cfg(any(feature = "entropy", feature = "getrandom"))]
2524
#[must_use]
2625
pub fn new() -> Self {
2726
let mut entropy: [u8; core::mem::size_of::<u128>()] = Default::default();
@@ -61,7 +60,7 @@ impl Pcg64 {
6160
}
6261
}
6362

64-
#[cfg(feature = "std")]
63+
#[cfg(any(feature = "entropy", feature = "getrandom"))]
6564
impl Default for Pcg64 {
6665
/// Create a new [`Pcg64`] instance, seeding from the system's default source of entropy.
6766
fn default() -> Self {

src/rand/wyrand.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use zeroize::Zeroize;
1010
/// **This generator is _NOT_ cryptographically secure.**
1111
#[cfg_attr(feature = "zeroize", derive(Zeroize))]
1212
#[cfg_attr(feature = "zeroize", zeroize(drop))]
13-
#[cfg_attr(docsrs, doc(cfg(feature = "wyrand")))]
1413
pub struct WyRand {
1514
seed: u64,
1615
}
1716

1817
impl WyRand {
1918
/// Create a new [`WyRand`] instance, seeding from the system's default source of entropy.
19+
#[cfg(any(feature = "entropy", feature = "getrandom"))]
2020
#[must_use]
2121
pub fn new() -> Self {
2222
Self::default()
@@ -29,6 +29,7 @@ impl WyRand {
2929
}
3030
}
3131

32+
#[cfg(any(feature = "entropy", feature = "getrandom"))]
3233
impl Default for WyRand {
3334
/// Create a new [`WyRand`] instance, seeding from the system's default source of entropy.
3435
fn default() -> Self {

src/tls.rs

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ impl SeedableRng<8, 8> for TlsWyRand {
3737
/// println!("Random number: {}", rng.generate::<u64>());
3838
/// });
3939
/// ```
40-
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
4140
pub fn tls_rng() -> TlsWyRand {
4241
WYRAND.with(|tls| TlsWyRand(tls.clone()))
4342
}

0 commit comments

Comments
 (0)