Tuple
let numbers: (i32, i32, f64) = (1, 2, 3.5);
// destructuring
let (a, b, c) = numbers;
// mutable
let mut mau = (10, 11, 12)
mau.0 = 90 // (90, 11, 12)
mau = (90, 91, 92) // pattern matching
need to respect the type to avoid
mismatched types
Array
let neo: [i32;3] = [1, 2, 3]
neo[1] // 2
let mut morpheu = [1.1, 2.2, 3.3]
morpheu[2] = 10.15
// slice
&neo[1..] // [2, 3]
&neo[..2] // [1, 2]
&neo[1..2] // [2]
arrays should have only one type
Out-of-bound error
- Trying to get an element out of the limits: index out of bounds
Memory Awareness
- STATIC memory needs fixed-size
static _Y: u32 = 13
- STACK are local variables,
static _Y: u32 = 13
fn main() {
let x = 5;
let z = true;
let numbers = [1, 2, 3];
}
- HEAP memory
static _Y: u32 = 13
fn main() {
let x = 5;
let z = true;
let numbers = [1, 2, 3];
let users = get_users();
}
Memory Cleanup
- drop method to clean up it
Top comments (0)