]> git.lizzy.rs Git - generate-random.git/commitdiff
Support HashSet
authorLizzy Fleckenstein <eliasfleckenstein@web.de>
Wed, 8 Feb 2023 01:40:43 +0000 (02:40 +0100)
committerLizzy Fleckenstein <eliasfleckenstein@web.de>
Wed, 8 Feb 2023 01:40:43 +0000 (02:40 +0100)
lib/src/lib.rs

index c7e92851d86af12a7804ae1a2f4c42e4a9003640..4995eb69103bb630194eb6e395a2ade1b0e750bd 100644 (file)
@@ -104,6 +104,16 @@ impl<T: GenerateRandom> GenerateRandom for Vec<T> {
     }
 }
 
+impl<T> GenerateRandom for std::collections::HashSet<T>
+where
+    T: GenerateRandom + std::cmp::Eq + std::hash::Hash,
+{
+    fn generate_random<R: rand::Rng + ?Sized>(rng: &mut R) -> Self {
+        let len = rng.gen_range(0..8);
+        (0..len).map(|_| T::generate_random(rng)).collect()
+    }
+}
+
 impl<K, V> GenerateRandom for std::collections::HashMap<K, V>
 where
     K: GenerateRandom + std::cmp::Eq + std::hash::Hash,