File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -162,13 +162,18 @@ A ‘slice’ is a reference to (or “view” into) another data structure. The
162162useful for allowing safe, efficient access to a portion of an array without
163163copying. For example, you might want to reference just one line of a file read
164164into memory. By nature, a slice is not created directly, but from an existing
165- variable. Slices have a length, can be mutable or not, and in many ways behave
166- like arrays:
165+ variable binding. Slices have a defined length, can be mutable or immutable.
166+
167+ ## Slicing syntax
168+
169+ You can use a combo of ` & ` and ` [] ` to create a slice from various things. The
170+ ` & ` indicates that slices are similar to references, and the ` [] ` s, with a
171+ range, let you define the length of the slice:
167172
168173``` rust
169174let a = [0 , 1 , 2 , 3 , 4 ];
170- let middle = & a [1 .. 4 ]; // A slice of a: just the elements 1, 2, and 3
171175let complete = & a [.. ]; // A slice containing all of the elements in a
176+ let middle = & a [1 .. 4 ]; // A slice of a: just the elements 1, 2, and 3
172177```
173178
174179Slices have type ` &[T] ` . We’ll talk about that ` T ` when we cover
You can’t perform that action at this time.
0 commit comments