知识卡片
函数指针选择同签名行为
fn(i32,i32)->i32表示可指向这种签名函数的指针,调用时能按运行时选择执行不同实现。函数名本身先对应独有的function item类型,需要时可转为fn指针。函数指针实现比较能力,但相等不能可靠证明函数身份:编译过程可能复制同一函数或合并相同实现。
补充核验:函数身份限制见Rust标准库函数指针文档,2026-10-27查阅。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 1. Types Function Pointers · 查看原书依据
Function Pointers The previous section described how to associate a name (and a parameter list) with some code. However, invoking a function always results in the same code being executed; all that changes from invocation to invocation is the data that the function operates on. That covers a lot of possible scenarios, but what if the code needs to vary at ru
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《Function Pointers》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u017-ch01-014)。
- 结论依据:原文在“Function Pointers”附近的定义、例子或代码支撑本卡核心说明:fn(i32,i32)->i32表示可指向这种签名函数的指针,调用时能按运行时选择执行不同实现。边界按已读前提解释;示例未执行。
- 原始内容:Function Pointers The previous section described how to associate a name (and a parameter list) with some code. However, invoking a function always results in the same code being executed; all that changes from invocation to invocation is the data that the function operates on. That covers a lot of possible scenarios, but what if the code needs to vary at ru