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:

structs

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 a None, a is unchanged.

  • If b is a Some(b_inner):

    • If a is a Some(a_inner), a_inner is merged with b_inner.

    • If a is a None, a becomes Some(b_inner).

Vec

The elements of b are appended to a.

BTreeMap

For each key k in b:

  • If a contains the key k too, the value in a is merged with the value in b.

  • If a does not contain the key k, the value in b is inserted into a.

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§

Merge other into self.

Implementations on Foreign Types§

Implementors§