Integration with C#

I want to make a softwhere in C#. But I want to make Engin part of this in Rust. So, I want create dll files in rust and read in C#. What am I doing? I am Japanese, so I can't write English very well. So I'll write in Japanese too.↓
私はC#を用いてソフトウェアを作りたくて、そのエンジン部分をRustによって記述したいと思っています。このため、Rustで.dllファイルを作成し、C#に読み込ませたいのですが、どうすればよいのでしょう?
If you can, reply in easily english please.

To make a DLL in Rust, you need to set:

[lib] 
crate-type = ["cdylib"]

in Cargo.toml.

C# only knows how to call C, not Rust, so you need to make your Rust functions look like C. Make a C-compatible API using extern "C" functions, and #[no_mangle].

Then in C#, use P/Invoke to load Rust's DLL and call functions from it.

2 Likes

Thanks. I'll try it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.