title: How to default-initialize a struct containing an array in Rust?
body: <p>What is the recommended way to declare a struct that contains an array, and then create a zero-initialized instance? </p>
  
  <p>Here is the struct:</p>
  
  <pre><code>#[derive(Default)]
  struct Histogram {
      sum: u32,
      bins: [u32; 256],
  }
  </code></pre>
  
  <p>and the compiler error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0277]: the trait bound `[u32; 256]: std::default::Default` is not satisfied
   --&gt; src/lib.rs:4:5
    |
  4 |     bins: [u32; 256],
    |     ^^^^^^^^^^^^^^^^ the trait `std::default::Default` is not implemented for `[u32; 256]`
    |
    = help: the following implementations were found:
              &lt;[T; 14] as std::default::Default&gt;
              &lt;&amp;'a [T] as std::default::Default&gt;
              &lt;[T; 22] as std::default::Default&gt;
              &lt;[T; 7] as std::default::Default&gt;
            and 31 others
    = note: required by `std::default::Default::default`
  </code></pre>
  
  <p>If I attempt to add the missing initializer for the array:</p>
  
  <pre><code>impl Default for [u32; 256] {
      fn default() -&gt; [u32; 255] {
          [0; 256]
      }
  }
  </code></pre>
  
  <p>I get:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
   --&gt; src/lib.rs:7:5
    |
  7 |     impl Default for [u32; 256] {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
    |
    = note: the impl does not reference any types defined in this crate
    = note: define and implement a trait or new type instead
  </code></pre>
  
  <p>Am I doing something wrong?</p>