pub trait Merge: Sized {
// Required method
fn merge(parent: Option<&Self>, others: Box<[Self]>) -> MergeResult<Self>;
}Expand description
Defines how multiple instances of a type are merged.
The Merge trait is used to combine several versions of a value into a single instance.
It is mainly used in a fork-join lifecycle.
Implementations should define the merging logic between an optional parent value and a collection of child values.
§Examples
use node_flow::context::storage::local_storage::{Merge, MergeResult};
struct Counter(u32);
impl Merge for Counter {
fn merge(parent: Option<&Self>, others: Box<[Self]>) -> MergeResult<Self> {
let sum: u32 = others.iter().map(|c| c.0).sum();
let base = parent.map_or(0, |p| p.0);
MergeResult::ReplaceOrInsert(Counter(base + sum))
}
}Required Methods§
Sourcefn merge(parent: Option<&Self>, others: Box<[Self]>) -> MergeResult<Self>
fn merge(parent: Option<&Self>, others: Box<[Self]>) -> MergeResult<Self>
Merges the parent value with a list of child values and returns a MergeResult.
§Parameters
parent: An optional reference to the existing value in the parent context.others: A list of values to merge into the parent.
§Returns
A MergeResult indicating how the parent should be updated.
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.