When using a reference to a function pointer, it gets converted to a reference to a function item instead, making future assignments require a typecast to the wanted function pointer instead.
Relevant link below:
https://play.rust-lang.org/?gist=00a013ae03ba8b50ceb37499985807f1&version=nightly&mode=debug
This illustrates several diagnostic issues.
fn foo() {}
fn main() {
let _f: fn() = foo; // Works
let _fref: &fn() = &foo; //~ERROR expected fn pointer, found fn item
}
produces the error:
error[E0308]: mismatched types
--> src/main.rs:5:24
|
5 | let _fref: &fn() = &foo; //~ERROR expected fn pointer, found fn item
| ^^^^ expected fn pointer, found fn item
|
= note: expected type `&fn()`
found type `&fn() {foo}`
fn pointer or fn item are, especially for a beginner. (Arguably the term fn item is compiler jargon.)fn() {foo} is meaningless unless you're already familiar with how Rust handles function types.
Most helpful comment
This illustrates several diagnostic issues.
produces the error:
fn pointerorfn itemare, especially for a beginner. (Arguably the termfn itemis compiler jargon.)fn() {foo}is meaningless unless you're already familiar with how Rust handles function types.