OK, time for another teapot. This one is a combination of the two in this earlier post. The code which creates the geometry of the teapot is copied from the Rust example, and the code which does the rendering is copied from the WebGL example.

But how do they work together? Rust compiles to native, and WebGL is only available in a browser or in something like electron. The trick is something calle wasm-pack. This compiles the Rust code to WebAssembly. Then you can use that as a module you can call from JavaScript.

Teapot

Connecting the two is surprisingly simple. You just mark the functions and types you want to expose to javascript with the wasm_bindgen macro and then you can import them in your JS code.

The source is here. You can run it from github pages.