mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-10-01 14:30:33 +00:00
56 lines
9.5 KiB
HTML
56 lines
9.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="32-bit hashing machinery"><meta name="keywords" content="rust, rustlang, rust-lang, hash32"><title>hash32 - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings" ></script><script src="../storage.js"></script><script src="../crates.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../hash32/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><h2 class="location">Crate hash32</h2><div class="block version"><div class="narrow-helper"></div><p>Version 0.2.1</p></div><div class="sidebar-elems"><a id="all-types" href="all.html"><p>See all hash32's items</p></a><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#traits">Traits</a></li></ul></div><div id="sidebar-vars" data-name="hash32" data-ty="mod" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="18" height="18" alt="Pick another theme!" src="../brush.svg"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../settings.html" title="settings"><img width="18" height="18" alt="Change settings" src="../wheel.svg"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Crate <a class="mod" href="#">hash32</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../src/hash32/lib.rs.html#1-363" title="goto source code">[src]</a></span></h1><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>32-bit hashing machinery</p>
|
||
<h2 id="why" class="section-header"><a href="#why">Why?</a></h2>
|
||
<p>Because 32-bit architectures are a thing (e.g. ARM Cortex-M) and you don’t want your hashing
|
||
function to pull in a bunch of slow 64-bit compiler intrinsics (software implementations of
|
||
64-bit operations).</p>
|
||
<h2 id="relationship-to-corehash" class="section-header"><a href="#relationship-to-corehash">Relationship to <code>core::hash</code></a></h2>
|
||
<p>This crate exposes the same interfaces you’ll find in <a href="https://doc.rust-lang.org/std/hash/index.html"><code>core::hash</code></a>: <code>Hash</code>, <code>Hasher</code>,
|
||
<code>BuildHasher</code> and <code>BuildHasherDefault</code>. The main difference is that <code>hash32::Hasher::finish</code>
|
||
returns a <code>u32</code> instead of <code>u64</code>, and the contract of <code>hash32::Hasher</code> forbids the implementer
|
||
from performing 64-bit (or 128-bit) operations while computing the hash.</p>
|
||
<h2 id="derivehash32" class="section-header"><a href="#derivehash32"><code>#[derive(Hash32)]</code></a></h2>
|
||
<p>The easiest way to implement <code>hash32::Hash</code> for a <code>struct</code> is to use the <code>#[derive(Hash32)]</code>.</p>
|
||
<p>Note that you need to <em>explicitly</em> depend on both <code>hash32</code> <em>and</em> <code>hash32_derive</code>; both crates
|
||
must appear in your <code>Cargo.toml</code>.</p>
|
||
|
||
<div class='information'><div class='tooltip ignore'>ⓘ</div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore"><code><span class="kw">use</span> <span class="ident">hash32_derive::Hash32</span>;
|
||
|
||
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Hash32</span>)]</span>
|
||
<span class="kw">struct</span> <span class="ident">Ipv4Addr</span>([<span class="ident">u8</span>; <span class="number">4</span>]);
|
||
|
||
</code></pre></div>
|
||
<h2 id="hashers" class="section-header"><a href="#hashers">Hashers</a></h2>
|
||
<p>This crate provides implementations of the following 32-bit hashing algorithms:</p>
|
||
<ul>
|
||
<li><a href="struct.FnvHasher.html">Fowler-Noll-Vo</a></li>
|
||
<li><a href="struct.Murmur3Hasher.html">MurmurHash3</a></li>
|
||
</ul>
|
||
<h2 id="msrv" class="section-header"><a href="#msrv">MSRV</a></h2>
|
||
<p>This crate is guaranteed to compile on latest stable Rust. It <em>might</em> compile on older
|
||
versions but that may change in any new patch release.</p>
|
||
<h2 id="future" class="section-header"><a href="#future">Future</a></h2>
|
||
<p>In the future we’d like to deprecate this crate in favor of making <code>core::hash::Hasher</code> generic
|
||
over the size of the computed hash. Below is shown the planned change (but it doesn’t work due
|
||
to limitations in the <code>associated_type_defaults</code> feature):</p>
|
||
|
||
<div class='information'><div class='tooltip ignore'>ⓘ</div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">associated_type_defaults</span>)]</span>
|
||
|
||
<span class="kw">trait</span> <span class="ident">Hasher</span> {
|
||
<span class="kw">type</span> <span class="ident">Hash</span> <span class="op">=</span> <span class="ident">u64</span>; <span class="comment">// default type for backwards compatibility</span>
|
||
|
||
<span class="kw">fn</span> <span class="ident">finish</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident"><span class="self">Self</span>::Hash</span>; <span class="comment">// changed</span>
|
||
<span class="kw">fn</span> <span class="ident">write</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>, <span class="ident">bytes</span>: <span class="kw-2">&</span>[<span class="ident">u8</span>]);
|
||
}</code></pre></div>
|
||
<p>With this change a single <code>#[derive(Hash)]</code> would enough to make a type hashable with 32-bit and
|
||
64-bit hashers.</p>
|
||
</div></details><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2>
|
||
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.BuildHasherDefault.html" title="hash32::BuildHasherDefault struct">BuildHasherDefault</a></div><div class="item-right docblock-short"><p>See <a href="https://doc.rust-lang.org/core/hash/struct.BuildHasherDefault.html"><code>core::hash::BuildHasherDefault</code></a> for details</p>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.FnvHasher.html" title="hash32::FnvHasher struct">FnvHasher</a></div><div class="item-right docblock-short"><p>32-bit Fowler-Noll-Vo hasher</p>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Murmur3Hasher.html" title="hash32::Murmur3Hasher struct">Murmur3Hasher</a></div><div class="item-right docblock-short"><p>32-bit MurmurHash3 hasher</p>
|
||
</div></div></div><h2 id="traits" class="section-header"><a href="#traits">Traits</a></h2>
|
||
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.BuildHasher.html" title="hash32::BuildHasher trait">BuildHasher</a></div><div class="item-right docblock-short"><p>See <a href="https://doc.rust-lang.org/core/hash/trait.BuildHasher.html"><code>core::hash::BuildHasher</code></a> for details</p>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Hash.html" title="hash32::Hash trait">Hash</a></div><div class="item-right docblock-short"><p>See <a href="https://doc.rust-lang.org/core/hash/trait.Hash.html"><code>core::hash::Hash</code></a> for details</p>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Hasher.html" title="hash32::Hasher trait">Hasher</a></div><div class="item-right docblock-short"><p>See <a href="https://doc.rust-lang.org/core/hash/trait.Hasher.html"><code>core::hash::Hasher</code></a> for details</p>
|
||
</div></div></div></section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="hash32" data-search-index-js="../search-index.js" data-search-js="../search.js"></div>
|
||
<script src="../main.js"></script>
|
||
</body></html> |