This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rustup default nightly | |
| rustup target add wasm32-unknown-unknown --toolchain nightly | |
| cargo install wasm-gc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[no_mangle] | |
| pub fn simple_arr() -> *mut i32 { | |
| let vec = Box::new([100, 200, 300, 400]); | |
| Box::into_raw(vec) as *mut i32 | |
| } | |
| fn main() { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const typedArr = new Uint32Array(arrayBuffer, 0, 4); | |
| const arr = [...typedArray]; | |
| // [100, 200, 300, 400] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fetch('memory-access.gc.wasm') | |
| .then(r => r.arrayBuffer()) | |
| .then(arrayBuff => WebAssembly.instantiate(arrBuff, {})) | |
| .then(rustWasm => console.log(rustWasm)); | |
| // Object { module: WebAssembly.Module, instance: WebAssembly.Instance } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ rustc +nightly --target wasm32-unknown-unknown -O vector.rs | |
| $ wasm-gc vector.wasm vector.wasm | |
| $ python -m SimpleHTTPServer # Power up an inline HTTP server on port 80 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fetch('memory-access.gc.wasm') | |
| .then(r => r.arrayBuffer()) | |
| .then(arrayBuff => WebAssembly.instantiate(arrBuff, {})) | |
| .then(rustWasm => { | |
| const vecLocation = wasmRust.instance.exports.simple_arr(); | |
| const vecTyped = new Uint32Array(wasmRust.instance.exports.memory.buffer, vecLocation, 4); | |
| const simpleVec = [...vecTyped] | |
| console.log(simpleVec) | |
| // [ 100, 200, 300, 400 ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| process.argv | |
| .filter(function(item){ return !Number.isNaN(Number(item)); }) | |
| .map(function(item){ return Number(item); }) | |
| .reduce(function(acc, item){ return acc + item }, 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extern crate cfg_if; | |
| extern crate wasm_bindgen; | |
| extern crate regex; | |
| #[macro_use] | |
| extern crate serde_derive; | |
| use wasm_bindgen::prelude::*; | |
| use regex::Regex; | |
| #[wasm_bindgen] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as fuzzySearch from "fuzzy-search"; | |
| import books from './books-db'; | |
| import lorem from './lorem'; | |
| const loremOpts = { | |
| isHardcore: false | |
| }; | |
| renderLorem(); | |
| renderBooks(books); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <ClickOutside onClick=() => 'Close tooltip'> | |
| <span> | |
| A helpful tooltip! | |
| </span> | |
| </ClickOutside> |