add tuples and tuple unpacking
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user