Support foreign implementations of trait interfaces (#1578)
Scaffolding:
* Generate a struct that implements the trait using a callback interface callback
* Make `try_lift` input a callback interface handle and create one of those structs.
* Don't use `try_lift` in the trait interface method scaffolding.
`try_lift` expects to lift a callback handle, but scaffolding
methods are called with a leaked object pointer.
* Removed the unused RustCallStatus param from the callback initialization function
Kotlin/Python/Swift:
* Factored out the callback interface impl and interface/protocol
templates so it can also be used for trait interfaces.
* Changed the callback interface handle map code so that it doesn't
try to re-use the handles. If an object is lowered twice, we now
generate two different handles. This is required for trait
interfaces, and I think it's also would be the right thing for
callback interfaces if they could be passed back into the foreign
language from Rust.
* Make `lower()` return a callback interface handle.
* Added some code to clarify how we generate the protocol and the
implementation of that protocol for an object
Other:
* Trait interfaces are still not supported on Ruby.
* Updated the coverall bindings tests to test this.
* Updated the traits example, although there's definitely more room for improvement.
TODO:
I think a better handle solution (#1730) could help with a few things:
* We're currently wrapping the object every time it's passed across the
FFI. If the foreign code receives a trait object, then passes it back
to Rust. Rust now has a handle to the foreign impl and that foreign
impl just calls back into Rust. This can lead to some extremely
inefficent FFI calls if an object is passed around enough.
* The way we're coercing between pointers, usize, and uint64 is
probably wrong and at the very least extremely brittle.
There should be better tests for reference counts, but I'm waiting until
we address the handle issue to implement them.