Anybody Integrating Rust with C#?


#1

Hi everyone,

I’ve been thinking about integrating Rust with C# recently, and after noticing it aligns with the roadmap I thought I’d cast the net for thoughts in the community. This is a dump of my thoughts so far:

I’m working on a project to write handlers for a hyper server in C# as an excuse to work on tooling to integrate Rust into .NET projects. Rust already has good support for exposing a C-like API, and .NET already has good support for consuming one so I see this touching the following areas:

  • Building and consuming Rust libraries in a .NET workflow. I’ve got a simple tool for packing Rust libs for nuget, but proper msbuild integration is probably also worth exploring
  • Code generation for FFI structures. I haven’t experimented with this yet, but thought a custom derive would be a simple, but maybe surprising, way to dump blittable Rust structs and enums as C# types. An external tool that looks at an .rs file could also work though
  • Wrapper libraries for translating some common Rust/.NET concepts. Being able to poll a C# Task as a Rust Future would be really neat (but probably quite subtle)
  • IDE support is already working for VS Code, and VS 2017 shouldn’t be far behind.

If anyone is actively integrating Rust with C# or has any thoughts I’d love to hear it :slight_smile:


#2

You can look at my rust_swig project.
Currently it supports only Java, but I suppose it would be not hard, to add support of generation of C# code with Platform Invoke in addition to Java


#3

You may want to like at the way rusty-cheddar do it. I have zero experience with this library so I don’t know if it is good or not.