Loading RustViz Engine...
Tuples combine heterogeneous values into fixed records, while arrays allocate a contiguous sequence of identical types on the stack with zero heap overhead.
fn main() {
// Heterogeneous Tuple
let socket: (&str, u16) = ("127.0.0.1", 3000);
let (ip, port) = socket; // Destructuring pattern
println!("Listening on {}:{} (via direct index: {})", ip, port, socket.1);
// Contiguous Stack Array
let netmask: [u8; 4] = [255, 255, 255, 0];
let zeros: [u64; 8] = [0; 8]; // Repeat expression syntax
println!("Netmask: {:?}, length: {}", netmask, netmask.len());
println!("Zeros count: {}", zeros.len());
}Tuples and arrays do not require heap allocation. They are packed directly into the function's stack frame.
An array's length is part of its static type: `[u8; 4]` and `[u8; 8]` are distinct types. This allows the compiler to verify bounds statically and vectorize operations with SIMD.
An array `[u8; 4]` occupies exactly 4 contiguous bytes in memory. A tuple `(u8, u32)` occupies 8 bytes due to 4-byte alignment padding between the `u8` and the `u32`.
// (u8, u32) layout on 64-bit architecture:
// [ byte 0: u8 | bytes 1-3: padding | bytes 4-7: u32 ] -> total 8 bytes