News for hackers. Stuff that matters.
Re:Rust once, run everywhere by alexcrichton on Friday April 24, 2015 @02:21PM (#9435116)
If you omit the `#[no_mangle]` definition then the compiler will end up emitting a mangled symbol (e.g. one with a long hash at the end that's hard to guess).

Many C APIs take a callback function pointer, which in rust has the type `extern fn()`, and this is the primary use case for an `extern` function defined in Rust which doesn't have `#[no_mangle]` on it.

Re:Rust once, run everywhere by lclarkmichalek on Friday April 24, 2015 @02:59PM (#9435364)
Here's an example of that in a lib I've been working on: https://github.com/bluepeppers/libnetfilter_queue/blob/maste...
Re:Rust once, run everywhere by cpeterso on Friday April 24, 2015 @04:11PM (#9435748)
Thanks for the example. What is the advantage of using an unmangled extern fn as a C callback? That the user-friendlier unmangled function name will appear in stack traces or can more safely be called from other Rust code?
Re:Rust once, run everywhere by lclarkmichalek on Friday April 24, 2015 @04:34PM (#9435863)
True, though it wouldn't be hard to write a GDB extension to unmangle the names (I know D had this from quite early in it's lifetime). In general, I leave unmangled names to things that are part of the external interface: when unmangling the name, I'm explicitly saying "this symbol's name is part of the contract I have with user of this library".
Re:Rust once, run everywhere by steveklabnik on Friday April 24, 2015 @04:59PM (#9435972)
There's already something that ships with Rust that unmangles some stuff: http://michaelwoerister.github.io/2015/03/27/rust-xxdb.html
Re:Rust once, run everywhere by tomjakubowski on Friday April 24, 2015 @06:17PM (#9436303)
Can you make external "C" callback functions generic? The function itself I mean, not the signature of the FFI function that takes the callback. If so, there's a great use case for not mangling C callbacks.
Re:Rust once, run everywhere by Rusky on Friday April 24, 2015 @10:38PM (#9436960)
Re:Rust once, run everywhere by cpeterso on Friday April 24, 2015 @08:50PM (#9436722)
Thanks. I guess using `extern "C"` to imply `#[no_mangle]` would be too cute. :-)