What is the proper way to pass around named functions as function pointers?
static mut foo: *mut fn(buf: Vec<u8>) = 0 as *mut fn(buf: Vec<u8>);
fn main() {
bar(&mut baz);
}
fn bar(f: &mut fn(buf: Vec<u8>)) {
unsafe { foo = f };
}
fn baz(buf: Vec<u8>) {}
Produces:
error: mismatched types [--explain E0308]
--> <anon>:5:9
|>
5 |> bar(&mut baz);
|> ^^^^^^^^ expected fn pointer, found fn item
note: expected type '&mut fn(std::vec::Vec<u8>)'
note: found type '&mut fn(std::vec::Vec<u8>) {baz}'