1
use crate::Commands;
2
use uniplate::Uniplate;
3

            
4
pub struct Reduction<T, M>
5
where
6
    T: Uniplate,
7
{
8
    pub new_tree: T,
9
    pub(crate) commands: Commands<T, M>,
10
}
11

            
12
impl<T, M> Reduction<T, M>
13
where
14
    T: Uniplate,
15
{
16
222
    pub(crate) fn apply_transform<F>(transform: F, tree: &T, meta: &M) -> Option<Self>
17
222
    where
18
222
        F: Fn(&mut Commands<T, M>, &T, &M) -> Option<T>,
19
222
    {
20
222
        let mut commands = Commands::new();
21
222
        let new_tree = transform(&mut commands, &tree, &meta)?;
22
36
        Some(Self { new_tree, commands })
23
222
    }
24
}