Rust-for-Arduboy/docs/doc/hash32/index.html

46 lines
9.6 KiB
HTML
Raw Normal View History

2023-08-23 08:44:29 +02:00
<!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"><title>hash32 - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-cb6f1f67f1bcd037.css" id="mainThemeStyle"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="hash32" data-themes="" data-resource-suffix="" data-rustdoc-version="1.73.0-nightly (8131b9774 2023-08-02)" data-channel="nightly" data-search-js="search-6dfdfced5eff6596.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-6d2c9675f3d09c26.css" data-theme-dark-css="dark-45ceb8f2e522f4d1.css" data-theme-ayu-css="ayu-fd19013d6ce078bf.css" ><script src="../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-0795b7d26be81095.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-6d2c9675f3d09c26.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-45ceb8f2e522f4d1.css"><link rel="stylesheet" href="../static.files/noscript-cffde32267a19fd6.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></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="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="logo-container" href="../hash32/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../hash32/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2 class="location"><a href="#">Crate hash32</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.2.1</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#traits">Traits</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class
<h2 id="why"><a href="#why">Why?</a></h2>
<p>Because 32-bit architectures are a thing (e.g. ARM Cortex-M) and you dont 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"><a href="#relationship-to-corehash">Relationship to <code>core::hash</code></a></h2>
<p>This crate exposes the same interfaces youll 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"><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="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested"></a><pre class="rust rust-example-rendered"><code><span class="kw">use </span>hash32_derive::Hash32;
<span class="attr">#[derive(Hash32)]
</span><span class="kw">struct </span>Ipv4Addr([u8; <span class="number">4</span>]);
</code></pre></div>
<h2 id="hashers"><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"><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"><a href="#future">Future</a></h2>
<p>In the future wed 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 doesnt work due
to limitations in the <code>associated_type_defaults</code> feature):</p>
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested"></a><pre class="rust rust-example-rendered"><code><span class="attr">#![feature(associated_type_defaults)]
</span><span class="kw">trait </span>Hasher {
<span class="kw">type </span>Hash = u64; <span class="comment">// default type for backwards compatibility
</span><span class="kw">fn </span>finish(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="self">Self</span>::Hash; <span class="comment">// changed
</span><span class="kw">fn </span>write(<span class="kw-2">&amp;mut </span><span class="self">self</span>, bytes: <span class="kw-2">&amp;</span>[u8]);
}</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="small-section-header"><a href="#structs">Structs</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.BuildHasherDefault.html" title="struct hash32::BuildHasherDefault">BuildHasherDefault</a></div><div class="desc docblock-short">See <a href="https://doc.rust-lang.org/core/hash/struct.BuildHasherDefault.html"><code>core::hash::BuildHasherDefault</code></a> for details</div></li><li><div class="item-name"><a class="struct" href="struct.FnvHasher.html" title="struct hash32::FnvHasher">FnvHasher</a></div><div class="desc docblock-short">32-bit Fowler-Noll-Vo hasher</div></li><li><div class="item-name"><a class="struct" href="struct.Murmur3Hasher.html" title="struct hash32::Murmur3Hasher">Murmur3Hasher</a></div><div class="desc docblock-short">32-bit MurmurHash3 hasher</div></li></ul><h2 id="traits" class="small-section-header"><a href="#traits">Traits</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.BuildHasher.html" title="trait hash32::BuildHasher">BuildHasher</a></div><div class="desc docblock-short">See <a href="https://doc.rust-lang.org/core/hash/trait.BuildHasher.html"><code>core::hash::BuildHasher</code></a> for details</div></li><li><div class="item-name"><a class="trait" href="trait.Hash.html" title="trait hash32::Hash">Hash</a></div><div class="desc docblock-short">See <a href="https://doc.rust-lang.org/core/hash/trait.Hash.html"><code>core::hash::Hash</code></a> for details</div></li><li><div class="item-name"><a class="trait" href="trait.Hasher.html" title="trait hash32::Hasher">Hasher</a></div><div class="desc docblock-short">See <a href="https://doc.rust-lang.org/core/hash/trait.Hasher.html"><code>core::hash::Hasher</code></a> for details</div></li></ul></section></div></main></body></html>