title: Is there a simple way remove duplicate elements from an array?
body: <p>I want to remove duplicate elements from an array:</p>
  <pre><code>use itertools::Itertools;
  use std::collections::HashSet;
  
  #[derive(Debug)]
  struct Person {
      name: String,
      age: u32,
  }
  
  fn main() {
      let arr = [
          Person { name: &quot;aaa&quot;.to_string(), age: 10 },
          Person { name: &quot;bbb&quot;.to_string(), age: 20 },
          Person { name: &quot;bbb&quot;.to_string(), age: 20 },
          Person { name: &quot;ccc&quot;.to_string(), age: 30 },
      ];
  
      // Way 1:
      let arr2 = {
          let names: Vec&lt;_&gt; = arr.iter().map(|v| v.name.clone()).unique().collect();
          names
              .iter()
              .map(|name| arr.iter().find(|person| &amp;person.name == name).unwrap())
              .collect::&lt;Vec&lt;_&gt;&gt;()
      };
      dbg!(arr2);
  
      // Way 2:
      let arr2 = {
          let mut names = HashSet::new();
          arr.iter()
              .filter(|p| names.insert(p.name.clone()))
              .collect::&lt;Vec&lt;_&gt;&gt;()
      };
      dbg!(arr2);
  
      /*
      expect:
          [
              Person{name: &quot;aaa&quot;.to_string(), age: 10},
              Person{name: &quot;bbb&quot;.to_string(), age: 20},
              Person{name: &quot;ccc&quot;.to_string(), age: 30},
          ]
      */
  }
  </code></pre>
  <p>Way 2 is simple compared to way 1, but is there anything simpler?</p>