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§
- Struct
Merge - Merge another struct into
Self. - Struct
Merge Into - Counterpart of StructMerge.
This will merge
Selfinto a given target. - Struct
Merge Into Ref - Counterpart of StructMergeRef.
This will merge
&Selfinto a given target. - Struct
Merge Ref - Merge another borrowed struct into
Self.