pub trait Mergeable {
// Required methods
fn can_merge(&self, other: &Self) -> bool;
fn merge(self, other: Self) -> Self;
}Expand description
Trait for operations that can be merged (coalesced)
Implement this trait to enable automatic merging of consecutive similar operations (e.g., multiple character insertions into one).
§Example
ⓘ
impl Mergeable for TextOp {
fn can_merge(&self, other: &Self) -> bool {
match (self, other) {
(TextOp::Insert { pos: p1, .. }, TextOp::Insert { pos: p2, .. }) => {
// Can merge if inserting at consecutive positions
*p2 == *p1 + 1
}
_ => false,
}
}
fn merge(self, other: Self) -> Self {
match (self, other) {
(TextOp::Insert { pos, text: mut t1 }, TextOp::Insert { text: t2, .. }) => {
t1.push_str(&t2);
TextOp::Insert { pos, text: t1 }
}
_ => self,
}
}
}Required Methods§
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.