From 627bc78e46a85a48ba096ae8a2e3fce500b6efe5 Mon Sep 17 00:00:00 2001 From: Haf Date: Thu, 3 Oct 2024 12:09:35 +0200 Subject: [PATCH] feat: support for IndexSet --- fake/src/impls/indexmap/mod.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/fake/src/impls/indexmap/mod.rs b/fake/src/impls/indexmap/mod.rs index 849ef9c..ec68aa0 100644 --- a/fake/src/impls/indexmap/mod.rs +++ b/fake/src/impls/indexmap/mod.rs @@ -1,5 +1,5 @@ use crate::{Dummy, Fake, Faker}; -use indexmap::IndexMap; +use indexmap::{IndexMap, IndexSet}; use rand::Rng; use std::hash::{BuildHasher, Hash}; @@ -20,3 +20,18 @@ where m } } + +impl Dummy for IndexSet +where + T: Dummy + Hash + Eq, + S: BuildHasher + Default, +{ + fn dummy_with_rng(config: &Faker, rng: &mut R) -> Self { + let len = get_len(config, rng); + let mut m = IndexSet::with_capacity_and_hasher(len, S::default()); + for _ in 0..len { + m.insert(config.fake_with_rng(rng)); + } + m + } +}