-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can you pass functions as arguments to uniffi? #2003
Comments
You should be able to do that using |
@badboy that might work, but I have something like this in mind: #[derive(uniffi::Record)]
struct Button {
on_click: fn()
}
#[uniffi::export]
fn app() -> Button {
Button {
on_click: || {}
}
} Swift will call the Yes, I know I can use an Object for this, but the idea is that the handler should be provided by the user. I was also thinking of this: // make Button an Object instead of a Record
#[uniffi::export]
impl Button {
fn on_click(&self) {
(self.on_click)();
}
} But I was wondering whether there is a better solution for this |
If the |
In addition to what @badboy says, the more general solution here is to use a |
I think we gave a good workaround, and we aren't going to make functions first-class, so let's close this. |
For example, let's take the following trait:
Currently this gives the following compilation error:
I understand that this is a pretty complicated issue and most probably cannot be done directly, but I was wondering if there is any workaround
The text was updated successfully, but these errors were encountered: