How to reference private types from public functions in private modules?
<p>I want to group similar functions in a file. Those functions need to return a type which is not public:</p>

<pre><code>struct MyStruct;

mod my_mod {
    use super::MyStruct;

    // There are other, similar functions that also return `MyStruct`
    pub fn foo() -&gt; MyStruct {
        MyStruct
    }
}

fn main() {
    let _var = my_mod::foo();
}
</code></pre>

<p>This fails with the error</p>

<pre class="lang-none prettyprint-override"><code>error[E0446]: private type `MyStruct` in public interface
 --&gt; src/main.rs:7:3
  |
1 |     struct MyStruct;
  |     - `MyStruct` declared as private
...
7 |         pub fn foo() -&gt; MyStruct { MyStruct }
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
</code></pre>

<p>In general, it makes sense not to allow public functions to have private types in their signature, but in this specific case the structure <em>is</em> available at the modules root level.</p>

<p>Is there a way to support this without making <code>MyStruct</code> public?</p>