title: How to format types implementing Display in rust?
body: <p>playground link: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=ed531c76be5298b858a05c705292a804" rel="nofollow noreferrer">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=ed531c76be5298b858a05c705292a804</a></p>
  <p>How can I format structs that implement the Display trait?<br />
  Seems a bit redundant to need to call to_string() on everything?</p>
  <pre><code>struct MyStruct();
  
  impl std::fmt::Display for MyStruct {
      fn fmt(&amp;self, f: &amp;mut std::fmt::Formatter&lt;'_&gt;) -&gt; std::fmt::Result {
          write!(f, &quot;X&quot;)
      }
  }
  
  fn main() {
      
      let x = MyStruct{};
      let y = &quot;Y&quot;;
      
      println!(&quot;{:_^9}&quot;, x); // WHY isnt this properly formatted?
      println!(&quot;{:_^9}&quot;, x.to_string());
      println!(&quot;{:_^9}&quot;, y);
  }
  </code></pre>
  <p>outputs:</p>
  <pre><code>X
  ____X____
  ____Y____
  </code></pre>
  <p>What am I doing wrong?</p>