Rantanen / intercom

Object based cross-language FFI for Rust
MIT License
63 stars 7 forks source link

Split ExternType into ExternInput + ExternOutput #141

Closed Rantanen closed 4 years ago

Rantanen commented 4 years ago

The goal was to simplify ExternType, but I guess the result was the opposite.

Even so, the handling of input/output parameters and their memory is now in better hands.

In the past we had ExternType trait that defined various types and the actual memory management was left to the IntercomFrom trait, which had to guess about memory ownership based on types (such as *const pointers being borrows and *mut pointers being owned memory).

Now the IntercomFrom traits are gone and the ExternType (or rather the new Externinput/ExternOutput) traits contain the implementation that is responsible for converting values. This allows for better clarity concerning the memory ownership: In general Output parameters pass memory, Input parameters reference memory.

This also clarified the needed conversions a lot. With the use of the old ExternType that had to specify temporary/owned types for some conversions, specifying all the required IntercomFrom´ traits became painful. This change is best seen in thestrings.rs, which has lost over 100 lines since it doesn't need all theIntercomFrom` implementations.