Lines Matching full:merge
4 //! Provides [`Merge`][], a trait for objects that can be merged.
9 //! trait Merge {
10 //! fn merge(&mut self, other: Self);
14 //! The [`Merge`][] trait can be used to merge two objects of the same type into one. The intended
18 //! `Merge` is implemented for `Option` and can be derived for structs. When deriving the `Merge`
19 //! trait for a struct, you can provide custom merge strategies for the fields that don’t implement
20 //! `Merge`. A merge strategy is a function with the signature `fn merge<T>(left: &mut T, right:
28 //! - `derive` (default): Enables the derive macro for the `Merge` trait using the `merge_derive`
30 //! - `num` (default): Enables the merge strategies in the `num` module that require the
32 //! - `std` (default): Enables the merge strategies in the `vec` module that require the standard
33 //! library. If this feature is not set, `merge` is a `no_std` library.
38 //! use merge::Merge;
40 //! #[derive(Merge)]
42 //! // Fields with the skip attribute are skipped by Merge
43 //! #[merge(skip)]
46 //! // The Merge implementation for Option replaces its value if it is None
49 //! // The strategy attribute is used to customize the merge behavior
50 //! #[merge(strategy = merge::vec::append)]
64 //! ferris.merge(defaults);
71 //! [`Merge`]: trait.Merge.html
72 //! [`args.rs`]: https://git.sr.ht/~ireas/merge-rs/tree/master/examples/args.rs
83 /// `Merge` can be derived for structs if the `derive` feature is enabled. The generated
84 /// implementation calls the `merge` method for all fields, or the merge strategy function if set.
86 /// - `skip`: Skip this field in the `merge` method.
87 /// - `strategy = f`: Call `f(self.field, other.field)` instead of calling the `merge` function for
92 /// Using the `Merge` implementation for `Option`:
95 /// use merge::Merge as _;
98 /// val.merge(Some(42));
102 /// Deriving `Merge` for a struct:
105 /// use merge::Merge;
107 /// #[derive(Debug, PartialEq, Merge)]
111 /// #[merge(skip)]
114 /// #[merge(strategy = merge::bool::overwrite_false)]
123 /// val.merge(S {
134 pub trait Merge { trait
135 /// Merge another object into this object.
136 fn merge(&mut self, other: Self); in merge() method
139 impl<T> Merge for Option<T> {
140 fn merge(&mut self, mut other: Self) { in merge() method
147 /// Merge strategies for boolean types.
164 /// Merge strategies for numeric types.
182 /// Merge strategies for types that form a total order.
201 /// Merge strategies for vectors.