Skip to content

Commit

Permalink
Merge pull request #195 from huuff/indexmap
Browse files Browse the repository at this point in the history
feat: support for indexmap
  • Loading branch information
cksac authored Sep 30, 2024
2 parents 8e9b02e + d499ff2 commit a11ac07
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Available features:
- `zerocopy`
- `glam`
- `url`
- `indexmap`
- `always-true-rng`: expose AlwaysTrueRng
- `maybe-non-empty-collections`: allow to use AlwaysTrueRng to generate non-empty collections

Expand Down
1 change: 1 addition & 0 deletions fake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ glam = { version = "0.29.0", optional = true }
url-escape = { version = "0.1", optional = true }
bson = { version = "2.10", optional = true }
url = { version = "2.5.2", optional = true }
indexmap = { version = "2", optional = true}

[dev-dependencies]
chrono = { version = "0.4", features = ["clock"], default-features = false }
Expand Down
22 changes: 22 additions & 0 deletions fake/src/impls/indexmap/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::{Dummy, Fake, Faker};
use indexmap::IndexMap;
use rand::Rng;
use std::hash::{BuildHasher, Hash};

use super::std::collections::get_len;

impl<K, V, S> Dummy<Faker> for IndexMap<K, V, S>
where
K: Dummy<Faker> + Hash + Eq,
V: Dummy<Faker>,
S: BuildHasher + Default,
{
fn dummy_with_rng<R: Rng + ?Sized>(config: &Faker, rng: &mut R) -> Self {
let len = get_len(config, rng);
let mut m = IndexMap::with_capacity_and_hasher(len, S::default());
for _ in 0..len {
m.insert(config.fake_with_rng(rng), config.fake_with_rng(rng));
}
m
}
}
2 changes: 2 additions & 0 deletions fake/src/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub mod geo;
pub mod glam;
#[cfg(feature = "http")]
pub mod http;
#[cfg(feature = "indexmap")]
pub mod indexmap;
#[cfg(feature = "semver")]
pub mod semver;
#[cfg(feature = "serde_json")]
Expand Down

0 comments on commit a11ac07

Please sign in to comment.