Skip to content

Commit

Permalink
Clarify error-handling behaviour of OsRng and ThreadRng
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Feb 23, 2022
1 parent 98ba32e commit 56ed9ab
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/guide-err.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ reduce to calls to [`RngCore`]'s "infallible" methods. Since most RNGs cannot
fail anyway this is usually not a problem, but the few generators which can may
be forced to fail in this case:

- [`OsRng`] is a wrapper over [`getrandom`]. "In general, on supported
platforms, failure is highly unlikely, though not impossible."
- [`OsRng`] is a wrapper over [`getrandom`]. From the latter's documentation:
"In general, on supported platforms, failure is highly unlikely, though not
impossible." [`OsRng`] will forward errors through
[`RngCore::try_fill_bytes`] while other methods panic on error.
- [`thread_rng`] seeds itself via [`OsRng`] on first use and periodically
thereafter, thus can potentially fail, though unlikely
thereafter, thus can potentially fail, though unlikely. If initial seeding
fails, a panic will result. If a failure happens during reseeding (less
likely) then the RNG continues without reseeding; a log message (warning)
is emitted if logging is enabled.

[`Rng::try_fill`]: ../rand/rand/trait.Rng.html#method.try_fill
[`RngCore::try_fill_bytes`]: ../rand/rand_core/trait.RngCore.html#tymethod.try_fill_bytes
Expand Down

0 comments on commit 56ed9ab

Please sign in to comment.