706 lines
130 KiB
HTML
706 lines
130 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="A dense table-based deterministic finite automaton (DFA)."><title>DFA in regex_automata::dfa::dense - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="regex_automata" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../../../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">DFA</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../regex_automata/index.html">regex_<wbr>automata</a><span class="version">0.4.14</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">DFA</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#type-parameters" title="Type parameters">Type parameters</a></li><li><a href="#the-automaton-trait" title="The `Automaton` trait">The <code>Automaton</code> trait</a></li></ul><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.alphabet_len" title="alphabet_len">alphabet_len</a></li><li><a href="#method.always_match" title="always_match">always_match</a></li><li><a href="#method.as_ref" title="as_ref">as_ref</a></li><li><a href="#method.builder" title="builder">builder</a></li><li><a href="#method.byte_classes" title="byte_classes">byte_classes</a></li><li><a href="#method.config" title="config">config</a></li><li><a href="#method.from_bytes" title="from_bytes">from_bytes</a></li><li><a href="#method.from_bytes_unchecked" title="from_bytes_unchecked">from_bytes_unchecked</a></li><li><a href="#method.memory_usage" title="memory_usage">memory_usage</a></li><li><a href="#method.never_match" title="never_match">never_match</a></li><li><a href="#method.new" title="new">new</a></li><li><a href="#method.new_many" title="new_many">new_many</a></li><li><a href="#method.set_prefilter" title="set_prefilter">set_prefilter</a></li><li><a href="#method.start_kind" title="start_kind">start_kind</a></li><li><a href="#method.starts_for_each_pattern" title="starts_for_each_pattern">starts_for_each_pattern</a></li><li><a href="#method.stride" title="stride">stride</a></li><li><a href="#method.stride2" title="stride2">stride2</a></li><li><a href="#method.to_bytes_big_endian" title="to_bytes_big_endian">to_bytes_big_endian</a></li><li><a href="#method.to_bytes_little_endian" title="to_bytes_little_endian">to_bytes_little_endian</a></li><li><a href="#method.to_bytes_native_endian" title="to_bytes_native_endian">to_bytes_native_endian</a></li><li><a href="#method.to_owned" title="to_owned">to_owned</a></li><li><a href="#method.to_sparse" title="to_sparse">to_sparse</a></li><li><a href="#method.write_to_big_endian" title="write_to_big_endian">write_to_big_endian</a></li><li><a href="#method.write_to_len" title="write_to_len">write_to_len</a></li><li><a href="#method.write_to_little_endian" title="write_to_little_endian">write_to_little_endian</a></li><li><a href="#method.write_to_native_endian" title="write_to_native_endian">write_to_native_endian</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Automaton-for-DFA%3CT%3E" title="Automaton">Automaton</a></li><li><a href="#impl-Clone-for-DFA%3CT%3E" title="Clone">Clone</a></li><li><a href="#impl-Debug-for-DFA%3CT%3E" title="Debug">Debug</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-Freeze-for-DFA%3CT%3E" title="Freeze">Freeze</a></li><li><a href="#impl-RefUnwindSafe-for-DFA%3CT%3E" title="RefUnwindSafe">RefUnwindSafe</a></li><li><a href="#impl-Send-for-DFA%3CT%3E" title="Send">Send</a></li><li><a href="#impl-Sync-for-DFA%3CT%3E" title="Sync">Sync</a></li><li><a href="#impl-Unpin-for-DFA%3CT%3E" title="Unpin">Unpin</a></li><li><a href="#impl-UnwindSafe-for-DFA%3CT%3E" title="UnwindSafe">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T" title="Any">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T" title="Borrow<T>">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T" title="BorrowMut<T>">BorrowMut<T></a></li><li><a href="#impl-CloneToUninit-for-T" title="CloneToUninit">CloneToUninit</a></li><li><a href="#impl-From%3CT%3E-for-T" title="From<T>">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-T" title="Into<U>">Into<U></a></li><li><a href="#impl-ToOwned-for-T" title="ToOwned">ToOwned</a></li><li><a href="#impl-TryFrom%3CU%3E-for-T" title="TryFrom<U>">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-T" title="TryInto<U>">TryInto<U></a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In regex_<wbr>automata::<wbr>dfa::<wbr>dense</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../index.html">regex_automata</a>::<wbr><a href="../index.html">dfa</a>::<wbr><a href="index.html">dense</a></div><h1>Struct <span class="struct">DFA</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/regex_automata/dfa/dense.rs.html#1394-1445">Source</a> </span></div><pre class="rust item-decl"><code>pub struct DFA<T> { <span class="comment">/* private fields */</span> }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A dense table-based deterministic finite automaton (DFA).</p>
|
||
<p>All dense DFAs have one or more start states, zero or more match states
|
||
and a transition table that maps the current state and the current byte
|
||
of input to the next state. A DFA can use this information to implement
|
||
fast searching. In particular, the use of a dense DFA generally makes the
|
||
trade off that match speed is the most valuable characteristic, even if
|
||
building the DFA may take significant time <em>and</em> space. (More concretely,
|
||
building a DFA takes time and space that is exponential in the size of the
|
||
pattern in the worst case.) As such, the processing of every byte of input
|
||
is done with a small constant number of operations that does not vary with
|
||
the pattern, its size or the size of the alphabet. If your needs don’t line
|
||
up with this trade off, then a dense DFA may not be an adequate solution to
|
||
your problem.</p>
|
||
<p>In contrast, a <a href="../sparse/struct.DFA.html" title="struct regex_automata::dfa::sparse::DFA"><code>sparse::DFA</code></a> makes the opposite
|
||
trade off: it uses less space but will execute a variable number of
|
||
instructions per byte at match time, which makes it slower for matching.
|
||
(Note that space usage is still exponential in the size of the pattern in
|
||
the worst case.)</p>
|
||
<p>A DFA can be built using the default configuration via the
|
||
<a href="struct.DFA.html#method.new" title="associated function regex_automata::dfa::dense::DFA::new"><code>DFA::new</code></a> constructor. Otherwise, one can
|
||
configure various aspects via <a href="struct.Builder.html" title="struct regex_automata::dfa::dense::Builder"><code>dense::Builder</code></a>.</p>
|
||
<p>A single DFA fundamentally supports the following operations:</p>
|
||
<ol>
|
||
<li>Detection of a match.</li>
|
||
<li>Location of the end of a match.</li>
|
||
<li>In the case of a DFA with multiple patterns, which pattern matched is
|
||
reported as well.</li>
|
||
</ol>
|
||
<p>A notable absence from the above list of capabilities is the location of
|
||
the <em>start</em> of a match. In order to provide both the start and end of
|
||
a match, <em>two</em> DFAs are required. This functionality is provided by a
|
||
<a href="../regex/struct.Regex.html" title="struct regex_automata::dfa::regex::Regex"><code>Regex</code></a>.</p>
|
||
<h2 id="type-parameters"><a class="doc-anchor" href="#type-parameters">§</a>Type parameters</h2>
|
||
<p>A <code>DFA</code> has one type parameter, <code>T</code>, which is used to represent state IDs,
|
||
pattern IDs and accelerators. <code>T</code> is typically a <code>Vec<u32></code> or a <code>&[u32]</code>.</p>
|
||
<h2 id="the-automaton-trait"><a class="doc-anchor" href="#the-automaton-trait">§</a>The <code>Automaton</code> trait</h2>
|
||
<p>This type implements the <a href="../trait.Automaton.html" title="trait regex_automata::dfa::Automaton"><code>Automaton</code></a> trait, which means it can be used
|
||
for searching. For example:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense::DFA}, HalfMatch, Input};
|
||
|
||
<span class="kw">let </span>dfa = DFA::new(<span class="string">"foo[0-9]+"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>expected = HalfMatch::must(<span class="number">0</span>, <span class="number">8</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(expected), dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345"</span>))<span class="question-mark">?</span>);</code></pre></div></div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-DFA%3CVec%3Cu32%3E%3E" class="impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1448-1492">Source</a><a href="#impl-DFA%3CVec%3Cu32%3E%3E" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><<a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>>></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.new" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1466-1468">Source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>(pattern: &<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.str.html">str</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><<a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>>>, <a class="struct" href="struct.BuildError.html" title="struct regex_automata::dfa::dense::BuildError">BuildError</a>></h4></section></summary><div class="docblock"><p>Parse the given regular expression using a default configuration and
|
||
return the corresponding DFA.</p>
|
||
<p>If you want a non-default configuration, then use the
|
||
<a href="struct.Builder.html" title="struct regex_automata::dfa::dense::Builder"><code>dense::Builder</code></a> to set your own configuration.</p>
|
||
<h5 id="example"><a class="doc-anchor" href="#example">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense}, HalfMatch, Input};
|
||
|
||
<span class="kw">let </span>dfa = dense::DFA::new(<span class="string">"foo[0-9]+bar"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">11</span>));
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345bar"</span>))<span class="question-mark">?</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.new_many" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1487-1491">Source</a><h4 class="code-header">pub fn <a href="#method.new_many" class="fn">new_many</a><P: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.str.html">str</a>>>(
|
||
patterns: &<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.slice.html">[P]</a>,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><<a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>>>, <a class="struct" href="struct.BuildError.html" title="struct regex_automata::dfa::dense::BuildError">BuildError</a>></h4></section></summary><div class="docblock"><p>Parse the given regular expressions using a default configuration and
|
||
return the corresponding multi-DFA.</p>
|
||
<p>If you want a non-default configuration, then use the
|
||
<a href="struct.Builder.html" title="struct regex_automata::dfa::dense::Builder"><code>dense::Builder</code></a> to set your own configuration.</p>
|
||
<h5 id="example-1"><a class="doc-anchor" href="#example-1">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense}, HalfMatch, Input};
|
||
|
||
<span class="kw">let </span>dfa = dense::DFA::new_many(<span class="kw-2">&</span>[<span class="string">"[0-9]+"</span>, <span class="string">"[a-z]+"</span>])<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">1</span>, <span class="number">3</span>));
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345bar"</span>))<span class="question-mark">?</span>);</code></pre></div></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-DFA%3CVec%3Cu32%3E%3E-1" class="impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1495-1558">Source</a><a href="#impl-DFA%3CVec%3Cu32%3E%3E-1" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><<a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>>></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.always_match" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1510-1513">Source</a><h4 class="code-header">pub fn <a href="#method.always_match" class="fn">always_match</a>() -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><<a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>>>, <a class="struct" href="struct.BuildError.html" title="struct regex_automata::dfa::dense::BuildError">BuildError</a>></h4></section></summary><div class="docblock"><p>Create a new DFA that matches every input.</p>
|
||
<h5 id="example-2"><a class="doc-anchor" href="#example-2">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense}, HalfMatch, Input};
|
||
|
||
<span class="kw">let </span>dfa = dense::DFA::always_match()<span class="question-mark">?</span>;
|
||
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">0</span>));
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">""</span>))<span class="question-mark">?</span>);
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo"</span>))<span class="question-mark">?</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.never_match" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1527-1530">Source</a><h4 class="code-header">pub fn <a href="#method.never_match" class="fn">never_match</a>() -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><<a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>>>, <a class="struct" href="struct.BuildError.html" title="struct regex_automata::dfa::dense::BuildError">BuildError</a>></h4></section></summary><div class="docblock"><p>Create a new DFA that never matches any input.</p>
|
||
<h5 id="example-3"><a class="doc-anchor" href="#example-3">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense}, Input};
|
||
|
||
<span class="kw">let </span>dfa = dense::DFA::never_match()<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">""</span>))<span class="question-mark">?</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo"</span>))<span class="question-mark">?</span>);</code></pre></div></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-DFA%3C%26%5Bu32%5D%3E" class="impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1561-1577">Source</a><a href="#impl-DFA%3C%26%5Bu32%5D%3E" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><&[<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>]></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.config" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1566-1568">Source</a><h4 class="code-header">pub fn <a href="#method.config" class="fn">config</a>() -> <a class="struct" href="struct.Config.html" title="struct regex_automata::dfa::dense::Config">Config</a></h4></section></summary><div class="docblock"><p>Return a new default dense DFA compiler configuration.</p>
|
||
<p>This is a convenience routine to avoid needing to import the <a href="struct.Config.html" title="struct regex_automata::dfa::dense::Config"><code>Config</code></a>
|
||
type when customizing the construction of a dense DFA.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.builder" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1574-1576">Source</a><h4 class="code-header">pub fn <a href="#method.builder" class="fn">builder</a>() -> <a class="struct" href="struct.Builder.html" title="struct regex_automata::dfa::dense::Builder">Builder</a></h4></section></summary><div class="docblock"><p>Create a new dense DFA builder with the default configuration.</p>
|
||
<p>This is a convenience routine to avoid needing to import the
|
||
<a href="struct.Builder.html" title="struct regex_automata::dfa::dense::Builder"><code>Builder</code></a> type in common cases.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-DFA%3CT%3E" class="impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1579-1737">Source</a><a href="#impl-DFA%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>]>> <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><T></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.as_ref" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1582-1593">Source</a><h4 class="code-header">pub fn <a href="#method.as_ref" class="fn">as_ref</a>(&self) -> <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><&[<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>]></h4></section></summary><div class="docblock"><p>Cheaply return a borrowed version of this dense DFA. Specifically,
|
||
the DFA returned always uses <code>&[u32]</code> for its transition table.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.to_owned" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1601-1612">Source</a><h4 class="code-header">pub fn <a href="#method.to_owned" class="fn">to_owned</a>(&self) -> <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><<a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>>></h4></section></summary><div class="docblock"><p>Return an owned version of this sparse DFA. Specifically, the DFA
|
||
returned always uses <code>Vec<u32></code> for its transition table.</p>
|
||
<p>Effectively, this returns a dense DFA whose transition table lives on
|
||
the heap.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.start_kind" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1621-1623">Source</a><h4 class="code-header">pub fn <a href="#method.start_kind" class="fn">start_kind</a>(&self) -> <a class="enum" href="../enum.StartKind.html" title="enum regex_automata::dfa::StartKind">StartKind</a></h4></section></summary><div class="docblock"><p>Returns the starting state configuration for this DFA.</p>
|
||
<p>The default is <a href="../enum.StartKind.html#variant.Both" title="variant regex_automata::dfa::StartKind::Both"><code>StartKind::Both</code></a>, which means the DFA supports both
|
||
unanchored and anchored searches. However, this can generally lead to
|
||
bigger DFAs. Therefore, a DFA might be compiled with support for just
|
||
unanchored or anchored searches. In that case, running a search with
|
||
an unsupported configuration will panic.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.starts_for_each_pattern" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1640-1642">Source</a><h4 class="code-header">pub fn <a href="#method.starts_for_each_pattern" class="fn">starts_for_each_pattern</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns true only if this DFA has starting states for each pattern.</p>
|
||
<p>When a DFA has starting states for each pattern, then a search with the
|
||
DFA can be configured to only look for anchored matches of a specific
|
||
pattern. Specifically, APIs like <a href="../trait.Automaton.html#method.try_search_fwd" title="method regex_automata::dfa::Automaton::try_search_fwd"><code>Automaton::try_search_fwd</code></a> can
|
||
accept a non-None <code>pattern_id</code> if and only if this method returns true.
|
||
Otherwise, calling <code>try_search_fwd</code> will panic.</p>
|
||
<p>Note that if the DFA has no patterns, this always returns false.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.byte_classes" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1657-1659">Source</a><h4 class="code-header">pub fn <a href="#method.byte_classes" class="fn">byte_classes</a>(&self) -> &<a class="struct" href="../../util/alphabet/struct.ByteClasses.html" title="struct regex_automata::util::alphabet::ByteClasses">ByteClasses</a></h4></section></summary><div class="docblock"><p>Returns the equivalence classes that make up the alphabet for this DFA.</p>
|
||
<p>Unless <a href="struct.Config.html#method.byte_classes" title="method regex_automata::dfa::dense::Config::byte_classes"><code>Config::byte_classes</code></a> was disabled, it is possible that
|
||
multiple distinct bytes are grouped into the same equivalence class
|
||
if it is impossible for them to discriminate between a match and a
|
||
non-match. This has the effect of reducing the overall alphabet size
|
||
and in turn potentially substantially reducing the size of the DFA’s
|
||
transition table.</p>
|
||
<p>The downside of using equivalence classes like this is that every state
|
||
transition will automatically use this map to convert an arbitrary
|
||
byte to its corresponding equivalence class. In practice this has a
|
||
negligible impact on performance.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.alphabet_len" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1685-1687">Source</a><h4 class="code-header">pub fn <a href="#method.alphabet_len" class="fn">alphabet_len</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the total number of elements in the alphabet for this DFA.</p>
|
||
<p>That is, this returns the total number of transitions that each state
|
||
in this DFA must have. Typically, a normal byte oriented DFA would
|
||
always have an alphabet size of 256, corresponding to the number of
|
||
unique values in a single byte. However, this implementation has two
|
||
peculiarities that impact the alphabet length:</p>
|
||
<ul>
|
||
<li>Every state has a special “EOI” transition that is only followed
|
||
after the end of some haystack is reached. This EOI transition is
|
||
necessary to account for one byte of look-ahead when implementing
|
||
things like <code>\b</code> and <code>$</code>.</li>
|
||
<li>Bytes are grouped into equivalence classes such that no two bytes in
|
||
the same class can distinguish a match from a non-match. For example,
|
||
in the regex <code>^[a-z]+$</code>, the ASCII bytes <code>a-z</code> could all be in the
|
||
same equivalence class. This leads to a massive space savings.</li>
|
||
</ul>
|
||
<p>Note though that the alphabet length does <em>not</em> necessarily equal the
|
||
total stride space taken up by a single DFA state in the transition
|
||
table. Namely, for performance reasons, the stride is always the
|
||
smallest power of two that is greater than or equal to the alphabet
|
||
length. For this reason, <a href="struct.DFA.html#method.stride" title="method regex_automata::dfa::dense::DFA::stride"><code>DFA::stride</code></a> or <a href="struct.DFA.html#method.stride2" title="method regex_automata::dfa::dense::DFA::stride2"><code>DFA::stride2</code></a> are
|
||
often more useful. The alphabet length is typically useful only for
|
||
informational purposes.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.stride2" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1709-1711">Source</a><h4 class="code-header">pub fn <a href="#method.stride2" class="fn">stride2</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the total stride for every state in this DFA, expressed as the
|
||
exponent of a power of 2. The stride is the amount of space each state
|
||
takes up in the transition table, expressed as a number of transitions.
|
||
(Unused transitions map to dead states.)</p>
|
||
<p>The stride of a DFA is always equivalent to the smallest power of 2
|
||
that is greater than or equal to the DFA’s alphabet length. This
|
||
definition uses extra space, but permits faster translation between
|
||
premultiplied state identifiers and contiguous indices (by using shifts
|
||
instead of relying on integer division).</p>
|
||
<p>For example, if the DFA’s stride is 16 transitions, then its <code>stride2</code>
|
||
is <code>4</code> since <code>2^4 = 16</code>.</p>
|
||
<p>The minimum <code>stride2</code> value is <code>1</code> (corresponding to a stride of <code>2</code>)
|
||
while the maximum <code>stride2</code> value is <code>9</code> (corresponding to a stride of
|
||
<code>512</code>). The maximum is not <code>8</code> since the maximum alphabet size is <code>257</code>
|
||
when accounting for the special EOI transition. However, an alphabet
|
||
length of that size is exceptionally rare since the alphabet is shrunk
|
||
into equivalence classes.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.stride" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1720-1722">Source</a><h4 class="code-header">pub fn <a href="#method.stride" class="fn">stride</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the total stride for every state in this DFA. This corresponds
|
||
to the total number of transitions used by each state in this DFA’s
|
||
transition table.</p>
|
||
<p>Please see <a href="struct.DFA.html#method.stride2" title="method regex_automata::dfa::dense::DFA::stride2"><code>DFA::stride2</code></a> for more information. In particular, this
|
||
returns the stride as the number of transitions, where as <code>stride2</code>
|
||
returns it as the exponent of a power of 2.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.memory_usage" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1731-1736">Source</a><h4 class="code-header">pub fn <a href="#method.memory_usage" class="fn">memory_usage</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the memory usage, in bytes, of this DFA.</p>
|
||
<p>The memory usage is computed based on the number of bytes used to
|
||
represent this DFA.</p>
|
||
<p>This does <strong>not</strong> include the stack size used up by this DFA. To
|
||
compute that, use <code>std::mem::size_of::<dense::DFA>()</code>.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-DFA%3CT%3E-1" class="impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1741-2163">Source</a><a href="#impl-DFA%3CT%3E-1" class="anchor">§</a><h3 class="code-header">impl<T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>]>> <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><T></h3><div class="docblock"><p>Routines for converting a dense DFA to other representations, such as
|
||
sparse DFAs or raw bytes suitable for persistent storage.</p>
|
||
</div></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.to_sparse" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1762-1764">Source</a><h4 class="code-header">pub fn <a href="#method.to_sparse" class="fn">to_sparse</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../sparse/struct.DFA.html" title="struct regex_automata::dfa::sparse::DFA">DFA</a><<a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>>>, <a class="struct" href="struct.BuildError.html" title="struct regex_automata::dfa::dense::BuildError">BuildError</a>></h4></section></summary><div class="docblock"><p>Convert this dense DFA to a sparse DFA.</p>
|
||
<p>If a <code>StateID</code> is too small to represent all states in the sparse
|
||
DFA, then this returns an error. In most cases, if a dense DFA is
|
||
constructable with <code>StateID</code> then a sparse DFA will be as well.
|
||
However, it is not guaranteed.</p>
|
||
<h5 id="example-4"><a class="doc-anchor" href="#example-4">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense}, HalfMatch, Input};
|
||
|
||
<span class="kw">let </span>dense = dense::DFA::new(<span class="string">"foo[0-9]+"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>sparse = dense.to_sparse()<span class="question-mark">?</span>;
|
||
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">8</span>));
|
||
<span class="macro">assert_eq!</span>(expected, sparse.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345"</span>))<span class="question-mark">?</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.to_bytes_little_endian" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1805-1807">Source</a><h4 class="code-header">pub fn <a href="#method.to_bytes_little_endian" class="fn">to_bytes_little_endian</a>(&self) -> (<a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>>, <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>)</h4></section></summary><div class="docblock"><p>Serialize this DFA as raw bytes to a <code>Vec<u8></code> in little endian
|
||
format. Upon success, the <code>Vec<u8></code> and the initial padding length are
|
||
returned.</p>
|
||
<p>The written bytes are guaranteed to be deserialized correctly and
|
||
without errors in a semver compatible release of this crate by a
|
||
<code>DFA</code>’s deserialization APIs (assuming all other criteria for the
|
||
deserialization APIs has been satisfied):</p>
|
||
<ul>
|
||
<li><a href="struct.DFA.html#method.from_bytes" title="associated function regex_automata::dfa::dense::DFA::from_bytes"><code>DFA::from_bytes</code></a></li>
|
||
<li><a href="struct.DFA.html#method.from_bytes_unchecked" title="associated function regex_automata::dfa::dense::DFA::from_bytes_unchecked"><code>DFA::from_bytes_unchecked</code></a></li>
|
||
</ul>
|
||
<p>The padding returned is non-zero if the returned <code>Vec<u8></code> starts at
|
||
an address that does not have the same alignment as <code>u32</code>. The padding
|
||
corresponds to the number of leading bytes written to the returned
|
||
<code>Vec<u8></code>.</p>
|
||
<h5 id="example-5"><a class="doc-anchor" href="#example-5">§</a>Example</h5>
|
||
<p>This example shows how to serialize and deserialize a DFA:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense::DFA}, HalfMatch, Input};
|
||
|
||
<span class="comment">// Compile our original DFA.
|
||
</span><span class="kw">let </span>original_dfa = DFA::new(<span class="string">"foo[0-9]+"</span>)<span class="question-mark">?</span>;
|
||
|
||
<span class="comment">// N.B. We use native endianness here to make the example work, but
|
||
// using to_bytes_little_endian would work on a little endian target.
|
||
</span><span class="kw">let </span>(buf, <span class="kw">_</span>) = original_dfa.to_bytes_native_endian();
|
||
<span class="comment">// Even if buf has initial padding, DFA::from_bytes will automatically
|
||
// ignore it.
|
||
</span><span class="kw">let </span>dfa: DFA<<span class="kw-2">&</span>[u32]> = DFA::from_bytes(<span class="kw-2">&</span>buf)<span class="question-mark">?</span>.<span class="number">0</span>;
|
||
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">8</span>));
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345"</span>))<span class="question-mark">?</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.to_bytes_big_endian" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1848-1850">Source</a><h4 class="code-header">pub fn <a href="#method.to_bytes_big_endian" class="fn">to_bytes_big_endian</a>(&self) -> (<a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>>, <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>)</h4></section></summary><div class="docblock"><p>Serialize this DFA as raw bytes to a <code>Vec<u8></code> in big endian
|
||
format. Upon success, the <code>Vec<u8></code> and the initial padding length are
|
||
returned.</p>
|
||
<p>The written bytes are guaranteed to be deserialized correctly and
|
||
without errors in a semver compatible release of this crate by a
|
||
<code>DFA</code>’s deserialization APIs (assuming all other criteria for the
|
||
deserialization APIs has been satisfied):</p>
|
||
<ul>
|
||
<li><a href="struct.DFA.html#method.from_bytes" title="associated function regex_automata::dfa::dense::DFA::from_bytes"><code>DFA::from_bytes</code></a></li>
|
||
<li><a href="struct.DFA.html#method.from_bytes_unchecked" title="associated function regex_automata::dfa::dense::DFA::from_bytes_unchecked"><code>DFA::from_bytes_unchecked</code></a></li>
|
||
</ul>
|
||
<p>The padding returned is non-zero if the returned <code>Vec<u8></code> starts at
|
||
an address that does not have the same alignment as <code>u32</code>. The padding
|
||
corresponds to the number of leading bytes written to the returned
|
||
<code>Vec<u8></code>.</p>
|
||
<h5 id="example-6"><a class="doc-anchor" href="#example-6">§</a>Example</h5>
|
||
<p>This example shows how to serialize and deserialize a DFA:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense::DFA}, HalfMatch, Input};
|
||
|
||
<span class="comment">// Compile our original DFA.
|
||
</span><span class="kw">let </span>original_dfa = DFA::new(<span class="string">"foo[0-9]+"</span>)<span class="question-mark">?</span>;
|
||
|
||
<span class="comment">// N.B. We use native endianness here to make the example work, but
|
||
// using to_bytes_big_endian would work on a big endian target.
|
||
</span><span class="kw">let </span>(buf, <span class="kw">_</span>) = original_dfa.to_bytes_native_endian();
|
||
<span class="comment">// Even if buf has initial padding, DFA::from_bytes will automatically
|
||
// ignore it.
|
||
</span><span class="kw">let </span>dfa: DFA<<span class="kw-2">&</span>[u32]> = DFA::from_bytes(<span class="kw-2">&</span>buf)<span class="question-mark">?</span>.<span class="number">0</span>;
|
||
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">8</span>));
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345"</span>))<span class="question-mark">?</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.to_bytes_native_endian" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1898-1900">Source</a><h4 class="code-header">pub fn <a href="#method.to_bytes_native_endian" class="fn">to_bytes_native_endian</a>(&self) -> (<a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>>, <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>)</h4></section></summary><div class="docblock"><p>Serialize this DFA as raw bytes to a <code>Vec<u8></code> in native endian
|
||
format. Upon success, the <code>Vec<u8></code> and the initial padding length are
|
||
returned.</p>
|
||
<p>The written bytes are guaranteed to be deserialized correctly and
|
||
without errors in a semver compatible release of this crate by a
|
||
<code>DFA</code>’s deserialization APIs (assuming all other criteria for the
|
||
deserialization APIs has been satisfied):</p>
|
||
<ul>
|
||
<li><a href="struct.DFA.html#method.from_bytes" title="associated function regex_automata::dfa::dense::DFA::from_bytes"><code>DFA::from_bytes</code></a></li>
|
||
<li><a href="struct.DFA.html#method.from_bytes_unchecked" title="associated function regex_automata::dfa::dense::DFA::from_bytes_unchecked"><code>DFA::from_bytes_unchecked</code></a></li>
|
||
</ul>
|
||
<p>The padding returned is non-zero if the returned <code>Vec<u8></code> starts at
|
||
an address that does not have the same alignment as <code>u32</code>. The padding
|
||
corresponds to the number of leading bytes written to the returned
|
||
<code>Vec<u8></code>.</p>
|
||
<p>Generally speaking, native endian format should only be used when
|
||
you know that the target you’re compiling the DFA for matches the
|
||
endianness of the target on which you’re compiling DFA. For example,
|
||
if serialization and deserialization happen in the same process or on
|
||
the same machine. Otherwise, when serializing a DFA for use in a
|
||
portable environment, you’ll almost certainly want to serialize <em>both</em>
|
||
a little endian and a big endian version and then load the correct one
|
||
based on the target’s configuration.</p>
|
||
<h5 id="example-7"><a class="doc-anchor" href="#example-7">§</a>Example</h5>
|
||
<p>This example shows how to serialize and deserialize a DFA:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense::DFA}, HalfMatch, Input};
|
||
|
||
<span class="comment">// Compile our original DFA.
|
||
</span><span class="kw">let </span>original_dfa = DFA::new(<span class="string">"foo[0-9]+"</span>)<span class="question-mark">?</span>;
|
||
|
||
<span class="kw">let </span>(buf, <span class="kw">_</span>) = original_dfa.to_bytes_native_endian();
|
||
<span class="comment">// Even if buf has initial padding, DFA::from_bytes will automatically
|
||
// ignore it.
|
||
</span><span class="kw">let </span>dfa: DFA<<span class="kw-2">&</span>[u32]> = DFA::from_bytes(<span class="kw-2">&</span>buf)<span class="question-mark">?</span>.<span class="number">0</span>;
|
||
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">8</span>));
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345"</span>))<span class="question-mark">?</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.write_to_little_endian" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1966-1971">Source</a><h4 class="code-header">pub fn <a href="#method.write_to_little_endian" class="fn">write_to_little_endian</a>(
|
||
&self,
|
||
dst: &mut [<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>],
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>, <a class="struct" href="../../util/wire/struct.SerializeError.html" title="struct regex_automata::util::wire::SerializeError">SerializeError</a>></h4></section></summary><div class="docblock"><p>Serialize this DFA as raw bytes to the given slice, in little endian
|
||
format. Upon success, the total number of bytes written to <code>dst</code> is
|
||
returned.</p>
|
||
<p>The written bytes are guaranteed to be deserialized correctly and
|
||
without errors in a semver compatible release of this crate by a
|
||
<code>DFA</code>’s deserialization APIs (assuming all other criteria for the
|
||
deserialization APIs has been satisfied):</p>
|
||
<ul>
|
||
<li><a href="struct.DFA.html#method.from_bytes" title="associated function regex_automata::dfa::dense::DFA::from_bytes"><code>DFA::from_bytes</code></a></li>
|
||
<li><a href="struct.DFA.html#method.from_bytes_unchecked" title="associated function regex_automata::dfa::dense::DFA::from_bytes_unchecked"><code>DFA::from_bytes_unchecked</code></a></li>
|
||
</ul>
|
||
<p>Note that unlike the various <code>to_byte_*</code> routines, this does not write
|
||
any padding. Callers are responsible for handling alignment correctly.</p>
|
||
<h5 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h5>
|
||
<p>This returns an error if the given destination slice is not big enough
|
||
to contain the full serialized DFA. If an error occurs, then nothing
|
||
is written to <code>dst</code>.</p>
|
||
<h5 id="example-8"><a class="doc-anchor" href="#example-8">§</a>Example</h5>
|
||
<p>This example shows how to serialize and deserialize a DFA without
|
||
dynamic memory allocation.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense::DFA}, HalfMatch, Input};
|
||
|
||
<span class="comment">// Compile our original DFA.
|
||
</span><span class="kw">let </span>original_dfa = DFA::new(<span class="string">"foo[0-9]+"</span>)<span class="question-mark">?</span>;
|
||
|
||
<span class="comment">// Create a 4KB buffer on the stack to store our serialized DFA. We
|
||
// need to use a special type to force the alignment of our [u8; N]
|
||
// array to be aligned to a 4 byte boundary. Otherwise, deserializing
|
||
// the DFA may fail because of an alignment mismatch.
|
||
</span><span class="attr">#[repr(C)]
|
||
</span><span class="kw">struct </span>Aligned<B: <span class="question-mark">?</span>Sized> {
|
||
_align: [u32; <span class="number">0</span>],
|
||
bytes: B,
|
||
}
|
||
<span class="kw">let </span><span class="kw-2">mut </span>buf = Aligned { _align: [], bytes: [<span class="number">0u8</span>; <span class="number">4 </span>* (<span class="number">1</span><<<span class="number">10</span>)] };
|
||
<span class="comment">// N.B. We use native endianness here to make the example work, but
|
||
// using write_to_little_endian would work on a little endian target.
|
||
</span><span class="kw">let </span>written = original_dfa.write_to_native_endian(<span class="kw-2">&mut </span>buf.bytes)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>dfa: DFA<<span class="kw-2">&</span>[u32]> = DFA::from_bytes(<span class="kw-2">&</span>buf.bytes[..written])<span class="question-mark">?</span>.<span class="number">0</span>;
|
||
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">8</span>));
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345"</span>))<span class="question-mark">?</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.write_to_big_endian" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#2024-2029">Source</a><h4 class="code-header">pub fn <a href="#method.write_to_big_endian" class="fn">write_to_big_endian</a>(
|
||
&self,
|
||
dst: &mut [<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>],
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>, <a class="struct" href="../../util/wire/struct.SerializeError.html" title="struct regex_automata::util::wire::SerializeError">SerializeError</a>></h4></section></summary><div class="docblock"><p>Serialize this DFA as raw bytes to the given slice, in big endian
|
||
format. Upon success, the total number of bytes written to <code>dst</code> is
|
||
returned.</p>
|
||
<p>The written bytes are guaranteed to be deserialized correctly and
|
||
without errors in a semver compatible release of this crate by a
|
||
<code>DFA</code>’s deserialization APIs (assuming all other criteria for the
|
||
deserialization APIs has been satisfied):</p>
|
||
<ul>
|
||
<li><a href="struct.DFA.html#method.from_bytes" title="associated function regex_automata::dfa::dense::DFA::from_bytes"><code>DFA::from_bytes</code></a></li>
|
||
<li><a href="struct.DFA.html#method.from_bytes_unchecked" title="associated function regex_automata::dfa::dense::DFA::from_bytes_unchecked"><code>DFA::from_bytes_unchecked</code></a></li>
|
||
</ul>
|
||
<p>Note that unlike the various <code>to_byte_*</code> routines, this does not write
|
||
any padding. Callers are responsible for handling alignment correctly.</p>
|
||
<h5 id="errors-1"><a class="doc-anchor" href="#errors-1">§</a>Errors</h5>
|
||
<p>This returns an error if the given destination slice is not big enough
|
||
to contain the full serialized DFA. If an error occurs, then nothing
|
||
is written to <code>dst</code>.</p>
|
||
<h5 id="example-9"><a class="doc-anchor" href="#example-9">§</a>Example</h5>
|
||
<p>This example shows how to serialize and deserialize a DFA without
|
||
dynamic memory allocation.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense::DFA}, HalfMatch, Input};
|
||
|
||
<span class="comment">// Compile our original DFA.
|
||
</span><span class="kw">let </span>original_dfa = DFA::new(<span class="string">"foo[0-9]+"</span>)<span class="question-mark">?</span>;
|
||
|
||
<span class="comment">// Create a 4KB buffer on the stack to store our serialized DFA. We
|
||
// need to use a special type to force the alignment of our [u8; N]
|
||
// array to be aligned to a 4 byte boundary. Otherwise, deserializing
|
||
// the DFA may fail because of an alignment mismatch.
|
||
</span><span class="attr">#[repr(C)]
|
||
</span><span class="kw">struct </span>Aligned<B: <span class="question-mark">?</span>Sized> {
|
||
_align: [u32; <span class="number">0</span>],
|
||
bytes: B,
|
||
}
|
||
<span class="kw">let </span><span class="kw-2">mut </span>buf = Aligned { _align: [], bytes: [<span class="number">0u8</span>; <span class="number">4 </span>* (<span class="number">1</span><<<span class="number">10</span>)] };
|
||
<span class="comment">// N.B. We use native endianness here to make the example work, but
|
||
// using write_to_big_endian would work on a big endian target.
|
||
</span><span class="kw">let </span>written = original_dfa.write_to_native_endian(<span class="kw-2">&mut </span>buf.bytes)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>dfa: DFA<<span class="kw-2">&</span>[u32]> = DFA::from_bytes(<span class="kw-2">&</span>buf.bytes[..written])<span class="question-mark">?</span>.<span class="number">0</span>;
|
||
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">8</span>));
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345"</span>))<span class="question-mark">?</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.write_to_native_endian" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#2089-2094">Source</a><h4 class="code-header">pub fn <a href="#method.write_to_native_endian" class="fn">write_to_native_endian</a>(
|
||
&self,
|
||
dst: &mut [<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>],
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>, <a class="struct" href="../../util/wire/struct.SerializeError.html" title="struct regex_automata::util::wire::SerializeError">SerializeError</a>></h4></section></summary><div class="docblock"><p>Serialize this DFA as raw bytes to the given slice, in native endian
|
||
format. Upon success, the total number of bytes written to <code>dst</code> is
|
||
returned.</p>
|
||
<p>The written bytes are guaranteed to be deserialized correctly and
|
||
without errors in a semver compatible release of this crate by a
|
||
<code>DFA</code>’s deserialization APIs (assuming all other criteria for the
|
||
deserialization APIs has been satisfied):</p>
|
||
<ul>
|
||
<li><a href="struct.DFA.html#method.from_bytes" title="associated function regex_automata::dfa::dense::DFA::from_bytes"><code>DFA::from_bytes</code></a></li>
|
||
<li><a href="struct.DFA.html#method.from_bytes_unchecked" title="associated function regex_automata::dfa::dense::DFA::from_bytes_unchecked"><code>DFA::from_bytes_unchecked</code></a></li>
|
||
</ul>
|
||
<p>Generally speaking, native endian format should only be used when
|
||
you know that the target you’re compiling the DFA for matches the
|
||
endianness of the target on which you’re compiling DFA. For example,
|
||
if serialization and deserialization happen in the same process or on
|
||
the same machine. Otherwise, when serializing a DFA for use in a
|
||
portable environment, you’ll almost certainly want to serialize <em>both</em>
|
||
a little endian and a big endian version and then load the correct one
|
||
based on the target’s configuration.</p>
|
||
<p>Note that unlike the various <code>to_byte_*</code> routines, this does not write
|
||
any padding. Callers are responsible for handling alignment correctly.</p>
|
||
<h5 id="errors-2"><a class="doc-anchor" href="#errors-2">§</a>Errors</h5>
|
||
<p>This returns an error if the given destination slice is not big enough
|
||
to contain the full serialized DFA. If an error occurs, then nothing
|
||
is written to <code>dst</code>.</p>
|
||
<h5 id="example-10"><a class="doc-anchor" href="#example-10">§</a>Example</h5>
|
||
<p>This example shows how to serialize and deserialize a DFA without
|
||
dynamic memory allocation.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense::DFA}, HalfMatch, Input};
|
||
|
||
<span class="comment">// Compile our original DFA.
|
||
</span><span class="kw">let </span>original_dfa = DFA::new(<span class="string">"foo[0-9]+"</span>)<span class="question-mark">?</span>;
|
||
|
||
<span class="comment">// Create a 4KB buffer on the stack to store our serialized DFA. We
|
||
// need to use a special type to force the alignment of our [u8; N]
|
||
// array to be aligned to a 4 byte boundary. Otherwise, deserializing
|
||
// the DFA may fail because of an alignment mismatch.
|
||
</span><span class="attr">#[repr(C)]
|
||
</span><span class="kw">struct </span>Aligned<B: <span class="question-mark">?</span>Sized> {
|
||
_align: [u32; <span class="number">0</span>],
|
||
bytes: B,
|
||
}
|
||
<span class="kw">let </span><span class="kw-2">mut </span>buf = Aligned { _align: [], bytes: [<span class="number">0u8</span>; <span class="number">4 </span>* (<span class="number">1</span><<<span class="number">10</span>)] };
|
||
<span class="kw">let </span>written = original_dfa.write_to_native_endian(<span class="kw-2">&mut </span>buf.bytes)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>dfa: DFA<<span class="kw-2">&</span>[u32]> = DFA::from_bytes(<span class="kw-2">&</span>buf.bytes[..written])<span class="question-mark">?</span>.<span class="number">0</span>;
|
||
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">8</span>));
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345"</span>))<span class="question-mark">?</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.write_to_len" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#2150-2162">Source</a><h4 class="code-header">pub fn <a href="#method.write_to_len" class="fn">write_to_len</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Return the total number of bytes required to serialize this DFA.</p>
|
||
<p>This is useful for determining the size of the buffer required to pass
|
||
to one of the serialization routines:</p>
|
||
<ul>
|
||
<li><a href="struct.DFA.html#method.write_to_little_endian" title="method regex_automata::dfa::dense::DFA::write_to_little_endian"><code>DFA::write_to_little_endian</code></a></li>
|
||
<li><a href="struct.DFA.html#method.write_to_big_endian" title="method regex_automata::dfa::dense::DFA::write_to_big_endian"><code>DFA::write_to_big_endian</code></a></li>
|
||
<li><a href="struct.DFA.html#method.write_to_native_endian" title="method regex_automata::dfa::dense::DFA::write_to_native_endian"><code>DFA::write_to_native_endian</code></a></li>
|
||
</ul>
|
||
<p>Passing a buffer smaller than the size returned by this method will
|
||
result in a serialization error. Serialization routines are guaranteed
|
||
to succeed when the buffer is big enough.</p>
|
||
<h5 id="example-11"><a class="doc-anchor" href="#example-11">§</a>Example</h5>
|
||
<p>This example shows how to dynamically allocate enough room to serialize
|
||
a DFA.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense::DFA}, HalfMatch, Input};
|
||
|
||
<span class="kw">let </span>original_dfa = DFA::new(<span class="string">"foo[0-9]+"</span>)<span class="question-mark">?</span>;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>buf = <span class="macro">vec!</span>[<span class="number">0</span>; original_dfa.write_to_len()];
|
||
<span class="comment">// This is guaranteed to succeed, because the only serialization error
|
||
// that can occur is when the provided buffer is too small. But
|
||
// write_to_len guarantees a correct size.
|
||
</span><span class="kw">let </span>written = original_dfa.write_to_native_endian(<span class="kw-2">&mut </span>buf).unwrap();
|
||
<span class="comment">// But this is not guaranteed to succeed! In particular,
|
||
// deserialization requires proper alignment for &[u32], but our buffer
|
||
// was allocated as a &[u8] whose required alignment is smaller than
|
||
// &[u32]. However, it's likely to work in practice because of how most
|
||
// allocators work. So if you write code like this, make sure to either
|
||
// handle the error correctly and/or run it under Miri since Miri will
|
||
// likely provoke the error by returning Vec<u8> buffers with alignment
|
||
// less than &[u32].
|
||
</span><span class="kw">let </span>dfa: DFA<<span class="kw-2">&</span>[u32]> = <span class="kw">match </span>DFA::from_bytes(<span class="kw-2">&</span>buf[..written]) {
|
||
<span class="comment">// As mentioned above, it is legal for an error to be returned
|
||
// here. It is quite difficult to get a Vec<u8> with a guaranteed
|
||
// alignment equivalent to Vec<u32>.
|
||
</span><span class="prelude-val">Err</span>(<span class="kw">_</span>) => <span class="kw">return </span><span class="prelude-val">Ok</span>(()),
|
||
<span class="prelude-val">Ok</span>((dfa, <span class="kw">_</span>)) => dfa,
|
||
};
|
||
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">8</span>));
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345"</span>))<span class="question-mark">?</span>);</code></pre></div>
|
||
<p>Note that this example isn’t actually guaranteed to work! In
|
||
particular, if <code>buf</code> is not aligned to a 4-byte boundary, then the
|
||
<code>DFA::from_bytes</code> call will fail. If you need this to work, then you
|
||
either need to deal with adding some initial padding yourself, or use
|
||
one of the <code>to_bytes</code> methods, which will do it for you.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-DFA%3C%26%5Bu32%5D%3E-1" class="impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#2165-2481">Source</a><a href="#impl-DFA%3C%26%5Bu32%5D%3E-1" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><&'a [<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>]></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from_bytes" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#2340-2379">Source</a><h4 class="code-header">pub fn <a href="#method.from_bytes" class="fn">from_bytes</a>(
|
||
slice: &'a [<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>],
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><(<a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><&'a [<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>]>, <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>), <a class="struct" href="../../util/wire/struct.DeserializeError.html" title="struct regex_automata::util::wire::DeserializeError">DeserializeError</a>></h4></section></summary><div class="docblock"><p>Safely deserialize a DFA with a specific state identifier
|
||
representation. Upon success, this returns both the deserialized DFA
|
||
and the number of bytes read from the given slice. Namely, the contents
|
||
of the slice beyond the DFA are not read.</p>
|
||
<p>Deserializing a DFA using this routine will never allocate heap memory.
|
||
For safety purposes, the DFA’s transition table will be verified such
|
||
that every transition points to a valid state. If this verification is
|
||
too costly, then a <a href="struct.DFA.html#method.from_bytes_unchecked" title="associated function regex_automata::dfa::dense::DFA::from_bytes_unchecked"><code>DFA::from_bytes_unchecked</code></a> API is provided, which
|
||
will always execute in constant time.</p>
|
||
<p>The bytes given must be generated by one of the serialization APIs
|
||
of a <code>DFA</code> using a semver compatible release of this crate. Those
|
||
include:</p>
|
||
<ul>
|
||
<li><a href="struct.DFA.html#method.to_bytes_little_endian" title="method regex_automata::dfa::dense::DFA::to_bytes_little_endian"><code>DFA::to_bytes_little_endian</code></a></li>
|
||
<li><a href="struct.DFA.html#method.to_bytes_big_endian" title="method regex_automata::dfa::dense::DFA::to_bytes_big_endian"><code>DFA::to_bytes_big_endian</code></a></li>
|
||
<li><a href="struct.DFA.html#method.to_bytes_native_endian" title="method regex_automata::dfa::dense::DFA::to_bytes_native_endian"><code>DFA::to_bytes_native_endian</code></a></li>
|
||
<li><a href="struct.DFA.html#method.write_to_little_endian" title="method regex_automata::dfa::dense::DFA::write_to_little_endian"><code>DFA::write_to_little_endian</code></a></li>
|
||
<li><a href="struct.DFA.html#method.write_to_big_endian" title="method regex_automata::dfa::dense::DFA::write_to_big_endian"><code>DFA::write_to_big_endian</code></a></li>
|
||
<li><a href="struct.DFA.html#method.write_to_native_endian" title="method regex_automata::dfa::dense::DFA::write_to_native_endian"><code>DFA::write_to_native_endian</code></a></li>
|
||
</ul>
|
||
<p>The <code>to_bytes</code> methods allocate and return a <code>Vec<u8></code> for you, along
|
||
with handling alignment correctly. The <code>write_to</code> methods do not
|
||
allocate and write to an existing slice (which may be on the stack).
|
||
Since deserialization always uses the native endianness of the target
|
||
platform, the serialization API you use should match the endianness of
|
||
the target platform. (It’s often a good idea to generate serialized
|
||
DFAs for both forms of endianness and then load the correct one based
|
||
on endianness.)</p>
|
||
<h5 id="errors-3"><a class="doc-anchor" href="#errors-3">§</a>Errors</h5>
|
||
<p>Generally speaking, it’s easier to state the conditions in which an
|
||
error is <em>not</em> returned. All of the following must be true:</p>
|
||
<ul>
|
||
<li>The bytes given must be produced by one of the serialization APIs
|
||
on this DFA, as mentioned above.</li>
|
||
<li>The endianness of the target platform matches the endianness used to
|
||
serialized the provided DFA.</li>
|
||
<li>The slice given must have the same alignment as <code>u32</code>.</li>
|
||
</ul>
|
||
<p>If any of the above are not true, then an error will be returned.</p>
|
||
<h5 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h5>
|
||
<p>This routine will never panic for any input.</p>
|
||
<h5 id="example-12"><a class="doc-anchor" href="#example-12">§</a>Example</h5>
|
||
<p>This example shows how to serialize a DFA to raw bytes, deserialize it
|
||
and then use it for searching.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense::DFA}, HalfMatch, Input};
|
||
|
||
<span class="kw">let </span>initial = DFA::new(<span class="string">"foo[0-9]+"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>(bytes, <span class="kw">_</span>) = initial.to_bytes_native_endian();
|
||
<span class="kw">let </span>dfa: DFA<<span class="kw-2">&</span>[u32]> = DFA::from_bytes(<span class="kw-2">&</span>bytes)<span class="question-mark">?</span>.<span class="number">0</span>;
|
||
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">8</span>));
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345"</span>))<span class="question-mark">?</span>);</code></pre></div><h5 id="example-dealing-with-alignment-and-padding"><a class="doc-anchor" href="#example-dealing-with-alignment-and-padding">§</a>Example: dealing with alignment and padding</h5>
|
||
<p>In the above example, we used the <code>to_bytes_native_endian</code> method to
|
||
serialize a DFA, but we ignored part of its return value corresponding
|
||
to padding added to the beginning of the serialized DFA. This is OK
|
||
because deserialization will skip this initial padding. What matters
|
||
is that the address immediately following the padding has an alignment
|
||
that matches <code>u32</code>. That is, the following is an equivalent but
|
||
alternative way to write the above example:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense::DFA}, HalfMatch, Input};
|
||
|
||
<span class="kw">let </span>initial = DFA::new(<span class="string">"foo[0-9]+"</span>)<span class="question-mark">?</span>;
|
||
<span class="comment">// Serialization returns the number of leading padding bytes added to
|
||
// the returned Vec<u8>.
|
||
</span><span class="kw">let </span>(bytes, pad) = initial.to_bytes_native_endian();
|
||
<span class="kw">let </span>dfa: DFA<<span class="kw-2">&</span>[u32]> = DFA::from_bytes(<span class="kw-2">&</span>bytes[pad..])<span class="question-mark">?</span>.<span class="number">0</span>;
|
||
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">8</span>));
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345"</span>))<span class="question-mark">?</span>);</code></pre></div>
|
||
<p>This padding is necessary because Rust’s standard library does
|
||
not expose any safe and robust way of creating a <code>Vec<u8></code> with a
|
||
guaranteed alignment other than 1. Now, in practice, the underlying
|
||
allocator is likely to provide a <code>Vec<u8></code> that meets our alignment
|
||
requirements, which means <code>pad</code> is zero in practice most of the time.</p>
|
||
<p>The purpose of exposing the padding like this is flexibility for the
|
||
caller. For example, if one wants to embed a serialized DFA into a
|
||
compiled program, then it’s important to guarantee that it starts at a
|
||
<code>u32</code>-aligned address. The simplest way to do this is to discard the
|
||
padding bytes and set it up so that the serialized DFA itself begins at
|
||
a properly aligned address. We can show this in two parts. The first
|
||
part is serializing the DFA to a file:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::dfa::dense::DFA;
|
||
|
||
<span class="kw">let </span>dfa = DFA::new(<span class="string">"foo[0-9]+"</span>)<span class="question-mark">?</span>;
|
||
|
||
<span class="kw">let </span>(bytes, pad) = dfa.to_bytes_big_endian();
|
||
<span class="comment">// Write the contents of the DFA *without* the initial padding.
|
||
</span>std::fs::write(<span class="string">"foo.bigendian.dfa"</span>, <span class="kw-2">&</span>bytes[pad..])<span class="question-mark">?</span>;
|
||
|
||
<span class="comment">// Do it again, but this time for little endian.
|
||
</span><span class="kw">let </span>(bytes, pad) = dfa.to_bytes_little_endian();
|
||
std::fs::write(<span class="string">"foo.littleendian.dfa"</span>, <span class="kw-2">&</span>bytes[pad..])<span class="question-mark">?</span>;</code></pre></div>
|
||
<p>And now the second part is embedding the DFA into the compiled program
|
||
and deserializing it at runtime on first use. We use conditional
|
||
compilation to choose the correct endianness.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{
|
||
dfa::{Automaton, dense::DFA},
|
||
util::{lazy::Lazy, wire::AlignAs},
|
||
HalfMatch, Input,
|
||
};
|
||
|
||
<span class="comment">// This crate provides its own "lazy" type, kind of like
|
||
// lazy_static! or once_cell::sync::Lazy. But it works in no-alloc
|
||
// no-std environments and let's us write this using completely
|
||
// safe code.
|
||
</span><span class="kw">static </span>RE: Lazy<DFA<<span class="kw-2">&</span><span class="lifetime">'static </span>[u32]>> = Lazy::new(|| {
|
||
<span class="comment">// This assignment is made possible (implicitly) via the
|
||
// CoerceUnsized trait. This is what guarantees that our
|
||
// bytes are stored in memory on a 4 byte boundary. You
|
||
// *must* do this or something equivalent for correct
|
||
// deserialization.
|
||
</span><span class="kw">static </span>ALIGNED: <span class="kw-2">&</span>AlignAs<[u8], u32> = <span class="kw-2">&</span>AlignAs {
|
||
_align: [],
|
||
<span class="attr">#[cfg(target_endian = <span class="string">"big"</span>)]
|
||
</span>bytes: <span class="kw-2">*</span><span class="macro">include_bytes!</span>(<span class="string">"foo.bigendian.dfa"</span>),
|
||
<span class="attr">#[cfg(target_endian = <span class="string">"little"</span>)]
|
||
</span>bytes: <span class="kw-2">*</span><span class="macro">include_bytes!</span>(<span class="string">"foo.littleendian.dfa"</span>),
|
||
};
|
||
|
||
<span class="kw">let </span>(dfa, <span class="kw">_</span>) = DFA::from_bytes(<span class="kw-2">&</span>ALIGNED.bytes)
|
||
.expect(<span class="string">"serialized DFA should be valid"</span>);
|
||
dfa
|
||
});
|
||
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">8</span>)));
|
||
<span class="macro">assert_eq!</span>(expected, RE.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345"</span>)));</code></pre></div>
|
||
<p>An alternative to <a href="../../util/lazy/struct.Lazy.html" title="struct regex_automata::util::lazy::Lazy"><code>util::lazy::Lazy</code></a>
|
||
is <a href="https://crates.io/crates/lazy_static"><code>lazy_static</code></a> or
|
||
<a href="https://crates.io/crates/once_cell"><code>once_cell</code></a>, which provide
|
||
stronger guarantees (like the initialization function only being
|
||
executed once). And <code>once_cell</code> in particular provides a more
|
||
expressive API. But a <code>Lazy</code> value from this crate is likely just fine
|
||
in most circumstances.</p>
|
||
<p>Note that regardless of which initialization method you use, you
|
||
will still need to use the <a href="../../util/wire/struct.AlignAs.html" title="struct regex_automata::util::wire::AlignAs"><code>AlignAs</code></a>
|
||
trick above to force correct alignment, but this is safe to do and
|
||
<code>from_bytes</code> will return an error if you get it wrong.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_bytes_unchecked" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#2408-2447">Source</a><h4 class="code-header">pub unsafe fn <a href="#method.from_bytes_unchecked" class="fn">from_bytes_unchecked</a>(
|
||
slice: &'a [<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>],
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><(<a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><&'a [<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>]>, <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>), <a class="struct" href="../../util/wire/struct.DeserializeError.html" title="struct regex_automata::util::wire::DeserializeError">DeserializeError</a>></h4></section></summary><div class="docblock"><p>Deserialize a DFA with a specific state identifier representation in
|
||
constant time by omitting the verification of the validity of the
|
||
transition table and other data inside the DFA.</p>
|
||
<p>This is just like <a href="struct.DFA.html#method.from_bytes" title="associated function regex_automata::dfa::dense::DFA::from_bytes"><code>DFA::from_bytes</code></a>, except it can potentially return
|
||
a DFA that exhibits undefined behavior if its transition table contains
|
||
invalid state identifiers.</p>
|
||
<p>This routine is useful if you need to deserialize a DFA cheaply
|
||
and cannot afford the transition table validation performed by
|
||
<code>from_bytes</code>.</p>
|
||
<h5 id="example-13"><a class="doc-anchor" href="#example-13">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_automata::{dfa::{Automaton, dense::DFA}, HalfMatch, Input};
|
||
|
||
<span class="kw">let </span>initial = DFA::new(<span class="string">"foo[0-9]+"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>(bytes, <span class="kw">_</span>) = initial.to_bytes_native_endian();
|
||
<span class="comment">// SAFETY: This is guaranteed to be safe since the bytes given come
|
||
// directly from a compatible serialization routine.
|
||
</span><span class="kw">let </span>dfa: DFA<<span class="kw-2">&</span>[u32]> = <span class="kw">unsafe </span>{ DFA::from_bytes_unchecked(<span class="kw-2">&</span>bytes)<span class="question-mark">?</span>.<span class="number">0 </span>};
|
||
|
||
<span class="kw">let </span>expected = <span class="prelude-val">Some</span>(HalfMatch::must(<span class="number">0</span>, <span class="number">8</span>));
|
||
<span class="macro">assert_eq!</span>(expected, dfa.try_search_fwd(<span class="kw-2">&</span>Input::new(<span class="string">"foo12345"</span>))<span class="question-mark">?</span>);</code></pre></div></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-DFA%3CT%3E-2" class="impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#2484-2494">Source</a><a href="#impl-DFA%3CT%3E-2" class="anchor">§</a><h3 class="code-header">impl<T> <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><T></h3><div class="docblock"><p>Other routines that work for all <code>T</code>.</p>
|
||
</div></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.set_prefilter" class="method"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#2491-2493">Source</a><h4 class="code-header">pub fn <a href="#method.set_prefilter" class="fn">set_prefilter</a>(&mut self, prefilter: <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="../../util/prefilter/struct.Prefilter.html" title="struct regex_automata::util::prefilter::Prefilter">Prefilter</a>>)</h4></section></summary><div class="docblock"><p>Set or unset the prefilter attached to this DFA.</p>
|
||
<p>This is useful when one has deserialized a DFA from <code>&[u8]</code>.
|
||
Deserialization does not currently include prefilters, so if you
|
||
want prefilter acceleration, you’ll need to rebuild it and attach
|
||
it here.</p>
|
||
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Automaton-for-DFA%3CT%3E" class="impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3163-3302">Source</a><a href="#impl-Automaton-for-DFA%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>]>> <a class="trait" href="../trait.Automaton.html" title="trait regex_automata::dfa::Automaton">Automaton</a> for <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><T></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.is_special_state" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3165-3167">Source</a><a href="#method.is_special_state" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.is_special_state" class="fn">is_special_state</a>(&self, id: <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Returns true if and only if the given identifier corresponds to a
|
||
“special” state. A special state is one or more of the following:
|
||
a dead state, a quit state, a match state, a start state or an
|
||
accelerated state. <a href="../trait.Automaton.html#tymethod.is_special_state">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.is_dead_state" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3170-3172">Source</a><a href="#method.is_dead_state" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.is_dead_state" class="fn">is_dead_state</a>(&self, id: <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Returns true if and only if the given identifier corresponds to a dead
|
||
state. When a DFA enters a dead state, it is impossible to leave. That
|
||
is, every transition on a dead state by definition leads back to the
|
||
same dead state. <a href="../trait.Automaton.html#tymethod.is_dead_state">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.is_quit_state" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3175-3177">Source</a><a href="#method.is_quit_state" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.is_quit_state" class="fn">is_quit_state</a>(&self, id: <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Returns true if and only if the given identifier corresponds to a quit
|
||
state. A quit state is like a dead state (it has no transitions other
|
||
than to itself), except it indicates that the DFA failed to complete
|
||
the search. When this occurs, callers can neither accept or reject that
|
||
a match occurred. <a href="../trait.Automaton.html#tymethod.is_quit_state">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.is_match_state" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3180-3182">Source</a><a href="#method.is_match_state" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.is_match_state" class="fn">is_match_state</a>(&self, id: <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Returns true if and only if the given identifier corresponds to a
|
||
match state. A match state is also referred to as a “final” state and
|
||
indicates that a match has been found. <a href="../trait.Automaton.html#tymethod.is_match_state">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.is_start_state" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3185-3187">Source</a><a href="#method.is_start_state" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.is_start_state" class="fn">is_start_state</a>(&self, id: <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Returns true only if the given identifier corresponds to a start
|
||
state <a href="../trait.Automaton.html#tymethod.is_start_state">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.is_accel_state" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3190-3192">Source</a><a href="#method.is_accel_state" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.is_accel_state" class="fn">is_accel_state</a>(&self, id: <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Returns true if and only if the given identifier corresponds to an
|
||
accelerated state. <a href="../trait.Automaton.html#tymethod.is_accel_state">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.next_state" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3195-3199">Source</a><a href="#method.next_state" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.next_state" class="fn">next_state</a>(&self, current: <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>, input: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>) -> <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a></h4></section></summary><div class='docblock'>Transitions from the current state to the next state, given the next
|
||
byte of input. <a href="../trait.Automaton.html#tymethod.next_state">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.next_state_unchecked" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3202-3215">Source</a><a href="#method.next_state_unchecked" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="../trait.Automaton.html#tymethod.next_state_unchecked" class="fn">next_state_unchecked</a>(&self, current: <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>, byte: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>) -> <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a></h4></section></summary><div class='docblock'>Transitions from the current state to the next state, given the next
|
||
byte of input. <a href="../trait.Automaton.html#tymethod.next_state_unchecked">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.next_eoi_state" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3218-3222">Source</a><a href="#method.next_eoi_state" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.next_eoi_state" class="fn">next_eoi_state</a>(&self, current: <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>) -> <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a></h4></section></summary><div class='docblock'>Transitions from the current state to the next state for the special
|
||
EOI symbol. <a href="../trait.Automaton.html#tymethod.next_eoi_state">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.pattern_len" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3225-3227">Source</a><a href="#method.pattern_len" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.pattern_len" class="fn">pattern_len</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a></h4></section></summary><div class='docblock'>Returns the total number of patterns compiled into this DFA. <a href="../trait.Automaton.html#tymethod.pattern_len">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.match_len" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3230-3232">Source</a><a href="#method.match_len" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.match_len" class="fn">match_len</a>(&self, id: <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a></h4></section></summary><div class='docblock'>Returns the total number of patterns that match in this state. <a href="../trait.Automaton.html#tymethod.match_len">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.match_pattern" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3235-3246">Source</a><a href="#method.match_pattern" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.match_pattern" class="fn">match_pattern</a>(&self, id: <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>, match_index: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../struct.PatternID.html" title="struct regex_automata::PatternID">PatternID</a></h4></section></summary><div class='docblock'>Returns the pattern ID corresponding to the given match index in the
|
||
given state. <a href="../trait.Automaton.html#tymethod.match_pattern">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.has_empty" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3249-3251">Source</a><a href="#method.has_empty" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.has_empty" class="fn">has_empty</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Returns true if and only if this automaton can match the empty string.
|
||
When it returns false, all possible matches are guaranteed to have a
|
||
non-zero length. <a href="../trait.Automaton.html#tymethod.has_empty">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.is_utf8" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3254-3256">Source</a><a href="#method.is_utf8" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.is_utf8" class="fn">is_utf8</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Whether UTF-8 mode is enabled for this DFA or not. <a href="../trait.Automaton.html#tymethod.is_utf8">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.is_always_start_anchored" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3259-3261">Source</a><a href="#method.is_always_start_anchored" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.is_always_start_anchored" class="fn">is_always_start_anchored</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Returns true if and only if this DFA is limited to returning matches
|
||
whose start position is <code>0</code>. <a href="../trait.Automaton.html#tymethod.is_always_start_anchored">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.start_state" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3264-3279">Source</a><a href="#method.start_state" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#tymethod.start_state" class="fn">start_state</a>(&self, config: &<a class="struct" href="../../util/start/struct.Config.html" title="struct regex_automata::util::start::Config">Config</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>, <a class="enum" href="../enum.StartError.html" title="enum regex_automata::dfa::StartError">StartError</a>></h4></section></summary><div class='docblock'>Return the ID of the start state for this DFA for the given starting
|
||
configuration. <a href="../trait.Automaton.html#tymethod.start_state">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.universal_start_state" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3282-3288">Source</a><a href="#method.universal_start_state" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#method.universal_start_state" class="fn">universal_start_state</a>(&self, mode: <a class="enum" href="../../enum.Anchored.html" title="enum regex_automata::Anchored">Anchored</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>></h4></section></summary><div class='docblock'>If this DFA has a universal starting state for the given anchor mode
|
||
and the DFA supports universal starting states, then this returns that
|
||
state’s identifier. <a href="../trait.Automaton.html#method.universal_start_state">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.accelerator" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3291-3296">Source</a><a href="#method.accelerator" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#method.accelerator" class="fn">accelerator</a>(&self, id: <a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>) -> &[<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>] <a href="#" class="tooltip" data-notable-ty="&[u8]">ⓘ</a></h4></section></summary><div class='docblock'>Return a slice of bytes to accelerate for the given state, if possible. <a href="../trait.Automaton.html#method.accelerator">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.get_prefilter" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3299-3301">Source</a><a href="#method.get_prefilter" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#method.get_prefilter" class="fn">get_prefilter</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<a class="struct" href="../../util/prefilter/struct.Prefilter.html" title="struct regex_automata::util::prefilter::Prefilter">Prefilter</a>></h4></section></summary><div class='docblock'>Returns the prefilter associated with a DFA, if one exists. <a href="../trait.Automaton.html#method.get_prefilter">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.start_state_forward" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/automaton.rs.html#281-298">Source</a><a href="#method.start_state_forward" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#method.start_state_forward" class="fn">start_state_forward</a>(&self, input: &<a class="struct" href="../../struct.Input.html" title="struct regex_automata::Input">Input</a><'_>) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>, <a class="struct" href="../../struct.MatchError.html" title="struct regex_automata::MatchError">MatchError</a>></h4></section></summary><div class='docblock'>Return the ID of the start state for this DFA when executing a forward
|
||
search. <a href="../trait.Automaton.html#method.start_state_forward">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.start_state_reverse" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/automaton.rs.html#315-329">Source</a><a href="#method.start_state_reverse" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#method.start_state_reverse" class="fn">start_state_reverse</a>(&self, input: &<a class="struct" href="../../struct.Input.html" title="struct regex_automata::Input">Input</a><'_>) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../../util/primitives/struct.StateID.html" title="struct regex_automata::util::primitives::StateID">StateID</a>, <a class="struct" href="../../struct.MatchError.html" title="struct regex_automata::MatchError">MatchError</a>></h4></section></summary><div class='docblock'>Return the ID of the start state for this DFA when executing a reverse
|
||
search. <a href="../trait.Automaton.html#method.start_state_reverse">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.try_search_fwd" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/automaton.rs.html#1297-1325">Source</a><a href="#method.try_search_fwd" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#method.try_search_fwd" class="fn">try_search_fwd</a>(
|
||
&self,
|
||
input: &<a class="struct" href="../../struct.Input.html" title="struct regex_automata::Input">Input</a><'_>,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="https://doc.rust-lang.org/1.93.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="../../struct.HalfMatch.html" title="struct regex_automata::HalfMatch">HalfMatch</a>>, <a class="struct" href="../../struct.MatchError.html" title="struct regex_automata::MatchError">MatchError</a>></h4></section></summary><div class='docblock'>Executes a forward search and returns the end position of the leftmost
|
||
match that is found. If no match exists, then <code>None</code> is returned. <a href="../trait.Automaton.html#method.try_search_fwd">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.try_search_rev" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/automaton.rs.html#1486-1500">Source</a><a href="#method.try_search_rev" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#method.try_search_rev" class="fn">try_search_rev</a>(
|
||
&self,
|
||
input: &<a class="struct" href="../../struct.Input.html" title="struct regex_automata::Input">Input</a><'_>,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="https://doc.rust-lang.org/1.93.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="../../struct.HalfMatch.html" title="struct regex_automata::HalfMatch">HalfMatch</a>>, <a class="struct" href="../../struct.MatchError.html" title="struct regex_automata::MatchError">MatchError</a>></h4></section></summary><div class='docblock'>Executes a reverse search and returns the start of the position of the
|
||
leftmost match that is found. If no match exists, then <code>None</code> is
|
||
returned. <a href="../trait.Automaton.html#method.try_search_rev">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.try_search_overlapping_fwd" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/automaton.rs.html#1582-1600">Source</a><a href="#method.try_search_overlapping_fwd" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#method.try_search_overlapping_fwd" class="fn">try_search_overlapping_fwd</a>(
|
||
&self,
|
||
input: &<a class="struct" href="../../struct.Input.html" title="struct regex_automata::Input">Input</a><'_>,
|
||
state: &mut <a class="struct" href="../struct.OverlappingState.html" title="struct regex_automata::dfa::OverlappingState">OverlappingState</a>,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>, <a class="struct" href="../../struct.MatchError.html" title="struct regex_automata::MatchError">MatchError</a>></h4></section></summary><div class='docblock'>Executes an overlapping forward search. Matches, if one exists, can be
|
||
obtained via the <a href="../struct.OverlappingState.html#method.get_match" title="method regex_automata::dfa::OverlappingState::get_match"><code>OverlappingState::get_match</code></a> method. <a href="../trait.Automaton.html#method.try_search_overlapping_fwd">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.try_search_overlapping_rev" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/automaton.rs.html#1719-1737">Source</a><a href="#method.try_search_overlapping_rev" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#method.try_search_overlapping_rev" class="fn">try_search_overlapping_rev</a>(
|
||
&self,
|
||
input: &<a class="struct" href="../../struct.Input.html" title="struct regex_automata::Input">Input</a><'_>,
|
||
state: &mut <a class="struct" href="../struct.OverlappingState.html" title="struct regex_automata::dfa::OverlappingState">OverlappingState</a>,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>, <a class="struct" href="../../struct.MatchError.html" title="struct regex_automata::MatchError">MatchError</a>></h4></section></summary><div class='docblock'>Executes a reverse overlapping forward search. Matches, if one exists,
|
||
can be obtained via the <a href="../struct.OverlappingState.html#method.get_match" title="method regex_automata::dfa::OverlappingState::get_match"><code>OverlappingState::get_match</code></a> method. <a href="../trait.Automaton.html#method.try_search_overlapping_rev">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.try_which_overlapping_matches" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/automaton.rs.html#1808-1826">Source</a><a href="#method.try_which_overlapping_matches" class="anchor">§</a><h4 class="code-header">fn <a href="../trait.Automaton.html#method.try_which_overlapping_matches" class="fn">try_which_overlapping_matches</a>(
|
||
&self,
|
||
input: &<a class="struct" href="../../struct.Input.html" title="struct regex_automata::Input">Input</a><'_>,
|
||
patset: &mut <a class="struct" href="../../struct.PatternSet.html" title="struct regex_automata::PatternSet">PatternSet</a>,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>, <a class="struct" href="../../struct.MatchError.html" title="struct regex_automata::MatchError">MatchError</a>></h4></section></summary><div class='docblock'>Writes the set of patterns that match anywhere in the given search
|
||
configuration to <code>patset</code>. If multiple patterns match at the same
|
||
position and the underlying DFA supports overlapping matches, then all
|
||
matching patterns are written to the given set. <a href="../trait.Automaton.html#method.try_which_overlapping_matches">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Clone-for-DFA%3CT%3E" class="impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1393">Source</a><a href="#impl-Clone-for-DFA%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><T></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.clone" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#1393">Source</a><a href="#method.clone" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html#tymethod.clone" class="fn">clone</a>(&self) -> <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><T></h4></section></summary><div class='docblock'>Returns a duplicate of the value. <a href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html#tymethod.clone">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.clone_from" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.93.1/src/core/clone.rs.html#245-247">Source</a></span><a href="#method.clone_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html#method.clone_from" class="fn">clone_from</a>(&mut self, source: &Self)</h4></section></summary><div class='docblock'>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html#method.clone_from">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-DFA%3CT%3E" class="impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3102-3160">Source</a><a href="#impl-Debug-for-DFA%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>]>> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><T></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><a class="src rightside" href="../../../src/regex_automata/dfa/dense.rs.html#3103-3159">Source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/1.93.1/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/1.93.1/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.93.1/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-Freeze-for-DFA%3CT%3E" class="impl"><a href="#impl-Freeze-for-DFA%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><T><div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a>,</div></h3></section><section id="impl-RefUnwindSafe-for-DFA%3CT%3E" class="impl"><a href="#impl-RefUnwindSafe-for-DFA%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><T><div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a>,</div></h3></section><section id="impl-Send-for-DFA%3CT%3E" class="impl"><a href="#impl-Send-for-DFA%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><T><div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,</div></h3></section><section id="impl-Sync-for-DFA%3CT%3E" class="impl"><a href="#impl-Sync-for-DFA%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><T><div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>,</div></h3></section><section id="impl-Unpin-for-DFA%3CT%3E" class="impl"><a href="#impl-Unpin-for-DFA%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><T><div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></h3></section><section id="impl-UnwindSafe-for-DFA%3CT%3E" class="impl"><a href="#impl-UnwindSafe-for-DFA%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.DFA.html" title="struct regex_automata::dfa::dense::DFA">DFA</a><T><div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a>,</div></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/any.rs.html#138">Source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
|
||
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/any.rs.html#139">Source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.93.1/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.93.1/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/borrow.rs.html#212">Source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/borrow.rs.html#214">Source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/borrow.rs.html#221">Source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/borrow.rs.html#222">Source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-CloneToUninit-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/clone.rs.html#547">Source</a><a href="#impl-CloneToUninit-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/clone/trait.CloneToUninit.html" title="trait core::clone::CloneToUninit">CloneToUninit</a> for T<div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.clone_to_uninit" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/clone.rs.html#549">Source</a><a href="#method.clone_to_uninit" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="https://doc.rust-lang.org/1.93.1/core/clone/trait.CloneToUninit.html#tymethod.clone_to_uninit" class="fn">clone_to_uninit</a>(&self, dest: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.pointer.html">*mut </a><a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>)</h4></section></summary><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span><span>This is a nightly-only experimental API. (<code>clone_to_uninit</code>)</span></div></span><div class='docblock'>Performs copy-assignment from <code>self</code> to <code>dest</code>. <a href="https://doc.rust-lang.org/1.93.1/core/clone/trait.CloneToUninit.html#tymethod.clone_to_uninit">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#785">Source</a><a href="#impl-From%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#788">Source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#767-769">Source</a><a href="#impl-Into%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#777">Source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.Into.html#tymethod.into" class="fn">into</a>(self) -> U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
|
||
<p>That is, this conversion is whatever the implementation of
|
||
<code><a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for U</code> chooses to do.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-ToOwned-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/alloc/borrow.rs.html#85-87">Source</a><a href="#impl-ToOwned-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/alloc/borrow/trait.ToOwned.html" title="trait alloc::borrow::ToOwned">ToOwned</a> for T<div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Owned" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/alloc/borrow.rs.html#89">Source</a><a href="#associatedtype.Owned" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.93.1/alloc/borrow/trait.ToOwned.html#associatedtype.Owned" class="associatedtype">Owned</a> = T</h4></section></summary><div class='docblock'>The resulting type after obtaining ownership.</div></details><details class="toggle method-toggle" open><summary><section id="method.to_owned-1" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/alloc/borrow.rs.html#90">Source</a><a href="#method.to_owned-1" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/alloc/borrow/trait.ToOwned.html#tymethod.to_owned" class="fn">to_owned</a>(&self) -> T</h4></section></summary><div class='docblock'>Creates owned data from borrowed data, usually by cloning. <a href="https://doc.rust-lang.org/1.93.1/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.clone_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/alloc/borrow.rs.html#94">Source</a><a href="#method.clone_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/alloc/borrow/trait.ToOwned.html#method.clone_into" class="fn">clone_into</a>(&self, target: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&mut T</a>)</h4></section></summary><div class='docblock'>Uses borrowed data to replace owned data, usually by cloning. <a href="https://doc.rust-lang.org/1.93.1/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#827-829">Source</a><a href="#impl-TryFrom%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#831">Source</a><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#834">Source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#811-813">Source</a><a href="#impl-TryInto%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#815">Source</a><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#818">Source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div><script type="text/json" id="notable-traits-data">{"&[u8]":"<h3>Notable traits for <code>&[<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.93.1/std/primitive.u8.html\">u8</a>]</code></h3><pre><code><div class=\"where\">impl <a class=\"trait\" href=\"https://doc.rust-lang.org/1.93.1/std/io/trait.Read.html\" title=\"trait std::io::Read\">Read</a> for &[<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.93.1/std/primitive.u8.html\">u8</a>]</div>"}</script></section></div></main></body></html> |