← 返回起始笔记位置

知识卡片

普通读书笔记卡 · 6074.f.1

切片借用连续区间

理解等级:中级

&[T]借用连续元素的一段,概念上包含数据位置与长度,既可指向数组也可指向Vec内容。它不拥有集合,不能靠切片让已释放数据继续有效。数组长度属于类型,Vec长度可变;借用存在期间也不能任意扩容或修改而使引用失效。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 1. Types Slices · 查看原书依据

      Slices The first fat pointer type is the slice: a reference to a subset of some contiguous collection of values. It’s built from a (non-owning) simple pointer, together with a length field, making it twice the size of a simple pointer (16 bytes on a 64-bit platform). The type of a slice is written as &[T]—a reference to [T], which is the notional type for a

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《Slices》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u043-ch01-057)。 - 结论依据:原文在“Slices”附近的定义、例子或代码支撑本卡核心说明:&[T]借用连续元素的一段,概念上包含数据位置与长度,既可指向数组也可指向Vec内容。边界按已读前提解释;示例未执行。 - 原始内容:Slices The first fat pointer type is the slice: a reference to a subset of some contiguous collection of values. It’s built from a (non-owning) simple pointer, together with a length field, making it twice the size of a simple pointer (16 bytes on a 64-bit platform). The type of a slice is written as &[T]—a reference to [T], which is the notional type for a