Rust Notes
Created: 29-08-2025
Tags: rust | programming | CS
Getting Started
Rustup: Rustup is a one place command line application for installing and managing Rust toolings like the rustc compiler and cargo. (To link files, a common c compiler such as GCC is expected)
Common Rustup Commands:
$ rustc --version
$ rustup update
$ rustup self uninstall
$ rustup doc
Hello, World!
fn main() {
println!("Hello, World!");
}
fn -> Declares a function
main -> Has a C behaviour, acts as the entry point
println! -> Is a macro (NOT a function!)*
*Rust macros are a way to write code that generates code to extend Rust syntax. Differ from a function call by ! as println! (macro) and not println (function)
Compilation and execution are different processes. Rust is an ahead-of-time compiled language, meaning you can compile a program and give the executable to someone else, and they can run it even without having Rust installed.
To compile:
$ rustc file.rs
To execute the compilation:
$ ./file
Hello, Cargo
Cargo is the build system and package manager for Rust. It handles dependency management, project creation, building the project and provides tools for development.
$ cargo --version
To create a new project:
$ cargo new project_name
This creates a directory 'project_name' and populates it with a Cargo.toml file and the canonical hello world code in a new src/ directory. If a project is created inside an existing project, VCS like Git is NOT initialised by default to avoid nested repositories.
The Cargo.toml file consists of two fields:
[package] -> contains name of the project, version, edition of Rust it is built upon, etc.
[dependencies] -> Well, dependencies :)
To create a new project in an existing directory, use $ cargo init in that directory instead.