pub trait Merge {
// Required method
fn merge(&mut self, other: Self);
}
Expand description
A trait for objects that can be merged.
§Deriving
Merge
can be derived for structs if the derive
feature is enabled. The generated
implementation calls the merge
method for all fields, or the merge strategy function if set.
You can use these field attributes to configure the generated implementation:
skip
: Skip this field in themerge
method.strategy = f
: Callf(self.field, other.field)
instead of calling themerge
function for this field.
§Examples
Using the Merge
implementation for Option
:
use merge::Merge as _;
let mut val = None;
val.merge(Some(42));
assert_eq!(Some(42), val);
Deriving Merge
for a struct:
use merge::Merge;
#[derive(Debug, PartialEq, Merge)]
struct S {
option: Option<usize>,
#[merge(skip)]
s: String,
#[merge(strategy = merge::bool::overwrite_false)]
flag: bool,
}
let mut val = S {
option: None,
s: "some ignored value".to_owned(),
flag: false,
};
val.merge(S {
option: Some(42),
s: "some other ignored value".to_owned(),
flag: true,
});
assert_eq!(S {
option: Some(42),
s: "some ignored value".to_owned(),
flag: true,
}, val);
Required Methods§
Object Safety§
This trait is not object safe.