1191 lines
234 KiB
HTML
1191 lines
234 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 `MOBILE_CSS` struct in crate `pages`."><meta name="keywords" content="rust, rustlang, rust-lang, MOBILE_CSS"><title>MOBILE_CSS in pages::static_assets::static_files::assets - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../main.js"></script><noscript><link rel="stylesheet" href="../../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../../favicon.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../../../../pages/index.html"><div class="logo-container"><img class="rust-logo" src="../../../../rust-logo.svg" alt="logo"></div>
|
|||
|
</a><h2 class="location"></h2>
|
|||
|
</nav>
|
|||
|
<nav class="sidebar"><a class="sidebar-logo" href="../../../../pages/index.html"><div class="logo-container"><img class="rust-logo" src="../../../../rust-logo.svg" alt="logo"></div>
|
|||
|
</a><h2 class="location"><a href="#">MOBILE_CSS</a></h2><div class="sidebar-elems"><section><div class="block"><h3 class="sidebar-title"><a href="#fields">Fields</a></h3><ul><li><a href="#structfield.__private_field">__private_field</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#deref-methods-%26%27static%20str">Methods from Deref<Target=&'static str></a></h3><ul><li><a href="#method.as_bytes">as_bytes</a></li><li><a href="#method.as_ptr">as_ptr</a></li><li><a href="#method.bytes">bytes</a></li><li><a href="#method.ceil_char_boundary">ceil_char_boundary</a></li><li><a href="#method.char_indices">char_indices</a></li><li><a href="#method.chars">chars</a></li><li><a href="#method.contains">contains</a></li><li><a href="#method.encode_utf16">encode_utf16</a></li><li><a href="#method.ends_with">ends_with</a></li><li><a href="#method.eq_ignore_ascii_case">eq_ignore_ascii_case</a></li><li><a href="#method.escape_debug">escape_debug</a></li><li><a href="#method.escape_default">escape_default</a></li><li><a href="#method.escape_unicode">escape_unicode</a></li><li><a href="#method.find">find</a></li><li><a href="#method.floor_char_boundary">floor_char_boundary</a></li><li><a href="#method.get">get</a></li><li><a href="#method.get_unchecked">get_unchecked</a></li><li><a href="#method.is_ascii">is_ascii</a></li><li><a href="#method.is_char_boundary">is_char_boundary</a></li><li><a href="#method.is_empty">is_empty</a></li><li><a href="#method.len">len</a></li><li><a href="#method.lines">lines</a></li><li><a href="#method.lines_any">lines_any</a></li><li><a href="#method.match_indices">match_indices</a></li><li><a href="#method.matches">matches</a></li><li><a href="#method.parse">parse</a></li><li><a href="#method.repeat">repeat</a></li><li><a href="#method.replace">replace</a></li><li><a href="#method.replacen">replacen</a></li><li><a href="#method.rfind">rfind</a></li><li><a href="#method.rmatch_indices">rmatch_indices</a></li><li><a href="#method.rmatches">rmatches</a></li><li><a href="#method.rsplit">rsplit</a></li><li><a href="#method.rsplit_once">rsplit_once</a></li><li><a href="#method.rsplit_terminator">rsplit_terminator</a></li><li><a href="#method.rsplitn">rsplitn</a></li><li><a href="#method.slice_unchecked">slice_unchecked</a></li><li><a href="#method.split">split</a></li><li><a href="#method.split_ascii_whitespace">split_ascii_whitespace</a></li><li><a href="#method.split_at">split_at</a></li><li><a href="#method.split_inclusive">split_inclusive</a></li><li><a href="#method.split_once">split_once</a></li><li><a href="#method.split_terminator">split_terminator</a></li><li><a href="#method.split_whitespace">split_whitespace</a></li><li><a href="#method.splitn">splitn</a></li><li><a href="#method.starts_with">starts_with</a></li><li><a href="#method.strip_prefix">strip_prefix</a></li><li><a href="#method.strip_suffix">strip_suffix</a></li><li><a href="#method.to_ascii_lowercase">to_ascii_lowercase</a></li><li><a href="#method.to_ascii_uppercase">to_ascii_uppercase</a></li><li><a href="#method.to_lowercase">to_lowercase</a></li><li><a href="#method.to_uppercase">to_uppercase</a></li><li><a href="#method.trim">trim</a></li><li><a href="#method.trim_end">trim_end</a></li><li><a href="#method.trim_end_matches">trim_end_matches</a></li><li><a href="#method.trim_left">trim_left</a></li><li><a href="#method.trim_left_matches">trim_left_matches</a></li><li><a href="#method.trim_matches">trim_matches</a></li><li><a href="#method.trim_right">trim_right</a></li><li><a href="#method.trim_right_matches">trim_right_matches</a></li><li><a href="#method.trim_start">trim_start</a></li><li><a href="#method.trim_start_matches">trim_start_matches</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#trait-implementations">Trait Implementations</a></h3><ul><li><a href="#impl-Deref">Deref</a></li><li><a href="#impl-LazyStatic">LazyStatic</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul><
|
|||
|
<a href="../../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../../wheel.svg"></a></div>
|
|||
|
</div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
|
|||
|
<h1 class="fqn"><span class="in-band">Struct <a href="../../../index.html">pages</a>::<wbr><a href="../../index.html">static_assets</a>::<wbr><a href="../index.html">static_files</a>::<wbr><a href="index.html">assets</a>::<wbr><a class="struct" href="#">MOBILE_CSS</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../../../../src/pages/static_assets/static_files.rs.html#30-34">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="docblock item-decl"><pre class="rust struct"><code>pub struct MOBILE_CSS {
|
|||
|
__private_field: <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.unit.html">()</a>,
|
|||
|
}</code></pre></div><h2 id="fields" class="fields small-section-header">Fields<a href="#fields" class="anchor"></a></h2><span id="structfield.__private_field" class="structfield small-section-header"><a href="#structfield.__private_field" class="anchor field"></a><code>__private_field: <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.unit.html">()</a></code></span><h2 id="deref-methods-%26%27static%20str" class="small-section-header"><span>Methods from <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = &'static <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>></span><a href="#deref-methods-%26%27static%20str" class="anchor"></a></h2><div id="deref-methods-%26%27static%20str-1"><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.len" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#157">source</a></span><a href="#method.len" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.len" class="fnname">len</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the length of <code>self</code>.</p>
|
|||
|
<p>This length is in bytes, not <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s or graphemes. In other words,
|
|||
|
it might not be what a human considers the length of the string.</p>
|
|||
|
<h5 id="examples"><a href="#examples">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">len</span> <span class="op">=</span> <span class="string">"foo"</span>.<span class="ident">len</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="number">3</span>, <span class="ident">len</span>);
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"ƒoo"</span>.<span class="ident">len</span>(), <span class="number">4</span>); <span class="comment">// fancy f!</span>
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"ƒoo"</span>.<span class="ident">chars</span>().<span class="ident">count</span>(), <span class="number">3</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_empty" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#178">source</a></span><a href="#method.is_empty" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.is_empty" class="fnname">is_empty</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if <code>self</code> has a length of zero bytes.</p>
|
|||
|
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">""</span>;
|
|||
|
<span class="macro">assert!</span>(<span class="ident">s</span>.<span class="ident">is_empty</span>());
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"not empty"</span>;
|
|||
|
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">s</span>.<span class="ident">is_empty</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_char_boundary" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.9.0">1.9.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#209">source</a></span><a href="#method.is_char_boundary" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.is_char_boundary" class="fnname">is_char_boundary</a>(&self, index: <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Checks that <code>index</code>-th byte is the first byte in a UTF-8 code point
|
|||
|
sequence or the end of the string.</p>
|
|||
|
<p>The start and end of the string (when <code>index == self.len()</code>) are
|
|||
|
considered to be boundaries.</p>
|
|||
|
<p>Returns <code>false</code> if <code>index</code> is greater than <code>self.len()</code>.</p>
|
|||
|
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"Löwe 老虎 Léopard"</span>;
|
|||
|
<span class="macro">assert!</span>(<span class="ident">s</span>.<span class="ident">is_char_boundary</span>(<span class="number">0</span>));
|
|||
|
<span class="comment">// start of `老`</span>
|
|||
|
<span class="macro">assert!</span>(<span class="ident">s</span>.<span class="ident">is_char_boundary</span>(<span class="number">6</span>));
|
|||
|
<span class="macro">assert!</span>(<span class="ident">s</span>.<span class="ident">is_char_boundary</span>(<span class="ident">s</span>.<span class="ident">len</span>()));
|
|||
|
|
|||
|
<span class="comment">// second byte of `ö`</span>
|
|||
|
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">s</span>.<span class="ident">is_char_boundary</span>(<span class="number">2</span>));
|
|||
|
|
|||
|
<span class="comment">// third byte of `老`</span>
|
|||
|
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">s</span>.<span class="ident">is_char_boundary</span>(<span class="number">8</span>));</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.floor_char_boundary" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#256">source</a></span><a href="#method.floor_char_boundary" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.floor_char_boundary" class="fnname">floor_char_boundary</a>(&self, index: <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>round_char_boundary</code>)</div></span></summary><div class="docblock"><p>Finds the closest <code>x</code> not exceeding <code>index</code> where <code>is_char_boundary(x)</code> is <code>true</code>.</p>
|
|||
|
<p>This method can help you truncate a string so that it’s still valid UTF-8, but doesn’t
|
|||
|
exceed a given number of bytes. Note that this is done purely at the character level
|
|||
|
and can still visually split graphemes, even though the underlying characters aren’t
|
|||
|
split. For example, the emoji 🧑🔬 (scientist) could be split so that the string only
|
|||
|
includes 🧑 (person) instead.</p>
|
|||
|
<h5 id="examples-3"><a href="#examples-3">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">round_char_boundary</span>)]</span>
|
|||
|
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"❤️🧡💛💚💙💜"</span>;
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">len</span>(), <span class="number">26</span>);
|
|||
|
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">s</span>.<span class="ident">is_char_boundary</span>(<span class="number">13</span>));
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">closest</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">floor_char_boundary</span>(<span class="number">13</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">closest</span>, <span class="number">10</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span><span class="ident">s</span>[..<span class="ident">closest</span>], <span class="string">"❤️🧡"</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ceil_char_boundary" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#295">source</a></span><a href="#method.ceil_char_boundary" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.ceil_char_boundary" class="fnname">ceil_char_boundary</a>(&self, index: <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>round_char_boundary</code>)</div></span></summary><div class="docblock"><p>Finds the closest <code>x</code> not below <code>index</code> where <code>is_char_boundary(x)</code> is <code>true</code>.</p>
|
|||
|
<p>This method is the natural complement to <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.floor_char_boundary"><code>floor_char_boundary</code></a>. See that method
|
|||
|
for more details.</p>
|
|||
|
<h5 id="panics"><a href="#panics">Panics</a></h5>
|
|||
|
<p>Panics if <code>index > self.len()</code>.</p>
|
|||
|
<h5 id="examples-4"><a href="#examples-4">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">round_char_boundary</span>)]</span>
|
|||
|
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"❤️🧡💛💚💙💜"</span>;
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">len</span>(), <span class="number">26</span>);
|
|||
|
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">s</span>.<span class="ident">is_char_boundary</span>(<span class="number">13</span>));
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">closest</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">ceil_char_boundary</span>(<span class="number">13</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">closest</span>, <span class="number">14</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span><span class="ident">s</span>[..<span class="ident">closest</span>], <span class="string">"❤️🧡💛"</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_bytes" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#323">source</a></span><a href="#method.as_bytes" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_bytes" class="fnname">as_bytes</a>(&self) -> &[<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.u8.html">u8</a>]<span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for &[<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.u8.html">u8</a>]</span><code class="content"><span class="where fmt-newline">impl<'_> <a class="trait" href="https://doc.rust-lang.org/1.63.0/std/io/trait.Read.html" title="trait std::io::Read">Read</a> for &[<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.u8.html">u8</a>]</span><span class="where fmt-newline">impl<'_> <a class="trait" href="https://doc.rust-lang.org/1.63.0/std/io/trait.Write.html" title="trait std::io::Write">Write</a> for &mut [<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.u8.html">u8</a>]</span></code></span></span></span></span></h4></section></summary><div class="docblock"><p>Converts a string slice to a byte slice. To convert the byte slice back
|
|||
|
into a string slice, use the <a href="https://doc.rust-lang.org/1.63.0/core/str/converts/fn.from_utf8.html" title="from_utf8"><code>from_utf8</code></a> function.</p>
|
|||
|
<h5 id="examples-5"><a href="#examples-5">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="string">"bors"</span>.<span class="ident">as_bytes</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">b"bors"</span>, <span class="ident">bytes</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_ptr" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#398">source</a></span><a href="#method.as_ptr" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_ptr" class="fnname">as_ptr</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.pointer.html">*const </a><a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.u8.html">u8</a></h4></section></summary><div class="docblock"><p>Converts a string slice to a raw pointer.</p>
|
|||
|
<p>As string slices are a slice of bytes, the raw pointer points to a
|
|||
|
<a href="https://doc.rust-lang.org/1.63.0/std/primitive.u8.html" title="u8"><code>u8</code></a>. This pointer will be pointing to the first byte of the string
|
|||
|
slice.</p>
|
|||
|
<p>The caller must ensure that the returned pointer is never written to.
|
|||
|
If you need to mutate the contents of the string slice, use <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.as_mut_ptr"><code>as_mut_ptr</code></a>.</p>
|
|||
|
<h5 id="examples-6"><a href="#examples-6">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"Hello"</span>;
|
|||
|
<span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">as_ptr</span>();</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.get" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.20.0">1.20.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#439">source</a></span><a href="#method.get" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.get" class="fnname">get</a><I>(&self, i: I) -> <a class="enum" href="https://doc.rust-lang.org/1.63.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<I as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/slice/index/trait.SliceIndex.html#associatedtype.Output" title="type core::slice::index::SliceIndex::Output">Output</a>> <span class="where fmt-newline">where<br> I: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>>, </span></h4></section></summary><div class="docblock"><p>Returns a subslice of <code>str</code>.</p>
|
|||
|
<p>This is the non-panicking alternative to indexing the <code>str</code>. Returns
|
|||
|
<a href="https://doc.rust-lang.org/1.63.0/core/option/enum.Option.html#variant.None" title="None"><code>None</code></a> whenever equivalent indexing operation would panic.</p>
|
|||
|
<h5 id="examples-7"><a href="#examples-7">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="ident">String::from</span>(<span class="string">"🗻∈🌏"</span>);
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"🗻"</span>), <span class="ident">v</span>.<span class="ident">get</span>(<span class="number">0</span>..<span class="number">4</span>));
|
|||
|
|
|||
|
<span class="comment">// indices not on UTF-8 sequence boundaries</span>
|
|||
|
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">get</span>(<span class="number">1</span>..).<span class="ident">is_none</span>());
|
|||
|
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">get</span>(..<span class="number">8</span>).<span class="ident">is_none</span>());
|
|||
|
|
|||
|
<span class="comment">// out of bounds</span>
|
|||
|
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">get</span>(..<span class="number">42</span>).<span class="ident">is_none</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.get_unchecked" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.20.0">1.20.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#505">source</a></span><a href="#method.get_unchecked" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.get_unchecked" class="fnname">get_unchecked</a><I>(&self, i: I) -> &<I as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/slice/index/trait.SliceIndex.html#associatedtype.Output" title="type core::slice::index::SliceIndex::Output">Output</a> <span class="where fmt-newline">where<br> I: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>>, </span></h4></section></summary><div class="docblock"><p>Returns an unchecked subslice of <code>str</code>.</p>
|
|||
|
<p>This is the unchecked alternative to indexing the <code>str</code>.</p>
|
|||
|
<h5 id="safety"><a href="#safety">Safety</a></h5>
|
|||
|
<p>Callers of this function are responsible that these preconditions are
|
|||
|
satisfied:</p>
|
|||
|
<ul>
|
|||
|
<li>The starting index must not exceed the ending index;</li>
|
|||
|
<li>Indexes must be within bounds of the original slice;</li>
|
|||
|
<li>Indexes must lie on UTF-8 sequence boundaries.</li>
|
|||
|
</ul>
|
|||
|
<p>Failing that, the returned string slice may reference invalid memory or
|
|||
|
violate the invariants communicated by the <code>str</code> type.</p>
|
|||
|
<h5 id="examples-8"><a href="#examples-8">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="string">"🗻∈🌏"</span>;
|
|||
|
<span class="kw">unsafe</span> {
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"🗻"</span>, <span class="ident">v</span>.<span class="ident">get_unchecked</span>(<span class="number">0</span>..<span class="number">4</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"∈"</span>, <span class="ident">v</span>.<span class="ident">get_unchecked</span>(<span class="number">4</span>..<span class="number">7</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"🌏"</span>, <span class="ident">v</span>.<span class="ident">get_unchecked</span>(<span class="number">7</span>..<span class="number">11</span>));
|
|||
|
}</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.slice_unchecked" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#597">source</a></span><a href="#method.slice_unchecked" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.slice_unchecked" class="fnname">slice_unchecked</a>(&self, begin: <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a>, end: <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a>) -> &<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span> Deprecated since 1.29.0: <p>use <code>get_unchecked(begin..end)</code> instead</p>
|
|||
|
</div></span></summary><div class="docblock"><p>Creates a string slice from another string slice, bypassing safety
|
|||
|
checks.</p>
|
|||
|
<p>This is generally not recommended, use with caution! For a safe
|
|||
|
alternative see <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html" title="str"><code>str</code></a> and <a href="https://doc.rust-lang.org/1.63.0/core/ops/index/trait.Index.html"><code>Index</code></a>.</p>
|
|||
|
<p>This new slice goes from <code>begin</code> to <code>end</code>, including <code>begin</code> but
|
|||
|
excluding <code>end</code>.</p>
|
|||
|
<p>To get a mutable string slice instead, see the
|
|||
|
<a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.slice_mut_unchecked"><code>slice_mut_unchecked</code></a> method.</p>
|
|||
|
<h5 id="safety-1"><a href="#safety-1">Safety</a></h5>
|
|||
|
<p>Callers of this function are responsible that three preconditions are
|
|||
|
satisfied:</p>
|
|||
|
<ul>
|
|||
|
<li><code>begin</code> must not exceed <code>end</code>.</li>
|
|||
|
<li><code>begin</code> and <code>end</code> must be byte positions within the string slice.</li>
|
|||
|
<li><code>begin</code> and <code>end</code> must lie on UTF-8 sequence boundaries.</li>
|
|||
|
</ul>
|
|||
|
<h5 id="examples-9"><a href="#examples-9">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"Löwe 老虎 Léopard"</span>;
|
|||
|
|
|||
|
<span class="kw">unsafe</span> {
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"Löwe 老虎 Léopard"</span>, <span class="ident">s</span>.<span class="ident">slice_unchecked</span>(<span class="number">0</span>, <span class="number">21</span>));
|
|||
|
}
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"Hello, world!"</span>;
|
|||
|
|
|||
|
<span class="kw">unsafe</span> {
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"world"</span>, <span class="ident">s</span>.<span class="ident">slice_unchecked</span>(<span class="number">7</span>, <span class="number">12</span>));
|
|||
|
}</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split_at" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.4.0">1.4.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#670">source</a></span><a href="#method.split_at" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_at" class="fnname">split_at</a>(&self, mid: <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a>) -> (&<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>, &<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>)</h4></section></summary><div class="docblock"><p>Divide one string slice into two at an index.</p>
|
|||
|
<p>The argument, <code>mid</code>, should be a byte offset from the start of the
|
|||
|
string. It must also be on the boundary of a UTF-8 code point.</p>
|
|||
|
<p>The two slices returned go from the start of the string slice to <code>mid</code>,
|
|||
|
and from <code>mid</code> to the end of the string slice.</p>
|
|||
|
<p>To get mutable string slices instead, see the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.split_at_mut"><code>split_at_mut</code></a>
|
|||
|
method.</p>
|
|||
|
<h5 id="panics-1"><a href="#panics-1">Panics</a></h5>
|
|||
|
<p>Panics if <code>mid</code> is not on a UTF-8 code point boundary, or if it is
|
|||
|
past the end of the last code point of the string slice.</p>
|
|||
|
<h5 id="examples-10"><a href="#examples-10">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"Per Martin-Löf"</span>;
|
|||
|
|
|||
|
<span class="kw">let</span> (<span class="ident">first</span>, <span class="ident">last</span>) <span class="op">=</span> <span class="ident">s</span>.<span class="ident">split_at</span>(<span class="number">3</span>);
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"Per"</span>, <span class="ident">first</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">" Martin-Löf"</span>, <span class="ident">last</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.chars" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#780">source</a></span><a href="#method.chars" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.chars" class="fnname">chars</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.Chars.html" title="struct core::str::iter::Chars">Chars</a><'_></h4></section></summary><div class="docblock"><p>Returns an iterator over the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s of a string slice.</p>
|
|||
|
<p>As a string slice consists of valid UTF-8, we can iterate through a
|
|||
|
string slice by <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>. This method returns such an iterator.</p>
|
|||
|
<p>It’s important to remember that <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a> represents a Unicode Scalar
|
|||
|
Value, and might not match your idea of what a ‘character’ is. Iteration
|
|||
|
over grapheme clusters may be what you actually want. This functionality
|
|||
|
is not provided by Rust’s standard library, check crates.io instead.</p>
|
|||
|
<h5 id="examples-11"><a href="#examples-11">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">word</span> <span class="op">=</span> <span class="string">"goodbye"</span>;
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">count</span> <span class="op">=</span> <span class="ident">word</span>.<span class="ident">chars</span>().<span class="ident">count</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="number">7</span>, <span class="ident">count</span>);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">chars</span> <span class="op">=</span> <span class="ident">word</span>.<span class="ident">chars</span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">'g'</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">'o'</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">'o'</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">'d'</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">'b'</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">'y'</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">'e'</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">chars</span>.<span class="ident">next</span>());</code></pre></div>
|
|||
|
<p>Remember, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s might not match your intuition about characters:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="string">"y̆"</span>;
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">chars</span> <span class="op">=</span> <span class="ident">y</span>.<span class="ident">chars</span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">'y'</span>), <span class="ident">chars</span>.<span class="ident">next</span>()); <span class="comment">// not 'y̆'</span>
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">'\u{0306}'</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">chars</span>.<span class="ident">next</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.char_indices" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#837">source</a></span><a href="#method.char_indices" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.char_indices" class="fnname">char_indices</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.CharIndices.html" title="struct core::str::iter::CharIndices">CharIndices</a><'_></h4></section></summary><div class="docblock"><p>Returns an iterator over the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s of a string slice, and their
|
|||
|
positions.</p>
|
|||
|
<p>As a string slice consists of valid UTF-8, we can iterate through a
|
|||
|
string slice by <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>. This method returns an iterator of both
|
|||
|
these <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, as well as their byte positions.</p>
|
|||
|
<p>The iterator yields tuples. The position is first, the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a> is
|
|||
|
second.</p>
|
|||
|
<h5 id="examples-12"><a href="#examples-12">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">word</span> <span class="op">=</span> <span class="string">"goodbye"</span>;
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">count</span> <span class="op">=</span> <span class="ident">word</span>.<span class="ident">char_indices</span>().<span class="ident">count</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="number">7</span>, <span class="ident">count</span>);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">char_indices</span> <span class="op">=</span> <span class="ident">word</span>.<span class="ident">char_indices</span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">0</span>, <span class="string">'g'</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="string">'o'</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">2</span>, <span class="string">'o'</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">3</span>, <span class="string">'d'</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">4</span>, <span class="string">'b'</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">5</span>, <span class="string">'y'</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">6</span>, <span class="string">'e'</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">char_indices</span>.<span class="ident">next</span>());</code></pre></div>
|
|||
|
<p>Remember, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s might not match your intuition about characters:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">yes</span> <span class="op">=</span> <span class="string">"y̆es"</span>;
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">char_indices</span> <span class="op">=</span> <span class="ident">yes</span>.<span class="ident">char_indices</span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">0</span>, <span class="string">'y'</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>()); <span class="comment">// not (0, 'y̆')</span>
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="string">'\u{0306}'</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="comment">// note the 3 here - the last character took up two bytes</span>
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">3</span>, <span class="string">'e'</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">4</span>, <span class="string">'s'</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">char_indices</span>.<span class="ident">next</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.bytes" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#862">source</a></span><a href="#method.bytes" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.bytes" class="fnname">bytes</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.Bytes.html" title="struct core::str::iter::Bytes">Bytes</a><'_></h4></section></summary><div class="docblock"><p>An iterator over the bytes of a string slice.</p>
|
|||
|
<p>As a string slice consists of a sequence of bytes, we can iterate
|
|||
|
through a string slice by byte. This method returns such an iterator.</p>
|
|||
|
<h5 id="examples-13"><a href="#examples-13">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="string">"bors"</span>.<span class="ident">bytes</span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">b'b'</span>), <span class="ident">bytes</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">b'o'</span>), <span class="ident">bytes</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">b'r'</span>), <span class="ident">bytes</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">b's'</span>), <span class="ident">bytes</span>.<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">bytes</span>.<span class="ident">next</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split_whitespace" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.1.0">1.1.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#908">source</a></span><a href="#method.split_whitespace" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_whitespace" class="fnname">split_whitespace</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.SplitWhitespace.html" title="struct core::str::iter::SplitWhitespace">SplitWhitespace</a><'_></h4></section></summary><div class="docblock"><p>Splits a string slice by whitespace.</p>
|
|||
|
<p>The iterator returned will return string slices that are sub-slices of
|
|||
|
the original string slice, separated by any amount of whitespace.</p>
|
|||
|
<p>‘Whitespace’ is defined according to the terms of the Unicode Derived
|
|||
|
Core Property <code>White_Space</code>. If you only want to split on ASCII whitespace
|
|||
|
instead, use <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.split_ascii_whitespace"><code>split_ascii_whitespace</code></a>.</p>
|
|||
|
<h5 id="examples-14"><a href="#examples-14">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="string">"A few words"</span>.<span class="ident">split_whitespace</span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"A"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"few"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"words"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">iter</span>.<span class="ident">next</span>());</code></pre></div>
|
|||
|
<p>All kinds of whitespace are considered:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="string">" Mary had\ta\u{2009}little \n\t lamb"</span>.<span class="ident">split_whitespace</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"Mary"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"had"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"a"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"little"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"lamb"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">iter</span>.<span class="ident">next</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split_ascii_whitespace" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.34.0">1.34.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#951">source</a></span><a href="#method.split_ascii_whitespace" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_ascii_whitespace" class="fnname">split_ascii_whitespace</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.SplitAsciiWhitespace.html" title="struct core::str::iter::SplitAsciiWhitespace">SplitAsciiWhitespace</a><'_></h4></section></summary><div class="docblock"><p>Splits a string slice by ASCII whitespace.</p>
|
|||
|
<p>The iterator returned will return string slices that are sub-slices of
|
|||
|
the original string slice, separated by any amount of ASCII whitespace.</p>
|
|||
|
<p>To split by Unicode <code>Whitespace</code> instead, use <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.split_whitespace"><code>split_whitespace</code></a>.</p>
|
|||
|
<h5 id="examples-15"><a href="#examples-15">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="string">"A few words"</span>.<span class="ident">split_ascii_whitespace</span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"A"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"few"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"words"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">iter</span>.<span class="ident">next</span>());</code></pre></div>
|
|||
|
<p>All kinds of ASCII whitespace are considered:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="string">" Mary had\ta little \n\t lamb"</span>.<span class="ident">split_ascii_whitespace</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"Mary"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"had"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"a"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"little"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"lamb"</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">iter</span>.<span class="ident">next</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.lines" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#997">source</a></span><a href="#method.lines" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.lines" class="fnname">lines</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.Lines.html" title="struct core::str::iter::Lines">Lines</a><'_></h4></section></summary><div class="docblock"><p>An iterator over the lines of a string, as string slices.</p>
|
|||
|
<p>Lines are ended with either a newline (<code>\n</code>) or a carriage return with
|
|||
|
a line feed (<code>\r\n</code>).</p>
|
|||
|
<p>The final line ending is optional. A string that ends with a final line
|
|||
|
ending will return the same lines as an otherwise identical string
|
|||
|
without a final line ending.</p>
|
|||
|
<h5 id="examples-16"><a href="#examples-16">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">text</span> <span class="op">=</span> <span class="string">"foo\r\nbar\n\nbaz\n"</span>;
|
|||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">lines</span> <span class="op">=</span> <span class="ident">text</span>.<span class="ident">lines</span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"foo"</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"bar"</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">""</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"baz"</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">lines</span>.<span class="ident">next</span>());</code></pre></div>
|
|||
|
<p>The final line ending isn’t required:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">text</span> <span class="op">=</span> <span class="string">"foo\nbar\n\r\nbaz"</span>;
|
|||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">lines</span> <span class="op">=</span> <span class="ident">text</span>.<span class="ident">lines</span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"foo"</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"bar"</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">""</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"baz"</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">lines</span>.<span class="ident">next</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.lines_any" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1006">source</a></span><a href="#method.lines_any" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.lines_any" class="fnname">lines_any</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.LinesAny.html" title="struct core::str::iter::LinesAny">LinesAny</a><'_></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span> Deprecated since 1.4.0: <p>use lines() instead now</p>
|
|||
|
</div></span></summary><div class="docblock"><p>An iterator over the lines of a string.</p>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.encode_utf16" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.8.0">1.8.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1027">source</a></span><a href="#method.encode_utf16" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.encode_utf16" class="fnname">encode_utf16</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.EncodeUtf16.html" title="struct core::str::iter::EncodeUtf16">EncodeUtf16</a><'_></h4></section></summary><div class="docblock"><p>Returns an iterator of <code>u16</code> over the string encoded as UTF-16.</p>
|
|||
|
<h5 id="examples-17"><a href="#examples-17">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">text</span> <span class="op">=</span> <span class="string">"Zażółć gęślą jaźń"</span>;
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">utf8_len</span> <span class="op">=</span> <span class="ident">text</span>.<span class="ident">len</span>();
|
|||
|
<span class="kw">let</span> <span class="ident">utf16_len</span> <span class="op">=</span> <span class="ident">text</span>.<span class="ident">encode_utf16</span>().<span class="ident">count</span>();
|
|||
|
|
|||
|
<span class="macro">assert!</span>(<span class="ident">utf16_len</span> <span class="op"><</span><span class="op">=</span> <span class="ident">utf8_len</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.contains" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1054">source</a></span><a href="#method.contains" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.contains" class="fnname">contains</a><'a, P>(&'a self, pat: P) -> <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the given pattern matches a sub-slice of
|
|||
|
this string slice.</p>
|
|||
|
<p>Returns <code>false</code> if it does not.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="examples-18"><a href="#examples-18">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">bananas</span> <span class="op">=</span> <span class="string">"bananas"</span>;
|
|||
|
|
|||
|
<span class="macro">assert!</span>(<span class="ident">bananas</span>.<span class="ident">contains</span>(<span class="string">"nana"</span>));
|
|||
|
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">bananas</span>.<span class="ident">contains</span>(<span class="string">"apples"</span>));</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.starts_with" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1080">source</a></span><a href="#method.starts_with" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.starts_with" class="fnname">starts_with</a><'a, P>(&'a self, pat: P) -> <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the given pattern matches a prefix of this
|
|||
|
string slice.</p>
|
|||
|
<p>Returns <code>false</code> if it does not.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="examples-19"><a href="#examples-19">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">bananas</span> <span class="op">=</span> <span class="string">"bananas"</span>;
|
|||
|
|
|||
|
<span class="macro">assert!</span>(<span class="ident">bananas</span>.<span class="ident">starts_with</span>(<span class="string">"bana"</span>));
|
|||
|
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">bananas</span>.<span class="ident">starts_with</span>(<span class="string">"nana"</span>));</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ends_with" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1106-1108">source</a></span><a href="#method.ends_with" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.ends_with" class="fnname">ends_with</a><'a, P>(&'a self, pat: P) -> <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>,<br> <P as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type core::str::pattern::Pattern::Searcher">Searcher</a>: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.ReverseSearcher.html" title="trait core::str::pattern::ReverseSearcher">ReverseSearcher</a><'a>, </span></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the given pattern matches a suffix of this
|
|||
|
string slice.</p>
|
|||
|
<p>Returns <code>false</code> if it does not.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="examples-20"><a href="#examples-20">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">bananas</span> <span class="op">=</span> <span class="string">"bananas"</span>;
|
|||
|
|
|||
|
<span class="macro">assert!</span>(<span class="ident">bananas</span>.<span class="ident">ends_with</span>(<span class="string">"anas"</span>));
|
|||
|
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">bananas</span>.<span class="ident">ends_with</span>(<span class="string">"nana"</span>));</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.find" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1157">source</a></span><a href="#method.find" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.find" class="fnname">find</a><'a, P>(&'a self, pat: P) -> <a class="enum" href="https://doc.rust-lang.org/1.63.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a>> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>Returns the byte index of the first character of this string slice that
|
|||
|
matches the pattern.</p>
|
|||
|
<p>Returns <a href="https://doc.rust-lang.org/1.63.0/core/option/enum.Option.html#variant.None" title="None"><code>None</code></a> if the pattern doesn’t match.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="examples-21"><a href="#examples-21">Examples</a></h5>
|
|||
|
<p>Simple patterns:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"Löwe 老虎 Léopard Gepardi"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="string">'L'</span>), <span class="prelude-val">Some</span>(<span class="number">0</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="string">'é'</span>), <span class="prelude-val">Some</span>(<span class="number">14</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="string">"pard"</span>), <span class="prelude-val">Some</span>(<span class="number">17</span>));</code></pre></div>
|
|||
|
<p>More complex patterns using point-free style and closures:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"Löwe 老虎 Léopard"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="ident">char::is_whitespace</span>), <span class="prelude-val">Some</span>(<span class="number">5</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="ident">char::is_lowercase</span>), <span class="prelude-val">Some</span>(<span class="number">1</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="op">|</span><span class="ident">c</span>: <span class="ident">char</span><span class="op">|</span> <span class="ident">c</span>.<span class="ident">is_whitespace</span>() <span class="op">|</span><span class="op">|</span> <span class="ident">c</span>.<span class="ident">is_lowercase</span>()), <span class="prelude-val">Some</span>(<span class="number">1</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="op">|</span><span class="ident">c</span>: <span class="ident">char</span><span class="op">|</span> (<span class="ident">c</span> <span class="op"><</span> <span class="string">'o'</span>) <span class="op">&&</span> (<span class="ident">c</span> <span class="op">></span> <span class="string">'a'</span>)), <span class="prelude-val">Some</span>(<span class="number">4</span>));</code></pre></div>
|
|||
|
<p>Not finding the pattern:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"Löwe 老虎 Léopard"</span>;
|
|||
|
<span class="kw">let</span> <span class="ident">x</span>: <span class="kw-2">&</span>[<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'1'</span>, <span class="string">'2'</span>];
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="ident">x</span>), <span class="prelude-val">None</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.rfind" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1203-1205">source</a></span><a href="#method.rfind" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rfind" class="fnname">rfind</a><'a, P>(&'a self, pat: P) -> <a class="enum" href="https://doc.rust-lang.org/1.63.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a>> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>,<br> <P as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type core::str::pattern::Pattern::Searcher">Searcher</a>: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.ReverseSearcher.html" title="trait core::str::pattern::ReverseSearcher">ReverseSearcher</a><'a>, </span></h4></section></summary><div class="docblock"><p>Returns the byte index for the first character of the last match of the pattern in
|
|||
|
this string slice.</p>
|
|||
|
<p>Returns <a href="https://doc.rust-lang.org/1.63.0/core/option/enum.Option.html#variant.None" title="None"><code>None</code></a> if the pattern doesn’t match.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="examples-22"><a href="#examples-22">Examples</a></h5>
|
|||
|
<p>Simple patterns:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"Löwe 老虎 Léopard Gepardi"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">rfind</span>(<span class="string">'L'</span>), <span class="prelude-val">Some</span>(<span class="number">13</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">rfind</span>(<span class="string">'é'</span>), <span class="prelude-val">Some</span>(<span class="number">14</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">rfind</span>(<span class="string">"pard"</span>), <span class="prelude-val">Some</span>(<span class="number">24</span>));</code></pre></div>
|
|||
|
<p>More complex patterns with closures:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"Löwe 老虎 Léopard"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">rfind</span>(<span class="ident">char::is_whitespace</span>), <span class="prelude-val">Some</span>(<span class="number">12</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">rfind</span>(<span class="ident">char::is_lowercase</span>), <span class="prelude-val">Some</span>(<span class="number">20</span>));</code></pre></div>
|
|||
|
<p>Not finding the pattern:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"Löwe 老虎 Léopard"</span>;
|
|||
|
<span class="kw">let</span> <span class="ident">x</span>: <span class="kw-2">&</span>[<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'1'</span>, <span class="string">'2'</span>];
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">rfind</span>(<span class="ident">x</span>), <span class="prelude-val">None</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1325">source</a></span><a href="#method.split" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split" class="fnname">split</a><'a, P>(&'a self, pat: P) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.Split.html" title="struct core::str::iter::Split">Split</a><'a, P> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>An iterator over substrings of this string slice, separated by
|
|||
|
characters matched by a pattern.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="iterator-behavior"><a href="#iterator-behavior">Iterator behavior</a></h5>
|
|||
|
<p>The returned iterator will be a <a href="https://doc.rust-lang.org/1.63.0/core/iter/traits/double_ended/trait.DoubleEndedIterator.html" title="DoubleEndedIterator"><code>DoubleEndedIterator</code></a> if the pattern
|
|||
|
allows a reverse search and forward/reverse search yields the same
|
|||
|
elements. This is true for, e.g., <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, but not for <code>&str</code>.</p>
|
|||
|
<p>If the pattern allows a reverse search but its results might differ
|
|||
|
from a forward search, the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.rsplit"><code>rsplit</code></a> method can be used.</p>
|
|||
|
<h5 id="examples-23"><a href="#examples-23">Examples</a></h5>
|
|||
|
<p>Simple patterns:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"Mary had a little lamb"</span>.<span class="ident">split</span>(<span class="string">' '</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</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> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">""</span>.<span class="ident">split</span>(<span class="string">'X'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">""</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"lionXXtigerXleopard"</span>.<span class="ident">split</span>(<span class="string">'X'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</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> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"lion::tiger::leopard"</span>.<span class="ident">split</span>(<span class="string">"::"</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"lion"</span>, <span class="string">"tiger"</span>, <span class="string">"leopard"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"abc1def2ghi"</span>.<span class="ident">split</span>(<span class="ident">char::is_numeric</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"abc"</span>, <span class="string">"def"</span>, <span class="string">"ghi"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"lionXtigerXleopard"</span>.<span class="ident">split</span>(<span class="ident">char::is_uppercase</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"lion"</span>, <span class="string">"tiger"</span>, <span class="string">"leopard"</span>]);</code></pre></div>
|
|||
|
<p>If the pattern is a slice of chars, split on each occurrence of any of the characters:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"2020-11-03 23:59"</span>.<span class="ident">split</span>(<span class="kw-2">&</span>[<span class="string">'-'</span>, <span class="string">' '</span>, <span class="string">':'</span>, <span class="string">'@'</span>][..]).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"2020"</span>, <span class="string">"11"</span>, <span class="string">"03"</span>, <span class="string">"23"</span>, <span class="string">"59"</span>]);</code></pre></div>
|
|||
|
<p>A more complex pattern, using a closure:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"abc1defXghi"</span>.<span class="ident">split</span>(<span class="op">|</span><span class="ident">c</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'1'</span> <span class="op">|</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'X'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"abc"</span>, <span class="string">"def"</span>, <span class="string">"ghi"</span>]);</code></pre></div>
|
|||
|
<p>If a string contains multiple contiguous separators, you will end up
|
|||
|
with empty strings in the output:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="string">"||||a||b|c"</span>.<span class="ident">to_string</span>();
|
|||
|
<span class="kw">let</span> <span class="ident">d</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">split</span>(<span class="string">'|'</span>).<span class="ident">collect</span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">d</span>, <span class="kw-2">&</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>Contiguous separators are separated by the empty string.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="string">"(///)"</span>.<span class="ident">to_string</span>();
|
|||
|
<span class="kw">let</span> <span class="ident">d</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">split</span>(<span class="string">'/'</span>).<span class="ident">collect</span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">d</span>, <span class="kw-2">&</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 string are neighbored
|
|||
|
by empty strings.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">d</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="string">"010"</span>.<span class="ident">split</span>(<span class="string">"0"</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">d</span>, <span class="kw-2">&</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 separator, it separates
|
|||
|
every character in the string, along with the beginning
|
|||
|
and end of the string.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">f</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="string">"rust"</span>.<span class="ident">split</span>(<span class="string">""</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">f</span>, <span class="kw-2">&</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>]);</code></pre></div>
|
|||
|
<p>Contiguous separators can lead to possibly surprising behavior
|
|||
|
when whitespace is used as the separator. This code is correct:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="string">" a b c"</span>.<span class="ident">to_string</span>();
|
|||
|
<span class="kw">let</span> <span class="ident">d</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">split</span>(<span class="string">' '</span>).<span class="ident">collect</span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">d</span>, <span class="kw-2">&</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:</p>
|
|||
|
|
|||
|
<div class='information'><div class='tooltip ignore'>ⓘ</div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore"><code><span class="macro">assert_eq!</span>(<span class="ident">d</span>, <span class="kw-2">&</span>[<span class="string">"a"</span>, <span class="string">"b"</span>, <span class="string">"c"</span>]);</code></pre></div>
|
|||
|
<p>Use <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.split_whitespace"><code>split_whitespace</code></a> for this behavior.</p>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split_inclusive" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.51.0">1.51.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1365">source</a></span><a href="#method.split_inclusive" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_inclusive" class="fnname">split_inclusive</a><'a, P>(&'a self, pat: P) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.SplitInclusive.html" title="struct core::str::iter::SplitInclusive">SplitInclusive</a><'a, P> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>An iterator over substrings of this string slice, separated by
|
|||
|
characters matched by a pattern. Differs from the iterator produced by
|
|||
|
<code>split</code> in that <code>split_inclusive</code> leaves the matched part as the
|
|||
|
terminator of the substring.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="examples-24"><a href="#examples-24">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"Mary had a little lamb\nlittle lamb\nlittle lamb."</span>
|
|||
|
.<span class="ident">split_inclusive</span>(<span class="string">'\n'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"Mary had a little lamb\n"</span>, <span class="string">"little lamb\n"</span>, <span class="string">"little lamb."</span>]);</code></pre></div>
|
|||
|
<p>If the last element of the string is matched,
|
|||
|
that element will be considered the terminator of the preceding substring.
|
|||
|
That substring will be the last item returned by the iterator.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"Mary had a little lamb\nlittle lamb\nlittle lamb.\n"</span>
|
|||
|
.<span class="ident">split_inclusive</span>(<span class="string">'\n'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"Mary had a little lamb\n"</span>, <span class="string">"little lamb\n"</span>, <span class="string">"little lamb.\n"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.rsplit" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1420-1422">source</a></span><a href="#method.rsplit" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rsplit" class="fnname">rsplit</a><'a, P>(&'a self, pat: P) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.RSplit.html" title="struct core::str::iter::RSplit">RSplit</a><'a, P> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>,<br> <P as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type core::str::pattern::Pattern::Searcher">Searcher</a>: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.ReverseSearcher.html" title="trait core::str::pattern::ReverseSearcher">ReverseSearcher</a><'a>, </span></h4></section></summary><div class="docblock"><p>An iterator over substrings of the given string slice, separated by
|
|||
|
characters matched by a pattern and yielded in reverse order.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="iterator-behavior-1"><a href="#iterator-behavior-1">Iterator behavior</a></h5>
|
|||
|
<p>The returned iterator requires that the pattern supports a reverse
|
|||
|
search, and it will be a <a href="https://doc.rust-lang.org/1.63.0/core/iter/traits/double_ended/trait.DoubleEndedIterator.html" title="DoubleEndedIterator"><code>DoubleEndedIterator</code></a> if a forward/reverse
|
|||
|
search yields the same elements.</p>
|
|||
|
<p>For iterating from the front, the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.split"><code>split</code></a> method can be used.</p>
|
|||
|
<h5 id="examples-25"><a href="#examples-25">Examples</a></h5>
|
|||
|
<p>Simple patterns:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"Mary had a little lamb"</span>.<span class="ident">rsplit</span>(<span class="string">' '</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"lamb"</span>, <span class="string">"little"</span>, <span class="string">"a"</span>, <span class="string">"had"</span>, <span class="string">"Mary"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">""</span>.<span class="ident">rsplit</span>(<span class="string">'X'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">""</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"lionXXtigerXleopard"</span>.<span class="ident">rsplit</span>(<span class="string">'X'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"leopard"</span>, <span class="string">"tiger"</span>, <span class="string">""</span>, <span class="string">"lion"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"lion::tiger::leopard"</span>.<span class="ident">rsplit</span>(<span class="string">"::"</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"leopard"</span>, <span class="string">"tiger"</span>, <span class="string">"lion"</span>]);</code></pre></div>
|
|||
|
<p>A more complex pattern, using a closure:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"abc1defXghi"</span>.<span class="ident">rsplit</span>(<span class="op">|</span><span class="ident">c</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'1'</span> <span class="op">|</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'X'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"ghi"</span>, <span class="string">"def"</span>, <span class="string">"abc"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split_terminator" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1471">source</a></span><a href="#method.split_terminator" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_terminator" class="fnname">split_terminator</a><'a, P>(&'a self, pat: P) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.SplitTerminator.html" title="struct core::str::iter::SplitTerminator">SplitTerminator</a><'a, P> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>An iterator over substrings of the given string slice, separated by
|
|||
|
characters matched by a pattern.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<p>Equivalent to <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.split"><code>split</code></a>, except that the trailing substring
|
|||
|
is skipped if empty.</p>
|
|||
|
<p>This method can be used for string data that is <em>terminated</em>,
|
|||
|
rather than <em>separated</em> by a pattern.</p>
|
|||
|
<h5 id="iterator-behavior-2"><a href="#iterator-behavior-2">Iterator behavior</a></h5>
|
|||
|
<p>The returned iterator will be a <a href="https://doc.rust-lang.org/1.63.0/core/iter/traits/double_ended/trait.DoubleEndedIterator.html" title="DoubleEndedIterator"><code>DoubleEndedIterator</code></a> if the pattern
|
|||
|
allows a reverse search and forward/reverse search yields the same
|
|||
|
elements. This is true for, e.g., <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, but not for <code>&str</code>.</p>
|
|||
|
<p>If the pattern allows a reverse search but its results might differ
|
|||
|
from a forward search, the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.rsplit_terminator"><code>rsplit_terminator</code></a> method can be used.</p>
|
|||
|
<h5 id="examples-26"><a href="#examples-26">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"A.B."</span>.<span class="ident">split_terminator</span>(<span class="string">'.'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"A"</span>, <span class="string">"B"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"A..B.."</span>.<span class="ident">split_terminator</span>(<span class="string">"."</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"A"</span>, <span class="string">""</span>, <span class="string">"B"</span>, <span class="string">""</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"A.B:C.D"</span>.<span class="ident">split_terminator</span>(<span class="kw-2">&</span>[<span class="string">'.'</span>, <span class="string">':'</span>][..]).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"A"</span>, <span class="string">"B"</span>, <span class="string">"C"</span>, <span class="string">"D"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.rsplit_terminator" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1517-1519">source</a></span><a href="#method.rsplit_terminator" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rsplit_terminator" class="fnname">rsplit_terminator</a><'a, P>(&'a self, pat: P) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.RSplitTerminator.html" title="struct core::str::iter::RSplitTerminator">RSplitTerminator</a><'a, P> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>,<br> <P as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type core::str::pattern::Pattern::Searcher">Searcher</a>: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.ReverseSearcher.html" title="trait core::str::pattern::ReverseSearcher">ReverseSearcher</a><'a>, </span></h4></section></summary><div class="docblock"><p>An iterator over substrings of <code>self</code>, separated by characters
|
|||
|
matched by a pattern and yielded in reverse order.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<p>Equivalent to <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.split"><code>split</code></a>, except that the trailing substring is
|
|||
|
skipped if empty.</p>
|
|||
|
<p>This method can be used for string data that is <em>terminated</em>,
|
|||
|
rather than <em>separated</em> by a pattern.</p>
|
|||
|
<h5 id="iterator-behavior-3"><a href="#iterator-behavior-3">Iterator behavior</a></h5>
|
|||
|
<p>The returned iterator requires that the pattern supports a
|
|||
|
reverse search, and it will be double ended if a forward/reverse
|
|||
|
search yields the same elements.</p>
|
|||
|
<p>For iterating from the front, the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.split_terminator"><code>split_terminator</code></a> method can be
|
|||
|
used.</p>
|
|||
|
<h5 id="examples-27"><a href="#examples-27">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"A.B."</span>.<span class="ident">rsplit_terminator</span>(<span class="string">'.'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"B"</span>, <span class="string">"A"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"A..B.."</span>.<span class="ident">rsplit_terminator</span>(<span class="string">"."</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">""</span>, <span class="string">"B"</span>, <span class="string">""</span>, <span class="string">"A"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"A.B:C.D"</span>.<span class="ident">rsplit_terminator</span>(<span class="kw-2">&</span>[<span class="string">'.'</span>, <span class="string">':'</span>][..]).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"D"</span>, <span class="string">"C"</span>, <span class="string">"B"</span>, <span class="string">"A"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.splitn" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1572">source</a></span><a href="#method.splitn" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.splitn" class="fnname">splitn</a><'a, P>(&'a self, n: <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a>, pat: P) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.SplitN.html" title="struct core::str::iter::SplitN">SplitN</a><'a, P> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>An iterator over substrings of the given string slice, separated by a
|
|||
|
pattern, restricted to returning at most <code>n</code> items.</p>
|
|||
|
<p>If <code>n</code> substrings are returned, the last substring (the <code>n</code>th substring)
|
|||
|
will contain the remainder of the string.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="iterator-behavior-4"><a href="#iterator-behavior-4">Iterator behavior</a></h5>
|
|||
|
<p>The returned iterator will not be double ended, because it is
|
|||
|
not efficient to support.</p>
|
|||
|
<p>If the pattern allows a reverse search, the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.rsplitn"><code>rsplitn</code></a> method can be
|
|||
|
used.</p>
|
|||
|
<h5 id="examples-28"><a href="#examples-28">Examples</a></h5>
|
|||
|
<p>Simple patterns:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"Mary had a little lambda"</span>.<span class="ident">splitn</span>(<span class="number">3</span>, <span class="string">' '</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"Mary"</span>, <span class="string">"had"</span>, <span class="string">"a little lambda"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"lionXXtigerXleopard"</span>.<span class="ident">splitn</span>(<span class="number">3</span>, <span class="string">"X"</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"lion"</span>, <span class="string">""</span>, <span class="string">"tigerXleopard"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"abcXdef"</span>.<span class="ident">splitn</span>(<span class="number">1</span>, <span class="string">'X'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"abcXdef"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">""</span>.<span class="ident">splitn</span>(<span class="number">1</span>, <span class="string">'X'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">""</span>]);</code></pre></div>
|
|||
|
<p>A more complex pattern, using a closure:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"abc1defXghi"</span>.<span class="ident">splitn</span>(<span class="number">2</span>, <span class="op">|</span><span class="ident">c</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'1'</span> <span class="op">|</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'X'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"abc"</span>, <span class="string">"defXghi"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.rsplitn" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1621-1623">source</a></span><a href="#method.rsplitn" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rsplitn" class="fnname">rsplitn</a><'a, P>(&'a self, n: <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a>, pat: P) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.RSplitN.html" title="struct core::str::iter::RSplitN">RSplitN</a><'a, P> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>,<br> <P as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type core::str::pattern::Pattern::Searcher">Searcher</a>: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.ReverseSearcher.html" title="trait core::str::pattern::ReverseSearcher">ReverseSearcher</a><'a>, </span></h4></section></summary><div class="docblock"><p>An iterator over substrings of this string slice, separated by a
|
|||
|
pattern, starting from the end of the string, restricted to returning
|
|||
|
at most <code>n</code> items.</p>
|
|||
|
<p>If <code>n</code> substrings are returned, the last substring (the <code>n</code>th substring)
|
|||
|
will contain the remainder of the string.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="iterator-behavior-5"><a href="#iterator-behavior-5">Iterator behavior</a></h5>
|
|||
|
<p>The returned iterator will not be double ended, because it is not
|
|||
|
efficient to support.</p>
|
|||
|
<p>For splitting from the front, the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.splitn"><code>splitn</code></a> method can be used.</p>
|
|||
|
<h5 id="examples-29"><a href="#examples-29">Examples</a></h5>
|
|||
|
<p>Simple patterns:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"Mary had a little lamb"</span>.<span class="ident">rsplitn</span>(<span class="number">3</span>, <span class="string">' '</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"lamb"</span>, <span class="string">"little"</span>, <span class="string">"Mary had a"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"lionXXtigerXleopard"</span>.<span class="ident">rsplitn</span>(<span class="number">3</span>, <span class="string">'X'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"leopard"</span>, <span class="string">"tiger"</span>, <span class="string">"lionX"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"lion::tiger::leopard"</span>.<span class="ident">rsplitn</span>(<span class="number">2</span>, <span class="string">"::"</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"leopard"</span>, <span class="string">"lion::tiger"</span>]);</code></pre></div>
|
|||
|
<p>A more complex pattern, using a closure:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"abc1defXghi"</span>.<span class="ident">rsplitn</span>(<span class="number">2</span>, <span class="op">|</span><span class="ident">c</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'1'</span> <span class="op">|</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'X'</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"ghi"</span>, <span class="string">"abc1def"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split_once" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.52.0">1.52.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1641">source</a></span><a href="#method.split_once" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_once" class="fnname">split_once</a><'a, P>(&'a self, delimiter: P) -> <a class="enum" href="https://doc.rust-lang.org/1.63.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><(&'a <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>, &'a <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>)> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>Splits the string on the first occurrence of the specified delimiter and
|
|||
|
returns prefix before delimiter and suffix after delimiter.</p>
|
|||
|
<h5 id="examples-30"><a href="#examples-30">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"cfg"</span>.<span class="ident">split_once</span>(<span class="string">'='</span>), <span class="prelude-val">None</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"cfg="</span>.<span class="ident">split_once</span>(<span class="string">'='</span>), <span class="prelude-val">Some</span>((<span class="string">"cfg"</span>, <span class="string">""</span>)));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"cfg=foo"</span>.<span class="ident">split_once</span>(<span class="string">'='</span>), <span class="prelude-val">Some</span>((<span class="string">"cfg"</span>, <span class="string">"foo"</span>)));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"cfg=foo=bar"</span>.<span class="ident">split_once</span>(<span class="string">'='</span>), <span class="prelude-val">Some</span>((<span class="string">"cfg"</span>, <span class="string">"foo=bar"</span>)));</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.rsplit_once" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.52.0">1.52.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1659-1661">source</a></span><a href="#method.rsplit_once" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rsplit_once" class="fnname">rsplit_once</a><'a, P>(&'a self, delimiter: P) -> <a class="enum" href="https://doc.rust-lang.org/1.63.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><(&'a <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>, &'a <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>)> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>,<br> <P as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type core::str::pattern::Pattern::Searcher">Searcher</a>: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.ReverseSearcher.html" title="trait core::str::pattern::ReverseSearcher">ReverseSearcher</a><'a>, </span></h4></section></summary><div class="docblock"><p>Splits the string on the last occurrence of the specified delimiter and
|
|||
|
returns prefix before delimiter and suffix after delimiter.</p>
|
|||
|
<h5 id="examples-31"><a href="#examples-31">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"cfg"</span>.<span class="ident">rsplit_once</span>(<span class="string">'='</span>), <span class="prelude-val">None</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"cfg=foo"</span>.<span class="ident">rsplit_once</span>(<span class="string">'='</span>), <span class="prelude-val">Some</span>((<span class="string">"cfg"</span>, <span class="string">"foo"</span>)));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"cfg=foo=bar"</span>.<span class="ident">rsplit_once</span>(<span class="string">'='</span>), <span class="prelude-val">Some</span>((<span class="string">"cfg=foo"</span>, <span class="string">"bar"</span>)));</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.matches" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.2.0">1.2.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1701">source</a></span><a href="#method.matches" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.matches" class="fnname">matches</a><'a, P>(&'a self, pat: P) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.Matches.html" title="struct core::str::iter::Matches">Matches</a><'a, P> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>An iterator over the disjoint matches of a pattern within the given string
|
|||
|
slice.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="iterator-behavior-6"><a href="#iterator-behavior-6">Iterator behavior</a></h5>
|
|||
|
<p>The returned iterator will be a <a href="https://doc.rust-lang.org/1.63.0/core/iter/traits/double_ended/trait.DoubleEndedIterator.html" title="DoubleEndedIterator"><code>DoubleEndedIterator</code></a> if the pattern
|
|||
|
allows a reverse search and forward/reverse search yields the same
|
|||
|
elements. This is true for, e.g., <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, but not for <code>&str</code>.</p>
|
|||
|
<p>If the pattern allows a reverse search but its results might differ
|
|||
|
from a forward search, the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.matches"><code>rmatches</code></a> method can be used.</p>
|
|||
|
<h5 id="examples-32"><a href="#examples-32">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"abcXXXabcYYYabc"</span>.<span class="ident">matches</span>(<span class="string">"abc"</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"abc"</span>, <span class="string">"abc"</span>, <span class="string">"abc"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"1abc2abc3"</span>.<span class="ident">matches</span>(<span class="ident">char::is_numeric</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"1"</span>, <span class="string">"2"</span>, <span class="string">"3"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.rmatches" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.2.0">1.2.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1737-1739">source</a></span><a href="#method.rmatches" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rmatches" class="fnname">rmatches</a><'a, P>(&'a self, pat: P) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.RMatches.html" title="struct core::str::iter::RMatches">RMatches</a><'a, P> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>,<br> <P as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type core::str::pattern::Pattern::Searcher">Searcher</a>: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.ReverseSearcher.html" title="trait core::str::pattern::ReverseSearcher">ReverseSearcher</a><'a>, </span></h4></section></summary><div class="docblock"><p>An iterator over the disjoint matches of a pattern within this string slice,
|
|||
|
yielded in reverse order.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="iterator-behavior-7"><a href="#iterator-behavior-7">Iterator behavior</a></h5>
|
|||
|
<p>The returned iterator requires that the pattern supports a reverse
|
|||
|
search, and it will be a <a href="https://doc.rust-lang.org/1.63.0/core/iter/traits/double_ended/trait.DoubleEndedIterator.html" title="DoubleEndedIterator"><code>DoubleEndedIterator</code></a> if a forward/reverse
|
|||
|
search yields the same elements.</p>
|
|||
|
<p>For iterating from the front, the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.matches"><code>matches</code></a> method can be used.</p>
|
|||
|
<h5 id="examples-33"><a href="#examples-33">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"abcXXXabcYYYabc"</span>.<span class="ident">rmatches</span>(<span class="string">"abc"</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"abc"</span>, <span class="string">"abc"</span>, <span class="string">"abc"</span>]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span><span class="op">></span> <span class="op">=</span> <span class="string">"1abc2abc3"</span>.<span class="ident">rmatches</span>(<span class="ident">char::is_numeric</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="string">"3"</span>, <span class="string">"2"</span>, <span class="string">"1"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.match_indices" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.5.0">1.5.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1783">source</a></span><a href="#method.match_indices" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.match_indices" class="fnname">match_indices</a><'a, P>(&'a self, pat: P) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.MatchIndices.html" title="struct core::str::iter::MatchIndices">MatchIndices</a><'a, P> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>An iterator over the disjoint matches of a pattern within this string
|
|||
|
slice as well as the index that the match starts at.</p>
|
|||
|
<p>For matches of <code>pat</code> within <code>self</code> that overlap, only the indices
|
|||
|
corresponding to the first match are returned.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="iterator-behavior-8"><a href="#iterator-behavior-8">Iterator behavior</a></h5>
|
|||
|
<p>The returned iterator will be a <a href="https://doc.rust-lang.org/1.63.0/core/iter/traits/double_ended/trait.DoubleEndedIterator.html" title="DoubleEndedIterator"><code>DoubleEndedIterator</code></a> if the pattern
|
|||
|
allows a reverse search and forward/reverse search yields the same
|
|||
|
elements. This is true for, e.g., <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, but not for <code>&str</code>.</p>
|
|||
|
<p>If the pattern allows a reverse search but its results might differ
|
|||
|
from a forward search, the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.rmatch_indices"><code>rmatch_indices</code></a> method can be used.</p>
|
|||
|
<h5 id="examples-34"><a href="#examples-34">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="string">"abcXXXabcYYYabc"</span>.<span class="ident">match_indices</span>(<span class="string">"abc"</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [(<span class="number">0</span>, <span class="string">"abc"</span>), (<span class="number">6</span>, <span class="string">"abc"</span>), (<span class="number">12</span>, <span class="string">"abc"</span>)]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="string">"1abcabc2"</span>.<span class="ident">match_indices</span>(<span class="string">"abc"</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [(<span class="number">1</span>, <span class="string">"abc"</span>), (<span class="number">4</span>, <span class="string">"abc"</span>)]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="string">"ababa"</span>.<span class="ident">match_indices</span>(<span class="string">"aba"</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [(<span class="number">0</span>, <span class="string">"aba"</span>)]); <span class="comment">// only the first `aba`</span></code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.rmatch_indices" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.5.0">1.5.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1825-1827">source</a></span><a href="#method.rmatch_indices" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rmatch_indices" class="fnname">rmatch_indices</a><'a, P>(&'a self, pat: P) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.RMatchIndices.html" title="struct core::str::iter::RMatchIndices">RMatchIndices</a><'a, P> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>,<br> <P as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type core::str::pattern::Pattern::Searcher">Searcher</a>: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.ReverseSearcher.html" title="trait core::str::pattern::ReverseSearcher">ReverseSearcher</a><'a>, </span></h4></section></summary><div class="docblock"><p>An iterator over the disjoint matches of a pattern within <code>self</code>,
|
|||
|
yielded in reverse order along with the index of the match.</p>
|
|||
|
<p>For matches of <code>pat</code> within <code>self</code> that overlap, only the indices
|
|||
|
corresponding to the last match are returned.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="iterator-behavior-9"><a href="#iterator-behavior-9">Iterator behavior</a></h5>
|
|||
|
<p>The returned iterator requires that the pattern supports a reverse
|
|||
|
search, and it will be a <a href="https://doc.rust-lang.org/1.63.0/core/iter/traits/double_ended/trait.DoubleEndedIterator.html" title="DoubleEndedIterator"><code>DoubleEndedIterator</code></a> if a forward/reverse
|
|||
|
search yields the same elements.</p>
|
|||
|
<p>For iterating from the front, the <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.match_indices"><code>match_indices</code></a> method can be used.</p>
|
|||
|
<h5 id="examples-35"><a href="#examples-35">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="string">"abcXXXabcYYYabc"</span>.<span class="ident">rmatch_indices</span>(<span class="string">"abc"</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [(<span class="number">12</span>, <span class="string">"abc"</span>), (<span class="number">6</span>, <span class="string">"abc"</span>), (<span class="number">0</span>, <span class="string">"abc"</span>)]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="string">"1abcabc2"</span>.<span class="ident">rmatch_indices</span>(<span class="string">"abc"</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [(<span class="number">4</span>, <span class="string">"abc"</span>), (<span class="number">1</span>, <span class="string">"abc"</span>)]);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="string">"ababa"</span>.<span class="ident">rmatch_indices</span>(<span class="string">"aba"</span>).<span class="ident">collect</span>();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [(<span class="number">2</span>, <span class="string">"aba"</span>)]); <span class="comment">// only the last `aba`</span></code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.trim" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1851">source</a></span><a href="#method.trim" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.trim" class="fnname">trim</a>(&self) -> &<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a></h4></section></summary><div class="docblock"><p>Returns a string slice with leading and trailing whitespace removed.</p>
|
|||
|
<p>‘Whitespace’ is defined according to the terms of the Unicode Derived
|
|||
|
Core Property <code>White_Space</code>, which includes newlines.</p>
|
|||
|
<h5 id="examples-36"><a href="#examples-36">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"\n Hello\tworld\t\n"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"Hello\tworld"</span>, <span class="ident">s</span>.<span class="ident">trim</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.trim_start" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.30.0">1.30.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1890">source</a></span><a href="#method.trim_start" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.trim_start" class="fnname">trim_start</a>(&self) -> &<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a></h4></section></summary><div class="docblock"><p>Returns a string slice with leading whitespace removed.</p>
|
|||
|
<p>‘Whitespace’ is defined according to the terms of the Unicode Derived
|
|||
|
Core Property <code>White_Space</code>, which includes newlines.</p>
|
|||
|
<h5 id="text-directionality"><a href="#text-directionality">Text directionality</a></h5>
|
|||
|
<p>A string is a sequence of bytes. <code>start</code> in this context means the first
|
|||
|
position of that byte string; for a left-to-right language like English or
|
|||
|
Russian, this will be left side, and for right-to-left languages like
|
|||
|
Arabic or Hebrew, this will be the right side.</p>
|
|||
|
<h5 id="examples-37"><a href="#examples-37">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"\n Hello\tworld\t\n"</span>;
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"Hello\tworld\t\n"</span>, <span class="ident">s</span>.<span class="ident">trim_start</span>());</code></pre></div>
|
|||
|
<p>Directionality:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">" English "</span>;
|
|||
|
<span class="macro">assert!</span>(<span class="prelude-val">Some</span>(<span class="string">'E'</span>) <span class="op">==</span> <span class="ident">s</span>.<span class="ident">trim_start</span>().<span class="ident">chars</span>().<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">" עברית "</span>;
|
|||
|
<span class="macro">assert!</span>(<span class="prelude-val">Some</span>(<span class="string">'ע'</span>) <span class="op">==</span> <span class="ident">s</span>.<span class="ident">trim_start</span>().<span class="ident">chars</span>().<span class="ident">next</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.trim_end" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.30.0">1.30.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1929">source</a></span><a href="#method.trim_end" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.trim_end" class="fnname">trim_end</a>(&self) -> &<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a></h4></section></summary><div class="docblock"><p>Returns a string slice with trailing whitespace removed.</p>
|
|||
|
<p>‘Whitespace’ is defined according to the terms of the Unicode Derived
|
|||
|
Core Property <code>White_Space</code>, which includes newlines.</p>
|
|||
|
<h5 id="text-directionality-1"><a href="#text-directionality-1">Text directionality</a></h5>
|
|||
|
<p>A string is a sequence of bytes. <code>end</code> in this context means the last
|
|||
|
position of that byte string; for a left-to-right language like English or
|
|||
|
Russian, this will be right side, and for right-to-left languages like
|
|||
|
Arabic or Hebrew, this will be the left side.</p>
|
|||
|
<h5 id="examples-38"><a href="#examples-38">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"\n Hello\tworld\t\n"</span>;
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"\n Hello\tworld"</span>, <span class="ident">s</span>.<span class="ident">trim_end</span>());</code></pre></div>
|
|||
|
<p>Directionality:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">" English "</span>;
|
|||
|
<span class="macro">assert!</span>(<span class="prelude-val">Some</span>(<span class="string">'h'</span>) <span class="op">==</span> <span class="ident">s</span>.<span class="ident">trim_end</span>().<span class="ident">chars</span>().<span class="ident">rev</span>().<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">" עברית "</span>;
|
|||
|
<span class="macro">assert!</span>(<span class="prelude-val">Some</span>(<span class="string">'ת'</span>) <span class="op">==</span> <span class="ident">s</span>.<span class="ident">trim_end</span>().<span class="ident">chars</span>().<span class="ident">rev</span>().<span class="ident">next</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.trim_left" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#1969">source</a></span><a href="#method.trim_left" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.trim_left" class="fnname">trim_left</a>(&self) -> &<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span> Deprecated since 1.33.0: <p>superseded by <code>trim_start</code></p>
|
|||
|
</div></span></summary><div class="docblock"><p>Returns a string slice with leading whitespace removed.</p>
|
|||
|
<p>‘Whitespace’ is defined according to the terms of the Unicode Derived
|
|||
|
Core Property <code>White_Space</code>.</p>
|
|||
|
<h5 id="text-directionality-2"><a href="#text-directionality-2">Text directionality</a></h5>
|
|||
|
<p>A string is a sequence of bytes. ‘Left’ in this context means the first
|
|||
|
position of that byte string; for a language like Arabic or Hebrew
|
|||
|
which are ‘right to left’ rather than ‘left to right’, this will be
|
|||
|
the <em>right</em> side, not the left.</p>
|
|||
|
<h5 id="examples-39"><a href="#examples-39">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">" Hello\tworld\t"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"Hello\tworld\t"</span>, <span class="ident">s</span>.<span class="ident">trim_left</span>());</code></pre></div>
|
|||
|
<p>Directionality:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">" English"</span>;
|
|||
|
<span class="macro">assert!</span>(<span class="prelude-val">Some</span>(<span class="string">'E'</span>) <span class="op">==</span> <span class="ident">s</span>.<span class="ident">trim_left</span>().<span class="ident">chars</span>().<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">" עברית"</span>;
|
|||
|
<span class="macro">assert!</span>(<span class="prelude-val">Some</span>(<span class="string">'ע'</span>) <span class="op">==</span> <span class="ident">s</span>.<span class="ident">trim_left</span>().<span class="ident">chars</span>().<span class="ident">next</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.trim_right" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2009">source</a></span><a href="#method.trim_right" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.trim_right" class="fnname">trim_right</a>(&self) -> &<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span> Deprecated since 1.33.0: <p>superseded by <code>trim_end</code></p>
|
|||
|
</div></span></summary><div class="docblock"><p>Returns a string slice with trailing whitespace removed.</p>
|
|||
|
<p>‘Whitespace’ is defined according to the terms of the Unicode Derived
|
|||
|
Core Property <code>White_Space</code>.</p>
|
|||
|
<h5 id="text-directionality-3"><a href="#text-directionality-3">Text directionality</a></h5>
|
|||
|
<p>A string is a sequence of bytes. ‘Right’ in this context means the last
|
|||
|
position of that byte string; for a language like Arabic or Hebrew
|
|||
|
which are ‘right to left’ rather than ‘left to right’, this will be
|
|||
|
the <em>left</em> side, not the right.</p>
|
|||
|
<h5 id="examples-40"><a href="#examples-40">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">" Hello\tworld\t"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">" Hello\tworld"</span>, <span class="ident">s</span>.<span class="ident">trim_right</span>());</code></pre></div>
|
|||
|
<p>Directionality:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"English "</span>;
|
|||
|
<span class="macro">assert!</span>(<span class="prelude-val">Some</span>(<span class="string">'h'</span>) <span class="op">==</span> <span class="ident">s</span>.<span class="ident">trim_right</span>().<span class="ident">chars</span>().<span class="ident">rev</span>().<span class="ident">next</span>());
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"עברית "</span>;
|
|||
|
<span class="macro">assert!</span>(<span class="prelude-val">Some</span>(<span class="string">'ת'</span>) <span class="op">==</span> <span class="ident">s</span>.<span class="ident">trim_right</span>().<span class="ident">chars</span>().<span class="ident">rev</span>().<span class="ident">next</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.trim_matches" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2042-2044">source</a></span><a href="#method.trim_matches" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.trim_matches" class="fnname">trim_matches</a><'a, P>(&'a self, pat: P) -> &'a <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>,<br> <P as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type core::str::pattern::Pattern::Searcher">Searcher</a>: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.DoubleEndedSearcher.html" title="trait core::str::pattern::DoubleEndedSearcher">DoubleEndedSearcher</a><'a>, </span></h4></section></summary><div class="docblock"><p>Returns a string slice with all prefixes and suffixes that match a
|
|||
|
pattern repeatedly removed.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a function
|
|||
|
or closure that determines if a character matches.</p>
|
|||
|
<h5 id="examples-41"><a href="#examples-41">Examples</a></h5>
|
|||
|
<p>Simple patterns:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"11foo1bar11"</span>.<span class="ident">trim_matches</span>(<span class="string">'1'</span>), <span class="string">"foo1bar"</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"123foo1bar123"</span>.<span class="ident">trim_matches</span>(<span class="ident">char::is_numeric</span>), <span class="string">"foo1bar"</span>);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">x</span>: <span class="kw-2">&</span>[<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'1'</span>, <span class="string">'2'</span>];
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"12foo1bar12"</span>.<span class="ident">trim_matches</span>(<span class="ident">x</span>), <span class="string">"foo1bar"</span>);</code></pre></div>
|
|||
|
<p>A more complex pattern, using a closure:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"1foo1barXX"</span>.<span class="ident">trim_matches</span>(<span class="op">|</span><span class="ident">c</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'1'</span> <span class="op">|</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'X'</span>), <span class="string">"foo1bar"</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.trim_start_matches" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.30.0">1.30.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2091">source</a></span><a href="#method.trim_start_matches" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.trim_start_matches" class="fnname">trim_start_matches</a><'a, P>(&'a self, pat: P) -> &'a <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>Returns a string slice with all prefixes that match a pattern
|
|||
|
repeatedly removed.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="text-directionality-4"><a href="#text-directionality-4">Text directionality</a></h5>
|
|||
|
<p>A string is a sequence of bytes. <code>start</code> in this context means the first
|
|||
|
position of that byte string; for a left-to-right language like English or
|
|||
|
Russian, this will be left side, and for right-to-left languages like
|
|||
|
Arabic or Hebrew, this will be the right side.</p>
|
|||
|
<h5 id="examples-42"><a href="#examples-42">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"11foo1bar11"</span>.<span class="ident">trim_start_matches</span>(<span class="string">'1'</span>), <span class="string">"foo1bar11"</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"123foo1bar123"</span>.<span class="ident">trim_start_matches</span>(<span class="ident">char::is_numeric</span>), <span class="string">"foo1bar123"</span>);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">x</span>: <span class="kw-2">&</span>[<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'1'</span>, <span class="string">'2'</span>];
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"12foo1bar12"</span>.<span class="ident">trim_start_matches</span>(<span class="ident">x</span>), <span class="string">"foo1bar12"</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.strip_prefix" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.45.0">1.45.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2124">source</a></span><a href="#method.strip_prefix" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.strip_prefix" class="fnname">strip_prefix</a><'a, P>(&'a self, prefix: P) -> <a class="enum" href="https://doc.rust-lang.org/1.63.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&'a <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>Returns a string slice with the prefix removed.</p>
|
|||
|
<p>If the string starts with the pattern <code>prefix</code>, returns substring after the prefix, wrapped
|
|||
|
in <code>Some</code>. Unlike <code>trim_start_matches</code>, this method removes the prefix exactly once.</p>
|
|||
|
<p>If the string does not start with <code>prefix</code>, returns <code>None</code>.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="examples-43"><a href="#examples-43">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"foo:bar"</span>.<span class="ident">strip_prefix</span>(<span class="string">"foo:"</span>), <span class="prelude-val">Some</span>(<span class="string">"bar"</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"foo:bar"</span>.<span class="ident">strip_prefix</span>(<span class="string">"bar"</span>), <span class="prelude-val">None</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"foofoo"</span>.<span class="ident">strip_prefix</span>(<span class="string">"foo"</span>), <span class="prelude-val">Some</span>(<span class="string">"foo"</span>));</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.strip_suffix" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.45.0">1.45.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2151-2154">source</a></span><a href="#method.strip_suffix" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.strip_suffix" class="fnname">strip_suffix</a><'a, P>(&'a self, suffix: P) -> <a class="enum" href="https://doc.rust-lang.org/1.63.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&'a <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>,<br> <P as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type core::str::pattern::Pattern::Searcher">Searcher</a>: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.ReverseSearcher.html" title="trait core::str::pattern::ReverseSearcher">ReverseSearcher</a><'a>, </span></h4></section></summary><div class="docblock"><p>Returns a string slice with the suffix removed.</p>
|
|||
|
<p>If the string ends with the pattern <code>suffix</code>, returns the substring before the suffix,
|
|||
|
wrapped in <code>Some</code>. Unlike <code>trim_end_matches</code>, this method removes the suffix exactly once.</p>
|
|||
|
<p>If the string does not end with <code>suffix</code>, returns <code>None</code>.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="examples-44"><a href="#examples-44">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"bar:foo"</span>.<span class="ident">strip_suffix</span>(<span class="string">":foo"</span>), <span class="prelude-val">Some</span>(<span class="string">"bar"</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"bar:foo"</span>.<span class="ident">strip_suffix</span>(<span class="string">"bar"</span>), <span class="prelude-val">None</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"foofoo"</span>.<span class="ident">strip_suffix</span>(<span class="string">"foo"</span>), <span class="prelude-val">Some</span>(<span class="string">"foo"</span>));</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.trim_end_matches" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.30.0">1.30.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2195-2197">source</a></span><a href="#method.trim_end_matches" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.trim_end_matches" class="fnname">trim_end_matches</a><'a, P>(&'a self, pat: P) -> &'a <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>,<br> <P as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type core::str::pattern::Pattern::Searcher">Searcher</a>: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.ReverseSearcher.html" title="trait core::str::pattern::ReverseSearcher">ReverseSearcher</a><'a>, </span></h4></section></summary><div class="docblock"><p>Returns a string slice with all suffixes that match a pattern
|
|||
|
repeatedly removed.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="text-directionality-5"><a href="#text-directionality-5">Text directionality</a></h5>
|
|||
|
<p>A string is a sequence of bytes. <code>end</code> in this context means the last
|
|||
|
position of that byte string; for a left-to-right language like English or
|
|||
|
Russian, this will be right side, and for right-to-left languages like
|
|||
|
Arabic or Hebrew, this will be the left side.</p>
|
|||
|
<h5 id="examples-45"><a href="#examples-45">Examples</a></h5>
|
|||
|
<p>Simple patterns:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"11foo1bar11"</span>.<span class="ident">trim_end_matches</span>(<span class="string">'1'</span>), <span class="string">"11foo1bar"</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"123foo1bar123"</span>.<span class="ident">trim_end_matches</span>(<span class="ident">char::is_numeric</span>), <span class="string">"123foo1bar"</span>);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">x</span>: <span class="kw-2">&</span>[<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'1'</span>, <span class="string">'2'</span>];
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"12foo1bar12"</span>.<span class="ident">trim_end_matches</span>(<span class="ident">x</span>), <span class="string">"12foo1bar"</span>);</code></pre></div>
|
|||
|
<p>A more complex pattern, using a closure:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"1fooX"</span>.<span class="ident">trim_end_matches</span>(<span class="op">|</span><span class="ident">c</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'1'</span> <span class="op">|</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'X'</span>), <span class="string">"1foo"</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.trim_left_matches" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2241">source</a></span><a href="#method.trim_left_matches" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.trim_left_matches" class="fnname">trim_left_matches</a><'a, P>(&'a self, pat: P) -> &'a <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span> Deprecated since 1.33.0: <p>superseded by <code>trim_start_matches</code></p>
|
|||
|
</div></span></summary><div class="docblock"><p>Returns a string slice with all prefixes that match a pattern
|
|||
|
repeatedly removed.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="text-directionality-6"><a href="#text-directionality-6">Text directionality</a></h5>
|
|||
|
<p>A string is a sequence of bytes. ‘Left’ in this context means the first
|
|||
|
position of that byte string; for a language like Arabic or Hebrew
|
|||
|
which are ‘right to left’ rather than ‘left to right’, this will be
|
|||
|
the <em>right</em> side, not the left.</p>
|
|||
|
<h5 id="examples-46"><a href="#examples-46">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"11foo1bar11"</span>.<span class="ident">trim_left_matches</span>(<span class="string">'1'</span>), <span class="string">"foo1bar11"</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"123foo1bar123"</span>.<span class="ident">trim_left_matches</span>(<span class="ident">char::is_numeric</span>), <span class="string">"foo1bar123"</span>);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">x</span>: <span class="kw-2">&</span>[<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'1'</span>, <span class="string">'2'</span>];
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"12foo1bar12"</span>.<span class="ident">trim_left_matches</span>(<span class="ident">x</span>), <span class="string">"foo1bar12"</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.trim_right_matches" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2284-2286">source</a></span><a href="#method.trim_right_matches" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.trim_right_matches" class="fnname">trim_right_matches</a><'a, P>(&'a self, pat: P) -> &'a <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>,<br> <P as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type core::str::pattern::Pattern::Searcher">Searcher</a>: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.ReverseSearcher.html" title="trait core::str::pattern::ReverseSearcher">ReverseSearcher</a><'a>, </span></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span> Deprecated since 1.33.0: <p>superseded by <code>trim_end_matches</code></p>
|
|||
|
</div></span></summary><div class="docblock"><p>Returns a string slice with all suffixes that match a pattern
|
|||
|
repeatedly removed.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.63.0/core/str/pattern/index.html">pattern</a> can be a <code>&str</code>, <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>, a slice of <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html"><code>char</code></a>s, or a
|
|||
|
function or closure that determines if a character matches.</p>
|
|||
|
<h5 id="text-directionality-7"><a href="#text-directionality-7">Text directionality</a></h5>
|
|||
|
<p>A string is a sequence of bytes. ‘Right’ in this context means the last
|
|||
|
position of that byte string; for a language like Arabic or Hebrew
|
|||
|
which are ‘right to left’ rather than ‘left to right’, this will be
|
|||
|
the <em>left</em> side, not the right.</p>
|
|||
|
<h5 id="examples-47"><a href="#examples-47">Examples</a></h5>
|
|||
|
<p>Simple patterns:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"11foo1bar11"</span>.<span class="ident">trim_right_matches</span>(<span class="string">'1'</span>), <span class="string">"11foo1bar"</span>);
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"123foo1bar123"</span>.<span class="ident">trim_right_matches</span>(<span class="ident">char::is_numeric</span>), <span class="string">"123foo1bar"</span>);
|
|||
|
|
|||
|
<span class="kw">let</span> <span class="ident">x</span>: <span class="kw-2">&</span>[<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'1'</span>, <span class="string">'2'</span>];
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"12foo1bar12"</span>.<span class="ident">trim_right_matches</span>(<span class="ident">x</span>), <span class="string">"12foo1bar"</span>);</code></pre></div>
|
|||
|
<p>A more complex pattern, using a closure:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"1fooX"</span>.<span class="ident">trim_right_matches</span>(<span class="op">|</span><span class="ident">c</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'1'</span> <span class="op">|</span><span class="op">|</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">'X'</span>), <span class="string">"1foo"</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.parse" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2336">source</a></span><a href="#method.parse" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.parse" class="fnname">parse</a><F>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.63.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><F, <F as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/traits/trait.FromStr.html" title="trait core::str::traits::FromStr">FromStr</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/str/traits/trait.FromStr.html#associatedtype.Err" title="type core::str::traits::FromStr::Err">Err</a>> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/traits/trait.FromStr.html" title="trait core::str::traits::FromStr">FromStr</a>, </span></h4></section></summary><div class="docblock"><p>Parses this string slice into another type.</p>
|
|||
|
<p>Because <code>parse</code> is so general, it can cause problems with type
|
|||
|
inference. As such, <code>parse</code> is one of the few times you’ll see
|
|||
|
the syntax affectionately known as the ‘turbofish’: <code>::<></code>. This
|
|||
|
helps the inference algorithm understand specifically which type
|
|||
|
you’re trying to parse into.</p>
|
|||
|
<p><code>parse</code> can parse into any type that implements the <a href="https://doc.rust-lang.org/1.63.0/core/str/traits/trait.FromStr.html" title="FromStr"><code>FromStr</code></a> trait.</p>
|
|||
|
<h5 id="errors"><a href="#errors">Errors</a></h5>
|
|||
|
<p>Will return <a href="https://doc.rust-lang.org/1.63.0/core/str/traits/trait.FromStr.html#associatedtype.Err"><code>Err</code></a> if it’s not possible to parse this string slice into
|
|||
|
the desired type.</p>
|
|||
|
<h5 id="examples-48"><a href="#examples-48">Examples</a></h5>
|
|||
|
<p>Basic usage</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">four</span>: <span class="ident">u32</span> <span class="op">=</span> <span class="string">"4"</span>.<span class="ident">parse</span>().<span class="ident">unwrap</span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="number">4</span>, <span class="ident">four</span>);</code></pre></div>
|
|||
|
<p>Using the ‘turbofish’ instead of annotating <code>four</code>:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">four</span> <span class="op">=</span> <span class="string">"4"</span>.<span class="ident">parse</span>::<span class="op"><</span><span class="ident">u32</span><span class="op">></span>();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Ok</span>(<span class="number">4</span>), <span class="ident">four</span>);</code></pre></div>
|
|||
|
<p>Failing to parse:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">nope</span> <span class="op">=</span> <span class="string">"j"</span>.<span class="ident">parse</span>::<span class="op"><</span><span class="ident">u32</span><span class="op">></span>();
|
|||
|
|
|||
|
<span class="macro">assert!</span>(<span class="ident">nope</span>.<span class="ident">is_err</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_ascii" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.23.0">1.23.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2354">source</a></span><a href="#method.is_ascii" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.is_ascii" class="fnname">is_ascii</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Checks if all characters in this string are within the ASCII range.</p>
|
|||
|
<h5 id="examples-49"><a href="#examples-49">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">ascii</span> <span class="op">=</span> <span class="string">"hello!\n"</span>;
|
|||
|
<span class="kw">let</span> <span class="ident">non_ascii</span> <span class="op">=</span> <span class="string">"Grüße, Jürgen ❤"</span>;
|
|||
|
|
|||
|
<span class="macro">assert!</span>(<span class="ident">ascii</span>.<span class="ident">is_ascii</span>());
|
|||
|
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">non_ascii</span>.<span class="ident">is_ascii</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.eq_ignore_ascii_case" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.23.0">1.23.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2376">source</a></span><a href="#method.eq_ignore_ascii_case" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.eq_ignore_ascii_case" class="fnname">eq_ignore_ascii_case</a>(&self, other: &<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Checks that two strings are an ASCII case-insensitive match.</p>
|
|||
|
<p>Same as <code>to_ascii_lowercase(a) == to_ascii_lowercase(b)</code>,
|
|||
|
but without allocating and copying temporaries.</p>
|
|||
|
<h5 id="examples-50"><a href="#examples-50">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert!</span>(<span class="string">"Ferris"</span>.<span class="ident">eq_ignore_ascii_case</span>(<span class="string">"FERRIS"</span>));
|
|||
|
<span class="macro">assert!</span>(<span class="string">"Ferrös"</span>.<span class="ident">eq_ignore_ascii_case</span>(<span class="string">"FERRöS"</span>));
|
|||
|
<span class="macro">assert!</span>(<span class="op">!</span><span class="string">"Ferrös"</span>.<span class="ident">eq_ignore_ascii_case</span>(<span class="string">"FERRÖS"</span>));</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.escape_debug" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.34.0">1.34.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2471">source</a></span><a href="#method.escape_debug" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.escape_debug" class="fnname">escape_debug</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.EscapeDebug.html" title="struct core::str::iter::EscapeDebug">EscapeDebug</a><'_></h4></section></summary><div class="docblock"><p>Return an iterator that escapes each char in <code>self</code> with <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html#method.escape_debug" title="char::escape_debug"><code>char::escape_debug</code></a>.</p>
|
|||
|
<p>Note: only extended grapheme codepoints that begin the string will be
|
|||
|
escaped.</p>
|
|||
|
<h5 id="examples-51"><a href="#examples-51">Examples</a></h5>
|
|||
|
<p>As an iterator:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">for</span> <span class="ident">c</span> <span class="kw">in</span> <span class="string">"❤\n!"</span>.<span class="ident">escape_debug</span>() {
|
|||
|
<span class="macro">print!</span>(<span class="string">"{c}"</span>);
|
|||
|
}
|
|||
|
<span class="macro">println!</span>();</code></pre></div>
|
|||
|
<p>Using <code>println!</code> directly:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">println!</span>(<span class="string">"{}"</span>, <span class="string">"❤\n!"</span>.<span class="ident">escape_debug</span>());</code></pre></div>
|
|||
|
<p>Both are equivalent to:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">println!</span>(<span class="string">"❤\\n!"</span>);</code></pre></div>
|
|||
|
<p>Using <code>to_string</code>:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"❤\n!"</span>.<span class="ident">escape_debug</span>().<span class="ident">to_string</span>(), <span class="string">"❤\\n!"</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.escape_default" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.34.0">1.34.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2517">source</a></span><a href="#method.escape_default" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.escape_default" class="fnname">escape_default</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.EscapeDefault.html" title="struct core::str::iter::EscapeDefault">EscapeDefault</a><'_></h4></section></summary><div class="docblock"><p>Return an iterator that escapes each char in <code>self</code> with <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html#method.escape_default" title="char::escape_default"><code>char::escape_default</code></a>.</p>
|
|||
|
<h5 id="examples-52"><a href="#examples-52">Examples</a></h5>
|
|||
|
<p>As an iterator:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">for</span> <span class="ident">c</span> <span class="kw">in</span> <span class="string">"❤\n!"</span>.<span class="ident">escape_default</span>() {
|
|||
|
<span class="macro">print!</span>(<span class="string">"{c}"</span>);
|
|||
|
}
|
|||
|
<span class="macro">println!</span>();</code></pre></div>
|
|||
|
<p>Using <code>println!</code> directly:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">println!</span>(<span class="string">"{}"</span>, <span class="string">"❤\n!"</span>.<span class="ident">escape_default</span>());</code></pre></div>
|
|||
|
<p>Both are equivalent to:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">println!</span>(<span class="string">"\\u{{2764}}\\n!"</span>);</code></pre></div>
|
|||
|
<p>Using <code>to_string</code>:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"❤\n!"</span>.<span class="ident">escape_default</span>().<span class="ident">to_string</span>(), <span class="string">"\\u{2764}\\n!"</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.escape_unicode" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.34.0">1.34.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/str/mod.rs.html#2555">source</a></span><a href="#method.escape_unicode" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.escape_unicode" class="fnname">escape_unicode</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/core/str/iter/struct.EscapeUnicode.html" title="struct core::str::iter::EscapeUnicode">EscapeUnicode</a><'_></h4></section></summary><div class="docblock"><p>Return an iterator that escapes each char in <code>self</code> with <a href="https://doc.rust-lang.org/1.63.0/std/primitive.char.html#method.escape_unicode" title="char::escape_unicode"><code>char::escape_unicode</code></a>.</p>
|
|||
|
<h5 id="examples-53"><a href="#examples-53">Examples</a></h5>
|
|||
|
<p>As an iterator:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">for</span> <span class="ident">c</span> <span class="kw">in</span> <span class="string">"❤\n!"</span>.<span class="ident">escape_unicode</span>() {
|
|||
|
<span class="macro">print!</span>(<span class="string">"{c}"</span>);
|
|||
|
}
|
|||
|
<span class="macro">println!</span>();</code></pre></div>
|
|||
|
<p>Using <code>println!</code> directly:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">println!</span>(<span class="string">"{}"</span>, <span class="string">"❤\n!"</span>.<span class="ident">escape_unicode</span>());</code></pre></div>
|
|||
|
<p>Both are equivalent to:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">println!</span>(<span class="string">"\\u{{2764}}\\u{{a}}\\u{{21}}"</span>);</code></pre></div>
|
|||
|
<p>Using <code>to_string</code>:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"❤\n!"</span>.<span class="ident">escape_unicode</span>().<span class="ident">to_string</span>(), <span class="string">"\\u{2764}\\u{a}\\u{21}"</span>);</code></pre></div>
|
|||
|
</div></details></div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.replace" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/alloc/str.rs.html#289">source</a></span><a href="#method.replace" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.replace" class="fnname">replace</a><'a, P>(&'a self, from: P, to: &<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>Replaces all matches of a pattern with another string.</p>
|
|||
|
<p><code>replace</code> creates a new <a href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="String"><code>String</code></a>, and copies the data from this string slice into it.
|
|||
|
While doing so, it attempts to find matches of a pattern. If it finds any, it
|
|||
|
replaces them with the replacement string slice.</p>
|
|||
|
<h5 id="examples-54"><a href="#examples-54">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"this is old"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"this is new"</span>, <span class="ident">s</span>.<span class="ident">replace</span>(<span class="string">"old"</span>, <span class="string">"new"</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"than an old"</span>, <span class="ident">s</span>.<span class="ident">replace</span>(<span class="string">"is"</span>, <span class="string">"an"</span>));</code></pre></div>
|
|||
|
<p>When the pattern doesn’t match:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"this is old"</span>;
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>, <span class="ident">s</span>.<span class="ident">replace</span>(<span class="string">"cookie monster"</span>, <span class="string">"little lamb"</span>));</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.replacen" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.16.0">1.16.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/alloc/str.rs.html#329">source</a></span><a href="#method.replacen" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.replacen" class="fnname">replacen</a><'a, P>(&'a self, pat: P, to: &<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a>, count: <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/str/pattern/trait.Pattern.html" title="trait core::str::pattern::Pattern">Pattern</a><'a>, </span></h4></section></summary><div class="docblock"><p>Replaces first N matches of a pattern with another string.</p>
|
|||
|
<p><code>replacen</code> creates a new <a href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="String"><code>String</code></a>, and copies the data from this string slice into it.
|
|||
|
While doing so, it attempts to find matches of a pattern. If it finds any, it
|
|||
|
replaces them with the replacement string slice at most <code>count</code> times.</p>
|
|||
|
<h5 id="examples-55"><a href="#examples-55">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"foo foo 123 foo"</span>;
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"new new 123 foo"</span>, <span class="ident">s</span>.<span class="ident">replacen</span>(<span class="string">"foo"</span>, <span class="string">"new"</span>, <span class="number">2</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"faa fao 123 foo"</span>, <span class="ident">s</span>.<span class="ident">replacen</span>(<span class="string">'o'</span>, <span class="string">"a"</span>, <span class="number">3</span>));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"foo foo new23 foo"</span>, <span class="ident">s</span>.<span class="ident">replacen</span>(<span class="ident">char::is_numeric</span>, <span class="string">"new"</span>, <span class="number">1</span>));</code></pre></div>
|
|||
|
<p>When the pattern doesn’t match:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"this is old"</span>;
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">s</span>, <span class="ident">s</span>.<span class="ident">replacen</span>(<span class="string">"cookie monster"</span>, <span class="string">"little lamb"</span>, <span class="number">10</span>));</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_lowercase" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.2.0">1.2.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/alloc/str.rs.html#386">source</a></span><a href="#method.to_lowercase" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.to_lowercase" class="fnname">to_lowercase</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h4></section></summary><div class="docblock"><p>Returns the lowercase equivalent of this string slice, as a new <a href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="String"><code>String</code></a>.</p>
|
|||
|
<p>‘Lowercase’ is defined according to the terms of the Unicode Derived Core Property
|
|||
|
<code>Lowercase</code>.</p>
|
|||
|
<p>Since some characters can expand into multiple characters when changing
|
|||
|
the case, this function returns a <a href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="String"><code>String</code></a> instead of modifying the
|
|||
|
parameter in-place.</p>
|
|||
|
<h5 id="examples-56"><a href="#examples-56">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"HELLO"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"hello"</span>, <span class="ident">s</span>.<span class="ident">to_lowercase</span>());</code></pre></div>
|
|||
|
<p>A tricky example, with sigma:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">sigma</span> <span class="op">=</span> <span class="string">"Σ"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"σ"</span>, <span class="ident">sigma</span>.<span class="ident">to_lowercase</span>());
|
|||
|
|
|||
|
<span class="comment">// but at the end of a word, it's ς, not σ:</span>
|
|||
|
<span class="kw">let</span> <span class="ident">odysseus</span> <span class="op">=</span> <span class="string">"ὈΔΥΣΣΕΎΣ"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"ὀδυσσεύς"</span>, <span class="ident">odysseus</span>.<span class="ident">to_lowercase</span>());</code></pre></div>
|
|||
|
<p>Languages without case are not changed:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">new_year</span> <span class="op">=</span> <span class="string">"农历新年"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">new_year</span>, <span class="ident">new_year</span>.<span class="ident">to_lowercase</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_uppercase" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.2.0">1.2.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/alloc/str.rs.html#477">source</a></span><a href="#method.to_uppercase" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.to_uppercase" class="fnname">to_uppercase</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h4></section></summary><div class="docblock"><p>Returns the uppercase equivalent of this string slice, as a new <a href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="String"><code>String</code></a>.</p>
|
|||
|
<p>‘Uppercase’ is defined according to the terms of the Unicode Derived Core Property
|
|||
|
<code>Uppercase</code>.</p>
|
|||
|
<p>Since some characters can expand into multiple characters when changing
|
|||
|
the case, this function returns a <a href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="String"><code>String</code></a> instead of modifying the
|
|||
|
parameter in-place.</p>
|
|||
|
<h5 id="examples-57"><a href="#examples-57">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"hello"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"HELLO"</span>, <span class="ident">s</span>.<span class="ident">to_uppercase</span>());</code></pre></div>
|
|||
|
<p>Scripts without case are not changed:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">new_year</span> <span class="op">=</span> <span class="string">"农历新年"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="ident">new_year</span>, <span class="ident">new_year</span>.<span class="ident">to_uppercase</span>());</code></pre></div>
|
|||
|
<p>One character can become multiple:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"tschüß"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"TSCHÜSS"</span>, <span class="ident">s</span>.<span class="ident">to_uppercase</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.repeat" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.16.0">1.16.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/alloc/str.rs.html#549">source</a></span><a href="#method.repeat" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.repeat" class="fnname">repeat</a>(&self, n: <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h4></section></summary><div class="docblock"><p>Creates a new <a href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="String"><code>String</code></a> by repeating a string <code>n</code> times.</p>
|
|||
|
<h5 id="panics-2"><a href="#panics-2">Panics</a></h5>
|
|||
|
<p>This function will panic if the capacity would overflow.</p>
|
|||
|
<h5 id="examples-58"><a href="#examples-58">Examples</a></h5>
|
|||
|
<p>Basic usage:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="string">"abc"</span>.<span class="ident">repeat</span>(<span class="number">4</span>), <span class="ident">String::from</span>(<span class="string">"abcabcabcabc"</span>));</code></pre></div>
|
|||
|
<p>A panic upon overflow:</p>
|
|||
|
|
|||
|
<div class='information'><div class='tooltip should_panic'>ⓘ</div></div><div class="example-wrap"><pre class="rust rust-example-rendered should_panic"><code><span class="comment">// this will panic at runtime</span>
|
|||
|
<span class="kw">let</span> <span class="ident">huge</span> <span class="op">=</span> <span class="string">"0123456789abcdef"</span>.<span class="ident">repeat</span>(<span class="ident">usize::MAX</span>);</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_ascii_uppercase" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.23.0">1.23.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/alloc/str.rs.html#579">source</a></span><a href="#method.to_ascii_uppercase" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.to_ascii_uppercase" class="fnname">to_ascii_uppercase</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h4></section></summary><div class="docblock"><p>Returns a copy of this string where each character is mapped to its
|
|||
|
ASCII upper case equivalent.</p>
|
|||
|
<p>ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’,
|
|||
|
but non-ASCII letters are unchanged.</p>
|
|||
|
<p>To uppercase the value in-place, use <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.make_ascii_uppercase"><code>make_ascii_uppercase</code></a>.</p>
|
|||
|
<p>To uppercase ASCII characters in addition to non-ASCII characters, use
|
|||
|
<a href="#method.to_uppercase"><code>to_uppercase</code></a>.</p>
|
|||
|
<h5 id="examples-59"><a href="#examples-59">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"Grüße, Jürgen ❤"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"GRüßE, JüRGEN ❤"</span>, <span class="ident">s</span>.<span class="ident">to_ascii_uppercase</span>());</code></pre></div>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_ascii_lowercase" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.23.0">1.23.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/alloc/str.rs.html#612">source</a></span><a href="#method.to_ascii_lowercase" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.to_ascii_lowercase" class="fnname">to_ascii_lowercase</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.63.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h4></section></summary><div class="docblock"><p>Returns a copy of this string where each character is mapped to its
|
|||
|
ASCII lower case equivalent.</p>
|
|||
|
<p>ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’,
|
|||
|
but non-ASCII letters are unchanged.</p>
|
|||
|
<p>To lowercase the value in-place, use <a href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html#method.make_ascii_lowercase"><code>make_ascii_lowercase</code></a>.</p>
|
|||
|
<p>To lowercase ASCII characters in addition to non-ASCII characters, use
|
|||
|
<a href="#method.to_lowercase"><code>to_lowercase</code></a>.</p>
|
|||
|
<h5 id="examples-60"><a href="#examples-60">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"Grüße, Jürgen ❤"</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="string">"grüße, jürgen ❤"</span>, <span class="ident">s</span>.<span class="ident">to_ascii_lowercase</span>());</code></pre></div>
|
|||
|
</div></details></div></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Deref" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../../../../src/pages/static_assets/static_files.rs.html#30-34">source</a></span><a href="#impl-Deref" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a> for <a class="struct" href="struct.MOBILE_CSS.html" title="struct pages::static_assets::static_files::assets::MOBILE_CSS">MOBILE_CSS</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Target" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Target" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.63.0/core/ops/deref/trait.Deref.html#associatedtype.Target" class="associatedtype">Target</a> = &'static <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a></h4></section></summary><div class='docblock'><p>The resulting type after dereferencing.</p>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.deref" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../../../../src/pages/static_assets/static_files.rs.html#30-34">source</a></span><a href="#method.deref" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.63.0/core/ops/deref/trait.Deref.html#tymethod.deref" class="fnname">deref</a>(&self) -> &&'static <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a></h4></section></summary><div class='docblock'><p>Dereferences the value.</p>
|
|||
|
</div></details></div></details><section id="impl-LazyStatic" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../../../../src/pages/static_assets/static_files.rs.html#30-34">source</a></span><a href="#impl-LazyStatic" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://docs.rs/lazy_static/1.4.0/lazy_static/trait.LazyStatic.html" title="trait lazy_static::LazyStatic">LazyStatic</a> for <a class="struct" href="struct.MOBILE_CSS.html" title="struct pages::static_assets::static_files::assets::MOBILE_CSS">MOBILE_CSS</a></h3></section></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe" class="impl has-srclink"><a href="#impl-RefUnwindSafe" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.MOBILE_CSS.html" title="struct pages::static_assets::static_files::assets::MOBILE_CSS">MOBILE_CSS</a></h3></section><section id="impl-Send" class="impl has-srclink"><a href="#impl-Send" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.MOBILE_CSS.html" title="struct pages::static_assets::static_files::assets::MOBILE_CSS">MOBILE_CSS</a></h3></section><section id="impl-Sync" class="impl has-srclink"><a href="#impl-Sync" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.MOBILE_CSS.html" title="struct pages::static_assets::static_files::assets::MOBILE_CSS">MOBILE_CSS</a></h3></section><section id="impl-Unpin" class="impl has-srclink"><a href="#impl-Unpin" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.MOBILE_CSS.html" title="struct pages::static_assets::static_files::assets::MOBILE_CSS">MOBILE_CSS</a></h3></section><section id="impl-UnwindSafe" class="impl has-srclink"><a href="#impl-UnwindSafe" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.MOBILE_CSS.html" title="struct pages::static_assets::static_files::assets::MOBILE_CSS">MOBILE_CSS</a></h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Any" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/any.rs.html#203-207">source</a></span><a href="#impl-Any" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br> T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.63.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/any.rs.html#204">source</a></s
|
|||
|
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/borrow.rs.html#209-214">source</a></span><a href="#impl-Borrow%3CT%3E" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T <span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/1.63.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/borrow.rs.html#211">source</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.63.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.reference.html">&</a>T</h4></section></summary><div class='docblock'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.63.0/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
|
|||
|
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/borrow.rs.html#218-222">source</a></span><a href="#impl-BorrowMut%3CT%3E" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T <span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/1.63.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/borrow.rs.html#219">source</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.63.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.reference.html">&mut </a>T</h4></section></summary><div class='docblock'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.63.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
|
|||
|
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/convert/mod.rs.html#557-562">source</a></span><a href="#impl-From%3CT%3E" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/convert/mod.rs.html#559">source</a></span><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.63.0/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
|
|||
|
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Instrument" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://docs.rs/tracing/0.1.36/src/tracing/instrument.rs.html#276">source</a></span><a href="#impl-Instrument" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://docs.rs/tracing/0.1.36/tracing/instrument/trait.Instrument.html" title="trait tracing::instrument::Instrument">Instrument</a> for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.instrument" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://docs.rs/tracing/0.1.36/src/tracing/instrument.rs.html#82">source</a></span><a href="#method.instrument" class="anchor"></a><h4 class="code-header">fn <a href="https://docs.rs/tracing/0.1.36/tracing/instrument/trait.Instrument.html#method.instrument" class="fnname">instrument</a>(self, span: <a class="struct" href="https://docs.rs/tracing/0.1.36/tracing/span/struct.Span.html" title="struct tracing::span::Span">Span</a>) -> <a class="struct" href="https://docs.rs/tracing/0.1.36/tracing/instrument/struct.Instrumented.html" title="struct tracing::instrument::Instrumented">Instrumented</a><Self></h4></section></summary><div class='docblock'><p>Instruments this type with the provided <a href="https://docs.rs/tracing/0.1.36/tracing/span/struct.Span.html" title="Span"><code>Span</code></a>, returning an
|
|||
|
<code>Instrumented</code> wrapper. <a href="https://docs.rs/tracing/0.1.36/tracing/instrument/trait.Instrument.html#method.instrument">Read more</a></p>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.in_current_span" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://docs.rs/tracing/0.1.36/src/tracing/instrument.rs.html#121">source</a></span><a href="#method.in_current_span" class="anchor"></a><h4 class="code-header">fn <a href="https://docs.rs/tracing/0.1.36/tracing/instrument/trait.Instrument.html#method.in_current_span" class="fnname">in_current_span</a>(self) -> <a class="struct" href="https://docs.rs/tracing/0.1.36/tracing/instrument/struct.Instrumented.html" title="struct tracing::instrument::Instrumented">Instrumented</a><Self></h4></section></summary><div class='docblock'><p>Instruments this type with the <a href="https://docs.rs/tracing/0.1.36/tracing/span/struct.Span.html#method.current">current</a> <a href="https://docs.rs/tracing/0.1.36/tracing/span/struct.Span.html"><code>Span</code></a>, returning an
|
|||
|
<code>Instrumented</code> wrapper. <a href="https://docs.rs/tracing/0.1.36/tracing/instrument/trait.Instrument.html#method.in_current_span">Read more</a></p>
|
|||
|
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/convert/mod.rs.html#541-552">source</a></span><a href="#impl-Into%3CU%3E" class="anchor"></a><h3 class="code-header in-band">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>, </span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/convert/mod.rs.html#549">source</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.63.0/core/convert/trait.Into.html#tymethod.into" class="fnname">into</a>(self) -> U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
|
|||
|
<p>That is, this conversion is whatever the implementation of
|
|||
|
<code><a href="https://doc.rust-lang.org/1.63.0/core/convert/trait.From.html" title="From">From</a><T> for U</code> chooses to do.</p>
|
|||
|
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Same%3CT%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://docs.rs/typenum/1.15.0/src/typenum/type_operators.rs.html#34-36">source</a></span><a href="#impl-Same%3CT%3E" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://docs.rs/typenum/1.15.0/typenum/type_operators/trait.Same.html" title="trait typenum::type_operators::Same">Same</a><T> for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output" class="anchor"></a><h4 class="code-header">type <a href="https://docs.rs/typenum/1.15.0/typenum/type_operators/trait.Same.html#associatedtype.Output" class="associatedtype">Output</a> = T</h4></section></summary><div class='docblock'><p>Should always be <code>Self</code></p>
|
|||
|
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/convert/mod.rs.html#598-607">source</a></span><a href="#impl-TryFrom%3CU%3E" class="anchor"></a><h3 class="code-header in-band">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>, </span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.63.0/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.63.0/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'><p>The type returned in the event of a conversion error.</p>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/convert/mod.rs.html#604">source</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.63.0/core/convert/trait.TryFrom.html#tymethod.try_from" class="fnname">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/1.63.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'><p>Performs the conversion.</p>
|
|||
|
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/convert/mod.rs.html#583-592">source</a></span><a href="#impl-TryInto%3CU%3E" class="anchor"></a><h3 class="code-header in-band">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>, </span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.63.0/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'><p>The type returned in the event of a conversion error.</p>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/1.63.0/src/core/convert/mod.rs.html#589">source</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.63.0/core/convert/trait.TryInto.html#tymethod.try_into" class="fnname">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.63.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'><p>Performs the conversion.</p>
|
|||
|
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-VZip%3CV%3E" class="impl has-srclink"><a href="#impl-VZip%3CV%3E" class="anchor"></a><h3 class="code-header in-band">impl<V, T> VZip<V> for T <span class="where fmt-newline">where<br> V: MultiLane<T>, </span></h3></section></summary><div class="impl-items"><section id="method.vzip" class="method trait-impl has-srclink"><a href="#method.vzip" class="anchor"></a><h4 class="code-header">fn <a class="fnname">vzip</a>(self) -> V</h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-WithSubscriber" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://docs.rs/tracing/0.1.36/src/tracing/instrument.rs.html#334">source</a></span><a href="#impl-WithSubscriber" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://docs.rs/tracing/0.1.36/tracing/instrument/trait.WithSubscriber.html" title="trait tracing::instrument::WithSubscriber">WithSubscriber</a> for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_subscriber" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://docs.rs/tracing/0.1.36/src/tracing/instrument.rs.html#169-171">source</a></span><a href="#method.with_subscriber" class="anchor"></a><h4 class="code-header">fn <a href="https://docs.rs/tracing/0.1.36/tracing/instrument/trait.WithSubscriber.html#method.with_subscriber" class="fnname">with_subscriber</a><S>(self, subscriber: S) -> <a class="struct" href="https://docs.rs/tracing/0.1.36/tracing/instrument/struct.WithDispatch.html" title="struct tracing::instrument::WithDispatch">WithDispatch</a><Self> <span class="where fmt-newline">where<br> S: <a class="trait" href="https://doc.rust-lang.org/1.63.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="struct" href="https://docs.rs/tracing-core/0.1.22/tracing_core/dispatcher/struct.Dispatch.html" title="struct tracing_core::dispatcher::Dispatch">Dispatch</a>>, </span></h4></section></summary><div class='docblock'><p>Attaches the provided <a href="https://docs.rs/tracing-core/0.1.22/tracing_core/subscriber/trait.Subscriber.html"><code>Subscriber</code></a> to this type, returning a
|
|||
|
<a href="https://docs.rs/tracing/0.1.36/tracing/instrument/struct.WithDispatch.html" title="WithDispatch"><code>WithDispatch</code></a> wrapper. <a href="https://docs.rs/tracing/0.1.36/tracing/instrument/trait.WithSubscriber.html#method.with_subscriber">Read more</a></p>
|
|||
|
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_current_subscriber" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://docs.rs/tracing/0.1.36/src/tracing/instrument.rs.html#221">source</a></span><a href="#method.with_current_subscriber" class="anchor"></a><h4 class="code-header">fn <a href="https://docs.rs/tracing/0.1.36/tracing/instrument/trait.WithSubscriber.html#method.with_current_subscriber" class="fnname">with_current_subscriber</a>(self) -> <a class="struct" href="https://docs.rs/tracing/0.1.36/tracing/instrument/struct.WithDispatch.html" title="struct tracing::instrument::WithDispatch">WithDispatch</a><Self></h4></section></summary><div class='docblock'><p>Attaches the current <a href="https://docs.rs/tracing/0.1.36/tracing/dispatcher/index.html#setting-the-default-subscriber">default</a> <a href="https://docs.rs/tracing-core/0.1.22/tracing_core/subscriber/trait.Subscriber.html"><code>Subscriber</code></a> to this type, returning a
|
|||
|
<a href="https://docs.rs/tracing/0.1.36/tracing/instrument/struct.WithDispatch.html" title="WithDispatch"><code>WithDispatch</code></a> wrapper. <a href="https://docs.rs/tracing/0.1.36/tracing/instrument/trait.WithSubscriber.html#method.with_current_subscriber">Read more</a></p>
|
|||
|
</div></details></div></details></div></section></div></main><div id="rustdoc-vars" data-root-path="../../../../" data-current-crate="pages" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.63.0 (4b91a6ea7 2022-08-08)" ></div>
|
|||
|
</body></html>
|