GithubHelp home page GithubHelp logo

gnoff / wasm-bindgen Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rustwasm/wasm-bindgen

0.0 2.0 0.0 15.19 MB

Facilitating high-level interactions between wasm modules and JavaScript

Home Page: https://rustwasm.github.io/docs/wasm-bindgen/

License: Apache License 2.0

JavaScript 4.66% HTML 0.78% WebAssembly 0.06% Rust 94.22% Shell 0.21% TypeScript 0.08%

wasm-bindgen's Introduction

wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript.

Build Status Crates.io version Download docs.rs docs

Built with ๐Ÿฆ€๐Ÿ•ธ by The Rust and WebAssembly Working Group

Example

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

use wasm_bindgen::prelude::*;

// Import the `window.alert` function from the Web.
#[wasm_bindgen]
extern "C" {
    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 with ECMAScript modules!

import { greet } from "./hello_world";

greet("World!");

Features

  • Lightweight. Only pay for what you use. wasm-bindgen only generates bindings and glue for the JavaScript imports you actually use and Rust functionality that you export. For example, importing and using the document.querySelector method doesn't cause Node.prototype.appendChild or window.alert to be included in the bindings as well.

  • ECMAScript modules. Just import WebAssembly modules the same way you would import JavaScript modules. Future compatible with WebAssembly modules and ECMAScript modules integration.

  • Designed with the "Web IDL bindings" proposal in mind. Eventually, there won't be any JavaScript shims between Rust-generated wasm functions and native DOM methods. Because the wasm functions are statically type checked, some of those native methods' dynamic type checks should become unnecessary, promising to unlock even-faster-than-JavaScript DOM access.

Guide

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

You can find general documentation about using Rust and WebAssembly together here.

API Docs

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

afdw avatar akryvomaz avatar alexcrichton avatar belfz avatar brisad avatar c410-f3r avatar chinedufn avatar dependabot-support avatar derekdreery avatar eminence avatar fitzgen avatar hywan avatar ibaryshnikov avatar jannikkeye avatar jonathan-s avatar jonathankingston avatar jrakow avatar konstin avatar ohanar avatar pauan avatar pepsighan avatar rreverser avatar rylev avatar sendilkumarn avatar t5uku5hi avatar toversus avatar twilco avatar wismer avatar xeqlol avatar xtuc 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.