Trait Merge

Source
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§

Source

fn merge_ref(&mut self, other: Self) -> Result<(), Error>

Merge self with other without taking ownership of self.

§Example
let mut a = vec![1, 3, 4];
let b = vec![7, 2, 0];

a.merge_ref(b).unwrap();

assert_eq!(a, &[1, 3, 4, 7, 2, 0]);

Provided Methods§

Source

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 &str

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for &[u8]

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for IpAddr

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for SocketAddr

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for bool

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for char

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for f32

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for f64

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for i8

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for i16

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for i32

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for i64

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for isize

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for u8

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for u16

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for u32

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for u64

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for ()

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, (): Self) -> Result<(), Error>

Source§

impl Merge for usize

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Box<str>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Box<CStr>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Box<OsStr>

Available on crate feature std only.
Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Box<Path>

Available on crate feature std only.
Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for CString

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for String

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Ipv4Addr

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Ipv6Addr

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for SocketAddrV4

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for SocketAddrV6

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Saturating<i8>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Saturating<i16>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Saturating<i32>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Saturating<i64>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Saturating<isize>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Saturating<u8>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Saturating<u16>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Saturating<u32>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Saturating<u64>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Saturating<usize>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Wrapping<i8>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Wrapping<i16>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Wrapping<i32>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Wrapping<i64>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Wrapping<isize>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Wrapping<u8>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Wrapping<u16>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Wrapping<u32>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Wrapping<u64>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Wrapping<usize>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for Duration

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for OsString

Available on crate feature std only.
Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for PathBuf

Available on crate feature std only.
Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for SystemTime

Available on crate feature std only.
Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for NonZeroI8

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for NonZeroI16

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for NonZeroI32

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for NonZeroI64

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for NonZeroIsize

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for NonZeroU8

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for NonZeroU16

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for NonZeroU32

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for NonZeroU64

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl Merge for NonZeroUsize

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl<K, V> Merge for BTreeMap<K, V>
where K: Ord + Display, V: Merge,

Source§

fn merge_ref(&mut self, other: Self) -> Result<(), Error>

Source§

impl<K, V, S> Merge for HashMap<K, V, S>
where K: Eq + Hash + Display, V: Merge, S: BuildHasher,

Available on crate feature std only.
Source§

fn merge_ref(&mut self, other: Self) -> Result<(), Error>

Source§

impl<T> Merge for Cow<'_, T>
where T: ?Sized + ToOwned, T::Owned: Merge,

Source§

fn merge_ref(&mut self, other: Self) -> Result<(), Error>

Source§

impl<T> Merge for Option<T>
where T: Merge,

Source§

fn merge_ref(&mut self, other: Self) -> Result<(), Error>

Source§

impl<T> Merge for Box<[T]>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl<T> Merge for Box<T>
where T: Merge,

Source§

fn merge_ref(&mut self, other: Self) -> Result<(), Error>

Source§

impl<T> Merge for BTreeSet<T>
where T: Ord,

Source§

fn merge_ref(&mut self, other: Self) -> Result<(), Error>

Source§

impl<T> Merge for LinkedList<T>

Source§

fn merge_ref(&mut self, other: Self) -> Result<(), Error>

Source§

impl<T> Merge for Vec<T>

Source§

fn merge_ref(&mut self, other: Self) -> Result<(), Error>

Source§

impl<T> Merge for Cell<T>
where T: Merge,

Source§

fn merge_ref(&mut self, other: Self) -> Result<(), Error>

Source§

impl<T> Merge for PhantomData<T>

Source§

fn merge_ref(&mut self, _: Self) -> Result<(), Error>

Source§

impl<T> Merge for Range<T>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl<T> Merge for RangeFrom<T>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl<T> Merge for RangeInclusive<T>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl<T> Merge for RangeTo<T>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl<T, E> Merge for Result<T, E>

Source§

fn merge(self, _other: Self) -> Result<Self, Error>

Source§

fn merge_ref(&mut self, _other: Self) -> Result<(), Error>

Source§

impl<T, S> Merge for HashSet<T, S>
where T: Eq + Hash, S: BuildHasher,

Available on crate feature std only.
Source§

fn merge_ref(&mut self, other: Self) -> Result<(), Error>

Implementors§

Source§

impl Merge for Lines

Source§

impl<T> Merge for NoMerge<T>

Source§

impl<T, const DEFAULT: isize> Merge for Overridable<T, DEFAULT>