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

fix: re-export correct features #161

Merged
merged 1 commit into from
Dec 16, 2023
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Default:

```toml
[dependencies]
fake = { version = "2.9", features = ["derive"] }
fake = { version = "2.9.2", features = ["derive"] }
```

Available features:
Expand Down Expand Up @@ -59,7 +59,7 @@ fn main() {
// type derived Dummy
let f: Foo = Faker.fake();
println!("{:?}", f);

let b: Bar<Foo> = Faker.fake();
println!("{:?}", b);

Expand Down
2 changes: 1 addition & 1 deletion fake/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fake"
version = "2.9.1"
version = "2.9.2"
authors = ["cksac <[email protected]>"]
description = "An easy to use library for generating fake data like name, number, address, lorem, dates, etc."
keywords = ["faker", "data", "generator", "random"]
Expand Down
2 changes: 1 addition & 1 deletion fake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Default:

```toml
[dependencies]
fake = { version = "2.9", features = ["derive"] }
fake = { version = "2.9.2", features = ["derive"] }
```

Available features:
Expand Down
23 changes: 11 additions & 12 deletions fake/src/impls/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,36 +58,35 @@ impl Dummy<Faker> for PrimitiveDateTime {
pub struct Precision<const N: usize>;

trait AllowedPrecision {
const SCALE: i128;
const SCALE: u32;

fn to_scale(nanos: i128) -> i128 {
fn to_scale(nanos: u32) -> u32 {
if nanos != 0 {
nanos / Self::SCALE * Self::SCALE
} else {
nanos
}
}
}

macro_rules! allow_precision {
($($precision:expr),*) => {
$(impl AllowedPrecision for Precision<$precision> {
const SCALE: i128 = 10i128.pow(9 - $precision);
const SCALE: u32 = 10u32.pow(9 - $precision);
})*
};
}

allow_precision!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);

impl<const N: usize> Dummy<Precision<N>> for Time
where
Precision<N>: AllowedPrecision,
{
fn dummy_with_rng<R: Rng + ?Sized>(_: &Precision<N>, rng: &mut R) -> Self {
let hour = (0..24).fake_with_rng(rng);
let min = (0..60).fake_with_rng(rng);
let sec = (0..60).fake_with_rng(rng);
let nanos: i128 = (0..1_000_000_000).fake_with_rng(rng);
let nanos = Precision::<N>::to_scale(nanos) as u32;
Time::from_hms_nano(hour, min, sec, nanos).expect("failed to create time")
let time: Time = Faker.fake_with_rng(rng);
time.replace_nanosecond(Precision::<N>::to_scale(time.nanosecond()))
.expect("failed to create time")
}
}

Expand All @@ -107,8 +106,8 @@ where
Precision<N>: AllowedPrecision,
{
fn dummy_with_rng<R: Rng + ?Sized>(_: &Precision<N>, rng: &mut R) -> Self {
let nanos = (MIN_NANOS..MAX_NANOS).fake_with_rng(rng);
let nanos = Precision::<N>::to_scale(nanos);
OffsetDateTime::from_unix_timestamp_nanos(nanos).unwrap()
let time: OffsetDateTime = Faker.fake_with_rng(rng);
time.replace_nanosecond(Precision::<N>::to_scale(time.nanosecond()))
.expect("failed to create time")
}
}
8 changes: 7 additions & 1 deletion fake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,18 @@ pub use impls::uuid;
#[cfg(feature = "rust_decimal")]
pub use impls::decimal;

#[cfg(feature = "bigdecimal")]
#[cfg(any(feature = "bigdecimal", feature = "bigdecimal-rs"))]
pub use impls::bigdecimal;

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

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

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

/// Fake value generation for specific formats.
///
/// It is structured in a way such that the modules here describes the custom
Expand Down
Loading