primitive_types4.rs (592B)
1 fn main() { 2 // You can optionally experiment here. 3 } 4 5 #[cfg(test)] 6 mod tests { 7 #[test] 8 fn slice_out_of_array() { 9 let a = [1, 2, 3, 4, 5]; 10 // 0 1 2 3 4 <- indices 11 // ------- 12 // | 13 // +--- slice 14 15 // Note that the upper index 4 is excluded. 16 let nice_slice = &a[1..4]; 17 assert_eq!([2, 3, 4], nice_slice); 18 19 // The upper index can be included by using the syntax `..=` (with `=` sign) 20 let nice_slice = &a[1..=3]; 21 assert_eq!([2, 3, 4], nice_slice); 22 } 23 }