use super::super::core::RelSessionIndex;
use std::collections::VecDeque;
pub struct PostQueues<T> {
pub current: VecDeque<T>,
pub prev: VecDeque<T>,
pub default: VecDeque<T>,
}
impl<T> PostQueues<T> {
pub fn new(capacity: usize) -> Self {
Self {
current: VecDeque::with_capacity(capacity),
prev: VecDeque::with_capacity(capacity),
default: VecDeque::with_capacity(capacity),
}
}
pub fn iter(&self) -> impl Iterator<Item = &VecDeque<T>> {
[&self.current, &self.prev, &self.default].into_iter()
}
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut VecDeque<T>> {
[&mut self.current, &mut self.prev, &mut self.default].into_iter()
}
}
impl<T> std::ops::Index<Option<RelSessionIndex>> for PostQueues<T> {
type Output = VecDeque<T>;
fn index(&self, index: Option<RelSessionIndex>) -> &Self::Output {
match index {
Some(RelSessionIndex::Current) => &self.current,
Some(RelSessionIndex::Prev) => &self.prev,
None => &self.default,
}
}
}
impl<T> std::ops::IndexMut<Option<RelSessionIndex>> for PostQueues<T> {
fn index_mut(&mut self, index: Option<RelSessionIndex>) -> &mut Self::Output {
match index {
Some(RelSessionIndex::Current) => &mut self.current,
Some(RelSessionIndex::Prev) => &mut self.prev,
None => &mut self.default,
}
}
}