<!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="This library provides heavily optimized routines for string search primitives."><title>memchr - 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/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><linkrel="stylesheet"href="../static.files/normalize-76eba96aa4d2e634.css"><linkrel="stylesheet"href="../static.files/rustdoc-ac92e1bbe349e143.css"><metaname="rustdoc-vars"data-root-path="../"data-static-root-path="../static.files/"data-current-crate="memchr"data-themes=""data-resource-suffix=""data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)"data-channel="1.76.0"data-search-js="search-2b6ce74ff89ae146.js"data-settings-js="settings-4313503d2e1961c2.js"><scriptsrc="../static.files/storage-f2adc0d6ca4d09fb.js"></script><scriptdefersrc="../crates.js"></script><scriptdefersrc="../static.files/main-305769736d49e732.js"></script><noscript><linkrel="stylesheet"href="../static.files/noscript-feafe1bb7466e4bd.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></nav><navclass="sidebar"><divclass="sidebar-crate"><h2><ahref="../memchr/index.html">memchr</a><spanclass="version">2.7.1</span></h2></div><divclass="sidebar-elems"><ulclass="block">
<main><divclass="width-limiter"><navclass="sub"><formclass="search-form"><span></span><divid="sidebar-button"tabindex="-1"><ahref="../memchr/all.html"title="show sidebar"></a></div><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"tabindex="-1"><ahref="../help.html"title="help">?</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="mod"href="#">memchr</a><buttonid="copy-path"title="Copy item path to clipboard"><imgsrc="../static.files/clipboard-7571035ce49a181d.svg"width="19"height="18"alt="Copy item path"></button></h1><spanclass="out-of-band"><aclass="src"href="../src/memchr/lib.rs.html#1-221">source</a> · <buttonid="toggle-all-docs"title="collapse all docs">[<span>−</span>]</button></span></div><detailsclass="toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><p>This library provides heavily optimized routines for string search primitives.</p>
<h2id="example-matching-one-of-three-possible-bytes"><ahref="#example-matching-one-of-three-possible-bytes">Example: matching one of three possible bytes</a></h2>
<p>This examples shows how to use <code>memrchr3</code> to find occurrences of <code>a</code>, <code>b</code> or
<code>c</code>, starting at the end of the haystack.</p>
<h2id="example-repeating-a-search-for-the-same-needle"><ahref="#example-repeating-a-search-for-the-same-needle">Example: repeating a search for the same needle</a></h2>
<p>It may be possible for the overhead of constructing a substring searcher to be
measurable in some workloads. In cases where the same needle is used to search
many haystacks, it is possible to do construction once and thus to avoid it for
subsequent searches. This can be done with a <ahref="memmem/struct.Finder.html"title="struct memchr::memmem::Finder"><code>memmem::Finder</code></a>:</p>
<ahref="memmem/struct.Finder.html#method.into_owned"title="method memchr::memmem::Finder::into_owned"><code>memmem::Finder::into_owned</code></a> API and the
implementation. Otherwise, this crate is designed from the ground up to be
usable in core-only contexts, so the <code>alloc</code> feature doesn’t add much
currently. Notably, disabling <code>std</code> but enabling <code>alloc</code> will <strong>not</strong> result
in the use of AVX2 on <code>x86_64</code> targets unless the <code>avx2</code> feature is enabled
at compile time. (With <code>std</code> enabled, AVX2 can be used even without the <code>avx2</code>
feature enabled at compile time by way of runtime CPU feature detection.)</li>
<li><strong>logging</strong> - When enabled (disabled by default), the <code>log</code> crate is used
to emit log messages about what kinds of <code>memchr</code> and <code>memmem</code> algorithms
are used. Namely, both <code>memchr</code> and <code>memmem</code> have a number of different
implementation choices depending on the target and CPU, and the log messages
can help show what specific implementations are being used. Generally, this is
useful for debugging performance issues.</li>
<li><strong>libc</strong> - <strong>DEPRECATED</strong>. Previously, this enabled the use of the target’s
<code>memchr</code> function from whatever <code>libc</code> was linked into the program. This
feature is now a no-op because this crate’s implementation of <code>memchr</code> should
now be sufficiently fast on a number of platforms that <code>libc</code> should no longer
be needed. (This feature is somewhat of a holdover from this crate’s origins.
Originally, this crate was literally just a safe wrapper function around the
<code>memchr</code> function from <code>libc</code>.)</li>
</ul>
</div></details><h2id="modules"class="section-header"><ahref="#modules">Modules</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="mod"href="arch/index.html"title="mod memchr::arch">arch</a></div><divclass="desc docblock-short">A module with low-level architecture dependent routines.</div></li><li><divclass="item-name"><aclass="mod"href="memmem/index.html"title="mod memchr::memmem">memmem</a></div><divclass="desc docblock-short">This module provides forward and reverse substring search routines.</div></li></ul><h2id="structs"class="section-header"><ahref="#structs">Structs</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="struct"href="struct.Memchr.html"title="struct memchr::Memchr">Memchr</a></div><divclass="desc docblock-short">An iterator over all occurrences of a single byte in a haystack.</div></li><li><divclass="item-name"><aclass="struct"href="struct.Memchr2.html"title="struct memchr::Memchr2">Memchr2</a></div><divclass="desc docblock-short">An iterator over all occurrences of two possible bytes in a haystack.</div></li><li><divclass="item-name"><aclass="struct"href="struct.Memchr3.html"title="struct memchr::Memchr3">Memchr3</a></div><divclass="desc docblock-short">An iterator over all occurrences of three possible bytes in a haystack.</div></li></ul><h2id="functions"class="section-header"><ahref="#functions">Functions</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="fn"href="fn.memchr.html"title="fn memchr::memchr">memchr</a></div><divclass="desc docblock-short">Search for the first occurrence of a byte in a slice.</div></li><li><divclass="item-name"><aclass="fn"href="fn.memchr2.html"title="fn memchr::memchr2">memchr2</a></div><divclass="desc docblock-short">Search for the first occurrence of two possible bytes in a haystack.</div></li><li><divclass="item-name"><aclass="fn"href="fn.memchr2_iter.html"title="fn memchr::memchr2_iter">memchr2_iter</a></div><divclass="desc docblock-short">Returns an iterator over all occurrences of the needles in a haystack.</div></li><li><divclass="item-name"><aclass="fn"href="fn.memchr3.html"title="fn memchr::memchr3">memchr3</a></div><divclass="desc docblock-short">Search for the first occurrence of three possible bytes in a haystack.</div></li><li><divclass="item-name"><aclass="fn"href="fn.memchr3_iter.html"title="fn memchr::memchr3_iter">memchr3_iter</a></div><divclass="desc docblock-short">Returns an iterator over all occurrences of the needles in a haystack.</div></li><li><divclass="item-name"><aclass="fn"href="fn.memchr_iter.html"title="fn memchr::memchr_iter">memchr_iter</a></div><divclass="desc docblock-short">Returns an iterator over all occurrences of the needle in a haystack.</div></li><li><divclass="item-name"><aclass="fn"href="fn.memrchr.html"title="fn memchr::memrchr">memrchr</a></div><divclass="desc docblock-short">Search for the last occurrence of a byte in a slice.</div></li><li><divclass="item-name"><aclass="fn"href="fn.memrchr2.html"title="fn memchr::memrchr2">memrchr2</a></div><divclass="desc docblock-short">Search for the last occurrence of two possible bytes in a haystack.</div></li><li><divclass="item-name"><aclass="fn"href="fn.memrchr2_iter.html"title="fn memchr::memrchr2_iter">memrchr2_iter</a></div><divclass="desc docblock-short">Returns an iterator over all occurrences of the needles in a haystack, in
reverse.</div></li><li><divclass="item-name"><aclass="fn"href="fn.memrchr3.html"title="fn memchr::memrchr3">memrchr3</a></div><divclass="desc docblock-short">Search for the last occurrence of three possible bytes in a haystack.</div></li><li><divclass="item-name"><aclass="fn"href="fn.memrchr3_iter.html"title="fn memchr::memrchr3_iter">memrchr3_iter</a></div><divclass="desc docblock-short">Returns an iterator over all occurrences of the needles in a haystack, in
reverse.</div></li><li><divclass="item-name"><aclass="fn"href="fn.memrchr_iter.html"title="fn memchr::memrchr_iter">memrchr_iter</a></div><divclass="desc docblock-short">Returns an iterator over all occurrences of the needle in a haystack, in