diff --git a/src/mango/util/collection/mod.rs b/src/mango/util/collection/mod.rs new file mode 100644 index 00000000..5f327a57 --- /dev/null +++ b/src/mango/util/collection/mod.rs @@ -0,0 +1,2 @@ +pub mod queue; +pub use self::queue::Queue; diff --git a/src/mango/util/collection/queue.rs b/src/mango/util/collection/queue.rs new file mode 100644 index 00000000..02996c44 --- /dev/null +++ b/src/mango/util/collection/queue.rs @@ -0,0 +1,23 @@ +use std::collections::VecDeque; + +/// A one-ended queue. +/// This is just a wrapper around deque so nobody pushes or pops the wrong end. +pub struct Queue { + deque: VecDeque, +} + +impl Queue { + pub fn new() -> Self { + Queue { + deque: VecDeque::with_capacity(16), + } + } + + pub fn push(&mut self, value: T) { + self.deque.push_back(value) + } + + pub fn pop(&mut self) -> Option { + self.deque.pop_front() + } +} diff --git a/src/mango/util/mod.rs b/src/mango/util/mod.rs index 11224671..e6c649ab 100644 --- a/src/mango/util/mod.rs +++ b/src/mango/util/mod.rs @@ -1,3 +1,5 @@ +pub mod collection; + pub mod strtype; pub mod numtype;