Files
Rust-High-Performance/Chapter03/example5.rs
2018-03-28 11:18:06 +05:30

25 lines
392 B
Rust

union Plant {
g: Geranium,
c: Carnation,
}
#[derive(Copy, Clone)]
struct Geranium {
height: u32,
}
#[derive(Copy, Clone)]
struct Carnation {
flowers: u8,
}
fn main() {
let mut my_plant = Plant {
c: Carnation { flowers: 15 },
};
my_plant.g = Geranium { height: 300 };
let height = unsafe { my_plant.g }.height;
println!("Height: {}", height);
}