Rust development notes

Rust development notes

March 31, 2026, 1:06 p.m.

gradient image

This is a place for me to put my rust language based notes.
https://doc.rust-lang.org/book/

Compile : rustc main.rs (or chosen file name)
$ > ./main

Testing strings :

use std::io;
use std::io::Write;

fn main() {
println!("testing string\n");
io::stdout().flush().unwrap();
}

$ >

testing string

Storing values inside a variable :

// Variables are immutable
fn main() {
let x = 5;
println!("The value of x is: {x}");
}

Making variable mutable :

// mut annotation allows mutability
fn main() {
let mut x = 5;
println!("The value of x is: {x}");
x = 6;
println!("The value of x is: {x}");
}

$ >
The value of x is: 5
The value of x is: 6

Constants :

// constants are just that constant
// cant use mut with constants
// convention use upper case and underscore
fn main() {
const TWENTY_BUT_TWICE: u32 = 20 * 2;

println!("{}", TWENTY_BUT_TWICE)
}

$ >
40

Types :

Scalar Types : Intergers , floating-point numbers, booleans, characters

Integer Types : number without fractional components.

Signed : need sign as the number could be negative number
Unsigned : will only be represented as a positive number

i8,u8,i16,u16,i32,u32, i64, u64,i128,u128, isize, usize

Setting types :

let f : bool = false //sets f as boolean type with value of false

Compund Types : can group multiple values into one type . 2 primitive compund types tuple and Array

Tuples : general way of grouping a number of values with different types ; fixed length cant grow or get smaller once declared.

fn main() {
let temps: (u32, i8) = (20, -8);

println!("{:?}", temps)
}

$ >
(20, -8)

Array : collection of multiple values must be same type

// writing an array with type and amount of elements inside the array
fn main() {
let a: [u32; 3] = [5, 10, 12];

println!("{:?}", a)
}

$ >
[5, 10, 12]

Array element access :

(continued)