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
#[macro_export]
macro_rules! impl_summary {
($dest:ty, $field:ident<$key:ty, $value:ty>) => {
impl $crate::report::summary::Summary<$key, $value> for $dest {
fn iter(&self) -> ::std::collections::btree_map::Iter<$key, $value> {
self.$field.iter()
}
fn contains_key(&self, key: &$key) -> bool {
self.$field.contains_key(key)
}
fn get(&self, key: &$key) -> Option<&$value> {
self.$field.get(key)
}
fn len(&self) -> usize {
self.$field.len()
}
}
}
}
#[macro_export]
macro_rules! impl_try_merge_self_summary {
($dest:ty:$field:ident, $err:ty) => {
impl<'a> $crate::merger::ops::TryMerge<&'a $dest> for $dest {
type Err = $err;
fn try_merge(&mut self, other: &'a $dest) -> MergeResult<Self::Err> {
for (key, other_value) in other.iter() {
if !self.$field.contains_key(key) {
self.$field.insert(key.clone(), other_value.clone());
continue;
}
let value = self.$field.get_mut(key).unwrap();
let _ = value.try_merge(other_value)?;
}
Ok(())
}
}
}
}
#[macro_export]
macro_rules! impl_try_merge {
($dest:ty:$field:ident, $append:ty, $err:ty) => {
impl<'a> $crate::merger::ops::TryMerge<&'a $append> for $dest {
type Err = $err;
fn try_merge(&mut self, data: &'a $append) -> MergeResult<Self::Err> {
self.$field.try_merge(data)
}
}
};
}
#[macro_export]
macro_rules! impl_from_error {
($from:ty, $dest:ident::$item:ident) => {
impl ::std::convert::From<$from> for $dest {
fn from(error: $from) -> Self {
$dest::$item(error)
}
}
};
($from:ty, $nest_dest:ident::$nest_item:ident=>$dest:ident::$item:ident) => {
impl From<$from> for MergeError {
fn from(error: $from) -> Self {
$dest::$item($nest_dest::$nest_item(error))
}
}
}
}