title: How to implement bidirectional conversion with From trait in Rust?
body: <p>Suppose I have the following type:</p>
  
  <pre><code>#[derive(Default)]
  struct Foo(pub i32); // public
  </code></pre>
  
  <p>Since it's a tuple with a public member, any conversions from/to <code>i32</code> can simply be made using the <code>0</code> member:</p>
  
  <pre><code>let foo = Foo::default();
  
  let num: i32 = foo.0; // Foo to i32
  let goo = Foo(123);   // i32 to Foo
  </code></pre>
  
  <p>Now I want to make the <code>0</code> member non-public, implementing <a href="https://doc.rust-lang.org/std/convert/trait.From.html" rel="nofollow noreferrer">From trait</a>:</p>
  
  <pre><code>#[derive(Default)]
  struct Foo(i32); // non-public
  
  impl From&lt;i32&gt; for Foo {
      fn from(n: i32) -&gt; Foo {
          Foo(n)
      }
  }
  </code></pre>
  
  <p>But the conversion fails from <code>i32</code>  to <code>Foo</code>:</p>
  
  <pre><code>let foo = ay::Foo::default();
  let num: i32 = foo.into();    // error!
  let goo = ay::Foo::from(123); // okay
  </code></pre>
  
  <p>What's the correct way to implement this bidirectional conversion? Rust playground <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=3797660e24ba314419cc9b44bc38427c" rel="nofollow noreferrer">here</a>.</p>