I need a global static variable, that references a extern "C" function.
I get the following compiler error:
error[E0308]: mismatched types
--> src/main.rs:17:28
|
17 | static BAR: Bar = Bar::new(&foobar);
| ^^^^^^^ expected fn pointer, found fn item
|
= note: expected reference `&'static unsafe extern "C" fn() -> !`
found reference `&unsafe extern "C" fn() -> ! {foobar}`
My code down below or on Rust playground
extern "C" {
fn foobar() -> !;
}
struct Bar {
foo: &'static unsafe extern "C" fn() -> !
}
impl Bar {
const fn new(foo: &'static unsafe extern "C" fn() -> !) -> Self {
Self {
foo
}
}
}
static BAR: Bar = Bar::new(&foobar);
fn main() {
}
How can I solve this?
fn() -> !is a type useful by itself, you don't need explicit references to make "function pointers": play.rust-lang.org/…