Skip to content

Instantly share code, notes, and snippets.

@maretekent
Last active September 13, 2018 13:48
Show Gist options
  • Save maretekent/dc5a8285c85791d15899344cf7f518c7 to your computer and use it in GitHub Desktop.
Save maretekent/dc5a8285c85791d15899344cf7f518c7 to your computer and use it in GitHub Desktop.
Copying elements of one struct to another
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