Rust 0.1

Version of implementation Rust of programming language Rust

Alpha-release, released on January 20th, 2012. Supports most of the intended features of the language.

Examples:

Hello, World! - Rust (415):

use std;
import std::io;

fn main() {
    io::println("Hello, World!");
}

Factorial - Rust (416):

This example uses recursive factorial definition. Due to uint overflow values of 13! and larger are calculated incorrectly.

use std;
import std::io;

fn factorial(x: int) -> uint {
  if (x <= 1) {
    ret 1u;
  } else {
    ret (x as uint) * factorial(x - 1);
  }
}

fn main() {
  let i = 0;
  while i <= 16 {
    io::println(#fmt("%d! = %u", i, factorial(i)));
    i = i + 1;
  }
}

Fibonacci numbers - Rust (417):

This example calculates Fibonacci numbers recursively.

use std;
import std::io;

fn fibonacci(x: int) -> int {
  if (x <= 2) {
    ret 1;
  } else {
    ret fibonacci(x - 1) + fibonacci(x - 2);
  }
}

fn main() {
  let i = 1;
  while i <= 16 {
    io::print(#fmt("%d, ", fibonacci(i)));
    i = i + 1;
  }
  io::println("...");
}