[][src]Trait merge::Merge

pub trait Merge {
    fn merge(&mut self, other: Self);
}

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 the merge method.
  • strategy = f: Call f(self.field, other.field) instead of calling the merge 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

fn merge(&mut self, other: Self)

Merge another object into this object.

Loading content...

Implementations on Foreign Types

impl<T> Merge for Option<T>[src]

Loading content...

Implementors

Loading content...