Skip to content

Commit 5b2ab43

Browse files
committed
Document what OsRng implements
1 parent 67ca060 commit 5b2ab43

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/rng.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,27 @@ use rand_core::{TryCryptoRng, TryRngCore};
1010
/// This struct is also available as [`rand::rngs::OsRng`] when using [rand].
1111
///
1212
/// # Usage example
13+
///
14+
/// `OsRng` implements [`TryRngCore`]:
1315
/// ```
14-
/// use getrandom::{rand_core::{TryRngCore, RngCore}, OsRng};
16+
/// use getrandom::{rand_core::TryRngCore, OsRng};
1517
///
1618
/// let mut key = [0u8; 32];
1719
/// OsRng.try_fill_bytes(&mut key).unwrap();
20+
/// ```
21+
///
22+
/// Using it as an [`RngCore`] is possible using [`TryRngCore::unwrap_err`]:
23+
/// ```
24+
/// use getrandom::rand_core::{TryRngCore, RngCore};
25+
/// use getrandom::OsRng;
1826
///
1927
/// let mut rng = OsRng.unwrap_err();
2028
/// let random_u64 = rng.next_u64();
2129
/// ```
2230
///
2331
/// [rand]: https://crates.io/crates/rand
2432
/// [`rand::rngs::OsRng`]: https://docs.rs/rand/latest/rand/rngs/struct.OsRng.html
33+
/// [`RngCore`]: rand_core::RngCore
2534
#[derive(Clone, Copy, Debug, Default)]
2635
pub struct OsRng;
2736

0 commit comments

Comments
 (0)