Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-updates > by-pkgid > 878cdd00a13d17a73c6619a777ef5d74 > files > 4794

rust-doc-1.19.0-1.mga6.x86_64.rpm

<!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 `str` primitive in crate `std`.">
    <meta name="keywords" content="rust, rustlang, rust-lang, str">

    <title>str - Rust</title>

    <link rel="stylesheet" type="text/css" href="../normalize.css">
    <link rel="stylesheet" type="text/css" href="../rustdoc.css">
    <link rel="stylesheet" type="text/css" href="../main.css">
    

    <link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico">
    
</head>
<body class="rustdoc primitive">
    <!--[if lte IE 8]>
    <div class="warning">
        This old browser is unsupported and will most likely display funky
        things.
    </div>
    <![endif]-->

    

    <nav class="sidebar">
        <a href='../std/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a>
        <p class='location'>Primitive Type str</p><div class="block items"><ul><li><a href="#methods">Methods</a></li><li><a href="#implementations">Trait Implementations</a></li></ul></div><p class='location'><a href='index.html'>std</a></p><script>window.sidebarCurrent = {name: 'str', ty: 'primitive', relpath: ''};</script><script defer src="sidebar-items.js"></script>
    </nav>

    <nav class="sub">
        <form class="search-form js-only">
            <div class="search-container">
                <input class="search-input" name="search"
                       autocomplete="off"
                       placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
                       type="search">
            </div>
        </form>
    </nav>

    <section id='main' class="content">
<h1 class='fqn'><span class='in-band'>Primitive Type <a class="primitive" href=''>str</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><span id='render-detail'>
                   <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
                       [<span class='inner'>&#x2212;</span>]
                   </a>
               </span></span></h1>
<div class='docblock'><p>String slices.</p>

<p>The <code>str</code> type, also called a &#39;string slice&#39;, is the most primitive string
type. It is usually seen in its borrowed form, <code>&amp;str</code>. It is also the type
of string literals, <code>&amp;&#39;static str</code>.</p>

<p>Strings slices are always valid UTF-8.</p>

<p>This documentation describes a number of methods and trait implementations
on the <code>str</code> type. For technical reasons, there is additional, separate
documentation in the <a href="str/index.html"><code>std::str</code></a> module as well.</p>

<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
<p>String literals are string slices:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">hello</span> <span class="op">=</span> <span class="string">&quot;Hello, world!&quot;</span>;

<span class="comment">// with an explicit type annotation</span>
<span class="kw">let</span> <span class="ident">hello</span>: <span class="kw-2">&amp;</span><span class="lifetime">&#39;static</span> <span class="ident">str</span> <span class="op">=</span> <span class="string">&quot;Hello, world!&quot;</span>;<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20hello%20%3D%20%22Hello%2C%20world!%22%3B%0A%0A%2F%2F%20with%20an%20explicit%20type%20annotation%0Alet%20hello%3A%20%26'static%20str%20%3D%20%22Hello%2C%20world!%22%3B%0A%7D">Run</a></pre>

<p>They are <code>&#39;static</code> because they&#39;re stored directly in the final binary, and
so will be valid for the <code>&#39;static</code> duration.</p>

<h1 id='representation' class='section-header'><a href='#representation'>Representation</a></h1>
<p>A <code>&amp;str</code> is made up of two components: a pointer to some bytes, and a
length. You can look at these with the <a href="#method.as_ptr"><code>as_ptr</code></a> and <a href="#method.len"><code>len</code></a> methods:</p>

<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">slice</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">str</span>;

<span class="kw">let</span> <span class="ident">story</span> <span class="op">=</span> <span class="string">&quot;Once upon a time...&quot;</span>;

<span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="ident">story</span>.<span class="ident">as_ptr</span>();
<span class="kw">let</span> <span class="ident">len</span> <span class="op">=</span> <span class="ident">story</span>.<span class="ident">len</span>();

<span class="comment">// story has nineteen bytes</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">19</span>, <span class="ident">len</span>);

<span class="comment">// We can re-build a str out of ptr and len. This is all unsafe because</span>
<span class="comment">// we are responsible for making sure the two components are valid:</span>
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="kw">unsafe</span> {
    <span class="comment">// First, we build a &amp;[u8]...</span>
    <span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> <span class="ident">slice</span>::<span class="ident">from_raw_parts</span>(<span class="ident">ptr</span>, <span class="ident">len</span>);

    <span class="comment">// ... and then convert that slice into a string slice</span>
    <span class="ident">str</span>::<span class="ident">from_utf8</span>(<span class="ident">slice</span>)
};

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>, <span class="prelude-val">Ok</span>(<span class="ident">story</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Aslice%3B%0Ause%20std%3A%3Astr%3B%0A%0Alet%20story%20%3D%20%22Once%20upon%20a%20time...%22%3B%0A%0Alet%20ptr%20%3D%20story.as_ptr()%3B%0Alet%20len%20%3D%20story.len()%3B%0A%0A%2F%2F%20story%20has%20nineteen%20bytes%0Aassert_eq!(19%2C%20len)%3B%0A%0A%2F%2F%20We%20can%20re-build%20a%20str%20out%20of%20ptr%20and%20len.%20This%20is%20all%20unsafe%20because%0A%2F%2F%20we%20are%20responsible%20for%20making%20sure%20the%20two%20components%20are%20valid%3A%0Alet%20s%20%3D%20unsafe%20%7B%0A%20%20%20%20%2F%2F%20First%2C%20we%20build%20a%20%26%5Bu8%5D...%0A%20%20%20%20let%20slice%20%3D%20slice%3A%3Afrom_raw_parts(ptr%2C%20len)%3B%0A%0A%20%20%20%20%2F%2F%20...%20and%20then%20convert%20that%20slice%20into%20a%20string%20slice%0A%20%20%20%20str%3A%3Afrom_utf8(slice)%0A%7D%3B%0A%0Aassert_eq!(s%2C%20Ok(story))%3B%0A%7D">Run</a></pre>

<p>Note: This example shows the internals of <code>&amp;str</code>. <code>unsafe</code> should not be
used to get a string slice under normal circumstances. Use <code>as_slice</code>
instead.</p>
</div><h2 id='methods'>Methods</h2><h3 class='impl'><span class='in-band'><code>impl <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/collections/str.rs.html#204-1997' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Methods for string slices.</p>
</div><div class='impl-items'><h4 id='method.len' class="method"><span id='len.v' class='invisible'><code>fn <a href='#method.len' class='fnname'>len</a>(&amp;self) -&gt; <a class="primitive" href="primitive.usize.html">usize</a></code></span></h4>
<div class='docblock'><p>Returns the length of <code>self</code>.</p>

<p>This length is in bytes, not <a href="primitive.char.html"><code>char</code></a>s or graphemes. In other words,
it may not be what a human considers the length of the string.</p>

<h1 id='examples-1' class='section-header'><a href='#examples-1'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">len</span> <span class="op">=</span> <span class="string">&quot;foo&quot;</span>.<span class="ident">len</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">3</span>, <span class="ident">len</span>);

<span class="kw">let</span> <span class="ident">len</span> <span class="op">=</span> <span class="string">&quot;ƒoo&quot;</span>.<span class="ident">len</span>(); <span class="comment">// fancy f!</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">4</span>, <span class="ident">len</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20len%20%3D%20%22foo%22.len()%3B%0Aassert_eq!(3%2C%20len)%3B%0A%0Alet%20len%20%3D%20%22%C6%92oo%22.len()%3B%20%2F%2F%20fancy%20f!%0Aassert_eq!(4%2C%20len)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.is_empty' class="method"><span id='is_empty.v' class='invisible'><code>fn <a href='#method.is_empty' class='fnname'>is_empty</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>Returns <code>true</code> if <code>self</code> has a length of zero bytes.</p>

<h1 id='examples-2' class='section-header'><a href='#examples-2'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;&quot;</span>;
<span class="macro">assert</span><span class="macro">!</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">&quot;not empty&quot;</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">s</span>.<span class="ident">is_empty</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22%22%3B%0Aassert!(s.is_empty())%3B%0A%0Alet%20s%20%3D%20%22not%20empty%22%3B%0Aassert!(!s.is_empty())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.is_char_boundary' class="method"><span id='is_char_boundary.v' class='invisible'><code>fn <a href='#method.is_char_boundary' class='fnname'>is_char_boundary</a>(&amp;self, index: <a class="primitive" href="primitive.usize.html">usize</a>) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code><div class='since' title='Stable since Rust version 1.9.0'>1.9.0</div></span></h4>
<div class='docblock'><p>Checks that <code>index</code>-th byte lies at the start and/or end of a
UTF-8 code point sequence.</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>

<h1 id='examples-3' class='section-header'><a href='#examples-3'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;Löwe 老虎 Léopard&quot;</span>;
<span class="macro">assert</span><span class="macro">!</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="macro">!</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="macro">!</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="macro">!</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="macro">!</span>(<span class="op">!</span><span class="ident">s</span>.<span class="ident">is_char_boundary</span>(<span class="number">8</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22L%C3%B6we%20%E8%80%81%E8%99%8E%20L%C3%A9opard%22%3B%0Aassert!(s.is_char_boundary(0))%3B%0A%2F%2F%20start%20of%20%60%E8%80%81%60%0Aassert!(s.is_char_boundary(6))%3B%0Aassert!(s.is_char_boundary(s.len()))%3B%0A%0A%2F%2F%20second%20byte%20of%20%60%C3%B6%60%0Aassert!(!s.is_char_boundary(2))%3B%0A%0A%2F%2F%20third%20byte%20of%20%60%E8%80%81%60%0Aassert!(!s.is_char_boundary(8))%3B%0A%7D">Run</a></pre>
</div><h4 id='method.as_bytes' class="method"><span id='as_bytes.v' class='invisible'><code>fn <a href='#method.as_bytes' class='fnname'>as_bytes</a>(&amp;self) -&gt; <a class="primitive" href="primitive.slice.html">&amp;[</a><a class="primitive" href="primitive.u8.html">u8</a><a class="primitive" href="primitive.slice.html">]</a></code></span></h4>
<div class='docblock'><p>Converts a string slice to a byte slice.</p>

<h1 id='examples-4' class='section-header'><a href='#examples-4'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="string">&quot;bors&quot;</span>.<span class="ident">as_bytes</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">b&quot;bors&quot;</span>, <span class="ident">bytes</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20bytes%20%3D%20%22bors%22.as_bytes()%3B%0Aassert_eq!(b%22bors%22%2C%20bytes)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.as_bytes_mut' class="method"><span id='as_bytes_mut.v' class='invisible'><code>unsafe fn <a href='#method.as_bytes_mut' class='fnname'>as_bytes_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="primitive.slice.html">&amp;mut [</a><a class="primitive" href="primitive.u8.html">u8</a><a class="primitive" href="primitive.slice.html">]</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>str_mut_extras </code><a href="https://github.com/rust-lang/rust/issues/41119">#41119</a>)</div></div><div class='docblock'><p>Converts a mutable string slice to a mutable byte slice.</p>
</div><h4 id='method.as_ptr' class="method"><span id='as_ptr.v' class='invisible'><code>fn <a href='#method.as_ptr' class='fnname'>as_ptr</a>(&amp;self) -&gt; <a class="primitive" href="primitive.pointer.html">*const </a><a class="primitive" href="primitive.u8.html">u8</a></code></span></h4>
<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="primitive.u8.html"><code>u8</code></a>. This pointer will be pointing to the first byte of the string
slice.</p>

<h1 id='examples-5' class='section-header'><a href='#examples-5'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;Hello&quot;</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>();<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22Hello%22%3B%0Alet%20ptr%20%3D%20s.as_ptr()%3B%0A%7D">Run</a></pre>
</div><h4 id='method.get' class="method"><span id='get.v' class='invisible'><code>fn <a href='#method.get' class='fnname'>get</a>&lt;I&gt;(&amp;self, i: I) -&gt; <a class="enum" href="../std/option/enum.Option.html" title="enum std::option::Option">Option</a>&lt;&amp;&lt;I as <a class="trait" href="../std/slice/trait.SliceIndex.html" title="trait std::slice::SliceIndex">SliceIndex</a>&lt;<a class="primitive" href="primitive.str.html">str</a>&gt;&gt;::<a class="trait" href="../std/slice/trait.SliceIndex.html" title="trait std::slice::SliceIndex">Output</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../std/slice/trait.SliceIndex.html" title="trait std::slice::SliceIndex">SliceIndex</a>&lt;<a class="primitive" href="primitive.str.html">str</a>&gt;,&nbsp;</span></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>str_checked_slicing </code><a href="https://github.com/rust-lang/rust/issues/39932">#39932</a>)</div></div><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="option/enum.Option.html#variant.None"><code>None</code></a> whenever equivalent indexing operation would panic.</p>

<h1 id='examples-6' class='section-header'><a href='#examples-6'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="string">&quot;🗻∈🌏&quot;</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;🗻&quot;</span>), <span class="ident">v</span>.<span class="ident">get</span>(<span class="number">0</span>..<span class="number">4</span>));
<span class="macro">assert</span><span class="macro">!</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="macro">!</span>(<span class="ident">v</span>.<span class="ident">get</span>(..<span class="number">8</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">get</span>(..<span class="number">42</span>).<span class="ident">is_none</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Bfeature(str_checked_slicing)%5D%0Afn%20main()%20%7B%0Alet%20v%20%3D%20%22%F0%9F%97%BB%E2%88%88%F0%9F%8C%8F%22%3B%0Aassert_eq!(Some(%22%F0%9F%97%BB%22)%2C%20v.get(0..4))%3B%0Aassert!(v.get(1..).is_none())%3B%0Aassert!(v.get(..8).is_none())%3B%0Aassert!(v.get(..42).is_none())%3B%0A%7D&amp;version=nightly">Run</a></pre>
</div><h4 id='method.get_mut' class="method"><span id='get_mut.v' class='invisible'><code>fn <a href='#method.get_mut' class='fnname'>get_mut</a>&lt;I&gt;(&amp;mut self, i: I) -&gt; <a class="enum" href="../std/option/enum.Option.html" title="enum std::option::Option">Option</a>&lt;&amp;mut &lt;I as <a class="trait" href="../std/slice/trait.SliceIndex.html" title="trait std::slice::SliceIndex">SliceIndex</a>&lt;<a class="primitive" href="primitive.str.html">str</a>&gt;&gt;::<a class="trait" href="../std/slice/trait.SliceIndex.html" title="trait std::slice::SliceIndex">Output</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../std/slice/trait.SliceIndex.html" title="trait std::slice::SliceIndex">SliceIndex</a>&lt;<a class="primitive" href="primitive.str.html">str</a>&gt;,&nbsp;</span></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>str_checked_slicing </code><a href="https://github.com/rust-lang/rust/issues/39932">#39932</a>)</div></div><div class='docblock'><p>Returns a mutable subslice of <code>str</code>.</p>

<p>This is the non-panicking alternative to indexing the <code>str</code>. Returns
<a href="option/enum.Option.html#variant.None"><code>None</code></a> whenever equivalent indexing operation would panic.</p>

<h1 id='examples-7' class='section-header'><a href='#examples-7'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">&quot;🗻∈🌏&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;🗻&quot;</span>), <span class="ident">v</span>.<span class="ident">get_mut</span>(<span class="number">0</span>..<span class="number">4</span>).<span class="ident">map</span>(<span class="op">|</span><span class="ident">v</span><span class="op">|</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">v</span>));
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">get_mut</span>(<span class="number">1</span>..).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">get_mut</span>(..<span class="number">8</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">get_mut</span>(..<span class="number">42</span>).<span class="ident">is_none</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Bfeature(str_checked_slicing)%5D%0Afn%20main()%20%7B%0Alet%20mut%20v%20%3D%20String%3A%3Afrom(%22%F0%9F%97%BB%E2%88%88%F0%9F%8C%8F%22)%3B%0Aassert_eq!(Some(%22%F0%9F%97%BB%22)%2C%20v.get_mut(0..4).map(%7Cv%7C%20%26*v))%3B%0Aassert!(v.get_mut(1..).is_none())%3B%0Aassert!(v.get_mut(..8).is_none())%3B%0Aassert!(v.get_mut(..42).is_none())%3B%0A%7D&amp;version=nightly">Run</a></pre>
</div><h4 id='method.get_unchecked' class="method"><span id='get_unchecked.v' class='invisible'><code>unsafe fn <a href='#method.get_unchecked' class='fnname'>get_unchecked</a>&lt;I&gt;(&amp;self, i: I) -&gt; &amp;&lt;I as <a class="trait" href="../std/slice/trait.SliceIndex.html" title="trait std::slice::SliceIndex">SliceIndex</a>&lt;<a class="primitive" href="primitive.str.html">str</a>&gt;&gt;::<a class="trait" href="../std/slice/trait.SliceIndex.html" title="trait std::slice::SliceIndex">Output</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../std/slice/trait.SliceIndex.html" title="trait std::slice::SliceIndex">SliceIndex</a>&lt;<a class="primitive" href="primitive.str.html">str</a>&gt;,&nbsp;</span></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>str_checked_slicing </code><a href="https://github.com/rust-lang/rust/issues/39932">#39932</a>)</div></div><div class='docblock'><p>Returns a unchecked subslice of <code>str</code>.</p>

<p>This is the unchecked alternative to indexing the <code>str</code>.</p>

<h1 id='safety' class='section-header'><a href='#safety'>Safety</a></h1>
<p>Callers of this function are responsible that these preconditions are
satisfied:</p>

<ul>
<li>The starting index must come before 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>

<h1 id='examples-8' class='section-header'><a href='#examples-8'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="string">&quot;🗻∈🌏&quot;</span>;
<span class="kw">unsafe</span> {
    <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;🗻&quot;</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="macro">!</span>(<span class="string">&quot;∈&quot;</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="macro">!</span>(<span class="string">&quot;🌏&quot;</span>, <span class="ident">v</span>.<span class="ident">get_unchecked</span>(<span class="number">7</span>..<span class="number">11</span>));
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Bfeature(str_checked_slicing)%5D%0Afn%20main()%20%7B%0Alet%20v%20%3D%20%22%F0%9F%97%BB%E2%88%88%F0%9F%8C%8F%22%3B%0Aunsafe%20%7B%0A%20%20%20%20assert_eq!(%22%F0%9F%97%BB%22%2C%20v.get_unchecked(0..4))%3B%0A%20%20%20%20assert_eq!(%22%E2%88%88%22%2C%20v.get_unchecked(4..7))%3B%0A%20%20%20%20assert_eq!(%22%F0%9F%8C%8F%22%2C%20v.get_unchecked(7..11))%3B%0A%7D%0A%7D&amp;version=nightly">Run</a></pre>
</div><h4 id='method.get_unchecked_mut' class="method"><span id='get_unchecked_mut.v' class='invisible'><code>unsafe fn <a href='#method.get_unchecked_mut' class='fnname'>get_unchecked_mut</a>&lt;I&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;i: I<br>) -&gt; &amp;mut &lt;I as <a class="trait" href="../std/slice/trait.SliceIndex.html" title="trait std::slice::SliceIndex">SliceIndex</a>&lt;<a class="primitive" href="primitive.str.html">str</a>&gt;&gt;::<a class="trait" href="../std/slice/trait.SliceIndex.html" title="trait std::slice::SliceIndex">Output</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../std/slice/trait.SliceIndex.html" title="trait std::slice::SliceIndex">SliceIndex</a>&lt;<a class="primitive" href="primitive.str.html">str</a>&gt;,&nbsp;</span></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>str_checked_slicing </code><a href="https://github.com/rust-lang/rust/issues/39932">#39932</a>)</div></div><div class='docblock'><p>Returns a mutable, unchecked subslice of <code>str</code>.</p>

<p>This is the unchecked alternative to indexing the <code>str</code>.</p>

<h1 id='safety-1' class='section-header'><a href='#safety-1'>Safety</a></h1>
<p>Callers of this function are responsible that these preconditions are
satisfied:</p>

<ul>
<li>The starting index must come before 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>

<h1 id='examples-9' class='section-header'><a href='#examples-9'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">&quot;🗻∈🌏&quot;</span>);
<span class="kw">unsafe</span> {
    <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;🗻&quot;</span>, <span class="ident">v</span>.<span class="ident">get_unchecked_mut</span>(<span class="number">0</span>..<span class="number">4</span>));
    <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;∈&quot;</span>, <span class="ident">v</span>.<span class="ident">get_unchecked_mut</span>(<span class="number">4</span>..<span class="number">7</span>));
    <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;🌏&quot;</span>, <span class="ident">v</span>.<span class="ident">get_unchecked_mut</span>(<span class="number">7</span>..<span class="number">11</span>));
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Bfeature(str_checked_slicing)%5D%0Afn%20main()%20%7B%0Alet%20mut%20v%20%3D%20String%3A%3Afrom(%22%F0%9F%97%BB%E2%88%88%F0%9F%8C%8F%22)%3B%0Aunsafe%20%7B%0A%20%20%20%20assert_eq!(%22%F0%9F%97%BB%22%2C%20v.get_unchecked_mut(0..4))%3B%0A%20%20%20%20assert_eq!(%22%E2%88%88%22%2C%20v.get_unchecked_mut(4..7))%3B%0A%20%20%20%20assert_eq!(%22%F0%9F%8C%8F%22%2C%20v.get_unchecked_mut(7..11))%3B%0A%7D%0A%7D&amp;version=nightly">Run</a></pre>
</div><h4 id='method.slice_unchecked' class="method"><span id='slice_unchecked.v' class='invisible'><code>unsafe fn <a href='#method.slice_unchecked' class='fnname'>slice_unchecked</a>(&amp;self, begin: <a class="primitive" href="primitive.usize.html">usize</a>, end: <a class="primitive" href="primitive.usize.html">usize</a>) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<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="primitive.str.html"><code>str</code></a> and <a href="ops/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="#method.slice_mut_unchecked"><code>slice_mut_unchecked</code></a> method.</p>

<h1 id='safety-2' class='section-header'><a href='#safety-2'>Safety</a></h1>
<p>Callers of this function are responsible that three preconditions are
satisfied:</p>

<ul>
<li><code>begin</code> must come before <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>

<h1 id='examples-10' class='section-header'><a href='#examples-10'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;Löwe 老虎 Léopard&quot;</span>;

<span class="kw">unsafe</span> {
    <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;Löwe 老虎 Léopard&quot;</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">&quot;Hello, world!&quot;</span>;

<span class="kw">unsafe</span> {
    <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;world&quot;</span>, <span class="ident">s</span>.<span class="ident">slice_unchecked</span>(<span class="number">7</span>, <span class="number">12</span>));
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22L%C3%B6we%20%E8%80%81%E8%99%8E%20L%C3%A9opard%22%3B%0A%0Aunsafe%20%7B%0A%20%20%20%20assert_eq!(%22L%C3%B6we%20%E8%80%81%E8%99%8E%20L%C3%A9opard%22%2C%20s.slice_unchecked(0%2C%2021))%3B%0A%7D%0A%0Alet%20s%20%3D%20%22Hello%2C%20world!%22%3B%0A%0Aunsafe%20%7B%0A%20%20%20%20assert_eq!(%22world%22%2C%20s.slice_unchecked(7%2C%2012))%3B%0A%7D%0A%7D">Run</a></pre>
</div><h4 id='method.slice_mut_unchecked' class="method"><span id='slice_mut_unchecked.v' class='invisible'><code>unsafe fn <a href='#method.slice_mut_unchecked' class='fnname'>slice_mut_unchecked</a>(&amp;mut self, begin: <a class="primitive" href="primitive.usize.html">usize</a>, end: <a class="primitive" href="primitive.usize.html">usize</a>) -&gt; &amp;mut <a class="primitive" href="primitive.str.html">str</a></code><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div></span></h4>
<div class='docblock'><p>Creates a string slice from another string slice, bypassing safety
checks.
This is generally not recommended, use with caution! For a safe
alternative see <a href="primitive.str.html"><code>str</code></a> and <a href="ops/trait.IndexMut.html"><code>IndexMut</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 an immutable string slice instead, see the
<a href="#method.slice_unchecked"><code>slice_unchecked</code></a> method.</p>

<h1 id='safety-3' class='section-header'><a href='#safety-3'>Safety</a></h1>
<p>Callers of this function are responsible that three preconditions are
satisfied:</p>

<ul>
<li><code>begin</code> must come before <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>
</div><h4 id='method.split_at' class="method"><span id='split_at.v' class='invisible'><code>fn <a href='#method.split_at' class='fnname'>split_at</a>(&amp;self, mid: <a class="primitive" href="primitive.usize.html">usize</a>) -&gt; <a class="primitive" href="primitive.tuple.html">(</a>&amp;<a class="primitive" href="primitive.str.html">str</a>, &amp;<a class="primitive" href="primitive.str.html">str</a><a class="primitive" href="primitive.tuple.html">)</a></code><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div></span></h4>
<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="#method.split_at_mut"><code>split_at_mut</code></a>
method.</p>

<h1 id='panics' class='section-header'><a href='#panics'>Panics</a></h1>
<p>Panics if <code>mid</code> is not on a UTF-8 code point boundary, or if it is
beyond the last code point of the string slice.</p>

<h1 id='examples-11' class='section-header'><a href='#examples-11'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;Per Martin-Löf&quot;</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="macro">!</span>(<span class="string">&quot;Per&quot;</span>, <span class="ident">first</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot; Martin-Löf&quot;</span>, <span class="ident">last</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22Per%20Martin-L%C3%B6f%22%3B%0A%0Alet%20(first%2C%20last)%20%3D%20s.split_at(3)%3B%0A%0Aassert_eq!(%22Per%22%2C%20first)%3B%0Aassert_eq!(%22%20Martin-L%C3%B6f%22%2C%20last)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.split_at_mut' class="method"><span id='split_at_mut.v' class='invisible'><code>fn <a href='#method.split_at_mut' class='fnname'>split_at_mut</a>(&amp;mut self, mid: <a class="primitive" href="primitive.usize.html">usize</a>) -&gt; <a class="primitive" href="primitive.tuple.html">(</a>&amp;mut <a class="primitive" href="primitive.str.html">str</a>, &amp;mut <a class="primitive" href="primitive.str.html">str</a><a class="primitive" href="primitive.tuple.html">)</a></code><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div></span></h4>
<div class='docblock'><p>Divide one mutable 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 immutable string slices instead, see the <a href="#method.split_at"><code>split_at</code></a> method.</p>

<h1 id='panics-1' class='section-header'><a href='#panics-1'>Panics</a></h1>
<p>Panics if <code>mid</code> is not on a UTF-8 code point boundary, or if it is
beyond the last code point of the string slice.</p>

<h1 id='examples-12' class='section-header'><a href='#examples-12'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;Per Martin-Löf&quot;</span>.<span class="ident">to_string</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_mut</span>(<span class="number">3</span>);

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;Per&quot;</span>, <span class="ident">first</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot; Martin-Löf&quot;</span>, <span class="ident">last</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20%22Per%20Martin-L%C3%B6f%22.to_string()%3B%0A%0Alet%20(first%2C%20last)%20%3D%20s.split_at_mut(3)%3B%0A%0Aassert_eq!(%22Per%22%2C%20first)%3B%0Aassert_eq!(%22%20Martin-L%C3%B6f%22%2C%20last)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.chars' class="method"><span id='chars.v' class='invisible'><code>fn <a href='#method.chars' class='fnname'>chars</a>(&amp;self) -&gt; <a class="struct" href="../std/str/struct.Chars.html" title="struct std::str::Chars">Chars</a></code></span></h4>
<div class='docblock'><p>Returns an iterator over the <a href="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="primitive.char.html"><code>char</code></a>. This method returns such an iterator.</p>

<p>It&#39;s important to remember that <a href="primitive.char.html"><code>char</code></a> represents a Unicode Scalar
Value, and may not match your idea of what a &#39;character&#39; is. Iteration
over grapheme clusters may be what you actually want.</p>

<h1 id='examples-13' class='section-header'><a href='#examples-13'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">word</span> <span class="op">=</span> <span class="string">&quot;goodbye&quot;</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="macro">!</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="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&#39;g&#39;</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&#39;o&#39;</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&#39;o&#39;</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&#39;d&#39;</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&#39;b&#39;</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&#39;y&#39;</span>), <span class="ident">chars</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&#39;e&#39;</span>), <span class="ident">chars</span>.<span class="ident">next</span>());

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">None</span>, <span class="ident">chars</span>.<span class="ident">next</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20word%20%3D%20%22goodbye%22%3B%0A%0Alet%20count%20%3D%20word.chars().count()%3B%0Aassert_eq!(7%2C%20count)%3B%0A%0Alet%20mut%20chars%20%3D%20word.chars()%3B%0A%0Aassert_eq!(Some('g')%2C%20chars.next())%3B%0Aassert_eq!(Some('o')%2C%20chars.next())%3B%0Aassert_eq!(Some('o')%2C%20chars.next())%3B%0Aassert_eq!(Some('d')%2C%20chars.next())%3B%0Aassert_eq!(Some('b')%2C%20chars.next())%3B%0Aassert_eq!(Some('y')%2C%20chars.next())%3B%0Aassert_eq!(Some('e')%2C%20chars.next())%3B%0A%0Aassert_eq!(None%2C%20chars.next())%3B%0A%7D">Run</a></pre>

<p>Remember, <a href="primitive.char.html"><code>char</code></a>s may not match your human intuition about characters:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="string">&quot;y̆&quot;</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="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&#39;y&#39;</span>), <span class="ident">chars</span>.<span class="ident">next</span>()); <span class="comment">// not &#39;y̆&#39;</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&#39;\u{0306}&#39;</span>), <span class="ident">chars</span>.<span class="ident">next</span>());

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">None</span>, <span class="ident">chars</span>.<span class="ident">next</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20y%20%3D%20%22y%CC%86%22%3B%0A%0Alet%20mut%20chars%20%3D%20y.chars()%3B%0A%0Aassert_eq!(Some('y')%2C%20chars.next())%3B%20%2F%2F%20not%20'y%CC%86'%0Aassert_eq!(Some('%5Cu%7B0306%7D')%2C%20chars.next())%3B%0A%0Aassert_eq!(None%2C%20chars.next())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.char_indices' class="method"><span id='char_indices.v' class='invisible'><code>fn <a href='#method.char_indices' class='fnname'>char_indices</a>(&amp;self) -&gt; <a class="struct" href="../std/str/struct.CharIndices.html" title="struct std::str::CharIndices">CharIndices</a></code></span></h4>
<div class='docblock'><p>Returns an iterator over the <a href="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="primitive.char.html"><code>char</code></a>. This method returns an iterator of both
these <a href="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="primitive.char.html"><code>char</code></a> is
second.</p>

<h1 id='examples-14' class='section-header'><a href='#examples-14'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">word</span> <span class="op">=</span> <span class="string">&quot;goodbye&quot;</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="macro">!</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="macro">!</span>(<span class="prelude-val">Some</span>((<span class="number">0</span>, <span class="string">&#39;g&#39;</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="string">&#39;o&#39;</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>((<span class="number">2</span>, <span class="string">&#39;o&#39;</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>((<span class="number">3</span>, <span class="string">&#39;d&#39;</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>((<span class="number">4</span>, <span class="string">&#39;b&#39;</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>((<span class="number">5</span>, <span class="string">&#39;y&#39;</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>((<span class="number">6</span>, <span class="string">&#39;e&#39;</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">None</span>, <span class="ident">char_indices</span>.<span class="ident">next</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20word%20%3D%20%22goodbye%22%3B%0A%0Alet%20count%20%3D%20word.char_indices().count()%3B%0Aassert_eq!(7%2C%20count)%3B%0A%0Alet%20mut%20char_indices%20%3D%20word.char_indices()%3B%0A%0Aassert_eq!(Some((0%2C%20'g'))%2C%20char_indices.next())%3B%0Aassert_eq!(Some((1%2C%20'o'))%2C%20char_indices.next())%3B%0Aassert_eq!(Some((2%2C%20'o'))%2C%20char_indices.next())%3B%0Aassert_eq!(Some((3%2C%20'd'))%2C%20char_indices.next())%3B%0Aassert_eq!(Some((4%2C%20'b'))%2C%20char_indices.next())%3B%0Aassert_eq!(Some((5%2C%20'y'))%2C%20char_indices.next())%3B%0Aassert_eq!(Some((6%2C%20'e'))%2C%20char_indices.next())%3B%0A%0Aassert_eq!(None%2C%20char_indices.next())%3B%0A%7D">Run</a></pre>

<p>Remember, <a href="primitive.char.html"><code>char</code></a>s may not match your human intuition about characters:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="string">&quot;y̆&quot;</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">y</span>.<span class="ident">char_indices</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>((<span class="number">0</span>, <span class="string">&#39;y&#39;</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>()); <span class="comment">// not (0, &#39;y̆&#39;)</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="string">&#39;\u{0306}&#39;</span>)), <span class="ident">char_indices</span>.<span class="ident">next</span>());

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">None</span>, <span class="ident">char_indices</span>.<span class="ident">next</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20y%20%3D%20%22y%CC%86%22%3B%0A%0Alet%20mut%20char_indices%20%3D%20y.char_indices()%3B%0A%0Aassert_eq!(Some((0%2C%20'y'))%2C%20char_indices.next())%3B%20%2F%2F%20not%20(0%2C%20'y%CC%86')%0Aassert_eq!(Some((1%2C%20'%5Cu%7B0306%7D'))%2C%20char_indices.next())%3B%0A%0Aassert_eq!(None%2C%20char_indices.next())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.bytes' class="method"><span id='bytes.v' class='invisible'><code>fn <a href='#method.bytes' class='fnname'>bytes</a>(&amp;self) -&gt; <a class="struct" href="../std/str/struct.Bytes.html" title="struct std::str::Bytes">Bytes</a></code></span></h4>
<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>

<h1 id='examples-15' class='section-header'><a href='#examples-15'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="string">&quot;bors&quot;</span>.<span class="ident">bytes</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">b&#39;b&#39;</span>), <span class="ident">bytes</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">b&#39;o&#39;</span>), <span class="ident">bytes</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">b&#39;r&#39;</span>), <span class="ident">bytes</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">b&#39;s&#39;</span>), <span class="ident">bytes</span>.<span class="ident">next</span>());

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">None</span>, <span class="ident">bytes</span>.<span class="ident">next</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20bytes%20%3D%20%22bors%22.bytes()%3B%0A%0Aassert_eq!(Some(b'b')%2C%20bytes.next())%3B%0Aassert_eq!(Some(b'o')%2C%20bytes.next())%3B%0Aassert_eq!(Some(b'r')%2C%20bytes.next())%3B%0Aassert_eq!(Some(b's')%2C%20bytes.next())%3B%0A%0Aassert_eq!(None%2C%20bytes.next())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.split_whitespace' class="method"><span id='split_whitespace.v' class='invisible'><code>fn <a href='#method.split_whitespace' class='fnname'>split_whitespace</a>(&amp;self) -&gt; <a class="struct" href="../std/str/struct.SplitWhitespace.html" title="struct std::str::SplitWhitespace">SplitWhitespace</a></code><div class='since' title='Stable since Rust version 1.1.0'>1.1.0</div></span></h4>
<div class='docblock'><p>Split 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>&#39;Whitespace&#39; is defined according to the terms of the Unicode Derived
Core Property <code>White_Space</code>.</p>

<h1 id='examples-16' class='section-header'><a href='#examples-16'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="string">&quot;A few words&quot;</span>.<span class="ident">split_whitespace</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;A&quot;</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;few&quot;</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;words&quot;</span>), <span class="ident">iter</span>.<span class="ident">next</span>());

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">None</span>, <span class="ident">iter</span>.<span class="ident">next</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20iter%20%3D%20%22A%20few%20words%22.split_whitespace()%3B%0A%0Aassert_eq!(Some(%22A%22)%2C%20iter.next())%3B%0Aassert_eq!(Some(%22few%22)%2C%20iter.next())%3B%0Aassert_eq!(Some(%22words%22)%2C%20iter.next())%3B%0A%0Aassert_eq!(None%2C%20iter.next())%3B%0A%7D">Run</a></pre>

<p>All kinds of whitespace are considered:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="string">&quot; Mary   had\ta\u{2009}little  \n\t lamb&quot;</span>.<span class="ident">split_whitespace</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;Mary&quot;</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;had&quot;</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;a&quot;</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;little&quot;</span>), <span class="ident">iter</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;lamb&quot;</span>), <span class="ident">iter</span>.<span class="ident">next</span>());

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">None</span>, <span class="ident">iter</span>.<span class="ident">next</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20iter%20%3D%20%22%20Mary%20%20%20had%5Cta%5Cu%7B2009%7Dlittle%20%20%5Cn%5Ct%20lamb%22.split_whitespace()%3B%0Aassert_eq!(Some(%22Mary%22)%2C%20iter.next())%3B%0Aassert_eq!(Some(%22had%22)%2C%20iter.next())%3B%0Aassert_eq!(Some(%22a%22)%2C%20iter.next())%3B%0Aassert_eq!(Some(%22little%22)%2C%20iter.next())%3B%0Aassert_eq!(Some(%22lamb%22)%2C%20iter.next())%3B%0A%0Aassert_eq!(None%2C%20iter.next())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.lines' class="method"><span id='lines.v' class='invisible'><code>fn <a href='#method.lines' class='fnname'>lines</a>(&amp;self) -&gt; <a class="struct" href="../std/str/struct.Lines.html" title="struct std::str::Lines">Lines</a></code></span></h4>
<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.</p>

<h1 id='examples-17' class='section-header'><a href='#examples-17'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">text</span> <span class="op">=</span> <span class="string">&quot;foo\r\nbar\n\nbaz\n&quot;</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="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;foo&quot;</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;bar&quot;</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;&quot;</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;baz&quot;</span>), <span class="ident">lines</span>.<span class="ident">next</span>());

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">None</span>, <span class="ident">lines</span>.<span class="ident">next</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20text%20%3D%20%22foo%5Cr%5Cnbar%5Cn%5Cnbaz%5Cn%22%3B%0Alet%20mut%20lines%20%3D%20text.lines()%3B%0A%0Aassert_eq!(Some(%22foo%22)%2C%20lines.next())%3B%0Aassert_eq!(Some(%22bar%22)%2C%20lines.next())%3B%0Aassert_eq!(Some(%22%22)%2C%20lines.next())%3B%0Aassert_eq!(Some(%22baz%22)%2C%20lines.next())%3B%0A%0Aassert_eq!(None%2C%20lines.next())%3B%0A%7D">Run</a></pre>

<p>The final line ending isn&#39;t required:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">text</span> <span class="op">=</span> <span class="string">&quot;foo\nbar\n\r\nbaz&quot;</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="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;foo&quot;</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;bar&quot;</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;&quot;</span>), <span class="ident">lines</span>.<span class="ident">next</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;baz&quot;</span>), <span class="ident">lines</span>.<span class="ident">next</span>());

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">None</span>, <span class="ident">lines</span>.<span class="ident">next</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20text%20%3D%20%22foo%5Cnbar%5Cn%5Cr%5Cnbaz%22%3B%0Alet%20mut%20lines%20%3D%20text.lines()%3B%0A%0Aassert_eq!(Some(%22foo%22)%2C%20lines.next())%3B%0Aassert_eq!(Some(%22bar%22)%2C%20lines.next())%3B%0Aassert_eq!(Some(%22%22)%2C%20lines.next())%3B%0Aassert_eq!(Some(%22baz%22)%2C%20lines.next())%3B%0A%0Aassert_eq!(None%2C%20lines.next())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.lines_any' class="method"><span id='lines_any.v' class='invisible'><code>fn <a href='#method.lines_any' class='fnname'>lines_any</a>(&amp;self) -&gt; <a class="struct" href="../std/str/struct.LinesAny.html" title="struct std::str::LinesAny">LinesAny</a></code></span></h4>
<div class='stability'><div class='stab deprecated'>Deprecated since 1.4.0<p>: use lines() instead now</p>
</div></div><div class='docblock'><p>An iterator over the lines of a string.</p>
</div><h4 id='method.encode_utf16' class="method"><span id='encode_utf16.v' class='invisible'><code>fn <a href='#method.encode_utf16' class='fnname'>encode_utf16</a>(&amp;self) -&gt; <a class="struct" href="../std/str/struct.EncodeUtf16.html" title="struct std::str::EncodeUtf16">EncodeUtf16</a></code><div class='since' title='Stable since Rust version 1.8.0'>1.8.0</div></span></h4>
<div class='docblock'><p>Returns an iterator of <code>u16</code> over the string encoded as UTF-16.</p>
</div><h4 id='method.contains' class="method"><span id='contains.v' class='invisible'><code>fn <a href='#method.contains' class='fnname'>contains</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; <a class="primitive" href="primitive.bool.html">bool</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<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>

<h1 id='examples-18' class='section-header'><a href='#examples-18'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">bananas</span> <span class="op">=</span> <span class="string">&quot;bananas&quot;</span>;

<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">bananas</span>.<span class="ident">contains</span>(<span class="string">&quot;nana&quot;</span>));
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">bananas</span>.<span class="ident">contains</span>(<span class="string">&quot;apples&quot;</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20bananas%20%3D%20%22bananas%22%3B%0A%0Aassert!(bananas.contains(%22nana%22))%3B%0Aassert!(!bananas.contains(%22apples%22))%3B%0A%7D">Run</a></pre>
</div><h4 id='method.starts_with' class="method"><span id='starts_with.v' class='invisible'><code>fn <a href='#method.starts_with' class='fnname'>starts_with</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; <a class="primitive" href="primitive.bool.html">bool</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<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>

<h1 id='examples-19' class='section-header'><a href='#examples-19'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">bananas</span> <span class="op">=</span> <span class="string">&quot;bananas&quot;</span>;

<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">bananas</span>.<span class="ident">starts_with</span>(<span class="string">&quot;bana&quot;</span>));
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">bananas</span>.<span class="ident">starts_with</span>(<span class="string">&quot;nana&quot;</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20bananas%20%3D%20%22bananas%22%3B%0A%0Aassert!(bananas.starts_with(%22bana%22))%3B%0Aassert!(!bananas.starts_with(%22nana%22))%3B%0A%7D">Run</a></pre>
</div><h4 id='method.ends_with' class="method"><span id='ends_with.v' class='invisible'><code>fn <a href='#method.ends_with' class='fnname'>ends_with</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; <a class="primitive" href="primitive.bool.html">bool</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;P as <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;&gt;::<a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Searcher</a>: <a class="trait" href="../std/str/pattern/trait.ReverseSearcher.html" title="trait std::str::pattern::ReverseSearcher">ReverseSearcher</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<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>

<h1 id='examples-20' class='section-header'><a href='#examples-20'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">bananas</span> <span class="op">=</span> <span class="string">&quot;bananas&quot;</span>;

<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">bananas</span>.<span class="ident">ends_with</span>(<span class="string">&quot;anas&quot;</span>));
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">bananas</span>.<span class="ident">ends_with</span>(<span class="string">&quot;nana&quot;</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20bananas%20%3D%20%22bananas%22%3B%0A%0Aassert!(bananas.ends_with(%22anas%22))%3B%0Aassert!(!bananas.ends_with(%22nana%22))%3B%0A%7D">Run</a></pre>
</div><h4 id='method.find' class="method"><span id='find.v' class='invisible'><code>fn <a href='#method.find' class='fnname'>find</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; <a class="enum" href="../std/option/enum.Option.html" title="enum std::option::Option">Option</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<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="option/enum.Option.html#variant.None"><code>None</code></a> if the pattern doesn&#39;t match.</p>

<p>The pattern can be a <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that determines if
a character matches.</p>

<h1 id='examples-21' class='section-header'><a href='#examples-21'>Examples</a></h1>
<p>Simple patterns:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;Löwe 老虎 Léopard&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="string">&#39;L&#39;</span>), <span class="prelude-val">Some</span>(<span class="number">0</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="string">&#39;é&#39;</span>), <span class="prelude-val">Some</span>(<span class="number">14</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="string">&quot;Léopard&quot;</span>), <span class="prelude-val">Some</span>(<span class="number">13</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22L%C3%B6we%20%E8%80%81%E8%99%8E%20L%C3%A9opard%22%3B%0A%0Aassert_eq!(s.find('L')%2C%20Some(0))%3B%0Aassert_eq!(s.find('%C3%A9')%2C%20Some(14))%3B%0Aassert_eq!(s.find(%22L%C3%A9opard%22)%2C%20Some(13))%3B%0A%7D">Run</a></pre>

<p>More complex patterns with closures:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;Löwe 老虎 Léopard&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="ident">char</span>::<span class="ident">is_whitespace</span>), <span class="prelude-val">Some</span>(<span class="number">5</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="ident">char</span>::<span class="ident">is_lowercase</span>), <span class="prelude-val">Some</span>(<span class="number">1</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22L%C3%B6we%20%E8%80%81%E8%99%8E%20L%C3%A9opard%22%3B%0A%0Aassert_eq!(s.find(char%3A%3Ais_whitespace)%2C%20Some(5))%3B%0Aassert_eq!(s.find(char%3A%3Ais_lowercase)%2C%20Some(1))%3B%0A%7D">Run</a></pre>

<p>Not finding the pattern:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;Löwe 老虎 Léopard&quot;</span>;
<span class="kw">let</span> <span class="ident">x</span>: <span class="kw-2">&amp;</span>[_] <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&#39;1&#39;</span>, <span class="string">&#39;2&#39;</span>];

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">find</span>(<span class="ident">x</span>), <span class="prelude-val">None</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22L%C3%B6we%20%E8%80%81%E8%99%8E%20L%C3%A9opard%22%3B%0Alet%20x%3A%20%26%5B_%5D%20%3D%20%26%5B'1'%2C%20'2'%5D%3B%0A%0Aassert_eq!(s.find(x)%2C%20None)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.rfind' class="method"><span id='rfind.v' class='invisible'><code>fn <a href='#method.rfind' class='fnname'>rfind</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; <a class="enum" href="../std/option/enum.Option.html" title="enum std::option::Option">Option</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;P as <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;&gt;::<a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Searcher</a>: <a class="trait" href="../std/str/pattern/trait.ReverseSearcher.html" title="trait std::str::pattern::ReverseSearcher">ReverseSearcher</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<div class='docblock'><p>Returns the byte index of the last character of this string slice that
matches the pattern.</p>

<p>Returns <a href="option/enum.Option.html#variant.None"><code>None</code></a> if the pattern doesn&#39;t match.</p>

<p>The pattern can be a <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that determines if
a character matches.</p>

<h1 id='examples-22' class='section-header'><a href='#examples-22'>Examples</a></h1>
<p>Simple patterns:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;Löwe 老虎 Léopard&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">rfind</span>(<span class="string">&#39;L&#39;</span>), <span class="prelude-val">Some</span>(<span class="number">13</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">rfind</span>(<span class="string">&#39;é&#39;</span>), <span class="prelude-val">Some</span>(<span class="number">14</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22L%C3%B6we%20%E8%80%81%E8%99%8E%20L%C3%A9opard%22%3B%0A%0Aassert_eq!(s.rfind('L')%2C%20Some(13))%3B%0Aassert_eq!(s.rfind('%C3%A9')%2C%20Some(14))%3B%0A%7D">Run</a></pre>

<p>More complex patterns with closures:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;Löwe 老虎 Léopard&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">rfind</span>(<span class="ident">char</span>::<span class="ident">is_whitespace</span>), <span class="prelude-val">Some</span>(<span class="number">12</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">rfind</span>(<span class="ident">char</span>::<span class="ident">is_lowercase</span>), <span class="prelude-val">Some</span>(<span class="number">20</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22L%C3%B6we%20%E8%80%81%E8%99%8E%20L%C3%A9opard%22%3B%0A%0Aassert_eq!(s.rfind(char%3A%3Ais_whitespace)%2C%20Some(12))%3B%0Aassert_eq!(s.rfind(char%3A%3Ais_lowercase)%2C%20Some(20))%3B%0A%7D">Run</a></pre>

<p>Not finding the pattern:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;Löwe 老虎 Léopard&quot;</span>;
<span class="kw">let</span> <span class="ident">x</span>: <span class="kw-2">&amp;</span>[_] <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&#39;1&#39;</span>, <span class="string">&#39;2&#39;</span>];

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">rfind</span>(<span class="ident">x</span>), <span class="prelude-val">None</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22L%C3%B6we%20%E8%80%81%E8%99%8E%20L%C3%A9opard%22%3B%0Alet%20x%3A%20%26%5B_%5D%20%3D%20%26%5B'1'%2C%20'2'%5D%3B%0A%0Aassert_eq!(s.rfind(x)%2C%20None)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.split' class="method"><span id='split.v' class='invisible'><code>fn <a href='#method.split' class='fnname'>split</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; <a class="struct" href="../std/str/struct.Split.html" title="struct std::str::Split">Split</a>&lt;'a, P&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<div class='docblock'><p>An iterator over substrings of this string slice, separated by
characters matched by a pattern.</p>

<p>The pattern can be a <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that determines the
split.</p>

<h1 id='iterator-behavior' class='section-header'><a href='#iterator-behavior'>Iterator behavior</a></h1>
<p>The returned iterator will be a <a href="iter/trait.DoubleEndedIterator.html"><code>DoubleEndedIterator</code></a> if the pattern
allows a reverse search and forward/reverse search yields the same
elements. This is true for, eg, <a href="primitive.char.html"><code>char</code></a> but not for <code>&amp;str</code>.</p>

<p>If the pattern allows a reverse search but its results might differ
from a forward search, the <a href="#method.rsplit"><code>rsplit</code></a> method can be used.</p>

<h1 id='examples-23' class='section-header'><a href='#examples-23'>Examples</a></h1>
<p>Simple patterns:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;Mary had a little lamb&quot;</span>.<span class="ident">split</span>(<span class="string">&#39; &#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;Mary&quot;</span>, <span class="string">&quot;had&quot;</span>, <span class="string">&quot;a&quot;</span>, <span class="string">&quot;little&quot;</span>, <span class="string">&quot;lamb&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;&quot;</span>.<span class="ident">split</span>(<span class="string">&#39;X&#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;lionXXtigerXleopard&quot;</span>.<span class="ident">split</span>(<span class="string">&#39;X&#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;lion&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;tiger&quot;</span>, <span class="string">&quot;leopard&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;lion::tiger::leopard&quot;</span>.<span class="ident">split</span>(<span class="string">&quot;::&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;lion&quot;</span>, <span class="string">&quot;tiger&quot;</span>, <span class="string">&quot;leopard&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;abc1def2ghi&quot;</span>.<span class="ident">split</span>(<span class="ident">char</span>::<span class="ident">is_numeric</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;def&quot;</span>, <span class="string">&quot;ghi&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;lionXtigerXleopard&quot;</span>.<span class="ident">split</span>(<span class="ident">char</span>::<span class="ident">is_uppercase</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;lion&quot;</span>, <span class="string">&quot;tiger&quot;</span>, <span class="string">&quot;leopard&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22Mary%20had%20a%20little%20lamb%22.split('%20').collect()%3B%0Aassert_eq!(v%2C%20%5B%22Mary%22%2C%20%22had%22%2C%20%22a%22%2C%20%22little%22%2C%20%22lamb%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22%22.split('X').collect()%3B%0Aassert_eq!(v%2C%20%5B%22%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22lionXXtigerXleopard%22.split('X').collect()%3B%0Aassert_eq!(v%2C%20%5B%22lion%22%2C%20%22%22%2C%20%22tiger%22%2C%20%22leopard%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22lion%3A%3Atiger%3A%3Aleopard%22.split(%22%3A%3A%22).collect()%3B%0Aassert_eq!(v%2C%20%5B%22lion%22%2C%20%22tiger%22%2C%20%22leopard%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22abc1def2ghi%22.split(char%3A%3Ais_numeric).collect()%3B%0Aassert_eq!(v%2C%20%5B%22abc%22%2C%20%22def%22%2C%20%22ghi%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22lionXtigerXleopard%22.split(char%3A%3Ais_uppercase).collect()%3B%0Aassert_eq!(v%2C%20%5B%22lion%22%2C%20%22tiger%22%2C%20%22leopard%22%5D)%3B%0A%7D">Run</a></pre>

<p>A more complex pattern, using a closure:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;abc1defXghi&quot;</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">&#39;1&#39;</span> <span class="op">||</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">&#39;X&#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;def&quot;</span>, <span class="string">&quot;ghi&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22abc1defXghi%22.split(%7Cc%7C%20c%20%3D%3D%20'1'%20%7C%7C%20c%20%3D%3D%20'X').collect()%3B%0Aassert_eq!(v%2C%20%5B%22abc%22%2C%20%22def%22%2C%20%22ghi%22%5D)%3B%0A%7D">Run</a></pre>

<p>If a string contains multiple contiguous separators, you will end up
with empty strings in the output:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="string">&quot;||||a||b|c&quot;</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">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">split</span>(<span class="string">&#39;|&#39;</span>).<span class="ident">collect</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>, <span class="kw-2">&amp;</span>[<span class="string">&quot;&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;a&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;b&quot;</span>, <span class="string">&quot;c&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20x%20%3D%20%22%7C%7C%7C%7Ca%7C%7Cb%7Cc%22.to_string()%3B%0Alet%20d%3A%20Vec%3C_%3E%20%3D%20x.split('%7C').collect()%3B%0A%0Aassert_eq!(d%2C%20%26%5B%22%22%2C%20%22%22%2C%20%22%22%2C%20%22%22%2C%20%22a%22%2C%20%22%22%2C%20%22b%22%2C%20%22c%22%5D)%3B%0A%7D">Run</a></pre>

<p>Contiguous separators are separated by the empty string.</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="string">&quot;(///)&quot;</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">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">split</span>(<span class="string">&#39;/&#39;</span>).<span class="ident">collect</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>, <span class="kw-2">&amp;</span>[<span class="string">&quot;(&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;)&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20x%20%3D%20%22(%2F%2F%2F)%22.to_string()%3B%0Alet%20d%3A%20Vec%3C_%3E%20%3D%20x.split('%2F').collect()%3B%0A%0Aassert_eq!(d%2C%20%26%5B%22(%22%2C%20%22%22%2C%20%22%22%2C%20%22)%22%5D)%3B%0A%7D">Run</a></pre>

<p>Separators at the start or end of a string are neighbored
by empty strings.</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">d</span>: <span class="ident">Vec</span><span class="op">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;010&quot;</span>.<span class="ident">split</span>(<span class="string">&quot;0&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>, <span class="kw-2">&amp;</span>[<span class="string">&quot;&quot;</span>, <span class="string">&quot;1&quot;</span>, <span class="string">&quot;&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20d%3A%20Vec%3C_%3E%20%3D%20%22010%22.split(%220%22).collect()%3B%0Aassert_eq!(d%2C%20%26%5B%22%22%2C%20%221%22%2C%20%22%22%5D)%3B%0A%7D">Run</a></pre>

<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>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">f</span>: <span class="ident">Vec</span><span class="op">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;rust&quot;</span>.<span class="ident">split</span>(<span class="string">&quot;&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">f</span>, <span class="kw-2">&amp;</span>[<span class="string">&quot;&quot;</span>, <span class="string">&quot;r&quot;</span>, <span class="string">&quot;u&quot;</span>, <span class="string">&quot;s&quot;</span>, <span class="string">&quot;t&quot;</span>, <span class="string">&quot;&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20f%3A%20Vec%3C_%3E%20%3D%20%22rust%22.split(%22%22).collect()%3B%0Aassert_eq!(f%2C%20%26%5B%22%22%2C%20%22r%22%2C%20%22u%22%2C%20%22s%22%2C%20%22t%22%2C%20%22%22%5D)%3B%0A%7D">Run</a></pre>

<p>Contiguous separators can lead to possibly surprising behavior
when whitespace is used as the separator. This code is correct:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="string">&quot;    a  b c&quot;</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">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">split</span>(<span class="string">&#39; &#39;</span>).<span class="ident">collect</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>, <span class="kw-2">&amp;</span>[<span class="string">&quot;&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;a&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;b&quot;</span>, <span class="string">&quot;c&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20x%20%3D%20%22%20%20%20%20a%20%20b%20c%22.to_string()%3B%0Alet%20d%3A%20Vec%3C_%3E%20%3D%20x.split('%20').collect()%3B%0A%0Aassert_eq!(d%2C%20%26%5B%22%22%2C%20%22%22%2C%20%22%22%2C%20%22%22%2C%20%22a%22%2C%20%22%22%2C%20%22b%22%2C%20%22c%22%5D)%3B%0A%7D">Run</a></pre>

<p>It does <em>not</em> give you:</p>

<pre class="rust rust-example-rendered">
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>, <span class="kw-2">&amp;</span>[<span class="string">&quot;a&quot;</span>, <span class="string">&quot;b&quot;</span>, <span class="string">&quot;c&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Aassert_eq!(d%2C%20%26%5B%22a%22%2C%20%22b%22%2C%20%22c%22%5D)%3B%0A%7D">Run</a></pre>

<p>Use <a href="#method.split_whitespace"><code>split_whitespace</code></a> for this behavior.</p>
</div><h4 id='method.rsplit' class="method"><span id='rsplit.v' class='invisible'><code>fn <a href='#method.rsplit' class='fnname'>rsplit</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; <a class="struct" href="../std/str/struct.RSplit.html" title="struct std::str::RSplit">RSplit</a>&lt;'a, P&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;P as <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;&gt;::<a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Searcher</a>: <a class="trait" href="../std/str/pattern/trait.ReverseSearcher.html" title="trait std::str::pattern::ReverseSearcher">ReverseSearcher</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<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 pattern can be a <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that determines the
split.</p>

<h1 id='iterator-behavior-1' class='section-header'><a href='#iterator-behavior-1'>Iterator behavior</a></h1>
<p>The returned iterator requires that the pattern supports a reverse
search, and it will be a <a href="iter/trait.DoubleEndedIterator.html"><code>DoubleEndedIterator</code></a> if a forward/reverse
search yields the same elements.</p>

<p>For iterating from the front, the <a href="#method.split"><code>split</code></a> method can be used.</p>

<h1 id='examples-24' class='section-header'><a href='#examples-24'>Examples</a></h1>
<p>Simple patterns:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;Mary had a little lamb&quot;</span>.<span class="ident">rsplit</span>(<span class="string">&#39; &#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;lamb&quot;</span>, <span class="string">&quot;little&quot;</span>, <span class="string">&quot;a&quot;</span>, <span class="string">&quot;had&quot;</span>, <span class="string">&quot;Mary&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;&quot;</span>.<span class="ident">rsplit</span>(<span class="string">&#39;X&#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;lionXXtigerXleopard&quot;</span>.<span class="ident">rsplit</span>(<span class="string">&#39;X&#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;leopard&quot;</span>, <span class="string">&quot;tiger&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;lion&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;lion::tiger::leopard&quot;</span>.<span class="ident">rsplit</span>(<span class="string">&quot;::&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;leopard&quot;</span>, <span class="string">&quot;tiger&quot;</span>, <span class="string">&quot;lion&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22Mary%20had%20a%20little%20lamb%22.rsplit('%20').collect()%3B%0Aassert_eq!(v%2C%20%5B%22lamb%22%2C%20%22little%22%2C%20%22a%22%2C%20%22had%22%2C%20%22Mary%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22%22.rsplit('X').collect()%3B%0Aassert_eq!(v%2C%20%5B%22%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22lionXXtigerXleopard%22.rsplit('X').collect()%3B%0Aassert_eq!(v%2C%20%5B%22leopard%22%2C%20%22tiger%22%2C%20%22%22%2C%20%22lion%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22lion%3A%3Atiger%3A%3Aleopard%22.rsplit(%22%3A%3A%22).collect()%3B%0Aassert_eq!(v%2C%20%5B%22leopard%22%2C%20%22tiger%22%2C%20%22lion%22%5D)%3B%0A%7D">Run</a></pre>

<p>A more complex pattern, using a closure:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;abc1defXghi&quot;</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">&#39;1&#39;</span> <span class="op">||</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">&#39;X&#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;ghi&quot;</span>, <span class="string">&quot;def&quot;</span>, <span class="string">&quot;abc&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22abc1defXghi%22.rsplit(%7Cc%7C%20c%20%3D%3D%20'1'%20%7C%7C%20c%20%3D%3D%20'X').collect()%3B%0Aassert_eq!(v%2C%20%5B%22ghi%22%2C%20%22def%22%2C%20%22abc%22%5D)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.split_terminator' class="method"><span id='split_terminator.v' class='invisible'><code>fn <a href='#method.split_terminator' class='fnname'>split_terminator</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; <a class="struct" href="../std/str/struct.SplitTerminator.html" title="struct std::str::SplitTerminator">SplitTerminator</a>&lt;'a, P&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<div class='docblock'><p>An iterator over substrings of the given string slice, separated by
characters matched by a pattern.</p>

<p>The pattern can be a <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that determines the
split.</p>

<p>Equivalent to <a href="#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>

<h1 id='iterator-behavior-2' class='section-header'><a href='#iterator-behavior-2'>Iterator behavior</a></h1>
<p>The returned iterator will be a <a href="iter/trait.DoubleEndedIterator.html"><code>DoubleEndedIterator</code></a> if the pattern
allows a reverse search and forward/reverse search yields the same
elements. This is true for, eg, <a href="primitive.char.html"><code>char</code></a> but not for <code>&amp;str</code>.</p>

<p>If the pattern allows a reverse search but its results might differ
from a forward search, the <a href="#method.rsplit_terminator"><code>rsplit_terminator</code></a> method can be used.</p>

<h1 id='examples-25' class='section-header'><a href='#examples-25'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;A.B.&quot;</span>.<span class="ident">split_terminator</span>(<span class="string">&#39;.&#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;A&quot;</span>, <span class="string">&quot;B&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;A..B..&quot;</span>.<span class="ident">split_terminator</span>(<span class="string">&quot;.&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;A&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;B&quot;</span>, <span class="string">&quot;&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22A.B.%22.split_terminator('.').collect()%3B%0Aassert_eq!(v%2C%20%5B%22A%22%2C%20%22B%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22A..B..%22.split_terminator(%22.%22).collect()%3B%0Aassert_eq!(v%2C%20%5B%22A%22%2C%20%22%22%2C%20%22B%22%2C%20%22%22%5D)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.rsplit_terminator' class="method"><span id='rsplit_terminator.v' class='invisible'><code>fn <a href='#method.rsplit_terminator' class='fnname'>rsplit_terminator</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; <a class="struct" href="../std/str/struct.RSplitTerminator.html" title="struct std::str::RSplitTerminator">RSplitTerminator</a>&lt;'a, P&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;P as <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;&gt;::<a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Searcher</a>: <a class="trait" href="../std/str/pattern/trait.ReverseSearcher.html" title="trait std::str::pattern::ReverseSearcher">ReverseSearcher</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<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 pattern can be a simple <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that
determines the split.
Additional libraries might provide more complex patterns like
regular expressions.</p>

<p>Equivalent to <a href="#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>

<h1 id='iterator-behavior-3' class='section-header'><a href='#iterator-behavior-3'>Iterator behavior</a></h1>
<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="#method.split_terminator"><code>split_terminator</code></a> method can be
used.</p>

<h1 id='examples-26' class='section-header'><a href='#examples-26'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;A.B.&quot;</span>.<span class="ident">rsplit_terminator</span>(<span class="string">&#39;.&#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;B&quot;</span>, <span class="string">&quot;A&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;A..B..&quot;</span>.<span class="ident">rsplit_terminator</span>(<span class="string">&quot;.&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;&quot;</span>, <span class="string">&quot;B&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;A&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22A.B.%22.rsplit_terminator('.').collect()%3B%0Aassert_eq!(v%2C%20%5B%22B%22%2C%20%22A%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22A..B..%22.rsplit_terminator(%22.%22).collect()%3B%0Aassert_eq!(v%2C%20%5B%22%22%2C%20%22B%22%2C%20%22%22%2C%20%22A%22%5D)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.splitn' class="method"><span id='splitn.v' class='invisible'><code>fn <a href='#method.splitn' class='fnname'>splitn</a>&lt;'a, P&gt;(&amp;'a self, n: <a class="primitive" href="primitive.usize.html">usize</a>, pat: P) -&gt; <a class="struct" href="../std/str/struct.SplitN.html" title="struct std::str::SplitN">SplitN</a>&lt;'a, P&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<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 pattern can be a <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that determines the
split.</p>

<h1 id='iterator-behavior-4' class='section-header'><a href='#iterator-behavior-4'>Iterator behavior</a></h1>
<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="#method.rsplitn"><code>rsplitn</code></a> method can be
used.</p>

<h1 id='examples-27' class='section-header'><a href='#examples-27'>Examples</a></h1>
<p>Simple patterns:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;Mary had a little lambda&quot;</span>.<span class="ident">splitn</span>(<span class="number">3</span>, <span class="string">&#39; &#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;Mary&quot;</span>, <span class="string">&quot;had&quot;</span>, <span class="string">&quot;a little lambda&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;lionXXtigerXleopard&quot;</span>.<span class="ident">splitn</span>(<span class="number">3</span>, <span class="string">&quot;X&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;lion&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;tigerXleopard&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;abcXdef&quot;</span>.<span class="ident">splitn</span>(<span class="number">1</span>, <span class="string">&#39;X&#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;abcXdef&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;&quot;</span>.<span class="ident">splitn</span>(<span class="number">1</span>, <span class="string">&#39;X&#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22Mary%20had%20a%20little%20lambda%22.splitn(3%2C%20'%20').collect()%3B%0Aassert_eq!(v%2C%20%5B%22Mary%22%2C%20%22had%22%2C%20%22a%20little%20lambda%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22lionXXtigerXleopard%22.splitn(3%2C%20%22X%22).collect()%3B%0Aassert_eq!(v%2C%20%5B%22lion%22%2C%20%22%22%2C%20%22tigerXleopard%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22abcXdef%22.splitn(1%2C%20'X').collect()%3B%0Aassert_eq!(v%2C%20%5B%22abcXdef%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22%22.splitn(1%2C%20'X').collect()%3B%0Aassert_eq!(v%2C%20%5B%22%22%5D)%3B%0A%7D">Run</a></pre>

<p>A more complex pattern, using a closure:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;abc1defXghi&quot;</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">&#39;1&#39;</span> <span class="op">||</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">&#39;X&#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;defXghi&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22abc1defXghi%22.splitn(2%2C%20%7Cc%7C%20c%20%3D%3D%20'1'%20%7C%7C%20c%20%3D%3D%20'X').collect()%3B%0Aassert_eq!(v%2C%20%5B%22abc%22%2C%20%22defXghi%22%5D)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.rsplitn' class="method"><span id='rsplitn.v' class='invisible'><code>fn <a href='#method.rsplitn' class='fnname'>rsplitn</a>&lt;'a, P&gt;(&amp;'a self, n: <a class="primitive" href="primitive.usize.html">usize</a>, pat: P) -&gt; <a class="struct" href="../std/str/struct.RSplitN.html" title="struct std::str::RSplitN">RSplitN</a>&lt;'a, P&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;P as <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;&gt;::<a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Searcher</a>: <a class="trait" href="../std/str/pattern/trait.ReverseSearcher.html" title="trait std::str::pattern::ReverseSearcher">ReverseSearcher</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<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 pattern can be a <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that
determines the split.</p>

<h1 id='iterator-behavior-5' class='section-header'><a href='#iterator-behavior-5'>Iterator behavior</a></h1>
<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="#method.splitn"><code>splitn</code></a> method can be used.</p>

<h1 id='examples-28' class='section-header'><a href='#examples-28'>Examples</a></h1>
<p>Simple patterns:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;Mary had a little lamb&quot;</span>.<span class="ident">rsplitn</span>(<span class="number">3</span>, <span class="string">&#39; &#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;lamb&quot;</span>, <span class="string">&quot;little&quot;</span>, <span class="string">&quot;Mary had a&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;lionXXtigerXleopard&quot;</span>.<span class="ident">rsplitn</span>(<span class="number">3</span>, <span class="string">&#39;X&#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;leopard&quot;</span>, <span class="string">&quot;tiger&quot;</span>, <span class="string">&quot;lionX&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;lion::tiger::leopard&quot;</span>.<span class="ident">rsplitn</span>(<span class="number">2</span>, <span class="string">&quot;::&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;leopard&quot;</span>, <span class="string">&quot;lion::tiger&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22Mary%20had%20a%20little%20lamb%22.rsplitn(3%2C%20'%20').collect()%3B%0Aassert_eq!(v%2C%20%5B%22lamb%22%2C%20%22little%22%2C%20%22Mary%20had%20a%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22lionXXtigerXleopard%22.rsplitn(3%2C%20'X').collect()%3B%0Aassert_eq!(v%2C%20%5B%22leopard%22%2C%20%22tiger%22%2C%20%22lionX%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22lion%3A%3Atiger%3A%3Aleopard%22.rsplitn(2%2C%20%22%3A%3A%22).collect()%3B%0Aassert_eq!(v%2C%20%5B%22leopard%22%2C%20%22lion%3A%3Atiger%22%5D)%3B%0A%7D">Run</a></pre>

<p>A more complex pattern, using a closure:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;abc1defXghi&quot;</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">&#39;1&#39;</span> <span class="op">||</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">&#39;X&#39;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;ghi&quot;</span>, <span class="string">&quot;abc1def&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22abc1defXghi%22.rsplitn(2%2C%20%7Cc%7C%20c%20%3D%3D%20'1'%20%7C%7C%20c%20%3D%3D%20'X').collect()%3B%0Aassert_eq!(v%2C%20%5B%22ghi%22%2C%20%22abc1def%22%5D)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.matches' class="method"><span id='matches.v' class='invisible'><code>fn <a href='#method.matches' class='fnname'>matches</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; <a class="struct" href="../std/str/struct.Matches.html" title="struct std::str::Matches">Matches</a>&lt;'a, P&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,&nbsp;</span></code><div class='since' title='Stable since Rust version 1.2.0'>1.2.0</div></span></h4>
<div class='docblock'><p>An iterator over the matches of a pattern within the given string
slice.</p>

<p>The pattern can be a <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that
determines if a character matches.</p>

<h1 id='iterator-behavior-6' class='section-header'><a href='#iterator-behavior-6'>Iterator behavior</a></h1>
<p>The returned iterator will be a <a href="iter/trait.DoubleEndedIterator.html"><code>DoubleEndedIterator</code></a> if the pattern
allows a reverse search and forward/reverse search yields the same
elements. This is true for, eg, <a href="primitive.char.html"><code>char</code></a> but not for <code>&amp;str</code>.</p>

<p>If the pattern allows a reverse search but its results might differ
from a forward search, the <a href="#method.rmatches"><code>rmatches</code></a> method can be used.</p>

<h1 id='examples-29' class='section-header'><a href='#examples-29'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;abcXXXabcYYYabc&quot;</span>.<span class="ident">matches</span>(<span class="string">&quot;abc&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abc&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;1abc2abc3&quot;</span>.<span class="ident">matches</span>(<span class="ident">char</span>::<span class="ident">is_numeric</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;1&quot;</span>, <span class="string">&quot;2&quot;</span>, <span class="string">&quot;3&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22abcXXXabcYYYabc%22.matches(%22abc%22).collect()%3B%0Aassert_eq!(v%2C%20%5B%22abc%22%2C%20%22abc%22%2C%20%22abc%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%221abc2abc3%22.matches(char%3A%3Ais_numeric).collect()%3B%0Aassert_eq!(v%2C%20%5B%221%22%2C%20%222%22%2C%20%223%22%5D)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.rmatches' class="method"><span id='rmatches.v' class='invisible'><code>fn <a href='#method.rmatches' class='fnname'>rmatches</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; <a class="struct" href="../std/str/struct.RMatches.html" title="struct std::str::RMatches">RMatches</a>&lt;'a, P&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;P as <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;&gt;::<a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Searcher</a>: <a class="trait" href="../std/str/pattern/trait.ReverseSearcher.html" title="trait std::str::pattern::ReverseSearcher">ReverseSearcher</a>&lt;'a&gt;,&nbsp;</span></code><div class='since' title='Stable since Rust version 1.2.0'>1.2.0</div></span></h4>
<div class='docblock'><p>An iterator over the matches of a pattern within this string slice,
yielded in reverse order.</p>

<p>The pattern can be a <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that determines if
a character matches.</p>

<h1 id='iterator-behavior-7' class='section-header'><a href='#iterator-behavior-7'>Iterator behavior</a></h1>
<p>The returned iterator requires that the pattern supports a reverse
search, and it will be a <a href="iter/trait.DoubleEndedIterator.html"><code>DoubleEndedIterator</code></a> if a forward/reverse
search yields the same elements.</p>

<p>For iterating from the front, the <a href="#method.matches"><code>matches</code></a> method can be used.</p>

<h1 id='examples-30' class='section-header'><a href='#examples-30'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;abcXXXabcYYYabc&quot;</span>.<span class="ident">rmatches</span>(<span class="string">&quot;abc&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abc&quot;</span>]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;1abc2abc3&quot;</span>.<span class="ident">rmatches</span>(<span class="ident">char</span>::<span class="ident">is_numeric</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">&quot;3&quot;</span>, <span class="string">&quot;2&quot;</span>, <span class="string">&quot;1&quot;</span>]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%22abcXXXabcYYYabc%22.rmatches(%22abc%22).collect()%3B%0Aassert_eq!(v%2C%20%5B%22abc%22%2C%20%22abc%22%2C%20%22abc%22%5D)%3B%0A%0Alet%20v%3A%20Vec%3C%26str%3E%20%3D%20%221abc2abc3%22.rmatches(char%3A%3Ais_numeric).collect()%3B%0Aassert_eq!(v%2C%20%5B%223%22%2C%20%222%22%2C%20%221%22%5D)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.match_indices' class="method"><span id='match_indices.v' class='invisible'><code>fn <a href='#method.match_indices' class='fnname'>match_indices</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; <a class="struct" href="../std/str/struct.MatchIndices.html" title="struct std::str::MatchIndices">MatchIndices</a>&lt;'a, P&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,&nbsp;</span></code><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div></span></h4>
<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 pattern can be a <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that determines
if a character matches.</p>

<h1 id='iterator-behavior-8' class='section-header'><a href='#iterator-behavior-8'>Iterator behavior</a></h1>
<p>The returned iterator will be a <a href="iter/trait.DoubleEndedIterator.html"><code>DoubleEndedIterator</code></a> if the pattern
allows a reverse search and forward/reverse search yields the same
elements. This is true for, eg, <a href="primitive.char.html"><code>char</code></a> but not for <code>&amp;str</code>.</p>

<p>If the pattern allows a reverse search but its results might differ
from a forward search, the <a href="#method.rmatch_indices"><code>rmatch_indices</code></a> method can be used.</p>

<h1 id='examples-31' class='section-header'><a href='#examples-31'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;abcXXXabcYYYabc&quot;</span>.<span class="ident">match_indices</span>(<span class="string">&quot;abc&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [(<span class="number">0</span>, <span class="string">&quot;abc&quot;</span>), (<span class="number">6</span>, <span class="string">&quot;abc&quot;</span>), (<span class="number">12</span>, <span class="string">&quot;abc&quot;</span>)]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;1abcabc2&quot;</span>.<span class="ident">match_indices</span>(<span class="string">&quot;abc&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [(<span class="number">1</span>, <span class="string">&quot;abc&quot;</span>), (<span class="number">4</span>, <span class="string">&quot;abc&quot;</span>)]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;ababa&quot;</span>.<span class="ident">match_indices</span>(<span class="string">&quot;aba&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [(<span class="number">0</span>, <span class="string">&quot;aba&quot;</span>)]); <span class="comment">// only the first `aba`</span><a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C_%3E%20%3D%20%22abcXXXabcYYYabc%22.match_indices(%22abc%22).collect()%3B%0Aassert_eq!(v%2C%20%5B(0%2C%20%22abc%22)%2C%20(6%2C%20%22abc%22)%2C%20(12%2C%20%22abc%22)%5D)%3B%0A%0Alet%20v%3A%20Vec%3C_%3E%20%3D%20%221abcabc2%22.match_indices(%22abc%22).collect()%3B%0Aassert_eq!(v%2C%20%5B(1%2C%20%22abc%22)%2C%20(4%2C%20%22abc%22)%5D)%3B%0A%0Alet%20v%3A%20Vec%3C_%3E%20%3D%20%22ababa%22.match_indices(%22aba%22).collect()%3B%0Aassert_eq!(v%2C%20%5B(0%2C%20%22aba%22)%5D)%3B%20%2F%2F%20only%20the%20first%20%60aba%60%0A%7D">Run</a></pre>
</div><h4 id='method.rmatch_indices' class="method"><span id='rmatch_indices.v' class='invisible'><code>fn <a href='#method.rmatch_indices' class='fnname'>rmatch_indices</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; <a class="struct" href="../std/str/struct.RMatchIndices.html" title="struct std::str::RMatchIndices">RMatchIndices</a>&lt;'a, P&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;P as <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;&gt;::<a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Searcher</a>: <a class="trait" href="../std/str/pattern/trait.ReverseSearcher.html" title="trait std::str::pattern::ReverseSearcher">ReverseSearcher</a>&lt;'a&gt;,&nbsp;</span></code><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div></span></h4>
<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 pattern can be a <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that determines if a
character matches.</p>

<h1 id='iterator-behavior-9' class='section-header'><a href='#iterator-behavior-9'>Iterator behavior</a></h1>
<p>The returned iterator requires that the pattern supports a reverse
search, and it will be a <a href="iter/trait.DoubleEndedIterator.html"><code>DoubleEndedIterator</code></a> if a forward/reverse
search yields the same elements.</p>

<p>For iterating from the front, the <a href="#method.match_indices"><code>match_indices</code></a> method can be used.</p>

<h1 id='examples-32' class='section-header'><a href='#examples-32'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;abcXXXabcYYYabc&quot;</span>.<span class="ident">rmatch_indices</span>(<span class="string">&quot;abc&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [(<span class="number">12</span>, <span class="string">&quot;abc&quot;</span>), (<span class="number">6</span>, <span class="string">&quot;abc&quot;</span>), (<span class="number">0</span>, <span class="string">&quot;abc&quot;</span>)]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;1abcabc2&quot;</span>.<span class="ident">rmatch_indices</span>(<span class="string">&quot;abc&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [(<span class="number">4</span>, <span class="string">&quot;abc&quot;</span>), (<span class="number">1</span>, <span class="string">&quot;abc&quot;</span>)]);

<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="string">&quot;ababa&quot;</span>.<span class="ident">rmatch_indices</span>(<span class="string">&quot;aba&quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [(<span class="number">2</span>, <span class="string">&quot;aba&quot;</span>)]); <span class="comment">// only the last `aba`</span><a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20v%3A%20Vec%3C_%3E%20%3D%20%22abcXXXabcYYYabc%22.rmatch_indices(%22abc%22).collect()%3B%0Aassert_eq!(v%2C%20%5B(12%2C%20%22abc%22)%2C%20(6%2C%20%22abc%22)%2C%20(0%2C%20%22abc%22)%5D)%3B%0A%0Alet%20v%3A%20Vec%3C_%3E%20%3D%20%221abcabc2%22.rmatch_indices(%22abc%22).collect()%3B%0Aassert_eq!(v%2C%20%5B(4%2C%20%22abc%22)%2C%20(1%2C%20%22abc%22)%5D)%3B%0A%0Alet%20v%3A%20Vec%3C_%3E%20%3D%20%22ababa%22.rmatch_indices(%22aba%22).collect()%3B%0Aassert_eq!(v%2C%20%5B(2%2C%20%22aba%22)%5D)%3B%20%2F%2F%20only%20the%20last%20%60aba%60%0A%7D">Run</a></pre>
</div><h4 id='method.trim' class="method"><span id='trim.v' class='invisible'><code>fn <a href='#method.trim' class='fnname'>trim</a>(&amp;self) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>Returns a string slice with leading and trailing whitespace removed.</p>

<p>&#39;Whitespace&#39; is defined according to the terms of the Unicode Derived
Core Property <code>White_Space</code>.</p>

<h1 id='examples-33' class='section-header'><a href='#examples-33'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot; Hello\tworld\t&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;Hello\tworld&quot;</span>, <span class="ident">s</span>.<span class="ident">trim</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22%20Hello%5Ctworld%5Ct%22%3B%0A%0Aassert_eq!(%22Hello%5Ctworld%22%2C%20s.trim())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.trim_left' class="method"><span id='trim_left.v' class='invisible'><code>fn <a href='#method.trim_left' class='fnname'>trim_left</a>(&amp;self) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>Returns a string slice with leading whitespace removed.</p>

<p>&#39;Whitespace&#39; is defined according to the terms of the Unicode Derived
Core Property <code>White_Space</code>.</p>

<h1 id='text-directionality' class='section-header'><a href='#text-directionality'>Text directionality</a></h1>
<p>A string is a sequence of bytes. &#39;Left&#39; in this context means the first
position of that byte string; for a language like Arabic or Hebrew
which are &#39;right to left&#39; rather than &#39;left to right&#39;, this will be
the <em>right</em> side, not the left.</p>

<h1 id='examples-34' class='section-header'><a href='#examples-34'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot; Hello\tworld\t&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;Hello\tworld\t&quot;</span>, <span class="ident">s</span>.<span class="ident">trim_left</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22%20Hello%5Ctworld%5Ct%22%3B%0A%0Aassert_eq!(%22Hello%5Ctworld%5Ct%22%2C%20s.trim_left())%3B%0A%7D">Run</a></pre>

<p>Directionality:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;  English&quot;</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&#39;E&#39;</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">&quot;  עברית&quot;</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&#39;ע&#39;</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>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22%20%20English%22%3B%0Aassert!(Some('E')%20%3D%3D%20s.trim_left().chars().next())%3B%0A%0Alet%20s%20%3D%20%22%20%20%D7%A2%D7%91%D7%A8%D7%99%D7%AA%22%3B%0Aassert!(Some('%D7%A2')%20%3D%3D%20s.trim_left().chars().next())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.trim_right' class="method"><span id='trim_right.v' class='invisible'><code>fn <a href='#method.trim_right' class='fnname'>trim_right</a>(&amp;self) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>Returns a string slice with trailing whitespace removed.</p>

<p>&#39;Whitespace&#39; is defined according to the terms of the Unicode Derived
Core Property <code>White_Space</code>.</p>

<h1 id='text-directionality-1' class='section-header'><a href='#text-directionality-1'>Text directionality</a></h1>
<p>A string is a sequence of bytes. &#39;Right&#39; in this context means the last
position of that byte string; for a language like Arabic or Hebrew
which are &#39;right to left&#39; rather than &#39;left to right&#39;, this will be
the <em>left</em> side, not the right.</p>

<h1 id='examples-35' class='section-header'><a href='#examples-35'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot; Hello\tworld\t&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot; Hello\tworld&quot;</span>, <span class="ident">s</span>.<span class="ident">trim_right</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22%20Hello%5Ctworld%5Ct%22%3B%0A%0Aassert_eq!(%22%20Hello%5Ctworld%22%2C%20s.trim_right())%3B%0A%7D">Run</a></pre>

<p>Directionality:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;English  &quot;</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&#39;h&#39;</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">&quot;עברית  &quot;</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="string">&#39;ת&#39;</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>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22English%20%20%22%3B%0Aassert!(Some('h')%20%3D%3D%20s.trim_right().chars().rev().next())%3B%0A%0Alet%20s%20%3D%20%22%D7%A2%D7%91%D7%A8%D7%99%D7%AA%20%20%22%3B%0Aassert!(Some('%D7%AA')%20%3D%3D%20s.trim_right().chars().rev().next())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.trim_matches' class="method"><span id='trim_matches.v' class='invisible'><code>fn <a href='#method.trim_matches' class='fnname'>trim_matches</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; &amp;'a <a class="primitive" href="primitive.str.html">str</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;P as <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;&gt;::<a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Searcher</a>: <a class="trait" href="../std/str/pattern/trait.DoubleEndedSearcher.html" title="trait std::str::pattern::DoubleEndedSearcher">DoubleEndedSearcher</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<div class='docblock'><p>Returns a string slice with all prefixes and suffixes that match a
pattern repeatedly removed.</p>

<p>The pattern can be a <a href="primitive.char.html"><code>char</code></a> or a closure that determines if a
character matches.</p>

<h1 id='examples-36' class='section-header'><a href='#examples-36'>Examples</a></h1>
<p>Simple patterns:</p>

<pre class="rust rust-example-rendered">
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;11foo1bar11&quot;</span>.<span class="ident">trim_matches</span>(<span class="string">&#39;1&#39;</span>), <span class="string">&quot;foo1bar&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;123foo1bar123&quot;</span>.<span class="ident">trim_matches</span>(<span class="ident">char</span>::<span class="ident">is_numeric</span>), <span class="string">&quot;foo1bar&quot;</span>);

<span class="kw">let</span> <span class="ident">x</span>: <span class="kw-2">&amp;</span>[_] <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&#39;1&#39;</span>, <span class="string">&#39;2&#39;</span>];
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;12foo1bar12&quot;</span>.<span class="ident">trim_matches</span>(<span class="ident">x</span>), <span class="string">&quot;foo1bar&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Aassert_eq!(%2211foo1bar11%22.trim_matches('1')%2C%20%22foo1bar%22)%3B%0Aassert_eq!(%22123foo1bar123%22.trim_matches(char%3A%3Ais_numeric)%2C%20%22foo1bar%22)%3B%0A%0Alet%20x%3A%20%26%5B_%5D%20%3D%20%26%5B'1'%2C%20'2'%5D%3B%0Aassert_eq!(%2212foo1bar12%22.trim_matches(x)%2C%20%22foo1bar%22)%3B%0A%7D">Run</a></pre>

<p>A more complex pattern, using a closure:</p>

<pre class="rust rust-example-rendered">
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;1foo1barXX&quot;</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">&#39;1&#39;</span> <span class="op">||</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">&#39;X&#39;</span>), <span class="string">&quot;foo1bar&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Aassert_eq!(%221foo1barXX%22.trim_matches(%7Cc%7C%20c%20%3D%3D%20'1'%20%7C%7C%20c%20%3D%3D%20'X')%2C%20%22foo1bar%22)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.trim_left_matches' class="method"><span id='trim_left_matches.v' class='invisible'><code>fn <a href='#method.trim_left_matches' class='fnname'>trim_left_matches</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; &amp;'a <a class="primitive" href="primitive.str.html">str</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<div class='docblock'><p>Returns a string slice with all prefixes that match a pattern
repeatedly removed.</p>

<p>The pattern can be a <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that determines if
a character matches.</p>

<h1 id='text-directionality-2' class='section-header'><a href='#text-directionality-2'>Text directionality</a></h1>
<p>A string is a sequence of bytes. &#39;Left&#39; in this context means the first
position of that byte string; for a language like Arabic or Hebrew
which are &#39;right to left&#39; rather than &#39;left to right&#39;, this will be
the <em>right</em> side, not the left.</p>

<h1 id='examples-37' class='section-header'><a href='#examples-37'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;11foo1bar11&quot;</span>.<span class="ident">trim_left_matches</span>(<span class="string">&#39;1&#39;</span>), <span class="string">&quot;foo1bar11&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;123foo1bar123&quot;</span>.<span class="ident">trim_left_matches</span>(<span class="ident">char</span>::<span class="ident">is_numeric</span>), <span class="string">&quot;foo1bar123&quot;</span>);

<span class="kw">let</span> <span class="ident">x</span>: <span class="kw-2">&amp;</span>[_] <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&#39;1&#39;</span>, <span class="string">&#39;2&#39;</span>];
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;12foo1bar12&quot;</span>.<span class="ident">trim_left_matches</span>(<span class="ident">x</span>), <span class="string">&quot;foo1bar12&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Aassert_eq!(%2211foo1bar11%22.trim_left_matches('1')%2C%20%22foo1bar11%22)%3B%0Aassert_eq!(%22123foo1bar123%22.trim_left_matches(char%3A%3Ais_numeric)%2C%20%22foo1bar123%22)%3B%0A%0Alet%20x%3A%20%26%5B_%5D%20%3D%20%26%5B'1'%2C%20'2'%5D%3B%0Aassert_eq!(%2212foo1bar12%22.trim_left_matches(x)%2C%20%22foo1bar12%22)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.trim_right_matches' class="method"><span id='trim_right_matches.v' class='invisible'><code>fn <a href='#method.trim_right_matches' class='fnname'>trim_right_matches</a>&lt;'a, P&gt;(&amp;'a self, pat: P) -&gt; &amp;'a <a class="primitive" href="primitive.str.html">str</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;P as <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;&gt;::<a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Searcher</a>: <a class="trait" href="../std/str/pattern/trait.ReverseSearcher.html" title="trait std::str::pattern::ReverseSearcher">ReverseSearcher</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<div class='docblock'><p>Returns a string slice with all suffixes that match a pattern
repeatedly removed.</p>

<p>The pattern can be a <code>&amp;str</code>, <a href="primitive.char.html"><code>char</code></a>, or a closure that
determines if a character matches.</p>

<h1 id='text-directionality-3' class='section-header'><a href='#text-directionality-3'>Text directionality</a></h1>
<p>A string is a sequence of bytes. &#39;Right&#39; in this context means the last
position of that byte string; for a language like Arabic or Hebrew
which are &#39;right to left&#39; rather than &#39;left to right&#39;, this will be
the <em>left</em> side, not the right.</p>

<h1 id='examples-38' class='section-header'><a href='#examples-38'>Examples</a></h1>
<p>Simple patterns:</p>

<pre class="rust rust-example-rendered">
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;11foo1bar11&quot;</span>.<span class="ident">trim_right_matches</span>(<span class="string">&#39;1&#39;</span>), <span class="string">&quot;11foo1bar&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;123foo1bar123&quot;</span>.<span class="ident">trim_right_matches</span>(<span class="ident">char</span>::<span class="ident">is_numeric</span>), <span class="string">&quot;123foo1bar&quot;</span>);

<span class="kw">let</span> <span class="ident">x</span>: <span class="kw-2">&amp;</span>[_] <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&#39;1&#39;</span>, <span class="string">&#39;2&#39;</span>];
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;12foo1bar12&quot;</span>.<span class="ident">trim_right_matches</span>(<span class="ident">x</span>), <span class="string">&quot;12foo1bar&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Aassert_eq!(%2211foo1bar11%22.trim_right_matches('1')%2C%20%2211foo1bar%22)%3B%0Aassert_eq!(%22123foo1bar123%22.trim_right_matches(char%3A%3Ais_numeric)%2C%20%22123foo1bar%22)%3B%0A%0Alet%20x%3A%20%26%5B_%5D%20%3D%20%26%5B'1'%2C%20'2'%5D%3B%0Aassert_eq!(%2212foo1bar12%22.trim_right_matches(x)%2C%20%2212foo1bar%22)%3B%0A%7D">Run</a></pre>

<p>A more complex pattern, using a closure:</p>

<pre class="rust rust-example-rendered">
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;1fooX&quot;</span>.<span class="ident">trim_left_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">&#39;1&#39;</span> <span class="op">||</span> <span class="ident">c</span> <span class="op">==</span> <span class="string">&#39;X&#39;</span>), <span class="string">&quot;fooX&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Aassert_eq!(%221fooX%22.trim_left_matches(%7Cc%7C%20c%20%3D%3D%20'1'%20%7C%7C%20c%20%3D%3D%20'X')%2C%20%22fooX%22)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.parse' class="method"><span id='parse.v' class='invisible'><code>fn <a href='#method.parse' class='fnname'>parse</a>&lt;F&gt;(&amp;self) -&gt; <a class="enum" href="../std/result/enum.Result.html" title="enum std::result::Result">Result</a>&lt;F, &lt;F as <a class="trait" href="../std/str/trait.FromStr.html" title="trait std::str::FromStr">FromStr</a>&gt;::<a class="trait" href="../std/str/trait.FromStr.html" title="trait std::str::FromStr">Err</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="../std/str/trait.FromStr.html" title="trait std::str::FromStr">FromStr</a>,&nbsp;</span></code></span></h4>
<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&#39;ll see
the syntax affectionately known as the &#39;turbofish&#39;: <code>::&lt;&gt;</code>. This
helps the inference algorithm understand specifically which type
you&#39;re trying to parse into.</p>

<p><code>parse</code> can parse any type that implements the <a href="str/trait.FromStr.html"><code>FromStr</code></a> trait.</p>

<h1 id='errors' class='section-header'><a href='#errors'>Errors</a></h1>
<p>Will return <a href="str/trait.FromStr.html#associatedtype.Err"><code>Err</code></a> if it&#39;s not possible to parse this string slice into
the desired type.</p>

<h1 id='example' class='section-header'><a href='#example'>Example</a></h1>
<p>Basic usage</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">four</span>: <span class="ident">u32</span> <span class="op">=</span> <span class="string">&quot;4&quot;</span>.<span class="ident">parse</span>().<span class="ident">unwrap</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">4</span>, <span class="ident">four</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20four%3A%20u32%20%3D%20%224%22.parse().unwrap()%3B%0A%0Aassert_eq!(4%2C%20four)%3B%0A%7D">Run</a></pre>

<p>Using the &#39;turbofish&#39; instead of annotating <code>four</code>:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">four</span> <span class="op">=</span> <span class="string">&quot;4&quot;</span>.<span class="ident">parse</span>::<span class="op">&lt;</span><span class="ident">u32</span><span class="op">&gt;</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Ok</span>(<span class="number">4</span>), <span class="ident">four</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20four%20%3D%20%224%22.parse%3A%3A%3Cu32%3E()%3B%0A%0Aassert_eq!(Ok(4)%2C%20four)%3B%0A%7D">Run</a></pre>

<p>Failing to parse:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">nope</span> <span class="op">=</span> <span class="string">&quot;j&quot;</span>.<span class="ident">parse</span>::<span class="op">&lt;</span><span class="ident">u32</span><span class="op">&gt;</span>();

<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">nope</span>.<span class="ident">is_err</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20nope%20%3D%20%22j%22.parse%3A%3A%3Cu32%3E()%3B%0A%0Aassert!(nope.is_err())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.into_boxed_bytes' class="method"><span id='into_boxed_bytes.v' class='invisible'><code>fn <a href='#method.into_boxed_bytes' class='fnname'>into_boxed_bytes</a>(self: <a class="struct" href="../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a>&lt;<a class="primitive" href="primitive.str.html">str</a>&gt;) -&gt; <a class="struct" href="../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a>&lt;<a class="primitive" href="primitive.slice.html">[</a><a class="primitive" href="primitive.u8.html">u8</a><a class="primitive" href="primitive.slice.html">]</a>&gt;</code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>str_box_extras </code><a href="https://github.com/rust-lang/rust/issues/41119">#41119</a>)</div></div><div class='docblock'><p>Converts a <code>Box&lt;str&gt;</code> into a <code>Box&lt;[u8]&gt;</code> without copying or allocating.</p>
</div><h4 id='method.replace' class="method"><span id='replace.v' class='invisible'><code>fn <a href='#method.replace' class='fnname'>replace</a>&lt;'a, P&gt;(&amp;'a self, from: P, to: &amp;<a class="primitive" href="primitive.str.html">str</a>) -&gt; <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<div class='docblock'><p>Replaces all matches of a pattern with another string.</p>

<p><code>replace</code> creates a new <a href="string/struct.String.html"><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>

<h1 id='examples-39' class='section-header'><a href='#examples-39'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;this is old&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;this is new&quot;</span>, <span class="ident">s</span>.<span class="ident">replace</span>(<span class="string">&quot;old&quot;</span>, <span class="string">&quot;new&quot;</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22this%20is%20old%22%3B%0A%0Aassert_eq!(%22this%20is%20new%22%2C%20s.replace(%22old%22%2C%20%22new%22))%3B%0A%7D">Run</a></pre>

<p>When the pattern doesn&#39;t match:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;this is old&quot;</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>, <span class="ident">s</span>.<span class="ident">replace</span>(<span class="string">&quot;cookie monster&quot;</span>, <span class="string">&quot;little lamb&quot;</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22this%20is%20old%22%3B%0Aassert_eq!(s%2C%20s.replace(%22cookie%20monster%22%2C%20%22little%20lamb%22))%3B%0A%7D">Run</a></pre>
</div><h4 id='method.replacen' class="method"><span id='replacen.v' class='invisible'><code>fn <a href='#method.replacen' class='fnname'>replacen</a>&lt;'a, P&gt;(&amp;'a self, pat: P, to: &amp;<a class="primitive" href="primitive.str.html">str</a>, count: <a class="primitive" href="primitive.usize.html">usize</a>) -&gt; <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt;,&nbsp;</span></code><div class='since' title='Stable since Rust version 1.16.0'>1.16.0</div></span></h4>
<div class='docblock'><p>Replaces first N matches of a pattern with another string.</p>

<p><code>replacen</code> creates a new <a href="string/struct.String.html"><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>

<h1 id='examples-40' class='section-header'><a href='#examples-40'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;foo foo 123 foo&quot;</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;new new 123 foo&quot;</span>, <span class="ident">s</span>.<span class="ident">replacen</span>(<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;new&quot;</span>, <span class="number">2</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;faa fao 123 foo&quot;</span>, <span class="ident">s</span>.<span class="ident">replacen</span>(<span class="string">&#39;o&#39;</span>, <span class="string">&quot;a&quot;</span>, <span class="number">3</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;foo foo new23 foo&quot;</span>, <span class="ident">s</span>.<span class="ident">replacen</span>(<span class="ident">char</span>::<span class="ident">is_numeric</span>, <span class="string">&quot;new&quot;</span>, <span class="number">1</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22foo%20foo%20123%20foo%22%3B%0Aassert_eq!(%22new%20new%20123%20foo%22%2C%20s.replacen(%22foo%22%2C%20%22new%22%2C%202))%3B%0Aassert_eq!(%22faa%20fao%20123%20foo%22%2C%20s.replacen('o'%2C%20%22a%22%2C%203))%3B%0Aassert_eq!(%22foo%20foo%20new23%20foo%22%2C%20s.replacen(char%3A%3Ais_numeric%2C%20%22new%22%2C%201))%3B%0A%7D">Run</a></pre>

<p>When the pattern doesn&#39;t match:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;this is old&quot;</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>, <span class="ident">s</span>.<span class="ident">replacen</span>(<span class="string">&quot;cookie monster&quot;</span>, <span class="string">&quot;little lamb&quot;</span>, <span class="number">10</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22this%20is%20old%22%3B%0Aassert_eq!(s%2C%20s.replacen(%22cookie%20monster%22%2C%20%22little%20lamb%22%2C%2010))%3B%0A%7D">Run</a></pre>
</div><h4 id='method.to_lowercase' class="method"><span id='to_lowercase.v' class='invisible'><code>fn <a href='#method.to_lowercase' class='fnname'>to_lowercase</a>(&amp;self) -&gt; <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a></code><div class='since' title='Stable since Rust version 1.2.0'>1.2.0</div></span></h4>
<div class='docblock'><p>Returns the lowercase equivalent of this string slice, as a new <a href="string/struct.String.html"><code>String</code></a>.</p>

<p>&#39;Lowercase&#39; 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="string/struct.String.html"><code>String</code></a> instead of modifying the
parameter in-place.</p>

<h1 id='examples-41' class='section-header'><a href='#examples-41'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;HELLO&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;hello&quot;</span>, <span class="ident">s</span>.<span class="ident">to_lowercase</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22HELLO%22%3B%0A%0Aassert_eq!(%22hello%22%2C%20s.to_lowercase())%3B%0A%7D">Run</a></pre>

<p>A tricky example, with sigma:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">sigma</span> <span class="op">=</span> <span class="string">&quot;Σ&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;σ&quot;</span>, <span class="ident">sigma</span>.<span class="ident">to_lowercase</span>());

<span class="comment">// but at the end of a word, it&#39;s ς, not σ:</span>
<span class="kw">let</span> <span class="ident">odysseus</span> <span class="op">=</span> <span class="string">&quot;ὈΔΥΣΣΕΎΣ&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;ὀδυσσεύς&quot;</span>, <span class="ident">odysseus</span>.<span class="ident">to_lowercase</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20sigma%20%3D%20%22%CE%A3%22%3B%0A%0Aassert_eq!(%22%CF%83%22%2C%20sigma.to_lowercase())%3B%0A%0A%2F%2F%20but%20at%20the%20end%20of%20a%20word%2C%20it's%20%CF%82%2C%20not%20%CF%83%3A%0Alet%20odysseus%20%3D%20%22%E1%BD%88%CE%94%CE%A5%CE%A3%CE%A3%CE%95%CE%8E%CE%A3%22%3B%0A%0Aassert_eq!(%22%E1%BD%80%CE%B4%CF%85%CF%83%CF%83%CE%B5%CF%8D%CF%82%22%2C%20odysseus.to_lowercase())%3B%0A%7D">Run</a></pre>

<p>Languages without case are not changed:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">new_year</span> <span class="op">=</span> <span class="string">&quot;农历新年&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">new_year</span>, <span class="ident">new_year</span>.<span class="ident">to_lowercase</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20new_year%20%3D%20%22%E5%86%9C%E5%8E%86%E6%96%B0%E5%B9%B4%22%3B%0A%0Aassert_eq!(new_year%2C%20new_year.to_lowercase())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.to_uppercase' class="method"><span id='to_uppercase.v' class='invisible'><code>fn <a href='#method.to_uppercase' class='fnname'>to_uppercase</a>(&amp;self) -&gt; <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a></code><div class='since' title='Stable since Rust version 1.2.0'>1.2.0</div></span></h4>
<div class='docblock'><p>Returns the uppercase equivalent of this string slice, as a new <a href="string/struct.String.html"><code>String</code></a>.</p>

<p>&#39;Uppercase&#39; 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="string/struct.String.html"><code>String</code></a> instead of modifying the
parameter in-place.</p>

<h1 id='examples-42' class='section-header'><a href='#examples-42'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;hello&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;HELLO&quot;</span>, <span class="ident">s</span>.<span class="ident">to_uppercase</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22hello%22%3B%0A%0Aassert_eq!(%22HELLO%22%2C%20s.to_uppercase())%3B%0A%7D">Run</a></pre>

<p>Scripts without case are not changed:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">new_year</span> <span class="op">=</span> <span class="string">&quot;农历新年&quot;</span>;

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">new_year</span>, <span class="ident">new_year</span>.<span class="ident">to_uppercase</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20new_year%20%3D%20%22%E5%86%9C%E5%8E%86%E6%96%B0%E5%B9%B4%22%3B%0A%0Aassert_eq!(new_year%2C%20new_year.to_uppercase())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.escape_debug' class="method"><span id='escape_debug.v' class='invisible'><code>fn <a href='#method.escape_debug' class='fnname'>escape_debug</a>(&amp;self) -&gt; <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a></code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>str_escape </code><a href="https://github.com/rust-lang/rust/issues/27791">#27791</a>)</summary><p>return type may change to be an iterator</p>
</details></div></div><div class='docblock'><p>Escapes each char in <code>s</code> with <a href="primitive.char.html#method.escape_debug"><code>char::escape_debug</code></a>.</p>
</div><h4 id='method.escape_default' class="method"><span id='escape_default.v' class='invisible'><code>fn <a href='#method.escape_default' class='fnname'>escape_default</a>(&amp;self) -&gt; <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a></code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>str_escape </code><a href="https://github.com/rust-lang/rust/issues/27791">#27791</a>)</summary><p>return type may change to be an iterator</p>
</details></div></div><div class='docblock'><p>Escapes each char in <code>s</code> with <a href="primitive.char.html#method.escape_default"><code>char::escape_default</code></a>.</p>
</div><h4 id='method.escape_unicode' class="method"><span id='escape_unicode.v' class='invisible'><code>fn <a href='#method.escape_unicode' class='fnname'>escape_unicode</a>(&amp;self) -&gt; <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a></code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>str_escape </code><a href="https://github.com/rust-lang/rust/issues/27791">#27791</a>)</summary><p>return type may change to be an iterator</p>
</details></div></div><div class='docblock'><p>Escapes each char in <code>s</code> with <a href="primitive.char.html#method.escape_unicode"><code>char::escape_unicode</code></a>.</p>
</div><h4 id='method.into_string' class="method"><span id='into_string.v' class='invisible'><code>fn <a href='#method.into_string' class='fnname'>into_string</a>(self: <a class="struct" href="../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a>&lt;<a class="primitive" href="primitive.str.html">str</a>&gt;) -&gt; <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a></code><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div></span></h4>
<div class='docblock'><p>Converts a <a href="boxed/struct.Box.html"><code>Box&lt;str&gt;</code></a> into a <a href="string/struct.String.html"><code>String</code></a> without copying or allocating.</p>

<h1 id='examples-43' class='section-header'><a href='#examples-43'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">string</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">&quot;birthday gift&quot;</span>);
<span class="kw">let</span> <span class="ident">boxed_str</span> <span class="op">=</span> <span class="ident">string</span>.<span class="ident">clone</span>().<span class="ident">into_boxed_str</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">boxed_str</span>.<span class="ident">into_string</span>(), <span class="ident">string</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20string%20%3D%20String%3A%3Afrom(%22birthday%20gift%22)%3B%0Alet%20boxed_str%20%3D%20string.clone().into_boxed_str()%3B%0A%0Aassert_eq!(boxed_str.into_string()%2C%20string)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.repeat' class="method"><span id='repeat.v' class='invisible'><code>fn <a href='#method.repeat' class='fnname'>repeat</a>(&amp;self, n: <a class="primitive" href="primitive.usize.html">usize</a>) -&gt; <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a></code><div class='since' title='Stable since Rust version 1.16.0'>1.16.0</div></span></h4>
<div class='docblock'><p>Create a <a href="string/struct.String.html"><code>String</code></a> by repeating a string <code>n</code> times.</p>

<h1 id='examples-44' class='section-header'><a href='#examples-44'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;abc&quot;</span>.<span class="ident">repeat</span>(<span class="number">4</span>), <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">&quot;abcabcabcabc&quot;</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Aassert_eq!(%22abc%22.repeat(4)%2C%20String%3A%3Afrom(%22abcabcabcabc%22))%3B%0A%7D">Run</a></pre>
</div></div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/borrow/trait.ToOwned.html" title="trait std::borrow::ToOwned">ToOwned</a> for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/collections/str.rs.html#188-199' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='associatedtype.Owned' class="type"><span id='Owned.t' class='invisible'><code>type <a href='../std/borrow/trait.ToOwned.html#associatedtype.Owned' class="type">Owned</a> = <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a></code></span></h4>
<h4 id='method.to_owned' class="method"><span id='to_owned.v' class='invisible'><code>fn <a href='../std/borrow/trait.ToOwned.html#tymethod.to_owned' class='fnname'>to_owned</a>(&amp;self) -&gt; <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a></code></span></h4>
<div class='docblock'><p>Creates owned data from borrowed data, usually by cloning. <a href="../std/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></p>
</div><h4 id='method.clone_into' class="method"><span id='clone_into.v' class='invisible'><code>fn <a href='../std/borrow/trait.ToOwned.html#method.clone_into' class='fnname'>clone_into</a>(&amp;self, target: &amp;mut <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a>)</code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>toowned_clone_into </code><a href="https://github.com/rust-lang/rust/issues/41263">#41263</a>)</summary><p>recently added</p>
</details></div></div><div class='docblock'><p>Uses borrowed data to replace owned data, usually by cloning. <a href="../std/borrow/trait.ToOwned.html#method.clone_into">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl&lt;'a, 'b&gt; <a class="trait" href="../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a>&lt;<a class="enum" href="../std/borrow/enum.Cow.html" title="enum std::borrow::Cow">Cow</a>&lt;'a, <a class="primitive" href="primitive.str.html">str</a>&gt;&gt; for &amp;'b <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/collections/string.rs.html#1707-1712' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.eq' class="method"><span id='eq.v' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, other: &amp;<a class="enum" href="../std/borrow/enum.Cow.html" title="enum std::borrow::Cow">Cow</a>&lt;'a, <a class="primitive" href="primitive.str.html">str</a>&gt;) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../std/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div><h4 id='method.ne' class="method"><span id='ne.v' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, other: &amp;<a class="enum" href="../std/borrow/enum.Cow.html" title="enum std::borrow::Cow">Cow</a>&lt;'a, <a class="primitive" href="primitive.str.html">str</a>&gt;) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl&lt;'a, 'b&gt; <a class="trait" href="../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a>&lt;<a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a>&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/collections/string.rs.html#1707-1712' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.eq-1' class="method"><span id='eq.v-1' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, other: &amp;<a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a>) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../std/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div><h4 id='method.ne-1' class="method"><span id='ne.v-1' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, other: &amp;<a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a>) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl&lt;'a, 'b&gt; <a class="trait" href="../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a>&lt;<a class="enum" href="../std/borrow/enum.Cow.html" title="enum std::borrow::Cow">Cow</a>&lt;'a, <a class="primitive" href="primitive.str.html">str</a>&gt;&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/collections/string.rs.html#1707-1712' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.eq-2' class="method"><span id='eq.v-2' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, other: &amp;<a class="enum" href="../std/borrow/enum.Cow.html" title="enum std::borrow::Cow">Cow</a>&lt;'a, <a class="primitive" href="primitive.str.html">str</a>&gt;) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../std/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div><h4 id='method.ne-2' class="method"><span id='ne.v-2' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, other: &amp;<a class="enum" href="../std/borrow/enum.Cow.html" title="enum std::borrow::Cow">Cow</a>&lt;'a, <a class="primitive" href="primitive.str.html">str</a>&gt;) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl&lt;'a, 'b&gt; <a class="trait" href="../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a>&lt;<a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a>&gt; for &amp;'a <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/collections/string.rs.html#1707-1712' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.eq-3' class="method"><span id='eq.v-3' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, other: &amp;<a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a>) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../std/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div><h4 id='method.ne-3' class="method"><span id='ne.v-3' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, other: &amp;<a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a>) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/string/trait.ToString.html" title="trait std::string::ToString">ToString</a> for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.9.0'>1.9.0</div><a class='srclink' href='../src/collections/string.rs.html#2035-2040' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.to_string' class="method"><span id='to_string.v' class='invisible'><code>fn <a href='../std/string/trait.ToString.html#tymethod.to_string' class='fnname'>to_string</a>(&amp;self) -&gt; <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a></code></span></h4>
<div class='docblock'><p>Converts the given value to a <code>String</code>. <a href="../std/string/trait.ToString.html#tymethod.to_string">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/convert/trait.AsRef.html" title="trait std::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="primitive.slice.html">[</a><a class="primitive" href="primitive.u8.html">u8</a><a class="primitive" href="primitive.slice.html">]</a>&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#2444-2449' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.as_ref' class="method"><span id='as_ref.v' class='invisible'><code>fn <a href='../std/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&amp;self) -&gt; <a class="primitive" href="primitive.slice.html">&amp;[</a><a class="primitive" href="primitive.u8.html">u8</a><a class="primitive" href="primitive.slice.html">]</a></code></span></h4>
<div class='docblock'><p>Performs the conversion.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/convert/trait.AsRef.html" title="trait std::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="primitive.str.html">str</a>&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/convert.rs.html#439-444' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.as_ref-1' class="method"><span id='as_ref.v-1' class='invisible'><code>fn <a href='../std/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&amp;self) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>Performs the conversion.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#1528' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'></div><h3 class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="../std/default/trait.Default.html" title="trait std::default::Default">Default</a> for &amp;'a <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#2452-2455' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.default' class="method"><span id='default.v' class='invisible'><code>fn <a href='../std/default/trait.Default.html#tymethod.default' class='fnname'>default</a>() -&gt; &amp;'a <a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>Creates an empty str</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/fmt/trait.Debug.html" title="trait std::fmt::Debug">Debug</a> for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/fmt/mod.rs.html#1516-1534' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='../std/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="../std/fmt/struct.Formatter.html" title="struct std::fmt::Formatter">Formatter</a>) -&gt; <a class="enum" href="../std/result/enum.Result.html" title="enum std::result::Result">Result</a>&lt;<a class="primitive" href="primitive.tuple.html">()</a>, <a class="struct" href="../std/fmt/struct.Error.html" title="struct std::fmt::Error">Error</a>&gt;</code></span></h4>
<div class='docblock'><p>Formats the value using the given formatter.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/ops/trait.Index.html" title="trait std::ops::Index">Index</a>&lt;<a class="struct" href="../std/ops/struct.RangeToInclusive.html" title="struct std::ops::RangeToInclusive">RangeToInclusive</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#1736-1745' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='associatedtype.Output' class="type"><span id='Output.t' class='invisible'><code>type <a href='../std/ops/trait.Index.html#associatedtype.Output' class="type">Output</a> = <a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The returned type after indexing</p>
</div><h4 id='method.index' class="method"><span id='index.v' class='invisible'><code>fn <a href='../std/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&amp;self, index: <a class="struct" href="../std/ops/struct.RangeToInclusive.html" title="struct std::ops::RangeToInclusive">RangeToInclusive</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The method for the indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/ops/trait.Index.html" title="trait std::ops::Index">Index</a>&lt;<a class="struct" href="../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#1722-1731' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='associatedtype.Output-1' class="type"><span id='Output.t-1' class='invisible'><code>type <a href='../std/ops/trait.Index.html#associatedtype.Output' class="type">Output</a> = <a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The returned type after indexing</p>
</div><h4 id='method.index-1' class="method"><span id='index.v-1' class='invisible'><code>fn <a href='../std/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&amp;self, index: <a class="struct" href="../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The method for the indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/ops/trait.Index.html" title="trait std::ops::Index">Index</a>&lt;<a class="struct" href="../std/ops/struct.RangeFrom.html" title="struct std::ops::RangeFrom">RangeFrom</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#1655-1667' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Implements substring slicing with syntax <code>&amp;self[begin ..]</code>.</p>

<p>Returns a slice of the string from byte offset <code>begin</code>
to the end of the string.</p>

<p>Equivalent to <code>&amp;self[begin .. len]</code>.</p>
</div><div class='impl-items'><h4 id='associatedtype.Output-2' class="type"><span id='Output.t-2' class='invisible'><code>type <a href='../std/ops/trait.Index.html#associatedtype.Output' class="type">Output</a> = <a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The returned type after indexing</p>
</div><h4 id='method.index-2' class="method"><span id='index.v-2' class='invisible'><code>fn <a href='../std/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&amp;self, index: <a class="struct" href="../std/ops/struct.RangeFrom.html" title="struct std::ops::RangeFrom">RangeFrom</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The method for the indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/ops/trait.Index.html" title="trait std::ops::Index">Index</a>&lt;<a class="struct" href="../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#1578-1584' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Implements substring slicing with syntax <code>&amp;self[begin .. end]</code>.</p>

<p>Returns a slice of the given string from the byte range
[<code>begin</code>..<code>end</code>).</p>

<p>This operation is <code>O(1)</code>.</p>

<h1 id='panics-2' class='section-header'><a href='#panics-2'>Panics</a></h1>
<p>Panics if <code>begin</code> or <code>end</code> does not point to the starting
byte offset of a character (as defined by <code>is_char_boundary</code>).
Requires that <code>begin &lt;= end</code> and <code>end &lt;= len</code> where <code>len</code> is the
length of the string.</p>

<h1 id='examples-45' class='section-header'><a href='#examples-45'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">&quot;Löwe 老虎 Léopard&quot;</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&amp;</span><span class="ident">s</span>[<span class="number">0</span> .. <span class="number">1</span>], <span class="string">&quot;L&quot;</span>);

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&amp;</span><span class="ident">s</span>[<span class="number">1</span> .. <span class="number">9</span>], <span class="string">&quot;öwe 老&quot;</span>);

<span class="comment">// these will panic:</span>
<span class="comment">// byte 2 lies within `ö`:</span>
<span class="comment">// &amp;s[2 ..3];</span>

<span class="comment">// byte 8 lies within `老`</span>
<span class="comment">// &amp;s[1 .. 8];</span>

<span class="comment">// byte 100 is outside the string</span>
<span class="comment">// &amp;s[3 .. 100];</span><a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22L%C3%B6we%20%E8%80%81%E8%99%8E%20L%C3%A9opard%22%3B%0Aassert_eq!(%26s%5B0%20..%201%5D%2C%20%22L%22)%3B%0A%0Aassert_eq!(%26s%5B1%20..%209%5D%2C%20%22%C3%B6we%20%E8%80%81%22)%3B%0A%0A%2F%2F%20these%20will%20panic%3A%0A%2F%2F%20byte%202%20lies%20within%20%60%C3%B6%60%3A%0A%2F%2F%20%26s%5B2%20..3%5D%3B%0A%0A%2F%2F%20byte%208%20lies%20within%20%60%E8%80%81%60%0A%2F%2F%20%26s%5B1%20..%208%5D%3B%0A%0A%2F%2F%20byte%20100%20is%20outside%20the%20string%0A%2F%2F%20%26s%5B3%20..%20100%5D%3B%0A%7D">Run</a></pre>
</div><div class='impl-items'><h4 id='associatedtype.Output-3' class="type"><span id='Output.t-3' class='invisible'><code>type <a href='../std/ops/trait.Index.html#associatedtype.Output' class="type">Output</a> = <a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The returned type after indexing</p>
</div><h4 id='method.index-3' class="method"><span id='index.v-3' class='invisible'><code>fn <a href='../std/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&amp;self, index: <a class="struct" href="../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The method for the indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/ops/trait.Index.html" title="trait std::ops::Index">Index</a>&lt;<a class="struct" href="../std/ops/struct.RangeFull.html" title="struct std::ops::RangeFull">RangeFull</a>&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#1696-1703' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Implements substring slicing with syntax <code>&amp;self[..]</code>.</p>

<p>Returns a slice of the whole string. This operation can
never panic.</p>

<p>Equivalent to <code>&amp;self[0 .. len]</code>.</p>
</div><div class='impl-items'><h4 id='associatedtype.Output-4' class="type"><span id='Output.t-4' class='invisible'><code>type <a href='../std/ops/trait.Index.html#associatedtype.Output' class="type">Output</a> = <a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The returned type after indexing</p>
</div><h4 id='method.index-4' class="method"><span id='index.v-4' class='invisible'><code>fn <a href='../std/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&amp;self, _index: <a class="struct" href="../std/ops/struct.RangeFull.html" title="struct std::ops::RangeFull">RangeFull</a>) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The method for the indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/ops/trait.Index.html" title="trait std::ops::Index">Index</a>&lt;<a class="struct" href="../std/ops/struct.RangeTo.html" title="struct std::ops::RangeTo">RangeTo</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#1615-1627' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Implements substring slicing with syntax <code>&amp;self[.. end]</code>.</p>

<p>Returns a slice of the string from the beginning to byte offset
<code>end</code>.</p>

<p>Equivalent to <code>&amp;self[0 .. end]</code>.</p>
</div><div class='impl-items'><h4 id='associatedtype.Output-5' class="type"><span id='Output.t-5' class='invisible'><code>type <a href='../std/ops/trait.Index.html#associatedtype.Output' class="type">Output</a> = <a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The returned type after indexing</p>
</div><h4 id='method.index-5' class="method"><span id='index.v-5' class='invisible'><code>fn <a href='../std/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&amp;self, index: <a class="struct" href="../std/ops/struct.RangeTo.html" title="struct std::ops::RangeTo">RangeTo</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The method for the indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/cmp/trait.Ord.html" title="trait std::cmp::Ord">Ord</a> for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#1510-1515' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Implements ordering of strings.</p>

<p>Strings are ordered  lexicographically by their byte values.  This orders Unicode code
points based on their positions in the code charts.  This is not necessarily the same as
&quot;alphabetical&quot; order, which varies by language and locale.  Sorting strings according to
culturally-accepted standards requires locale-specific data that is outside the scope of
the <code>str</code> type.</p>
</div><div class='impl-items'><h4 id='method.cmp' class="method"><span id='cmp.v' class='invisible'><code>fn <a href='../std/cmp/trait.Ord.html#tymethod.cmp' class='fnname'>cmp</a>(&amp;self, other: &amp;<a class="primitive" href="primitive.str.html">str</a>) -&gt; <a class="enum" href="../std/cmp/enum.Ordering.html" title="enum std::cmp::Ordering">Ordering</a></code></span></h4>
<div class='docblock'><p>This method returns an <code>Ordering</code> between <code>self</code> and <code>other</code>. <a href="../std/cmp/trait.Ord.html#tymethod.cmp">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a>&lt;<a class="primitive" href="primitive.str.html">str</a>&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#1518-1525' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.eq-4' class="method"><span id='eq.v-4' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, other: &amp;<a class="primitive" href="primitive.str.html">str</a>) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../std/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div><h4 id='method.ne-4' class="method"><span id='ne.v-4' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, other: &amp;<a class="primitive" href="primitive.str.html">str</a>) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/fmt/trait.Display.html" title="trait std::fmt::Display">Display</a> for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/fmt/mod.rs.html#1537-1541' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.fmt-1' class="method"><span id='fmt.v-1' class='invisible'><code>fn <a href='../std/fmt/trait.Display.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="../std/fmt/struct.Formatter.html" title="struct std::fmt::Formatter">Formatter</a>) -&gt; <a class="enum" href="../std/result/enum.Result.html" title="enum std::result::Result">Result</a>&lt;<a class="primitive" href="primitive.tuple.html">()</a>, <a class="struct" href="../std/fmt/struct.Error.html" title="struct std::fmt::Error">Error</a>&gt;</code></span></h4>
<div class='docblock'><p>Formats the value using the given formatter. <a href="../std/fmt/trait.Display.html#tymethod.fmt">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl&lt;'a, 'b&gt; <a class="trait" href="../std/str/pattern/trait.Pattern.html" title="trait std::str::pattern::Pattern">Pattern</a>&lt;'a&gt; for &amp;'b <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/pattern.rs.html#543-565' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Non-allocating substring search.</p>

<p>Will handle the pattern <code>&quot;&quot;</code> as returning empty matches at each character
boundary.</p>
</div><div class='impl-items'><h4 id='associatedtype.Searcher' class="type"><span id='Searcher.t' class='invisible'><code>type <a href='../std/str/pattern/trait.Pattern.html#associatedtype.Searcher' class="type">Searcher</a> = <a class="struct" href="../std/str/pattern/struct.StrSearcher.html" title="struct std::str::pattern::StrSearcher">StrSearcher</a>&lt;'a, 'b&gt;</code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>pattern </code><a href="https://github.com/rust-lang/rust/issues/27721">#27721</a>)</summary><p>API not fully fleshed out and ready to be stabilized</p>
</details></div></div><div class='docblock'><p>Associated searcher for this pattern</p>
</div><h4 id='method.into_searcher' class="method"><span id='into_searcher.v' class='invisible'><code>fn <a href='../std/str/pattern/trait.Pattern.html#tymethod.into_searcher' class='fnname'>into_searcher</a>(self, haystack: &amp;'a <a class="primitive" href="primitive.str.html">str</a>) -&gt; <a class="struct" href="../std/str/pattern/struct.StrSearcher.html" title="struct std::str::pattern::StrSearcher">StrSearcher</a>&lt;'a, 'b&gt;</code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>pattern </code><a href="https://github.com/rust-lang/rust/issues/27721">#27721</a>)</summary><p>API not fully fleshed out and ready to be stabilized</p>
</details></div></div><div class='docblock'><p>Constructs the associated searcher from <code>self</code> and the <code>haystack</code> to search in. <a href="../std/str/pattern/trait.Pattern.html#tymethod.into_searcher">Read more</a></p>
</div><h4 id='method.is_prefix_of' class="method"><span id='is_prefix_of.v' class='invisible'><code>fn <a href='../std/str/pattern/trait.Pattern.html#method.is_prefix_of' class='fnname'>is_prefix_of</a>(self, haystack: &amp;'a <a class="primitive" href="primitive.str.html">str</a>) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>pattern </code><a href="https://github.com/rust-lang/rust/issues/27721">#27721</a>)</summary><p>API not fully fleshed out and ready to be stabilized</p>
</details></div></div><div class='docblock'><p>Checks whether the pattern matches at the front of the haystack</p>
</div><h4 id='method.is_suffix_of' class="method"><span id='is_suffix_of.v' class='invisible'><code>fn <a href='../std/str/pattern/trait.Pattern.html#method.is_suffix_of' class='fnname'>is_suffix_of</a>(self, haystack: &amp;'a <a class="primitive" href="primitive.str.html">str</a>) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>pattern </code><a href="https://github.com/rust-lang/rust/issues/27721">#27721</a>)</summary><p>API not fully fleshed out and ready to be stabilized</p>
</details></div></div><div class='docblock'><p>Checks whether the pattern matches at the back of the haystack</p>
</div><h4 id='method.is_contained_in' class="method"><span id='is_contained_in.v' class='invisible'><code>fn <a href='../std/str/pattern/trait.Pattern.html#method.is_contained_in' class='fnname'>is_contained_in</a>(self, haystack: &amp;'a <a class="primitive" href="primitive.str.html">str</a>) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>pattern </code><a href="https://github.com/rust-lang/rust/issues/27721">#27721</a>)</summary><p>API not fully fleshed out and ready to be stabilized</p>
</details></div></div><div class='docblock'><p>Checks whether the pattern matches anywhere in the haystack</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/cmp/trait.PartialOrd.html" title="trait std::cmp::PartialOrd">PartialOrd</a>&lt;<a class="primitive" href="primitive.str.html">str</a>&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#1538-1543' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Implements comparison operations on strings.</p>

<p>Strings are compared lexicographically by their byte values.  This compares Unicode code
points based on their positions in the code charts.  This is not necessarily the same as
&quot;alphabetical&quot; order, which varies by language and locale.  Comparing strings according to
culturally-accepted standards requires locale-specific data that is outside the scope of
the <code>str</code> type.</p>
</div><div class='impl-items'><h4 id='method.partial_cmp' class="method"><span id='partial_cmp.v' class='invisible'><code>fn <a href='../std/cmp/trait.PartialOrd.html#tymethod.partial_cmp' class='fnname'>partial_cmp</a>(&amp;self, other: &amp;<a class="primitive" href="primitive.str.html">str</a>) -&gt; <a class="enum" href="../std/option/enum.Option.html" title="enum std::option::Option">Option</a>&lt;<a class="enum" href="../std/cmp/enum.Ordering.html" title="enum std::cmp::Ordering">Ordering</a>&gt;</code></span></h4>
<div class='docblock'><p>This method returns an ordering between <code>self</code> and <code>other</code> values if one exists. <a href="../std/cmp/trait.PartialOrd.html#tymethod.partial_cmp">Read more</a></p>
</div><h4 id='method.lt' class="method"><span id='lt.v' class='invisible'><code>fn <a href='../std/cmp/trait.PartialOrd.html#method.lt' class='fnname'>lt</a>(&amp;self, other: &amp;Rhs) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests less than (for <code>self</code> and <code>other</code>) and is used by the <code>&lt;</code> operator. <a href="../std/cmp/trait.PartialOrd.html#method.lt">Read more</a></p>
</div><h4 id='method.le' class="method"><span id='le.v' class='invisible'><code>fn <a href='../std/cmp/trait.PartialOrd.html#method.le' class='fnname'>le</a>(&amp;self, other: &amp;Rhs) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests less than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code>&lt;=</code> operator. <a href="../std/cmp/trait.PartialOrd.html#method.le">Read more</a></p>
</div><h4 id='method.gt' class="method"><span id='gt.v' class='invisible'><code>fn <a href='../std/cmp/trait.PartialOrd.html#method.gt' class='fnname'>gt</a>(&amp;self, other: &amp;Rhs) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests greater than (for <code>self</code> and <code>other</code>) and is used by the <code>&gt;</code> operator. <a href="../std/cmp/trait.PartialOrd.html#method.gt">Read more</a></p>
</div><h4 id='method.ge' class="method"><span id='ge.v' class='invisible'><code>fn <a href='../std/cmp/trait.PartialOrd.html#method.ge' class='fnname'>ge</a>(&amp;self, other: &amp;Rhs) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests greater than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code>&gt;=</code> operator. <a href="../std/cmp/trait.PartialOrd.html#method.ge">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/hash/mod.rs.html#545-550' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.hash' class="method"><span id='hash.v' class='invisible'><code>fn <a href='../std/hash/trait.Hash.html#tymethod.hash' class='fnname'>hash</a>&lt;H&gt;(&amp;self, state: &amp;mut H) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;H: <a class="trait" href="../std/hash/trait.Hasher.html" title="trait std::hash::Hasher">Hasher</a>,&nbsp;</span></code></span></h4>
<div class='docblock'><p>Feeds this value into the given [<code>Hasher</code>]. <a href="../std/hash/trait.Hash.html#tymethod.hash">Read more</a></p>
</div><h4 id='method.hash_slice' class="method"><span id='hash_slice.v' class='invisible'><code>fn <a href='../std/hash/trait.Hash.html#method.hash_slice' class='fnname'>hash_slice</a>&lt;H&gt;(data: <a class="primitive" href="primitive.slice.html">&amp;[Self]</a>, state: &amp;mut H) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;H: <a class="trait" href="../std/hash/trait.Hasher.html" title="trait std::hash::Hasher">Hasher</a>,&nbsp;</span></code><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div></span></h4>
<div class='docblock'><p>Feeds a slice of this type into the given [<code>Hasher</code>]. <a href="../std/hash/trait.Hash.html#method.hash_slice">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/ops/trait.IndexMut.html" title="trait std::ops::IndexMut">IndexMut</a>&lt;<a class="struct" href="../std/ops/struct.RangeTo.html" title="struct std::ops::RangeTo">RangeTo</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../src/core/str/mod.rs.html#1636-1646' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Implements mutable substring slicing with syntax <code>&amp;mut self[.. end]</code>.</p>

<p>Returns a mutable slice of the string from the beginning to byte offset
<code>end</code>.</p>

<p>Equivalent to <code>&amp;mut self[0 .. end]</code>.</p>
</div><div class='impl-items'><h4 id='method.index_mut' class="method"><span id='index_mut.v' class='invisible'><code>fn <a href='../std/ops/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&amp;mut self, index: <a class="struct" href="../std/ops/struct.RangeTo.html" title="struct std::ops::RangeTo">RangeTo</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;) -&gt; &amp;mut <a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The method for the mutable indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/ops/trait.IndexMut.html" title="trait std::ops::IndexMut">IndexMut</a>&lt;<a class="struct" href="../std/ops/struct.RangeToInclusive.html" title="struct std::ops::RangeToInclusive">RangeToInclusive</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#1761-1768' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.index_mut-1' class="method"><span id='index_mut.v-1' class='invisible'><code>fn <a href='../std/ops/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&amp;mut self, index: <a class="struct" href="../std/ops/struct.RangeToInclusive.html" title="struct std::ops::RangeToInclusive">RangeToInclusive</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;) -&gt; &amp;mut <a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The method for the mutable indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/ops/trait.IndexMut.html" title="trait std::ops::IndexMut">IndexMut</a>&lt;<a class="struct" href="../std/ops/struct.RangeFull.html" title="struct std::ops::RangeFull">RangeFull</a>&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../src/core/str/mod.rs.html#1712-1717' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Implements mutable substring slicing with syntax <code>&amp;mut self[..]</code>.</p>

<p>Returns a mutable slice of the whole string. This operation can
never panic.</p>

<p>Equivalent to <code>&amp;mut self[0 .. len]</code>.</p>
</div><div class='impl-items'><h4 id='method.index_mut-2' class="method"><span id='index_mut.v-2' class='invisible'><code>fn <a href='../std/ops/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&amp;mut self, _index: <a class="struct" href="../std/ops/struct.RangeFull.html" title="struct std::ops::RangeFull">RangeFull</a>) -&gt; &amp;mut <a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The method for the mutable indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/ops/trait.IndexMut.html" title="trait std::ops::IndexMut">IndexMut</a>&lt;<a class="struct" href="../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../src/core/str/mod.rs.html#1601-1606' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Implements mutable substring slicing with syntax
<code>&amp;mut self[begin .. end]</code>.</p>

<p>Returns a mutable slice of the given string from the byte range
[<code>begin</code>..<code>end</code>).</p>

<p>This operation is <code>O(1)</code>.</p>

<h1 id='panics-3' class='section-header'><a href='#panics-3'>Panics</a></h1>
<p>Panics if <code>begin</code> or <code>end</code> does not point to the starting
byte offset of a character (as defined by <code>is_char_boundary</code>).
Requires that <code>begin &lt;= end</code> and <code>end &lt;= len</code> where <code>len</code> is the
length of the string.</p>
</div><div class='impl-items'><h4 id='method.index_mut-3' class="method"><span id='index_mut.v-3' class='invisible'><code>fn <a href='../std/ops/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&amp;mut self, index: <a class="struct" href="../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;) -&gt; &amp;mut <a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The method for the mutable indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/ops/trait.IndexMut.html" title="trait std::ops::IndexMut">IndexMut</a>&lt;<a class="struct" href="../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/core/str/mod.rs.html#1750-1757' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.index_mut-4' class="method"><span id='index_mut.v-4' class='invisible'><code>fn <a href='../std/ops/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&amp;mut self, index: <a class="struct" href="../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;) -&gt; &amp;mut <a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The method for the mutable indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/ops/trait.IndexMut.html" title="trait std::ops::IndexMut">IndexMut</a>&lt;<a class="struct" href="../std/ops/struct.RangeFrom.html" title="struct std::ops::RangeFrom">RangeFrom</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../src/core/str/mod.rs.html#1676-1687' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Implements mutable substring slicing with syntax <code>&amp;mut self[begin ..]</code>.</p>

<p>Returns a mutable slice of the string from byte offset <code>begin</code>
to the end of the string.</p>

<p>Equivalent to <code>&amp;mut self[begin .. len]</code>.</p>
</div><div class='impl-items'><h4 id='method.index_mut-5' class="method"><span id='index_mut.v-5' class='invisible'><code>fn <a href='../std/ops/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&amp;mut self, index: <a class="struct" href="../std/ops/struct.RangeFrom.html" title="struct std::ops::RangeFrom">RangeFrom</a>&lt;<a class="primitive" href="primitive.usize.html">usize</a>&gt;) -&gt; &amp;mut <a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='docblock'><p>The method for the mutable indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std_unicode/u_str/trait.UnicodeStr.html" title="trait std_unicode::u_str::UnicodeStr">UnicodeStr</a> for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/std_unicode/u_str.rs.html#45-75' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.split_whitespace-1' class="method"><span id='split_whitespace.v-1' class='invisible'><code>fn <a href='../std_unicode/u_str/trait.UnicodeStr.html#tymethod.split_whitespace' class='fnname'>split_whitespace</a>(&amp;self) -&gt; <a class="struct" href="../std/str/struct.SplitWhitespace.html" title="struct std::str::SplitWhitespace">SplitWhitespace</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>unicode </code><a href="https://github.com/rust-lang/rust/issues/27783">#27783</a>)</div></div><h4 id='method.is_whitespace' class="method"><span id='is_whitespace.v' class='invisible'><code>fn <a href='../std_unicode/u_str/trait.UnicodeStr.html#tymethod.is_whitespace' class='fnname'>is_whitespace</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>unicode </code><a href="https://github.com/rust-lang/rust/issues/27783">#27783</a>)</div></div><h4 id='method.is_alphanumeric' class="method"><span id='is_alphanumeric.v' class='invisible'><code>fn <a href='../std_unicode/u_str/trait.UnicodeStr.html#tymethod.is_alphanumeric' class='fnname'>is_alphanumeric</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>unicode </code><a href="https://github.com/rust-lang/rust/issues/27783">#27783</a>)</div></div><h4 id='method.trim-1' class="method"><span id='trim.v-1' class='invisible'><code>fn <a href='../std_unicode/u_str/trait.UnicodeStr.html#tymethod.trim' class='fnname'>trim</a>(&amp;self) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>unicode </code><a href="https://github.com/rust-lang/rust/issues/27783">#27783</a>)</div></div><h4 id='method.trim_left-1' class="method"><span id='trim_left.v-1' class='invisible'><code>fn <a href='../std_unicode/u_str/trait.UnicodeStr.html#tymethod.trim_left' class='fnname'>trim_left</a>(&amp;self) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>unicode </code><a href="https://github.com/rust-lang/rust/issues/27783">#27783</a>)</div></div><h4 id='method.trim_right-1' class="method"><span id='trim_right.v-1' class='invisible'><code>fn <a href='../std_unicode/u_str/trait.UnicodeStr.html#tymethod.trim_right' class='fnname'>trim_right</a>(&amp;self) -&gt; &amp;<a class="primitive" href="primitive.str.html">str</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>unicode </code><a href="https://github.com/rust-lang/rust/issues/27783">#27783</a>)</div></div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/ascii/trait.AsciiExt.html" title="trait std::ascii::AsciiExt">AsciiExt</a> for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/std/ascii.rs.html#571-659' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='associatedtype.Owned-1' class="type"><span id='Owned.t-1' class='invisible'><code>type <a href='../std/ascii/trait.AsciiExt.html#associatedtype.Owned' class="type">Owned</a> = <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a></code></span></h4>
<div class='docblock'><p>Container type for copied ASCII characters.</p>
</div><h4 id='method.is_ascii' class="method"><span id='is_ascii.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#tymethod.is_ascii' class='fnname'>is_ascii</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>Checks if the value is within the ASCII range. <a href="../std/ascii/trait.AsciiExt.html#tymethod.is_ascii">Read more</a></p>
</div><h4 id='method.to_ascii_uppercase' class="method"><span id='to_ascii_uppercase.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#tymethod.to_ascii_uppercase' class='fnname'>to_ascii_uppercase</a>(&amp;self) -&gt; <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a></code></span></h4>
<div class='docblock'><p>Makes a copy of the value in its ASCII upper case equivalent. <a href="../std/ascii/trait.AsciiExt.html#tymethod.to_ascii_uppercase">Read more</a></p>
</div><h4 id='method.to_ascii_lowercase' class="method"><span id='to_ascii_lowercase.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#tymethod.to_ascii_lowercase' class='fnname'>to_ascii_lowercase</a>(&amp;self) -&gt; <a class="struct" href="../std/string/struct.String.html" title="struct std::string::String">String</a></code></span></h4>
<div class='docblock'><p>Makes a copy of the value in its ASCII lower case equivalent. <a href="../std/ascii/trait.AsciiExt.html#tymethod.to_ascii_lowercase">Read more</a></p>
</div><h4 id='method.eq_ignore_ascii_case' class="method"><span id='eq_ignore_ascii_case.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#tymethod.eq_ignore_ascii_case' class='fnname'>eq_ignore_ascii_case</a>(&amp;self, other: &amp;<a class="primitive" href="primitive.str.html">str</a>) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>Checks that two values are an ASCII case-insensitive match. <a href="../std/ascii/trait.AsciiExt.html#tymethod.eq_ignore_ascii_case">Read more</a></p>
</div><h4 id='method.make_ascii_uppercase' class="method"><span id='make_ascii_uppercase.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#tymethod.make_ascii_uppercase' class='fnname'>make_ascii_uppercase</a>(&amp;mut self)</code></span></h4>
<div class='docblock'><p>Converts this type to its ASCII upper case equivalent in-place. <a href="../std/ascii/trait.AsciiExt.html#tymethod.make_ascii_uppercase">Read more</a></p>
</div><h4 id='method.make_ascii_lowercase' class="method"><span id='make_ascii_lowercase.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#tymethod.make_ascii_lowercase' class='fnname'>make_ascii_lowercase</a>(&amp;mut self)</code></span></h4>
<div class='docblock'><p>Converts this type to its ASCII lower case equivalent in-place. <a href="../std/ascii/trait.AsciiExt.html#tymethod.make_ascii_lowercase">Read more</a></p>
</div><h4 id='method.is_ascii_alphabetic' class="method"><span id='is_ascii_alphabetic.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#method.is_ascii_alphabetic' class='fnname'>is_ascii_alphabetic</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>ascii_ctype </code><a href="https://github.com/rust-lang/rust/issues/39658">#39658</a>)</div></div><div class='docblock'><p>Checks if the value is an ASCII alphabetic character: U+0041 &#39;A&#39; ... U+005A &#39;Z&#39; or U+0061 &#39;a&#39; ... U+007A &#39;z&#39;. For strings, true if all characters in the string are ASCII alphabetic. <a href="../std/ascii/trait.AsciiExt.html#method.is_ascii_alphabetic">Read more</a></p>
</div><h4 id='method.is_ascii_uppercase' class="method"><span id='is_ascii_uppercase.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#method.is_ascii_uppercase' class='fnname'>is_ascii_uppercase</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>ascii_ctype </code><a href="https://github.com/rust-lang/rust/issues/39658">#39658</a>)</div></div><div class='docblock'><p>Checks if the value is an ASCII uppercase character: U+0041 &#39;A&#39; ... U+005A &#39;Z&#39;. For strings, true if all characters in the string are ASCII uppercase. <a href="../std/ascii/trait.AsciiExt.html#method.is_ascii_uppercase">Read more</a></p>
</div><h4 id='method.is_ascii_lowercase' class="method"><span id='is_ascii_lowercase.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#method.is_ascii_lowercase' class='fnname'>is_ascii_lowercase</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>ascii_ctype </code><a href="https://github.com/rust-lang/rust/issues/39658">#39658</a>)</div></div><div class='docblock'><p>Checks if the value is an ASCII lowercase character: U+0061 &#39;a&#39; ... U+007A &#39;z&#39;. For strings, true if all characters in the string are ASCII lowercase. <a href="../std/ascii/trait.AsciiExt.html#method.is_ascii_lowercase">Read more</a></p>
</div><h4 id='method.is_ascii_alphanumeric' class="method"><span id='is_ascii_alphanumeric.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#method.is_ascii_alphanumeric' class='fnname'>is_ascii_alphanumeric</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>ascii_ctype </code><a href="https://github.com/rust-lang/rust/issues/39658">#39658</a>)</div></div><div class='docblock'><p>Checks if the value is an ASCII alphanumeric character: U+0041 &#39;A&#39; ... U+005A &#39;Z&#39;, U+0061 &#39;a&#39; ... U+007A &#39;z&#39;, or U+0030 &#39;0&#39; ... U+0039 &#39;9&#39;. For strings, true if all characters in the string are ASCII alphanumeric. <a href="../std/ascii/trait.AsciiExt.html#method.is_ascii_alphanumeric">Read more</a></p>
</div><h4 id='method.is_ascii_digit' class="method"><span id='is_ascii_digit.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#method.is_ascii_digit' class='fnname'>is_ascii_digit</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>ascii_ctype </code><a href="https://github.com/rust-lang/rust/issues/39658">#39658</a>)</div></div><div class='docblock'><p>Checks if the value is an ASCII decimal digit: U+0030 &#39;0&#39; ... U+0039 &#39;9&#39;. For strings, true if all characters in the string are ASCII digits. <a href="../std/ascii/trait.AsciiExt.html#method.is_ascii_digit">Read more</a></p>
</div><h4 id='method.is_ascii_hexdigit' class="method"><span id='is_ascii_hexdigit.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#method.is_ascii_hexdigit' class='fnname'>is_ascii_hexdigit</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>ascii_ctype </code><a href="https://github.com/rust-lang/rust/issues/39658">#39658</a>)</div></div><div class='docblock'><p>Checks if the value is an ASCII hexadecimal digit: U+0030 &#39;0&#39; ... U+0039 &#39;9&#39;, U+0041 &#39;A&#39; ... U+0046 &#39;F&#39;, or U+0061 &#39;a&#39; ... U+0066 &#39;f&#39;. For strings, true if all characters in the string are ASCII hex digits. <a href="../std/ascii/trait.AsciiExt.html#method.is_ascii_hexdigit">Read more</a></p>
</div><h4 id='method.is_ascii_punctuation' class="method"><span id='is_ascii_punctuation.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#method.is_ascii_punctuation' class='fnname'>is_ascii_punctuation</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>ascii_ctype </code><a href="https://github.com/rust-lang/rust/issues/39658">#39658</a>)</div></div><div class='docblock'><p>Checks if the value is an ASCII punctuation character: U+0021 ... U+002F <code>! &quot; # $ % &amp; &#39; ( ) * + , - . /</code> U+003A ... U+0040 <code>: ; &lt; = &gt; ? @</code> U+005B ... U+0060 <code>[ \\ ] ^ _ \</code><code>U+007B ... U+007E</code>{ | } ~` For strings, true if all characters in the string are ASCII punctuation. <a href="../std/ascii/trait.AsciiExt.html#method.is_ascii_punctuation">Read more</a></p>
</div><h4 id='method.is_ascii_graphic' class="method"><span id='is_ascii_graphic.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#method.is_ascii_graphic' class='fnname'>is_ascii_graphic</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>ascii_ctype </code><a href="https://github.com/rust-lang/rust/issues/39658">#39658</a>)</div></div><div class='docblock'><p>Checks if the value is an ASCII graphic character: U+0021 &#39;@&#39; ... U+007E &#39;~&#39;. For strings, true if all characters in the string are ASCII punctuation. <a href="../std/ascii/trait.AsciiExt.html#method.is_ascii_graphic">Read more</a></p>
</div><h4 id='method.is_ascii_whitespace' class="method"><span id='is_ascii_whitespace.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#method.is_ascii_whitespace' class='fnname'>is_ascii_whitespace</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>ascii_ctype </code><a href="https://github.com/rust-lang/rust/issues/39658">#39658</a>)</div></div><div class='docblock'><p>Checks if the value is an ASCII whitespace character: U+0020 SPACE, U+0009 HORIZONTAL TAB, U+000A LINE FEED, U+000C FORM FEED, or U+000D CARRIAGE RETURN. For strings, true if all characters in the string are ASCII whitespace. <a href="../std/ascii/trait.AsciiExt.html#method.is_ascii_whitespace">Read more</a></p>
</div><h4 id='method.is_ascii_control' class="method"><span id='is_ascii_control.v' class='invisible'><code>fn <a href='../std/ascii/trait.AsciiExt.html#method.is_ascii_control' class='fnname'>is_ascii_control</a>(&amp;self) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>ascii_ctype </code><a href="https://github.com/rust-lang/rust/issues/39658">#39658</a>)</div></div><div class='docblock'><p>Checks if the value is an ASCII control character: U+0000 NUL ... U+001F UNIT SEPARATOR, or U+007F DELETE. Note that most ASCII whitespace characters are control characters, but SPACE is not. <a href="../std/ascii/trait.AsciiExt.html#method.is_ascii_control">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a>&lt;<a class="struct" href="../std/ffi/struct.OsString.html" title="struct std::ffi::OsString">OsString</a>&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/std/ffi/os_str.rs.html#334-338' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.eq-5' class="method"><span id='eq.v-5' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, other: &amp;<a class="struct" href="../std/ffi/struct.OsString.html" title="struct std::ffi::OsString">OsString</a>) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../std/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div><h4 id='method.ne-5' class="method"><span id='ne.v-5' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, other: &amp;Rhs) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a>&lt;<a class="struct" href="../std/ffi/struct.OsStr.html" title="struct std::ffi::OsStr">OsStr</a>&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/std/ffi/os_str.rs.html#581-585' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.eq-6' class="method"><span id='eq.v-6' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, other: &amp;<a class="struct" href="../std/ffi/struct.OsStr.html" title="struct std::ffi::OsStr">OsStr</a>) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../std/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div><h4 id='method.ne-6' class="method"><span id='ne.v-6' class='invisible'><code>fn <a href='../std/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, other: &amp;Rhs) -&gt; <a class="primitive" href="primitive.bool.html">bool</a></code></span></h4>
<div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/convert/trait.AsRef.html" title="trait std::convert::AsRef">AsRef</a>&lt;<a class="struct" href="../std/ffi/struct.OsStr.html" title="struct std::ffi::OsStr">OsStr</a>&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/std/ffi/os_str.rs.html#708-712' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.as_ref-2' class="method"><span id='as_ref.v-2' class='invisible'><code>fn <a href='../std/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&amp;self) -&gt; &amp;<a class="struct" href="../std/ffi/struct.OsStr.html" title="struct std::ffi::OsStr">OsStr</a></code></span></h4>
<div class='docblock'><p>Performs the conversion.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/net/trait.ToSocketAddrs.html" title="trait std::net::ToSocketAddrs">ToSocketAddrs</a> for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/std/net/addr.rs.html#832-857' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='associatedtype.Iter' class="type"><span id='Iter.t' class='invisible'><code>type <a href='../std/net/trait.ToSocketAddrs.html#associatedtype.Iter' class="type">Iter</a> = <a class="struct" href="../std/vec/struct.IntoIter.html" title="struct std::vec::IntoIter">IntoIter</a>&lt;<a class="enum" href="../std/net/enum.SocketAddr.html" title="enum std::net::SocketAddr">SocketAddr</a>&gt;</code></span></h4>
<div class='docblock'><p>Returned iterator over socket addresses which this type may correspond to. <a href="../std/net/trait.ToSocketAddrs.html#associatedtype.Iter">Read more</a></p>
</div><h4 id='method.to_socket_addrs' class="method"><span id='to_socket_addrs.v' class='invisible'><code>fn <a href='../std/net/trait.ToSocketAddrs.html#tymethod.to_socket_addrs' class='fnname'>to_socket_addrs</a>(&amp;self) -&gt; <a class="type" href="../std/io/type.Result.html" title="type std::io::Result">Result</a>&lt;<a class="struct" href="../std/vec/struct.IntoIter.html" title="struct std::vec::IntoIter">IntoIter</a>&lt;<a class="enum" href="../std/net/enum.SocketAddr.html" title="enum std::net::SocketAddr">SocketAddr</a>&gt;&gt;</code></span></h4>
<div class='docblock'><p>Converts this object to an iterator of resolved <code>SocketAddr</code>s. <a href="../std/net/trait.ToSocketAddrs.html#tymethod.to_socket_addrs">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../std/convert/trait.AsRef.html" title="trait std::convert::AsRef">AsRef</a>&lt;<a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a>&gt; for <a class="primitive" href="primitive.str.html">str</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/std/path.rs.html#2390-2394' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.as_ref-3' class="method"><span id='as_ref.v-3' class='invisible'><code>fn <a href='../std/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&amp;self) -&gt; &amp;<a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a></code></span></h4>
<div class='docblock'><p>Performs the conversion.</p>
</div></div></section>
    <section id='search' class="content hidden"></section>

    <section class="footer"></section>

    <aside id="help" class="hidden">
        <div>
            <h1 class="hidden">Help</h1>

            <div class="shortcuts">
                <h2>Keyboard Shortcuts</h2>

                <dl>
                    <dt>?</dt>
                    <dd>Show this help dialog</dd>
                    <dt>S</dt>
                    <dd>Focus the search field</dd>
                    <dt>&larrb;</dt>
                    <dd>Move up in search results</dd>
                    <dt>&rarrb;</dt>
                    <dd>Move down in search results</dd>
                    <dt>&#9166;</dt>
                    <dd>Go to active search result</dd>
                    <dt>+</dt>
                    <dd>Collapse/expand all sections</dd>
                </dl>
            </div>

            <div class="infos">
                <h2>Search Tricks</h2>

                <p>
                    Prefix searches with a type followed by a colon (e.g.
                    <code>fn:</code>) to restrict the search to a given type.
                </p>

                <p>
                    Accepted types are: <code>fn</code>, <code>mod</code>,
                    <code>struct</code>, <code>enum</code>,
                    <code>trait</code>, <code>type</code>, <code>macro</code>,
                    and <code>const</code>.
                </p>

                <p>
                    Search functions by type signature (e.g.
                    <code>vec -> usize</code> or <code>* -> vec</code>)
                </p>
            </div>
        </div>
    </aside>

    

    <script>
        window.rootPath = "../";
        window.currentCrate = "std";
    </script>
    <script src="../main.js"></script>
    <script defer src="../search-index.js"></script>
</body>
</html>