Advertisement
Guest User

Untitled

a guest
May 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. struct Foo {
  2. value: u32
  3. }
  4.  
  5. impl Foo {
  6. fn method(&mut self, value: &u32) {
  7. self.value += *value;
  8. }
  9. }
  10.  
  11. struct Bar {
  12. value: u32,
  13. foo: Foo,
  14. }
  15.  
  16. impl Bar {
  17. fn new() -> Self {
  18. Bar {
  19. value: 1,
  20. foo: Foo {
  21. value: 2,
  22. },
  23. }
  24. }
  25.  
  26. fn get_mut(&mut self) -> Option<&mut u32> {
  27. Some(&mut self.value)
  28. }
  29.  
  30. fn other_helper(&mut self, value: &mut u32) {
  31. self.foo.method(value);
  32. }
  33.  
  34. fn static_helper(foo: &mut Foo, value: &mut u32) {
  35. foo.method(value);
  36. }
  37.  
  38. fn helper(&mut self) {
  39. if let Some(value) = self.get_mut() {
  40. self.other_helper(&mut self.value);
  41. //Self::static_helper(&mut self.foo, &mut self.value);
  42. }
  43. }
  44.  
  45. fn method(&mut self) {
  46.  
  47. }
  48. }
  49.  
  50. fn main() {
  51. let mut bar = Bar::new();
  52. bar.method();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement