A short, probably useful answer : there is a block box that looks like it can do the job.
A short, useless answer . To my knowledge, Rust does not support Apple extension support. There is no equivalent type of Rust, assuming you want to call the API that the block expects.
A longer, slightly less unhelpful response . From what I can compile from some Clang documentation on Apple Block ABI , void(^)(void) will be the same size as a regular pointer.
So my advice is this: treat the blocks as opaque pointer size values. To call it, write a function in C that calls it for you.
The following has not been verified (I don't have a Mac), but at least you will go in the right direction. I also mark this community wiki, so anyone who can test it can fix it if necessary.
In the rust:
In C:
typedef struct AppleBlock { void *ptr; } AppleBlock; typedef struct RustClosure { void *ptr; void *vt; } RustClosure; void call_rust_closure(RustClosure closure_blob); AppleBlock rust_closure_to_block(RustClosure closure_blob) { return (AppleBlock)Block_copy(^() { call_rust_closure(closure_blob); }); }
source share