Skip to content

Commit 0fe2383

Browse files
committed
Tweak docs
1 parent 02c9159 commit 0fe2383

File tree

3 files changed

+14
-32
lines changed

3 files changed

+14
-32
lines changed

rand_core/src/block.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,15 @@ pub trait CryptoBlockRng: BlockRngCore {}
9696
/// `BlockRng` has heavily optimized implementations of the [`RngCore`] methods
9797
/// reading values from the results buffer, as well as
9898
/// calling [`BlockRngCore::generate`] directly on the output array when
99-
/// [`fill_bytes`] / [`try_fill_bytes`] is called on a large array. These methods
100-
/// also handle the bookkeeping of when to generate a new batch of values.
99+
/// [`fill_bytes`] is called on a large array. These methods also handle
100+
/// the bookkeeping of when to generate a new batch of values.
101101
///
102102
/// No whole generated `u32` values are thrown away and all values are consumed
103103
/// in-order. [`next_u32`] simply takes the next available `u32` value.
104104
/// [`next_u64`] is implemented by combining two `u32` values, least
105-
/// significant first. [`fill_bytes`] and [`try_fill_bytes`] consume a whole
106-
/// number of `u32` values, converting each `u32` to a byte slice in
107-
/// little-endian order. If the requested byte length is not a multiple of 4,
108-
/// some bytes will be discarded.
105+
/// significant first. [`fill_bytes`] consume a whole number of `u32` values,
106+
/// converting each `u32` to a byte slice in little-endian order. If the requested byte
107+
/// length is not a multiple of 4, some bytes will be discarded.
109108
///
110109
/// See also [`BlockRng64`] which uses `u64` array buffers. Currently there is
111110
/// no direct support for other buffer types.
@@ -115,7 +114,6 @@ pub trait CryptoBlockRng: BlockRngCore {}
115114
/// [`next_u32`]: RngCore::next_u32
116115
/// [`next_u64`]: RngCore::next_u64
117116
/// [`fill_bytes`]: RngCore::fill_bytes
118-
/// [`try_fill_bytes`]: RngCore::try_fill_bytes
119117
#[derive(Clone)]
120118
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
121119
#[cfg_attr(
@@ -272,14 +270,12 @@ impl<R: CryptoBlockRng + BlockRngCore<Item = u32>> CryptoRng for BlockRng<R> {}
272270
/// then the other half is then consumed, however both [`next_u64`] and
273271
/// [`fill_bytes`] discard the rest of any half-consumed `u64`s when called.
274272
///
275-
/// [`fill_bytes`] and [`try_fill_bytes`] consume a whole number of `u64`
276-
/// values. If the requested length is not a multiple of 8, some bytes will be
277-
/// discarded.
273+
/// [`fill_bytes`] `] consume a whole number of `u64` values. If the requested length
274+
/// is not a multiple of 8, some bytes will be discarded.
278275
///
279276
/// [`next_u32`]: RngCore::next_u32
280277
/// [`next_u64`]: RngCore::next_u64
281278
/// [`fill_bytes`]: RngCore::fill_bytes
282-
/// [`try_fill_bytes`]: RngCore::try_fill_bytes
283279
#[derive(Clone)]
284280
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
285281
pub struct BlockRng64<R: BlockRngCore + ?Sized> {

rand_core/src/lib.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
//! [`SeedableRng`] is an extension trait for construction from fixed seeds and
2020
//! other random number generators.
2121
//!
22-
//! [`Error`] is provided for error-handling. It is safe to use in `no_std`
23-
//! environments.
24-
//!
2522
//! The [`impls`] and [`le`] sub-modules include a few small functions to assist
2623
//! implementation of [`RngCore`].
2724
//!
@@ -68,11 +65,6 @@ pub mod le;
6865
/// [`next_u32`] and [`next_u64`] methods, implementations may discard some
6966
/// random bits for efficiency.
7067
///
71-
/// The [`try_fill_bytes`] method is a variant of [`fill_bytes`] allowing error
72-
/// handling; it is not deemed sufficiently useful to add equivalents for
73-
/// [`next_u32`] or [`next_u64`] since the latter methods are almost always used
74-
/// with algorithmic generators (PRNGs), which are normally infallible.
75-
///
7668
/// Implementers should produce bits uniformly. Pathological RNGs (e.g. always
7769
/// returning the same value, or never setting certain bits) can break rejection
7870
/// sampling used by random distributions, and also break other RNGs when
@@ -128,7 +120,6 @@ pub mod le;
128120
/// ```
129121
///
130122
/// [`rand`]: https://docs.rs/rand
131-
/// [`try_fill_bytes`]: RngCore::try_fill_bytes
132123
/// [`fill_bytes`]: RngCore::fill_bytes
133124
/// [`next_u32`]: RngCore::next_u32
134125
/// [`next_u64`]: RngCore::next_u64
@@ -151,11 +142,7 @@ pub trait RngCore {
151142
///
152143
/// RNGs must implement at least one method from this trait directly. In
153144
/// the case this method is not implemented directly, it can be implemented
154-
/// via [`impls::fill_bytes_via_next`] or
155-
/// via [`RngCore::try_fill_bytes`]; if this generator can
156-
/// fail the implementation must choose how best to handle errors here
157-
/// (e.g. panic with a descriptive message or log a warning and retry a few
158-
/// times).
145+
/// via [`impls::fill_bytes_via_next`].
159146
///
160147
/// This method should guarantee that `dest` is entirely filled
161148
/// with new data, and may panic if this is impossible
@@ -434,6 +421,9 @@ pub trait SeedableRng: Sized {
434421
/// This method is the recommended way to construct non-deterministic PRNGs
435422
/// since it is convenient and secure.
436423
///
424+
/// Note that this method may panic on (extremely unlikely) [`getrandom`] errors.
425+
/// If it's not desirable, use the [`try_from_entropy`] method instead.
426+
///
437427
/// In case the overhead of using [`getrandom`] to seed *many* PRNGs is an
438428
/// issue, one may prefer to seed from a local PRNG, e.g.
439429
/// `from_rng(thread_rng()).unwrap()`.
@@ -443,6 +433,7 @@ pub trait SeedableRng: Sized {
443433
/// If [`getrandom`] is unable to provide secure entropy this method will panic.
444434
///
445435
/// [`getrandom`]: https://docs.rs/getrandom
436+
/// [`try_from_entropy`]: SeedableRng::try_from_entropy
446437
#[cfg(feature = "getrandom")]
447438
#[cfg_attr(doc_cfg, doc(cfg(feature = "getrandom")))]
448439
fn from_entropy() -> Self {
@@ -452,10 +443,8 @@ pub trait SeedableRng: Sized {
452443
}
453444
}
454445

455-
/// Creates a new instance of the RNG seeded via [`getrandom`].
456-
///
457-
/// This method is the recommended way to construct non-deterministic PRNGs
458-
/// since it is convenient and secure.
446+
/// Creates a new instance of the RNG seeded via [`getrandom`] without unwrapping
447+
/// potential [`getrandom`] errors.
459448
///
460449
/// In case the overhead of using [`getrandom`] to seed *many* PRNGs is an
461450
/// issue, one may prefer to seed from a local PRNG, e.g.

src/rng.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ pub trait Rng: RngCore {
223223
/// The distribution is expected to be uniform with portable results, but
224224
/// this cannot be guaranteed for third-party implementations.
225225
///
226-
/// This is identical to [`try_fill`] except that it panics on error.
227-
///
228226
/// # Example
229227
///
230228
/// ```
@@ -235,7 +233,6 @@ pub trait Rng: RngCore {
235233
/// ```
236234
///
237235
/// [`fill_bytes`]: RngCore::fill_bytes
238-
/// [`try_fill`]: Rng::try_fill
239236
fn fill<T: Fill + ?Sized>(&mut self, dest: &mut T) {
240237
dest.fill(self)
241238
}

0 commit comments

Comments
 (0)