Files
GopherGate/target/doc/rand_core/block/index.html
2026-02-26 12:00:21 -05:00

44 lines
7.5 KiB
HTML

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="The `BlockRngCore` trait and implementation helpers"><title>rand_core::block - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="rand_core" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.css"></noscript><link rel="icon" href="https://www.rust-lang.org/favicon.ico"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Module block</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../rand_core/index.html"><img src="https://www.rust-lang.org/logos/rust-logo-128x128-blk.png" alt="logo"></a><h2><a href="../../rand_core/index.html">rand_<wbr>core</a><span class="version">0.9.5</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module block</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</a></li></ul><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#traits" title="Traits">Traits</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate rand_<wbr>core</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">rand_core</a></div><h1>Module <span>block</span>&nbsp;<button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/rand_core/block.rs.html#9-534">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>The <code>BlockRngCore</code> trait and implementation helpers</p>
<p>The <a href="trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore"><code>BlockRngCore</code></a> trait exists to assist in the implementation of RNGs
which generate a block of data in a cache instead of returning generated
values directly.</p>
<p>Usage of this trait is optional, but provides two advantages:
implementations only need to concern themselves with generation of the
block, not the various <a href="../trait.RngCore.html" title="trait rand_core::RngCore"><code>RngCore</code></a> methods (especially <a href="../trait.RngCore.html#tymethod.fill_bytes" title="method rand_core::RngCore::fill_bytes"><code>fill_bytes</code></a>, where
the optimal implementations are not trivial), and this allows
<code>ReseedingRng</code> (see <a href="https://docs.rs/rand"><code>rand</code></a> crate) perform periodic
reseeding with very low overhead.</p>
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand_core::{RngCore, SeedableRng};
<span class="kw">use </span>rand_core::block::{BlockRngCore, BlockRng};
<span class="kw">struct </span>MyRngCore;
<span class="kw">impl </span>BlockRngCore <span class="kw">for </span>MyRngCore {
<span class="kw">type </span>Item = u32;
<span class="kw">type </span>Results = [u32; <span class="number">16</span>];
<span class="kw">fn </span>generate(<span class="kw-2">&amp;mut </span><span class="self">self</span>, results: <span class="kw-2">&amp;mut </span><span class="self">Self</span>::Results) {
<span class="macro">unimplemented!</span>()
}
}
<span class="kw">impl </span>SeedableRng <span class="kw">for </span>MyRngCore {
<span class="kw">type </span>Seed = [u8; <span class="number">32</span>];
<span class="kw">fn </span>from_seed(seed: <span class="self">Self</span>::Seed) -&gt; <span class="self">Self </span>{
<span class="macro">unimplemented!</span>()
}
}
<span class="comment">// optionally, also implement CryptoBlockRng for MyRngCore
// Final RNG.
</span><span class="kw">let </span><span class="kw-2">mut </span>rng = BlockRng::&lt;MyRngCore&gt;::seed_from_u64(<span class="number">0</span>);
<span class="macro">println!</span>(<span class="string">"First value: {}"</span>, rng.next_u32());</code></pre></div></div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.BlockRng.html" title="struct rand_core::block::BlockRng">Block<wbr>Rng</a></dt><dd>A wrapper type implementing <a href="../trait.RngCore.html" title="trait rand_core::RngCore"><code>RngCore</code></a> for some type implementing
<a href="trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore"><code>BlockRngCore</code></a> with <code>u32</code> array buffer; i.e. this can be used to implement
a full RNG from just a <code>generate</code> function.</dd><dt><a class="struct" href="struct.BlockRng64.html" title="struct rand_core::block::BlockRng64">Block<wbr>Rng64</a></dt><dd>A wrapper type implementing <a href="../trait.RngCore.html" title="trait rand_core::RngCore"><code>RngCore</code></a> for some type implementing
<a href="trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore"><code>BlockRngCore</code></a> with <code>u64</code> array buffer; i.e. this can be used to implement
a full RNG from just a <code>generate</code> function.</dd></dl><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><dl class="item-table"><dt><a class="trait" href="trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore">Block<wbr>RngCore</a></dt><dd>A trait for RNGs which do not generate random numbers individually, but in
blocks (typically <code>[u32; N]</code>). This technique is commonly used by
cryptographic RNGs to improve performance.</dd><dt><a class="trait" href="trait.CryptoBlockRng.html" title="trait rand_core::block::CryptoBlockRng">Crypto<wbr>Block<wbr>Rng</a></dt><dd>A marker trait used to indicate that an <a href="../trait.RngCore.html" title="trait rand_core::RngCore"><code>RngCore</code></a> implementation is
supposed to be cryptographically secure.</dd></dl></section></div></main></body></html>