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