DEV Community

Discussion on: Calling Rust from C#

Collapse
 
torkleyy profile image
Thomas Schaller

Hey, thanks for the post. As you noted, the string handling is not ideal. I suggest you allocate a Box / Vec for the string, pass it to C#. From there, you just copy it into its native String type and call a Rust-defined free_string function. For users who are unexperienced with memory management / unsafety, the additional overhead seems justified for me.

Another minor I've noticed is the unideomatic return in one function (can be skipped at the end) ;)

Collapse
 
kelsonball profile image
Kelson Ball

Any links on how to do that?

Collapse
 
torkleyy profile image
Thomas Schaller

Don't have a link at hand, but I'd just return the char pointer directly (instead of storing it in a global) and ask for it again in the free function.

Collapse
 
living_syn profile image
Jeremy Mill

Hey, thanks for the reply. I have a lot more experience with this now than when I wrote this. It definitely needs to be updated, i'll try and get around to it sooner than later