知识卡片
静态引用与常量地址不相同
‘static引用要求目标在整个程序期间有效,static项提供稳定存储位置。const保证的是值,可在不同使用处复制,不保证共享唯一地址;引用提升也受析构和内部可变性等条件限制。不要仅因常量名字相同,就把其地址当成唯一身份。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 3. Concepts The 'static Lifetime · 查看原书依据
The 'static Lifetime The previous section described various possible mappings between the input and output reference lifetimes for a function, but it neglected to cover one special case. What happens if there are no input lifetimes, but the output return value includes a reference anyway? pub fn the_answer() -> &Item { // ... } error[E0106]: missing lifetime
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《The 'static Lifetime》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u083-ch03-008)。
- 结论依据:原文在“The 'static Lifetime”附近的定义、例子或代码支撑本卡核心说明:'static引用要求目标在整个程序期间有效,static项提供稳定存储位置。边界按已读前提解释;示例未执行。
- 原始内容:The 'static Lifetime The previous section described various possible mappings between the input and output reference lifetimes for a function, but it neglected to cover one special case. What happens if there are no input lifetimes, but the output return value includes a reference anyway? pub fn the_answer() -> &Item { // ... } error[E0106]: missing lifetime