Guest User

Untitled

a guest
Oct 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #[derive(Debug)]
  2. struct A
  3. {
  4. b: B,
  5. }
  6.  
  7. impl A
  8. {
  9. fn new() -> A
  10. {
  11. A
  12. {
  13. b: B::new(),
  14. }
  15. }
  16.  
  17. fn foo(&mut self)
  18. {
  19. {
  20. let b = &mut self.b;
  21. b.foo();
  22. }
  23. self.baz();
  24. }
  25.  
  26. fn baz(&self) -> String
  27. {
  28. String::from("Qux")
  29. }
  30. }
  31.  
  32. #[derive(Debug)]
  33. struct B
  34. {
  35. b1: String,
  36. }
  37.  
  38. impl B
  39. {
  40. fn new() -> B
  41. {
  42. B
  43. {
  44. b1: String::from(""),
  45. }
  46. }
  47.  
  48. fn foo(&mut self)
  49. {
  50. self.b1 = String::from("Foo");
  51. }
  52. }
  53.  
  54. fn main()
  55. {
  56. let mut a = A::new();
  57. a.foo();
  58.  
  59. println!("{:?}", &a);
  60. }
Add Comment
Please, Sign In to add comment