Get the best of both worlds: Integrating Rust with other languages
summary
Integrates Rust with C, C++ and Java by exposing a BinaryHeap-backed priority queue over a C FFI (extern "C", no_mangle) and generating headers with cbindgen, using the Option<Box<usize> nullability trick for nullable pointers, mapping C++ via the cxx crate, and calling from Java via JNI plus the JNI + jni-fn macro to simplify signatures. Valgrind shows no leaks; example image filters measure big wins: grayscale ~18ms → ~8ms and blur ~85ms → ~33ms, and build scripts automate header and binding generation.
AI-written summary · about
chapters (15)
- 0:00Start
- 1:58Introduction
- 5:26Use a Rust library from C - Constructor
- 10:14cbindgen - Build script (build.rs)
- 11:21cbindgen - Generated header file
- 13:16C++ bindings using cxx - Declarations
- 14:48C++ bindings using cxx - Implementation
- 16:11Conclusion
- 16:52Code repo & presentation slides
- 18:03Java Native Interface (JNI)
- 18:20Native method declaration
- 22:02Implement the Rust side
- 28:15Load native Library
- 33:58Demo
- 40:56Filter Kernel
related talks
25mRust and C++
31mUsing Rust from C... or Any Language
53mC++/Rust Interop: A Practical Guide to Bridging the Gap Between C++ and Rust
43mRust intro for Java Developers
19mHow to use a Rust library inside the JVM application
01h 02mRust/C++ Interop: Carcinization or Intelligent Design?
31mEmbedding Rust in C/C++
50mConfessions of a Rusty Java developer
