We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents feb8f91 + d9e8d93 commit 1095df2Copy full SHA for 1095df2
src/primitives/array.md
@@ -53,6 +53,17 @@ fn main() {
53
assert_eq!(&empty_array, &[]);
54
assert_eq!(&empty_array, &[][..]); // same but more verbose
55
56
+ // Arrays can be safely accessed using `.get`, which returns an
57
+ // `Option`. This can be matched as shown below, or used with
58
+ // `.expect()` if you would like the program to exit with a nice
59
+ // message instead of happily continue.
60
+ for i in 0..xs.len() + 1 { // OOPS, one element too far
61
+ match xs.get(i) {
62
+ Some(xval) => println!("{}: {}", i, xval),
63
+ None => println!("Slow down! {} is too far!", i),
64
+ }
65
66
+
67
// Out of bound indexing causes compile error
68
//println!("{}", xs[5]);
69
}
0 commit comments