Is there a way to use rust modules in JS or node.js projects?

#1

Hello, this is my first time here in the Rust community and I am pretty new to the rust programming language. I started learning rust last week for fun, while doing so I came across a rust library called syntect, which can syntax highlight using sublime-syntax grammars. I came across this while making my own Editor plugin in JS, which I had slowed down in making due to a lack of knowledge in lexing for syntax highlighting and frustration in using antlr4. I tried it out and before I knew it, I realized that this was what I wanted all along, but there was obviously one problem- It was in rust, and even though I love rust, I didn’t know how to implement a cargo package in a JS project. So is there a way to use cargo bundles in a JS project, or through node.js .

#2

A quick google search came up with this blog post about getting rust to compile with wasm, and I’ve found the rust ffi omnibus pretty useful. Essentially what it does is build the rust into a .wasm file, then generate javascript bindings.


Oh, and probably the most important of all is the wasm-bindgen crate’s introductory book to rust with javascript in wasm.

#3

You can use Neon, which gives you a native module for node, or you can use wasm-pack, which gives you a wasm one, for node or the browser.

1 Like