知识卡片
内部偏移避免部分地址依赖
把内部切片改为起止偏移,可在需要时从当前文本重新借用,避免直接保存指针。整体对象移动后偏移仍可解释,但文本插删、长度和UTF-8边界变化仍可能使区间失效。索引方案减少引用约束,不会自动维护数据编辑的一致性。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 3. Concepts Self-referential data structures · 查看原书依据
SelfRefIdx { text: String, // Indices into `text` where the title text is. title: Option<std::ops::Range<usize>>, } However, this indexing approach works only for simple examples and has the same drawbacks as noted previously: the index itself becomes a pseudo-pointer that can become out of sync or even refer to ranges of the text that no longer exist. A mor
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Self-referential data structures》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u096-ch03-024)。
- 结论依据:原文在“SelfRefIdx”附近的定义、例子或代码支撑本卡核心说明:把内部切片改为起止偏移,可在需要时从当前文本重新借用,避免直接保存指针。边界按已读前提解释;示例未执行。
- 原始内容:SelfRefIdx { text: String, // Indices into `text` where the title text is. title: Option<std::ops::Range<usize>>, } However, this indexing approach works only for simple examples and has the same drawbacks as noted previously: the index itself becomes a pseudo-pointer that can become out of sync or even refer to ranges of the text that no longer exist. A mor