From 5300c4f4fc681aa700563ea453f64f20a31f51b6 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Sun, 22 Nov 2020 22:59:43 -0500 Subject: [PATCH] added queue structure, add to main file --- src/main.rs | 1 + src/queue.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/queue.rs diff --git a/src/main.rs b/src/main.rs index 12ab113..c7eb191 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ mod app; mod config; mod generate; mod request; +mod queue; const NUM_LEDS: usize = 150; diff --git a/src/queue.rs b/src/queue.rs new file mode 100644 index 0000000..a95d8c3 --- /dev/null +++ b/src/queue.rs @@ -0,0 +1,31 @@ +struct Queue { + pub queue: Vec +} + +impl Queue { + 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() + } +}