summaryrefslogtreecommitdiffstats
path: root/crates/runner/src/util/stack.rs
blob: 15d5daf2b55187682e030b9f1080f43e0bf3b594 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use std::mem;

/// Simple inefficient datastructure with guaranteed drop order
#[derive(Debug)]
pub enum Stack<T> {
	Cons(Box<(T, Stack<T>)>),
	Empty,
}

impl<T> Default for Stack<T> {
	fn default() -> Self {
		Self::Empty
	}
}

impl<T> Stack<T> {
	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)));
	}
}