XCODX |

Rust Online Compiler & Interpreter

Select Language
Online Code Compiler
Full HTML IDE
Py main.py
Program Output Ready
  Welcome to XCODX Online Compiler

  Quick Start:
  Ctrl+Enter  Run code
  Ctrl+S      Save / Download
  Ctrl+L      Clear output

  Select a language and start coding.
Success
Operation completed

About Rust

Rust is a systems programming language that grew out of a personal project by Graydon Hoare, was sponsored by Mozilla, and reached its stable 1.0 release in 2015. It offers the low-level control and raw speed of C or C++, but replaces manual memory management with an ownership and borrowing model that the compiler verifies before your program ever runs. There is no garbage collector, yet whole categories of bugs -- dangling pointers, data races, use-after-free -- are caught at compile time instead of in production. That guarantee is why Rust now shows up in the Linux kernel, Firefox, AWS Firecracker, Cloudflare's edge, and Discord's backend services. The trade-off is a steeper learning curve, because the borrow checker rejects code that other languages would happily run and crash on later. On XCODX you can explore that compiler feedback loop directly in the browser, with no local toolchain to install.

Hello World in Rust

use std::collections::HashMap;

#[derive(Debug)]
struct Language {
    name: String,
    year: u32,
}

fn main() {
    let langs = vec![
        Language { name: String::from("Rust"), year: 2015 },
        Language { name: String::from("Go"), year: 2009 },
        Language { name: String::from("Swift"), year: 2014 },
    ];

    // Iterators: average release year without a manual loop counter
    let total: u32 = langs.iter().map(|l| l.year).sum();
    let avg = total as f64 / langs.len() as f64;

    for lang in &langs {
        println!("{} was released in {}", lang.name, lang.year);
    }
    println!("Average release year: {:.1}", avg);

    // HashMap from std: group names by first letter
    let mut by_letter: HashMap<char, u32> = HashMap::new();
    for lang in &langs {
        let first = lang.name.chars().next().unwrap();
        *by_letter.entry(first).or_insert(0) += 1;
    }
    println!("Grouped by first letter: {:?}", by_letter);
}

When to use Rust

Rust shines wherever speed and correctness matter at the same time: operating-system components, browser and game engines, databases, WebAssembly modules, network services, and command-line tools that must not leak memory or crash. Choose it when you would otherwise reach for C or C++ but want the compiler to prove your memory access is sound, or when you need fearless concurrency across threads. It is a poor fit for quick throwaway scripts and early prototypes where the data model changes every hour, because the borrow checker's discipline is overhead you feel most while the design is still fluid. For that kind of exploratory work a garbage-collected language like Python or Go usually gets you moving faster.

Common questions

How do I read input from stdin in Rust?

Use std::io::stdin() with a mutable String and read_line, then trim the trailing newline, for example: let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap();. On XCODX the terminal is live, so read_line pauses and waits while you type -- press Enter to send a line and Ctrl+D to close the stream. You can also paste everything up front into the Stdin Box before you run the program.

Can I add crates from crates.io like serde, tokio, or rand?

No. The sandbox compiles a single crate with rustc using the standard library only -- there is no Cargo, no cargo add, and no network to reach crates.io, so serde, tokio, rand, and every other external crate are unavailable. Anything in std works fine, including collections, iterators, threads, formatting, and std::io. Dependency-heavy projects need a local Rust toolchain instead.

Why won't my Rust code compile with borrow checker errors?

The borrow checker enforces two rules at compile time: every value has a single owner, and you may hold either many shared (&) references or one mutable (&mut) reference, never both at once. Messages like 'cannot borrow as mutable' or 'value moved here' mean two parts of your code want conflicting access to the same data. They are compile-time only, and fixing them usually means cloning, narrowing a scope, or borrowing later -- once it builds, the program is memory-safe.

Is Rust faster than Go or C++?

Rust runs at roughly the same speed as C++ and generally faster than Go, because it compiles to native code with no garbage collector and no runtime overhead. Go trades some speed for a simpler model and built-in goroutines, while C++ can match Rust but without the compile-time safety guarantees. In this sandbox a short run timeout limits heavy benchmarks, so it is better suited to learning the language than to timing tight loops.

Does a Rust program need a main function to run here?

Yes. A runnable Rust program needs fn main() as its entry point, and that is exactly what the sandbox compiles and executes. You do not need a Cargo.toml or a project layout -- paste a single file with a main function and run it. Library-style code without main will compile-check but produce no output.

Can Rust save files or make network requests in this compiler?

No. Each run gets a fresh, temporary filesystem that is discarded when the program ends, and there is no outbound network access, so HTTP clients and sockets fail to connect. You can still open, write, and read files within a single run to practice std::fs, but nothing carries over to the next run.

How Rust runs on XCODX

Sandbox filename
main.rs
Entry point
single main source file
Editor grammar
rust
Reading stdin
io::stdin().read_line()
Input delivery
live WebSocket stream
Prompt flushing
unbuffered automatically (print! macro-shadowed to flush is prepended on live runs)
Compile limit
10 s
Run limit
3 s batch · up to 3 min live
Memory
256 MB per stage
Max source
50,000 characters

Default program on this page

fn main() {
    println!("Hello from Rust!");
    println!("Welcome to XCODX Online Compiler!");
}