RustJS is an engine that is able to convert Rust code into native JavaScript, so that it can run directly on the browser without issues instead of heavy web-assembly. This project is also open-source, so if you'd like to suggest any changes, please, consider making a pull request on GitHub.
Currently, no. Some parts may be tricky to implement, but some core features are there and (hopefully) everything will have been implemented some time into the near future.
The files for RustJS are hosted on this very site, so to install RustJS, all you need to do is:
<script> tag inside your HTML file. Place it before any runner files to avoid scope errors.
<script src="https://rustjs.netlify.app/cdn/rustjs/latest"></script>
You should be all set now.
In order to actually use RustJS, first, call the function rustjs.init(). Then to do the conversion, simply add rustjs.convert() anywhere after RustJS is initialised. Make sure to add the Rust code you would like to convert as the parameter. The function will return the JavaScript code.
Currently not supported in v0.1.
Support for Node.js will be added in a future release — so stay tuned for that.
Using RustJS is simple. To initialise, simply call rustjs.init(). And to convert any code directly to JavaScript, all you have to do is call rustjs.convert().
Below shows an example involving Microsoft's Monaco Editor.
// Initialise the package:
rustjs.init();
// Monaco Example (assuming it already exists):
rustjs.convert(window.editor.getValue());
If for some reason you'd like to use an older version of RustJS, all you need to do is swap latest for the version you would like to use. Any non-existent versions will automatically serve the latest. So for example, if you wanted v0.1, then simply put the following in your code.
<script src="https://rustjs.netlify.app/cdn/rustjs/v0.1"></script>
| Version Number | CDN |
|---|---|
| Latest | https://rustjs.netlify.app/cdn/rustjs/latestopen_in_new |
| v0.1 | https://rustjs.netlify.app/cdn/rustjs/v0.1open_in_new |