Email or username:

Password:

Forgot your password?
Top-level
Joshua Barretto

To be clear to all those responding with 'just use a function pointer': a function pointer specifically *does not* do what I'm looking for. Instead, I'm looking for an API like this: play.rust-lang.org/?version=st

6 comments
Kornel

@jsbarretto it's going to be zero-sized only in generic structs, but these generally are not fit for use in FFI, so I don't see how it would be useful for FFI in particular.

Joshua Barretto

@kornel It's not specifically useful for passing *over* FFI boundaries, but it allows the construction of safe APIs that wrap FFI and go to and from the same functor on either end.

Joshua Barretto

@kornel Right now, the best approach I have is to have a `assert!(size_of::<F>() == 0);` inside the API and then do an ugly transmute out of thin air on the other side, which I'm certain is at least partially unsound (depending on decisions about whether fn pointers have provenance)

Joshua Barretto

@kornel Also, I can't just remember the function pointer in the enclosing scope: the code I'm writing relies on the final trampoline being a tail call, so any data left in the function body needs to go unused.

I know it seems like a niche case, but this is, I think, the third time (in totally unrelated circumstances) I've wanted to reach for such an API

Go Up