Main Function
fn main() {
}The entry point of a Rust program.
Rust syntax quick reference: ownership, structs, enums, match, Option/Result and Cargo, from The Rust Book. Every item below is clearly marked as a shortcut, command, or syntax reference.
fn main() {
}The entry point of a Rust program.
println!("Hello {}", name);Prints a formatted line.
let x = 5;
let mut y = 1;Variables are immutable by default.
fn add(a: i32, b: i32) -> i32 {
a + b
}Defines a function with a return type.
match n {
1 => "one",
_ => "other",
}Matches a value against patterns.
for i in 0..10 {
}Loops over a range.
let mut v = vec![1, 2, 3];
v.push(4);Creates a growable list.
fn len(s: &String) -> usize { s.len() }Passes a value without moving it.
The entry point of a Rust program.
fn main() {
}Prints a formatted line.
println!("Hello {}", name);Variables are immutable by default.
let x = 5;
let mut y = 1;Defines a function with a return type.
fn add(a: i32, b: i32) -> i32 {
a + b
}Matches a value against patterns.
match n {
1 => "one",
_ => "other",
}Loops over a range.
for i in 0..10 {
}Creates a growable list.
let mut v = vec![1, 2, 3];
v.push(4);Passes a value without moving it.
fn len(s: &String) -> usize { s.len() }Groups related fields.
struct User {
name: String,
age: u32,
}Creates and runs a project.
cargo new app
cargo runIf returns a value.
let label = if n > 0 { "pos" } else { "neg" };Creates an owned string.
let s = String::from("hi");Adds methods to a struct.
impl User {
fn greet(&self) -> String { format!("Hi {}", self.name) }
}Represents a value that may be missing.
if let Some(x) = maybe {
}Returns errors up the call stack.
let text = std::fs::read_to_string("a.txt")?;Defines a type with variants.
enum Shape {
Circle(f64),
Square(f64),
}Describes shared behavior.
trait Area {
fn area(&self) -> f64;
}Transforms a collection.
v.iter().filter(|x| **x > 1).map(|x| x * 2).collect::<Vec<_>>()Declares a typed constant.
const MAX: u32 = 100;Loops until break.
loop {
break;
}It covers 20 common Rust patterns and examples, including Main Function, Print Output, Declare a Variable, Define a Function, Match Expression.
Yes. Each reference page includes a copyable code example.
Check the linked documentation for language or runtime version requirements. Libraries, file paths, terminal quoting and environment settings can differ across systems; no blanket platform compatibility is implied.