Comments (5)
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) {
// [...]
}
- Name maker. Pass in java path and the name becomes java-y.
- Auto-conversion between Rust and Java types. Java types can still be expressed if you want to do it yourself.
catch_unwind
- Handle
Result
s and throw on error
from jni-rs.
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:
- 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.
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:
- Name maker. Pass in java path and the name becomes java-y.
...
I'm happy to explore incorporating the
jni_fn
macro intojni
if there's interest!
@antonok-edm That looks super useful! Will try it in our project soon. Thanks for sharing
from jni-rs.
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.
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)
- Provide ways to use `CallNonvirtual*Method` in `JNIEnv` HOT 1
- Converting between types in JNI code HOT 2
- `AttachGuard` detaches too soon when dropped out of order HOT 2
- how to use call_static_method_unchecked with a GlobalRef to a class? HOT 2
- how to get java list on rust HOT 1
- CallNonvirtual<type>Method support request HOT 2
- Can i load native function on exec self ? HOT 3
- Question: How I use `GetObjectRefType` HOT 4
- Make methods `const fn` when it makes sense HOT 1
- `get_rust_field()` exclusive access to `JNIEnv` HOT 8
- How I use `MonitorEnter` and `MonitorExit`
- use catch_unwind to ensure balanced push/pop_local_frame in with_local_frame
- `JNIEnv::get_version()` should be infallible
- JNIVersion should implement `Ord` and be able to hold unknown, newer versions as u32 values
- JNIEnv::exception_check should just return a bool and REQUIRES JNI 1.2 as a minimum supported version! HOT 1
- Can't use JNI_GetCreatedJavaVMs HOT 1
- `ensure_local_capacity` doesn't check for errors correctly
- `attach_current_thread_as_daemon` (and any notion that we support 'daemon' threads) should probably be removed
- Remove/deprecate Executor API?
- The performance seems to be only 80% of that of cpp (jni) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jni-rs.