Rust playground

Run Rust online

Write, compile and run Rust online. A free Rust compiler in your browser, with the borrow checker's full error messages, input you can read and no sign-up.

Code main.rs

// Welcome to the coding.kitty Rust playground.
// Press Run (or Ctrl+Enter) to compile this and see what it prints.

use std::io;

struct Cat {
    name: String,
    age: u32,
}

impl Cat {
    fn describe(&self) -> String {
        format!("{} is {} and says meow", self.name, self.age)
    }
}

fn main() {
    let mut cats = vec![
        Cat { name: String::from("Miko"), age: 3 },
        Cat { name: String::from("Nola"), age: 5 },
        Cat { name: String::from("Baymax"), age: 1 },
    ];

    // Youngest first.
    cats.sort_by_key(|cat| cat.age);

    for (i, cat) in cats.iter().enumerate() {
        println!("{}. {}", i + 1, cat.describe());
    }

    // Type a name in the Input box and press Run again to see this line.
    let mut name = String::new();
    if io::stdin().read_line(&mut name).unwrap_or(0) > 0 {
        println!("Hello, {}!", name.trim());
    }
}
Output

Press Run to see what your code prints.

About this Rust playground

This is a Rust compiler you can use straight away. Write Rust in the editor, press Run, and your program is compiled with rustc and run. The output appears next to it: everything it prints, the compiler's errors and warnings with their explanations, any panic, and how long it took.

It compiles as edition 2024, in an isolated sandbox on our servers, with the same error messages you would get from cargo on your own machine. It is free, with nothing to install and no account needed.

What you can run

  • Rust 1.98, edition 2024, running one file per run, saved as main.rs.
  • Compiled, then run. Each run compiles your file with rustc --edition 2024 -o main main.rs and runs the program if it compiles. Compiler errors and warnings appear in the output like any other error.
  • Standard library only. The whole Rust standard library is there: collections such as Vec, HashMap and BTreeMap, strings, iterators, std::io, std::fmt, threads, Rc, RefCell and the rest. There is no package installer, and programs have no network access.
  • Limits: 10 seconds and 256 MB of memory per run, plus up to 20 seconds to compile first. Output past 64 KB is cut off, code can be up to 64 KB and input up to 16 KB.
  • Fair use: 5 runs a minute and 50 a day without an account, 10 a minute when you are signed in.

Reading input

Open the Input box under the editor and type what your program should read. It arrives as standard input: io::stdin().read_line reads the next line into a String, and .lines() goes through them all. With the box empty, read_line reads 0 bytes.

let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();

Frequently asked questions

Is this online Rust compiler free?

Yes. There is no sign-up and no limit on how much you can write. Signed-out visitors get a quick, usually invisible bot check when they press Run, and a fair-use cap of 5 runs a minute and 50 a day. Signing in raises it to 10 runs a minute.

Which version of Rust does it run?

Rust 1.98 (stable), compiling with rustc as edition 2024. It is a debug build, like cargo run without --release, so integer overflow panics rather than wrapping around silently.

Can I use crates from crates.io?

No. There is no Cargo and no network, so there is no Cargo.toml and no dependencies. The playground compiles one file, main.rs, against the standard library, which covers collections, strings, I/O and threads.

Why does compiling take a moment?

rustc checks borrows, lifetimes and types before it builds anything, which takes a moment even for a small program. Compiling has 20 seconds of its own, separate from your program's time, so a slow compile never cuts your program short.

Why did my program stop with a time-out?

Compiling gets up to 20 seconds of its own. Then the program gets 10 seconds and 256 MB of memory, and is stopped if it goes past either. The usual cause is a loop that never ends, or a read_line in a loop waiting for input that is not in the Input box.

Is my code saved or shared?

Your code is kept in your own browser so it is still there next time, and nowhere else. When you press Run it is sent to our code runner, run once in a sandbox, and thrown away. We do not store it or show it to anyone.

Keep going

Also in the playground: Python, JavaScript, TypeScript, SQL, Bash, C, C++, Go, Java, C#, Ruby, PHP, Lua, R, Dart, Swift.