added queue structure, add to main file
This commit is contained in:
parent
137962a538
commit
5300c4f4fc
@ -11,6 +11,7 @@ mod app;
|
|||||||
mod config;
|
mod config;
|
||||||
mod generate;
|
mod generate;
|
||||||
mod request;
|
mod request;
|
||||||
|
mod queue;
|
||||||
|
|
||||||
const NUM_LEDS: usize = 150;
|
const NUM_LEDS: usize = 150;
|
||||||
|
|
||||||
|
31
src/queue.rs
Normal file
31
src/queue.rs
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user