b2KIT

Rust to WASM Playground

Compile and run Rust snippets targeting WebAssembly with instant output and error reporting.

Tested tool guide Tested browser tools Checked August 16, 2026

What Rust to WASM Playground does, with a checked example

This playground compiles a Rust snippet to a WebAssembly module and runs it in the page, returning the program's output and the compiler's diagnostics without a local toolchain. Paste a complete program with a main() entry point and press Run; the module executes in a sandbox that has no file system, network, or threads. The usual surprise is the target itself: wasm32 uses 32-bit pointers, so code that assumes 64-bit widths can behave differently here, and standard-library calls that touch the host compile but panic at runtime.

Worked example

A concrete input and expected output from the current implementation.

Input

fn main() {
    for i in 1..=6 {
        println!("{} x {} = {}", i, i, i * i);
    }
}

Expected output

1 x 1 = 1
2 x 2 = 4
3 x 3 = 9
4 x 4 = 16
5 x 5 = 25
6 x 6 = 36

The inclusive range 1..=6 makes the loop run for i = 1 through 6, and each iteration prints i, i, and i * i, so the output lines show the squares 1, 4, 9, 16, 25, 36. The playground runs main() as the entry point and shows what the program writes to standard output.

How the result is produced

1

Compile step

Every Run compiles the editor's source into a WebAssembly module for the wasm32 target before anything executes, so rustc's diagnostics - borrow-checker, type, and lifetime errors - appear first and no module is produced until the source is valid. Because the target is wasm32, pointer and integer widths follow WebAssembly, not the host machine.

2

Run and output

The program must declare a main() entry point; running the module executes it inside a sandbox that offers no file system, network, or threads. Output is captured from the program's standard output and presented as the result, while a panic stops the run and its message is reported in place of normal output.

Good uses

  • Prototyping an algorithm or data structure in Rust without installing a toolchain: paste a self-contained program, run it, and read the result or the compile error in the same tab.
  • Checking how a snippet behaves on a 32-bit target before deploying to wasm: usize is 32 bits here, so code that assumes 64-bit pointers often shows its bug in the output.
  • Reproducing a compile error or runtime panic from a Rust snippet shared in a forum or issue thread, then experimenting with fixes until it compiles and runs.

Limits and checks

  • A run that prints nothing is not proof the code did nothing: results appear only through println! and similar output. A program that computes a value but never prints it finishes with an empty output pane, which is easy to misread as a failure or a no-op.
  • Success here is not success on native hardware. The sandbox denies file, network, and thread operations with panics (commonly reporting 'not implemented'), and integer and pointer widths are 32 bits, so a program that runs cleanly on a desktop can panic or produce different numbers in this environment.
  • The tool compiles one snippet as a single crate, so imports of external crates resolve only if the playground provides them; a snippet that relies on Cargo dependencies will fail at compile time and must be reduced to a self-contained file first.

Common questions

Why does a program that runs fine on my laptop panic here?

Because the module runs on the wasm32 target in a sandbox, not on your operating system. The standard library for this target keeps the language but leaves out the host: file, network, and thread calls are stubs that panic, and usize is 32 bits. Computation-only programs usually run as expected; anything touching the outside world usually does not.

Is my source code uploaded to a server?

No. The snippet stays in your browser: compilation and execution both happen inside the page, so the code is never sent anywhere. That also means behavior depends on the toolchain version the playground ships, which may be older or newer than your local install - results are authoritative for this environment, not for your machine.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools