mod list;
mod ring;
use list::BlockList;
use ring::Ring;
pub(crate) enum Flavor<T> {
Bounded(Ring<T>),
Unbounded(BlockList<T>),
}
impl<T> Flavor<T> {
pub(crate) fn bounded(cap: usize) -> Self {
Self::Bounded(Ring::with_capacity(cap))
}
pub(crate) fn unbounded() -> Self {
Self::Unbounded(BlockList::new())
}
#[inline(always)]
pub(crate) fn len(&self) -> usize {
match self {
Self::Bounded(r) => r.len(),
Self::Unbounded(l) => l.len(),
}
}
#[inline(always)]
pub(crate) fn is_empty(&self) -> bool {
match self {
Self::Bounded(r) => r.is_empty(),
Self::Unbounded(l) => l.is_empty(),
}
}
#[inline(always)]
pub(crate) fn cap(&self) -> Option<usize> {
match self {
Self::Bounded(r) => Some(r.cap()),
Self::Unbounded(_) => None,
}
}
#[inline(always)]
pub(crate) fn is_full(&self) -> bool {
match self {
Self::Bounded(r) => r.is_full(),
Self::Unbounded(_) => false,
}
}
#[inline(always)]
pub(crate) fn try_push(&mut self, item: T) -> Result<(), T> {
match self {
Self::Bounded(r) => r.push(item),
Self::Unbounded(l) => {
l.push(item);
Ok(())
}
}
}
#[inline(always)]
pub(crate) fn pop(&mut self) -> Option<T> {
match self {
Self::Bounded(r) => r.pop(),
Self::Unbounded(l) => l.pop(),
}
}
}