Vec.get example in the documentation


Could someone please explain why is there […] in the last line of the following example involving getting the slice of a vector by range?

let v = [10, 40, 30];
assert_eq!(Some(&40), v.get(1));
assert_eq!(Some(&[10, 40][…]), v.get(0…2));


[10, 40] has the type [i32; 2], but Option<[i32; 2]> isn’t comparable to Option<&[i32]>. The &v[..] explicitly turns the [i32; 2] into a &[i32].


so v.get(a…b) returns Option(&[T]), where T is the type of Vec(T) ?
If so, fine, thank you. I had trouble digging that information out of too many layers of abstractions, even in the examples.


Yep, similarly to how indexing behaves.