-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from saiintbrisson/master
feat: add precision to time and chrono
- Loading branch information
Showing
9 changed files
with
147 additions
and
52 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "fake" | ||
version = "2.8.0" | ||
version = "2.9.0" | ||
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"] | ||
|
@@ -9,6 +9,7 @@ readme = "README.md" | |
repository = "https://github.com/cksac/fake-rs" | ||
homepage = "https://github.com/cksac/fake-rs" | ||
edition = "2021" | ||
rust-version = "1.56" | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,53 @@ | ||
use crate::decimal::*; | ||
use crate::{Dummy, Fake, Faker}; | ||
use bigdecimal_rs as bd; | ||
use bigdecimal_rs::num_bigint::{BigInt, Sign}; | ||
use rand::Rng; | ||
use rust_decimal; | ||
use std::str::FromStr; | ||
|
||
pub struct BigDecimal; | ||
pub struct NegativeBigDecimal; | ||
pub struct PositiveBigDecimal; | ||
pub struct NoBigDecimalPoints; | ||
|
||
impl Dummy<Faker> for bd::BigDecimal { | ||
fn create_big_decimal<R: Rng + ?Sized>(rng: &mut R, sign: Sign) -> bigdecimal_rs::BigDecimal { | ||
let parts: [u32; 4] = Faker.fake_with_rng(rng); | ||
let int = BigInt::from_slice(sign, &parts); | ||
let scale = (0..64).fake_with_rng(rng); | ||
|
||
bigdecimal_rs::BigDecimal::new(int, scale) | ||
} | ||
|
||
impl Dummy<Faker> for bigdecimal_rs::BigDecimal { | ||
fn dummy_with_rng<R: Rng + ?Sized>(_: &Faker, rng: &mut R) -> Self { | ||
let decimal: rust_decimal::Decimal = Faker.fake_with_rng(rng); | ||
let sign = if Faker.fake_with_rng(rng) { | ||
Sign::Plus | ||
} else { | ||
Sign::Minus | ||
}; | ||
|
||
bd::BigDecimal::from_str(&decimal.to_string()).unwrap() | ||
create_big_decimal(rng, sign) | ||
} | ||
} | ||
|
||
impl Dummy<BigDecimal> for bd::BigDecimal { | ||
impl Dummy<BigDecimal> for bigdecimal_rs::BigDecimal { | ||
fn dummy_with_rng<R: Rng + ?Sized>(_: &BigDecimal, rng: &mut R) -> Self { | ||
let decimal: rust_decimal::Decimal = Decimal.fake_with_rng(rng); | ||
|
||
bd::BigDecimal::from_str(&decimal.to_string()).unwrap() | ||
Faker.fake_with_rng(rng) | ||
} | ||
} | ||
|
||
impl Dummy<NegativeBigDecimal> for bd::BigDecimal { | ||
impl Dummy<NegativeBigDecimal> for bigdecimal_rs::BigDecimal { | ||
fn dummy_with_rng<R: Rng + ?Sized>(_: &NegativeBigDecimal, rng: &mut R) -> Self { | ||
let decimal: rust_decimal::Decimal = NegativeDecimal.fake_with_rng(rng); | ||
|
||
bd::BigDecimal::from_str(&decimal.to_string()).unwrap() | ||
create_big_decimal(rng, Sign::Minus) | ||
} | ||
} | ||
|
||
impl Dummy<PositiveBigDecimal> for bd::BigDecimal { | ||
impl Dummy<PositiveBigDecimal> for bigdecimal_rs::BigDecimal { | ||
fn dummy_with_rng<R: Rng + ?Sized>(_: &PositiveBigDecimal, rng: &mut R) -> Self { | ||
let decimal: rust_decimal::Decimal = PositiveDecimal.fake_with_rng(rng); | ||
|
||
bd::BigDecimal::from_str(&decimal.to_string()).unwrap() | ||
create_big_decimal(rng, Sign::Plus) | ||
} | ||
} | ||
|
||
impl Dummy<NoBigDecimalPoints> for bd::BigDecimal { | ||
impl Dummy<NoBigDecimalPoints> for bigdecimal_rs::BigDecimal { | ||
fn dummy_with_rng<R: Rng + ?Sized>(_: &NoBigDecimalPoints, rng: &mut R) -> Self { | ||
let decimal: rust_decimal::Decimal = NoDecimalPoints.fake_with_rng(rng); | ||
|
||
bd::BigDecimal::from_str(&decimal.to_string()).unwrap() | ||
let decimal: bigdecimal_rs::BigDecimal = Faker.fake_with_rng(rng); | ||
decimal.with_scale(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,11 @@ | ||
use crate::{Dummy, Fake}; | ||
use rand::Rng; | ||
|
||
macro_rules! array_impl { | ||
{$n:expr, $t:ident $($ts:ident)*} => { | ||
impl<T, U> Dummy<U> for [T; $n] where T: Dummy<U> { | ||
fn dummy_with_rng<R: Rng + ?Sized>(config: &U, rng: &mut R) -> Self { | ||
[Fake::fake_with_rng::<$t, _>(config, rng), $(Fake::fake_with_rng::<$ts, _>(config, rng)),*] | ||
} | ||
} | ||
array_impl!{($n - 1), $($ts)*} | ||
}; | ||
{$n:expr,} => { | ||
impl<T, U> Dummy<U> for [T; $n] where T: Dummy<U> { | ||
fn dummy(_: &U) -> Self { | ||
[] | ||
} | ||
|
||
fn dummy_with_rng<R: Rng + ?Sized>(_: &U, _rng: &mut R) -> Self { | ||
[] | ||
} | ||
} | ||
}; | ||
impl<T, U, const N: usize> Dummy<U> for [T; N] | ||
where | ||
T: Dummy<U>, | ||
{ | ||
fn dummy_with_rng<R: Rng + ?Sized>(config: &U, rng: &mut R) -> Self { | ||
std::array::from_fn(|_| Fake::fake_with_rng::<T, _>(config, rng)) | ||
} | ||
} | ||
|
||
array_impl! {32, T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters