Sunday, September 25, 2011

Hello World in Rust

Rust is a low level systems language developed by Mozilla for future embedding into their browser and other tools.  I was first made aware of it a year ago on the programming subreddit, but it looked a little too abstract to be useful.

I stumbled across it again yesterday and decided to compile the language tool chain and give it another go.

The language seems to have some very nice functionality, a cross between erlang and C, which may suit my fancy.

The toolchain was a bit annoying to set up, and I might go harrass the #Rust irc channel to see if there is a simpler way to get started.

In the mean time, here is hello world.

-- hello-world.rs -- 

use std;
import std::io;

fn main(argv: [str]) {

    let out = io::stdout();

    out.write_line("Hello world");
   
}

I compiled it with the command:

$ rustc hello-world.rs -o hello-world -L /usr/local/lib/rust/

$ ./hello-world
Hello world

Fin.

2 comments:

Anonymouz said...

Interestingly its slightly larger than a C hello world.

Unknown said...

When I wrote an equivalent hello world program on 64bit mac, the rust version was orders of magnitude larger. There was also a paragraph of text after some assertion failure...not sure why since all I did was println! hello world. And, the program ran just fine.