Skip to content

Commit d38b5d1

Browse files
committed
📝 Add feature flags for docs.rs in documentation
1 parent 34ba243 commit d38b5d1

9 files changed

+13
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ getrandom = { version = "0.2", optional = true, features = ["rdrand"] }
3636
[target.'cfg(not(any(target_arch = "wasm32", target_arch = "x86", target_arch = "x86_64")))'.dependencies]
3737
getrandom = { version = "0.2", optional = true }
3838

39-
4039
[dev-dependencies]
4140
hex = "0.4.3"
4241

4342
[package.metadata.docs.rs]
4443
all-features = true
44+
rustdoc-args = ["--cfg", "docsrs"]
4545
default-target = "x86_64-unknown-linux-gnu"
4646
targets = ["x86_64-pc-windows-msvc"]
4747

src/buffer.rs

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

7474
#[cfg(feature = "std")]
75+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
7576
impl<InternalGenerator: Rng<OUTPUT>, const OUTPUT: usize> std::io::Read
7677
for BufferedRng<InternalGenerator, OUTPUT>
7778
{

src/entropy.rs

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

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

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![cfg_attr(not(feature = "std"), no_std)]
2+
#![cfg_attr(docsrs, feature(doc_cfg))]
23
#![forbid(missing_docs)]
34
#![warn(
45
clippy::perf,
@@ -107,6 +108,7 @@ pub use rand::*;
107108
pub use tls::tls_rng;
108109

109110
#[cfg(feature = "alloc")]
111+
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
110112
/// Provides a buffered wrapper for RNGs, preventing bits from being wasted.
111113
pub mod buffer;
112114
/// Implementation of cryptography, for CSPRNGs.
@@ -118,5 +120,6 @@ pub mod gen;
118120
/// RNG algorithms.
119121
pub mod rand;
120122
#[cfg(feature = "tls")]
123+
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
121124
/// Provides a thread-local [`WyRand`] RNG.
122125
pub mod tls;

src/rand.rs

+3
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ 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")))]
1415
pub mod wyrand;
1516

1617
/// Implementation of the Pcg64 PRNG algorithm.
1718
/// More details can be seen at <https://www.pcg-random.org/index.html>
1819
#[cfg(feature = "pcg64")]
20+
#[cfg_attr(docsrs, doc(cfg(feature = "pcg64")))]
1921
pub mod pcg64;
2022

2123
/// Implementation of the ChaCha CSPRNG algorithm.
2224
/// More details can be seen at <https://en.wikipedia.org/wiki/Salsa20>
2325
#[cfg(feature = "chacha")]
26+
#[cfg_attr(docsrs, doc(cfg(feature = "chacha")))]
2427
pub mod chacha;
2528

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

src/rand/chacha.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ 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")))]
2324
pub struct ChaCha<const ROUNDS: u8> {
2425
state: [u32; 16],
2526
}

src/rand/pcg64.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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")))]
1516
pub struct Pcg64 {
1617
seed: u128,
1718
state: u128,

src/rand/wyrand.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ 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")))]
1314
pub struct WyRand {
1415
seed: u64,
1516
}

src/tls.rs

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

0 commit comments

Comments
 (0)