aboutsummaryrefslogtreecommitdiff
path: root/lib/src
diff options
context:
space:
mode:
authorLizzy Fleckenstein <eliasfleckenstein@web.de>2023-02-08 02:40:43 +0100
committerLizzy Fleckenstein <eliasfleckenstein@web.de>2023-02-08 02:40:43 +0100
commit8dceb474a5a7991dafeb1b9c846244c71ca33301 (patch)
tree82c9bdc9ca91ea5f0397d93b3e2095a31f141ca1 /lib/src
parent2a6f3ebd7b63817edc45a20c333028dc855de6da (diff)
downloadgenerate-random-8dceb474a5a7991dafeb1b9c846244c71ca33301.tar.xz
Support HashSet
Diffstat (limited to 'lib/src')
-rw-r--r--lib/src/lib.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/src/lib.rs b/lib/src/lib.rs
index c7e9285..4995eb6 100644
--- a/lib/src/lib.rs
+++ b/lib/src/lib.rs
@@ -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,