title: Is there a better way of getting mutable references to disjoint struct fields?
body: <p>I have some Rust code that I find to be pretty smelly. I want to get mutable references from the fields of a struct at the same time, but of course Rust does not allow more than one mutable reference at the same time.</p>
  
  <p>What I have been doing currently is basically making a newtype of a tuple and then pattern matching the two different types out into separate <code>ref mut</code> patterns. Not a huge fan of the way this looks in practice.</p>
  
  <pre><code>struct Foo;
  
  impl Foo {
      fn foo(&amp;mut self, bar: &amp;mut Bar) {
          bar.bar();
      }
  }
  
  struct Bar;
  
  impl Bar {
      fn bar(&amp;mut self) {
          println!("bar")
      }
  }
  
  struct FooBar((Foo, Bar));
  
  impl FooBar {
      fn foobar(&amp;mut self) {
          let &amp;mut FooBar((ref mut foo, ref mut bar)) = self;
          foo.foo(bar);
          println!("foobar");
      }
  }
  
  fn main() {
      let mut foobar = FooBar((Foo, Bar));
      foobar.foobar();
  }
  </code></pre>
  
  <p><a href="https://play.rust-lang.org/?code=struct%20Foo%3B%0A%0Aimpl%20Foo%20%7B%0A%20%20%20%20fn%20foo%28%26mut%20self%2C%20bar%3A%20%26mut%20Bar%29%20%7B%0A%20%20%20%20%20%20%20%20bar.bar%28%29%3B%0A%20%20%20%20%7D%0A%7D%0A%0Astruct%20Bar%3B%0A%0Aimpl%20Bar%20%7B%0A%20%20%20%20fn%20bar%28%26mut%20self%29%20%7B%0A%20%20%20%20%20%20%20%20println!%28%22bar%22%29%0A%20%20%20%20%7D%0A%7D%0A%0Astruct%20FooBar%28%28Foo%2C%20Bar%29%29%3B%0A%0Aimpl%20FooBar%20%7B%0A%20%20%20%20fn%20foobar%28%26mut%20self%29%20%7B%0A%20%20%20%20%20%20%20%20let%20%26mut%20FooBar%28%28ref%20mut%20foo%2C%20ref%20mut%20bar%29%29%20%3D%20self%3B%0A%20%20%20%20%20%20%20%20foo.foo%28bar%29%3B%0A%20%20%20%20%20%20%20%20println!%28%22foobar%22%29%3B%0A%20%20%20%20%7D%0A%7D%0A%0Afn%20main%28%29%20%7B%0A%20%20%20%20let%20mut%20foobar%20%3D%20FooBar%28%28Foo%2C%20Bar%29%29%3B%0A%20%20%20%20foobar.foobar%28%29%3B%0A%7D&amp;version=stable" rel="nofollow">Rust Playground</a></p>
  
  <p>Is there a better way I should be doing this? Or perhaps some ideas about general ways to structure the code so that I do not need this newtype?</p>