Last active
September 13, 2018 13:48
-
-
Save maretekent/dc5a8285c85791d15899344cf7f518c7 to your computer and use it in GitHub Desktop.
Copying elements of one struct to another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Color { | |
red: u8, | |
green: u8, | |
blue: u8 | |
} | |
fn main() { | |
let mut link_color = Color {red: 0,green: 0,blue: 255}; | |
link_color.blue = 238; | |
println!("Link Color = rgb({}, {}, {})", link_color.red, link_color.green, link_color.blue); //Link Color = rgb(0, 0, 238) | |
// copy elements from another instance | |
let blue = Color {blue: 255, .. link_color}; | |
println!("Blue = rgb({}, {}, {})", blue.red, blue.green, blue.blue); //Blue = rgb(0, 0, 255) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment