pub struct Queue<T> { /* private fields */ }
Implementations§
source§impl<T: Clone> Queue<T>
impl<T: Clone> Queue<T>
pub const fn new(tick_id: TickId) -> Self
sourcepub fn clear(&mut self, initial_tick_id: TickId)
pub fn clear(&mut self, initial_tick_id: TickId)
Clears the queue and resets the expected read and write tick IDs.
sourcepub fn push(&mut self, tick_id: TickId, item: T) -> Result<(), QueueError>
pub fn push(&mut self, tick_id: TickId, item: T) -> Result<(), QueueError>
Pushes an item into the queue at the specified TickId
.
This method ensures that the item is added at the correct position in the tick sequence. The
tick_id
must match the expected TickId
for the queue to maintain an unbroken sequence.
§Parameters
tick_id
: TheTickId
where the item should be inserted. It must match the queue’s expected nextTickId
.item
: The item to be inserted into the queue.
§Returns
Ok(())
if the item is successfully added to the queue.Err(QueueError)
if the providedtick_id
does not match the expectedTickId
.
§Errors
- Returns a
QueueError::WrongTickId
if thetick_id
provided does not match the expectedTickId
, which maintains the sequential order of the queue.
pub fn debug_get(&self, index: usize) -> Option<&ItemInfo<T>>
pub fn pop(&mut self) -> Option<ItemInfo<T>>
pub fn discard_up_to(&mut self, tick_id: TickId)
pub fn discard_count(&mut self, count: usize)
sourcepub fn take(&mut self, count: usize) -> Option<(TickId, Vec<T>)>
pub fn take(&mut self, count: usize) -> Option<(TickId, Vec<T>)>
Pops up to a certain amount of items from the front of the queue and returns
the first TickId
and a vector of T
. Returns None
if the queue
is empty.
§Parameters
count
: The number of items to pop (or fewer if not enough items are available).
§Returns
Some((TickId, Vec<T>))
if there are items available.None
if the queue is empty.
§Example
use tick_id::TickId;
use tick_queue::Queue;
let mut items = Queue::new(TickId::new(0));
items.push(TickId::new(0), "Step 1").unwrap();
items.push(TickId::new(1), "Step 2").unwrap();
let result = items.take(5); // Will return up to 5 items (in this case 2)
if let Some((tick_id, popped_items)) = result {
assert_eq!(tick_id, TickId::new(0));
assert_eq!(popped_items, vec!["Step 1", "Step 2"]);
}
pub fn front_tick_id(&self) -> Option<TickId>
pub const fn expected_write_tick_id(&self) -> TickId
pub fn back_tick_id(&self) -> Option<TickId>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn to_vec(&self) -> Vec<T>
pub const fn iter_index(&self, start_index: usize) -> FromIndexIterator<'_, T> ⓘ
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Queue<T>
impl<T> RefUnwindSafe for Queue<T>where
T: RefUnwindSafe,
impl<T> Send for Queue<T>where
T: Send,
impl<T> Sync for Queue<T>where
T: Sync,
impl<T> Unpin for Queue<T>where
T: Unpin,
impl<T> UnwindSafe for Queue<T>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