<main><divclass="width-limiter"><navclass="sub"><formclass="search-form"><span></span><divid="sidebar-button"tabindex="-1"><ahref="../aho_corasick/all.html"title="show sidebar"></a></div><inputclass="search-input"name="search"aria-label="Run search in the documentation"autocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"><divid="help-button"tabindex="-1"><ahref="../help.html"title="help">?</a></div><divid="settings-menu"tabindex="-1"><ahref="../settings.html"title="settings"><imgwidth="22"height="22"alt="Change settings"src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><sectionid="main-content"class="content"><divclass="main-heading"><h1>Struct <ahref="index.html">aho_corasick</a>::<wbr><aclass="struct"href="#">AhoCorasickBuilder</a><buttonid="copy-path"title="Copy item path to clipboard"><imgsrc="../static.files/clipboard-7571035ce49a181d.svg"width="19"height="18"alt="Copy item path"></button></h1><spanclass="out-of-band"><aclass="src"href="../src/aho_corasick/ahocorasick.rs.html#2135-2141">source</a> · <buttonid="toggle-all-docs"title="collapse all docs">[<span>−</span>]</button></span></div><preclass="rust item-decl"><code>pub struct AhoCorasickBuilder { <spanclass="comment">/* private fields */</span> }</code></pre><detailsclass="toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><p>A builder for configuring an Aho-Corasick automaton.</p>
<li>Use <ahref="struct.AhoCorasickBuilder.html#method.match_kind"title="method aho_corasick::AhoCorasickBuilder::match_kind"><code>AhoCorasickBuilder::match_kind</code></a> to configure your searcher
with <ahref="enum.MatchKind.html#variant.LeftmostFirst"title="variant aho_corasick::MatchKind::LeftmostFirst"><code>MatchKind::LeftmostFirst</code></a> if you want to match how backtracking
regex engines execute searches for <code>pat1|pat2|..|patN</code>. Use
<ahref="enum.MatchKind.html#variant.LeftmostLongest"title="variant aho_corasick::MatchKind::LeftmostLongest"><code>MatchKind::LeftmostLongest</code></a> if you want to match how POSIX regex engines
do it.</li>
<li>If you need an anchored search, use <ahref="struct.AhoCorasickBuilder.html#method.start_kind"title="method aho_corasick::AhoCorasickBuilder::start_kind"><code>AhoCorasickBuilder::start_kind</code></a> to
set the <ahref="enum.StartKind.html#variant.Anchored"title="variant aho_corasick::StartKind::Anchored"><code>StartKind::Anchored</code></a> mode since <ahref="enum.StartKind.html#variant.Unanchored"title="variant aho_corasick::StartKind::Unanchored"><code>StartKind::Unanchored</code></a> is the
default. Or just use <ahref="enum.StartKind.html#variant.Both"title="variant aho_corasick::StartKind::Both"><code>StartKind::Both</code></a> to support both types of searches.</li>
<li>You might want to use <ahref="struct.AhoCorasickBuilder.html#method.kind"title="method aho_corasick::AhoCorasickBuilder::kind"><code>AhoCorasickBuilder::kind</code></a> to set your searcher
to always use a <ahref="enum.AhoCorasickKind.html#variant.DFA"title="variant aho_corasick::AhoCorasickKind::DFA"><code>AhoCorasickKind::DFA</code></a> if search speed is critical and
memory usage isn’t a concern. Otherwise, not setting a kind will probably
make the right choice for you. Beware that if you use <ahref="enum.StartKind.html#variant.Both"title="variant aho_corasick::StartKind::Both"><code>StartKind::Both</code></a>
to build a searcher that supports both unanchored and anchored searches
<em>and</em> you set <ahref="enum.AhoCorasickKind.html#variant.DFA"title="variant aho_corasick::AhoCorasickKind::DFA"><code>AhoCorasickKind::DFA</code></a>, then the DFA will essentially be
duplicated to support both simultaneously. This results in very high memory
usage.</li>
<li>For all other options, their defaults are almost certainly what you want.</li>
</ul>
</div></details><h2id="implementations"class="section-header">Implementations<ahref="#implementations"class="anchor">§</a></h2><divid="implementations-list"><detailsclass="toggle implementors-toggle"open><summary><sectionid="impl-AhoCorasickBuilder"class="impl"><aclass="src rightside"href="../src/aho_corasick/ahocorasick.rs.html#2143-2617">source</a><ahref="#impl-AhoCorasickBuilder"class="anchor">§</a><h3class="code-header">impl <aclass="struct"href="struct.AhoCorasickBuilder.html"title="struct aho_corasick::AhoCorasickBuilder">AhoCorasickBuilder</a></h3></section></summary><divclass="impl-items"><detailsclass="toggle method-toggle"open><summary><sectionid="method.new"class="method"><aclass="src rightside"href="../src/aho_corasick/ahocorasick.rs.html#2148-2150">source</a><h4class="code-header">pub fn <ahref="#method.new"class="fn">new</a>() -><aclass="struct"href="struct.AhoCorasickBuilder.html"title="struct aho_corasick::AhoCorasickBuilder">AhoCorasickBuilder</a></h4></section></summary><divclass="docblock"><p>Create a new builder for configuring an Aho-Corasick automaton.</p>
<p>The builder provides a way to configure a number of things, including
ASCII case insensitivity and what kind of match semantics are used.</p>
P: <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/convert/trait.AsRef.html"title="trait core::convert::AsRef">AsRef</a><[<aclass="primitive"href="https://doc.rust-lang.org/1.78.0/std/primitive.u8.html">u8</a>]>,</div></h4></section></summary><divclass="docblock"><p>Build an Aho-Corasick automaton using the configuration set on this
ac.find(<spanclass="string">"xxx bar xxx"</span>).map(|m| m.pattern()),
);</code></pre></div>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.match_kind"class="method"><aclass="src rightside"href="../src/aho_corasick/ahocorasick.rs.html#2342-2347">source</a><h4class="code-header">pub fn <ahref="#method.match_kind"class="fn">match_kind</a>(&mut self, kind: <aclass="enum"href="enum.MatchKind.html"title="enum aho_corasick::MatchKind">MatchKind</a>) ->&mut <aclass="struct"href="struct.AhoCorasickBuilder.html"title="struct aho_corasick::AhoCorasickBuilder">AhoCorasickBuilder</a></h4></section></summary><divclass="docblock"><p>Set the desired match semantics.</p>
<p>The default is <ahref="enum.MatchKind.html#variant.Standard"title="variant aho_corasick::MatchKind::Standard"><code>MatchKind::Standard</code></a>, which corresponds to the match
semantics supported by the standard textbook description of the
Aho-Corasick algorithm. Namely, matches are reported as soon as they
are found. Moreover, this is the only way to get overlapping matches
or do stream searching.</p>
<p>The other kinds of match semantics that are supported are
<ahref="enum.MatchKind.html#variant.LeftmostFirst"title="variant aho_corasick::MatchKind::LeftmostFirst"><code>MatchKind::LeftmostFirst</code></a> and <ahref="enum.MatchKind.html#variant.LeftmostLongest"title="variant aho_corasick::MatchKind::LeftmostLongest"><code>MatchKind::LeftmostLongest</code></a>. The
former corresponds to the match you would get if you were to try to
match each pattern at each position in the haystack in the same order
that you give to the automaton. That is, it returns the leftmost match
corresponding to the earliest pattern given to the automaton. The
latter corresponds to finding the longest possible match among all
leftmost matches.</p>
<p>For more details on match semantics, see the <ahref="enum.MatchKind.html"title="enum aho_corasick::MatchKind">documentation for
<code>MatchKind</code></a>.</p>
<p>Note that setting this to <ahref="enum.MatchKind.html#variant.LeftmostFirst"title="variant aho_corasick::MatchKind::LeftmostFirst"><code>MatchKind::LeftmostFirst</code></a> or
<ahref="enum.MatchKind.html#variant.LeftmostLongest"title="variant aho_corasick::MatchKind::LeftmostLongest"><code>MatchKind::LeftmostLongest</code></a> will cause some search routines on
<ahref="struct.AhoCorasick.html"title="struct aho_corasick::AhoCorasick"><code>AhoCorasick</code></a> to return an error (or panic if you’re using the
infallible API). Notably, this includes stream and overlapping
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.start_kind"class="method"><aclass="src rightside"href="../src/aho_corasick/ahocorasick.rs.html#2437-2441">source</a><h4class="code-header">pub fn <ahref="#method.start_kind"class="fn">start_kind</a>(&mut self, kind: <aclass="enum"href="enum.StartKind.html"title="enum aho_corasick::StartKind">StartKind</a>) ->&mut <aclass="struct"href="struct.AhoCorasickBuilder.html"title="struct aho_corasick::AhoCorasickBuilder">AhoCorasickBuilder</a></h4></section></summary><divclass="docblock"><p>Sets the starting state configuration for the automaton.</p>
<p>Every Aho-Corasick automaton is capable of having two start states: one
that is used for unanchored searches and one that is used for anchored
searches. Some automatons, like the NFAs, support this with almost zero
additional cost. Other automatons, like the DFA, require two copies of
the underlying transition table to support both simultaneously.</p>
<p>Because there may be an added non-trivial cost to supporting both, it
is possible to configure which starting state configuration is needed.</p>
<p>Indeed, since anchored searches tend to be somewhat more rare,
<em>only</em> unanchored searches are supported by default. Thus,
<ahref="enum.StartKind.html#variant.Unanchored"title="variant aho_corasick::StartKind::Unanchored"><code>StartKind::Unanchored</code></a> is the default.</p>
<p>Note that when this is set to <ahref="enum.StartKind.html#variant.Unanchored"title="variant aho_corasick::StartKind::Unanchored"><code>StartKind::Unanchored</code></a>, then
running an anchored search will result in an error (or a panic
if using the infallible APIs). Similarly, when this is set to
<ahref="enum.StartKind.html#variant.Anchored"title="variant aho_corasick::StartKind::Anchored"><code>StartKind::Anchored</code></a>, then running an unanchored search will
result in an error (or a panic if using the infallible APIs). When
<ahref="enum.StartKind.html#variant.Both"title="variant aho_corasick::StartKind::Both"><code>StartKind::Both</code></a> is used, then both unanchored and anchored searches
are always supported.</p>
<p>Also note that even if an <code>AhoCorasick</code> searcher is using an NFA
internally (which always supports both unanchored and anchored
searches), an error will still be reported for a search that isn’t
supported by the configuration set via this method. This means,
for example, that an error is never dependent on which internal
<h5id="example-unanchored-and-anchored-searches"><aclass="doc-anchor"href="#example-unanchored-and-anchored-searches">§</a>Example: unanchored and anchored searches</h5>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.kind"class="method"><aclass="src rightside"href="../src/aho_corasick/ahocorasick.rs.html#2527-2533">source</a><h4class="code-header">pub fn <ahref="#method.kind"class="fn">kind</a>(&mut self, kind: <aclass="enum"href="https://doc.rust-lang.org/1.78.0/core/option/enum.Option.html"title="enum core::option::Option">Option</a><<aclass="enum"href="enum.AhoCorasickKind.html"title="enum aho_corasick::AhoCorasickKind">AhoCorasickKind</a>>) ->&mut <aclass="struct"href="struct.AhoCorasickBuilder.html"title="struct aho_corasick::AhoCorasickBuilder">AhoCorasickBuilder</a></h4></section></summary><divclass="docblock"><p>Choose the type of underlying automaton to use.</p>
<li><ahref="enum.AhoCorasickKind.html#variant.NoncontiguousNFA"title="variant aho_corasick::AhoCorasickKind::NoncontiguousNFA"><code>AhoCorasickKind::NoncontiguousNFA</code></a> instructs the searcher to
use a <ahref="nfa/noncontiguous/struct.NFA.html"title="struct aho_corasick::nfa::noncontiguous::NFA"><code>noncontiguous::NFA</code></a>. A noncontiguous NFA is the fastest to
be built, has moderate memory usage and is typically the slowest to
execute a search.</li>
<li><ahref="enum.AhoCorasickKind.html#variant.ContiguousNFA"title="variant aho_corasick::AhoCorasickKind::ContiguousNFA"><code>AhoCorasickKind::ContiguousNFA</code></a> instructs the searcher to use a
<ahref="nfa/contiguous/struct.NFA.html"title="struct aho_corasick::nfa::contiguous::NFA"><code>contiguous::NFA</code></a>. A contiguous NFA is a little slower to build than
a noncontiguous NFA, has excellent memory usage and is typically a
little slower than a DFA for a search.</li>
<li><ahref="enum.AhoCorasickKind.html#variant.DFA"title="variant aho_corasick::AhoCorasickKind::DFA"><code>AhoCorasickKind::DFA</code></a> instructs the searcher to use a
<ahref="dfa/struct.DFA.html"title="struct aho_corasick::dfa::DFA"><code>dfa::DFA</code></a>. A DFA is very slow to build, uses exorbitant amounts of
memory, but will typically execute searches the fastest.</li>
<li><code>None</code> (the default) instructs the searcher to choose the “best”
Aho-Corasick implementation. This choice is typically based primarily
on the number of patterns.</li>
</ul>
<p>Setting this configuration does not change the time complexity for
constructing the Aho-Corasick automaton (which is <code>O(p)</code> where <code>p</code>
is the total number of patterns being compiled). Setting this to
<ahref="enum.AhoCorasickKind.html#variant.DFA"title="variant aho_corasick::AhoCorasickKind::DFA"><code>AhoCorasickKind::DFA</code></a> does however reduce the time complexity of
non-overlapping searches from <code>O(n + p)</code> to <code>O(n)</code>, where <code>n</code> is the
length of the haystack.</p>
<p>In general, you should probably stick to the default unless you have
some kind of reason to use a specific Aho-Corasick implementation. For
example, you might choose <code>AhoCorasickKind::DFA</code> if you don’t care
about memory usage and want the fastest possible search times.</p>
<p>Setting this guarantees that the searcher returned uses the chosen
implementation. If that implementation could not be constructed, then
an error will be returned. In contrast, when <code>None</code> is used, it is
possible for it to attempt to construct, for example, a contiguous
NFA and have it fail. In which case, it will fall back to using a
noncontiguous NFA.</p>
<p>If <code>None</code> is given, then one may use <ahref="struct.AhoCorasick.html#method.kind"title="method aho_corasick::AhoCorasick::kind"><code>AhoCorasick::kind</code></a> to determine
which Aho-Corasick implementation was chosen.</p>
<p>Note that the heuristics used for choosing which <code>AhoCorasickKind</code>
may be changed in a semver compatible release.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.dense_depth"class="method"><aclass="src rightside"href="../src/aho_corasick/ahocorasick.rs.html#2581-2585">source</a><h4class="code-header">pub fn <ahref="#method.dense_depth"class="fn">dense_depth</a>(&mut self, depth: <aclass="primitive"href="https://doc.rust-lang.org/1.78.0/std/primitive.usize.html">usize</a>) ->&mut <aclass="struct"href="struct.AhoCorasickBuilder.html"title="struct aho_corasick::AhoCorasickBuilder">AhoCorasickBuilder</a></h4></section></summary><divclass="docblock"><p>Set the limit on how many states use a dense representation for their
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.byte_classes"class="method"><aclass="src rightside"href="../src/aho_corasick/ahocorasick.rs.html#2612-2616">source</a><h4class="code-header">pub fn <ahref="#method.byte_classes"class="fn">byte_classes</a>(&mut self, yes: <aclass="primitive"href="https://doc.rust-lang.org/1.78.0/std/primitive.bool.html">bool</a>) ->&mut <aclass="struct"href="struct.AhoCorasickBuilder.html"title="struct aho_corasick::AhoCorasickBuilder">AhoCorasickBuilder</a></h4></section></summary><divclass="docblock"><p>A debug settting for whether to attempt to shrink the size of the
<code><ahref="https://doc.rust-lang.org/1.78.0/core/convert/trait.From.html"title="trait core::convert::From">From</a><T> for U</code> chooses to do.</p>
</div></details></div></details><detailsclass="toggle implementors-toggle"><summary><sectionid="impl-ToOwned-for-T"class="impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.78.0/src/alloc/borrow.rs.html#83-85">source</a><ahref="#impl-ToOwned-for-T"class="anchor">§</a><h3class="code-header">impl<T><aclass="trait"href="https://doc.rust-lang.org/1.78.0/alloc/borrow/trait.ToOwned.html"title="trait alloc::borrow::ToOwned">ToOwned</a> for T<divclass="where">where
T: <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/clone/trait.Clone.html"title="trait core::clone::Clone">Clone</a>,</div></h3></section></summary><divclass="impl-items"><detailsclass="toggle"open><summary><sectionid="associatedtype.Owned"class="associatedtype trait-impl"><ahref="#associatedtype.Owned"class="anchor">§</a><h4class="code-header">type <ahref="https://doc.rust-lang.org/1.78.0/alloc/borrow/trait.ToOwned.html#associatedtype.Owned"class="associatedtype">Owned</a> = T</h4></section></summary><divclass='docblock'>The resulting type after obtaining ownership.</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.to_owned"class="method trait-impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.78.0/src/alloc/borrow.rs.html#88">source</a><ahref="#method.to_owned"class="anchor">§</a><h4class="code-header">fn <ahref="https://doc.rust-lang.org/1.78.0/alloc/borrow/trait.ToOwned.html#tymethod.to_owned"class="fn">to_owned</a>(&self) -> T</h4></section></summary><divclass='docblock'>Creates owned data from borrowed data, usually by cloning. <ahref="https://doc.rust-lang.org/1.78.0/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.clone_into"class="method trait-impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.78.0/src/alloc/borrow.rs.html#92">source</a><ahref="#method.clone_into"class="anchor">§</a><h4class="code-header">fn <ahref="https://doc.rust-lang.org/1.78.0/alloc/borrow/trait.ToOwned.html#method.clone_into"class="fn">clone_into</a>(&self, target: <aclass="primitive"href="https://doc.rust-lang.org/1.78.0/std/primitive.reference.html">&mut T</a>)</h4></section></summary><divclass='docblock'>Uses borrowed data to replace owned data, usually by cloning. <ahref="https://doc.rust-lang.org/1.78.0/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></div></details></div></details><detailsclass="toggle implementors-toggle"><summary><sectionid="impl-TryFrom%3CU%3E-for-T"class="impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.78.0/src/core/convert/mod.rs.html#805-807">source</a><ahref="#impl-TryFrom%3CU%3E-for-T"class="anchor">§</a><h3class="code-header">impl<T, U><aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html"title="trait core::convert::TryFrom">TryFrom</a><U> for T<divclass="where">where
U: <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/convert/trait.Into.html"title="trait core::convert::Into">Into</a><T>,</div></h3></section></summary><divclass="impl-items"><detailsclass="toggle"open><summary><sectionid="associatedtype.Error-1"class="associatedtype trait-impl"><ahref="#associatedtype.Error-1"class="anchor">§</a><h4class="code-header">type <ahref="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html#associatedtype.Error"class="associatedtype">Error</a> = <aclass="enum"href="https://doc.rust-lang.org/1.78.0/core/convert/enum.Infallible.html"title="enum core::convert::Infallible">Infallible</a></h4></section></summary><divclass='docblock'>The type returned in the event of a conversion error.</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.try_from"class="method trait-impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.78.0/src/core/convert/mod.rs.html#812">source</a><ahref="#method.try_from"class="anchor">§</a><h4class="code-header">fn <ahref="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html#tymethod.try_from"class="fn">try_from</a>(value: U) -><aclass="enum"href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html"title="enum core::result::Result">Result</a><T, <T as <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html"title="trait core::convert::TryFrom">TryFrom</a><U>>::<aclass="associatedtype"href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html#associatedtype.Error"title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><divclass='docblock'>Performs the conversion.</div></details></div></details><detailsclass="toggle implementors-toggle"><summary><sectionid="impl-TryInto%3CU%3E-for-T"class="impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.78.0/src/core/convert/mod.rs.html#790-792">source</a><ahref="#impl-TryInto%3CU%3E-for-T"class="anchor">§</a><h3class="code-header">impl<T, U><aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryInto.html"title="trait core::convert::TryInto">TryInto</a><U> for T<divclass="where">where
U: <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html"title="trait core::convert::TryFrom">TryFrom</a><T>,</div></h3></section></summary><divclass="impl-items"><detailsclass="toggle"open><summary><sectionid="associatedtype.Error"class="associatedtype trait-impl"><ahref="#associatedtype.Error"class="anchor">§</a><h4class="code-header">type <ahref="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryInto.html#associatedtype.Error"class="associatedtype">Error</a> = <U as <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html"title="trait core::convert::TryFrom">TryFrom</a><T>>::<aclass="associatedtype"href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html#associatedtype.Error"title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><divclass='docblock'>The type returned in the event of a conversion error.</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.try_into"class="method trait-impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.78.0/src/core/convert/mod.rs.html#797">source</a><ahref="#method.try_into"class="anchor">§</a><h4class="code-header">fn <ahref="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryInto.html#tymethod.try_into"class="fn">try_into</a>(self) -><aclass="enum"href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html"title="enum core::result::Result">Result</a><U, <U as <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html"title="trait core::convert::TryFrom">TryFrom</a><T>>::<aclass="associatedtype"href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html#associatedtype.Error"title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><divclass='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main></body></html>