pub trait StructMerge<Src> {
// Required methods
fn merge(&mut self, src: Src);
fn merge_soft(&mut self, src: Src);
}
Expand description
Merge another struct into Self
.
Required Methods§
Sourcefn merge_soft(&mut self, src: Src)
fn merge_soft(&mut self, src: Src)
Merge the given struct into Self
whilst consuming it.
Nearly the same as merge
, but any Self::Option<T>
fields will only get merged if the
value of the field is None
.
For example:
ⓘ
struct Target { a: Option<String> };
struct Src { a: String };
let target = Target { a: Some("test".to_string()) };
let src = Src { a: "test2".to_string() };
target.merge_soft(src);
// Value didn't get merged as `target.a` was `Some`
assert_eq!(target.a, "test".to_string());
Implementors§
impl<Target, Src: StructMergeInto<Target>> StructMerge<Src> for Target
Implement the StructMerge trait for all types that provide StructMergeInto for it.