Back to home
rust programming language icon

Rust Online Compiler

Practice Rust right here — no installs, no signups.

Rust Compiler
Output
Code runs on the Play with Coding execution engine — your code is saved locally for next time.

About the Rust online compiler

Rust gives you C-level performance with compile-time memory safety and no garbage collector. The trade is a strict compiler — but Rust's error messages are the friendliest of any systems language, usually telling you the exact fix. This online Rust compiler shows those messages in full.

Practise ownership and borrowing, pattern matching with match, Option and Result instead of null and exceptions, structs and impl blocks, and iterators. Fighting the borrow checker for an hour teaches more about memory than a semester of theory.

  • Understanding ownership, moves and borrows
  • Practising match and exhaustive pattern handling
  • Learning Option/Result error handling
  • Testing iterator chains without a local toolchain

Rust sample programs you can run right now

Copy any snippet into the editor above and press Run. Each one is short on purpose — retype it from memory afterwards.

Ownership and borrowing

fn length(s: &String) -> usize { s.len() }

fn main() {
    let name = String::from("Play with Coding");
    println!("{} chars", length(&name));
    println!("still usable: {}", name);
}

Passing &name borrows the value instead of moving it, so name is still valid afterwards.

Pattern matching on Option

fn main() {
    let nums = vec![10, 20, 30];
    match nums.get(5) {
        Some(v) => println!("found {}", v),
        None => println!("index out of range"),
    }
}

get returns Option instead of panicking, and match forces you to handle both cases.

Common Rust errors and how to fix them

borrow of moved value

Why: The value was moved into another binding or function and is no longer owned here.

Fix: Borrow with & instead of moving, or .clone() when a copy is acceptable.

cannot borrow `x` as mutable more than once at a time

Why: Two mutable references overlap.

Fix: Shorten the first borrow's scope so it ends before the second begins.

mismatched types: expected `&str`, found `String`

Why: String and &str are different types.

Fix: Use &value or value.as_str() to convert.

Rust syntax cheatsheet

ConceptSyntax
Entry pointfn main() { }
Printprintln!("{}", x);
Mutable variablelet mut x = 5;
Vectorlet v = vec![1, 2, 3];
Struct + implstruct P; impl P { fn go(&self) {} }
Matchmatch v { Some(x) => .., None => .. }

Rust compiler FAQs

Can I use external crates?

No — snippets compile without Cargo dependencies, so stick to the standard library.

Why does the compiler reject working-looking code?

Usually the borrow checker. Read the help: line in the error — it almost always names the exact fix.

Keep going after the compiler

Running snippets builds speed; the 17-chapter course builds understanding. Work through the Rust chapters, take the quiz, then claim your certificate.

Other compilers: JavaScript compiler, TypeScript compiler, Python 3 compiler, Java compiler, C compiler, C++ compiler, Go compiler, HTML compiler, CSS compiler, SQLite compiler