mirror of
https://github.com/edg-l/edlang.git
synced 2024-11-23 16:38:24 +00:00
221 lines
45 KiB
HTML
221 lines
45 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="Extracts prefix or suffix literal sequences from `Hir` expressions."><title>Extractor in regex_syntax::hir::literal - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="regex_syntax" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-2c020d218678b618.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]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../regex_syntax/index.html">regex_syntax</a><span class="version">0.8.2</span></h2></div><h2 class="location"><a href="#">Extractor</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.extract">extract</a></li><li><a href="#method.kind">kind</a></li><li><a href="#method.limit_class">limit_class</a></li><li><a href="#method.limit_literal_len">limit_literal_len</a></li><li><a href="#method.limit_repeat">limit_repeat</a></li><li><a href="#method.limit_total">limit_total</a></li><li><a href="#method.new">new</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Clone-for-Extractor">Clone</a></li><li><a href="#impl-Debug-for-Extractor">Debug</a></li><li><a href="#impl-Default-for-Extractor">Default</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-RefUnwindSafe-for-Extractor">RefUnwindSafe</a></li><li><a href="#impl-Send-for-Extractor">Send</a></li><li><a href="#impl-Sync-for-Extractor">Sync</a></li><li><a href="#impl-Unpin-for-Extractor">Unpin</a></li><li><a href="#impl-UnwindSafe-for-Extractor">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">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-T">From<T></a></li><li><a
|
|||
|
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../../../regex_syntax/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../../../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Struct <a href="../../index.html">regex_syntax</a>::<wbr><a href="../index.html">hir</a>::<wbr><a href="index.html">literal</a>::<wbr><a class="struct" href="#">Extractor</a><button id="copy-path" title="Copy item path to clipboard"><img src="../../../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../../../src/regex_syntax/hir/literal.rs.html#147-153">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub struct Extractor { <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>Extracts prefix or suffix literal sequences from <a href="../struct.Hir.html" title="struct regex_syntax::hir::Hir"><code>Hir</code></a> expressions.</p>
|
|||
|
<p>Literal extraction is based on the following observations:</p>
|
|||
|
<ul>
|
|||
|
<li>Many regexes start with one or a small number of literals.</li>
|
|||
|
<li>Substring search for literals is often much faster (sometimes by an order
|
|||
|
of magnitude) than a regex search.</li>
|
|||
|
</ul>
|
|||
|
<p>Thus, in many cases, one can search for literals to find candidate starting
|
|||
|
locations of a match, and then only run the full regex engine at each such
|
|||
|
location instead of over the full haystack.</p>
|
|||
|
<p>The main downside of literal extraction is that it can wind up causing a
|
|||
|
search to be slower overall. For example, if there are many matches or if
|
|||
|
there are many candidates that don’t ultimately lead to a match, then a
|
|||
|
lot of overhead will be spent in shuffing back-and-forth between substring
|
|||
|
search and the regex engine. This is the fundamental reason why literal
|
|||
|
optimizations for regex patterns is sometimes considered a “black art.”</p>
|
|||
|
<h2 id="look-around-assertions"><a href="#look-around-assertions">Look-around assertions</a></h2>
|
|||
|
<p>Literal extraction treats all look-around assertions as-if they match every
|
|||
|
empty string. So for example, the regex <code>\bquux\b</code> will yield a sequence
|
|||
|
containing a single exact literal <code>quux</code>. However, not all occurrences
|
|||
|
of <code>quux</code> correspond to a match a of the regex. For example, <code>\bquux\b</code>
|
|||
|
does not match <code>ZquuxZ</code> anywhere because <code>quux</code> does not fall on a word
|
|||
|
boundary.</p>
|
|||
|
<p>In effect, if your regex contains look-around assertions, then a match of
|
|||
|
an exact literal does not necessarily mean the regex overall matches. So
|
|||
|
you may still need to run the regex engine in such cases to confirm the
|
|||
|
match.</p>
|
|||
|
<p>The precise guarantee you get from a literal sequence is: if every literal
|
|||
|
in the sequence is exact and the original regex contains zero look-around
|
|||
|
assertions, then a preference-order multi-substring search of those
|
|||
|
literals will precisely match a preference-order search of the original
|
|||
|
regex.</p>
|
|||
|
<h2 id="example"><a href="#example">Example</a></h2>
|
|||
|
<p>This shows how to extract prefixes:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_syntax::{hir::literal::{Extractor, Literal, Seq}, parse};
|
|||
|
|
|||
|
<span class="kw">let </span>hir = parse(<span class="string">r"(a|b|c)(x|y|z)[A-Z]+foo"</span>)<span class="question-mark">?</span>;
|
|||
|
<span class="kw">let </span>got = Extractor::new().extract(<span class="kw-2">&</span>hir);
|
|||
|
<span class="comment">// All literals returned are "inexact" because none of them reach the
|
|||
|
// match state.
|
|||
|
</span><span class="kw">let </span>expected = Seq::from_iter([
|
|||
|
Literal::inexact(<span class="string">"ax"</span>),
|
|||
|
Literal::inexact(<span class="string">"ay"</span>),
|
|||
|
Literal::inexact(<span class="string">"az"</span>),
|
|||
|
Literal::inexact(<span class="string">"bx"</span>),
|
|||
|
Literal::inexact(<span class="string">"by"</span>),
|
|||
|
Literal::inexact(<span class="string">"bz"</span>),
|
|||
|
Literal::inexact(<span class="string">"cx"</span>),
|
|||
|
Literal::inexact(<span class="string">"cy"</span>),
|
|||
|
Literal::inexact(<span class="string">"cz"</span>),
|
|||
|
]);
|
|||
|
<span class="macro">assert_eq!</span>(expected, got);
|
|||
|
</code></pre></div>
|
|||
|
<p>This shows how to extract suffixes:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_syntax::{
|
|||
|
hir::literal::{Extractor, ExtractKind, Literal, Seq},
|
|||
|
parse,
|
|||
|
};
|
|||
|
|
|||
|
<span class="kw">let </span>hir = parse(<span class="string">r"foo|[A-Z]+bar"</span>)<span class="question-mark">?</span>;
|
|||
|
<span class="kw">let </span>got = Extractor::new().kind(ExtractKind::Suffix).extract(<span class="kw-2">&</span>hir);
|
|||
|
<span class="comment">// Since 'foo' gets to a match state, it is considered exact. But 'bar'
|
|||
|
// does not because of the '[A-Z]+', and thus is marked inexact.
|
|||
|
</span><span class="kw">let </span>expected = Seq::from_iter([
|
|||
|
Literal::exact(<span class="string">"foo"</span>),
|
|||
|
Literal::inexact(<span class="string">"bar"</span>),
|
|||
|
]);
|
|||
|
<span class="macro">assert_eq!</span>(expected, got);
|
|||
|
</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-Extractor" class="impl"><a class="src rightside" href="../../../src/regex_syntax/hir/literal.rs.html#155-627">source</a><a href="#impl-Extractor" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.Extractor.html" title="struct regex_syntax::hir::literal::Extractor">Extractor</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_syntax/hir/literal.rs.html#160-168">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>() -> <a class="struct" href="struct.Extractor.html" title="struct regex_syntax::hir::literal::Extractor">Extractor</a></h4></section></summary><div class="docblock"><p>Create a new extractor with a default configuration.</p>
|
|||
|
<p>The extractor can be optionally configured before calling
|
|||
|
<a href="struct.Extractor.html#method.extract" title="method regex_syntax::hir::literal::Extractor::extract"><code>Extractor::extract</code></a> to get a literal sequence.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.extract" class="method"><a class="src rightside" href="../../../src/regex_syntax/hir/literal.rs.html#171-199">source</a><h4 class="code-header">pub fn <a href="#method.extract" class="fn">extract</a>(&self, hir: &<a class="struct" href="../struct.Hir.html" title="struct regex_syntax::hir::Hir">Hir</a>) -> <a class="struct" href="struct.Seq.html" title="struct regex_syntax::hir::literal::Seq">Seq</a></h4></section></summary><div class="docblock"><p>Execute the extractor and return a sequence of literals.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.kind" class="method"><a class="src rightside" href="../../../src/regex_syntax/hir/literal.rs.html#220-223">source</a><h4 class="code-header">pub fn <a href="#method.kind" class="fn">kind</a>(&mut self, kind: <a class="enum" href="enum.ExtractKind.html" title="enum regex_syntax::hir::literal::ExtractKind">ExtractKind</a>) -> &mut <a class="struct" href="struct.Extractor.html" title="struct regex_syntax::hir::literal::Extractor">Extractor</a></h4></section></summary><div class="docblock"><p>Set the kind of literal sequence to extract from an <a href="../struct.Hir.html" title="struct regex_syntax::hir::Hir"><code>Hir</code></a> expression.</p>
|
|||
|
<p>The default is to extract prefixes, but suffixes can be selected
|
|||
|
instead. The contract for prefixes is that every match of the
|
|||
|
corresponding <code>Hir</code> must start with one of the literals in the sequence
|
|||
|
returned. Moreover, the <em>order</em> of the sequence returned corresponds to
|
|||
|
the preference order.</p>
|
|||
|
<p>Suffixes satisfy a similar contract in that every match of the
|
|||
|
corresponding <code>Hir</code> must end with one of the literals in the sequence
|
|||
|
returned. However, there is no guarantee that the literals are in
|
|||
|
preference order.</p>
|
|||
|
<p>Remember that a sequence can be infinite. For example, unless the
|
|||
|
limits are configured to be impractically large, attempting to extract
|
|||
|
prefixes (or suffixes) for the pattern <code>[A-Z]</code> will return an infinite
|
|||
|
sequence. Generally speaking, if the sequence returned is infinite,
|
|||
|
then it is presumed to be unwise to do prefix (or suffix) optimizations
|
|||
|
for the pattern.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.limit_class" class="method"><a class="src rightside" href="../../../src/regex_syntax/hir/literal.rs.html#255-258">source</a><h4 class="code-header">pub fn <a href="#method.limit_class" class="fn">limit_class</a>(&mut self, limit: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> &mut <a class="struct" href="struct.Extractor.html" title="struct regex_syntax::hir::literal::Extractor">Extractor</a></h4></section></summary><div class="docblock"><p>Configure a limit on the length of the sequence that is permitted for
|
|||
|
a character class. If a character class exceeds this limit, then the
|
|||
|
sequence returned for it is infinite.</p>
|
|||
|
<p>This prevents classes like <code>[A-Z]</code> or <code>\pL</code> from getting turned into
|
|||
|
huge and likely unproductive sequences of literals.</p>
|
|||
|
<h5 id="example-1"><a href="#example-1">Example</a></h5>
|
|||
|
<p>This example shows how this limit can be lowered to decrease the tolerance
|
|||
|
for character classes being turned into literal sequences.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_syntax::{hir::literal::{Extractor, Seq}, parse};
|
|||
|
|
|||
|
<span class="kw">let </span>hir = parse(<span class="string">r"[0-9]"</span>)<span class="question-mark">?</span>;
|
|||
|
|
|||
|
<span class="kw">let </span>got = Extractor::new().extract(<span class="kw-2">&</span>hir);
|
|||
|
<span class="kw">let </span>expected = Seq::new([
|
|||
|
<span class="string">"0"</span>, <span class="string">"1"</span>, <span class="string">"2"</span>, <span class="string">"3"</span>, <span class="string">"4"</span>, <span class="string">"5"</span>, <span class="string">"6"</span>, <span class="string">"7"</span>, <span class="string">"8"</span>, <span class="string">"9"</span>,
|
|||
|
]);
|
|||
|
<span class="macro">assert_eq!</span>(expected, got);
|
|||
|
|
|||
|
<span class="comment">// Now let's shrink the limit and see how that changes things.
|
|||
|
</span><span class="kw">let </span>got = Extractor::new().limit_class(<span class="number">4</span>).extract(<span class="kw-2">&</span>hir);
|
|||
|
<span class="kw">let </span>expected = Seq::infinite();
|
|||
|
<span class="macro">assert_eq!</span>(expected, got);
|
|||
|
</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.limit_repeat" class="method"><a class="src rightside" href="../../../src/regex_syntax/hir/literal.rs.html#292-295">source</a><h4 class="code-header">pub fn <a href="#method.limit_repeat" class="fn">limit_repeat</a>(&mut self, limit: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> &mut <a class="struct" href="struct.Extractor.html" title="struct regex_syntax::hir::literal::Extractor">Extractor</a></h4></section></summary><div class="docblock"><p>Configure a limit on the total number of repetitions that is permitted
|
|||
|
before literal extraction is stopped.</p>
|
|||
|
<p>This is useful for limiting things like <code>(abcde){50}</code>, or more
|
|||
|
insidiously, <code>(?:){1000000000}</code>. This limit prevents any one single
|
|||
|
repetition from adding too much to a literal sequence.</p>
|
|||
|
<p>With this limit set, repetitions that exceed it will be stopped and any
|
|||
|
literals extracted up to that point will be made inexact.</p>
|
|||
|
<h5 id="example-2"><a href="#example-2">Example</a></h5>
|
|||
|
<p>This shows how to decrease the limit and compares it with the default.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_syntax::{hir::literal::{Extractor, Literal, Seq}, parse};
|
|||
|
|
|||
|
<span class="kw">let </span>hir = parse(<span class="string">r"(abc){8}"</span>)<span class="question-mark">?</span>;
|
|||
|
|
|||
|
<span class="kw">let </span>got = Extractor::new().extract(<span class="kw-2">&</span>hir);
|
|||
|
<span class="kw">let </span>expected = Seq::new([<span class="string">"abcabcabcabcabcabcabcabc"</span>]);
|
|||
|
<span class="macro">assert_eq!</span>(expected, got);
|
|||
|
|
|||
|
<span class="comment">// Now let's shrink the limit and see how that changes things.
|
|||
|
</span><span class="kw">let </span>got = Extractor::new().limit_repeat(<span class="number">4</span>).extract(<span class="kw-2">&</span>hir);
|
|||
|
<span class="kw">let </span>expected = Seq::from_iter([
|
|||
|
Literal::inexact(<span class="string">"abcabcabcabc"</span>),
|
|||
|
]);
|
|||
|
<span class="macro">assert_eq!</span>(expected, got);
|
|||
|
</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.limit_literal_len" class="method"><a class="src rightside" href="../../../src/regex_syntax/hir/literal.rs.html#329-332">source</a><h4 class="code-header">pub fn <a href="#method.limit_literal_len" class="fn">limit_literal_len</a>(&mut self, limit: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> &mut <a class="struct" href="struct.Extractor.html" title="struct regex_syntax::hir::literal::Extractor">Extractor</a></h4></section></summary><div class="docblock"><p>Configure a limit on the maximum length of any literal in a sequence.</p>
|
|||
|
<p>This is useful for limiting things like <code>(abcde){5}{5}{5}{5}</code>. While
|
|||
|
each repetition or literal in that regex is small, when all the
|
|||
|
repetitions are applied, one ends up with a literal of length <code>5^4 = 625</code>.</p>
|
|||
|
<p>With this limit set, literals that exceed it will be made inexact and
|
|||
|
thus prevented from growing.</p>
|
|||
|
<h5 id="example-3"><a href="#example-3">Example</a></h5>
|
|||
|
<p>This shows how to decrease the limit and compares it with the default.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_syntax::{hir::literal::{Extractor, Literal, Seq}, parse};
|
|||
|
|
|||
|
<span class="kw">let </span>hir = parse(<span class="string">r"(abc){2}{2}{2}"</span>)<span class="question-mark">?</span>;
|
|||
|
|
|||
|
<span class="kw">let </span>got = Extractor::new().extract(<span class="kw-2">&</span>hir);
|
|||
|
<span class="kw">let </span>expected = Seq::new([<span class="string">"abcabcabcabcabcabcabcabc"</span>]);
|
|||
|
<span class="macro">assert_eq!</span>(expected, got);
|
|||
|
|
|||
|
<span class="comment">// Now let's shrink the limit and see how that changes things.
|
|||
|
</span><span class="kw">let </span>got = Extractor::new().limit_literal_len(<span class="number">14</span>).extract(<span class="kw-2">&</span>hir);
|
|||
|
<span class="kw">let </span>expected = Seq::from_iter([
|
|||
|
Literal::inexact(<span class="string">"abcabcabcabcab"</span>),
|
|||
|
]);
|
|||
|
<span class="macro">assert_eq!</span>(expected, got);
|
|||
|
</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.limit_total" class="method"><a class="src rightside" href="../../../src/regex_syntax/hir/literal.rs.html#385-388">source</a><h4 class="code-header">pub fn <a href="#method.limit_total" class="fn">limit_total</a>(&mut self, limit: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> &mut <a class="struct" href="struct.Extractor.html" title="struct regex_syntax::hir::literal::Extractor">Extractor</a></h4></section></summary><div class="docblock"><p>Configure a limit on the total number of literals that will be
|
|||
|
returned.</p>
|
|||
|
<p>This is useful as a practical measure for avoiding the creation of
|
|||
|
large sequences of literals. While the extractor will automatically
|
|||
|
handle local creations of large sequences (for example, <code>[A-Z]</code> yields
|
|||
|
an infinite sequence by default), large sequences can be created
|
|||
|
through non-local means as well.</p>
|
|||
|
<p>For example, <code>[ab]{3}{3}</code> would yield a sequence of length <code>512 = 2^9</code>
|
|||
|
despite each of the repetitions being small on their own. This limit
|
|||
|
thus represents a “catch all” for avoiding locally small sequences from
|
|||
|
combining into large sequences.</p>
|
|||
|
<h5 id="example-4"><a href="#example-4">Example</a></h5>
|
|||
|
<p>This example shows how reducing the limit will change the literal
|
|||
|
sequence returned.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex_syntax::{hir::literal::{Extractor, Literal, Seq}, parse};
|
|||
|
|
|||
|
<span class="kw">let </span>hir = parse(<span class="string">r"[ab]{2}{2}"</span>)<span class="question-mark">?</span>;
|
|||
|
|
|||
|
<span class="kw">let </span>got = Extractor::new().extract(<span class="kw-2">&</span>hir);
|
|||
|
<span class="kw">let </span>expected = Seq::new([
|
|||
|
<span class="string">"aaaa"</span>, <span class="string">"aaab"</span>, <span class="string">"aaba"</span>, <span class="string">"aabb"</span>,
|
|||
|
<span class="string">"abaa"</span>, <span class="string">"abab"</span>, <span class="string">"abba"</span>, <span class="string">"abbb"</span>,
|
|||
|
<span class="string">"baaa"</span>, <span class="string">"baab"</span>, <span class="string">"baba"</span>, <span class="string">"babb"</span>,
|
|||
|
<span class="string">"bbaa"</span>, <span class="string">"bbab"</span>, <span class="string">"bbba"</span>, <span class="string">"bbbb"</span>,
|
|||
|
]);
|
|||
|
<span class="macro">assert_eq!</span>(expected, got);
|
|||
|
|
|||
|
<span class="comment">// The default limit is not too big, but big enough to extract all
|
|||
|
// literals from '[ab]{2}{2}'. If we shrink the limit to less than 16,
|
|||
|
// then we'll get a truncated set. Notice that it returns a sequence of
|
|||
|
// length 4 even though our limit was 10. This is because the sequence
|
|||
|
// is difficult to increase without blowing the limit. Notice also
|
|||
|
// that every literal in the sequence is now inexact because they were
|
|||
|
// stripped of some suffix.
|
|||
|
</span><span class="kw">let </span>got = Extractor::new().limit_total(<span class="number">10</span>).extract(<span class="kw-2">&</span>hir);
|
|||
|
<span class="kw">let </span>expected = Seq::from_iter([
|
|||
|
Literal::inexact(<span class="string">"aa"</span>),
|
|||
|
Literal::inexact(<span class="string">"ab"</span>),
|
|||
|
Literal::inexact(<span class="string">"ba"</span>),
|
|||
|
Literal::inexact(<span class="string">"bb"</span>),
|
|||
|
]);
|
|||
|
<span class="macro">assert_eq!</span>(expected, got);
|
|||
|
</code></pre></div>
|
|||
|
</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-Clone-for-Extractor" class="impl"><a class="src rightside" href="../../../src/regex_syntax/hir/literal.rs.html#146">source</a><a href="#impl-Clone-for-Extractor" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="struct.Extractor.html" title="struct regex_syntax::hir::literal::Extractor">Extractor</a></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_syntax/hir/literal.rs.html#146">source</a><a href="#method.clone" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html#tymethod.clone" class="fn">clone</a>(&self) -> <a class="struct" href="struct.Extractor.html" title="struct regex_syntax::hir::literal::Extractor">Extractor</a></h4></section></summary><div class='docblock'>Returns a copy of the value. <a href="https://doc.rust-lang.org/1.76.0/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.76.0/src/core/clone.rs.html#169">source</a></span><a href="#method.clone_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html#method.clone_from" class="fn">clone_from</a>(&mut self, source: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&Self</a>)</h4></section></summary><div class='docblock'>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/1.76.0/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-Extractor" class="impl"><a class="src rightside" href="../../../src/regex_syntax/hir/literal.rs.html#146">source</a><a href="#impl-Debug-for-Extractor" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.Extractor.html" title="struct regex_syntax::hir::literal::Extractor">Extractor</a></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_syntax/hir/literal.rs.html#146">source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/1.76.0/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/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.76.0/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Default-for-Extractor" class="impl"><a class="src rightside" href="../../../src/regex_syntax/hir/literal.rs.html#629-633">source</a><a href="#impl-Default-for-Extractor" class="anchor">§</a><h3 class="code
|
|||
|
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.76.0/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.76.0/src/core/any.rs.html#141">source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/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.76.0/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.76.0/src/core/borrow.rs.html#208">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.76.0/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.76.0/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.76.0/src/core/borrow.rs.html#210">source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/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.76.0/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.76.0/src/core/borrow.rs.html#216">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.76.0/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.76.0/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.76.0/src/core/borrow.rs.html#217">source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/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.76.0/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.76.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">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.76.0/src/core/convert/mod.rs.html#763">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.76.0/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.76.0/src/core/convert/mod.rs.html#766">source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/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.76.0/src/core/convert/mod.rs.html#747-749">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.76.0/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.76.0/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.76.0/src/core/convert/mod.rs.html#756">source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/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.76.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for U</code> chooses to do.</p>
|
|||
|
</div></details></div></details><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.76.0/src/alloc/borrow.rs.html#83-85">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.76.0/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.76.0/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 href="#associatedtype.Owned" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/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" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/alloc/borrow.rs.html#88">source</a><a href="#method.to_owned" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/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.76.0/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.76.0/src/alloc/borrow.rs.html#92">source</a><a href="#method.clone_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/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.76.0/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.76.0/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.76.0/src/core/convert/mod.rs.html#803-805">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.76.0/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.76.0/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" class="associatedtype trait-impl"><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.76.0/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.76.0/src/core/convert/mod.rs.html#810">source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/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.76.0/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.76.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/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.76.0/src/core/convert/mod.rs.html#788-790">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.76.0/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.76.0/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-1" class="associatedtype trait-impl"><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/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.76.0/src/core/convert/mod.rs.html#795">source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/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.76.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/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></section></div></main></body></html>
|