Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates > by-pkgid > 564935689ab5527f955e5449ded02799 > files > 681

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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="generator" content="rustdoc">
    <meta name="description" content="API documentation for the Rust `String` struct in crate `collections`.">
    <meta name="keywords" content="rust, rustlang, rust-lang, String">

    <title>collections::string::String - Rust</title>

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

    <link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico">
    
</head>
<body class="rustdoc 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">
        <a href='../../collections/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="block items"><ul><li><a href="#methods">Methods</a></li><li><a href="#implementations">Trait Implementations</a></li></ul></div><p class='location'><a href='../index.html'>collections</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>
    </nav>

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

    <section id='main' class="content">
<h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>collections</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'>&#x2212;</span>]
                   </a>
               </span><a class='srclink' href='../../src/collections/string.rs.html#264-266' title='goto source code'>[src]</a></span></h1>
<pre class='rust struct'>pub struct String { /* fields omitted */ }</pre><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 <code>String::from</code>:</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">&quot;Hello, world!&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20hello%20%3D%20String%3A%3Afrom(%22Hello%2C%20world!%22)%3B%0A%7D">Run</a></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>&amp;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">&quot;Hello, &quot;</span>);

<span class="ident">hello</span>.<span class="ident">push</span>(<span class="string">&#39;w&#39;</span>);
<span class="ident">hello</span>.<span class="ident">push_str</span>(<span class="string">&quot;orld!&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20hello%20%3D%20String%3A%3Afrom(%22Hello%2C%20%22)%3B%0A%0Ahello.push('w')%3B%0Ahello.push_str(%22orld!%22)%3B%0A%7D">Run</a></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&#39;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">&quot;💖&quot;</span>, <span class="ident">sparkle_heart</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%2F%2F%20some%20bytes%2C%20in%20a%20vector%0Alet%20sparkle_heart%20%3D%20vec!%5B240%2C%20159%2C%20146%2C%20150%5D%3B%0A%0A%2F%2F%20We%20know%20these%20bytes%20are%20valid%2C%20so%20we'll%20use%20%60unwrap()%60.%0Alet%20sparkle_heart%20%3D%20String%3A%3Afrom_utf8(sparkle_heart).unwrap()%3B%0A%0Aassert_eq!(%22%F0%9F%92%96%22%2C%20sparkle_heart)%3B%0A%7D">Run</a></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>

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

<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;The first letter of s is {}&quot;</span>, <span class="ident">s</span>[<span class="number">0</span>]); <span class="comment">// ERROR!!!</span><a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20%22hello%22%3B%0A%0Aprintln!(%22The%20first%20letter%20of%20s%20is%20%7B%7D%22%2C%20s%5B0%5D)%3B%20%2F%2F%20ERROR!!!%0A%7D">Run</a></pre>

<p>Indexing is intended to be a constant-time operation, but UTF-8 encoding
does not allow us to do this. Furthermore, it&#39;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>&lt;Target=str&gt;</code>, and so inherit all of <a href="../../std/primitive.str.html"><code>str</code></a>&#39;s
methods. In addition, this means that you can pass a <code>String</code> to any
function which takes a <a href="../../std/primitive.str.html"><code>&amp;str</code></a> by using an ampersand (<code>&amp;</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">&amp;</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">&quot;Hello&quot;</span>);

<span class="ident">takes_str</span>(<span class="kw-2">&amp;</span><span class="ident">s</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Afn%20takes_str(s%3A%20%26str)%20%7B%20%7D%0A%0Alet%20s%20%3D%20String%3A%3Afrom(%22Hello%22)%3B%0A%0Atakes_str(%26s)%3B%0A%7D">Run</a></pre>

<p>This will create a <a href="../../std/primitive.str.html"><code>&amp;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>&amp;str</code></a>s as arguments unless they need a <code>String</code> for some specific reason.</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">&quot;Once upon a time...&quot;</span>);

<span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="ident">story</span>.<span class="ident">as_ptr</span>();
<span class="kw">let</span> <span class="ident">len</span> <span class="op">=</span> <span class="ident">story</span>.<span class="ident">len</span>();
<span class="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="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">&quot;Once upon a time...&quot;</span>), <span class="ident">s</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Amem%3B%0A%0Alet%20story%20%3D%20String%3A%3Afrom(%22Once%20upon%20a%20time...%22)%3B%0A%0Alet%20ptr%20%3D%20story.as_ptr()%3B%0Alet%20len%20%3D%20story.len()%3B%0Alet%20capacity%20%3D%20story.capacity()%3B%0A%0A%2F%2F%20story%20has%20nineteen%20bytes%0Aassert_eq!(19%2C%20len)%3B%0A%0A%2F%2F%20Now%20that%20we%20have%20our%20parts%2C%20we%20throw%20the%20story%20away.%0Amem%3A%3Aforget(story)%3B%0A%0A%2F%2F%20We%20can%20re-build%20a%20String%20out%20of%20ptr%2C%20len%2C%20and%20capacity.%20This%20is%20all%0A%2F%2F%20unsafe%20because%20we%20are%20responsible%20for%20making%20sure%20the%20components%20are%0A%2F%2F%20valid%3A%0Alet%20s%20%3D%20unsafe%20%7B%20String%3A%3Afrom_raw_parts(ptr%20as%20*mut%20_%2C%20len%2C%20capacity)%20%7D%20%3B%0A%0Aassert_eq!(String%3A%3Afrom(%22Once%20upon%20a%20time...%22)%2C%20s)%3B%0A%7D">Run</a></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">&quot;{}&quot;</span>, <span class="ident">s</span>.<span class="ident">capacity</span>());

<span class="kw">for</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">&quot;hello&quot;</span>);
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">s</span>.<span class="ident">capacity</span>());
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Anew()%3B%0A%0Aprintln!(%22%7B%7D%22%2C%20s.capacity())%3B%0A%0Afor%20_%20in%200..5%20%7B%0A%20%20%20%20s.push_str(%22hello%22)%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20s.capacity())%3B%0A%7D%0A%7D">Run</a></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">&quot;{}&quot;</span>, <span class="ident">s</span>.<span class="ident">capacity</span>());

<span class="kw">for</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">&quot;hello&quot;</span>);
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">s</span>.<span class="ident">capacity</span>());
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Awith_capacity(25)%3B%0A%0Aprintln!(%22%7B%7D%22%2C%20s.capacity())%3B%0A%0Afor%20_%20in%200..5%20%7B%0A%20%20%20%20s.push_str(%22hello%22)%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20s.capacity())%3B%0A%7D%0A%7D">Run</a></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&#39;s no need to allocate more memory inside the loop.</p>
</div><h2 id='methods'>Methods</h2><h3 class='impl'><span class='in-band'><code>impl <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#332-1469' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><code>fn <a href='#method.new' class='fnname'>new</a>() -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></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, but 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>();<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20String%3A%3Anew()%3B%0A%7D">Run</a></pre>
</div><h4 id='method.with_capacity' class="method"><span id='with_capacity.v' class='invisible'><code>fn <a href='#method.with_capacity' class='fnname'>with_capacity</a>(capacity: usize) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></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">&#39;a&#39;</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">&#39;a&#39;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Awith_capacity(10)%3B%0A%0A%2F%2F%20The%20String%20contains%20no%20chars%2C%20even%20though%20it%20has%20capacity%20for%20more%0Aassert_eq!(s.len()%2C%200)%3B%0A%0A%2F%2F%20These%20are%20all%20done%20without%20reallocating...%0Alet%20cap%20%3D%20s.capacity()%3B%0Afor%20i%20in%200..10%20%7B%0A%20%20%20%20s.push('a')%3B%0A%7D%0A%0Aassert_eq!(s.capacity()%2C%20cap)%3B%0A%0A%2F%2F%20...but%20this%20may%20make%20the%20vector%20reallocate%0As.push('a')%3B%0A%7D">Run</a></pre>
</div><h4 id='method.from_utf8' class="method"><span id='from_utf8.v' class='invisible'><code>fn <a href='#method.from_utf8' class='fnname'>from_utf8</a>(vec: <a class="struct" href="../../collections/vec/struct.Vec.html" title="struct collections::vec::Vec">Vec</a>&lt;u8&gt;) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>, <a class="struct" href="../../collections/string/struct.FromUtf8Error.html" title="struct collections::string::FromUtf8Error">FromUtf8Error</a>&gt;</code></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>&amp;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&lt;u8&gt;</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&#39;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&#39;s
sake.</p>

<p>If you need a <code>&amp;str</code> 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="#method.as_bytes"><code>as_bytes</code></a>.</p>

<h1 id='errors' class='section-header'><a href='#errors'>Errors</a></h1>
<p>Returns <code>Err</code> 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&#39;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">&quot;💖&quot;</span>, <span class="ident">sparkle_heart</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%2F%2F%20some%20bytes%2C%20in%20a%20vector%0Alet%20sparkle_heart%20%3D%20vec!%5B240%2C%20159%2C%20146%2C%20150%5D%3B%0A%0A%2F%2F%20We%20know%20these%20bytes%20are%20valid%2C%20so%20we'll%20use%20%60unwrap()%60.%0Alet%20sparkle_heart%20%3D%20String%3A%3Afrom_utf8(sparkle_heart).unwrap()%3B%0A%0Aassert_eq!(%22%F0%9F%92%96%22%2C%20sparkle_heart)%3B%0A%7D">Run</a></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>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%2F%2F%20some%20invalid%20bytes%2C%20in%20a%20vector%0Alet%20sparkle_heart%20%3D%20vec!%5B0%2C%20159%2C%20146%2C%20150%5D%3B%0A%0Aassert!(String%3A%3Afrom_utf8(sparkle_heart).is_err())%3B%0A%7D">Run</a></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'><code>fn <a href='#method.from_utf8_lossy' class='fnname'>from_utf8_lossy</a>&lt;'a&gt;(v: &amp;'a [u8]) -&gt; <a class="enum" href="../../collections/borrow/enum.Cow.html" title="enum collections::borrow::Cow">Cow</a>&lt;'a, str&gt;</code></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>&amp;[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&#39;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&lt;&#39;a, str&gt;</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&#39;s already valid UTF-8, we don&#39;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">&amp;</span><span class="ident">sparkle_heart</span>);

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;💖&quot;</span>, <span class="ident">sparkle_heart</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%2F%2F%20some%20bytes%2C%20in%20a%20vector%0Alet%20sparkle_heart%20%3D%20vec!%5B240%2C%20159%2C%20146%2C%20150%5D%3B%0A%0Alet%20sparkle_heart%20%3D%20String%3A%3Afrom_utf8_lossy(%26sparkle_heart)%3B%0A%0Aassert_eq!(%22%F0%9F%92%96%22%2C%20sparkle_heart)%3B%0A%7D">Run</a></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&quot;Hello \xF0\x90\x80World&quot;</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">&quot;Hello �World&quot;</span>, <span class="ident">output</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%2F%2F%20some%20invalid%20bytes%0Alet%20input%20%3D%20b%22Hello%20%5CxF0%5Cx90%5Cx80World%22%3B%0Alet%20output%20%3D%20String%3A%3Afrom_utf8_lossy(input)%3B%0A%0Aassert_eq!(%22Hello%20%EF%BF%BDWorld%22%2C%20output)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.from_utf16' class="method"><span id='from_utf16.v' class='invisible'><code>fn <a href='#method.from_utf16' class='fnname'>from_utf16</a>(v: &amp;[u16]) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>, <a class="struct" href="../../collections/string/struct.FromUtf16Error.html" title="struct collections::string::FromUtf16Error">FromUtf16Error</a>&gt;</code></span></h4>
<div class='docblock'><p>Decode a UTF-16 encoded vector <code>v</code> into a <code>String</code>, returning <code>Err</code>
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">&amp;</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">&quot;𝄞music&quot;</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&lt;invalid&gt;ic</span>
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&amp;</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>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%2F%2F%20%F0%9D%84%9Emusic%0Alet%20v%20%3D%20%26%5B0xD834%2C%200xDD1E%2C%200x006d%2C%200x0075%2C%0A%20%20%20%20%20%20%20%20%20%200x0073%2C%200x0069%2C%200x0063%5D%3B%0Aassert_eq!(String%3A%3Afrom(%22%F0%9D%84%9Emusic%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20String%3A%3Afrom_utf16(v).unwrap())%3B%0A%0A%2F%2F%20%F0%9D%84%9Emu%3Cinvalid%3Eic%0Alet%20v%20%3D%20%26%5B0xD834%2C%200xDD1E%2C%200x006d%2C%200x0075%2C%0A%20%20%20%20%20%20%20%20%20%200xD800%2C%200x0069%2C%200x0063%5D%3B%0Aassert!(String%3A%3Afrom_utf16(v).is_err())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.from_utf16_lossy' class="method"><span id='from_utf16_lossy.v' class='invisible'><code>fn <a href='#method.from_utf16_lossy' class='fnname'>from_utf16_lossy</a>(v: &amp;[u16]) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span></h4>
<div class='docblock'><p>Decode a UTF-16 encoded vector <code>v</code> into a string, replacing
invalid data with the replacement character (U+FFFD).</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&lt;invalid&gt;ic&lt;invalid&gt;</span>
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&amp;</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">&quot;𝄞mus\u{FFFD}ic\u{FFFD}&quot;</span>),
           <span class="ident">String</span>::<span class="ident">from_utf16_lossy</span>(<span class="ident">v</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%2F%2F%20%F0%9D%84%9Emus%3Cinvalid%3Eic%3Cinvalid%3E%0Alet%20v%20%3D%20%26%5B0xD834%2C%200xDD1E%2C%200x006d%2C%200x0075%2C%0A%20%20%20%20%20%20%20%20%20%200x0073%2C%200xDD1E%2C%200x0069%2C%200x0063%2C%0A%20%20%20%20%20%20%20%20%20%200xD834%5D%3B%0A%0Aassert_eq!(String%3A%3Afrom(%22%F0%9D%84%9Emus%5Cu%7BFFFD%7Dic%5Cu%7BFFFD%7D%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20String%3A%3Afrom_utf16_lossy(v))%3B%0A%7D">Run</a></pre>
</div><h4 id='method.from_raw_parts' class="method"><span id='from_raw_parts.v' class='invisible'><code>unsafe fn <a href='#method.from_raw_parts' class='fnname'>from_raw_parts</a>(buf: *mut u8, length: usize, capacity: usize) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></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&#39;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&#39;s
internal datastructures.</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">&quot;hello&quot;</span>);
    <span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">as_ptr</span>();
    <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="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">&quot;hello&quot;</span>), <span class="ident">s</span>);
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Amem%3B%0A%0Aunsafe%20%7B%0A%20%20%20%20let%20s%20%3D%20String%3A%3Afrom(%22hello%22)%3B%0A%20%20%20%20let%20ptr%20%3D%20s.as_ptr()%3B%0A%20%20%20%20let%20len%20%3D%20s.len()%3B%0A%20%20%20%20let%20capacity%20%3D%20s.capacity()%3B%0A%0A%20%20%20%20mem%3A%3Aforget(s)%3B%0A%0A%20%20%20%20let%20s%20%3D%20String%3A%3Afrom_raw_parts(ptr%20as%20*mut%20_%2C%20len%2C%20capacity)%3B%0A%0A%20%20%20%20assert_eq!(String%3A%3Afrom(%22hello%22)%2C%20s)%3B%0A%7D%0A%7D">Run</a></pre>
</div><h4 id='method.from_utf8_unchecked' class="method"><span id='from_utf8_unchecked.v' class='invisible'><code>unsafe fn <a href='#method.from_utf8_unchecked' class='fnname'>from_utf8_unchecked</a>(bytes: <a class="struct" href="../../collections/vec/struct.Vec.html" title="struct collections::vec::Vec">Vec</a>&lt;u8&gt;) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></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">&quot;💖&quot;</span>, <span class="ident">sparkle_heart</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%2F%2F%20some%20bytes%2C%20in%20a%20vector%0Alet%20sparkle_heart%20%3D%20vec!%5B240%2C%20159%2C%20146%2C%20150%5D%3B%0A%0Alet%20sparkle_heart%20%3D%20unsafe%20%7B%0A%20%20%20%20String%3A%3Afrom_utf8_unchecked(sparkle_heart)%0A%7D%3B%0A%0Aassert_eq!(%22%F0%9F%92%96%22%2C%20sparkle_heart)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.into_bytes' class="method"><span id='into_bytes.v' class='invisible'><code>fn <a href='#method.into_bytes' class='fnname'>into_bytes</a>(self) -&gt; <a class="struct" href="../../collections/vec/struct.Vec.html" title="struct collections::vec::Vec">Vec</a>&lt;u8&gt;</code></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">&quot;hello&quot;</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">&amp;</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">&amp;</span><span class="ident">bytes</span>[..]);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20String%3A%3Afrom(%22hello%22)%3B%0Alet%20bytes%20%3D%20s.into_bytes()%3B%0A%0Aassert_eq!(%26%5B104%2C%20101%2C%20108%2C%20108%2C%20111%5D%5B..%5D%2C%20%26bytes%5B..%5D)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.as_str' class="method"><span id='as_str.v' class='invisible'><code>fn <a href='#method.as_str' class='fnname'>as_str</a>(&amp;self) -&gt; &amp;str</code><div class='since' title='Stable since Rust version 1.7.0'>1.7.0</div></span></h4>
<div class='docblock'><p>Extracts a string slice containing the entire string.</p>
</div><h4 id='method.as_mut_str' class="method"><span id='as_mut_str.v' class='invisible'><code>fn <a href='#method.as_mut_str' class='fnname'>as_mut_str</a>(&amp;mut self) -&gt; &amp;mut str</code><div class='since' title='Stable since Rust version 1.7.0'>1.7.0</div></span></h4>
<div class='docblock'><p>Extracts a string slice containing the entire string.</p>
</div><h4 id='method.push_str' class="method"><span id='push_str.v' class='invisible'><code>fn <a href='#method.push_str' class='fnname'>push_str</a>(&amp;mut self, string: &amp;str)</code></span></h4>
<div class='docblock'><p>Appends a given string slice onto the end of this <code>String</code>.</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="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">&quot;foo&quot;</span>);

<span class="ident">s</span>.<span class="ident">push_str</span>(<span class="string">&quot;bar&quot;</span>);

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;foobar&quot;</span>, <span class="ident">s</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Afrom(%22foo%22)%3B%0A%0As.push_str(%22bar%22)%3B%0A%0Aassert_eq!(%22foobar%22%2C%20s)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.capacity' class="method"><span id='capacity.v' class='invisible'><code>fn <a href='#method.capacity' class='fnname'>capacity</a>(&amp;self) -&gt; usize</code></span></h4>
<div class='docblock'><p>Returns this <code>String</code>&#39;s capacity, in bytes.</p>

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

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="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">&gt;=</span> <span class="number">10</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20String%3A%3Awith_capacity(10)%3B%0A%0Aassert!(s.capacity()%20%3E%3D%2010)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.reserve' class="method"><span id='reserve.v' class='invisible'><code>fn <a href='#method.reserve' class='fnname'>reserve</a>(&amp;mut self, additional: usize)</code></span></h4>
<div class='docblock'><p>Ensures that this <code>String</code>&#39;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 &quot;at least&quot; behavior, see the <a href="#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 <code>usize</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">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">&gt;=</span> <span class="number">10</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Anew()%3B%0A%0As.reserve(10)%3B%0A%0Aassert!(s.capacity()%20%3E%3D%2010)%3B%0A%7D">Run</a></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">&#39;a&#39;</span>);
<span class="ident">s</span>.<span class="ident">push</span>(<span class="string">&#39;b&#39;</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&#39;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>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Awith_capacity(10)%3B%0As.push('a')%3B%0As.push('b')%3B%0A%0A%2F%2F%20s%20now%20has%20a%20length%20of%202%20and%20a%20capacity%20of%2010%0Aassert_eq!(2%2C%20s.len())%3B%0Aassert_eq!(10%2C%20s.capacity())%3B%0A%0A%2F%2F%20Since%20we%20already%20have%20an%20extra%208%20capacity%2C%20calling%20this...%0As.reserve(8)%3B%0A%0A%2F%2F%20...%20doesn't%20actually%20increase.%0Aassert_eq!(10%2C%20s.capacity())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.reserve_exact' class="method"><span id='reserve_exact.v' class='invisible'><code>fn <a href='#method.reserve_exact' class='fnname'>reserve_exact</a>(&amp;mut self, additional: usize)</code></span></h4>
<div class='docblock'><p>Ensures that this <code>String</code>&#39;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-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="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">&gt;=</span> <span class="number">10</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Anew()%3B%0A%0As.reserve_exact(10)%3B%0A%0Aassert!(s.capacity()%20%3E%3D%2010)%3B%0A%7D">Run</a></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">&#39;a&#39;</span>);
<span class="ident">s</span>.<span class="ident">push</span>(<span class="string">&#39;b&#39;</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&#39;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>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Awith_capacity(10)%3B%0As.push('a')%3B%0As.push('b')%3B%0A%0A%2F%2F%20s%20now%20has%20a%20length%20of%202%20and%20a%20capacity%20of%2010%0Aassert_eq!(2%2C%20s.len())%3B%0Aassert_eq!(10%2C%20s.capacity())%3B%0A%0A%2F%2F%20Since%20we%20already%20have%20an%20extra%208%20capacity%2C%20calling%20this...%0As.reserve_exact(8)%3B%0A%0A%2F%2F%20...%20doesn't%20actually%20increase.%0Aassert_eq!(10%2C%20s.capacity())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.shrink_to_fit' class="method"><span id='shrink_to_fit.v' class='invisible'><code>fn <a href='#method.shrink_to_fit' class='fnname'>shrink_to_fit</a>(&amp;mut self)</code></span></h4>
<div class='docblock'><p>Shrinks the capacity of this <code>String</code> to match its length.</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">from</span>(<span class="string">&quot;foo&quot;</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">&gt;=</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>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Afrom(%22foo%22)%3B%0A%0As.reserve(100)%3B%0Aassert!(s.capacity()%20%3E%3D%20100)%3B%0A%0As.shrink_to_fit()%3B%0Aassert_eq!(3%2C%20s.capacity())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.push' class="method"><span id='push.v' class='invisible'><code>fn <a href='#method.push' class='fnname'>push</a>(&amp;mut self, ch: char)</code></span></h4>
<div class='docblock'><p>Appends the given <code>char</code> to the end of this <code>String</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">from</span>(<span class="string">&quot;abc&quot;</span>);

<span class="ident">s</span>.<span class="ident">push</span>(<span class="string">&#39;1&#39;</span>);
<span class="ident">s</span>.<span class="ident">push</span>(<span class="string">&#39;2&#39;</span>);
<span class="ident">s</span>.<span class="ident">push</span>(<span class="string">&#39;3&#39;</span>);

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;abc123&quot;</span>, <span class="ident">s</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Afrom(%22abc%22)%3B%0A%0As.push('1')%3B%0As.push('2')%3B%0As.push('3')%3B%0A%0Aassert_eq!(%22abc123%22%2C%20s)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.as_bytes' class="method"><span id='as_bytes.v' class='invisible'><code>fn <a href='#method.as_bytes' class='fnname'>as_bytes</a>(&amp;self) -&gt; &amp;[u8]</code></span></h4>
<div class='docblock'><p>Returns a byte slice of this <code>String</code>&#39;s contents.</p>

<p>The inverse of this method is <a href="#method.from_utf8"><code>from_utf8</code></a>.</p>

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

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

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&amp;</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>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20String%3A%3Afrom(%22hello%22)%3B%0A%0Aassert_eq!(%26%5B104%2C%20101%2C%20108%2C%20108%2C%20111%5D%2C%20s.as_bytes())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.truncate' class="method"><span id='truncate.v' class='invisible'><code>fn <a href='#method.truncate' class='fnname'>truncate</a>(&amp;mut self, new_len: usize)</code></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&#39;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-17' class='section-header'><a href='#examples-17'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="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">&quot;hello&quot;</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">&quot;he&quot;</span>, <span class="ident">s</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Afrom(%22hello%22)%3B%0A%0As.truncate(2)%3B%0A%0Aassert_eq!(%22he%22%2C%20s)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.pop' class="method"><span id='pop.v' class='invisible'><code>fn <a href='#method.pop' class='fnname'>pop</a>(&amp;mut self) -&gt; <a class="enum" href="../../core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;char&gt;</code></span></h4>
<div class='docblock'><p>Removes the last character from the string buffer and returns it.</p>

<p>Returns <code>None</code> if this <code>String</code> is empty.</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">&quot;foo&quot;</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">&#39;o&#39;</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">&#39;o&#39;</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">&#39;f&#39;</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>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Afrom(%22foo%22)%3B%0A%0Aassert_eq!(s.pop()%2C%20Some('o'))%3B%0Aassert_eq!(s.pop()%2C%20Some('o'))%3B%0Aassert_eq!(s.pop()%2C%20Some('f'))%3B%0A%0Aassert_eq!(s.pop()%2C%20None)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.remove' class="method"><span id='remove.v' class='invisible'><code>fn <a href='#method.remove' class='fnname'>remove</a>(&amp;mut self, idx: usize) -&gt; char</code></span></h4>
<div class='docblock'><p>Removes a <code>char</code> 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>&#39;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-19' class='section-header'><a href='#examples-19'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="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">&quot;foo&quot;</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">&#39;f&#39;</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">&#39;o&#39;</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">&#39;o&#39;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Afrom(%22foo%22)%3B%0A%0Aassert_eq!(s.remove(0)%2C%20'f')%3B%0Aassert_eq!(s.remove(1)%2C%20'o')%3B%0Aassert_eq!(s.remove(0)%2C%20'o')%3B%0A%7D">Run</a></pre>
</div><h4 id='method.insert' class="method"><span id='insert.v' class='invisible'><code>fn <a href='#method.insert' class='fnname'>insert</a>(&amp;mut self, idx: usize, ch: char)</code></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>&#39;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-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">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">&#39;f&#39;</span>);
<span class="ident">s</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="string">&#39;o&#39;</span>);
<span class="ident">s</span>.<span class="ident">insert</span>(<span class="number">2</span>, <span class="string">&#39;o&#39;</span>);

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;foo&quot;</span>, <span class="ident">s</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Awith_capacity(3)%3B%0A%0As.insert(0%2C%20'f')%3B%0As.insert(1%2C%20'o')%3B%0As.insert(2%2C%20'o')%3B%0A%0Aassert_eq!(%22foo%22%2C%20s)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.insert_str' class="method"><span id='insert_str.v' class='invisible'><code>fn <a href='#method.insert_str' class='fnname'>insert_str</a>(&amp;mut self, idx: usize, string: &amp;str)</code><div class='since' title='Stable since Rust version 1.16.0'>1.16.0</div></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>&#39;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-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="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">&quot;bar&quot;</span>);

<span class="ident">s</span>.<span class="ident">insert_str</span>(<span class="number">0</span>, <span class="string">&quot;foo&quot;</span>);

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;foobar&quot;</span>, <span class="ident">s</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Afrom(%22bar%22)%3B%0A%0As.insert_str(0%2C%20%22foo%22)%3B%0A%0Aassert_eq!(%22foobar%22%2C%20s)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.as_mut_vec' class="method"><span id='as_mut_vec.v' class='invisible'><code>unsafe fn <a href='#method.as_mut_vec' class='fnname'>as_mut_vec</a>(&amp;mut self) -&gt; &amp;mut <a class="struct" href="../../collections/vec/struct.Vec.html" title="struct collections::vec::Vec">Vec</a>&lt;u8&gt;</code></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-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">&quot;hello&quot;</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">&amp;</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">&amp;</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">&quot;olleh&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Afrom(%22hello%22)%3B%0A%0Aunsafe%20%7B%0A%20%20%20%20let%20vec%20%3D%20s.as_mut_vec()%3B%0A%20%20%20%20assert_eq!(%26%5B104%2C%20101%2C%20108%2C%20108%2C%20111%5D%5B..%5D%2C%20%26vec%5B..%5D)%3B%0A%0A%20%20%20%20vec.reverse()%3B%0A%7D%0Aassert_eq!(s%2C%20%22olleh%22)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.len' class="method"><span id='len.v' class='invisible'><code>fn <a href='#method.len' class='fnname'>len</a>(&amp;self) -&gt; usize</code></span></h4>
<div class='docblock'><p>Returns the length of this <code>String</code>, in bytes.</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="ident">a</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">&quot;foo&quot;</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>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20a%20%3D%20String%3A%3Afrom(%22foo%22)%3B%0A%0Aassert_eq!(a.len()%2C%203)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.is_empty' class="method"><span id='is_empty.v' class='invisible'><code>fn <a href='#method.is_empty' class='fnname'>is_empty</a>(&amp;self) -&gt; bool</code></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-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">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">&#39;a&#39;</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>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20v%20%3D%20String%3A%3Anew()%3B%0Aassert!(v.is_empty())%3B%0A%0Av.push('a')%3B%0Aassert!(!v.is_empty())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.split_off' class="method"><span id='split_off.v' class='invisible'><code>fn <a href='#method.split_off' class='fnname'>split_off</a>(&amp;mut self, at: usize) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code><div class='since' title='Stable since Rust version 1.16.0'>1.16.0</div></span></h4>
<div class='docblock'><p>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-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">hello</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">&quot;Hello, World!&quot;</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">&quot;Hello, &quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">world</span>, <span class="string">&quot;World!&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20hello%20%3D%20String%3A%3Afrom(%22Hello%2C%20World!%22)%3B%0Alet%20world%20%3D%20hello.split_off(7)%3B%0Aassert_eq!(hello%2C%20%22Hello%2C%20%22)%3B%0Aassert_eq!(world%2C%20%22World!%22)%3B%0A%7D%0A">Run</a></pre>
</div><h4 id='method.clear' class="method"><span id='clear.v' class='invisible'><code>fn <a href='#method.clear' class='fnname'>clear</a>(&amp;mut self)</code></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-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">from</span>(<span class="string">&quot;foo&quot;</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>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Afrom(%22foo%22)%3B%0A%0As.clear()%3B%0A%0Aassert!(s.is_empty())%3B%0Aassert_eq!(0%2C%20s.len())%3B%0Aassert_eq!(3%2C%20s.capacity())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.drain' class="method"><span id='drain.v' class='invisible'><code>fn <a href='#method.drain' class='fnname'>drain</a>&lt;R&gt;(&amp;mut self, range: R) -&gt; <a class="struct" href="../../collections/string/struct.Drain.html" title="struct collections::string::Drain">Drain</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../../collections/range/trait.RangeArgument.html" title="trait collections::range::RangeArgument">RangeArgument</a>&lt;usize&gt;,&nbsp;</span></code><div class='since' title='Stable since Rust version 1.6.0'>1.6.0</div></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&#39;re out of bounds.</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">&quot;α is alpha, β is beta&quot;</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">&#39;β&#39;</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">&quot;α is alpha, &quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>, <span class="string">&quot;β is beta&quot;</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">&quot;&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Afrom(%22%CE%B1%20is%20alpha%2C%20%CE%B2%20is%20beta%22)%3B%0Alet%20beta_offset%20%3D%20s.find('%CE%B2').unwrap_or(s.len())%3B%0A%0A%2F%2F%20Remove%20the%20range%20up%20until%20the%20%CE%B2%20from%20the%20string%0Alet%20t%3A%20String%20%3D%20s.drain(..beta_offset).collect()%3B%0Aassert_eq!(t%2C%20%22%CE%B1%20is%20alpha%2C%20%22)%3B%0Aassert_eq!(s%2C%20%22%CE%B2%20is%20beta%22)%3B%0A%0A%2F%2F%20A%20full%20range%20clears%20the%20string%0As.drain(..)%3B%0Aassert_eq!(s%2C%20%22%22)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.splice' class="method"><span id='splice.v' class='invisible'><code>fn <a href='#method.splice' class='fnname'>splice</a>&lt;'a, 'b, R&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;range: R, <br>&nbsp;&nbsp;&nbsp;&nbsp;replace_with: &amp;'b str<br>) -&gt; <a class="struct" href="../../collections/string/struct.Splice.html" title="struct collections::string::Splice">Splice</a>&lt;'a, 'b&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../../collections/range/trait.RangeArgument.html" title="trait collections::range::RangeArgument">RangeArgument</a>&lt;usize&gt;,&nbsp;</span></code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>splice </code><a href="https://github.com/rust-lang/rust/issues/32310">#32310</a>)</summary><p>recently added</p>
</details></div></div><div class='docblock'><p>Creates a splicing iterator that removes the specified range in the string,
replaces with the given string, and yields the removed chars.
The given string doesn’t need to be the same length as the range.</p>

<p>Note: The element range is removed when the <code>Splice</code> is dropped,
even if the iterator is not consumed until the end.</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&#39;re out of bounds.</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="attribute">#<span class="op">!</span>[<span class="ident">feature</span>(<span class="ident">splice</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">&quot;α is alpha, β is beta&quot;</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">&#39;β&#39;</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="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">splice</span>(..<span class="ident">beta_offset</span>, <span class="string">&quot;Α is capital alpha; &quot;</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">t</span>, <span class="string">&quot;α is alpha, &quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>, <span class="string">&quot;Α is capital alpha; β is beta&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Bfeature(splice)%5D%0Afn%20main()%20%7B%0Alet%20mut%20s%20%3D%20String%3A%3Afrom(%22%CE%B1%20is%20alpha%2C%20%CE%B2%20is%20beta%22)%3B%0Alet%20beta_offset%20%3D%20s.find('%CE%B2').unwrap_or(s.len())%3B%0A%0A%2F%2F%20Replace%20the%20range%20up%20until%20the%20%CE%B2%20from%20the%20string%0Alet%20t%3A%20String%20%3D%20s.splice(..beta_offset%2C%20%22%CE%91%20is%20capital%20alpha%3B%20%22).collect()%3B%0Aassert_eq!(t%2C%20%22%CE%B1%20is%20alpha%2C%20%22)%3B%0Aassert_eq!(s%2C%20%22%CE%91%20is%20capital%20alpha%3B%20%CE%B2%20is%20beta%22)%3B%0A%7D&amp;version=nightly">Run</a></pre>
</div><h4 id='method.into_boxed_str' class="method"><span id='into_boxed_str.v' class='invisible'><code>fn <a href='#method.into_boxed_str' class='fnname'>into_boxed_str</a>(self) -&gt; <a class="struct" href="../../collections/boxed/struct.Box.html" title="struct collections::boxed::Box">Box</a>&lt;str&gt;</code><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div></span></h4>
<div class='docblock'><p>Converts this <code>String</code> into a <code>Box&lt;str&gt;</code>.</p>

<p>This will drop any excess capacity.</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">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">&quot;hello&quot;</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>();<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20s%20%3D%20String%3A%3Afrom(%22hello%22)%3B%0A%0Alet%20b%20%3D%20s.into_boxed_str()%3B%0A%7D">Run</a></pre>
</div></div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../collections/borrow/trait.Borrow.html" title="trait collections::borrow::Borrow">Borrow</a>&lt;str&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/str.rs.html#180-185' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.borrow' class="method"><span id='borrow.v' class='invisible'><code>fn <a href='../../collections/borrow/trait.Borrow.html#tymethod.borrow' class='fnname'>borrow</a>(&amp;self) -&gt; &amp;str</code></span></h4>
<div class='docblock'><p>Immutably borrows from an owned value. <a href="../../collections/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#262' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.partial_cmp' class="method"><span id='partial_cmp.v' class='invisible'><code>fn <a href='../../core/cmp/trait.PartialOrd.html#tymethod.partial_cmp' class='fnname'>partial_cmp</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>) -&gt; <a class="enum" href="../../core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="../../core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>&gt;</code></span></h4>
<div class='docblock'><p>This method returns an ordering between <code>self</code> and <code>other</code> values if one exists. <a href="../../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'><code>fn <a href='../../core/cmp/trait.PartialOrd.html#method.lt' class='fnname'>lt</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests less than (for <code>self</code> and <code>other</code>) and is used by the <code>&lt;</code> operator. <a href="../../core/cmp/trait.PartialOrd.html#method.lt">Read more</a></p>
</div><h4 id='method.le' class="method"><span id='le.v' class='invisible'><code>fn <a href='../../core/cmp/trait.PartialOrd.html#method.le' class='fnname'>le</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests less than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code>&lt;=</code> operator. <a href="../../core/cmp/trait.PartialOrd.html#method.le">Read more</a></p>
</div><h4 id='method.gt' class="method"><span id='gt.v' class='invisible'><code>fn <a href='../../core/cmp/trait.PartialOrd.html#method.gt' class='fnname'>gt</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests greater than (for <code>self</code> and <code>other</code>) and is used by the <code>&gt;</code> operator. <a href="../../core/cmp/trait.PartialOrd.html#method.gt">Read more</a></p>
</div><h4 id='method.ge' class="method"><span id='ge.v' class='invisible'><code>fn <a href='../../core/cmp/trait.PartialOrd.html#method.ge' class='fnname'>ge</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests greater than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code>&gt;=</code> operator. <a href="../../core/cmp/trait.PartialOrd.html#method.ge">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#262' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#262' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.cmp' class="method"><span id='cmp.v' class='invisible'><code>fn <a href='../../core/cmp/trait.Ord.html#tymethod.cmp' class='fnname'>cmp</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>) -&gt; <a class="enum" href="../../core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></code></span></h4>
<div class='docblock'><p>This method returns an <code>Ordering</code> between <code>self</code> and <code>other</code>. <a href="../../core/cmp/trait.Ord.html#tymethod.cmp">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1561-1569' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.clone' class="method"><span id='clone.v' class='invisible'><code>fn <a href='../../core/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&amp;self) -&gt; Self</code></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'><code>fn <a href='../../core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&amp;mut self, source: &amp;Self)</code></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 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/iter/traits/trait.FromIterator.html" title="trait core::iter::traits::FromIterator">FromIterator</a>&lt;char&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1572-1578' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.from_iter' class="method"><span id='from_iter.v' class='invisible'><code>fn <a href='../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a>&lt;I:&nbsp;<a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = char&gt;&gt;(iter: I) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></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 class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="../../core/iter/traits/trait.FromIterator.html" title="trait core::iter::traits::FromIterator">FromIterator</a>&lt;&amp;'a char&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><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/collections/string.rs.html#1581-1587' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.from_iter-1' class="method"><span id='from_iter.v-1' class='invisible'><code>fn <a href='../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a>&lt;I:&nbsp;<a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = &amp;'a char&gt;&gt;(iter: I) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></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 class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="../../core/iter/traits/trait.FromIterator.html" title="trait core::iter::traits::FromIterator">FromIterator</a>&lt;&amp;'a str&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1590-1596' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.from_iter-2' class="method"><span id='from_iter.v-2' class='invisible'><code>fn <a href='../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a>&lt;I:&nbsp;<a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = &amp;'a str&gt;&gt;(iter: I) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></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 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/iter/traits/trait.FromIterator.html" title="trait core::iter::traits::FromIterator">FromIterator</a>&lt;<a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><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/collections/string.rs.html#1599-1605' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.from_iter-3' class="method"><span id='from_iter.v-3' class='invisible'><code>fn <a href='../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a>&lt;I:&nbsp;<a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>&gt;&gt;(iter: I) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></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 class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="../../core/iter/traits/trait.FromIterator.html" title="trait core::iter::traits::FromIterator">FromIterator</a>&lt;<a class="enum" href="../../collections/borrow/enum.Cow.html" title="enum collections::borrow::Cow">Cow</a>&lt;'a, str&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><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/collections/string.rs.html#1608-1614' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.from_iter-4' class="method"><span id='from_iter.v-4' class='invisible'><code>fn <a href='../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a>&lt;I:&nbsp;<a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = <a class="enum" href="../../collections/borrow/enum.Cow.html" title="enum collections::borrow::Cow">Cow</a>&lt;'a, str&gt;&gt;&gt;(iter: I) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></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 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a>&lt;char&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1617-1626' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.extend' class="method"><span id='extend.v' class='invisible'><code>fn <a href='../../core/iter/traits/trait.Extend.html#tymethod.extend' class='fnname'>extend</a>&lt;I:&nbsp;<a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = char&gt;&gt;(&amp;mut self, iter: I)</code></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 class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a>&lt;&amp;'a char&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><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/collections/string.rs.html#1629-1633' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.extend-1' class="method"><span id='extend.v-1' class='invisible'><code>fn <a href='../../core/iter/traits/trait.Extend.html#tymethod.extend' class='fnname'>extend</a>&lt;I:&nbsp;<a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = &amp;'a char&gt;&gt;(&amp;mut self, iter: I)</code></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 class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a>&lt;&amp;'a str&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1636-1642' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.extend-2' class="method"><span id='extend.v-2' class='invisible'><code>fn <a href='../../core/iter/traits/trait.Extend.html#tymethod.extend' class='fnname'>extend</a>&lt;I:&nbsp;<a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = &amp;'a str&gt;&gt;(&amp;mut self, iter: I)</code></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 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a>&lt;<a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><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/collections/string.rs.html#1645-1651' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.extend-3' class="method"><span id='extend.v-3' class='invisible'><code>fn <a href='../../core/iter/traits/trait.Extend.html#tymethod.extend' class='fnname'>extend</a>&lt;I:&nbsp;<a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>&gt;&gt;(&amp;mut self, iter: I)</code></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 class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a>&lt;<a class="enum" href="../../collections/borrow/enum.Cow.html" title="enum collections::borrow::Cow">Cow</a>&lt;'a, str&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><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/collections/string.rs.html#1654-1660' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.extend-4' class="method"><span id='extend.v-4' class='invisible'><code>fn <a href='../../core/iter/traits/trait.Extend.html#tymethod.extend' class='fnname'>extend</a>&lt;I:&nbsp;<a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = <a class="enum" href="../../collections/borrow/enum.Cow.html" title="enum collections::borrow::Cow">Cow</a>&lt;'a, str&gt;&gt;&gt;(&amp;mut self, iter: I)</code></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 class='impl'><span class='in-band'><code>impl&lt;'a, 'b&gt; <a class="trait" href="../../collections/str/pattern/trait.Pattern.html" title="trait collections::str::pattern::Pattern">Pattern</a>&lt;'a&gt; for &amp;'b <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1666-1682' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>A convenience impl that delegates to the impl for <code>&amp;str</code></p>
</div><div class='impl-items'><h4 id='associatedtype.Searcher' class="type"><span id='Searcher.t' class='invisible'><code>type <a href='../../collections/str/pattern/trait.Pattern.html#associatedtype.Searcher' class="type">Searcher</a> = &lt;&amp;'b str as <a class="trait" href="../../collections/str/pattern/trait.Pattern.html" title="trait collections::str::pattern::Pattern">Pattern</a>&lt;'a&gt;&gt;::<a class="trait" href="../../collections/str/pattern/trait.Pattern.html" title="trait collections::str::pattern::Pattern">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'><code>fn <a href='../../collections/str/pattern/trait.Pattern.html#tymethod.into_searcher' class='fnname'>into_searcher</a>(self, haystack: &amp;'a str) -&gt; &lt;&amp;'b str as <a class="trait" href="../../collections/str/pattern/trait.Pattern.html" title="trait collections::str::pattern::Pattern">Pattern</a>&lt;'a&gt;&gt;::<a class="trait" href="../../collections/str/pattern/trait.Pattern.html" title="trait collections::str::pattern::Pattern">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>Constructs the associated searcher from <code>self</code> and the <code>haystack</code> to search in. <a href="../../collections/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'><code>fn <a href='../../collections/str/pattern/trait.Pattern.html#method.is_contained_in' class='fnname'>is_contained_in</a>(self, haystack: &amp;'a str) -&gt; bool</code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>pattern </code><a href="https://github.com/rust-lang/rust/issues/27721">#27721</a>)</summary><p>API not fully fleshed out and ready to be stabilized</p>
</details></div></div><div class='docblock'><p>Checks whether the pattern matches anywhere in the haystack</p>
</div><h4 id='method.is_prefix_of' class="method"><span id='is_prefix_of.v' class='invisible'><code>fn <a href='../../collections/str/pattern/trait.Pattern.html#method.is_prefix_of' class='fnname'>is_prefix_of</a>(self, haystack: &amp;'a str) -&gt; bool</code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>pattern </code><a href="https://github.com/rust-lang/rust/issues/27721">#27721</a>)</summary><p>API not fully fleshed out and ready to be stabilized</p>
</details></div></div><div class='docblock'><p>Checks whether the pattern matches at the front of the haystack</p>
</div><h4 id='method.is_suffix_of' class="method"><span id='is_suffix_of.v' class='invisible'><code>fn <a href='../../collections/str/pattern/trait.Pattern.html#method.is_suffix_of' class='fnname'>is_suffix_of</a>(self, haystack: &amp;'a str) -&gt; bool <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self::<a class="trait" href="../../collections/str/pattern/trait.Pattern.html" title="trait collections::str::pattern::Pattern">Searcher</a>: <a class="trait" href="../../collections/str/pattern/trait.ReverseSearcher.html" title="trait collections::str::pattern::ReverseSearcher">ReverseSearcher</a>&lt;'a&gt;,&nbsp;</span></code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>pattern </code><a href="https://github.com/rust-lang/rust/issues/27721">#27721</a>)</summary><p>API not fully fleshed out and ready to be stabilized</p>
</details></div></div><div class='docblock'><p>Checks whether the pattern matches at the back of the haystack</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1685-1694' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.eq' class="method"><span id='eq.v' class='invisible'><code>fn <a href='../../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, other: &amp;<a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../core/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div><h4 id='method.ne' class="method"><span id='ne.v' class='invisible'><code>fn <a href='../../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, other: &amp;<a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl&lt;'a, 'b&gt; <a class="trait" href="../../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a>&lt;str&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1699-1704' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.eq-1' class="method"><span id='eq.v-1' class='invisible'><code>fn <a href='../../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, other: &amp;str) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../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'><code>fn <a href='../../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, other: &amp;str) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl&lt;'a, 'b&gt; <a class="trait" href="../../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a>&lt;&amp;'a str&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1699-1704' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.eq-2' class="method"><span id='eq.v-2' class='invisible'><code>fn <a href='../../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, other: &amp;&amp;'a str) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../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'><code>fn <a href='../../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, other: &amp;&amp;'a str) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl&lt;'a, 'b&gt; <a class="trait" href="../../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a>&lt;<a class="enum" href="../../collections/borrow/enum.Cow.html" title="enum collections::borrow::Cow">Cow</a>&lt;'a, str&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1707-1712' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.eq-3' class="method"><span id='eq.v-3' class='invisible'><code>fn <a href='../../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, other: &amp;<a class="enum" href="../../collections/borrow/enum.Cow.html" title="enum collections::borrow::Cow">Cow</a>&lt;'a, str&gt;) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../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'><code>fn <a href='../../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, other: &amp;<a class="enum" href="../../collections/borrow/enum.Cow.html" title="enum collections::borrow::Cow">Cow</a>&lt;'a, str&gt;) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1724-1730' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.default' class="method"><span id='default.v' class='invisible'><code>fn <a href='../../core/default/trait.Default.html#tymethod.default' class='fnname'>default</a>() -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span></h4>
<div class='docblock'><p>Creates an empty <code>String</code>.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../collections/fmt/trait.Display.html" title="trait collections::fmt::Display">Display</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1733-1738' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='../../collections/fmt/trait.Display.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="../../collections/fmt/struct.Formatter.html" title="struct collections::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="../../collections/fmt/type.Result.html" title="type collections::fmt::Result">Result</a></code></span></h4>
<div class='docblock'><p>Formats the value using the given formatter. <a href="../../collections/fmt/trait.Display.html#tymethod.fmt">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../collections/fmt/trait.Debug.html" title="trait collections::fmt::Debug">Debug</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1741-1746' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.fmt-1' class="method"><span id='fmt.v-1' class='invisible'><code>fn <a href='../../collections/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="../../collections/fmt/struct.Formatter.html" title="struct collections::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="../../collections/fmt/type.Result.html" title="type collections::fmt::Result">Result</a></code></span></h4>
<div class='docblock'><p>Formats the value using the given formatter.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1749-1754' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.hash' class="method"><span id='hash.v' class='invisible'><code>fn <a href='../../core/hash/trait.Hash.html#tymethod.hash' class='fnname'>hash</a>&lt;H:&nbsp;<a class="trait" href="../../core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>&gt;(&amp;self, hasher: &amp;mut H)</code></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'><code>fn <a href='../../core/hash/trait.Hash.html#method.hash_slice' class='fnname'>hash_slice</a>&lt;H&gt;(data: &amp;[Self], state: &amp;mut H) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;H: <a class="trait" href="../../core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>,&nbsp;</span></code><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div></span></h4>
<div class='docblock'><p>Feeds a slice of this type into the given [<code>Hasher</code>]. <a href="../../core/hash/trait.Hash.html#method.hash_slice">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="../../core/ops/trait.Add.html" title="trait core::ops::Add">Add</a>&lt;&amp;'a str&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1794-1802' title='goto source code'>[src]</a></span></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-30' class='section-header'><a href='#examples-30'>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">&quot;hello&quot;</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">&quot; world&quot;</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">&amp;</span><span class="ident">b</span>;
<span class="comment">// `a` is moved and can no longer be used here.</span><a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20a%20%3D%20String%3A%3Afrom(%22hello%22)%3B%0Alet%20b%20%3D%20String%3A%3Afrom(%22%20world%22)%3B%0Alet%20c%20%3D%20a%20%2B%20%26b%3B%0A%2F%2F%20%60a%60%20is%20moved%20and%20can%20no%20longer%20be%20used%20here.%0A%7D">Run</a></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">&quot;hello&quot;</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">&quot; world&quot;</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">&amp;</span><span class="ident">b</span>;
<span class="comment">// `a` is still valid here.</span><a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20a%20%3D%20String%3A%3Afrom(%22hello%22)%3B%0Alet%20b%20%3D%20String%3A%3Afrom(%22%20world%22)%3B%0Alet%20c%20%3D%20a.clone()%20%2B%20%26b%3B%0A%2F%2F%20%60a%60%20is%20still%20valid%20here.%0A%7D">Run</a></pre>

<p>Concatenating <code>&amp;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">&quot;hello&quot;</span>;
<span class="kw">let</span> <span class="ident">b</span> <span class="op">=</span> <span class="string">&quot; world&quot;</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>;<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Alet%20a%20%3D%20%22hello%22%3B%0Alet%20b%20%3D%20%22%20world%22%3B%0Alet%20c%20%3D%20a.to_string()%20%2B%20b%3B%0A%7D">Run</a></pre>
</div><div class='impl-items'><h4 id='associatedtype.Output' class="type"><span id='Output.t' class='invisible'><code>type <a href='../../core/ops/trait.Add.html#associatedtype.Output' class="type">Output</a> = <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::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'><code>fn <a href='../../core/ops/trait.Add.html#tymethod.add' class='fnname'>add</a>(self, other: &amp;str) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span></h4>
<div class='docblock'><p>The method for the <code>+</code> operator</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="../../core/ops/trait.AddAssign.html" title="trait core::ops::AddAssign">AddAssign</a>&lt;&amp;'a str&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><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/collections/string.rs.html#1810-1815' title='goto source code'>[src]</a></span></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'><code>fn <a href='../../core/ops/trait.AddAssign.html#tymethod.add_assign' class='fnname'>add_assign</a>(&amp;mut self, other: &amp;str)</code></span></h4>
<div class='docblock'><p>The method for the <code>+=</code> operator</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.Index.html" title="trait core::ops::Index">Index</a>&lt;<a class="struct" href="../../core/ops/struct.Range.html" title="struct core::ops::Range">Range</a>&lt;usize&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1818-1825' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='associatedtype.Output-1' class="type"><span id='Output.t-1' class='invisible'><code>type <a href='../../core/ops/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'><code>fn <a href='../../core/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&amp;self, index: <a class="struct" href="../../core/ops/struct.Range.html" title="struct core::ops::Range">Range</a>&lt;usize&gt;) -&gt; &amp;str</code></span></h4>
<div class='docblock'><p>The method for the indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.Index.html" title="trait core::ops::Index">Index</a>&lt;<a class="struct" href="../../core/ops/struct.RangeTo.html" title="struct core::ops::RangeTo">RangeTo</a>&lt;usize&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1827-1834' title='goto source code'>[src]</a></span></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/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'><code>fn <a href='../../core/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&amp;self, index: <a class="struct" href="../../core/ops/struct.RangeTo.html" title="struct core::ops::RangeTo">RangeTo</a>&lt;usize&gt;) -&gt; &amp;str</code></span></h4>
<div class='docblock'><p>The method for the indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.Index.html" title="trait core::ops::Index">Index</a>&lt;<a class="struct" href="../../core/ops/struct.RangeFrom.html" title="struct core::ops::RangeFrom">RangeFrom</a>&lt;usize&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1836-1843' title='goto source code'>[src]</a></span></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/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'><code>fn <a href='../../core/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&amp;self, index: <a class="struct" href="../../core/ops/struct.RangeFrom.html" title="struct core::ops::RangeFrom">RangeFrom</a>&lt;usize&gt;) -&gt; &amp;str</code></span></h4>
<div class='docblock'><p>The method for the indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.Index.html" title="trait core::ops::Index">Index</a>&lt;<a class="struct" href="../../core/ops/struct.RangeFull.html" title="struct core::ops::RangeFull">RangeFull</a>&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1845-1852' title='goto source code'>[src]</a></span></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/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'><code>fn <a href='../../core/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&amp;self, _index: <a class="struct" href="../../core/ops/struct.RangeFull.html" title="struct core::ops::RangeFull">RangeFull</a>) -&gt; &amp;str</code></span></h4>
<div class='docblock'><p>The method for the indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.Index.html" title="trait core::ops::Index">Index</a>&lt;<a class="struct" href="../../core/ops/struct.RangeInclusive.html" title="struct core::ops::RangeInclusive">RangeInclusive</a>&lt;usize&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1854-1861' title='goto source code'>[src]</a></span></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/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'><code>fn <a href='../../core/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&amp;self, index: <a class="struct" href="../../core/ops/struct.RangeInclusive.html" title="struct core::ops::RangeInclusive">RangeInclusive</a>&lt;usize&gt;) -&gt; &amp;str</code></span></h4>
<div class='docblock'><p>The method for the indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.Index.html" title="trait core::ops::Index">Index</a>&lt;<a class="struct" href="../../core/ops/struct.RangeToInclusive.html" title="struct core::ops::RangeToInclusive">RangeToInclusive</a>&lt;usize&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1863-1870' title='goto source code'>[src]</a></span></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/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'><code>fn <a href='../../core/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&amp;self, index: <a class="struct" href="../../core/ops/struct.RangeToInclusive.html" title="struct core::ops::RangeToInclusive">RangeToInclusive</a>&lt;usize&gt;) -&gt; &amp;str</code></span></h4>
<div class='docblock'><p>The method for the indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.IndexMut.html" title="trait core::ops::IndexMut">IndexMut</a>&lt;<a class="struct" href="../../core/ops/struct.Range.html" title="struct core::ops::Range">Range</a>&lt;usize&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../../src/collections/string.rs.html#1873-1878' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.index_mut' class="method"><span id='index_mut.v' class='invisible'><code>fn <a href='../../core/ops/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&amp;mut self, index: <a class="struct" href="../../core/ops/struct.Range.html" title="struct core::ops::Range">Range</a>&lt;usize&gt;) -&gt; &amp;mut str</code></span></h4>
<div class='docblock'><p>The method for the mutable indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.IndexMut.html" title="trait core::ops::IndexMut">IndexMut</a>&lt;<a class="struct" href="../../core/ops/struct.RangeTo.html" title="struct core::ops::RangeTo">RangeTo</a>&lt;usize&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../../src/collections/string.rs.html#1880-1885' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.index_mut-1' class="method"><span id='index_mut.v-1' class='invisible'><code>fn <a href='../../core/ops/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&amp;mut self, index: <a class="struct" href="../../core/ops/struct.RangeTo.html" title="struct core::ops::RangeTo">RangeTo</a>&lt;usize&gt;) -&gt; &amp;mut str</code></span></h4>
<div class='docblock'><p>The method for the mutable indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.IndexMut.html" title="trait core::ops::IndexMut">IndexMut</a>&lt;<a class="struct" href="../../core/ops/struct.RangeFrom.html" title="struct core::ops::RangeFrom">RangeFrom</a>&lt;usize&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../../src/collections/string.rs.html#1887-1892' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.index_mut-2' class="method"><span id='index_mut.v-2' class='invisible'><code>fn <a href='../../core/ops/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&amp;mut self, index: <a class="struct" href="../../core/ops/struct.RangeFrom.html" title="struct core::ops::RangeFrom">RangeFrom</a>&lt;usize&gt;) -&gt; &amp;mut str</code></span></h4>
<div class='docblock'><p>The method for the mutable indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.IndexMut.html" title="trait core::ops::IndexMut">IndexMut</a>&lt;<a class="struct" href="../../core/ops/struct.RangeFull.html" title="struct core::ops::RangeFull">RangeFull</a>&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../../src/collections/string.rs.html#1894-1899' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.index_mut-3' class="method"><span id='index_mut.v-3' class='invisible'><code>fn <a href='../../core/ops/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&amp;mut self, _index: <a class="struct" href="../../core/ops/struct.RangeFull.html" title="struct core::ops::RangeFull">RangeFull</a>) -&gt; &amp;mut str</code></span></h4>
<div class='docblock'><p>The method for the mutable indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.IndexMut.html" title="trait core::ops::IndexMut">IndexMut</a>&lt;<a class="struct" href="../../core/ops/struct.RangeInclusive.html" title="struct core::ops::RangeInclusive">RangeInclusive</a>&lt;usize&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1901-1906' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.index_mut-4' class="method"><span id='index_mut.v-4' class='invisible'><code>fn <a href='../../core/ops/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&amp;mut self, index: <a class="struct" href="../../core/ops/struct.RangeInclusive.html" title="struct core::ops::RangeInclusive">RangeInclusive</a>&lt;usize&gt;) -&gt; &amp;mut str</code></span></h4>
<div class='docblock'><p>The method for the mutable indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.IndexMut.html" title="trait core::ops::IndexMut">IndexMut</a>&lt;<a class="struct" href="../../core/ops/struct.RangeToInclusive.html" title="struct core::ops::RangeToInclusive">RangeToInclusive</a>&lt;usize&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1908-1913' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.index_mut-5' class="method"><span id='index_mut.v-5' class='invisible'><code>fn <a href='../../core/ops/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&amp;mut self, index: <a class="struct" href="../../core/ops/struct.RangeToInclusive.html" title="struct core::ops::RangeToInclusive">RangeToInclusive</a>&lt;usize&gt;) -&gt; &amp;mut str</code></span></h4>
<div class='docblock'><p>The method for the mutable indexing (<code>container[index]</code>) operation</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.Deref.html" title="trait core::ops::Deref">Deref</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1916-1923' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='associatedtype.Target' class="type"><span id='Target.t' class='invisible'><code>type <a href='../../core/ops/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'><code>fn <a href='../../core/ops/trait.Deref.html#tymethod.deref' class='fnname'>deref</a>(&amp;self) -&gt; &amp;str</code></span></h4>
<div class='docblock'><p>The method called to dereference a value</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/ops/trait.DerefMut.html" title="trait core::ops::DerefMut">DerefMut</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../../src/collections/string.rs.html#1926-1931' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.deref_mut' class="method"><span id='deref_mut.v' class='invisible'><code>fn <a href='../../core/ops/trait.DerefMut.html#tymethod.deref_mut' class='fnname'>deref_mut</a>(&amp;mut self) -&gt; &amp;mut str</code></span></h4>
<div class='docblock'><p>The method called to mutably dereference a value</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../collections/str/trait.FromStr.html" title="trait collections::str::FromStr">FromStr</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#1950-1956' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='associatedtype.Err' class="type"><span id='Err.t' class='invisible'><code>type <a href='../../collections/str/trait.FromStr.html#associatedtype.Err' class="type">Err</a> = <a class="enum" href="../../collections/string/enum.ParseError.html" title="enum collections::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'><code>fn <a href='../../collections/str/trait.FromStr.html#tymethod.from_str' class='fnname'>from_str</a>(s: &amp;str) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a>, <a class="enum" href="../../collections/string/enum.ParseError.html" title="enum collections::string::ParseError">ParseError</a>&gt;</code></span></h4>
<div class='docblock'><p>Parses a string <code>s</code> to return a value of this type. <a href="../../collections/str/trait.FromStr.html#tymethod.from_str">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../collections/string/trait.ToString.html" title="trait collections::string::ToString">ToString</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><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/collections/string.rs.html#2051-2056' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.to_string' class="method"><span id='to_string.v' class='invisible'><code>fn <a href='../../collections/string/trait.ToString.html#tymethod.to_string' class='fnname'>to_string</a>(&amp;self) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span></h4>
<div class='docblock'><p>Converts the given value to a <code>String</code>. <a href="../../collections/string/trait.ToString.html#tymethod.to_string">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;str&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#2059-2064' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.as_ref' class="method"><span id='as_ref.v' class='invisible'><code>fn <a href='../../core/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&amp;self) -&gt; &amp;str</code></span></h4>
<div class='docblock'><p>Performs the conversion.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;[u8]&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#2067-2072' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.as_ref-1' class="method"><span id='as_ref.v-1' class='invisible'><code>fn <a href='../../core/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&amp;self) -&gt; &amp;[u8]</code></span></h4>
<div class='docblock'><p>Performs the conversion.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;&amp;'a str&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#2075-2079' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.from' class="method"><span id='from.v' class='invisible'><code>fn <a href='../../core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: &amp;'a str) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span></h4>
<div class='docblock'><p>Performs the conversion.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;<a class="struct" href="../../collections/boxed/struct.Box.html" title="struct collections::boxed::Box">Box</a>&lt;str&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><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/collections/string.rs.html#2084-2088' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.from-1' class="method"><span id='from.v-1' class='invisible'><code>fn <a href='../../core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: <a class="struct" href="../../collections/boxed/struct.Box.html" title="struct collections::boxed::Box">Box</a>&lt;str&gt;) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span></h4>
<div class='docblock'><p>Performs the conversion.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="../../collections/boxed/struct.Box.html" title="struct collections::boxed::Box">Box</a>&lt;str&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><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/collections/string.rs.html#2091-2095' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.into' class="method"><span id='into.v' class='invisible'><code>fn <a href='../../core/convert/trait.Into.html#tymethod.into' class='fnname'>into</a>(self) -&gt; <a class="struct" href="../../collections/boxed/struct.Box.html" title="struct collections::boxed::Box">Box</a>&lt;str&gt;</code></span></h4>
<div class='docblock'><p>Performs the conversion.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;<a class="enum" href="../../collections/borrow/enum.Cow.html" title="enum collections::borrow::Cow">Cow</a>&lt;'a, str&gt;&gt; for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><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/collections/string.rs.html#2098-2102' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.from-2' class="method"><span id='from.v-2' class='invisible'><code>fn <a href='../../core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: <a class="enum" href="../../collections/borrow/enum.Cow.html" title="enum collections::borrow::Cow">Cow</a>&lt;'a, str&gt;) -&gt; <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span></h4>
<div class='docblock'><p>Performs the conversion.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../collections/fmt/trait.Write.html" title="trait collections::fmt::Write">Write</a> for <a class="struct" href="../../collections/string/struct.String.html" title="struct collections::string::String">String</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/collections/string.rs.html#2149-2161' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.write_str' class="method"><span id='write_str.v' class='invisible'><code>fn <a href='../../collections/fmt/trait.Write.html#tymethod.write_str' class='fnname'>write_str</a>(&amp;mut self, s: &amp;str) -&gt; <a class="type" href="../../collections/fmt/type.Result.html" title="type collections::fmt::Result">Result</a></code></span></h4>
<div class='docblock'><p>Writes a slice of bytes into this writer, returning whether the write succeeded. <a href="../../collections/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'><code>fn <a href='../../collections/fmt/trait.Write.html#method.write_char' class='fnname'>write_char</a>(&amp;mut self, c: char) -&gt; <a class="type" href="../../collections/fmt/type.Result.html" title="type collections::fmt::Result">Result</a></code></span></h4>
<div class='docblock'><p>Writes a [<code>char</code>] into this writer, returning whether the write succeeded. <a href="../../collections/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'><code>fn <a href='../../collections/fmt/trait.Write.html#method.write_fmt' class='fnname'>write_fmt</a>(&amp;mut self, args: <a class="struct" href="../../collections/fmt/struct.Arguments.html" title="struct collections::fmt::Arguments">Arguments</a>) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(), <a class="struct" href="../../collections/fmt/struct.Error.html" title="struct collections::fmt::Error">Error</a>&gt;</code></span></h4>
<div class='docblock'><p>Glue for usage of the [<code>write!</code>] macro with implementors of this trait. <a href="../../collections/fmt/trait.Write.html#method.write_fmt">Read more</a></p>
</div></div></section>
    <section id='search' class="content hidden"></section>

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

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

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

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

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

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

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

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

    

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