Group Abstract Group Abstract

Message Boards Message Boards

Feature Request - add Rust to EmbedCode and ExternalEvaluate

Posted 6 years ago
POSTED BY: Jose M.
3 Replies

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.

POSTED BY: Arnoud Buzing

You can download the Rust code (plus Cargo.toml file) from here:

https://amoeba.wolfram.com/index.php/s/ykm3H72tRbtfxBr

POSTED BY: Arnoud Buzing

Feature requests should be submitted to:

http://www.wolfram.com/support/contact/email/?topic=Feedback

POSTED BY: A J Hardesty
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard