Coder Social home page Coder Social logo

Return Option<jobject> about jni-rs HOT 5 CLOSED

dbrgn avatar dbrgn commented on May 29, 2024
Return Option

from jni-rs.

Comments (5)

dbrgn avatar dbrgn commented on May 29, 2024

Ah, this seems to work:

ptr::null_mut() as *mut _jobject

Maybe that could somehow be made more ergonomic? Via an Option would be fantastic, but even a provided helper function creating such a null-jobject would be nice.

from jni-rs.

jrobsonchase avatar jrobsonchase commented on May 29, 2024

Do you mean that you're trying to return either a jobject or a null pointer from an extern "C" function? I think that the "Option to represent a null ffi pointer" pattern is mainly used for function pointers. I'm pretty sure that returning an Option to C-land doesn't work in the same manner, so it won't be possible to do that here. A helper should be pretty easy though.

from jni-rs.

dbrgn avatar dbrgn commented on May 29, 2024

Do you mean that you're trying to return either a jobject or a null pointer from an extern "C" function?

Exactly. In Java it would be something like this:

public MyObject foo() {
    if (...) {
        return new MyObject();
    } else {
        return null;
    }
}

from jni-rs.

jrobsonchase avatar jrobsonchase commented on May 29, 2024

Going ahead and closing this since I'm like 95% sure that returning an option from an FFI function is not and likely will never be possible, and the helper for constructing a null object made its way into 0.6.1.

If you can find anything to the contrary on the option return, feel free to reopen!

from jni-rs.

dbrgn avatar dbrgn commented on May 29, 2024

Would something like that work? llogiq/optional#23

from jni-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.