pub struct VecQueue<T> { /* private fields */ }Expand description
A queue that uses a vector to store the elements.
It is a similar to std::collections::VecDeque, but it provides a few additional methods
that are used by Orengine's projects.
Implementations§
Source§impl<T> VecQueue<T>
 
impl<T> VecQueue<T>
Sourcepub fn extend_to(&mut self, capacity: usize)
 
pub fn extend_to(&mut self, capacity: usize)
Extends the vector to the given capacity.
§Panics
Panics if the provided capacity is not a power of two or is less than the current capacity.
Sourcepub fn push_priority_value(&mut self, value: T)
 
pub fn push_priority_value(&mut self, value: T)
Pushes the provided value to the front of the queue.
§Example
use orengine_utils::VecQueue;
let mut queue = VecQueue::new();
queue.push_priority_value(1); // [1, _, _]
queue.push(2); // [1, 2, _]
queue.push_priority_value(3); // [3, 1, 2]
assert_eq!(queue.pop(), Some(3));
assert_eq!(queue.pop(), Some(1));
assert_eq!(queue.pop(), Some(2));Sourcepub fn pop_less_priority_value(&mut self) -> Option<T>
 
pub fn pop_less_priority_value(&mut self) -> Option<T>
Removes the last element and returns it, or None if the queue is empty.
§Example
use orengine_utils::VecQueue;
let mut queue = VecQueue::new();
queue.push(1); // [1, _, _]
queue.push(2); // [1, 2, _]
queue.push(3); // [1, 2, 3]
assert_eq!(queue.pop_less_priority_value(), Some(3));
assert_eq!(queue.pop(), Some(1));
assert_eq!(queue.pop(), Some(2));Sourcepub unsafe fn extend_from_slice(&mut self, slice: &[T])
 
pub unsafe fn extend_from_slice(&mut self, slice: &[T])
Sourcepub unsafe fn take_batch<F: FnOnce(&[T], &[T])>(&mut self, f: F, limit: usize)
 
pub unsafe fn take_batch<F: FnOnce(&[T], &[T])>(&mut self, f: F, limit: usize)
Accepts a function that will be called with the slices of the queue to move.
§Safety
The function should copy all elements from the provided slices.
§Example
use orengine_utils::VecQueue;
let mut queue = VecQueue::new();
for i in 0..10 {
    queue.push(i);
}
let mut receiver = Vec::with_capacity(10);
unsafe {
    queue.take_batch(|first_slice, second_slice| {
        receiver.extend_from_slice(first_slice);
        receiver.extend_from_slice(second_slice);
    }, 8);
}
assert_eq!(receiver, (0..8).collect::<Vec<_>>());
assert_eq!(queue.len(), 2);
assert_eq!(queue.pop(), Some(8));
assert_eq!(queue.pop(), Some(9));Sourcepub fn clear_with<F: Fn(T)>(&mut self, f: F)
 
pub fn clear_with<F: Fn(T)>(&mut self, f: F)
Clears the queue by calling the provided function on each element.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for VecQueue<T>
impl<T> RefUnwindSafe for VecQueue<T>where
    T: RefUnwindSafe,
impl<T> !Send for VecQueue<T>
impl<T> !Sync for VecQueue<T>
impl<T> Unpin for VecQueue<T>
impl<T> UnwindSafe for VecQueue<T>where
    T: RefUnwindSafe,
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