1 use std::borrow::Borrow; 2 use std::cmp::Eq; 3 use std::hash::Hash; 4 5 /// Abstracts the stack operations needed to track timeouts. 6 pub(crate) trait Stack: Default { 7 /// Type of the item stored in the stack 8 type Owned: Borrow<Self::Borrowed>; 9 10 /// Borrowed item 11 type Borrowed: Eq + Hash; 12 13 /// Item storage, this allows a slab to be used instead of just the heap 14 type Store; 15 16 /// Returns `true` if the stack is empty is_empty(&self) -> bool17 fn is_empty(&self) -> bool; 18 19 /// Push an item onto the stack push(&mut self, item: Self::Owned, store: &mut Self::Store)20 fn push(&mut self, item: Self::Owned, store: &mut Self::Store); 21 22 /// Pop an item from the stack pop(&mut self, store: &mut Self::Store) -> Option<Self::Owned>23 fn pop(&mut self, store: &mut Self::Store) -> Option<Self::Owned>; 24 25 /// Peek into the stack. peek(&self) -> Option<Self::Owned>26 fn peek(&self) -> Option<Self::Owned>; 27 remove(&mut self, item: &Self::Borrowed, store: &mut Self::Store)28 fn remove(&mut self, item: &Self::Borrowed, store: &mut Self::Store); 29 when(item: &Self::Borrowed, store: &Self::Store) -> u6430 fn when(item: &Self::Borrowed, store: &Self::Store) -> u64; 31 } 32