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

Type-based ABI conversions #22

Closed randomPoison closed 4 years ago

randomPoison commented 4 years ago

Closes #21, Closes #13

This PR makes two major changes to how we handle marshaling data across the language boundary and how we generate the C# bindings:

ABI Conversions

ABI conversions are now handled by the FromAbi and IntoAbi traits. These are implemented for any type that can be passed to or received from C#. This also drastically simplifies code generation, since all generated bindings now uniformly defer to the FromAbi/IntoAbi implementation for a given value.

Type Schemas

In order to support more robust bindings on the C# side, we're now using the schematic crate to generate type schemas for any user-defined types exposed. This give C# full type information, so that it can perform the correct type conversions. This isn't being used fully now, but paves the way for initial support for returning custom types from exported functions.