[Rust] Installation and Hello World

This is the first post of a series of posts about the Rust. I trying to learn rust for some time and the best way to learn is trying to teach.

Rust is a system programming language developed by Mozilla Research that is designed to be safe, concurrent and practical. It contains functional, procedural and object oriented elements. But focused in speedy and safety.

Install Rust

Rust is very easy to install. A list of release for Linux, Mac and Windows are available at rust/download.

Setup script for Linux and Mac OSX:

$ curl -sSf https://static.rust-lang.org/rustup.sh | sh

Alternative, using Brew on Mac OSX:

 $ brew install rust 

After finish, check running the command below:

$ rustc --version
  rustc 1.7.0

Hello World using Cargo

Rust contains a package manage called cargo that help create structured project, crate, that can be easily configured and build. To create a hello_world crate run the command below.

$ cargo new hello_world --bin

This command create a directory with a git repository called hello_world with two files. Cargo.toml and src/main.rs.

Cargo.toml is a manifest that describes the application, dependencies and misc.

[package]
name = "hello_world"
version = "0.1.0"
authors = ["Emiliano Firmino <me@emilianofirmino.com.br>"]

[dependencies]

main.rs the entry point of the program.

fn main() {
    println!("Hello, world!");
}

To build and run, use the commands below:

$ cargo build
    Compiling hello_world v0.1.0
$ cargo run
    Running `target/debug/hello_world`
  Hello, world!

For more rust, read the book.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s