pub struct BoundedQueue { /* private fields */ }Expand description
Bounded message queue
A queue with a fixed maximum capacity and configurable overflow policy.
§Example
use canlink_hal::queue::{BoundedQueue, QueueOverflowPolicy};
use canlink_hal::message::CanMessage;
// Create queue with default policy (DropOldest)
let mut queue = BoundedQueue::new(100);
// Create queue with custom policy
let mut queue = BoundedQueue::with_policy(100, QueueOverflowPolicy::DropNewest);Implementations§
Source§impl BoundedQueue
impl BoundedQueue
Sourcepub fn with_policy(capacity: usize, policy: QueueOverflowPolicy) -> Self
pub fn with_policy(capacity: usize, policy: QueueOverflowPolicy) -> Self
Create a new bounded queue with specified overflow policy
§Arguments
capacity- Maximum number of messages the queue can holdpolicy- Overflow handling policy
Sourcepub fn policy(&self) -> QueueOverflowPolicy
pub fn policy(&self) -> QueueOverflowPolicy
Get the overflow policy
Sourcepub fn stats(&self) -> QueueStats
pub fn stats(&self) -> QueueStats
Get queue statistics
Sourcepub fn push(&mut self, message: CanMessage) -> Result<(), QueueError>
pub fn push(&mut self, message: CanMessage) -> Result<(), QueueError>
Push a message to the queue
Behavior depends on the overflow policy:
DropOldest: Removes the oldest message if fullDropNewest: Rejects the new message if fullBlock: ReturnsQueueError::QueueFull(async version handles blocking)
§Errors
- Returns
QueueError::QueueFullif usingBlockpolicy and queue is full - Returns
QueueError::MessageDroppedif usingDropNewestpolicy and queue is full
Sourcepub fn pop(&mut self) -> Option<CanMessage>
pub fn pop(&mut self) -> Option<CanMessage>
Pop a message from the queue
Returns None if the queue is empty.
Sourcepub fn peek(&self) -> Option<&CanMessage>
pub fn peek(&self) -> Option<&CanMessage>
Peek at the next message without removing it
Sourcepub fn adjust_capacity(&mut self, new_capacity: usize)
pub fn adjust_capacity(&mut self, new_capacity: usize)
Adjust the queue capacity
If the new capacity is smaller than the current number of messages, excess messages are removed according to the overflow policy.
§Arguments
new_capacity- New maximum capacity
Sourcepub fn iter(&self) -> impl Iterator<Item = &CanMessage>
pub fn iter(&self) -> impl Iterator<Item = &CanMessage>
Iterate over messages without removing them
Source§impl BoundedQueue
impl BoundedQueue
Sourcepub fn from_config(config: &QueueConfig) -> Self
pub fn from_config(config: &QueueConfig) -> Self
Create a BoundedQueue from configuration
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for BoundedQueue
impl RefUnwindSafe for BoundedQueue
impl Send for BoundedQueue
impl Sync for BoundedQueue
impl Unpin for BoundedQueue
impl UnsafeUnpin for BoundedQueue
impl UnwindSafe for BoundedQueue
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