title: Accessing private fields from different modules
body: <pre><code>mod root {
      mod foo {
          pub struct Foo {
              i: i32,
          }
      }
      mod bar {
          pub struct Bar {
              f: ::root::foo::Foo,
          }
          impl Bar {
              pub fn new(i: i32) -&gt; Self {
                  Bar { f: ::root::foo::Foo { i: i } }
              }
          }
      }
  }
  fn main() {}
  </code></pre>
  
  <p><a href="https://play.rust-lang.org/?gist=a3d83152784807978c042c301cbcb610&amp;version=stable&amp;backtrace=0" rel="nofollow noreferrer">playground</a></p>
  
  <p>The user should be able to interact with <code>Foo</code>, but the user should not be able to construct it manually because it is unsafe.</p>
  
  <p>The module <code>bar</code> should still be able to construct Foo. As far as I know the only way to do this is to put <code>Foo</code> inside the <code>root</code> module or inside the <code>bar</code> module.</p>
  
  <p>Is there a cleaner way to solve this problem? I named the modules here <code>foo</code> and <code>bar</code> but in my code they are separate files like <code>foo.rs</code> <code>bar.rs</code>. Is possible to put <code>foo.rs</code> <code>bar.rs</code> into the same module so that they can see the private fields but still be live in separate files?</p>
  
  <p>My current workaround was to expose a public unsafe <code>new</code> method for Foo.</p>