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
64
65
66
67
68
use crate::{fact::Bounds, Check, Fact};
use arbitrary::Unstructured;
#[tracing::instrument(skip(fact))]
pub fn check_seq<T, F>(seq: &[T], mut fact: F) -> Check
where
F: Fact<T>,
T: Bounds,
{
let mut reasons: Vec<String> = Vec::new();
for (i, obj) in seq.iter().enumerate() {
reasons.extend(
fact.check(obj)
.into_iter()
.map(|reason| format!("item {}: {}", i, reason))
.collect::<Vec<_>>(),
);
fact.advance(obj);
}
reasons.into()
}
#[tracing::instrument(skip(u, fact))]
pub fn build_seq<T, F>(u: &mut Unstructured<'static>, num: usize, mut fact: F) -> Vec<T>
where
T: Bounds,
F: Fact<T>,
{
let mut seq = Vec::new();
for _i in 0..num {
tracing::trace!("i: {}", _i);
let obj = fact.build(u);
fact.advance(&obj);
seq.push(obj);
}
return seq;
}
#[macro_export]
macro_rules! facts {
( $( $fact:expr ),+ $(,)?) => {{
let mut fs: $crate::Facts<_> = Vec::new();
$(
fs.push(Box::new($fact));
)+
fs
}};
}