راست (زبان برنامه‌نویسی)
نمونه‌ها

نمونه کد زیر برای Rust نسخه ۰٫۸ معتبر می‌باشد. نحو و معناشناسی ممکن است در نسخه‌های بعدی تغییر یابد.
برنامه Hello World:
fn main() {
    println!("Hello, World");
}
دو نمونه از تابع فاکتوریل در ساختارهای بازگشتی و ترتیبی :
/* The branches in this function exhibit Rust's optional implicit return
   values, which can be utilized where a more "functional" style is preferred.
   Unlike C++ and related languages, Rust's `if` construct is an expression
   rather than a statement, and thus has a return value of its own. */
fn recursive_factorial(n: i32) -> i32 {
    if n <= 1 { 1 }
    else { n * recursive_factorial(n - 1) }
}

fn iterative_factorial(n: i32) -> i32 {
    // Variables are declared with `let`.
    // The `mut` keyword allows these variables to be mutated.
    let mut i = 1;
    let mut result = 1;
    while i <= n {
        result *= i;
        i += 1;
    }
    return result; // An explicit return, in contrast to the prior function.
}

fn main() {
    println!("Recursive result: {:?}", recursive_factorial(10));
    println!("Iterative result: {:?}", iterative_factorial(10));
}
یک نمایش ساده از قابلیت همزمانی ساده از Rust:
/* This function creates ten "tasks" that all execute concurrently. Run it
   several times and observe the irregular output that results as each task
   races on stdout, due to the fact that each task may yield both between
   successive calls to `println` and within the `println` function itself. */
fn main() {
    // This string is immutable, so it can safely be accessed from multiple tasks.
    let message = "Look at me, I'm in a lightweight thread!";
    // `for` loops work with any type that implements the `Iterator` trait.
    for num in range(0, 10) {
        do spawn {
            println(message);
            // `println!` is a macro that statically verifies a format string.
            // Macros are structural (as in Scheme) rather than textual (as in C).
            println!("This message brought to you by task {:?}.", num);
        }
    }
}
یک نمایش ساده از اشاره‌گرهای هوشمند یگانی همراه با tagged unions و روش‌ها:
use IntList::{Node, Empty};

// This program defines a recursive data structure and implements methods upon it.
// Recursive data structures require a layer of indirection, which is provided here
// by a unique pointer, constructed via the `Box::new` constructor. These are
// analogous to the C++ library type `std::unique_ptr`, though with more static
// safety guarantees.
fn main() {
    let list = IntList::new().prepend(3).prepend(2).prepend(1);
    println!("Sum of all values in the list: {}.", list.sum());
    println!("Sum of all doubled values in the list: {}.", list.multiply_by(2).sum());
}

// `enum` defines a tagged union that may be one of several different kinds of values at runtime.
// The type here will either contain no value, or a value and a pointer to another `IntList`.
enum IntList {
    Node(i32, Box<IntList>),
    Empty
}

// An `impl` block allows methods to be defined on a type.
impl IntList {
    fn new() -> Box<IntList> {
        Box::new(Empty)
    }

    fn prepend(self, value: i32) -> Box<IntList> {
        Box::new(Node(value, Box::new(self)))
    }

    fn sum(&self) -> i32 {
        // `match` expressions are the typical way of employing pattern-matching,
        // and are somewhat analogous to the `switch` statement from C and C++.
        match *self {
            Node(value, ref next) => value + next.sum(),
            Empty => 0
        }
    }

    fn multiply_by(&self, n: i32) -> Box<IntList> {
        match *self {
            Node(value, ref next) => Box::new(Node(value * n, next.multiply_by(n))),
            Empty => Box::new(Empty)
        }
    }
}