rebuild pages at 2bb8546

This commit is contained in:
Steve Klabnik
2016-03-09 21:47:09 +00:00
parent 2199035183
commit 08a4da055c
2 changed files with 18 additions and 10 deletions
+9 -5
View File
@@ -2588,7 +2588,7 @@ around which need to be kept in sync.</p>
<pre><code class="language-rust">let s = String::from(&quot;hello world&quot;);
let hello = &amp;s[0..5];
let world = &amp;s[5..9];
let world = &amp;s[6..11];
</code></pre>
<p>This looks just like taking a reference to the whole <code>String</code>, but with the
extra <code>[0..5]</code> bit. Instead of being a reference to the entire <code>String</code>,
@@ -2596,6 +2596,10 @@ it’s a reference to an internal position in the <code>String</code>, but it al
track of the number of elements that it refers to as well. In other words,
it looks like this:</p>
<p>DIAGRAM GOES HERE of s, hello, and world</p>
<p>Note that the internal position is specified through byte-offsets, not
characters. The offset to the first byte of a <code>String</code> is 0 and the
trailing number should point to the first byte that is <em>not</em> included
in the slice.</p>
<p>With Rust’s <code>..</code> syntax, if you want to start at zero, you can drop the zero.
In other words, these are equal:</p>
<pre><code class="language-rust">let s = String::from(&quot;hello&quot;);
@@ -2603,15 +2607,15 @@ In other words, these are equal:</p>
let slice = &amp;s[0..2];
let slice = &amp;s[..2];
</code></pre>
<p>By the same token, if you want to go to the maximum value, which for slices is
the last element, you can drop the trailing number. In other words, these are
<p>By the same token, if your slice should include the last byte of the
<code>String</code>, you can drop the trailing number. In other words, these are
equal:</p>
<pre><code class="language-rust">let s = String::from(&quot;hello&quot;);
let len = s.len();
let slice = &amp;s[1..len];
let slice = &amp;s[1..];
let slice = &amp;s[0..len];
let slice = &amp;s[0..];
</code></pre>
<p>With this in mind, let’s re-write <code>first_word()</code> to return a slice:</p>
<pre><code class="language-rust">fn first_word(s: &amp;String) -&gt; &amp;str {
+9 -5
View File
@@ -166,7 +166,7 @@ around which need to be kept in sync.</p>
<pre><code class="language-rust">let s = String::from(&quot;hello world&quot;);
let hello = &amp;s[0..5];
let world = &amp;s[5..9];
let world = &amp;s[6..11];
</code></pre>
<p>This looks just like taking a reference to the whole <code>String</code>, but with the
extra <code>[0..5]</code> bit. Instead of being a reference to the entire <code>String</code>,
@@ -174,6 +174,10 @@ it’s a reference to an internal position in the <code>String</code>, but it al
track of the number of elements that it refers to as well. In other words,
it looks like this:</p>
<p>DIAGRAM GOES HERE of s, hello, and world</p>
<p>Note that the internal position is specified through byte-offsets, not
characters. The offset to the first byte of a <code>String</code> is 0 and the
trailing number should point to the first byte that is <em>not</em> included
in the slice.</p>
<p>With Rust’s <code>..</code> syntax, if you want to start at zero, you can drop the zero.
In other words, these are equal:</p>
<pre><code class="language-rust">let s = String::from(&quot;hello&quot;);
@@ -181,15 +185,15 @@ In other words, these are equal:</p>
let slice = &amp;s[0..2];
let slice = &amp;s[..2];
</code></pre>
<p>By the same token, if you want to go to the maximum value, which for slices is
the last element, you can drop the trailing number. In other words, these are
<p>By the same token, if your slice should include the last byte of the
<code>String</code>, you can drop the trailing number. In other words, these are
equal:</p>
<pre><code class="language-rust">let s = String::from(&quot;hello&quot;);
let len = s.len();
let slice = &amp;s[1..len];
let slice = &amp;s[1..];
let slice = &amp;s[0..len];
let slice = &amp;s[0..];
</code></pre>
<p>With this in mind, let’s re-write <code>first_word()</code> to return a slice:</p>
<pre><code class="language-rust">fn first_word(s: &amp;String) -&gt; &amp;str {