tick_queue

Struct Queue

source
pub struct Queue<T> { /* private fields */ }

Implementations§

source§

impl<T> Queue<T>

source

pub fn iter(&self) -> impl Iterator<Item = &ItemInfo<T>>

source§

impl<T: Clone> Queue<T>

source

pub const fn new(tick_id: TickId) -> Self

source

pub fn clear(&mut self, initial_tick_id: TickId)

Clears the queue and resets the expected read and write tick IDs.

source

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: The TickId where the item should be inserted. It must match the queue’s expected next TickId.
  • item: The item to be inserted into the queue.
§Returns
  • Ok(()) if the item is successfully added to the queue.
  • Err(QueueError) if the provided tick_id does not match the expected TickId.
§Errors
  • Returns a QueueError::WrongTickId if the tick_id provided does not match the expected TickId, which maintains the sequential order of the queue.
source

pub fn debug_get(&self, index: usize) -> Option<&ItemInfo<T>>

source

pub fn pop(&mut self) -> Option<ItemInfo<T>>

source

pub fn discard_up_to(&mut self, tick_id: TickId)

source

pub fn discard_count(&mut self, count: usize)

source

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"]);
}
source

pub fn front_tick_id(&self) -> Option<TickId>

source

pub const fn expected_write_tick_id(&self) -> TickId

source

pub fn back_tick_id(&self) -> Option<TickId>

source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

pub fn to_vec(&self) -> Vec<T>

source

pub const fn iter_index(&self, start_index: usize) -> FromIndexIterator<'_, T>

Trait Implementations§

source§

impl<T: Debug> Debug for Queue<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Default for Queue<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T> IntoIterator for Queue<T>

source§

fn into_iter(self) -> Self::IntoIter

Consumes the Queue collection and returns an iterator over the items.

This allows the use of the for loop and other iterator methods without manually calling iter().

source§

type Item = ItemInfo<T>

The type of the elements being iterated over.
source§

type IntoIter = IntoIter<ItemInfo<T>>

Which kind of iterator are we turning this into?

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.