99//! Interface to the random number generator of the operating system.
1010// Note: keep this code in sync with the rand_os crate!
1111
12- use crate :: getrandom:: getrandom;
13- use rand_core :: { CryptoRng , RngCore , Error , impls} ;
12+ use getrandom:: getrandom;
13+ use crate :: { CryptoRng , RngCore , Error , impls} ;
1414
1515/// A random number generator that retrieves randomness from from the
1616/// operating system.
@@ -20,6 +20,9 @@ use rand_core::{CryptoRng, RngCore, Error, impls};
2020/// The implementation is provided by the [getrandom] crate. Refer to
2121/// [getrandom] documentation for details.
2222///
23+ /// This struct is only available when specifying the crate feature `getrandom`
24+ /// or `std`. When using the `rand` lib, it is also available as `rand::rngs::OsRng`.
25+ ///
2326/// # Blocking and error handling
2427///
2528/// It is possible that when used during early boot the first call to `OsRng`
@@ -33,30 +36,17 @@ use rand_core::{CryptoRng, RngCore, Error, impls};
3336///
3437/// # Usage example
3538/// ```
36- /// use rand::rngs::{StdRng, OsRng};
37- /// use rand::{RngCore, SeedableRng};
39+ /// use rand_core::{RngCore, OsRng};
3840///
3941/// let mut key = [0u8; 16];
4042/// OsRng.fill_bytes(&mut key);
4143/// let random_u64 = OsRng.next_u64();
42- ///
43- /// // OsRng is especially useful for seeding other RNGs (see also from_entropy)
44- /// let mut rng = StdRng::from_rng(OsRng).unwrap();
45- /// let _ = rng.next_u32();
4644/// ```
4745///
4846/// [getrandom]: https://crates.io/crates/getrandom
4947#[ derive( Clone , Copy , Debug , Default ) ]
5048pub struct OsRng ;
5149
52- impl OsRng {
53- /// Create a new `OsRng`.
54- #[ deprecated( since="0.7.0" , note="replace OsRng::new().unwrap() with just OsRng" ) ]
55- pub fn new ( ) -> Result < OsRng , Error > {
56- Ok ( OsRng )
57- }
58- }
59-
6050impl CryptoRng for OsRng { }
6151
6252impl RngCore for OsRng {
0 commit comments