tree_edit_distance/edit.rs
1use crate::Fold;
2
3/// A single operation between two [Node][crate::Node]s.
4#[derive(Debug, Clone, Eq, PartialEq, Hash)]
5pub enum Edit {
6 /// Swap the [Node][crate::Node]s and edit their children.
7 Replace(Box<[Edit]>),
8
9 /// Insert the incoming [Node][crate::Node] along with its children in place.
10 Insert,
11
12 /// Remove the existing [Node][crate::Node] along with its children.
13 Remove,
14}
15
16impl Fold for Edit {
17 #[inline]
18 fn fold<R, Fn: FnMut(R, &Self) -> R>(&self, init: R, f: &mut Fn) -> R {
19 if let Edit::Replace(c) = self {
20 c.fold(f(init, self), f)
21 } else {
22 f(init, self)
23 }
24 }
25}