aboutsummaryrefslogtreecommitdiff
path: root/src/time/wheel/stack.rs
blob: 7d32f27d2313c2bba39aa6d908e952de73c3aeae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::borrow::Borrow;
use std::cmp::Eq;
use std::hash::Hash;

/// Abstracts the stack operations needed to track timeouts.
pub(crate) trait Stack: Default {
    /// Type of the item stored in the stack
    type Owned: Borrow<Self::Borrowed>;

    /// Borrowed item
    type Borrowed: Eq + Hash;

    /// Item storage, this allows a slab to be used instead of just the heap
    type Store;

    /// Returns `true` if the stack is empty
    fn is_empty(&self) -> bool;

    /// Push an item onto the stack
    fn push(&mut self, item: Self::Owned, store: &mut Self::Store);

    /// Pop an item from the stack
    fn pop(&mut self, store: &mut Self::Store) -> Option<Self::Owned>;

    /// Peek into the stack.
    fn peek(&self) -> Option<Self::Owned>;

    fn remove(&mut self, item: &Self::Borrowed, store: &mut Self::Store);

    fn when(item: &Self::Borrowed, store: &Self::Store) -> u64;
}