Giter Club home page Giter Club logo

wasm-bindgen-demo's Introduction

wasm-bindgen demo

We have two example flavors of a demo getConfig function:

  • getConfigDeserializeInput: "Deserialized" version of the getConfig function, where the input is provided as a JSON string. It panics if the input is not a valid JSON string compatible with the GetConfigParams type
  • getConfigTyped: "Typed" version of the getConfig function, where the function input is provided as a GetConfigParams object directly.

Build Rust crates

cargo update -p wasm-bindgen 
cargo install -f [email protected]
  • Build the Rust libraries and the WebAssembly artifacts
chmod +x ./build.sh
OUT=../nodejs ./build.sh

Run Node.js examples

  • Open a terminal in the ./nodejs folder
  • Install the dependencies
npm i

Run the "Deserialized" version

npm run deserialized

Example output:

value@getConfigDeserializeInput: ok

panic@getConfigDeserializeInput: RuntimeError: unreachable
    at __rust_start_panic (wasm://wasm/00096816:wasm-function[331]:0x1c376)
    at rust_panic (wasm://wasm/00096816:wasm-function[207]:0x1baaa)
    at std::panicking::rust_panic_with_hook::hb09154fa23e06c37 (wasm://wasm/00096816:wasm-function[124]:0x196c4)
    at std::panicking::begin_panic_handler::{{closure}}::h6091c197f0d08bf0 (wasm://wasm/00096816:wasm-function[141]:0x1a313)
    at std::sys_common::backtrace::__rust_end_short_backtrace::h004afb3e6a867c40 (wasm://wasm/00096816:wasm-function[247]:0x1bf71)
    at rust_begin_unwind (wasm://wasm/00096816:wasm-function[197]:0x1b8c4)
    at core::panicking::panic_fmt::h9e229748e3ae9f9d (wasm://wasm/00096816:wasm-function[199]:0x1b945)
    at get_config::get_config_deserialize_input::h7b785da7ff3fbf0b (wasm://wasm/00096816:wasm-function[42]:0x1133c)
    at getConfigDeserializeInput (wasm://wasm/00096816:wasm-function[74]:0x15861)
    at module.exports.getConfigDeserializeInput (/Users/jkomyno/work/prisma/wasm-bindgen-demo/nodejs/src/wasm/get_config_wasm.js:125:14)

is error a panic?  true

Fin

Run the "Typed" version

npm run typed

Example output:

value@getConfigTyped: ok

error@getConfigTyped: Error: {"errorCode":"P1012","message":"This is an error"}
    at module.exports.__wbindgen_error_new (/Users/jkomyno/work/prisma/wasm-bindgen-demo/nodejs/src/wasm/get_config_wasm.js:184:17)
    at getConfigTyped (wasm://wasm/00096816:wasm-function[34]:0xf71c)
    at module.exports.getConfigTyped (/Users/jkomyno/work/prisma/wasm-bindgen-demo/nodejs/src/wasm/get_config_wasm.js:151:14)
    at main (/Users/jkomyno/work/prisma/wasm-bindgen-demo/nodejs/src/typed.ts:20:19)
    at Object.<anonymous> (/Users/jkomyno/work/prisma/wasm-bindgen-demo/nodejs/src/typed.ts:32:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module.m._compile (/Users/jkomyno/work/prisma/wasm-bindgen-demo/nodejs/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/jkomyno/work/prisma/wasm-bindgen-demo/nodejs/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)

errorOutput@getConfigTyped: { errorCode: 'P1012', message: 'This is an error' }

is error a panic?  false

Fin

wasm-bindgen-demo's People

Contributors

jkomyno avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.