Skip to content

Commit 895c2c9

Browse files
committed
Remove fns {try_,}from_os_rng
1 parent 723d1d9 commit 895c2c9

File tree

4 files changed

+3
-52
lines changed

4 files changed

+3
-52
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ compiler versions will be compatible. This is especially true of Rand's
9191
experimental `simd_support` feature.
9292

9393
Rand supports limited functionality in `no_std` mode (enabled via
94-
`default-features = false`). In this case, `OsRng` and `from_os_rng` are
94+
`default-features = false`). In this case, `OsRng` is
9595
unavailable (unless `os_rng` is enabled), large parts of `seq` are
9696
unavailable (unless `alloc` is enabled), and `ThreadRng` is unavailable.
9797

rand_core/src/lib.rs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -490,48 +490,6 @@ pub trait SeedableRng: Sized {
490490
rng.try_fill_bytes(seed.as_mut())?;
491491
Ok(Self::from_seed(seed))
492492
}
493-
494-
/// Creates a new instance of the RNG seeded via [`getrandom`].
495-
///
496-
/// This method is the recommended way to construct non-deterministic PRNGs
497-
/// since it is convenient and secure.
498-
///
499-
/// Note that this method may panic on (extremely unlikely) [`getrandom`] errors.
500-
/// If it's not desirable, use the [`try_from_os_rng`] method instead.
501-
///
502-
/// In case the overhead of using [`getrandom`] to seed *many* PRNGs is an
503-
/// issue, one may prefer to seed from a local PRNG, e.g.
504-
/// `from_rng(rand::rng()).unwrap()`.
505-
///
506-
/// # Panics
507-
///
508-
/// If [`getrandom`] is unable to provide secure entropy this method will panic.
509-
///
510-
/// [`getrandom`]: https://docs.rs/getrandom
511-
/// [`try_from_os_rng`]: SeedableRng::try_from_os_rng
512-
#[cfg(feature = "os_rng")]
513-
fn from_os_rng() -> Self {
514-
match Self::try_from_os_rng() {
515-
Ok(res) => res,
516-
Err(err) => panic!("from_os_rng failed: {}", err),
517-
}
518-
}
519-
520-
/// Creates a new instance of the RNG seeded via [`getrandom`] without unwrapping
521-
/// potential [`getrandom`] errors.
522-
///
523-
/// In case the overhead of using [`getrandom`] to seed *many* PRNGs is an
524-
/// issue, one may prefer to seed from a local PRNG, e.g.
525-
/// `from_rng(&mut rand::rng()).unwrap()`.
526-
///
527-
/// [`getrandom`]: https://docs.rs/getrandom
528-
#[cfg(feature = "os_rng")]
529-
fn try_from_os_rng() -> Result<Self, getrandom::Error> {
530-
let mut seed = Self::Seed::default();
531-
getrandom::fill(seed.as_mut())?;
532-
let res = Self::from_seed(seed);
533-
Ok(res)
534-
}
535493
}
536494

537495
#[cfg(test)]

src/rngs/small.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@ type Rng = super::xoshiro256plusplus::Xoshiro256PlusPlus;
4747
/// let rng = SmallRng::from_rng(&mut rand::rng());
4848
/// # let _: SmallRng = rng;
4949
/// ```
50-
/// or [`SeedableRng::from_os_rng`]:
51-
/// ```
52-
/// # use rand::SeedableRng;
53-
/// # use rand::rngs::SmallRng;
54-
/// let rng = SmallRng::from_os_rng();
55-
/// # let _: SmallRng = rng;
56-
/// ```
5750
/// 2. To use a deterministic integral seed, use `seed_from_u64`. This uses a
5851
/// hash function internally to yield a (typically) good seed from any
5952
/// input.

src/rngs/std.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ use chacha20::ChaCha12Rng as Rng;
3939
///
4040
/// Using a fresh seed **direct from the OS** is the most secure option:
4141
/// ```
42-
/// # use rand::{SeedableRng, rngs::StdRng};
43-
/// let rng = StdRng::from_os_rng();
42+
/// # use rand::{SeedableRng, rngs::{StdRng, OsRng}};
43+
/// let rng = StdRng::try_from_rng(&mut OsRng).unwrap();
4444
/// # let _: StdRng = rng;
4545
/// ```
4646
///

0 commit comments

Comments
 (0)