1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
pub enum Tramp<R> {
    Traverse(R),
    Complete(R),
}

impl<R> Tramp<R> {
    pub fn execute<F>(mut self, f: F) -> R
    where
        F: Fn(R) -> Tramp<R>,
    {
        loop {
            match self {
                Tramp::Traverse(value) => {
                    self = f(value);
                }
                Tramp::Complete(value) => {
                    return value;
                }
            }
        }
    }
}