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", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Merge for SocketAddr
impl Merge for SocketAddr
Source§impl Merge for SocketAddrV4
impl Merge for SocketAddrV4
Source§impl Merge for SocketAddrV6
impl Merge for SocketAddrV6
Source§impl Merge for Saturating<i8>
impl Merge for Saturating<i8>
Source§impl Merge for Saturating<i16>
impl Merge for Saturating<i16>
Source§impl Merge for Saturating<i32>
impl Merge for Saturating<i32>
Source§impl Merge for Saturating<i64>
impl Merge for Saturating<i64>
Source§impl Merge for Saturating<isize>
impl Merge for Saturating<isize>
Source§impl Merge for Saturating<u8>
impl Merge for Saturating<u8>
Source§impl Merge for Saturating<u16>
impl Merge for Saturating<u16>
Source§impl Merge for Saturating<u32>
impl Merge for Saturating<u32>
Source§impl Merge for Saturating<u64>
impl Merge for Saturating<u64>
Source§impl Merge for Saturating<usize>
impl Merge for Saturating<usize>
Source§impl Merge for SystemTime
Available on crate feature std
only.
impl Merge for SystemTime
std
only.