Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- union IntOrFloat {
- i: i32,
- f: f32
- }
- fn process_value(iof: IntOrFloat){
- unsafe {
- match iof {
- IntOrFloat { i: 42 } => {
- println!("meaning of life value");
- }
- IntOrFloat { f } => {
- println!("value = {}", f)
- }
- }
- }
- }
- fn main() {
- let mut iof = IntOrFloat { i: 123 };
- iof.i = 234;
- let value = unsafe { iof.i };
- println!("iof.i = {}", value);
- process_value(IntOrFloat{i:5});
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement