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
use super::{super::variant::*, error::*, mode::*};
use {kutil::std::error::*, std::fmt};
impl<AnnotatedT> Variant<AnnotatedT> {
/// Merge another [Variant] into this [Variant]. Return true if any change happened.
///
/// This function only affects lists and maps.
///
/// The merging behavior depends on the [MergeMode].
pub fn merge_with_errors<'own, ErrorReceiverT>(
&mut self,
other: &'own Self,
merge_mode: &MergeMode,
errors: &mut ErrorReceiverT,
) -> Result<bool, MergeError<'own, AnnotatedT>>
where
AnnotatedT: Clone,
ErrorReceiverT: ErrorReceiver<MergeError<'own, AnnotatedT>>,
{
match (self, other) {
(Self::List(list), Self::List(other_list)) => list.merge_with_errors(other_list, merge_mode, errors),
(Self::Map(map), Self::Map(other_map)) => map.merge_with_errors(other_map, merge_mode, errors),
_ => Ok(false),
}
}
/// Merge another [Variant] into this [Variant] while failing on the first encountered error.
/// Return true if any change happened.
///
/// This function only affects lists and maps.
///
/// The merging behavior depends on the [MergeMode].
pub fn merge_with_mode<'own>(
&mut self,
other: &'own Self,
merge_mode: &MergeMode,
) -> Result<bool, MergeError<'own, AnnotatedT>>
where
AnnotatedT: Clone,
{
self.merge_with_errors(other, merge_mode, &mut FailFastErrorReceiver)
}
/// Merge another [Variant] into this value. Return true if any change happened.
///
/// This function only affects lists and maps.
///
/// Uses the default [MergeMode].
pub fn merge(&mut self, other: &Self) -> bool
where
AnnotatedT: Clone + fmt::Debug,
{
// The default mode should never cause errors, so unwrap is safe
self.merge_with_mode(other, &Default::default()).expect("merge_with_mode")
}
}