added queue structure, add to main file

This commit is contained in:
Wyatt J. Miller 2020-11-22 22:59:43 -05:00
parent 137962a538
commit 5300c4f4fc
2 changed files with 32 additions and 0 deletions

View File

@ -11,6 +11,7 @@ mod app;
mod config;
mod generate;
mod request;
mod queue;
const NUM_LEDS: usize = 150;

31
src/queue.rs Normal file
View File

@ -0,0 +1,31 @@
struct Queue<T> {
pub queue: Vec<T>
}
impl<T> Queue<T> {
pub fn new() -> Self {
Queue {
queue: Vec::new()
}
}
pub fn enqueue(&mut self, item: T) {
self.queue.push(item)
}
pub fn dequeue(&mut self) -> T {
self.queue.remove(0)
}
pub fn length(&self) -> usize {
self.queue.len()
}
pub fn is_empty(&self) -> bool {
self.queue.is_empty()
}
pub fn peek(&self) -> Option<&T> {
self.queue.first()
}
}