pub trait Merge: Sized {
// Required method
fn merge_ref(&mut self, other: Self) -> Result<(), Error>;
// Provided method
fn merge(self, other: Self) -> Result<Self, Error> { ... }
}Expand description
A value that may be merged.
This trait defines the interface by which 2 values are merged together.
There are 2 ways to merge values together only differing in whether they take ownership of the value.
Both of these methods must perform merging in the same way. Any deviation in the 2 implementations is considered undefined behavior and will lead to bugs.
Merge::merge is provided by default as long as you provide the
implementation for Merge::merge_ref. Generally there should be no reason
to have to implement both of the above.
Required Methods§
Provided Methods§
Sourcefn merge(self, other: Self) -> Result<Self, Error>
fn merge(self, other: Self) -> Result<Self, Error>
Merge self with other.
§Example
let a = vec![1, 3, 4];
let b = vec![7, 2, 0];
let c = a.merge(b).unwrap();
assert_eq!(c, &[1, 3, 4, 7, 2, 0]);§Implementation
The default implementation of this method calls out to Merge::merge_ref.
Don’t implemenent this unless you can do something better.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".