Rust Project Initiation

This is my rust installation cheatsheet

  • create a new rust file, compile, and run executable
  • create a rust project using Cargo, compile, check and run executable

RUST file : manually you can write a rust program in main.rs and compile it

// file: main.rs
fn main() {                        // function main()
    println!("Aloha, world!");}    // 4 spacing not tab 
                                   // println! is a rust macro, not a func

// in terminal
$ rustc main.rs    // compile main.rs
$ ./main           // executable is created
Aloha, world!

CARGO project : you can use cargo (almost like a framework that will support package/dependency management when your project gets more complicated)

cargo is installed during the rust installation

$ cargo --version                  // checking cargo installation
$ cargo new aloha_cargo            // creating cargo project
$ cargo new aloha_cargo --vcs=git. // creating cargo project initiating git repo
$ cd aloha_cargo                   
$ cargo build                      // compiling and generating executable

$ cargo run                        // running executable
$ /target/debug/aloha_cargo        // same as cargo run
$ cargo check                      // compiling but no generating executable