mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-25 10:22:19 +00:00
646 lines
109 KiB
HTML
646 lines
109 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="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">☰</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<T></a><a href="#impl-BorrowMut%3CT%3E">BorrowMut<T></a><a href="#impl-From%3CT%3E">From<T></a><a href="#impl-Into%3CU%3E">Into<U></a><a href="#impl-ToOwned">ToOwned</a><a href="#impl-TryFrom%3CU%3E">TryFrom<U></a><a href="#impl-TryInto%3CU%3E">TryInto<U></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'>−</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<S: <a class="trait" href="../aho_corasick/trait.StateID.html" title="trait aho_corasick::StateID">StateID</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>> { /* 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">&</span>[<span class="string">"apple"</span>, <span class="string">"maple"</span>, <span class="string">"snapple"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"Nobody likes maple in their apple flavored Snapple."</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">&</span>[<span class="string">"fox"</span>, <span class="string">"brown"</span>, <span class="string">"quick"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"The quick brown fox."</span>;
|
||
<span class="kw">let</span> <span class="ident">replace_with</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">"sloth"</span>, <span class="string">"grey"</span>, <span class="string">"slow"</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">"The slow grey sloth."</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><I, P>(patterns: I) -> <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a> <span class="where fmt-newline">where<br> 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><Item = P>,<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</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.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>, </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">&</span>[
|
||
<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</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">"xxx bar xxx"</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><B>(patterns: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[B]</a>) -> <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a> <span class="where fmt-newline">where<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</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.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>, </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">&</span>[
|
||
<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</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">"xxx bar xxx"</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<S: <a class="trait" href="../aho_corasick/trait.StateID.html" title="trait aho_corasick::StateID">StateID</a>> <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a><S></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><B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</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.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>>(&self, haystack: B) -> <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>&[u8]</code>.
|
||
This includes, but is not limited to, <code>String</code>, <code>&str</code>, <code>Vec<u8></code>, and
|
||
<code>&[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">&</span>[
|
||
<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"quux"</span>, <span class="string">"baz"</span>,
|
||
]);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">ac</span>.<span class="ident">is_match</span>(<span class="string">"xxx bar xxx"</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">"xxx qux xxx"</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><B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</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.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>>(&self, haystack: B) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="../aho_corasick/struct.Match.html" title="struct aho_corasick::Match">Match</a>></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>&[u8]</code>.
|
||
This includes, but is not limited to, <code>String</code>, <code>&str</code>, <code>Vec<u8></code>, and
|
||
<code>&[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">&</span>[
|
||
<span class="string">"abc"</span>, <span class="string">"b"</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">"abcd"</span>).<span class="ident">expect</span>(<span class="string">"should have match"</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><B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</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.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>>(&self, haystack: B) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="../aho_corasick/struct.Match.html" title="struct aho_corasick::Match">Match</a>></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>&[u8]</code>.
|
||
This includes, but is not limited to, <code>String</code>, <code>&str</code>, <code>Vec<u8></code>, and
|
||
<code>&[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">&</span>[<span class="string">"b"</span>, <span class="string">"abc"</span>, <span class="string">"abcd"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"abcd"</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">"should have a match"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"b"</span>, <span class="kw-2">&</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">&</span>[<span class="string">"b"</span>, <span class="string">"abc"</span>, <span class="string">"abcd"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"abcd"</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">"should have a match"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"abc"</span>, <span class="kw-2">&</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">&</span>[<span class="string">"b"</span>, <span class="string">"abc"</span>, <span class="string">"abcd"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"abcd"</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">"should have a match"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"abcd"</span>, <span class="kw-2">&</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><'a, 'b, S></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><'a, 'b, S></h3><code class="content"><span class="where fmt-newline">impl<'a, 'b, S: <a class="trait" href="../aho_corasick/trait.StateID.html" title="trait aho_corasick::StateID">StateID</a>> <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><'a, 'b, S></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><'a, 'b, B: ?<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><<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>>>(<br> &'a self, <br> haystack: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'b </a>B<br>) -> <a class="struct" href="../aho_corasick/struct.FindIter.html" title="struct aho_corasick::FindIter">FindIter</a><'a, 'b, S></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>&[u8]</code>.
|
||
This includes, but is not limited to, <code>String</code>, <code>&str</code>, <code>Vec<u8></code>, and
|
||
<code>&[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">&</span>[<span class="string">"append"</span>, <span class="string">"appendage"</span>, <span class="string">"app"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"append the app to the appendage"</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"><</span><span class="ident">usize</span><span class="op">></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">&</span>[<span class="string">"append"</span>, <span class="string">"appendage"</span>, <span class="string">"app"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"append the app to the appendage"</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"><</span><span class="ident">usize</span><span class="op">></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">&</span>[<span class="string">"append"</span>, <span class="string">"appendage"</span>, <span class="string">"app"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"append the app to the appendage"</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"><</span><span class="ident">usize</span><span class="op">></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><'a, 'b, S></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><'a, 'b, S></h3><code class="content"><span class="where fmt-newline">impl<'a, 'b, S: <a class="trait" href="../aho_corasick/trait.StateID.html" title="trait aho_corasick::StateID">StateID</a>> <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><'a, 'b, S></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><'a, 'b, B: ?<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><<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>>>(<br> &'a self, <br> haystack: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'b </a>B<br>) -> <a class="struct" href="../aho_corasick/struct.FindOverlappingIter.html" title="struct aho_corasick::FindOverlappingIter">FindOverlappingIter</a><'a, 'b, S></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>&[u8]</code>.
|
||
This includes, but is not limited to, <code>String</code>, <code>&str</code>, <code>Vec<u8></code>, and
|
||
<code>&[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">&</span>[<span class="string">"append"</span>, <span class="string">"appendage"</span>, <span class="string">"app"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"append the app to the appendage"</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"><</span><span class="ident">usize</span><span class="op">></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><B>(&self, haystack: &<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">&[B]</a>) -> <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> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>>, </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">&</span>[<span class="string">"append"</span>, <span class="string">"appendage"</span>, <span class="string">"app"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"append the app to the appendage"</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">&</span>[<span class="string">"x"</span>, <span class="string">"y"</span>, <span class="string">"z"</span>]);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"x the z to the xage"</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><B>(<br> &self, <br> haystack: <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>, <br> replace_with: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[B]</a><br>) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>> <span class="where fmt-newline">where<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</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.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>, </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">&</span>[<span class="string">"append"</span>, <span class="string">"appendage"</span>, <span class="string">"app"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">b"append the app to the appendage"</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">&</span>[<span class="string">"x"</span>, <span class="string">"y"</span>, <span class="string">"z"</span>]);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">b"x the z to the xage"</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><F>(<br> &self, <br> haystack: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, <br> dst: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>, <br> replace_with: F<br>) <span class="where fmt-newline">where<br> 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>(&<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.str.html">str</a>, &mut <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </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">&</span>[<span class="string">"append"</span>, <span class="string">"appendage"</span>, <span class="string">"app"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"append the app to the appendage"</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">&</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">&</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">"0 the 2 to the 0age"</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><F>(<br> &self, <br> haystack: <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>, <br> dst: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>>, <br> replace_with: F<br>) <span class="where fmt-newline">where<br> 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>(&<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">&[</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>, &mut <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</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.bool.html">bool</a>, </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">&</span>[<span class="string">"append"</span>, <span class="string">"appendage"</span>, <span class="string">"app"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">b"append the app to the appendage"</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">&</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"0 the 2 to the 0age"</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><'a, R, S></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><'a, R, S></h3><code class="content"><span class="where fmt-newline">impl<'a, R: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html" title="trait std::io::Read">Read</a>, S: <a class="trait" href="../aho_corasick/trait.StateID.html" title="trait aho_corasick::StateID">StateID</a>> <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><'a, R, S></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><<a class="struct" href="../aho_corasick/struct.Match.html" title="struct aho_corasick::Match">Match</a>>;</span></code></div></div><code id='stream_find_iter.v'>pub fn <a href='#method.stream_find_iter' class='fnname'>stream_find_iter</a><'a, R: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html" title="trait std::io::Read">Read</a>>(<br> &'a self, <br> rdr: R<br>) -> <a class="struct" href="../aho_corasick/struct.StreamFindIter.html" title="struct aho_corasick::StreamFindIter">StreamFindIter</a><'a, R, S></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<Match></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">&</span>[<span class="string">"append"</span>, <span class="string">"appendage"</span>, <span class="string">"app"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"append the app to the appendage"</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><R, W, B>(<br> &self, <br> rdr: R, <br> wtr: W, <br> replace_with: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[B]</a><br>) -> <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>> <span class="where fmt-newline">where<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html" title="trait std::io::Read">Read</a>,<br> W: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html" title="trait std::io::Write">Write</a>,<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</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.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>, </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">&</span>[<span class="string">"fox"</span>, <span class="string">"brown"</span>, <span class="string">"quick"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"The quick brown fox."</span>;
|
||
<span class="kw">let</span> <span class="ident">replace_with</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">"sloth"</span>, <span class="string">"grey"</span>, <span class="string">"slow"</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">&</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"The slow grey sloth."</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><R, W, F>(<br> &self, <br> rdr: R, <br> wtr: W, <br> replace_with: F<br>) -> <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>> <span class="where fmt-newline">where<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html" title="trait std::io::Read">Read</a>,<br> W: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html" title="trait std::io::Write">Write</a>,<br> 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>(&<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">&[</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">&mut </a>W) -> <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>>, </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">&</span>[<span class="string">"fox"</span>, <span class="string">"brown"</span>, <span class="string">"quick"</span>];
|
||
<span class="kw">let</span> <span class="ident">haystack</span> <span class="op">=</span> <span class="string">"The quick brown fox."</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">&</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"The 2 1 0."</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>(&self) -> &<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">&</span>[
|
||
<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"quux"</span>, <span class="string">"baz"</span>,
|
||
]);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&</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>(&self) -> <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">&</span>[
|
||
<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"quux"</span>, <span class="string">"baz"</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>(&self) -> <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">&</span>[
|
||
<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</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>(&self) -> <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">&</span>[<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</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">&</span>[<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</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>(&self) -> <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">&</span>[<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</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">&</span>[<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</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>(&self) -> <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">&</span>[<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</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">&</span>[<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</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">&</span>[<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</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">&</span>[<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</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">&</span>[<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</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<S: <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>> <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><S></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>(&self) -> <a class="struct" href="../aho_corasick/struct.AhoCorasick.html" title="struct aho_corasick::AhoCorasick">AhoCorasick</a><S></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>(&mut self, source: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</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<S: <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>> <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><S></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>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -> <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<S> <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><S> <span class="where fmt-newline">where<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>, </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<S> <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><S> <span class="where fmt-newline">where<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </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<S> <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><S> <span class="where fmt-newline">where<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>, </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<S> <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><S> <span class="where fmt-newline">where<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.RefUnwindSafe.html" title="trait std::panic::RefUnwindSafe">RefUnwindSafe</a>, </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<S> <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><S> <span class="where fmt-newline">where<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a>, </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<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>, </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) -> 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<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> 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) -> 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<T> <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> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </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>(&self) -> 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>(&self, target: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&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<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>, </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) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<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><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<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>, </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> = <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<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) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<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><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<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T <span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </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>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&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<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T <span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </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>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</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<T> <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> T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </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>(&self) -> <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>⏎</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> |