O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A tour of the language and trying it out

For the fundamental language features, Rust does not stray far from what you are used to. Programs are defined in modules; they contain functions, variables, and compound data structures. Here's how a minimal program looks:

fn main() {   println!("Are you writing this or reading it?"); }  

Try compiling and running this. Write it to a file called main.rs and then run the Rust compiler:

> rustc -o main main.rs > ./main Are you writing this or reading it? 

Running rustc manually is not how you will do it for real programs, but it will do for these small programs. A fine alternative to running small pieces of code is to use the Rust Playground service in http://play.rust-lang.org:

The program itself ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required