知识卡片
连续序列的索引边界
数组 [T; N]、向量 Vec<T> 和借用切片 &[T] 都由一连串相同类型的元素组成,因而共享 len() 和 v[i]。索引类型是 usize,有效下标满足 0 <= i < v.len()。越界会 panic,包括试取空序列的第 0 项。存储的所有者和能否增长可据三类类型区分。
关联阅读:[[用切片统一借用连续数据]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Fundamental Types 连续序列的存储与索引约定 · 查看原书依据
checks that i always falls within this range; if it doesn’t, the expression panics. The length of v may be zero, in which case
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第02章《Fundamental Types》|连续序列的存储与索引约定,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch02.xhtml#arrays-vectors-and-slices`
- 结论依据:原文统一说明连续序列的元素计数、整数索引类型和越界行为,并比较三种序列的所有权与长度。
- 原始内容:checks that i always falls within this range; if it doesn’t, the expression panics. The length of v may be zero, in which case