Code Monkey home page Code Monkey logo

Comments (5)

mehcode avatar mehcode commented on May 24, 2024 15

Definitely want to see this. Something like:

#[jni("com.example.Foo")]
pub fn init(filename: &str) -> Result<(), Error> { ... }

#[jni("com.example.Bar")]
pub fn close_it(env: JNIEnv, filename: JString) -> Result<(), Error> { ... }

Becomes something like

#[no_mangle]
pub extern "system" fn Java_com_example_Bar_closeIt(env: JNIEnv, _: JClass, filename: JString) {
  // [...]
} 
  1. Name maker. Pass in java path and the name becomes java-y.
  2. Auto-conversion between Rust and Java types. Java types can still be expressed if you want to do it yourself.
  3. catch_unwind
  4. Handle Results and throw on error

from jni-rs.

antonok-edm avatar antonok-edm commented on May 24, 2024 2

After playing around with some JNI bindings of my own and encountering similar pain points, I've just published jni_fn which accomplishes at least the first item from @mehcode's comment:

  1. Name maker. Pass in java path and the name becomes java-y.

That seemed like the most well-defined problem to knock off the list, and was also my biggest confusion when starting out (where did this long auto-generated name come from and why do I need to care about it?).

I'm happy to explore incorporating the jni_fn macro into jni if there's interest!

I'm also open to adding in the other 3 items from that list, but I'd appreciate more design discussion; ideally examples of code before and after expansion. I've only just started investigating JNI and I'm sure I don't have a good mental model of the "edge cases" of JNI usage yet.

from jni-rs.

haraldreingruber-dedalus avatar haraldreingruber-dedalus commented on May 24, 2024 1

After playing around with some JNI bindings of my own and encountering similar pain points, I've just published jni_fn which accomplishes at least the first item from @mehcode's comment:

  1. Name maker. Pass in java path and the name becomes java-y.

...

I'm happy to explore incorporating the jni_fn macro into jni if there's interest!

@antonok-edm That looks super useful! Will try it in our project soon. Thanks for sharing 🙏

from jni-rs.

Progdrasil avatar Progdrasil commented on May 24, 2024

After having used a functionality pretty muchg exactly as @mehcode describes in Pyo3, this would be a great productivity boost. However it wouldn't be too difficult to simply create a proc_macro crate on top of jni to do this.

from jni-rs.

Diegovsky avatar Diegovsky commented on May 24, 2024

Agreed. Having to mix java's exceptions and rust's Result enum, I'm confident the syntax proposed would look and feel so much better.

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.