实际上……它并不总是静态分配的。请注意具体措辞:
let string = "Hello there.";
let vec = vec!(1i, 2, 3); // create a dynamically allocated array of 3 `int`
let slice = vec.as_slice(); // create a slice into this array,
// the lifetime of which cannot (obviously)
// exceed that of the array.
vec
的生命周期为 'a
,那么 slice
的类型为 &'a [int]
,可以在类型签名中看到:fn as_slice(&'a self) -> &'a [T]
(from the std::vec::Vec
page)