切片允许你引用集合中一段连续的元素序列。
fn main() { let s = String::from("hello world"); let hello = &s[0..5]; let world = &s[6..11]; println!("{} {}", hello, world); }
fn main() { let a = [1, 2, 3, 4, 5]; let slice = &a[1..3]; println!("{:?}", slice); }
继续学习:下一章 - Rust 结构体