Rust Language – Hello World

What is RUST?

Rust is an experimental, concurrent, multi-paradigm, compiled programming language developed by Mozilla Labs. It is designed to be practical, supporting pure-functional, concurrent-actor, imperative-procedural, and object-oriented styles. /wikipedia/

How to install it on your Gnu/Linux box?
Pre-requirements:

  • g++ 4.4 or clang++ 3.x
  • python 2.6 or later
  • perl 5.0 or later
  • gnu make 3.81 or later
  • curl


Download latest version (0.2 pre at the moment)

git clone https://github.com/mozilla/rust.git

Make it

$cd rust
$./configure
$ make & make install

Note:

It takes a lot of time and you do need an active internet connection during the compiling process.

Hack
Open your Geany or your favourite IDE and write this:

use std;

fn hello_world(name: str) {  
	let greetings: str = "Hello World, "+ name +"! and Здравей свят! and 您好,世界!";
	std::io::println(greetings);
}


fn main(args: [str]) {
	hello_world(args[1]);
}

Save it as helloworld.rs

Compile it

$rustc helloworld.rs

Execute

$./helloworld.rs Bogo //put here your name

One response to “Rust Language – Hello World”

  1. Erik says:

    Code above appears to be broken in 0.6. Also, at least on Windows the Rust compiler doesn’t handle the Unicode byte-order-mark correctly, so I can’t get foreign characters to work.

    The code below works:

    fn usage() {
    io::println(fmt!(“%s\n”, “Hello world”));
    }

    fn hello_world(name: &str) -> () {
    io::println(fmt!(“Hello %s\n”, name));
    }

    pub fn main() {
    let os_args = os::args();
    let args = os_args.tail();

    if !args.is_empty() {
    for os_args.each |command| {
    hello_world(*command);
    }
    }

    usage();
    }

Leave a Reply

Your email address will not be published. Required fields are marked *