News for hackers. Stuff that matters.
Re:Try Out Rust IDE Support in Visual Studio Code by vvanders on Saturday August 19, 2017 @12:30AM (#15051683)
C# and Rust are a wicked combo. The fact that you can pass delegates as fn pointers down to Rust is freaking sweet from an FFI perspective.
Re:Try Out Rust IDE Support in Visual Studio Code by darklajid on Saturday August 19, 2017 @05:13AM (#15052473)
Do you have any pointers to projects doing this?

I'm very interested in rust and a C# guy during the day. A decent, as in 'serious', example showing rust integration would be quite appreciated.

Re:Try Out Rust IDE Support in Visual Studio Code by vvanders on Saturday August 19, 2017 @10:38AM (#15053608)
Nothing public unfortunately.

It's pretty straightforward though. Just declare a delegate with the same type signature as a your C function callback. Add that as the signature passed in to a native function and C# will make sure to marshal it to a standard C function pointer.

Only catch is if you want to keep a hold of the pointer in native you need to make sure to create a GCHandle to the passed in delegate with an identical lifetime. Otherwise the GC will collect the delegate from underneath you.