<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="32-bit hashing machinery"><title>hash32 - Rust</title><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><linkrel="stylesheet"href="../static.files/normalize-76eba96aa4d2e634.css"><linkrel="stylesheet"href="../static.files/rustdoc-cb6f1f67f1bcd037.css"id="mainThemeStyle"><metaname="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"><scriptsrc="../static.files/storage-db41da1a38ea3cb8.js"></script><scriptdefersrc="../crates.js"></script><scriptdefersrc="../static.files/main-0795b7d26be81095.js"></script><noscript><linkrel="stylesheet"media="(prefers-color-scheme:light)"href="../static.files/light-6d2c9675f3d09c26.css"><linkrel="stylesheet"media="(prefers-color-scheme:dark)"href="../static.files/dark-45ceb8f2e522f4d1.css"><linkrel="stylesheet"href="../static.files/noscript-cffde32267a19fd6.css"></noscript><linkrel="alternate icon"type="image/png"href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><linkrel="alternate icon"type="image/png"href="../static.files/favicon-32x32-422f7d1d52889060.png"><linkrel="icon"type="image/svg+xml"href="../static.files/favicon-2c020d218678b618.svg"></head><bodyclass="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="mobile-topbar"><buttonclass="sidebar-menu-toggle">☰</button><aclass="logo-container"href="../hash32/index.html"><imgclass="rust-logo"src="../static.files/rust-logo-151179464ae7ed46.svg"alt="logo"></a><h2></h2></nav><navclass="sidebar"><aclass="logo-container"href="../hash32/index.html"><imgclass="rust-logo"src="../static.files/rust-logo-151179464ae7ed46.svg"alt="logo"></a><h2class="location"><ahref="#">Crate hash32</a></h2><divclass="sidebar-elems"><ulclass="block"><liclass="version">Version 0.2.1</li><li><aid="all-types"href="all.html">All Items</a></li></ul><section><ulclass="block"><li><ahref="#structs">Structs</a></li><li><ahref="#traits">Traits</a></li></ul></section></div></nav><main><divclass="width-limiter"><navclass="sub"><formclass="search-form"><span></span><inputclass="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"><divid="help-button"title="help"tabindex="-1"><ahref="../help.html">?</a></div><divid="settings-menu"tabindex="-1"><ahref="../settings.html"title="settings"><imgwidth="22"height="22"alt="Change settings"src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><sectionid="main-content"class="content"><divclass="main-heading"><h1>Crate <aclass
<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>
<h2id="relationship-to-corehash"><ahref="#relationship-to-corehash">Relationship to <code>core::hash</code></a></h2>
<p>This crate exposes the same interfaces you’ll find in <ahref="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>
<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>
<divclass="example-wrap ignore"><ahref="#"class="tooltip"title="This example is not tested">ⓘ</a><preclass="rust rust-example-rendered"><code><spanclass="kw">use </span>hash32_derive::Hash32;
<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>
<h2id="future"><ahref="#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>
<divclass="example-wrap ignore"><ahref="#"class="tooltip"title="This example is not tested">ⓘ</a><preclass="rust rust-example-rendered"><code><spanclass="attr">#![feature(associated_type_defaults)]
</span><spanclass="kw">trait </span>Hasher {
<spanclass="kw">type </span>Hash = u64; <spanclass="comment">// default type for backwards compatibility