Rust with other languages

I am only Starting to learn Rust and would like to ask about other programmes,written on c++, python how can I easely and safely use Them simultaneously with rust programme,Thanks)

Rust is able to call C functions and get called from C (or alike) using the FFI (Foreign Function Interface).
Some docs are here:

This is not "safe" according to what Rust considers safe, as you're leaving Rust land.
However, there's a bunch of tooling to make this easier (and safer) to use with other languages.

For some there's direct bindings, e.g. PyO3 to interact with Python, JNI to interact with Java (or other JVM languages).
There's other tooling out there to ease some of the challenges around this.

I gave a talk recently on how we build a cross-platform library in Rust.

1 Like

Okay, and also i want to learn JavaScript, do you know how to interect with this one also?)

Usually Rust with JS is used via Web Assembly (WASM).

A bit more specific option is to write native extensions to Node.js using Rust.

You could also use natively-compiled Rust with JS together via V8 bindings, but this is an advanced technique, and I don't recommend that if you're not an experienced programmer.

1 Like

When I compile C/C++ with emscipten it produces WASM all nicely wrapped up to use a node module.

Is there nothing so simple for Rust and WASM?

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.