title: C++ Friend-like construct for Rust
body: <p>In certain cases I would like to leverage whatever alternative there is in Rust to C++'s <code>friend</code> keyword. In crate <strong>A</strong> I have the following modules:</p>
  
  <p><strong>mod a0</strong>:</p>
  
  <pre><code>pub struct A {
      pub a0: u8,
      a1: SomeType,
  }
  
  impl A {
      pub fn fa0(...) { ... }
      fn fa1(...) { ... }
  }
  </code></pre>
  
  <p>Modules <code>b0</code> and <code>c0</code> need access to all public and private members of <code>A</code>. Code cannot do that unless it is in <code>mod a0</code>. I want to expose only <code>A</code>, <code>A::a0</code> and <code>A::fa0</code> to other crates interfacing with this crate, but within this crate I want access to the complete implementation of <code>A</code> (public and private).</p>
  
  <p>I usually end up doing something like:</p>
  
  <p><strong>mod a0</strong>:</p>
  
  <pre><code>pub struct A {
      pub a0: u8,
      inner: Inner
  }
  
  pub struct Inner { /* all pub fields */ }
  
  pub fn get_inner&lt;'a&gt;(obj: &amp;'a mut A) -&gt; &amp;'a Inner {
       &amp;mut obj.inner
  }
  </code></pre>
  
  <p>Modules <code>b0</code> and <code>c0</code> access <code>get_inner</code> and hence <code>Inner</code>, while in <code>lib.rs</code> I do:</p>
  
  <pre><code>mod a0;
  mod b0;
  mod c0;
  
  pub use a0::A; // so other crates cannot use get_inner(...) etc.
  </code></pre>
  
  <p>This seems very convoluted and I seem to be missing something. Or is this the only way to do it ?</p>