randomPoison / cs-bindgen

Experiment in using Rust to build a library that can be loaded by Unity across multiple platforms
4 stars 0 forks source link

Generalized, trait-based type marshalling #21

Closed randomPoison closed 4 years ago

randomPoison commented 4 years ago

The current approach for marshaling values between Rust and C# is syntax-based, requiring that the #[cs_bindgen] proc macro be able to recognize argument/return types so that it can generate the correct conversions. This was a simple approach to get us started, but has numerous drawbacks that ultimately can't be resolved with a syntax-based approach. Instead, we should switch to a trait-based approach.

The trait-based approach has two main parts:

This approach is based off how wasm-bindgen handles generating bindings for complex Rust types. We should take a similar approach as much as possible, while striving to keep our implementation generalized beyond C# as much as possible.