title: How do you Implment fmt::Display for an array or slice of type T in Rust?
body: <p>How do I implement <code>Display</code> for <code>[&amp;MyStruct]</code>?</p>
  
  <p>I've implemented <code>Display</code> for <code>MyStruct</code>,</p>
  
  <pre><code>impl fmt::Display for MyStruct {
      fn fmt(&amp;self, f: &amp;mut fmt::Formatter) -&gt; fmt::Result {
          write!(f, ..., ...)
      }
  }
  </code></pre>
  
  <p>This issue I'm running into is when I return a <code>[&amp;MyStruct]</code>, I can't print it,</p>
  
  <pre><code>11 |     println!("{}", sliceOfMyStructs);
     |                               ^^^^^^^^^ `[&amp;MyStruct]` cannot be formatted with the default formatter
     |
     = help: the trait `std::fmt::Display` is not implemented for `[&amp;MyStruct]`
     = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
     = note: required because of the requirements on the impl of `std::fmt::Display` for `&amp;[&amp;MyStruct]`
     = note: required by `std::fmt::Display::fmt`
  </code></pre>
  
  <p>What I've ready tried is (<code>MyStruct</code> is defined in my crate),</p>
  
  <pre><code>17 | impl fmt::Display for [MyStruct] {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
     |
     = note: the impl does not reference only types defined in this crate
     = note: define and implement a trait or new type instead
  </code></pre>