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
use super::DEFAULT_LEN_RANGE;
use crate::{Dummy, Fake, Faker};
use rand::Rng;
impl<T> Dummy<Faker> for Vec<T>
where
T: Dummy<Faker>,
{
fn dummy_with_rng<R: Rng + ?Sized>(config: &Faker, rng: &mut R) -> Self {
let len: usize = DEFAULT_LEN_RANGE.fake_with_rng(rng);
let mut v = Vec::with_capacity(len);
for _ in 0..len {
v.push(config.fake_with_rng(rng));
}
v
}
}
impl<T, E, L> Dummy<(E, L)> for Vec<T>
where
T: Dummy<E>,
usize: Dummy<L>,
{
fn dummy_with_rng<R: Rng + ?Sized>(config: &(E, L), rng: &mut R) -> Self {
let len: usize = config.1.fake_with_rng(rng);
let mut v = Vec::with_capacity(len);
for _ in 0..len {
v.push(config.0.fake_with_rng(rng));
}
v
}
}
#[macro_export]
macro_rules! vec {
(@ty $t:ty) => ($t);
(@ty $t:ty;) => ($t);
(@ty $t:ty; $e:expr) => (std::vec::Vec<$t>);
(@ty $t:ty; $e:expr, $($r:tt)*) => {
std::vec::Vec<$crate::vec!(@ty $t; $($r)*)>
};
(@c $e:expr; $l:expr) => (($e, $l));
(@c $e:expr; $l:expr,) => (($e, $l));
(@c $e:expr; $l:expr, $($r:tt)*) => {
($crate::vec!(@c $e; $($r)*) , $l)
};
($t:ty; $($l:tt)+) => {
$crate::vec!($t as $crate::Faker; $($l)*)
};
($t:ty as $e:expr; $($l:tt)+) => {
$crate::Fake::fake::<$crate::vec!(@ty $t; $($l)*)>(&$crate::vec!(@c $e; $($l)*))
};
}