use std::mem; /// Simple inefficient datastructure with guaranteed drop order #[derive(Debug)] pub enum Stack { Cons(Box<(T, Stack)>), Empty, } impl Default for Stack { fn default() -> Self { Self::Empty } } impl Stack { pub fn new() -> Self { Self::Empty } pub fn push(&mut self, value: T) { let tmp = mem::take(self); *self = Stack::Cons(Box::new((value, tmp))); } }