Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #[derive(Debug)]
  2. struct PP {
  3. a: u16
  4. }
  5.  
  6. #[derive(Debug)]
  7. enum AnnotationType {
  8. A(PP),
  9. B { b: u32, c: u64 }
  10. }
  11.  
  12.  
  13. fn main() {
  14. println!("Hello, world!");
  15. let mut pp = PP { a: 123};
  16. let mut x: AnnotationType = AnnotationType::A(pp);
  17. test(&mut x);
  18. println!("{:?}", x);
  19.  
  20. x = AnnotationType::B { b: 13, c: 15 };
  21. test(&mut x);
  22. println!("{:?}", x);
  23. }
  24.  
  25. fn test(f: &mut AnnotationType) {
  26. match f {
  27. AnnotationType::A(ref mut pp) => { pp.a = 5 },
  28. AnnotationType::B { ref mut b, ref mut c } => { *b = 132; *c = 151 },
  29. };
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement