You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We currently support remote records and enums, but we don't support remote interface types. #2087 starts that support since it allows the interface types to be used in function signatures, however it doesn't allow users to actually define any methods on remote interface types.
We should fix that, I'm thinking the syntax could look like this (using anyhow::Error since it's the main example driving this right now):
The remote keyword indicates that anyhow::Error is remote so UniFFI should generate the scaffolding for this type, but only implement the FFI traits for the local UniFfiTag. It should not output the impl item and the methods, those are actually defined in the anyhow crate. Note: in this case to_string is not an inherent method, but it's still defined since anyhow::Error implements Display.
Function bodies are ignored and users should just write an empty block for them.
If possible, we should also implement the Rust trait system. That would let users write:
It will often be the case that remote methods are not supported by UniFFI. In that case, users can use an extension trait to define their own methods on the type, then expose them with uniffi::export(remote). Maybe we could provide some syntactic sugar to easily do that:
#[uniffi::export(remote_extend, Display)]
impl anyhow::Error {
// the `is` method can't be exposed directly by UniFFI, since it's generic. But we can define a set of `is_*` methods for specific types.
fn is_foo_error(&self) -> bool {
self.is::<foo::Error>()
}
}
In this case, UniFFI will:
Define an extension trait
Implement the trait for anyhow::Error using the user-supplied code
Generate the scaffolding for the type (I think we still need to use the local UniFfiTag
The text was updated successfully, but these errors were encountered:
We currently support remote records and enums, but we don't support remote interface types. #2087 starts that support since it allows the interface types to be used in function signatures, however it doesn't allow users to actually define any methods on remote interface types.
We should fix that, I'm thinking the syntax could look like this (using
anyhow::Error
since it's the main example driving this right now):remote
keyword indicates thatanyhow::Error
is remote so UniFFI should generate the scaffolding for this type, but only implement the FFI traits for the localUniFfiTag
. It should not output theimpl
item and the methods, those are actually defined in theanyhow
crate. Note: in this caseto_string
is not an inherent method, but it's still defined sinceanyhow::Error
implementsDisplay
.If possible, we should also implement the Rust trait system. That would let users write:
It will often be the case that remote methods are not supported by UniFFI. In that case, users can use an extension trait to define their own methods on the type, then expose them with
uniffi::export(remote)
. Maybe we could provide some syntactic sugar to easily do that:In this case, UniFFI will:
anyhow::Error
using the user-supplied codeUniFfiTag
The text was updated successfully, but these errors were encountered: