I'm interested in doing some low level programming of Rust and React-Native, this tweet by Jared Sumner peaked my interested.
So basically he used the JSI to do a c++ implementation and apparently the results are much much faster than the regular libraries, so I got spelunking and followed some tutorials to get rust code working on a RN project.
Here is my basic rust code:
extern crate libc;
mod string;
use string::StringPtr;
// string ffi
#[no_mangle]
pub unsafe extern "C" fn rust_string_ptr(s: *mut String) -> *mut StringPtr {
Box::into_raw(Box::new(StringPtr::from(&**s)))
}
#[no_mangle]
pub unsafe extern "C" fn rust_string_destroy(s: *mut String) {
let _ = Box::from_raw(s);
}
#[no_mangle]
pub unsafe extern "C" fn rust_string_ptr_destroy(s: *mut StringPtr) {
let _ = Box::from_raw(s);
}
#[no_mangle]
pub unsafe extern "C" fn hello_world(name: *mut StringPtr) -> *mut String {
let name = (*name).as_str();
let response = format!("Hello {}!", name);
Box::into_raw(Box::new(response))
}
#[cfg(feature = "jni")]
#[allow(non_snake_case)]
pub mod android {
extern crate jni;
use self::jni::objects::{JClass, JString};
use self::jni::sys::jstring;
use self::jni::JNIEnv;
#[no_mangle]
pub unsafe extern "C" fn Java_com_mobile_1app_MobileAppBridge_helloWorld(
env: JNIEnv,
_: JClass,
name: JString,
) -> jstring {
let name: String = env.get_string(name).unwrap().into();
let response = format!("Hello {}!", name);
env.new_string(response).unwrap().into_inner()
}
}
I have managed to compile rust code and pass a string to the RN code, the module is registered and I can call the library and get some strings, now however my question is, how do I import the photos module from iOS to get the camera roll photos?
Basically I would like to replace the camera-roll framework with a faster implementation, I would need to figure out how to get the photos.h library working with the rust code though.