]> git.lizzy.rs Git - rust.git/commitdiff
Call out slicing syntax more explicitly
authorSteve Klabnik <steve@steveklabnik.com>
Wed, 30 Sep 2015 17:21:02 +0000 (13:21 -0400)
committerSteve Klabnik <steve@steveklabnik.com>
Wed, 30 Sep 2015 17:21:04 +0000 (13:21 -0400)
Fixes #28359

src/doc/trpl/primitive-types.md

index 027909dd058769c70031e0d32a8424a803c5e58b..a8c7a7d41573e4fa565a264cf829bc451f2e1b20 100644 (file)
@@ -162,13 +162,18 @@ A ‘slice’ is a reference to (or “view” into) another data structure. The
 useful for allowing safe, efficient access to a portion of an array without
 copying. For example, you might want to reference just one line of a file read
 into memory. By nature, a slice is not created directly, but from an existing
-variable. Slices have a length, can be mutable or not, and in many ways behave
-like arrays:
+variable binding. Slices have a defined length, can be mutable or immutable.
+
+## Slicing syntax
+
+You can use a combo of `&` and `[]` to create a slice from various things. The
+`&` indicates that slices are similar to references, and the `[]`s, with a
+range, let you define the length of the slice:
 
 ```rust
 let a = [0, 1, 2, 3, 4];
-let middle = &a[1..4]; // A slice of a: just the elements 1, 2, and 3
 let complete = &a[..]; // A slice containing all of the elements in a
+let middle = &a[1..4]; // A slice of a: just the elements 1, 2, and 3
 ```
 
 Slices have type `&[T]`. We’ll talk about that `T` when we cover