Skip to content

Commit a4fa077

Browse files
committed
CryptoRngCore: Improve docs
1 parent c797f07 commit a4fa077

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

rand_core/src/lib.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,24 @@ pub trait RngCore {
208208
/// [`BlockRngCore`]: block::BlockRngCore
209209
pub trait CryptoRng {}
210210

211-
/// An extension trait to support trait objects that implement [`RngCore`] and
212-
/// [`CryptoRng`]. Upcasting to [`RngCore`] is supported via the
213-
/// [`CryptoRngCore::as_rngcore`] method.
211+
/// An extension trait that is automatically implemented for any type
212+
/// implementing [`RngCore`] and [`CryptoRng`].
213+
///
214+
/// It may be used as a trait object, and supports upcasting to [`RngCore`] via
215+
/// the [`CryptoRngCore::as_rngcore`] method.
216+
///
217+
/// # Example
218+
///
219+
/// ```
220+
/// use rand_core::CryptoRngCore;
221+
///
222+
/// #[allow(unused)]
223+
/// fn make_token(rng: &mut dyn CryptoRngCore) -> [u8; 32] {
224+
/// let mut buf = [0u8; 32];
225+
/// rng.fill_bytes(&mut buf);
226+
/// buf
227+
/// }
228+
/// ```
214229
pub trait CryptoRngCore: RngCore {
215230
/// Upcast to an [`RngCore`] trait object.
216231
fn as_rngcore(&mut self) -> &mut dyn RngCore;

0 commit comments

Comments
 (0)