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

Add ulid support #164

Merged
merged 1 commit into from
Jan 22, 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 @@ -22,6 +22,7 @@ Available features:
- `chrono`
- `chrono-tz`
- `http`
- `ulid`
- `uuid`
- `bigdecimal` (via `bigdecimal-rs`)
- `rust_decimal`
Expand Down
1 change: 1 addition & 0 deletions fake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ geo-types = { version = "0.7", default-features = false, optional = true }
http = { version = "1", optional = true }
semver = { version = "1", optional = true }
serde_json = { version = "1.0", optional = true }
ulid = { version = "1.1", optional = true }
uuid = { version = "1.5", features = ["v1", "v3", "v4", "v5"], optional = true }
time = { version = "0.3", features = ["formatting"], optional = true }
num-traits = { version = "0.2", optional = true }
Expand Down
2 changes: 2 additions & 0 deletions fake/src/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub mod serde_json;
pub mod std;
#[cfg(feature = "time")]
pub mod time;
#[cfg(feature = "ulid")]
pub mod ulid;
#[cfg(feature = "uuid")]
pub mod uuid;
#[cfg(feature = "zerocopy")]
Expand Down
13 changes: 13 additions & 0 deletions fake/src/impls/ulid/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! ulid

use ulid::Ulid;

use crate::{Dummy, Faker};

impl Dummy<Faker> for Ulid {
fn dummy_with_rng<R: rand::Rng + ?Sized>(_: &Faker, rng: &mut R) -> Self {
let time_part: u64 = rng.gen_range(0..(1 << Ulid::TIME_BITS));
let rand_part: u128 = rng.gen_range(0..(1 << Ulid::RAND_BITS));
Ulid::from_parts(time_part, rand_part)
}
}
4 changes: 4 additions & 0 deletions fake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! - `derive` provides `#[derive(Dummy)]`
//! - `chrono` [chrono](https://docs.rs/chrono) integration
//! - `http` [http](https://docs.rs/http) integration
//! - `ulid` [ulid](https://docs.rs/ulid) integration
//! - `uuid` [uuid](https://docs.rs/uuid) integration
//!
//! # Usage
Expand Down Expand Up @@ -251,6 +252,9 @@ pub use impls::std::string::StringFaker;
#[cfg(feature = "geo")]
pub use impls::geo;

#[cfg(feature = "ulid")]
pub use impls::ulid;

#[cfg(feature = "uuid")]
pub use impls::uuid;

Expand Down
8 changes: 8 additions & 0 deletions fake/tests/determinism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ check_determinism! { l10d SafeEmail; String, fake_safeemail_en, fake_safeemail_f
check_determinism! { l10d UserAgent; String, fake_useragent_en, fake_useragent_fr, fake_useragent_cn, fake_useragent_tw, fake_useragent_jp, fake_useragent_br }
check_determinism! { l10d Username; String, fake_username_en, fake_username_fr, fake_username_cn, fake_username_tw, fake_username_jp, fake_username_br }

// it's sufficient to check one language, because it doesn't change anything
#[cfg(feature = "ulid")]
mod ulid {
use fake::{Fake, Faker};
use rand::SeedableRng as _;
check_determinism! { one fake_ulid, ulid::Ulid, Faker }
}

// it's sufficient to check one language, because it doesn't change anything
#[cfg(feature = "uuid")]
mod uuid {
Expand Down
Loading