add tuples and tuple unpacking

This commit is contained in:
Sil Klaasboer
2025-12-20 15:52:46 +01:00
parent 05f130692e
commit 0f2cd1d524

View File

@@ -40,5 +40,10 @@ fn main() {
let color = RGB{red:255,green:255,blue:255};
println!("color has R:{} G:{} B:{}",color.red,color.green,color.blue);
// tuples
let pixel = (100,100,RGB{red:0xff,green:0xff,blue:0xff});
println!("pixel tuple: x:{} y:{} color:{}.{}.{}",pixel.0,pixel.1,pixel.2.red,pixel.2.green,pixel.2.blue);
//tuple unpacking
let (xcoord, ycoord, color) = pixel;
println!("unpacking pixel tuple: x:{} y:{} color:{}.{}.{}",xcoord,ycoord,color.red,color.green,color.blue);
}