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

Generate interface impls and operator overloads corresponding to derived traits #55

Open randomPoison opened 4 years ago

randomPoison commented 4 years ago

In order to aid the creation of newtype structs, we should generate C# interface implementations and operator overloads that correspond to any derived traits so that the C# types behave as similarly as possible to the Rust types. For by-value types, the generated implementations will operate field-wise, the same way that the derived Rust impls do. For handle types we'll have to call into Rust code to use the Rust impls directly.

So for example, if an exported type derives PartialEq, we should implement the IEquatable interface and overload Equals for the generated C# type. Below are the traits we should detect along with the corresponding C# code that needs to be generated:

Additionally, the following traits don't have built-in derives but can be derived using crates like derive_more:

For these we may not want to automatically detect the derive (at least not without a feature flag), but it should be possible to opt-in to the generated implementations via attributes.