Rust Syntax References

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.

Most Useful Rust Syntax References

RustSyntax

Main Function

Code example
fn main() { }

The entry point of a Rust program.

Learn More
RustSyntax

Print Output

Code example
println!("Hello {}", name);

Prints a formatted line.

Learn More
RustSyntax

Declare a Variable

Code example
let x = 5; let mut y = 1;

Variables are immutable by default.

Learn More
RustSyntax

Define a Function

Code example
fn add(a: i32, b: i32) -> i32 { a + b }

Defines a function with a return type.

Learn More
RustSyntax

Match Expression

Code example
match n { 1 => "one", _ => "other", }

Matches a value against patterns.

Learn More
RustSyntax

For Loop over a Range

Code example
for i in 0..10 { }

Loops over a range.

Learn More
RustSyntax

Create a Vector

Code example
let mut v = vec![1, 2, 3]; v.push(4);

Creates a growable list.

Learn More
RustSyntax

Borrow a Reference

Code example
fn len(s: &String) -> usize { s.len() }

Passes a value without moving it.

Learn More

More Rust Syntax References

Frequently Asked Questions

What does this Rust syntax reference cover?

It covers 20 common Rust patterns and examples, including Main Function, Print Output, Declare a Variable, Define a Function, Match Expression.

Can I copy the Rust examples?

Yes. Each reference page includes a copyable code example.

What affects these Rust examples?

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.