Skip to main content

Runnable Code Blocks (API Playground)

Code blocks marked with run execute directly in the browser, with results shown inline. No backend required — JavaScript runs on the page, and Rust code is compiled and run through the public Rust Playground API.

Network dependency

Running requires the browser to reach the target API. The Rust Playground and GitHub API occasionally time out in mainland China; on failure the error panel shows troubleshooting hints — just retry later.

Running Rust​

Click the "Run" button below. The code is sent to the Rust Playground, and the panel shows program stdout plus cargo build logs (stderr):

fn main() {
let pins = ["GPIO1_A0", "GPIO1_A1", "I2C1_SDA", "I2C1_SCL"];
for (i, pin) in pins.iter().enumerate() {
println!("pin {i}: {pin}");
}
let sum: u32 = (1..=100).sum();
println!("1+2+...+100 = {sum}");
}
Rust · stable/2024

A compile error is not a "request failure" — it still runs and shows the error in stderr:

fn main() {
let x: u32 = "not a number";
println!("{x}");
}
Rust · stable/2024

Override compiler options via the metastring (edition / channel / mode):

fn main() {
// A simple example that behaves the same on 2021 and 2024 editions
let v = vec![1, 2, 3];
let total: i32 = v.iter().sum();
println!("total = {total}");
}
Rust · stable/2021

Running JavaScript​

js run blocks execute on the page. Top-level await works, and both fetch results and console output are captured:

const res = await fetch('https://api.github.com/repos/facebook/docusaurus');
const repo = await res.json();
console.log('stars:', repo.stargazers_count);
console.log('topics:', repo.topics);
JavaScript

Send a POST request:

const res = await fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({title: 'hello', body: 'from browser', userId: 1}),
});
console.log('status:', res.status);
console.log(await res.json());
JavaScript

Author guide​

Syntax​

MarkupEffect
```js runExecute JS on the page (new Function, top-level await supported)
```rust runSubmit to the Rust Playground
```rust run edition=2024 channel=stable mode=releaseOverride playground options (defaults: stable/debug/2024)

Limitations​

  • CORS: the JS path requires the target API to allow cross-origin requests (Access-Control-Allow-Origin), otherwise the browser blocks them — the error panel explains.
  • Timeouts: 15s per request, 30s overall for JS, 60s for Rust (including compilation).
  • Local cache: successful results are cached in localStorage (7 days, max 100 entries); a cache hit skips the request entirely. Editing the snippet or its options invalidates the key automatically. Use "Run again" on the panel to bypass the cache.
  • The Rust Playground is a free third-party service (no SLA, occasional rate limits); it compiles a single-file bin crate with no network or device access.
  • CSP: js run relies on unsafe-eval; a future strict CSP would break the JS path (rust is unaffected).