pub struct DynamicDeque<T, const STACK_SIZE: usize> { /* private fields */ }Expand description
A dynamic deque that can store elements in a stack or a heap. First, elements are pushed to the stack. If the stack is full, elements are pushed to the heap. When popping elements, the stack is popped first. If the stack is empty and the heap is not, the heap is popped and the elements are pushed to the stack. Example:
use sans_io_runtime::collections::DynamicDeque;
let mut deque: DynamicDeque<i32, 5> = DynamicDeque::default();
deque.push_back_stack(1).unwrap();
deque.push_back_stack(2).unwrap();
deque.push_back_stack(3).unwrap();
deque.push_back_stack(4).unwrap();
deque.push_back_stack(5).unwrap();
deque.push_back(6); // Should overflow to heap
assert_eq!(deque.len(), 6);Implementations§
Source§impl<T, const STATIC_SIZE: usize> DynamicDeque<T, STATIC_SIZE>
impl<T, const STATIC_SIZE: usize> DynamicDeque<T, STATIC_SIZE>
Sourcepub fn push_back_stack(&mut self, value: T) -> Result<(), T>
pub fn push_back_stack(&mut self, value: T) -> Result<(), T>
Sourcepub fn pop_front(&mut self) -> Option<T>
pub fn pop_front(&mut self) -> Option<T>
Pops the element from the front of the deque.
§Returns
The popped element, or None if the deque is empty.
Trait Implementations§
Auto Trait Implementations§
impl<T, const STACK_SIZE: usize> Freeze for DynamicDeque<T, STACK_SIZE>where
T: Freeze,
impl<T, const STACK_SIZE: usize> RefUnwindSafe for DynamicDeque<T, STACK_SIZE>where
T: RefUnwindSafe,
impl<T, const STACK_SIZE: usize> Send for DynamicDeque<T, STACK_SIZE>where
T: Send,
impl<T, const STACK_SIZE: usize> Sync for DynamicDeque<T, STACK_SIZE>where
T: Sync,
impl<T, const STACK_SIZE: usize> Unpin for DynamicDeque<T, STACK_SIZE>where
T: Unpin,
impl<T, const STACK_SIZE: usize> UnwindSafe for DynamicDeque<T, STACK_SIZE>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more