Code Monkey home page Code Monkey logo

wasm-bindgen's Introduction

wasm-bindgen

Facilitating high-level interactions between wasm modules and JavaScript.

Introduction blog post: "JavaScript to Rust and Back Again: A wasm-bindgen Tale"

Build Status Build status API Documentation on docs.rs

Import JavaScript things into Rust and export Rust things to JavaScript.

src/lib.rs:

#![feature(proc_macro, wasm_custom_section, wasm_import_module)]

extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;

// Import the `window.alert` function from the Web.
#[wasm_bindgen]
extern {
    fn alert(s: &str);
}

// Export a `greet` function from Rust to JavaScript, that alerts a
// hello message.
#[wasm_bindgen]
pub fn greet(name: &str) {
    alert(&format!("Hello, {}!", name));
}

Use exported Rust things from JavaScript!

index.js:

// Asynchronously load, compile, and import the Rust's WebAssembly
// and JavaScript interface.
import("./hello_world").then(module => {
  // Alert "Hello, World!"
  module.greet("World!");
});

Guide

๐Ÿ“š Read the wasm-bindgen guide here! ๐Ÿ“š

License

This project is licensed under either of

at your option.

Contribution

See the "Contributing" section of the guide for information on hacking on wasm-bindgen!

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

wasm-bindgen's People

Contributors

alexcrichton avatar fitzgen avatar ohanar avatar jonathan-s avatar sendilkumarn avatar wismer avatar rylev avatar pepsighan avatar konstin avatar elpiel avatar belfz avatar ashleygwilliams avatar xeqlol avatar dflemstr avatar spastorino avatar xtuc avatar kzvi avatar freemasen avatar johannhof avatar akryvomaz avatar hexywitch avatar tcr avatar sophiebits avatar rillian avatar killercup avatar noahlemen avatar nikvolf avatar nikgraf avatar froydnj avatar markandrus avatar

Watchers

James Cloos avatar Ivan Enderlin 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.