Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In Rust, an array with 10 elements that are function pointers whose functions receive i32 and return f32 is like this:

    [fn(i32) -> f32; 10]
https://doc.rust-lang.org/reference/types/function-pointer.h...

That's maybe cheating because this type doesn't use Rust raw pointers; C's char* in Rust is something like const char or mut char. But, if you wanted a raw pointer (and were ok with a double pointer: an array of pointers to function pointers), it would be like this:

    [*mut (fn(i32) -> f32); 10]
Which I think we can drop the (), since there is no ambiguity

    [*mut fn(i32) -> f32; 10]


ok, so HN formatting ate a couple * here and there. I meant that

    char* something;
in C is like

    let something: *mut char;
or

    let something: *const char;
In Rust. So complex pointers are easily expressible: they are just *mut something complex




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: