Skip to content
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

Support for Option<T>? #15

Open
togetherwithasteria opened this issue Jul 30, 2022 · 8 comments
Open

Support for Option<T>? #15

togetherwithasteria opened this issue Jul 30, 2022 · 8 comments
Labels
enhancement New feature or request

Comments

@togetherwithasteria
Copy link

togetherwithasteria commented Jul 30, 2022

Hiiii <3

Will this project support passing Option to JNI? There are many APIs in the Android Sdk that might involve nullable values, soo this would help a lot!!!

@togetherwithasteria
Copy link
Author

togetherwithasteria commented Jul 30, 2022

I'm trying to make it myself, but it's not complete yet!!! https://github.com/EchidnaHQ/robusta

It involves lots of unholy magics like patching the jni crate itself !!

@giovanniberti giovanniberti added the enhancement New feature or request label Aug 3, 2022
@giovanniberti
Copy link
Owner

Hi @lovelyyfiaaa, thank you for bringing up this issue! I had a look at your commits and they seem fine. Given that there is also a compiler bug that you're fighting with I don't think we can hope for a better solution for the time being.

Another option would be to special-case Option into the library, but I'm not really a fan of that.

@togetherwithasteria
Copy link
Author

togetherwithasteria commented Aug 3, 2022

Yeah, sure!!

Umm, I think we should go with the JOption enum for now?

I too dislike it, but it seems it's the only option..

@giovanniberti
Copy link
Owner

Yeah, for now you can go on and just open a PR with JOption 💪
As a workaround maybe we can use some auxiliary traits in order to still have Option as a return type and automatically convert from JOption to Option, but for now it's ok even if you don't provide such machinery.

@stevefan1999-personal
Copy link

Is it using Optional<T>?

@sergeych
Copy link

So any idea how to cope with nullables returned from java side?

@sergeych
Copy link

as a temporary workaround I use:

fn opt<T>(r: JniResult<T>) -> JniResult<Option<T>> {
        match r {
            Ok(value) => { Ok(Some(value)) }
            Err(NullPtr(&_)) => { Ok(None) }
            Err(e) => { Err(e) }
        }
    }

it works well if java/kotlin side returns null, but it most likely will also misreport NPE on java side as returning null. See no better solution yet.

uvlad7 added a commit to uvlad7/robusta that referenced this issue Jan 4, 2024
uvlad7 added a commit to uvlad7/robusta that referenced this issue Jan 4, 2024
uvlad7 added a commit to uvlad7/robusta that referenced this issue Jan 4, 2024
@uvlad7
Copy link
Contributor

uvlad7 commented Jan 4, 2024

@sergeych take a look at #50 and commits above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants