Module inter_struct::merge
source · [−]Expand description
Docs and traits for struct merging.
Merge Behavior
The following will explain the merge behavior on the example of a single field.
Merge behavior of merge and merge_ref
Same Type
ⓘ
struct Src {
test: T
}
struct Target {
test: T
}This will simply merge src.test into target.test:
target.test = src.test
Target is Optional
ⓘ
struct Src {
test: T
}
struct Target {
test: Option<T>
}This will wrap src.test into an Option and merge it into target.test:
target.test = Some(src.test);
Source is Optional
ⓘ
struct Src {
test: Option<T>
}
struct Target {
test: T
}This will only merge src.test into target.test if src.test is Some:
ⓘ
if let Some(value) = src.test {
target.test = value;
}Traits
Merge another struct into Self.
Counterpart of StructMerge.
This will merge Self into a given target.
Counterpart of StructMergeRef.
This will merge &Self into a given target.
Merge another borrowed struct into Self.