wasmer/rustdoc/aho_corasick/struct.AhoCorasick.html
2019-09-16 15:54:50 -07:00

646 lines
109 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="API documentation for the Rust `AhoCorasick` struct in crate `aho_corasick`."><meta name="keywords" content="rust, rustlang, rust-lang, AhoCorasick"><title>aho_corasick::AhoCorasick - 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="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc struct"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../aho_corasick/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><p class='location'>Struct AhoCorasick</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.earliest_find">earliest_find</a><a href="#method.find">find</a><a href="#method.find_iter">find_iter</a><a href="#method.find_overlapping_iter">find_overlapping_iter</a><a href="#method.heap_bytes">heap_bytes</a><a href="#method.is_match">is_match</a><a href="#method.match_kind">match_kind</a><a href="#method.max_pattern_len">max_pattern_len</a><a href="#method.new">new</a><a href="#method.new_auto_configured">new_auto_configured</a><a href="#method.pattern_count">pattern_count</a><a href="#method.replace_all">replace_all</a><a href="#method.replace_all_bytes">replace_all_bytes</a><a href="#method.replace_all_with">replace_all_with</a><a href="#method.replace_all_with_bytes">replace_all_with_bytes</a><a href="#method.stream_find_iter">stream_find_iter</a><a href="#method.stream_replace_all">stream_replace_all</a><a href="#method.stream_replace_all_with">stream_replace_all_with</a><a href="#method.supports_overlapping">supports_overlapping</a><a href="#method.supports_stream">supports_stream</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Clone">Clone</a><a href="#impl-Debug">Debug</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-RefUnwindSafe">RefUnwindSafe</a><a href="#impl-Send">Send</a><a href="#impl-Sync">Sync</a><a href="#impl-Unpin">Unpin</a><a href="#impl-UnwindSafe">UnwindSafe</a></div><a class="sidebar-title" href="#blanket-implementations">Blanket Implementations</a><div class="sidebar-links"><a href="#impl-Any">Any</a><a href="#impl-Borrow%3CT%3E">Borrow&lt;T&gt;</a><a href="#impl-BorrowMut%3CT%3E">BorrowMut&lt;T&gt;</a><a href="#impl-From%3CT%3E">From&lt;T&gt;</a><a href="#impl-Into%3CU%3E">Into&lt;U&gt;</a><a href="#impl-ToOwned">ToOwned</a><a href="#impl-TryFrom%3CU%3E">TryFrom&lt;U&gt;</a><a href="#impl-TryInto%3CU%3E">TryInto&lt;U&gt;</a></div></div><p class='location'><a href='index.html'>aho_corasick</a></p><script>window.sidebarCurrent = {name: 'AhoCorasick', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><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'>&#x2212;</span>]</a></span><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#86-89' title='goto source code'>[src]</a></span><span class='in-band'>Struct <a href='index.html'>aho_corasick</a>::<wbr><a class="struct" href=''>AhoCorasick</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class='rust struct'>pub struct AhoCorasick&lt;S:&nbsp;<a class="trait" href="../aho_corasick/trait.StateID.html" title="trait aho_corasick::StateID">StateID</a>&nbsp;=&nbsp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>&gt; { /* fields omitted */ }</pre></div><div class='docblock'><p>An automaton for searching multiple strings in linear time.</p>
<p>The <code>AhoCorasick</code> type supports a few basic ways of constructing an
automaton, including
<a href="struct.AhoCorasick.html#method.new"><code>AhoCorasick::new</code></a>
and
<a href="struct.AhoCorasick.html#method.new_auto_configured"><code>AhoCorasick::new_auto_configured</code></a>.
However, there are a fair number of configurable options that can be set
by using
<a href="struct.AhoCorasickBuilder.html"><code>AhoCorasickBuilder</code></a>
instead. Such options include, but are not limited to, how matches are
determined, simple case insensitivity, whether to use a DFA or not and
various knobs for controlling the space-vs-time trade offs taken when
building the automaton.</p>
<p>If you aren't sure where to start, try beginning with
<a href="struct.AhoCorasick.html#method.new_auto_configured"><code>AhoCorasick::new_auto_configured</code></a>.</p>
<h1 id="resource-usage" class="section-header"><a href="#resource-usage">Resource usage</a></h1>
<p>Aho-Corasick automatons are always constructed in <code>O(p)</code> time, where <code>p</code>
is the combined length of all patterns being searched. With that said,
building an automaton can be fairly costly because of high constant
factors, particularly when enabling the
<a href="struct.AhoCorasickBuilder.html#method.dfa">DFA</a>
option (which is disabled by default). For this reason, it's generally a
good idea to build an automaton once and reuse it as much as possible.</p>
<p>Aho-Corasick automatons can also use a fair bit of memory. To get a
concrete idea of how much memory is being used, try using the
<a href="struct.AhoCorasick.html#method.heap_bytes"><code>AhoCorasick::heap_bytes</code></a>
method.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<p>This example shows how to search for occurrences of multiple patterns
simultaneously in a case insensitive fashion. Each match includes the
pattern that matched along with the byte offsets of the match.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">AhoCorasickBuilder</span>;
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;apple&quot;</span>, <span class="string">&quot;maple&quot;</span>, <span class="string">&quot;snapple&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;Nobody likes maple in their apple flavored Snapple.&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">ascii_case_insensitive</span>(<span class="bool-val">true</span>)
.<span class="ident">build</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">matches</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[];
<span class="kw">for</span> <span class="ident">mat</span> <span class="kw">in</span> <span class="ident">ac</span>.<span class="ident">find_iter</span>(<span class="ident">haystack</span>) {
<span class="ident">matches</span>.<span class="ident">push</span>((<span class="ident">mat</span>.<span class="ident">pattern</span>(), <span class="ident">mat</span>.<span class="ident">start</span>(), <span class="ident">mat</span>.<span class="ident">end</span>()));
}
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">matches</span>, <span class="macro">vec</span><span class="macro">!</span>[
(<span class="number">1</span>, <span class="number">13</span>, <span class="number">18</span>),
(<span class="number">0</span>, <span class="number">28</span>, <span class="number">33</span>),
(<span class="number">2</span>, <span class="number">43</span>, <span class="number">50</span>),
]);</pre></div>
<p>This example shows how to replace matches with some other string:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">AhoCorasick</span>;
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;fox&quot;</span>, <span class="string">&quot;brown&quot;</span>, <span class="string">&quot;quick&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;The quick brown fox.&quot;</span>;
<span class="kw">let</span> <span class="ident">replace_with</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;sloth&quot;</span>, <span class="string">&quot;grey&quot;</span>, <span class="string">&quot;slow&quot;</span>];
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasick</span>::<span class="ident">new</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="ident">result</span> <span class="op">=</span> <span class="ident">ac</span>.<span class="ident">replace_all</span>(<span class="ident">haystack</span>, <span class="ident">replace_with</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">result</span>, <span class="string">&quot;The slow grey sloth.&quot;</span>);</pre></div>
</div><h2 id='methods' class='small-section-header'>Methods<a href='#methods' class='anchor'></a></h2><h3 id='impl' class='impl'><code class='in-band'>impl <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a></code><a href='#impl' class='anchor'></a><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#91-160' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.new' class="method"><code id='new.v'>pub fn <a href='#method.new' class='fnname'>new</a>&lt;I, P&gt;(patterns: I) -&gt; <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>&lt;Item = P&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>&gt;,&nbsp;</span></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#119-125' title='goto source code'>[src]</a></h4><div class='docblock'><p>Create a new Aho-Corasick automaton using the default configuration.</p>
<p>The default configuration optimizes for less space usage, but at the
expense of longer search times. To change the configuration, use
<a href="struct.AhoCorasickBuilder.html"><code>AhoCorasickBuilder</code></a>
for fine-grained control, or
<a href="struct.AhoCorasick.html#method.new_auto_configured"><code>AhoCorasick::new_auto_configured</code></a>
for automatic configuration if you aren't sure which settings to pick.</p>
<p>This uses the default
<a href="enum.MatchKind.html#variant.Standard"><code>MatchKind::Standard</code></a>
match semantics, which reports a match as soon as it is found. This
corresponds to the standard match semantics supported by textbook
descriptions of the Aho-Corasick algorithm.</p>
<h1 id="examples-1" class="section-header"><a href="#examples-1">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">AhoCorasick</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasick</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span>[
<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;baz&quot;</span>,
]);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="number">1</span>), <span class="ident">ac</span>.<span class="ident">find</span>(<span class="string">&quot;xxx bar xxx&quot;</span>).<span class="ident">map</span>(<span class="op">|</span><span class="ident">m</span><span class="op">|</span> <span class="ident">m</span>.<span class="ident">pattern</span>()));</pre></div>
</div><h4 id='method.new_auto_configured' class="method"><code id='new_auto_configured.v'>pub fn <a href='#method.new_auto_configured' class='fnname'>new_auto_configured</a>&lt;B&gt;(patterns: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[B]</a>) -&gt; <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>&gt;,&nbsp;</span></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#154-159' title='goto source code'>[src]</a></h4><div class='docblock'><p>Build an Aho-Corasick automaton with an automatically determined
configuration.</p>
<p>Specifically, this requires a slice of patterns instead of an iterator
since the configuration is determined by looking at the patterns before
constructing the automaton. The idea here is to balance space and time
automatically. That is, when searching a small number of patterns, this
will attempt to use the fastest possible configuration since the total
space required will be small anyway. As the number of patterns grows,
this will fall back to slower configurations that use less space.</p>
<p>If you want auto configuration but with match semantics different from
the default <code>MatchKind::Standard</code>, then use
<a href="struct.AhoCorasickBuilder.html#method.auto_configure"><code>AhoCorasickBuilder::auto_configure</code></a>.</p>
<h1 id="examples-2" class="section-header"><a href="#examples-2">Examples</a></h1>
<p>Basic usage is just like <code>new</code>, except you must provide a slice:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">AhoCorasick</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasick</span>::<span class="ident">new_auto_configured</span>(<span class="kw-2">&amp;</span>[
<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;baz&quot;</span>,
]);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="number">1</span>), <span class="ident">ac</span>.<span class="ident">find</span>(<span class="string">&quot;xxx bar xxx&quot;</span>).<span class="ident">map</span>(<span class="op">|</span><span class="ident">m</span><span class="op">|</span> <span class="ident">m</span>.<span class="ident">pattern</span>()));</pre></div>
</div></div><h3 id='impl-1' class='impl'><code class='in-band'>impl&lt;S:&nbsp;<a class="trait" href="../aho_corasick/trait.StateID.html" title="trait aho_corasick::StateID">StateID</a>&gt; <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a>&lt;S&gt;</code><a href='#impl-1' class='anchor'></a><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#162-992' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.is_match' class="method"><code id='is_match.v'>pub fn <a href='#method.is_match' class='fnname'>is_match</a>&lt;B:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>&gt;&gt;(&amp;self, haystack: B) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#183-185' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns true if and only if this automaton matches the haystack at any
position.</p>
<p><code>haystack</code> may be any type that is cheaply convertible to a <code>&amp;[u8]</code>.
This includes, but is not limited to, <code>String</code>, <code>&amp;str</code>, <code>Vec&lt;u8&gt;</code>, and
<code>&amp;[u8]</code> itself.</p>
<h1 id="examples-3" class="section-header"><a href="#examples-3">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">AhoCorasick</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasick</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span>[
<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;quux&quot;</span>, <span class="string">&quot;baz&quot;</span>,
]);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">ac</span>.<span class="ident">is_match</span>(<span class="string">&quot;xxx bar xxx&quot;</span>));
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">ac</span>.<span class="ident">is_match</span>(<span class="string">&quot;xxx qux xxx&quot;</span>));</pre></div>
</div><h4 id='method.earliest_find' class="method"><code id='earliest_find.v'>pub fn <a href='#method.earliest_find' class='fnname'>earliest_find</a>&lt;B:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>&gt;&gt;(&amp;self, haystack: B) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../aho_corasick/struct.Match.html" title="struct aho_corasick::Match">Match</a>&gt;</code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#211-220' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the location of the first detected match in <code>haystack</code>.</p>
<p>This method has the same behavior regardless of the
<a href="enum.MatchKind.html"><code>MatchKind</code></a>
of this automaton.</p>
<p><code>haystack</code> may be any type that is cheaply convertible to a <code>&amp;[u8]</code>.
This includes, but is not limited to, <code>String</code>, <code>&amp;str</code>, <code>Vec&lt;u8&gt;</code>, and
<code>&amp;[u8]</code> itself.</p>
<h1 id="examples-4" class="section-header"><a href="#examples-4">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">AhoCorasick</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasick</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span>[
<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;b&quot;</span>,
]);
<span class="kw">let</span> <span class="ident">mat</span> <span class="op">=</span> <span class="ident">ac</span>.<span class="ident">earliest_find</span>(<span class="string">&quot;abcd&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;should have match&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">1</span>, <span class="ident">mat</span>.<span class="ident">pattern</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>((<span class="number">1</span>, <span class="number">2</span>), (<span class="ident">mat</span>.<span class="ident">start</span>(), <span class="ident">mat</span>.<span class="ident">end</span>()));</pre></div>
</div><h4 id='method.find' class="method"><code id='find.v'>pub fn <a href='#method.find' class='fnname'>find</a>&lt;B:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>&gt;&gt;(&amp;self, haystack: B) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../aho_corasick/struct.Match.html" title="struct aho_corasick::Match">Match</a>&gt;</code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#283-286' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the location of the first match according to the match
semantics that this automaton was constructed with.</p>
<p>When using <code>MatchKind::Standard</code>, this corresponds precisely to the
same behavior as
<a href="struct.AhoCorasick.html#method.earliest_find"><code>earliest_find</code></a>.
Otherwise, match semantics correspond to either
<a href="enum.MatchKind.html#variant.LeftmostFirst">leftmost-first</a>
or
<a href="enum.MatchKind.html#variant.LeftmostLongest">leftmost-longest</a>.</p>
<p><code>haystack</code> may be any type that is cheaply convertible to a <code>&amp;[u8]</code>.
This includes, but is not limited to, <code>String</code>, <code>&amp;str</code>, <code>Vec&lt;u8&gt;</code>, and
<code>&amp;[u8]</code> itself.</p>
<h1 id="examples-5" class="section-header"><a href="#examples-5">Examples</a></h1>
<p>Basic usage, with standard semantics:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasickBuilder</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;b&quot;</span>, <span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abcd&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;abcd&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">Standard</span>) <span class="comment">// default, not necessary</span>
.<span class="ident">build</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="ident">mat</span> <span class="op">=</span> <span class="ident">ac</span>.<span class="ident">find</span>(<span class="ident">haystack</span>).<span class="ident">expect</span>(<span class="string">&quot;should have a match&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;b&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">haystack</span>[<span class="ident">mat</span>.<span class="ident">start</span>()..<span class="ident">mat</span>.<span class="ident">end</span>()]);</pre></div>
<p>Now with leftmost-first semantics:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasickBuilder</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;b&quot;</span>, <span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abcd&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;abcd&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">LeftmostFirst</span>)
.<span class="ident">build</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="ident">mat</span> <span class="op">=</span> <span class="ident">ac</span>.<span class="ident">find</span>(<span class="ident">haystack</span>).<span class="ident">expect</span>(<span class="string">&quot;should have a match&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;abc&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">haystack</span>[<span class="ident">mat</span>.<span class="ident">start</span>()..<span class="ident">mat</span>.<span class="ident">end</span>()]);</pre></div>
<p>And finally, leftmost-longest semantics:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasickBuilder</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;b&quot;</span>, <span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abcd&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;abcd&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">LeftmostLongest</span>)
.<span class="ident">build</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="ident">mat</span> <span class="op">=</span> <span class="ident">ac</span>.<span class="ident">find</span>(<span class="ident">haystack</span>).<span class="ident">expect</span>(<span class="string">&quot;should have a match&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;abcd&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">haystack</span>[<span class="ident">mat</span>.<span class="ident">start</span>()..<span class="ident">mat</span>.<span class="ident">end</span>()]);</pre></div>
</div><h4 id='method.find_iter' class="method"><div class="important-traits"><div class='tooltip'><span class='tooltiptext'>Important traits for <a class="struct" href="../aho_corasick/struct.FindIter.html" title="struct aho_corasick::FindIter">FindIter</a>&lt;'a, 'b, S&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../aho_corasick/struct.FindIter.html" title="struct aho_corasick::FindIter">FindIter</a>&lt;'a, 'b, S&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, 'b, S:&nbsp;<a class="trait" href="../aho_corasick/trait.StateID.html" title="trait aho_corasick::StateID">StateID</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="../aho_corasick/struct.FindIter.html" title="struct aho_corasick::FindIter">FindIter</a>&lt;'a, 'b, S&gt;</span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="struct" href="../aho_corasick/struct.Match.html" title="struct aho_corasick::Match">Match</a>;</span></code></div></div><code id='find_iter.v'>pub fn <a href='#method.find_iter' class='fnname'>find_iter</a>&lt;'a, 'b, B:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>&gt;&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a self, <br>&nbsp;&nbsp;&nbsp;&nbsp;haystack: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;'b </a>B<br>) -&gt; <a class="struct" href="../aho_corasick/struct.FindIter.html" title="struct aho_corasick::FindIter">FindIter</a>&lt;'a, 'b, S&gt;</code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#350-355' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns an iterator of non-overlapping matches, using the match
semantics that this automaton was constructed with.</p>
<p><code>haystack</code> may be any type that is cheaply convertible to a <code>&amp;[u8]</code>.
This includes, but is not limited to, <code>String</code>, <code>&amp;str</code>, <code>Vec&lt;u8&gt;</code>, and
<code>&amp;[u8]</code> itself.</p>
<h1 id="examples-6" class="section-header"><a href="#examples-6">Examples</a></h1>
<p>Basic usage, with standard semantics:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasickBuilder</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;append&quot;</span>, <span class="string">&quot;appendage&quot;</span>, <span class="string">&quot;app&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;append the app to the appendage&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">Standard</span>) <span class="comment">// default, not necessary</span>
.<span class="ident">build</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="ident">matches</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">usize</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">ac</span>
.<span class="ident">find_iter</span>(<span class="ident">haystack</span>)
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">mat</span><span class="op">|</span> <span class="ident">mat</span>.<span class="ident">pattern</span>())
.<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">2</span>, <span class="number">2</span>, <span class="number">2</span>], <span class="ident">matches</span>);</pre></div>
<p>Now with leftmost-first semantics:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasickBuilder</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;append&quot;</span>, <span class="string">&quot;appendage&quot;</span>, <span class="string">&quot;app&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;append the app to the appendage&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">LeftmostFirst</span>)
.<span class="ident">build</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="ident">matches</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">usize</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">ac</span>
.<span class="ident">find_iter</span>(<span class="ident">haystack</span>)
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">mat</span><span class="op">|</span> <span class="ident">mat</span>.<span class="ident">pattern</span>())
.<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">0</span>], <span class="ident">matches</span>);</pre></div>
<p>And finally, leftmost-longest semantics:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasickBuilder</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;append&quot;</span>, <span class="string">&quot;appendage&quot;</span>, <span class="string">&quot;app&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;append the app to the appendage&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">LeftmostLongest</span>)
.<span class="ident">build</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="ident">matches</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">usize</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">ac</span>
.<span class="ident">find_iter</span>(<span class="ident">haystack</span>)
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">mat</span><span class="op">|</span> <span class="ident">mat</span>.<span class="ident">pattern</span>())
.<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">1</span>], <span class="ident">matches</span>);</pre></div>
</div><h4 id='method.find_overlapping_iter' class="method"><div class="important-traits"><div class='tooltip'><span class='tooltiptext'>Important traits for <a class="struct" href="../aho_corasick/struct.FindOverlappingIter.html" title="struct aho_corasick::FindOverlappingIter">FindOverlappingIter</a>&lt;'a, 'b, S&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../aho_corasick/struct.FindOverlappingIter.html" title="struct aho_corasick::FindOverlappingIter">FindOverlappingIter</a>&lt;'a, 'b, S&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, 'b, S:&nbsp;<a class="trait" href="../aho_corasick/trait.StateID.html" title="trait aho_corasick::StateID">StateID</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="../aho_corasick/struct.FindOverlappingIter.html" title="struct aho_corasick::FindOverlappingIter">FindOverlappingIter</a>&lt;'a, 'b, S&gt;</span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="struct" href="../aho_corasick/struct.Match.html" title="struct aho_corasick::Match">Match</a>;</span></code></div></div><code id='find_overlapping_iter.v'>pub fn <a href='#method.find_overlapping_iter' class='fnname'>find_overlapping_iter</a>&lt;'a, 'b, B:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>&gt;&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a self, <br>&nbsp;&nbsp;&nbsp;&nbsp;haystack: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;'b </a>B<br>) -&gt; <a class="struct" href="../aho_corasick/struct.FindOverlappingIter.html" title="struct aho_corasick::FindOverlappingIter">FindOverlappingIter</a>&lt;'a, 'b, S&gt;</code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#393-398' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns an iterator of overlapping matches in the given <code>haystack</code>.</p>
<p>Overlapping matches can <em>only</em> be detected using
<code>MatchKind::Standard</code> semantics. If this automaton was constructed with
leftmost semantics, then this method will panic. To determine whether
this will panic at runtime, use the
<a href="struct.AhoCorasick.html#method.supports_overlapping"><code>AhoCorasick::supports_overlapping</code></a>
method.</p>
<p><code>haystack</code> may be any type that is cheaply convertible to a <code>&amp;[u8]</code>.
This includes, but is not limited to, <code>String</code>, <code>&amp;str</code>, <code>Vec&lt;u8&gt;</code>, and
<code>&amp;[u8]</code> itself.</p>
<h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
<p>This panics when <code>AhoCorasick::supports_overlapping</code> returns <code>false</code>.
That is, this panics when this automaton's match semantics are not
<code>MatchKind::Standard</code>.</p>
<h1 id="examples-7" class="section-header"><a href="#examples-7">Examples</a></h1>
<p>Basic usage, with standard semantics:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">AhoCorasick</span>;
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;append&quot;</span>, <span class="string">&quot;appendage&quot;</span>, <span class="string">&quot;app&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;append the app to the appendage&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasick</span>::<span class="ident">new</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="ident">matches</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">usize</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">ac</span>
.<span class="ident">find_overlapping_iter</span>(<span class="ident">haystack</span>)
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">mat</span><span class="op">|</span> <span class="ident">mat</span>.<span class="ident">pattern</span>())
.<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">2</span>, <span class="number">0</span>, <span class="number">2</span>, <span class="number">2</span>, <span class="number">0</span>, <span class="number">1</span>], <span class="ident">matches</span>);</pre></div>
</div><h4 id='method.replace_all' class="method"><code id='replace_all.v'>pub fn <a href='#method.replace_all' class='fnname'>replace_all</a>&lt;B&gt;(&amp;self, haystack: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, replace_with: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[B]</a>) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>&gt;,&nbsp;</span></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#429-445' title='goto source code'>[src]</a></h4><div class='docblock'><p>Replace all matches with a corresponding value in the <code>replace_with</code>
slice given. Matches correspond to the same matches as reported by
<a href="struct.AhoCorasick.html#method.find_iter"><code>find_iter</code></a>.</p>
<p>Replacements are determined by the index of the matching pattern.
For example, if the pattern with index <code>2</code> is found, then it is
replaced by <code>replace_with[2]</code>.</p>
<h1 id="panics-1" class="section-header"><a href="#panics-1">Panics</a></h1>
<p>This panics when <code>replace_with.len()</code> does not equal the total number
of patterns that are matched by this automaton.</p>
<h1 id="examples-8" class="section-header"><a href="#examples-8">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasickBuilder</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;append&quot;</span>, <span class="string">&quot;appendage&quot;</span>, <span class="string">&quot;app&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;append the app to the appendage&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">LeftmostFirst</span>)
.<span class="ident">build</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="ident">result</span> <span class="op">=</span> <span class="ident">ac</span>.<span class="ident">replace_all</span>(<span class="ident">haystack</span>, <span class="kw-2">&amp;</span>[<span class="string">&quot;x&quot;</span>, <span class="string">&quot;y&quot;</span>, <span class="string">&quot;z&quot;</span>]);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;x the z to the xage&quot;</span>, <span class="ident">result</span>);</pre></div>
</div><h4 id='method.replace_all_bytes' class="method"><code id='replace_all_bytes.v'>pub fn <a href='#method.replace_all_bytes' class='fnname'>replace_all_bytes</a>&lt;B&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;haystack: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;replace_with: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[B]</a><br>) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>&gt;,&nbsp;</span></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#476-496' title='goto source code'>[src]</a></h4><div class='docblock'><p>Replace all matches using raw bytes with a corresponding value in the
<code>replace_with</code> slice given. Matches correspond to the same matches as
reported by <a href="struct.AhoCorasick.html#method.find_iter"><code>find_iter</code></a>.</p>
<p>Replacements are determined by the index of the matching pattern.
For example, if the pattern with index <code>2</code> is found, then it is
replaced by <code>replace_with[2]</code>.</p>
<h1 id="panics-2" class="section-header"><a href="#panics-2">Panics</a></h1>
<p>This panics when <code>replace_with.len()</code> does not equal the total number
of patterns that are matched by this automaton.</p>
<h1 id="examples-9" class="section-header"><a href="#examples-9">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasickBuilder</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;append&quot;</span>, <span class="string">&quot;appendage&quot;</span>, <span class="string">&quot;app&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">b&quot;append the app to the appendage&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">LeftmostFirst</span>)
.<span class="ident">build</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="ident">result</span> <span class="op">=</span> <span class="ident">ac</span>.<span class="ident">replace_all_bytes</span>(<span class="ident">haystack</span>, <span class="kw-2">&amp;</span>[<span class="string">&quot;x&quot;</span>, <span class="string">&quot;y&quot;</span>, <span class="string">&quot;z&quot;</span>]);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">b&quot;x the z to the xage&quot;</span>.<span class="ident">to_vec</span>(), <span class="ident">result</span>);</pre></div>
</div><h4 id='method.replace_all_with' class="method"><code id='replace_all_with.v'>pub fn <a href='#method.replace_all_with' class='fnname'>replace_all_with</a>&lt;F&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;haystack: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;dst: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;replace_with: F<br>) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;<a class="struct" href="../aho_corasick/struct.Match.html" title="struct aho_corasick::Match">Match</a>, &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>,&nbsp;</span></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#527-542' title='goto source code'>[src]</a></h4><div class='docblock'><p>Replace all matches using a closure called on each match.
Matches correspond to the same matches as reported by
<a href="struct.AhoCorasick.html#method.find_iter"><code>find_iter</code></a>.</p>
<p>The closure accepts three parameters: the match found, the text of
the match and a string buffer with which to write the replaced text
(if any). If the closure returns <code>true</code>, then it continues to the next
match. If the closure returns false, then searching is stopped.</p>
<h1 id="examples-10" class="section-header"><a href="#examples-10">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasickBuilder</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;append&quot;</span>, <span class="string">&quot;appendage&quot;</span>, <span class="string">&quot;app&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;append the app to the appendage&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">LeftmostFirst</span>)
.<span class="ident">build</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">result</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">new</span>();
<span class="ident">ac</span>.<span class="ident">replace_all_with</span>(<span class="ident">haystack</span>, <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">result</span>, <span class="op">|</span><span class="ident">mat</span>, <span class="kw">_</span>, <span class="ident">dst</span><span class="op">|</span> {
<span class="ident">dst</span>.<span class="ident">push_str</span>(<span class="kw-2">&amp;</span><span class="ident">mat</span>.<span class="ident">pattern</span>().<span class="ident">to_string</span>());
<span class="bool-val">true</span>
});
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;0 the 2 to the 0age&quot;</span>, <span class="ident">result</span>);</pre></div>
</div><h4 id='method.replace_all_with_bytes' class="method"><code id='replace_all_with_bytes.v'>pub fn <a href='#method.replace_all_with_bytes' class='fnname'>replace_all_with_bytes</a>&lt;F&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;haystack: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;dst: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;replace_with: F<br>) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;<a class="struct" href="../aho_corasick/struct.Match.html" title="struct aho_corasick::Match">Match</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>, &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>&gt;) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>,&nbsp;</span></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#573-588' title='goto source code'>[src]</a></h4><div class='docblock'><p>Replace all matches using raw bytes with a closure called on each
match. Matches correspond to the same matches as reported by
<a href="struct.AhoCorasick.html#method.find_iter"><code>find_iter</code></a>.</p>
<p>The closure accepts three parameters: the match found, the text of
the match and a byte buffer with which to write the replaced text
(if any). If the closure returns <code>true</code>, then it continues to the next
match. If the closure returns false, then searching is stopped.</p>
<h1 id="examples-11" class="section-header"><a href="#examples-11">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasickBuilder</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;append&quot;</span>, <span class="string">&quot;appendage&quot;</span>, <span class="string">&quot;app&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">b&quot;append the app to the appendage&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">LeftmostFirst</span>)
.<span class="ident">build</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">result</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[];
<span class="ident">ac</span>.<span class="ident">replace_all_with_bytes</span>(<span class="ident">haystack</span>, <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">result</span>, <span class="op">|</span><span class="ident">mat</span>, <span class="kw">_</span>, <span class="ident">dst</span><span class="op">|</span> {
<span class="ident">dst</span>.<span class="ident">extend</span>(<span class="ident">mat</span>.<span class="ident">pattern</span>().<span class="ident">to_string</span>().<span class="ident">bytes</span>());
<span class="bool-val">true</span>
});
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">b&quot;0 the 2 to the 0age&quot;</span>.<span class="ident">to_vec</span>(), <span class="ident">result</span>);</pre></div>
</div><h4 id='method.stream_find_iter' class="method"><div class="important-traits"><div class='tooltip'><span class='tooltiptext'>Important traits for <a class="struct" href="../aho_corasick/struct.StreamFindIter.html" title="struct aho_corasick::StreamFindIter">StreamFindIter</a>&lt;'a, R, S&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../aho_corasick/struct.StreamFindIter.html" title="struct aho_corasick::StreamFindIter">StreamFindIter</a>&lt;'a, R, S&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, R:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html" title="trait std::io::Read">Read</a>, S:&nbsp;<a class="trait" href="../aho_corasick/trait.StateID.html" title="trait aho_corasick::StateID">StateID</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="../aho_corasick/struct.StreamFindIter.html" title="struct aho_corasick::StreamFindIter">StreamFindIter</a>&lt;'a, R, S&gt;</span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="struct" href="../aho_corasick/struct.Match.html" title="struct aho_corasick::Match">Match</a>&gt;;</span></code></div></div><code id='stream_find_iter.v'>pub fn <a href='#method.stream_find_iter' class='fnname'>stream_find_iter</a>&lt;'a, R:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html" title="trait std::io::Read">Read</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a self, <br>&nbsp;&nbsp;&nbsp;&nbsp;rdr: R<br>) -&gt; <a class="struct" href="../aho_corasick/struct.StreamFindIter.html" title="struct aho_corasick::StreamFindIter">StreamFindIter</a>&lt;'a, R, S&gt;</code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#645-650' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns an iterator of non-overlapping matches in the given
stream. Matches correspond to the same matches as reported by
<a href="struct.AhoCorasick.html#method.find_iter"><code>find_iter</code></a>.</p>
<p>The matches yielded by this iterator use absolute position offsets in
the stream given, where the first byte has index <code>0</code>. Matches are
yieled until the stream is exhausted.</p>
<p>Each item yielded by the iterator is an <code>io::Result&lt;Match&gt;</code>, where an
error is yielded if there was a problem reading from the reader given.</p>
<p>When searching a stream, an internal buffer is used. Therefore, callers
should avoiding providing a buffered reader, if possible.</p>
<p>Searching a stream requires that the automaton was built with
<code>MatchKind::Standard</code> semantics. If this automaton was constructed
with leftmost semantics, then this method will panic. To determine
whether this will panic at runtime, use the
<a href="struct.AhoCorasick.html#method.supports_stream"><code>AhoCorasick::supports_stream</code></a>
method.</p>
<h1 id="memory-usage" class="section-header"><a href="#memory-usage">Memory usage</a></h1>
<p>In general, searching streams will use a constant amount of memory for
its internal buffer. The one requirement is that the internal buffer
must be at least the size of the longest possible match. In most use
cases, the default buffer size will be much larger than any individual
match.</p>
<h1 id="panics-3" class="section-header"><a href="#panics-3">Panics</a></h1>
<p>This panics when <code>AhoCorasick::supports_stream</code> returns <code>false</code>.
That is, this panics when this automaton's match semantics are not
<code>MatchKind::Standard</code>. This restriction may be lifted in the future.</p>
<h1 id="examples-12" class="section-header"><a href="#examples-12">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">AhoCorasick</span>;
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;append&quot;</span>, <span class="string">&quot;appendage&quot;</span>, <span class="string">&quot;app&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;append the app to the appendage&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasick</span>::<span class="ident">new</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">matches</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[];
<span class="kw">for</span> <span class="ident">result</span> <span class="kw">in</span> <span class="ident">ac</span>.<span class="ident">stream_find_iter</span>(<span class="ident">haystack</span>.<span class="ident">as_bytes</span>()) {
<span class="kw">let</span> <span class="ident">mat</span> <span class="op">=</span> <span class="ident">result</span><span class="question-mark">?</span>;
<span class="ident">matches</span>.<span class="ident">push</span>(<span class="ident">mat</span>.<span class="ident">pattern</span>());
}
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">2</span>, <span class="number">2</span>, <span class="number">2</span>], <span class="ident">matches</span>);</pre></div>
</div><h4 id='method.stream_replace_all' class="method"><code id='stream_replace_all.v'>pub fn <a href='#method.stream_replace_all' class='fnname'>stream_replace_all</a>&lt;R, W, B&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;rdr: R, <br>&nbsp;&nbsp;&nbsp;&nbsp;wtr: W, <br>&nbsp;&nbsp;&nbsp;&nbsp;replace_with: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[B]</a><br>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html" title="trait std::io::Read">Read</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html" title="trait std::io::Write">Write</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>&gt;,&nbsp;</span></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#710-730' title='goto source code'>[src]</a></h4><div class='docblock'><p>Search for and replace all matches of this automaton in
the given reader, and write the replacements to the given
writer. Matches correspond to the same matches as reported by
<a href="struct.AhoCorasick.html#method.find_iter"><code>find_iter</code></a>.</p>
<p>Replacements are determined by the index of the matching pattern.
For example, if the pattern with index <code>2</code> is found, then it is
replaced by <code>replace_with[2]</code>.</p>
<p>After all matches are replaced, the writer is <em>not</em> flushed.</p>
<p>If there was a problem reading from the given reader or writing to the
given writer, then the corresponding <code>io::Error</code> is returned and all
replacement is stopped.</p>
<p>When searching a stream, an internal buffer is used. Therefore, callers
should avoiding providing a buffered reader, if possible. However,
callers may want to provide a buffered writer.</p>
<p>Searching a stream requires that the automaton was built with
<code>MatchKind::Standard</code> semantics. If this automaton was constructed
with leftmost semantics, then this method will panic. To determine
whether this will panic at runtime, use the
<a href="struct.AhoCorasick.html#method.supports_stream"><code>AhoCorasick::supports_stream</code></a>
method.</p>
<h1 id="memory-usage-1" class="section-header"><a href="#memory-usage-1">Memory usage</a></h1>
<p>In general, searching streams will use a constant amount of memory for
its internal buffer. The one requirement is that the internal buffer
must be at least the size of the longest possible match. In most use
cases, the default buffer size will be much larger than any individual
match.</p>
<h1 id="panics-4" class="section-header"><a href="#panics-4">Panics</a></h1>
<p>This panics when <code>AhoCorasick::supports_stream</code> returns <code>false</code>.
That is, this panics when this automaton's match semantics are not
<code>MatchKind::Standard</code>. This restriction may be lifted in the future.</p>
<h1 id="examples-13" class="section-header"><a href="#examples-13">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">AhoCorasick</span>;
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;fox&quot;</span>, <span class="string">&quot;brown&quot;</span>, <span class="string">&quot;quick&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;The quick brown fox.&quot;</span>;
<span class="kw">let</span> <span class="ident">replace_with</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;sloth&quot;</span>, <span class="string">&quot;grey&quot;</span>, <span class="string">&quot;slow&quot;</span>];
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasick</span>::<span class="ident">new</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">result</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[];
<span class="ident">ac</span>.<span class="ident">stream_replace_all</span>(<span class="ident">haystack</span>.<span class="ident">as_bytes</span>(), <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">result</span>, <span class="ident">replace_with</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">b&quot;The slow grey sloth.&quot;</span>.<span class="ident">to_vec</span>(), <span class="ident">result</span>);</pre></div>
</div><h4 id='method.stream_replace_all_with' class="method"><code id='stream_replace_all_with.v'>pub fn <a href='#method.stream_replace_all_with' class='fnname'>stream_replace_all_with</a>&lt;R, W, F&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;rdr: R, <br>&nbsp;&nbsp;&nbsp;&nbsp;wtr: W, <br>&nbsp;&nbsp;&nbsp;&nbsp;replace_with: F<br>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html" title="trait std::io::Read">Read</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html" title="trait std::io::Write">Write</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;<a class="struct" href="../aho_corasick/struct.Match.html" title="struct aho_corasick::Match">Match</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>W) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;,&nbsp;</span></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#797-821' title='goto source code'>[src]</a></h4><div class='docblock'><p>Search the given reader and replace all matches of this automaton
using the given closure. The result is written to the given
writer. Matches correspond to the same matches as reported by
<a href="struct.AhoCorasick.html#method.find_iter"><code>find_iter</code></a>.</p>
<p>The closure accepts three parameters: the match found, the text of
the match and the writer with which to write the replaced text
(if any). If the closure returns <code>true</code>, then it continues to the next
match. If the closure returns false, then searching is stopped.</p>
<p>After all matches are replaced, the writer is <em>not</em> flushed.</p>
<p>If there was a problem reading from the given reader or writing to the
given writer, then the corresponding <code>io::Error</code> is returned and all
replacement is stopped.</p>
<p>When searching a stream, an internal buffer is used. Therefore, callers
should avoiding providing a buffered reader, if possible. However,
callers may want to provide a buffered writer.</p>
<p>Searching a stream requires that the automaton was built with
<code>MatchKind::Standard</code> semantics. If this automaton was constructed
with leftmost semantics, then this method will panic. To determine
whether this will panic at runtime, use the
<a href="struct.AhoCorasick.html#method.supports_stream"><code>AhoCorasick::supports_stream</code></a>
method.</p>
<h1 id="memory-usage-2" class="section-header"><a href="#memory-usage-2">Memory usage</a></h1>
<p>In general, searching streams will use a constant amount of memory for
its internal buffer. The one requirement is that the internal buffer
must be at least the size of the longest possible match. In most use
cases, the default buffer size will be much larger than any individual
match.</p>
<h1 id="panics-5" class="section-header"><a href="#panics-5">Panics</a></h1>
<p>This panics when <code>AhoCorasick::supports_stream</code> returns <code>false</code>.
That is, this panics when this automaton's match semantics are not
<code>MatchKind::Standard</code>. This restriction may be lifted in the future.</p>
<h1 id="examples-14" class="section-header"><a href="#examples-14">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>::<span class="ident">Write</span>;
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">AhoCorasick</span>;
<span class="kw">let</span> <span class="ident">patterns</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;fox&quot;</span>, <span class="string">&quot;brown&quot;</span>, <span class="string">&quot;quick&quot;</span>];
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">&quot;The quick brown fox.&quot;</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasick</span>::<span class="ident">new</span>(<span class="ident">patterns</span>);
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">result</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[];
<span class="ident">ac</span>.<span class="ident">stream_replace_all_with</span>(
<span class="ident">haystack</span>.<span class="ident">as_bytes</span>(),
<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">result</span>,
<span class="op">|</span><span class="ident">mat</span>, <span class="kw">_</span>, <span class="ident">wtr</span><span class="op">|</span> {
<span class="ident">wtr</span>.<span class="ident">write_all</span>(<span class="ident">mat</span>.<span class="ident">pattern</span>().<span class="ident">to_string</span>().<span class="ident">as_bytes</span>())
},
)<span class="question-mark">?</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">b&quot;The 2 1 0.&quot;</span>.<span class="ident">to_vec</span>(), <span class="ident">result</span>);</pre></div>
</div><h4 id='method.match_kind' class="method"><code id='match_kind.v'>pub fn <a href='#method.match_kind' class='fnname'>match_kind</a>(&amp;self) -&gt; &amp;<a class="enum" href="../aho_corasick/enum.MatchKind.html" title="enum aho_corasick::MatchKind">MatchKind</a></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#837-839' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the match kind used by this automaton.</p>
<h1 id="examples-15" class="section-header"><a href="#examples-15">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasick</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasick</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span>[
<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;quux&quot;</span>, <span class="string">&quot;baz&quot;</span>,
]);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&amp;</span><span class="ident">MatchKind</span>::<span class="ident">Standard</span>, <span class="ident">ac</span>.<span class="ident">match_kind</span>());</pre></div>
</div><h4 id='method.max_pattern_len' class="method"><code id='max_pattern_len.v'>pub fn <a href='#method.max_pattern_len' class='fnname'>max_pattern_len</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#855-857' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the length of the longest pattern matched by this automaton.</p>
<h1 id="examples-16" class="section-header"><a href="#examples-16">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">AhoCorasick</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasick</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span>[
<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;quux&quot;</span>, <span class="string">&quot;baz&quot;</span>,
]);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">4</span>, <span class="ident">ac</span>.<span class="ident">max_pattern_len</span>());</pre></div>
</div><h4 id='method.pattern_count' class="method"><code id='pattern_count.v'>pub fn <a href='#method.pattern_count' class='fnname'>pattern_count</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#880-882' title='goto source code'>[src]</a></h4><div class='docblock'><p>Return the total number of patterns matched by this automaton.</p>
<p>This includes patterns that may never participate in a match. For
example, if
<a href="enum.MatchKind.html#variant.LeftmostFirst"><code>MatchKind::LeftmostFirst</code></a>
match semantics are used, and the patterns <code>Sam</code> and <code>Samwise</code> were
used to build the automaton, then <code>Samwise</code> can never participate in a
match because <code>Sam</code> will always take priority.</p>
<h1 id="examples-17" class="section-header"><a href="#examples-17">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">AhoCorasick</span>;
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasick</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span>[
<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;baz&quot;</span>,
]);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">3</span>, <span class="ident">ac</span>.<span class="ident">pattern_count</span>());</pre></div>
</div><h4 id='method.supports_overlapping' class="method"><code id='supports_overlapping.v'>pub fn <a href='#method.supports_overlapping' class='fnname'>supports_overlapping</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#912-914' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns true if and only if this automaton supports reporting
overlapping matches.</p>
<p>If this returns false and overlapping matches are requested, then it
will result in a panic.</p>
<p>Since leftmost matching is inherently incompatible with overlapping
matches, only
<a href="enum.MatchKind.html#variant.Standard"><code>MatchKind::Standard</code></a>
supports overlapping matches. This is unlikely to change in the future.</p>
<h1 id="examples-18" class="section-header"><a href="#examples-18">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasickBuilder</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">Standard</span>)
.<span class="ident">build</span>(<span class="kw-2">&amp;</span>[<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;baz&quot;</span>]);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">ac</span>.<span class="ident">supports_overlapping</span>());
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">LeftmostFirst</span>)
.<span class="ident">build</span>(<span class="kw-2">&amp;</span>[<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;baz&quot;</span>]);
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">ac</span>.<span class="ident">supports_overlapping</span>());</pre></div>
</div><h4 id='method.supports_stream' class="method"><code id='supports_stream.v'>pub fn <a href='#method.supports_stream' class='fnname'>supports_stream</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#942-944' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns true if and only if this automaton supports stream searching.</p>
<p>If this returns false and stream searching (or replacing) is attempted,
then it will result in a panic.</p>
<p>Currently, only
<a href="enum.MatchKind.html#variant.Standard"><code>MatchKind::Standard</code></a>
supports streaming. This may be expanded in the future.</p>
<h1 id="examples-19" class="section-header"><a href="#examples-19">Examples</a></h1>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasickBuilder</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">Standard</span>)
.<span class="ident">build</span>(<span class="kw-2">&amp;</span>[<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;baz&quot;</span>]);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">ac</span>.<span class="ident">supports_stream</span>());
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">LeftmostFirst</span>)
.<span class="ident">build</span>(<span class="kw-2">&amp;</span>[<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;baz&quot;</span>]);
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">ac</span>.<span class="ident">supports_stream</span>());</pre></div>
</div><h4 id='method.heap_bytes' class="method"><code id='heap_bytes.v'>pub fn <a href='#method.heap_bytes' class='fnname'>heap_bytes</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#986-991' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the approximate total amount of heap used by this automaton, in
units of bytes.</p>
<h1 id="examples-20" class="section-header"><a href="#examples-20">Examples</a></h1>
<p>This example shows the difference in heap usage between a few
configurations:</p>
<div class='information'><div class='tooltip ignore'><span class='tooltiptext'>This example is not tested</span></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore">
<span class="kw">use</span> <span class="ident">aho_corasick</span>::{<span class="ident">AhoCorasickBuilder</span>, <span class="ident">MatchKind</span>};
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">dfa</span>(<span class="bool-val">false</span>) <span class="comment">// default</span>
.<span class="ident">build</span>(<span class="kw-2">&amp;</span>[<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;baz&quot;</span>]);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">10_336</span>, <span class="ident">ac</span>.<span class="ident">heap_bytes</span>());
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">dfa</span>(<span class="bool-val">false</span>) <span class="comment">// default</span>
.<span class="ident">ascii_case_insensitive</span>(<span class="bool-val">true</span>)
.<span class="ident">build</span>(<span class="kw-2">&amp;</span>[<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;baz&quot;</span>]);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">10_384</span>, <span class="ident">ac</span>.<span class="ident">heap_bytes</span>());
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">dfa</span>(<span class="bool-val">true</span>)
.<span class="ident">byte_classes</span>(<span class="bool-val">false</span>)
.<span class="ident">build</span>(<span class="kw-2">&amp;</span>[<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;baz&quot;</span>]);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">20_768</span>, <span class="ident">ac</span>.<span class="ident">heap_bytes</span>());
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">dfa</span>(<span class="bool-val">true</span>)
.<span class="ident">byte_classes</span>(<span class="bool-val">true</span>) <span class="comment">// default</span>
.<span class="ident">build</span>(<span class="kw-2">&amp;</span>[<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;baz&quot;</span>]);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">1_248</span>, <span class="ident">ac</span>.<span class="ident">heap_bytes</span>());
<span class="kw">let</span> <span class="ident">ac</span> <span class="op">=</span> <span class="ident">AhoCorasickBuilder</span>::<span class="ident">new</span>()
.<span class="ident">dfa</span>(<span class="bool-val">true</span>)
.<span class="ident">ascii_case_insensitive</span>(<span class="bool-val">true</span>)
.<span class="ident">build</span>(<span class="kw-2">&amp;</span>[<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>, <span class="string">&quot;baz&quot;</span>]);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">1_248</span>, <span class="ident">ac</span>.<span class="ident">heap_bytes</span>());</pre></div>
</div></div><h2 id='implementations' class='small-section-header'>Trait Implementations<a href='#implementations' class='anchor'></a></h2><div id='implementations-list'><h3 id='impl-Clone' class='impl'><code class='in-band'>impl&lt;S:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="../aho_corasick/trait.StateID.html" title="trait aho_corasick::StateID">StateID</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a>&lt;S&gt;</code><a href='#impl-Clone' class='anchor'></a><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#85' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.clone' class="method hidden"><code id='clone.v'>fn <a href='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&amp;self) -&gt; <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a>&lt;S&gt;</code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#85' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Returns a copy of the value. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone">Read more</a></p>
</div><h4 id='method.clone_from' class="method hidden"><code id='clone_from.v'>fn <a href='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&amp;mut self, source: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>Self)</code><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/clone.rs.html#131-133' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from">Read more</a></p>
</div></div><h3 id='impl-Debug' class='impl'><code class='in-band'>impl&lt;S:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> + <a class="trait" href="../aho_corasick/trait.StateID.html" title="trait aho_corasick::StateID">StateID</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a>&lt;S&gt;</code><a href='#impl-Debug' class='anchor'></a><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#85' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.fmt' class="method hidden"><code id='fmt.v'>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code><a class='srclink' href='../src/aho_corasick/ahocorasick.rs.html#85' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
</div></div></div><h2 id='synthetic-implementations' class='small-section-header'>Auto Trait Implementations<a href='#synthetic-implementations' class='anchor'></a></h2><div id='synthetic-implementations-list'><h3 id='impl-Sync' class='impl'><code class='in-band'>impl&lt;S&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a>&lt;S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>,&nbsp;</span></code><a href='#impl-Sync' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-Send' class='impl'><code class='in-band'>impl&lt;S&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a>&lt;S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,&nbsp;</span></code><a href='#impl-Send' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-Unpin' class='impl'><code class='in-band'>impl&lt;S&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a>&lt;S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,&nbsp;</span></code><a href='#impl-Unpin' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-RefUnwindSafe' class='impl'><code class='in-band'>impl&lt;S&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.RefUnwindSafe.html" title="trait std::panic::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a>&lt;S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.RefUnwindSafe.html" title="trait std::panic::RefUnwindSafe">RefUnwindSafe</a>,&nbsp;</span></code><a href='#impl-RefUnwindSafe' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-UnwindSafe' class='impl'><code class='in-band'>impl&lt;S&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a> for <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a>&lt;S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a>,&nbsp;</span></code><a href='#impl-UnwindSafe' class='anchor'></a></h3><div class='impl-items'></div></div><h2 id='blanket-implementations' class='small-section-header'>Blanket Implementations<a href='#blanket-implementations' class='anchor'></a></h2><div id='blanket-implementations-list'><h3 id='impl-Into%3CU%3E' class='impl'><code class='in-band'>impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;U&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt;,&nbsp;</span></code><a href='#impl-Into%3CU%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert.rs.html#543-548' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.into' class="method hidden"><code id='into.v'>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.Into.html#tymethod.into' class='fnname'>into</a>(self) -&gt; U</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert.rs.html#545-547' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-From%3CT%3E' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for T</code><a href='#impl-From%3CT%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert.rs.html#552-554' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from' class="method hidden"><code id='from.v'>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(t: T) -&gt; T</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert.rs.html#553' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-ToOwned' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html" title="trait alloc::borrow::ToOwned">ToOwned</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,&nbsp;</span></code><a href='#impl-ToOwned' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#81-92' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Owned' class="type"><code id='Owned.t'>type <a href='https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#associatedtype.Owned' class="type">Owned</a> = T</code></h4><div class='docblock'><p>The resulting type after obtaining ownership.</p>
</div><h4 id='method.to_owned' class="method hidden"><code id='to_owned.v'>fn <a href='https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#tymethod.to_owned' class='fnname'>to_owned</a>(&amp;self) -&gt; T</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#85-87' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates owned data from borrowed data, usually by cloning. <a href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></p>
</div><h4 id='method.clone_into' class="method hidden"><code id='clone_into.v'>fn <a href='https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#method.clone_into' class='fnname'>clone_into</a>(&amp;self, target: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#89-91' title='goto source code'>[src]</a></h4><div class='stability hidden'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>toowned_clone_into</code>)</summary><p>recently added</p>
</details></div></div><div class='docblock hidden'><p>Uses borrowed data to replace owned data, usually by cloning. <a href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></p>
</div></div><h3 id='impl-TryFrom%3CU%3E' class='impl'><code class='in-band'>impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;T&gt;,&nbsp;</span></code><a href='#impl-TryFrom%3CU%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert.rs.html#571-577' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Error' class="type"><code id='Error.t'>type <a href='https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error' class="type">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></code></h4><div class='docblock'><p>The type returned in the event of a conversion error.</p>
</div><h4 id='method.try_from' class="method hidden"><code id='try_from.v'>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#tymethod.try_from' class='fnname'>try_from</a>(value: U) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T, &lt;T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt;&gt;::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert.rs.html#574-576' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-TryInto%3CU%3E' class='impl'><code class='in-band'>impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a>&lt;U&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;,&nbsp;</span></code><a href='#impl-TryInto%3CU%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert.rs.html#559-566' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Error-1' class="type"><code id='Error.t-1'>type <a href='https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error' class="type">Error</a> = &lt;U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></code></h4><div class='docblock'><p>The type returned in the event of a conversion error.</p>
</div><h4 id='method.try_into' class="method hidden"><code id='try_into.v'>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#tymethod.try_into' class='fnname'>try_into</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;U, &lt;U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert.rs.html#563-565' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-BorrowMut%3CT%3E' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a>&lt;T&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href='#impl-BorrowMut%3CT%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#218-220' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.borrow_mut' class="method hidden"><code id='borrow_mut.v'>fn <a href='https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut' class='fnname'>borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#219' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
</div></div><h3 id='impl-Borrow%3CT%3E' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href='#impl-Borrow%3CT%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#213-215' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.borrow' class="method hidden"><code id='borrow.v'>fn <a href='https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow' class='fnname'>borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#214' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
</div></div><h3 id='impl-Any' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href='#impl-Any' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/any.rs.html#100-102' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.type_id' class="method hidden"><code id='type_id.v'>fn <a href='https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id' class='fnname'>type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/any.rs.html#101' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>
</div></div></div></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd></kbd></dt><dd>Move up in search results</dd><dt><kbd></kbd></dt><dd>Move down in search results</dd><dt><kbd></kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g., <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../";window.currentCrate = "aho_corasick";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>