title: How to have a private part of a trait?
body: <p>In a crate I write, I have a bunch of internal <code>struct</code>s public to the user and that share some code. Some of the shared code is public, some is an internal implementation. To share efficiently the code, I am using macros, but now that the project has more features, this begins to be messy, and I am not satisfied by the semantic of this.</p>
  
  <p>I would like to use a trait, but without exposing the implementation. For example:</p>
  
  <pre><code>pub trait MyTrait {
      type Next;
  
      // This function is for the user.
      fn forward(&amp;self) -&gt; Self::Next {
          self.do_the_job()
      }
  
      // This function is for the user.
      fn stop(&amp;self) {
          self.do_the_job();
      }
  
      // This function is an implementation detail.
      fn do_the_job(&amp;self) -&gt; Self::Next;
  }
  </code></pre>
  
  <p>I want the user to see and use <code>forward</code> and <code>stop</code>, but not <code>do_the_job</code>, while my data would only implement <code>do_the_job</code>.</p>
  
  <p>Is it possible to design my code to do something like that? I have tried to imagine some solutions, but nothing has come to my mind.</p>
  
  <p><a href="https://play.rust-lang.org/?version=beta&amp;mode=debug&amp;edition=2018&amp;gist=d28280b46dbc1f78dfee30f0fba0b438" rel="noreferrer">Playground</a></p>
  
  <hr>
  
  <p>In an object oriented language with inheritance, I would do (pseudo code):</p>
  
  <pre class="lang-none prettyprint-override"><code>public interface MyTrait {
      type Next;
  
      fn forward(&amp;self) -&gt; Self::Next;
  
      fn stop(&amp;self);
  }
  
  public abstract class MyCommonCode extends MyTrait {
      fn forward(&amp;self) -&gt; Self::Next {
          self.do_the_job()
      }
  
      fn stop(&amp;self) {
          self.do_the_job();
      }
  
      protected abstract fn do_the_job(&amp;self) -&gt; Self::Next;
  }
  
  public MyType extends MyCommonCode {
      type Next = i32;
  
      protected override fn do_the_job(&amp;self) -&gt; Self::Next {
          // etc.
      }
  }
  </code></pre>