use crate::*;
pub struct Stash<'a, M, P>
where
M: Send,
P: PartialOrd + Ord,
{
pub(crate) msgs: Vec<Message<M, P>>,
pq: Option<&'a PriorityQueue<M, P>>,
}
impl<'a, M, P> Stash<'a, M, P>
where
M: Send,
P: PartialOrd + Ord,
{
pub fn new(pq: &'a PriorityQueue<M, P>) -> Self {
Stash {
msgs: Vec::new(),
pq: Some(pq),
}
}
pub fn without_priority_queue() -> Self {
Stash {
msgs: Vec::new(),
pq: None,
}
}
pub fn is_empty(&self) -> bool {
self.msgs.is_empty()
}
pub fn len(&self) -> usize {
self.msgs.len()
}
pub fn capacity(&self) -> usize {
self.msgs.capacity()
}
}
impl<M, P> Drop for Stash<'_, M, P>
where
M: Send,
P: PartialOrd + Ord,
{
fn drop(&mut self) {
if let Some(pq) = self.pq {
pq.sync(self);
}
}
}