Online Rust Compiler
Write, run and test Rust code online, right in your browser. This free online Rust compiler needs no installation or signup — just type your code and click Run.
Rust is a systems language focused on speed and memory safety without a garbage collector, used for tooling, WebAssembly and high-performance services.
How to use the Rust compiler
- Write or paste your Rust code in the editor.
- If your program reads input, open the I/O tab and type it into the STDIN box (one value per line).
- Click Run — the output and any errors appear in the output panel.
Sample: read input in Rust
use std::io;
fn main() {
let mut name = String::new();
io::stdin().read_line(&mut name).unwrap();
println!("Hello, {}!", name.trim());
}
Paste this into the editor, type your name in the STDIN box and click Run.
More Rust examples to try
Vectors and iterators
Reads numbers from STDIN and uses iterator methods to filter and sum them. Try 3 8 12 5.
use std::io::{self, Read};
fn main() {
let mut input = String::new();
io::stdin().read_to_string(&mut input).unwrap();
let nums: Vec<i32> = input.split_whitespace().map(|x| x.parse().unwrap()).collect();
let even_sum: i32 = nums.iter().filter(|&&x| x % 2 == 0).sum();
println!("Numbers: {:?}", nums);
println!("Sum of even numbers: {}", even_sum);
}
Structs, impl and Option
A struct with methods, and Option to handle a missing value safely.
struct Account {
owner: String,
balance: f64,
}
impl Account {
fn withdraw(&mut self, amount: f64) -> Option<f64> {
if amount > self.balance {
None
} else {
self.balance -= amount;
Some(self.balance)
}
}
}
fn main() {
let mut acc = Account { owner: String::from("Asha"), balance: 100.0 };
match acc.withdraw(30.0) {
Some(left) => println!("{} has {} left", acc.owner, left),
None => println!("Insufficient funds"),
}
}
Common Rust errors and how to fix them
error[E0382]: borrow of moved value- The value was moved to another variable or function. Pass a reference (
&value) or call.clone(). error[E0596]: cannot borrow as mutable- Declare the variable with
let mut, and pass it as&mut value. error[E0308]: mismatched types- The value type does not match what is expected, e.g.
i32vsf64. Convert withas f64or.parse(). thread 'main' panicked at 'called `Option::unwrap()` on a `None` value'unwrap()found nothing — often missing input. Provide STDIN, or handle the case withmatchorunwrap_or.
Frequently asked questions
Is this online Rust compiler free?
Yes. It is completely free to use, with no signup required to write and run code.
Do I need to install anything?
No. It all works from your web browser, so there is nothing to download or set up — it works on Windows, macOS, Linux, Chromebooks and phones.
How do I give input to my Rust program?
Before clicking Run, type the input into the STDIN box under the I/O tab, one value per line. Your program reads it as standard input, just like typing in a terminal.
Is this good for learning Rust?
Yes. It is ideal for practising exercises, testing small programs and trying out ideas from tutorials, because you can run code instantly without configuring an environment.
Other online compilers
Python Compiler Java Compiler C Compiler C++ Compiler C# Compiler JavaScript Compiler TypeScript Compiler SQL Compiler React.js Compiler HTML Compiler Go Compiler R Compiler PHP Compiler Kotlin Compiler Swift Compiler Scala Compiler Dart Compiler Ruby Compiler Prolog Compiler Perl Compiler
Editor powered by OneCompiler.