Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. use std::ops::Deref;
  2.  
  3.  
  4. #[derive(Default)]
  5. struct Child {
  6. a: f32,
  7. b: f32,
  8. }
  9.  
  10. #[derive(Default)]
  11. struct Example2 {
  12. ch: Child,
  13. c: f32,
  14. d: f32,
  15. }
  16.  
  17. impl Deref for Example2 {
  18. type Target = Child;
  19. fn deref(&self) -> &Child {
  20. &self.ch
  21. }
  22. }
  23.  
  24. fn main() {
  25. let e = Example2{
  26. ch: Child {
  27. a: 1.0,
  28. b: 2.0,
  29. },
  30. c: 3.0,
  31. d: 4.0,
  32. };
  33. println!("{}", e.a);
  34. println!("{}", e.b);
  35. println!("{}", e.c);
  36. println!("{}", e.d);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement