Skip to content

Commit e9f93cf

Browse files
authored
Merge pull request #1538 from balroggg/fix_slices
Add empty slice example
2 parents 7129ee4 + 374f375 commit e9f93cf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/primitives/array.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ fn main() {
4848
println!("borrow a section of the array as a slice");
4949
analyze_slice(&ys[1 .. 4]);
5050
51+
// Example of empty slice `&[]`
52+
let empty_array: [u32; 0] = [];
53+
assert_eq!(&empty_array, &[]);
54+
assert_eq!(&empty_array, &[][..]); // same but more verbose
55+
5156
// Out of bound indexing causes compile error
52-
println!("{}", xs[5]);
57+
//println!("{}", xs[5]);
5358
}
5459
```

0 commit comments

Comments
 (0)