1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use rand::Rng;
pub struct Faker;
pub trait Dummy<T>: Sized {
fn dummy(config: &T) -> Self {
let mut r = rand::thread_rng();
Dummy::<T>::dummy_with_rng(config, &mut r)
}
fn dummy_with_rng<R: Rng + ?Sized>(config: &T, rng: &mut R) -> Self;
}
mod private {
pub trait FakeBase<T>: Sized {
fn _fake(&self) -> T;
fn _fake_with_rng<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> T;
}
impl<T, U> FakeBase<U> for T
where
U: crate::Dummy<T>,
{
fn _fake(&self) -> U {
U::dummy(self)
}
fn _fake_with_rng<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> U {
U::dummy_with_rng(self, rng)
}
}
}
pub trait Fake: Sized {
#[inline]
fn fake<U>(&self) -> U
where
Self: private::FakeBase<U>,
{
self._fake()
}
#[inline]
fn fake_with_rng<U, R: Rng + ?Sized>(&self, rng: &mut R) -> U
where
Self: private::FakeBase<U>,
{
self._fake_with_rng(rng)
}
}
impl<T> Fake for T {}
#[macro_use]
mod impls;
pub use impls::std::path::PathFaker;
pub use impls::std::result::ResultFaker;
pub use impls::std::string::StringFaker;
pub mod faker;
pub mod locales;
#[cfg(feature = "derive")]
pub use dummy::Dummy;