pub struct Mergable<T> { /* private fields */ }
Expand description

Very often, types from the standard library and other crates will not implement the Merge or MergeMut traits, preventing us from leveraging recursive merging with complex data structures. Given that rust only allows trait implementations in the crate defining the trait or the struct, this puts users in a tough position of writing more code.

The Mergable type is a type wrapper that implements the Merge and MergeMut traits using the provided [Strategy] while exposing the underlying type through Deref and a number of operators that forward the underlying implementation to the inner type.

Usage

use merge_rs::Merge;
use merge_rs::mergeable::Mergable;
 
struct Message(String);
impl Message {
  pub fn new(msg: String) -> Self {
    Self(msg)
  }
 
  pub fn get(&self) -> &str {
    &self.0
  }
}
 
fn concat_messages(
  left: &Message, 
  right: &Message
) -> Message {
  Message::new(
    format!("{} {}", left.get(), right.get())
  )
}
 
let msg1 = Mergable::new(
    Message::new("hello".to_string()),
    concat_messages
);
let msg2 = Mergable::new(
    Message::new("world".to_string()),
    concat_messages
);
let greeting = msg1.merge(&msg2);
 
let hello_sring = msg1.get();

Implementations

Construct a new Mergable type with a given inner type and strategy for merging instances of the inner types together.

Trait Implementations

The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
The resulting type after applying the & operator.
Performs the & operation. Read more
The resulting type after applying the & operator.
Performs the & operation. Read more
Performs the &= operation. Read more
Performs the &= operation. Read more
The resulting type after applying the | operator.
Performs the | operation. Read more
The resulting type after applying the | operator.
Performs the | operation. Read more
Performs the |= operation. Read more
Performs the |= operation. Read more
The resulting type after applying the ^ operator.
Performs the ^ operation. Read more
The resulting type after applying the ^ operator.
Performs the ^ operation. Read more
Performs the ^= operation. Read more
Performs the ^= operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
The resulting type after applying the ! operator.
Performs the unary ! operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
Performs the %= operation. Read more
Performs the %= operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.