Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for indexmap #195

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading