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
//! Small utilities.
use Value as JsonValue;
use io;
use TcpListener;
/// Find a TCP port number to use. This is racy but see
/// https://bugzilla.mozilla.org/show_bug.cgi?id=1240830
///
/// If port is Some, check if we can bind to the given port. Otherwise
/// pick a random port.
pub
/// Recursively merge serde_json::Value's from a then b into a new
/// returned value.
///
/// # Example
///
/// ```
/// # #[macro_use] extern crate serde_json;
/// # extern crate webdriver_client;
/// #
/// # use webdriver_client::util::merge_json;
/// # fn main() {
/// #
/// let a = json!({
/// "a": "only in a",
/// "overwritten": "value in a",
/// "child_object": { "x": "value in a" },
/// "array": ["value 1 in a", "value 2 in a"],
/// "different_types": 5
/// });
/// let b = json!({
/// "b": "only in b",
/// "overwritten": "value in b",
/// "child_object": { "x": "value in b" },
/// "array": ["value in b"],
/// "different_types": true
/// });
/// let merged = merge_json(&a, &b);
///
/// assert_eq!(merged, json!({
/// // When only one input contains the key, the value is cloned.
/// "a": "only in a",
/// "b": "only in b",
///
/// // When both inputs contain a key, the value from b is cloned.
/// "overwritten": "value in b",
///
/// // When a child object is present in both values, it is recursively
/// // merged.
/// "child_object": { "x": "value in b" },
///
/// // If both values are an array, the value from b is cloned.
/// "array": ["value in b"],
///
/// // If the two values have different types, the value from b is cloned.
/// "different_types": true
/// }));
/// #
/// # } // Close main.
/// Recursively merge serde_json::Value's from b into a.