DEV Community

Sofia Winters
Sofia Winters

Posted on

Small examples to use Rust from C#

When I make games with Unity, sometimes I need to write a native plugin. C is the most used language for native plugins, but it's not safe. So recently I use Rust. (Though Rust's safety is limited because native plugins use foreign function calls, I believe Rust is safer than C.)

Then, I made small examples that use Rust from C#, including basic function calls, passing/receiving string, callback, passing/receiving struct, and handle Rust's object through a pointer.

Repo: SofiaWinters/CSharpWithRust
Rust: csharp-with-rust/src/lib.rs
C#: CSharpWithRust/CSharpWithRust/RustTest.cs

You can build a DLL file by executing /csharp-with-rust/build.bat

Currently, the repo only has a .Net Core project, I'll add a Unity project.

Top comments (0)