Learn Rust-playground - 10 Code Examples & CST Typing Practice Test
Rust Playground is an official web-based tool for writing, compiling, and running Rust code in a browser. It allows developers to experiment with Rust code snippets, test features, and share examples without needing a local Rust setup.
Learn RUST-PLAYGROUND with Real Code Examples
Updated Nov 26, 2025
Code Sample Descriptions
Hello World in Rust Playground
fn main() {
println!("Hello, world!");
}
A basic Hello World program written and run in Rust Playground.
Rust Variables Example
fn main() {
let x = 42;
let name = "Alice";
println!("x = {}, name = {}", x, name);
}
Declares variables and prints them in Rust Playground.
Rust If Statement Example
fn main() {
let num = -3;
if num > 0 {
println!("Positive");
} else {
println!("Non-positive");
}
}
Checks if a number is positive or negative in Rust.
Rust Loop Example
fn main() {
for i in 1..=5 {
println!("{}", i);
}
}
Prints numbers from 1 to 5 using a for loop in Rust.
Rust Function Example
fn add(a: i32, b: i32) -> i32 {
a + b
}
fn main() {
println!("Sum: {}", add(3, 4));
}
Defines a function to add two numbers and prints the result.
Rust Vector Example
fn main() {
let nums = vec![10, 20, 30];
for n in nums {
println!("{}", n);
}
}
Creates a vector and iterates over it in Rust Playground.
Rust Mutable Variable Example
fn main() {
let mut counter = 0;
counter += 1;
println!("Counter: {}", counter);
}
Shows mutable variables and updates their values in Rust.
Rust Match Statement Example
fn main() {
let x = 2;
match x {
1 => println!("One"),
2 => println!("Two"),
_ => println!("Other"),
}
}
Uses match to handle multiple cases in Rust Playground.
Rust Struct Example
struct Person {
name: String,
age: u8,
}
fn main() {
let p = Person { name: String::from("Alice"), age: 30 };
println!("{} is {} years old", p.name, p.age);
}
Defines a struct and prints its fields in Rust Playground.
Rust Ownership Example
fn main() {
let s1 = String::from("hello");
let s2 = s1;
// println!("{}", s1); // This would cause an error
println!("{}", s2);
}
Demonstrates basic ownership rules in Rust Playground.
Frequently Asked Questions about Rust-playground
What is Rust-playground?
Rust Playground is an official web-based tool for writing, compiling, and running Rust code in a browser. It allows developers to experiment with Rust code snippets, test features, and share examples without needing a local Rust setup.
What are the primary use cases for Rust-playground?
Learning Rust programming online. Experimenting with Rust features and syntax. Testing Rust code snippets before integrating into larger projects. Demonstrating Rust code in tutorials, blogs, or forums. Sharing reproducible examples with other Rust developers
What are the strengths of Rust-playground?
No Rust installation required. Instant compilation and execution. Safe sandbox environment for code testing. Useful for learning and rapid prototyping. Shareable examples simplify collaboration
What are the limitations of Rust-playground?
Limited to small code snippets; not suited for large projects. No persistent project storage. Cannot host web services or long-running processes. Resource limitations for compute-heavy code. Some system-dependent functionality may be restricted
How can I practice Rust-playground typing speed?
CodeSpeedTest offers 10+ real Rust-playground code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.