1. Getting Started

Learning objectives

By the end of this session you should be able to…

  • answer the question “Why Rust?”
  • run a hello, world program
  • understand how to manage projects with cargo

Rust

A language empowering everyone to build reliable and efficient software.

Set up

  • Install Rust
  • Choose an editor
  • Install extensions

Hello, World

fn main() {
    println!("Hello, world!");
}
  • fn main() is required in main.rs
  • The ! in println! means macro
  • The ; is required

Compile and run

rustc main.rs
./main

Cargo

[package]
name = "hello_cargo"
version = "0.1.0"
edition = "2021"

[dependencies]

Cargo

  • cargo new project_name
  • Cargo.toml
  • cargo.lock
  • project_name/.Rproj
  • DESCRIPTION
  • renv.lock

Discussion