Skip to content

Latest commit

 

History

History
62 lines (40 loc) · 1.23 KB

rust.md

File metadata and controls

62 lines (40 loc) · 1.23 KB

Rust

Installation

  • Run in the terminal: curl https://sh.rustup.rs -sSf | sh
  • Reboot
  • Confirm installation: cargo --version
  • If command not found: cargo: then: read this

Usage

Manually create project

If you want to create (compile) your code manually, you will use rustc.

Example:

Create a file main.rs: touch main.rs

Write a hello world-example:

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

Create the file (compile): rustc main.rs

Run the created file: ./main

Workflow:

  1. Write code in .rs
  2. Compile file with: rustc [code-file]
  3. Run compiled file: ./[compiled-file]

Let cargo do the lifting

Most of the time you will use cargo, the Rust package manager.

Create a new rust project (like npm init): cargo new [name]

Compile & run project: cargo run

Looking at some code

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

There is a function named main. It has no parameters, (). The main function is special, because it always runs first.

Further Reading

Rust Docs Cargo Docs Learn Rust