title: Is there a more concise or declarative way to initialize a HashMap?
body: <p>I'm using a <code>HashMap</code> to count the occurrences of different characters in a string:</p>
  
  <pre><code>let text = "GATTACA";
  let mut counts: HashMap&lt;char, i32&gt; = HashMap::new();
  counts.insert('A', 0);
  counts.insert('C', 0);
  counts.insert('G', 0);
  counts.insert('T', 0);
  
  for c in text.chars() {
      match counts.get_mut(&amp;c) {
          Some(x) =&gt; *x += 1,
          None =&gt; (),
      }
  }
  </code></pre>
  
  <p>Is there a more concise or declarative way to initialize a <code>HashMap</code>? For example in Python I would do:</p>
  
  <pre><code>counts = { 'A': 0, 'C': 0, 'G': 0, 'T': 0 }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>counts = { key: 0 for key in 'ACGT' }
  </code></pre>