SHARE
TWEET

Untitled

a guest Aug 19th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 Parent {
  12.     ch: Child,
  13.     c: f32,
  14.     d: f32,
  15. }
  16.  
  17. impl Deref for Parent {
  18.     type Target = Child;
  19.     fn deref(&self) -> &Child {
  20.         &self.ch
  21.     }
  22. }
  23.  
  24. fn main() {
  25.     let p = Parent{
  26.         ch: Child {
  27.             a: 1.0,
  28.             b: 2.0,
  29.         },
  30.         c: 3.0,
  31.         d: 4.0,
  32.     };
  33.     println!("{}", p.a);
  34.     println!("{}", p.b);
  35.     println!("{}", p.c);
  36.     println!("{}", p.d);
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top