From 0f2cd1d5243c9755f504a08be7ce118842aa559c Mon Sep 17 00:00:00 2001 From: Sil Klaasboer Date: Sat, 20 Dec 2025 15:52:46 +0100 Subject: [PATCH] add tuples and tuple unpacking --- containers/src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/containers/src/main.rs b/containers/src/main.rs index 0706332..9a5d203 100644 --- a/containers/src/main.rs +++ b/containers/src/main.rs @@ -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); } \ No newline at end of file