知识卡片
强制转换只在特定位置发生
coercion在语言规定的上下文自动调整兼容形式,例如&mut T转&T、数组引用转切片引用、非捕获闭包转fn指针。它不包括任意数字扩大,也不会自动调用所有From实现。生成原始指针本身不等于可以安全解引用;后者仍需满足相应安全前提。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 1. Types Coercion · 查看原书依据
Coercion The explicit as casts described in the previous section are a superset of the implicit coercions that the compiler will silently perform: any coercion can be forced with an explicit as, but the converse is not true. In particular, the integral conversions performed in the previous section are not coercions and so will always require as. Most coercio
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《Coercion》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u034-ch01-043)。
- 结论依据:原文在“Coercion”附近的定义、例子或代码支撑本卡核心说明:coercion在语言规定的上下文自动调整兼容形式,例如&mut T转&T、数组引用转切片引用、非捕获闭包转fn指针。边界按已读前提解释;示例未执行。
- 原始内容:Coercion The explicit as casts described in the previous section are a superset of the implicit coercions that the compiler will silently perform: any coercion can be forced with an explicit as, but the converse is not true. In particular, the integral conversions performed in the previous section are not coercions and so will always require as. Most coercio