Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. union IntOrFloat {
  2. i: i32,
  3. f: f32
  4. }
  5.  
  6. fn process_value(iof: IntOrFloat){
  7. unsafe {
  8. match iof {
  9. IntOrFloat { i: 42 } => {
  10. println!("meaning of life value");
  11. }
  12. IntOrFloat { f } => {
  13. println!("value = {}", f)
  14. }
  15. }
  16. }
  17. }
  18.  
  19. fn main() {
  20. let mut iof = IntOrFloat { i: 123 };
  21. iof.i = 234;
  22.  
  23. let value = unsafe { iof.i };
  24. println!("iof.i = {}", value);
  25.  
  26. process_value(IntOrFloat{i:5});
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement