Web Development

Introducing web-sys: A crate to enable interaction with all the standard web platform methods

2 min read

Yesterday, the Rust and WebAssembly team introduced a new crate called web-sys, which provides raw bindings to all the Web APIs. The web-sys crate enables the interaction with all the standard web platform methods.

Why use web-sys crate?

Web includes many APIs and adding support for all of them manually can prove to be a very hectic task. These APIs are standardized with the same interface definition language (Web IDL). The developers came up with a new Web IDL frontend to wasm-bindgen.

When the frontend was ready, they took the interface definitions for all the Web APIs from all their standards to automatically generate a -sys crate from them, known as web-sys. Bringing all these APIs at one place will make it easy for people to write neat libraries and other utility crates for the Web.

The wasm-bindgen architecture

The new wasm-bindgen architecture is shown below:

Source: GitHub

A frontend named wasm-bindgen-webidl is added to wasm-bindgen, which takes in Web IDL interface definitions and emits the internal Abstract Syntax Tree (AST) of wasm-bindgen.

Once we have the AST, emitting zero-overhead Rust and JavaScript glue code to do type conversion and shepherding of function parameters is the same as normal #[wasm_bindgen] annotations.

Using this architecture makes wasm-bindgen future-compatible with the host bindings proposal. This proposal focuses on making WebAssembly to directly call into native DOM methods without going through a JavaScript shim. This will provide better performance since calls from wasm can be statically validated to type check once at compilation time, rather than dynamically on every single call.

To know more about the web-sys crate, check out the official announcement at GitHub.

Read Next

Introducing Wasmjit: A kernel mode WebAssembly runtime for Linux

Why is everyone going crazy over WebAssembly?

Next.js 7, framework for server-rendered React applications, releases with support for React context API and Webassembly

Bhagyashree R

Share
Published by
Bhagyashree R

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago