| Crates.io | limited-queue |
| lib.rs | limited-queue |
| version | 0.2.0 |
| created_at | 2024-07-08 14:17:06.354883+00 |
| updated_at | 2025-10-28 09:31:41.622881+00 |
| description | a limited queue that overrides the oldest data if trying to push a data when the queue is full. |
| homepage | |
| repository | https://github.com/Shiritai/limited-queue |
| max_upload_size | |
| id | 1296005 |
| size | 28,664 |
A circular queue that overrides the oldest data if trying to push a data when the queue is full.
All operations are of O(1) complexity, except the constructor with O(Vec::with_capacity).
There is a similar library circular-queue I found, but without the basic peek and pop operations.
The comparison for now is listed below:
LimitedQueue |
circular-queue |
|
|---|---|---|
| Algorithm | circular queue (front-rear, without additional element slot) | circular queue (based on len and capacity provided by Vec) |
| Element trait bound needed | No | - |
push, size-related methods |
✅ | ✅ |
peek, pop support |
✅: peek✅: pop |
❌ |
| Indexing | ✅ - [0, len)- support [idx]- support get(idx)- optionally mutable ( [idx]) |
❌ |
| Iterator | ✅ - iter() (DoubleEndedIterator)- iter_mut() (DoubleEndedIterator) |
✅ - both ways - optionally mutable |
clear complexity |
O(1) |
O(Vec::clear) |
serde support |
❌ (TODO) | ✅ |
We welcome any kinds of contributions, please don't be hesitate to submit issues & PRs.
This is a significant feature and stability release.
pop() no longer requires the T: Default trait bound. This was achieved by refactoring the internal storage to Vec<Option<T>> and is verified by tests .iter_mut(), providing a mutable, double-ended iterator.iter() now implements DoubleEndedIterator, allowing for reverse iteration (e.g., .iter().rev()).push() and with_capacity() logic was rewritten to pre-allocate the internal Vec with None, simplifying the implementation and removing potential panic paths.get(idx) that caused incorrect None returns.panic conditions, achieving 100% test coverage.Please run scripts/setup.sh to setup for committing. Currently, the script registers a git pre-commit hook.