2016-03-15 06:50:53 -05:00
|
|
|
fn empty_array() -> [u16; 0] {
|
|
|
|
[]
|
|
|
|
}
|
|
|
|
|
2016-04-22 07:38:46 -05:00
|
|
|
fn mini_array() -> [u16; 1] {
|
|
|
|
[42]
|
|
|
|
}
|
|
|
|
|
2016-03-15 06:50:53 -05:00
|
|
|
fn big_array() -> [u16; 5] {
|
|
|
|
[5, 4, 3, 2, 1]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn array_array() -> [[u8; 2]; 3] {
|
|
|
|
[[5, 4], [3, 2], [1, 0]]
|
|
|
|
}
|
2016-03-17 00:28:49 -05:00
|
|
|
|
2016-03-20 22:30:31 -05:00
|
|
|
fn index_unsafe() -> i32 {
|
2016-03-17 00:28:49 -05:00
|
|
|
let a = [0, 10, 20, 30];
|
|
|
|
unsafe { *a.get_unchecked(2) }
|
|
|
|
}
|
2016-03-20 22:30:31 -05:00
|
|
|
|
|
|
|
fn index() -> i32 {
|
|
|
|
let a = [0, 10, 20, 30];
|
|
|
|
a[2]
|
|
|
|
}
|
2016-03-21 03:37:31 -05:00
|
|
|
|
2016-03-21 04:34:24 -05:00
|
|
|
fn array_repeat() -> [u8; 8] {
|
|
|
|
[42; 8]
|
2016-03-21 03:39:41 -05:00
|
|
|
}
|
2016-04-22 03:34:14 -05:00
|
|
|
|
2016-04-23 01:26:10 -05:00
|
|
|
fn slice_index() -> u8 {
|
|
|
|
let arr: &[_] = &[101, 102, 103, 104, 105, 106];
|
|
|
|
arr[5]
|
|
|
|
}
|
|
|
|
|
2016-04-22 07:38:46 -05:00
|
|
|
fn main() {
|
2016-05-09 22:53:20 -05:00
|
|
|
assert_eq!(empty_array(), []);
|
2016-04-22 07:38:46 -05:00
|
|
|
assert_eq!(index_unsafe(), 20);
|
|
|
|
assert_eq!(index(), 20);
|
2016-04-23 01:26:10 -05:00
|
|
|
assert_eq!(slice_index(), 106);
|
2016-04-22 07:38:46 -05:00
|
|
|
assert_eq!(big_array(), [5, 4, 3, 2, 1]);
|
|
|
|
assert_eq!(array_array(), [[5, 4], [3, 2], [1, 0]]);
|
|
|
|
assert_eq!(array_repeat(), [42; 8]);
|
2016-06-13 07:27:05 -05:00
|
|
|
assert_eq!(mini_array(), [42]);
|
2016-04-22 07:38:46 -05:00
|
|
|
}
|