uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

External types don't work if they're not used in an interface

Open bendk opened this issue 1 year ago • 1 comments

If you define an external type, but don't use it in an exporting function/method, then we don't actually import the type in the bindings.

Here's a branch that contains a test for this and tries to fix it, although I couldn't get it all working: https://github.com/bendk/uniffi-rs/tree/ext-type-imports

bendk avatar Nov 28 '23 18:11 bendk

One use-case here is nested types. Suppose you wanted export a function that used the Line type from the geometry example crate. In that case, you also would want to export the Point type or else users would have no easy way of constructing a Line. Maybe UniFFI could recurse through the types to solve this one, but then how would it know if the ExternalKind to use for that type?

Another use case is simply re-exporting a type. Suppose the foo crate defined a Foo interface type that was really useful and you wanted to re-export that type and let users use it without needing to get it from foo.

bendk avatar Nov 28 '23 18:11 bendk