The Rust Playground
Return to the playgroundAbout
The playground is an open source project. If you have any suggestions for features, issues with the implementation, or just want to read the code for yourself, you are invited to participate!
This playground is modeled after the original Rust playground, and we owe a great debt to every contributor to that project.
This playground was created by Jake Goulding, part of Integer 32.
Features
Crates
The playground provides the top 100 most downloaded crates from crates.io, the crates from the Rust Cookbook, and all of their dependencies. To use a crate, add the appropriate extern crate foo
line to the code, or, since Rust Edition 2018, just use
any item from that crate.
See the complete list of crates to know what’s available.
Formatting code
rustfmt is a tool for formatting Rust code according to the Rust style guidelines. Click on the Format button in the Tools menu to automatically reformat your code.
Linting code
Clippy is a collection of lints to catch common mistakes and improve your Rust code. Click on the Clippy button in the Tools menu to see possible improvements to your code.
Checking code for undefined behavior
Miri is an interpreter for Rust’s mid-level intermediate representation (MIR) and can be used to detect certain kinds of undefined behavior in your unsafe Rust code. Click on the Miri button in the Tools menu to check.
Sharing code
Once you have some code worth saving or sharing, click on the Share button. This will create a GitHub Gist. You will also be provided with a URL to load that Gist back into the playground.
Linking to the playground with initial code
If you have a web page with Rust code that you’d like to show in action, you can link to the playground with the Rust code in the query parameter code
. Make sure to escape any special characters. Keep the code short, as URLs have limitations on the maximum length.
https://play.integer32.com/?code=fn main() { println!("hello world!"); }
Executing tests
If your code contains the #[test]
attribute and does not contain a main
method, cargo test
will be executed instead of cargo run
.
Compiling as a library
If your code contains the #![crate_type="lib"]
attribute, cargo build
will be executed instead of cargo run
.
Output formats
Instead of executing the code, you can also see intermediate output of the compiler as x86_64 assembly, LLVM IR, Rust MIR, or WebAssembly. This is often used in conjunction with the mode set to “Release” to see how the compiler has chosen to optimize some specific piece of code.
Compilation modes
Rust has two primary compilation modes: Debug and Release. Debug compiles code faster while Release performs more aggressive optimizations.
You can choose which mode to compile in using the Mode menu.
Rust channels
Rust releases new stable versions every 6 weeks. Between these stable releases, beta versions of the next stable release are made available. In addition, builds containing experimental features are produced nightly.
You can choose which channel to compile with using the Channel menu.
Customization
The Ajax.org Cloud9 Editor (Ace) is used to provide a better interface for editing code. Ace comes with several keybinding options (such as Emacs and Vim) as well as many themes.
You may also disable Ace completely, falling back to a simple HTML text area.
These options can be configured via the Config menu.
Persistence
The most recently entered code will be automatically saved in your browser’s local storage. This allows you to recover your last work even if you close the browser.
Local storage is a singleton resource, so if you use multiple windows, only the most recently saved code will be persisted.
Limitations
To prevent the playground from being used to attack other computers and to ensure it is available for everyone to use, some limitations are enforced.
- Network
- There is no network connection available during compilation or execution of user-submitted code.
- Memory
- The amount of memory the compiler and resulting executable use is limited.
- Execution Time
- The total compilation and execution time is limited.
- Disk
- The total disk space available to the compiler and resulting executable is limited.