Skip to content

Commit

Permalink
CryptoRngCore: Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vks committed Sep 20, 2021
1 parent c797f07 commit a4fa077
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions rand_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,24 @@ pub trait RngCore {
/// [`BlockRngCore`]: block::BlockRngCore
pub trait CryptoRng {}

/// An extension trait to support trait objects that implement [`RngCore`] and
/// [`CryptoRng`]. Upcasting to [`RngCore`] is supported via the
/// [`CryptoRngCore::as_rngcore`] method.
/// An extension trait that is automatically implemented for any type
/// implementing [`RngCore`] and [`CryptoRng`].
///
/// It may be used as a trait object, and supports upcasting to [`RngCore`] via
/// the [`CryptoRngCore::as_rngcore`] method.
///
/// # Example
///
/// ```
/// use rand_core::CryptoRngCore;
///
/// #[allow(unused)]
/// fn make_token(rng: &mut dyn CryptoRngCore) -> [u8; 32] {
/// let mut buf = [0u8; 32];
/// rng.fill_bytes(&mut buf);
/// buf
/// }
/// ```
pub trait CryptoRngCore: RngCore {
/// Upcast to an [`RngCore`] trait object.
fn as_rngcore(&mut self) -> &mut dyn RngCore;
Expand Down

0 comments on commit a4fa077

Please sign in to comment.