mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2025-12-22 22:20:02 +00:00
888 lines
128 KiB
HTML
888 lines
128 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `NAME_PATTERN_REG` struct in crate `common_base`."><title>NAME_PATTERN_REG in common_base::regex_pattern - 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-e56847b5.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="common_base" data-themes="" data-resource-suffix="" data-rustdoc-version="1.92.0-nightly (fa3155a64 2025-09-30)" data-channel="nightly" data-search-js="search-e256b49e.js" data-stringdex-js="stringdex-828709d0.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-ce535bd0.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="#">NAME_PATTERN_REG</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../common_base/index.html">common_<wbr>base</a><span class="version">1.0.0-beta.3</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">NAME_<wbr>PATTERN_<wbr>REG</a></h2><h3><a href="#fields">Fields</a></h3><ul class="block structfield"><li><a href="#structfield.__private_field" title="__private_field">__private_field</a></li></ul><h3><a href="#deref-methods-Regex">Methods from Deref<<wbr>Target=<wbr>Regex></a></h3><ul class="block deref-methods"><li><a href="#method.as_str" title="as_str">as_str</a></li><li><a href="#method.capture_locations" title="capture_locations">capture_locations</a></li><li><a href="#method.capture_names" title="capture_names">capture_names</a></li><li><a href="#method.captures" title="captures">captures</a></li><li><a href="#method.captures_at" title="captures_at">captures_at</a></li><li><a href="#method.captures_iter" title="captures_iter">captures_iter</a></li><li><a href="#method.captures_len" title="captures_len">captures_len</a></li><li><a href="#method.captures_read" title="captures_read">captures_read</a></li><li><a href="#method.captures_read_at" title="captures_read_at">captures_read_at</a></li><li><a href="#method.find" title="find">find</a></li><li><a href="#method.find_at" title="find_at">find_at</a></li><li><a href="#method.find_iter" title="find_iter">find_iter</a></li><li><a href="#method.is_match" title="is_match">is_match</a></li><li><a href="#method.is_match_at" title="is_match_at">is_match_at</a></li><li><a href="#method.replace" title="replace">replace</a></li><li><a href="#method.replace_all" title="replace_all">replace_all</a></li><li><a href="#method.replacen" title="replacen">replacen</a></li><li><a href="#method.shortest_match" title="shortest_match">shortest_match</a></li><li><a href="#method.shortest_match_at" title="shortest_match_at">shortest_match_at</a></li><li><a href="#method.split" title="split">split</a></li><li><a href="#method.splitn" title="splitn">splitn</a></li><li><a href="#method.static_captures_len" title="static_captures_len">static_captures_len</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-__Deref-for-NAME_PATTERN_REG" title="Deref">Deref</a></li><li><a href="#impl-LazyStatic-for-NAME_PATTERN_REG" title="LazyStatic">LazyStatic</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-Freeze-for-NAME_PATTERN_REG" title="Freeze">Freeze</a></li><li><a href="#impl-RefUnwindSafe-for-NAME_PATTERN_REG" title="RefUnwindSafe">RefUnwindSafe</a></li><li><a href="#impl-Send-for-NAME_PATTERN_REG" title="Send">Send</a></li><li><a href="#impl-Sync-for-NAME_PATTERN_REG" title="Sync">Sync</a></li><li><a href="#impl-Unpin-for-NAME_PATTERN_REG" title="Unpin">Unpin</a></li><li><a href="#impl-UnwindSafe-for-NAME_PATTERN_REG" 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-Any-for-T-1" 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-Conv-for-T" title="Conv">Conv</a></li><li><a href="#impl-FmtForward-for-T" title="FmtForward">FmtForward</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-Pipe-for-T" title="Pipe">Pipe</a></li><li><a href="#impl-Receiver-for-P" title="Receiver">Receiver</a></li><li><a href="#impl-Tap-for-T" title="Tap">Tap</a></li><li><a href="#impl-TryConv-for-T" title="TryConv">TryConv</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 common_<wbr>base::<wbr>regex_<wbr>pattern</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">common_base</a>::<wbr><a href="index.html">regex_pattern</a></div><h1>Struct <span class="struct">NAME_<wbr>PATTERN_<wbr>REG</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/common_base/regex_pattern.rs.html#20-22">Source</a> </span></div><pre class="rust item-decl"><code>pub struct NAME_PATTERN_REG {
|
||
__private_field: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>,
|
||
}</code></pre><h2 id="fields" class="fields section-header">Fields<a href="#fields" class="anchor">§</a></h2><span id="structfield.__private_field" class="structfield section-header"><a href="#structfield.__private_field" class="anchor field">§</a><code>__private_field: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a></code></span><details class="toggle big-toggle" open><summary><h2 id="deref-methods-Regex" class="section-header"><span>Methods from <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = Regex></span><a href="#deref-methods-Regex" class="anchor">§</a></h2></summary><div id="deref-methods-Regex-1" class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.is_match" class="method"><h4 class="code-header">pub fn <a href="#method.is_match" class="fn">is_match</a>(&self, haystack: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns true if and only if there is a match for the regex anywhere
|
||
in the haystack given.</p>
|
||
<p>It is recommended to use this method if all you need to do is test
|
||
whether a match exists, since the underlying matching engine may be
|
||
able to do less work.</p>
|
||
<h5 id="example"><a class="doc-anchor" href="#example">§</a>Example</h5>
|
||
<p>Test if some haystack contains at least one word with exactly 13
|
||
Unicode word characters:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"\b\w{13}\b"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"I categorically deny having triskaidekaphobia."</span>;
|
||
<span class="macro">assert!</span>(re.is_match(hay));</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.find" class="method"><h4 class="code-header">pub fn <a href="#method.find" class="fn">find</a><'h>(&self, haystack: &'h <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Match<'h>></h4></section></summary><div class="docblock"><p>This routine searches for the first match of this regex in the
|
||
haystack given, and if found, returns a [<code>Match</code>]. The <code>Match</code>
|
||
provides access to both the byte offsets of the match and the actual
|
||
substring that matched.</p>
|
||
<p>Note that this should only be used if you want to find the entire
|
||
match. If instead you just want to test the existence of a match,
|
||
it’s potentially faster to use <code>Regex::is_match(hay)</code> instead of
|
||
<code>Regex::find(hay).is_some()</code>.</p>
|
||
<h5 id="example-1"><a class="doc-anchor" href="#example-1">§</a>Example</h5>
|
||
<p>Find the first word with exactly 13 Unicode word characters:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"\b\w{13}\b"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"I categorically deny having triskaidekaphobia."</span>;
|
||
<span class="kw">let </span>mat = re.find(hay).unwrap();
|
||
<span class="macro">assert_eq!</span>(<span class="number">2</span>..<span class="number">15</span>, mat.range());
|
||
<span class="macro">assert_eq!</span>(<span class="string">"categorically"</span>, mat.as_str());</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.find_iter" class="method"><h4 class="code-header">pub fn <a href="#method.find_iter" class="fn">find_iter</a><'r, 'h>(&'r self, haystack: &'h <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> Matches<'r, 'h></h4></section></summary><div class="docblock"><p>Returns an iterator that yields successive non-overlapping matches in
|
||
the given haystack. The iterator yields values of type [<code>Match</code>].</p>
|
||
<h5 id="time-complexity"><a class="doc-anchor" href="#time-complexity">§</a>Time complexity</h5>
|
||
<p>Note that since <code>find_iter</code> runs potentially many searches on the
|
||
haystack and since each search has worst case <code>O(m * n)</code> time
|
||
complexity, the overall worst case time complexity for iteration is
|
||
<code>O(m * n^2)</code>.</p>
|
||
<h5 id="example-2"><a class="doc-anchor" href="#example-2">§</a>Example</h5>
|
||
<p>Find every word with exactly 13 Unicode word characters:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"\b\w{13}\b"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"Retroactively relinquishing remunerations is reprehensible."</span>;
|
||
<span class="kw">let </span>matches: Vec<<span class="kw">_</span>> = re.find_iter(hay).map(|m| m.as_str()).collect();
|
||
<span class="macro">assert_eq!</span>(matches, <span class="macro">vec!</span>[
|
||
<span class="string">"Retroactively"</span>,
|
||
<span class="string">"relinquishing"</span>,
|
||
<span class="string">"remunerations"</span>,
|
||
<span class="string">"reprehensible"</span>,
|
||
]);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.captures" class="method"><h4 class="code-header">pub fn <a href="#method.captures" class="fn">captures</a><'h>(&self, haystack: &'h <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Captures<'h>></h4></section></summary><div class="docblock"><p>This routine searches for the first match of this regex in the haystack
|
||
given, and if found, returns not only the overall match but also the
|
||
matches of each capture group in the regex. If no match is found, then
|
||
<code>None</code> is returned.</p>
|
||
<p>Capture group <code>0</code> always corresponds to an implicit unnamed group that
|
||
includes the entire match. If a match is found, this group is always
|
||
present. Subsequent groups may be named and are numbered, starting
|
||
at 1, by the order in which the opening parenthesis appears in the
|
||
pattern. For example, in the pattern <code>(?<a>.(?<b>.))(?<c>.)</code>, <code>a</code>,
|
||
<code>b</code> and <code>c</code> correspond to capture group indices <code>1</code>, <code>2</code> and <code>3</code>,
|
||
respectively.</p>
|
||
<p>You should only use <code>captures</code> if you need access to the capture group
|
||
matches. Otherwise, [<code>Regex::find</code>] is generally faster for discovering
|
||
just the overall match.</p>
|
||
<h5 id="example-3"><a class="doc-anchor" href="#example-3">§</a>Example</h5>
|
||
<p>Say you have some haystack with movie names and their release years,
|
||
like “‘Citizen Kane’ (1941)”. It’d be nice if we could search for
|
||
substrings looking like that, while also extracting the movie name and
|
||
its release year separately. The example below shows how to do that.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"'([^']+)'\s+\((\d{4})\)"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"Not my favorite movie: 'Citizen Kane' (1941)."</span>;
|
||
<span class="kw">let </span>caps = re.captures(hay).unwrap();
|
||
<span class="macro">assert_eq!</span>(caps.get(<span class="number">0</span>).unwrap().as_str(), <span class="string">"'Citizen Kane' (1941)"</span>);
|
||
<span class="macro">assert_eq!</span>(caps.get(<span class="number">1</span>).unwrap().as_str(), <span class="string">"Citizen Kane"</span>);
|
||
<span class="macro">assert_eq!</span>(caps.get(<span class="number">2</span>).unwrap().as_str(), <span class="string">"1941"</span>);
|
||
<span class="comment">// You can also access the groups by index using the Index notation.
|
||
// Note that this will panic on an invalid index. In this case, these
|
||
// accesses are always correct because the overall regex will only
|
||
// match when these capture groups match.
|
||
</span><span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="number">0</span>], <span class="string">"'Citizen Kane' (1941)"</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="number">1</span>], <span class="string">"Citizen Kane"</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="number">2</span>], <span class="string">"1941"</span>);</code></pre></div>
|
||
<p>Note that the full match is at capture group <code>0</code>. Each subsequent
|
||
capture group is indexed by the order of its opening <code>(</code>.</p>
|
||
<p>We can make this example a bit clearer by using <em>named</em> capture groups:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"'(?<title>[^']+)'\s+\((?<year>\d{4})\)"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"Not my favorite movie: 'Citizen Kane' (1941)."</span>;
|
||
<span class="kw">let </span>caps = re.captures(hay).unwrap();
|
||
<span class="macro">assert_eq!</span>(caps.get(<span class="number">0</span>).unwrap().as_str(), <span class="string">"'Citizen Kane' (1941)"</span>);
|
||
<span class="macro">assert_eq!</span>(caps.name(<span class="string">"title"</span>).unwrap().as_str(), <span class="string">"Citizen Kane"</span>);
|
||
<span class="macro">assert_eq!</span>(caps.name(<span class="string">"year"</span>).unwrap().as_str(), <span class="string">"1941"</span>);
|
||
<span class="comment">// You can also access the groups by name using the Index notation.
|
||
// Note that this will panic on an invalid group name. In this case,
|
||
// these accesses are always correct because the overall regex will
|
||
// only match when these capture groups match.
|
||
</span><span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="number">0</span>], <span class="string">"'Citizen Kane' (1941)"</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="string">"title"</span>], <span class="string">"Citizen Kane"</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="string">"year"</span>], <span class="string">"1941"</span>);</code></pre></div>
|
||
<p>Here we name the capture groups, which we can access with the <code>name</code>
|
||
method or the <code>Index</code> notation with a <code>&str</code>. Note that the named
|
||
capture groups are still accessible with <code>get</code> or the <code>Index</code> notation
|
||
with a <code>usize</code>.</p>
|
||
<p>The <code>0</code>th capture group is always unnamed, so it must always be
|
||
accessed with <code>get(0)</code> or <code>[0]</code>.</p>
|
||
<p>Finally, one other way to get the matched substrings is with the
|
||
[<code>Captures::extract</code>] API:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"'([^']+)'\s+\((\d{4})\)"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"Not my favorite movie: 'Citizen Kane' (1941)."</span>;
|
||
<span class="kw">let </span>(full, [title, year]) = re.captures(hay).unwrap().extract();
|
||
<span class="macro">assert_eq!</span>(full, <span class="string">"'Citizen Kane' (1941)"</span>);
|
||
<span class="macro">assert_eq!</span>(title, <span class="string">"Citizen Kane"</span>);
|
||
<span class="macro">assert_eq!</span>(year, <span class="string">"1941"</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.captures_iter" class="method"><h4 class="code-header">pub fn <a href="#method.captures_iter" class="fn">captures_iter</a><'r, 'h>(
|
||
&'r self,
|
||
haystack: &'h <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>,
|
||
) -> CaptureMatches<'r, 'h></h4></section></summary><div class="docblock"><p>Returns an iterator that yields successive non-overlapping matches in
|
||
the given haystack. The iterator yields values of type [<code>Captures</code>].</p>
|
||
<p>This is the same as [<code>Regex::find_iter</code>], but instead of only providing
|
||
access to the overall match, each value yield includes access to the
|
||
matches of all capture groups in the regex. Reporting this extra match
|
||
data is potentially costly, so callers should only use <code>captures_iter</code>
|
||
over <code>find_iter</code> when they actually need access to the capture group
|
||
matches.</p>
|
||
<h5 id="time-complexity-1"><a class="doc-anchor" href="#time-complexity-1">§</a>Time complexity</h5>
|
||
<p>Note that since <code>captures_iter</code> runs potentially many searches on the
|
||
haystack and since each search has worst case <code>O(m * n)</code> time
|
||
complexity, the overall worst case time complexity for iteration is
|
||
<code>O(m * n^2)</code>.</p>
|
||
<h5 id="example-4"><a class="doc-anchor" href="#example-4">§</a>Example</h5>
|
||
<p>We can use this to find all movie titles and their release years in
|
||
some haystack, where the movie is formatted like “‘Title’ (xxxx)”:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"'([^']+)'\s+\(([0-9]{4})\)"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."</span>;
|
||
<span class="kw">let </span><span class="kw-2">mut </span>movies = <span class="macro">vec!</span>[];
|
||
<span class="kw">for </span>(<span class="kw">_</span>, [title, year]) <span class="kw">in </span>re.captures_iter(hay).map(|c| c.extract()) {
|
||
movies.push((title, year.parse::<i64>()<span class="question-mark">?</span>));
|
||
}
|
||
<span class="macro">assert_eq!</span>(movies, <span class="macro">vec!</span>[
|
||
(<span class="string">"Citizen Kane"</span>, <span class="number">1941</span>),
|
||
(<span class="string">"The Wizard of Oz"</span>, <span class="number">1939</span>),
|
||
(<span class="string">"M"</span>, <span class="number">1931</span>),
|
||
]);</code></pre></div>
|
||
<p>Or with named groups:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"'(?<title>[^']+)'\s+\((?<year>[0-9]{4})\)"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."</span>;
|
||
<span class="kw">let </span><span class="kw-2">mut </span>it = re.captures_iter(hay);
|
||
|
||
<span class="kw">let </span>caps = it.next().unwrap();
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="string">"title"</span>], <span class="string">"Citizen Kane"</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="string">"year"</span>], <span class="string">"1941"</span>);
|
||
|
||
<span class="kw">let </span>caps = it.next().unwrap();
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="string">"title"</span>], <span class="string">"The Wizard of Oz"</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="string">"year"</span>], <span class="string">"1939"</span>);
|
||
|
||
<span class="kw">let </span>caps = it.next().unwrap();
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="string">"title"</span>], <span class="string">"M"</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="string">"year"</span>], <span class="string">"1931"</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.split" class="method"><h4 class="code-header">pub fn <a href="#method.split" class="fn">split</a><'r, 'h>(&'r self, haystack: &'h <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> Split<'r, 'h></h4></section></summary><div class="docblock"><p>Returns an iterator of substrings of the haystack given, delimited by a
|
||
match of the regex. Namely, each element of the iterator corresponds to
|
||
a part of the haystack that <em>isn’t</em> matched by the regular expression.</p>
|
||
<h5 id="time-complexity-2"><a class="doc-anchor" href="#time-complexity-2">§</a>Time complexity</h5>
|
||
<p>Since iterators over all matches requires running potentially many
|
||
searches on the haystack, and since each search has worst case
|
||
<code>O(m * n)</code> time complexity, the overall worst case time complexity for
|
||
this routine is <code>O(m * n^2)</code>.</p>
|
||
<h5 id="example-5"><a class="doc-anchor" href="#example-5">§</a>Example</h5>
|
||
<p>To split a string delimited by arbitrary amounts of spaces or tabs:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"[ \t]+"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"a b \t c\td e"</span>;
|
||
<span class="kw">let </span>fields: Vec<<span class="kw-2">&</span>str> = re.split(hay).collect();
|
||
<span class="macro">assert_eq!</span>(fields, <span class="macro">vec!</span>[<span class="string">"a"</span>, <span class="string">"b"</span>, <span class="string">"c"</span>, <span class="string">"d"</span>, <span class="string">"e"</span>]);</code></pre></div><h5 id="example-more-cases"><a class="doc-anchor" href="#example-more-cases">§</a>Example: more cases</h5>
|
||
<p>Basic usage:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r" "</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"Mary had a little lamb"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.split(hay).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">"Mary"</span>, <span class="string">"had"</span>, <span class="string">"a"</span>, <span class="string">"little"</span>, <span class="string">"lamb"</span>]);
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"X"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">""</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.split(hay).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">""</span>]);
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"X"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"lionXXtigerXleopard"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.split(hay).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">"lion"</span>, <span class="string">""</span>, <span class="string">"tiger"</span>, <span class="string">"leopard"</span>]);
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"::"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"lion::tiger::leopard"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.split(hay).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">"lion"</span>, <span class="string">"tiger"</span>, <span class="string">"leopard"</span>]);</code></pre></div>
|
||
<p>If a haystack contains multiple contiguous matches, you will end up
|
||
with empty spans yielded by the iterator:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"X"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"XXXXaXXbXc"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.split(hay).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">""</span>, <span class="string">""</span>, <span class="string">""</span>, <span class="string">""</span>, <span class="string">"a"</span>, <span class="string">""</span>, <span class="string">"b"</span>, <span class="string">"c"</span>]);
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"/"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"(///)"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.split(hay).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">"("</span>, <span class="string">""</span>, <span class="string">""</span>, <span class="string">")"</span>]);</code></pre></div>
|
||
<p>Separators at the start or end of a haystack are neighbored by empty
|
||
substring.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"0"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"010"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.split(hay).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">""</span>, <span class="string">"1"</span>, <span class="string">""</span>]);</code></pre></div>
|
||
<p>When the empty string is used as a regex, it splits at every valid
|
||
UTF-8 boundary by default (which includes the beginning and end of the
|
||
haystack):</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r""</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"rust"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.split(hay).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">""</span>, <span class="string">"r"</span>, <span class="string">"u"</span>, <span class="string">"s"</span>, <span class="string">"t"</span>, <span class="string">""</span>]);
|
||
|
||
<span class="comment">// Splitting by an empty string is UTF-8 aware by default!
|
||
</span><span class="kw">let </span>re = Regex::new(<span class="string">r""</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"☃"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.split(hay).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">""</span>, <span class="string">"☃"</span>, <span class="string">""</span>]);</code></pre></div>
|
||
<p>Contiguous separators (commonly shows up with whitespace), can lead to
|
||
possibly surprising behavior. For example, this code is correct:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r" "</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">" a b c"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.split(hay).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">""</span>, <span class="string">""</span>, <span class="string">""</span>, <span class="string">""</span>, <span class="string">"a"</span>, <span class="string">""</span>, <span class="string">"b"</span>, <span class="string">"c"</span>]);</code></pre></div>
|
||
<p>It does <em>not</em> give you <code>["a", "b", "c"]</code>. For that behavior, you’d want
|
||
to match contiguous space characters:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r" +"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">" a b c"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.split(hay).collect();
|
||
<span class="comment">// N.B. This does still include a leading empty span because ' +'
|
||
// matches at the beginning of the haystack.
|
||
</span><span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">""</span>, <span class="string">"a"</span>, <span class="string">"b"</span>, <span class="string">"c"</span>]);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.splitn" class="method"><h4 class="code-header">pub fn <a href="#method.splitn" class="fn">splitn</a><'r, 'h>(
|
||
&'r self,
|
||
haystack: &'h <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>,
|
||
limit: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>,
|
||
) -> SplitN<'r, 'h></h4></section></summary><div class="docblock"><p>Returns an iterator of at most <code>limit</code> substrings of the haystack
|
||
given, delimited by a match of the regex. (A <code>limit</code> of <code>0</code> will return
|
||
no substrings.) Namely, each element of the iterator corresponds to a
|
||
part of the haystack that <em>isn’t</em> matched by the regular expression.
|
||
The remainder of the haystack that is not split will be the last
|
||
element in the iterator.</p>
|
||
<h5 id="time-complexity-3"><a class="doc-anchor" href="#time-complexity-3">§</a>Time complexity</h5>
|
||
<p>Since iterators over all matches requires running potentially many
|
||
searches on the haystack, and since each search has worst case
|
||
<code>O(m * n)</code> time complexity, the overall worst case time complexity for
|
||
this routine is <code>O(m * n^2)</code>.</p>
|
||
<p>Although note that the worst case time here has an upper bound given
|
||
by the <code>limit</code> parameter.</p>
|
||
<h5 id="example-6"><a class="doc-anchor" href="#example-6">§</a>Example</h5>
|
||
<p>Get the first two words in some haystack:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"\W+"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"Hey! How are you?"</span>;
|
||
<span class="kw">let </span>fields: Vec<<span class="kw-2">&</span>str> = re.splitn(hay, <span class="number">3</span>).collect();
|
||
<span class="macro">assert_eq!</span>(fields, <span class="macro">vec!</span>[<span class="string">"Hey"</span>, <span class="string">"How"</span>, <span class="string">"are you?"</span>]);</code></pre></div><h5 id="examples-more-cases"><a class="doc-anchor" href="#examples-more-cases">§</a>Examples: more cases</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r" "</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"Mary had a little lamb"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.splitn(hay, <span class="number">3</span>).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">"Mary"</span>, <span class="string">"had"</span>, <span class="string">"a little lamb"</span>]);
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"X"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">""</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.splitn(hay, <span class="number">3</span>).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">""</span>]);
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"X"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"lionXXtigerXleopard"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.splitn(hay, <span class="number">3</span>).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">"lion"</span>, <span class="string">""</span>, <span class="string">"tigerXleopard"</span>]);
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"::"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"lion::tiger::leopard"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.splitn(hay, <span class="number">2</span>).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">"lion"</span>, <span class="string">"tiger::leopard"</span>]);
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"X"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"abcXdef"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.splitn(hay, <span class="number">1</span>).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">"abcXdef"</span>]);
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"X"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"abcdef"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.splitn(hay, <span class="number">2</span>).collect();
|
||
<span class="macro">assert_eq!</span>(got, <span class="macro">vec!</span>[<span class="string">"abcdef"</span>]);
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"X"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"abcXdef"</span>;
|
||
<span class="kw">let </span>got: Vec<<span class="kw-2">&</span>str> = re.splitn(hay, <span class="number">0</span>).collect();
|
||
<span class="macro">assert!</span>(got.is_empty());</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.replace" class="method"><h4 class="code-header">pub fn <a href="#method.replace" class="fn">replace</a><'h, R>(&self, haystack: &'h <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, rep: R) -> <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'h, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>><div class="where">where
|
||
R: Replacer,</div></h4></section></summary><div class="docblock"><p>Replaces the leftmost-first match in the given haystack with the
|
||
replacement provided. The replacement can be a regular string (where
|
||
<code>$N</code> and <code>$name</code> are expanded to match capture groups) or a function
|
||
that takes a [<code>Captures</code>] and returns the replaced string.</p>
|
||
<p>If no match is found, then the haystack is returned unchanged. In that
|
||
case, this implementation will likely return a <code>Cow::Borrowed</code> value
|
||
such that no allocation is performed.</p>
|
||
<p>When a <code>Cow::Borrowed</code> is returned, the value returned is guaranteed
|
||
to be equivalent to the <code>haystack</code> given.</p>
|
||
<h5 id="replacement-string-syntax"><a class="doc-anchor" href="#replacement-string-syntax">§</a>Replacement string syntax</h5>
|
||
<p>All instances of <code>$ref</code> in the replacement string are replaced with
|
||
the substring corresponding to the capture group identified by <code>ref</code>.</p>
|
||
<p><code>ref</code> may be an integer corresponding to the index of the capture group
|
||
(counted by order of opening parenthesis where <code>0</code> is the entire match)
|
||
or it can be a name (consisting of letters, digits or underscores)
|
||
corresponding to a named capture group.</p>
|
||
<p>If <code>ref</code> isn’t a valid capture group (whether the name doesn’t exist or
|
||
isn’t a valid index), then it is replaced with the empty string.</p>
|
||
<p>The longest possible name is used. For example, <code>$1a</code> looks up the
|
||
capture group named <code>1a</code> and not the capture group at index <code>1</code>. To
|
||
exert more precise control over the name, use braces, e.g., <code>${1}a</code>.</p>
|
||
<p>To write a literal <code>$</code> use <code>$$</code>.</p>
|
||
<h5 id="example-7"><a class="doc-anchor" href="#example-7">§</a>Example</h5>
|
||
<p>Note that this function is polymorphic with respect to the replacement.
|
||
In typical usage, this can just be a normal string:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"[^01]+"</span>).unwrap();
|
||
<span class="macro">assert_eq!</span>(re.replace(<span class="string">"1078910"</span>, <span class="string">""</span>), <span class="string">"1010"</span>);</code></pre></div>
|
||
<p>But anything satisfying the [<code>Replacer</code>] trait will work. For example,
|
||
a closure of type <code>|&Captures| -> String</code> provides direct access to the
|
||
captures corresponding to a match. This allows one to access capturing
|
||
group matches easily:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::{Captures, Regex};
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"([^,\s]+),\s+(\S+)"</span>).unwrap();
|
||
<span class="kw">let </span>result = re.replace(<span class="string">"Springsteen, Bruce"</span>, |caps: <span class="kw-2">&</span>Captures| {
|
||
<span class="macro">format!</span>(<span class="string">"{} {}"</span>, <span class="kw-2">&</span>caps[<span class="number">2</span>], <span class="kw-2">&</span>caps[<span class="number">1</span>])
|
||
});
|
||
<span class="macro">assert_eq!</span>(result, <span class="string">"Bruce Springsteen"</span>);</code></pre></div>
|
||
<p>But this is a bit cumbersome to use all the time. Instead, a simple
|
||
syntax is supported (as described above) that expands <code>$name</code> into the
|
||
corresponding capture group. Here’s the last example, but using this
|
||
expansion technique with named capture groups:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"(?<last>[^,\s]+),\s+(?<first>\S+)"</span>).unwrap();
|
||
<span class="kw">let </span>result = re.replace(<span class="string">"Springsteen, Bruce"</span>, <span class="string">"$first $last"</span>);
|
||
<span class="macro">assert_eq!</span>(result, <span class="string">"Bruce Springsteen"</span>);</code></pre></div>
|
||
<p>Note that using <code>$2</code> instead of <code>$first</code> or <code>$1</code> instead of <code>$last</code>
|
||
would produce the same result. To write a literal <code>$</code> use <code>$$</code>.</p>
|
||
<p>Sometimes the replacement string requires use of curly braces to
|
||
delineate a capture group replacement when it is adjacent to some other
|
||
literal text. For example, if we wanted to join two words together with
|
||
an underscore:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"(?<first>\w+)\s+(?<second>\w+)"</span>).unwrap();
|
||
<span class="kw">let </span>result = re.replace(<span class="string">"deep fried"</span>, <span class="string">"${first}_$second"</span>);
|
||
<span class="macro">assert_eq!</span>(result, <span class="string">"deep_fried"</span>);</code></pre></div>
|
||
<p>Without the curly braces, the capture group name <code>first_</code> would be
|
||
used, and since it doesn’t exist, it would be replaced with the empty
|
||
string.</p>
|
||
<p>Finally, sometimes you just want to replace a literal string with no
|
||
regard for capturing group expansion. This can be done by wrapping a
|
||
string with [<code>NoExpand</code>]:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::{NoExpand, Regex};
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"(?<last>[^,\s]+),\s+(\S+)"</span>).unwrap();
|
||
<span class="kw">let </span>result = re.replace(<span class="string">"Springsteen, Bruce"</span>, NoExpand(<span class="string">"$2 $last"</span>));
|
||
<span class="macro">assert_eq!</span>(result, <span class="string">"$2 $last"</span>);</code></pre></div>
|
||
<p>Using <code>NoExpand</code> may also be faster, since the replacement string won’t
|
||
need to be parsed for the <code>$</code> syntax.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.replace_all" class="method"><h4 class="code-header">pub fn <a href="#method.replace_all" class="fn">replace_all</a><'h, R>(&self, haystack: &'h <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, rep: R) -> <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'h, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>><div class="where">where
|
||
R: Replacer,</div></h4></section></summary><div class="docblock"><p>Replaces all non-overlapping matches in the haystack with the
|
||
replacement provided. This is the same as calling <code>replacen</code> with
|
||
<code>limit</code> set to <code>0</code>.</p>
|
||
<p>If no match is found, then the haystack is returned unchanged. In that
|
||
case, this implementation will likely return a <code>Cow::Borrowed</code> value
|
||
such that no allocation is performed.</p>
|
||
<p>When a <code>Cow::Borrowed</code> is returned, the value returned is guaranteed
|
||
to be equivalent to the <code>haystack</code> given.</p>
|
||
<p>The documentation for [<code>Regex::replace</code>] goes into more detail about
|
||
what kinds of replacement strings are supported.</p>
|
||
<h5 id="time-complexity-4"><a class="doc-anchor" href="#time-complexity-4">§</a>Time complexity</h5>
|
||
<p>Since iterators over all matches requires running potentially many
|
||
searches on the haystack, and since each search has worst case
|
||
<code>O(m * n)</code> time complexity, the overall worst case time complexity for
|
||
this routine is <code>O(m * n^2)</code>.</p>
|
||
<h5 id="fallibility"><a class="doc-anchor" href="#fallibility">§</a>Fallibility</h5>
|
||
<p>If you need to write a replacement routine where any individual
|
||
replacement might “fail,” doing so with this API isn’t really feasible
|
||
because there’s no way to stop the search process if a replacement
|
||
fails. Instead, if you need this functionality, you should consider
|
||
implementing your own replacement routine:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::{Captures, Regex};
|
||
|
||
<span class="kw">fn </span>replace_all<E>(
|
||
re: <span class="kw-2">&</span>Regex,
|
||
haystack: <span class="kw-2">&</span>str,
|
||
replacement: <span class="kw">impl </span>Fn(<span class="kw-2">&</span>Captures) -> <span class="prelude-ty">Result</span><String, E>,
|
||
) -> <span class="prelude-ty">Result</span><String, E> {
|
||
<span class="kw">let </span><span class="kw-2">mut </span>new = String::with_capacity(haystack.len());
|
||
<span class="kw">let </span><span class="kw-2">mut </span>last_match = <span class="number">0</span>;
|
||
<span class="kw">for </span>caps <span class="kw">in </span>re.captures_iter(haystack) {
|
||
<span class="kw">let </span>m = caps.get(<span class="number">0</span>).unwrap();
|
||
new.push_str(<span class="kw-2">&</span>haystack[last_match..m.start()]);
|
||
new.push_str(<span class="kw-2">&</span>replacement(<span class="kw-2">&</span>caps)<span class="question-mark">?</span>);
|
||
last_match = m.end();
|
||
}
|
||
new.push_str(<span class="kw-2">&</span>haystack[last_match..]);
|
||
<span class="prelude-val">Ok</span>(new)
|
||
}
|
||
|
||
<span class="comment">// Let's replace each word with the number of bytes in that word.
|
||
// But if we see a word that is "too long," we'll give up.
|
||
</span><span class="kw">let </span>re = Regex::new(<span class="string">r"\w+"</span>).unwrap();
|
||
<span class="kw">let </span>replacement = |caps: <span class="kw-2">&</span>Captures| -> <span class="prelude-ty">Result</span><String, <span class="kw-2">&</span><span class="lifetime">'static </span>str> {
|
||
<span class="kw">if </span>caps[<span class="number">0</span>].len() >= <span class="number">5 </span>{
|
||
<span class="kw">return </span><span class="prelude-val">Err</span>(<span class="string">"word too long"</span>);
|
||
}
|
||
<span class="prelude-val">Ok</span>(caps[<span class="number">0</span>].len().to_string())
|
||
};
|
||
<span class="macro">assert_eq!</span>(
|
||
<span class="prelude-val">Ok</span>(<span class="string">"2 3 3 3?"</span>.to_string()),
|
||
replace_all(<span class="kw-2">&</span>re, <span class="string">"hi how are you?"</span>, <span class="kw-2">&</span>replacement),
|
||
);
|
||
<span class="macro">assert!</span>(replace_all(<span class="kw-2">&</span>re, <span class="string">"hi there"</span>, <span class="kw-2">&</span>replacement).is_err());</code></pre></div><h5 id="example-8"><a class="doc-anchor" href="#example-8">§</a>Example</h5>
|
||
<p>This example shows how to flip the order of whitespace (excluding line
|
||
terminators) delimited fields, and normalizes the whitespace that
|
||
delimits the fields:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"(?m)^(\S+)[\s--\r\n]+(\S+)$"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"
|
||
Greetings 1973
|
||
Wild\t1973
|
||
BornToRun\t\t\t\t1975
|
||
Darkness 1978
|
||
TheRiver 1980
|
||
"</span>;
|
||
<span class="kw">let </span>new = re.replace_all(hay, <span class="string">"$2 $1"</span>);
|
||
<span class="macro">assert_eq!</span>(new, <span class="string">"
|
||
1973 Greetings
|
||
1973 Wild
|
||
1975 BornToRun
|
||
1978 Darkness
|
||
1980 TheRiver
|
||
"</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.replacen" class="method"><h4 class="code-header">pub fn <a href="#method.replacen" class="fn">replacen</a><'h, R>(
|
||
&self,
|
||
haystack: &'h <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>,
|
||
limit: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>,
|
||
rep: R,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'h, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>><div class="where">where
|
||
R: Replacer,</div></h4></section></summary><div class="docblock"><p>Replaces at most <code>limit</code> non-overlapping matches in the haystack with
|
||
the replacement provided. If <code>limit</code> is <code>0</code>, then all non-overlapping
|
||
matches are replaced. That is, <code>Regex::replace_all(hay, rep)</code> is
|
||
equivalent to <code>Regex::replacen(hay, 0, rep)</code>.</p>
|
||
<p>If no match is found, then the haystack is returned unchanged. In that
|
||
case, this implementation will likely return a <code>Cow::Borrowed</code> value
|
||
such that no allocation is performed.</p>
|
||
<p>When a <code>Cow::Borrowed</code> is returned, the value returned is guaranteed
|
||
to be equivalent to the <code>haystack</code> given.</p>
|
||
<p>The documentation for [<code>Regex::replace</code>] goes into more detail about
|
||
what kinds of replacement strings are supported.</p>
|
||
<h5 id="time-complexity-5"><a class="doc-anchor" href="#time-complexity-5">§</a>Time complexity</h5>
|
||
<p>Since iterators over all matches requires running potentially many
|
||
searches on the haystack, and since each search has worst case
|
||
<code>O(m * n)</code> time complexity, the overall worst case time complexity for
|
||
this routine is <code>O(m * n^2)</code>.</p>
|
||
<p>Although note that the worst case time here has an upper bound given
|
||
by the <code>limit</code> parameter.</p>
|
||
<h5 id="fallibility-1"><a class="doc-anchor" href="#fallibility-1">§</a>Fallibility</h5>
|
||
<p>See the corresponding section in the docs for [<code>Regex::replace_all</code>]
|
||
for tips on how to deal with a replacement routine that can fail.</p>
|
||
<h5 id="example-9"><a class="doc-anchor" href="#example-9">§</a>Example</h5>
|
||
<p>This example shows how to flip the order of whitespace (excluding line
|
||
terminators) delimited fields, and normalizes the whitespace that
|
||
delimits the fields. But we only do it for the first two matches.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"(?m)^(\S+)[\s--\r\n]+(\S+)$"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"
|
||
Greetings 1973
|
||
Wild\t1973
|
||
BornToRun\t\t\t\t1975
|
||
Darkness 1978
|
||
TheRiver 1980
|
||
"</span>;
|
||
<span class="kw">let </span>new = re.replacen(hay, <span class="number">2</span>, <span class="string">"$2 $1"</span>);
|
||
<span class="macro">assert_eq!</span>(new, <span class="string">"
|
||
1973 Greetings
|
||
1973 Wild
|
||
BornToRun\t\t\t\t1975
|
||
Darkness 1978
|
||
TheRiver 1980
|
||
"</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.shortest_match" class="method"><h4 class="code-header">pub fn <a href="#method.shortest_match" class="fn">shortest_match</a>(&self, haystack: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>></h4></section></summary><div class="docblock"><p>Returns the end byte offset of the first match in the haystack given.</p>
|
||
<p>This method may have the same performance characteristics as
|
||
<code>is_match</code>. Behaviorally, it doesn’t just report whether it match
|
||
occurs, but also the end offset for a match. In particular, the offset
|
||
returned <em>may be shorter</em> than the proper end of the leftmost-first
|
||
match that you would find via [<code>Regex::find</code>].</p>
|
||
<p>Note that it is not guaranteed that this routine finds the shortest or
|
||
“earliest” possible match. Instead, the main idea of this API is that
|
||
it returns the offset at the point at which the internal regex engine
|
||
has determined that a match has occurred. This may vary depending on
|
||
which internal regex engine is used, and thus, the offset itself may
|
||
change based on internal heuristics.</p>
|
||
<h5 id="example-10"><a class="doc-anchor" href="#example-10">§</a>Example</h5>
|
||
<p>Typically, <code>a+</code> would match the entire first sequence of <code>a</code> in some
|
||
haystack, but <code>shortest_match</code> <em>may</em> give up as soon as it sees the
|
||
first <code>a</code>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"a+"</span>).unwrap();
|
||
<span class="kw">let </span>offset = re.shortest_match(<span class="string">"aaaaa"</span>).unwrap();
|
||
<span class="macro">assert_eq!</span>(offset, <span class="number">1</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.shortest_match_at" class="method"><h4 class="code-header">pub fn <a href="#method.shortest_match_at" class="fn">shortest_match_at</a>(&self, haystack: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, start: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>></h4></section></summary><div class="docblock"><p>Returns the same as [<code>Regex::shortest_match</code>], but starts the search at
|
||
the given offset.</p>
|
||
<p>The significance of the starting point is that it takes the surrounding
|
||
context into consideration. For example, the <code>\A</code> anchor can only match
|
||
when <code>start == 0</code>.</p>
|
||
<p>If a match is found, the offset returned is relative to the beginning
|
||
of the haystack, not the beginning of the search.</p>
|
||
<h5 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h5>
|
||
<p>This panics when <code>start >= haystack.len() + 1</code>.</p>
|
||
<h5 id="example-11"><a class="doc-anchor" href="#example-11">§</a>Example</h5>
|
||
<p>This example shows the significance of <code>start</code> by demonstrating how it
|
||
can be used to permit look-around assertions in a regex to take the
|
||
surrounding context into account.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"\bchew\b"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"eschew"</span>;
|
||
<span class="comment">// We get a match here, but it's probably not intended.
|
||
</span><span class="macro">assert_eq!</span>(re.shortest_match(<span class="kw-2">&</span>hay[<span class="number">2</span>..]), <span class="prelude-val">Some</span>(<span class="number">4</span>));
|
||
<span class="comment">// No match because the assertions take the context into account.
|
||
</span><span class="macro">assert_eq!</span>(re.shortest_match_at(hay, <span class="number">2</span>), <span class="prelude-val">None</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.is_match_at" class="method"><h4 class="code-header">pub fn <a href="#method.is_match_at" class="fn">is_match_at</a>(&self, haystack: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, start: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns the same as [<code>Regex::is_match</code>], but starts the search at the
|
||
given offset.</p>
|
||
<p>The significance of the starting point is that it takes the surrounding
|
||
context into consideration. For example, the <code>\A</code> anchor can only
|
||
match when <code>start == 0</code>.</p>
|
||
<h5 id="panics-1"><a class="doc-anchor" href="#panics-1">§</a>Panics</h5>
|
||
<p>This panics when <code>start >= haystack.len() + 1</code>.</p>
|
||
<h5 id="example-12"><a class="doc-anchor" href="#example-12">§</a>Example</h5>
|
||
<p>This example shows the significance of <code>start</code> by demonstrating how it
|
||
can be used to permit look-around assertions in a regex to take the
|
||
surrounding context into account.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"\bchew\b"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"eschew"</span>;
|
||
<span class="comment">// We get a match here, but it's probably not intended.
|
||
</span><span class="macro">assert!</span>(re.is_match(<span class="kw-2">&</span>hay[<span class="number">2</span>..]));
|
||
<span class="comment">// No match because the assertions take the context into account.
|
||
</span><span class="macro">assert!</span>(!re.is_match_at(hay, <span class="number">2</span>));</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.find_at" class="method"><h4 class="code-header">pub fn <a href="#method.find_at" class="fn">find_at</a><'h>(&self, haystack: &'h <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, start: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Match<'h>></h4></section></summary><div class="docblock"><p>Returns the same as [<code>Regex::find</code>], but starts the search at the given
|
||
offset.</p>
|
||
<p>The significance of the starting point is that it takes the surrounding
|
||
context into consideration. For example, the <code>\A</code> anchor can only
|
||
match when <code>start == 0</code>.</p>
|
||
<h5 id="panics-2"><a class="doc-anchor" href="#panics-2">§</a>Panics</h5>
|
||
<p>This panics when <code>start >= haystack.len() + 1</code>.</p>
|
||
<h5 id="example-13"><a class="doc-anchor" href="#example-13">§</a>Example</h5>
|
||
<p>This example shows the significance of <code>start</code> by demonstrating how it
|
||
can be used to permit look-around assertions in a regex to take the
|
||
surrounding context into account.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"\bchew\b"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"eschew"</span>;
|
||
<span class="comment">// We get a match here, but it's probably not intended.
|
||
</span><span class="macro">assert_eq!</span>(re.find(<span class="kw-2">&</span>hay[<span class="number">2</span>..]).map(|m| m.range()), <span class="prelude-val">Some</span>(<span class="number">0</span>..<span class="number">4</span>));
|
||
<span class="comment">// No match because the assertions take the context into account.
|
||
</span><span class="macro">assert_eq!</span>(re.find_at(hay, <span class="number">2</span>), <span class="prelude-val">None</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.captures_at" class="method"><h4 class="code-header">pub fn <a href="#method.captures_at" class="fn">captures_at</a><'h>(
|
||
&self,
|
||
haystack: &'h <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>,
|
||
start: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Captures<'h>></h4></section></summary><div class="docblock"><p>Returns the same as [<code>Regex::captures</code>], but starts the search at the
|
||
given offset.</p>
|
||
<p>The significance of the starting point is that it takes the surrounding
|
||
context into consideration. For example, the <code>\A</code> anchor can only
|
||
match when <code>start == 0</code>.</p>
|
||
<h5 id="panics-3"><a class="doc-anchor" href="#panics-3">§</a>Panics</h5>
|
||
<p>This panics when <code>start >= haystack.len() + 1</code>.</p>
|
||
<h5 id="example-14"><a class="doc-anchor" href="#example-14">§</a>Example</h5>
|
||
<p>This example shows the significance of <code>start</code> by demonstrating how it
|
||
can be used to permit look-around assertions in a regex to take the
|
||
surrounding context into account.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"\bchew\b"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"eschew"</span>;
|
||
<span class="comment">// We get a match here, but it's probably not intended.
|
||
</span><span class="macro">assert_eq!</span>(<span class="kw-2">&</span>re.captures(<span class="kw-2">&</span>hay[<span class="number">2</span>..]).unwrap()[<span class="number">0</span>], <span class="string">"chew"</span>);
|
||
<span class="comment">// No match because the assertions take the context into account.
|
||
</span><span class="macro">assert!</span>(re.captures_at(hay, <span class="number">2</span>).is_none());</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.captures_read" class="method"><h4 class="code-header">pub fn <a href="#method.captures_read" class="fn">captures_read</a><'h>(
|
||
&self,
|
||
locs: &mut CaptureLocations,
|
||
haystack: &'h <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Match<'h>></h4></section></summary><div class="docblock"><p>This is like [<code>Regex::captures</code>], but writes the byte offsets of each
|
||
capture group match into the locations given.</p>
|
||
<p>A [<code>CaptureLocations</code>] stores the same byte offsets as a [<code>Captures</code>],
|
||
but does <em>not</em> store a reference to the haystack. This makes its API
|
||
a bit lower level and less convenient. But in exchange, callers
|
||
may allocate their own <code>CaptureLocations</code> and reuse it for multiple
|
||
searches. This may be helpful if allocating a <code>Captures</code> shows up in a
|
||
profile as too costly.</p>
|
||
<p>To create a <code>CaptureLocations</code> value, use the
|
||
[<code>Regex::capture_locations</code>] method.</p>
|
||
<p>This also returns the overall match if one was found. When a match is
|
||
found, its offsets are also always stored in <code>locs</code> at index <code>0</code>.</p>
|
||
<h5 id="panics-4"><a class="doc-anchor" href="#panics-4">§</a>Panics</h5>
|
||
<p>This routine may panic if the given <code>CaptureLocations</code> was not created
|
||
by this regex.</p>
|
||
<h5 id="example-15"><a class="doc-anchor" href="#example-15">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"^([a-z]+)=(\S*)$"</span>).unwrap();
|
||
<span class="kw">let </span><span class="kw-2">mut </span>locs = re.capture_locations();
|
||
<span class="macro">assert!</span>(re.captures_read(<span class="kw-2">&mut </span>locs, <span class="string">"id=foo123"</span>).is_some());
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">0</span>, <span class="number">9</span>)), locs.get(<span class="number">0</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">0</span>, <span class="number">2</span>)), locs.get(<span class="number">1</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">3</span>, <span class="number">9</span>)), locs.get(<span class="number">2</span>));</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.captures_read_at" class="method"><h4 class="code-header">pub fn <a href="#method.captures_read_at" class="fn">captures_read_at</a><'h>(
|
||
&self,
|
||
locs: &mut CaptureLocations,
|
||
haystack: &'h <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>,
|
||
start: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Match<'h>></h4></section></summary><div class="docblock"><p>Returns the same as [<code>Regex::captures_read</code>], but starts the search at
|
||
the given offset.</p>
|
||
<p>The significance of the starting point is that it takes the surrounding
|
||
context into consideration. For example, the <code>\A</code> anchor can only
|
||
match when <code>start == 0</code>.</p>
|
||
<h5 id="panics-5"><a class="doc-anchor" href="#panics-5">§</a>Panics</h5>
|
||
<p>This panics when <code>start >= haystack.len() + 1</code>.</p>
|
||
<p>This routine may also panic if the given <code>CaptureLocations</code> was not
|
||
created by this regex.</p>
|
||
<h5 id="example-16"><a class="doc-anchor" href="#example-16">§</a>Example</h5>
|
||
<p>This example shows the significance of <code>start</code> by demonstrating how it
|
||
can be used to permit look-around assertions in a regex to take the
|
||
surrounding context into account.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"\bchew\b"</span>).unwrap();
|
||
<span class="kw">let </span>hay = <span class="string">"eschew"</span>;
|
||
<span class="kw">let </span><span class="kw-2">mut </span>locs = re.capture_locations();
|
||
<span class="comment">// We get a match here, but it's probably not intended.
|
||
</span><span class="macro">assert!</span>(re.captures_read(<span class="kw-2">&mut </span>locs, <span class="kw-2">&</span>hay[<span class="number">2</span>..]).is_some());
|
||
<span class="comment">// No match because the assertions take the context into account.
|
||
</span><span class="macro">assert!</span>(re.captures_read_at(<span class="kw-2">&mut </span>locs, hay, <span class="number">2</span>).is_none());</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.as_str" class="method"><h4 class="code-header">pub fn <a href="#method.as_str" class="fn">as_str</a>(&self) -> &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a></h4></section></summary><div class="docblock"><p>Returns the original string of this regex.</p>
|
||
<h5 id="example-17"><a class="doc-anchor" href="#example-17">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"foo\w+bar"</span>).unwrap();
|
||
<span class="macro">assert_eq!</span>(re.as_str(), <span class="string">r"foo\w+bar"</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.capture_names" class="method"><h4 class="code-header">pub fn <a href="#method.capture_names" class="fn">capture_names</a>(&self) -> CaptureNames<'_></h4></section></summary><div class="docblock"><p>Returns an iterator over the capture names in this regex.</p>
|
||
<p>The iterator returned yields elements of type <code>Option<&str></code>. That is,
|
||
the iterator yields values for all capture groups, even ones that are
|
||
unnamed. The order of the groups corresponds to the order of the group’s
|
||
corresponding opening parenthesis.</p>
|
||
<p>The first element of the iterator always yields the group corresponding
|
||
to the overall match, and this group is always unnamed. Therefore, the
|
||
iterator always yields at least one group.</p>
|
||
<h5 id="example-18"><a class="doc-anchor" href="#example-18">§</a>Example</h5>
|
||
<p>This shows basic usage with a mix of named and unnamed capture groups:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"(?<a>.(?<b>.))(.)(?:.)(?<c>.)"</span>).unwrap();
|
||
<span class="kw">let </span><span class="kw-2">mut </span>names = re.capture_names();
|
||
<span class="macro">assert_eq!</span>(names.next(), <span class="prelude-val">Some</span>(<span class="prelude-val">None</span>));
|
||
<span class="macro">assert_eq!</span>(names.next(), <span class="prelude-val">Some</span>(<span class="prelude-val">Some</span>(<span class="string">"a"</span>)));
|
||
<span class="macro">assert_eq!</span>(names.next(), <span class="prelude-val">Some</span>(<span class="prelude-val">Some</span>(<span class="string">"b"</span>)));
|
||
<span class="macro">assert_eq!</span>(names.next(), <span class="prelude-val">Some</span>(<span class="prelude-val">None</span>));
|
||
<span class="comment">// the '(?:.)' group is non-capturing and so doesn't appear here!
|
||
</span><span class="macro">assert_eq!</span>(names.next(), <span class="prelude-val">Some</span>(<span class="prelude-val">Some</span>(<span class="string">"c"</span>)));
|
||
<span class="macro">assert_eq!</span>(names.next(), <span class="prelude-val">None</span>);</code></pre></div>
|
||
<p>The iterator always yields at least one element, even for regexes with
|
||
no capture groups and even for regexes that can never match:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r""</span>).unwrap();
|
||
<span class="kw">let </span><span class="kw-2">mut </span>names = re.capture_names();
|
||
<span class="macro">assert_eq!</span>(names.next(), <span class="prelude-val">Some</span>(<span class="prelude-val">None</span>));
|
||
<span class="macro">assert_eq!</span>(names.next(), <span class="prelude-val">None</span>);
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"[a&&b]"</span>).unwrap();
|
||
<span class="kw">let </span><span class="kw-2">mut </span>names = re.capture_names();
|
||
<span class="macro">assert_eq!</span>(names.next(), <span class="prelude-val">Some</span>(<span class="prelude-val">None</span>));
|
||
<span class="macro">assert_eq!</span>(names.next(), <span class="prelude-val">None</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.captures_len" class="method"><h4 class="code-header">pub fn <a href="#method.captures_len" class="fn">captures_len</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the number of captures groups in this regex.</p>
|
||
<p>This includes all named and unnamed groups, including the implicit
|
||
unnamed group that is always present and corresponds to the entire
|
||
match.</p>
|
||
<p>Since the implicit unnamed group is always included in this length, the
|
||
length returned is guaranteed to be greater than zero.</p>
|
||
<h5 id="example-19"><a class="doc-anchor" href="#example-19">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"foo"</span>).unwrap();
|
||
<span class="macro">assert_eq!</span>(<span class="number">1</span>, re.captures_len());
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"(foo)"</span>).unwrap();
|
||
<span class="macro">assert_eq!</span>(<span class="number">2</span>, re.captures_len());
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"(?<a>.(?<b>.))(.)(?:.)(?<c>.)"</span>).unwrap();
|
||
<span class="macro">assert_eq!</span>(<span class="number">5</span>, re.captures_len());
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"[a&&b]"</span>).unwrap();
|
||
<span class="macro">assert_eq!</span>(<span class="number">1</span>, re.captures_len());</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.static_captures_len" class="method"><h4 class="code-header">pub fn <a href="#method.static_captures_len" class="fn">static_captures_len</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>></h4></section></summary><div class="docblock"><p>Returns the total number of capturing groups that appear in every
|
||
possible match.</p>
|
||
<p>If the number of capture groups can vary depending on the match, then
|
||
this returns <code>None</code>. That is, a value is only returned when the number
|
||
of matching groups is invariant or “static.”</p>
|
||
<p>Note that like [<code>Regex::captures_len</code>], this <strong>does</strong> include the
|
||
implicit capturing group corresponding to the entire match. Therefore,
|
||
when a non-None value is returned, it is guaranteed to be at least <code>1</code>.
|
||
Stated differently, a return value of <code>Some(0)</code> is impossible.</p>
|
||
<h5 id="example-20"><a class="doc-anchor" href="#example-20">§</a>Example</h5>
|
||
<p>This shows a few cases where a static number of capture groups is
|
||
available and a few cases where it is not.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>len = |pattern| {
|
||
Regex::new(pattern).map(|re| re.static_captures_len())
|
||
};
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="number">1</span>), len(<span class="string">"a"</span>)<span class="question-mark">?</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="number">2</span>), len(<span class="string">"(a)"</span>)<span class="question-mark">?</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="number">2</span>), len(<span class="string">"(a)|(b)"</span>)<span class="question-mark">?</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="number">3</span>), len(<span class="string">"(a)(b)|(c)(d)"</span>)<span class="question-mark">?</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, len(<span class="string">"(a)|b"</span>)<span class="question-mark">?</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, len(<span class="string">"a|(b)"</span>)<span class="question-mark">?</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, len(<span class="string">"(b)*"</span>)<span class="question-mark">?</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="number">2</span>), len(<span class="string">"(b)+"</span>)<span class="question-mark">?</span>);
|
||
</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.capture_locations" class="method"><h4 class="code-header">pub fn <a href="#method.capture_locations" class="fn">capture_locations</a>(&self) -> CaptureLocations</h4></section></summary><div class="docblock"><p>Returns a fresh allocated set of capture locations that can
|
||
be reused in multiple calls to [<code>Regex::captures_read</code>] or
|
||
[<code>Regex::captures_read_at</code>].</p>
|
||
<p>The returned locations can be used for any subsequent search for this
|
||
particular regex. There is no guarantee that it is correct to use for
|
||
other regexes, even if they have the same number of capture groups.</p>
|
||
<h5 id="example-21"><a class="doc-anchor" href="#example-21">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex;
|
||
|
||
<span class="kw">let </span>re = Regex::new(<span class="string">r"(.)(.)(\w+)"</span>).unwrap();
|
||
<span class="kw">let </span><span class="kw-2">mut </span>locs = re.capture_locations();
|
||
<span class="macro">assert!</span>(re.captures_read(<span class="kw-2">&mut </span>locs, <span class="string">"Padron"</span>).is_some());
|
||
<span class="macro">assert_eq!</span>(locs.get(<span class="number">0</span>), <span class="prelude-val">Some</span>((<span class="number">0</span>, <span class="number">6</span>)));
|
||
<span class="macro">assert_eq!</span>(locs.get(<span class="number">1</span>), <span class="prelude-val">Some</span>((<span class="number">0</span>, <span class="number">1</span>)));
|
||
<span class="macro">assert_eq!</span>(locs.get(<span class="number">2</span>), <span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="number">2</span>)));
|
||
<span class="macro">assert_eq!</span>(locs.get(<span class="number">3</span>), <span class="prelude-val">Some</span>((<span class="number">2</span>, <span class="number">6</span>)));</code></pre></div></div></details></div></details><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-__Deref-for-NAME_PATTERN_REG" class="impl"><a class="src rightside" href="../../src/common_base/regex_pattern.rs.html#20-22">Source</a><a href="#impl-__Deref-for-NAME_PATTERN_REG" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a> for <a class="struct" href="struct.NAME_PATTERN_REG.html" title="struct common_base::regex_pattern::NAME_PATTERN_REG">NAME_PATTERN_REG</a></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Target" class="associatedtype trait-impl"><a class="src rightside" href="../../src/common_base/regex_pattern.rs.html#20-22">Source</a><a href="#associatedtype.Target" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html#associatedtype.Target" class="associatedtype">Target</a> = Regex</h4></section></summary><div class='docblock'>The resulting type after dereferencing.</div></details><details class="toggle method-toggle" open><summary><section id="method.deref" class="method trait-impl"><a class="src rightside" href="../../src/common_base/regex_pattern.rs.html#20-22">Source</a><a href="#method.deref" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html#tymethod.deref" class="fn">deref</a>(&self) -> &Regex</h4></section></summary><div class='docblock'>Dereferences the value.</div></details></div></details><section id="impl-LazyStatic-for-NAME_PATTERN_REG" class="impl"><a class="src rightside" href="../../src/common_base/regex_pattern.rs.html#20-22">Source</a><a href="#impl-LazyStatic-for-NAME_PATTERN_REG" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://docs.rs/lazy_static/1.5.0/lazy_static/trait.LazyStatic.html" title="trait lazy_static::LazyStatic">LazyStatic</a> for <a class="struct" href="struct.NAME_PATTERN_REG.html" title="struct common_base::regex_pattern::NAME_PATTERN_REG">NAME_PATTERN_REG</a></h3></section></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-NAME_PATTERN_REG" class="impl"><a href="#impl-Freeze-for-NAME_PATTERN_REG" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.NAME_PATTERN_REG.html" title="struct common_base::regex_pattern::NAME_PATTERN_REG">NAME_PATTERN_REG</a></h3></section><section id="impl-RefUnwindSafe-for-NAME_PATTERN_REG" class="impl"><a href="#impl-RefUnwindSafe-for-NAME_PATTERN_REG" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.NAME_PATTERN_REG.html" title="struct common_base::regex_pattern::NAME_PATTERN_REG">NAME_PATTERN_REG</a></h3></section><section id="impl-Send-for-NAME_PATTERN_REG" class="impl"><a href="#impl-Send-for-NAME_PATTERN_REG" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.NAME_PATTERN_REG.html" title="struct common_base::regex_pattern::NAME_PATTERN_REG">NAME_PATTERN_REG</a></h3></section><section id="impl-Sync-for-NAME_PATTERN_REG" class="impl"><a href="#impl-Sync-for-NAME_PATTERN_REG" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.NAME_PATTERN_REG.html" title="struct common_base::regex_pattern::NAME_PATTERN_REG">NAME_PATTERN_REG</a></h3></section><section id="impl-Unpin-for-NAME_PATTERN_REG" class="impl"><a href="#impl-Unpin-for-NAME_PATTERN_REG" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.NAME_PATTERN_REG.html" title="struct common_base::regex_pattern::NAME_PATTERN_REG">NAME_PATTERN_REG</a></h3></section><section id="impl-UnwindSafe-for-NAME_PATTERN_REG" class="impl"><a href="#impl-UnwindSafe-for-NAME_PATTERN_REG" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.NAME_PATTERN_REG.html" title="struct common_base::regex_pattern::NAME_PATTERN_REG">NAME_PATTERN_REG</a></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/nightly/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/nightly/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/nightly/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/nightly/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/nightly/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></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/nightly/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/nightly/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/nightly/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/nightly/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/nightly/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/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/nightly/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/nightly/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/nightly/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/nightly/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/nightly/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/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/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/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Conv-for-T" class="impl"><a href="#impl-Conv-for-T" class="anchor">§</a><h3 class="code-header">impl<T> Conv for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.conv" class="method trait-impl"><a href="#method.conv" class="anchor">§</a><h4 class="code-header">fn <a class="fn">conv</a><T>(self) -> T<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>,</div></h4></section></summary><div class='docblock'>Converts <code>self</code> into <code>T</code> using <code>Into<T></code>. <a>Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-FmtForward-for-T" class="impl"><a href="#impl-FmtForward-for-T" class="anchor">§</a><h3 class="code-header">impl<T> FmtForward for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt_binary" class="method trait-impl"><a href="#method.fmt_binary" class="anchor">§</a><h4 class="code-header">fn <a class="fn">fmt_binary</a>(self) -> FmtBinary<Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Binary.html" title="trait core::fmt::Binary">Binary</a>,</div></h4></section></summary><div class='docblock'>Causes <code>self</code> to use its <code>Binary</code> implementation when <code>Debug</code>-formatted.</div></details><details class="toggle method-toggle" open><summary><section id="method.fmt_display" class="method trait-impl"><a href="#method.fmt_display" class="anchor">§</a><h4 class="code-header">fn <a class="fn">fmt_display</a>(self) -> FmtDisplay<Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>,</div></h4></section></summary><div class='docblock'>Causes <code>self</code> to use its <code>Display</code> implementation when
|
||
<code>Debug</code>-formatted.</div></details><details class="toggle method-toggle" open><summary><section id="method.fmt_lower_exp" class="method trait-impl"><a href="#method.fmt_lower_exp" class="anchor">§</a><h4 class="code-header">fn <a class="fn">fmt_lower_exp</a>(self) -> FmtLowerExp<Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.LowerExp.html" title="trait core::fmt::LowerExp">LowerExp</a>,</div></h4></section></summary><div class='docblock'>Causes <code>self</code> to use its <code>LowerExp</code> implementation when
|
||
<code>Debug</code>-formatted.</div></details><details class="toggle method-toggle" open><summary><section id="method.fmt_lower_hex" class="method trait-impl"><a href="#method.fmt_lower_hex" class="anchor">§</a><h4 class="code-header">fn <a class="fn">fmt_lower_hex</a>(self) -> FmtLowerHex<Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.LowerHex.html" title="trait core::fmt::LowerHex">LowerHex</a>,</div></h4></section></summary><div class='docblock'>Causes <code>self</code> to use its <code>LowerHex</code> implementation when
|
||
<code>Debug</code>-formatted.</div></details><details class="toggle method-toggle" open><summary><section id="method.fmt_octal" class="method trait-impl"><a href="#method.fmt_octal" class="anchor">§</a><h4 class="code-header">fn <a class="fn">fmt_octal</a>(self) -> FmtOctal<Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Octal.html" title="trait core::fmt::Octal">Octal</a>,</div></h4></section></summary><div class='docblock'>Causes <code>self</code> to use its <code>Octal</code> implementation when <code>Debug</code>-formatted.</div></details><details class="toggle method-toggle" open><summary><section id="method.fmt_pointer" class="method trait-impl"><a href="#method.fmt_pointer" class="anchor">§</a><h4 class="code-header">fn <a class="fn">fmt_pointer</a>(self) -> FmtPointer<Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Pointer.html" title="trait core::fmt::Pointer">Pointer</a>,</div></h4></section></summary><div class='docblock'>Causes <code>self</code> to use its <code>Pointer</code> implementation when
|
||
<code>Debug</code>-formatted.</div></details><details class="toggle method-toggle" open><summary><section id="method.fmt_upper_exp" class="method trait-impl"><a href="#method.fmt_upper_exp" class="anchor">§</a><h4 class="code-header">fn <a class="fn">fmt_upper_exp</a>(self) -> FmtUpperExp<Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.UpperExp.html" title="trait core::fmt::UpperExp">UpperExp</a>,</div></h4></section></summary><div class='docblock'>Causes <code>self</code> to use its <code>UpperExp</code> implementation when
|
||
<code>Debug</code>-formatted.</div></details><details class="toggle method-toggle" open><summary><section id="method.fmt_upper_hex" class="method trait-impl"><a href="#method.fmt_upper_hex" class="anchor">§</a><h4 class="code-header">fn <a class="fn">fmt_upper_hex</a>(self) -> FmtUpperHex<Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.UpperHex.html" title="trait core::fmt::UpperHex">UpperHex</a>,</div></h4></section></summary><div class='docblock'>Causes <code>self</code> to use its <code>UpperHex</code> implementation when
|
||
<code>Debug</code>-formatted.</div></details><details class="toggle method-toggle" open><summary><section id="method.fmt_list" class="method trait-impl"><a href="#method.fmt_list" class="anchor">§</a><h4 class="code-header">fn <a class="fn">fmt_list</a>(self) -> FmtList<Self><div class="where">where
|
||
&'a Self: for<'a> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,</div></h4></section></summary><div class='docblock'>Formats each item in a sequence. <a>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/nightly/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/nightly/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/nightly/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/nightly/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/nightly/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/nightly/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/nightly/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/nightly/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/nightly/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/nightly/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-Pipe-for-T" class="impl"><a href="#impl-Pipe-for-T" class="anchor">§</a><h3 class="code-header">impl<T> Pipe for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/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.pipe" class="method trait-impl"><a href="#method.pipe" class="anchor">§</a><h4 class="code-header">fn <a class="fn">pipe</a><R>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(Self) -> R) -> R<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Pipes by value. This is generally the method you want to use. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.pipe_ref" class="method trait-impl"><a href="#method.pipe_ref" class="anchor">§</a><h4 class="code-header">fn <a class="fn">pipe_ref</a><'a, R>(&'a self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&'a Self) -> R) -> R<div class="where">where
|
||
R: 'a,</div></h4></section></summary><div class='docblock'>Borrows <code>self</code> and passes that borrow into the pipe function. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.pipe_ref_mut" class="method trait-impl"><a href="#method.pipe_ref_mut" class="anchor">§</a><h4 class="code-header">fn <a class="fn">pipe_ref_mut</a><'a, R>(&'a mut self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&'a mut Self) -> R) -> R<div class="where">where
|
||
R: 'a,</div></h4></section></summary><div class='docblock'>Mutably borrows <code>self</code> and passes that borrow into the pipe function. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.pipe_borrow" class="method trait-impl"><a href="#method.pipe_borrow" class="anchor">§</a><h4 class="code-header">fn <a class="fn">pipe_borrow</a><'a, B, R>(&'a self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a B</a>) -> R) -> R<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><B>,
|
||
B: 'a + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||
R: 'a,</div></h4></section></summary><div class='docblock'>Borrows <code>self</code>, then passes <code>self.borrow()</code> into the pipe function. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.pipe_borrow_mut" class="method trait-impl"><a href="#method.pipe_borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a class="fn">pipe_borrow_mut</a><'a, B, R>(
|
||
&'a mut self,
|
||
func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut B</a>) -> R,
|
||
) -> R<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><B>,
|
||
B: 'a + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||
R: 'a,</div></h4></section></summary><div class='docblock'>Mutably borrows <code>self</code>, then passes <code>self.borrow_mut()</code> into the pipe
|
||
function. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.pipe_as_ref" class="method trait-impl"><a href="#method.pipe_as_ref" class="anchor">§</a><h4 class="code-header">fn <a class="fn">pipe_as_ref</a><'a, U, R>(&'a self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a U</a>) -> R) -> R<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><U>,
|
||
U: 'a + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||
R: 'a,</div></h4></section></summary><div class='docblock'>Borrows <code>self</code>, then passes <code>self.as_ref()</code> into the pipe function.</div></details><details class="toggle method-toggle" open><summary><section id="method.pipe_as_mut" class="method trait-impl"><a href="#method.pipe_as_mut" class="anchor">§</a><h4 class="code-header">fn <a class="fn">pipe_as_mut</a><'a, U, R>(&'a mut self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut U</a>) -> R) -> R<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsMut.html" title="trait core::convert::AsMut">AsMut</a><U>,
|
||
U: 'a + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||
R: 'a,</div></h4></section></summary><div class='docblock'>Mutably borrows <code>self</code>, then passes <code>self.as_mut()</code> into the pipe
|
||
function.</div></details><details class="toggle method-toggle" open><summary><section id="method.pipe_deref" class="method trait-impl"><a href="#method.pipe_deref" class="anchor">§</a><h4 class="code-header">fn <a class="fn">pipe_deref</a><'a, T, R>(&'a self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a T</a>) -> R) -> R<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = T>,
|
||
T: 'a + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||
R: 'a,</div></h4></section></summary><div class='docblock'>Borrows <code>self</code>, then passes <code>self.deref()</code> into the pipe function.</div></details><details class="toggle method-toggle" open><summary><section id="method.pipe_deref_mut" class="method trait-impl"><a href="#method.pipe_deref_mut" class="anchor">§</a><h4 class="code-header">fn <a class="fn">pipe_deref_mut</a><'a, T, R>(
|
||
&'a mut self,
|
||
func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut T</a>) -> R,
|
||
) -> R<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.DerefMut.html" title="trait core::ops::deref::DerefMut">DerefMut</a><Target = T> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a>,
|
||
T: 'a + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||
R: 'a,</div></h4></section></summary><div class='docblock'>Mutably borrows <code>self</code>, then passes <code>self.deref_mut()</code> into the pipe
|
||
function.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Receiver-for-P" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/ops/deref.rs.html#378-380">Source</a><a href="#impl-Receiver-for-P" class="anchor">§</a><h3 class="code-header">impl<P, T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Receiver.html" title="trait core::ops::deref::Receiver">Receiver</a> for P<div class="where">where
|
||
P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = T> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Target-1" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/ops/deref.rs.html#382">Source</a><a href="#associatedtype.Target-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Receiver.html#associatedtype.Target" class="associatedtype">Target</a> = T</h4></section></summary><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span><span>This is a nightly-only experimental API. (<code>arbitrary_self_types</code>)</span></div></span><div class='docblock'>The target type on which the method may be called.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Tap-for-T" class="impl"><a href="#impl-Tap-for-T" class="anchor">§</a><h3 class="code-header">impl<T> Tap for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.tap" class="method trait-impl"><a href="#method.tap" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap</a>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&Self)) -> Self</h4></section></summary><div class='docblock'>Immutable access to a value. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.tap_mut" class="method trait-impl"><a href="#method.tap_mut" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_mut</a>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&mut Self)) -> Self</h4></section></summary><div class='docblock'>Mutable access to a value. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.tap_borrow" class="method trait-impl"><a href="#method.tap_borrow" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_borrow</a><B>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&B</a>)) -> Self<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><B>,
|
||
B: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Immutable access to the <code>Borrow<B></code> of a value. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.tap_borrow_mut" class="method trait-impl"><a href="#method.tap_borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_borrow_mut</a><B>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut B</a>)) -> Self<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><B>,
|
||
B: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Mutable access to the <code>BorrowMut<B></code> of a value. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.tap_ref" class="method trait-impl"><a href="#method.tap_ref" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_ref</a><R>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&R</a>)) -> Self<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><R>,
|
||
R: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Immutable access to the <code>AsRef<R></code> view of a value. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.tap_ref_mut" class="method trait-impl"><a href="#method.tap_ref_mut" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_ref_mut</a><R>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>)) -> Self<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsMut.html" title="trait core::convert::AsMut">AsMut</a><R>,
|
||
R: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Mutable access to the <code>AsMut<R></code> view of a value. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.tap_deref" class="method trait-impl"><a href="#method.tap_deref" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_deref</a><T>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&T</a>)) -> Self<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = T>,
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Immutable access to the <code>Deref::Target</code> of a value. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.tap_deref_mut" class="method trait-impl"><a href="#method.tap_deref_mut" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_deref_mut</a><T>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut T</a>)) -> Self<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.DerefMut.html" title="trait core::ops::deref::DerefMut">DerefMut</a><Target = T> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a>,
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Mutable access to the <code>Deref::Target</code> of a value. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.tap_dbg" class="method trait-impl"><a href="#method.tap_dbg" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_dbg</a>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&Self)) -> Self</h4></section></summary><div class='docblock'>Calls <code>.tap()</code> only in debug builds, and is erased in release builds.</div></details><details class="toggle method-toggle" open><summary><section id="method.tap_mut_dbg" class="method trait-impl"><a href="#method.tap_mut_dbg" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_mut_dbg</a>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&mut Self)) -> Self</h4></section></summary><div class='docblock'>Calls <code>.tap_mut()</code> only in debug builds, and is erased in release
|
||
builds.</div></details><details class="toggle method-toggle" open><summary><section id="method.tap_borrow_dbg" class="method trait-impl"><a href="#method.tap_borrow_dbg" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_borrow_dbg</a><B>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&B</a>)) -> Self<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><B>,
|
||
B: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Calls <code>.tap_borrow()</code> only in debug builds, and is erased in release
|
||
builds.</div></details><details class="toggle method-toggle" open><summary><section id="method.tap_borrow_mut_dbg" class="method trait-impl"><a href="#method.tap_borrow_mut_dbg" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_borrow_mut_dbg</a><B>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut B</a>)) -> Self<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><B>,
|
||
B: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Calls <code>.tap_borrow_mut()</code> only in debug builds, and is erased in release
|
||
builds.</div></details><details class="toggle method-toggle" open><summary><section id="method.tap_ref_dbg" class="method trait-impl"><a href="#method.tap_ref_dbg" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_ref_dbg</a><R>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&R</a>)) -> Self<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><R>,
|
||
R: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Calls <code>.tap_ref()</code> only in debug builds, and is erased in release
|
||
builds.</div></details><details class="toggle method-toggle" open><summary><section id="method.tap_ref_mut_dbg" class="method trait-impl"><a href="#method.tap_ref_mut_dbg" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_ref_mut_dbg</a><R>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>)) -> Self<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsMut.html" title="trait core::convert::AsMut">AsMut</a><R>,
|
||
R: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Calls <code>.tap_ref_mut()</code> only in debug builds, and is erased in release
|
||
builds.</div></details><details class="toggle method-toggle" open><summary><section id="method.tap_deref_dbg" class="method trait-impl"><a href="#method.tap_deref_dbg" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_deref_dbg</a><T>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&T</a>)) -> Self<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = T>,
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Calls <code>.tap_deref()</code> only in debug builds, and is erased in release
|
||
builds.</div></details><details class="toggle method-toggle" open><summary><section id="method.tap_deref_mut_dbg" class="method trait-impl"><a href="#method.tap_deref_mut_dbg" class="anchor">§</a><h4 class="code-header">fn <a class="fn">tap_deref_mut_dbg</a><T>(self, func: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut T</a>)) -> Self<div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.DerefMut.html" title="trait core::ops::deref::DerefMut">DerefMut</a><Target = T> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a>,
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Calls <code>.tap_deref_mut()</code> only in debug builds, and is erased in release
|
||
builds.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryConv-for-T" class="impl"><a href="#impl-TryConv-for-T" class="anchor">§</a><h3 class="code-header">impl<T> TryConv for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.try_conv" class="method trait-impl"><a href="#method.try_conv" class="anchor">§</a><h4 class="code-header">fn <a class="fn">try_conv</a><T>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, Self::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error" title="type core::convert::TryInto::Error">Error</a>><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><T>,</div></h4></section></summary><div class='docblock'>Attempts to convert <code>self</code> into <code>T</code> using <code>TryInto<T></code>. <a>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/nightly/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/nightly/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/nightly/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/nightly/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/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/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/nightly/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/nightly/core/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/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/nightly/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/nightly/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/nightly/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/nightly/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/nightly/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/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/nightly/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/nightly/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/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><section id="impl-Any-for-T-1" class="impl"><a href="#impl-Any-for-T-1" class="anchor">§</a><h3 class="code-header">impl<T> Any for T<div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a>,</div></h3></section></div></section></div></main></body></html> |