<!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 `String` struct in crate `alloc`."><meta name="keywords" content="rust, rustlang, rust-lang, String"><title>alloc::string::String - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><script src="../../storage.js"></script><link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico"></head><body class="rustdoc struct"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../../alloc/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a><p class='location'>Struct String</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.new">new</a><a href="#method.with_capacity">with_capacity</a><a href="#method.from_utf8">from_utf8</a><a href="#method.from_utf8_lossy">from_utf8_lossy</a><a href="#method.from_utf16">from_utf16</a><a href="#method.from_utf16_lossy">from_utf16_lossy</a><a href="#method.from_raw_parts">from_raw_parts</a><a href="#method.from_utf8_unchecked">from_utf8_unchecked</a><a href="#method.into_bytes">into_bytes</a><a href="#method.as_str">as_str</a><a href="#method.as_mut_str">as_mut_str</a><a href="#method.push_str">push_str</a><a href="#method.capacity">capacity</a><a href="#method.reserve">reserve</a><a href="#method.reserve_exact">reserve_exact</a><a href="#method.try_reserve">try_reserve</a><a href="#method.try_reserve_exact">try_reserve_exact</a><a href="#method.shrink_to_fit">shrink_to_fit</a><a href="#method.shrink_to">shrink_to</a><a href="#method.push">push</a><a href="#method.as_bytes">as_bytes</a><a href="#method.truncate">truncate</a><a href="#method.pop">pop</a><a href="#method.remove">remove</a><a href="#method.retain">retain</a><a href="#method.insert">insert</a><a href="#method.insert_str">insert_str</a><a href="#method.as_mut_vec">as_mut_vec</a><a href="#method.len">len</a><a href="#method.is_empty">is_empty</a><a href="#method.split_off">split_off</a><a href="#method.clear">clear</a><a href="#method.drain">drain</a><a href="#method.replace_range">replace_range</a><a href="#method.into_boxed_str">into_boxed_str</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-From%3CString%3E">From<String></a><a href="#impl-Borrow%3Cstr%3E">Borrow<str></a><a href="#impl-PartialOrd">PartialOrd</a><a href="#impl-Eq">Eq</a><a href="#impl-Ord">Ord</a><a href="#impl-Clone">Clone</a><a href="#impl-FromIterator%3Cchar%3E">FromIterator<char></a><a href="#impl-FromIterator%3C%26%27a%20char%3E">FromIterator<&'a char></a><a href="#impl-FromIterator%3C%26%27a%20str%3E">FromIterator<&'a str></a><a href="#impl-FromIterator%3CString%3E">FromIterator<String></a><a href="#impl-FromIterator%3CCow%3C%27a%2C%20str%3E%3E">FromIterator<Cow<'a, str>></a><a href="#impl-Extend%3Cchar%3E">Extend<char></a><a href="#impl-Extend%3C%26%27a%20char%3E">Extend<&'a char></a><a href="#impl-Extend%3C%26%27a%20str%3E">Extend<&'a str></a><a href="#impl-Extend%3CString%3E">Extend<String></a><a href="#impl-Extend%3CCow%3C%27a%2C%20str%3E%3E">Extend<Cow<'a, str>></a><a href="#impl-Pattern%3C%27a%3E">Pattern<'a></a><a href="#impl-PartialEq">PartialEq</a><a href="#impl-PartialEq%3Cstr%3E">PartialEq<str></a><a href="#impl-PartialEq%3CString%3E">PartialEq<String></a><a href="#impl-PartialEq%3C%26%27a%20str%3E">PartialEq<&'a str></a><a href="#impl-PartialEq%3CCow%3C%27a%2C%20str%3E%3E">PartialEq<Cow<'a, str>></a><a href="#impl-Default">Default</a><a href="#impl-Display">Display</a><a href="#impl-Debug">Debug</a><a href="#impl-Hash">Hash</a><a href="#impl-Add%3C%26%27a%20str%3E">Add<&'a str></a><a href="#impl-AddAssign%3C%26%27a%20str%3E">AddAssign<&'a str></a><a href="#impl-Index%3CRange%3Cusize%3E%3E">Index<Range<usize>></a><a href="#impl-Index%3CRangeTo%3Cusize%3E%3E">Index<RangeTo<usize>></a><a href="#impl-Index%3CRangeFrom%3Cusize%3E%3E">Index<RangeFrom<usize>></a><a href="#impl-Index%3CRangeFull%3E">Index<RangeFull></a><a href="#impl-Index%3CRangeInclusive%3Cusize%3E%3E">Index<RangeInclusive<usize>></a><a href="#impl-Index%3CRangeToInclusive%3Cusize%3E%3E">Index<RangeToInclusive<usize>></a><a href="#impl-IndexMut%3CRange%3Cusize%3E%3E">IndexMut<Range<usize>></a><a href="#impl-IndexMut%3CRangeTo%3Cusize%3E%3E">IndexMut<RangeTo<usize>></a><a href="#impl-IndexMut%3CRangeFrom%3Cusize%3E%3E">IndexMut<RangeFrom<usize>></a><a href="#impl-IndexMut%3CRangeFull%3E">IndexMut<RangeFull></a><a href="#impl-IndexMut%3CRangeInclusive%3Cusize%3E%3E">IndexMut<RangeInclusive<usize>></a><a href="#impl-IndexMut%3CRangeToInclusive%3Cusize%3E%3E">IndexMut<RangeToInclusive<usize>></a><a href="#impl-Deref">Deref</a><a href="#impl-DerefMut">DerefMut</a><a href="#impl-FromStr">FromStr</a><a href="#impl-ToString">ToString</a><a href="#impl-AsRef%3Cstr%3E">AsRef<str></a><a href="#impl-AsRef%3C%5Bu8%5D%3E">AsRef<[u8]></a><a href="#impl-From%3C%26%27a%20str%3E">From<&'a str></a><a href="#impl-From%3CBox%3Cstr%3E%3E">From<Box<str>></a><a href="#impl-From%3CCow%3C%27a%2C%20str%3E%3E">From<Cow<'a, str>></a><a href="#impl-Write">Write</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-Send">Send</a><a href="#impl-Sync">Sync</a></div></div><p class='location'><a href='../index.html'>alloc</a>::<wbr><a href='index.html'>string</a></p><script>window.sidebarCurrent = {name: 'String', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../../theme.js"></script><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"><a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>alloc</a>::<wbr><a href='index.html'>string</a>::<wbr><a class="struct" href=''>String</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'>−</span>]</a></span><a class='srclink' href='../../src/alloc/string.rs.html#294-296' title='goto source code'>[src]</a></span></h1><div class="docblock type-decl"><pre class='rust struct'>pub struct String { /* fields omitted */ }</pre></div><div class='docblock'><p>A UTF-8 encoded, growable string.</p> <p>The <code>String</code> type is the most common string type that has ownership over the contents of the string. It has a close relationship with its borrowed counterpart, the primitive <a href="../../std/primitive.str.html"><code>str</code></a>.</p> <h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1> <p>You can create a <code>String</code> from a literal string with <a href="#method.from"><code>String::from</code></a>:</p> <pre class="rust rust-example-rendered"> <span class="kw">let</span> <span class="ident">hello</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"Hello, world!"</span>);</pre> <p>You can append a <a href="../../std/primitive.char.html"><code>char</code></a> to a <code>String</code> with the <a href="#method.push"><code>push</code></a> method, and append a <a href="../../std/primitive.str.html"><code>&str</code></a> with the <a href="#method.push_str"><code>push_str</code></a> method:</p> <pre class="rust rust-example-rendered"> <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">hello</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"Hello, "</span>); <span class="ident">hello</span>.<span class="ident">push</span>(<span class="string">'w'</span>); <span class="ident">hello</span>.<span class="ident">push_str</span>(<span class="string">"orld!"</span>);</pre> <p>If you have a vector of UTF-8 bytes, you can create a <code>String</code> from it with the <a href="#method.from_utf8"><code>from_utf8</code></a> method:</p> <pre class="rust rust-example-rendered"> <span class="comment">// some bytes, in a vector</span> <span class="kw">let</span> <span class="ident">sparkle_heart</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">240</span>, <span class="number">159</span>, <span class="number">146</span>, <span class="number">150</span>]; <span class="comment">// We know these bytes are valid, so we'll use `unwrap()`.</span> <span class="kw">let</span> <span class="ident">sparkle_heart</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from_utf8</span>(<span class="ident">sparkle_heart</span>).<span class="ident">unwrap</span>(); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"💖"</span>, <span class="ident">sparkle_heart</span>);</pre> <h1 id="utf-8" class="section-header"><a href="#utf-8">UTF-8</a></h1> <p><code>String</code>s are always valid UTF-8. This has a few implications, the first of which is that if you need a non-UTF-8 string, consider <a href="../../std/ffi/struct.OsString.html"><code>OsString</code></a>. It is similar, but without the UTF-8 constraint. The second implication is that you cannot index into a <code>String</code>:</p> <div class='information'><div class='tooltip compile_fail'>ⓘ<span class='tooltiptext'>This example deliberately fails to compile</span></div></div><pre class="rust rust-example-rendered compile_fail"> <span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">"hello"</span>; <span class="macro">println</span><span class="macro">!</span>(<span class="string">"The first letter of s is {}"</span>, <span class="ident">s</span>[<span class="number">0</span>]); <span class="comment">// ERROR!!!</span></pre> <p>Indexing is intended to be a constant-time operation, but UTF-8 encoding does not allow us to do this. Furthermore, it's not clear what sort of thing the index should return: a byte, a codepoint, or a grapheme cluster. The <a href="#method.bytes"><code>bytes</code></a> and <a href="#method.chars"><code>chars</code></a> methods return iterators over the first two, respectively.</p> <h1 id="deref" class="section-header"><a href="#deref">Deref</a></h1> <p><code>String</code>s implement <a href="../../std/ops/trait.Deref.html"><code>Deref</code></a><code><Target=str></code>, and so inherit all of <a href="../../std/primitive.str.html"><code>str</code></a>'s methods. In addition, this means that you can pass a <code>String</code> to a function which takes a <a href="../../std/primitive.str.html"><code>&str</code></a> by using an ampersand (<code>&</code>):</p> <pre class="rust rust-example-rendered"> <span class="kw">fn</span> <span class="ident">takes_str</span>(<span class="ident">s</span>: <span class="kw-2">&</span><span class="ident">str</span>) { } <span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"Hello"</span>); <span class="ident">takes_str</span>(<span class="kw-2">&</span><span class="ident">s</span>);</pre> <p>This will create a <a href="../../std/primitive.str.html"><code>&str</code></a> from the <code>String</code> and pass it in. This conversion is very inexpensive, and so generally, functions will accept <a href="../../std/primitive.str.html"><code>&str</code></a>s as arguments unless they need a <code>String</code> for some specific reason.</p> <p>In certain cases Rust doesn't have enough information to make this conversion, known as <a href="../../std/ops/trait.Deref.html"><code>Deref</code></a> coercion. In the following example a string slice <a href="../../std/primitive.str.html"><code>&'a str</code></a> implements the trait <code>TraitExample</code>, and the function <code>example_func</code> takes anything that implements the trait. In this case Rust would need to make two implicit conversions, which Rust doesn't have the means to do. For that reason, the following example will not compile.</p> <div class='information'><div class='tooltip compile_fail'>ⓘ<span class='tooltiptext'>This example deliberately fails to compile</span></div></div><pre class="rust rust-example-rendered compile_fail"> <span class="kw">trait</span> <span class="ident">TraitExample</span> {} <span class="kw">impl</span><span class="op"><</span><span class="lifetime">'a</span><span class="op">></span> <span class="ident">TraitExample</span> <span class="kw">for</span> <span class="kw-2">&</span><span class="lifetime">'a</span> <span class="ident">str</span> {} <span class="kw">fn</span> <span class="ident">example_func</span><span class="op"><</span><span class="ident">A</span>: <span class="ident">TraitExample</span><span class="op">></span>(<span class="ident">example_arg</span>: <span class="ident">A</span>) {} <span class="kw">fn</span> <span class="ident">main</span>() { <span class="kw">let</span> <span class="ident">example_string</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"example_string"</span>); <span class="ident">example_func</span>(<span class="kw-2">&</span><span class="ident">example_string</span>); }</pre> <p>There are two options that would work instead. The first would be to change the line <code>example_func(&example_string);</code> to <code>example_func(example_string.as_str());</code>, using the method <a href="struct.String.html#method.as_str"><code>as_str()</code></a> to explicitly extract the string slice containing the string. The second way changes <code>example_func(&example_string);</code> to <code>example_func(&*example_string);</code>. In this case we are dereferencing a <code>String</code> to a <a href="../../std/primitive.str.html"><code>str</code></a>, then referencing the <a href="../../std/primitive.str.html"><code>str</code></a> back to <a href="../../std/primitive.str.html"><code>&str</code></a>. The second way is more idiomatic, however both work to do the conversion explicitly rather than relying on the implicit conversion.</p> <h1 id="representation" class="section-header"><a href="#representation">Representation</a></h1> <p>A <code>String</code> is made up of three components: a pointer to some bytes, a length, and a capacity. The pointer points to an internal buffer <code>String</code> uses to store its data. The length is the number of bytes currently stored in the buffer, and the capacity is the size of the buffer in bytes. As such, the length will always be less than or equal to the capacity.</p> <p>This buffer is always stored on the heap.</p> <p>You can look at these with the <a href="#method.as_ptr"><code>as_ptr</code></a>, <a href="#method.len"><code>len</code></a>, and <a href="#method.capacity"><code>capacity</code></a> methods:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">mem</span>; <span class="kw">let</span> <span class="ident">story</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"Once upon a time..."</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="kw">let</span> <span class="ident">capacity</span> <span class="op">=</span> <span class="ident">story</span>.<span class="ident">capacity</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">// Now that we have our parts, we throw the story away.</span> <span class="ident">mem</span>::<span class="ident">forget</span>(<span class="ident">story</span>); <span class="comment">// We can re-build a String out of ptr, len, and capacity. This is all</span> <span class="comment">// unsafe because we are responsible for making sure the components are</span> <span class="comment">// valid:</span> <span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">String</span>::<span class="ident">from_raw_parts</span>(<span class="ident">ptr</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="kw">_</span>, <span class="ident">len</span>, <span class="ident">capacity</span>) } ; <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"Once upon a time..."</span>), <span class="ident">s</span>);</pre> <p>If a <code>String</code> has enough capacity, adding elements to it will not re-allocate. For example, consider this program:</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="ident">String</span>::<span class="ident">new</span>(); <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">s</span>.<span class="ident">capacity</span>()); <span class="kw">for</span> <span class="kw">_</span> <span class="kw">in</span> <span class="number">0</span>..<span class="number">5</span> { <span class="ident">s</span>.<span class="ident">push_str</span>(<span class="string">"hello"</span>); <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">s</span>.<span class="ident">capacity</span>()); }</pre> <p>This will output the following:</p> <pre><code class="language-text">0 5 10 20 20 40 </code></pre> <p>At first, we have no memory allocated at all, but as we append to the string, it increases its capacity appropriately. If we instead use the <a href="#method.with_capacity"><code>with_capacity</code></a> method to allocate the correct capacity initially:</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="ident">String</span>::<span class="ident">with_capacity</span>(<span class="number">25</span>); <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">s</span>.<span class="ident">capacity</span>()); <span class="kw">for</span> <span class="kw">_</span> <span class="kw">in</span> <span class="number">0</span>..<span class="number">5</span> { <span class="ident">s</span>.<span class="ident">push_str</span>(<span class="string">"hello"</span>); <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">s</span>.<span class="ident">capacity</span>()); }</pre> <p>We end up with a different output:</p> <pre><code class="language-text">25 25 25 25 25 25 </code></pre> <p>Here, there's no need to allocate more memory inside the loop.</p> </div> <h2 id='methods' class='small-section-header'> Methods<a href='#methods' class='anchor'></a> </h2> <h3 id='impl' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#362-1591' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.new' class='fnname'>new</a>() -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#383-385' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a new empty <code>String</code>.</p> <p>Given that the <code>String</code> is empty, this will not allocate any initial buffer. While that means that this initial operation is very inexpensive, it may cause excessive allocation later when you add data. If you have an idea of how much data the <code>String</code> will hold, consider the <a href="#method.with_capacity"><code>with_capacity</code></a> method to prevent excessive re-allocation.</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">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">new</span>();</pre> </div><h4 id='method.with_capacity' class="method"><span id='with_capacity.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.with_capacity' class='fnname'>with_capacity</a>(capacity: usize) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#426-428' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a new empty <code>String</code> with a particular capacity.</p> <p><code>String</code>s have an internal buffer to hold their data. The capacity is the length of that buffer, and can be queried with the <a href="#method.capacity"><code>capacity</code></a> method. This method creates an empty <code>String</code>, but one with an initial buffer that can hold <code>capacity</code> bytes. This is useful when you may be appending a bunch of data to the <code>String</code>, reducing the number of reallocations it needs to do.</p> <p>If the given capacity is <code>0</code>, no allocation will occur, and this method is identical to the <a href="#method.new"><code>new</code></a> method.</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="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">with_capacity</span>(<span class="number">10</span>); <span class="comment">// The String contains no chars, even though it has capacity for more</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">len</span>(), <span class="number">0</span>); <span class="comment">// These are all done without reallocating...</span> <span class="kw">let</span> <span class="ident">cap</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">capacity</span>(); <span class="kw">for</span> <span class="ident">i</span> <span class="kw">in</span> <span class="number">0</span>..<span class="number">10</span> { <span class="ident">s</span>.<span class="ident">push</span>(<span class="string">'a'</span>); } <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">capacity</span>(), <span class="ident">cap</span>); <span class="comment">// ...but this may make the vector reallocate</span> <span class="ident">s</span>.<span class="ident">push</span>(<span class="string">'a'</span>);</pre> </div><h4 id='method.from_utf8' class="method"><span id='from_utf8.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.from_utf8' class='fnname'>from_utf8</a>(vec: <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><u8>) -> <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>, <a class="struct" href="../../alloc/string/struct.FromUtf8Error.html" title="struct alloc::string::FromUtf8Error">FromUtf8Error</a>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#502-512' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Converts a vector of bytes to a <code>String</code>.</p> <p>A string slice (<a href="../../std/primitive.str.html"><code>&str</code></a>) is made of bytes (<a href="../../std/primitive.u8.html"><code>u8</code></a>), and a vector of bytes (<a href="../../std/vec/struct.Vec.html"><code>Vec<u8></code></a>) is made of bytes, so this function converts between the two. Not all byte slices are valid <code>String</code>s, however: <code>String</code> requires that it is valid UTF-8. <code>from_utf8()</code> checks to ensure that the bytes are valid UTF-8, and then does the conversion.</p> <p>If you are sure that the byte slice is valid UTF-8, and you don't want to incur the overhead of the validity check, there is an unsafe version of this function, <a href="struct.String.html#method.from_utf8_unchecked"><code>from_utf8_unchecked</code></a>, which has the same behavior but skips the check.</p> <p>This method will take care to not copy the vector, for efficiency's sake.</p> <p>If you need a <a href="../../std/primitive.str.html"><code>&str</code></a> instead of a <code>String</code>, consider <a href="../../std/str/fn.from_utf8.html"><code>str::from_utf8</code></a>.</p> <p>The inverse of this method is <a href="struct.String.html#method.as_bytes"><code>as_bytes</code></a>.</p> <h1 id="errors" class="section-header"><a href="#errors">Errors</a></h1> <p>Returns <a href="../../stdresult/enum.Result.html#variant.Err"><code>Err</code></a> if the slice is not UTF-8 with a description as to why the provided bytes are not UTF-8. The vector you moved in is also included.</p> <h1 id="examples-3" class="section-header"><a href="#examples-3">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="comment">// some bytes, in a vector</span> <span class="kw">let</span> <span class="ident">sparkle_heart</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">240</span>, <span class="number">159</span>, <span class="number">146</span>, <span class="number">150</span>]; <span class="comment">// We know these bytes are valid, so we'll use `unwrap()`.</span> <span class="kw">let</span> <span class="ident">sparkle_heart</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from_utf8</span>(<span class="ident">sparkle_heart</span>).<span class="ident">unwrap</span>(); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"💖"</span>, <span class="ident">sparkle_heart</span>);</pre> <p>Incorrect bytes:</p> <pre class="rust rust-example-rendered"> <span class="comment">// some invalid bytes, in a vector</span> <span class="kw">let</span> <span class="ident">sparkle_heart</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>, <span class="number">159</span>, <span class="number">146</span>, <span class="number">150</span>]; <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">String</span>::<span class="ident">from_utf8</span>(<span class="ident">sparkle_heart</span>).<span class="ident">is_err</span>());</pre> <p>See the docs for <a href="struct.FromUtf8Error.html"><code>FromUtf8Error</code></a> for more details on what you can do with this error.</p> </div><h4 id='method.from_utf8_lossy' class="method"><span id='from_utf8_lossy.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.from_utf8_lossy' class='fnname'>from_utf8_lossy</a><'a>(v: &'a [u8]) -> <a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#564-594' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Converts a slice of bytes to a string, including invalid characters.</p> <p>Strings are made of bytes (<a href="../../std/primitive.u8.html"><code>u8</code></a>), and a slice of bytes (<a href="../../std/primitive.slice.html"><code>&[u8]</code></a>) is made of bytes, so this function converts between the two. Not all byte slices are valid strings, however: strings are required to be valid UTF-8. During this conversion, <code>from_utf8_lossy()</code> will replace any invalid UTF-8 sequences with <code>U+FFFD REPLACEMENT CHARACTER</code>, which looks like this: �</p> <p>If you are sure that the byte slice is valid UTF-8, and you don't want to incur the overhead of the conversion, there is an unsafe version of this function, <a href="struct.String.html#method.from_utf8_unchecked"><code>from_utf8_unchecked</code></a>, which has the same behavior but skips the checks.</p> <p>This function returns a <a href="../../std/borrow/enum.Cow.html"><code>Cow<'a, str></code></a>. If our byte slice is invalid UTF-8, then we need to insert the replacement characters, which will change the size of the string, and hence, require a <code>String</code>. But if it's already valid UTF-8, we don't need a new allocation. This return type allows us to handle both cases.</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="comment">// some bytes, in a vector</span> <span class="kw">let</span> <span class="ident">sparkle_heart</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">240</span>, <span class="number">159</span>, <span class="number">146</span>, <span class="number">150</span>]; <span class="kw">let</span> <span class="ident">sparkle_heart</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from_utf8_lossy</span>(<span class="kw-2">&</span><span class="ident">sparkle_heart</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"💖"</span>, <span class="ident">sparkle_heart</span>);</pre> <p>Incorrect bytes:</p> <pre class="rust rust-example-rendered"> <span class="comment">// some invalid bytes</span> <span class="kw">let</span> <span class="ident">input</span> <span class="op">=</span> <span class="string">b"Hello \xF0\x90\x80World"</span>; <span class="kw">let</span> <span class="ident">output</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from_utf8_lossy</span>(<span class="ident">input</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"Hello �World"</span>, <span class="ident">output</span>);</pre> </div><h4 id='method.from_utf16' class="method"><span id='from_utf16.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.from_utf16' class='fnname'>from_utf16</a>(v: &[u16]) -> <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>, <a class="struct" href="../../alloc/string/struct.FromUtf16Error.html" title="struct alloc::string::FromUtf16Error">FromUtf16Error</a>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#618-620' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Decode a UTF-16 encoded vector <code>v</code> into a <code>String</code>, returning <a href="../../std/result/enum.Result.html#variant.Err"><code>Err</code></a> if <code>v</code> contains any invalid data.</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="comment">// 𝄞music</span> <span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">0xD834</span>, <span class="number">0xDD1E</span>, <span class="number">0x006d</span>, <span class="number">0x0075</span>, <span class="number">0x0073</span>, <span class="number">0x0069</span>, <span class="number">0x0063</span>]; <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"𝄞music"</span>), <span class="ident">String</span>::<span class="ident">from_utf16</span>(<span class="ident">v</span>).<span class="ident">unwrap</span>()); <span class="comment">// 𝄞mu<invalid>ic</span> <span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">0xD834</span>, <span class="number">0xDD1E</span>, <span class="number">0x006d</span>, <span class="number">0x0075</span>, <span class="number">0xD800</span>, <span class="number">0x0069</span>, <span class="number">0x0063</span>]; <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">String</span>::<span class="ident">from_utf16</span>(<span class="ident">v</span>).<span class="ident">is_err</span>());</pre> </div><h4 id='method.from_utf16_lossy' class="method"><span id='from_utf16_lossy.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.from_utf16_lossy' class='fnname'>from_utf16_lossy</a>(v: &[u16]) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#647-649' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Decode a UTF-16 encoded slice <code>v</code> into a <code>String</code>, replacing invalid data with the replacement character (U+FFFD).</p> <p>Unlike <a href="#method.from_utf8_lossy"><code>from_utf8_lossy</code></a> which returns a <a href="../borrow/enum.Cow.html"><code>Cow<'a, str></code></a>, <code>from_utf16_lossy</code> returns a <code>String</code> since the UTF-16 to UTF-8 conversion requires a memory allocation.</p> <h1 id="examples-6" class="section-header"><a href="#examples-6">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="comment">// 𝄞mus<invalid>ic<invalid></span> <span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">0xD834</span>, <span class="number">0xDD1E</span>, <span class="number">0x006d</span>, <span class="number">0x0075</span>, <span class="number">0x0073</span>, <span class="number">0xDD1E</span>, <span class="number">0x0069</span>, <span class="number">0x0063</span>, <span class="number">0xD834</span>]; <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"𝄞mus\u{FFFD}ic\u{FFFD}"</span>), <span class="ident">String</span>::<span class="ident">from_utf16_lossy</span>(<span class="ident">v</span>));</pre> </div><h4 id='method.from_raw_parts' class="method"><span id='from_raw_parts.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub unsafe fn <a href='#method.from_raw_parts' class='fnname'>from_raw_parts</a>(<br> buf: *mut u8, <br> length: usize, <br> capacity: usize<br>) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#694-696' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a new <code>String</code> from a length, capacity, and pointer.</p> <h1 id="safety" class="section-header"><a href="#safety">Safety</a></h1> <p>This is highly unsafe, due to the number of invariants that aren't checked:</p> <ul> <li>The memory at <code>ptr</code> needs to have been previously allocated by the same allocator the standard library uses.</li> <li><code>length</code> needs to be less than or equal to <code>capacity</code>.</li> <li><code>capacity</code> needs to be the correct value.</li> </ul> <p>Violating these may cause problems like corrupting the allocator's internal data structures.</p> <p>The ownership of <code>ptr</code> is effectively transferred to the <code>String</code> which may then deallocate, reallocate or change the contents of memory pointed to by the pointer at will. Ensure that nothing else uses the pointer after calling this function.</p> <h1 id="examples-7" class="section-header"><a href="#examples-7">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">mem</span>; <span class="kw">unsafe</span> { <span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"hello"</span>); <span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">as_ptr</span>(); <span class="kw">let</span> <span class="ident">len</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">len</span>(); <span class="kw">let</span> <span class="ident">capacity</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">capacity</span>(); <span class="ident">mem</span>::<span class="ident">forget</span>(<span class="ident">s</span>); <span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from_raw_parts</span>(<span class="ident">ptr</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="kw">_</span>, <span class="ident">len</span>, <span class="ident">capacity</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"hello"</span>), <span class="ident">s</span>); }</pre> </div><h4 id='method.from_utf8_unchecked' class="method"><span id='from_utf8_unchecked.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub unsafe fn <a href='#method.from_utf8_unchecked' class='fnname'>from_utf8_unchecked</a>(bytes: <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><u8>) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#728-730' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Converts a vector of bytes to a <code>String</code> without checking that the string contains valid UTF-8.</p> <p>See the safe version, <a href="struct.String.html#method.from_utf8"><code>from_utf8</code></a>, for more details.</p> <h1 id="safety-1" class="section-header"><a href="#safety-1">Safety</a></h1> <p>This function is unsafe because it does not check that the bytes passed to it are valid UTF-8. If this constraint is violated, it may cause memory unsafety issues with future users of the <code>String</code>, as the rest of the standard library assumes that <code>String</code>s are valid UTF-8.</p> <h1 id="examples-8" class="section-header"><a href="#examples-8">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="comment">// some bytes, in a vector</span> <span class="kw">let</span> <span class="ident">sparkle_heart</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">240</span>, <span class="number">159</span>, <span class="number">146</span>, <span class="number">150</span>]; <span class="kw">let</span> <span class="ident">sparkle_heart</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">String</span>::<span class="ident">from_utf8_unchecked</span>(<span class="ident">sparkle_heart</span>) }; <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"💖"</span>, <span class="ident">sparkle_heart</span>);</pre> </div><h4 id='method.into_bytes' class="method"><span id='into_bytes.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.into_bytes' class='fnname'>into_bytes</a>(self) -> <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><u8></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#748-750' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Converts a <code>String</code> into a byte vector.</p> <p>This consumes the <code>String</code>, so we do not need to copy its contents.</p> <h1 id="examples-9" class="section-header"><a href="#examples-9">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="ident">String</span>::<span class="ident">from</span>(<span class="string">"hello"</span>); <span class="kw">let</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">into_bytes</span>(); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&</span>[<span class="number">104</span>, <span class="number">101</span>, <span class="number">108</span>, <span class="number">108</span>, <span class="number">111</span>][..], <span class="kw-2">&</span><span class="ident">bytes</span>[..]);</pre> </div><h4 id='method.as_str' class="method"><span id='as_str.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.as_str' class='fnname'>as_str</a>(&self) -> &str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.7.0'>1.7.0</div><a class='srclink' href='../../src/alloc/string.rs.html#765-767' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Extracts a string slice containing the entire string.</p> <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="ident">String</span>::<span class="ident">from</span>(<span class="string">"foo"</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"foo"</span>, <span class="ident">s</span>.<span class="ident">as_str</span>());</pre> </div><h4 id='method.as_mut_str' class="method"><span id='as_mut_str.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.as_mut_str' class='fnname'>as_mut_str</a>(&mut self) -> &mut str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.7.0'>1.7.0</div><a class='srclink' href='../../src/alloc/string.rs.html#785-787' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Converts a <code>String</code> into a mutable 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="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"foobar"</span>); <span class="kw">let</span> <span class="ident">s_mut_str</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">as_mut_str</span>(); <span class="ident">s_mut_str</span>.<span class="ident">make_ascii_uppercase</span>(); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"FOOBAR"</span>, <span class="ident">s_mut_str</span>);</pre> </div><h4 id='method.push_str' class="method"><span id='push_str.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.push_str' class='fnname'>push_str</a>(&mut self, string: &str)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#804-806' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Appends a given string slice onto the end of this <code>String</code>.</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="ident">String</span>::<span class="ident">from</span>(<span class="string">"foo"</span>); <span class="ident">s</span>.<span class="ident">push_str</span>(<span class="string">"bar"</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"foobar"</span>, <span class="ident">s</span>);</pre> </div><h4 id='method.capacity' class="method"><span id='capacity.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.capacity' class='fnname'>capacity</a>(&self) -> usize</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#821-823' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns this <code>String</code>'s capacity, in bytes.</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">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">with_capacity</span>(<span class="number">10</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">capacity</span>() <span class="op">>=</span> <span class="number">10</span>);</pre> </div><h4 id='method.reserve' class="method"><span id='reserve.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.reserve' class='fnname'>reserve</a>(&mut self, additional: usize)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#872-874' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Ensures that this <code>String</code>'s capacity is at least <code>additional</code> bytes larger than its length.</p> <p>The capacity may be increased by more than <code>additional</code> bytes if it chooses, to prevent frequent reallocations.</p> <p>If you do not want this "at least" behavior, see the <a href="struct.String.html#method.reserve_exact"><code>reserve_exact</code></a> method.</p> <h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1> <p>Panics if the new capacity overflows <a href="../../std/primitive.usize.html"><code>usize</code></a>.</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="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">new</span>(); <span class="ident">s</span>.<span class="ident">reserve</span>(<span class="number">10</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">capacity</span>() <span class="op">>=</span> <span class="number">10</span>);</pre> <p>This may not actually increase the capacity:</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="ident">String</span>::<span class="ident">with_capacity</span>(<span class="number">10</span>); <span class="ident">s</span>.<span class="ident">push</span>(<span class="string">'a'</span>); <span class="ident">s</span>.<span class="ident">push</span>(<span class="string">'b'</span>); <span class="comment">// s now has a length of 2 and a capacity of 10</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">2</span>, <span class="ident">s</span>.<span class="ident">len</span>()); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">10</span>, <span class="ident">s</span>.<span class="ident">capacity</span>()); <span class="comment">// Since we already have an extra 8 capacity, calling this...</span> <span class="ident">s</span>.<span class="ident">reserve</span>(<span class="number">8</span>); <span class="comment">// ... doesn't actually increase.</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">10</span>, <span class="ident">s</span>.<span class="ident">capacity</span>());</pre> </div><h4 id='method.reserve_exact' class="method"><span id='reserve_exact.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.reserve_exact' class='fnname'>reserve_exact</a>(&mut self, additional: usize)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#919-921' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Ensures that this <code>String</code>'s capacity is <code>additional</code> bytes larger than its length.</p> <p>Consider using the <a href="#method.reserve"><code>reserve</code></a> method unless you absolutely know better than the allocator.</p> <h1 id="panics-1" class="section-header"><a href="#panics-1">Panics</a></h1> <p>Panics if the new capacity overflows <code>usize</code>.</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">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">new</span>(); <span class="ident">s</span>.<span class="ident">reserve_exact</span>(<span class="number">10</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">capacity</span>() <span class="op">>=</span> <span class="number">10</span>);</pre> <p>This may not actually increase the capacity:</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="ident">String</span>::<span class="ident">with_capacity</span>(<span class="number">10</span>); <span class="ident">s</span>.<span class="ident">push</span>(<span class="string">'a'</span>); <span class="ident">s</span>.<span class="ident">push</span>(<span class="string">'b'</span>); <span class="comment">// s now has a length of 2 and a capacity of 10</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">2</span>, <span class="ident">s</span>.<span class="ident">len</span>()); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">10</span>, <span class="ident">s</span>.<span class="ident">capacity</span>()); <span class="comment">// Since we already have an extra 8 capacity, calling this...</span> <span class="ident">s</span>.<span class="ident">reserve_exact</span>(<span class="number">8</span>); <span class="comment">// ... doesn't actually increase.</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">10</span>, <span class="ident">s</span>.<span class="ident">capacity</span>());</pre> </div><h4 id='method.try_reserve' class="method"><span id='try_reserve.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.try_reserve' class='fnname'>try_reserve</a>(<br> &mut self, <br> additional: usize<br>) -> <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a><(), <a class="enum" href="../../core/alloc/enum.CollectionAllocErr.html" title="enum core::alloc::CollectionAllocErr">CollectionAllocErr</a>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#954-956' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API. (<code>try_reserve </code><a href="https://github.com/rust-lang/rust/issues/48043">#48043</a>)</summary><p>new API</p> </details></div></div><div class='docblock'><p>Tries to reserve capacity for at least <code>additional</code> more elements to be inserted in the given <code>String</code>. The collection may reserve more space to avoid frequent reallocations. After calling <code>reserve</code>, capacity will be greater than or equal to <code>self.len() + additional</code>. Does nothing if capacity is already sufficient.</p> <h1 id="errors-1" class="section-header"><a href="#errors-1">Errors</a></h1> <p>If the capacity overflows, or the allocator reports a failure, then an error is returned.</p> <h1 id="examples-16" class="section-header"><a href="#examples-16">Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="attribute">#![<span class="ident">feature</span>(<span class="ident">try_reserve</span>)]</span> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">CollectionAllocErr</span>; <span class="kw">fn</span> <span class="ident">process_data</span>(<span class="ident">data</span>: <span class="kw-2">&</span><span class="ident">str</span>) <span class="op">-></span> <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">String</span>, <span class="ident">CollectionAllocErr</span><span class="op">></span> { <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">output</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">new</span>(); <span class="comment">// Pre-reserve the memory, exiting if we can't</span> <span class="ident">output</span>.<span class="ident">try_reserve</span>(<span class="ident">data</span>.<span class="ident">len</span>())<span class="question-mark">?</span>; <span class="comment">// Now we know this can't OOM in the middle of our complex work</span> <span class="ident">output</span>.<span class="ident">push_str</span>(<span class="ident">data</span>); <span class="prelude-val">Ok</span>(<span class="ident">output</span>) }</pre> </div><h4 id='method.try_reserve_exact' class="method"><span id='try_reserve_exact.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.try_reserve_exact' class='fnname'>try_reserve_exact</a>(<br> &mut self, <br> additional: usize<br>) -> <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a><(), <a class="enum" href="../../core/alloc/enum.CollectionAllocErr.html" title="enum core::alloc::CollectionAllocErr">CollectionAllocErr</a>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#992-994' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API. (<code>try_reserve </code><a href="https://github.com/rust-lang/rust/issues/48043">#48043</a>)</summary><p>new API</p> </details></div></div><div class='docblock'><p>Tries to reserves the minimum capacity for exactly <code>additional</code> more elements to be inserted in the given <code>String</code>. After calling <code>reserve_exact</code>, capacity will be greater than or equal to <code>self.len() + additional</code>. Does nothing if the capacity is already sufficient.</p> <p>Note that the allocator may give the collection more space than it requests. Therefore capacity can not be relied upon to be precisely minimal. Prefer <code>reserve</code> if future insertions are expected.</p> <h1 id="errors-2" class="section-header"><a href="#errors-2">Errors</a></h1> <p>If the capacity overflows, or the allocator reports a failure, then an error is returned.</p> <h1 id="examples-17" class="section-header"><a href="#examples-17">Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="attribute">#![<span class="ident">feature</span>(<span class="ident">try_reserve</span>)]</span> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">CollectionAllocErr</span>; <span class="kw">fn</span> <span class="ident">process_data</span>(<span class="ident">data</span>: <span class="kw-2">&</span><span class="ident">str</span>) <span class="op">-></span> <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">String</span>, <span class="ident">CollectionAllocErr</span><span class="op">></span> { <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">output</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">new</span>(); <span class="comment">// Pre-reserve the memory, exiting if we can't</span> <span class="ident">output</span>.<span class="ident">try_reserve</span>(<span class="ident">data</span>.<span class="ident">len</span>())<span class="question-mark">?</span>; <span class="comment">// Now we know this can't OOM in the middle of our complex work</span> <span class="ident">output</span>.<span class="ident">push_str</span>(<span class="ident">data</span>); <span class="prelude-val">Ok</span>(<span class="ident">output</span>) }</pre> </div><h4 id='method.shrink_to_fit' class="method"><span id='shrink_to_fit.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.shrink_to_fit' class='fnname'>shrink_to_fit</a>(&mut self)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1013-1015' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Shrinks the capacity of this <code>String</code> to match its length.</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="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"foo"</span>); <span class="ident">s</span>.<span class="ident">reserve</span>(<span class="number">100</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">capacity</span>() <span class="op">>=</span> <span class="number">100</span>); <span class="ident">s</span>.<span class="ident">shrink_to_fit</span>(); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">3</span>, <span class="ident">s</span>.<span class="ident">capacity</span>());</pre> </div><h4 id='method.shrink_to' class="method"><span id='shrink_to.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.shrink_to' class='fnname'>shrink_to</a>(&mut self, min_capacity: usize)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1041-1043' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API. (<code>shrink_to</code>)</summary><p>new API</p> </details></div></div><div class='docblock'><p>Shrinks the capacity of this <code>String</code> with a lower bound.</p> <p>The capacity will remain at least as large as both the length and the supplied value.</p> <p>Panics if the current capacity is smaller than the supplied minimum capacity.</p> <h1 id="examples-19" class="section-header"><a href="#examples-19">Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="attribute">#![<span class="ident">feature</span>(<span class="ident">shrink_to</span>)]</span> <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"foo"</span>); <span class="ident">s</span>.<span class="ident">reserve</span>(<span class="number">100</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">capacity</span>() <span class="op">>=</span> <span class="number">100</span>); <span class="ident">s</span>.<span class="ident">shrink_to</span>(<span class="number">10</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">capacity</span>() <span class="op">>=</span> <span class="number">10</span>); <span class="ident">s</span>.<span class="ident">shrink_to</span>(<span class="number">0</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">capacity</span>() <span class="op">>=</span> <span class="number">3</span>);</pre> </div><h4 id='method.push' class="method"><span id='push.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.push' class='fnname'>push</a>(&mut self, ch: char)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1064-1069' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Appends the given <a href="../../std/primitive.char.html"><code>char</code></a> to the end of this <code>String</code>.</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="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"abc"</span>); <span class="ident">s</span>.<span class="ident">push</span>(<span class="string">'1'</span>); <span class="ident">s</span>.<span class="ident">push</span>(<span class="string">'2'</span>); <span class="ident">s</span>.<span class="ident">push</span>(<span class="string">'3'</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"abc123"</span>, <span class="ident">s</span>);</pre> </div><h4 id='method.as_bytes' class="method"><span id='as_bytes.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.as_bytes' class='fnname'>as_bytes</a>(&self) -> &[u8]</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1088-1090' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns a byte slice of this <code>String</code>'s contents.</p> <p>The inverse of this method is <a href="#method.from_utf8"><code>from_utf8</code></a>.</p> <h1 id="examples-21" class="section-header"><a href="#examples-21">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="ident">String</span>::<span class="ident">from</span>(<span class="string">"hello"</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&</span>[<span class="number">104</span>, <span class="number">101</span>, <span class="number">108</span>, <span class="number">108</span>, <span class="number">111</span>], <span class="ident">s</span>.<span class="ident">as_bytes</span>());</pre> </div><h4 id='method.truncate' class="method"><span id='truncate.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.truncate' class='fnname'>truncate</a>(&mut self, new_len: usize)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1119-1124' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Shortens this <code>String</code> to the specified length.</p> <p>If <code>new_len</code> is greater than the string's current length, this has no effect.</p> <p>Note that this method has no effect on the allocated capacity of the string</p> <h1 id="panics-2" class="section-header"><a href="#panics-2">Panics</a></h1> <p>Panics if <code>new_len</code> does not lie on a <a href="../../std/primitive.char.html"><code>char</code></a> boundary.</p> <h1 id="examples-22" class="section-header"><a href="#examples-22">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="ident">String</span>::<span class="ident">from</span>(<span class="string">"hello"</span>); <span class="ident">s</span>.<span class="ident">truncate</span>(<span class="number">2</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"he"</span>, <span class="ident">s</span>);</pre> </div><h4 id='method.pop' class="method"><span id='pop.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.pop' class='fnname'>pop</a>(&mut self) -> <a class="enum" href="../../core/option/enum.Option.html" title="enum core::option::Option">Option</a><char></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1147-1154' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Removes the last character from the string buffer and returns it.</p> <p>Returns <a href="../../std/option/enum.Option.html#variant.None"><code>None</code></a> if this <code>String</code> is empty.</p> <h1 id="examples-23" class="section-header"><a href="#examples-23">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="ident">String</span>::<span class="ident">from</span>(<span class="string">"foo"</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">pop</span>(), <span class="prelude-val">Some</span>(<span class="string">'o'</span>)); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">pop</span>(), <span class="prelude-val">Some</span>(<span class="string">'o'</span>)); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">pop</span>(), <span class="prelude-val">Some</span>(<span class="string">'f'</span>)); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">pop</span>(), <span class="prelude-val">None</span>);</pre> </div><h4 id='method.remove' class="method"><span id='remove.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.remove' class='fnname'>remove</a>(&mut self, idx: usize) -> char</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1181-1196' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Removes a <a href="../../std/primitive.char.html"><code>char</code></a> from this <code>String</code> at a byte position and returns it.</p> <p>This is an <code>O(n)</code> operation, as it requires copying every element in the buffer.</p> <h1 id="panics-3" class="section-header"><a href="#panics-3">Panics</a></h1> <p>Panics if <code>idx</code> is larger than or equal to the <code>String</code>'s length, or if it does not lie on a <a href="../../std/primitive.char.html"><code>char</code></a> boundary.</p> <h1 id="examples-24" class="section-header"><a href="#examples-24">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="ident">String</span>::<span class="ident">from</span>(<span class="string">"foo"</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">remove</span>(<span class="number">0</span>), <span class="string">'f'</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">remove</span>(<span class="number">1</span>), <span class="string">'o'</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">remove</span>(<span class="number">0</span>), <span class="string">'o'</span>);</pre> </div><h4 id='method.retain' class="method"><span id='retain.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.retain' class='fnname'>retain</a><F>(&mut self, f: F) <span class="where fmt-newline">where<br> F: <a class="trait" href="../../core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(char) -> bool, </span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.26.0'>1.26.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1215-1245' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Retains only the characters specified by the predicate.</p> <p>In other words, remove all characters <code>c</code> such that <code>f(c)</code> returns <code>false</code>. This method operates in place and preserves the order of the retained characters.</p> <h1 id="examples-25" class="section-header"><a href="#examples-25">Examples</a></h1> <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="ident">String</span>::<span class="ident">from</span>(<span class="string">"f_o_ob_ar"</span>); <span class="ident">s</span>.<span class="ident">retain</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">'_'</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>, <span class="string">"foobar"</span>);</pre> </div><h4 id='method.insert' class="method"><span id='insert.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.insert' class='fnname'>insert</a>(&mut self, idx: usize, ch: char)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1274-1282' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Inserts a character into this <code>String</code> at a byte position.</p> <p>This is an <code>O(n)</code> operation as it requires copying every element in the buffer.</p> <h1 id="panics-4" class="section-header"><a href="#panics-4">Panics</a></h1> <p>Panics if <code>idx</code> is larger than the <code>String</code>'s length, or if it does not lie on a <a href="../../std/primitive.char.html"><code>char</code></a> boundary.</p> <h1 id="examples-26" class="section-header"><a href="#examples-26">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="ident">String</span>::<span class="ident">with_capacity</span>(<span class="number">3</span>); <span class="ident">s</span>.<span class="ident">insert</span>(<span class="number">0</span>, <span class="string">'f'</span>); <span class="ident">s</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="string">'o'</span>); <span class="ident">s</span>.<span class="ident">insert</span>(<span class="number">2</span>, <span class="string">'o'</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"foo"</span>, <span class="ident">s</span>);</pre> </div><h4 id='method.insert_str' class="method"><span id='insert_str.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.insert_str' class='fnname'>insert_str</a>(&mut self, idx: usize, string: &str)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.16.0'>1.16.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1323-1329' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Inserts a string slice into this <code>String</code> at a byte position.</p> <p>This is an <code>O(n)</code> operation as it requires copying every element in the buffer.</p> <h1 id="panics-5" class="section-header"><a href="#panics-5">Panics</a></h1> <p>Panics if <code>idx</code> is larger than the <code>String</code>'s length, or if it does not lie on a <a href="../../std/primitive.char.html"><code>char</code></a> boundary.</p> <h1 id="examples-27" class="section-header"><a href="#examples-27">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="ident">String</span>::<span class="ident">from</span>(<span class="string">"bar"</span>); <span class="ident">s</span>.<span class="ident">insert_str</span>(<span class="number">0</span>, <span class="string">"foo"</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"foobar"</span>, <span class="ident">s</span>);</pre> </div><h4 id='method.as_mut_vec' class="method"><span id='as_mut_vec.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub unsafe fn <a href='#method.as_mut_vec' class='fnname'>as_mut_vec</a>(&mut self) -> &mut <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><u8></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1357-1359' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns a mutable reference to the contents of this <code>String</code>.</p> <h1 id="safety-2" class="section-header"><a href="#safety-2">Safety</a></h1> <p>This function is unsafe because it does not check that the bytes passed to it are valid UTF-8. If this constraint is violated, it may cause memory unsafety issues with future users of the <code>String</code>, as the rest of the standard library assumes that <code>String</code>s are valid UTF-8.</p> <h1 id="examples-28" class="section-header"><a href="#examples-28">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="ident">String</span>::<span class="ident">from</span>(<span class="string">"hello"</span>); <span class="kw">unsafe</span> { <span class="kw">let</span> <span class="ident">vec</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">as_mut_vec</span>(); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&</span>[<span class="number">104</span>, <span class="number">101</span>, <span class="number">108</span>, <span class="number">108</span>, <span class="number">111</span>][..], <span class="kw-2">&</span><span class="ident">vec</span>[..]); <span class="ident">vec</span>.<span class="ident">reverse</span>(); } <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>, <span class="string">"olleh"</span>);</pre> </div><h4 id='method.len' class="method"><span id='len.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.len' class='fnname'>len</a>(&self) -> usize</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1374-1376' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns the length of this <code>String</code>, in bytes.</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">a</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"foo"</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">len</span>(), <span class="number">3</span>);</pre> </div><h4 id='method.is_empty' class="method"><span id='is_empty.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.is_empty' class='fnname'>is_empty</a>(&self) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1395-1397' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns <code>true</code> if this <code>String</code> has a length of zero.</p> <p>Returns <code>false</code> otherwise.</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="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">new</span>(); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">is_empty</span>()); <span class="ident">v</span>.<span class="ident">push</span>(<span class="string">'a'</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">v</span>.<span class="ident">is_empty</span>());</pre> </div><h4 id='method.split_off' class="method"><span id='split_off.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.split_off' class='fnname'>split_off</a>(&mut self, at: usize) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.16.0'>1.16.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1424-1428' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Splits the string into two at the given index.</p> <p>Returns a newly allocated <code>String</code>. <code>self</code> contains bytes <code>[0, at)</code>, and the returned <code>String</code> contains bytes <code>[at, len)</code>. <code>at</code> must be on the boundary of a UTF-8 code point.</p> <p>Note that the capacity of <code>self</code> does not change.</p> <h1 id="panics-6" class="section-header"><a href="#panics-6">Panics</a></h1> <p>Panics if <code>at</code> is not on a <code>UTF-8</code> code point boundary, or if it is beyond the last code point of the string.</p> <h1 id="examples-31" class="section-header"><a href="#examples-31">Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">hello</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"Hello, World!"</span>); <span class="kw">let</span> <span class="ident">world</span> <span class="op">=</span> <span class="ident">hello</span>.<span class="ident">split_off</span>(<span class="number">7</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">hello</span>, <span class="string">"Hello, "</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">world</span>, <span class="string">"World!"</span>);</pre> </div><h4 id='method.clear' class="method"><span id='clear.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.clear' class='fnname'>clear</a>(&mut self)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1450-1452' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Truncates this <code>String</code>, removing all contents.</p> <p>While this means the <code>String</code> will have a length of zero, it does not touch its capacity.</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="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"foo"</span>); <span class="ident">s</span>.<span class="ident">clear</span>(); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">s</span>.<span class="ident">is_empty</span>()); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">0</span>, <span class="ident">s</span>.<span class="ident">len</span>()); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">3</span>, <span class="ident">s</span>.<span class="ident">capacity</span>());</pre> </div><h4 id='method.drain' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../alloc/string/struct.Drain.html" title="struct alloc::string::Drain">Drain</a><'a></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../alloc/string/struct.Drain.html" title="struct alloc::string::Drain">Drain</a><'a></h3><code class="content"><span class="where fmt-newline">impl<'a> <a class="trait" href="../../core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../../alloc/string/struct.Drain.html" title="struct alloc::string::Drain">Drain</a><'a></span><span class="where fmt-newline"> type <a href='../../core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = char;</span></code></div></div><span id='drain.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.drain' class='fnname'>drain</a><R>(&mut self, range: R) -> <a class="struct" href="../../alloc/string/struct.Drain.html" title="struct alloc::string::Drain">Drain</a> <span class="where fmt-newline">where<br> R: <a class="trait" href="../../core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a><usize>, </span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.6.0'>1.6.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1485-1518' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a draining iterator that removes the specified range in the string and yields the removed chars.</p> <p>Note: The element range is removed even if the iterator is not consumed until the end.</p> <h1 id="panics-7" class="section-header"><a href="#panics-7">Panics</a></h1> <p>Panics if the starting point or end point do not lie on a <a href="../../std/primitive.char.html"><code>char</code></a> boundary, or if they're out of bounds.</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="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"α is alpha, β is beta"</span>); <span class="kw">let</span> <span class="ident">beta_offset</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">find</span>(<span class="string">'β'</span>).<span class="ident">unwrap_or</span>(<span class="ident">s</span>.<span class="ident">len</span>()); <span class="comment">// Remove the range up until the β from the string</span> <span class="kw">let</span> <span class="ident">t</span>: <span class="ident">String</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">drain</span>(..<span class="ident">beta_offset</span>).<span class="ident">collect</span>(); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">t</span>, <span class="string">"α is alpha, "</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>, <span class="string">"β is beta"</span>); <span class="comment">// A full range clears the string</span> <span class="ident">s</span>.<span class="ident">drain</span>(..); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>, <span class="string">""</span>);</pre> </div><h4 id='method.replace_range' class="method"><span id='replace_range.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.replace_range' class='fnname'>replace_range</a><R>(&mut self, range: R, replace_with: &str) <span class="where fmt-newline">where<br> R: <a class="trait" href="../../core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a><usize>, </span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.27.0'>1.27.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1545-1567' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Removes the specified range in the string, and replaces it with the given string. The given string doesn't need to be the same length as the range.</p> <h1 id="panics-8" class="section-header"><a href="#panics-8">Panics</a></h1> <p>Panics if the starting point or end point do not lie on a <a href="../../std/primitive.char.html"><code>char</code></a> boundary, or if they're out of bounds.</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="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"α is alpha, β is beta"</span>); <span class="kw">let</span> <span class="ident">beta_offset</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">find</span>(<span class="string">'β'</span>).<span class="ident">unwrap_or</span>(<span class="ident">s</span>.<span class="ident">len</span>()); <span class="comment">// Replace the range up until the β from the string</span> <span class="ident">s</span>.<span class="ident">replace_range</span>(..<span class="ident">beta_offset</span>, <span class="string">"Α is capital alpha; "</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>, <span class="string">"Α is capital alpha; β is beta"</span>);</pre> </div><h4 id='method.into_boxed_str' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><I></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><I></h3><code class="content"><span class="where fmt-newline">impl<I: <a class="trait" href="../../core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> + ?<a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>> <a class="trait" href="../../core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../../alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><I></span><span class="where fmt-newline"> type <a href='../../core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = I::<a class="type" href="../../core/iter/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::iterator::Iterator::Item">Item</a>;</span></code></div></div><span id='into_boxed_str.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.into_boxed_str' class='fnname'>into_boxed_str</a>(self) -> <a class="struct" href="../../alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><str></code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1587-1590' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Converts this <code>String</code> into a <a href="../../std/boxed/struct.Box.html"><code>Box</code></a><code><</code><a href="../../std/primitive.str.html"><code>str</code></a><code>></code>.</p> <p>This will drop any excess capacity.</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="ident">String</span>::<span class="ident">from</span>(<span class="string">"hello"</span>); <span class="kw">let</span> <span class="ident">b</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">into_boxed_str</span>();</pre> </div></div> <h2 id='implementations' class='small-section-header'> Trait Implementations<a href='#implementations' class='anchor'></a> </h2> <div id='implementations-list'><h3 id='impl-From%3CString%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>> for <a class="struct" href="../../alloc/arc/struct.Arc.html" title="struct alloc::arc::Arc">Arc</a><str></code><a href='#impl-From%3CString%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.21.0'>1.21.0</div><a class='srclink' href='../../src/alloc/arc.rs.html#1383-1388' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from' class="method"><span id='from.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(v: <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> <a class="struct" href="../../alloc/arc/struct.Arc.html" title="struct alloc::arc::Arc">Arc</a><str></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/arc.rs.html#1385-1387' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-From%3CString%3E-1' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>> for <a class="struct" href="../../alloc/rc/struct.Rc.html" title="struct alloc::rc::Rc">Rc</a><str></code><a href='#impl-From%3CString%3E-1' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.21.0'>1.21.0</div><a class='srclink' href='../../src/alloc/rc.rs.html#1107-1112' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from-1' class="method"><span id='from.v-1' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(v: <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> <a class="struct" href="../../alloc/rc/struct.Rc.html" title="struct alloc::rc::Rc">Rc</a><str></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#1109-1111' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-Borrow%3Cstr%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../alloc/borrow/trait.Borrow.html" title="trait alloc::borrow::Borrow">Borrow</a><str> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Borrow%3Cstr%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/str.rs.html#139-144' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.borrow' class="method"><span id='borrow.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../alloc/borrow/trait.Borrow.html#tymethod.borrow' class='fnname'>borrow</a>(&self) -> &str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/str.rs.html#141-143' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Immutably borrows from an owned value. <a href="../../alloc/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p> </div></div><h3 id='impl-PartialOrd' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-PartialOrd' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#292' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.partial_cmp' class="method"><span id='partial_cmp.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialOrd.html#tymethod.partial_cmp' class='fnname'>partial_cmp</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> <a class="enum" href="../../core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="../../core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#292' title='goto source code'>[src]</a></td></tr></tbody></table></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="../../core/cmp/trait.PartialOrd.html#tymethod.partial_cmp">Read more</a></p> </div><h4 id='method.lt' class="method"><span id='lt.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialOrd.html#method.lt' class='fnname'>lt</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#292' title='goto source code'>[src]</a></td></tr></tbody></table></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><</code> operator. <a href="../../core/cmp/trait.PartialOrd.html#method.lt">Read more</a></p> </div><h4 id='method.le' class="method"><span id='le.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialOrd.html#method.le' class='fnname'>le</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#292' title='goto source code'>[src]</a></td></tr></tbody></table></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><=</code> operator. <a href="../../core/cmp/trait.PartialOrd.html#method.le">Read more</a></p> </div><h4 id='method.gt' class="method"><span id='gt.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialOrd.html#method.gt' class='fnname'>gt</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#292' title='goto source code'>[src]</a></td></tr></tbody></table></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>></code> operator. <a href="../../core/cmp/trait.PartialOrd.html#method.gt">Read more</a></p> </div><h4 id='method.ge' class="method"><span id='ge.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialOrd.html#method.ge' class='fnname'>ge</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#292' title='goto source code'>[src]</a></td></tr></tbody></table></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>>=</code> operator. <a href="../../core/cmp/trait.PartialOrd.html#method.ge">Read more</a></p> </div></div><h3 id='impl-Eq' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Eq' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#292' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'></div><h3 id='impl-Ord' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Ord' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#292' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.cmp' class="method"><span id='cmp.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.Ord.html#tymethod.cmp' class='fnname'>cmp</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> <a class="enum" href="../../core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#292' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>This method returns an <code>Ordering</code> between <code>self</code> and <code>other</code>. <a href="../../core/cmp/trait.Ord.html#tymethod.cmp">Read more</a></p> </div><h4 id='method.max' class="method"><span id='max.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.Ord.html#method.max' class='fnname'>max</a>(self, other: Self) -> Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.21.0'>1.21.0</div><a class='srclink' href='../../src/core/cmp.rs.html#469-472' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Compares and returns the maximum of two values. <a href="../../core/cmp/trait.Ord.html#method.max">Read more</a></p> </div><h4 id='method.min' class="method"><span id='min.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.Ord.html#method.min' class='fnname'>min</a>(self, other: Self) -> Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.21.0'>1.21.0</div><a class='srclink' href='../../src/core/cmp.rs.html#485-488' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Compares and returns the minimum of two values. <a href="../../core/cmp/trait.Ord.html#method.min">Read more</a></p> </div></div><h3 id='impl-Clone' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Clone' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1682-1690' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.clone' class="method"><span id='clone.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&self) -> Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1683-1685' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns a copy of the value. <a href="../../core/clone/trait.Clone.html#tymethod.clone">Read more</a></p> </div><h4 id='method.clone_from' class="method"><span id='clone_from.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&mut self, source: &Self)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1687-1689' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs copy-assignment from <code>source</code>. <a href="../../core/clone/trait.Clone.html#method.clone_from">Read more</a></p> </div></div><h3 id='impl-FromIterator%3Cchar%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/iter/traits/trait.FromIterator.html" title="trait core::iter::traits::FromIterator">FromIterator</a><char> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-FromIterator%3Cchar%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1693-1699' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from_iter' class="method"><span id='from_iter.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = char>>(iter: I) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1694-1698' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a value from an iterator. <a href="../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter">Read more</a></p> </div></div><h3 id='impl-FromIterator%3C%26%27a%20char%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../core/iter/traits/trait.FromIterator.html" title="trait core::iter::traits::FromIterator">FromIterator</a><&'a char> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-FromIterator%3C%26%27a%20char%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.17.0'>1.17.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1702-1708' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from_iter-1' class="method"><span id='from_iter.v-1' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = &'a char>>(iter: I) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1703-1707' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a value from an iterator. <a href="../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter">Read more</a></p> </div></div><h3 id='impl-FromIterator%3C%26%27a%20str%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../core/iter/traits/trait.FromIterator.html" title="trait core::iter::traits::FromIterator">FromIterator</a><&'a str> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-FromIterator%3C%26%27a%20str%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1711-1717' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from_iter-2' class="method"><span id='from_iter.v-2' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = &'a str>>(iter: I) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1712-1716' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a value from an iterator. <a href="../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter">Read more</a></p> </div></div><h3 id='impl-FromIterator%3CString%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/iter/traits/trait.FromIterator.html" title="trait core::iter::traits::FromIterator">FromIterator</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-FromIterator%3CString%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1720-1726' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from_iter-3' class="method"><span id='from_iter.v-3' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>>(iter: I) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1721-1725' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a value from an iterator. <a href="../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter">Read more</a></p> </div></div><h3 id='impl-FromIterator%3CCow%3C%27a%2C%20str%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../core/iter/traits/trait.FromIterator.html" title="trait core::iter::traits::FromIterator">FromIterator</a><<a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-FromIterator%3CCow%3C%27a%2C%20str%3E%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.19.0'>1.19.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1729-1735' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from_iter-4' class="method"><span id='from_iter.v-4' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = <a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str>>>(iter: I) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1730-1734' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a value from an iterator. <a href="../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter">Read more</a></p> </div></div><h3 id='impl-Extend%3Cchar%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a><char> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Extend%3Cchar%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1738-1747' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.extend' class="method"><span id='extend.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/iter/traits/trait.Extend.html#tymethod.extend' class='fnname'>extend</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = char>>(&mut self, iter: I)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1739-1746' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Extends a collection with the contents of an iterator. <a href="../../core/iter/traits/trait.Extend.html#tymethod.extend">Read more</a></p> </div></div><h3 id='impl-Extend%3C%26%27a%20char%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a><&'a char> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Extend%3C%26%27a%20char%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.2.0'>1.2.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1750-1754' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.extend-1' class="method"><span id='extend.v-1' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/iter/traits/trait.Extend.html#tymethod.extend' class='fnname'>extend</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = &'a char>>(&mut self, iter: I)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1751-1753' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Extends a collection with the contents of an iterator. <a href="../../core/iter/traits/trait.Extend.html#tymethod.extend">Read more</a></p> </div></div><h3 id='impl-Extend%3C%26%27a%20str%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a><&'a str> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Extend%3C%26%27a%20str%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1757-1763' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.extend-2' class="method"><span id='extend.v-2' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/iter/traits/trait.Extend.html#tymethod.extend' class='fnname'>extend</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = &'a str>>(&mut self, iter: I)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1758-1762' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Extends a collection with the contents of an iterator. <a href="../../core/iter/traits/trait.Extend.html#tymethod.extend">Read more</a></p> </div></div><h3 id='impl-Extend%3CString%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Extend%3CString%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1766-1772' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.extend-3' class="method"><span id='extend.v-3' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/iter/traits/trait.Extend.html#tymethod.extend' class='fnname'>extend</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>>(&mut self, iter: I)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1767-1771' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Extends a collection with the contents of an iterator. <a href="../../core/iter/traits/trait.Extend.html#tymethod.extend">Read more</a></p> </div></div><h3 id='impl-Extend%3CCow%3C%27a%2C%20str%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a><<a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Extend%3CCow%3C%27a%2C%20str%3E%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.19.0'>1.19.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1775-1781' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.extend-4' class="method"><span id='extend.v-4' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/iter/traits/trait.Extend.html#tymethod.extend' class='fnname'>extend</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = <a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str>>>(&mut self, iter: I)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1776-1780' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Extends a collection with the contents of an iterator. <a href="../../core/iter/traits/trait.Extend.html#tymethod.extend">Read more</a></p> </div></div><h3 id='impl-Pattern%3C%27a%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a, 'b> <a class="trait" href="../../alloc/str/pattern/trait.Pattern.html" title="trait alloc::str::pattern::Pattern">Pattern</a><'a> for &'b <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Pattern%3C%27a%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1787-1803' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='docblock'><p>A convenience impl that delegates to the impl for <code>&str</code></p> </div><div class='impl-items'><h4 id='associatedtype.Searcher' class="type"><span id='Searcher.t' class='invisible'><code>type <a href='../../alloc/str/pattern/trait.Pattern.html#associatedtype.Searcher' class="type">Searcher</a> = <&'b str as <a class="trait" href="../../alloc/str/pattern/trait.Pattern.html" title="trait alloc::str::pattern::Pattern">Pattern</a><'a>>::<a class="type" href="../../alloc/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type alloc::str::pattern::Pattern::Searcher">Searcher</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>Associated searcher for this pattern</p> </div><h4 id='method.into_searcher' class="method"><span id='into_searcher.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../alloc/str/pattern/trait.Pattern.html#tymethod.into_searcher' class='fnname'>into_searcher</a>(self, haystack: &'a str) -> <&'b str as <a class="trait" href="../../alloc/str/pattern/trait.Pattern.html" title="trait alloc::str::pattern::Pattern">Pattern</a><'a>>::<a class="type" href="../../alloc/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type alloc::str::pattern::Pattern::Searcher">Searcher</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1790-1792' title='goto source code'>[src]</a></td></tr></tbody></table></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="../../alloc/str/pattern/trait.Pattern.html#tymethod.into_searcher">Read more</a></p> </div><h4 id='method.is_contained_in' class="method"><span id='is_contained_in.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../alloc/str/pattern/trait.Pattern.html#method.is_contained_in' class='fnname'>is_contained_in</a>(self, haystack: &'a str) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1795-1797' title='goto source code'>[src]</a></td></tr></tbody></table></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><h4 id='method.is_prefix_of' class="method"><span id='is_prefix_of.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../alloc/str/pattern/trait.Pattern.html#method.is_prefix_of' class='fnname'>is_prefix_of</a>(self, haystack: &'a str) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1800-1802' title='goto source code'>[src]</a></td></tr></tbody></table></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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../alloc/str/pattern/trait.Pattern.html#method.is_suffix_of' class='fnname'>is_suffix_of</a>(self, haystack: &'a str) -> bool <span class="where fmt-newline">where<br> Self::<a class="type" href="../../alloc/str/pattern/trait.Pattern.html#associatedtype.Searcher" title="type alloc::str::pattern::Pattern::Searcher">Searcher</a>: <a class="trait" href="../../alloc/str/pattern/trait.ReverseSearcher.html" title="trait alloc::str::pattern::ReverseSearcher">ReverseSearcher</a><'a>, </span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/str/pattern.rs.html#63-70' title='goto source code'>[src]</a></td></tr></tbody></table></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></div><h3 id='impl-PartialEq' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-PartialEq' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1806-1815' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.eq' class="method"><span id='eq.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1808-1810' title='goto source code'>[src]</a></td></tr></tbody></table></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="../../core/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p> </div><h4 id='method.ne' class="method"><span id='ne.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1812-1814' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>This method tests for <code>!=</code>.</p> </div></div><h3 id='impl-PartialEq%3Cstr%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a, 'b> <a class="trait" href="../../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><str> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-PartialEq%3Cstr%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1820-1825' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.eq-1' class="method"><span id='eq.v-1' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &str) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1822' title='goto source code'>[src]</a></td></tr></tbody></table></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="../../core/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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &str) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1824' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>This method tests for <code>!=</code>.</p> </div></div><h3 id='impl-PartialEq%3CString%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a, 'b> <a class="trait" href="../../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>> for str</code><a href='#impl-PartialEq%3CString%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1828-1833' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.eq-2' class="method"><span id='eq.v-2' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1830' title='goto source code'>[src]</a></td></tr></tbody></table></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="../../core/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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1832' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>This method tests for <code>!=</code>.</p> </div></div><h3 id='impl-PartialEq%3C%26%27a%20str%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a, 'b> <a class="trait" href="../../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><&'a str> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-PartialEq%3C%26%27a%20str%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1820-1825' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.eq-3' class="method"><span id='eq.v-3' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &&'a str) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1822' title='goto source code'>[src]</a></td></tr></tbody></table></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="../../core/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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &&'a str) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1824' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>This method tests for <code>!=</code>.</p> </div></div><h3 id='impl-PartialEq%3CString%3E-1' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a, 'b> <a class="trait" href="../../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>> for &'a str</code><a href='#impl-PartialEq%3CString%3E-1' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1828-1833' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.eq-4' class="method"><span id='eq.v-4' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1830' title='goto source code'>[src]</a></td></tr></tbody></table></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="../../core/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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1832' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>This method tests for <code>!=</code>.</p> </div></div><h3 id='impl-PartialEq%3CString%3E-2' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a, 'b> <a class="trait" href="../../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>> for <a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str></code><a href='#impl-PartialEq%3CString%3E-2' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1820-1825' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.eq-5' class="method"><span id='eq.v-5' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1822' title='goto source code'>[src]</a></td></tr></tbody></table></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="../../core/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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1824' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>This method tests for <code>!=</code>.</p> </div></div><h3 id='impl-PartialEq%3CCow%3C%27a%2C%20str%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a, 'b> <a class="trait" href="../../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><<a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-PartialEq%3CCow%3C%27a%2C%20str%3E%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1828-1833' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.eq-6' class="method"><span id='eq.v-6' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1830' title='goto source code'>[src]</a></td></tr></tbody></table></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="../../core/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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &<a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str>) -> bool</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1832' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>This method tests for <code>!=</code>.</p> </div></div><h3 id='impl-Default' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Default' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1845-1851' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.default' class="method"><span id='default.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/default/trait.Default.html#tymethod.default' class='fnname'>default</a>() -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1848-1850' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates an empty <code>String</code>.</p> </div></div><h3 id='impl-Display' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../alloc/fmt/trait.Display.html" title="trait alloc::fmt::Display">Display</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Display' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1854-1859' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../alloc/fmt/trait.Display.html#tymethod.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class="struct" href="../../alloc/fmt/struct.Formatter.html" title="struct alloc::fmt::Formatter">Formatter</a>) -> <a class="type" href="../../alloc/fmt/type.Result.html" title="type alloc::fmt::Result">Result</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1856-1858' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Formats the value using the given formatter. <a href="../../alloc/fmt/trait.Display.html#tymethod.fmt">Read more</a></p> </div></div><h3 id='impl-Debug' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../alloc/fmt/trait.Debug.html" title="trait alloc::fmt::Debug">Debug</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Debug' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1862-1867' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.fmt-1' class="method"><span id='fmt.v-1' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../alloc/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class="struct" href="../../alloc/fmt/struct.Formatter.html" title="struct alloc::fmt::Formatter">Formatter</a>) -> <a class="type" href="../../alloc/fmt/type.Result.html" title="type alloc::fmt::Result">Result</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1864-1866' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Formats the value using the given formatter. <a href="../../alloc/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p> </div></div><h3 id='impl-Hash' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Hash' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1870-1875' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.hash' class="method"><span id='hash.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/hash/trait.Hash.html#tymethod.hash' class='fnname'>hash</a><H: <a class="trait" href="../../core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>>(&self, hasher: &mut H)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1872-1874' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Feeds this value into the given [<code>Hasher</code>]. <a href="../../core/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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/hash/trait.Hash.html#method.hash_slice' class='fnname'>hash_slice</a><H>(data: &[Self], state: &mut H) <span class="where fmt-newline">where<br> H: <a class="trait" href="../../core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>, </span></code></span></td><td><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/hash/mod.rs.html#203-209' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Feeds a slice of this type into the given [<code>Hasher</code>]. <a href="../../core/hash/trait.Hash.html#method.hash_slice">Read more</a></p> </div></div><h3 id='impl-Add%3C%26%27a%20str%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../core/ops/arith/trait.Add.html" title="trait core::ops::arith::Add">Add</a><&'a str> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Add%3C%26%27a%20str%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1915-1923' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='docblock'><p>Implements the <code>+</code> operator for concatenating two strings.</p> <p>This consumes the <code>String</code> on the left-hand side and re-uses its buffer (growing it if necessary). This is done to avoid allocating a new <code>String</code> and copying the entire contents on every operation, which would lead to <code>O(n^2)</code> running time when building an <code>n</code>-byte string by repeated concatenation.</p> <p>The string on the right-hand side is only borrowed; its contents are copied into the returned <code>String</code>.</p> <h1 id="examples-36" class="section-header"><a href="#examples-36">Examples</a></h1> <p>Concatenating two <code>String</code>s takes the first by value and borrows the second:</p> <pre class="rust rust-example-rendered"> <span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"hello"</span>); <span class="kw">let</span> <span class="ident">b</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">" world"</span>); <span class="kw">let</span> <span class="ident">c</span> <span class="op">=</span> <span class="ident">a</span> <span class="op">+</span> <span class="kw-2">&</span><span class="ident">b</span>; <span class="comment">// `a` is moved and can no longer be used here.</span></pre> <p>If you want to keep using the first <code>String</code>, you can clone it and append to the clone instead:</p> <pre class="rust rust-example-rendered"> <span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"hello"</span>); <span class="kw">let</span> <span class="ident">b</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">" world"</span>); <span class="kw">let</span> <span class="ident">c</span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">clone</span>() <span class="op">+</span> <span class="kw-2">&</span><span class="ident">b</span>; <span class="comment">// `a` is still valid here.</span></pre> <p>Concatenating <code>&str</code> slices can be done by converting the first to a <code>String</code>:</p> <pre class="rust rust-example-rendered"> <span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> <span class="string">"hello"</span>; <span class="kw">let</span> <span class="ident">b</span> <span class="op">=</span> <span class="string">" world"</span>; <span class="kw">let</span> <span class="ident">c</span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">to_string</span>() <span class="op">+</span> <span class="ident">b</span>;</pre> </div><div class='impl-items'><h4 id='associatedtype.Output' class="type"><span id='Output.t' class='invisible'><code>type <a href='../../core/ops/arith/trait.Add.html#associatedtype.Output' class="type">Output</a> = <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></h4> <div class='docblock'><p>The resulting type after applying the <code>+</code> operator.</p> </div><h4 id='method.add' class="method"><span id='add.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/arith/trait.Add.html#tymethod.add' class='fnname'>add</a>(self, other: &str) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1919-1922' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the <code>+</code> operation.</p> </div></div><h3 id='impl-AddAssign%3C%26%27a%20str%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a><&'a str> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-AddAssign%3C%26%27a%20str%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.12.0'>1.12.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1931-1936' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='docblock'><p>Implements the <code>+=</code> operator for appending to a <code>String</code>.</p> <p>This has the same behavior as the <a href="struct.String.html#method.push_str"><code>push_str</code></a> method.</p> </div><div class='impl-items'><h4 id='method.add_assign' class="method"><span id='add_assign.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/arith/trait.AddAssign.html#tymethod.add_assign' class='fnname'>add_assign</a>(&mut self, other: &str)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1933-1935' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the <code>+=</code> operation.</p> </div></div><h3 id='impl-Index%3CRange%3Cusize%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/index/trait.Index.html" title="trait core::ops::index::Index">Index</a><<a class="struct" href="../../core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a><usize>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Index%3CRange%3Cusize%3E%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1939-1946' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='associatedtype.Output-1' class="type"><span id='Output.t-1' class='invisible'><code>type <a href='../../core/ops/index/trait.Index.html#associatedtype.Output' class="type">Output</a> = str</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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/index/trait.Index.html#tymethod.index' class='fnname'>index</a>(&self, index: <a class="struct" href="../../core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a><usize>) -> &str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1943-1945' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the indexing (<code>container[index]</code>) operation.</p> </div></div><h3 id='impl-Index%3CRangeTo%3Cusize%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/index/trait.Index.html" title="trait core::ops::index::Index">Index</a><<a class="struct" href="../../core/ops/range/struct.RangeTo.html" title="struct core::ops::range::RangeTo">RangeTo</a><usize>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Index%3CRangeTo%3Cusize%3E%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1948-1955' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='associatedtype.Output-2' class="type"><span id='Output.t-2' class='invisible'><code>type <a href='../../core/ops/index/trait.Index.html#associatedtype.Output' class="type">Output</a> = str</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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/index/trait.Index.html#tymethod.index' class='fnname'>index</a>(&self, index: <a class="struct" href="../../core/ops/range/struct.RangeTo.html" title="struct core::ops::range::RangeTo">RangeTo</a><usize>) -> &str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1952-1954' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the indexing (<code>container[index]</code>) operation.</p> </div></div><h3 id='impl-Index%3CRangeFrom%3Cusize%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/index/trait.Index.html" title="trait core::ops::index::Index">Index</a><<a class="struct" href="../../core/ops/range/struct.RangeFrom.html" title="struct core::ops::range::RangeFrom">RangeFrom</a><usize>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Index%3CRangeFrom%3Cusize%3E%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1957-1964' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='associatedtype.Output-3' class="type"><span id='Output.t-3' class='invisible'><code>type <a href='../../core/ops/index/trait.Index.html#associatedtype.Output' class="type">Output</a> = str</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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/index/trait.Index.html#tymethod.index' class='fnname'>index</a>(&self, index: <a class="struct" href="../../core/ops/range/struct.RangeFrom.html" title="struct core::ops::range::RangeFrom">RangeFrom</a><usize>) -> &str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1961-1963' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the indexing (<code>container[index]</code>) operation.</p> </div></div><h3 id='impl-Index%3CRangeFull%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/index/trait.Index.html" title="trait core::ops::index::Index">Index</a><<a class="struct" href="../../core/ops/range/struct.RangeFull.html" title="struct core::ops::range::RangeFull">RangeFull</a>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Index%3CRangeFull%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1966-1973' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='associatedtype.Output-4' class="type"><span id='Output.t-4' class='invisible'><code>type <a href='../../core/ops/index/trait.Index.html#associatedtype.Output' class="type">Output</a> = str</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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/index/trait.Index.html#tymethod.index' class='fnname'>index</a>(&self, _index: <a class="struct" href="../../core/ops/range/struct.RangeFull.html" title="struct core::ops::range::RangeFull">RangeFull</a>) -> &str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1970-1972' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the indexing (<code>container[index]</code>) operation.</p> </div></div><h3 id='impl-Index%3CRangeInclusive%3Cusize%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/index/trait.Index.html" title="trait core::ops::index::Index">Index</a><<a class="struct" href="../../core/ops/range/struct.RangeInclusive.html" title="struct core::ops::range::RangeInclusive">RangeInclusive</a><usize>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Index%3CRangeInclusive%3Cusize%3E%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.26.0'>1.26.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1975-1982' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='associatedtype.Output-5' class="type"><span id='Output.t-5' class='invisible'><code>type <a href='../../core/ops/index/trait.Index.html#associatedtype.Output' class="type">Output</a> = str</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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/index/trait.Index.html#tymethod.index' class='fnname'>index</a>(&self, index: <a class="struct" href="../../core/ops/range/struct.RangeInclusive.html" title="struct core::ops::range::RangeInclusive">RangeInclusive</a><usize>) -> &str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1979-1981' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the indexing (<code>container[index]</code>) operation.</p> </div></div><h3 id='impl-Index%3CRangeToInclusive%3Cusize%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/index/trait.Index.html" title="trait core::ops::index::Index">Index</a><<a class="struct" href="../../core/ops/range/struct.RangeToInclusive.html" title="struct core::ops::range::RangeToInclusive">RangeToInclusive</a><usize>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Index%3CRangeToInclusive%3Cusize%3E%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.26.0'>1.26.0</div><a class='srclink' href='../../src/alloc/string.rs.html#1984-1991' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='associatedtype.Output-6' class="type"><span id='Output.t-6' class='invisible'><code>type <a href='../../core/ops/index/trait.Index.html#associatedtype.Output' class="type">Output</a> = str</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'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/index/trait.Index.html#tymethod.index' class='fnname'>index</a>(&self, index: <a class="struct" href="../../core/ops/range/struct.RangeToInclusive.html" title="struct core::ops::range::RangeToInclusive">RangeToInclusive</a><usize>) -> &str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1988-1990' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the indexing (<code>container[index]</code>) operation.</p> </div></div><h3 id='impl-IndexMut%3CRange%3Cusize%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/index/trait.IndexMut.html" title="trait core::ops::index::IndexMut">IndexMut</a><<a class="struct" href="../../core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a><usize>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-IndexMut%3CRange%3Cusize%3E%3E' class='anchor'></a></span></td><td><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/alloc/string.rs.html#1994-1999' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.index_mut' class="method"><span id='index_mut.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/index/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&mut self, index: <a class="struct" href="../../core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a><usize>) -> &mut str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#1996-1998' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the mutable indexing (<code>container[index]</code>) operation.</p> </div></div><h3 id='impl-IndexMut%3CRangeTo%3Cusize%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/index/trait.IndexMut.html" title="trait core::ops::index::IndexMut">IndexMut</a><<a class="struct" href="../../core/ops/range/struct.RangeTo.html" title="struct core::ops::range::RangeTo">RangeTo</a><usize>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-IndexMut%3CRangeTo%3Cusize%3E%3E' class='anchor'></a></span></td><td><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/alloc/string.rs.html#2001-2006' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.index_mut-1' class="method"><span id='index_mut.v-1' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/index/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&mut self, index: <a class="struct" href="../../core/ops/range/struct.RangeTo.html" title="struct core::ops::range::RangeTo">RangeTo</a><usize>) -> &mut str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2003-2005' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the mutable indexing (<code>container[index]</code>) operation.</p> </div></div><h3 id='impl-IndexMut%3CRangeFrom%3Cusize%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/index/trait.IndexMut.html" title="trait core::ops::index::IndexMut">IndexMut</a><<a class="struct" href="../../core/ops/range/struct.RangeFrom.html" title="struct core::ops::range::RangeFrom">RangeFrom</a><usize>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-IndexMut%3CRangeFrom%3Cusize%3E%3E' class='anchor'></a></span></td><td><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/alloc/string.rs.html#2008-2013' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.index_mut-2' class="method"><span id='index_mut.v-2' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/index/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&mut self, index: <a class="struct" href="../../core/ops/range/struct.RangeFrom.html" title="struct core::ops::range::RangeFrom">RangeFrom</a><usize>) -> &mut str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2010-2012' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the mutable indexing (<code>container[index]</code>) operation.</p> </div></div><h3 id='impl-IndexMut%3CRangeFull%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/index/trait.IndexMut.html" title="trait core::ops::index::IndexMut">IndexMut</a><<a class="struct" href="../../core/ops/range/struct.RangeFull.html" title="struct core::ops::range::RangeFull">RangeFull</a>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-IndexMut%3CRangeFull%3E' class='anchor'></a></span></td><td><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/alloc/string.rs.html#2015-2020' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.index_mut-3' class="method"><span id='index_mut.v-3' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/index/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&mut self, _index: <a class="struct" href="../../core/ops/range/struct.RangeFull.html" title="struct core::ops::range::RangeFull">RangeFull</a>) -> &mut str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2017-2019' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the mutable indexing (<code>container[index]</code>) operation.</p> </div></div><h3 id='impl-IndexMut%3CRangeInclusive%3Cusize%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/index/trait.IndexMut.html" title="trait core::ops::index::IndexMut">IndexMut</a><<a class="struct" href="../../core/ops/range/struct.RangeInclusive.html" title="struct core::ops::range::RangeInclusive">RangeInclusive</a><usize>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-IndexMut%3CRangeInclusive%3Cusize%3E%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.26.0'>1.26.0</div><a class='srclink' href='../../src/alloc/string.rs.html#2022-2027' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.index_mut-4' class="method"><span id='index_mut.v-4' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/index/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&mut self, index: <a class="struct" href="../../core/ops/range/struct.RangeInclusive.html" title="struct core::ops::range::RangeInclusive">RangeInclusive</a><usize>) -> &mut str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2024-2026' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the mutable indexing (<code>container[index]</code>) operation.</p> </div></div><h3 id='impl-IndexMut%3CRangeToInclusive%3Cusize%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/index/trait.IndexMut.html" title="trait core::ops::index::IndexMut">IndexMut</a><<a class="struct" href="../../core/ops/range/struct.RangeToInclusive.html" title="struct core::ops::range::RangeToInclusive">RangeToInclusive</a><usize>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-IndexMut%3CRangeToInclusive%3Cusize%3E%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.26.0'>1.26.0</div><a class='srclink' href='../../src/alloc/string.rs.html#2029-2034' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.index_mut-5' class="method"><span id='index_mut.v-5' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/index/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&mut self, index: <a class="struct" href="../../core/ops/range/struct.RangeToInclusive.html" title="struct core::ops::range::RangeToInclusive">RangeToInclusive</a><usize>) -> &mut str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2031-2033' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the mutable indexing (<code>container[index]</code>) operation.</p> </div></div><h3 id='impl-Deref' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Deref' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2037-2044' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='associatedtype.Target' class="type"><span id='Target.t' class='invisible'><code>type <a href='../../core/ops/deref/trait.Deref.html#associatedtype.Target' class="type">Target</a> = str</code></span></h4> <div class='docblock'><p>The resulting type after dereferencing.</p> </div><h4 id='method.deref' class="method"><span id='deref.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/deref/trait.Deref.html#tymethod.deref' class='fnname'>deref</a>(&self) -> &str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2041-2043' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Dereferences the value.</p> </div></div><h3 id='impl-DerefMut' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/ops/deref/trait.DerefMut.html" title="trait core::ops::deref::DerefMut">DerefMut</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-DerefMut' class='anchor'></a></span></td><td><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/alloc/string.rs.html#2047-2052' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.deref_mut' class="method"><span id='deref_mut.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/ops/deref/trait.DerefMut.html#tymethod.deref_mut' class='fnname'>deref_mut</a>(&mut self) -> &mut str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2049-2051' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Mutably dereferences the value.</p> </div></div><h3 id='impl-FromStr' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../alloc/str/trait.FromStr.html" title="trait alloc::str::FromStr">FromStr</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-FromStr' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2071-2077' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='associatedtype.Err' class="type"><span id='Err.t' class='invisible'><code>type <a href='../../alloc/str/trait.FromStr.html#associatedtype.Err' class="type">Err</a> = <a class="enum" href="../../alloc/string/enum.ParseError.html" title="enum alloc::string::ParseError">ParseError</a></code></span></h4> <div class='docblock'><p>The associated error which can be returned from parsing.</p> </div><h4 id='method.from_str' class="method"><span id='from_str.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../alloc/str/trait.FromStr.html#tymethod.from_str' class='fnname'>from_str</a>(s: &str) -> <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>, <a class="enum" href="../../alloc/string/enum.ParseError.html" title="enum alloc::string::ParseError">ParseError</a>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2074-2076' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Parses a string <code>s</code> to return a value of this type. <a href="../../alloc/str/trait.FromStr.html#tymethod.from_str">Read more</a></p> </div></div><h3 id='impl-ToString' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../alloc/string/trait.ToString.html" title="trait alloc::string::ToString">ToString</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-ToString' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.17.0'>1.17.0</div><a class='srclink' href='../../src/alloc/string.rs.html#2173-2178' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.to_string' class="method"><span id='to_string.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../alloc/string/trait.ToString.html#tymethod.to_string' class='fnname'>to_string</a>(&self) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2175-2177' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Converts the given value to a <code>String</code>. <a href="../../alloc/string/trait.ToString.html#tymethod.to_string">Read more</a></p> </div></div><h3 id='impl-AsRef%3Cstr%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><str> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-AsRef%3Cstr%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2181-2186' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.as_ref' class="method"><span id='as_ref.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&self) -> &str</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2183-2185' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-AsRef%3C%5Bu8%5D%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[u8]> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-AsRef%3C%5Bu8%5D%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2189-2194' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.as_ref-1' class="method"><span id='as_ref.v-1' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&self) -> &[u8]</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2191-2193' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-From%3C%26%27a%20str%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a><&'a str> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-From%3C%26%27a%20str%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2197-2201' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from-2' class="method"><span id='from.v-2' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: &'a str) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2198-2200' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-From%3CBox%3Cstr%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="struct" href="../../alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><str>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-From%3CBox%3Cstr%3E%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.18.0'>1.18.0</div><a class='srclink' href='../../src/alloc/string.rs.html#2206-2210' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from-3' class="method"><span id='from.v-3' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: <a class="struct" href="../../alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><str>) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2207-2209' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-From%3CString%3E-2' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>> for <a class="struct" href="../../alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><str></code><a href='#impl-From%3CString%3E-2' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.20.0'>1.20.0</div><a class='srclink' href='../../src/alloc/string.rs.html#2213-2217' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from-4' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><I></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><I></h3><code class="content"><span class="where fmt-newline">impl<I: <a class="trait" href="../../core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> + ?<a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>> <a class="trait" href="../../core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../../alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><I></span><span class="where fmt-newline"> type <a href='../../core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = I::<a class="type" href="../../core/iter/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::iterator::Iterator::Item">Item</a>;</span></code></div></div><span id='from.v-4' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> <a class="struct" href="../../alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><str></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2214-2216' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-From%3CCow%3C%27a%2C%20str%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str>> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-From%3CCow%3C%27a%2C%20str%3E%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.14.0'>1.14.0</div><a class='srclink' href='../../src/alloc/string.rs.html#2220-2224' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from-5' class="method"><span id='from.v-5' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: <a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str>) -> <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2221-2223' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-From%3CString%3E-3' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>> for <a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str></code><a href='#impl-From%3CString%3E-3' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2235-2240' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from-6' class="method"><span id='from.v-6' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> <a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2237-2239' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-FromIterator%3CString%3E-1' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../core/iter/traits/trait.FromIterator.html" title="trait core::iter::traits::FromIterator">FromIterator</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>> for <a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str></code><a href='#impl-FromIterator%3CString%3E-1' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.12.0'>1.12.0</div><a class='srclink' href='../../src/alloc/string.rs.html#2257-2261' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from_iter-5' class="method"><span id='from_iter.v-5' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>>(it: I) -> <a class="enum" href="../../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, str></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2258-2260' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a value from an iterator. <a href="../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter">Read more</a></p> </div></div><h3 id='impl-From%3CString%3E-4' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>> for <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><u8></code><a href='#impl-From%3CString%3E-4' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.14.0'>1.14.0</div><a class='srclink' href='../../src/alloc/string.rs.html#2264-2268' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from-7' class="method"><span id='from.v-7' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(string: <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) -> <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><u8></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2265-2267' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-Write' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../alloc/fmt/trait.Write.html" title="trait alloc::fmt::Write">Write</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Write' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2271-2283' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.write_str' class="method"><span id='write_str.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../alloc/fmt/trait.Write.html#tymethod.write_str' class='fnname'>write_str</a>(&mut self, s: &str) -> <a class="type" href="../../alloc/fmt/type.Result.html" title="type alloc::fmt::Result">Result</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2273-2276' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Writes a slice of bytes into this writer, returning whether the write succeeded. <a href="../../alloc/fmt/trait.Write.html#tymethod.write_str">Read more</a></p> </div><h4 id='method.write_char' class="method"><span id='write_char.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../alloc/fmt/trait.Write.html#method.write_char' class='fnname'>write_char</a>(&mut self, c: char) -> <a class="type" href="../../alloc/fmt/type.Result.html" title="type alloc::fmt::Result">Result</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/string.rs.html#2279-2282' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Writes a [<code>char</code>] into this writer, returning whether the write succeeded. <a href="../../alloc/fmt/trait.Write.html#method.write_char">Read more</a></p> </div><h4 id='method.write_fmt' class="method"><span id='write_fmt.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../alloc/fmt/trait.Write.html#method.write_fmt' class='fnname'>write_fmt</a>(&mut self, args: <a class="struct" href="../../alloc/fmt/struct.Arguments.html" title="struct alloc::fmt::Arguments">Arguments</a>) -> <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a><(), <a class="struct" href="../../alloc/fmt/struct.Error.html" title="struct alloc::fmt::Error">Error</a>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/fmt/mod.rs.html#204-227' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Glue for usage of the [<code>write!</code>] macro with implementors of this trait. <a href="../../alloc/fmt/trait.Write.html#method.write_fmt">Read more</a></p> </div></div></div> <h2 id='synthetic-implementations' class='small-section-header'> Auto Trait Implementations<a href='#synthetic-implementations' class='anchor'></a> </h2> <div id='synthetic-implementations-list'> <h3 id='impl-Send' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Send' class='anchor'></a></span></td><td><span class='out-of-band'></span></td></tr></tbody></table></h3><div class='impl-items'></div><h3 id='impl-Sync' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="../../alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a href='#impl-Sync' class='anchor'></a></span></td><td><span class='out-of-band'></span></td></tr></tbody></table></h3><div class='impl-items'></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><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>⏎</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse 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><p>Search multiple things at once by splitting your query with comma (e.g. <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../../";window.currentCrate = "alloc";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>