The best way to do this is to create a Rust library with external functions and then use the Foreign Function Interface to load and execute these functions:
https://reference.wolfram.com/language/guide/ForeignFunctionInterface.html
For example if you have this Rust code (add.rs
):
use std::os::raw::{c_int};
#[no_mangle]
pub extern "C" fn add(a: c_int, b: c_int) -> c_int {
a + b
}
And build it with Cargo, then you will get an add.dylib
library, which you can load in Wolfram Language:
add = ForeignFunctionLoad[ "add.dylib", "add", {"Integer64", "Integer64"} -> "Integer64"]
Now you can call this function from the Wolfram Language:
add[4,5]
Hope that helps.