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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! A module holding the crate's public traits.
/**
This trait defines a way to merge two instances of the same type.
```
# use schema_analysis::{Schema, context::{BooleanContext, DefaultContext}, traits::{Coalesce, Aggregate}};
#
# fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut context_1: BooleanContext = Default::default();
context_1.aggregate(&true);
context_1.aggregate(&true);
let mut schema_1 = Schema::<DefaultContext>::Boolean(context_1);
let mut context_2: BooleanContext = Default::default();
context_2.aggregate(&false);
let mut schema_2 = Schema::<DefaultContext>::Boolean(context_2);
schema_1.coalesce(schema_2); // schema_2 is gone.
let mut context_merged: BooleanContext = Default::default();
context_merged.aggregate(&true);
context_merged.aggregate(&true);
context_merged.aggregate(&false);
let schema_merged = Schema::<DefaultContext>::Boolean(context_merged);
assert_eq!(schema_1, schema_merged);
#
# Ok(())
# }
```
*/
/// This trait defines an interface used for types that need to receive values one at a time to
/// record something about them.
///
/// V is ?[Sized] to allow for `Aggregator<str>`.
/// In the future a better borrowing API might be implemented.
/// This trait checks whether the shape of two objects is the same.
/// The goal is to determine whether two representations are equivalent.
///
/// Example: two schemas of the same type might be structurally equivalent even if some of the
/// internal metadata is different because they have been visited by different sets of examples.
/// Example: two schemas of different types might be structurally equivalent if they represent the
/// same shape of data.
///
/// Notes:
/// - sample-dependent metadata should be ignored.
/// - semantic information (like a regex pattern) should match.
/// - unreliable information (like an *inferred* regex) might be ignored.
///
/// This trait closely mirrors [PartialEq].