Trait k8s_openapi::DeepMerge
source · pub trait DeepMerge {
fn merge_from(&mut self, other: Self);
}
Expand description
A trait applies to types that support deep merging.
a.merge_from(b)
behaves in the following ways:
struct
s
Structs are merged by individually merging each of their fields. For example, given:
struct S {
a: i32,
b: String,
}
… the expected impl of DeepMerge
for S
would be:
impl DeepMerge for S {
fn merge_from(&mut self, other: Self) {
self.a.merge_from(other.a);
self.b.merge_from(other.b);
}
}
The structs in the k8s-openapi
crate behave this way. If you are implementing this trait for your own types, it is recommended to impl it in the same way.
Option
-
If
b
is aNone
,a
is unchanged. -
If
b
is aSome(b_inner)
:-
If
a
is aSome(a_inner)
,a_inner
is merged withb_inner
. -
If
a
is aNone
,a
becomesSome(b_inner)
.
-
Vec
The elements of b
are appended to a
.
BTreeMap
For each key k
in b
:
-
If
a
contains the keyk
too, the value ina
is merged with the value inb
. -
If
a
does not contain the keyk
, the value inb
is inserted intoa
.
serde_json::Value
serde_json::Value
is merged using the JSON merge algorithm (RFC 7396).
Other types
self
is just replaced by other
.
Required Methods§
sourcefn merge_from(&mut self, other: Self)
fn merge_from(&mut self, other: Self)
Merge other
into self
.