Slices in Rust allow us to reference contiguous sequences of elements in collections, offering more granular control over data manipulation. We explored how to create slices using array and string literals, understanding the range syntax and its exclusivity.
Rust中的切片允许我们引用集合中连续的元素序列,从而对数据操作提供更细粒度的控制。我们探讨了如何使用数组和字符串字面量创建切片,了解范围语法及其排他性。
Introduction 介绍
In rust, Slices allow you to refer to a contiguous sequence of elements in a collection of items, rather than the whole collection.
在rust中,Slices允许你引用一个项目集合中的一个连续的元素序列,而不是整个集合。
let numbers = [1, 2, 3, 4, 5];
let slice = &numbers[1..4]; // [2, 3, 4]
[1..4]
starts at index 1 and ends at 3. 4 is exclusive.[1..4]
开始于索引1,结束于索引3。四是排他性。