Merge2
Provides Merge
trait that can be used to merge structs into single by it's values:
Merge
can be derived for structs:
use Merge;
let mut defaults = User ;
let mut ferris = User ;
ferris.merge;
assert_eq!;
assert_eq!;
assert_eq!;
A merge strategy is a function with the signature fn merge<T>(left: &mut T, right: &mut T)
that merges right
into left
. The merge2
crate provides strategies
for the most common types, but you can also define your own strategies.
The trait can be used to merge configuration from different sources:
environment variables, multiple configuration files and command-line
arguments, see the args.rs
example.
Features
This crate has the following features:
derive
(default): Enables the derive macro for theMerge
trait using themerge_derive
crate.num
(default): Enables the merge strategies in thenum
module that require thenum_traits
crate.std
(default): Enables the merge strategies for thehashmap
andvec
that require the standard library. If this feature is not set,merge2
is ano_std
.