mirror of
https://github.com/PacktPublishing/Rust-High-Performance.git
synced 2026-01-25 02:34:19 +09:00
25 lines
392 B
Rust
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);
|
|
}
|