知识卡片

普通读书笔记卡 · 6074.f.1.c · 生成模型:未记录

切片让范围依附原数据

理解等级:中级

&[T] 和 &str 是借用的连续区间。裸下标只是数字,源内容更新后可能已经失效。返回借用切片可让编译器限制结果仍在使用时对源的独占修改。字符串的范围端点还必须在合法 UTF-8 边界。

相关卡片 [[可变借用要求独占]]

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第04章 理解所有权(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c04.xhtml`,块 0231) - 结论依据:原文把返回值解释为与底层数据相连的起点和长度。 - 原始内容:Now when we call first_word, we get back a single value that is tied to the underlying data. The value is made up of a reference to the starting point of the slice and the number of elements in the slice.