Online Rust CLI Runner

Execute Rust code in a safe CLI-like interface—ideal for testing and learning Rust syntax.

🚀 246,443 total executions (414 this month)

Udemy Logo Udemy Affiliates: Popular Rust courses people love

Loading...

🦀 About This Rust Online Executor

The CodeUtility Rust Executor lets you write and run Rust code directly in your browser — no installation, toolchain setup, or local environment required. It’s powered by a secure sandbox that supports real Rust compiler versions 1.70, 1.72, 1.73, and 1.74.

This tool compiles and executes your Rust programs in the cloud using a genuine rustc compiler, ensuring accurate and consistent results. You can experiment with variables, ownership, borrowing, pattern matching, traits, generics, and other modern Rust features with ease.

It’s ideal for learning Rust’s core concepts — especially memory safety, error handling, and concurrency — without needing to install Cargo or any local setup. Everything runs directly in your browser within seconds.

⚙️ How to Use This Tool

  • 1. Select a Rust version (1.70, 1.72, 1.73, or 1.74) from the dropdown at the top of the editor.
  • 2. Write or paste your Rust code into the editor area.
  • 3. Click Run to compile and execute your program — output will appear in the console below.
  • 4. While running, a Stop button appears — click it to stop execution early.
  • 5. Use Fix Code to automatically correct minor formatting or syntax issues.
  • 6. After fixing, a Fixes button appears — click it to review recent fixes.
  • 7. Use the Upload button to import code from a local file, or the Download button to save your current code from the editor.
  • 8. Each execution runs up to 20 seconds before automatically terminating.

🧠 Tip: This environment runs real Rust code securely in your browser — no login or setup required.

💡 Rust Basics & Examples You Can Try Above

1. Declaring Variables and Constants

Use let to declare variables. Use const for constants and mut for mutable variables.

let x = 10;
let pi: f64 = 3.14;
let name = "Alice";
let is_active = true;

const MAX_USERS: u32 = 100;

2. Conditionals (if / match)

Rust uses if for conditions and match for pattern matching.

let x = 2;
if x == 1 {
    println!("One");
} else if x == 2 {
    println!("Two");
} else {
    println!("Other");
}

match x {
    1 => println!("One"),
    2 => println!("Two"),
    _ => println!("Other"),
}

3. Loops

Rust supports for, while, and infinite loop.

for i in 0..3 {
    println!("{}", i);
}

let mut n = 3;
while n > 0 {
    println!("{}", n);
    n -= 1;
}

4. Arrays

Fixed-size arrays in Rust use square brackets. Use slices for views.

let nums = [10, 20, 30];
println!("{}", nums[1]);

5. Vectors (Dynamic Arrays)

Vec is used for dynamic arrays.

let mut fruits = vec!["apple", "banana"];
fruits.push("cherry");
fruits.pop();

for fruit in &fruits {
    println!("{}", fruit);
}

6. Console Input/Output

Use println! for output and std::io for input.

use std::io;

let mut name = String::new();
println!("Enter your name:");
io::stdin().read_line(&mut name).unwrap();
println!("Hello, {}", name.trim());

7. Functions

Functions use fn and can return values using ->.

fn greet(name: &str) -> String {
    format!("Hello, {}", name)
}

println!("{}", greet("Alice"));

8. HashMaps

Use std::collections::HashMap for key-value data.

use std::collections::HashMap;

let mut person = HashMap::new();
person.insert("name", "Bob");
println!("{}", person["name"])

9. Error Handling

Rust handles errors using Result and match or unwrap().

fn fail() -> Result<(), String> {
    Err("Something went wrong".to_string())
}

match fail() {
    Ok(_) => println!("Success"),
    Err(e) => println!("{}", e),
}

10. File I/O

Use std::fs to read and write files.

use std::fs;

fs::write("file.txt", "Hello File").unwrap();
let content = fs::read_to_string("file.txt").unwrap();
println!("{}", content);

11. String Manipulation

Strings in Rust are heap-allocated and support many methods.

let mut text = String::from(" Hello Rust ");
println!("{}", text.trim());
println!("{}", text.to_uppercase());
text = text.replace("Hello", "Hi");
println!("{}", text);

12. Structs & Methods

Rust uses struct for data types and impl for methods.

struct Person {
    name: String,
}

impl Person {
    fn greet(&self) -> String {
        format!("Hi, I'm {}", self.name)
    }
}

let p = Person { name: "Alice".to_string() };
println!("{}", p.greet());

13. References & Borrowing

Rust uses & to borrow values and &mut for mutable references.

fn update(x: &mut i32) {
    *x += 1;
}

let mut value = 10;
update(&mut value);
println!("{}", value);